[FFmpeg-devel] [PATCH]Fix tiff grayscale palette
Carl Eugen Hoyos
cehoyos at ag.or.at
Mon Sep 5 22:56:02 CEST 2011
On Monday 05 September 2011 06:25:37 pm Michael Niedermayer wrote:
> On Mon, Sep 05, 2011 at 03:03:13PM +0000, Carl Eugen Hoyos wrote:
> > Michael Niedermayer <michaelni <at> gmx.at> writes:
> > > > +++ b/libavcodec/tiff.c
> > > > @@ -294,8 +294,8 @@ static int init_image(TiffContext *s)
> > > > } else {
> > > > /* make default grayscale pal */
> > > > pal = (uint32_t *) s->picture.data[1];
> > > > - for (i = 0; i < 256; i++)
> > > > - pal[i] = i * 0x010101;
> > > > + for (i = 0; i < 1<<s->bpp; i++)
> > > > + pal[256 - (1<<s->bpp) + i] = i * 255 / ((1<<s->bpp) - 1) *
> > > > 0x010101;
> > >
> > > filling the top only looks a bit strange why is it not
> > > pal[0..(1<<bpp)] ?
> >
> > That doesn't work / shows wrong colours because TIFF_INVERT triggers
> > "src[i] = 255 - src[i]" in the decode function.
> >
> > Should the palette be filled from both ends?
> > Or is there a better solution?
>
> invert (1<<bpp-1) - src[i] instead of 255 - src[i]
New patch attached.
Please comment, Carl Eugen
-------------- next part --------------
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 1997e54..e2c80ef 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -294,8 +294,8 @@ static int init_image(TiffContext *s)
} else {
/* make default grayscale pal */
pal = (uint32_t *) s->picture.data[1];
- for (i = 0; i < 256; i++)
- pal[i] = i * 0x010101;
+ for (i = 0; i < 1<<s->bpp; i++)
+ pal[i] = i * 255 / ((1<<s->bpp) - 1) * 0x010101;
}
}
return 0;
@@ -615,7 +615,7 @@ static int decode_frame(AVCodecContext *avctx,
src = s->picture.data[0];
for(j = 0; j < s->height; j++){
for(i = 0; i < s->picture.linesize[0]; i++)
- src[i] = 255 - src[i];
+ src[i] = (s->avctx->pix_fmt == PIX_FMT_PAL8 ? (1<<s->bpp) - 1 : 255) - src[i];
src += s->picture.linesize[0];
}
}
More information about the ffmpeg-devel
mailing list