]> git.imager.perl.org - imager.git/blobdiff - gif.c
describe the color model
[imager.git] / gif.c
diff --git a/gif.c b/gif.c
index c1a82c97cc8deabcf63e9d67c120255b26a8c2fa..21882789df95f41f51205c3502837d33c0789c42 100644 (file)
--- a/gif.c
+++ b/gif.c
@@ -529,6 +529,11 @@ i_img **i_readgif_multi_low(GifFileType *GifFile, int *count, int page) {
   i_img **results = NULL;
   int result_alloc = 0;
   int channels;
+  int image_colors = 0;
+  i_color black; /* used to expand the palette if needed */
+
+  for (i = 0; i < MAXCHANNELS; ++i)
+    black.channel[i] = 0;
   
   *count = 0;
 
@@ -610,6 +615,7 @@ i_img **i_readgif_multi_low(GifFileType *GifFile, int *count, int page) {
          
          i_addcolors(img, &col, 1);
        }
+       image_colors = ColorMapSize;
        ++*count;
        if (*count > result_alloc) {
          if (result_alloc == 0) {
@@ -630,6 +636,7 @@ i_img **i_readgif_multi_low(GifFileType *GifFile, int *count, int page) {
        i_tags_addn(&img->tags, "gif_interlace", 0, GifFile->Image.Interlace);
        i_tags_addn(&img->tags, "gif_screen_width", 0, GifFile->SWidth);
        i_tags_addn(&img->tags, "gif_screen_height", 0, GifFile->SHeight);
+       i_tags_addn(&img->tags, "gif_colormap_size", 0, ColorMapSize);
        if (GifFile->SColorMap && !GifFile->Image.ColorMap) {
          i_tags_addn(&img->tags, "gif_background", 0, 
                      GifFile->SBackGroundColor);
@@ -682,7 +689,19 @@ i_img **i_readgif_multi_low(GifFileType *GifFile, int *count, int page) {
                myfree(GifRow);
                return NULL;
              }
-             
+
+             /* range check the scanline if needed */
+             if (image_colors != 256) {
+               int x;
+               for (x = 0; x < Width; ++x) {
+                 while (GifRow[x] >= image_colors) {
+                   /* expand the palette since a palette index is too big */
+                   i_addcolors(img, &black, 1);
+                   ++image_colors;
+                 }
+               }
+             }
+
              i_ppal(img, 0, Width, j, GifRow);
            }
          }
@@ -698,6 +717,18 @@ i_img **i_readgif_multi_low(GifFileType *GifFile, int *count, int page) {
              return NULL;
            }
            
+           /* range check the scanline if needed */
+           if (image_colors != 256) {
+             int x;
+             for (x = 0; x < Width; ++x) {
+               while (GifRow[x] >= image_colors) {
+                 /* expand the palette since a palette index is too big */
+                 i_addcolors(img, &black, 1);
+                 ++image_colors;
+               }
+             }
+           }
+
            i_ppal(img, 0, Width, i, GifRow);
          }
        }