[FFmpeg-devel] [PATCH] Animated GIF Support
Vitaliy Sugrobov
vsugrob at hotmail.com
Fri Oct 12 00:19:37 CEST 2012
>Is transparency still working if you remove this?
Thank you for feedback, Carl. Yes, transparency still working but now it
is handled by other pieces of code.
In contrast to previous version of libavformat/gifdec.c which was
written for single-frame gif images, now we need to handle transparency
with bit more complicated approach: transparent pixels of subsequent
frames must leave underlying pixels of previous frames unaffected.
Following piece of code provides this behavior by iterating through
every pixel of scanline:
for (px = ptr, idx = s->idx_line; px < pr; px++, idx++) {
if (*idx != s->transparent_color_index)
*px = pal[*idx];
}
As you can see, there is explicit check of whether each scanline color
index is not equal to transparent color index prior to writing color
value to the canvas.
The other piece of code handles whether given gif image has transparent
background or must be filled with some color. Before decoding first
frame we check:
if (s->transparent_color_index == -1 && s->has_global_palette) {
/* transparency wasn't set before the first frame, fill with background
color */
gif_fill(&s->picture, s->bg_color);
} else {
/* otherwise fill with transparent color.
* this is necessary since by default picture filled with 0x80808080.
*/
gif_fill(&s->picture, GIF_TRANSPARENT_COLOR);
}
Together these two pieces of code forms full support of transparency for
multiframe gif images.
Thanks to your question i noticed other mistake related to my patch: it
is not valid for HEAD version of ffmpeg source! I missed changes related
to .i64 and .dbl fields in AVOption struct, so here is the new patch in
attachment.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Animated-GIF-Support.patch
Type: text/x-patch
Size: 27964 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121012/b4cc9100/attachment.bin>
More information about the ffmpeg-devel
mailing list