FFmpeg  4.4.9
flicvideo.c
Go to the documentation of this file.
1 /*
2  * FLI/FLC Animation Video Decoder
3  * Copyright (C) 2003, 2004 The FFmpeg project
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * Autodesk Animator FLI/FLC Video Decoder
25  * by Mike Melanson (melanson@pcisys.net)
26  * for more information on the .fli/.flc file format and all of its many
27  * variations, visit:
28  * http://www.compuphase.com/flic.htm
29  *
30  * This decoder outputs PAL8/RGB555/RGB565/BGR24. To use this decoder, be
31  * sure that your demuxer sends the FLI file header to the decoder via
32  * the extradata chunk in AVCodecContext. The chunk should be 128 bytes
33  * large. The only exception is for FLI files from the game "Magic Carpet",
34  * in which the header is only 12 bytes.
35  */
36 
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 
41 #include "libavutil/intreadwrite.h"
42 #include "avcodec.h"
43 #include "bytestream.h"
44 #include "internal.h"
45 #include "mathops.h"
46 
47 #define FLI_256_COLOR 4
48 #define FLI_DELTA 7
49 #define FLI_COLOR 11
50 #define FLI_LC 12
51 #define FLI_BLACK 13
52 #define FLI_BRUN 15
53 #define FLI_COPY 16
54 #define FLI_MINI 18
55 #define FLI_DTA_BRUN 25
56 #define FLI_DTA_COPY 26
57 #define FLI_DTA_LC 27
58 
59 #define FLI_TYPE_CODE (0xAF11)
60 #define FLC_FLX_TYPE_CODE (0xAF12)
61 #define FLC_DTA_TYPE_CODE (0xAF44) /* Marks an "Extended FLC" comes from Dave's Targa Animator (DTA) */
62 #define FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE (0xAF13)
63 
64 static inline int check_pixel_ptr(ptrdiff_t ptr, int n,
65  ptrdiff_t limit, int direction)
66 {
67  if (( direction && ptr + n > limit) ||
68  (!direction && ptr + n < limit))
69  return AVERROR_INVALIDDATA;
70  return 0;
71 }
72 
73 #define CHECK_PIXEL_PTR(n) \
74 { \
75  ret = check_pixel_ptr(pixel_ptr, (n), pixel_limit, direction); \
76  if (ret < 0) \
77  return ret; \
78 }
79 
80 #define CHECK_Y_PTR() \
81 { \
82  ret = check_pixel_ptr(y_ptr, 0, pixel_limit, direction); \
83  if (ret < 0) \
84  return ret; \
85 }
86 
87 typedef struct FlicDecodeContext {
90 
91  unsigned int palette[256];
93  int fli_type; /* either 0xAF11 or 0xAF12, affects palette resolution */
95 
97 {
98  FlicDecodeContext *s = avctx->priv_data;
99  unsigned char *fli_header = (unsigned char *)avctx->extradata;
100  int depth;
101 
102  if (avctx->extradata_size != 0 &&
103  avctx->extradata_size != 12 &&
104  avctx->extradata_size != 128 &&
105  avctx->extradata_size != 256 &&
106  avctx->extradata_size != 904 &&
107  avctx->extradata_size != 1024) {
108  av_log(avctx, AV_LOG_ERROR, "Unexpected extradata size %d\n", avctx->extradata_size);
109  return AVERROR_INVALIDDATA;
110  }
111 
112  s->avctx = avctx;
113 
114  if (s->avctx->extradata_size == 12) {
115  /* special case for magic carpet FLIs */
117  depth = 8;
118  } else if (avctx->extradata_size == 1024) {
119  uint8_t *ptr = avctx->extradata;
120  int i;
121 
122  for (i = 0; i < 256; i++) {
123  s->palette[i] = AV_RL32(ptr);
124  ptr += 4;
125  }
126  depth = 8;
127  /* FLI in MOV, see e.g. FFmpeg trac issue #626 */
128  } else if (avctx->extradata_size == 0 ||
129  avctx->extradata_size == 256 ||
130  /* see FFmpeg ticket #1234 */
131  avctx->extradata_size == 904) {
132  s->fli_type = FLI_TYPE_CODE;
133  depth = 8;
134  } else {
135  s->fli_type = AV_RL16(&fli_header[4]);
136  depth = AV_RL16(&fli_header[12]);
137  }
138 
139  if (depth == 0) {
140  depth = 8; /* Some FLC generators set depth to zero, when they mean 8Bpp. Fix up here */
141  }
142 
143  if ((s->fli_type == FLC_FLX_TYPE_CODE) && (depth == 16)) {
144  depth = 15; /* Original Autodesk FLX's say the depth is 16Bpp when it is really 15Bpp */
145  }
146 
147  switch (depth) {
148  case 8 : avctx->pix_fmt = AV_PIX_FMT_PAL8; break;
149  case 15 : avctx->pix_fmt = AV_PIX_FMT_RGB555; break;
150  case 16 : avctx->pix_fmt = AV_PIX_FMT_RGB565; break;
151  case 24 : avctx->pix_fmt = AV_PIX_FMT_BGR24; break;
152  default :
153  av_log(avctx, AV_LOG_ERROR, "Unknown FLC/FLX depth of %d Bpp is unsupported.\n",depth);
154  return AVERROR_INVALIDDATA;
155  }
156 
157  s->frame = av_frame_alloc();
158  if (!s->frame)
159  return AVERROR(ENOMEM);
160 
161  s->new_palette = 0;
162 
163  return 0;
164 }
165 
167  void *data, int *got_frame,
168  const uint8_t *buf, int buf_size)
169 {
170  FlicDecodeContext *s = avctx->priv_data;
171 
172  GetByteContext g2;
173  ptrdiff_t pixel_ptr;
174  int palette_ptr;
175  unsigned char palette_idx1;
176  unsigned char palette_idx2;
177 
178  unsigned int frame_size;
179  int num_chunks;
180 
181  unsigned int chunk_size;
182  int chunk_type;
183 
184  int i, j, ret, direction;
185 
186  int color_packets;
187  int color_changes;
188  int color_shift;
189  unsigned char r, g, b;
190 
191  int lines;
192  int compressed_lines;
193  int starting_line;
194  int line_packets;
195  ptrdiff_t y_ptr;
196  int byte_run;
197  int pixel_skip;
198  int pixel_countdown;
199  unsigned char *pixels;
200  ptrdiff_t pixel_limit;
201 
202  bytestream2_init(&g2, buf, buf_size);
203 
204  if ((ret = ff_reget_buffer(avctx, s->frame, 0)) < 0)
205  return ret;
206 
207  direction = s->frame->linesize[0] > 0;
208  pixels = s->frame->data[0];
209  pixel_limit = s->avctx->height * s->frame->linesize[0];
210  if (buf_size < 16 || buf_size > INT_MAX - (3 * 256 + AV_INPUT_BUFFER_PADDING_SIZE))
211  return AVERROR_INVALIDDATA;
212  frame_size = bytestream2_get_le32(&g2);
213  if (frame_size > buf_size)
214  frame_size = buf_size;
215  bytestream2_skip(&g2, 2); /* skip the magic number */
216  num_chunks = bytestream2_get_le16(&g2);
217  bytestream2_skip(&g2, 8); /* skip padding */
218 
219  if (frame_size < 16)
220  return AVERROR_INVALIDDATA;
221 
222  frame_size -= 16;
223 
224  /* iterate through the chunks */
225  while ((frame_size >= 6) && (num_chunks > 0) &&
226  bytestream2_get_bytes_left(&g2) >= 4) {
227  int stream_ptr_after_chunk;
228  chunk_size = bytestream2_get_le32(&g2);
229  if (chunk_size > frame_size) {
230  av_log(avctx, AV_LOG_WARNING,
231  "Invalid chunk_size = %u > frame_size = %u\n", chunk_size, frame_size);
232  chunk_size = frame_size;
233  }
234  stream_ptr_after_chunk = bytestream2_tell(&g2) - 4 + chunk_size;
235 
236  chunk_type = bytestream2_get_le16(&g2);
237 
238  switch (chunk_type) {
239  case FLI_256_COLOR:
240  case FLI_COLOR:
241  /* check special case: If this file is from the Magic Carpet
242  * game and uses 6-bit colors even though it reports 256-color
243  * chunks in a 0xAF12-type file (fli_type is set to 0xAF13 during
244  * initialization) */
245  if ((chunk_type == FLI_256_COLOR) && (s->fli_type != FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE))
246  color_shift = 0;
247  else
248  color_shift = 2;
249  /* set up the palette */
250  color_packets = bytestream2_get_le16(&g2);
251  palette_ptr = 0;
252  for (i = 0; i < color_packets; i++) {
253  /* first byte is how many colors to skip */
254  palette_ptr += bytestream2_get_byte(&g2);
255 
256  /* next byte indicates how many entries to change */
257  color_changes = bytestream2_get_byte(&g2);
258 
259  /* if there are 0 color changes, there are actually 256 */
260  if (color_changes == 0)
261  color_changes = 256;
262 
263  if (bytestream2_tell(&g2) + color_changes * 3 > stream_ptr_after_chunk)
264  break;
265 
266  for (j = 0; j < color_changes; j++) {
267  unsigned int entry;
268 
269  /* wrap around, for good measure */
270  if ((unsigned)palette_ptr >= 256)
271  palette_ptr = 0;
272 
273  r = bytestream2_get_byte(&g2) << color_shift;
274  g = bytestream2_get_byte(&g2) << color_shift;
275  b = bytestream2_get_byte(&g2) << color_shift;
276  entry = 0xFFU << 24 | r << 16 | g << 8 | b;
277  if (color_shift == 2)
278  entry |= entry >> 6 & 0x30303;
279  if (s->palette[palette_ptr] != entry)
280  s->new_palette = 1;
281  s->palette[palette_ptr++] = entry;
282  }
283  }
284  break;
285 
286  case FLI_DELTA:
287  y_ptr = 0;
288  compressed_lines = bytestream2_get_le16(&g2);
289  while (compressed_lines > 0) {
290  if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk)
291  break;
292  CHECK_Y_PTR()
293  line_packets = sign_extend(bytestream2_get_le16(&g2), 16);
294  if ((line_packets & 0xC000) == 0xC000) {
295  // line skip opcode
296  line_packets = -line_packets;
297  if (line_packets > s->avctx->height)
298  return AVERROR_INVALIDDATA;
299  y_ptr += line_packets * s->frame->linesize[0];
300  } else if ((line_packets & 0xC000) == 0x4000) {
301  av_log(avctx, AV_LOG_ERROR, "Undefined opcode (%x) in DELTA_FLI\n", line_packets);
302  } else if ((line_packets & 0xC000) == 0x8000) {
303  // "last byte" opcode
304  pixel_ptr= y_ptr + s->frame->linesize[0] - 1;
305  CHECK_PIXEL_PTR(0);
306  pixels[pixel_ptr] = line_packets & 0xff;
307  } else {
308  compressed_lines--;
309  pixel_ptr = y_ptr;
310  CHECK_PIXEL_PTR(0);
311  pixel_countdown = s->avctx->width;
312  for (i = 0; i < line_packets; i++) {
313  if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk)
314  break;
315  /* account for the skip bytes */
316  pixel_skip = bytestream2_get_byte(&g2);
317  pixel_ptr += pixel_skip;
318  pixel_countdown -= pixel_skip;
319  byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
320  if (byte_run < 0) {
321  byte_run = -byte_run;
322  palette_idx1 = bytestream2_get_byte(&g2);
323  palette_idx2 = bytestream2_get_byte(&g2);
324  CHECK_PIXEL_PTR(byte_run * 2);
325  for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
326  pixels[pixel_ptr++] = palette_idx1;
327  pixels[pixel_ptr++] = palette_idx2;
328  }
329  } else {
330  CHECK_PIXEL_PTR(byte_run * 2);
331  if (bytestream2_tell(&g2) + byte_run * 2 > stream_ptr_after_chunk)
332  break;
333  for (j = 0; j < byte_run * 2; j++, pixel_countdown--) {
334  pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
335  }
336  }
337  }
338 
339  y_ptr += s->frame->linesize[0];
340  }
341  }
342  break;
343 
344  case FLI_LC:
345  /* line compressed */
346  starting_line = bytestream2_get_le16(&g2);
347  if (starting_line >= s->avctx->height)
348  return AVERROR_INVALIDDATA;
349  y_ptr = 0;
350  y_ptr += starting_line * s->frame->linesize[0];
351 
352  compressed_lines = bytestream2_get_le16(&g2);
353  while (compressed_lines > 0) {
354  pixel_ptr = y_ptr;
355  CHECK_PIXEL_PTR(0);
356  pixel_countdown = s->avctx->width;
357  if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
358  break;
359  line_packets = bytestream2_get_byte(&g2);
360  if (line_packets > 0) {
361  for (i = 0; i < line_packets; i++) {
362  /* account for the skip bytes */
363  if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
364  break;
365  pixel_skip = bytestream2_get_byte(&g2);
366  pixel_ptr += pixel_skip;
367  pixel_countdown -= pixel_skip;
368  byte_run = sign_extend(bytestream2_get_byte(&g2),8);
369  if (byte_run > 0) {
370  CHECK_PIXEL_PTR(byte_run);
371  if (bytestream2_tell(&g2) + byte_run > stream_ptr_after_chunk)
372  break;
373  for (j = 0; j < byte_run; j++, pixel_countdown--) {
374  pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
375  }
376  } else if (byte_run < 0) {
377  byte_run = -byte_run;
378  palette_idx1 = bytestream2_get_byte(&g2);
379  CHECK_PIXEL_PTR(byte_run);
380  for (j = 0; j < byte_run; j++, pixel_countdown--) {
381  pixels[pixel_ptr++] = palette_idx1;
382  }
383  }
384  }
385  }
386 
387  y_ptr += s->frame->linesize[0];
388  compressed_lines--;
389  }
390  break;
391 
392  case FLI_BLACK:
393  /* set the whole frame to color 0 (which is usually black) */
394  for (int y = 0; y < s->avctx->height; y++)
395  memset(pixels + y * s->frame->linesize[0], 0, s->avctx->width);
396  break;
397 
398  case FLI_BRUN:
399  /* Byte run compression: This chunk type only occurs in the first
400  * FLI frame and it will update the entire frame. */
401  y_ptr = 0;
402  for (lines = 0; lines < s->avctx->height; lines++) {
403  pixel_ptr = y_ptr;
404  /* disregard the line packets; instead, iterate through all
405  * pixels on a row */
406  bytestream2_skip(&g2, 1);
407  pixel_countdown = s->avctx->width;
408  while (pixel_countdown > 0) {
409  if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
410  break;
411  byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
412  if (!byte_run) {
413  av_log(avctx, AV_LOG_ERROR, "Invalid byte run value.\n");
414  return AVERROR_INVALIDDATA;
415  }
416 
417  if (byte_run > 0) {
418  palette_idx1 = bytestream2_get_byte(&g2);
419  CHECK_PIXEL_PTR(byte_run);
420  for (j = 0; j < byte_run; j++) {
421  pixels[pixel_ptr++] = palette_idx1;
422  pixel_countdown--;
423  if (pixel_countdown < 0)
424  av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) at line %d\n",
425  pixel_countdown, lines);
426  }
427  } else { /* copy bytes if byte_run < 0 */
428  byte_run = -byte_run;
429  CHECK_PIXEL_PTR(byte_run);
430  if (bytestream2_tell(&g2) + byte_run > stream_ptr_after_chunk)
431  break;
432  for (j = 0; j < byte_run; j++) {
433  pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
434  pixel_countdown--;
435  if (pixel_countdown < 0)
436  av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) at line %d\n",
437  pixel_countdown, lines);
438  }
439  }
440  }
441 
442  y_ptr += s->frame->linesize[0];
443  }
444  break;
445 
446  case FLI_COPY:
447  /* copy the chunk (uncompressed frame) */
448  if (chunk_size - 6 != FFALIGN(s->avctx->width, 4) * s->avctx->height) {
449  av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \
450  "has incorrect size, skipping chunk\n", chunk_size - 6);
451  bytestream2_skip(&g2, chunk_size - 6);
452  } else {
453  for (y_ptr = 0; check_pixel_ptr(y_ptr, 0, pixel_limit, direction) == 0;
454  y_ptr += s->frame->linesize[0]) {
455  bytestream2_get_buffer(&g2, &pixels[y_ptr],
456  s->avctx->width);
457  if (s->avctx->width & 3)
458  bytestream2_skip(&g2, 4 - (s->avctx->width & 3));
459  }
460  }
461  break;
462 
463  case FLI_MINI:
464  /* some sort of a thumbnail? disregard this chunk... */
465  break;
466 
467  default:
468  av_log(avctx, AV_LOG_ERROR, "Unrecognized chunk type: %d\n", chunk_type);
469  break;
470  }
471 
472  if (stream_ptr_after_chunk - bytestream2_tell(&g2) >= 0) {
473  bytestream2_skip(&g2, stream_ptr_after_chunk - bytestream2_tell(&g2));
474  } else {
475  av_log(avctx, AV_LOG_ERROR, "Chunk overread\n");
476  break;
477  }
478 
479  frame_size -= chunk_size;
480  num_chunks--;
481  }
482 
483  /* by the end of the chunk, the stream ptr should equal the frame
484  * size (minus 1 or 2, possibly); if it doesn't, issue a warning */
485  if (bytestream2_get_bytes_left(&g2) > 2)
486  av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \
487  "and final chunk ptr = %d\n", buf_size,
488  buf_size - bytestream2_get_bytes_left(&g2));
489 
490  /* make the palette available on the way out */
491  memcpy(s->frame->data[1], s->palette, AVPALETTE_SIZE);
492  if (s->new_palette) {
493  s->frame->palette_has_changed = 1;
494  s->new_palette = 0;
495  }
496 
497  if ((ret = av_frame_ref(data, s->frame)) < 0)
498  return ret;
499 
500  *got_frame = 1;
501 
502  return buf_size;
503 }
504 
506  void *data, int *got_frame,
507  const uint8_t *buf, int buf_size)
508 {
509  /* Note, the only difference between the 15Bpp and 16Bpp */
510  /* Format is the pixel format, the packets are processed the same. */
511  FlicDecodeContext *s = avctx->priv_data;
512 
513  GetByteContext g2;
514  ptrdiff_t pixel_ptr;
515  unsigned char palette_idx1;
516 
517  unsigned int frame_size;
518  int num_chunks;
519 
520  unsigned int chunk_size;
521  int chunk_type;
522 
523  int i, j, ret, direction;
524 
525  int lines;
526  int compressed_lines;
527  int line_packets;
528  ptrdiff_t y_ptr;
529  int byte_run;
530  int pixel_skip;
531  int pixel_countdown;
532  unsigned char *pixels;
533  int pixel;
534  ptrdiff_t pixel_limit;
535 
536  bytestream2_init(&g2, buf, buf_size);
537 
538  if ((ret = ff_reget_buffer(avctx, s->frame, 0)) < 0)
539  return ret;
540 
541  direction = s->frame->linesize[0] > 0;
542  pixels = s->frame->data[0];
543  pixel_limit = s->avctx->height * s->frame->linesize[0];
544 
545  frame_size = bytestream2_get_le32(&g2);
546  bytestream2_skip(&g2, 2); /* skip the magic number */
547  num_chunks = bytestream2_get_le16(&g2);
548  bytestream2_skip(&g2, 8); /* skip padding */
549  if (frame_size > buf_size)
550  frame_size = buf_size;
551 
552  if (frame_size < 16)
553  return AVERROR_INVALIDDATA;
554  frame_size -= 16;
555 
556  /* iterate through the chunks */
557  while ((frame_size > 0) && (num_chunks > 0) &&
558  bytestream2_get_bytes_left(&g2) >= 4) {
559  int stream_ptr_after_chunk;
560  chunk_size = bytestream2_get_le32(&g2);
561  if (chunk_size > frame_size) {
562  av_log(avctx, AV_LOG_WARNING,
563  "Invalid chunk_size = %u > frame_size = %u\n", chunk_size, frame_size);
564  chunk_size = frame_size;
565  }
566  stream_ptr_after_chunk = bytestream2_tell(&g2) - 4 + chunk_size;
567 
568  chunk_type = bytestream2_get_le16(&g2);
569 
570 
571  switch (chunk_type) {
572  case FLI_256_COLOR:
573  case FLI_COLOR:
574  /* For some reason, it seems that non-palettized flics do
575  * include one of these chunks in their first frame.
576  * Why I do not know, it seems rather extraneous. */
577  ff_dlog(avctx,
578  "Unexpected Palette chunk %d in non-palettized FLC\n",
579  chunk_type);
580  bytestream2_skip(&g2, chunk_size - 6);
581  break;
582 
583  case FLI_DELTA:
584  case FLI_DTA_LC:
585  y_ptr = 0;
586  compressed_lines = bytestream2_get_le16(&g2);
587  while (compressed_lines > 0) {
588  if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk)
589  break;
590  CHECK_Y_PTR()
591  line_packets = sign_extend(bytestream2_get_le16(&g2), 16);
592  if (line_packets < 0) {
593  line_packets = -line_packets;
594  if (line_packets > s->avctx->height)
595  return AVERROR_INVALIDDATA;
596  y_ptr += line_packets * s->frame->linesize[0];
597  } else {
598  compressed_lines--;
599  pixel_ptr = y_ptr;
600  CHECK_PIXEL_PTR(0);
601  pixel_countdown = s->avctx->width;
602  for (i = 0; i < line_packets; i++) {
603  /* account for the skip bytes */
604  if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk)
605  break;
606  pixel_skip = bytestream2_get_byte(&g2);
607  pixel_ptr += (pixel_skip*2); /* Pixel is 2 bytes wide */
608  pixel_countdown -= pixel_skip;
609  byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
610  if (byte_run < 0) {
611  byte_run = -byte_run;
612  pixel = bytestream2_get_le16(&g2);
613  CHECK_PIXEL_PTR(2 * byte_run);
614  for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
615  *((signed short*)(&pixels[pixel_ptr])) = pixel;
616  pixel_ptr += 2;
617  }
618  } else {
619  if (bytestream2_tell(&g2) + 2*byte_run > stream_ptr_after_chunk)
620  break;
621  CHECK_PIXEL_PTR(2 * byte_run);
622  for (j = 0; j < byte_run; j++, pixel_countdown--) {
623  *((signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2);
624  pixel_ptr += 2;
625  }
626  }
627  }
628 
629  y_ptr += s->frame->linesize[0];
630  }
631  }
632  break;
633 
634  case FLI_LC:
635  av_log(avctx, AV_LOG_ERROR, "Unexpected FLI_LC chunk in non-palettized FLC\n");
636  bytestream2_skip(&g2, chunk_size - 6);
637  break;
638 
639  case FLI_BLACK:
640  /* set the whole frame to 0x0000 which is black in both 15Bpp and 16Bpp modes. */
641  for (int y = 0; y < s->avctx->height; y++)
642  memset(pixels + y * s->frame->linesize[0], 0, s->avctx->width * 2);
643  break;
644 
645  case FLI_BRUN:
646  y_ptr = 0;
647  for (lines = 0; lines < s->avctx->height; lines++) {
648  pixel_ptr = y_ptr;
649  /* disregard the line packets; instead, iterate through all
650  * pixels on a row */
651  bytestream2_skip(&g2, 1);
652  pixel_countdown = (s->avctx->width * 2);
653 
654  while (pixel_countdown > 0) {
655  if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
656  break;
657  byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
658  if (byte_run > 0) {
659  palette_idx1 = bytestream2_get_byte(&g2);
660  CHECK_PIXEL_PTR(byte_run);
661  for (j = 0; j < byte_run; j++) {
662  pixels[pixel_ptr++ ^ HAVE_BIGENDIAN] = palette_idx1;
663  pixel_countdown--;
664  if (pixel_countdown < 0)
665  av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) (linea%d)\n",
666  pixel_countdown, lines);
667  }
668  } else { /* copy bytes if byte_run < 0 */
669  byte_run = -byte_run;
670  if (bytestream2_tell(&g2) + byte_run > stream_ptr_after_chunk)
671  break;
672  CHECK_PIXEL_PTR(byte_run);
673  for (j = 0; j < byte_run; j++) {
674  palette_idx1 = bytestream2_get_byte(&g2);
675  pixels[pixel_ptr++ ^ HAVE_BIGENDIAN] = palette_idx1;
676  pixel_countdown--;
677  if (pixel_countdown < 0)
678  av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) at line %d\n",
679  pixel_countdown, lines);
680  }
681  }
682  }
683  y_ptr += s->frame->linesize[0];
684  }
685  break;
686 
687  case FLI_DTA_BRUN:
688  y_ptr = 0;
689  for (lines = 0; lines < s->avctx->height; lines++) {
690  pixel_ptr = y_ptr;
691  /* disregard the line packets; instead, iterate through all
692  * pixels on a row */
693  bytestream2_skip(&g2, 1);
694  pixel_countdown = s->avctx->width; /* Width is in pixels, not bytes */
695 
696  while (pixel_countdown > 0) {
697  if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
698  break;
699  byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
700  if (byte_run > 0) {
701  pixel = bytestream2_get_le16(&g2);
702  CHECK_PIXEL_PTR(2 * byte_run);
703  for (j = 0; j < byte_run; j++) {
704  *((signed short*)(&pixels[pixel_ptr])) = pixel;
705  pixel_ptr += 2;
706  pixel_countdown--;
707  if (pixel_countdown < 0)
708  av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n",
709  pixel_countdown);
710  }
711  } else { /* copy pixels if byte_run < 0 */
712  byte_run = -byte_run;
713  if (bytestream2_tell(&g2) + 2 * byte_run > stream_ptr_after_chunk)
714  break;
715  CHECK_PIXEL_PTR(2 * byte_run);
716  for (j = 0; j < byte_run; j++) {
717  *((signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2);
718  pixel_ptr += 2;
719  pixel_countdown--;
720  if (pixel_countdown < 0)
721  av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n",
722  pixel_countdown);
723  }
724  }
725  }
726 
727  y_ptr += s->frame->linesize[0];
728  }
729  break;
730 
731  case FLI_COPY:
732  case FLI_DTA_COPY:
733  /* copy the chunk (uncompressed frame) */
734  if (chunk_size - 6 > (unsigned int)(FFALIGN(s->avctx->width, 2) * s->avctx->height)*2) {
735  av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \
736  "bigger than image, skipping chunk\n", chunk_size - 6);
737  bytestream2_skip(&g2, chunk_size - 6);
738  } else {
739 
740  if (bytestream2_get_bytes_left(&g2) < 2 * s->avctx->width * s->avctx->height )
741  return AVERROR_INVALIDDATA;
742  for (y_ptr = 0; check_pixel_ptr(y_ptr, 0, pixel_limit, direction) == 0;
743  y_ptr += s->frame->linesize[0]) {
744 
745  pixel_countdown = s->avctx->width;
746  pixel_ptr = 0;
747  while (pixel_countdown > 0) {
748  *((signed short*)(&pixels[y_ptr + pixel_ptr])) = bytestream2_get_le16(&g2);
749  pixel_ptr += 2;
750  pixel_countdown--;
751  }
752  if (s->avctx->width & 1)
753  bytestream2_skip(&g2, 2);
754  }
755  }
756  break;
757 
758  case FLI_MINI:
759  /* some sort of a thumbnail? disregard this chunk... */
760  bytestream2_skip(&g2, chunk_size - 6);
761  break;
762 
763  default:
764  av_log(avctx, AV_LOG_ERROR, "Unrecognized chunk type: %d\n", chunk_type);
765  break;
766  }
767 
768  if (stream_ptr_after_chunk - bytestream2_tell(&g2) >= 0) {
769  bytestream2_skip(&g2, stream_ptr_after_chunk - bytestream2_tell(&g2));
770  } else {
771  av_log(avctx, AV_LOG_ERROR, "Chunk overread\n");
772  break;
773  }
774 
775  frame_size -= chunk_size;
776  num_chunks--;
777  }
778 
779  /* by the end of the chunk, the stream ptr should equal the frame
780  * size (minus 1, possibly); if it doesn't, issue a warning */
781  if ((bytestream2_get_bytes_left(&g2) != 0) && (bytestream2_get_bytes_left(&g2) != 1))
782  av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \
783  "and final chunk ptr = %d\n", buf_size, bytestream2_tell(&g2));
784 
785  if ((ret = av_frame_ref(data, s->frame)) < 0)
786  return ret;
787 
788  *got_frame = 1;
789 
790  return buf_size;
791 }
792 
794  void *data, int *got_frame,
795  const uint8_t *buf, int buf_size)
796 {
797  FlicDecodeContext *s = avctx->priv_data;
798 
799  GetByteContext g2;
800  ptrdiff_t pixel_ptr;
801  unsigned char palette_idx1;
802 
803  unsigned int frame_size;
804  int num_chunks;
805 
806  unsigned int chunk_size;
807  int chunk_type;
808 
809  int i, j, ret, direction;
810 
811  int lines;
812  int compressed_lines;
813  int line_packets;
814  ptrdiff_t y_ptr;
815  int byte_run;
816  int pixel_skip;
817  int pixel_countdown;
818  unsigned char *pixels;
819  int pixel;
820  ptrdiff_t pixel_limit;
821 
822  bytestream2_init(&g2, buf, buf_size);
823 
824  if ((ret = ff_reget_buffer(avctx, s->frame, 0)) < 0)
825  return ret;
826 
827  direction = s->frame->linesize[0] > 0;
828  pixels = s->frame->data[0];
829  pixel_limit = s->avctx->height * s->frame->linesize[0];
830 
831  frame_size = bytestream2_get_le32(&g2);
832  bytestream2_skip(&g2, 2); /* skip the magic number */
833  num_chunks = bytestream2_get_le16(&g2);
834  bytestream2_skip(&g2, 8); /* skip padding */
835  if (frame_size > buf_size)
836  frame_size = buf_size;
837 
838  if (frame_size < 16)
839  return AVERROR_INVALIDDATA;
840  frame_size -= 16;
841 
842  /* iterate through the chunks */
843  while ((frame_size > 0) && (num_chunks > 0) &&
844  bytestream2_get_bytes_left(&g2) >= 4) {
845  int stream_ptr_after_chunk;
846  chunk_size = bytestream2_get_le32(&g2);
847  if (chunk_size > frame_size) {
848  av_log(avctx, AV_LOG_WARNING,
849  "Invalid chunk_size = %u > frame_size = %u\n", chunk_size, frame_size);
850  chunk_size = frame_size;
851  }
852  stream_ptr_after_chunk = bytestream2_tell(&g2) - 4 + chunk_size;
853 
854  chunk_type = bytestream2_get_le16(&g2);
855 
856 
857  switch (chunk_type) {
858  case FLI_256_COLOR:
859  case FLI_COLOR:
860  /* For some reason, it seems that non-palettized flics do
861  * include one of these chunks in their first frame.
862  * Why I do not know, it seems rather extraneous. */
863  ff_dlog(avctx,
864  "Unexpected Palette chunk %d in non-palettized FLC\n",
865  chunk_type);
866  bytestream2_skip(&g2, chunk_size - 6);
867  break;
868 
869  case FLI_DELTA:
870  case FLI_DTA_LC:
871  y_ptr = 0;
872  compressed_lines = bytestream2_get_le16(&g2);
873  while (compressed_lines > 0) {
874  if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk)
875  break;
876  CHECK_Y_PTR()
877  line_packets = sign_extend(bytestream2_get_le16(&g2), 16);
878  if (line_packets < 0) {
879  line_packets = -line_packets;
880  if (line_packets > s->avctx->height)
881  return AVERROR_INVALIDDATA;
882  y_ptr += line_packets * s->frame->linesize[0];
883  } else {
884  compressed_lines--;
885  pixel_ptr = y_ptr;
886  CHECK_PIXEL_PTR(0);
887  pixel_countdown = s->avctx->width;
888  for (i = 0; i < line_packets; i++) {
889  /* account for the skip bytes */
890  if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk)
891  break;
892  pixel_skip = bytestream2_get_byte(&g2);
893  pixel_ptr += (pixel_skip*3); /* Pixel is 3 bytes wide */
894  pixel_countdown -= pixel_skip;
895  byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
896  if (byte_run < 0) {
897  byte_run = -byte_run;
898  pixel = bytestream2_get_le24(&g2);
899  CHECK_PIXEL_PTR(3 * byte_run);
900  for (j = 0; j < byte_run; j++, pixel_countdown -= 1) {
901  AV_WL24(&pixels[pixel_ptr], pixel);
902  pixel_ptr += 3;
903  }
904  } else {
905  if (bytestream2_tell(&g2) + 2*byte_run > stream_ptr_after_chunk)
906  break;
907  CHECK_PIXEL_PTR(3 * byte_run);
908  for (j = 0; j < byte_run; j++, pixel_countdown--) {
909  pixel = bytestream2_get_le24(&g2);
910  AV_WL24(&pixels[pixel_ptr], pixel);
911  pixel_ptr += 3;
912  }
913  }
914  }
915 
916  y_ptr += s->frame->linesize[0];
917  }
918  }
919  break;
920 
921  case FLI_LC:
922  av_log(avctx, AV_LOG_ERROR, "Unexpected FLI_LC chunk in non-palettized FLC\n");
923  bytestream2_skip(&g2, chunk_size - 6);
924  break;
925 
926  case FLI_BLACK:
927  /* set the whole frame to 0x00 which is black for 24 bit mode. */
928  for (int y = 0; y < s->avctx->height; y++)
929  memset(pixels + y * s->frame->linesize[0], 0, s->avctx->width * 3);
930  break;
931 
932  case FLI_BRUN:
933  y_ptr = 0;
934  for (lines = 0; lines < s->avctx->height; lines++) {
935  pixel_ptr = y_ptr;
936  /* disregard the line packets; instead, iterate through all
937  * pixels on a row */
938  bytestream2_skip(&g2, 1);
939  pixel_countdown = (s->avctx->width * 3);
940 
941  while (pixel_countdown > 0) {
942  if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
943  break;
944  byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
945  if (byte_run > 0) {
946  palette_idx1 = bytestream2_get_byte(&g2);
947  CHECK_PIXEL_PTR(byte_run);
948  for (j = 0; j < byte_run; j++) {
949  pixels[pixel_ptr++] = palette_idx1;
950  pixel_countdown--;
951  if (pixel_countdown < 0)
952  av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) (linea%d)\n",
953  pixel_countdown, lines);
954  }
955  } else { /* copy bytes if byte_run < 0 */
956  byte_run = -byte_run;
957  if (bytestream2_tell(&g2) + byte_run > stream_ptr_after_chunk)
958  break;
959  CHECK_PIXEL_PTR(byte_run);
960  for (j = 0; j < byte_run; j++) {
961  palette_idx1 = bytestream2_get_byte(&g2);
962  pixels[pixel_ptr++] = palette_idx1;
963  pixel_countdown--;
964  if (pixel_countdown < 0)
965  av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) at line %d\n",
966  pixel_countdown, lines);
967  }
968  }
969  }
970 
971  y_ptr += s->frame->linesize[0];
972  }
973  break;
974 
975  case FLI_DTA_BRUN:
976  y_ptr = 0;
977  for (lines = 0; lines < s->avctx->height; lines++) {
978  pixel_ptr = y_ptr;
979  /* disregard the line packets; instead, iterate through all
980  * pixels on a row */
981  bytestream2_skip(&g2, 1);
982  pixel_countdown = s->avctx->width; /* Width is in pixels, not bytes */
983 
984  while (pixel_countdown > 0) {
985  if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
986  break;
987  byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
988  if (byte_run > 0) {
989  pixel = bytestream2_get_le24(&g2);
990  CHECK_PIXEL_PTR(3 * byte_run);
991  for (j = 0; j < byte_run; j++) {
992  AV_WL24(pixels + pixel_ptr, pixel);
993  pixel_ptr += 3;
994  pixel_countdown--;
995  if (pixel_countdown < 0)
996  av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n",
997  pixel_countdown);
998  }
999  } else { /* copy pixels if byte_run < 0 */
1000  byte_run = -byte_run;
1001  if (bytestream2_tell(&g2) + 3 * byte_run > stream_ptr_after_chunk)
1002  break;
1003  CHECK_PIXEL_PTR(3 * byte_run);
1004  for (j = 0; j < byte_run; j++) {
1005  pixel = bytestream2_get_le24(&g2);
1006  AV_WL24(pixels + pixel_ptr, pixel);
1007  pixel_ptr += 3;
1008  pixel_countdown--;
1009  if (pixel_countdown < 0)
1010  av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n",
1011  pixel_countdown);
1012  }
1013  }
1014  }
1015 
1016  y_ptr += s->frame->linesize[0];
1017  }
1018  break;
1019 
1020  case FLI_COPY:
1021  case FLI_DTA_COPY:
1022  /* copy the chunk (uncompressed frame) */
1023  if (chunk_size - 6 > (unsigned int)(FFALIGN(s->avctx->width, 2) * s->avctx->height)*3) {
1024  av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \
1025  "bigger than image, skipping chunk\n", chunk_size - 6);
1026  bytestream2_skip(&g2, chunk_size - 6);
1027  } else {
1028  for (y_ptr = 0; check_pixel_ptr(y_ptr, 0, pixel_limit, direction) == 0;
1029  y_ptr += s->frame->linesize[0]) {
1030 
1031  bytestream2_get_buffer(&g2, pixels + y_ptr, 3*s->avctx->width);
1032  if (s->avctx->width & 1)
1033  bytestream2_skip(&g2, 3);
1034  }
1035  }
1036  break;
1037 
1038  case FLI_MINI:
1039  /* some sort of a thumbnail? disregard this chunk... */
1040  bytestream2_skip(&g2, chunk_size - 6);
1041  break;
1042 
1043  default:
1044  av_log(avctx, AV_LOG_ERROR, "Unrecognized chunk type: %d\n", chunk_type);
1045  break;
1046  }
1047 
1048  if (stream_ptr_after_chunk - bytestream2_tell(&g2) >= 0) {
1049  bytestream2_skip(&g2, stream_ptr_after_chunk - bytestream2_tell(&g2));
1050  } else {
1051  av_log(avctx, AV_LOG_ERROR, "Chunk overread\n");
1052  break;
1053  }
1054 
1055  frame_size -= chunk_size;
1056  num_chunks--;
1057  }
1058 
1059  /* by the end of the chunk, the stream ptr should equal the frame
1060  * size (minus 1, possibly); if it doesn't, issue a warning */
1061  if ((bytestream2_get_bytes_left(&g2) != 0) && (bytestream2_get_bytes_left(&g2) != 1))
1062  av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \
1063  "and final chunk ptr = %d\n", buf_size, bytestream2_tell(&g2));
1064 
1065  if ((ret = av_frame_ref(data, s->frame)) < 0)
1066  return ret;
1067 
1068  *got_frame = 1;
1069 
1070  return buf_size;
1071 }
1072 
1074  void *data, int *got_frame,
1075  AVPacket *avpkt)
1076 {
1077  const uint8_t *buf = avpkt->data;
1078  int buf_size = avpkt->size;
1079  if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
1080  return flic_decode_frame_8BPP(avctx, data, got_frame,
1081  buf, buf_size);
1082  } else if ((avctx->pix_fmt == AV_PIX_FMT_RGB555) ||
1083  (avctx->pix_fmt == AV_PIX_FMT_RGB565)) {
1084  return flic_decode_frame_15_16BPP(avctx, data, got_frame,
1085  buf, buf_size);
1086  } else if (avctx->pix_fmt == AV_PIX_FMT_BGR24) {
1087  return flic_decode_frame_24BPP(avctx, data, got_frame,
1088  buf, buf_size);
1089  }
1090 
1091  /* Should not get here, ever as the pix_fmt is processed */
1092  /* in flic_decode_init and the above if should deal with */
1093  /* the finite set of possibilities allowable by here. */
1094  /* But in case we do, just error out. */
1095  av_log(avctx, AV_LOG_ERROR, "Unknown FLC format, my science cannot explain how this happened.\n");
1096  return AVERROR_BUG;
1097 }
1098 
1099 
1101 {
1102  FlicDecodeContext *s = avctx->priv_data;
1103 
1104  av_frame_free(&s->frame);
1105 
1106  return 0;
1107 }
1108 
1110  .name = "flic",
1111  .long_name = NULL_IF_CONFIG_SMALL("Autodesk Animator Flic video"),
1112  .type = AVMEDIA_TYPE_VIDEO,
1113  .id = AV_CODEC_ID_FLIC,
1114  .priv_data_size = sizeof(FlicDecodeContext),
1116  .close = flic_decode_end,
1118  .capabilities = AV_CODEC_CAP_DR1,
1119 };
#define av_cold
Definition: attributes.h:88
uint8_t
Libavcodec external API header.
#define AV_RL16
Definition: intreadwrite.h:42
#define AV_RL32
Definition: intreadwrite.h:146
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition: bytestream.h:267
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:158
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:137
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:168
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:192
#define s(width, name)
Definition: cbs_vp9.c:257
#define HAVE_BIGENDIAN
Definition: config.h:202
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.
Definition: decode.c:2018
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
static av_cold int flic_decode_init(AVCodecContext *avctx)
Definition: flicvideo.c:96
#define FLI_COPY
Definition: flicvideo.c:53
#define FLC_FLX_TYPE_CODE
Definition: flicvideo.c:60
static int check_pixel_ptr(ptrdiff_t ptr, int n, ptrdiff_t limit, int direction)
Definition: flicvideo.c:64
#define FLI_BLACK
Definition: flicvideo.c:51
#define FLI_MINI
Definition: flicvideo.c:54
#define FLI_256_COLOR
Definition: flicvideo.c:47
#define FLI_DTA_COPY
Definition: flicvideo.c:56
static av_cold int flic_decode_end(AVCodecContext *avctx)
Definition: flicvideo.c:1100
#define FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE
Definition: flicvideo.c:62
#define FLI_BRUN
Definition: flicvideo.c:52
#define FLI_DTA_BRUN
Definition: flicvideo.c:55
#define FLI_LC
Definition: flicvideo.c:50
static int flic_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: flicvideo.c:1073
#define CHECK_Y_PTR()
Definition: flicvideo.c:80
#define FLI_DELTA
Definition: flicvideo.c:48
#define FLI_DTA_LC
Definition: flicvideo.c:57
AVCodec ff_flic_decoder
Definition: flicvideo.c:1109
#define FLI_TYPE_CODE
Definition: flicvideo.c:59
static int flic_decode_frame_8BPP(AVCodecContext *avctx, void *data, int *got_frame, const uint8_t *buf, int buf_size)
Definition: flicvideo.c:166
static int flic_decode_frame_15_16BPP(AVCodecContext *avctx, void *data, int *got_frame, const uint8_t *buf, int buf_size)
Definition: flicvideo.c:505
static int flic_decode_frame_24BPP(AVCodecContext *avctx, void *data, int *got_frame, const uint8_t *buf, int buf_size)
Definition: flicvideo.c:793
#define CHECK_PIXEL_PTR(n)
Definition: flicvideo.c:73
#define FLI_COLOR
Definition: flicvideo.c:49
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
@ AV_CODEC_ID_FLIC
Definition: codec_id.h:99
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition: avcodec.h:215
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define AVERROR(e)
Definition: error.h:43
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:443
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:190
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
int i
Definition: input.c:407
#define AV_WL24(p, d)
Definition: intreadwrite.h:464
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
#define FFALIGN(x, a)
Definition: macros.h:48
static av_const int sign_extend(int val, unsigned bits)
Definition: mathops.h:130
const char data[16]
Definition: mxf.c:142
int frame_size
Definition: mxfenc.c:2206
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:77
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
#define AV_PIX_FMT_RGB565
Definition: pixfmt.h:386
#define AVPALETTE_SIZE
Definition: pixfmt.h:32
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:387
main external API structure.
Definition: avcodec.h:536
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:746
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:637
int extradata_size
Definition: avcodec.h:638
void * priv_data
Definition: avcodec.h:563
AVCodec.
Definition: codec.h:197
const char * name
Name of the codec implementation.
Definition: codec.h:204
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
This structure stores compressed data.
Definition: packet.h:346
int size
Definition: packet.h:370
uint8_t * data
Definition: packet.h:369
unsigned int palette[256]
Definition: flicvideo.c:91
AVCodecContext * avctx
Definition: flicvideo.c:88
AVFrame * frame
Definition: flicvideo.c:89
#define ff_dlog(a,...)
#define av_log(a,...)
uint8_t pixel
Definition: tiny_ssim.c:42
const char * b
Definition: vf_curves.c:119
const char * g
Definition: vf_curves.c:118
const char * r
Definition: vf_curves.c:117
if(ret< 0)
Definition: vf_mcdeint.c:282