about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--converter/other/pnmtops.c61
-rw-r--r--doc/HISTORY2
2 files changed, 40 insertions, 23 deletions
diff --git a/converter/other/pnmtops.c b/converter/other/pnmtops.c
index 5c86a2ab..0348a870 100644
--- a/converter/other/pnmtops.c
+++ b/converter/other/pnmtops.c
@@ -955,8 +955,32 @@ putEnd(bool         const showpage,
 
 
 static void
+warnUserAboutReducedDepth(unsigned int const bitsGot,
+                          unsigned int const bitsWanted,
+                          unsigned int const postscriptLevel,
+                          bool         const psFilter) {
+
+    if (bitsGot < bitsWanted) {
+        pm_message("Postscript will have %u bits of color resolution, "
+                   "though the input has %u bits.",
+                   bitsGot, bitsWanted);
+
+        if (postscriptLevel < 2)
+            pm_message("Postscript level %u has a maximum depth of 8 bits.  "
+                       "You could get up to 12 with -level=2 and -psfilter.",
+                       postscriptLevel);
+
+        if (postscriptLevel >= 2 && !psFilter)
+            pm_message("You can get up to 12 bits with -psfilter");
+    }
+}
+
+
+
+static void
 computeDepth(xelval         const inputMaxval,
              unsigned int   const postscriptLevel, 
+             bool           const psFilter,
              unsigned int * const bitspersampleP,
              unsigned int * const psMaxvalP) {
 /*----------------------------------------------------------------------------
@@ -972,30 +996,22 @@ computeDepth(xelval         const inputMaxval,
         *bitspersampleP = 2;
     else if (bitsRequiredByMaxval <= 4)
         *bitspersampleP = 4;
-    else        
-        *bitspersampleP = 8;
-
-    /* There is supposedly a 12 bits per pixel Postscript format, but
-       what?  We produce a raster that is composed of bytes, each
-       coded as a pair of hexadecimal characters and representing 8,
-       4, 2, or 1 pixels.  We also have the RLE format, where some of
-       those bytes are run lengths.
-    */
-
-    if (*bitspersampleP < bitsRequiredByMaxval) {
-        if (bitsRequiredByMaxval <= 12 && postscriptLevel >= 2)
-            pm_message("Maxval of input requires %u bit samples for full "
-                       "resolution, and Postscript level %u is capable "
-                       "of representing that many, but this program "
-                       "doesn't know how.  So we are using %u",
-                       bitsRequiredByMaxval, postscriptLevel, *bitspersampleP);
+    else {
+        /* Post script level 2 defines a format with 12 bits per sample,
+           but I don't know the details of that format (both RLE and
+           non-RLE variations) and existing native raster generation code
+           simply can't handle bps > 8.  But the built-in filters know
+           how to do 12 bps.
+        */
+        if (postscriptLevel >= 2 && psFilter)
+            *bitspersampleP = 12;
         else
-            pm_message("Maxval of input requires %u bit samples for full "
-                       "resolution, but we are using the Postscript level %u "
-                       "maximum of %u",
-                       bitsRequiredByMaxval, postscriptLevel, *bitspersampleP);
+            *bitspersampleP = 8;
     }
 
+    warnUserAboutReducedDepth(*bitspersampleP, bitsRequiredByMaxval,
+                              postscriptLevel, psFilter);
+
     *psMaxvalP = pm_bitstomaxval(*bitspersampleP);
 
     if (verbose)
@@ -1183,7 +1199,8 @@ convertPage(FILE * const ifP,
     if (color)
         pm_message("generating color Postscript program.");
 
-    computeDepth(inpam.maxval, postscriptLevel, &bitspersample, &psMaxval);
+    computeDepth(inpam.maxval, postscriptLevel, psFilter,
+                 &bitspersample, &psMaxval);
     {
         unsigned int const realBitsPerLine = inpam.width * bitspersample;
         unsigned int const paddedBitsPerLine = ((realBitsPerLine + 7) / 8) * 8;
diff --git a/doc/HISTORY b/doc/HISTORY
index 2d45b757..b6e43cde 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -8,7 +8,7 @@ not yet  BJH  Release 10.40.00
 
               pnmtops: fix crash when program attempts to write 12 bits per
               sample Postscript.  It doesn't really know how to do that, so
-              now it just writes 8.
+              now it just writes 8 unless you do -psfilter.
 
               pamfunc: Add -andmask, -ormask, -xormask, -not,
               -shiftleft, -shiftright.