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 av_log(avctx, AV_LOG_ERROR, "Expected extradata of 12 or 128 bytes\n");
90 return AVERROR_INVALIDDATA;
95 if (s->avctx->extradata_size == 12) {
96 /* special case for magic carpet FLIs */
97 s->fli_type = FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE;
99 } else if (avctx->extradata_size == 0) {
100 /* FLI in MOV, see e.g. FFmpeg trac issue #626 */
101 s->fli_type = FLI_TYPE_CODE;
104 s->fli_type = AV_RL16(&fli_header[4]);
105 depth = AV_RL16(&fli_header[12]);
109 depth = 8; /* Some FLC generators set depth to zero, when they mean 8Bpp. Fix up here */
112 if ((s->fli_type == FLC_FLX_TYPE_CODE) && (depth == 16)) {
113 depth = 15; /* Original Autodesk FLX's say the depth is 16Bpp when it is really 15Bpp */
117 case 8 : avctx->pix_fmt = PIX_FMT_PAL8; break;
118 case 15 : avctx->pix_fmt = PIX_FMT_RGB555; break;
119 case 16 : avctx->pix_fmt = PIX_FMT_RGB565; break;
120 case 24 : avctx->pix_fmt = PIX_FMT_BGR24; /* Supposedly BGR, but havent any files to test with */
121 av_log(avctx, AV_LOG_ERROR, "24Bpp FLC/FLX is unsupported due to no test files.\n");
124 av_log(avctx, AV_LOG_ERROR, "Unknown FLC/FLX depth of %d Bpp is unsupported.\n",depth);
128 avcodec_get_frame_defaults(&s->frame);
129 s->frame.data[0] = NULL;
135 static int flic_decode_frame_8BPP(AVCodecContext *avctx,
136 void *data, int *data_size,
137 const uint8_t *buf, int buf_size)
139 FlicDecodeContext *s = avctx->priv_data;
144 unsigned char palette_idx1;
145 unsigned char palette_idx2;
147 unsigned int frame_size;
150 unsigned int chunk_size;
158 unsigned char r, g, b;
161 int compressed_lines;
163 signed short line_packets;
168 unsigned char *pixels;
169 unsigned int pixel_limit;
171 bytestream2_init(&g2, buf, buf_size);
173 s->frame.reference = 3;
174 s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
175 if (avctx->reget_buffer(avctx, &s->frame) < 0) {
176 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
180 pixels = s->frame.data[0];
181 pixel_limit = s->avctx->height * s->frame.linesize[0];
182 if (buf_size < 16 || buf_size > INT_MAX - (3 * 256 + FF_INPUT_BUFFER_PADDING_SIZE))
183 return AVERROR_INVALIDDATA;
184 frame_size = bytestream2_get_le32(&g2);
185 if (frame_size > buf_size)
186 frame_size = buf_size;
187 bytestream2_skip(&g2, 2); /* skip the magic number */
188 num_chunks = bytestream2_get_le16(&g2);
189 bytestream2_skip(&g2, 8); /* skip padding */
193 /* iterate through the chunks */
194 while ((frame_size >= 6) && (num_chunks > 0)) {
195 int stream_ptr_after_chunk;
196 chunk_size = bytestream2_get_le32(&g2);
197 if (chunk_size > frame_size) {
198 av_log(avctx, AV_LOG_WARNING,
199 "Invalid chunk_size = %u > frame_size = %u\n", chunk_size, frame_size);
200 chunk_size = frame_size;
202 stream_ptr_after_chunk = bytestream2_tell(&g2) - 4 + chunk_size;
204 chunk_type = bytestream2_get_le16(&g2);
206 switch (chunk_type) {
209 /* check special case: If this file is from the Magic Carpet
210 * game and uses 6-bit colors even though it reports 256-color
211 * chunks in a 0xAF12-type file (fli_type is set to 0xAF13 during
213 if ((chunk_type == FLI_256_COLOR) && (s->fli_type != FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE))
217 /* set up the palette */
218 color_packets = bytestream2_get_le16(&g2);
220 for (i = 0; i < color_packets; i++) {
221 /* first byte is how many colors to skip */
222 palette_ptr += bytestream2_get_byte(&g2);
224 /* next byte indicates how many entries to change */
225 color_changes = bytestream2_get_byte(&g2);
227 /* if there are 0 color changes, there are actually 256 */
228 if (color_changes == 0)
231 if (bytestream2_tell(&g2) + color_changes * 3 > stream_ptr_after_chunk)
234 for (j = 0; j < color_changes; j++) {
237 /* wrap around, for good measure */
238 if ((unsigned)palette_ptr >= 256)
241 r = bytestream2_get_byte(&g2) << color_shift;
242 g = bytestream2_get_byte(&g2) << color_shift;
243 b = bytestream2_get_byte(&g2) << color_shift;
244 entry = 0xFF << 24 | r << 16 | g << 8 | b;
245 if (color_shift == 2)
246 entry |= entry >> 6 & 0x30303;
247 if (s->palette[palette_ptr] != entry)
249 s->palette[palette_ptr++] = entry;
256 compressed_lines = bytestream2_get_le16(&g2);
257 while (compressed_lines > 0) {
258 if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk)
260 line_packets = bytestream2_get_le16(&g2);
261 if ((line_packets & 0xC000) == 0xC000) {
263 line_packets = -line_packets;
264 y_ptr += line_packets * s->frame.linesize[0];
265 } else if ((line_packets & 0xC000) == 0x4000) {
266 av_log(avctx, AV_LOG_ERROR, "Undefined opcode (%x) in DELTA_FLI\n", line_packets);
267 } else if ((line_packets & 0xC000) == 0x8000) {
268 // "last byte" opcode
269 pixel_ptr= y_ptr + s->frame.linesize[0] - 1;
271 pixels[pixel_ptr] = line_packets & 0xff;
276 pixel_countdown = s->avctx->width;
277 for (i = 0; i < line_packets; i++) {
278 if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk)
280 /* account for the skip bytes */
281 pixel_skip = bytestream2_get_byte(&g2);
282 pixel_ptr += pixel_skip;
283 pixel_countdown -= pixel_skip;
284 byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
286 byte_run = -byte_run;
287 palette_idx1 = bytestream2_get_byte(&g2);
288 palette_idx2 = bytestream2_get_byte(&g2);
289 CHECK_PIXEL_PTR(byte_run * 2);
290 for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
291 pixels[pixel_ptr++] = palette_idx1;
292 pixels[pixel_ptr++] = palette_idx2;
295 CHECK_PIXEL_PTR(byte_run * 2);
296 if (bytestream2_tell(&g2) + byte_run * 2 > stream_ptr_after_chunk)
298 for (j = 0; j < byte_run * 2; j++, pixel_countdown--) {
299 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
304 y_ptr += s->frame.linesize[0];
310 /* line compressed */
311 starting_line = bytestream2_get_le16(&g2);
313 y_ptr += starting_line * s->frame.linesize[0];
315 compressed_lines = bytestream2_get_le16(&g2);
316 while (compressed_lines > 0) {
319 pixel_countdown = s->avctx->width;
320 if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
322 line_packets = bytestream2_get_byte(&g2);
323 if (line_packets > 0) {
324 for (i = 0; i < line_packets; i++) {
325 /* account for the skip bytes */
326 if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
328 pixel_skip = bytestream2_get_byte(&g2);
329 pixel_ptr += pixel_skip;
330 pixel_countdown -= pixel_skip;
331 byte_run = sign_extend(bytestream2_get_byte(&g2),8);
333 CHECK_PIXEL_PTR(byte_run);
334 if (bytestream2_tell(&g2) + byte_run > stream_ptr_after_chunk)
336 for (j = 0; j < byte_run; j++, pixel_countdown--) {
337 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
339 } else if (byte_run < 0) {
340 byte_run = -byte_run;
341 palette_idx1 = bytestream2_get_byte(&g2);
342 CHECK_PIXEL_PTR(byte_run);
343 for (j = 0; j < byte_run; j++, pixel_countdown--) {
344 pixels[pixel_ptr++] = palette_idx1;
350 y_ptr += s->frame.linesize[0];
356 /* set the whole frame to color 0 (which is usually black) */
358 s->frame.linesize[0] * s->avctx->height);
362 /* Byte run compression: This chunk type only occurs in the first
363 * FLI frame and it will update the entire frame. */
365 for (lines = 0; lines < s->avctx->height; lines++) {
367 /* disregard the line packets; instead, iterate through all
369 bytestream2_skip(&g2, 1);
370 pixel_countdown = s->avctx->width;
371 while (pixel_countdown > 0) {
372 if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
374 byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
376 palette_idx1 = bytestream2_get_byte(&g2);
377 CHECK_PIXEL_PTR(byte_run);
378 for (j = 0; j < byte_run; j++) {
379 pixels[pixel_ptr++] = palette_idx1;
381 if (pixel_countdown < 0)
382 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) at line %d\n",
383 pixel_countdown, lines);
385 } else { /* copy bytes if byte_run < 0 */
386 byte_run = -byte_run;
387 CHECK_PIXEL_PTR(byte_run);
388 if (bytestream2_tell(&g2) + byte_run > stream_ptr_after_chunk)
390 for (j = 0; j < byte_run; j++) {
391 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
393 if (pixel_countdown < 0)
394 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) at line %d\n",
395 pixel_countdown, lines);
400 y_ptr += s->frame.linesize[0];
405 /* copy the chunk (uncompressed frame) */
406 if (chunk_size - 6 != s->avctx->width * s->avctx->height) {
407 av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \
408 "has incorrect size, skipping chunk\n", chunk_size - 6);
409 bytestream2_skip(&g2, chunk_size - 6);
411 for (y_ptr = 0; y_ptr < s->frame.linesize[0] * s->avctx->height;
412 y_ptr += s->frame.linesize[0]) {
413 bytestream2_get_buffer(&g2, &pixels[y_ptr],
420 /* some sort of a thumbnail? disregard this chunk... */
424 av_log(avctx, AV_LOG_ERROR, "Unrecognized chunk type: %d\n", chunk_type);
428 if (stream_ptr_after_chunk - bytestream2_tell(&g2) > 0)
429 bytestream2_skip(&g2, stream_ptr_after_chunk - bytestream2_tell(&g2));
431 frame_size -= chunk_size;
435 /* by the end of the chunk, the stream ptr should equal the frame
436 * size (minus 1, possibly); if it doesn't, issue a warning */
437 if ((bytestream2_get_bytes_left(&g2) != 0) &&
438 (bytestream2_get_bytes_left(&g2) != 1))
439 av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \
440 "and final chunk ptr = %d\n", buf_size,
441 buf_size - bytestream2_get_bytes_left(&g2));
443 /* make the palette available on the way out */
444 memcpy(s->frame.data[1], s->palette, AVPALETTE_SIZE);
445 if (s->new_palette) {
446 s->frame.palette_has_changed = 1;
450 *data_size=sizeof(AVFrame);
451 *(AVFrame*)data = s->frame;
456 static int flic_decode_frame_15_16BPP(AVCodecContext *avctx,
457 void *data, int *data_size,
458 const uint8_t *buf, int buf_size)
460 /* Note, the only difference between the 15Bpp and 16Bpp */
461 /* Format is the pixel format, the packets are processed the same. */
462 FlicDecodeContext *s = avctx->priv_data;
466 unsigned char palette_idx1;
468 unsigned int frame_size;
471 unsigned int chunk_size;
477 int compressed_lines;
478 signed short line_packets;
483 unsigned char *pixels;
485 unsigned int pixel_limit;
487 bytestream2_init(&g2, buf, buf_size);
489 s->frame.reference = 3;
490 s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
491 if (avctx->reget_buffer(avctx, &s->frame) < 0) {
492 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
496 pixels = s->frame.data[0];
497 pixel_limit = s->avctx->height * s->frame.linesize[0];
499 frame_size = bytestream2_get_le32(&g2);
500 bytestream2_skip(&g2, 2); /* skip the magic number */
501 num_chunks = bytestream2_get_le16(&g2);
502 bytestream2_skip(&g2, 8); /* skip padding */
503 if (frame_size > buf_size)
504 frame_size = buf_size;
508 /* iterate through the chunks */
509 while ((frame_size > 0) && (num_chunks > 0)) {
510 int stream_ptr_after_chunk;
511 chunk_size = bytestream2_get_le32(&g2);
512 if (chunk_size > frame_size) {
513 av_log(avctx, AV_LOG_WARNING,
514 "Invalid chunk_size = %u > frame_size = %u\n", chunk_size, frame_size);
515 chunk_size = frame_size;
517 stream_ptr_after_chunk = bytestream2_tell(&g2) - 4 + chunk_size;
519 chunk_type = bytestream2_get_le16(&g2);
522 switch (chunk_type) {
525 /* For some reason, it seems that non-palettized flics do
526 * include one of these chunks in their first frame.
527 * Why I do not know, it seems rather extraneous. */
528 /* av_log(avctx, AV_LOG_ERROR, "Unexpected Palette chunk %d in non-paletised FLC\n",chunk_type);*/
529 bytestream2_skip(&g2, chunk_size - 6);
535 compressed_lines = bytestream2_get_le16(&g2);
536 while (compressed_lines > 0) {
537 if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk)
539 line_packets = bytestream2_get_le16(&g2);
540 if (line_packets < 0) {
541 line_packets = -line_packets;
542 y_ptr += line_packets * s->frame.linesize[0];
547 pixel_countdown = s->avctx->width;
548 for (i = 0; i < line_packets; i++) {
549 /* account for the skip bytes */
550 if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk)
552 pixel_skip = bytestream2_get_byte(&g2);
553 pixel_ptr += (pixel_skip*2); /* Pixel is 2 bytes wide */
554 pixel_countdown -= pixel_skip;
555 byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
557 byte_run = -byte_run;
558 pixel = bytestream2_get_le16(&g2);
559 CHECK_PIXEL_PTR(2 * byte_run);
560 for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
561 *((signed short*)(&pixels[pixel_ptr])) = pixel;
565 if (bytestream2_tell(&g2) + 2*byte_run > stream_ptr_after_chunk)
567 CHECK_PIXEL_PTR(2 * byte_run);
568 for (j = 0; j < byte_run; j++, pixel_countdown--) {
569 *((signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2);
575 y_ptr += s->frame.linesize[0];
581 av_log(avctx, AV_LOG_ERROR, "Unexpected FLI_LC chunk in non-paletised FLC\n");
582 bytestream2_skip(&g2, chunk_size - 6);
586 /* set the whole frame to 0x0000 which is black in both 15Bpp and 16Bpp modes. */
587 memset(pixels, 0x0000,
588 s->frame.linesize[0] * s->avctx->height);
593 for (lines = 0; lines < s->avctx->height; lines++) {
595 /* disregard the line packets; instead, iterate through all
597 bytestream2_skip(&g2, 1);
598 pixel_countdown = (s->avctx->width * 2);
600 while (pixel_countdown > 0) {
601 if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
603 byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
605 palette_idx1 = bytestream2_get_byte(&g2);
606 CHECK_PIXEL_PTR(byte_run);
607 for (j = 0; j < byte_run; j++) {
608 pixels[pixel_ptr++] = palette_idx1;
610 if (pixel_countdown < 0)
611 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) (linea%d)\n",
612 pixel_countdown, lines);
614 } else { /* copy bytes if byte_run < 0 */
615 byte_run = -byte_run;
616 if (bytestream2_tell(&g2) + byte_run > stream_ptr_after_chunk)
618 CHECK_PIXEL_PTR(byte_run);
619 for (j = 0; j < byte_run; j++) {
620 palette_idx1 = bytestream2_get_byte(&g2);
621 pixels[pixel_ptr++] = palette_idx1;
623 if (pixel_countdown < 0)
624 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) at line %d\n",
625 pixel_countdown, lines);
630 /* Now FLX is strange, in that it is "byte" as opposed to "pixel" run length compressed.
631 * This does not give us any good oportunity to perform word endian conversion
632 * during decompression. So if it is required (i.e., this is not a LE target, we do
633 * a second pass over the line here, swapping the bytes.
637 pixel_countdown = s->avctx->width;
638 while (pixel_countdown > 0) {
639 *((signed short*)(&pixels[pixel_ptr])) = AV_RL16(&buf[pixel_ptr]);
643 y_ptr += s->frame.linesize[0];
649 for (lines = 0; lines < s->avctx->height; lines++) {
651 /* disregard the line packets; instead, iterate through all
653 bytestream2_skip(&g2, 1);
654 pixel_countdown = s->avctx->width; /* Width is in pixels, not bytes */
656 while (pixel_countdown > 0) {
657 if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk)
659 byte_run = sign_extend(bytestream2_get_byte(&g2), 8);
661 pixel = bytestream2_get_le16(&g2);
662 CHECK_PIXEL_PTR(2 * byte_run);
663 for (j = 0; j < byte_run; j++) {
664 *((signed short*)(&pixels[pixel_ptr])) = pixel;
667 if (pixel_countdown < 0)
668 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n",
671 } else { /* copy pixels if byte_run < 0 */
672 byte_run = -byte_run;
673 if (bytestream2_tell(&g2) + 2 * byte_run > stream_ptr_after_chunk)
675 CHECK_PIXEL_PTR(2 * byte_run);
676 for (j = 0; j < byte_run; j++) {
677 *((signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2);
680 if (pixel_countdown < 0)
681 av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n",
687 y_ptr += s->frame.linesize[0];
693 /* copy the chunk (uncompressed frame) */
694 if (chunk_size - 6 > (unsigned int)(s->avctx->width * s->avctx->height)*2) {
695 av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \
696 "bigger than image, skipping chunk\n", chunk_size - 6);
697 bytestream2_skip(&g2, chunk_size - 6);
700 for (y_ptr = 0; y_ptr < s->frame.linesize[0] * s->avctx->height;
701 y_ptr += s->frame.linesize[0]) {
703 pixel_countdown = s->avctx->width;
705 while (pixel_countdown > 0) {
706 *((signed short*)(&pixels[y_ptr + pixel_ptr])) = bytestream2_get_le16(&g2);
715 /* some sort of a thumbnail? disregard this chunk... */
716 bytestream2_skip(&g2, chunk_size - 6);
720 av_log(avctx, AV_LOG_ERROR, "Unrecognized chunk type: %d\n", chunk_type);
724 frame_size -= chunk_size;
728 /* by the end of the chunk, the stream ptr should equal the frame
729 * size (minus 1, possibly); if it doesn't, issue a warning */
730 if ((bytestream2_get_bytes_left(&g2) != 0) && (bytestream2_get_bytes_left(&g2) != 1))
731 av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \
732 "and final chunk ptr = %d\n", buf_size, bytestream2_tell(&g2));
735 *data_size=sizeof(AVFrame);
736 *(AVFrame*)data = s->frame;
741 static int flic_decode_frame_24BPP(AVCodecContext *avctx,
742 void *data, int *data_size,
743 const uint8_t *buf, int buf_size)
745 av_log(avctx, AV_LOG_ERROR, "24Bpp FLC Unsupported due to lack of test files.\n");
749 static int flic_decode_frame(AVCodecContext *avctx,
750 void *data, int *data_size,
753 const uint8_t *buf = avpkt->data;
754 int buf_size = avpkt->size;
755 if (avctx->pix_fmt == PIX_FMT_PAL8) {
756 return flic_decode_frame_8BPP(avctx, data, data_size,
759 else if ((avctx->pix_fmt == PIX_FMT_RGB555) ||
760 (avctx->pix_fmt == PIX_FMT_RGB565)) {
761 return flic_decode_frame_15_16BPP(avctx, data, data_size,
764 else if (avctx->pix_fmt == PIX_FMT_BGR24) {
765 return flic_decode_frame_24BPP(avctx, data, data_size,
769 /* Should not get here, ever as the pix_fmt is processed */
770 /* in flic_decode_init and the above if should deal with */
771 /* the finite set of possibilites allowable by here. */
772 /* But in case we do, just error out. */
773 av_log(avctx, AV_LOG_ERROR, "Unknown FLC format, my science cannot explain how this happened.\n");
778 static av_cold int flic_decode_end(AVCodecContext *avctx)
780 FlicDecodeContext *s = avctx->priv_data;
782 if (s->frame.data[0])
783 avctx->release_buffer(avctx, &s->frame);
788 AVCodec ff_flic_decoder = {
790 .type = AVMEDIA_TYPE_VIDEO,
792 .priv_data_size = sizeof(FlicDecodeContext),
793 .init = flic_decode_init,
794 .close = flic_decode_end,
795 .decode = flic_decode_frame,
796 .capabilities = CODEC_CAP_DR1,
797 .long_name = NULL_IF_CONFIG_SMALL("Autodesk Animator Flic video"),