28 #include "libavutil/imgutils.h"
60 #define LUT8_PART(plane, v) \
61 AV_LE2NE64C(UINT64_C(0x0000000)<<32 | v) << plane, \
62 AV_LE2NE64C(UINT64_C(0x1000000)<<32 | v) << plane, \
63 AV_LE2NE64C(UINT64_C(0x0010000)<<32 | v) << plane, \
64 AV_LE2NE64C(UINT64_C(0x1010000)<<32 | v) << plane, \
65 AV_LE2NE64C(UINT64_C(0x0000100)<<32 | v) << plane, \
66 AV_LE2NE64C(UINT64_C(0x1000100)<<32 | v) << plane, \
67 AV_LE2NE64C(UINT64_C(0x0010100)<<32 | v) << plane, \
68 AV_LE2NE64C(UINT64_C(0x1010100)<<32 | v) << plane, \
69 AV_LE2NE64C(UINT64_C(0x0000001)<<32 | v) << plane, \
70 AV_LE2NE64C(UINT64_C(0x1000001)<<32 | v) << plane, \
71 AV_LE2NE64C(UINT64_C(0x0010001)<<32 | v) << plane, \
72 AV_LE2NE64C(UINT64_C(0x1010001)<<32 | v) << plane, \
73 AV_LE2NE64C(UINT64_C(0x0000101)<<32 | v) << plane, \
74 AV_LE2NE64C(UINT64_C(0x1000101)<<32 | v) << plane, \
75 AV_LE2NE64C(UINT64_C(0x0010101)<<32 | v) << plane, \
76 AV_LE2NE64C(UINT64_C(0x1010101)<<32 | v) << plane
78 #define LUT8(plane) { \
79 LUT8_PART(plane, 0x0000000), \
80 LUT8_PART(plane, 0x1000000), \
81 LUT8_PART(plane, 0x0010000), \
82 LUT8_PART(plane, 0x1010000), \
83 LUT8_PART(plane, 0x0000100), \
84 LUT8_PART(plane, 0x1000100), \
85 LUT8_PART(plane, 0x0010100), \
86 LUT8_PART(plane, 0x1010100), \
87 LUT8_PART(plane, 0x0000001), \
88 LUT8_PART(plane, 0x1000001), \
89 LUT8_PART(plane, 0x0010001), \
90 LUT8_PART(plane, 0x1010001), \
91 LUT8_PART(plane, 0x0000101), \
92 LUT8_PART(plane, 0x1000101), \
93 LUT8_PART(plane, 0x0010101), \
94 LUT8_PART(plane, 0x1010101), \
103 #define LUT32(plane) { \
105 0, 0, 0, 1 << plane, \
106 0, 0, 1 << plane, 0, \
107 0, 0, 1 << plane, 1 << plane, \
108 0, 1 << plane, 0, 0, \
109 0, 1 << plane, 0, 1 << plane, \
110 0, 1 << plane, 1 << plane, 0, \
111 0, 1 << plane, 1 << plane, 1 << plane, \
112 1 << plane, 0, 0, 0, \
113 1 << plane, 0, 0, 1 << plane, \
114 1 << plane, 0, 1 << plane, 0, \
115 1 << plane, 0, 1 << plane, 1 << plane, \
116 1 << plane, 1 << plane, 0, 0, \
117 1 << plane, 1 << plane, 0, 1 << plane, \
118 1 << plane, 1 << plane, 1 << plane, 0, \
119 1 << plane, 1 << plane, 1 << plane, 1 << plane, \
136 return x << 16 | x << 8 | x;
156 count =
FFMIN(palette_size / 3, count);
158 for (i = 0; i <
count; i++)
159 pal[i] = 0xFF000000 |
AV_RB24(palette + i*3);
160 if (s->
flags && count >= 32) {
161 for (i = 0; i < 32; i++)
162 pal[i + 32] = 0xFF000000 | (
AV_RB24(palette + i*3) & 0xFEFEFE) >> 1;
163 count =
FFMAX(count, 64);
168 for (i = 0; i <
count; i++)
173 for (i = 0; i <
count; i++)
208 buf_size = bytestream_get_be16(&buf);
209 if (buf_size <= 1 || image_size <= 1) {
211 "Invalid image size received: %u -> image data offset: %d\n",
212 buf_size, image_size);
217 buf_size = bytestream_get_be16(&buf);
218 if (buf_size <= 1 || palette_size < 0) {
220 "Invalid palette size received: %u -> palette data offset: %d\n",
221 buf_size, palette_size);
226 if (buf_size >= 41) {
228 s->
bpp = bytestream_get_byte(&buf);
229 s->
ham = bytestream_get_byte(&buf);
230 s->
flags = bytestream_get_byte(&buf);
232 s->
masking = bytestream_get_byte(&buf);
233 for (i = 0; i < 16; i++)
234 s->
tvdc[i] = bytestream_get_be16(&buf);
237 if (s->
bpp >= 8 && !s->
ham) {
260 if (!s->
bpp || s->
bpp > 32) {
263 }
else if (s->
ham >= 8) {
280 ham_count = 8 * (1 << s->
ham);
289 memset(s->
ham_palbuf, 0, (1 << s->
ham) * 2 * sizeof (uint32_t));
290 for (i=0; i <
count; i++) {
296 for (i=0; i <
count; i++) {
301 for (i=0; i <
count; i++) {
302 uint32_t tmp = i << (8 - s->
ham);
303 tmp |= tmp >> s->
ham;
308 s->
ham_palbuf[(i+count*2)*2+1] = 0xFF000000 | tmp;
309 s->
ham_palbuf[(i+count*3)*2+1] = 0xFF000000 | tmp << 8;
312 for (i = 0; i < ham_count; i++)
387 uint64_t
v =
AV_RN64A(dst) | lut[*buf++];
390 }
while (--buf_size);
404 unsigned mask = (*buf >> 2) & ~3;
405 dst[0] |= lut[mask++];
406 dst[1] |= lut[mask++];
407 dst[2] |= lut[mask++];
409 mask = (*buf++ << 2) & 0x3F;
410 dst[4] |= lut[mask++];
411 dst[5] |= lut[mask++];
412 dst[6] |= lut[mask++];
415 }
while (--buf_size);
418 #define DECODE_HAM_PLANE32(x) \
419 first = buf[x] << 1; \
420 second = buf[(x)+1] << 1; \
421 delta &= pal[first++]; \
422 delta |= pal[first]; \
424 delta &= pal[second++]; \
425 delta |= pal[second]; \
437 const uint32_t *
const pal,
unsigned buf_size)
439 uint32_t
delta = pal[1];
441 uint32_t first, second;
448 }
while (--buf_size);
452 const uint32_t *
const pal,
unsigned width)
455 *dst++ = pal[*buf++];
473 for (x = 0; x < dst_size && buf < buf_end;) {
475 const int8_t
value = *buf++;
478 memcpy(dst + x, buf,
FFMIN3(length, dst_size - x, buf_end - buf));
480 }
else if (value > -128) {
482 memset(dst + x, *buf++,
FFMIN(length, dst_size - x));
488 return buf - buf_start;
491 #define DECODE_RGBX_COMMON(type) \
493 length = bytestream2_get_byte(gb); \
495 length = bytestream2_get_be16(gb); \
500 for (i = 0; i < length; i++) { \
501 *(type *)(dst + y*linesize + x * sizeof(type)) = pixel; \
522 uint32_t
pixel = 0xFF000000 | bytestream2_get_be24(gb);
523 length = bytestream2_get_byte(gb) & 0x7F;
539 uint32_t
pixel = bytestream2_get_be16u(gb);
540 length = pixel & 0x7;
557 const uint8_t *src_end = src + src_size;
559 while (src + 5 <= src_end) {
561 opcode = *(int8_t *)src++;
563 int size = opcode + 1;
564 for (i = 0; i <
size; i++) {
566 memcpy(dst +
y*linesize + x * 4, src, length * 4);
578 int size = -opcode + 1;
580 for (i = 0; i <
size; i++) {
581 *(uint32_t *)(dst +
y*linesize + x * 4) =
pixel;
607 int x = 0,
y = 0, plane = 0;
611 for (i = 0; i < src_size * 2;) {
612 #define GETNIBBLE ((i & 1) ? (src[i>>1] & 0xF) : (src[i>>1] >> 4))
617 dst[
y * linesize + x*4 + plane] =
pixel;
620 if (i >= src_size * 2)
624 d =
FFMIN(d, width - x);
625 for (j = 0; j < d; j++) {
626 dst[
y * linesize + x*4 + plane] =
pixel;
653 void *
data,
int *got_frame,
659 const uint8_t *buf_end = buf + buf_size;
683 for (plane = 0; plane < s->
bpp; plane++) {
684 for (y = 0; y < avctx->
height && buf < buf_end; y++) {
692 for (y = 0; y < avctx->
height; y++) {
695 for (plane = 0; plane < s->
bpp; plane++) {
697 if (start >= buf_end)
709 for (y = 0; y < avctx->
height && buf < buf_end; y++) {
711 memcpy(row, buf,
FFMIN(raw_width, buf_end - buf));
714 for (x = 0; x < avctx->
width; x++)
715 row[4 * x + 3] = row[4 * x + 3] & 0xF0 | (row[4 * x + 3] >> 4);
720 for (y = 0; y < avctx->
height; y++) {
722 memset(row, 0, avctx->
width);
723 for (plane = 0; plane < s->
bpp && buf < buf_end; plane++) {
729 for (y = 0; y < avctx->
height; y++) {
732 for (plane = 0; plane < s->
bpp && buf < buf_end; plane++) {
739 for (y = 0; y < avctx->
height; y++) {
741 memset(row, 0, avctx->
width << 2);
742 for (plane = 0; plane < s->
bpp && buf < buf_end; plane++) {
751 for (y = 0; y < avctx->
height && buf_end >
buf; y++) {
753 memcpy(row, buf,
FFMIN(avctx->
width, buf_end - buf));
757 for (y = 0; y < avctx->
height && buf_end >
buf; y++) {
770 for (y = 0; y < avctx->
height; y++) {
772 memset(row, 0, avctx->
width);
773 for (plane = 0; plane < s->
bpp; plane++) {
779 for (y = 0; y < avctx->
height; y++) {
782 for (plane = 0; plane < s->
bpp; plane++) {
789 for (y = 0; y < avctx->
height; y++) {
792 for (plane = 0; plane < s->
bpp; plane++) {
799 for (y = 0; y < avctx->
height; y++) {
801 memset(row, 0, avctx->
width << 2);
802 for (plane = 0; plane < s->
bpp; plane++) {
810 for (y = 0; y < avctx->
height; y++) {
815 for (y = 0; y < avctx->
height; y++) {
871 #if CONFIG_IFF_ILBM_DECODER
872 AVCodec ff_iff_ilbm_decoder = {
884 #if CONFIG_IFF_BYTERUN1_DECODER
885 AVCodec ff_iff_byterun1_decoder = {
static void decodeplane32(uint32_t *dst, const uint8_t *buf, int buf_size, int plane)
Decode interleaved plane buffer up to 24bpp.
#define AVERROR_PATCHWELCOME
unsigned compression
delta compression method used
This structure describes decoded (raw) audio or video data.
uint32_t * mask_palbuf
masking palette table
#define AV_LOG_WARNING
Something somehow does not look correct.
unsigned masking
TODO: masking method used.
static av_cold int init(AVCodecContext *avctx)
unsigned transparency
TODO: transparency color index in palette.
static int cmap_read_palette(AVCodecContext *avctx, uint32_t *pal)
Convert CMAP buffer (stored in extradata) to lavc palette format.
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)
unsigned flags
1 for EHB, 0 is no extra half darkening
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static void decodeplane8(uint8_t *dst, const uint8_t *buf, int buf_size, int plane)
Decode interleaved plane buffer up to 8bpp.
uint32_t * mask_buf
temporary buffer for palette indices
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
#define DECODE_HAM_PLANE32(x)
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
static av_cold int decode_end(AVCodecContext *avctx)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static void decode_deep_tvdc32(uint8_t *dst, const uint8_t *src, int src_size, int width, int height, int linesize, const int16_t *tvdc)
Decode DEEP TVDC 32-bit buffer.
uint8_t * ham_buf
temporary buffer for planar to chunky conversation
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.
bitstream reader API header.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const uint16_t mask[17]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Libavcodec external API header.
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
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.
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#define DECODE_RGBX_COMMON(type)
main external API structure.
static void close(AVCodecParserContext *s)
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
BYTE int const BYTE int int int height
#define MKTAG(a, b, c, d)
static av_always_inline uint32_t gray2rgb(const uint32_t x)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
#define AV_PIX_FMT_RGB444
static void decode_rgbn(GetByteContext *gb, uint8_t *dst, int width, int height, int linesize)
Decode RGBN buffer.
common internal api header.
unsigned ham
0 if non-HAM or number of hold bits (6 for bpp > 6, 4 otherwise)
static const uint32_t plane32_lut[32][16 *4]
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static void decode_rgb8(GetByteContext *gb, uint8_t *dst, int width, int height, int linesize)
Decode RGB8 buffer.
static void decode_ham_plane32(uint32_t *dst, const uint8_t *buf, const uint32_t *const pal, unsigned buf_size)
Converts one line of HAM6/8-encoded chunky buffer to 24bpp.
static av_cold int decode_init(AVCodecContext *avctx)
static const uint64_t plane8_lut[8][256]
#define AVERROR_INVALIDDATA
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static int extract_header(AVCodecContext *const avctx, const AVPacket *const avpkt)
Extracts the IFF extra context and updates internal decoder structures.
8 bit with PIX_FMT_RGB32 palette
static void lookup_pal_indicies(uint32_t *dst, const uint32_t *buf, const uint32_t *const pal, unsigned width)
int16_t tvdc[16]
TVDC lookup table.
static int decode_byterun(uint8_t *dst, int dst_size, const uint8_t *buf, const uint8_t *const buf_end)
Decode one complete byterun1 encoded line.
static int unsupported(AVCodecContext *avctx)
#define AV_PIX_FMT_0BGR32
This structure stores compressed data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
uint32_t * ham_palbuf
HAM decode table.
unsigned bpp
bits per plane to decode (differs from bits_per_coded_sample if HAM)
static void decode_deep_rle32(uint8_t *dst, const uint8_t *src, int src_size, int width, int height, int linesize)
Decode DEEP RLE 32-bit buffer.