71 #define LUT8_PART(plane, v) \
72 AV_LE2NE64C(UINT64_C(0x0000000)<<32 | v) << plane, \
73 AV_LE2NE64C(UINT64_C(0x1000000)<<32 | v) << plane, \
74 AV_LE2NE64C(UINT64_C(0x0010000)<<32 | v) << plane, \
75 AV_LE2NE64C(UINT64_C(0x1010000)<<32 | v) << plane, \
76 AV_LE2NE64C(UINT64_C(0x0000100)<<32 | v) << plane, \
77 AV_LE2NE64C(UINT64_C(0x1000100)<<32 | v) << plane, \
78 AV_LE2NE64C(UINT64_C(0x0010100)<<32 | v) << plane, \
79 AV_LE2NE64C(UINT64_C(0x1010100)<<32 | v) << plane, \
80 AV_LE2NE64C(UINT64_C(0x0000001)<<32 | v) << plane, \
81 AV_LE2NE64C(UINT64_C(0x1000001)<<32 | v) << plane, \
82 AV_LE2NE64C(UINT64_C(0x0010001)<<32 | v) << plane, \
83 AV_LE2NE64C(UINT64_C(0x1010001)<<32 | v) << plane, \
84 AV_LE2NE64C(UINT64_C(0x0000101)<<32 | v) << plane, \
85 AV_LE2NE64C(UINT64_C(0x1000101)<<32 | v) << plane, \
86 AV_LE2NE64C(UINT64_C(0x0010101)<<32 | v) << plane, \
87 AV_LE2NE64C(UINT64_C(0x1010101)<<32 | v) << plane
89 #define LUT8(plane) { \
90 LUT8_PART(plane, 0x0000000), \
91 LUT8_PART(plane, 0x1000000), \
92 LUT8_PART(plane, 0x0010000), \
93 LUT8_PART(plane, 0x1010000), \
94 LUT8_PART(plane, 0x0000100), \
95 LUT8_PART(plane, 0x1000100), \
96 LUT8_PART(plane, 0x0010100), \
97 LUT8_PART(plane, 0x1010100), \
98 LUT8_PART(plane, 0x0000001), \
99 LUT8_PART(plane, 0x1000001), \
100 LUT8_PART(plane, 0x0010001), \
101 LUT8_PART(plane, 0x1010001), \
102 LUT8_PART(plane, 0x0000101), \
103 LUT8_PART(plane, 0x1000101), \
104 LUT8_PART(plane, 0x0010101), \
105 LUT8_PART(plane, 0x1010101), \
114 #define LUT32(plane) { \
116 0, 0, 0, 1U << plane, \
117 0, 0, 1U << plane, 0, \
118 0, 0, 1U << plane, 1U << plane, \
119 0, 1U << plane, 0, 0, \
120 0, 1U << plane, 0, 1U << plane, \
121 0, 1U << plane, 1U << plane, 0, \
122 0, 1U << plane, 1U << plane, 1U << plane, \
123 1U << plane, 0, 0, 0, \
124 1U << plane, 0, 0, 1U << plane, \
125 1U << plane, 0, 1U << plane, 0, \
126 1U << plane, 0, 1U << plane, 1U << plane, \
127 1U << plane, 1U << plane, 0, 0, \
128 1U << plane, 1U << plane, 0, 1U << plane, \
129 1U << plane, 1U << plane, 1U << plane, 0, \
130 1U << plane, 1U << plane, 1U << plane, 1U << plane, \
147 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;
209 unsigned buf_size = 0;
225 chunk_id = bytestream2_get_le32(gb);
226 data_size = bytestream2_get_be32(gb);
228 if (chunk_id ==
MKTAG(
'B',
'M',
'H',
'D')) {
230 }
else if (chunk_id ==
MKTAG(
'A',
'N',
'H',
'D')) {
235 s->compression = (bytestream2_get_byte(gb) << 8) | (
s->compression & 0xFF);
237 extra = bytestream2_get_be32(gb);
238 s->is_short = !(extra & 1);
239 s->is_brush = extra == 2;
240 s->is_interlaced = !!(extra & 0x40);
243 }
else if (chunk_id ==
MKTAG(
'D',
'L',
'T',
'A') ||
244 chunk_id ==
MKTAG(
'B',
'O',
'D',
'Y')) {
245 if (chunk_id ==
MKTAG(
'B',
'O',
'D',
'Y'))
246 s->compression &= 0xFF;
248 }
else if (chunk_id ==
MKTAG(
'C',
'M',
'A',
'P')) {
249 int count = data_size / 3;
250 uint32_t *pal =
s->pal;
255 for (
i = 0;
i < count;
i++)
256 pal[
i] = 0xFF000000 | bytestream2_get_le24(gb);
258 for (
i = 0;
i < count;
i++)
259 pal[
i] = 0xFF000000 | bytestream2_get_be24(gb);
268 buf_size = bytestream_get_be16(&buf);
269 if (buf_size <= 1 || palette_size < 0) {
271 "Invalid palette size received: %u -> palette data offset: %d\n",
272 buf_size, palette_size);
277 if (buf_size >= 41) {
278 s->compression = bytestream_get_byte(&buf);
279 s->bpp = bytestream_get_byte(&buf);
280 s->ham = bytestream_get_byte(&buf);
281 s->flags = bytestream_get_byte(&buf);
282 s->transparency = bytestream_get_be16(&buf);
283 s->masking = bytestream_get_byte(&buf);
284 for (
i = 0;
i < 16;
i++)
285 s->tvdc[
i] = bytestream_get_be16(&buf);
291 }
else if (
s->ham != (
s->bpp > 6 ? 6 : 4)) {
292 av_log(avctx,
AV_LOG_ERROR,
"Invalid number of hold bits for HAM: %u, BPP: %u\n",
s->ham,
s->bpp);
298 if (
s->bpp >= 8 && !
s->ham) {
310 if (!
s->mask_palbuf) {
320 if (!
s->bpp ||
s->bpp > 32) {
324 if (
s->video_size &&
s->planesize *
s->bpp * avctx->
height >
s->video_size)
331 int i, count =
FFMIN(palette_size / 3, 1 <<
s->ham);
343 ham_count = 8 * (1 <<
s->ham);
345 if (!
s->ham_palbuf) {
352 memset(
s->ham_palbuf, 0, (1 <<
s->ham) * 2 * sizeof (uint32_t));
353 for (
i=0;
i < count;
i++) {
354 s->ham_palbuf[
i*2+1] = 0xFF000000 |
AV_RL24(palette +
i*3);
359 for (
i=0;
i < count;
i++) {
360 s->ham_palbuf[
i*2] = 0xFF000000;
364 for (
i=0;
i < count;
i++) {
365 uint32_t
tmp =
i << (8 -
s->ham);
367 s->ham_palbuf[(
i+count)*2] = 0xFF00FFFF;
368 s->ham_palbuf[(
i+count*2)*2] = 0xFFFFFF00;
369 s->ham_palbuf[(
i+count*3)*2] = 0xFFFF00FF;
370 s->ham_palbuf[(
i+count)*2+1] = 0xFF000000 |
tmp << 16;
371 s->ham_palbuf[(
i+count*2)*2+1] = 0xFF000000 |
tmp;
372 s->ham_palbuf[(
i+count*3)*2+1] = 0xFF000000 |
tmp << 8;
375 for (
i = 0;
i < ham_count;
i++)
376 s->ham_palbuf[(1 <<
s->bpp) +
i] =
s->ham_palbuf[
i] | 0xFF000000;
447 if (!
s->video[0] || !
s->video[1] || !
s->pal)
464 static void decodeplane8(uint8_t *dst,
const uint8_t *buf,
int buf_size,
int plane)
473 uint64_t v =
AV_RN64A(dst) | lut[*buf++];
476 }
while (--buf_size);
486 static void decodeplane32(uint32_t *dst,
const uint8_t *buf,
int buf_size,
int plane)
490 unsigned mask = (*buf >> 2) & ~3;
491 dst[0] |= lut[
mask++];
492 dst[1] |= lut[
mask++];
493 dst[2] |= lut[
mask++];
495 mask = (*buf++ << 2) & 0x3F;
496 dst[4] |= lut[
mask++];
497 dst[5] |= lut[
mask++];
498 dst[6] |= lut[
mask++];
501 }
while (--buf_size);
504 #define DECODE_HAM_PLANE32(x) \
505 first = buf[x] << 1; \
506 second = buf[(x)+1] << 1; \
507 delta &= pal[first++]; \
508 delta |= pal[first]; \
510 delta &= pal[second++]; \
511 delta |= pal[second]; \
523 const uint32_t *
const pal,
unsigned buf_size)
525 uint32_t
delta = pal[1];
527 uint32_t
first, second;
534 }
while (--buf_size);
538 const uint32_t *
const pal,
unsigned width)
541 *dst++ = pal[*buf++];
560 const int8_t
value = bytestream2_get_byte(gb);
564 if (length <
value + 1)
566 }
else if (
value > -128) {
568 memset(dst + x, bytestream2_get_byte(gb), length);
576 memset(dst+x, 0, dst_size - x);
586 int i, y_pos = 0, x_pos = 0;
588 if (bytestream2_get_be32(gb) !=
MKBETAG(
'V',
'D',
'A',
'T'))
592 count = bytestream2_get_be16(gb) - 2;
599 for (
i = 0;
i < count && x_pos < line_size;
i++) {
600 int8_t cmd = bytestream2_get_byte(&
cmds);
604 l = bytestream2_get_be16(gb);
605 while (l-- > 0 && x_pos < line_size) {
606 dst[x_pos + y_pos * line_size ] = bytestream2_get_byte(gb);
607 dst[x_pos + y_pos++ * line_size + 1] = bytestream2_get_byte(gb);
613 }
else if (cmd < 0) {
615 while (l-- > 0 && x_pos < line_size) {
616 dst[x_pos + y_pos * line_size ] = bytestream2_get_byte(gb);
617 dst[x_pos + y_pos++ * line_size + 1] = bytestream2_get_byte(gb);
623 }
else if (cmd == 1) {
624 l = bytestream2_get_be16(gb);
625 r = bytestream2_get_be16(gb);
626 while (l-- > 0 && x_pos < line_size) {
627 dst[x_pos + y_pos * line_size ] =
r >> 8;
628 dst[x_pos + y_pos++ * line_size + 1] =
r & 0xFF;
636 r = bytestream2_get_be16(gb);
637 while (l-- > 0 && x_pos < line_size) {
638 dst[x_pos + y_pos * line_size ] =
r >> 8;
639 dst[x_pos + y_pos++ * line_size + 1] =
r & 0xFF;
651 #define DECODE_RGBX_COMMON(type) \
653 length = bytestream2_get_byte(gb); \
655 length = bytestream2_get_be16(gb); \
660 for (i = 0; i < length; i++) { \
661 *(type *)(dst + y*linesize + x * sizeof(type)) = pixel; \
680 int x = 0, y = 0,
i, length;
682 uint32_t
pixel = 0xFF000000 | bytestream2_get_be24(gb);
683 length = bytestream2_get_byte(gb) & 0x7F;
697 int x = 0, y = 0,
i, length;
699 uint32_t
pixel = bytestream2_get_be16u(gb);
700 length =
pixel & 0x7;
717 const uint8_t *src_end =
src + src_size;
719 while (src_end -
src >= 5) {
721 opcode = *(int8_t *)
src++;
723 int size = opcode + 1;
726 if (src_end -
src < length * 4)
728 memcpy(dst + y*linesize + x * 4,
src, length * 4);
740 int size = -opcode + 1;
743 *(uint32_t *)(dst + y*linesize + x * 4) =
pixel;
769 int x = 0, y = 0, plane = 0;
773 for (
i = 0;
i < src_size * 2;) {
774 #define GETNIBBLE ((i & 1) ? (src[i>>1] & 0xF) : (src[i>>1] >> 4))
779 dst[y * linesize + x*4 + plane] =
pixel;
782 if (
i >= src_size * 2)
787 for (j = 0; j <
d; j++) {
788 dst[y * linesize + x*4 + plane] =
pixel;
808 const uint8_t *buf,
const uint8_t *buf_end,
809 int w,
int bpp,
int dst_size)
811 int planepitch =
FFALIGN(
w, 16) >> 3;
812 int pitch = planepitch * bpp;
815 unsigned ofssrc,
pos;
821 for (k = 0; k < bpp; k++) {
822 ofssrc = bytestream2_get_be32(&ptrs);
828 if (ofssrc >= buf_end - buf)
833 int16_t
offset = bytestream2_get_be16(&gb);
837 unsigned data = bytestream2_get_be16(&gb);
840 noffset = (
pos / planepitch) * pitch + (
pos % planepitch) + k * planepitch;
842 bytestream2_put_be16(&pb,
data);
844 uint16_t count = bytestream2_get_be16(&gb);
847 for (
i = 0;
i < count;
i++) {
848 uint16_t
data = bytestream2_get_be16(&gb);
851 noffset = (
pos / planepitch) * pitch + (
pos % planepitch) + k * planepitch;
853 bytestream2_put_be16(&pb,
data);
861 const uint8_t *buf,
const uint8_t *buf_end,
862 int w,
int xor,
int bpp,
int dst_size)
864 int ncolumns = ((
w + 15) / 16) * 2;
865 int dstpitch = ncolumns * bpp;
866 unsigned ofsdst, ofssrc, opcode, x;
874 for (k = 0; k < bpp; k++) {
875 ofssrc = bytestream2_get_be32(&ptrs);
880 if (ofssrc >= buf_end - buf)
884 for (j = 0; j < ncolumns; j++) {
885 ofsdst = j + k * ncolumns;
887 i = bytestream2_get_byte(&gb);
889 opcode = bytestream2_get_byte(&gb);
892 opcode = bytestream2_get_byte(&gb);
893 x = bytestream2_get_byte(&gb);
897 if (xor && ofsdst < dst_size) {
898 bytestream2_put_byte(&pb, dst[ofsdst] ^ x);
900 bytestream2_put_byte(&pb, x);
905 }
else if (opcode < 0x80) {
906 ofsdst += opcode * dstpitch;
912 if (xor && ofsdst < dst_size) {
913 bytestream2_put_byte(&pb, dst[ofsdst] ^ bytestream2_get_byte(&gb));
915 bytestream2_put_byte(&pb, bytestream2_get_byte(&gb));
928 const uint8_t *buf,
const uint8_t *buf_end,
929 int w,
int h,
int bpp,
int dst_size)
933 uint32_t
type,
flag, cols, groups, rows, bytes;
935 int planepitch_byte = (
w + 7) / 8;
936 int planepitch = ((
w + 15) / 16) * 2;
937 int kludge_j,
b,
g,
r,
d;
940 pitch = planepitch * bpp;
941 kludge_j =
w < 320 ? (320 -
w) / 8 / 2 : 0;
946 type = bytestream2_get_be16(&gb);
952 flag = bytestream2_get_be16(&gb);
953 cols = bytestream2_get_be16(&gb);
954 groups = bytestream2_get_be16(&gb);
956 for (
g = 0;
g < groups;
g++) {
957 offset = bytestream2_get_be16(&gb);
969 for (
b = 0;
b < cols;
b++) {
970 for (
d = 0;
d < bpp;
d++) {
971 uint8_t
value = bytestream2_get_byte(&gb);
985 if ((cols * bpp) & 1)
990 flag = bytestream2_get_be16(&gb);
991 rows = bytestream2_get_be16(&gb);
992 bytes = bytestream2_get_be16(&gb);
993 groups = bytestream2_get_be16(&gb);
995 for (
g = 0;
g < groups;
g++) {
996 offset = bytestream2_get_be16(&gb);
1003 for (
r = 0;
r < rows;
r++) {
1004 for (
d = 0;
d < bpp;
d++) {
1005 unsigned noffset =
offset + (
r * pitch) +
d * planepitch;
1012 for (
b = 0;
b < bytes;
b++) {
1013 uint8_t
value = bytestream2_get_byte(&gb);
1015 if (noffset >= dst_size)
1017 ptr = dst + noffset;
1028 if ((rows * bytes * bpp) & 1)
1039 const uint8_t *buf,
const uint8_t *buf_end,
1040 int w,
int bpp,
int dst_size)
1042 int ncolumns = (
w + 15) >> 4;
1043 int dstpitch = ncolumns * bpp * 2;
1044 unsigned ofsdst, ofssrc, ofsdata, opcode, x;
1049 if (buf_end - buf <= 64)
1056 for (k = 0; k < bpp; k++) {
1057 ofssrc = bytestream2_get_be32(&ptrs);
1058 ofsdata = bytestream2_get_be32(&dptrs);
1063 if (ofssrc >= buf_end - buf)
1066 if (ofsdata >= buf_end - buf)
1071 for (j = 0; j < ncolumns; j++) {
1072 ofsdst = (j + k * ncolumns) * 2;
1074 i = bytestream2_get_byte(&gb);
1076 opcode = bytestream2_get_byte(&gb);
1079 opcode = bytestream2_get_byte(&gb);
1080 x = bytestream2_get_be16(&dgb);
1084 bytestream2_put_be16(&pb, x);
1088 }
else if (opcode < 0x80) {
1089 ofsdst += opcode * dstpitch;
1095 bytestream2_put_be16(&pb, bytestream2_get_be16(&dgb));
1107 const uint8_t *buf,
const uint8_t *buf_end,
1108 int w,
int bpp,
int dst_size)
1110 int ncolumns = (
w + 31) >> 5;
1111 int dstpitch = ((
w + 15) / 16 * 2) * bpp;
1112 unsigned ofsdst, ofssrc, ofsdata, opcode, x;
1117 if (buf_end - buf <= 64)
1120 h = (((
w + 15) / 16 * 2) != ((
w + 31) / 32 * 4)) ? 1 : 0;
1125 for (k = 0; k < bpp; k++) {
1126 ofssrc = bytestream2_get_be32(&ptrs);
1127 ofsdata = bytestream2_get_be32(&dptrs);
1132 if (ofssrc >= buf_end - buf)
1135 if (ofsdata >= buf_end - buf)
1140 for (j = 0; j < ncolumns; j++) {
1141 ofsdst = (j + k * ncolumns) * 4 -
h * (2 * k);
1143 i = bytestream2_get_byte(&gb);
1145 opcode = bytestream2_get_byte(&gb);
1148 opcode = bytestream2_get_byte(&gb);
1149 if (
h && (j == (ncolumns - 1))) {
1150 x = bytestream2_get_be16(&dgb);
1153 x = bytestream2_get_be32(&dgb);
1161 if (
h && (j == (ncolumns - 1))) {
1162 bytestream2_put_be16(&pb, x);
1164 bytestream2_put_be32(&pb, x);
1169 }
else if (opcode < 0x80) {
1170 ofsdst += opcode * dstpitch;
1176 if (
h && (j == (ncolumns - 1))) {
1177 bytestream2_put_be16(&pb, bytestream2_get_be16(&dgb));
1180 bytestream2_put_be32(&pb, bytestream2_get_be32(&dgb));
1193 const uint8_t *buf,
const uint8_t *buf_end,
1194 int w,
int bpp,
int dst_size)
1196 int ncolumns = (
w + 15) >> 4;
1197 int dstpitch = ncolumns * bpp * 2;
1198 unsigned ofsdst, ofssrc, opcode, x;
1206 for (k = 0; k < bpp; k++) {
1207 ofssrc = bytestream2_get_be32(&ptrs);
1212 if (ofssrc >= buf_end - buf)
1216 for (j = 0; j < ncolumns; j++) {
1217 ofsdst = (j + k * ncolumns) * 2;
1219 i = bytestream2_get_be16(&gb);
1221 opcode = bytestream2_get_be16(&gb);
1224 opcode = bytestream2_get_be16(&gb);
1225 x = bytestream2_get_be16(&gb);
1229 bytestream2_put_be16(&pb, x);
1233 }
else if (opcode < 0x8000) {
1234 ofsdst += opcode * dstpitch;
1241 bytestream2_put_be16(&pb, bytestream2_get_be16(&gb));
1253 const uint8_t *buf,
const uint8_t *buf_end,
1254 int w,
int bpp,
int dst_size)
1256 int ncolumns = (
w + 31) >> 5;
1257 int dstpitch = ((
w + 15) / 16 * 2) * bpp;
1258 unsigned ofsdst, ofssrc, opcode, x;
1259 unsigned skip = 0x80000000,
mask = skip - 1;
1264 h = (((
w + 15) / 16 * 2) != ((
w + 31) / 32 * 4)) ? 1 : 0;
1268 for (k = 0; k < bpp; k++) {
1269 ofssrc = bytestream2_get_be32(&ptrs);
1274 if (ofssrc >= buf_end - buf)
1278 for (j = 0; j < ncolumns; j++) {
1279 ofsdst = (j + k * ncolumns) * 4 -
h * (2 * k);
1281 if (
h && (j == (ncolumns - 1))) {
1286 i = bytestream2_get_be32(&gb);
1288 opcode = bytestream2_get_be32(&gb);
1291 if (
h && (j == ncolumns - 1)) {
1292 opcode = bytestream2_get_be16(&gb);
1293 x = bytestream2_get_be16(&gb);
1295 opcode = bytestream2_get_be32(&gb);
1296 x = bytestream2_get_be32(&gb);
1304 if (
h && (j == ncolumns - 1))
1305 bytestream2_put_be16(&pb, x);
1307 bytestream2_put_be32(&pb, x);
1311 }
else if (opcode < skip) {
1312 ofsdst += opcode * dstpitch;
1319 if (
h && (j == ncolumns - 1)) {
1320 bytestream2_put_be16(&pb, bytestream2_get_be16(&gb));
1322 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_be32(&gb);
1368 int32_t opcode = bytestream2_get_be32(&gb);
1369 unsigned offset = bytestream2_get_be32(&gb);
1373 uint32_t x = bytestream2_get_be32(&gb);
1377 bytestream2_put_be32(&pb, x);
1383 bytestream2_put_be32(&pb, bytestream2_get_be32(&gb));
1394 const uint8_t *buf,
const uint8_t *buf_end,
1395 int w,
int flag,
int bpp,
int dst_size)
1397 int planepitch =
FFALIGN(
w, 16) >> 3;
1398 int pitch = planepitch * bpp;
1399 int planepitch_byte = (
w + 7) / 8;
1400 unsigned entries, ofssrc;
1405 if (buf_end - buf <= 4 * bpp)
1411 for (k = 0; k < bpp; k++) {
1412 ofssrc = bytestream2_get_be32(&ptrs);
1417 if (ofssrc >= buf_end - buf)
1422 entries = bytestream2_get_be16(&gb);
1424 int16_t opcode = bytestream2_get_be16(&gb);
1425 unsigned offset = bytestream2_get_be32(&gb);
1429 uint16_t x = bytestream2_get_be16(&gb);
1431 bytestream2_put_be16(&pb, x);
1438 bytestream2_put_be16(&pb, bytestream2_get_be16(&gb));
1449 const uint8_t *buf,
const uint8_t *buf_end,
1450 int w,
int flag,
int bpp,
int dst_size)
1454 unsigned poff0, poff1;
1456 int planepitch_byte = (
w + 7) / 8;
1457 int planepitch = ((
w + 15) / 16) * 2;
1458 int pitch = planepitch * bpp;
1461 if (buf_end - buf <= 64)
1468 dstpitch =
flag ? (((
w + 7) / 8) * bpp): 2;
1470 for (k = 0; k < bpp; k++) {
1471 poff0 = bytestream2_get_be32(&off0);
1472 poff1 = bytestream2_get_be32(&off1);
1477 if (2LL * poff0 >= buf_end - buf)
1480 if (2LL * poff1 >= buf_end - buf)
1487 uint32_t
offset = bytestream2_get_be16(&ogb);
1488 int16_t cnt = bytestream2_get_be16(&ogb);
1491 if (count > dst_size)
1493 offset = ((2 *
offset) / planepitch_byte) * pitch + ((2 *
offset) % planepitch_byte) + k * planepitch;
1499 data = bytestream2_get_be16(&dgb);
1501 for (
i = 0;
i < cnt;
i++) {
1502 bytestream2_put_be16(&pb,
data);
1510 for (
i = 0;
i < cnt;
i++) {
1511 data = bytestream2_get_be16(&dgb);
1512 bytestream2_put_be16(&pb,
data);
1523 avpriv_request_sample(avctx,
"bitmap (compression 0x%0x, bpp %i, ham %i, interlaced %i)",
s->compression,
s->bpp,
s->ham,
s->is_interlaced);
1528 void *
data,
int *got_frame,
1533 const uint8_t *buf = avpkt->
data;
1534 int buf_size = avpkt->
size;
1535 const uint8_t *buf_end = buf + buf_size;
1564 if (
s->compression <= 0xff && (avctx->
codec_tag ==
MKTAG(
'A',
'N',
'I',
'M'))) {
1566 memcpy(
s->pal,
s->frame->data[1], 256 * 4);
1569 switch (
s->compression) {
1574 for (plane = 0; plane <
s->bpp; plane++) {
1575 for (y = 0; y < avctx->
height && buf < buf_end; y++) {
1576 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1578 buf +=
s->planesize;
1581 }
else if (
s->ham) {
1583 for (y = 0; y < avctx->
height; y++) {
1584 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1585 memset(
s->ham_buf, 0,
s->planesize * 8);
1586 for (plane = 0; plane <
s->bpp; plane++) {
1587 const uint8_t * start = buf + (plane * avctx->
height + y) *
s->planesize;
1588 if (start >= buf_end)
1599 for (y = 0; y < avctx->
height && buf < buf_end; y++) {
1600 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1601 memcpy(row, buf,
FFMIN(raw_width, buf_end - buf));
1604 for (x = 0; x < avctx->
width; x++)
1605 row[4 * x + 3] = row[4 * x + 3] & 0xF0 | (row[4 * x + 3] >> 4);
1611 memcpy(
s->video[0], buf,
FFMIN(buf_end - buf,
s->video_size));
1613 for (y = 0; y < avctx->
height; y++) {
1614 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1615 memset(row, 0, avctx->
width);
1616 for (plane = 0; plane <
s->bpp && buf < buf_end; plane++) {
1618 buf +=
s->planesize;
1621 }
else if (
s->ham) {
1622 for (y = 0; y < avctx->
height; y++) {
1623 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1624 memset(
s->ham_buf, 0,
s->planesize * 8);
1625 for (plane = 0; plane <
s->bpp && buf < buf_end; plane++) {
1627 buf +=
s->planesize;
1632 for (y = 0; y < avctx->
height; y++) {
1633 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1634 memset(row, 0, avctx->
width << 2);
1635 for (plane = 0; plane <
s->bpp && buf < buf_end; plane++) {
1637 FFMIN(
s->planesize, buf_end - buf), plane);
1638 buf +=
s->planesize;
1644 for (y = 0; y < avctx->
height && buf_end > buf; y++) {
1645 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1646 memcpy(row, buf,
FFMIN(avctx->
width, buf_end - buf));
1649 }
else if (
s->ham) {
1650 for (y = 0; y < avctx->
height && buf_end > buf; y++) {
1651 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1652 memcpy(
s->ham_buf, buf,
FFMIN(avctx->
width, buf_end - buf));
1666 uint8_t *
video =
s->video[0];
1668 for (y = 0; y < avctx->
height; y++) {
1669 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1670 memset(row, 0, avctx->
width);
1671 for (plane = 0; plane <
s->bpp; plane++) {
1674 memcpy(
video,
s->planebuf,
s->planesize);
1681 for (y = 0; y < avctx->
height; y++) {
1682 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1683 memset(
s->mask_buf, 0, avctx->
width *
sizeof(uint32_t));
1684 for (plane = 0; plane <
s->bpp; plane++) {
1690 }
else if (
s->ham) {
1691 uint8_t *
video =
s->video[0];
1692 for (y = 0; y < avctx->
height; y++) {
1693 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1694 memset(
s->ham_buf, 0,
s->planesize * 8);
1695 for (plane = 0; plane <
s->bpp; plane++) {
1698 memcpy(
video,
s->planebuf,
s->planesize);
1706 for (y = 0; y < avctx->
height; y++) {
1707 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1708 memset(row, 0, avctx->
width << 2);
1709 for (plane = 0; plane <
s->bpp; plane++) {
1717 for (y = 0; y < avctx->
height; y++) {
1718 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1721 }
else if (
s->ham) {
1722 for (y = 0; y < avctx->
height; y++) {
1723 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1737 for (plane = 0; plane <
s->bpp; plane++) {
1738 for (y = 0; y < avctx->
height && buf < buf_end; y++) {
1739 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1741 buf +=
s->planesize;
1744 }
else if (
s->ham) {
1746 for (y = 0; y < avctx->
height; y++) {
1747 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1748 memset(
s->ham_buf, 0,
s->planesize * 8);
1749 for (plane = 0; plane <
s->bpp; plane++) {
1750 const uint8_t * start = buf + (plane * avctx->
height + y) *
s->planesize;
1751 if (start >= buf_end)
1766 for (plane = 0; plane <
s->bpp; plane++) {
1768 for (y = 0; y < avctx->
height; y++) {
1769 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1770 decodeplane8(row,
s->planebuf +
s->planesize * y,
s->planesize, plane);
1822 if (
s->is_interlaced)
1828 if (
s->is_interlaced)
1840 if (
s->compression <= 0xff && (avctx->
codec_tag ==
MKTAG(
'A',
'N',
'I',
'M'))) {
1841 memcpy(
s->video[1],
s->video[0],
s->video_size);
1844 if (
s->compression > 0xff) {
1847 for (y = 0; y < avctx->
height; y++) {
1848 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1849 memset(row, 0, avctx->
width);
1850 for (plane = 0; plane <
s->bpp; plane++) {
1852 buf +=
s->planesize;
1856 memcpy(
frame->data[1],
s->pal, 256 * 4);
1857 }
else if (
s->ham) {
1858 int i, count = 1 <<
s->ham;
1861 memset(
s->ham_palbuf, 0, (1 <<
s->ham) * 2 *
sizeof(uint32_t));
1862 for (
i = 0;
i < count;
i++) {
1863 s->ham_palbuf[
i*2+1] =
s->pal[
i];
1865 for (
i = 0;
i < count;
i++) {
1866 uint32_t
tmp =
i << (8 -
s->ham);
1868 s->ham_palbuf[(
i+count)*2] = 0xFF00FFFF;
1869 s->ham_palbuf[(
i+count*2)*2] = 0xFFFFFF00;
1870 s->ham_palbuf[(
i+count*3)*2] = 0xFFFF00FF;
1871 s->ham_palbuf[(
i+count)*2+1] = 0xFF000000 |
tmp << 16;
1872 s->ham_palbuf[(
i+count*2)*2+1] = 0xFF000000 |
tmp;
1873 s->ham_palbuf[(
i+count*3)*2+1] = 0xFF000000 |
tmp << 8;
1876 for (
i = 0;
i < 8 * (1 <<
s->ham);
i++)
1877 s->ham_palbuf[(1 <<
s->bpp) +
i] =
s->ham_palbuf[
i] | 0xFF000000;
1879 for (y = 0; y < avctx->
height; y++) {
1880 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1881 memset(
s->ham_buf, 0,
s->planesize * 8);
1882 for (plane = 0; plane <
s->bpp; plane++) {
1884 buf +=
s->planesize;
1893 FFSWAP(uint8_t *,
s->video[0],
s->video[1]);
1898 frame->key_frame = 1;
1901 frame->key_frame = 0;
1910 #if CONFIG_IFF_ILBM_DECODER