diff options
-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); } } } |