From 2d3c7460263bc5229e5a21d5db1789ba89f8f5a8 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sun, 3 Jan 2010 19:03:57 +0000 Subject: 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 --- converter/other/pnmtopalm/palmtopnm.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'converter/other') 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; -- cgit 1.4.1