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"
47 #define FLI_256_COLOR 4
55 #define FLI_DTA_BRUN 25
56 #define FLI_DTA_COPY 26
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)
64 #define CHECK_PIXEL_PTR(n) \
65 if (pixel_ptr + n > pixel_limit) { \
66 av_log (s->avctx, AV_LOG_ERROR, "Invalid pixel_ptr = %d > pixel_limit = %d\n", \
67 pixel_ptr + n, pixel_limit); \
68 return AVERROR_INVALIDDATA; \
71 typedef struct FlicDecodeContext {
72 AVCodecContext *avctx;
75 unsigned int palette[256];
77 int fli_type; /* either 0xAF11 or 0xAF12, affects palette resolution */
80 static av_cold int flic_decode_init(AVCodecContext *avctx)
82 FlicDecodeContext *s = avctx->priv_data;
83 unsigned char *fli_header = (unsigned char *)avctx->extradata;
86 if (avctx->extradata_size != 0 &&
87 avctx->extradata_size != 12 &&
88 avctx->extradata_size != 128 &&
89 avctx->extradata_size != 1024) {
90 av_log(avctx, AV_LOG_ERROR, "Expected extradata of 12, 128 or 1024 bytes\n");
91 return AVERROR_INVALIDDATA;
96 if (s->avctx->extradata_size == 12) {
97 /* special case for magic carpet FLIs */
98 s->fli_type = FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE;
100 } else if (avctx->extradata_size == 1024) {
101 uint8_t *ptr = avctx->extradata;
104 for (i = 0; i < 256; i++) {
105 s->palette[i] = AV_RL32(ptr);
109 } else if (avctx->extradata_size == 0) {
110 /* FLI in MOV, see e.g. FFmpeg trac issue #626 */
111 s->fli_type = FLI_TYPE_CODE;
114 s->fli_type = AV_RL16(&fli_header[4]);
115 depth = AV_RL16(&fli_header[12]);
119 depth = 8; /* Some FLC generators set depth to zero, when they mean 8Bpp. Fix up here */
122 if ((s->fli_type == FLC_FLX_TYPE_CODE) && (depth == 16)) {
123 depth = 15; /* Original Autodesk FLX's say the depth is 16Bpp when it is really 15Bpp */
127 case 8 : avctx->pix_fmt = PIX_FMT_PAL8; break;
128 case 15 : avctx->pix_fmt = PIX_FMT_RGB555; break;
129 case 16 : avctx->pix_fmt = PIX_FMT_RGB565; break;
130 case 24 : avctx->pix_fmt = PIX_FMT_BGR24; /* Supposedly BGR, but havent any files to test with */
131 av_log(avctx, AV_LOG_ERROR, "24Bpp FLC/FLX is unsupported due to no test files.\n");
134 av_log(avctx, AV_LOG_ERROR, "Unknown FLC/FLX depth of %d Bpp is unsupported.\n",depth);
138 avcodec_get_frame_defaults(&s->frame);
139 s->frame.data[0] = NULL;
145 static int flic_decode_frame_8BPP(AVCodecContext *avctx,
146 void *data, int *data_size,
147 const uint8_t *buf, int buf_size)
149 FlicDecodeContext *s = avctx->priv_data;
154 unsigned char palette_idx1;
155 unsigned char palette_idx2;
157 unsigned int frame_size;
160 unsigned int chunk_size;
168 unsigned char r, g, b;
171 int compressed_lines;
173 signed short line_packets;
178 unsigned char *pixels;
179 unsigned int pixel_limit;
181 bytestream2_init(&g2, buf, buf_size);
183 s->frame.reference = 3;
184 s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
185 if (avctx->reget_buffer(avctx, &s->frame) < 0) {
186 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
190 pixels = s->frame.data[0];
191 pixel_limit = s->avctx->height * s->frame.linesize[0];
192 if (buf_size < 16 || buf_size > INT_MAX - (3 * 256 + FF_INPUT_BUFFER_PADDING_SIZE))
193 return AVERROR_INVALIDDATA;
194 frame_size = bytestream2_get_le32(&g2);
195 if (frame_size > buf_size)
196 frame_size = buf_size;
197 bytestream2_skip(&g2, 2); /* skip the magic number */
198 num_chunks = bytestream2_get_le16(&g2);
199 bytestream2_skip(&g2, 8); /* skip padding */
203 /* iterate through the chunks */
204 while ((frame_size >= 6) && (num_chunks > 0)) {
205 int stream_ptr_after_chunk;
206 chunk_size = bytestream2_get_le32(&g2);
207 if (chunk_size > frame_size) {
208 av_log(avctx, AV_LOG_WARNING,
209 "Invalid chunk_size = %u > frame_size = %u\n", chunk_size, frame_size);
210 chunk_size = frame_size;
212 stream_ptr_after_chunk = bytestream2_tell(&g2) - 4 + chunk_size;
214 chunk_type = bytestream2_get_le16(&g2);
216 switch (chunk_type) {
219 /* check special case: If this file is from the Magic Carpet
220 * game and uses 6-bit colors even though it reports 256-color
221 * chunks in a 0xAF12-type file (fli_type is set to 0xAF13 during
223 if ((chunk_type == FLI_256_COLOR) && (s->fli_type != FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE))
227 /* set up the palette */
228 color_packets = bytestream2_get_le16(&g2);
230 for (i = 0; i < color_packets; i++) {
231 /* first byte is how many colors to skip */
232 palette_ptr += bytestream2_get_byte(&g2);
234 /* next byte indicates how many entries to change */
235 color_changes = bytestream2_get_byte(&g2);
237 /* if there are 0 color changes, there are actually 256 */
238 if (color_changes == 0)
241 if (bytestream2_tell(&g2) + color_changes * 3 > stream_ptr_after_chunk)
244 for (j = 0; j < color_changes; j++) {
247 /* wrap around, for good measure */
248 if ((unsigned)palette_ptr >= 256)
251 r = bytestream2_get_byte(&g2) << color_shift;
252 g = bytestream2_get_byte(&g2) << color_shift;
253 b = bytestream2_get_byte(&g2) << color_shift;
254 entry = 0xFF << 24 | r << 16 | g << 8 | b;
255 if (color_shift == 2)
256 entry |= entry >> 6 & 0x30303;
257 if (s->palette[palette_ptr] != entry)
259 s->palette[palette_ptr++] = entry;
266 compressed_lines = bytestream2_get_le16(&g2);
267 while (compressed_lines > 0) {
268 if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk)
270 line_packets = bytestream2_get_le16(&g2);
271 if ((line_packets & 0xC000) == 0xC000) {
273 line_packets = -line_packets;
274 y_ptr += line_packets * s->frame.linesize[0];
275 } else if ((line_packets & 0xC000) == 0x4000) {
276 av_log(avctx, AV_LOG_ERROR, "Undefined opcode (%x) in DELTA_FLI\n", line_packets);
277 } else if ((line_packets & 0xC000) == 0x8000) {
278 // "last byte" opcode
279 pixel_ptr= y_ptr + s->frame.linesize[0] - 1;
281 pixels[pixel_ptr] = line_packets & 0xff;
286 pixel_countdown = s->avctx->width;
287 for (i = 0; i < line_packets; i++) {
288 if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk)
290 /* account for the skip bytes */
291 pixel_skip = bytestream2_get_byte(&g2);
292 pixel_ptr += pixel_skip;
293 pixel_countdown -= pixel_skip;
294 byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
296 byte_run = -byte_run;
297 palette_idx1 = bytestream2_get_byte(&g2);
298 palette_idx2 = bytestream2_get_byte(&g2);
299 CHECK_PIXEL_PTR(byte_run * 2);
300 for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
301 pixels[pixel_ptr++] = palette_idx1;
302 pixels[pixel_ptr++] = palette_idx2;
305 CHECK_PIXEL_PTR(byte_run * 2);
306 if (bytestream2_tell(&g2) + byte_run * 2 > stream_ptr_after_chunk)
308 for (j = 0; j < byte_run * 2; j++, pixel_countdown--) {
309 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
314 y_ptr += s->frame.linesize[0];
320 /* line compressed */
321 starting_line = bytestream2_get_le16(&g2);
323 y_ptr += starting_line * s->frame.linesize[0];
325 compressed_lines = bytestream2_get_le16(&g2);
326 while (compressed_lines > 0) {
329 pixel_countdown = s->avctx->width;
330 if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
332 line_packets = bytestream2_get_byte(&g2);
333 if (line_packets > 0) {
334 for (i = 0; i < line_packets; i++) {
335 /* account for the skip bytes */
336 if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
338 pixel_skip = bytestream2_get_byte(&g2);
339 pixel_ptr += pixel_skip;
340 pixel_countdown -= pixel_skip;
341 byte_run = sign_extend(bytestream2_get_byte(&g2),8);
343 CHECK_PIXEL_PTR(byte_run);
344 if (bytestream2_tell(&g2) + byte_run > stream_ptr_after_chunk)
346 for (j = 0; j < byte_run; j++, pixel_countdown--) {
347 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
349 } else if (byte_run < 0) {
350 byte_run = -byte_run;
351 palette_idx1 = bytestream2_get_byte(&g2);
352 CHECK_PIXEL_PTR(byte_run);
353 for (j = 0; j < byte_run; j++, pixel_countdown--) {
354 pixels[pixel_ptr++] = palette_idx1;
360 y_ptr += s->frame.linesize[0];
366 /* set the whole frame to color 0 (which is usually black) */
368 s->frame.linesize[0] * s->avctx->height);
372 /* Byte run compression: This chunk type only occurs in the first
373 * FLI frame and it will update the entire frame. */
375 for (lines = 0; lines < s->avctx->height; lines++) {
377 /* disregard the line packets; instead, iterate through all
379 bytestream2_skip(&g2, 1);
380 pixel_countdown = s->avctx->width;
381 while (pixel_countdown > 0) {
382 if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
384 byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
386 palette_idx1 = bytestream2_get_byte(&g2);
387 CHECK_PIXEL_PTR(byte_run);
388 for (j = 0; j < byte_run; j++) {
389 pixels[pixel_ptr++] = palette_idx1;
391 if (pixel_countdown < 0)
392 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) at line %d\n",
393 pixel_countdown, lines);
395 } else { /* copy bytes if byte_run < 0 */
396 byte_run = -byte_run;
397 CHECK_PIXEL_PTR(byte_run);
398 if (bytestream2_tell(&g2) + byte_run > stream_ptr_after_chunk)
400 for (j = 0; j < byte_run; j++) {
401 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
403 if (pixel_countdown < 0)
404 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) at line %d\n",
405 pixel_countdown, lines);
410 y_ptr += s->frame.linesize[0];
415 /* copy the chunk (uncompressed frame) */
416 if (chunk_size - 6 != s->avctx->width * s->avctx->height) {
417 av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \
418 "has incorrect size, skipping chunk\n", chunk_size - 6);
419 bytestream2_skip(&g2, chunk_size - 6);
421 for (y_ptr = 0; y_ptr < s->frame.linesize[0] * s->avctx->height;
422 y_ptr += s->frame.linesize[0]) {
423 bytestream2_get_buffer(&g2, &pixels[y_ptr],
430 /* some sort of a thumbnail? disregard this chunk... */
434 av_log(avctx, AV_LOG_ERROR, "Unrecognized chunk type: %d\n", chunk_type);
438 if (stream_ptr_after_chunk - bytestream2_tell(&g2) > 0)
439 bytestream2_skip(&g2, stream_ptr_after_chunk - bytestream2_tell(&g2));
441 frame_size -= chunk_size;
445 /* by the end of the chunk, the stream ptr should equal the frame
446 * size (minus 1 or 2, possibly); if it doesn't, issue a warning */
447 if (bytestream2_get_bytes_left(&g2) > 2)
448 av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \
449 "and final chunk ptr = %d\n", buf_size,
450 buf_size - bytestream2_get_bytes_left(&g2));
452 /* make the palette available on the way out */
453 memcpy(s->frame.data[1], s->palette, AVPALETTE_SIZE);
454 if (s->new_palette) {
455 s->frame.palette_has_changed = 1;
459 *data_size=sizeof(AVFrame);
460 *(AVFrame*)data = s->frame;
465 static int flic_decode_frame_15_16BPP(AVCodecContext *avctx,
466 void *data, int *data_size,
467 const uint8_t *buf, int buf_size)
469 /* Note, the only difference between the 15Bpp and 16Bpp */
470 /* Format is the pixel format, the packets are processed the same. */
471 FlicDecodeContext *s = avctx->priv_data;
475 unsigned char palette_idx1;
477 unsigned int frame_size;
480 unsigned int chunk_size;
486 int compressed_lines;
487 signed short line_packets;
492 unsigned char *pixels;
494 unsigned int pixel_limit;
496 bytestream2_init(&g2, buf, buf_size);
498 s->frame.reference = 3;
499 s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
500 if (avctx->reget_buffer(avctx, &s->frame) < 0) {
501 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
505 pixels = s->frame.data[0];
506 pixel_limit = s->avctx->height * s->frame.linesize[0];
508 frame_size = bytestream2_get_le32(&g2);
509 bytestream2_skip(&g2, 2); /* skip the magic number */
510 num_chunks = bytestream2_get_le16(&g2);
511 bytestream2_skip(&g2, 8); /* skip padding */
512 if (frame_size > buf_size)
513 frame_size = buf_size;
517 /* iterate through the chunks */
518 while ((frame_size > 0) && (num_chunks > 0)) {
519 int stream_ptr_after_chunk;
520 chunk_size = bytestream2_get_le32(&g2);
521 if (chunk_size > frame_size) {
522 av_log(avctx, AV_LOG_WARNING,
523 "Invalid chunk_size = %u > frame_size = %u\n", chunk_size, frame_size);
524 chunk_size = frame_size;
526 stream_ptr_after_chunk = bytestream2_tell(&g2) - 4 + chunk_size;
528 chunk_type = bytestream2_get_le16(&g2);
531 switch (chunk_type) {
534 /* For some reason, it seems that non-palettized flics do
535 * include one of these chunks in their first frame.
536 * Why I do not know, it seems rather extraneous. */
537 /* av_log(avctx, AV_LOG_ERROR, "Unexpected Palette chunk %d in non-paletised FLC\n",chunk_type);*/
538 bytestream2_skip(&g2, chunk_size - 6);
544 compressed_lines = bytestream2_get_le16(&g2);
545 while (compressed_lines > 0) {
546 if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk)
548 line_packets = bytestream2_get_le16(&g2);
549 if (line_packets < 0) {
550 line_packets = -line_packets;
551 y_ptr += line_packets * s->frame.linesize[0];
556 pixel_countdown = s->avctx->width;
557 for (i = 0; i < line_packets; i++) {
558 /* account for the skip bytes */
559 if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk)
561 pixel_skip = bytestream2_get_byte(&g2);
562 pixel_ptr += (pixel_skip*2); /* Pixel is 2 bytes wide */
563 pixel_countdown -= pixel_skip;
564 byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
566 byte_run = -byte_run;
567 pixel = bytestream2_get_le16(&g2);
568 CHECK_PIXEL_PTR(2 * byte_run);
569 for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
570 *((signed short*)(&pixels[pixel_ptr])) = pixel;
574 if (bytestream2_tell(&g2) + 2*byte_run > stream_ptr_after_chunk)
576 CHECK_PIXEL_PTR(2 * byte_run);
577 for (j = 0; j < byte_run; j++, pixel_countdown--) {
578 *((signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2);
584 y_ptr += s->frame.linesize[0];
590 av_log(avctx, AV_LOG_ERROR, "Unexpected FLI_LC chunk in non-paletised FLC\n");
591 bytestream2_skip(&g2, chunk_size - 6);
595 /* set the whole frame to 0x0000 which is black in both 15Bpp and 16Bpp modes. */
596 memset(pixels, 0x0000,
597 s->frame.linesize[0] * s->avctx->height);
602 for (lines = 0; lines < s->avctx->height; lines++) {
604 /* disregard the line packets; instead, iterate through all
606 bytestream2_skip(&g2, 1);
607 pixel_countdown = (s->avctx->width * 2);
609 while (pixel_countdown > 0) {
610 if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
612 byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
614 palette_idx1 = bytestream2_get_byte(&g2);
615 CHECK_PIXEL_PTR(byte_run);
616 for (j = 0; j < byte_run; j++) {
617 pixels[pixel_ptr++] = palette_idx1;
619 if (pixel_countdown < 0)
620 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) (linea%d)\n",
621 pixel_countdown, lines);
623 } else { /* copy bytes if byte_run < 0 */
624 byte_run = -byte_run;
625 if (bytestream2_tell(&g2) + byte_run > stream_ptr_after_chunk)
627 CHECK_PIXEL_PTR(byte_run);
628 for (j = 0; j < byte_run; j++) {
629 palette_idx1 = bytestream2_get_byte(&g2);
630 pixels[pixel_ptr++] = palette_idx1;
632 if (pixel_countdown < 0)
633 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) at line %d\n",
634 pixel_countdown, lines);
639 /* Now FLX is strange, in that it is "byte" as opposed to "pixel" run length compressed.
640 * This does not give us any good oportunity to perform word endian conversion
641 * during decompression. So if it is required (i.e., this is not a LE target, we do
642 * a second pass over the line here, swapping the bytes.
646 pixel_countdown = s->avctx->width;
647 while (pixel_countdown > 0) {
648 *((signed short*)(&pixels[pixel_ptr])) = AV_RL16(&buf[pixel_ptr]);
652 y_ptr += s->frame.linesize[0];
658 for (lines = 0; lines < s->avctx->height; lines++) {
660 /* disregard the line packets; instead, iterate through all
662 bytestream2_skip(&g2, 1);
663 pixel_countdown = s->avctx->width; /* Width is in pixels, not bytes */
665 while (pixel_countdown > 0) {
666 if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
668 byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
670 pixel = bytestream2_get_le16(&g2);
671 CHECK_PIXEL_PTR(2 * byte_run);
672 for (j = 0; j < byte_run; j++) {
673 *((signed short*)(&pixels[pixel_ptr])) = pixel;
676 if (pixel_countdown < 0)
677 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n",
680 } else { /* copy pixels if byte_run < 0 */
681 byte_run = -byte_run;
682 if (bytestream2_tell(&g2) + 2 * byte_run > stream_ptr_after_chunk)
684 CHECK_PIXEL_PTR(2 * byte_run);
685 for (j = 0; j < byte_run; j++) {
686 *((signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2);
689 if (pixel_countdown < 0)
690 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n",
696 y_ptr += s->frame.linesize[0];
702 /* copy the chunk (uncompressed frame) */
703 if (chunk_size - 6 > (unsigned int)(s->avctx->width * s->avctx->height)*2) {
704 av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \
705 "bigger than image, skipping chunk\n", chunk_size - 6);
706 bytestream2_skip(&g2, chunk_size - 6);
709 for (y_ptr = 0; y_ptr < s->frame.linesize[0] * s->avctx->height;
710 y_ptr += s->frame.linesize[0]) {
712 pixel_countdown = s->avctx->width;
714 while (pixel_countdown > 0) {
715 *((signed short*)(&pixels[y_ptr + pixel_ptr])) = bytestream2_get_le16(&g2);
724 /* some sort of a thumbnail? disregard this chunk... */
725 bytestream2_skip(&g2, chunk_size - 6);
729 av_log(avctx, AV_LOG_ERROR, "Unrecognized chunk type: %d\n", chunk_type);
733 frame_size -= chunk_size;
737 /* by the end of the chunk, the stream ptr should equal the frame
738 * size (minus 1, possibly); if it doesn't, issue a warning */
739 if ((bytestream2_get_bytes_left(&g2) != 0) && (bytestream2_get_bytes_left(&g2) != 1))
740 av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \
741 "and final chunk ptr = %d\n", buf_size, bytestream2_tell(&g2));
744 *data_size=sizeof(AVFrame);
745 *(AVFrame*)data = s->frame;
750 static int flic_decode_frame_24BPP(AVCodecContext *avctx,
751 void *data, int *data_size,
752 const uint8_t *buf, int buf_size)
754 av_log(avctx, AV_LOG_ERROR, "24Bpp FLC Unsupported due to lack of test files.\n");
758 static int flic_decode_frame(AVCodecContext *avctx,
759 void *data, int *data_size,
762 const uint8_t *buf = avpkt->data;
763 int buf_size = avpkt->size;
764 if (avctx->pix_fmt == PIX_FMT_PAL8) {
765 return flic_decode_frame_8BPP(avctx, data, data_size,
768 else if ((avctx->pix_fmt == PIX_FMT_RGB555) ||
769 (avctx->pix_fmt == PIX_FMT_RGB565)) {
770 return flic_decode_frame_15_16BPP(avctx, data, data_size,
773 else if (avctx->pix_fmt == PIX_FMT_BGR24) {
774 return flic_decode_frame_24BPP(avctx, data, data_size,
778 /* Should not get here, ever as the pix_fmt is processed */
779 /* in flic_decode_init and the above if should deal with */
780 /* the finite set of possibilites allowable by here. */
781 /* But in case we do, just error out. */
782 av_log(avctx, AV_LOG_ERROR, "Unknown FLC format, my science cannot explain how this happened.\n");
787 static av_cold int flic_decode_end(AVCodecContext *avctx)
789 FlicDecodeContext *s = avctx->priv_data;
791 if (s->frame.data[0])
792 avctx->release_buffer(avctx, &s->frame);
797 AVCodec ff_flic_decoder = {
799 .type = AVMEDIA_TYPE_VIDEO,
801 .priv_data_size = sizeof(FlicDecodeContext),
802 .init = flic_decode_init,
803 .close = flic_decode_end,
804 .decode = flic_decode_frame,
805 .capabilities = CODEC_CAP_DR1,
806 .long_name = NULL_IF_CONFIG_SMALL("Autodesk Animator Flic video"),