]> mj.ucw.cz Git - libucw.git/blobdiff - images/color.c
Merge with git+ssh://cvs.ucw.cz/projects/sherlock/GIT/sherlock.git
[libucw.git] / images / color.c
index 457e2e2cda44313e1fa06bc8258bdd2c7f885b02..e6846605681d45a4c955f30192113370445a542c 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
+#define TESTS 10
   byte *a = xmalloc(3 * CNT), *b = xmalloc(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