diff options
Diffstat (limited to 'converter')
-rw-r--r-- | converter/other/pngtopnm.c | 49 |
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); } } } |