diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2010-02-02 03:41:23 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2010-02-02 03:41:23 +0000 |
commit | c3f3686ad99c4e95661959ff577dd2c0740a6a0a (patch) | |
tree | 89c01f020ad58dc5e0bf3a71b149e033f6cbd6c3 | |
parent | e461d0b5bb5d0d1e957d7101f28eabe14f042c53 (diff) | |
download | netpbm-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
-rw-r--r-- | doc/HISTORY | 7 | ||||
-rw-r--r-- | editor/pnmhisteq.c | 54 |
2 files changed, 49 insertions, 12 deletions
diff --git a/doc/HISTORY b/doc/HISTORY index 40d052e8..c8b3db60 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -8,16 +8,19 @@ not yet BJH Release 10.50.00 Add pampaintspill. + pnmconvol: Add -normalize . + + pnmhisteq: slight speedup. Thanks Thomas Baruchel. + libppmd/ppmpat: fix wild pointer in ppmd_fill_drawprocp(); broken in 10.47. - pnmconvol: Add -normalize . - palmtopnm: fix incorrect "PALM_DIRECT_COLOR_FLAG is not valid for version 3 encoding type" failure. Thanks Paul Bolle <pebolle@tiscali.nl>. pamtosvg: fix bug: occasional crash with out of range error. + Introduced in 10.42. palmtopnm: fix incorrect output with version 3 direct color. Thanks Paul Bolle <pebolle@tiscali.nl>. 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); } } } |