about summary refs log tree commit diff
path: root/converter
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2007-08-02 01:52:27 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2007-08-02 01:52:27 +0000
commit66bc60e86eb17b356edc83e8c8326b7eefb5c5e9 (patch)
treec53afcff67c8e11e772fec9505e08cc11365be97 /converter
parent2bc806bc85e98997b0bd60d7608b5d9eddf6c1e1 (diff)
downloadnetpbm-mirror-66bc60e86eb17b356edc83e8c8326b7eefb5c5e9.tar.gz
netpbm-mirror-66bc60e86eb17b356edc83e8c8326b7eefb5c5e9.tar.xz
netpbm-mirror-66bc60e86eb17b356edc83e8c8326b7eefb5c5e9.zip
Release 10.39.03
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@372 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter')
-rw-r--r--converter/other/pnmtops.c57
1 files changed, 45 insertions, 12 deletions
diff --git a/converter/other/pnmtops.c b/converter/other/pnmtops.c
index 85d5d36d..5b12cee9 100644
--- a/converter/other/pnmtops.c
+++ b/converter/other/pnmtops.c
@@ -275,6 +275,7 @@ putitem(void) {
         putchar('\n');
         itemsinline = 0;
     }
+    assert(item >> 8 == 0);
     putchar(hexits[item >> 4]);
     putchar(hexits[item & 15]);
     ++itemsinline;
@@ -954,8 +955,35 @@ 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);
+        else {
+            if (!psFilter)
+                pm_message("You can get up to 12 bits with -psfilter");
+            else
+                pm_message("The Postscript maximum is 12.");
+        }
+    }
+}
+
+
+
+static void
 computeDepth(xelval         const inputMaxval,
              unsigned int   const postscriptLevel, 
+             bool           const psFilter,
              unsigned int * const bitspersampleP,
              unsigned int * const psMaxvalP) {
 /*----------------------------------------------------------------------------
@@ -971,16 +999,21 @@ computeDepth(xelval         const inputMaxval,
         *bitspersampleP = 2;
     else if (bitsRequiredByMaxval <= 4)
         *bitspersampleP = 4;
-    else if (bitsRequiredByMaxval <= 8 || postscriptLevel < 2)
-        *bitspersampleP = 8;
-    else
-        *bitspersampleP = 12;
+    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
+            *bitspersampleP = 8;
+    }
 
-    if (*bitspersampleP < bitsRequiredByMaxval)
-        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);
+    warnUserAboutReducedDepth(*bitspersampleP, bitsRequiredByMaxval,
+                              postscriptLevel, psFilter);
 
     *psMaxvalP = pm_bitstomaxval(*bitspersampleP);
 
@@ -1034,8 +1067,7 @@ convertRowPsFilter(struct pam *     const pamP,
     unsigned int const stragglers =
         (((bitsPerSample * pamP->depth) % 8) * pamP->width) % 8;
         /* Number of bits at the right edge that don't fill out a
-           whole byte
-        */
+           whole byte */
 
     unsigned int col;
     tuple scaledTuple;
@@ -1170,7 +1202,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;