Browse code

tiff: set palette in the context when specified in TIFF_PAL tag

Since image initialization was moved after tag parsing, the
palette needs to be specified in the context and then copied
to the allocated image in init_image().

Fixes a regression with TIFF images that have palette data,
trac issue #230, file Test_Flate_8bpp.tif.

Signed-off-by: Diego Biurrun <diego@biurrun.de>

Stefano Sabatini authored on 2011/05/24 08:17:25
Showing 1 changed files
... ...
@@ -41,6 +41,8 @@ typedef struct TiffContext {
41 41
 
42 42
     int width, height;
43 43
     unsigned int bpp, bppcount;
44
+    uint32_t palette[256];
45
+    int palette_is_set;
44 46
     int le;
45 47
     enum TiffCompr compr;
46 48
     int invert;
... ...
@@ -257,11 +259,15 @@ static int init_image(TiffContext *s)
257 257
         av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
258 258
         return ret;
259 259
     }
260
-    if (s->bpp == 8 && s->picture.data[1]){
261
-        /* make default grayscale pal */
262
-        pal = (uint32_t *) s->picture.data[1];
263
-        for (i = 0; i < 256; i++)
264
-            pal[i] = i * 0x010101;
260
+    if (s->avctx->pix_fmt == PIX_FMT_PAL8) {
261
+        if (s->palette_is_set) {
262
+            memcpy(s->picture.data[1], s->palette, sizeof(s->palette));
263
+        } else {
264
+            /* make default grayscale pal */
265
+            pal = (uint32_t *) s->picture.data[1];
266
+            for (i = 0; i < 256; i++)
267
+                pal[i] = i * 0x010101;
268
+        }
265 269
     }
266 270
     return 0;
267 271
 }
... ...
@@ -444,11 +450,7 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *
444 444
         s->fill_order = value - 1;
445 445
         break;
446 446
     case TIFF_PAL:
447
-        if(s->avctx->pix_fmt != PIX_FMT_PAL8){
448
-            av_log(s->avctx, AV_LOG_ERROR, "Palette met but this is not palettized format\n");
449
-            return -1;
450
-        }
451
-        pal = (uint32_t *) s->picture.data[1];
447
+        pal = (uint32_t *) s->palette;
452 448
         off = type_sizes[type];
453 449
         rp = buf;
454 450
         gp = buf + count / 3 * off;
... ...
@@ -460,6 +462,7 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *
460 460
             j |= tget(&bp, type, s->le) >> off;
461 461
             pal[i] = j;
462 462
         }
463
+        s->palette_is_set = 1;
463 464
         break;
464 465
     case TIFF_PLANAR:
465 466
         if(value == 2){