about summary refs log tree commit diff
path: root/converter/other
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-01-03 19:03:57 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-01-03 19:03:57 +0000
commit2d3c7460263bc5229e5a21d5db1789ba89f8f5a8 (patch)
tree99d7cd8c652d56d4d7f58289d685ec787c0b2049 /converter/other
parent546b704902497903734cdbdac320c753652fc542 (diff)
downloadnetpbm-mirror-2d3c7460263bc5229e5a21d5db1789ba89f8f5a8.tar.gz
netpbm-mirror-2d3c7460263bc5229e5a21d5db1789ba89f8f5a8.tar.xz
netpbm-mirror-2d3c7460263bc5229e5a21d5db1789ba89f8f5a8.zip
Fix incorrect PALM_DIRECT_COLOR_FLAG not valid failure; fix incorrect output with version 3 direct color
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1088 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/other')
-rw-r--r--converter/other/pnmtopalm/palmtopnm.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/converter/other/pnmtopalm/palmtopnm.c b/converter/other/pnmtopalm/palmtopnm.c
index d66af69b..d6164680 100644
--- a/converter/other/pnmtopalm/palmtopnm.c
+++ b/converter/other/pnmtopalm/palmtopnm.c
@@ -322,10 +322,13 @@ interpretHeader(struct palmHeader * const palmHeaderP,
     palmHeaderP->transparentValue = transparentValue;
     palmHeaderP->transparentIndex = transparentIndex;
 
-    if (palmHeaderP->version == 3 && (flags & PALM_DIRECT_COLOR_FLAG))
-        /* There's no directColorInfoType section in a version 3 Palm Bitmap */
-        pm_error("PALM_DIRECT_COLOR_FLAG is not valid for version 3 "
-                 "encoding type.");
+    if (palmHeaderP->version == 3 && ((flags & PALM_DIRECT_COLOR_FLAG) &&
+                                      (pixelFormat != PALM_FORMAT_565)))
+        /* There's no directColorInfoType section in a version 3 Palm Bitmap
+           so we also need PALM_FORMAT_565 for this flag to make sense
+        */
+        pm_error("PALM_DIRECT_COLOR_FLAG is set but pixelFormat is not"
+                 "PALM_FORMAT_565.");
         
     palmHeaderP->directColor = ((flags & PALM_DIRECT_COLOR_FLAG) || 
                                 palmHeaderP->pixelFormat == PALM_FORMAT_565);
@@ -630,11 +633,18 @@ getColorInfo(struct palmHeader        const palmHeader,
         directColorInfoP->pixelFormat.redbits   = 5;
         directColorInfoP->pixelFormat.greenbits = 6;
         directColorInfoP->pixelFormat.bluebits  = 5;
-        /* FIXME Just guessing here ... */
         directColorInfoP->transparentColor = 
-            (((palmHeader.transparentValue >> 11) & 0x1F) << 16) |
-            (((palmHeader.transparentValue >>  5) & 0x3F) <<  8) |
-            (((palmHeader.transparentValue >>  0) & 0x1F) <<  0);
+            /* See convertRowToPnmDirect for this trick
+
+               This will break once maxval isn't always set 255 for
+               directColor
+            */
+            ((((palmHeader.transparentValue >> 11) & 0x1F) * 255 / 0x1F)
+             << 16) |
+            ((((palmHeader.transparentValue >>  5) & 0x3F) * 255 / 0x3F)
+             <<  8) |
+            ((((palmHeader.transparentValue >>  0) & 0x1F) * 255 / 0x1F)
+             <<  0);
     } else if (palmHeader.directColor) {
         *colormapP = NULL;
         *directColorInfoP = directInfoType;