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 avpriv_request_sample(avctx, "24Bpp FLC/FLX");
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 s->frame = av_frame_alloc();
146 return AVERROR(ENOMEM);
153 static int flic_decode_frame_8BPP(AVCodecContext *avctx,
154 void *data, int *got_frame,
155 const uint8_t *buf, int buf_size)
157 FlicDecodeContext *s = avctx->priv_data;
162 unsigned char palette_idx1;
163 unsigned char palette_idx2;
165 unsigned int frame_size;
168 unsigned int chunk_size;
176 unsigned char r, g, b;
179 int compressed_lines;
181 signed short line_packets;
186 unsigned char *pixels;
187 unsigned int pixel_limit;
189 bytestream2_init(&g2, buf, buf_size);
191 if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
194 pixels = s->frame->data[0];
195 pixel_limit = s->avctx->height * s->frame->linesize[0];
196 if (buf_size < 16 || buf_size > INT_MAX - (3 * 256 + AV_INPUT_BUFFER_PADDING_SIZE))
197 return AVERROR_INVALIDDATA;
198 frame_size = bytestream2_get_le32(&g2);
199 if (frame_size > buf_size)
200 frame_size = buf_size;
201 bytestream2_skip(&g2, 2); /* skip the magic number */
202 num_chunks = bytestream2_get_le16(&g2);
203 bytestream2_skip(&g2, 8); /* skip padding */
207 /* iterate through the chunks */
208 while ((frame_size >= 6) && (num_chunks > 0) &&
209 bytestream2_get_bytes_left(&g2) >= 4) {
210 int stream_ptr_after_chunk;
211 chunk_size = bytestream2_get_le32(&g2);
212 if (chunk_size > frame_size) {
213 av_log(avctx, AV_LOG_WARNING,
214 "Invalid chunk_size = %u > frame_size = %u\n", chunk_size, frame_size);
215 chunk_size = frame_size;
217 stream_ptr_after_chunk = bytestream2_tell(&g2) - 4 + chunk_size;
219 chunk_type = bytestream2_get_le16(&g2);
221 switch (chunk_type) {
224 /* check special case: If this file is from the Magic Carpet
225 * game and uses 6-bit colors even though it reports 256-color
226 * chunks in a 0xAF12-type file (fli_type is set to 0xAF13 during
228 if ((chunk_type == FLI_256_COLOR) && (s->fli_type != FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE))
232 /* set up the palette */
233 color_packets = bytestream2_get_le16(&g2);
235 for (i = 0; i < color_packets; i++) {
236 /* first byte is how many colors to skip */
237 palette_ptr += bytestream2_get_byte(&g2);
239 /* next byte indicates how many entries to change */
240 color_changes = bytestream2_get_byte(&g2);
242 /* if there are 0 color changes, there are actually 256 */
243 if (color_changes == 0)
246 if (bytestream2_tell(&g2) + color_changes * 3 > stream_ptr_after_chunk)
249 for (j = 0; j < color_changes; j++) {
252 /* wrap around, for good measure */
253 if ((unsigned)palette_ptr >= 256)
256 r = bytestream2_get_byte(&g2) << color_shift;
257 g = bytestream2_get_byte(&g2) << color_shift;
258 b = bytestream2_get_byte(&g2) << color_shift;
259 entry = 0xFFU << 24 | r << 16 | g << 8 | b;
260 if (color_shift == 2)
261 entry |= entry >> 6 & 0x30303;
262 if (s->palette[palette_ptr] != entry)
264 s->palette[palette_ptr++] = entry;
271 compressed_lines = bytestream2_get_le16(&g2);
272 while (compressed_lines > 0) {
273 if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk)
275 line_packets = bytestream2_get_le16(&g2);
276 if ((line_packets & 0xC000) == 0xC000) {
278 line_packets = -line_packets;
279 y_ptr += line_packets * s->frame->linesize[0];
280 } else if ((line_packets & 0xC000) == 0x4000) {
281 av_log(avctx, AV_LOG_ERROR, "Undefined opcode (%x) in DELTA_FLI\n", line_packets);
282 } else if ((line_packets & 0xC000) == 0x8000) {
283 // "last byte" opcode
284 pixel_ptr= y_ptr + s->frame->linesize[0] - 1;
286 pixels[pixel_ptr] = line_packets & 0xff;
291 pixel_countdown = s->avctx->width;
292 for (i = 0; i < line_packets; i++) {
293 if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk)
295 /* account for the skip bytes */
296 pixel_skip = bytestream2_get_byte(&g2);
297 pixel_ptr += pixel_skip;
298 pixel_countdown -= pixel_skip;
299 byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
301 byte_run = -byte_run;
302 palette_idx1 = bytestream2_get_byte(&g2);
303 palette_idx2 = bytestream2_get_byte(&g2);
304 CHECK_PIXEL_PTR(byte_run * 2);
305 for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
306 pixels[pixel_ptr++] = palette_idx1;
307 pixels[pixel_ptr++] = palette_idx2;
310 CHECK_PIXEL_PTR(byte_run * 2);
311 if (bytestream2_tell(&g2) + byte_run * 2 > stream_ptr_after_chunk)
313 for (j = 0; j < byte_run * 2; j++, pixel_countdown--) {
314 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
319 y_ptr += s->frame->linesize[0];
325 /* line compressed */
326 starting_line = bytestream2_get_le16(&g2);
328 y_ptr += starting_line * s->frame->linesize[0];
330 compressed_lines = bytestream2_get_le16(&g2);
331 while (compressed_lines > 0) {
334 pixel_countdown = s->avctx->width;
335 if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
337 line_packets = bytestream2_get_byte(&g2);
338 if (line_packets > 0) {
339 for (i = 0; i < line_packets; i++) {
340 /* account for the skip bytes */
341 if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
343 pixel_skip = bytestream2_get_byte(&g2);
344 pixel_ptr += pixel_skip;
345 pixel_countdown -= pixel_skip;
346 byte_run = sign_extend(bytestream2_get_byte(&g2),8);
348 CHECK_PIXEL_PTR(byte_run);
349 if (bytestream2_tell(&g2) + byte_run > stream_ptr_after_chunk)
351 for (j = 0; j < byte_run; j++, pixel_countdown--) {
352 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
354 } else if (byte_run < 0) {
355 byte_run = -byte_run;
356 palette_idx1 = bytestream2_get_byte(&g2);
357 CHECK_PIXEL_PTR(byte_run);
358 for (j = 0; j < byte_run; j++, pixel_countdown--) {
359 pixels[pixel_ptr++] = palette_idx1;
365 y_ptr += s->frame->linesize[0];
371 /* set the whole frame to color 0 (which is usually black) */
373 s->frame->linesize[0] * s->avctx->height);
377 /* Byte run compression: This chunk type only occurs in the first
378 * FLI frame and it will update the entire frame. */
380 for (lines = 0; lines < s->avctx->height; lines++) {
382 /* disregard the line packets; instead, iterate through all
384 bytestream2_skip(&g2, 1);
385 pixel_countdown = s->avctx->width;
386 while (pixel_countdown > 0) {
387 if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
389 byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
391 av_log(avctx, AV_LOG_ERROR, "Invalid byte run value.\n");
392 return AVERROR_INVALIDDATA;
396 palette_idx1 = bytestream2_get_byte(&g2);
397 CHECK_PIXEL_PTR(byte_run);
398 for (j = 0; j < byte_run; j++) {
399 pixels[pixel_ptr++] = palette_idx1;
401 if (pixel_countdown < 0)
402 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) at line %d\n",
403 pixel_countdown, lines);
405 } else { /* copy bytes if byte_run < 0 */
406 byte_run = -byte_run;
407 CHECK_PIXEL_PTR(byte_run);
408 if (bytestream2_tell(&g2) + byte_run > stream_ptr_after_chunk)
410 for (j = 0; j < byte_run; j++) {
411 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
413 if (pixel_countdown < 0)
414 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) at line %d\n",
415 pixel_countdown, lines);
420 y_ptr += s->frame->linesize[0];
425 /* copy the chunk (uncompressed frame) */
426 if (chunk_size - 6 != FFALIGN(s->avctx->width, 4) * s->avctx->height) {
427 av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \
428 "has incorrect size, skipping chunk\n", chunk_size - 6);
429 bytestream2_skip(&g2, chunk_size - 6);
431 for (y_ptr = 0; y_ptr < s->frame->linesize[0] * s->avctx->height;
432 y_ptr += s->frame->linesize[0]) {
433 bytestream2_get_buffer(&g2, &pixels[y_ptr],
435 if (s->avctx->width & 3)
436 bytestream2_skip(&g2, 4 - (s->avctx->width & 3));
442 /* some sort of a thumbnail? disregard this chunk... */
446 av_log(avctx, AV_LOG_ERROR, "Unrecognized chunk type: %d\n", chunk_type);
450 if (stream_ptr_after_chunk - bytestream2_tell(&g2) > 0)
451 bytestream2_skip(&g2, stream_ptr_after_chunk - bytestream2_tell(&g2));
453 frame_size -= chunk_size;
457 /* by the end of the chunk, the stream ptr should equal the frame
458 * size (minus 1 or 2, possibly); if it doesn't, issue a warning */
459 if (bytestream2_get_bytes_left(&g2) > 2)
460 av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \
461 "and final chunk ptr = %d\n", buf_size,
462 buf_size - bytestream2_get_bytes_left(&g2));
464 /* make the palette available on the way out */
465 memcpy(s->frame->data[1], s->palette, AVPALETTE_SIZE);
466 if (s->new_palette) {
467 s->frame->palette_has_changed = 1;
471 if ((ret = av_frame_ref(data, s->frame)) < 0)
479 static int flic_decode_frame_15_16BPP(AVCodecContext *avctx,
480 void *data, int *got_frame,
481 const uint8_t *buf, int buf_size)
483 /* Note, the only difference between the 15Bpp and 16Bpp */
484 /* Format is the pixel format, the packets are processed the same. */
485 FlicDecodeContext *s = avctx->priv_data;
489 unsigned char palette_idx1;
491 unsigned int frame_size;
494 unsigned int chunk_size;
500 int compressed_lines;
501 signed short line_packets;
506 unsigned char *pixels;
508 unsigned int pixel_limit;
510 bytestream2_init(&g2, buf, buf_size);
512 if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
515 pixels = s->frame->data[0];
516 pixel_limit = s->avctx->height * s->frame->linesize[0];
518 frame_size = bytestream2_get_le32(&g2);
519 bytestream2_skip(&g2, 2); /* skip the magic number */
520 num_chunks = bytestream2_get_le16(&g2);
521 bytestream2_skip(&g2, 8); /* skip padding */
522 if (frame_size > buf_size)
523 frame_size = buf_size;
527 /* iterate through the chunks */
528 while ((frame_size > 0) && (num_chunks > 0) &&
529 bytestream2_get_bytes_left(&g2) >= 4) {
530 int stream_ptr_after_chunk;
531 chunk_size = bytestream2_get_le32(&g2);
532 if (chunk_size > frame_size) {
533 av_log(avctx, AV_LOG_WARNING,
534 "Invalid chunk_size = %u > frame_size = %u\n", chunk_size, frame_size);
535 chunk_size = frame_size;
537 stream_ptr_after_chunk = bytestream2_tell(&g2) - 4 + chunk_size;
539 chunk_type = bytestream2_get_le16(&g2);
542 switch (chunk_type) {
545 /* For some reason, it seems that non-palettized flics do
546 * include one of these chunks in their first frame.
547 * Why I do not know, it seems rather extraneous. */
549 "Unexpected Palette chunk %d in non-palettized FLC\n",
551 bytestream2_skip(&g2, chunk_size - 6);
557 compressed_lines = bytestream2_get_le16(&g2);
558 while (compressed_lines > 0) {
559 if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk)
561 line_packets = bytestream2_get_le16(&g2);
562 if (line_packets < 0) {
563 line_packets = -line_packets;
564 y_ptr += line_packets * s->frame->linesize[0];
569 pixel_countdown = s->avctx->width;
570 for (i = 0; i < line_packets; i++) {
571 /* account for the skip bytes */
572 if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk)
574 pixel_skip = bytestream2_get_byte(&g2);
575 pixel_ptr += (pixel_skip*2); /* Pixel is 2 bytes wide */
576 pixel_countdown -= pixel_skip;
577 byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
579 byte_run = -byte_run;
580 pixel = bytestream2_get_le16(&g2);
581 CHECK_PIXEL_PTR(2 * byte_run);
582 for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
583 *((signed short*)(&pixels[pixel_ptr])) = pixel;
587 if (bytestream2_tell(&g2) + 2*byte_run > stream_ptr_after_chunk)
589 CHECK_PIXEL_PTR(2 * byte_run);
590 for (j = 0; j < byte_run; j++, pixel_countdown--) {
591 *((signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2);
597 y_ptr += s->frame->linesize[0];
603 av_log(avctx, AV_LOG_ERROR, "Unexpected FLI_LC chunk in non-palettized FLC\n");
604 bytestream2_skip(&g2, chunk_size - 6);
608 /* set the whole frame to 0x0000 which is black in both 15Bpp and 16Bpp modes. */
609 memset(pixels, 0x0000,
610 s->frame->linesize[0] * s->avctx->height);
615 for (lines = 0; lines < s->avctx->height; lines++) {
617 /* disregard the line packets; instead, iterate through all
619 bytestream2_skip(&g2, 1);
620 pixel_countdown = (s->avctx->width * 2);
622 while (pixel_countdown > 0) {
623 if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
625 byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
627 palette_idx1 = bytestream2_get_byte(&g2);
628 CHECK_PIXEL_PTR(byte_run);
629 for (j = 0; j < byte_run; j++) {
630 pixels[pixel_ptr++] = palette_idx1;
632 if (pixel_countdown < 0)
633 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) (linea%d)\n",
634 pixel_countdown, lines);
636 } else { /* copy bytes if byte_run < 0 */
637 byte_run = -byte_run;
638 if (bytestream2_tell(&g2) + byte_run > stream_ptr_after_chunk)
640 CHECK_PIXEL_PTR(byte_run);
641 for (j = 0; j < byte_run; j++) {
642 palette_idx1 = bytestream2_get_byte(&g2);
643 pixels[pixel_ptr++] = palette_idx1;
645 if (pixel_countdown < 0)
646 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) at line %d\n",
647 pixel_countdown, lines);
652 /* Now FLX is strange, in that it is "byte" as opposed to "pixel" run length compressed.
653 * This does not give us any good opportunity to perform word endian conversion
654 * during decompression. So if it is required (i.e., this is not a LE target, we do
655 * a second pass over the line here, swapping the bytes.
659 pixel_countdown = s->avctx->width;
660 while (pixel_countdown > 0) {
661 *((signed short*)(&pixels[pixel_ptr])) = AV_RL16(&buf[pixel_ptr]);
665 y_ptr += s->frame->linesize[0];
671 for (lines = 0; lines < s->avctx->height; lines++) {
673 /* disregard the line packets; instead, iterate through all
675 bytestream2_skip(&g2, 1);
676 pixel_countdown = s->avctx->width; /* Width is in pixels, not bytes */
678 while (pixel_countdown > 0) {
679 if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
681 byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
683 pixel = bytestream2_get_le16(&g2);
684 CHECK_PIXEL_PTR(2 * byte_run);
685 for (j = 0; j < byte_run; j++) {
686 *((signed short*)(&pixels[pixel_ptr])) = pixel;
689 if (pixel_countdown < 0)
690 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n",
693 } else { /* copy pixels if byte_run < 0 */
694 byte_run = -byte_run;
695 if (bytestream2_tell(&g2) + 2 * byte_run > stream_ptr_after_chunk)
697 CHECK_PIXEL_PTR(2 * byte_run);
698 for (j = 0; j < byte_run; j++) {
699 *((signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2);
702 if (pixel_countdown < 0)
703 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n",
709 y_ptr += s->frame->linesize[0];
715 /* copy the chunk (uncompressed frame) */
716 if (chunk_size - 6 > (unsigned int)(FFALIGN(s->avctx->width, 2) * s->avctx->height)*2) {
717 av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \
718 "bigger than image, skipping chunk\n", chunk_size - 6);
719 bytestream2_skip(&g2, chunk_size - 6);
722 for (y_ptr = 0; y_ptr < s->frame->linesize[0] * s->avctx->height;
723 y_ptr += s->frame->linesize[0]) {
725 pixel_countdown = s->avctx->width;
727 while (pixel_countdown > 0) {
728 *((signed short*)(&pixels[y_ptr + pixel_ptr])) = bytestream2_get_le16(&g2);
732 if (s->avctx->width & 1)
733 bytestream2_skip(&g2, 2);
739 /* some sort of a thumbnail? disregard this chunk... */
740 bytestream2_skip(&g2, chunk_size - 6);
744 av_log(avctx, AV_LOG_ERROR, "Unrecognized chunk type: %d\n", chunk_type);
748 frame_size -= chunk_size;
752 /* by the end of the chunk, the stream ptr should equal the frame
753 * size (minus 1, possibly); if it doesn't, issue a warning */
754 if ((bytestream2_get_bytes_left(&g2) != 0) && (bytestream2_get_bytes_left(&g2) != 1))
755 av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \
756 "and final chunk ptr = %d\n", buf_size, bytestream2_tell(&g2));
758 if ((ret = av_frame_ref(data, s->frame)) < 0)
766 static int flic_decode_frame_24BPP(AVCodecContext *avctx,
767 void *data, int *got_frame,
768 const uint8_t *buf, int buf_size)
770 av_log(avctx, AV_LOG_ERROR, "24Bpp FLC Unsupported due to lack of test files.\n");
771 return AVERROR_PATCHWELCOME;
774 static int flic_decode_frame(AVCodecContext *avctx,
775 void *data, int *got_frame,
778 const uint8_t *buf = avpkt->data;
779 int buf_size = avpkt->size;
780 if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
781 return flic_decode_frame_8BPP(avctx, data, got_frame,
784 else if ((avctx->pix_fmt == AV_PIX_FMT_RGB555) ||
785 (avctx->pix_fmt == AV_PIX_FMT_RGB565)) {
786 return flic_decode_frame_15_16BPP(avctx, data, got_frame,
789 else if (avctx->pix_fmt == AV_PIX_FMT_BGR24) {
790 return flic_decode_frame_24BPP(avctx, data, got_frame,
794 /* Should not get here, ever as the pix_fmt is processed */
795 /* in flic_decode_init and the above if should deal with */
796 /* the finite set of possibilites allowable by here. */
797 /* But in case we do, just error out. */
798 av_log(avctx, AV_LOG_ERROR, "Unknown FLC format, my science cannot explain how this happened.\n");
803 static av_cold int flic_decode_end(AVCodecContext *avctx)
805 FlicDecodeContext *s = avctx->priv_data;
807 av_frame_free(&s->frame);
812 AVCodec ff_flic_decoder = {
814 .long_name = NULL_IF_CONFIG_SMALL("Autodesk Animator Flic video"),
815 .type = AVMEDIA_TYPE_VIDEO,
816 .id = AV_CODEC_ID_FLIC,
817 .priv_data_size = sizeof(FlicDecodeContext),
818 .init = flic_decode_init,
819 .close = flic_decode_end,
820 .decode = flic_decode_frame,
821 .capabilities = AV_CODEC_CAP_DR1,