29 #include "config_components.h"
74 #define LUT8_PART(plane, v) \
75 AV_LE2NE64C(UINT64_C(0x0000000)<<32 | v) << plane, \
76 AV_LE2NE64C(UINT64_C(0x1000000)<<32 | v) << plane, \
77 AV_LE2NE64C(UINT64_C(0x0010000)<<32 | v) << plane, \
78 AV_LE2NE64C(UINT64_C(0x1010000)<<32 | v) << plane, \
79 AV_LE2NE64C(UINT64_C(0x0000100)<<32 | v) << plane, \
80 AV_LE2NE64C(UINT64_C(0x1000100)<<32 | v) << plane, \
81 AV_LE2NE64C(UINT64_C(0x0010100)<<32 | v) << plane, \
82 AV_LE2NE64C(UINT64_C(0x1010100)<<32 | v) << plane, \
83 AV_LE2NE64C(UINT64_C(0x0000001)<<32 | v) << plane, \
84 AV_LE2NE64C(UINT64_C(0x1000001)<<32 | v) << plane, \
85 AV_LE2NE64C(UINT64_C(0x0010001)<<32 | v) << plane, \
86 AV_LE2NE64C(UINT64_C(0x1010001)<<32 | v) << plane, \
87 AV_LE2NE64C(UINT64_C(0x0000101)<<32 | v) << plane, \
88 AV_LE2NE64C(UINT64_C(0x1000101)<<32 | v) << plane, \
89 AV_LE2NE64C(UINT64_C(0x0010101)<<32 | v) << plane, \
90 AV_LE2NE64C(UINT64_C(0x1010101)<<32 | v) << plane
92 #define LUT8(plane) { \
93 LUT8_PART(plane, 0x0000000), \
94 LUT8_PART(plane, 0x1000000), \
95 LUT8_PART(plane, 0x0010000), \
96 LUT8_PART(plane, 0x1010000), \
97 LUT8_PART(plane, 0x0000100), \
98 LUT8_PART(plane, 0x1000100), \
99 LUT8_PART(plane, 0x0010100), \
100 LUT8_PART(plane, 0x1010100), \
101 LUT8_PART(plane, 0x0000001), \
102 LUT8_PART(plane, 0x1000001), \
103 LUT8_PART(plane, 0x0010001), \
104 LUT8_PART(plane, 0x1010001), \
105 LUT8_PART(plane, 0x0000101), \
106 LUT8_PART(plane, 0x1000101), \
107 LUT8_PART(plane, 0x0010101), \
108 LUT8_PART(plane, 0x1010101), \
117 #define LUT32(plane) { \
119 0, 0, 0, 1U << plane, \
120 0, 0, 1U << plane, 0, \
121 0, 0, 1U << plane, 1U << plane, \
122 0, 1U << plane, 0, 0, \
123 0, 1U << plane, 0, 1U << plane, \
124 0, 1U << plane, 1U << plane, 0, \
125 0, 1U << plane, 1U << plane, 1U << plane, \
126 1U << plane, 0, 0, 0, \
127 1U << plane, 0, 0, 1U << plane, \
128 1U << plane, 0, 1U << plane, 0, \
129 1U << plane, 0, 1U << plane, 1U << plane, \
130 1U << plane, 1U << plane, 0, 0, \
131 1U << plane, 1U << plane, 0, 1U << plane, \
132 1U << plane, 1U << plane, 1U << plane, 0, \
133 1U << plane, 1U << plane, 1U << plane, 1U << plane, \
150 return x << 16 | x << 8 | x;
170 count =
FFMIN(palette_size / 3, count);
172 for (
i = 0;
i < count;
i++)
173 pal[
i] = 0xFF000000 |
AV_RB24(palette +
i*3);
174 if (
s->flags && count >= 32) {
175 for (
i = 0;
i < 32;
i++)
176 pal[
i + 32] = 0xFF000000 | (
AV_RB24(palette +
i*3) & 0xFEFEFE) >> 1;
177 count =
FFMAX(count, 64);
182 for (
i = 0;
i < count;
i++)
191 for (
i = 0;
i < count;
i++)
195 pal[
s->transparency] &= 0xFFFFFF;
212 unsigned buf_size = 0;
228 chunk_id = bytestream2_get_le32(gb);
229 data_size = bytestream2_get_be32(gb);
231 if (chunk_id ==
MKTAG(
'B',
'M',
'H',
'D')) {
233 }
else if (chunk_id ==
MKTAG(
'A',
'N',
'H',
'D')) {
238 s->compression = (bytestream2_get_byte(gb) << 8) | (
s->compression & 0xFF);
240 extra = bytestream2_get_be32(gb);
241 s->is_short = !(extra & 1);
242 s->is_brush = extra == 2;
243 s->is_interlaced = !!(extra & 0x40);
246 }
else if (chunk_id ==
MKTAG(
'D',
'L',
'T',
'A') ||
247 chunk_id ==
MKTAG(
'B',
'O',
'D',
'Y')) {
248 if (chunk_id ==
MKTAG(
'B',
'O',
'D',
'Y'))
249 s->compression &= 0xFF;
251 }
else if (chunk_id ==
MKTAG(
'C',
'M',
'A',
'P')) {
252 int count = data_size / 3;
253 uint32_t *pal =
s->pal;
258 for (
i = 0;
i < count;
i++)
259 pal[
i] = 0xFF000000 | bytestream2_get_le24(gb);
261 for (
i = 0;
i < count;
i++)
262 pal[
i] = 0xFF000000 | bytestream2_get_be24(gb);
271 buf_size = bytestream_get_be16(&buf);
272 if (buf_size <= 1 || palette_size < 0) {
274 "Invalid palette size received: %u -> palette data offset: %d\n",
275 buf_size, palette_size);
280 if (buf_size >= 41) {
281 s->compression = bytestream_get_byte(&buf);
282 s->bpp = bytestream_get_byte(&buf);
283 s->ham = bytestream_get_byte(&buf);
284 s->flags = bytestream_get_byte(&buf);
285 s->transparency = bytestream_get_be16(&buf);
286 s->masking = bytestream_get_byte(&buf);
287 for (
i = 0;
i < 16;
i++)
288 s->tvdc[
i] = bytestream_get_be16(&buf);
294 }
else if (
s->ham != (
s->bpp > 6 ? 6 : 4)) {
295 av_log(avctx,
AV_LOG_ERROR,
"Invalid number of hold bits for HAM: %u, BPP: %u\n",
s->ham,
s->bpp);
301 if (
s->bpp >= 8 && !
s->ham) {
313 if (!
s->mask_palbuf) {
323 if (!
s->bpp ||
s->bpp > 32) {
327 if (
s->video_size &&
s->planesize *
s->bpp * avctx->
height >
s->video_size)
334 int i, count =
FFMIN(palette_size / 3, 1 <<
s->ham);
346 ham_count = 8 * (1 <<
s->ham);
348 if (!
s->ham_palbuf) {
355 memset(
s->ham_palbuf, 0, (1 <<
s->ham) * 2 * sizeof (uint32_t));
356 for (
i=0;
i < count;
i++) {
357 s->ham_palbuf[
i*2+1] = 0xFF000000 |
AV_RL24(palette +
i*3);
362 for (
i=0;
i < count;
i++) {
363 s->ham_palbuf[
i*2] = 0xFF000000;
367 for (
i=0;
i < count;
i++) {
368 uint32_t
tmp =
i << (8 -
s->ham);
370 s->ham_palbuf[(
i+count)*2] = 0xFF00FFFF;
371 s->ham_palbuf[(
i+count*2)*2] = 0xFFFFFF00;
372 s->ham_palbuf[(
i+count*3)*2] = 0xFFFF00FF;
373 s->ham_palbuf[(
i+count)*2+1] = 0xFF000000 |
tmp << 16;
374 s->ham_palbuf[(
i+count*2)*2+1] = 0xFF000000 |
tmp;
375 s->ham_palbuf[(
i+count*3)*2+1] = 0xFF000000 |
tmp << 8;
378 for (
i = 0;
i < ham_count;
i++)
379 s->ham_palbuf[(1 <<
s->bpp) +
i] =
s->ham_palbuf[
i] | 0xFF000000;
450 if (!
s->video[0] || !
s->video[1] || !
s->pal)
467 static void decodeplane8(uint8_t *dst,
const uint8_t *buf,
int buf_size,
int plane)
476 uint64_t v =
AV_RN64A(dst) | lut[*buf++];
479 }
while (--buf_size);
489 static void decodeplane32(uint32_t *dst,
const uint8_t *buf,
int buf_size,
int plane)
493 unsigned mask = (*buf >> 2) & ~3;
494 dst[0] |= lut[
mask++];
495 dst[1] |= lut[
mask++];
496 dst[2] |= lut[
mask++];
498 mask = (*buf++ << 2) & 0x3F;
499 dst[4] |= lut[
mask++];
500 dst[5] |= lut[
mask++];
501 dst[6] |= lut[
mask++];
504 }
while (--buf_size);
507 #define DECODE_HAM_PLANE32(x) \
508 first = buf[x] << 1; \
509 second = buf[(x)+1] << 1; \
510 delta &= pal[first++]; \
511 delta |= pal[first]; \
513 delta &= pal[second++]; \
514 delta |= pal[second]; \
526 const uint32_t *
const pal,
unsigned buf_size)
528 uint32_t
delta = pal[1];
530 uint32_t
first, second;
537 }
while (--buf_size);
541 const uint32_t *
const pal,
unsigned width)
544 *dst++ = pal[*buf++];
563 const int8_t
value = bytestream2_get_byte(gb);
567 if (length <
value + 1)
569 }
else if (
value > -128) {
571 memset(dst + x, bytestream2_get_byte(gb), length);
579 memset(dst+x, 0, dst_size - x);
589 int i, y_pos = 0, x_pos = 0;
591 if (bytestream2_get_be32(gb) !=
MKBETAG(
'V',
'D',
'A',
'T'))
595 count = bytestream2_get_be16(gb) - 2;
602 for (
i = 0;
i < count && x_pos < line_size;
i++) {
603 int8_t cmd = bytestream2_get_byte(&
cmds);
607 l = bytestream2_get_be16(gb);
608 while (l-- > 0 && x_pos < line_size) {
609 dst[x_pos + y_pos * line_size ] = bytestream2_get_byte(gb);
610 dst[x_pos + y_pos++ * line_size + 1] = bytestream2_get_byte(gb);
616 }
else if (cmd < 0) {
618 while (l-- > 0 && x_pos < line_size) {
619 dst[x_pos + y_pos * line_size ] = bytestream2_get_byte(gb);
620 dst[x_pos + y_pos++ * line_size + 1] = bytestream2_get_byte(gb);
626 }
else if (cmd == 1) {
627 l = bytestream2_get_be16(gb);
628 r = bytestream2_get_be16(gb);
629 while (l-- > 0 && x_pos < line_size) {
630 dst[x_pos + y_pos * line_size ] =
r >> 8;
631 dst[x_pos + y_pos++ * line_size + 1] =
r & 0xFF;
639 r = bytestream2_get_be16(gb);
640 while (l-- > 0 && x_pos < line_size) {
641 dst[x_pos + y_pos * line_size ] =
r >> 8;
642 dst[x_pos + y_pos++ * line_size + 1] =
r & 0xFF;
654 #define DECODE_RGBX_COMMON(type) \
656 length = bytestream2_get_byte(gb); \
658 length = bytestream2_get_be16(gb); \
663 for (i = 0; i < length; i++) { \
664 *(type *)(dst + y*linesize + x * sizeof(type)) = pixel; \
683 int x = 0, y = 0,
i, length;
685 uint32_t
pixel = 0xFF000000 | bytestream2_get_be24(gb);
686 length = bytestream2_get_byte(gb) & 0x7F;
700 int x = 0, y = 0,
i, length;
702 uint32_t
pixel = bytestream2_get_be16u(gb);
703 length =
pixel & 0x7;
720 const uint8_t *src_end =
src + src_size;
722 while (src_end -
src >= 5) {
724 opcode = *(int8_t *)
src++;
726 int size = opcode + 1;
729 if (src_end -
src < length * 4)
731 memcpy(dst + y*linesize + x * 4,
src, length * 4);
743 int size = -opcode + 1;
746 *(uint32_t *)(dst + y*linesize + x * 4) =
pixel;
772 int x = 0, y = 0, plane = 0;
776 for (
i = 0;
i < src_size * 2;) {
777 #define GETNIBBLE ((i & 1) ? (src[i>>1] & 0xF) : (src[i>>1] >> 4))
782 dst[y * linesize + x*4 + plane] =
pixel;
785 if (
i >= src_size * 2)
790 for (j = 0; j <
d; j++) {
791 dst[y * linesize + x*4 + plane] =
pixel;
811 const uint8_t *buf,
const uint8_t *buf_end,
812 int w,
int bpp,
int dst_size)
814 int planepitch =
FFALIGN(
w, 16) >> 3;
815 int pitch = planepitch * bpp;
818 unsigned ofssrc,
pos;
824 for (k = 0; k < bpp; k++) {
825 ofssrc = bytestream2_get_be32(&ptrs);
831 if (ofssrc >= buf_end - buf)
836 int16_t
offset = bytestream2_get_be16(&gb);
840 unsigned data = bytestream2_get_be16(&gb);
843 noffset = (
pos / planepitch) * pitch + (
pos % planepitch) + k * planepitch;
845 bytestream2_put_be16(&pb,
data);
847 uint16_t count = bytestream2_get_be16(&gb);
850 for (
i = 0;
i < count;
i++) {
851 uint16_t
data = bytestream2_get_be16(&gb);
854 noffset = (
pos / planepitch) * pitch + (
pos % planepitch) + k * planepitch;
856 bytestream2_put_be16(&pb,
data);
864 const uint8_t *buf,
const uint8_t *buf_end,
865 int w,
int xor,
int bpp,
int dst_size)
867 int ncolumns = ((
w + 15) / 16) * 2;
868 int dstpitch = ncolumns * bpp;
869 unsigned ofsdst, ofssrc, opcode, x;
877 for (k = 0; k < bpp; k++) {
878 ofssrc = bytestream2_get_be32(&ptrs);
883 if (ofssrc >= buf_end - buf)
887 for (j = 0; j < ncolumns; j++) {
888 ofsdst = j + k * ncolumns;
890 i = bytestream2_get_byte(&gb);
892 opcode = bytestream2_get_byte(&gb);
895 opcode = bytestream2_get_byte(&gb);
896 x = bytestream2_get_byte(&gb);
900 if (xor && ofsdst < dst_size) {
901 bytestream2_put_byte(&pb, dst[ofsdst] ^ x);
903 bytestream2_put_byte(&pb, x);
908 }
else if (opcode < 0x80) {
909 ofsdst += opcode * dstpitch;
915 if (xor && ofsdst < dst_size) {
916 bytestream2_put_byte(&pb, dst[ofsdst] ^ bytestream2_get_byte(&gb));
918 bytestream2_put_byte(&pb, bytestream2_get_byte(&gb));
931 const uint8_t *buf,
const uint8_t *buf_end,
932 int w,
int h,
int bpp,
int dst_size)
936 uint32_t
type,
flag, cols, groups, rows, bytes;
938 int planepitch_byte = (
w + 7) / 8;
939 int planepitch = ((
w + 15) / 16) * 2;
940 int kludge_j,
b,
g,
r,
d;
943 pitch = planepitch * bpp;
944 kludge_j =
w < 320 ? (320 -
w) / 8 / 2 : 0;
949 type = bytestream2_get_be16(&gb);
955 flag = bytestream2_get_be16(&gb);
956 cols = bytestream2_get_be16(&gb);
957 groups = bytestream2_get_be16(&gb);
959 for (
g = 0;
g < groups;
g++) {
960 offset = bytestream2_get_be16(&gb);
972 for (
b = 0;
b < cols;
b++) {
973 for (
d = 0;
d < bpp;
d++) {
974 uint8_t
value = bytestream2_get_byte(&gb);
988 if ((cols * bpp) & 1)
993 flag = bytestream2_get_be16(&gb);
994 rows = bytestream2_get_be16(&gb);
995 bytes = bytestream2_get_be16(&gb);
996 groups = bytestream2_get_be16(&gb);
998 for (
g = 0;
g < groups;
g++) {
999 offset = bytestream2_get_be16(&gb);
1006 for (
r = 0;
r < rows;
r++) {
1007 for (
d = 0;
d < bpp;
d++) {
1008 unsigned noffset =
offset + (
r * pitch) +
d * planepitch;
1015 for (
b = 0;
b < bytes;
b++) {
1016 uint8_t
value = bytestream2_get_byte(&gb);
1018 if (noffset >= dst_size)
1020 ptr = dst + noffset;
1031 if ((rows * bytes * bpp) & 1)
1042 const uint8_t *buf,
const uint8_t *buf_end,
1043 int w,
int bpp,
int dst_size)
1045 int ncolumns = (
w + 15) >> 4;
1046 int dstpitch = ncolumns * bpp * 2;
1047 unsigned ofsdst, ofssrc, ofsdata, opcode, x;
1052 if (buf_end - buf <= 64)
1059 for (k = 0; k < bpp; k++) {
1060 ofssrc = bytestream2_get_be32(&ptrs);
1061 ofsdata = bytestream2_get_be32(&dptrs);
1066 if (ofssrc >= buf_end - buf)
1069 if (ofsdata >= buf_end - buf)
1074 for (j = 0; j < ncolumns; j++) {
1075 ofsdst = (j + k * ncolumns) * 2;
1077 i = bytestream2_get_byte(&gb);
1079 opcode = bytestream2_get_byte(&gb);
1082 opcode = bytestream2_get_byte(&gb);
1083 x = bytestream2_get_be16(&dgb);
1087 bytestream2_put_be16(&pb, x);
1091 }
else if (opcode < 0x80) {
1092 ofsdst += opcode * dstpitch;
1098 bytestream2_put_be16(&pb, bytestream2_get_be16(&dgb));
1110 const uint8_t *buf,
const uint8_t *buf_end,
1111 int w,
int bpp,
int dst_size)
1113 int ncolumns = (
w + 31) >> 5;
1114 int dstpitch = ((
w + 15) / 16 * 2) * bpp;
1115 unsigned ofsdst, ofssrc, ofsdata, opcode, x;
1120 if (buf_end - buf <= 64)
1123 h = (((
w + 15) / 16 * 2) != ((
w + 31) / 32 * 4)) ? 1 : 0;
1128 for (k = 0; k < bpp; k++) {
1129 ofssrc = bytestream2_get_be32(&ptrs);
1130 ofsdata = bytestream2_get_be32(&dptrs);
1135 if (ofssrc >= buf_end - buf)
1138 if (ofsdata >= buf_end - buf)
1143 for (j = 0; j < ncolumns; j++) {
1144 ofsdst = (j + k * ncolumns) * 4 -
h * (2 * k);
1146 i = bytestream2_get_byte(&gb);
1148 opcode = bytestream2_get_byte(&gb);
1151 opcode = bytestream2_get_byte(&gb);
1152 if (
h && (j == (ncolumns - 1))) {
1153 x = bytestream2_get_be16(&dgb);
1156 x = bytestream2_get_be32(&dgb);
1164 if (
h && (j == (ncolumns - 1))) {
1165 bytestream2_put_be16(&pb, x);
1167 bytestream2_put_be32(&pb, x);
1172 }
else if (opcode < 0x80) {
1173 ofsdst += opcode * dstpitch;
1179 if (
h && (j == (ncolumns - 1))) {
1180 bytestream2_put_be16(&pb, bytestream2_get_be16(&dgb));
1183 bytestream2_put_be32(&pb, bytestream2_get_be32(&dgb));
1196 const uint8_t *buf,
const uint8_t *buf_end,
1197 int w,
int bpp,
int dst_size)
1199 int ncolumns = (
w + 15) >> 4;
1200 int dstpitch = ncolumns * bpp * 2;
1201 unsigned ofsdst, ofssrc, opcode, x;
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) * 2;
1222 i = bytestream2_get_be16(&gb);
1224 opcode = bytestream2_get_be16(&gb);
1227 opcode = bytestream2_get_be16(&gb);
1228 x = bytestream2_get_be16(&gb);
1232 bytestream2_put_be16(&pb, x);
1236 }
else if (opcode < 0x8000) {
1237 ofsdst += opcode * dstpitch;
1244 bytestream2_put_be16(&pb, bytestream2_get_be16(&gb));
1256 const uint8_t *buf,
const uint8_t *buf_end,
1257 int w,
int bpp,
int dst_size)
1259 int ncolumns = (
w + 31) >> 5;
1260 int dstpitch = ((
w + 15) / 16 * 2) * bpp;
1261 unsigned ofsdst, ofssrc, opcode, x;
1262 unsigned skip = 0x80000000,
mask = skip - 1;
1267 h = (((
w + 15) / 16 * 2) != ((
w + 31) / 32 * 4)) ? 1 : 0;
1271 for (k = 0; k < bpp; k++) {
1272 ofssrc = bytestream2_get_be32(&ptrs);
1277 if (ofssrc >= buf_end - buf)
1281 for (j = 0; j < ncolumns; j++) {
1282 ofsdst = (j + k * ncolumns) * 4 -
h * (2 * k);
1284 if (
h && (j == (ncolumns - 1))) {
1289 i = bytestream2_get_be32(&gb);
1291 opcode = bytestream2_get_be32(&gb);
1294 if (
h && (j == ncolumns - 1)) {
1295 opcode = bytestream2_get_be16(&gb);
1296 x = bytestream2_get_be16(&gb);
1298 opcode = bytestream2_get_be32(&gb);
1299 x = bytestream2_get_be32(&gb);
1307 if (
h && (j == ncolumns - 1))
1308 bytestream2_put_be16(&pb, x);
1310 bytestream2_put_be32(&pb, x);
1314 }
else if (opcode < skip) {
1315 ofsdst += opcode * dstpitch;
1322 if (
h && (j == ncolumns - 1)) {
1323 bytestream2_put_be16(&pb, bytestream2_get_be16(&gb));
1325 bytestream2_put_be32(&pb, bytestream2_get_be32(&gb));
1338 const uint8_t *buf,
const uint8_t *buf_end,
1339 int w,
int flag,
int bpp,
int dst_size)
1341 int planepitch =
FFALIGN(
w, 16) >> 3;
1342 int pitch = planepitch * bpp;
1343 int planepitch_byte = (
w + 7) / 8;
1344 unsigned entries, ofssrc;
1349 if (buf_end - buf <= 4 * bpp)
1355 for (k = 0; k < bpp; k++) {
1356 ofssrc = bytestream2_get_be32(&ptrs);
1361 if (ofssrc >= buf_end - buf)
1366 entries = bytestream2_get_be32(&gb);
1371 int32_t opcode = bytestream2_get_be32(&gb);
1372 unsigned offset = bytestream2_get_be32(&gb);
1376 uint32_t x = bytestream2_get_be32(&gb);
1380 bytestream2_put_be32(&pb, x);
1386 bytestream2_put_be32(&pb, bytestream2_get_be32(&gb));
1397 const uint8_t *buf,
const uint8_t *buf_end,
1398 int w,
int flag,
int bpp,
int dst_size)
1400 int planepitch =
FFALIGN(
w, 16) >> 3;
1401 int pitch = planepitch * bpp;
1402 int planepitch_byte = (
w + 7) / 8;
1403 unsigned entries, ofssrc;
1408 if (buf_end - buf <= 4 * bpp)
1414 for (k = 0; k < bpp; k++) {
1415 ofssrc = bytestream2_get_be32(&ptrs);
1420 if (ofssrc >= buf_end - buf)
1425 entries = bytestream2_get_be16(&gb);
1427 int16_t opcode = bytestream2_get_be16(&gb);
1428 unsigned offset = bytestream2_get_be32(&gb);
1432 uint16_t x = bytestream2_get_be16(&gb);
1434 bytestream2_put_be16(&pb, x);
1441 bytestream2_put_be16(&pb, bytestream2_get_be16(&gb));
1452 const uint8_t *buf,
const uint8_t *buf_end,
1453 int w,
int flag,
int bpp,
int dst_size)
1457 unsigned poff0, poff1;
1459 int planepitch_byte = (
w + 7) / 8;
1460 int planepitch = ((
w + 15) / 16) * 2;
1461 int pitch = planepitch * bpp;
1464 if (buf_end - buf <= 64)
1471 dstpitch =
flag ? (((
w + 7) / 8) * bpp): 2;
1473 for (k = 0; k < bpp; k++) {
1474 poff0 = bytestream2_get_be32(&off0);
1475 poff1 = bytestream2_get_be32(&off1);
1480 if (2LL * poff0 >= buf_end - buf)
1483 if (2LL * poff1 >= buf_end - buf)
1490 uint32_t
offset = bytestream2_get_be16(&ogb);
1491 int16_t cnt = bytestream2_get_be16(&ogb);
1494 if (count > dst_size)
1496 offset = ((2 *
offset) / planepitch_byte) * pitch + ((2 *
offset) % planepitch_byte) + k * planepitch;
1502 data = bytestream2_get_be16(&dgb);
1504 for (
i = 0;
i < cnt;
i++) {
1505 bytestream2_put_be16(&pb,
data);
1513 for (
i = 0;
i < cnt;
i++) {
1514 data = bytestream2_get_be16(&dgb);
1515 bytestream2_put_be16(&pb,
data);
1526 avpriv_request_sample(avctx,
"bitmap (compression 0x%0x, bpp %i, ham %i, interlaced %i)",
s->compression,
s->bpp,
s->ham,
s->is_interlaced);
1534 const uint8_t *buf = avpkt->
data;
1535 int buf_size = avpkt->
size;
1536 const uint8_t *buf_end = buf + buf_size;
1565 if (
s->compression <= 0xff && (avctx->
codec_tag ==
MKTAG(
'A',
'N',
'I',
'M'))) {
1567 memcpy(
s->pal,
s->frame->data[1], 256 * 4);
1570 switch (
s->compression) {
1575 for (plane = 0; plane <
s->bpp; plane++) {
1576 for (y = 0; y < avctx->
height && buf < buf_end; y++) {
1577 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1579 buf +=
s->planesize;
1582 }
else if (
s->ham) {
1584 for (y = 0; y < avctx->
height; y++) {
1585 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1586 memset(
s->ham_buf, 0,
s->planesize * 8);
1587 for (plane = 0; plane <
s->bpp; plane++) {
1588 const uint8_t * start = buf + (plane * avctx->
height + y) *
s->planesize;
1589 if (start >= buf_end)
1600 for (y = 0; y < avctx->
height && buf < buf_end; y++) {
1601 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1602 memcpy(row, buf,
FFMIN(raw_width, buf_end - buf));
1605 for (x = 0; x < avctx->
width; x++)
1606 row[4 * x + 3] = row[4 * x + 3] & 0xF0 | (row[4 * x + 3] >> 4);
1612 memcpy(
s->video[0], buf,
FFMIN(buf_end - buf,
s->video_size));
1614 for (y = 0; y < avctx->
height; y++) {
1615 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1616 memset(row, 0, avctx->
width);
1617 for (plane = 0; plane <
s->bpp && buf < buf_end; plane++) {
1619 buf +=
s->planesize;
1622 }
else if (
s->ham) {
1623 for (y = 0; y < avctx->
height; y++) {
1624 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1625 memset(
s->ham_buf, 0,
s->planesize * 8);
1626 for (plane = 0; plane <
s->bpp && buf < buf_end; plane++) {
1628 buf +=
s->planesize;
1633 for (y = 0; y < avctx->
height; y++) {
1634 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1635 memset(row, 0, avctx->
width << 2);
1636 for (plane = 0; plane <
s->bpp && buf < buf_end; plane++) {
1638 FFMIN(
s->planesize, buf_end - buf), plane);
1639 buf +=
s->planesize;
1645 for (y = 0; y < avctx->
height && buf_end > buf; y++) {
1646 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1647 memcpy(row, buf,
FFMIN(avctx->
width, buf_end - buf));
1650 }
else if (
s->ham) {
1651 for (y = 0; y < avctx->
height && buf_end > buf; y++) {
1652 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1653 memcpy(
s->ham_buf, buf,
FFMIN(avctx->
width, buf_end - buf));
1667 uint8_t *
video =
s->video[0];
1669 for (y = 0; y < avctx->
height; y++) {
1670 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1671 memset(row, 0, avctx->
width);
1672 for (plane = 0; plane <
s->bpp; plane++) {
1675 memcpy(
video,
s->planebuf,
s->planesize);
1682 for (y = 0; y < avctx->
height; y++) {
1683 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1684 memset(
s->mask_buf, 0, avctx->
width *
sizeof(uint32_t));
1685 for (plane = 0; plane <
s->bpp; plane++) {
1691 }
else if (
s->ham) {
1692 uint8_t *
video =
s->video[0];
1693 for (y = 0; y < avctx->
height; y++) {
1694 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1695 memset(
s->ham_buf, 0,
s->planesize * 8);
1696 for (plane = 0; plane <
s->bpp; plane++) {
1699 memcpy(
video,
s->planebuf,
s->planesize);
1707 for (y = 0; y < avctx->
height; y++) {
1708 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1709 memset(row, 0, avctx->
width << 2);
1710 for (plane = 0; plane <
s->bpp; plane++) {
1718 for (y = 0; y < avctx->
height; y++) {
1719 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1722 }
else if (
s->ham) {
1723 for (y = 0; y < avctx->
height; y++) {
1724 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1738 for (plane = 0; plane <
s->bpp; plane++) {
1739 for (y = 0; y < avctx->
height && buf < buf_end; y++) {
1740 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1742 buf +=
s->planesize;
1745 }
else if (
s->ham) {
1747 for (y = 0; y < avctx->
height; y++) {
1748 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1749 memset(
s->ham_buf, 0,
s->planesize * 8);
1750 for (plane = 0; plane <
s->bpp; plane++) {
1751 const uint8_t * start = buf + (plane * avctx->
height + y) *
s->planesize;
1752 if (start >= buf_end)
1767 for (plane = 0; plane <
s->bpp; plane++) {
1769 for (y = 0; y < avctx->
height; y++) {
1770 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1771 decodeplane8(row,
s->planebuf +
s->planesize * y,
s->planesize, plane);
1823 if (
s->is_interlaced)
1829 if (
s->is_interlaced)
1841 if (
s->compression <= 0xff && (avctx->
codec_tag ==
MKTAG(
'A',
'N',
'I',
'M'))) {
1842 memcpy(
s->video[1],
s->video[0],
s->video_size);
1845 if (
s->compression > 0xff) {
1848 for (y = 0; y < avctx->
height; y++) {
1849 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1850 memset(row, 0, avctx->
width);
1851 for (plane = 0; plane <
s->bpp; plane++) {
1853 buf +=
s->planesize;
1857 memcpy(
frame->data[1],
s->pal, 256 * 4);
1858 }
else if (
s->ham) {
1859 int i, count = 1 <<
s->ham;
1862 memset(
s->ham_palbuf, 0, (1 <<
s->ham) * 2 *
sizeof(uint32_t));
1863 for (
i = 0;
i < count;
i++) {
1864 s->ham_palbuf[
i*2+1] =
s->pal[
i];
1866 for (
i = 0;
i < count;
i++) {
1867 uint32_t
tmp =
i << (8 -
s->ham);
1869 s->ham_palbuf[(
i+count)*2] = 0xFF00FFFF;
1870 s->ham_palbuf[(
i+count*2)*2] = 0xFFFFFF00;
1871 s->ham_palbuf[(
i+count*3)*2] = 0xFFFF00FF;
1872 s->ham_palbuf[(
i+count)*2+1] = 0xFF000000 |
tmp << 16;
1873 s->ham_palbuf[(
i+count*2)*2+1] = 0xFF000000 |
tmp;
1874 s->ham_palbuf[(
i+count*3)*2+1] = 0xFF000000 |
tmp << 8;
1877 for (
i = 0;
i < 8 * (1 <<
s->ham);
i++)
1878 s->ham_palbuf[(1 <<
s->bpp) +
i] =
s->ham_palbuf[
i] | 0xFF000000;
1880 for (y = 0; y < avctx->
height; y++) {
1881 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1882 memset(
s->ham_buf, 0,
s->planesize * 8);
1883 for (plane = 0; plane <
s->bpp; plane++) {
1885 buf +=
s->planesize;
1894 FFSWAP(uint8_t *,
s->video[0],
s->video[1]);
1899 frame->key_frame = 1;
1902 frame->key_frame = 0;
1911 #if CONFIG_IFF_ILBM_DECODER