about summary refs log tree commit diff
path: root/editor/pnmgamma.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2015-01-22 16:29:25 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2015-01-22 16:29:25 +0000
commitadddf9c7d041d0cdc3e9445ca33cad48dec7bfb8 (patch)
treef74a12cb6f0e45b0e38240aac3223355cb008e28 /editor/pnmgamma.c
parentc0162a145444aca87569ea24e0f6210281595183 (diff)
downloadnetpbm-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
Diffstat (limited to 'editor/pnmgamma.c')
-rw-r--r--editor/pnmgamma.c14
1 files changed, 12 insertions, 2 deletions
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;
     }
 }