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)) {
206 int stream_ptr_after_chunk;
207 chunk_size = bytestream2_get_le32(&g2);
208 if (chunk_size > frame_size) {
210 "Invalid chunk_size = %u > frame_size = %u\n", chunk_size, frame_size);
215 chunk_type = bytestream2_get_le16(&g2);
217 switch (chunk_type) {
229 color_packets = bytestream2_get_le16(&g2);
231 for (i = 0; i < color_packets; i++) {
233 palette_ptr += bytestream2_get_byte(&g2);
236 color_changes = bytestream2_get_byte(&g2);
239 if (color_changes == 0)
245 for (j = 0; j < color_changes; j++) {
249 if ((
unsigned)palette_ptr >= 256)
252 r = bytestream2_get_byte(&g2) << color_shift;
253 g = bytestream2_get_byte(&g2) << color_shift;
254 b = bytestream2_get_byte(&g2) << color_shift;
255 entry = 0xFF
U << 24 | r << 16 | g << 8 |
b;
256 if (color_shift == 2)
257 entry |= entry >> 6 & 0x30303;
258 if (s->
palette[palette_ptr] != entry)
260 s->
palette[palette_ptr++] = entry;
267 compressed_lines = bytestream2_get_le16(&g2);
268 while (compressed_lines > 0) {
271 line_packets = bytestream2_get_le16(&g2);
272 if ((line_packets & 0xC000) == 0xC000) {
274 line_packets = -line_packets;
276 }
else if ((line_packets & 0xC000) == 0x4000) {
278 }
else if ((line_packets & 0xC000) == 0x8000) {
282 pixels[pixel_ptr] = line_packets & 0xff;
288 for (i = 0; i < line_packets; i++) {
292 pixel_skip = bytestream2_get_byte(&g2);
293 pixel_ptr += pixel_skip;
294 pixel_countdown -= pixel_skip;
295 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
297 byte_run = -byte_run;
298 palette_idx1 = bytestream2_get_byte(&g2);
299 palette_idx2 = bytestream2_get_byte(&g2);
301 for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
302 pixels[pixel_ptr++] = palette_idx1;
303 pixels[pixel_ptr++] = palette_idx2;
309 for (j = 0; j < byte_run * 2; j++, pixel_countdown--) {
310 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
322 starting_line = bytestream2_get_le16(&g2);
326 compressed_lines = bytestream2_get_le16(&g2);
327 while (compressed_lines > 0) {
333 line_packets = bytestream2_get_byte(&g2);
334 if (line_packets > 0) {
335 for (i = 0; i < line_packets; i++) {
339 pixel_skip = bytestream2_get_byte(&g2);
340 pixel_ptr += pixel_skip;
341 pixel_countdown -= pixel_skip;
342 byte_run =
sign_extend(bytestream2_get_byte(&g2),8);
347 for (j = 0; j < byte_run; j++, pixel_countdown--) {
348 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
350 }
else if (byte_run < 0) {
351 byte_run = -byte_run;
352 palette_idx1 = bytestream2_get_byte(&g2);
354 for (j = 0; j < byte_run; j++, pixel_countdown--) {
355 pixels[pixel_ptr++] = palette_idx1;
376 for (lines = 0; lines < s->
avctx->
height; lines++) {
382 while (pixel_countdown > 0) {
385 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
392 palette_idx1 = bytestream2_get_byte(&g2);
394 for (j = 0; j < byte_run; j++) {
395 pixels[pixel_ptr++] = palette_idx1;
397 if (pixel_countdown < 0)
399 pixel_countdown, lines);
402 byte_run = -byte_run;
406 for (j = 0; j < byte_run; j++) {
407 pixels[pixel_ptr++] = bytestream2_get_byte(&g2);
409 if (pixel_countdown < 0)
411 pixel_countdown, lines);
424 "has incorrect size, skipping chunk\n", chunk_size - 6);
447 frame_size -= chunk_size;
455 "and final chunk ptr = %d\n", buf_size,
474 void *
data,
int *got_frame,
483 unsigned char palette_idx1;
488 unsigned int chunk_size;
494 int compressed_lines;
495 signed short line_packets;
500 unsigned char *pixels;
502 unsigned int pixel_limit;
512 frame_size = bytestream2_get_le32(&g2);
514 num_chunks = bytestream2_get_le16(&g2);
516 if (frame_size > buf_size)
517 frame_size = buf_size;
522 while ((frame_size > 0) && (num_chunks > 0)) {
523 int stream_ptr_after_chunk;
524 chunk_size = bytestream2_get_le32(&g2);
525 if (chunk_size > frame_size) {
527 "Invalid chunk_size = %u > frame_size = %u\n", chunk_size, frame_size);
532 chunk_type = bytestream2_get_le16(&g2);
535 switch (chunk_type) {
542 "Unexpected Palette chunk %d in non-palettized FLC\n",
550 compressed_lines = bytestream2_get_le16(&g2);
551 while (compressed_lines > 0) {
554 line_packets = bytestream2_get_le16(&g2);
555 if (line_packets < 0) {
556 line_packets = -line_packets;
563 for (i = 0; i < line_packets; i++) {
567 pixel_skip = bytestream2_get_byte(&g2);
568 pixel_ptr += (pixel_skip*2);
569 pixel_countdown -= pixel_skip;
570 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
572 byte_run = -byte_run;
573 pixel = bytestream2_get_le16(&g2);
575 for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
576 *((
signed short*)(&pixels[pixel_ptr])) = pixel;
583 for (j = 0; j < byte_run; j++, pixel_countdown--) {
584 *((
signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2);
602 memset(pixels, 0x0000,
608 for (lines = 0; lines < s->
avctx->
height; lines++) {
615 while (pixel_countdown > 0) {
618 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
620 palette_idx1 = bytestream2_get_byte(&g2);
622 for (j = 0; j < byte_run; j++) {
623 pixels[pixel_ptr++] = palette_idx1;
625 if (pixel_countdown < 0)
627 pixel_countdown, lines);
630 byte_run = -byte_run;
634 for (j = 0; j < byte_run; j++) {
635 palette_idx1 = bytestream2_get_byte(&g2);
636 pixels[pixel_ptr++] = palette_idx1;
638 if (pixel_countdown < 0)
640 pixel_countdown, lines);
653 while (pixel_countdown > 0) {
654 *((
signed short*)(&pixels[pixel_ptr])) =
AV_RL16(&buf[pixel_ptr]);
664 for (lines = 0; lines < s->
avctx->
height; lines++) {
671 while (pixel_countdown > 0) {
674 byte_run =
sign_extend(bytestream2_get_byte(&g2), 8);
676 pixel = bytestream2_get_le16(&g2);
678 for (j = 0; j < byte_run; j++) {
679 *((
signed short*)(&pixels[pixel_ptr])) = pixel;
682 if (pixel_countdown < 0)
687 byte_run = -byte_run;
691 for (j = 0; j < byte_run; j++) {
692 *((
signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2);
695 if (pixel_countdown < 0)
711 "bigger than image, skipping chunk\n", chunk_size - 6);
720 while (pixel_countdown > 0) {
721 *((
signed short*)(&pixels[y_ptr + pixel_ptr])) = bytestream2_get_le16(&g2);
739 frame_size -= chunk_size;
758 void *
data,
int *got_frame,
766 void *
data,
int *got_frame,
770 int buf_size = avpkt->
size;
789 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)
static av_cold int init(AVCodecContext *avctx)
#define AV_LOG_WARNING
Something somehow does not look correct.
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
static int flic_decode_frame_8BPP(AVCodecContext *avctx, void *data, int *got_frame, const uint8_t *buf, int buf_size)
8 bit with PIX_FMT_RGB32 palette
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]
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.
#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...
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.
static void close(AVCodecParserContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
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)
synthesis window for stochastic i
int palette_has_changed
Tell user application that palette has changed from previous frame.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
static av_const int sign_extend(int val, unsigned bits)
int av_frame_ref(AVFrame *dst, AVFrame *src)
Setup a new reference to the data described by an given frame.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
common internal api header.
#define AV_PIX_FMT_RGB555
unsigned int palette[256]
#define AV_PIX_FMT_RGB565
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
This structure stores compressed data.
static av_cold int flic_decode_init(AVCodecContext *avctx)