[FFmpeg-devel] [PATCH]Write transparent colour to pal8 gif

Michael Niedermayer michaelni at gmx.at
Wed Dec 7 15:16:55 CET 2011


On Wed, Dec 07, 2011 at 11:57:02AM +0100, Carl Eugen Hoyos wrote:
> On Wednesday 07 December 2011 03:40:31 am Michael Niedermayer wrote:
> > On Wed, Dec 07, 2011 at 02:22:38AM +0100, Carl Eugen Hoyos wrote:
> > > Hi!
> > >
> > > Attached allows to write transparent gif if the original file had a
> > > palette as in ticket 715.
> > > Tested with:
> > > ffmpeg -i 11.png -vcodec gif -f image2 out.gif
> > >
> > > Please comment, Carl Eugen
> > >
> > >  gif.c |   16 +++++++++++++++-
> > >  1 file changed, 15 insertions(+), 1 deletion(-)
> > > 20cc35d190a3b3e94fda434ac5aef2f5111e8ed7  patchgifalpha.diff
> > > diff --git a/libavcodec/gif.c b/libavcodec/gif.c
> > > index 8736f0f..655f2c7 100644
> > > --- a/libavcodec/gif.c
> > > +++ b/libavcodec/gif.c
> > > @@ -62,7 +62,7 @@ static int gif_image_write_header(AVCodecContext
> > > *avctx, uint8_t **bytestream, uint32_t *palette) {
> > >      int i;
> > > -    unsigned int v;
> > > +    unsigned int v, use_transparency = 0, alpha = 0;
> > >
> > >      bytestream_put_buffer(bytestream, "GIF", 3);
> > >      bytestream_put_buffer(bytestream, "89a", 3);
> > > @@ -77,8 +77,22 @@ static int gif_image_write_header(AVCodecContext
> > > *avctx, for(i=0;i<256;i++) {
> > >          v = palette[i];
> > >          bytestream_put_be24(bytestream, v);
> > > +        if ((v >> 24) < 0xFF - use_transparency) {
> > > +            use_transparency = 0xFF - (v >> 24);
> > 
> > id write
> > smallest_alpha = 0xFF;
> > 
> > if(smallest_alpha > v >> 24){
> >     smallest_alpha = v >> 24
> >     ...
> > }
> > 
> > if(smallest_alpha< ?){
> 
> Thank you, new patch attached.
> 
> Please comment, Carl Eugen

LGTM if tested

[....]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Avoid a single point of failure, be that a person or equipment.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20111207/517e4227/attachment.asc>


More information about the ffmpeg-devel mailing list