69 #define LUT8_PART(plane, v) \
70 AV_LE2NE64C(UINT64_C(0x0000000)<<32 | v) << plane, \
71 AV_LE2NE64C(UINT64_C(0x1000000)<<32 | v) << plane, \
72 AV_LE2NE64C(UINT64_C(0x0010000)<<32 | v) << plane, \
73 AV_LE2NE64C(UINT64_C(0x1010000)<<32 | v) << plane, \
74 AV_LE2NE64C(UINT64_C(0x0000100)<<32 | v) << plane, \
75 AV_LE2NE64C(UINT64_C(0x1000100)<<32 | v) << plane, \
76 AV_LE2NE64C(UINT64_C(0x0010100)<<32 | v) << plane, \
77 AV_LE2NE64C(UINT64_C(0x1010100)<<32 | v) << plane, \
78 AV_LE2NE64C(UINT64_C(0x0000001)<<32 | v) << plane, \
79 AV_LE2NE64C(UINT64_C(0x1000001)<<32 | v) << plane, \
80 AV_LE2NE64C(UINT64_C(0x0010001)<<32 | v) << plane, \
81 AV_LE2NE64C(UINT64_C(0x1010001)<<32 | v) << plane, \
82 AV_LE2NE64C(UINT64_C(0x0000101)<<32 | v) << plane, \
83 AV_LE2NE64C(UINT64_C(0x1000101)<<32 | v) << plane, \
84 AV_LE2NE64C(UINT64_C(0x0010101)<<32 | v) << plane, \
85 AV_LE2NE64C(UINT64_C(0x1010101)<<32 | v) << plane
87 #define LUT8(plane) { \
88 LUT8_PART(plane, 0x0000000), \
89 LUT8_PART(plane, 0x1000000), \
90 LUT8_PART(plane, 0x0010000), \
91 LUT8_PART(plane, 0x1010000), \
92 LUT8_PART(plane, 0x0000100), \
93 LUT8_PART(plane, 0x1000100), \
94 LUT8_PART(plane, 0x0010100), \
95 LUT8_PART(plane, 0x1010100), \
96 LUT8_PART(plane, 0x0000001), \
97 LUT8_PART(plane, 0x1000001), \
98 LUT8_PART(plane, 0x0010001), \
99 LUT8_PART(plane, 0x1010001), \
100 LUT8_PART(plane, 0x0000101), \
101 LUT8_PART(plane, 0x1000101), \
102 LUT8_PART(plane, 0x0010101), \
103 LUT8_PART(plane, 0x1010101), \
112 #define LUT32(plane) { \
114 0, 0, 0, 1U << plane, \
115 0, 0, 1U << plane, 0, \
116 0, 0, 1U << plane, 1U << plane, \
117 0, 1U << plane, 0, 0, \
118 0, 1U << plane, 0, 1U << plane, \
119 0, 1U << plane, 1U << plane, 0, \
120 0, 1U << plane, 1U << plane, 1U << plane, \
121 1U << plane, 0, 0, 0, \
122 1U << plane, 0, 0, 1U << plane, \
123 1U << plane, 0, 1U << plane, 0, \
124 1U << plane, 0, 1U << plane, 1U << plane, \
125 1U << plane, 1U << plane, 0, 0, \
126 1U << plane, 1U << plane, 0, 1U << plane, \
127 1U << plane, 1U << plane, 1U << plane, 0, \
128 1U << plane, 1U << plane, 1U << plane, 1U << plane, \
145 return x << 16 | x << 8 | x;
166 count =
FFMIN(palette_size / 3, count);
168 for (
i = 0;
i < count;
i++)
169 pal[
i] = 0xFF000000 |
AV_RB24(palette +
i*3);
170 if (
s->flags && count >= 32) {
171 for (
i = 0;
i < 32;
i++)
172 pal[
i + 32] = 0xFF000000 | (
AV_RB24(palette +
i*3) & 0xFEFEFE) >> 1;
173 count =
FFMAX(count, 64);
178 for (
i = 0;
i < count;
i++)
187 for (
i = 0;
i < count;
i++)
191 pal[
s->transparency] &= 0xFFFFFF;
203 const uint8_t *
const extradata,
int extradata_size)
206 const uint8_t *buf = extradata;
207 unsigned buf_size = 0;
210 if (extradata_size < 2) {
214 palette_size = extradata_size -
AV_RB16(extradata);
216 buf_size = bytestream_get_be16(&buf);
217 if (buf_size <= 1 || palette_size < 0) {
219 "Invalid palette size received: %u -> palette data offset: %d\n",
220 buf_size, palette_size);
227 s->compression = bytestream_get_byte(&buf);
228 s->bpp = bytestream_get_byte(&buf);
229 s->ham = bytestream_get_byte(&buf);
230 s->flags = bytestream_get_byte(&buf);
231 s->transparency = bytestream_get_be16(&buf);
232 s->masking = bytestream_get_byte(&buf);
233 for (
int i = 0;
i < 16;
i++)
234 s->tvdc[
i] = bytestream_get_be16(&buf);
240 }
else if (
s->ham != (
s->bpp > 6 ? 6 : 4)) {
241 av_log(avctx,
AV_LOG_ERROR,
"Invalid number of hold bits for HAM: %u, BPP: %u\n",
s->ham,
s->bpp);
247 if (
s->bpp >= 8 && !
s->ham) {
265 if (!
s->bpp ||
s->bpp > 32) {
269 if (
s->video_size &&
s->planesize *
s->bpp * avctx->
height >
s->video_size)
273 int count =
FFMIN(palette_size / 3, 1 <<
s->ham);
275 const uint8_t *
const palette = extradata +
AV_RB16(extradata);
285 ham_count = 8 * (1 <<
s->ham);
292 memset(
s->ham_palbuf, 0, (1 <<
s->ham) * 2 * sizeof (uint32_t));
293 for (
int i = 0;
i < count;
i++) {
294 s->ham_palbuf[
i*2+1] = 0xFF000000 |
AV_RL24(palette +
i*3);
299 for (
int i = 0;
i < count;
i++) {
300 s->ham_palbuf[
i*2] = 0xFF000000;
304 for (
int i = 0;
i < count;
i++) {
305 uint32_t
tmp =
i << (8 -
s->ham);
307 s->ham_palbuf[(
i+count)*2] = 0xFF00FFFF;
308 s->ham_palbuf[(
i+count*2)*2] = 0xFFFFFF00;
309 s->ham_palbuf[(
i+count*3)*2] = 0xFFFF00FF;
310 s->ham_palbuf[(
i+count)*2+1] = 0xFF000000 |
tmp << 16;
311 s->ham_palbuf[(
i+count*2)*2+1] = 0xFF000000 |
tmp;
312 s->ham_palbuf[(
i+count*3)*2+1] = 0xFF000000 |
tmp << 8;
315 for (
int i = 0;
i < ham_count;
i++)
316 s->ham_palbuf[(1 <<
s->bpp) +
i] =
s->ham_palbuf[
i] | 0xFF000000;
386 if (!
s->video[0] || !
s->video[1] || !
s->pal)
404 static void decodeplane8(uint8_t *dst,
const uint8_t *buf,
int buf_size,
int plane)
413 uint64_t v =
AV_RN64A(dst) | lut[*buf++];
416 }
while (--buf_size);
426 static void decodeplane32(uint32_t *dst,
const uint8_t *buf,
int buf_size,
int plane)
430 unsigned mask = (*buf >> 2) & ~3;
431 dst[0] |= lut[
mask++];
432 dst[1] |= lut[
mask++];
433 dst[2] |= lut[
mask++];
435 mask = (*buf++ << 2) & 0x3F;
436 dst[4] |= lut[
mask++];
437 dst[5] |= lut[
mask++];
438 dst[6] |= lut[
mask++];
441 }
while (--buf_size);
444 #define DECODE_HAM_PLANE32(x) \
445 first = buf[x] << 1; \
446 second = buf[(x)+1] << 1; \
447 delta &= pal[first++]; \
448 delta |= pal[first]; \
450 delta &= pal[second++]; \
451 delta |= pal[second]; \
463 const uint32_t *
const pal,
unsigned buf_size)
465 uint32_t
delta = pal[1];
467 uint32_t
first, second;
474 }
while (--buf_size);
478 const uint32_t *
const pal,
unsigned width)
481 *dst++ = pal[*buf++];
500 const int8_t
value = bytestream2_get_byte(gb);
504 if (length <
value + 1)
506 }
else if (
value > -128) {
508 memset(dst + x, bytestream2_get_byte(gb), length);
516 memset(dst+x, 0, dst_size - x);
526 int i, y_pos = 0, x_pos = 0;
528 if (bytestream2_get_be32(gb) !=
MKBETAG(
'V',
'D',
'A',
'T'))
532 count = bytestream2_get_be16(gb) - 2;
539 for (
i = 0;
i < count && x_pos < line_size;
i++) {
540 int8_t cmd = bytestream2_get_byte(&
cmds);
544 l = bytestream2_get_be16(gb);
545 while (l-- > 0 && x_pos < line_size) {
546 dst[x_pos + y_pos * line_size ] = bytestream2_get_byte(gb);
547 dst[x_pos + y_pos++ * line_size + 1] = bytestream2_get_byte(gb);
553 }
else if (cmd < 0) {
555 while (l-- > 0 && x_pos < line_size) {
556 dst[x_pos + y_pos * line_size ] = bytestream2_get_byte(gb);
557 dst[x_pos + y_pos++ * line_size + 1] = bytestream2_get_byte(gb);
563 }
else if (cmd == 1) {
564 l = bytestream2_get_be16(gb);
565 r = bytestream2_get_be16(gb);
566 while (l-- > 0 && x_pos < line_size) {
567 dst[x_pos + y_pos * line_size ] =
r >> 8;
568 dst[x_pos + y_pos++ * line_size + 1] =
r & 0xFF;
576 r = bytestream2_get_be16(gb);
577 while (l-- > 0 && x_pos < line_size) {
578 dst[x_pos + y_pos * line_size ] =
r >> 8;
579 dst[x_pos + y_pos++ * line_size + 1] =
r & 0xFF;
591 #define DECODE_RGBX_COMMON(type) \
593 length = bytestream2_get_byte(gb); \
595 length = bytestream2_get_be16(gb); \
600 for (i = 0; i < length; i++) { \
601 *(type *)(dst + y*linesize + x * sizeof(type)) = pixel; \
620 int x = 0, y = 0,
i, length;
622 uint32_t
pixel = 0xFF000000 | bytestream2_get_be24(gb);
623 length = bytestream2_get_byte(gb) & 0x7F;
637 int x = 0, y = 0,
i, length;
639 uint32_t
pixel = bytestream2_get_be16u(gb);
640 length =
pixel & 0x7;
657 const uint8_t *src_end =
src + src_size;
659 while (src_end -
src >= 5) {
661 opcode = *(int8_t *)
src++;
663 int size = opcode + 1;
666 if (src_end -
src < length * 4)
668 memcpy(dst + y*linesize + x * 4,
src, length * 4);
680 int size = -opcode + 1;
683 *(uint32_t *)(dst + y*linesize + x * 4) =
pixel;
709 int x = 0, y = 0, plane = 0;
713 for (
i = 0;
i < src_size * 2;) {
714 #define GETNIBBLE ((i & 1) ? (src[i>>1] & 0xF) : (src[i>>1] >> 4))
719 dst[y * linesize + x*4 + plane] =
pixel;
722 if (
i >= src_size * 2)
727 for (j = 0; j <
d; j++) {
728 dst[y * linesize + x*4 + plane] =
pixel;
748 const uint8_t *buf,
const uint8_t *buf_end,
749 int w,
int bpp,
int dst_size)
751 int planepitch =
FFALIGN(
w, 16) >> 3;
752 int pitch = planepitch * bpp;
755 unsigned ofssrc,
pos;
761 for (k = 0; k < bpp; k++) {
762 ofssrc = bytestream2_get_be32(&ptrs);
768 if (ofssrc >= buf_end - buf)
773 int16_t
offset = bytestream2_get_be16(&gb);
777 unsigned data = bytestream2_get_be16(&gb);
780 noffset = (
pos / planepitch) * pitch + (
pos % planepitch) + k * planepitch;
782 bytestream2_put_be16(&pb,
data);
784 uint16_t count = bytestream2_get_be16(&gb);
787 for (
i = 0;
i < count;
i++) {
788 uint16_t
data = bytestream2_get_be16(&gb);
791 noffset = (
pos / planepitch) * pitch + (
pos % planepitch) + k * planepitch;
793 bytestream2_put_be16(&pb,
data);
801 const uint8_t *buf,
const uint8_t *buf_end,
802 int w,
int xor,
int bpp,
int dst_size)
804 int ncolumns = ((
w + 15) / 16) * 2;
805 int dstpitch = ncolumns * bpp;
806 unsigned ofsdst, ofssrc, opcode, x;
814 for (k = 0; k < bpp; k++) {
815 ofssrc = bytestream2_get_be32(&ptrs);
820 if (ofssrc >= buf_end - buf)
824 for (j = 0; j < ncolumns; j++) {
825 ofsdst = j + k * ncolumns;
827 i = bytestream2_get_byte(&gb);
829 opcode = bytestream2_get_byte(&gb);
832 opcode = bytestream2_get_byte(&gb);
833 x = bytestream2_get_byte(&gb);
837 if (xor && ofsdst < dst_size) {
838 bytestream2_put_byte(&pb, dst[ofsdst] ^ x);
840 bytestream2_put_byte(&pb, x);
845 }
else if (opcode < 0x80) {
846 ofsdst += opcode * dstpitch;
852 if (xor && ofsdst < dst_size) {
853 bytestream2_put_byte(&pb, dst[ofsdst] ^ bytestream2_get_byte(&gb));
855 bytestream2_put_byte(&pb, bytestream2_get_byte(&gb));
868 const uint8_t *buf,
const uint8_t *buf_end,
869 int w,
int h,
int bpp,
int dst_size)
873 uint32_t
type,
flag, cols, groups, rows, bytes;
875 int planepitch_byte = (
w + 7) / 8;
876 int planepitch = ((
w + 15) / 16) * 2;
877 int kludge_j,
b,
g,
r,
d;
880 pitch = planepitch * bpp;
881 kludge_j =
w < 320 ? (320 -
w) / 8 / 2 : 0;
886 type = bytestream2_get_be16(&gb);
892 flag = bytestream2_get_be16(&gb);
893 cols = bytestream2_get_be16(&gb);
894 groups = bytestream2_get_be16(&gb);
896 for (
g = 0;
g < groups;
g++) {
897 offset = bytestream2_get_be16(&gb);
909 for (
b = 0;
b < cols;
b++) {
910 for (
d = 0;
d < bpp;
d++) {
911 uint8_t
value = bytestream2_get_byte(&gb);
925 if ((cols * bpp) & 1)
930 flag = bytestream2_get_be16(&gb);
931 rows = bytestream2_get_be16(&gb);
932 bytes = bytestream2_get_be16(&gb);
933 groups = bytestream2_get_be16(&gb);
935 for (
g = 0;
g < groups;
g++) {
936 offset = bytestream2_get_be16(&gb);
943 for (
r = 0;
r < rows;
r++) {
944 for (
d = 0;
d < bpp;
d++) {
945 unsigned noffset =
offset + (
r * pitch) +
d * planepitch;
952 for (
b = 0;
b < bytes;
b++) {
953 uint8_t
value = bytestream2_get_byte(&gb);
955 if (noffset >= dst_size)
968 if ((rows * bytes * bpp) & 1)
979 const uint8_t *buf,
const uint8_t *buf_end,
980 int w,
int bpp,
int dst_size)
982 int ncolumns = (
w + 15) >> 4;
983 int dstpitch = ncolumns * bpp * 2;
984 unsigned ofsdst, ofssrc, ofsdata, opcode, x;
989 if (buf_end - buf <= 64)
996 for (k = 0; k < bpp; k++) {
997 ofssrc = bytestream2_get_be32(&ptrs);
998 ofsdata = bytestream2_get_be32(&dptrs);
1003 if (ofssrc >= buf_end - buf)
1006 if (ofsdata >= buf_end - buf)
1011 for (j = 0; j < ncolumns; j++) {
1012 ofsdst = (j + k * ncolumns) * 2;
1014 i = bytestream2_get_byte(&gb);
1016 opcode = bytestream2_get_byte(&gb);
1019 opcode = bytestream2_get_byte(&gb);
1020 x = bytestream2_get_be16(&dgb);
1024 bytestream2_put_be16(&pb, x);
1028 }
else if (opcode < 0x80) {
1029 ofsdst += opcode * dstpitch;
1035 bytestream2_put_be16(&pb, bytestream2_get_be16(&dgb));
1047 const uint8_t *buf,
const uint8_t *buf_end,
1048 int w,
int bpp,
int dst_size)
1050 int ncolumns = (
w + 31) >> 5;
1051 int dstpitch = ((
w + 15) / 16 * 2) * bpp;
1052 unsigned ofsdst, ofssrc, ofsdata, opcode, x;
1057 if (buf_end - buf <= 64)
1060 h = (((
w + 15) / 16 * 2) != ((
w + 31) / 32 * 4)) ? 1 : 0;
1065 for (k = 0; k < bpp; k++) {
1066 ofssrc = bytestream2_get_be32(&ptrs);
1067 ofsdata = bytestream2_get_be32(&dptrs);
1072 if (ofssrc >= buf_end - buf)
1075 if (ofsdata >= buf_end - buf)
1080 for (j = 0; j < ncolumns; j++) {
1081 ofsdst = (j + k * ncolumns) * 4 -
h * (2 * k);
1083 i = bytestream2_get_byte(&gb);
1085 opcode = bytestream2_get_byte(&gb);
1088 opcode = bytestream2_get_byte(&gb);
1089 if (
h && (j == (ncolumns - 1))) {
1090 x = bytestream2_get_be16(&dgb);
1093 x = bytestream2_get_be32(&dgb);
1101 if (
h && (j == (ncolumns - 1))) {
1102 bytestream2_put_be16(&pb, x);
1104 bytestream2_put_be32(&pb, x);
1109 }
else if (opcode < 0x80) {
1110 ofsdst += opcode * dstpitch;
1116 if (
h && (j == (ncolumns - 1))) {
1117 bytestream2_put_be16(&pb, bytestream2_get_be16(&dgb));
1120 bytestream2_put_be32(&pb, bytestream2_get_be32(&dgb));
1133 const uint8_t *buf,
const uint8_t *buf_end,
1134 int w,
int bpp,
int dst_size)
1136 int ncolumns = (
w + 15) >> 4;
1137 int dstpitch = ncolumns * bpp * 2;
1138 unsigned ofsdst, ofssrc, opcode, x;
1146 for (k = 0; k < bpp; k++) {
1147 ofssrc = bytestream2_get_be32(&ptrs);
1152 if (ofssrc >= buf_end - buf)
1156 for (j = 0; j < ncolumns; j++) {
1157 ofsdst = (j + k * ncolumns) * 2;
1159 i = bytestream2_get_be16(&gb);
1161 opcode = bytestream2_get_be16(&gb);
1164 opcode = bytestream2_get_be16(&gb);
1165 x = bytestream2_get_be16(&gb);
1169 bytestream2_put_be16(&pb, x);
1173 }
else if (opcode < 0x8000) {
1174 ofsdst += opcode * dstpitch;
1181 bytestream2_put_be16(&pb, bytestream2_get_be16(&gb));
1193 const uint8_t *buf,
const uint8_t *buf_end,
1194 int w,
int bpp,
int dst_size)
1196 int ncolumns = (
w + 31) >> 5;
1197 int dstpitch = ((
w + 15) / 16 * 2) * bpp;
1198 unsigned ofsdst, ofssrc, opcode, x;
1204 h = (((
w + 15) / 16 * 2) != ((
w + 31) / 32 * 4)) ? 1 : 0;
1208 for (k = 0; k < bpp; k++) {
1209 ofssrc = bytestream2_get_be32(&ptrs);
1214 if (ofssrc >= buf_end - buf)
1218 for (j = 0; j < ncolumns; j++) {
1219 ofsdst = (j + k * ncolumns) * 4 -
h * (2 * k);
1221 if (
h && (j == (ncolumns - 1))) {
1226 i = bytestream2_get_be32(&gb);
1228 opcode = bytestream2_get_be32(&gb);
1231 if (
h && (j == ncolumns - 1)) {
1232 opcode = bytestream2_get_be16(&gb);
1233 x = bytestream2_get_be16(&gb);
1235 opcode = bytestream2_get_be32(&gb);
1236 x = bytestream2_get_be32(&gb);
1244 if (
h && (j == ncolumns - 1))
1245 bytestream2_put_be16(&pb, x);
1247 bytestream2_put_be32(&pb, x);
1251 }
else if (opcode <
skip) {
1252 ofsdst += opcode * dstpitch;
1259 if (
h && (j == ncolumns - 1)) {
1260 bytestream2_put_be16(&pb, bytestream2_get_be16(&gb));
1262 bytestream2_put_be32(&pb, bytestream2_get_be32(&gb));
1275 const uint8_t *buf,
const uint8_t *buf_end,
1276 int w,
int flag,
int bpp,
int dst_size)
1278 int planepitch =
FFALIGN(
w, 16) >> 3;
1279 int pitch = planepitch * bpp;
1280 int planepitch_byte = (
w + 7) / 8;
1281 unsigned entries, ofssrc;
1286 if (buf_end - buf <= 4 * bpp)
1292 for (k = 0; k < bpp; k++) {
1293 ofssrc = bytestream2_get_be32(&ptrs);
1298 if (ofssrc >= buf_end - buf)
1303 entries = bytestream2_get_be32(&gb);
1308 int32_t opcode = bytestream2_get_be32(&gb);
1309 unsigned offset = bytestream2_get_be32(&gb);
1313 uint32_t x = bytestream2_get_be32(&gb);
1317 bytestream2_put_be32(&pb, x);
1323 bytestream2_put_be32(&pb, bytestream2_get_be32(&gb));
1334 const uint8_t *buf,
const uint8_t *buf_end,
1335 int w,
int flag,
int bpp,
int dst_size)
1337 int planepitch =
FFALIGN(
w, 16) >> 3;
1338 int pitch = planepitch * bpp;
1339 int planepitch_byte = (
w + 7) / 8;
1340 unsigned entries, ofssrc;
1345 if (buf_end - buf <= 4 * bpp)
1351 for (k = 0; k < bpp; k++) {
1352 ofssrc = bytestream2_get_be32(&ptrs);
1357 if (ofssrc >= buf_end - buf)
1362 entries = bytestream2_get_be16(&gb);
1364 int16_t opcode = bytestream2_get_be16(&gb);
1365 unsigned offset = bytestream2_get_be32(&gb);
1369 uint16_t x = bytestream2_get_be16(&gb);
1371 bytestream2_put_be16(&pb, x);
1378 bytestream2_put_be16(&pb, bytestream2_get_be16(&gb));
1389 const uint8_t *buf,
const uint8_t *buf_end,
1390 int w,
int flag,
int bpp,
int dst_size)
1394 unsigned poff0, poff1;
1396 int planepitch_byte = (
w + 7) / 8;
1397 int planepitch = ((
w + 15) / 16) * 2;
1398 int pitch = planepitch * bpp;
1401 if (buf_end - buf <= 64)
1408 dstpitch =
flag ? (((
w + 7) / 8) * bpp): 2;
1410 for (k = 0; k < bpp; k++) {
1411 poff0 = bytestream2_get_be32(&off0);
1412 poff1 = bytestream2_get_be32(&off1);
1417 if (2LL * poff0 >= buf_end - buf)
1420 if (2LL * poff1 >= buf_end - buf)
1427 uint32_t
offset = bytestream2_get_be16(&ogb);
1428 int16_t cnt = bytestream2_get_be16(&ogb);
1431 if (count > dst_size)
1433 offset = ((2 *
offset) / planepitch_byte) * pitch + ((2 *
offset) % planepitch_byte) + k * planepitch;
1439 data = bytestream2_get_be16(&dgb);
1441 for (
i = 0;
i < cnt;
i++) {
1442 bytestream2_put_be16(&pb,
data);
1450 for (
i = 0;
i < cnt;
i++) {
1451 data = bytestream2_get_be16(&dgb);
1452 bytestream2_put_be16(&pb,
data);
1463 avpriv_request_sample(avctx,
"bitmap (compression 0x%0x, bpp %i, ham %i, interlaced %i)",
s->compression,
s->bpp,
s->ham,
s->is_interlaced);
1477 uint32_t chunk_id = bytestream2_get_le32(gb);
1478 uint64_t data_size = bytestream2_get_be32(gb);
1480 if (chunk_id ==
MKTAG(
'B',
'M',
'H',
'D')) {
1482 }
else if (chunk_id ==
MKTAG(
'A',
'N',
'H',
'D')) {
1487 s->compression = (bytestream2_get_byte(gb) << 8) | (
s->compression & 0xFF);
1489 extra = bytestream2_get_be32(gb);
1490 s->is_short = !(extra & 1);
1491 s->is_brush = extra == 2;
1492 s->is_interlaced = !!(extra & 0x40);
1495 }
else if (chunk_id ==
MKTAG(
'D',
'L',
'T',
'A') ||
1496 chunk_id ==
MKTAG(
'B',
'O',
'D',
'Y')) {
1497 if (chunk_id ==
MKTAG(
'B',
'O',
'D',
'Y'))
1498 s->compression &= 0xFF;
1500 }
else if (chunk_id ==
MKTAG(
'C',
'M',
'A',
'P')) {
1501 int count = data_size / 3;
1502 uint32_t *pal =
s->pal;
1507 for (
int i = 0;
i < count;
i++)
1508 pal[
i] = 0xFF000000 | bytestream2_get_le24(gb);
1510 for (
int i = 0;
i < count;
i++)
1511 pal[
i] = 0xFF000000 | bytestream2_get_be24(gb);
1526 const uint8_t *buf = avpkt->
data;
1527 int buf_size = avpkt->
size;
1528 const uint8_t *buf_end = buf + buf_size;
1556 if (
s->compression <= 0xff && (avctx->
codec_tag ==
MKTAG(
'A',
'N',
'I',
'M'))) {
1561 switch (
s->compression) {
1566 for (plane = 0; plane <
s->bpp; plane++) {
1567 for (y = 0; y < avctx->
height && buf < buf_end; y++) {
1570 buf +=
s->planesize;
1573 }
else if (
s->ham) {
1575 for (y = 0; y < avctx->
height; y++) {
1577 memset(
s->ham_buf, 0,
s->planesize * 8);
1578 for (plane = 0; plane <
s->bpp; plane++) {
1579 const uint8_t * start = buf + (plane * avctx->
height + y) *
s->planesize;
1580 if (start >= buf_end)
1591 for (y = 0; y < avctx->
height && buf < buf_end; y++) {
1593 memcpy(row, buf,
FFMIN(raw_width, buf_end - buf));
1596 for (x = 0; x < avctx->
width; x++)
1597 row[4 * x + 3] = row[4 * x + 3] & 0xF0 | (row[4 * x + 3] >> 4);
1603 memcpy(
s->video[0], buf,
FFMIN(buf_end - buf,
s->video_size));
1605 for (y = 0; y < avctx->
height; y++) {
1607 memset(row, 0, avctx->
width);
1608 for (plane = 0; plane <
s->bpp && buf < buf_end; plane++) {
1610 buf +=
s->planesize;
1613 }
else if (
s->ham) {
1614 for (y = 0; y < avctx->
height; y++) {
1616 memset(
s->ham_buf, 0,
s->planesize * 8);
1617 for (plane = 0; plane <
s->bpp && buf < buf_end; plane++) {
1619 buf +=
s->planesize;
1624 for (y = 0; y < avctx->
height; y++) {
1626 memset(row, 0, avctx->
width << 2);
1627 for (plane = 0; plane <
s->bpp && buf < buf_end; plane++) {
1629 FFMIN(
s->planesize, buf_end - buf), plane);
1630 buf +=
s->planesize;
1636 for (y = 0; y < avctx->
height && buf_end > buf; y++) {
1638 memcpy(row, buf,
FFMIN(avctx->
width, buf_end - buf));
1641 }
else if (
s->ham) {
1642 for (y = 0; y < avctx->
height && buf_end > buf; y++) {
1644 memcpy(
s->ham_buf, buf,
FFMIN(avctx->
width, buf_end - buf));
1658 uint8_t *
video =
s->video[0];
1660 for (y = 0; y < avctx->
height; y++) {
1662 memset(row, 0, avctx->
width);
1663 for (plane = 0; plane <
s->bpp; plane++) {
1666 memcpy(
video,
s->planebuf,
s->planesize);
1673 for (y = 0; y < avctx->
height; y++) {
1675 memset(
s->mask_buf, 0, avctx->
width *
sizeof(uint32_t));
1676 for (plane = 0; plane <
s->bpp; plane++) {
1682 }
else if (
s->ham) {
1683 uint8_t *
video =
s->video[0];
1684 for (y = 0; y < avctx->
height; y++) {
1686 memset(
s->ham_buf, 0,
s->planesize * 8);
1687 for (plane = 0; plane <
s->bpp; plane++) {
1690 memcpy(
video,
s->planebuf,
s->planesize);
1698 for (y = 0; y < avctx->
height; y++) {
1700 memset(row, 0, avctx->
width << 2);
1701 for (plane = 0; plane <
s->bpp; plane++) {
1709 for (y = 0; y < avctx->
height; y++) {
1713 }
else if (
s->ham) {
1714 for (y = 0; y < avctx->
height; y++) {
1729 for (plane = 0; plane <
s->bpp; plane++) {
1730 for (y = 0; y < avctx->
height && buf < buf_end; y++) {
1733 buf +=
s->planesize;
1736 }
else if (
s->ham) {
1738 for (y = 0; y < avctx->
height; y++) {
1740 memset(
s->ham_buf, 0,
s->planesize * 8);
1741 for (plane = 0; plane <
s->bpp; plane++) {
1742 const uint8_t * start = buf + (plane * avctx->
height + y) *
s->planesize;
1743 if (start >= buf_end)
1758 for (plane = 0; plane <
s->bpp; plane++) {
1760 for (y = 0; y < avctx->
height; y++) {
1762 decodeplane8(row,
s->planebuf +
s->planesize * y,
s->planesize, plane);
1814 if (
s->is_interlaced)
1820 if (
s->is_interlaced)
1832 if (
s->compression <= 0xff && (avctx->
codec_tag ==
MKTAG(
'A',
'N',
'I',
'M'))) {
1833 memcpy(
s->video[1],
s->video[0],
s->video_size);
1836 if (
s->compression > 0xff) {
1839 for (y = 0; y < avctx->
height; y++) {
1841 memset(row, 0, avctx->
width);
1842 for (plane = 0; plane <
s->bpp; plane++) {
1844 buf +=
s->planesize;
1849 }
else if (
s->ham) {
1850 int i, count = 1 <<
s->ham;
1853 memset(
s->ham_palbuf, 0, (1 <<
s->ham) * 2 *
sizeof(uint32_t));
1854 for (
i = 0;
i < count;
i++) {
1855 s->ham_palbuf[
i*2+1] =
s->pal[
i];
1857 for (
i = 0;
i < count;
i++) {
1858 uint32_t
tmp =
i << (8 -
s->ham);
1860 s->ham_palbuf[(
i+count)*2] = 0xFF00FFFF;
1861 s->ham_palbuf[(
i+count*2)*2] = 0xFFFFFF00;
1862 s->ham_palbuf[(
i+count*3)*2] = 0xFFFF00FF;
1863 s->ham_palbuf[(
i+count)*2+1] = 0xFF000000 |
tmp << 16;
1864 s->ham_palbuf[(
i+count*2)*2+1] = 0xFF000000 |
tmp;
1865 s->ham_palbuf[(
i+count*3)*2+1] = 0xFF000000 |
tmp << 8;
1868 for (
i = 0;
i < 8 * (1 <<
s->ham);
i++)
1869 s->ham_palbuf[(1 <<
s->bpp) +
i] =
s->ham_palbuf[
i] | 0xFF000000;
1871 for (y = 0; y < avctx->
height; y++) {
1873 memset(
s->ham_buf, 0,
s->planesize * 8);
1874 for (plane = 0; plane <
s->bpp; plane++) {
1876 buf +=
s->planesize;
1885 FFSWAP(uint8_t *,
s->video[0],
s->video[1]);