about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2015-03-29 02:36:25 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2015-03-29 02:36:25 +0000
commit3f3f46e686186dc9cc812d97960abfd6678b7c86 (patch)
treeeb58ba6ce3cf5ea3892bea2e8aa3da0905cace99
parent6782e15a1a451a11176871198a0d150293f15878 (diff)
downloadnetpbm-mirror-3f3f46e686186dc9cc812d97960abfd6678b7c86.tar.gz
netpbm-mirror-3f3f46e686186dc9cc812d97960abfd6678b7c86.tar.xz
netpbm-mirror-3f3f46e686186dc9cc812d97960abfd6678b7c86.zip
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@2432 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--converter/other/giftopnm.c43
1 files changed, 28 insertions, 15 deletions
diff --git a/converter/other/giftopnm.c b/converter/other/giftopnm.c
index d19620aa..1a42ffca 100644
--- a/converter/other/giftopnm.c
+++ b/converter/other/giftopnm.c
@@ -39,9 +39,6 @@
 
 #define MAX_LZW_BITS  12
 
-#define INTERLACE      0x40
-#define LOCALCOLORMAP  0x80
-
 #if !defined(BYTE_ORDER) || !defined(LITTLE_ENDIAN)
   /* make sure (BYTE_ORDER == LITTLE_ENDIAN) is FALSE */ 
   #define BYTE_ORDER    0
@@ -1711,6 +1708,8 @@ readGifHeader(FILE *             const gifFileP,
    positioned to the beginning of a GIF stream.  Return the info from it
    as *gifScreenP.
 -----------------------------------------------------------------------------*/
+#define GLOBALCOLORMAP  0x80
+
     unsigned char buf[16];
     char version[4];
     unsigned int cmapSize;
@@ -1754,7 +1753,7 @@ readGifHeader(FILE *             const gifFileP,
         pm_message("Colors = %d   Color Resolution = %d",
                    cmapSize, gifScreenP->colorResolution);
     }           
-    if (buf[4] & LOCALCOLORMAP) {    /* Global Colormap */
+    if (buf[4] & GLOBALCOLORMAP) {
         readColorMap(gifFileP, cmapSize, &gifScreenP->colorMap,
                      &gifScreenP->hasGray, &gifScreenP->hasColor);
         if (verbose) {
@@ -1766,6 +1765,8 @@ readGifHeader(FILE *             const gifFileP,
     
     if (gifScreenP->aspectRatio != 0 && gifScreenP->aspectRatio != 49)
         warnUserNotSquare(gifScreenP->aspectRatio);
+
+#undef GLOBALCOLORMAP
 }
 
 
@@ -1838,7 +1839,13 @@ struct GifImageHeader {
 /*----------------------------------------------------------------------------
    Information in the header (first 9 bytes) of a GIF image.
 -----------------------------------------------------------------------------*/
-    bool useGlobalColormap;
+    bool hasLocalColormap;
+        /* The image has its own color map.  Its size is 'localColorMapSize' */
+        /* (If an image does not have its own color map, the image uses the 
+           global color map for the GIF stream)
+        */
+    unsigned int localColorMapSize;
+        /* Meaningful only if 'hasLocalColormap' is true. */
 
     /* Position of the image (max 65535) */
     unsigned int lpos;
@@ -1847,7 +1854,7 @@ struct GifImageHeader {
     /* Dimensions of the image (max 65535) */
     unsigned int cols;
     unsigned int rows;
-    unsigned int localColorMapSize;
+
     bool interlaced;
 };
 
@@ -1864,11 +1871,11 @@ reportImageHeader(struct GifImageHeader const imageHeader) {
         pm_message("  Image left position: %u top position: %u",
                    imageHeader.lpos, imageHeader.tpos);
     
-    if (imageHeader.useGlobalColormap)
-        pm_message("  Uses global colormap");
-    else
+    if (imageHeader.hasLocalColormap)
         pm_message("  Uses local colormap of %u colors",
                    imageHeader.localColorMapSize);
+    else
+        pm_message("  Uses global colormap");
 }
 
 
@@ -1877,6 +1884,9 @@ static void
 readImageHeader(FILE *                  const ifP,
                 struct GifImageHeader * const imageHeaderP) {
 
+#define LOCALCOLORMAP  0x80
+#define INTERLACE      0x40
+
     unsigned char buf[16];
     const char * error;
 
@@ -1884,7 +1894,7 @@ readImageHeader(FILE *                  const ifP,
     if (error)
         pm_error("couldn't read left/top/width/height.  %s", error);
 
-    imageHeaderP->useGlobalColormap = !(buf[8] & LOCALCOLORMAP);
+    imageHeaderP->hasLocalColormap  = !!(buf[8] & LOCALCOLORMAP);
     imageHeaderP->localColorMapSize = 1u << ((buf[8] & 0x07) + 1);
     imageHeaderP->lpos              = LM_to_uint(buf[0], buf[1]);
     imageHeaderP->tpos              = LM_to_uint(buf[2], buf[3]);
@@ -1894,6 +1904,9 @@ readImageHeader(FILE *                  const ifP,
 
     if (verbose)
         reportImageHeader(*imageHeaderP);
+
+#undef INTERLACE
+#undef LOCALCOLORMAP
 }
 
 
@@ -1955,14 +1968,14 @@ convertImage(FILE *           const ifP,
 
     validateWithinGlobalScreen(imageHeader, gifScreen);
 
-    if (imageHeader.useGlobalColormap) {
-        currentColorMapP = &gifScreen.colorMap;
-        hasGray  = gifScreen.hasGray;
-        hasColor = gifScreen.hasColor;
-    } else {
+    if (imageHeader.hasLocalColormap) {
         readColorMap(ifP, imageHeader.localColorMapSize, &localColorMap, 
                      &hasGray, &hasColor);
         currentColorMapP = &localColorMap;
+    } else {
+        currentColorMapP = &gifScreen.colorMap;
+        hasGray  = gifScreen.hasGray;
+        hasColor = gifScreen.hasColor;
     }
 
     if (!skipIt) {