about summary refs log tree commit diff
path: root/editor/pnmhisteq.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-02-02 03:41:23 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-02-02 03:41:23 +0000
commitc3f3686ad99c4e95661959ff577dd2c0740a6a0a (patch)
tree89c01f020ad58dc5e0bf3a71b149e033f6cbd6c3 /editor/pnmhisteq.c
parente461d0b5bb5d0d1e957d7101f28eabe14f042c53 (diff)
downloadnetpbm-mirror-c3f3686ad99c4e95661959ff577dd2c0740a6a0a.tar.gz
netpbm-mirror-c3f3686ad99c4e95661959ff577dd2c0740a6a0a.tar.xz
netpbm-mirror-c3f3686ad99c4e95661959ff577dd2c0740a6a0a.zip
faster change of HSV value computation
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1109 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'editor/pnmhisteq.c')
-rw-r--r--editor/pnmhisteq.c54
1 files changed, 44 insertions, 10 deletions
diff --git a/editor/pnmhisteq.c b/editor/pnmhisteq.c
index 1987efc3..60202632 100644
--- a/editor/pnmhisteq.c
+++ b/editor/pnmhisteq.c
@@ -302,6 +302,48 @@ reportMap(const unsigned int * const lumahist,
 
 
 
+static xel
+scaleXel(xel    const thisXel,
+         double const scaler) {
+/*----------------------------------------------------------------------------
+   Scale the components of 'xel' by multiplying by 'scaler'.
+
+   Assume this doesn't cause it to exceed maxval.
+-----------------------------------------------------------------------------*/
+    xel retval;
+
+    PNM_ASSIGN(retval,
+               ((xelval)(PNM_GETR(thisXel) * scaler + 0.5)),
+               ((xelval)(PNM_GETG(thisXel) * scaler + 0.5)),
+               ((xelval)(PNM_GETB(thisXel) * scaler + 0.5)));
+    
+    return retval;
+}
+
+
+
+static xel
+remapRgbValue(xel          const thisXel,
+              xelval       const maxval,
+              const gray * const lumamap) {
+/*----------------------------------------------------------------------------
+  Return the color 'thisXel' with its HSV value changed per 'lumamap' but
+  the same hue and saturation.
+
+  'maxval' is the maxval for 'xel' and our return value.
+-----------------------------------------------------------------------------*/
+    struct hsv const hsv =
+        ppm_hsv_from_color(thisXel, maxval);
+    xelval const oldValue =
+        MIN(maxval, ROUNDU(hsv.v * maxval));
+    xelval const newValue =
+        lumamap[oldValue];
+    
+    return scaleXel(thisXel, (double)newValue/oldValue);
+}
+
+
+
 static void
 remap(xel **       const xels,
       unsigned int const cols,
@@ -323,16 +365,8 @@ remap(xel **       const xels,
                 if (monoOnly && PPM_ISGRAY(thisXel)) {
                     /* Leave this pixel alone */
                 } else {
-                    struct hsv hsv;
-                    xelval iv;
-
-                    hsv = ppm_hsv_from_color(thisXel, maxval);
-                    iv = MIN(maxval, ROUNDU(hsv.v * maxval));
-                    
-                    hsv.v = MIN(1.0, 
-                                ((double) lumamap[iv]) / ((double) maxval));
-
-                    xels[row][col] = ppm_color_from_hsv(hsv, maxval);
+                    xels[row][col] = remapRgbValue(xels[row][col],
+                                                   maxval, lumamap);
                 }
             }
         }