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++) {
154 void *
data,
int *got_frame,
162 unsigned char palette_idx1;
163 unsigned char palette_idx2;
168 unsigned int chunk_size;
176 unsigned char r,
g,
b;
179 int compressed_lines;
181 signed short line_packets;
187 unsigned int pixel_limit;
198 frame_size = bytestream2_get_le32(&g2);
199 if (frame_size > buf_size)
200 frame_size = buf_size;
202 num_chunks = bytestream2_get_le16(&g2);
211 while ((frame_size >= 6) && (num_chunks > 0) &&
213 int stream_ptr_after_chunk;
214 chunk_size = bytestream2_get_le32(&g2);
215 if (chunk_size > frame_size) {
217 "Invalid chunk_size = %u > frame_size = %u\n", chunk_size, frame_size);
222 chunk_type = bytestream2_get_le16(&g2);
224 switch (chunk_type) {
236 color_packets = bytestream2_get_le16(&g2);
238 for (i = 0; i < color_packets; i++) {
240 palette_ptr += bytestream2_get_byte(&g2);
243 color_changes = bytestream2_get_byte(&g2);
246 if (color_changes == 0)
252 for (j = 0; j < color_changes; j++) {
256 if ((
unsigned)palette_ptr >= 256)
259 r = bytestream2_get_byte(&g2) << color_shift;
260 g = bytestream2_get_byte(&g2) << color_shift;
261 b = bytestream2_get_byte(&g2) << color_shift;
262 entry = 0xFF
U << 24 | r << 16 | g << 8 |
b;
263 if (color_shift == 2)
264 entry |= entry >> 6 & 0x30303;
265 if (s->
palette[palette_ptr] != entry)
267 s->
palette[palette_ptr++] = entry;
274 compressed_lines = bytestream2_get_le16(&g2);
275 while (compressed_lines > 0) {
278 if (y_ptr > pixel_limit)
280 line_packets = bytestream2_get_le16(&g2);
281 if ((line_packets & 0xC000) == 0xC000) {
283 line_packets = -line_packets;
287 }
else if ((line_packets & 0xC000) == 0x4000) {
289 }
else if ((line_packets & 0xC000) == 0x8000) {
293 pixels[pixel_ptr] = line_packets & 0xff;
299 for (i = 0; i < line_packets; i++) {
303 pixel_skip = bytestream2_get_byte(&g2);
304 pixel_ptr += pixel_skip;
305 pixel_countdown -= pixel_skip;
306 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
308 byte_run = -byte_run;
309 palette_idx1 = bytestream2_get_byte(&g2);
310 palette_idx2 = bytestream2_get_byte(&g2);
312 for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
313 pixels[pixel_ptr++] = palette_idx1;
314 pixels[pixel_ptr++] = palette_idx2;
320 for (j = 0; j < byte_run * 2; j++, pixel_countdown--) {
321 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
333 starting_line = bytestream2_get_le16(&g2);
339 compressed_lines = bytestream2_get_le16(&g2);
340 while (compressed_lines > 0) {
346 line_packets = bytestream2_get_byte(&g2);
347 if (line_packets > 0) {
348 for (i = 0; i < line_packets; i++) {
352 pixel_skip = bytestream2_get_byte(&g2);
353 pixel_ptr += pixel_skip;
354 pixel_countdown -= pixel_skip;
355 byte_run =
sign_extend(bytestream2_get_byte(&g2),8);
360 for (j = 0; j < byte_run; j++, pixel_countdown--) {
361 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
363 }
else if (byte_run < 0) {
364 byte_run = -byte_run;
365 palette_idx1 = bytestream2_get_byte(&g2);
367 for (j = 0; j < byte_run; j++, pixel_countdown--) {
368 pixels[pixel_ptr++] = palette_idx1;
389 for (lines = 0; lines < s->
avctx->
height; lines++) {
395 while (pixel_countdown > 0) {
398 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
405 palette_idx1 = bytestream2_get_byte(&g2);
407 for (j = 0; j < byte_run; j++) {
408 pixels[pixel_ptr++] = palette_idx1;
410 if (pixel_countdown < 0)
412 pixel_countdown, lines);
415 byte_run = -byte_run;
419 for (j = 0; j < byte_run; j++) {
420 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
422 if (pixel_countdown < 0)
424 pixel_countdown, lines);
437 "has incorrect size, skipping chunk\n", chunk_size - 6);
460 frame_size -= chunk_size;
468 "and final chunk ptr = %d\n", buf_size,
487 void *
data,
int *got_frame,
496 unsigned char palette_idx1;
501 unsigned int chunk_size;
507 int compressed_lines;
508 signed short line_packets;
515 unsigned int pixel_limit;
525 frame_size = bytestream2_get_le32(&g2);
527 num_chunks = bytestream2_get_le16(&g2);
529 if (frame_size > buf_size)
530 frame_size = buf_size;
537 while ((frame_size > 0) && (num_chunks > 0) &&
539 int stream_ptr_after_chunk;
540 chunk_size = bytestream2_get_le32(&g2);
541 if (chunk_size > frame_size) {
543 "Invalid chunk_size = %u > frame_size = %u\n", chunk_size, frame_size);
548 chunk_type = bytestream2_get_le16(&g2);
551 switch (chunk_type) {
558 "Unexpected Palette chunk %d in non-palettized FLC\n",
566 compressed_lines = bytestream2_get_le16(&g2);
567 while (compressed_lines > 0) {
570 if (y_ptr > pixel_limit)
572 line_packets = bytestream2_get_le16(&g2);
573 if (line_packets < 0) {
574 line_packets = -line_packets;
583 for (i = 0; i < line_packets; i++) {
587 pixel_skip = bytestream2_get_byte(&g2);
588 pixel_ptr += (pixel_skip*2);
589 pixel_countdown -= pixel_skip;
590 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
592 byte_run = -byte_run;
593 pixel = bytestream2_get_le16(&g2);
595 for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
596 *((
signed short*)(&pixels[pixel_ptr])) = pixel;
603 for (j = 0; j < byte_run; j++, pixel_countdown--) {
604 *((
signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2);
622 memset(pixels, 0x0000,
628 for (lines = 0; lines < s->
avctx->
height; lines++) {
635 while (pixel_countdown > 0) {
638 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
640 palette_idx1 = bytestream2_get_byte(&g2);
642 for (j = 0; j < byte_run; j++) {
643 pixels[pixel_ptr++] = palette_idx1;
645 if (pixel_countdown < 0)
647 pixel_countdown, lines);
650 byte_run = -byte_run;
654 for (j = 0; j < byte_run; j++) {
655 palette_idx1 = bytestream2_get_byte(&g2);
656 pixels[pixel_ptr++] = palette_idx1;
658 if (pixel_countdown < 0)
660 pixel_countdown, lines);
673 while (pixel_countdown > 0) {
674 *((
signed short*)(&pixels[pixel_ptr])) =
AV_RL16(&buf[pixel_ptr]);
684 for (lines = 0; lines < s->
avctx->
height; lines++) {
691 while (pixel_countdown > 0) {
694 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
696 pixel = bytestream2_get_le16(&g2);
698 for (j = 0; j < byte_run; j++) {
699 *((
signed short*)(&pixels[pixel_ptr])) = pixel;
702 if (pixel_countdown < 0)
707 byte_run = -byte_run;
711 for (j = 0; j < byte_run; j++) {
712 *((
signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2);
715 if (pixel_countdown < 0)
731 "bigger than image, skipping chunk\n", chunk_size - 6);
740 while (pixel_countdown > 0) {
741 *((
signed short*)(&pixels[y_ptr + pixel_ptr])) = bytestream2_get_le16(&g2);
759 frame_size -= chunk_size;
778 void *
data,
int *got_frame,
786 void *
data,
int *got_frame,
790 int buf_size = avpkt->
size;
809 av_log(avctx,
AV_LOG_ERROR,
"Unknown FLC format, my science cannot explain how this happened.\n");
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
#define AV_LOG_WARNING
Something somehow does not look correct.
#define CHECK_PIXEL_PTR(n)
static av_cold int init(AVCodecContext *avctx)
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)
static int flic_decode_frame_15_16BPP(AVCodecContext *avctx, void *data, int *got_frame, const uint8_t *buf, int buf_size)
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.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
8 bit with AV_PIX_FMT_RGB32 palette
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
#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)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#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
const char * name
Name of the codec implementation.
Libavcodec external API header.
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...
int width
picture width / height.
#define FLC_FLX_TYPE_CODE
packed RGB 8:8:8, 24bpp, BGRBGR...
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static av_always_inline int bytestream2_tell(GetByteContext *g)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
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.
static av_const int sign_extend(int val, unsigned bits)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
common internal api header.
#define AV_PIX_FMT_RGB555
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
unsigned int palette[256]
#define AV_PIX_FMT_RGB565
This structure stores compressed data.
static av_cold int flic_decode_init(AVCodecContext *avctx)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.