FFmpeg  4.0
gifdec.c
Go to the documentation of this file.
1 /*
2  * GIF decoder
3  * Copyright (c) 2003 Fabrice Bellard
4  * Copyright (c) 2006 Baptiste Coudurier
5  * Copyright (c) 2012 Vitaliy E Sugrobov
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include "libavutil/imgutils.h"
25 #include "libavutil/opt.h"
26 #include "avcodec.h"
27 #include "bytestream.h"
28 #include "internal.h"
29 #include "lzw.h"
30 #include "gif.h"
31 
32 /* This value is intentionally set to "transparent white" color.
33  * It is much better to have white background instead of black
34  * when gif image converted to format which not support transparency.
35  */
36 #define GIF_TRANSPARENT_COLOR 0x00ffffff
37 
38 typedef struct GifState {
39  const AVClass *class;
45  uint32_t bg_color;
49  /* intermediate buffer for storing color indices
50  * obtained from lzw-encoded data stream */
53 
54  /* after the frame is displayed, the disposal method is used */
57  /* rectangle describing area that must be disposed */
59  /* depending on disposal method we store either part of the image
60  * drawn on the canvas or background color that
61  * should be used upon disposal */
62  uint32_t * stored_img;
65 
68 
69  /* aux buffers */
70  uint32_t global_palette[256];
71  uint32_t local_palette[256];
72 
74  int keyframe;
76  int trans_color; /**< color value that is used instead of transparent color */
77 } GifState;
78 
79 static void gif_read_palette(GifState *s, uint32_t *pal, int nb)
80 {
81  int i;
82 
83  for (i = 0; i < nb; i++, pal++)
84  *pal = (0xffu << 24) | bytestream2_get_be24u(&s->gb);
85 }
86 
87 static void gif_fill(AVFrame *picture, uint32_t color)
88 {
89  uint32_t *p = (uint32_t *)picture->data[0];
90  uint32_t *p_end = p + (picture->linesize[0] / sizeof(uint32_t)) * picture->height;
91 
92  for (; p < p_end; p++)
93  *p = color;
94 }
95 
96 static void gif_fill_rect(AVFrame *picture, uint32_t color, int l, int t, int w, int h)
97 {
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;
101  uint32_t *px;
102 
103  for (; py < pb; py += linesize) {
104  px = (uint32_t *)py + l;
105  pr = px + w;
106 
107  for (; px < pr; px++)
108  *px = color;
109  }
110 }
111 
112 static void gif_copy_img_rect(const uint32_t *src, uint32_t *dst,
113  int linesize, int l, int t, int w, int h)
114 {
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;
120  uint32_t *dst_px;
121 
122  for (; src_py < src_pb; src_py += linesize, dst_py += linesize) {
123  src_px = src_py + l;
124  dst_px = (uint32_t *)dst_py + l;
125 
126  memcpy(dst_px, src_px, w * sizeof(uint32_t));
127  }
128 }
129 
131 {
132  int left, top, width, height, bits_per_pixel, code_size, flags, pw;
133  int is_interleaved, has_local_palette, y, pass, y1, linesize, pal_size, lzwed_len;
134  uint32_t *ptr, *pal, *px, *pr, *ptr1;
135  int ret;
136  uint8_t *idx;
137 
138  /* At least 9 bytes of Image Descriptor. */
139  if (bytestream2_get_bytes_left(&s->gb) < 9)
140  return AVERROR_INVALIDDATA;
141 
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;
150 
151  ff_dlog(s->avctx, "image x=%d y=%d w=%d h=%d\n", left, top, width, height);
152 
153  if (has_local_palette) {
154  pal_size = 1 << bits_per_pixel;
155 
156  if (bytestream2_get_bytes_left(&s->gb) < pal_size * 3)
157  return AVERROR_INVALIDDATA;
158 
159  gif_read_palette(s, s->local_palette, pal_size);
160  pal = s->local_palette;
161  } else {
162  if (!s->has_global_palette) {
163  av_log(s->avctx, AV_LOG_ERROR, "picture doesn't have either global or local palette.\n");
164  return AVERROR_INVALIDDATA;
165  }
166 
167  pal = s->global_palette;
168  }
169 
170  if (s->keyframe) {
171  if (s->transparent_color_index == -1 && s->has_global_palette) {
172  /* transparency wasn't set before the first frame, fill with background color */
173  gif_fill(frame, s->bg_color);
174  } else {
175  /* otherwise fill with transparent color.
176  * this is necessary since by default picture filled with 0x80808080. */
177  gif_fill(frame, s->trans_color);
178  }
179  }
180 
181  /* verify that all the image is inside the screen dimensions */
182  if (!width || width > s->screen_width || left >= s->screen_width) {
183  av_log(s->avctx, AV_LOG_ERROR, "Invalid image width.\n");
184  return AVERROR_INVALIDDATA;
185  }
186  if (!height || height > s->screen_height || top >= s->screen_height) {
187  av_log(s->avctx, AV_LOG_ERROR, "Invalid image height.\n");
188  return AVERROR_INVALIDDATA;
189  }
190  if (left + width > s->screen_width) {
191  /* width must be kept around to avoid lzw vs line desync */
192  pw = s->screen_width - left;
193  av_log(s->avctx, AV_LOG_WARNING, "Image too wide by %d, truncating.\n",
194  left + width - s->screen_width);
195  } else {
196  pw = width;
197  }
198  if (top + height > s->screen_height) {
199  /* we don't care about the extra invisible lines */
200  av_log(s->avctx, AV_LOG_WARNING, "Image too high by %d, truncating.\n",
201  top + height - s->screen_height);
202  height = s->screen_height - top;
203  }
204 
205  /* process disposal method */
207  gif_fill_rect(frame, s->stored_bg_color, s->gce_l, s->gce_t, s->gce_w, s->gce_h);
208  } else if (s->gce_prev_disposal == GCE_DISPOSAL_RESTORE) {
209  gif_copy_img_rect(s->stored_img, (uint32_t *)frame->data[0],
210  frame->linesize[0] / sizeof(uint32_t), s->gce_l, s->gce_t, s->gce_w, s->gce_h);
211  }
212 
214 
215  if (s->gce_disposal != GCE_DISPOSAL_NONE) {
216  s->gce_l = left; s->gce_t = top;
217  s->gce_w = pw; s->gce_h = height;
218 
220  if (s->transparent_color_index >= 0)
222  else
223  s->stored_bg_color = s->bg_color;
224  } else if (s->gce_disposal == GCE_DISPOSAL_RESTORE) {
225  av_fast_malloc(&s->stored_img, &s->stored_img_size, frame->linesize[0] * frame->height);
226  if (!s->stored_img)
227  return AVERROR(ENOMEM);
228 
229  gif_copy_img_rect((uint32_t *)frame->data[0], s->stored_img,
230  frame->linesize[0] / sizeof(uint32_t), left, top, pw, height);
231  }
232  }
233 
234  /* Expect at least 2 bytes: 1 for lzw code size and 1 for block size. */
235  if (bytestream2_get_bytes_left(&s->gb) < 2)
236  return AVERROR_INVALIDDATA;
237 
238  /* now get the image data */
239  code_size = bytestream2_get_byteu(&s->gb);
240  if ((ret = ff_lzw_decode_init(s->lzw, code_size, s->gb.buffer,
242  av_log(s->avctx, AV_LOG_ERROR, "LZW init failed\n");
243  return ret;
244  }
245 
246  /* read all the image */
247  linesize = frame->linesize[0] / sizeof(uint32_t);
248  ptr1 = (uint32_t *)frame->data[0] + top * linesize + left;
249  ptr = ptr1;
250  pass = 0;
251  y1 = 0;
252  for (y = 0; y < height; y++) {
253  int count = ff_lzw_decode(s->lzw, s->idx_line, width);
254  if (count != width) {
255  if (count)
256  av_log(s->avctx, AV_LOG_ERROR, "LZW decode failed\n");
257  goto decode_tail;
258  }
259 
260  pr = ptr + pw;
261 
262  for (px = ptr, idx = s->idx_line; px < pr; px++, idx++) {
263  if (*idx != s->transparent_color_index)
264  *px = pal[*idx];
265  }
266 
267  if (is_interleaved) {
268  switch(pass) {
269  default:
270  case 0:
271  case 1:
272  y1 += 8;
273  ptr += linesize * 8;
274  break;
275  case 2:
276  y1 += 4;
277  ptr += linesize * 4;
278  break;
279  case 3:
280  y1 += 2;
281  ptr += linesize * 2;
282  break;
283  }
284  while (y1 >= height) {
285  y1 = 4 >> pass;
286  ptr = ptr1 + linesize * y1;
287  pass++;
288  }
289  } else {
290  ptr += linesize;
291  }
292  }
293 
294  decode_tail:
295  /* read the garbage data until end marker is found */
296  lzwed_len = ff_lzw_decode_tail(s->lzw);
297  bytestream2_skipu(&s->gb, lzwed_len);
298 
299  /* Graphic Control Extension's scope is single frame.
300  * Remove its influence. */
301  s->transparent_color_index = -1;
303 
304  return 0;
305 }
306 
308 {
309  int ext_code, ext_len, gce_flags, gce_transparent_index;
310 
311  /* There must be at least 2 bytes:
312  * 1 for extension label and 1 for extension length. */
313  if (bytestream2_get_bytes_left(&s->gb) < 2)
314  return AVERROR_INVALIDDATA;
315 
316  ext_code = bytestream2_get_byteu(&s->gb);
317  ext_len = bytestream2_get_byteu(&s->gb);
318 
319  ff_dlog(s->avctx, "ext_code=0x%x len=%d\n", ext_code, ext_len);
320 
321  switch(ext_code) {
322  case GIF_GCE_EXT_LABEL:
323  if (ext_len != 4)
324  goto discard_ext;
325 
326  /* We need at least 5 bytes more: 4 is for extension body
327  * and 1 for next block size. */
328  if (bytestream2_get_bytes_left(&s->gb) < 5)
329  return AVERROR_INVALIDDATA;
330 
331  gce_flags = bytestream2_get_byteu(&s->gb);
332  bytestream2_skipu(&s->gb, 2); // delay during which the frame is shown
333  gce_transparent_index = bytestream2_get_byteu(&s->gb);
334  if (gce_flags & 0x01)
335  s->transparent_color_index = gce_transparent_index;
336  else
337  s->transparent_color_index = -1;
338  s->gce_disposal = (gce_flags >> 2) & 0x7;
339 
340  ff_dlog(s->avctx, "gce_flags=%x tcolor=%d disposal=%d\n",
341  gce_flags,
343 
344  if (s->gce_disposal > 3) {
346  ff_dlog(s->avctx, "invalid value in gce_disposal (%d). Using default value of 0.\n", ext_len);
347  }
348 
349  ext_len = bytestream2_get_byteu(&s->gb);
350  break;
351  }
352 
353  /* NOTE: many extension blocks can come after */
354  discard_ext:
355  while (ext_len) {
356  /* There must be at least ext_len bytes and 1 for next block size byte. */
357  if (bytestream2_get_bytes_left(&s->gb) < ext_len + 1)
358  return AVERROR_INVALIDDATA;
359 
360  bytestream2_skipu(&s->gb, ext_len);
361  ext_len = bytestream2_get_byteu(&s->gb);
362 
363  ff_dlog(s->avctx, "ext_len1=%d\n", ext_len);
364  }
365  return 0;
366 }
367 
369 {
370  uint8_t sig[6];
371  int v, n;
373 
374  if (bytestream2_get_bytes_left(&s->gb) < 13)
375  return AVERROR_INVALIDDATA;
376 
377  /* read gif signature */
378  bytestream2_get_bufferu(&s->gb, sig, 6);
379  if (memcmp(sig, gif87a_sig, 6) &&
380  memcmp(sig, gif89a_sig, 6))
381  return AVERROR_INVALIDDATA;
382 
383  /* read screen header */
384  s->transparent_color_index = -1;
385  s->screen_width = bytestream2_get_le16u(&s->gb);
386  s->screen_height = bytestream2_get_le16u(&s->gb);
387 
388  v = bytestream2_get_byteu(&s->gb);
389  s->color_resolution = ((v & 0x70) >> 4) + 1;
390  s->has_global_palette = (v & 0x80);
391  s->bits_per_pixel = (v & 0x07) + 1;
392  background_color_index = bytestream2_get_byteu(&s->gb);
393  n = bytestream2_get_byteu(&s->gb);
394  if (n) {
395  s->avctx->sample_aspect_ratio.num = n + 15;
396  s->avctx->sample_aspect_ratio.den = 64;
397  }
398 
399  ff_dlog(s->avctx, "screen_w=%d screen_h=%d bpp=%d global_palette=%d\n",
401  s->has_global_palette);
402 
403  if (s->has_global_palette) {
405  n = 1 << s->bits_per_pixel;
406  if (bytestream2_get_bytes_left(&s->gb) < n * 3)
407  return AVERROR_INVALIDDATA;
408 
411  } else
412  s->background_color_index = -1;
413 
414  return 0;
415 }
416 
418 {
419  while (bytestream2_get_bytes_left(&s->gb) > 0) {
420  int code = bytestream2_get_byte(&s->gb);
421  int ret;
422 
423  av_log(s->avctx, AV_LOG_DEBUG, "code=%02x '%c'\n", code, code);
424 
425  switch (code) {
426  case GIF_IMAGE_SEPARATOR:
427  return gif_read_image(s, frame);
429  if ((ret = gif_read_extension(s)) < 0)
430  return ret;
431  break;
432  case GIF_TRAILER:
433  /* end of image */
434  return AVERROR_EOF;
435  default:
436  /* erroneous block label */
437  return AVERROR_INVALIDDATA;
438  }
439  }
440  return AVERROR_EOF;
441 }
442 
444 {
445  GifState *s = avctx->priv_data;
446 
447  s->avctx = avctx;
448 
449  avctx->pix_fmt = AV_PIX_FMT_RGB32;
450  s->frame = av_frame_alloc();
451  if (!s->frame)
452  return AVERROR(ENOMEM);
453  ff_lzw_decode_open(&s->lzw);
454  return 0;
455 }
456 
457 static int gif_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
458 {
459  GifState *s = avctx->priv_data;
460  int ret;
461 
462  bytestream2_init(&s->gb, avpkt->data, avpkt->size);
463 
464  s->frame->pts = avpkt->pts;
465 #if FF_API_PKT_PTS
467  s->frame->pkt_pts = avpkt->pts;
469 #endif
470  s->frame->pkt_dts = avpkt->dts;
471  s->frame->pkt_duration = avpkt->duration;
472 
473  if (avpkt->size >= 6) {
474  s->keyframe = memcmp(avpkt->data, gif87a_sig, 6) == 0 ||
475  memcmp(avpkt->data, gif89a_sig, 6) == 0;
476  } else {
477  s->keyframe = 0;
478  }
479 
480  if (s->keyframe) {
481  s->keyframe_ok = 0;
483  if ((ret = gif_read_header1(s)) < 0)
484  return ret;
485 
486  if ((ret = ff_set_dimensions(avctx, s->screen_width, s->screen_height)) < 0)
487  return ret;
488 
489  av_frame_unref(s->frame);
490  if ((ret = ff_get_buffer(avctx, s->frame, 0)) < 0)
491  return ret;
492 
494  if (!s->idx_line)
495  return AVERROR(ENOMEM);
496 
498  s->frame->key_frame = 1;
499  s->keyframe_ok = 1;
500  } else {
501  if (!s->keyframe_ok) {
502  av_log(avctx, AV_LOG_ERROR, "cannot decode frame without keyframe\n");
503  return AVERROR_INVALIDDATA;
504  }
505 
506  if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
507  return ret;
508 
510  s->frame->key_frame = 0;
511  }
512 
513  ret = gif_parse_next_image(s, s->frame);
514  if (ret < 0)
515  return ret;
516 
517  if ((ret = av_frame_ref(data, s->frame)) < 0)
518  return ret;
519  *got_frame = 1;
520 
521  return bytestream2_tell(&s->gb);
522 }
523 
525 {
526  GifState *s = avctx->priv_data;
527 
529  av_frame_free(&s->frame);
530  av_freep(&s->idx_line);
531  av_freep(&s->stored_img);
532 
533  return 0;
534 }
535 
536 static const AVOption options[] = {
537  { "trans_color", "color value (ARGB) that is used instead of transparent color",
539  {.i64 = GIF_TRANSPARENT_COLOR}, 0, 0xffffffff,
541  { NULL },
542 };
543 
544 static const AVClass decoder_class = {
545  .class_name = "gif decoder",
546  .item_name = av_default_item_name,
547  .option = options,
548  .version = LIBAVUTIL_VERSION_INT,
549  .category = AV_CLASS_CATEGORY_DECODER,
550 };
551 
553  .name = "gif",
554  .long_name = NULL_IF_CONFIG_SMALL("GIF (Graphics Interchange Format)"),
555  .type = AVMEDIA_TYPE_VIDEO,
556  .id = AV_CODEC_ID_GIF,
557  .priv_data_size = sizeof(GifState),
559  .close = gif_decode_close,
561  .capabilities = AV_CODEC_CAP_DR1,
562  .priv_class = &decoder_class,
563 };
uint32_t global_palette[256]
Definition: gifdec.c:70
int transparent_color_index
Definition: gifdec.c:47
static int gif_read_image(GifState *s, AVFrame *frame)
Definition: gifdec.c:130
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...
Definition: lzw.c:166
#define NULL
Definition: coverity.c:32
static int gif_read_extension(GifState *s)
Definition: gifdec.c:307
int keyframe
Definition: gifdec.c:74
const char * s
Definition: avisynth_c.h:768
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
This structure describes decoded (raw) audio or video data.
Definition: frame.h:218
uint32_t * stored_img
Definition: gifdec.c:62
AVOption.
Definition: opt.h:246
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
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.
Definition: utils.c:104
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
int stored_img_size
Definition: gifdec.c:63
#define GCE_DISPOSAL_BACKGROUND
Definition: gif.h:39
int num
Numerator.
Definition: rational.h:59
int size
Definition: avcodec.h:1431
uint32_t bg_color
Definition: gifdec.c:45
#define GCE_DISPOSAL_NONE
Definition: gif.h:37
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
static const uint8_t gif87a_sig[6]
Definition: gif.h:34
av_cold void ff_lzw_decode_close(LZWState **p)
Definition: lzw.c:115
#define GIF_GCE_EXT_LABEL
Definition: gif.h:45
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
Definition: avcodec.h:1896
av_cold void ff_lzw_decode_open(LZWState **p)
Definition: lzw.c:110
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1727
static void gif_fill_rect(AVFrame *picture, uint32_t color, int l, int t, int w, int h)
Definition: gifdec.c:96
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:133
#define src
Definition: vp8dsp.c:254
AVCodecContext * avctx
Definition: gifdec.c:73
int ff_lzw_decode_tail(LZWState *p)
Definition: lzw.c:96
AVCodec.
Definition: avcodec.h:3408
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:42
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition: bytestream.h:273
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame)
Identical in function to av_frame_make_writable(), except it uses ff_get_buffer() to allocate the buf...
Definition: decode.c:1938
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
uint8_t
#define av_cold
Definition: attributes.h:82
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:189
AVOptions.
int screen_height
Definition: gifdec.c:42
int keyframe_ok
Definition: gifdec.c:75
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1448
static void gif_fill(AVFrame *picture, uint32_t color)
Definition: gifdec.c:87
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:441
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:311
const char data[16]
Definition: mxf.c:90
#define height
int stored_bg_color
Definition: gifdec.c:64
uint8_t * data
Definition: avcodec.h:1430
#define GCE_DISPOSAL_RESTORE
Definition: gif.h:40
const uint8_t * buffer
Definition: bytestream.h:34
static int flags
Definition: log.c:55
static void gif_read_palette(GifState *s, uint32_t *pal, int nb)
Definition: gifdec.c:79
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
Definition: bytestream.h:170
#define ff_dlog(a,...)
#define AVERROR_EOF
End of file.
Definition: error.h:55
#define av_log(a,...)
int screen_width
Definition: gifdec.c:41
static void gif_copy_img_rect(const uint32_t *src, uint32_t *dst, int linesize, int l, int t, int w, int h)
Definition: gifdec.c:112
Definition: lzw.c:46
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
AVCodec ff_gif_decoder
Definition: gifdec.c:552
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
AVFrame * frame
Definition: gifdec.c:40
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:154
int idx_line_size
Definition: gifdec.c:52
int gce_prev_disposal
Definition: gifdec.c:55
uint16_t width
Definition: gdv.c:47
const char * name
Name of the codec implementation.
Definition: avcodec.h:3415
static int gif_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: gifdec.c:457
static av_cold int gif_decode_close(AVCodecContext *avctx)
Definition: gifdec.c:524
#define pass
Definition: fft_template.c:593
int gce_disposal
Definition: gifdec.c:56
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
Definition: mem.c:488
#define GIF_IMAGE_SEPARATOR
Definition: gif.h:44
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:301
Definition: lzw.h:38
uint8_t w
Definition: llviddspenc.c:38
uint8_t * idx_line
Definition: gifdec.c:51
int gce_t
Definition: gifdec.c:58
#define GIF_TRANSPARENT_COLOR
Definition: gifdec.c:36
int n
Definition: avisynth_c.h:684
#define GIF_EXTENSION_INTRODUCER
Definition: gif.h:43
int gce_l
Definition: gifdec.c:58
uint32_t local_palette[256]
Definition: gifdec.c:71
int trans_color
color value that is used instead of transparent color
Definition: gifdec.c:76
static const AVOption options[]
Definition: gifdec.c:536
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:188
Libavcodec external API header.
int64_t pkt_duration
duration of the corresponding packet, expressed in AVStream->time_base units, 0 if unknown...
Definition: frame.h:498
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:249
#define AV_OPT_FLAG_VIDEO_PARAM
Definition: opt.h:279
GIF format definitions.
main external API structure.
Definition: avcodec.h:1518
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:342
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1891
int background_color_index
Definition: gifdec.c:46
GetByteContext gb
Definition: gifdec.c:66
int gce_w
Definition: gifdec.c:58
Describe the class of an AVClass context structure.
Definition: log.h:67
int has_global_palette
Definition: gifdec.c:43
int gce_h
Definition: gifdec.c:58
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:277
#define GIF_TRAILER
Definition: gif.h:42
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:551
static int gif_parse_next_image(GifState *s, AVFrame *frame)
Definition: gifdec.c:417
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:232
attribute_deprecated int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
Definition: frame.h:319
LZW decoding routines.
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
Definition: frame.h:327
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:84
common internal api header.
static const uint8_t gif89a_sig[6]
Definition: gif.h:35
static av_cold int gif_decode_init(AVCodecContext *avctx)
Definition: gifdec.c:443
static const AVClass decoder_class
Definition: gifdec.c:544
int den
Denominator.
Definition: rational.h:60
int ff_lzw_decode_init(LZWState *p, int csize, const uint8_t *buf, int buf_size, int mode)
Initialize LZW decoder.
Definition: lzw.c:128
void * priv_data
Definition: avcodec.h:1545
LZWState * lzw
Definition: gifdec.c:67
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:85
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:296
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1429
int height
Definition: frame.h:276
#define av_freep(p)
void INT64 INT64 count
Definition: avisynth_c.h:690
int color_resolution
Definition: gifdec.c:48
static int gif_read_header1(GifState *s)
Definition: gifdec.c:368
int bits_per_pixel
Definition: gifdec.c:44
This structure stores compressed data.
Definition: avcodec.h:1407
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:959
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1423
for(j=16;j >0;--j)
Predicted.
Definition: avutil.h:275