]> mj.ucw.cz Git - libucw.git/blobdiff - images/color.h
Merge with git+ssh://cvs.ucw.cz/projects/sherlock/GIT/sherlock.git
[libucw.git] / images / color.h
index cb64a9c2320c9c823adbded641b966c7bf645eb9..ec3cd4afd99e928f88baef9f8bafa3a0712d3d5c 100644 (file)
@@ -6,11 +6,18 @@
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
  *
  *     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
  *     - maybe try to generate a long switch in color_conv_pixel()
  *       with optimized entries instead of access to interpolation table
  *     FIXME:
  *     - fix theoretical problems with rounding errors in srgb_to_luv_pixel()
  *     - SIMD should help to speed up conversion of large arrays
  *     - maybe try to generate a long switch in color_conv_pixel()
  *       with optimized entries instead of access to interpolation table
+ *     - most of multiplications in srgb_to_luv_pixels can be replaced
+ *       with tables lookup... tests shows almost the same speed for random
+ *       input and cca 40% gain when input colors fit in CPU chache
  */
 
 #ifndef _IMAGES_COLOR_H
  */
 
 #ifndef _IMAGES_COLOR_H
@@ -52,6 +59,7 @@ extern u32 srgb_to_luv_tab3[20 << SRGB_TO_LUV_TAB3_SIZE];
 void srgb_to_luv_init(void);
 void srgb_to_luv_pixels(byte *dest, byte *src, uns count);
 
 void srgb_to_luv_init(void);
 void srgb_to_luv_pixels(byte *dest, byte *src, uns count);
 
+/* L covers the interval [0..255]; u and v are centered to 128 and scaled by 1/4 in respect of L */
 static inline void
 srgb_to_luv_pixel(byte *dest, byte *src)
 {
 static inline void
 srgb_to_luv_pixel(byte *dest, byte *src)
 {
@@ -124,11 +132,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];
   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;
              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;
              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;
 }
 
              g2->val[2] * n->mul[2] + g3->val[2] * n->mul[3] + 128) >> 8;
 }