diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2008-07-27 20:36:04 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2008-07-27 20:36:04 +0000 |
commit | 1f0f4a30e3b27653821ffa4347694619320dce6a (patch) | |
tree | 87de9e1a8ccf7eb190a2b4f641dada571eb9867b | |
parent | 39a3b6d0fd7821eef8ec9392bdbfdb83bb356d1e (diff) | |
download | netpbm-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
-rw-r--r-- | Makefile.version | 2 | ||||
-rw-r--r-- | converter/other/pngtopnm.c | 49 | ||||
-rw-r--r-- | doc/HISTORY | 7 | ||||
-rw-r--r-- | editor/pamperspective.c | 112 |
4 files changed, 108 insertions, 62 deletions
diff --git a/Makefile.version b/Makefile.version index 69da8e6a..51a256c3 100644 --- a/Makefile.version +++ b/Makefile.version @@ -1,3 +1,3 @@ NETPBM_MAJOR_RELEASE = 10 NETPBM_MINOR_RELEASE = 35 -NETPBM_POINT_RELEASE = 47 +NETPBM_POINT_RELEASE = 48 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); } } } diff --git a/doc/HISTORY b/doc/HISTORY index 84bb963d..35f7082e 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -4,6 +4,13 @@ Netpbm. CHANGE HISTORY -------------- +08.07.27 BJH Release 10.35.48 + + pamperspective: change calculation of window height to avoid + buffer overrun. + + pngtopnm: fix gamma correction. + 08.07.13 BJH Release 10.35.47 pngtopnm: fix bug: when background is color, output diff --git a/editor/pamperspective.c b/editor/pamperspective.c index d460ffcf..a655443e 100644 --- a/editor/pamperspective.c +++ b/editor/pamperspective.c @@ -1083,46 +1083,82 @@ static int clean_y (int const y, const struct pam *const outpam) return MIN(MAX(0, y), outpam->height-1); } -static void init_buffer (buffer *const b, const world_data *const world, - const option *const options, - const struct pam *const inpam, - const struct pam *const outpam) -{ - int yul, yur, yll, ylr, y_min; - int i, num_rows; - - yul = outpixel_to_iny (0,0,world); - yur = outpixel_to_iny (outpam->width-1,0,world); - yll = outpixel_to_iny (0,outpam->height-1,world); - ylr = outpixel_to_iny (outpam->width-1,outpam->height-1,world); - - y_min = MIN (MIN (yul,yur), MIN (yll,ylr)); - num_rows = MAX (MAX (diff (yul, yur), - diff (yll, ylr)), - MAX (diff (clean_y(yul,outpam), clean_y(y_min,outpam)), - diff (clean_y(yur,outpam), clean_y(y_min,outpam)))) - + 2; - switch (options->enums[3]) { /* --interpolation */ - case interp_nearest: - break; - case interp_linear: - num_rows += 1; - break; - }; - if (num_rows > inpam->height) - num_rows = inpam->height; - - b->num_rows = num_rows; - MALLOCARRAY_SAFE (b->rows, num_rows); - for (i=0; i<num_rows; i++) { - b->rows[i] = pnm_allocpamrow (inpam); - pnm_readpamrow (inpam, b->rows[i]); - }; - b->last_physical = num_rows-1; - b->last_logical = num_rows-1; - b->inpam = inpam; +static unsigned int +distance(unsigned int const a, + unsigned int const b) { + + return a > b ? a - b : b - a; +} + + + +static int +boundedRow(int const unboundedRow, + const struct pam * const outpamP) { + + return MIN(MAX(0, unboundedRow), outpamP->height-1); +} + + + +static unsigned int +windowHeight(const world_data * const worldP, + const struct pam * const inpamP, + const struct pam * const outpamP, + const option * const optionsP) { + + unsigned int outRow; + unsigned int maxRowWindowHeight; + + maxRowWindowHeight = 1; /* initial value */ + + for (outRow = 0; outRow < outpamP->height; ++outRow) { + unsigned int const leftCol = 0; + unsigned int const rghtCol = outpamP->width - 1; + unsigned int const leftInRow = + boundedRow(outpixel_to_iny(leftCol, outRow, worldP), outpamP); + unsigned int const rghtInRow = + boundedRow(outpixel_to_iny(rghtCol, outRow, worldP), outpamP); + + unsigned int const rowWindowHeight = distance(leftInRow, rghtInRow); + + maxRowWindowHeight = MAX(maxRowWindowHeight, rowWindowHeight); + } + + /* We add 2 for rounding */ + + return maxRowWindowHeight + 2; +} + + + +static void +init_buffer(buffer * const bufferP, + const world_data * const worldP, + const option * const optionsP, + const struct pam * const inpamP, + const struct pam * const outpamP) { + + unsigned int const num_rows = + windowHeight(worldP, inpamP, outpamP, optionsP); + + MALLOCARRAY_SAFE(bufferP->rows, num_rows); + bufferP->num_rows = num_rows; + { + unsigned int row; + for (row = 0; row < num_rows; ++row) { + bufferP->rows[row] = pnm_allocpamrow(inpamP); + pnm_readpamrow(inpamP, bufferP->rows[row]); + } + } + bufferP->last_logical = num_rows-1; + bufferP->last_physical = num_rows-1; + bufferP->inpam = inpamP; } + + + static tuple* read_buffer (buffer *const b, int const logical_y) { int y; |