about summary refs log tree commit diff
path: root/converter/other
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2008-07-27 20:36:04 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2008-07-27 20:36:04 +0000
commit1f0f4a30e3b27653821ffa4347694619320dce6a (patch)
tree87de9e1a8ccf7eb190a2b4f641dada571eb9867b /converter/other
parent39a3b6d0fd7821eef8ec9392bdbfdb83bb356d1e (diff)
downloadnetpbm-mirror-1f0f4a30e3b27653821ffa4347694619320dce6a.tar.gz
netpbm-mirror-1f0f4a30e3b27653821ffa4347694619320dce6a.tar.xz
netpbm-mirror-1f0f4a30e3b27653821ffa4347694619320dce6a.zip
Release 10.35.48
git-svn-id: http://svn.code.sf.net/p/netpbm/code/stable@690 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/other')
-rw-r--r--converter/other/pngtopnm.c49
1 files changed, 26 insertions, 23 deletions
diff --git a/converter/other/pngtopnm.c b/converter/other/pngtopnm.c
index a393f966..c21420a7 100644
--- a/converter/other/pngtopnm.c
+++ b/converter/other/pngtopnm.c
@@ -35,6 +35,7 @@
 #endif                               /*  2 for warnings (1 == error) */
 
 #include <math.h>
+#include <float.h>
 #include <png.h>    /* includes zlib.h and setjmp.h */
 #define VERSION "2.37.4 (5 December 1999) +netpbm"
 
@@ -523,30 +524,32 @@ setupGammaCorrection(png_struct * const png_ptr,
     if (displaygamma == -1.0)
         *totalgammaP = -1.0;
     else {
-        if (info_ptr->valid & PNG_INFO_gAMA) {
-            if (displaygamma != info_ptr->gamma) {
-                png_set_gamma(png_ptr, displaygamma, info_ptr->gamma);
-                *totalgammaP =
-                    (double) info_ptr->gamma * (double) displaygamma;
-                /* in case of gamma-corrections, sBIT's as in the
-                   PNG-file are not valid anymore 
-                */
-                info_ptr->valid &= ~PNG_INFO_sBIT;
-                if (verbose)
-                    pm_message("image gamma is %4.2f, "
-                               "converted for display gamma of %4.2f",
-                               info_ptr->gamma, displaygamma);
-            }
+        float imageGamma;
+        if (info_ptr->valid & PNG_INFO_gAMA)
+            imageGamma = info_ptr->gamma;
+        else {
+            if (verbose)
+                pm_message("PNG doesn't specify image gamma.  Assuming 1.0");
+            imageGamma = 1.0;
+        }
+
+        if (fabs(displaygamma * imageGamma - 1.0) < .01) {
+            *totalgammaP = -1.0;
+            if (verbose)
+                pm_message("image gamma %4.2f matches "
+                           "display gamma %4.2f.  No conversion.",
+                           imageGamma, displaygamma);
         } else {
-            if (displaygamma != info_ptr->gamma) {
-                png_set_gamma (png_ptr, displaygamma, 1.0);
-                *totalgammaP = (double) displaygamma;
-                info_ptr->valid &= ~PNG_INFO_sBIT;
-                if (verbose)
-                    pm_message("image gamma assumed 1.0, "
-                               "converted for display gamma of %4.2f",
-                               displaygamma);
-            }
+            png_set_gamma(png_ptr, displaygamma, imageGamma);
+            *totalgammaP = imageGamma * displaygamma;
+            /* in case of gamma-corrections, sBIT's as in the
+               PNG-file are not valid anymore 
+            */
+            info_ptr->valid &= ~PNG_INFO_sBIT;
+            if (verbose)
+                pm_message("image gamma is %4.2f, "
+                           "converted for display gamma of %4.2f",
+                           imageGamma, displaygamma);
         }
     }
 }