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++)
399 uint64_t
v =
AV_RN64A(dst) | lut[*buf++];
402 }
while (--buf_size);
416 unsigned mask = (*buf >> 2) & ~3;
417 dst[0] |= lut[mask++];
418 dst[1] |= lut[mask++];
419 dst[2] |= lut[mask++];
421 mask = (*buf++ << 2) & 0x3F;
422 dst[4] |= lut[mask++];
423 dst[5] |= lut[mask++];
424 dst[6] |= lut[mask++];
427 }
while (--buf_size);
430 #define DECODE_HAM_PLANE32(x) \
431 first = buf[x] << 1; \
432 second = buf[(x)+1] << 1; \
433 delta &= pal[first++]; \
434 delta |= pal[first]; \
436 delta &= pal[second++]; \
437 delta |= pal[second]; \
449 const uint32_t *
const pal,
unsigned buf_size)
451 uint32_t
delta = pal[1];
453 uint32_t first, second;
460 }
while (--buf_size);
464 const uint32_t *
const pal,
unsigned width)
467 *dst++ = pal[*buf++];
485 for (x = 0; x < dst_size && buf < buf_end;) {
487 const int8_t
value = *buf++;
490 memcpy(dst + x, buf,
FFMIN3(length, dst_size - x, buf_end - buf));
492 }
else if (value > -128) {
494 memset(dst + x, *buf++,
FFMIN(length, dst_size - x));
500 return buf - buf_start;
503 #define DECODE_RGBX_COMMON(type) \
505 length = bytestream2_get_byte(gb); \
507 length = bytestream2_get_be16(gb); \
512 for (i = 0; i < length; i++) { \
513 *(type *)(dst + y*linesize + x * sizeof(type)) = pixel; \
534 uint32_t
pixel = 0xFF000000 | bytestream2_get_be24(gb);
535 length = bytestream2_get_byte(gb) & 0x7F;
551 uint32_t
pixel = bytestream2_get_be16u(gb);
552 length = pixel & 0x7;
569 const uint8_t *src_end = src + src_size;
571 while (src + 5 <= src_end) {
573 opcode = *(int8_t *)src++;
575 int size = opcode + 1;
576 for (i = 0; i <
size; i++) {
578 memcpy(dst +
y*linesize + x * 4, src, length * 4);
590 int size = -opcode + 1;
592 for (i = 0; i <
size; i++) {
593 *(uint32_t *)(dst +
y*linesize + x * 4) =
pixel;
619 int x = 0,
y = 0, plane = 0;
623 for (i = 0; i < src_size * 2;) {
624 #define GETNIBBLE ((i & 1) ? (src[i>>1] & 0xF) : (src[i>>1] >> 4))
629 dst[
y * linesize + x*4 + plane] =
pixel;
632 if (i >= src_size * 2)
636 d =
FFMIN(d, width - x);
637 for (j = 0; j < d; j++) {
638 dst[
y * linesize + x*4 + plane] =
pixel;
665 void *
data,
int *got_frame,
671 const uint8_t *buf_end = buf + buf_size;
695 for (plane = 0; plane < s->
bpp; plane++) {
696 for (y = 0; y < avctx->
height && buf < buf_end; y++) {
704 for (y = 0; y < avctx->
height; y++) {
707 for (plane = 0; plane < s->
bpp; plane++) {
709 if (start >= buf_end)
721 for (y = 0; y < avctx->
height && buf < buf_end; y++) {
723 memcpy(row, buf,
FFMIN(raw_width, buf_end - buf));
726 for (x = 0; x < avctx->
width; x++)
727 row[4 * x + 3] = row[4 * x + 3] & 0xF0 | (row[4 * x + 3] >> 4);
732 for (y = 0; y < avctx->
height; y++) {
734 memset(row, 0, avctx->
width);
735 for (plane = 0; plane < s->
bpp && buf < buf_end; plane++) {
741 for (y = 0; y < avctx->
height; y++) {
744 for (plane = 0; plane < s->
bpp && buf < buf_end; plane++) {
751 for (y = 0; y < avctx->
height; y++) {
753 memset(row, 0, avctx->
width << 2);
754 for (plane = 0; plane < s->
bpp && buf < buf_end; plane++) {
763 for (y = 0; y < avctx->
height && buf_end >
buf; y++) {
765 memcpy(row, buf,
FFMIN(avctx->
width, buf_end - buf));
769 for (y = 0; y < avctx->
height && buf_end >
buf; y++) {
782 for (y = 0; y < avctx->
height; y++) {
784 memset(row, 0, avctx->
width);
785 for (plane = 0; plane < s->
bpp; plane++) {
791 for (y = 0; y < avctx->
height; y++) {
794 for (plane = 0; plane < s->
bpp; plane++) {
801 for (y = 0; y < avctx->
height; y++) {
804 for (plane = 0; plane < s->
bpp; plane++) {
811 for (y = 0; y < avctx->
height; y++) {
813 memset(row, 0, avctx->
width << 2);
814 for (plane = 0; plane < s->
bpp; plane++) {
822 for (y = 0; y < avctx->
height; y++) {
827 for (y = 0; y < avctx->
height; y++) {
873 #if CONFIG_IFF_ILBM_DECODER
874 AVCodec ff_iff_ilbm_decoder = {
886 #if CONFIG_IFF_BYTERUN1_DECODER
887 AVCodec ff_iff_byterun1_decoder = {