about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2019-03-09 00:24:58 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2019-03-09 00:24:58 +0000
commit5b87908ff16268b9006b3a12ccae173b47a70005 (patch)
tree47a452b1e15aa0f1fe6b1343ee97d593d5978a0d
parent26f9346887720c451d2df5983e398179935d1e95 (diff)
downloadnetpbm-mirror-5b87908ff16268b9006b3a12ccae173b47a70005.tar.gz
netpbm-mirror-5b87908ff16268b9006b3a12ccae173b47a70005.tar.xz
netpbm-mirror-5b87908ff16268b9006b3a12ccae173b47a70005.zip
Release 10.85.04
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@3564 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--converter/other/pamtopng.c99
-rw-r--r--doc/HISTORY11
-rw-r--r--version.mk2
3 files changed, 89 insertions, 23 deletions
diff --git a/converter/other/pamtopng.c b/converter/other/pamtopng.c
index b7f779ca..a3c60f24 100644
--- a/converter/other/pamtopng.c
+++ b/converter/other/pamtopng.c
@@ -346,6 +346,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,
@@ -412,27 +466,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);
     }
 }
 
@@ -553,6 +592,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,
               png_byte *         const pngRow,
@@ -649,6 +702,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);
@@ -661,7 +716,7 @@ writePng(const struct pam * const pamP,
 
     /* no iccp */
 
-    doSbitChunk(pamP, pngxP);
+    doSbitChunk(pamP, pngxP, sBit);
 
     if (cmdline.srgbintentSpec)
         doSrgbChunk(pngxP, cmdline.srgbintent);
@@ -687,6 +742,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/doc/HISTORY b/doc/HISTORY
index b0461f89..c15bf8db 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -4,10 +4,19 @@ Netpbm.
 CHANGE HISTORY 
 --------------
 
+19.03.08 BJH  Release 10.85.04
+
+              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.03.01 BJH  Release 10.85.03
 
               pstopnm: Fix bug: -textalphabits has no effect.  Always broken.
-              (-textalphabits was new in Netpbm 10.53 (December 2010).
+              (-textalphabits was new in Netpbm 10.53 (December 2010)).
 
 19.02.10 BJH  Release 10.85.02
 
diff --git a/version.mk b/version.mk
index 3168f687..a80872eb 100644
--- a/version.mk
+++ b/version.mk
@@ -1,3 +1,3 @@
 NETPBM_MAJOR_RELEASE = 10
 NETPBM_MINOR_RELEASE = 85
-NETPBM_POINT_RELEASE = 3
+NETPBM_POINT_RELEASE = 4