[FFmpeg-cvslog] tiff: fix {2,4}bpp grayscale palettes.

Benoit Fouet git at videolan.org
Fri Sep 5 13:11:29 CEST 2014


ffmpeg | branch: master | Benoit Fouet <benoit.fouet at free.fr> | Fri Sep  5 11:15:13 2014 +0200| [4f10495055edc009ceaff8b5b69c90fd665698e1] | committer: Michael Niedermayer

tiff: fix {2,4}bpp grayscale palettes.

Create a default grayscale palette for 2 or 4 bpp grayscale tiff, if
there is no palette defined.
Fixes ticket #3915

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4f10495055edc009ceaff8b5b69c90fd665698e1
---

 libavcodec/tiff.c |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 1e2d235..0352639 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -653,6 +653,7 @@ static int tiff_unpack_strip(TiffContext *s, AVFrame *p, uint8_t *dst, int strid
 static int init_image(TiffContext *s, ThreadFrame *frame)
 {
     int ret;
+    int create_gray_palette = 0;
 
     switch (s->planar * 1000 + s->bpp * 10 + s->bppcount) {
     case 11:
@@ -662,6 +663,11 @@ static int init_image(TiffContext *s, ThreadFrame *frame)
         }
     case 21:
     case 41:
+        s->avctx->pix_fmt = AV_PIX_FMT_PAL8;
+        if (!s->palette_is_set) {
+            create_gray_palette = 1;
+        }
+        break;
     case 81:
         s->avctx->pix_fmt = s->palette_is_set ? AV_PIX_FMT_PAL8 : AV_PIX_FMT_GRAY8;
         break;
@@ -741,7 +747,15 @@ static int init_image(TiffContext *s, ThreadFrame *frame)
     if ((ret = ff_thread_get_buffer(s->avctx, frame, 0)) < 0)
         return ret;
     if (s->avctx->pix_fmt == AV_PIX_FMT_PAL8) {
-        memcpy(frame->f->data[1], s->palette, sizeof(s->palette));
+        if (!create_gray_palette)
+            memcpy(frame->f->data[1], s->palette, sizeof(s->palette));
+        else {
+            /* make default grayscale pal */
+            int i;
+            uint32_t *pal = (uint32_t *)frame->f->data[1];
+            for (i = 0; i < 1<<s->bpp; i++)
+                pal[i] = 0xFFU << 24 | i * 255 / ((1<<s->bpp) - 1) * 0x010101;
+        }
     }
     return 0;
 }



More information about the ffmpeg-cvslog mailing list