libavcodec/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 //#define DEBUG
25 
26 #include "libavutil/imgutils.h"
27 #include "libavutil/opt.h"
28 #include "avcodec.h"
29 #include "bytestream.h"
30 #include "internal.h"
31 #include "lzw.h"
32 #include "gif.h"
33 
34 /* This value is intentionally set to "transparent white" color.
35  * It is much better to have white background instead of black
36  * when gif image converted to format which not support transparency.
37  */
38 #define GIF_TRANSPARENT_COLOR 0x00ffffff
39 
40 typedef struct GifState {
41  const AVClass *class;
47  uint32_t bg_color;
51  /* intermediate buffer for storing color indices
52  * obtained from lzw-encoded data stream */
55 
56  /* after the frame is displayed, the disposal method is used */
59  /* rectangle describing area that must be disposed */
61  /* depending on disposal method we store either part of the image
62  * drawn on the canvas or background color that
63  * should be used upon disposal */
64  uint32_t * stored_img;
67 
69  /* LZW compatible decoder */
71 
72  /* aux buffers */
73  uint32_t global_palette[256];
74  uint32_t local_palette[256];
75 
77  int keyframe;
79  int trans_color; /**< color value that is used instead of transparent color */
80 } GifState;
81 
82 static void gif_read_palette(GifState *s, uint32_t *pal, int nb)
83 {
84  int i;
85 
86  for (i = 0; i < nb; i++, pal++)
87  *pal = (0xffu << 24) | bytestream2_get_be24u(&s->gb);
88 }
89 
90 static void gif_fill(AVFrame *picture, uint32_t color)
91 {
92  uint32_t *p = (uint32_t *)picture->data[0];
93  uint32_t *p_end = p + (picture->linesize[0] / sizeof(uint32_t)) * picture->height;
94 
95  for (; p < p_end; p++)
96  *p = color;
97 }
98 
99 static void gif_fill_rect(AVFrame *picture, uint32_t color, int l, int t, int w, int h)
100 {
101  const int linesize = picture->linesize[0] / sizeof(uint32_t);
102  const uint32_t *py = (uint32_t *)picture->data[0] + t * linesize;
103  const uint32_t *pr, *pb = py + h * linesize;
104  uint32_t *px;
105 
106  for (; py < pb; py += linesize) {
107  px = (uint32_t *)py + l;
108  pr = px + w;
109 
110  for (; px < pr; px++)
111  *px = color;
112  }
113 }
114 
115 static void gif_copy_img_rect(const uint32_t *src, uint32_t *dst,
116  int linesize, int l, int t, int w, int h)
117 {
118  const int y_start = t * linesize;
119  const uint32_t *src_px,
120  *src_py = src + y_start,
121  *dst_py = dst + y_start;
122  const uint32_t *src_pb = src_py + h * linesize;
123  uint32_t *dst_px;
124 
125  for (; src_py < src_pb; src_py += linesize, dst_py += linesize) {
126  src_px = src_py + l;
127  dst_px = (uint32_t *)dst_py + l;
128 
129  memcpy(dst_px, src_px, w * sizeof(uint32_t));
130  }
131 }
132 
134 {
135  int left, top, width, height, bits_per_pixel, code_size, flags;
136  int is_interleaved, has_local_palette, y, pass, y1, linesize, pal_size;
137  uint32_t *ptr, *pal, *px, *pr, *ptr1;
138  int ret;
139  uint8_t *idx;
140 
141  /* At least 9 bytes of Image Descriptor. */
142  if (bytestream2_get_bytes_left(&s->gb) < 9)
143  return AVERROR_INVALIDDATA;
144 
145  left = bytestream2_get_le16u(&s->gb);
146  top = bytestream2_get_le16u(&s->gb);
147  width = bytestream2_get_le16u(&s->gb);
148  height = bytestream2_get_le16u(&s->gb);
149  flags = bytestream2_get_byteu(&s->gb);
150  is_interleaved = flags & 0x40;
151  has_local_palette = flags & 0x80;
152  bits_per_pixel = (flags & 0x07) + 1;
153 
154  av_dlog(s->avctx, "image x=%d y=%d w=%d h=%d\n", left, top, width, height);
155 
156  if (has_local_palette) {
157  pal_size = 1 << bits_per_pixel;
158 
159  if (bytestream2_get_bytes_left(&s->gb) < pal_size * 3)
160  return AVERROR_INVALIDDATA;
161 
162  gif_read_palette(s, s->local_palette, pal_size);
163  pal = s->local_palette;
164  } else {
165  if (!s->has_global_palette) {
166  av_log(s->avctx, AV_LOG_ERROR, "picture doesn't have either global or local palette.\n");
167  return AVERROR_INVALIDDATA;
168  }
169 
170  pal = s->global_palette;
171  }
172 
173  if (s->keyframe) {
174  if (s->transparent_color_index == -1 && s->has_global_palette) {
175  /* transparency wasn't set before the first frame, fill with background color */
176  gif_fill(frame, s->bg_color);
177  } else {
178  /* otherwise fill with transparent color.
179  * this is necessary since by default picture filled with 0x80808080. */
180  gif_fill(frame, s->trans_color);
181  }
182  }
183 
184  /* verify that all the image is inside the screen dimensions */
185  if (left + width > s->screen_width ||
186  top + height > s->screen_height)
187  return AVERROR_INVALIDDATA;
188  if (width <= 0 || height <= 0)
189  return AVERROR_INVALIDDATA;
190 
191  /* process disposal method */
193  gif_fill_rect(frame, s->stored_bg_color, s->gce_l, s->gce_t, s->gce_w, s->gce_h);
194  } else if (s->gce_prev_disposal == GCE_DISPOSAL_RESTORE) {
195  gif_copy_img_rect(s->stored_img, (uint32_t *)frame->data[0],
196  frame->linesize[0] / sizeof(uint32_t), s->gce_l, s->gce_t, s->gce_w, s->gce_h);
197  }
198 
200 
201  if (s->gce_disposal != GCE_DISPOSAL_NONE) {
202  s->gce_l = left; s->gce_t = top;
203  s->gce_w = width; s->gce_h = height;
204 
206  if (s->transparent_color_index >= 0)
208  else
209  s->stored_bg_color = s->bg_color;
210  } else if (s->gce_disposal == GCE_DISPOSAL_RESTORE) {
211  av_fast_malloc(&s->stored_img, &s->stored_img_size, frame->linesize[0] * frame->height);
212  if (!s->stored_img)
213  return AVERROR(ENOMEM);
214 
215  gif_copy_img_rect((uint32_t *)frame->data[0], s->stored_img,
216  frame->linesize[0] / sizeof(uint32_t), left, top, width, height);
217  }
218  }
219 
220  /* Expect at least 2 bytes: 1 for lzw code size and 1 for block size. */
221  if (bytestream2_get_bytes_left(&s->gb) < 2)
222  return AVERROR_INVALIDDATA;
223 
224  /* now get the image data */
225  code_size = bytestream2_get_byteu(&s->gb);
226  if ((ret = ff_lzw_decode_init(s->lzw, code_size, s->gb.buffer,
228  av_log(s->avctx, AV_LOG_ERROR, "LZW init failed\n");
229  return ret;
230  }
231 
232  /* read all the image */
233  linesize = frame->linesize[0] / sizeof(uint32_t);
234  ptr1 = (uint32_t *)frame->data[0] + top * linesize + left;
235  ptr = ptr1;
236  pass = 0;
237  y1 = 0;
238  for (y = 0; y < height; y++) {
239  if (ff_lzw_decode(s->lzw, s->idx_line, width) == 0)
240  goto decode_tail;
241 
242  pr = ptr + width;
243 
244  for (px = ptr, idx = s->idx_line; px < pr; px++, idx++) {
245  if (*idx != s->transparent_color_index)
246  *px = pal[*idx];
247  }
248 
249  if (is_interleaved) {
250  switch(pass) {
251  default:
252  case 0:
253  case 1:
254  y1 += 8;
255  ptr += linesize * 8;
256  if (y1 >= height) {
257  y1 = pass ? 2 : 4;
258  ptr = ptr1 + linesize * y1;
259  pass++;
260  }
261  break;
262  case 2:
263  y1 += 4;
264  ptr += linesize * 4;
265  if (y1 >= height) {
266  y1 = 1;
267  ptr = ptr1 + linesize;
268  pass++;
269  }
270  break;
271  case 3:
272  y1 += 2;
273  ptr += linesize * 2;
274  break;
275  }
276  } else {
277  ptr += linesize;
278  }
279  }
280 
281  decode_tail:
282  /* read the garbage data until end marker is found */
284 
285  /* Graphic Control Extension's scope is single frame.
286  * Remove its influence. */
287  s->transparent_color_index = -1;
289 
290  return 0;
291 }
292 
294 {
295  int ext_code, ext_len, gce_flags, gce_transparent_index;
296 
297  /* There must be at least 2 bytes:
298  * 1 for extension label and 1 for extension length. */
299  if (bytestream2_get_bytes_left(&s->gb) < 2)
300  return AVERROR_INVALIDDATA;
301 
302  ext_code = bytestream2_get_byteu(&s->gb);
303  ext_len = bytestream2_get_byteu(&s->gb);
304 
305  av_dlog(s->avctx, "ext_code=0x%x len=%d\n", ext_code, ext_len);
306 
307  switch(ext_code) {
308  case GIF_GCE_EXT_LABEL:
309  if (ext_len != 4)
310  goto discard_ext;
311 
312  /* We need at least 5 bytes more: 4 is for extension body
313  * and 1 for next block size. */
314  if (bytestream2_get_bytes_left(&s->gb) < 5)
315  return AVERROR_INVALIDDATA;
316 
317  gce_flags = bytestream2_get_byteu(&s->gb);
318  bytestream2_skipu(&s->gb, 2); // delay during which the frame is shown
319  gce_transparent_index = bytestream2_get_byteu(&s->gb);
320  if (gce_flags & 0x01)
321  s->transparent_color_index = gce_transparent_index;
322  else
323  s->transparent_color_index = -1;
324  s->gce_disposal = (gce_flags >> 2) & 0x7;
325 
326  av_dlog(s->avctx, "gce_flags=%x tcolor=%d disposal=%d\n",
327  gce_flags,
329 
330  if (s->gce_disposal > 3) {
332  av_dlog(s->avctx, "invalid value in gce_disposal (%d). Using default value of 0.\n", ext_len);
333  }
334 
335  ext_len = bytestream2_get_byteu(&s->gb);
336  break;
337  }
338 
339  /* NOTE: many extension blocks can come after */
340  discard_ext:
341  while (ext_len) {
342  /* There must be at least ext_len bytes and 1 for next block size byte. */
343  if (bytestream2_get_bytes_left(&s->gb) < ext_len + 1)
344  return AVERROR_INVALIDDATA;
345 
346  bytestream2_skipu(&s->gb, ext_len);
347  ext_len = bytestream2_get_byteu(&s->gb);
348 
349  av_dlog(s->avctx, "ext_len1=%d\n", ext_len);
350  }
351  return 0;
352 }
353 
355 {
356  uint8_t sig[6];
357  int v, n;
359 
360  if (bytestream2_get_bytes_left(&s->gb) < 13)
361  return AVERROR_INVALIDDATA;
362 
363  /* read gif signature */
364  bytestream2_get_bufferu(&s->gb, sig, 6);
365  if (memcmp(sig, gif87a_sig, 6) &&
366  memcmp(sig, gif89a_sig, 6))
367  return AVERROR_INVALIDDATA;
368 
369  /* read screen header */
370  s->transparent_color_index = -1;
371  s->screen_width = bytestream2_get_le16u(&s->gb);
372  s->screen_height = bytestream2_get_le16u(&s->gb);
373 
374  v = bytestream2_get_byteu(&s->gb);
375  s->color_resolution = ((v & 0x70) >> 4) + 1;
376  s->has_global_palette = (v & 0x80);
377  s->bits_per_pixel = (v & 0x07) + 1;
378  background_color_index = bytestream2_get_byteu(&s->gb);
379  n = bytestream2_get_byteu(&s->gb);
380  if (n) {
381  s->avctx->sample_aspect_ratio.num = n + 15;
382  s->avctx->sample_aspect_ratio.den = 64;
383  }
384 
385  av_dlog(s->avctx, "screen_w=%d screen_h=%d bpp=%d global_palette=%d\n",
387  s->has_global_palette);
388 
389  if (s->has_global_palette) {
391  n = 1 << s->bits_per_pixel;
392  if (bytestream2_get_bytes_left(&s->gb) < n * 3)
393  return AVERROR_INVALIDDATA;
394 
397  } else
398  s->background_color_index = -1;
399 
400  return 0;
401 }
402 
404 {
405  while (bytestream2_get_bytes_left(&s->gb)) {
406  int code = bytestream2_get_byte(&s->gb);
407  int ret;
408 
409  av_log(s->avctx, AV_LOG_DEBUG, "code=%02x '%c'\n", code, code);
410 
411  switch (code) {
412  case GIF_IMAGE_SEPARATOR:
413  return gif_read_image(s, frame);
415  if ((ret = gif_read_extension(s)) < 0)
416  return ret;
417  break;
418  case GIF_TRAILER:
419  /* end of image */
420  return AVERROR_EOF;
421  default:
422  /* erroneous block label */
423  return AVERROR_INVALIDDATA;
424  }
425  }
426  return AVERROR_EOF;
427 }
428 
430 {
431  GifState *s = avctx->priv_data;
432 
433  s->avctx = avctx;
434 
435  avctx->pix_fmt = AV_PIX_FMT_RGB32;
436  s->frame = av_frame_alloc();
437  if (!s->frame)
438  return AVERROR(ENOMEM);
439  ff_lzw_decode_open(&s->lzw);
440  return 0;
441 }
442 
443 static int gif_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
444 {
445  GifState *s = avctx->priv_data;
446  int ret;
447 
448  bytestream2_init(&s->gb, avpkt->data, avpkt->size);
449 
450  s->frame->pts = avpkt->pts;
451  s->frame->pkt_pts = avpkt->pts;
452  s->frame->pkt_dts = avpkt->dts;
454 
455  if (avpkt->size >= 6) {
456  s->keyframe = memcmp(avpkt->data, gif87a_sig, 6) == 0 ||
457  memcmp(avpkt->data, gif89a_sig, 6) == 0;
458  } else {
459  s->keyframe = 0;
460  }
461 
462  if (s->keyframe) {
463  s->keyframe_ok = 0;
464  if ((ret = gif_read_header1(s)) < 0)
465  return ret;
466 
467  if ((ret = av_image_check_size(s->screen_width, s->screen_height, 0, avctx)) < 0)
468  return ret;
470 
471  av_frame_unref(s->frame);
472  if ((ret = ff_get_buffer(avctx, s->frame, 0)) < 0)
473  return ret;
474 
476  if (!s->idx_line)
477  return AVERROR(ENOMEM);
478 
480  s->frame->key_frame = 1;
481  s->keyframe_ok = 1;
482  } else {
483  if (!s->keyframe_ok) {
484  av_log(avctx, AV_LOG_ERROR, "cannot decode frame without keyframe\n");
485  return AVERROR_INVALIDDATA;
486  }
487 
488  if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
489  return ret;
490 
492  s->frame->key_frame = 0;
493  }
494 
495  ret = gif_parse_next_image(s, s->frame);
496  if (ret < 0)
497  return ret;
498 
499  if ((ret = av_frame_ref(data, s->frame)) < 0)
500  return ret;
501  *got_frame = 1;
502 
503  return avpkt->size;
504 }
505 
507 {
508  GifState *s = avctx->priv_data;
509 
511  av_frame_free(&s->frame);
512  av_freep(&s->idx_line);
513  av_freep(&s->stored_img);
514 
515  return 0;
516 }
517 
518 static const AVOption options[] = {
519  { "trans_color", "color value (ARGB) that is used instead of transparent color",
521  {.i64 = GIF_TRANSPARENT_COLOR}, 0, 0xffffffff,
523  { NULL },
524 };
525 
526 static const AVClass decoder_class = {
527  .class_name = "gif decoder",
528  .item_name = av_default_item_name,
529  .option = options,
530  .version = LIBAVUTIL_VERSION_INT,
531  .category = AV_CLASS_CATEGORY_DECODER,
532 };
533 
535  .name = "gif",
536  .type = AVMEDIA_TYPE_VIDEO,
537  .id = AV_CODEC_ID_GIF,
538  .priv_data_size = sizeof(GifState),
542  .capabilities = CODEC_CAP_DR1,
543  .long_name = NULL_IF_CONFIG_SMALL("GIF (Graphics Interchange Format)"),
544  .priv_class = &decoder_class,
545 };
uint32_t global_palette[256]
int transparent_color_index
static int gif_read_image(GifState *s, AVFrame *frame)
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:170
void ff_lzw_decode_tail(LZWState *p)
Definition: lzw.c:95
static int gif_read_extension(GifState *s)
float v
const char * s
Definition: avisynth_c.h:668
#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:76
uint32_t * stored_img
AVOption.
Definition: opt.h:251
av_default_item_name
misc image utilities
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define GCE_DISPOSAL_BACKGROUND
Definition: gif.h:39
int num
numerator
Definition: rational.h:44
void avcodec_set_dimensions(AVCodecContext *s, int width, int height)
uint32_t bg_color
y1
Definition: lab5.m:33
#define GCE_DISPOSAL_NONE
Definition: gif.h:37
static const uint8_t gif87a_sig[6]
Definition: gif.h:34
av_cold void ff_lzw_decode_close(LZWState **p)
Definition: lzw.c:118
#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...
#define pass
Definition: fft.c:335
av_cold void ff_lzw_decode_open(LZWState **p)
Definition: lzw.c:113
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static void gif_fill_rect(AVFrame *picture, uint32_t color, int l, int t, int w, int h)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:130
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
AVCodecContext * avctx
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition: bytestream.h:268
output residual component w
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
void av_frame_set_pkt_duration(AVFrame *frame, int64_t val)
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:55
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
uint8_t
#define av_cold
Definition: attributes.h:78
AVOptions.
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Definition: log.c:77
static void gif_fill(AVFrame *picture, uint32_t color)
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:159
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
uint8_t * data
#define GCE_DISPOSAL_RESTORE
Definition: gif.h:40
const uint8_t * buffer
Definition: bytestream.h:33
static void gif_read_palette(GifState *s, uint32_t *pal, int nb)
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
Definition: bytestream.h:165
#define AVERROR_EOF
End of file.
Definition: error.h:55
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
static void gif_copy_img_rect(const uint32_t *src, uint32_t *dst, int linesize, int l, int t, int w, int h)
Definition: lzw.c:45
AVCodec ff_gif_decoder
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
AVFrame * frame
Spectrum Plot time data
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:149
int gce_prev_disposal
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
const char * name
Name of the codec implementation.
external API header
static int gif_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static av_cold int gif_decode_close(AVCodecContext *avctx)
#define GIF_IMAGE_SEPARATOR
Definition: gif.h:44
struct GifState GifState
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:231
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...
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:144
Definition: lzw.h:38
ret
Definition: avfilter.c:821
uint8_t * idx_line
t
Definition: genspecsines3.m:6
#define GIF_TRANSPARENT_COLOR
#define GIF_EXTENSION_INTRODUCER
Definition: gif.h:43
uint32_t local_palette[256]
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
int trans_color
color value that is used instead of transparent color
static const AVOption options[]
NULL
Definition: eval.c:55
or the Software in violation of any applicable export control laws in any jurisdiction Except as provided by mandatorily applicable UPF has no obligation to provide you with source code to the Software In the event Software contains any source code
static int width
Definition: tests/utils.c:158
AVS_Value src
Definition: avisynth_c.h:523
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:101
#define AV_OPT_FLAG_VIDEO_PARAM
Definition: opt.h:285
GIF format definitions.
main external API structure.
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:375
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:259
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
int background_color_index
GetByteContext gb
BYTE int const BYTE int int int height
Definition: avisynth_c.h:713
Describe the class of an AVClass context structure.
Definition: log.h:50
int has_global_palette
synthesis window for stochastic i
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:282
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:330
#define GIF_TRAILER
Definition: gif.h:42
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:95
int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
Definition: frame.h:164
static int gif_parse_next_image(GifState *s, AVFrame *frame)
static int flags
Definition: cpu.c:23
int av_frame_ref(AVFrame *dst, AVFrame *src)
Setup a new reference to the data described by an given frame.
Definition: frame.c:228
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:87
LZW decoding routines.
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
Definition: frame.h:171
common internal api header.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:162
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:108
static const uint8_t gif89a_sig[6]
Definition: gif.h:35
static av_cold int gif_decode_init(AVCodecContext *avctx)
static const AVClass decoder_class
first frame pointer p_end
Definition: stft_peak.m:15
int den
denominator
Definition: rational.h:45
function y
Definition: D.m:1
int ff_lzw_decode_init(LZWState *p, int csize, const uint8_t *buf, int buf_size, int mode)
Initialize LZW decoder.
Definition: lzw.c:131
LZWState * lzw
else dst[i][x+y *dst_stride[i]]
Definition: vf_mcdeint.c:160
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:139
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
int height
Definition: frame.h:122
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: crystalhd.c:868
int color_resolution
static int gif_read_header1(GifState *s)
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
for(j=16;j >0;--j)
Predicted.
Definition: avutil.h:217