about summary refs log tree commit diff
path: root/converter/ppm
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-11-01 15:27:55 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-11-01 15:27:55 +0000
commitd5934b04729da6f56684bfc9d4ae36ed9774fe98 (patch)
tree06f3f8aa7d7cb24ef906b5ceff6631a7567cd4fe /converter/ppm
parent2080c257ca52e2f910f7dfe54a1c8b605530ca99 (diff)
downloadnetpbm-mirror-d5934b04729da6f56684bfc9d4ae36ed9774fe98.tar.gz
netpbm-mirror-d5934b04729da6f56684bfc9d4ae36ed9774fe98.tar.xz
netpbm-mirror-d5934b04729da6f56684bfc9d4ae36ed9774fe98.zip
Don't crash on ILBM that has a transparent color index, but no color map
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1354 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/ppm')
-rw-r--r--converter/ppm/ilbmtoppm.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/converter/ppm/ilbmtoppm.c b/converter/ppm/ilbmtoppm.c
index 3ce72fa8..a1aae7f4 100644
--- a/converter/ppm/ilbmtoppm.c
+++ b/converter/ppm/ilbmtoppm.c
@@ -848,12 +848,17 @@ transpColor(const BitMapHeader * const bmhdP,
             if (transpName)
                 *transpColorP = ppm_parsecolor(transpName, maxval);
             else {
-                short const transpIndex = bmhdP->transparentColor;
-                if (transpIndex >= cmapP->ncolors) {
-                    pm_message("using default transparent color (black)");
-                    PPM_ASSIGN(*transpColorP, 0, 0, 0);
-                } else
-                    *transpColorP = cmapP->color[transpIndex];
+                unsigned short const transpIdx = bmhdP->transparentColor;
+                if (HAS_COLORMAP(cmapP)) {
+                    if (transpIdx >= cmapP->ncolors) {
+                        pm_message("using default transparent color (black)");
+                        PPM_ASSIGN(*transpColorP, 0, 0, 0);
+                    } else
+                        *transpColorP = cmapP->color[transpIdx];
+                } else {
+                    /* The color index is just a direct gray level */
+                    PPM_ASSIGN(*transpColorP, transpIdx, transpIdx, transpIdx);
+                }
             }
         } else
             transpColorP = NULL;