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)
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_INFO, "Problem: pixel_ptr >= pixel_limit (%d >= %d)\n", \
67 pixel_ptr + n, pixel_limit); \
83 unsigned char *fli_header = (
unsigned char *)avctx->
extradata;
102 depth =
AV_RL16(&fli_header[12]);
121 av_log(avctx,
AV_LOG_ERROR,
"Unknown FLC/FLX depth of %d Bpp is unsupported.\n",depth);
132 void *
data,
int *got_frame,
133 const uint8_t *buf,
int buf_size)
138 int stream_ptr_after_color_chunk;
141 unsigned char palette_idx1;
142 unsigned char palette_idx2;
147 unsigned int chunk_size;
155 unsigned char r,
g,
b;
158 int compressed_lines;
160 signed short line_packets;
165 unsigned char *pixels;
166 unsigned int pixel_limit;
179 frame_size = bytestream2_get_le32(&g2);
181 num_chunks = bytestream2_get_le16(&g2);
187 while ((frame_size > 0) && (num_chunks > 0)) {
188 chunk_size = bytestream2_get_le32(&g2);
189 chunk_type = bytestream2_get_le16(&g2);
191 switch (chunk_type) {
205 color_packets = bytestream2_get_le16(&g2);
207 for (i = 0; i < color_packets; i++) {
209 palette_ptr += bytestream2_get_byte(&g2);
212 color_changes = bytestream2_get_byte(&g2);
215 if (color_changes == 0)
218 for (j = 0; j < color_changes; j++) {
222 if ((
unsigned)palette_ptr >= 256)
225 r = bytestream2_get_byte(&g2) << color_shift;
226 g = bytestream2_get_byte(&g2) << color_shift;
227 b = bytestream2_get_byte(&g2) << color_shift;
228 entry = (r << 16) | (g << 8) |
b;
229 if (s->
palette[palette_ptr] != entry)
231 s->
palette[palette_ptr++] = entry;
246 compressed_lines = bytestream2_get_le16(&g2);
247 while (compressed_lines > 0) {
248 line_packets = bytestream2_get_le16(&g2);
249 if ((line_packets & 0xC000) == 0xC000) {
251 line_packets = -line_packets;
253 }
else if ((line_packets & 0xC000) == 0x4000) {
255 }
else if ((line_packets & 0xC000) == 0x8000) {
259 pixels[pixel_ptr] = line_packets & 0xff;
265 for (i = 0; i < line_packets; i++) {
267 pixel_skip = bytestream2_get_byte(&g2);
268 pixel_ptr += pixel_skip;
269 pixel_countdown -= pixel_skip;
270 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
272 byte_run = -byte_run;
273 palette_idx1 = bytestream2_get_byte(&g2);
274 palette_idx2 = bytestream2_get_byte(&g2);
276 for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
277 pixels[pixel_ptr++] = palette_idx1;
278 pixels[pixel_ptr++] = palette_idx2;
282 for (j = 0; j < byte_run * 2; j++, pixel_countdown--) {
283 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
295 starting_line = bytestream2_get_le16(&g2);
299 compressed_lines = bytestream2_get_le16(&g2);
300 while (compressed_lines > 0) {
304 line_packets = bytestream2_get_byte(&g2);
305 if (line_packets > 0) {
306 for (i = 0; i < line_packets; i++) {
308 pixel_skip = bytestream2_get_byte(&g2);
309 pixel_ptr += pixel_skip;
310 pixel_countdown -= pixel_skip;
311 byte_run =
sign_extend(bytestream2_get_byte(&g2),8);
314 for (j = 0; j < byte_run; j++, pixel_countdown--) {
315 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
317 }
else if (byte_run < 0) {
318 byte_run = -byte_run;
319 palette_idx1 = bytestream2_get_byte(&g2);
321 for (j = 0; j < byte_run; j++, pixel_countdown--) {
322 pixels[pixel_ptr++] = palette_idx1;
343 for (lines = 0; lines < s->
avctx->
height; lines++) {
349 while (pixel_countdown > 0) {
350 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
357 palette_idx1 = bytestream2_get_byte(&g2);
359 for (j = 0; j < byte_run; j++) {
360 pixels[pixel_ptr++] = palette_idx1;
362 if (pixel_countdown < 0)
364 pixel_countdown, lines);
367 byte_run = -byte_run;
369 for (j = 0; j < byte_run; j++) {
370 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
372 if (pixel_countdown < 0)
374 pixel_countdown, lines);
387 "bigger than image, skipping chunk\n", chunk_size - 6);
408 frame_size -= chunk_size;
417 "and final chunk ptr = %d\n", buf_size,
434 void *
data,
int *got_frame,
435 const uint8_t *buf,
int buf_size)
443 unsigned char palette_idx1;
448 unsigned int chunk_size;
454 int compressed_lines;
455 signed short line_packets;
460 unsigned char *pixels;
462 unsigned int pixel_limit;
476 frame_size = bytestream2_get_le32(&g2);
478 num_chunks = bytestream2_get_le16(&g2);
484 while ((frame_size > 0) && (num_chunks > 0)) {
485 chunk_size = bytestream2_get_le32(&g2);
486 chunk_type = bytestream2_get_le16(&g2);
488 switch (chunk_type) {
495 "Unexpected Palette chunk %d in non-palettized FLC\n",
503 compressed_lines = bytestream2_get_le16(&g2);
504 while (compressed_lines > 0) {
505 line_packets = bytestream2_get_le16(&g2);
506 if (line_packets < 0) {
507 line_packets = -line_packets;
514 for (i = 0; i < line_packets; i++) {
516 pixel_skip = bytestream2_get_byte(&g2);
517 pixel_ptr += (pixel_skip*2);
518 pixel_countdown -= pixel_skip;
519 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
521 byte_run = -byte_run;
522 pixel = bytestream2_get_le16(&g2);
524 for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
525 *((
signed short*)(&pixels[pixel_ptr])) = pixel;
530 for (j = 0; j < byte_run; j++, pixel_countdown--) {
531 *((
signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2);
549 memset(pixels, 0x0000,
555 for (lines = 0; lines < s->
avctx->
height; lines++) {
562 while (pixel_countdown > 0) {
563 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
565 palette_idx1 = bytestream2_get_byte(&g2);
567 for (j = 0; j < byte_run; j++) {
568 pixels[pixel_ptr++] = palette_idx1;
570 if (pixel_countdown < 0)
572 pixel_countdown, lines);
575 byte_run = -byte_run;
577 for (j = 0; j < byte_run; j++) {
578 palette_idx1 = bytestream2_get_byte(&g2);
579 pixels[pixel_ptr++] = palette_idx1;
581 if (pixel_countdown < 0)
583 pixel_countdown, lines);
596 while (pixel_countdown > 0) {
597 *((
signed short*)(&pixels[pixel_ptr])) =
AV_RL16(&buf[pixel_ptr]);
607 for (lines = 0; lines < s->
avctx->
height; lines++) {
614 while (pixel_countdown > 0) {
615 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
617 pixel = bytestream2_get_le16(&g2);
619 for (j = 0; j < byte_run; j++) {
620 *((
signed short*)(&pixels[pixel_ptr])) = pixel;
623 if (pixel_countdown < 0)
628 byte_run = -byte_run;
630 for (j = 0; j < byte_run; j++) {
631 *((
signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2);
634 if (pixel_countdown < 0)
650 "bigger than image, skipping chunk\n", chunk_size - 6);
659 while (pixel_countdown > 0) {
660 *((
signed short*)(&pixels[y_ptr + pixel_ptr])) = bytestream2_get_le16(&g2);
678 frame_size -= chunk_size;
696 void *
data,
int *got_frame,
697 const uint8_t *buf,
int buf_size)
704 void *
data,
int *got_frame,
708 int buf_size = avpkt->
size;
727 av_log(avctx,
AV_LOG_ERROR,
"Unknown FLC format, my science cannot explain how this happened.\n");
This structure describes decoded (raw) audio or video data.
int buffer_hints
codec suggestion on buffer type if != 0
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
#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)
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)
struct FlicDecodeContext FlicDecodeContext
int(* reget_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called at the beginning of a frame to get cr buffer for it.
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)
8 bit with PIX_FMT_RGB32 palette
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
#define AV_PIX_FMT_RGB555
#define AV_PIX_FMT_RGB565
static int init(AVCodecParserContext *s)
static const uint8_t frame_size[4]
int reference
is this picture used as reference The values for this are the same as the MpegEncContext.picture_structure variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
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
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
int width
picture width / height.
#define FLC_FLX_TYPE_CODE
packed RGB 8:8:8, 24bpp, BGRBGR...
static av_always_inline int bytestream2_tell(GetByteContext *g)
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
main external API structure.
static void close(AVCodecParserContext *s)
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.
#define FF_BUFFER_HINTS_REUSABLE
static av_const int sign_extend(int val, unsigned bits)
#define FF_BUFFER_HINTS_PRESERVE
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define AVERROR_INVALIDDATA
unsigned int palette[256]
#define FF_BUFFER_HINTS_VALID
This structure stores compressed data.
static av_cold int flic_decode_init(AVCodecContext *avctx)
if(!(ptr_align%ac->ptr_align)&&samples_align >=aligned_len)