*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
- *
- * Reference:
- * - http://www.tecgraf.puc-rio.br/~mgattass/color/ColorIndex.html
*/
#undef LOCAL_DEBUG
#include "lib/math.h"
#include "images/color.h"
-u16 srgb_to_luv_tab1[256];
-u16 srgb_to_luv_tab2[9 << SRGB_TO_LUV_TAB2_SIZE];
-u32 srgb_to_luv_tab3[20 << SRGB_TO_LUV_TAB3_SIZE];
-struct color_grid_node *srgb_to_luv_grid;
-struct color_interpolation_node *color_interpolation_table;
+/********************* EXACT CONVERSION ROUTINES **********************/
/* sRGB to XYZ */
void
}
}
+
+/***************** OPTIMIZED SRGB -> LUV CONVERSION *********************/
+
+u16 srgb_to_luv_tab1[256];
+u16 srgb_to_luv_tab2[9 << SRGB_TO_LUV_TAB2_SIZE];
+u32 srgb_to_luv_tab3[20 << SRGB_TO_LUV_TAB3_SIZE];
+
void
srgb_to_luv_init(void)
{
}
}
+
+/************************ GRID INTERPOLATION ALGORITHM ************************/
+
+struct color_grid_node *srgb_to_luv_grid;
+struct color_interpolation_node *color_interpolation_table;
+
/* Returns volume of a given tetrahedron multiplied by 6 */
static inline uns
tetrahedron_volume(uns *v1, uns *v2, uns *v3, uns *v4)
}
}
+
+/**************************** TESTS *******************************/
+
#ifdef TEST
#include <string.h>
test_grid("grid sRGB -> Luv", srgb_to_luv_grid, srgb_to_luv_func);
#ifdef LOCAL_DEBUG
#define CNT 1000000
- byte *a = xmalloc(3 * CNT), *b = xmalloc(3 * CNT);
+#define TESTS 10
+ byte *a = xmalloc(3 * CNT), *b = xmalloc_zero(3 * CNT);
+ for (uns i = 0; i < 3 * CNT; i++)
+ a[i] = random_max(256);
init_timer();
- for (uns i = 0; i < 20; i++)
+ for (uns i = 0; i < TESTS; i++)
memcpy(b, a, CNT * 3);
DBG("memcpy time=%d", (uns)get_timer());
- for (uns i = 0; i < 3 * CNT; i++)
- a[i] = random_max(256);
init_timer();
- for (uns i = 0; i < 20; i++)
+ for (uns i = 0; i < TESTS; i++)
srgb_to_luv_pixels(b, a, CNT);
DBG("direct time=%d", (uns)get_timer());
init_timer();
- for (uns i = 0; i < 20; i++)
+ for (uns i = 0; i < TESTS; i++)
color_conv_pixels(b, a, CNT, srgb_to_luv_grid);
DBG("grid time=%d", (uns)get_timer());
#endif
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
*
+ *
+ * References:
+ * - http://www.tecgraf.puc-rio.br/~mgattass/color/ColorIndex.html
+ *
* FIXME:
* - fix theoretical problems with rounding errors in srgb_to_luv_pixel()
* - SIMD should help to speed up conversion of large arrays
g1 = g + n->ofs[1];
g2 = g + n->ofs[2];
g3 = g + n->ofs[3];
- dest[0] = (g0->val[0] * n->mul[0] + g1->val[0] * n->mul[1] +
+ dest[0] = (g0->val[0] * n->mul[0] + g1->val[0] * n->mul[1] +
g2->val[0] * n->mul[2] + g3->val[0] * n->mul[3] + 128) >> 8;
- dest[1] = (g0->val[1] * n->mul[0] + g1->val[1] * n->mul[1] +
+ dest[1] = (g0->val[1] * n->mul[0] + g1->val[1] * n->mul[1] +
g2->val[1] * n->mul[2] + g3->val[1] * n->mul[3] + 128) >> 8;
- dest[2] = (g0->val[2] * n->mul[0] + g1->val[2] * n->mul[1] +
+ dest[2] = (g0->val[2] * n->mul[0] + g1->val[2] * n->mul[1] +
g2->val[2] * n->mul[2] + g3->val[2] * n->mul[3] + 128) >> 8;
}