72 #define LUT8_PART(plane, v) \
73 AV_LE2NE64C(UINT64_C(0x0000000)<<32 | v) << plane, \
74 AV_LE2NE64C(UINT64_C(0x1000000)<<32 | v) << plane, \
75 AV_LE2NE64C(UINT64_C(0x0010000)<<32 | v) << plane, \
76 AV_LE2NE64C(UINT64_C(0x1010000)<<32 | v) << plane, \
77 AV_LE2NE64C(UINT64_C(0x0000100)<<32 | v) << plane, \
78 AV_LE2NE64C(UINT64_C(0x1000100)<<32 | v) << plane, \
79 AV_LE2NE64C(UINT64_C(0x0010100)<<32 | v) << plane, \
80 AV_LE2NE64C(UINT64_C(0x1010100)<<32 | v) << plane, \
81 AV_LE2NE64C(UINT64_C(0x0000001)<<32 | v) << plane, \
82 AV_LE2NE64C(UINT64_C(0x1000001)<<32 | v) << plane, \
83 AV_LE2NE64C(UINT64_C(0x0010001)<<32 | v) << plane, \
84 AV_LE2NE64C(UINT64_C(0x1010001)<<32 | v) << plane, \
85 AV_LE2NE64C(UINT64_C(0x0000101)<<32 | v) << plane, \
86 AV_LE2NE64C(UINT64_C(0x1000101)<<32 | v) << plane, \
87 AV_LE2NE64C(UINT64_C(0x0010101)<<32 | v) << plane, \
88 AV_LE2NE64C(UINT64_C(0x1010101)<<32 | v) << plane
90 #define LUT8(plane) { \
91 LUT8_PART(plane, 0x0000000), \
92 LUT8_PART(plane, 0x1000000), \
93 LUT8_PART(plane, 0x0010000), \
94 LUT8_PART(plane, 0x1010000), \
95 LUT8_PART(plane, 0x0000100), \
96 LUT8_PART(plane, 0x1000100), \
97 LUT8_PART(plane, 0x0010100), \
98 LUT8_PART(plane, 0x1010100), \
99 LUT8_PART(plane, 0x0000001), \
100 LUT8_PART(plane, 0x1000001), \
101 LUT8_PART(plane, 0x0010001), \
102 LUT8_PART(plane, 0x1010001), \
103 LUT8_PART(plane, 0x0000101), \
104 LUT8_PART(plane, 0x1000101), \
105 LUT8_PART(plane, 0x0010101), \
106 LUT8_PART(plane, 0x1010101), \
115 #define LUT32(plane) { \
117 0, 0, 0, 1U << plane, \
118 0, 0, 1U << plane, 0, \
119 0, 0, 1U << plane, 1U << plane, \
120 0, 1U << plane, 0, 0, \
121 0, 1U << plane, 0, 1U << plane, \
122 0, 1U << plane, 1U << plane, 0, \
123 0, 1U << plane, 1U << plane, 1U << plane, \
124 1U << plane, 0, 0, 0, \
125 1U << plane, 0, 0, 1U << plane, \
126 1U << plane, 0, 1U << plane, 0, \
127 1U << plane, 0, 1U << plane, 1U << plane, \
128 1U << plane, 1U << plane, 0, 0, \
129 1U << plane, 1U << plane, 0, 1U << plane, \
130 1U << plane, 1U << plane, 1U << plane, 0, \
131 1U << plane, 1U << plane, 1U << plane, 1U << plane, \
148 return x << 16 | x << 8 | x;
168 count =
FFMIN(palette_size / 3, count);
170 for (
i = 0;
i < count;
i++)
171 pal[
i] = 0xFF000000 |
AV_RB24(palette +
i*3);
172 if (
s->flags && count >= 32) {
173 for (
i = 0;
i < 32;
i++)
174 pal[
i + 32] = 0xFF000000 | (
AV_RB24(palette +
i*3) & 0xFEFEFE) >> 1;
175 count =
FFMAX(count, 64);
180 for (
i = 0;
i < count;
i++)
189 for (
i = 0;
i < count;
i++)
193 pal[
s->transparency] &= 0xFFFFFF;
210 unsigned buf_size = 0;
226 chunk_id = bytestream2_get_le32(gb);
227 data_size = bytestream2_get_be32(gb);
229 if (chunk_id ==
MKTAG(
'B',
'M',
'H',
'D')) {
231 }
else if (chunk_id ==
MKTAG(
'A',
'N',
'H',
'D')) {
236 s->compression = (bytestream2_get_byte(gb) << 8) | (
s->compression & 0xFF);
238 extra = bytestream2_get_be32(gb);
239 s->is_short = !(extra & 1);
240 s->is_brush = extra == 2;
241 s->is_interlaced = !!(extra & 0x40);
244 }
else if (chunk_id ==
MKTAG(
'D',
'L',
'T',
'A') ||
245 chunk_id ==
MKTAG(
'B',
'O',
'D',
'Y')) {
246 if (chunk_id ==
MKTAG(
'B',
'O',
'D',
'Y'))
247 s->compression &= 0xFF;
249 }
else if (chunk_id ==
MKTAG(
'C',
'M',
'A',
'P')) {
250 int count = data_size / 3;
251 uint32_t *pal =
s->pal;
256 for (
i = 0;
i < count;
i++)
257 pal[
i] = 0xFF000000 | bytestream2_get_le24(gb);
259 for (
i = 0;
i < count;
i++)
260 pal[
i] = 0xFF000000 | bytestream2_get_be24(gb);
269 buf_size = bytestream_get_be16(&buf);
270 if (buf_size <= 1 || palette_size < 0) {
272 "Invalid palette size received: %u -> palette data offset: %d\n",
273 buf_size, palette_size);
278 if (buf_size >= 41) {
279 s->compression = bytestream_get_byte(&buf);
280 s->bpp = bytestream_get_byte(&buf);
281 s->ham = bytestream_get_byte(&buf);
282 s->flags = bytestream_get_byte(&buf);
283 s->transparency = bytestream_get_be16(&buf);
284 s->masking = bytestream_get_byte(&buf);
285 for (
i = 0;
i < 16;
i++)
286 s->tvdc[
i] = bytestream_get_be16(&buf);
292 }
else if (
s->ham != (
s->bpp > 6 ? 6 : 4)) {
293 av_log(avctx,
AV_LOG_ERROR,
"Invalid number of hold bits for HAM: %u, BPP: %u\n",
s->ham,
s->bpp);
299 if (
s->bpp >= 8 && !
s->ham) {
311 if (!
s->mask_palbuf) {
321 if (!
s->bpp ||
s->bpp > 32) {
325 if (
s->video_size &&
s->planesize *
s->bpp * avctx->
height >
s->video_size)
332 int i, count =
FFMIN(palette_size / 3, 1 <<
s->ham);
344 ham_count = 8 * (1 <<
s->ham);
346 if (!
s->ham_palbuf) {
353 memset(
s->ham_palbuf, 0, (1 <<
s->ham) * 2 * sizeof (uint32_t));
354 for (
i=0;
i < count;
i++) {
355 s->ham_palbuf[
i*2+1] = 0xFF000000 |
AV_RL24(palette +
i*3);
360 for (
i=0;
i < count;
i++) {
361 s->ham_palbuf[
i*2] = 0xFF000000;
365 for (
i=0;
i < count;
i++) {
366 uint32_t
tmp =
i << (8 -
s->ham);
368 s->ham_palbuf[(
i+count)*2] = 0xFF00FFFF;
369 s->ham_palbuf[(
i+count*2)*2] = 0xFFFFFF00;
370 s->ham_palbuf[(
i+count*3)*2] = 0xFFFF00FF;
371 s->ham_palbuf[(
i+count)*2+1] = 0xFF000000 |
tmp << 16;
372 s->ham_palbuf[(
i+count*2)*2+1] = 0xFF000000 |
tmp;
373 s->ham_palbuf[(
i+count*3)*2+1] = 0xFF000000 |
tmp << 8;
376 for (
i = 0;
i < ham_count;
i++)
377 s->ham_palbuf[(1 <<
s->bpp) +
i] =
s->ham_palbuf[
i] | 0xFF000000;
448 if (!
s->video[0] || !
s->video[1] || !
s->pal)
465 static void decodeplane8(uint8_t *dst,
const uint8_t *buf,
int buf_size,
int plane)
474 uint64_t v =
AV_RN64A(dst) | lut[*buf++];
477 }
while (--buf_size);
487 static void decodeplane32(uint32_t *dst,
const uint8_t *buf,
int buf_size,
int plane)
491 unsigned mask = (*buf >> 2) & ~3;
492 dst[0] |= lut[
mask++];
493 dst[1] |= lut[
mask++];
494 dst[2] |= lut[
mask++];
496 mask = (*buf++ << 2) & 0x3F;
497 dst[4] |= lut[
mask++];
498 dst[5] |= lut[
mask++];
499 dst[6] |= lut[
mask++];
502 }
while (--buf_size);
505 #define DECODE_HAM_PLANE32(x) \
506 first = buf[x] << 1; \
507 second = buf[(x)+1] << 1; \
508 delta &= pal[first++]; \
509 delta |= pal[first]; \
511 delta &= pal[second++]; \
512 delta |= pal[second]; \
524 const uint32_t *
const pal,
unsigned buf_size)
526 uint32_t
delta = pal[1];
528 uint32_t
first, second;
535 }
while (--buf_size);
539 const uint32_t *
const pal,
unsigned width)
542 *dst++ = pal[*buf++];
561 const int8_t
value = bytestream2_get_byte(gb);
565 if (length <
value + 1)
567 }
else if (
value > -128) {
569 memset(dst + x, bytestream2_get_byte(gb), length);
577 memset(dst+x, 0, dst_size - x);
587 int i, y_pos = 0, x_pos = 0;
589 if (bytestream2_get_be32(gb) !=
MKBETAG(
'V',
'D',
'A',
'T'))
593 count = bytestream2_get_be16(gb) - 2;
600 for (
i = 0;
i < count && x_pos < line_size;
i++) {
601 int8_t cmd = bytestream2_get_byte(&
cmds);
605 l = bytestream2_get_be16(gb);
606 while (l-- > 0 && x_pos < line_size) {
607 dst[x_pos + y_pos * line_size ] = bytestream2_get_byte(gb);
608 dst[x_pos + y_pos++ * line_size + 1] = bytestream2_get_byte(gb);
614 }
else if (cmd < 0) {
616 while (l-- > 0 && x_pos < line_size) {
617 dst[x_pos + y_pos * line_size ] = bytestream2_get_byte(gb);
618 dst[x_pos + y_pos++ * line_size + 1] = bytestream2_get_byte(gb);
624 }
else if (cmd == 1) {
625 l = bytestream2_get_be16(gb);
626 r = bytestream2_get_be16(gb);
627 while (l-- > 0 && x_pos < line_size) {
628 dst[x_pos + y_pos * line_size ] =
r >> 8;
629 dst[x_pos + y_pos++ * line_size + 1] =
r & 0xFF;
637 r = bytestream2_get_be16(gb);
638 while (l-- > 0 && x_pos < line_size) {
639 dst[x_pos + y_pos * line_size ] =
r >> 8;
640 dst[x_pos + y_pos++ * line_size + 1] =
r & 0xFF;
652 #define DECODE_RGBX_COMMON(type) \
654 length = bytestream2_get_byte(gb); \
656 length = bytestream2_get_be16(gb); \
661 for (i = 0; i < length; i++) { \
662 *(type *)(dst + y*linesize + x * sizeof(type)) = pixel; \
681 int x = 0, y = 0,
i, length;
683 uint32_t
pixel = 0xFF000000 | bytestream2_get_be24(gb);
684 length = bytestream2_get_byte(gb) & 0x7F;
698 int x = 0, y = 0,
i, length;
700 uint32_t
pixel = bytestream2_get_be16u(gb);
701 length =
pixel & 0x7;
718 const uint8_t *src_end =
src + src_size;
720 while (src_end -
src >= 5) {
722 opcode = *(int8_t *)
src++;
724 int size = opcode + 1;
727 if (src_end -
src < length * 4)
729 memcpy(dst + y*linesize + x * 4,
src, length * 4);
741 int size = -opcode + 1;
744 *(uint32_t *)(dst + y*linesize + x * 4) =
pixel;
770 int x = 0, y = 0, plane = 0;
774 for (
i = 0;
i < src_size * 2;) {
775 #define GETNIBBLE ((i & 1) ? (src[i>>1] & 0xF) : (src[i>>1] >> 4))
780 dst[y * linesize + x*4 + plane] =
pixel;
783 if (
i >= src_size * 2)
788 for (j = 0; j <
d; j++) {
789 dst[y * linesize + x*4 + plane] =
pixel;
809 const uint8_t *buf,
const uint8_t *buf_end,
810 int w,
int bpp,
int dst_size)
812 int planepitch =
FFALIGN(
w, 16) >> 3;
813 int pitch = planepitch * bpp;
816 unsigned ofssrc,
pos;
822 for (k = 0; k < bpp; k++) {
823 ofssrc = bytestream2_get_be32(&ptrs);
829 if (ofssrc >= buf_end - buf)
834 int16_t
offset = bytestream2_get_be16(&gb);
838 unsigned data = bytestream2_get_be16(&gb);
841 noffset = (
pos / planepitch) * pitch + (
pos % planepitch) + k * planepitch;
843 bytestream2_put_be16(&pb,
data);
845 uint16_t count = bytestream2_get_be16(&gb);
848 for (
i = 0;
i < count;
i++) {
849 uint16_t
data = bytestream2_get_be16(&gb);
852 noffset = (
pos / planepitch) * pitch + (
pos % planepitch) + k * planepitch;
854 bytestream2_put_be16(&pb,
data);
862 const uint8_t *buf,
const uint8_t *buf_end,
863 int w,
int xor,
int bpp,
int dst_size)
865 int ncolumns = ((
w + 15) / 16) * 2;
866 int dstpitch = ncolumns * bpp;
867 unsigned ofsdst, ofssrc, opcode, x;
875 for (k = 0; k < bpp; k++) {
876 ofssrc = bytestream2_get_be32(&ptrs);
881 if (ofssrc >= buf_end - buf)
885 for (j = 0; j < ncolumns; j++) {
886 ofsdst = j + k * ncolumns;
888 i = bytestream2_get_byte(&gb);
890 opcode = bytestream2_get_byte(&gb);
893 opcode = bytestream2_get_byte(&gb);
894 x = bytestream2_get_byte(&gb);
898 if (xor && ofsdst < dst_size) {
899 bytestream2_put_byte(&pb, dst[ofsdst] ^ x);
901 bytestream2_put_byte(&pb, x);
906 }
else if (opcode < 0x80) {
907 ofsdst += opcode * dstpitch;
913 if (xor && ofsdst < dst_size) {
914 bytestream2_put_byte(&pb, dst[ofsdst] ^ bytestream2_get_byte(&gb));
916 bytestream2_put_byte(&pb, bytestream2_get_byte(&gb));
929 const uint8_t *buf,
const uint8_t *buf_end,
930 int w,
int h,
int bpp,
int dst_size)
934 uint32_t
type,
flag, cols, groups, rows, bytes;
936 int planepitch_byte = (
w + 7) / 8;
937 int planepitch = ((
w + 15) / 16) * 2;
938 int kludge_j,
b,
g,
r,
d;
941 pitch = planepitch * bpp;
942 kludge_j =
w < 320 ? (320 -
w) / 8 / 2 : 0;
947 type = bytestream2_get_be16(&gb);
953 flag = bytestream2_get_be16(&gb);
954 cols = bytestream2_get_be16(&gb);
955 groups = bytestream2_get_be16(&gb);
957 for (
g = 0;
g < groups;
g++) {
958 offset = bytestream2_get_be16(&gb);
970 for (
b = 0;
b < cols;
b++) {
971 for (
d = 0;
d < bpp;
d++) {
972 uint8_t
value = bytestream2_get_byte(&gb);
986 if ((cols * bpp) & 1)
991 flag = bytestream2_get_be16(&gb);
992 rows = bytestream2_get_be16(&gb);
993 bytes = bytestream2_get_be16(&gb);
994 groups = bytestream2_get_be16(&gb);
996 for (
g = 0;
g < groups;
g++) {
997 offset = bytestream2_get_be16(&gb);
1004 for (
r = 0;
r < rows;
r++) {
1005 for (
d = 0;
d < bpp;
d++) {
1006 unsigned noffset =
offset + (
r * pitch) +
d * planepitch;
1013 for (
b = 0;
b < bytes;
b++) {
1014 uint8_t
value = bytestream2_get_byte(&gb);
1016 if (noffset >= dst_size)
1018 ptr = dst + noffset;
1029 if ((rows * bytes * bpp) & 1)
1040 const uint8_t *buf,
const uint8_t *buf_end,
1041 int w,
int bpp,
int dst_size)
1043 int ncolumns = (
w + 15) >> 4;
1044 int dstpitch = ncolumns * bpp * 2;
1045 unsigned ofsdst, ofssrc, ofsdata, opcode, x;
1050 if (buf_end - buf <= 64)
1057 for (k = 0; k < bpp; k++) {
1058 ofssrc = bytestream2_get_be32(&ptrs);
1059 ofsdata = bytestream2_get_be32(&dptrs);
1064 if (ofssrc >= buf_end - buf)
1067 if (ofsdata >= buf_end - buf)
1072 for (j = 0; j < ncolumns; j++) {
1073 ofsdst = (j + k * ncolumns) * 2;
1075 i = bytestream2_get_byte(&gb);
1077 opcode = bytestream2_get_byte(&gb);
1080 opcode = bytestream2_get_byte(&gb);
1081 x = bytestream2_get_be16(&dgb);
1085 bytestream2_put_be16(&pb, x);
1089 }
else if (opcode < 0x80) {
1090 ofsdst += opcode * dstpitch;
1096 bytestream2_put_be16(&pb, bytestream2_get_be16(&dgb));
1108 const uint8_t *buf,
const uint8_t *buf_end,
1109 int w,
int bpp,
int dst_size)
1111 int ncolumns = (
w + 31) >> 5;
1112 int dstpitch = ((
w + 15) / 16 * 2) * bpp;
1113 unsigned ofsdst, ofssrc, ofsdata, opcode, x;
1118 if (buf_end - buf <= 64)
1121 h = (((
w + 15) / 16 * 2) != ((
w + 31) / 32 * 4)) ? 1 : 0;
1126 for (k = 0; k < bpp; k++) {
1127 ofssrc = bytestream2_get_be32(&ptrs);
1128 ofsdata = bytestream2_get_be32(&dptrs);
1133 if (ofssrc >= buf_end - buf)
1136 if (ofsdata >= buf_end - buf)
1141 for (j = 0; j < ncolumns; j++) {
1142 ofsdst = (j + k * ncolumns) * 4 -
h * (2 * k);
1144 i = bytestream2_get_byte(&gb);
1146 opcode = bytestream2_get_byte(&gb);
1149 opcode = bytestream2_get_byte(&gb);
1150 if (
h && (j == (ncolumns - 1))) {
1151 x = bytestream2_get_be16(&dgb);
1154 x = bytestream2_get_be32(&dgb);
1162 if (
h && (j == (ncolumns - 1))) {
1163 bytestream2_put_be16(&pb, x);
1165 bytestream2_put_be32(&pb, x);
1170 }
else if (opcode < 0x80) {
1171 ofsdst += opcode * dstpitch;
1177 if (
h && (j == (ncolumns - 1))) {
1178 bytestream2_put_be16(&pb, bytestream2_get_be16(&dgb));
1181 bytestream2_put_be32(&pb, bytestream2_get_be32(&dgb));
1194 const uint8_t *buf,
const uint8_t *buf_end,
1195 int w,
int bpp,
int dst_size)
1197 int ncolumns = (
w + 15) >> 4;
1198 int dstpitch = ncolumns * bpp * 2;
1199 unsigned ofsdst, ofssrc, opcode, x;
1207 for (k = 0; k < bpp; k++) {
1208 ofssrc = bytestream2_get_be32(&ptrs);
1213 if (ofssrc >= buf_end - buf)
1217 for (j = 0; j < ncolumns; j++) {
1218 ofsdst = (j + k * ncolumns) * 2;
1220 i = bytestream2_get_be16(&gb);
1222 opcode = bytestream2_get_be16(&gb);
1225 opcode = bytestream2_get_be16(&gb);
1226 x = bytestream2_get_be16(&gb);
1230 bytestream2_put_be16(&pb, x);
1234 }
else if (opcode < 0x8000) {
1235 ofsdst += opcode * dstpitch;
1242 bytestream2_put_be16(&pb, bytestream2_get_be16(&gb));
1254 const uint8_t *buf,
const uint8_t *buf_end,
1255 int w,
int bpp,
int dst_size)
1257 int ncolumns = (
w + 31) >> 5;
1258 int dstpitch = ((
w + 15) / 16 * 2) * bpp;
1259 unsigned ofsdst, ofssrc, opcode, x;
1260 unsigned skip = 0x80000000,
mask = skip - 1;
1265 h = (((
w + 15) / 16 * 2) != ((
w + 31) / 32 * 4)) ? 1 : 0;
1269 for (k = 0; k < bpp; k++) {
1270 ofssrc = bytestream2_get_be32(&ptrs);
1275 if (ofssrc >= buf_end - buf)
1279 for (j = 0; j < ncolumns; j++) {
1280 ofsdst = (j + k * ncolumns) * 4 -
h * (2 * k);
1282 if (
h && (j == (ncolumns - 1))) {
1287 i = bytestream2_get_be32(&gb);
1289 opcode = bytestream2_get_be32(&gb);
1292 if (
h && (j == ncolumns - 1)) {
1293 opcode = bytestream2_get_be16(&gb);
1294 x = bytestream2_get_be16(&gb);
1296 opcode = bytestream2_get_be32(&gb);
1297 x = bytestream2_get_be32(&gb);
1305 if (
h && (j == ncolumns - 1))
1306 bytestream2_put_be16(&pb, x);
1308 bytestream2_put_be32(&pb, x);
1312 }
else if (opcode < skip) {
1313 ofsdst += opcode * dstpitch;
1320 if (
h && (j == ncolumns - 1)) {
1321 bytestream2_put_be16(&pb, bytestream2_get_be16(&gb));
1323 bytestream2_put_be32(&pb, bytestream2_get_be32(&gb));
1336 const uint8_t *buf,
const uint8_t *buf_end,
1337 int w,
int flag,
int bpp,
int dst_size)
1339 int planepitch =
FFALIGN(
w, 16) >> 3;
1340 int pitch = planepitch * bpp;
1341 int planepitch_byte = (
w + 7) / 8;
1342 unsigned entries, ofssrc;
1347 if (buf_end - buf <= 4 * bpp)
1353 for (k = 0; k < bpp; k++) {
1354 ofssrc = bytestream2_get_be32(&ptrs);
1359 if (ofssrc >= buf_end - buf)
1364 entries = bytestream2_get_be32(&gb);
1369 int32_t opcode = bytestream2_get_be32(&gb);
1370 unsigned offset = bytestream2_get_be32(&gb);
1374 uint32_t x = bytestream2_get_be32(&gb);
1378 bytestream2_put_be32(&pb, x);
1384 bytestream2_put_be32(&pb, bytestream2_get_be32(&gb));
1395 const uint8_t *buf,
const uint8_t *buf_end,
1396 int w,
int flag,
int bpp,
int dst_size)
1398 int planepitch =
FFALIGN(
w, 16) >> 3;
1399 int pitch = planepitch * bpp;
1400 int planepitch_byte = (
w + 7) / 8;
1401 unsigned entries, ofssrc;
1406 if (buf_end - buf <= 4 * bpp)
1412 for (k = 0; k < bpp; k++) {
1413 ofssrc = bytestream2_get_be32(&ptrs);
1418 if (ofssrc >= buf_end - buf)
1423 entries = bytestream2_get_be16(&gb);
1425 int16_t opcode = bytestream2_get_be16(&gb);
1426 unsigned offset = bytestream2_get_be32(&gb);
1430 uint16_t x = bytestream2_get_be16(&gb);
1432 bytestream2_put_be16(&pb, x);
1439 bytestream2_put_be16(&pb, bytestream2_get_be16(&gb));
1450 const uint8_t *buf,
const uint8_t *buf_end,
1451 int w,
int flag,
int bpp,
int dst_size)
1455 unsigned poff0, poff1;
1457 int planepitch_byte = (
w + 7) / 8;
1458 int planepitch = ((
w + 15) / 16) * 2;
1459 int pitch = planepitch * bpp;
1462 if (buf_end - buf <= 64)
1469 dstpitch =
flag ? (((
w + 7) / 8) * bpp): 2;
1471 for (k = 0; k < bpp; k++) {
1472 poff0 = bytestream2_get_be32(&off0);
1473 poff1 = bytestream2_get_be32(&off1);
1478 if (2LL * poff0 >= buf_end - buf)
1481 if (2LL * poff1 >= buf_end - buf)
1488 uint32_t
offset = bytestream2_get_be16(&ogb);
1489 int16_t cnt = bytestream2_get_be16(&ogb);
1492 if (count > dst_size)
1494 offset = ((2 *
offset) / planepitch_byte) * pitch + ((2 *
offset) % planepitch_byte) + k * planepitch;
1500 data = bytestream2_get_be16(&dgb);
1502 for (
i = 0;
i < cnt;
i++) {
1503 bytestream2_put_be16(&pb,
data);
1511 for (
i = 0;
i < cnt;
i++) {
1512 data = bytestream2_get_be16(&dgb);
1513 bytestream2_put_be16(&pb,
data);
1524 avpriv_request_sample(avctx,
"bitmap (compression 0x%0x, bpp %i, ham %i, interlaced %i)",
s->compression,
s->bpp,
s->ham,
s->is_interlaced);
1532 const uint8_t *buf = avpkt->
data;
1533 int buf_size = avpkt->
size;
1534 const uint8_t *buf_end = buf + buf_size;
1563 if (
s->compression <= 0xff && (avctx->
codec_tag ==
MKTAG(
'A',
'N',
'I',
'M'))) {
1565 memcpy(
s->pal,
s->frame->data[1], 256 * 4);
1568 switch (
s->compression) {
1573 for (plane = 0; plane <
s->bpp; plane++) {
1574 for (y = 0; y < avctx->
height && buf < buf_end; y++) {
1575 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1577 buf +=
s->planesize;
1580 }
else if (
s->ham) {
1582 for (y = 0; y < avctx->
height; y++) {
1583 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1584 memset(
s->ham_buf, 0,
s->planesize * 8);
1585 for (plane = 0; plane <
s->bpp; plane++) {
1586 const uint8_t * start = buf + (plane * avctx->
height + y) *
s->planesize;
1587 if (start >= buf_end)
1598 for (y = 0; y < avctx->
height && buf < buf_end; y++) {
1599 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1600 memcpy(row, buf,
FFMIN(raw_width, buf_end - buf));
1603 for (x = 0; x < avctx->
width; x++)
1604 row[4 * x + 3] = row[4 * x + 3] & 0xF0 | (row[4 * x + 3] >> 4);
1610 memcpy(
s->video[0], buf,
FFMIN(buf_end - buf,
s->video_size));
1612 for (y = 0; y < avctx->
height; y++) {
1613 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1614 memset(row, 0, avctx->
width);
1615 for (plane = 0; plane <
s->bpp && buf < buf_end; plane++) {
1617 buf +=
s->planesize;
1620 }
else if (
s->ham) {
1621 for (y = 0; y < avctx->
height; y++) {
1622 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1623 memset(
s->ham_buf, 0,
s->planesize * 8);
1624 for (plane = 0; plane <
s->bpp && buf < buf_end; plane++) {
1626 buf +=
s->planesize;
1631 for (y = 0; y < avctx->
height; y++) {
1632 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1633 memset(row, 0, avctx->
width << 2);
1634 for (plane = 0; plane <
s->bpp && buf < buf_end; plane++) {
1636 FFMIN(
s->planesize, buf_end - buf), plane);
1637 buf +=
s->planesize;
1643 for (y = 0; y < avctx->
height && buf_end > buf; y++) {
1644 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1645 memcpy(row, buf,
FFMIN(avctx->
width, buf_end - buf));
1648 }
else if (
s->ham) {
1649 for (y = 0; y < avctx->
height && buf_end > buf; y++) {
1650 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1651 memcpy(
s->ham_buf, buf,
FFMIN(avctx->
width, buf_end - buf));
1665 uint8_t *
video =
s->video[0];
1667 for (y = 0; y < avctx->
height; y++) {
1668 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1669 memset(row, 0, avctx->
width);
1670 for (plane = 0; plane <
s->bpp; plane++) {
1673 memcpy(
video,
s->planebuf,
s->planesize);
1680 for (y = 0; y < avctx->
height; y++) {
1681 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1682 memset(
s->mask_buf, 0, avctx->
width *
sizeof(uint32_t));
1683 for (plane = 0; plane <
s->bpp; plane++) {
1689 }
else if (
s->ham) {
1690 uint8_t *
video =
s->video[0];
1691 for (y = 0; y < avctx->
height; y++) {
1692 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1693 memset(
s->ham_buf, 0,
s->planesize * 8);
1694 for (plane = 0; plane <
s->bpp; plane++) {
1697 memcpy(
video,
s->planebuf,
s->planesize);
1705 for (y = 0; y < avctx->
height; y++) {
1706 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1707 memset(row, 0, avctx->
width << 2);
1708 for (plane = 0; plane <
s->bpp; plane++) {
1716 for (y = 0; y < avctx->
height; y++) {
1717 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1720 }
else if (
s->ham) {
1721 for (y = 0; y < avctx->
height; y++) {
1722 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1736 for (plane = 0; plane <
s->bpp; plane++) {
1737 for (y = 0; y < avctx->
height && buf < buf_end; y++) {
1738 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1740 buf +=
s->planesize;
1743 }
else if (
s->ham) {
1745 for (y = 0; y < avctx->
height; y++) {
1746 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1747 memset(
s->ham_buf, 0,
s->planesize * 8);
1748 for (plane = 0; plane <
s->bpp; plane++) {
1749 const uint8_t * start = buf + (plane * avctx->
height + y) *
s->planesize;
1750 if (start >= buf_end)
1765 for (plane = 0; plane <
s->bpp; plane++) {
1767 for (y = 0; y < avctx->
height; y++) {
1768 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1769 decodeplane8(row,
s->planebuf +
s->planesize * y,
s->planesize, plane);
1821 if (
s->is_interlaced)
1827 if (
s->is_interlaced)
1839 if (
s->compression <= 0xff && (avctx->
codec_tag ==
MKTAG(
'A',
'N',
'I',
'M'))) {
1840 memcpy(
s->video[1],
s->video[0],
s->video_size);
1843 if (
s->compression > 0xff) {
1846 for (y = 0; y < avctx->
height; y++) {
1847 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1848 memset(row, 0, avctx->
width);
1849 for (plane = 0; plane <
s->bpp; plane++) {
1851 buf +=
s->planesize;
1855 memcpy(
frame->data[1],
s->pal, 256 * 4);
1856 }
else if (
s->ham) {
1857 int i, count = 1 <<
s->ham;
1860 memset(
s->ham_palbuf, 0, (1 <<
s->ham) * 2 *
sizeof(uint32_t));
1861 for (
i = 0;
i < count;
i++) {
1862 s->ham_palbuf[
i*2+1] =
s->pal[
i];
1864 for (
i = 0;
i < count;
i++) {
1865 uint32_t
tmp =
i << (8 -
s->ham);
1867 s->ham_palbuf[(
i+count)*2] = 0xFF00FFFF;
1868 s->ham_palbuf[(
i+count*2)*2] = 0xFFFFFF00;
1869 s->ham_palbuf[(
i+count*3)*2] = 0xFFFF00FF;
1870 s->ham_palbuf[(
i+count)*2+1] = 0xFF000000 |
tmp << 16;
1871 s->ham_palbuf[(
i+count*2)*2+1] = 0xFF000000 |
tmp;
1872 s->ham_palbuf[(
i+count*3)*2+1] = 0xFF000000 |
tmp << 8;
1875 for (
i = 0;
i < 8 * (1 <<
s->ham);
i++)
1876 s->ham_palbuf[(1 <<
s->bpp) +
i] =
s->ham_palbuf[
i] | 0xFF000000;
1878 for (y = 0; y < avctx->
height; y++) {
1879 uint8_t *row = &
frame->data[0][y *
frame->linesize[0]];
1880 memset(
s->ham_buf, 0,
s->planesize * 8);
1881 for (plane = 0; plane <
s->bpp; plane++) {
1883 buf +=
s->planesize;
1892 FFSWAP(uint8_t *,
s->video[0],
s->video[1]);
1897 frame->key_frame = 1;
1900 frame->key_frame = 0;