70 #define LUT8_PART(plane, v) \
71 AV_LE2NE64C(UINT64_C(0x0000000)<<32 | v) << plane, \
72 AV_LE2NE64C(UINT64_C(0x1000000)<<32 | v) << plane, \
73 AV_LE2NE64C(UINT64_C(0x0010000)<<32 | v) << plane, \
74 AV_LE2NE64C(UINT64_C(0x1010000)<<32 | v) << plane, \
75 AV_LE2NE64C(UINT64_C(0x0000100)<<32 | v) << plane, \
76 AV_LE2NE64C(UINT64_C(0x1000100)<<32 | v) << plane, \
77 AV_LE2NE64C(UINT64_C(0x0010100)<<32 | v) << plane, \
78 AV_LE2NE64C(UINT64_C(0x1010100)<<32 | v) << plane, \
79 AV_LE2NE64C(UINT64_C(0x0000001)<<32 | v) << plane, \
80 AV_LE2NE64C(UINT64_C(0x1000001)<<32 | v) << plane, \
81 AV_LE2NE64C(UINT64_C(0x0010001)<<32 | v) << plane, \
82 AV_LE2NE64C(UINT64_C(0x1010001)<<32 | v) << plane, \
83 AV_LE2NE64C(UINT64_C(0x0000101)<<32 | v) << plane, \
84 AV_LE2NE64C(UINT64_C(0x1000101)<<32 | v) << plane, \
85 AV_LE2NE64C(UINT64_C(0x0010101)<<32 | v) << plane, \
86 AV_LE2NE64C(UINT64_C(0x1010101)<<32 | v) << plane
88 #define LUT8(plane) { \
89 LUT8_PART(plane, 0x0000000), \
90 LUT8_PART(plane, 0x1000000), \
91 LUT8_PART(plane, 0x0010000), \
92 LUT8_PART(plane, 0x1010000), \
93 LUT8_PART(plane, 0x0000100), \
94 LUT8_PART(plane, 0x1000100), \
95 LUT8_PART(plane, 0x0010100), \
96 LUT8_PART(plane, 0x1010100), \
97 LUT8_PART(plane, 0x0000001), \
98 LUT8_PART(plane, 0x1000001), \
99 LUT8_PART(plane, 0x0010001), \
100 LUT8_PART(plane, 0x1010001), \
101 LUT8_PART(plane, 0x0000101), \
102 LUT8_PART(plane, 0x1000101), \
103 LUT8_PART(plane, 0x0010101), \
104 LUT8_PART(plane, 0x1010101), \
113 #define LUT32(plane) { \
115 0, 0, 0, 1U << plane, \
116 0, 0, 1U << plane, 0, \
117 0, 0, 1U << plane, 1U << plane, \
118 0, 1U << plane, 0, 0, \
119 0, 1U << plane, 0, 1U << plane, \
120 0, 1U << plane, 1U << plane, 0, \
121 0, 1U << plane, 1U << plane, 1U << plane, \
122 1U << plane, 0, 0, 0, \
123 1U << plane, 0, 0, 1U << plane, \
124 1U << plane, 0, 1U << plane, 0, \
125 1U << plane, 0, 1U << plane, 1U << plane, \
126 1U << plane, 1U << plane, 0, 0, \
127 1U << plane, 1U << plane, 0, 1U << plane, \
128 1U << plane, 1U << plane, 1U << plane, 0, \
129 1U << plane, 1U << plane, 1U << plane, 1U << plane, \
146 return x << 16 | x << 8 | x;
167 count =
FFMIN(palette_size / 3, count);
169 for (
i = 0;
i < count;
i++)
170 pal[
i] = 0xFF000000 |
AV_RB24(palette +
i*3);
171 if (
s->flags && count >= 32) {
172 for (
i = 0;
i < 32;
i++)
173 pal[
i + 32] = 0xFF000000 | (
AV_RB24(palette +
i*3) & 0xFEFEFE) >> 1;
174 count =
FFMAX(count, 64);
179 for (
i = 0;
i < count;
i++)
188 for (
i = 0;
i < count;
i++)
192 pal[
s->transparency] &= 0xFFFFFF;
204 const uint8_t *
const extradata,
int extradata_size)
207 const uint8_t *buf = extradata;
208 unsigned buf_size = 0;
211 if (extradata_size < 2) {
215 palette_size = extradata_size -
AV_RB16(extradata);
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);
228 s->compression = bytestream_get_byte(&buf);
229 s->bpp = bytestream_get_byte(&buf);
230 s->ham = bytestream_get_byte(&buf);
231 s->flags = bytestream_get_byte(&buf);
232 s->transparency = bytestream_get_be16(&buf);
233 s->masking = bytestream_get_byte(&buf);
234 for (
int i = 0;
i < 16;
i++)
235 s->tvdc[
i] = bytestream_get_be16(&buf);
241 }
else if (
s->ham != (
s->bpp > 6 ? 6 : 4)) {
242 av_log(avctx,
AV_LOG_ERROR,
"Invalid number of hold bits for HAM: %u, BPP: %u\n",
s->ham,
s->bpp);
248 if (
s->bpp >= 8 && !
s->ham) {
266 if (!
s->bpp ||
s->bpp > 32) {
270 if (
s->video_size &&
s->planesize *
s->bpp * avctx->
height >
s->video_size)
274 int count =
FFMIN(palette_size / 3, 1 <<
s->ham);
276 const uint8_t *
const palette = extradata +
AV_RB16(extradata);
286 ham_count = 8 * (1 <<
s->ham);
293 memset(
s->ham_palbuf, 0, (1 <<
s->ham) * 2 * sizeof (uint32_t));
294 for (
int i = 0;
i < count;
i++) {
295 s->ham_palbuf[
i*2+1] = 0xFF000000 |
AV_RL24(palette +
i*3);
300 for (
int i = 0;
i < count;
i++) {
301 s->ham_palbuf[
i*2] = 0xFF000000;
305 for (
int i = 0;
i < count;
i++) {
306 uint32_t
tmp =
i << (8 -
s->ham);
308 s->ham_palbuf[(
i+count)*2] = 0xFF00FFFF;
309 s->ham_palbuf[(
i+count*2)*2] = 0xFFFFFF00;
310 s->ham_palbuf[(
i+count*3)*2] = 0xFFFF00FF;
311 s->ham_palbuf[(
i+count)*2+1] = 0xFF000000 |
tmp << 16;
312 s->ham_palbuf[(
i+count*2)*2+1] = 0xFF000000 |
tmp;
313 s->ham_palbuf[(
i+count*3)*2+1] = 0xFF000000 |
tmp << 8;
316 for (
int i = 0;
i < ham_count;
i++)
317 s->ham_palbuf[(1 <<
s->bpp) +
i] =
s->ham_palbuf[
i] | 0xFF000000;
387 if (!
s->video[0] || !
s->video[1] || !
s->pal)
417 }
while (--buf_size);
431 unsigned mask = (*buf >> 2) & ~3;
436 mask = (*buf++ << 2) & 0x3F;
442 }
while (--buf_size);
445 #define DECODE_HAM_PLANE32(x) \
446 first = buf[x] << 1; \
447 second = buf[(x)+1] << 1; \
448 delta &= pal[first++]; \
449 delta |= pal[first]; \
451 delta &= pal[second++]; \
452 delta |= pal[second]; \
464 const uint32_t *
const pal,
unsigned buf_size)
466 uint32_t
delta = pal[1];
468 uint32_t
first, second;
475 }
while (--buf_size);
479 const uint32_t *
const pal,
unsigned width)
482 *
dst++ = pal[*buf++];
501 const int8_t
value = bytestream2_get_byte(gb);
505 if (length <
value + 1)
507 }
else if (
value > -128) {
509 memset(
dst + x, bytestream2_get_byte(gb), length);
517 memset(
dst+x, 0, dst_size - x);
527 int i, y_pos = 0, x_pos = 0;
529 if (bytestream2_get_be32(gb) !=
MKBETAG(
'V',
'D',
'A',
'T'))
533 count = bytestream2_get_be16(gb) - 2;
540 for (
i = 0;
i < count && x_pos < line_size;
i++) {
541 int8_t cmd = bytestream2_get_byte(&
cmds);
545 l = bytestream2_get_be16(gb);
546 while (l-- > 0 && x_pos < line_size) {
547 dst[x_pos + y_pos * line_size ] = bytestream2_get_byte(gb);
548 dst[x_pos + y_pos++ * line_size + 1] = bytestream2_get_byte(gb);
554 }
else if (cmd < 0) {
556 while (l-- > 0 && x_pos < line_size) {
557 dst[x_pos + y_pos * line_size ] = bytestream2_get_byte(gb);
558 dst[x_pos + y_pos++ * line_size + 1] = bytestream2_get_byte(gb);
564 }
else if (cmd == 1) {
565 l = bytestream2_get_be16(gb);
566 r = bytestream2_get_be16(gb);
567 while (l-- > 0 && x_pos < line_size) {
568 dst[x_pos + y_pos * line_size ] =
r >> 8;
569 dst[x_pos + y_pos++ * line_size + 1] =
r & 0xFF;
577 r = bytestream2_get_be16(gb);
578 while (l-- > 0 && x_pos < line_size) {
579 dst[x_pos + y_pos * line_size ] =
r >> 8;
580 dst[x_pos + y_pos++ * line_size + 1] =
r & 0xFF;
592 #define DECODE_RGBX_COMMON(type) \
594 length = bytestream2_get_byte(gb); \
596 length = bytestream2_get_be16(gb); \
601 for (i = 0; i < length; i++) { \
602 *(type *)(dst + y*linesize + x * sizeof(type)) = pixel; \
621 int x = 0, y = 0,
i, length;
623 uint32_t
pixel = 0xFF000000 | bytestream2_get_be24(gb);
624 length = bytestream2_get_byte(gb) & 0x7F;
638 int x = 0, y = 0,
i, length;
640 uint32_t
pixel = bytestream2_get_be16u(gb);
641 length =
pixel & 0x7;
658 const uint8_t *src_end =
src + src_size;
660 while (src_end -
src >= 5) {
662 opcode = *(int8_t *)
src++;
664 int size = opcode + 1;
667 if (src_end -
src < length * 4)
669 memcpy(
dst + y*linesize + x * 4,
src, length * 4);
681 int size = -opcode + 1;
684 *(uint32_t *)(
dst + y*linesize + x * 4) =
pixel;
710 int x = 0, y = 0, plane = 0;
714 for (
i = 0;
i < src_size * 2;) {
715 #define GETNIBBLE ((i & 1) ? (src[i>>1] & 0xF) : (src[i>>1] >> 4))
720 dst[y * linesize + x*4 + plane] =
pixel;
723 if (
i >= src_size * 2)
728 for (j = 0; j < d; j++) {
729 dst[y * linesize + x*4 + plane] =
pixel;
749 const uint8_t *buf,
const uint8_t *buf_end,
750 int w,
int bpp,
int dst_size)
752 int planepitch =
FFALIGN(
w, 16) >> 3;
753 int pitch = planepitch * bpp;
756 unsigned ofssrc,
pos;
762 for (k = 0; k < bpp; k++) {
763 ofssrc = bytestream2_get_be32(&ptrs);
769 if (ofssrc >= buf_end - buf)
774 int16_t
offset = bytestream2_get_be16(&gb);
778 unsigned data = bytestream2_get_be16(&gb);
781 noffset = (
pos / planepitch) * pitch + (
pos % planepitch) + k * planepitch;
783 bytestream2_put_be16(&pb,
data);
785 uint16_t count = bytestream2_get_be16(&gb);
788 for (
i = 0;
i < count;
i++) {
789 uint16_t
data = bytestream2_get_be16(&gb);
792 noffset = (
pos / planepitch) * pitch + (
pos % planepitch) + k * planepitch;
794 bytestream2_put_be16(&pb,
data);
802 const uint8_t *buf,
const uint8_t *buf_end,
803 int w,
int xor,
int bpp,
int dst_size)
805 int ncolumns = ((
w + 15) / 16) * 2;
806 int dstpitch = ncolumns * bpp;
807 unsigned ofsdst, ofssrc, opcode, x;
815 for (k = 0; k < bpp; k++) {
816 ofssrc = bytestream2_get_be32(&ptrs);
821 if (ofssrc >= buf_end - buf)
825 for (j = 0; j < ncolumns; j++) {
826 ofsdst = j + k * ncolumns;
828 i = bytestream2_get_byte(&gb);
830 opcode = bytestream2_get_byte(&gb);
833 opcode = bytestream2_get_byte(&gb);
834 x = bytestream2_get_byte(&gb);
838 if (xor && ofsdst < dst_size) {
839 bytestream2_put_byte(&pb,
dst[ofsdst] ^ x);
841 bytestream2_put_byte(&pb, x);
846 }
else if (opcode < 0x80) {
847 ofsdst += opcode * dstpitch;
853 if (xor && ofsdst < dst_size) {
854 bytestream2_put_byte(&pb,
dst[ofsdst] ^ bytestream2_get_byte(&gb));
856 bytestream2_put_byte(&pb, bytestream2_get_byte(&gb));
869 const uint8_t *buf,
const uint8_t *buf_end,
870 int w,
int h,
int bpp,
int dst_size)
874 uint32_t
type,
flag, cols, groups, rows, bytes;
876 int planepitch_byte = (
w + 7) / 8;
877 int planepitch = ((
w + 15) / 16) * 2;
878 int kludge_j,
b,
g,
r, d;
881 pitch = planepitch * bpp;
882 kludge_j =
w < 320 ? (320 -
w) / 8 / 2 : 0;
887 type = bytestream2_get_be16(&gb);
893 flag = bytestream2_get_be16(&gb);
894 cols = bytestream2_get_be16(&gb);
895 groups = bytestream2_get_be16(&gb);
897 for (
g = 0;
g < groups;
g++) {
898 offset = bytestream2_get_be16(&gb);
910 for (
b = 0;
b < cols;
b++) {
911 for (d = 0; d < bpp; d++) {
912 uint8_t
value = bytestream2_get_byte(&gb);
926 if ((cols * bpp) & 1)
931 flag = bytestream2_get_be16(&gb);
932 rows = bytestream2_get_be16(&gb);
933 bytes = bytestream2_get_be16(&gb);
934 groups = bytestream2_get_be16(&gb);
936 for (
g = 0;
g < groups;
g++) {
937 offset = bytestream2_get_be16(&gb);
944 for (
r = 0;
r < rows;
r++) {
945 for (d = 0; d < bpp; d++) {
946 unsigned noffset =
offset + (
r * pitch) + d * planepitch;
953 for (
b = 0;
b < bytes;
b++) {
954 uint8_t
value = bytestream2_get_byte(&gb);
956 if (noffset >= dst_size)
969 if ((rows * bytes * bpp) & 1)
980 const uint8_t *buf,
const uint8_t *buf_end,
981 int w,
int bpp,
int dst_size)
983 int ncolumns = (
w + 15) >> 4;
984 int dstpitch = ncolumns * bpp * 2;
985 unsigned ofsdst, ofssrc, ofsdata, opcode, x;
990 if (buf_end - buf <= 64)
997 for (k = 0; k < bpp; k++) {
998 ofssrc = bytestream2_get_be32(&ptrs);
999 ofsdata = bytestream2_get_be32(&dptrs);
1004 if (ofssrc >= buf_end - buf)
1007 if (ofsdata >= buf_end - buf)
1012 for (j = 0; j < ncolumns; j++) {
1013 ofsdst = (j + k * ncolumns) * 2;
1015 i = bytestream2_get_byte(&gb);
1017 opcode = bytestream2_get_byte(&gb);
1020 opcode = bytestream2_get_byte(&gb);
1021 x = bytestream2_get_be16(&dgb);
1025 bytestream2_put_be16(&pb, x);
1029 }
else if (opcode < 0x80) {
1030 ofsdst += opcode * dstpitch;
1036 bytestream2_put_be16(&pb, bytestream2_get_be16(&dgb));
1048 const uint8_t *buf,
const uint8_t *buf_end,
1049 int w,
int bpp,
int dst_size)
1051 int ncolumns = (
w + 31) >> 5;
1052 int dstpitch = ((
w + 15) / 16 * 2) * bpp;
1053 unsigned ofsdst, ofssrc, ofsdata, opcode, x;
1058 if (buf_end - buf <= 64)
1061 h = (((
w + 15) / 16 * 2) != ((
w + 31) / 32 * 4)) ? 1 : 0;
1066 for (k = 0; k < bpp; k++) {
1067 ofssrc = bytestream2_get_be32(&ptrs);
1068 ofsdata = bytestream2_get_be32(&dptrs);
1073 if (ofssrc >= buf_end - buf)
1076 if (ofsdata >= buf_end - buf)
1081 for (j = 0; j < ncolumns; j++) {
1082 ofsdst = (j + k * ncolumns) * 4 -
h * (2 * k);
1084 i = bytestream2_get_byte(&gb);
1086 opcode = bytestream2_get_byte(&gb);
1089 opcode = bytestream2_get_byte(&gb);
1090 if (
h && (j == (ncolumns - 1))) {
1091 x = bytestream2_get_be16(&dgb);
1094 x = bytestream2_get_be32(&dgb);
1102 if (
h && (j == (ncolumns - 1))) {
1103 bytestream2_put_be16(&pb, x);
1105 bytestream2_put_be32(&pb, x);
1110 }
else if (opcode < 0x80) {
1111 ofsdst += opcode * dstpitch;
1117 if (
h && (j == (ncolumns - 1))) {
1118 bytestream2_put_be16(&pb, bytestream2_get_be16(&dgb));
1121 bytestream2_put_be32(&pb, bytestream2_get_be32(&dgb));
1134 const uint8_t *buf,
const uint8_t *buf_end,
1135 int w,
int bpp,
int dst_size)
1137 int ncolumns = (
w + 15) >> 4;
1138 int dstpitch = ncolumns * bpp * 2;
1139 unsigned ofsdst, ofssrc, opcode, x;
1147 for (k = 0; k < bpp; k++) {
1148 ofssrc = bytestream2_get_be32(&ptrs);
1153 if (ofssrc >= buf_end - buf)
1157 for (j = 0; j < ncolumns; j++) {
1158 ofsdst = (j + k * ncolumns) * 2;
1160 i = bytestream2_get_be16(&gb);
1162 opcode = bytestream2_get_be16(&gb);
1165 opcode = bytestream2_get_be16(&gb);
1166 x = bytestream2_get_be16(&gb);
1170 bytestream2_put_be16(&pb, x);
1174 }
else if (opcode < 0x8000) {
1175 ofsdst += opcode * dstpitch;
1182 bytestream2_put_be16(&pb, bytestream2_get_be16(&gb));
1194 const uint8_t *buf,
const uint8_t *buf_end,
1195 int w,
int bpp,
int dst_size)
1197 int ncolumns = (
w + 31) >> 5;
1198 int dstpitch = ((
w + 15) / 16 * 2) * bpp;
1199 unsigned ofsdst, ofssrc, opcode, x;
1205 h = (((
w + 15) / 16 * 2) != ((
w + 31) / 32 * 4)) ? 1 : 0;
1209 for (k = 0; k < bpp; k++) {
1210 ofssrc = bytestream2_get_be32(&ptrs);
1215 if (ofssrc >= buf_end - buf)
1219 for (j = 0; j < ncolumns; j++) {
1220 ofsdst = (j + k * ncolumns) * 4 -
h * (2 * k);
1222 if (
h && (j == (ncolumns - 1))) {
1227 i = bytestream2_get_be32(&gb);
1229 opcode = bytestream2_get_be32(&gb);
1232 if (
h && (j == ncolumns - 1)) {
1233 opcode = bytestream2_get_be16(&gb);
1234 x = bytestream2_get_be16(&gb);
1236 opcode = bytestream2_get_be32(&gb);
1237 x = bytestream2_get_be32(&gb);
1245 if (
h && (j == ncolumns - 1))
1246 bytestream2_put_be16(&pb, x);
1248 bytestream2_put_be32(&pb, x);
1252 }
else if (opcode <
skip) {
1253 ofsdst += opcode * dstpitch;
1260 if (
h && (j == ncolumns - 1)) {
1261 bytestream2_put_be16(&pb, bytestream2_get_be16(&gb));
1263 bytestream2_put_be32(&pb, bytestream2_get_be32(&gb));
1276 const uint8_t *buf,
const uint8_t *buf_end,
1277 int w,
int flag,
int bpp,
int dst_size)
1279 int planepitch =
FFALIGN(
w, 16) >> 3;
1280 int pitch = planepitch * bpp;
1281 int planepitch_byte = (
w + 7) / 8;
1282 unsigned entries, ofssrc;
1287 if (buf_end - buf <= 4 * bpp)
1293 for (k = 0; k < bpp; k++) {
1294 ofssrc = bytestream2_get_be32(&ptrs);
1299 if (ofssrc >= buf_end - buf)
1304 entries = bytestream2_get_be32(&gb);
1309 int32_t opcode = bytestream2_get_be32(&gb);
1310 unsigned offset = bytestream2_get_be32(&gb);
1314 uint32_t x = bytestream2_get_be32(&gb);
1318 bytestream2_put_be32(&pb, x);
1324 bytestream2_put_be32(&pb, bytestream2_get_be32(&gb));
1335 const uint8_t *buf,
const uint8_t *buf_end,
1336 int w,
int flag,
int bpp,
int dst_size)
1338 int planepitch =
FFALIGN(
w, 16) >> 3;
1339 int pitch = planepitch * bpp;
1340 int planepitch_byte = (
w + 7) / 8;
1341 unsigned entries, ofssrc;
1346 if (buf_end - buf <= 4 * bpp)
1352 for (k = 0; k < bpp; k++) {
1353 ofssrc = bytestream2_get_be32(&ptrs);
1358 if (ofssrc >= buf_end - buf)
1363 entries = bytestream2_get_be16(&gb);
1365 int16_t opcode = bytestream2_get_be16(&gb);
1366 unsigned offset = bytestream2_get_be32(&gb);
1370 uint16_t x = bytestream2_get_be16(&gb);
1372 bytestream2_put_be16(&pb, x);
1379 bytestream2_put_be16(&pb, bytestream2_get_be16(&gb));
1390 const uint8_t *buf,
const uint8_t *buf_end,
1391 int w,
int flag,
int bpp,
int dst_size)
1395 unsigned poff0, poff1;
1397 int planepitch_byte = (
w + 7) / 8;
1398 int planepitch = ((
w + 15) / 16) * 2;
1399 int pitch = planepitch * bpp;
1402 if (buf_end - buf <= 64)
1409 dstpitch =
flag ? (((
w + 7) / 8) * bpp): 2;
1411 for (k = 0; k < bpp; k++) {
1412 poff0 = bytestream2_get_be32(&off0);
1413 poff1 = bytestream2_get_be32(&off1);
1418 if (2LL * poff0 >= buf_end - buf)
1421 if (2LL * poff1 >= buf_end - buf)
1428 uint32_t
offset = bytestream2_get_be16(&ogb);
1429 int16_t cnt = bytestream2_get_be16(&ogb);
1432 if (count > dst_size)
1434 offset = ((2 *
offset) / planepitch_byte) * pitch + ((2 *
offset) % planepitch_byte) + k * planepitch;
1440 data = bytestream2_get_be16(&dgb);
1442 for (
i = 0;
i < cnt;
i++) {
1443 bytestream2_put_be16(&pb,
data);
1451 for (
i = 0;
i < cnt;
i++) {
1452 data = bytestream2_get_be16(&dgb);
1453 bytestream2_put_be16(&pb,
data);
1464 avpriv_request_sample(avctx,
"bitmap (compression 0x%0x, bpp %i, ham %i, interlaced %i)",
s->compression,
s->bpp,
s->ham,
s->is_interlaced);
1478 uint32_t chunk_id = bytestream2_get_le32(gb);
1479 uint64_t data_size = bytestream2_get_be32(gb);
1481 if (chunk_id ==
MKTAG(
'B',
'M',
'H',
'D')) {
1483 }
else if (chunk_id ==
MKTAG(
'A',
'N',
'H',
'D')) {
1488 s->compression = (bytestream2_get_byte(gb) << 8) | (
s->compression & 0xFF);
1490 extra = bytestream2_get_be32(gb);
1491 s->is_short = !(extra & 1);
1492 s->is_brush = extra == 2;
1493 s->is_interlaced = !!(extra & 0x40);
1496 }
else if (chunk_id ==
MKTAG(
'D',
'L',
'T',
'A') ||
1497 chunk_id ==
MKTAG(
'B',
'O',
'D',
'Y')) {
1498 if (chunk_id ==
MKTAG(
'B',
'O',
'D',
'Y'))
1499 s->compression &= 0xFF;
1501 }
else if (chunk_id ==
MKTAG(
'C',
'M',
'A',
'P')) {
1502 int count = data_size / 3;
1503 uint32_t *pal =
s->pal;
1508 for (
int i = 0;
i < count;
i++)
1509 pal[
i] = 0xFF000000 | bytestream2_get_le24(gb);
1511 for (
int i = 0;
i < count;
i++)
1512 pal[
i] = 0xFF000000 | bytestream2_get_be24(gb);
1527 const uint8_t *buf = avpkt->
data;
1528 int buf_size = avpkt->
size;
1529 const uint8_t *buf_end = buf + buf_size;
1557 if (
s->compression <= 0xff && (avctx->
codec_tag ==
MKTAG(
'A',
'N',
'I',
'M'))) {
1559 memcpy(
s->pal,
frame->data[1], 256 * 4);
1562 switch (
s->compression) {
1567 for (plane = 0; plane <
s->bpp; plane++) {
1568 for (y = 0; y < avctx->
height && buf < buf_end; y++) {
1569 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1571 buf +=
s->planesize;
1574 }
else if (
s->ham) {
1576 for (y = 0; y < avctx->
height; y++) {
1577 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1578 memset(
s->ham_buf, 0,
s->planesize * 8);
1579 for (plane = 0; plane <
s->bpp; plane++) {
1580 const uint8_t * start = buf + (plane * avctx->
height + y) *
s->planesize;
1581 if (start >= buf_end)
1592 for (y = 0; y < avctx->
height && buf < buf_end; y++) {
1593 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1594 memcpy(row, buf,
FFMIN(raw_width, buf_end - buf));
1597 for (x = 0; x < avctx->
width; x++)
1598 row[4 * x + 3] = row[4 * x + 3] & 0xF0 | (row[4 * x + 3] >> 4);
1604 memcpy(
s->video[0], buf,
FFMIN(buf_end - buf,
s->video_size));
1606 for (y = 0; y < avctx->
height; y++) {
1607 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1608 memset(row, 0, avctx->
width);
1609 for (plane = 0; plane <
s->bpp && buf < buf_end; plane++) {
1611 buf +=
s->planesize;
1614 }
else if (
s->ham) {
1615 for (y = 0; y < avctx->
height; y++) {
1616 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1617 memset(
s->ham_buf, 0,
s->planesize * 8);
1618 for (plane = 0; plane <
s->bpp && buf < buf_end; plane++) {
1620 buf +=
s->planesize;
1625 for (y = 0; y < avctx->
height; y++) {
1626 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1627 memset(row, 0, avctx->
width << 2);
1628 for (plane = 0; plane <
s->bpp && buf < buf_end; plane++) {
1630 FFMIN(
s->planesize, buf_end - buf), plane);
1631 buf +=
s->planesize;
1637 for (y = 0; y < avctx->
height && buf_end > buf; y++) {
1638 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1639 memcpy(row, buf,
FFMIN(avctx->
width, buf_end - buf));
1642 }
else if (
s->ham) {
1643 for (y = 0; y < avctx->
height && buf_end > buf; y++) {
1644 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1645 memcpy(
s->ham_buf, buf,
FFMIN(avctx->
width, buf_end - buf));
1659 uint8_t *
video =
s->video[0];
1661 for (y = 0; y < avctx->
height; y++) {
1662 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1663 memset(row, 0, avctx->
width);
1664 for (plane = 0; plane <
s->bpp; plane++) {
1667 memcpy(
video,
s->planebuf,
s->planesize);
1674 for (y = 0; y < avctx->
height; y++) {
1675 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1676 memset(
s->mask_buf, 0, avctx->
width *
sizeof(uint32_t));
1677 for (plane = 0; plane <
s->bpp; plane++) {
1683 }
else if (
s->ham) {
1684 uint8_t *
video =
s->video[0];
1685 for (y = 0; y < avctx->
height; y++) {
1686 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1687 memset(
s->ham_buf, 0,
s->planesize * 8);
1688 for (plane = 0; plane <
s->bpp; plane++) {
1691 memcpy(
video,
s->planebuf,
s->planesize);
1699 for (y = 0; y < avctx->
height; y++) {
1700 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1701 memset(row, 0, avctx->
width << 2);
1702 for (plane = 0; plane <
s->bpp; plane++) {
1710 for (y = 0; y < avctx->
height; y++) {
1711 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1714 }
else if (
s->ham) {
1715 for (y = 0; y < avctx->
height; y++) {
1716 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1730 for (plane = 0; plane <
s->bpp; plane++) {
1731 for (y = 0; y < avctx->
height && buf < buf_end; y++) {
1732 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1734 buf +=
s->planesize;
1737 }
else if (
s->ham) {
1739 for (y = 0; y < avctx->
height; y++) {
1740 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1741 memset(
s->ham_buf, 0,
s->planesize * 8);
1742 for (plane = 0; plane <
s->bpp; plane++) {
1743 const uint8_t * start = buf + (plane * avctx->
height + y) *
s->planesize;
1744 if (start >= buf_end)
1759 for (plane = 0; plane <
s->bpp; plane++) {
1761 for (y = 0; y < avctx->
height; y++) {
1762 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1763 decodeplane8(row,
s->planebuf +
s->planesize * y,
s->planesize, plane);
1815 if (
s->is_interlaced)
1821 if (
s->is_interlaced)
1833 if (
s->compression <= 0xff && (avctx->
codec_tag ==
MKTAG(
'A',
'N',
'I',
'M'))) {
1834 memcpy(
s->video[1],
s->video[0],
s->video_size);
1837 if (
s->compression > 0xff) {
1840 for (y = 0; y < avctx->
height; y++) {
1841 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1842 memset(row, 0, avctx->
width);
1843 for (plane = 0; plane <
s->bpp; plane++) {
1845 buf +=
s->planesize;
1849 memcpy(
frame->data[1],
s->pal, 256 * 4);
1850 }
else if (
s->ham) {
1851 int i, count = 1 <<
s->ham;
1854 memset(
s->ham_palbuf, 0, (1 <<
s->ham) * 2 *
sizeof(uint32_t));
1855 for (
i = 0;
i < count;
i++) {
1856 s->ham_palbuf[
i*2+1] =
s->pal[
i];
1858 for (
i = 0;
i < count;
i++) {
1859 uint32_t
tmp =
i << (8 -
s->ham);
1861 s->ham_palbuf[(
i+count)*2] = 0xFF00FFFF;
1862 s->ham_palbuf[(
i+count*2)*2] = 0xFFFFFF00;
1863 s->ham_palbuf[(
i+count*3)*2] = 0xFFFF00FF;
1864 s->ham_palbuf[(
i+count)*2+1] = 0xFF000000 |
tmp << 16;
1865 s->ham_palbuf[(
i+count*2)*2+1] = 0xFF000000 |
tmp;
1866 s->ham_palbuf[(
i+count*3)*2+1] = 0xFF000000 |
tmp << 8;
1869 for (
i = 0;
i < 8 * (1 <<
s->ham);
i++)
1870 s->ham_palbuf[(1 <<
s->bpp) +
i] =
s->ham_palbuf[
i] | 0xFF000000;
1872 for (y = 0; y < avctx->
height; y++) {
1873 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1874 memset(
s->ham_buf, 0,
s->planesize * 8);
1875 for (plane = 0; plane <
s->bpp; plane++) {
1877 buf +=
s->planesize;
1886 FFSWAP(uint8_t *,
s->video[0],
s->video[1]);