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_INFO, "Problem: pixel_ptr >= pixel_limit (%d >= %d)\n", \ 68 pixel_ptr + n, pixel_limit); \ 69 return AVERROR_INVALIDDATA; \ 84 unsigned char *fli_header = (
unsigned char *)avctx->
extradata;
103 depth =
AV_RL16(&fli_header[12]);
122 av_log(avctx,
AV_LOG_ERROR,
"Unknown FLC/FLX depth of %d Bpp is unsupported.\n",depth);
136 void *
data,
int *got_frame,
137 const uint8_t *buf,
int buf_size)
142 int stream_ptr_after_color_chunk;
145 unsigned char palette_idx1;
146 unsigned char palette_idx2;
151 unsigned int chunk_size;
159 unsigned char r,
g,
b;
162 int compressed_lines;
164 signed short line_packets;
169 unsigned char *pixels;
170 unsigned int pixel_limit;
181 frame_size = bytestream2_get_le32(&g2);
183 num_chunks = bytestream2_get_le16(&g2);
189 while ((frame_size > 0) && (num_chunks > 0)) {
190 chunk_size = bytestream2_get_le32(&g2);
191 chunk_type = bytestream2_get_le16(&g2);
193 switch (chunk_type) {
207 color_packets = bytestream2_get_le16(&g2);
209 for (i = 0; i < color_packets; i++) {
211 palette_ptr += bytestream2_get_byte(&g2);
214 color_changes = bytestream2_get_byte(&g2);
217 if (color_changes == 0)
220 for (j = 0; j < color_changes; j++) {
224 if ((
unsigned)palette_ptr >= 256)
227 r = bytestream2_get_byte(&g2) << color_shift;
228 g = bytestream2_get_byte(&g2) << color_shift;
229 b = bytestream2_get_byte(&g2) << color_shift;
230 entry = (r << 16) | (g << 8) |
b;
231 if (s->
palette[palette_ptr] != entry)
233 s->
palette[palette_ptr++] = entry;
248 compressed_lines = bytestream2_get_le16(&g2);
249 while (compressed_lines > 0) {
250 line_packets = bytestream2_get_le16(&g2);
251 if ((line_packets & 0xC000) == 0xC000) {
253 line_packets = -line_packets;
255 }
else if ((line_packets & 0xC000) == 0x4000) {
257 }
else if ((line_packets & 0xC000) == 0x8000) {
261 pixels[pixel_ptr] = line_packets & 0xff;
267 for (i = 0; i < line_packets; i++) {
269 pixel_skip = bytestream2_get_byte(&g2);
270 pixel_ptr += pixel_skip;
271 pixel_countdown -= pixel_skip;
272 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
274 byte_run = -byte_run;
275 palette_idx1 = bytestream2_get_byte(&g2);
276 palette_idx2 = bytestream2_get_byte(&g2);
278 for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
279 pixels[pixel_ptr++] = palette_idx1;
280 pixels[pixel_ptr++] = palette_idx2;
284 for (j = 0; j < byte_run * 2; j++, pixel_countdown--) {
285 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
297 starting_line = bytestream2_get_le16(&g2);
301 compressed_lines = bytestream2_get_le16(&g2);
302 while (compressed_lines > 0) {
306 line_packets = bytestream2_get_byte(&g2);
307 if (line_packets > 0) {
308 for (i = 0; i < line_packets; i++) {
310 pixel_skip = bytestream2_get_byte(&g2);
311 pixel_ptr += pixel_skip;
312 pixel_countdown -= pixel_skip;
313 byte_run =
sign_extend(bytestream2_get_byte(&g2),8);
316 for (j = 0; j < byte_run; j++, pixel_countdown--) {
317 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
319 }
else if (byte_run < 0) {
320 byte_run = -byte_run;
321 palette_idx1 = bytestream2_get_byte(&g2);
323 for (j = 0; j < byte_run; j++, pixel_countdown--) {
324 pixels[pixel_ptr++] = palette_idx1;
345 for (lines = 0; lines < s->
avctx->
height; lines++) {
351 while (pixel_countdown > 0) {
352 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
359 palette_idx1 = bytestream2_get_byte(&g2);
361 for (j = 0; j < byte_run; j++) {
362 pixels[pixel_ptr++] = palette_idx1;
364 if (pixel_countdown < 0)
366 pixel_countdown, lines);
369 byte_run = -byte_run;
371 for (j = 0; j < byte_run; j++) {
372 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
374 if (pixel_countdown < 0)
376 pixel_countdown, lines);
389 "bigger than image, skipping chunk\n", chunk_size - 6);
410 frame_size -= chunk_size;
419 "and final chunk ptr = %d\n", buf_size,
438 void *
data,
int *got_frame,
439 const uint8_t *buf,
int buf_size)
447 unsigned char palette_idx1;
452 unsigned int chunk_size;
458 int compressed_lines;
459 signed short line_packets;
464 unsigned char *pixels;
466 unsigned int pixel_limit;
478 frame_size = bytestream2_get_le32(&g2);
480 num_chunks = bytestream2_get_le16(&g2);
486 while ((frame_size > 0) && (num_chunks > 0)) {
487 chunk_size = bytestream2_get_le32(&g2);
488 chunk_type = bytestream2_get_le16(&g2);
490 switch (chunk_type) {
497 "Unexpected Palette chunk %d in non-palettized FLC\n",
505 compressed_lines = bytestream2_get_le16(&g2);
506 while (compressed_lines > 0) {
507 line_packets = bytestream2_get_le16(&g2);
508 if (line_packets < 0) {
509 line_packets = -line_packets;
516 for (i = 0; i < line_packets; i++) {
518 pixel_skip = bytestream2_get_byte(&g2);
519 pixel_ptr += (pixel_skip*2);
520 pixel_countdown -= pixel_skip;
521 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
523 byte_run = -byte_run;
524 pixel = bytestream2_get_le16(&g2);
526 for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
527 *((
signed short*)(&pixels[pixel_ptr])) = pixel;
532 for (j = 0; j < byte_run; j++, pixel_countdown--) {
533 *((
signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2);
551 memset(pixels, 0x0000,
557 for (lines = 0; lines < s->
avctx->
height; lines++) {
564 while (pixel_countdown > 0) {
565 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
567 palette_idx1 = bytestream2_get_byte(&g2);
569 for (j = 0; j < byte_run; j++) {
570 pixels[pixel_ptr++] = palette_idx1;
572 if (pixel_countdown < 0)
574 pixel_countdown, lines);
577 byte_run = -byte_run;
579 for (j = 0; j < byte_run; j++) {
580 palette_idx1 = bytestream2_get_byte(&g2);
581 pixels[pixel_ptr++] = palette_idx1;
583 if (pixel_countdown < 0)
585 pixel_countdown, lines);
598 while (pixel_countdown > 0) {
599 *((
signed short*)(&pixels[pixel_ptr])) =
AV_RL16(&buf[pixel_ptr]);
609 for (lines = 0; lines < s->
avctx->
height; lines++) {
616 while (pixel_countdown > 0) {
617 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
619 pixel = bytestream2_get_le16(&g2);
621 for (j = 0; j < byte_run; j++) {
622 *((
signed short*)(&pixels[pixel_ptr])) = pixel;
625 if (pixel_countdown < 0)
630 byte_run = -byte_run;
632 for (j = 0; j < byte_run; j++) {
633 *((
signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2);
636 if (pixel_countdown < 0)
652 "bigger than image, skipping chunk\n", chunk_size - 6);
661 while (pixel_countdown > 0) {
662 *((
signed short*)(&pixels[y_ptr + pixel_ptr])) = bytestream2_get_le16(&g2);
680 frame_size -= chunk_size;
699 void *
data,
int *got_frame,
700 const uint8_t *buf,
int buf_size)
707 void *
data,
int *got_frame,
711 int buf_size = avpkt->
size;
730 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.
#define CHECK_PIXEL_PTR(n)
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)
av_dlog(ac->avr, "%d samples - audio_convert: %s to %s (%s)\, 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_8BPP(AVCodecContext *avctx, void *data, int *got_frame, const uint8_t *buf, int buf_size)
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
8 bit with 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 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)
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
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
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...
if(ac->has_optimized_func)
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
static av_always_inline int bytestream2_tell(GetByteContext *g)
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
static void close(AVCodecParserContext *s)
#define AVERROR_BUG
Bug detected, please report the issue.
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.
common internal api header.
#define AV_PIX_FMT_RGB555
static av_cold int init(AVCodecParserContext *s)
unsigned int palette[256]
#define AV_PIX_FMT_RGB565
This structure stores compressed data.
static av_cold int flic_decode_init(AVCodecContext *avctx)