2 * FLI/FLC Animation Video Decoder
3 * Copyright (C) 2003, 2004 the ffmpeg project
5 * This file is part of FFmpeg.
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.
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.
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
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
28 * http://www.compuphase.com/flic.htm
30 * This decoder outputs PAL8/RGB555/RGB565 and maybe one day RGB24
31 * colorspace data, depending on the FLC. To use this decoder, be
32 * sure that your demuxer sends the FLI file header to the decoder via
33 * the extradata chunk in AVCodecContext. The chunk should be 128 bytes
34 * large. The only exception is for FLI files from the game "Magic Carpet",
35 * in which the header is only 12 bytes.
42 #include "libavutil/intreadwrite.h"
44 #include "bytestream.h"
48 #define FLI_256_COLOR 4
56 #define FLI_DTA_BRUN 25
57 #define FLI_DTA_COPY 26
60 #define FLI_TYPE_CODE (0xAF11)
61 #define FLC_FLX_TYPE_CODE (0xAF12)
62 #define FLC_DTA_TYPE_CODE (0xAF44) /* Marks an "Extended FLC" comes from Dave's Targa Animator (DTA) */
63 #define FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE (0xAF13)
65 #define CHECK_PIXEL_PTR(n) \
66 if (pixel_ptr + n > pixel_limit) { \
67 av_log (s->avctx, AV_LOG_ERROR, "Invalid pixel_ptr = %d > pixel_limit = %d\n", \
68 pixel_ptr + n, pixel_limit); \
69 return AVERROR_INVALIDDATA; \
72 typedef struct FlicDecodeContext {
73 AVCodecContext *avctx;
76 unsigned int palette[256];
78 int fli_type; /* either 0xAF11 or 0xAF12, affects palette resolution */
81 static av_cold int flic_decode_init(AVCodecContext *avctx)
83 FlicDecodeContext *s = avctx->priv_data;
84 unsigned char *fli_header = (unsigned char *)avctx->extradata;
87 if (avctx->extradata_size != 0 &&
88 avctx->extradata_size != 12 &&
89 avctx->extradata_size != 128 &&
90 avctx->extradata_size != 256 &&
91 avctx->extradata_size != 904 &&
92 avctx->extradata_size != 1024) {
93 av_log(avctx, AV_LOG_ERROR, "Unexpected extradata size %d\n", avctx->extradata_size);
94 return AVERROR_INVALIDDATA;
99 if (s->avctx->extradata_size == 12) {
100 /* special case for magic carpet FLIs */
101 s->fli_type = FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE;
103 } else if (avctx->extradata_size == 1024) {
104 uint8_t *ptr = avctx->extradata;
107 for (i = 0; i < 256; i++) {
108 s->palette[i] = AV_RL32(ptr);
112 /* FLI in MOV, see e.g. FFmpeg trac issue #626 */
113 } else if (avctx->extradata_size == 0 ||
114 avctx->extradata_size == 256 ||
115 /* see FFmpeg ticket #1234 */
116 avctx->extradata_size == 904) {
117 s->fli_type = FLI_TYPE_CODE;
120 s->fli_type = AV_RL16(&fli_header[4]);
121 depth = AV_RL16(&fli_header[12]);
125 depth = 8; /* Some FLC generators set depth to zero, when they mean 8Bpp. Fix up here */
128 if ((s->fli_type == FLC_FLX_TYPE_CODE) && (depth == 16)) {
129 depth = 15; /* Original Autodesk FLX's say the depth is 16Bpp when it is really 15Bpp */
133 case 8 : avctx->pix_fmt = AV_PIX_FMT_PAL8; break;
134 case 15 : avctx->pix_fmt = AV_PIX_FMT_RGB555; break;
135 case 16 : avctx->pix_fmt = AV_PIX_FMT_RGB565; break;
136 case 24 : avctx->pix_fmt = AV_PIX_FMT_BGR24; /* Supposedly BGR, but havent any files to test with */
137 av_log(avctx, AV_LOG_ERROR, "24Bpp FLC/FLX is unsupported due to no test files.\n");
138 return AVERROR_PATCHWELCOME;
140 av_log(avctx, AV_LOG_ERROR, "Unknown FLC/FLX depth of %d Bpp is unsupported.\n",depth);
141 return AVERROR_INVALIDDATA;
144 avcodec_get_frame_defaults(&s->frame);
150 static int flic_decode_frame_8BPP(AVCodecContext *avctx,
151 void *data, int *got_frame,
152 const uint8_t *buf, int buf_size)
154 FlicDecodeContext *s = avctx->priv_data;
159 unsigned char palette_idx1;
160 unsigned char palette_idx2;
162 unsigned int frame_size;
165 unsigned int chunk_size;
173 unsigned char r, g, b;
176 int compressed_lines;
178 signed short line_packets;
183 unsigned char *pixels;
184 unsigned int pixel_limit;
186 bytestream2_init(&g2, buf, buf_size);
188 if ((ret = ff_reget_buffer(avctx, &s->frame)) < 0)
191 pixels = s->frame.data[0];
192 pixel_limit = s->avctx->height * s->frame.linesize[0];
193 if (buf_size < 16 || buf_size > INT_MAX - (3 * 256 + FF_INPUT_BUFFER_PADDING_SIZE))
194 return AVERROR_INVALIDDATA;
195 frame_size = bytestream2_get_le32(&g2);
196 if (frame_size > buf_size)
197 frame_size = buf_size;
198 bytestream2_skip(&g2, 2); /* skip the magic number */
199 num_chunks = bytestream2_get_le16(&g2);
200 bytestream2_skip(&g2, 8); /* skip padding */
204 /* iterate through the chunks */
205 while ((frame_size >= 6) && (num_chunks > 0)) {
206 int stream_ptr_after_chunk;
207 chunk_size = bytestream2_get_le32(&g2);
208 if (chunk_size > frame_size) {
209 av_log(avctx, AV_LOG_WARNING,
210 "Invalid chunk_size = %u > frame_size = %u\n", chunk_size, frame_size);
211 chunk_size = frame_size;
213 stream_ptr_after_chunk = bytestream2_tell(&g2) - 4 + chunk_size;
215 chunk_type = bytestream2_get_le16(&g2);
217 switch (chunk_type) {
220 /* check special case: If this file is from the Magic Carpet
221 * game and uses 6-bit colors even though it reports 256-color
222 * chunks in a 0xAF12-type file (fli_type is set to 0xAF13 during
224 if ((chunk_type == FLI_256_COLOR) && (s->fli_type != FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE))
228 /* set up the palette */
229 color_packets = bytestream2_get_le16(&g2);
231 for (i = 0; i < color_packets; i++) {
232 /* first byte is how many colors to skip */
233 palette_ptr += bytestream2_get_byte(&g2);
235 /* next byte indicates how many entries to change */
236 color_changes = bytestream2_get_byte(&g2);
238 /* if there are 0 color changes, there are actually 256 */
239 if (color_changes == 0)
242 if (bytestream2_tell(&g2) + color_changes * 3 > stream_ptr_after_chunk)
245 for (j = 0; j < color_changes; j++) {
248 /* wrap around, for good measure */
249 if ((unsigned)palette_ptr >= 256)
252 r = bytestream2_get_byte(&g2) << color_shift;
253 g = bytestream2_get_byte(&g2) << color_shift;
254 b = bytestream2_get_byte(&g2) << color_shift;
255 entry = 0xFFU << 24 | r << 16 | g << 8 | b;
256 if (color_shift == 2)
257 entry |= entry >> 6 & 0x30303;
258 if (s->palette[palette_ptr] != entry)
260 s->palette[palette_ptr++] = entry;
267 compressed_lines = bytestream2_get_le16(&g2);
268 while (compressed_lines > 0) {
269 if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk)
271 line_packets = bytestream2_get_le16(&g2);
272 if ((line_packets & 0xC000) == 0xC000) {
274 line_packets = -line_packets;
275 y_ptr += line_packets * s->frame.linesize[0];
276 } else if ((line_packets & 0xC000) == 0x4000) {
277 av_log(avctx, AV_LOG_ERROR, "Undefined opcode (%x) in DELTA_FLI\n", line_packets);
278 } else if ((line_packets & 0xC000) == 0x8000) {
279 // "last byte" opcode
280 pixel_ptr= y_ptr + s->frame.linesize[0] - 1;
282 pixels[pixel_ptr] = line_packets & 0xff;
287 pixel_countdown = s->avctx->width;
288 for (i = 0; i < line_packets; i++) {
289 if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk)
291 /* account for the skip bytes */
292 pixel_skip = bytestream2_get_byte(&g2);
293 pixel_ptr += pixel_skip;
294 pixel_countdown -= pixel_skip;
295 byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
297 byte_run = -byte_run;
298 palette_idx1 = bytestream2_get_byte(&g2);
299 palette_idx2 = bytestream2_get_byte(&g2);
300 CHECK_PIXEL_PTR(byte_run * 2);
301 for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
302 pixels[pixel_ptr++] = palette_idx1;
303 pixels[pixel_ptr++] = palette_idx2;
306 CHECK_PIXEL_PTR(byte_run * 2);
307 if (bytestream2_tell(&g2) + byte_run * 2 > stream_ptr_after_chunk)
309 for (j = 0; j < byte_run * 2; j++, pixel_countdown--) {
310 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
315 y_ptr += s->frame.linesize[0];
321 /* line compressed */
322 starting_line = bytestream2_get_le16(&g2);
324 y_ptr += starting_line * s->frame.linesize[0];
326 compressed_lines = bytestream2_get_le16(&g2);
327 while (compressed_lines > 0) {
330 pixel_countdown = s->avctx->width;
331 if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
333 line_packets = bytestream2_get_byte(&g2);
334 if (line_packets > 0) {
335 for (i = 0; i < line_packets; i++) {
336 /* account for the skip bytes */
337 if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
339 pixel_skip = bytestream2_get_byte(&g2);
340 pixel_ptr += pixel_skip;
341 pixel_countdown -= pixel_skip;
342 byte_run = sign_extend(bytestream2_get_byte(&g2),8);
344 CHECK_PIXEL_PTR(byte_run);
345 if (bytestream2_tell(&g2) + byte_run > stream_ptr_after_chunk)
347 for (j = 0; j < byte_run; j++, pixel_countdown--) {
348 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
350 } else if (byte_run < 0) {
351 byte_run = -byte_run;
352 palette_idx1 = bytestream2_get_byte(&g2);
353 CHECK_PIXEL_PTR(byte_run);
354 for (j = 0; j < byte_run; j++, pixel_countdown--) {
355 pixels[pixel_ptr++] = palette_idx1;
361 y_ptr += s->frame.linesize[0];
367 /* set the whole frame to color 0 (which is usually black) */
369 s->frame.linesize[0] * s->avctx->height);
373 /* Byte run compression: This chunk type only occurs in the first
374 * FLI frame and it will update the entire frame. */
376 for (lines = 0; lines < s->avctx->height; lines++) {
378 /* disregard the line packets; instead, iterate through all
380 bytestream2_skip(&g2, 1);
381 pixel_countdown = s->avctx->width;
382 while (pixel_countdown > 0) {
383 if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
385 byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
387 av_log(avctx, AV_LOG_ERROR, "Invalid byte run value.\n");
388 return AVERROR_INVALIDDATA;
392 palette_idx1 = bytestream2_get_byte(&g2);
393 CHECK_PIXEL_PTR(byte_run);
394 for (j = 0; j < byte_run; j++) {
395 pixels[pixel_ptr++] = palette_idx1;
397 if (pixel_countdown < 0)
398 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) at line %d\n",
399 pixel_countdown, lines);
401 } else { /* copy bytes if byte_run < 0 */
402 byte_run = -byte_run;
403 CHECK_PIXEL_PTR(byte_run);
404 if (bytestream2_tell(&g2) + byte_run > stream_ptr_after_chunk)
406 for (j = 0; j < byte_run; j++) {
407 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
409 if (pixel_countdown < 0)
410 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) at line %d\n",
411 pixel_countdown, lines);
416 y_ptr += s->frame.linesize[0];
421 /* copy the chunk (uncompressed frame) */
422 if (chunk_size - 6 != s->avctx->width * s->avctx->height) {
423 av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \
424 "has incorrect size, skipping chunk\n", chunk_size - 6);
425 bytestream2_skip(&g2, chunk_size - 6);
427 for (y_ptr = 0; y_ptr < s->frame.linesize[0] * s->avctx->height;
428 y_ptr += s->frame.linesize[0]) {
429 bytestream2_get_buffer(&g2, &pixels[y_ptr],
436 /* some sort of a thumbnail? disregard this chunk... */
440 av_log(avctx, AV_LOG_ERROR, "Unrecognized chunk type: %d\n", chunk_type);
444 if (stream_ptr_after_chunk - bytestream2_tell(&g2) > 0)
445 bytestream2_skip(&g2, stream_ptr_after_chunk - bytestream2_tell(&g2));
447 frame_size -= chunk_size;
451 /* by the end of the chunk, the stream ptr should equal the frame
452 * size (minus 1 or 2, possibly); if it doesn't, issue a warning */
453 if (bytestream2_get_bytes_left(&g2) > 2)
454 av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \
455 "and final chunk ptr = %d\n", buf_size,
456 buf_size - bytestream2_get_bytes_left(&g2));
458 /* make the palette available on the way out */
459 memcpy(s->frame.data[1], s->palette, AVPALETTE_SIZE);
460 if (s->new_palette) {
461 s->frame.palette_has_changed = 1;
465 if ((ret = av_frame_ref(data, &s->frame)) < 0)
473 static int flic_decode_frame_15_16BPP(AVCodecContext *avctx,
474 void *data, int *got_frame,
475 const uint8_t *buf, int buf_size)
477 /* Note, the only difference between the 15Bpp and 16Bpp */
478 /* Format is the pixel format, the packets are processed the same. */
479 FlicDecodeContext *s = avctx->priv_data;
483 unsigned char palette_idx1;
485 unsigned int frame_size;
488 unsigned int chunk_size;
494 int compressed_lines;
495 signed short line_packets;
500 unsigned char *pixels;
502 unsigned int pixel_limit;
504 bytestream2_init(&g2, buf, buf_size);
506 if ((ret = ff_reget_buffer(avctx, &s->frame)) < 0)
509 pixels = s->frame.data[0];
510 pixel_limit = s->avctx->height * s->frame.linesize[0];
512 frame_size = bytestream2_get_le32(&g2);
513 bytestream2_skip(&g2, 2); /* skip the magic number */
514 num_chunks = bytestream2_get_le16(&g2);
515 bytestream2_skip(&g2, 8); /* skip padding */
516 if (frame_size > buf_size)
517 frame_size = buf_size;
521 /* iterate through the chunks */
522 while ((frame_size > 0) && (num_chunks > 0)) {
523 int stream_ptr_after_chunk;
524 chunk_size = bytestream2_get_le32(&g2);
525 if (chunk_size > frame_size) {
526 av_log(avctx, AV_LOG_WARNING,
527 "Invalid chunk_size = %u > frame_size = %u\n", chunk_size, frame_size);
528 chunk_size = frame_size;
530 stream_ptr_after_chunk = bytestream2_tell(&g2) - 4 + chunk_size;
532 chunk_type = bytestream2_get_le16(&g2);
535 switch (chunk_type) {
538 /* For some reason, it seems that non-palettized flics do
539 * include one of these chunks in their first frame.
540 * Why I do not know, it seems rather extraneous. */
542 "Unexpected Palette chunk %d in non-palettized FLC\n",
544 bytestream2_skip(&g2, chunk_size - 6);
550 compressed_lines = bytestream2_get_le16(&g2);
551 while (compressed_lines > 0) {
552 if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk)
554 line_packets = bytestream2_get_le16(&g2);
555 if (line_packets < 0) {
556 line_packets = -line_packets;
557 y_ptr += line_packets * s->frame.linesize[0];
562 pixel_countdown = s->avctx->width;
563 for (i = 0; i < line_packets; i++) {
564 /* account for the skip bytes */
565 if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk)
567 pixel_skip = bytestream2_get_byte(&g2);
568 pixel_ptr += (pixel_skip*2); /* Pixel is 2 bytes wide */
569 pixel_countdown -= pixel_skip;
570 byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
572 byte_run = -byte_run;
573 pixel = bytestream2_get_le16(&g2);
574 CHECK_PIXEL_PTR(2 * byte_run);
575 for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
576 *((signed short*)(&pixels[pixel_ptr])) = pixel;
580 if (bytestream2_tell(&g2) + 2*byte_run > stream_ptr_after_chunk)
582 CHECK_PIXEL_PTR(2 * byte_run);
583 for (j = 0; j < byte_run; j++, pixel_countdown--) {
584 *((signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2);
590 y_ptr += s->frame.linesize[0];
596 av_log(avctx, AV_LOG_ERROR, "Unexpected FLI_LC chunk in non-palettized FLC\n");
597 bytestream2_skip(&g2, chunk_size - 6);
601 /* set the whole frame to 0x0000 which is black in both 15Bpp and 16Bpp modes. */
602 memset(pixels, 0x0000,
603 s->frame.linesize[0] * s->avctx->height);
608 for (lines = 0; lines < s->avctx->height; lines++) {
610 /* disregard the line packets; instead, iterate through all
612 bytestream2_skip(&g2, 1);
613 pixel_countdown = (s->avctx->width * 2);
615 while (pixel_countdown > 0) {
616 if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
618 byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
620 palette_idx1 = bytestream2_get_byte(&g2);
621 CHECK_PIXEL_PTR(byte_run);
622 for (j = 0; j < byte_run; j++) {
623 pixels[pixel_ptr++] = palette_idx1;
625 if (pixel_countdown < 0)
626 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) (linea%d)\n",
627 pixel_countdown, lines);
629 } else { /* copy bytes if byte_run < 0 */
630 byte_run = -byte_run;
631 if (bytestream2_tell(&g2) + byte_run > stream_ptr_after_chunk)
633 CHECK_PIXEL_PTR(byte_run);
634 for (j = 0; j < byte_run; j++) {
635 palette_idx1 = bytestream2_get_byte(&g2);
636 pixels[pixel_ptr++] = palette_idx1;
638 if (pixel_countdown < 0)
639 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) at line %d\n",
640 pixel_countdown, lines);
645 /* Now FLX is strange, in that it is "byte" as opposed to "pixel" run length compressed.
646 * This does not give us any good opportunity to perform word endian conversion
647 * during decompression. So if it is required (i.e., this is not a LE target, we do
648 * a second pass over the line here, swapping the bytes.
652 pixel_countdown = s->avctx->width;
653 while (pixel_countdown > 0) {
654 *((signed short*)(&pixels[pixel_ptr])) = AV_RL16(&buf[pixel_ptr]);
658 y_ptr += s->frame.linesize[0];
664 for (lines = 0; lines < s->avctx->height; lines++) {
666 /* disregard the line packets; instead, iterate through all
668 bytestream2_skip(&g2, 1);
669 pixel_countdown = s->avctx->width; /* Width is in pixels, not bytes */
671 while (pixel_countdown > 0) {
672 if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
674 byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
676 pixel = bytestream2_get_le16(&g2);
677 CHECK_PIXEL_PTR(2 * byte_run);
678 for (j = 0; j < byte_run; j++) {
679 *((signed short*)(&pixels[pixel_ptr])) = pixel;
682 if (pixel_countdown < 0)
683 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n",
686 } else { /* copy pixels if byte_run < 0 */
687 byte_run = -byte_run;
688 if (bytestream2_tell(&g2) + 2 * byte_run > stream_ptr_after_chunk)
690 CHECK_PIXEL_PTR(2 * byte_run);
691 for (j = 0; j < byte_run; j++) {
692 *((signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2);
695 if (pixel_countdown < 0)
696 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n",
702 y_ptr += s->frame.linesize[0];
708 /* copy the chunk (uncompressed frame) */
709 if (chunk_size - 6 > (unsigned int)(s->avctx->width * s->avctx->height)*2) {
710 av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \
711 "bigger than image, skipping chunk\n", chunk_size - 6);
712 bytestream2_skip(&g2, chunk_size - 6);
715 for (y_ptr = 0; y_ptr < s->frame.linesize[0] * s->avctx->height;
716 y_ptr += s->frame.linesize[0]) {
718 pixel_countdown = s->avctx->width;
720 while (pixel_countdown > 0) {
721 *((signed short*)(&pixels[y_ptr + pixel_ptr])) = bytestream2_get_le16(&g2);
730 /* some sort of a thumbnail? disregard this chunk... */
731 bytestream2_skip(&g2, chunk_size - 6);
735 av_log(avctx, AV_LOG_ERROR, "Unrecognized chunk type: %d\n", chunk_type);
739 frame_size -= chunk_size;
743 /* by the end of the chunk, the stream ptr should equal the frame
744 * size (minus 1, possibly); if it doesn't, issue a warning */
745 if ((bytestream2_get_bytes_left(&g2) != 0) && (bytestream2_get_bytes_left(&g2) != 1))
746 av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \
747 "and final chunk ptr = %d\n", buf_size, bytestream2_tell(&g2));
749 if ((ret = av_frame_ref(data, &s->frame)) < 0)
757 static int flic_decode_frame_24BPP(AVCodecContext *avctx,
758 void *data, int *got_frame,
759 const uint8_t *buf, int buf_size)
761 av_log(avctx, AV_LOG_ERROR, "24Bpp FLC Unsupported due to lack of test files.\n");
762 return AVERROR_PATCHWELCOME;
765 static int flic_decode_frame(AVCodecContext *avctx,
766 void *data, int *got_frame,
769 const uint8_t *buf = avpkt->data;
770 int buf_size = avpkt->size;
771 if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
772 return flic_decode_frame_8BPP(avctx, data, got_frame,
775 else if ((avctx->pix_fmt == AV_PIX_FMT_RGB555) ||
776 (avctx->pix_fmt == AV_PIX_FMT_RGB565)) {
777 return flic_decode_frame_15_16BPP(avctx, data, got_frame,
780 else if (avctx->pix_fmt == AV_PIX_FMT_BGR24) {
781 return flic_decode_frame_24BPP(avctx, data, got_frame,
785 /* Should not get here, ever as the pix_fmt is processed */
786 /* in flic_decode_init and the above if should deal with */
787 /* the finite set of possibilites allowable by here. */
788 /* But in case we do, just error out. */
789 av_log(avctx, AV_LOG_ERROR, "Unknown FLC format, my science cannot explain how this happened.\n");
794 static av_cold int flic_decode_end(AVCodecContext *avctx)
796 FlicDecodeContext *s = avctx->priv_data;
798 av_frame_unref(&s->frame);
803 AVCodec ff_flic_decoder = {
805 .type = AVMEDIA_TYPE_VIDEO,
806 .id = AV_CODEC_ID_FLIC,
807 .priv_data_size = sizeof(FlicDecodeContext),
808 .init = flic_decode_init,
809 .close = flic_decode_end,
810 .decode = flic_decode_frame,
811 .capabilities = CODEC_CAP_DR1,
812 .long_name = NULL_IF_CONFIG_SMALL("Autodesk Animator Flic video"),