about summary refs log tree commit diff
path: root/converter/ppm/ilbmtoppm.c
diff options
context:
space:
mode:
Diffstat (limited to 'converter/ppm/ilbmtoppm.c')
-rw-r--r--converter/ppm/ilbmtoppm.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/converter/ppm/ilbmtoppm.c b/converter/ppm/ilbmtoppm.c
index c88cdfb2..5001741a 100644
--- a/converter/ppm/ilbmtoppm.c
+++ b/converter/ppm/ilbmtoppm.c
@@ -94,7 +94,6 @@ static short wrotemask = 0;
 static IFF_ID typeid;       /* ID_ILBM, ID_RGBN, ID_RGB8 */
 
 static pixel *transpColor = NULL;       /* transparent color */
-static short transpIndex = -1;
 static char *transpName = NULL;
 
 static bool debug = FALSE;
@@ -776,15 +775,19 @@ check_cmap(bmhd, cmap)
     if( bmhd ) {
         if( bmhd->masking == mskHasTransparentColor || 
             bmhd->masking == mskLasso ) {
-            transpIndex = bmhd->transparentColor;
+            unsigned short const transpIdx = bmhd->transparentColor;
             if( !transpName ) {
                 MALLOCVAR_NOFAIL(transpColor);
-                if( transpIndex >= cmap->ncolors ) {
-                    pm_message("using default transparent color (black)");
-                    PPM_ASSIGN(*transpColor, 0, 0, 0);
+                if (HAS_COLORMAP(cmap)) {
+                    if( transpIdx >= cmap->ncolors ) {
+                        pm_message("using default transparent color (black)");
+                        PPM_ASSIGN(*transpColor, 0, 0, 0);
+                    } else
+                        *transpColor = cmap->color[transpIdx];
+                } else {
+                    /* The color index is just a direct gray level */
+                    PPM_ASSIGN(*transpColor, transpIdx, transpIdx, transpIdx);
                 }
-                else
-                    *transpColor = cmap->color[transpIndex];
             }
         }