about summary refs log tree commit diff
path: root/converter/other/pamtopng.c
diff options
context:
space:
mode:
Diffstat (limited to 'converter/other/pamtopng.c')
-rw-r--r--converter/other/pamtopng.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/converter/other/pamtopng.c b/converter/other/pamtopng.c
index 3a987820..51203df5 100644
--- a/converter/other/pamtopng.c
+++ b/converter/other/pamtopng.c
@@ -30,8 +30,6 @@
 #include <stdlib.h>
 #include <time.h>
 #include <png.h>
-/* setjmp.h needs to be included after png.h */
-#include <setjmp.h>
 
 #include "pm_c_util.h"
 #include "mallocvar.h"
@@ -50,8 +48,8 @@ struct CmdlineInfo {
     const char * inputFileName;
     unsigned int verbose;
     unsigned int interlace;
-    unsigned int transparencySpec;
-    const char * transparency;
+    unsigned int transparentSpec;
+    const char * transparent;
     unsigned int chromaSpec;
     struct pngx_chroma chroma;
     unsigned int gammaSpec;
@@ -84,9 +82,9 @@ parseChromaOpt(const char *         const chromaOpt,
                    &chromaP->gx, &chromaP->gy,
                    &chromaP->bx, &chromaP->by);
 
-    if (count != 6)
-        pm_error("Invalid syntax for the -rgb option value '%s'.  "
-                 "Should be 6 floating point number: "
+    if (count != 8)
+        pm_error("Invalid syntax for the -chroma option value '%s'.  "
+                 "Should be 8 floating point numbers: "
                  "x and y for each of white, red, green, and blue",
                  chromaOpt);
 }
@@ -196,8 +194,8 @@ parseCommandLine (int                  argc,
             &cmdlineP->verbose,        0);
     OPTENT3(0,  "interlace",    OPT_FLAG,       NULL,
             &cmdlineP->interlace,      0);
-    OPTENT3(0,  "transparency", OPT_STRING,     &cmdlineP->transparency,
-            &cmdlineP->transparencySpec, 0);
+    OPTENT3(0,  "transparent", OPT_STRING,      &cmdlineP->transparent,
+            &cmdlineP->transparentSpec, 0);
     OPTENT3(0,  "chroma",       OPT_STRING,     &chroma,
             &cmdlineP->chromaSpec,     0);
     OPTENT3(0,  "gamma",        OPT_FLOAT,      &cmdlineP->gamma,
@@ -220,7 +218,7 @@ parseCommandLine (int                  argc,
     opt.allowNegNum = false;  /* we have no parms that are negative numbers */
 
     /* uses and sets argc, argv, and some of *cmdlineP and others */
-    pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0);
+    pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0);
 
     if (cmdlineP->chromaSpec)
         parseChromaOpt(chroma, &cmdlineP->chroma);
@@ -287,7 +285,17 @@ colorTypeFromInputType(const struct pam * const pamP) {
             pm_error("Input tuple type is GRAYSCALE, "
                      "but number of planes is %u instead of 1",
                      pamP->depth);
-    } else if (strneq(pamP->tuple_type, "BLACKANDWHITE", 3)) {
+     } else if (strneq(pamP->tuple_type, "BLACKANDWHITE_ALPHA", 19)) {
+        if (pamP->depth != 2)
+            pm_error("Input tuple type is BLACKANDWHITE_ALPHA, "
+                     "but number of planes is %u instead of 2",
+                     pamP->depth);
+        if (pamP->maxval != 1)
+            pm_error("Input tuple type is BLACKANDWHITE_ALPHA, "
+                     "but maxval is %u instead of 1", (unsigned)pamP->maxval);
+
+        retval = PNG_COLOR_TYPE_GRAY_ALPHA;
+    } else if (strneq(pamP->tuple_type, "BLACKANDWHITE", 13)) {
         if (pamP->depth != 1)
             pm_error("Input tuple type is BLACKANDWHITE, "
                      "but number of planes is %u instead of 1",
@@ -403,7 +411,7 @@ doTrnsChunk(const struct pam * const pamP,
     else {
         xelval const pngMaxval = pm_bitstomaxval(pngx_bitDepth(pngxP));
         png_color_16 const pngColor = parseAndScaleColor(trans, pngMaxval);
-            /* Transparency color from text format scaled from 16-bit to
+            /* Transparent color from text format scaled from 16-bit to
                maxval.
             */
 
@@ -519,7 +527,6 @@ doZtxtChunkSet(struct pngx * const pngxP,
 
 
 
-
 static void
 doItxtChunkSet(struct pngx * const pngxP,
                const char *  const textFileName) {
@@ -785,7 +792,8 @@ pngBitDepth(unsigned int const pnmBitDepth,
     unsigned int retval;
 
     if ((pngColorType == PNG_COLOR_TYPE_RGB ||
-         pngColorType == PNG_COLOR_TYPE_RGB_ALPHA) &&
+         pngColorType == PNG_COLOR_TYPE_RGB_ALPHA ||
+         pngColorType == PNG_COLOR_TYPE_GRAY_ALPHA) &&
         pnmBitDepth < 8) {
 
         retval = 8;
@@ -805,8 +813,8 @@ addAncillaryChunks(struct pam *       const pamP,
 /*----------------------------------------------------------------------------
   Where requested, add ancillary chunks.
 -----------------------------------------------------------------------------*/
-    if (cmdline.transparencySpec)
-        doTrnsChunk(pamP, pngxP,cmdline.transparency);
+    if (cmdline.transparentSpec)
+        doTrnsChunk(pamP, pngxP,cmdline.transparent);
 
     if (cmdline.chromaSpec)
         doChrmChunk(pngxP, cmdline.chroma);