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);
161 if (s->
flags && count >= 32) {
162 for (i = 0; i < 32; i++)
163 pal[i + 32] = 0xFF000000 | (
AV_RB24(palette + i*3) & 0xFEFEFE) >> 1;
164 count =
FFMAX(count, 64);
169 for (i=0; i < count; i++) {
175 for (i = 0; i < count; i++)
210 buf_size = bytestream_get_be16(&buf);
211 if (buf_size <= 1 || image_size <= 1) {
213 "Invalid image size received: %u -> image data offset: %d\n",
214 buf_size, image_size);
219 buf_size = bytestream_get_be16(&buf);
220 if (buf_size <= 1 || palette_size < 0) {
222 "Invalid palette size received: %u -> palette data offset: %d\n",
223 buf_size, palette_size);
228 if (buf_size >= 41) {
230 s->
bpp = bytestream_get_byte(&buf);
231 s->
ham = bytestream_get_byte(&buf);
232 s->
flags = bytestream_get_byte(&buf);
234 s->
masking = bytestream_get_byte(&buf);
235 for (i = 0; i < 16; i++)
236 s->
tvdc[i] = bytestream_get_be16(&buf);
239 if (s->
bpp >= 8 && !s->
ham) {
262 if (!s->
bpp || s->
bpp > 32) {
265 }
else if (s->
ham >= 8) {
274 int i, count =
FFMIN(palette_size / 3, 1 << s->
ham);
282 ham_count = 8 * (1 << s->
ham);
291 memset(s->
ham_palbuf, 0, (1 << s->
ham) * 2 * sizeof (uint32_t));
292 for (i=0; i < count; i++) {
298 for (i=0; i < count; i++) {
303 for (i=0; i < count; i++) {
304 uint32_t tmp = i << (8 - s->
ham);
305 tmp |= tmp >> s->
ham;
309 s->
ham_palbuf[(i+count)*2+1] = 0xFF000000 | tmp << 16;
310 s->
ham_palbuf[(i+count*2)*2+1] = 0xFF000000 | tmp;
311 s->
ham_palbuf[(i+count*3)*2+1] = 0xFF000000 | tmp << 8;
314 for (i = 0; i < ham_count; i++)
388 uint64_t
v =
AV_RN64A(dst) | lut[*buf++];
391 }
while (--buf_size);
405 unsigned mask = (*buf >> 2) & ~3;
406 dst[0] |= lut[mask++];
407 dst[1] |= lut[mask++];
408 dst[2] |= lut[mask++];
410 mask = (*buf++ << 2) & 0x3F;
411 dst[4] |= lut[mask++];
412 dst[5] |= lut[mask++];
413 dst[6] |= lut[mask++];
416 }
while (--buf_size);
419 #define DECODE_HAM_PLANE32(x) \
420 first = buf[x] << 1; \
421 second = buf[(x)+1] << 1; \
422 delta &= pal[first++]; \
423 delta |= pal[first]; \
425 delta &= pal[second++]; \
426 delta |= pal[second]; \
438 const uint32_t *
const pal,
unsigned buf_size)
440 uint32_t
delta = pal[1];
442 uint32_t first, second;
449 }
while (--buf_size);
453 const uint32_t *
const pal,
unsigned width)
456 *dst++ = pal[*buf++];
471 const uint8_t *
const buf_start = 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; \
520 int x = 0,
y = 0, i, length;
522 uint32_t
pixel = 0xFF000000 | bytestream2_get_be24(gb);
523 length = bytestream2_get_byte(gb) & 0x7F;
537 int x = 0,
y = 0, i, length;
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++) {
565 int length =
FFMIN(size - i, width);
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;
687 for (plane = 0; plane < s->
bpp; plane++) {
688 for(y = 0; y < avctx->
height && buf < buf_end; y++ ) {
696 for(y = 0; y < avctx->
height; y++) {
699 for (plane = 0; plane < s->
bpp; plane++) {
701 if (start >= buf_end)
713 for(y = 0; y < avctx->
height && buf < buf_end; y++ ) {
715 memcpy(row, buf,
FFMIN(raw_width, buf_end - buf));
718 for(x = 0; x < avctx->
width; x++)
719 row[4 * x + 3] = row[4 * x + 3] & 0xF0 | (row[4 * x + 3] >> 4);
724 for(y = 0; y < avctx->
height; y++ ) {
726 memset(row, 0, avctx->
width);
727 for (plane = 0; plane < s->
bpp && buf < buf_end; plane++) {
733 for (y = 0; y < avctx->
height; y++) {
736 for (plane = 0; plane < s->
bpp && buf < buf_end; plane++) {
743 for(y = 0; y < avctx->
height; y++ ) {
745 memset(row, 0, avctx->
width << 2);
746 for (plane = 0; plane < s->
bpp && buf < buf_end; plane++) {
754 for(y = 0; y < avctx->
height && buf_end > buf; y++ ) {
756 memcpy(row, buf,
FFMIN(avctx->
width, buf_end - buf));
760 for (y = 0; y < avctx->
height && buf_end > buf; y++) {
773 for(y = 0; y < avctx->
height ; y++ ) {
775 memset(row, 0, avctx->
width);
776 for (plane = 0; plane < s->
bpp; plane++) {
782 for (y = 0; y < avctx->
height ; y++ ) {
785 for (plane = 0; plane < s->
bpp; plane++) {
792 for (y = 0; y < avctx->
height ; y++) {
795 for (plane = 0; plane < s->
bpp; plane++) {
802 for(y = 0; y < avctx->
height ; y++ ) {
804 memset(row, 0, avctx->
width << 2);
805 for (plane = 0; plane < s->
bpp; plane++) {
813 for(y = 0; y < avctx->
height ; y++ ) {
818 for (y = 0; y < avctx->
height ; y++) {
872 #if CONFIG_IFF_ILBM_DECODER
873 AVCodec ff_iff_ilbm_decoder = {
885 #if CONFIG_IFF_BYTERUN1_DECODER
886 AVCodec ff_iff_byterun1_decoder = {