On 08/09/2014 09:19 AM, Diego Elio Pettenò wrote:
Instead of simulating a grayscale palette, use real grayscale pixels, if no
palette is actually defined.
Signed-off-by: Diego Elio Pettenò <[email protected]>
---
libavcodec/tiff.c | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 2aff45a..ca5ec75 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -246,15 +246,14 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t
*dst, int stride,
static int init_image(TiffContext *s, AVFrame *frame)
{
- int i, ret;
- uint32_t *pal;
+ int ret;
switch (s->bpp * 10 + s->bppcount) {
case 11:
s->avctx->pix_fmt = AV_PIX_FMT_MONOBLACK;
break;
case 81:
- s->avctx->pix_fmt = AV_PIX_FMT_PAL8;
+ s->avctx->pix_fmt = s->palette_is_set ? AV_PIX_FMT_PAL8 :
AV_PIX_FMT_GRAY8;
break;
case 243:
s->avctx->pix_fmt = AV_PIX_FMT_RGB24;
@@ -290,14 +289,7 @@ static int init_image(TiffContext *s, AVFrame *frame)
return ret;
}
if (s->avctx->pix_fmt == AV_PIX_FMT_PAL8) {
- if (s->palette_is_set) {
- memcpy(frame->data[1], s->palette, sizeof(s->palette));
- } else {
- /* make default grayscale pal */
- pal = (uint32_t *) frame->data[1];
- for (i = 0; i < 256; i++)
- pal[i] = i * 0x010101;
- }
+ memcpy(frame->data[1], s->palette, sizeof(s->palette));
}
return 0;
}
This patch is definitely better than the current code, but there are a
few situations that still aren't handled properly.
We should only use the palette in 2 situations, neither of which is
checked for.
1. s->photometric == TIFF_PHOTOMETRIC_PALETTE
This is the normal TIFF6 palette type. If this type is set and
there is no palette, I'm ok with outputting gray8, but there should at
least be a warning. If the palette is set for other types (and component
count doesn't match the type), I think we should either return an error
or assume situation #2.
2. The "Indexed" tag (346) is set to 1
This is from an addendum by Adobe and allows colorspaces other than
RGB in the palette. To actually support this though, we would have to
change how the palette is read, as it can have different numbers of
components and may require conversion to RGB. (See
http://partners.adobe.com/public/developer/en/tiff/TIFFPM6.pdf)
Anyway, the patch is fine as-is, I just wanted to document what still
needs to be done to improve the palette handling.
Thanks,
Justin
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel