From 9cf26a46c73eceeb44eaa577dadce4209f1e6e16 Mon Sep 17 00:00:00 2001 From: Pavel Charvat Date: Mon, 1 May 2006 12:25:41 +0200 Subject: [PATCH] removed trailing spaces, fixed speed test, some moves --- images/color.c | 38 ++++++++++++++++++++++++-------------- images/color.h | 10 +++++++--- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/images/color.c b/images/color.c index 457e2e2c..036535c7 100644 --- a/images/color.c +++ b/images/color.c @@ -5,9 +5,6 @@ * * 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 @@ -16,12 +13,8 @@ #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 @@ -59,6 +52,13 @@ xyz_to_luv_slow(double luv[3], double xyz[3]) } } + +/***************** 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) { @@ -100,6 +100,12 @@ srgb_to_luv_pixels(byte *dest, byte *src, uns count) } } + +/************************ 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) @@ -239,6 +245,9 @@ color_conv_pixels(byte *dest, byte *src, uns count, struct color_grid_node *grid } } + +/**************************** TESTS *******************************/ + #ifdef TEST #include @@ -321,19 +330,20 @@ main(void) 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 diff --git a/images/color.h b/images/color.h index cb64a9c2..28daa822 100644 --- a/images/color.h +++ b/images/color.h @@ -6,6 +6,10 @@ * 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 @@ -124,11 +128,11 @@ color_conv_pixel(byte *dest, byte *src, struct color_grid_node *grid) 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; } -- 2.39.2