diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2015-01-22 16:29:25 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2015-01-22 16:29:25 +0000 |
commit | adddf9c7d041d0cdc3e9445ca33cad48dec7bfb8 (patch) | |
tree | f74a12cb6f0e45b0e38240aac3223355cb008e28 | |
parent | c0162a145444aca87569ea24e0f6210281595183 (diff) | |
download | netpbm-mirror-adddf9c7d041d0cdc3e9445ca33cad48dec7bfb8.tar.gz netpbm-mirror-adddf9c7d041d0cdc3e9445ca33cad48dec7bfb8.tar.xz netpbm-mirror-adddf9c7d041d0cdc3e9445ca33cad48dec7bfb8.zip |
Fix bug: used unnormalized value where normalized required in bt709->srgb and srgb->bt709 functions
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@2393 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r-- | doc/HISTORY | 4 | ||||
-rw-r--r-- | editor/pnmgamma.c | 14 |
2 files changed, 16 insertions, 2 deletions
diff --git a/doc/HISTORY b/doc/HISTORY index 16c68137..b4874ae9 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -15,6 +15,10 @@ not yet BJH Release 10.70.00 Add yuy2topam. Thanks Michael Haardt. + pnmgamma -srgbtobt709, -bt709tosrgb: fix bug; incorrect output + nearly always. Always broken (These options were new in + Netpbm 10.32 (February 2006)). + On Windows, don't leave temporary files around (previous code did so because unlink of an open file fails in Windows; new code deletes temporary files via atexit). Thanks diff --git a/editor/pnmgamma.c b/editor/pnmgamma.c index 9c939eab..b357b0d8 100644 --- a/editor/pnmgamma.c +++ b/editor/pnmgamma.c @@ -10,6 +10,7 @@ ** implied warranty. */ +#include <assert.h> #include <math.h> #include <ctype.h> @@ -308,6 +309,7 @@ buildPowGamma(xelval table[], double const normalized = ((double) i) / maxval; /* Xel sample value normalized to 0..1 */ double const v = pow(normalized, oneOverGamma); + table[i] = MIN((xelval)(v * newMaxval + 0.5), newMaxval); /* denormalize, round and clip */ } @@ -509,11 +511,15 @@ buildBt709ToSrgbGamma(xelval table[], else radiance = pow((normalized + 0.099) / 1.099, gamma709); - if (radiance < linearCutoffSrgb) + assert(radiance <= 1.0); + + if (radiance < linearCutoffSrgb * normalizer) srgb = radiance * linearExpansionSrgb; else srgb = 1.055 * pow(normalized, oneOverGammaSrgb) - 0.055; + assert(srgb <= 1.0); + table[i] = srgb * newMaxval + 0.5; } } @@ -563,11 +569,15 @@ buildSrgbToBt709Gamma(xelval table[], else radiance = pow((normalized + 0.099) / 1.099, gammaSrgb); - if (radiance < linearCutoff709) + assert(radiance <= 1.0); + + if (radiance < linearCutoff709 * normalizer) bt709 = radiance * linearExpansion709; else bt709 = 1.055 * pow(normalized, oneOverGamma709) - 0.055; + assert(bt709 <= 1.0); + table[i] = bt709 * newMaxval + 0.5; } } |