]> mj.ucw.cz Git - libucw.git/commitdiff
removed trailing spaces, fixed speed test, some moves
authorPavel Charvat <pavel.charvat@netcentrum.cz>
Mon, 1 May 2006 10:25:41 +0000 (12:25 +0200)
committerPavel Charvat <pavel.charvat@netcentrum.cz>
Mon, 1 May 2006 10:25:41 +0000 (12:25 +0200)
images/color.c
images/color.h

index 457e2e2cda44313e1fa06bc8258bdd2c7f885b02..036535c7483e9db024274c3454a20882a4d7ce56 100644 (file)
@@ -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
 #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 <string.h>
 
@@ -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
index cb64a9c2320c9c823adbded641b966c7bf645eb9..28daa822141bff1cef63e27655b8a6d272aff866 100644 (file)
@@ -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;
 }