42 #include "libavutil/intreadwrite.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)
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; \
84 unsigned char *fli_header = (
unsigned char *)avctx->
extradata;
107 for (i = 0; i < 256; i++) {
151 void *
data,
int *got_frame,
159 unsigned char palette_idx1;
160 unsigned char palette_idx2;
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;
195 frame_size = bytestream2_get_le32(&g2);
196 if (frame_size > buf_size)
197 frame_size = buf_size;
199 num_chunks = bytestream2_get_le16(&g2);
205 while ((frame_size >= 6) && (num_chunks > 0) &&
207 int stream_ptr_after_chunk;
208 chunk_size = bytestream2_get_le32(&g2);
209 if (chunk_size > frame_size) {
211 "Invalid chunk_size = %u > frame_size = %u\n", chunk_size, frame_size);
216 chunk_type = bytestream2_get_le16(&g2);
218 switch (chunk_type) {
230 color_packets = bytestream2_get_le16(&g2);
232 for (i = 0; i < color_packets; i++) {
234 palette_ptr += bytestream2_get_byte(&g2);
237 color_changes = bytestream2_get_byte(&g2);
240 if (color_changes == 0)
246 for (j = 0; j < color_changes; j++) {
250 if ((
unsigned)palette_ptr >= 256)
253 r = bytestream2_get_byte(&g2) << color_shift;
254 g = bytestream2_get_byte(&g2) << color_shift;
255 b = bytestream2_get_byte(&g2) << color_shift;
256 entry = 0xFF
U << 24 | r << 16 | g << 8 |
b;
257 if (color_shift == 2)
258 entry |= entry >> 6 & 0x30303;
259 if (s->
palette[palette_ptr] != entry)
261 s->
palette[palette_ptr++] = entry;
268 compressed_lines = bytestream2_get_le16(&g2);
269 while (compressed_lines > 0) {
272 line_packets = bytestream2_get_le16(&g2);
273 if ((line_packets & 0xC000) == 0xC000) {
275 line_packets = -line_packets;
277 }
else if ((line_packets & 0xC000) == 0x4000) {
279 }
else if ((line_packets & 0xC000) == 0x8000) {
283 pixels[pixel_ptr] = line_packets & 0xff;
289 for (i = 0; i < line_packets; i++) {
293 pixel_skip = bytestream2_get_byte(&g2);
294 pixel_ptr += pixel_skip;
295 pixel_countdown -= pixel_skip;
296 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
298 byte_run = -byte_run;
299 palette_idx1 = bytestream2_get_byte(&g2);
300 palette_idx2 = bytestream2_get_byte(&g2);
302 for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
303 pixels[pixel_ptr++] = palette_idx1;
304 pixels[pixel_ptr++] = palette_idx2;
310 for (j = 0; j < byte_run * 2; j++, pixel_countdown--) {
311 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
323 starting_line = bytestream2_get_le16(&g2);
327 compressed_lines = bytestream2_get_le16(&g2);
328 while (compressed_lines > 0) {
334 line_packets = bytestream2_get_byte(&g2);
335 if (line_packets > 0) {
336 for (i = 0; i < line_packets; i++) {
340 pixel_skip = bytestream2_get_byte(&g2);
341 pixel_ptr += pixel_skip;
342 pixel_countdown -= pixel_skip;
343 byte_run =
sign_extend(bytestream2_get_byte(&g2),8);
348 for (j = 0; j < byte_run; j++, pixel_countdown--) {
349 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
351 }
else if (byte_run < 0) {
352 byte_run = -byte_run;
353 palette_idx1 = bytestream2_get_byte(&g2);
355 for (j = 0; j < byte_run; j++, pixel_countdown--) {
356 pixels[pixel_ptr++] = palette_idx1;
377 for (lines = 0; lines < s->
avctx->
height; lines++) {
383 while (pixel_countdown > 0) {
386 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
393 palette_idx1 = bytestream2_get_byte(&g2);
395 for (j = 0; j < byte_run; j++) {
396 pixels[pixel_ptr++] = palette_idx1;
398 if (pixel_countdown < 0)
400 pixel_countdown, lines);
403 byte_run = -byte_run;
407 for (j = 0; j < byte_run; j++) {
408 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
410 if (pixel_countdown < 0)
412 pixel_countdown, lines);
425 "has incorrect size, skipping chunk\n", chunk_size - 6);
448 frame_size -= chunk_size;
456 "and final chunk ptr = %d\n", buf_size,
475 void *
data,
int *got_frame,
484 unsigned char palette_idx1;
489 unsigned int chunk_size;
495 int compressed_lines;
496 signed short line_packets;
501 unsigned char *pixels;
503 unsigned int pixel_limit;
513 frame_size = bytestream2_get_le32(&g2);
515 num_chunks = bytestream2_get_le16(&g2);
517 if (frame_size > buf_size)
518 frame_size = buf_size;
523 while ((frame_size > 0) && (num_chunks > 0) &&
525 int stream_ptr_after_chunk;
526 chunk_size = bytestream2_get_le32(&g2);
527 if (chunk_size > frame_size) {
529 "Invalid chunk_size = %u > frame_size = %u\n", chunk_size, frame_size);
534 chunk_type = bytestream2_get_le16(&g2);
537 switch (chunk_type) {
544 "Unexpected Palette chunk %d in non-palettized FLC\n",
552 compressed_lines = bytestream2_get_le16(&g2);
553 while (compressed_lines > 0) {
556 line_packets = bytestream2_get_le16(&g2);
557 if (line_packets < 0) {
558 line_packets = -line_packets;
565 for (i = 0; i < line_packets; i++) {
569 pixel_skip = bytestream2_get_byte(&g2);
570 pixel_ptr += (pixel_skip*2);
571 pixel_countdown -= pixel_skip;
572 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
574 byte_run = -byte_run;
575 pixel = bytestream2_get_le16(&g2);
577 for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
578 *((
signed short*)(&pixels[pixel_ptr])) = pixel;
585 for (j = 0; j < byte_run; j++, pixel_countdown--) {
586 *((
signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2);
604 memset(pixels, 0x0000,
610 for (lines = 0; lines < s->
avctx->
height; lines++) {
617 while (pixel_countdown > 0) {
620 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
622 palette_idx1 = bytestream2_get_byte(&g2);
624 for (j = 0; j < byte_run; j++) {
625 pixels[pixel_ptr++] = palette_idx1;
627 if (pixel_countdown < 0)
629 pixel_countdown, lines);
632 byte_run = -byte_run;
636 for (j = 0; j < byte_run; j++) {
637 palette_idx1 = bytestream2_get_byte(&g2);
638 pixels[pixel_ptr++] = palette_idx1;
640 if (pixel_countdown < 0)
642 pixel_countdown, lines);
655 while (pixel_countdown > 0) {
656 *((
signed short*)(&pixels[pixel_ptr])) =
AV_RL16(&buf[pixel_ptr]);
666 for (lines = 0; lines < s->
avctx->
height; lines++) {
673 while (pixel_countdown > 0) {
676 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
678 pixel = bytestream2_get_le16(&g2);
680 for (j = 0; j < byte_run; j++) {
681 *((
signed short*)(&pixels[pixel_ptr])) = pixel;
684 if (pixel_countdown < 0)
689 byte_run = -byte_run;
693 for (j = 0; j < byte_run; j++) {
694 *((
signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2);
697 if (pixel_countdown < 0)
713 "bigger than image, skipping chunk\n", chunk_size - 6);
722 while (pixel_countdown > 0) {
723 *((
signed short*)(&pixels[y_ptr + pixel_ptr])) = bytestream2_get_le16(&g2);
741 frame_size -= chunk_size;
760 void *
data,
int *got_frame,
768 void *
data,
int *got_frame,
772 int buf_size = avpkt->
size;
791 av_log(avctx,
AV_LOG_ERROR,
"Unknown FLC format, my science cannot explain how this happened.\n");
#define AVERROR_PATCHWELCOME
This structure describes decoded (raw) audio or video data.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define CHECK_PIXEL_PTR(n)
static av_cold int init(AVCodecContext *avctx)
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
static int flic_decode_frame_15_16BPP(AVCodecContext *avctx, void *data, int *got_frame, const uint8_t *buf, int buf_size)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
packed RGB 8:8:8, 24bpp, BGRBGR...
static int flic_decode_frame_8BPP(AVCodecContext *avctx, void *data, int *got_frame, const uint8_t *buf, int buf_size)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define AV_PIX_FMT_RGB555
const char * name
Name of the codec implementation.
int av_frame_ref(AVFrame *dst, AVFrame *src)
Setup a new reference to the data described by a given frame.
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static const uint8_t frame_size[4]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int flic_decode_frame_24BPP(AVCodecContext *avctx, void *data, int *got_frame, const uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
#define FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE
Libavcodec external API header.
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame)
Identical in function to av_frame_make_writable(), except it uses ff_get_buffer() to allocate the buf...
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int width
picture width / height.
#define FLC_FLX_TYPE_CODE
static av_always_inline int bytestream2_tell(GetByteContext *g)
main external API structure.
#define AV_PIX_FMT_RGB565
static void close(AVCodecParserContext *s)
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
static int flic_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static av_cold int flic_decode_end(AVCodecContext *avctx)
int palette_has_changed
Tell user application that palette has changed from previous frame.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static av_const int sign_extend(int val, unsigned bits)
common internal api header.
#define AVERROR_INVALIDDATA
unsigned int palette[256]
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
8 bit with PIX_FMT_RGB32 palette
This structure stores compressed data.
static av_cold int flic_decode_init(AVCodecContext *avctx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.