36 #define GIF_TRANSPARENT_COLOR 0x00ffffff
83 for (
i = 0;
i < nb;
i++, pal++)
84 *pal = (0xffu << 24) | bytestream2_get_be24u(&
s->gb);
89 uint32_t *p = (uint32_t *)picture->
data[0];
90 uint32_t *p_end = p + (picture->
linesize[0] /
sizeof(uint32_t)) * picture->
height;
92 for (; p < p_end; p++)
98 const int linesize = picture->
linesize[0] /
sizeof(uint32_t);
99 const uint32_t *py = (uint32_t *)picture->
data[0] + t * linesize;
100 const uint32_t *pr, *pb = py +
h * linesize;
103 for (; py < pb; py += linesize) {
104 px = (uint32_t *)py + l;
107 for (; px < pr; px++)
113 int linesize,
int l,
int t,
int w,
int h)
115 const int y_start = t * linesize;
116 const uint32_t *src_px,
117 *src_py =
src + y_start,
118 *dst_py = dst + y_start;
119 const uint32_t *src_pb = src_py +
h * linesize;
122 for (; src_py < src_pb; src_py += linesize, dst_py += linesize) {
124 dst_px = (uint32_t *)dst_py + l;
126 memcpy(dst_px, src_px,
w *
sizeof(uint32_t));
133 int is_interleaved, has_local_palette, y,
pass, y1, linesize, pal_size, lzwed_len;
134 uint32_t *ptr, *pal, *px, *pr, *ptr1;
142 left = bytestream2_get_le16u(&
s->gb);
143 top = bytestream2_get_le16u(&
s->gb);
144 width = bytestream2_get_le16u(&
s->gb);
145 height = bytestream2_get_le16u(&
s->gb);
146 flags = bytestream2_get_byteu(&
s->gb);
147 is_interleaved =
flags & 0x40;
148 has_local_palette =
flags & 0x80;
149 bits_per_pixel = (
flags & 0x07) + 1;
153 if (has_local_palette) {
154 pal_size = 1 << bits_per_pixel;
160 pal =
s->local_palette;
162 if (!
s->has_global_palette) {
167 pal =
s->global_palette;
171 if (
s->transparent_color_index == -1 &&
s->has_global_palette) {
186 if (left >=
s->screen_width) {
194 if (top >=
s->screen_height) {
198 if (left +
width >
s->screen_width) {
200 pw =
s->screen_width - left;
202 left +
width -
s->screen_width);
206 if (top +
height >
s->screen_height) {
209 top +
height -
s->screen_height);
210 height =
s->screen_height - top;
221 s->gce_prev_disposal =
s->gce_disposal;
224 s->gce_l = left;
s->gce_t = top;
228 if (
s->transparent_color_index >= 0)
229 s->stored_bg_color =
s->trans_color;
231 s->stored_bg_color =
s->bg_color;
247 code_size = bytestream2_get_byteu(&
s->gb);
256 ptr1 = (uint32_t *)
frame->
data[0] + top * linesize + left;
262 if (count !=
width) {
270 for (px = ptr, idx =
s->idx_line; px < pr; px++, idx++) {
271 if (*idx !=
s->transparent_color_index)
275 if (is_interleaved) {
294 ptr = ptr1 + linesize * y1;
309 s->transparent_color_index = -1;
317 int ext_code, ext_len, gce_flags, gce_transparent_index;
324 ext_code = bytestream2_get_byteu(&
s->gb);
325 ext_len = bytestream2_get_byteu(&
s->gb);
327 ff_dlog(
s->avctx,
"ext_code=0x%x len=%d\n", ext_code, ext_len);
339 gce_flags = bytestream2_get_byteu(&
s->gb);
341 gce_transparent_index = bytestream2_get_byteu(&
s->gb);
342 if (gce_flags & 0x01)
343 s->transparent_color_index = gce_transparent_index;
345 s->transparent_color_index = -1;
346 s->gce_disposal = (gce_flags >> 2) & 0x7;
348 ff_dlog(
s->avctx,
"gce_flags=%x tcolor=%d disposal=%d\n",
350 s->transparent_color_index,
s->gce_disposal);
352 if (
s->gce_disposal > 3) {
354 ff_dlog(
s->avctx,
"invalid value in gce_disposal (%d). Using default value of 0.\n", ext_len);
357 ext_len = bytestream2_get_byteu(&
s->gb);
369 ext_len = bytestream2_get_byteu(&
s->gb);
371 ff_dlog(
s->avctx,
"ext_len1=%d\n", ext_len);
380 int background_color_index;
392 s->transparent_color_index = -1;
393 s->screen_width = bytestream2_get_le16u(&
s->gb);
394 s->screen_height = bytestream2_get_le16u(&
s->gb);
396 v = bytestream2_get_byteu(&
s->gb);
397 s->color_resolution = ((v & 0x70) >> 4) + 1;
398 s->has_global_palette = (v & 0x80);
399 s->bits_per_pixel = (v & 0x07) + 1;
400 background_color_index = bytestream2_get_byteu(&
s->gb);
401 n = bytestream2_get_byteu(&
s->gb);
403 s->avctx->sample_aspect_ratio.num = n + 15;
404 s->avctx->sample_aspect_ratio.den = 64;
407 ff_dlog(
s->avctx,
"screen_w=%d screen_h=%d bpp=%d global_palette=%d\n",
408 s->screen_width,
s->screen_height,
s->bits_per_pixel,
409 s->has_global_palette);
411 if (
s->has_global_palette) {
412 s->background_color_index = background_color_index;
413 n = 1 <<
s->bits_per_pixel;
418 s->bg_color =
s->global_palette[
s->background_color_index];
420 s->background_color_index = -1;
428 int code = bytestream2_get_byte(&
s->gb);
474 s->frame->pts = avpkt->
pts;
477 s->frame->pkt_pts = avpkt->
pts;
480 s->frame->pkt_dts = avpkt->
dts;
481 s->frame->pkt_duration = avpkt->
duration;
483 if (avpkt->
size >= 6) {
508 s->frame->key_frame = 1;
511 if (!
s->keyframe_ok) {
520 s->frame->key_frame = 0;
547 {
"trans_color",
"color value (ARGB) that is used instead of transparent color",
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline int bytestream2_tell(GetByteContext *g)
#define flags(name, subs,...)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Identical in function to ff_get_buffer(), except it reuses the existing buffer if available.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
#define GIF_IMAGE_SEPARATOR
static const uint8_t gif89a_sig[6]
#define GCE_DISPOSAL_NONE
#define GIF_EXTENSION_INTRODUCER
static const uint8_t gif87a_sig[6]
#define GIF_GCE_EXT_LABEL
#define GCE_DISPOSAL_BACKGROUND
#define GCE_DISPOSAL_RESTORE
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
#define LIBAVUTIL_VERSION_INT
static av_cold int gif_decode_init(AVCodecContext *avctx)
static const AVOption options[]
static void gif_fill_rect(AVFrame *picture, uint32_t color, int l, int t, int w, int h)
#define GIF_TRANSPARENT_COLOR
static int gif_read_extension(GifState *s)
static const AVClass decoder_class
static av_cold int gif_decode_close(AVCodecContext *avctx)
static void gif_fill(AVFrame *picture, uint32_t color)
static int gif_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static int gif_parse_next_image(GifState *s, AVFrame *frame)
static int gif_read_image(GifState *s, AVFrame *frame)
static void gif_copy_img_rect(const uint32_t *src, uint32_t *dst, int linesize, int l, int t, int w, int h)
static void gif_read_palette(GifState *s, uint32_t *pal, int nb)
static int gif_read_header1(GifState *s)
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FF_DISABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
@ AV_CLASS_CATEGORY_DECODER
av_cold void ff_lzw_decode_close(LZWState **p)
int ff_lzw_decode_init(LZWState *p, int csize, const uint8_t *buf, int buf_size, int mode)
Initialize LZW decoder.
int ff_lzw_decode(LZWState *p, uint8_t *buf, int len)
Decode given number of bytes NOTE: the algorithm here is inspired from the LZW GIF decoder written by...
av_cold void ff_lzw_decode_open(LZWState **p)
int ff_lzw_decode_tail(LZWState *p)
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
#define AV_OPT_FLAG_VIDEO_PARAM
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
This structure stores compressed data.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
int background_color_index
uint32_t global_palette[256]
int trans_color
color value that is used instead of transparent color
int transparent_color_index
uint32_t local_palette[256]