From 8e79ec5cd4cac1229bbb291e555cd32afac3b604 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sun, 10 Mar 2019 04:24:42 +0000 Subject: Release 10.73.26 git-svn-id: http://svn.code.sf.net/p/netpbm/code/stable@3565 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- converter/other/pamtopng.c | 99 ++++++++++++++++++++++++++++++++++++---------- converter/other/pstopnm.c | 4 +- doc/HISTORY | 14 ++++++- version.mk | 2 +- 4 files changed, 94 insertions(+), 25 deletions(-) diff --git a/converter/other/pamtopng.c b/converter/other/pamtopng.c index 528184b2..fdeb6582 100644 --- a/converter/other/pamtopng.c +++ b/converter/other/pamtopng.c @@ -345,6 +345,60 @@ parseAndScaleColor(const char * const colorString, +static png_color_8 +sigBitsFmImgType(unsigned int const pnmBitDepth, + int const pngColorType) { +/*---------------------------------------------------------------------------- + A representation used in PNG of color resolutions in an original image. +-----------------------------------------------------------------------------*/ + png_color_8 retval; + + /* Initial values */ + if (pnmBitDepth < 8) { + switch (pngColorType) { + case PNG_COLOR_TYPE_RGB: + retval.red = pnmBitDepth; + retval.green = pnmBitDepth; + retval.blue = pnmBitDepth; + retval.gray = 0; + retval.alpha = 0; + break; + case PNG_COLOR_TYPE_RGB_ALPHA: + retval.red = pnmBitDepth; + retval.green = pnmBitDepth; + retval.blue = pnmBitDepth; + retval.gray = 0; + retval.alpha = pnmBitDepth; + break; + case PNG_COLOR_TYPE_GRAY: + /* PNG can (so presumably will) use original bit depth */ + retval.red = 0; + retval.green = 0; + retval.blue = 0; + retval.gray = 0; + retval.alpha = 0; + break; + case PNG_COLOR_TYPE_GRAY_ALPHA: + retval.red = 0; + retval.green = 0; + retval.blue = 0; + retval.gray = pnmBitDepth; + retval.alpha = pnmBitDepth; + break; + } + } else { + /* PNG can (so presumably will) use original bit depth */ + retval.red = 0; + retval.green = 0; + retval.blue = 0; + retval.gray = 0; + retval.alpha = 0; + } + return retval; +} + + + static void doTrnsChunk(const struct pam * const pamP, struct pngx * const pngxP, @@ -411,27 +465,12 @@ doGamaChunk(struct pngx * const pngxP, static void doSbitChunk(const struct pam * const pamP, - struct pngx * const pngxP) { - - unsigned int const pnmBitDepth = pm_maxvaltobits(pamP->maxval); + struct pngx * const pngxP, + png_color_8 const sigBits) { - /* create SBIT chunk in case of 1,2,4 bit deep images stored in 8 bit - format PNG files - */ - if (pngx_colorType(pngxP) != PNG_COLOR_TYPE_GRAY && pnmBitDepth < 8) { - png_color_8 sBit; - - if (pngx_colorType(pngxP) == PNG_COLOR_TYPE_RGB || - pngx_colorType(pngxP) == PNG_COLOR_TYPE_RGB_ALPHA) { - sBit.red = sBit.green = sBit.blue = pnmBitDepth; - } else { - sBit.gray = pnmBitDepth; - } - if (pngx_colorType(pngxP) == PNG_COLOR_TYPE_RGB_ALPHA || - pngx_colorType(pngxP) == PNG_COLOR_TYPE_GRAY_ALPHA) { - sBit.alpha = pnmBitDepth; - } - pngx_setSbit(pngxP, sBit); + if (sigBits.red + sigBits.green + sigBits.blue + + sigBits.gray + sigBits.alpha > 0) { + pngx_setSbit(pngxP, sigBits); } } @@ -551,6 +590,20 @@ doTimeChunk(struct pngx * const pngxP, +static void +setShift(struct pngx * const pngxP, + png_color_8 const sigBits) { + + if (sigBits.red + sigBits.green + sigBits.blue + + sigBits.gray + sigBits.alpha > 0) { + + /* Move the 1, 2, 4 bits to most significant bits */ + pngx_setShift(pngxP, sigBits); + } +} + + + static void convertRaster(const struct pam * const pamP, const tuple * const tuplerow, @@ -648,6 +701,8 @@ writePng(const struct pam * const pamP, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + sBit = sigBitsFmImgType(pnmBitDepth, pngColorType); + /* Where requested, add ancillary chunks */ if (cmdline.transparencySpec) doTrnsChunk(pamP, pngxP,cmdline.transparency); @@ -660,7 +715,7 @@ writePng(const struct pam * const pamP, /* no iccp */ - doSbitChunk(pamP, pngxP); + doSbitChunk(pamP, pngxP, sBit); if (cmdline.srgbintentSpec) doSrgbChunk(pngxP, cmdline.srgbintent); @@ -686,6 +741,8 @@ writePng(const struct pam * const pamP, if (cmdline.timeSpec) doTimeChunk(pngxP, cmdline.time); + setShift(pngxP, sBit); + /* Write the ancillary chunks to PNG file */ pngx_writeInfo(pngxP); diff --git a/converter/other/pstopnm.c b/converter/other/pstopnm.c index eb4d9d46..19b1630a 100644 --- a/converter/other/pstopnm.c +++ b/converter/other/pstopnm.c @@ -821,8 +821,8 @@ execGhostscript(int const inputPipeFd, "-dSAFER", "-"); } - execl(ghostscriptProg, arg0, deviceopt, outfileopt, gopt, ropt, "-q", - "-dNOPAUSE", "-dSAFER", "-", NULL); + execl(ghostscriptProg, arg0, deviceopt, outfileopt, gopt, ropt, + textalphabitsopt, "-q", "-dNOPAUSE", "-dSAFER", "-", NULL); pm_error("execl() of Ghostscript ('%s') failed, errno=%d (%s)", ghostscriptProg, errno, strerror(errno)); diff --git a/doc/HISTORY b/doc/HISTORY index bdcf87b6..f5c9ed0e 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -4,7 +4,19 @@ Netpbm. CHANGE HISTORY -------------- -18.02.09 BJH Release 10.73.25 +19.03.10 BJH Release 10.73.26 + + pstopnm: Fix bug: -textalphabits has no effect. Always broken. + (-textalphabits was new in Netpbm 10.53 (December 2010)). + + pamtopng: Fix sBit chunk, bit shift value for 1-, 2-, and 4-bit- + per-sample images. Always broken (Pamtopng was new in Netpbm + 10.71 (June 2015)). + + pamtopng: Fix buffer overrun. Always broken (Pamtopng was new + in Netpbm 10.71 (June 2015)). + +19.02.09 BJH Release 10.73.25 pnmtopng: fix bug: -interlace ignored. Broken in 10.55 (June 2011). diff --git a/version.mk b/version.mk index f1216717..74f51870 100644 --- a/version.mk +++ b/version.mk @@ -1,3 +1,3 @@ NETPBM_MAJOR_RELEASE = 10 NETPBM_MINOR_RELEASE = 73 -NETPBM_POINT_RELEASE = 25 +NETPBM_POINT_RELEASE = 26 -- cgit 1.4.1