54 8, 6, 5, 8, 12, 20, 26, 31,
55 6, 6, 7, 10, 13, 29, 30, 28,
56 7, 7, 8, 12, 20, 29, 35, 28,
57 7, 9, 11, 15, 26, 44, 40, 31,
58 9, 11, 19, 28, 34, 55, 52, 39,
59 12, 18, 28, 32, 41, 52, 57, 46,
60 25, 32, 39, 44, 52, 61, 60, 51,
61 36, 46, 48, 49, 56, 50, 52, 50
65 9, 9, 12, 24, 50, 50, 50, 50,
66 9, 11, 13, 33, 50, 50, 50, 50,
67 12, 13, 28, 50, 50, 50, 50, 50,
68 24, 33, 50, 50, 50, 50, 50, 50,
69 50, 50, 50, 50, 50, 50, 50, 50,
70 50, 50, 50, 50, 50, 50, 50, 50,
71 50, 50, 50, 50, 50, 50, 50, 50,
72 50, 50, 50, 50, 50, 50, 50, 50,
114 const uint8_t *val_table,
int nb_codes,
117 uint8_t huff_size[256] = { 0 };
118 uint16_t huff_code[256];
119 uint16_t huff_sym[256];
124 for (i = 0; i < 256; i++)
125 huff_sym[i] = i + 16 * is_ac;
128 huff_sym[0] = 16 * 256;
131 huff_code, 2, 2, huff_sym, 2, 2, 0);
167 for (i = 0; i < 2; i++) {
178 const uint8_t *src_end = src + src_size;
181 while (src < src_end) {
186 if (x == 0xFF && !*src)
189 *dst_size = dst - dst_start;
193 int plane, int16_t *
block)
196 const int is_chroma = !!plane;
205 dc = dc * qmat[0] + c->
prev_dc[plane];
231 out[0] = av_clip_uint8(Y + ( 91881 * V + 32768 >> 16));
232 out[1] = av_clip_uint8(Y + (-22554 * U - 46802 * V + 32768 >> 16));
233 out[2] = av_clip_uint8(Y + (116130 * U + 32768 >> 16));
243 int mb_w, mb_h, mb_x, mb_y, i, j;
257 mb_h = (height + 15) >> 4;
260 num_mbs = mb_w * mb_h * 4;
262 for (i = 0; i < 3; i++)
266 for (mb_y = 0; mb_y < mb_h; mb_y++) {
267 for (mb_x = 0; mb_x < mb_w; mb_x++) {
268 if (mask && !mask[mb_x * 2] && !mask[mb_x * 2 + 1] &&
269 !mask[mb_x * 2 + mask_stride] &&
270 !mask[mb_x * 2 + 1 + mask_stride]) {
274 for (j = 0; j < 2; j++) {
275 for (i = 0; i < 2; i++) {
276 if (mask && !mask[mb_x * 2 + i + j * mask_stride])
280 c->
block[i + j * 2])) != 0)
285 for (i = 1; i < 3; i++) {
291 for (j = 0; j < 16; j++) {
292 uint8_t *
out = dst + bx * 3 + (by + j) * dst_stride;
293 for (i = 0; i < 16; i++) {
296 Y = c->
block[(j >> 3) * 2 + (i >> 3)][(i & 7) + (j & 7) * 8];
297 U = c->
block[4 ^ swapuv][(i >> 1) + (j >> 1) * 8] - 128;
298 V = c->
block[5 ^ swapuv][(i >> 1) + (j >> 1) * 8] - 128;
310 mask += mask_stride * 2;
318 const uint8_t *jpeg_tile,
int tile_stride,
320 const uint8_t *pal,
int npal,
int tidx)
327 if (npal <= 2) nb = 1;
328 else if (npal <= 4) nb = 2;
329 else if (npal <= 16) nb = 4;
332 for (j = 0; j <
height; j++, dst += stride, jpeg_tile += tile_stride) {
335 for (i = 0; i <
width; i++) {
338 memcpy(dst + i * 3, pal + col * 3, 3);
340 memcpy(dst + i * 3, jpeg_tile + i * 3, 3);
349 int hdr, zsize, npal, tidx = -1,
ret;
351 const uint8_t *src_end = src + src_size;
355 int nblocks, cblocks, bstride;
356 int bits, bitbuf, coded;
370 memcpy(transp, src, 3);
373 for (i = 0; i <
width; i++)
374 memcpy(dst + i * 3, transp, 3);
376 }
else if (sub_type == 1) {
382 memcpy(transp, src, 3);
386 if (src_end - src < npal * 3)
388 memcpy(pal, src, npal * 3);
391 for (i = 0; i < npal; i++) {
392 if (!memcmp(pal + i * 3, transp, 3)) {
399 if (src_end - src < 2)
401 zsize = (src[0] << 8) | src[1];
404 if (src_end - src < zsize + (sub_type != 2))
414 NULL, 0, width, height, pal, npal, tidx);
418 nblocks = *src++ + 1;
420 bstride =
FFALIGN(width, 16) >> 3;
423 for (i = 0; i < (FFALIGN(height, 16) >> 4); i++) {
424 for (j = 0; j < (FFALIGN(width, 16) >> 4); j++) {
435 if (cblocks > nblocks)
440 c->
kempf_flags[j * 2 + 1 + (i * 2 + 1) * bstride] = coded;
451 width, height, pal, npal, tidx);
462 aligned_height = c->
height + 15;
496 uint32_t cur_size, cursor_w, cursor_h, cursor_stride;
497 uint32_t cursor_hot_x, cursor_hot_y;
500 cur_size = bytestream2_get_be32(gb);
501 cursor_w = bytestream2_get_byte(gb);
502 cursor_h = bytestream2_get_byte(gb);
503 cursor_hot_x = bytestream2_get_byte(gb);
504 cursor_hot_y = bytestream2_get_byte(gb);
505 cursor_fmt = bytestream2_get_byte(gb);
507 cursor_stride =
FFALIGN(cursor_w, cursor_fmt==1 ? 32 : 1) * 4;
509 if (cursor_w < 1 || cursor_w > 256 ||
510 cursor_h < 1 || cursor_h > 256) {
515 if (cursor_hot_x > cursor_w || cursor_hot_y > cursor_h) {
517 cursor_hot_x, cursor_hot_y);
518 cursor_hot_x =
FFMIN(cursor_hot_x, cursor_w - 1);
519 cursor_hot_y =
FFMIN(cursor_hot_y, cursor_h - 1);
527 if (cursor_fmt != 1 && cursor_fmt != 32) {
549 for (i = 0; i < c->
cursor_w; i += 32) {
550 bits = bytestream2_get_be32(gb);
551 for (k = 0; k < 32; k++) {
552 dst[0] = !!(bits & 0x80000000);
561 for (i = 0; i < c->
cursor_w; i += 32) {
562 bits = bytestream2_get_be32(gb);
563 for (k = 0; k < 32; k++) {
564 int mask_bit = !!(bits & 0x80000000);
565 switch (dst[0] * 2 + mask_bit) {
595 int val = bytestream2_get_be32(gb);
609 #define APPLY_ALPHA(src, new, alpha) \
610 src = (src * (256 - alpha) + new * alpha) >> 8
628 if (x + w > c->
width)
647 for (j = 0; j < h; j++) {
648 for (i = 0; i < w; i++) {
650 APPLY_ALPHA(dst[i * 3 + 0], cursor[i * 4 + 1], alpha);
651 APPLY_ALPHA(dst[i * 3 + 1], cursor[i * 4 + 2], alpha);
652 APPLY_ALPHA(dst[i * 3 + 2], cursor[i * 4 + 3], alpha);
660 int *got_picture_ptr,
AVPacket *avpkt)
663 int buf_size = avpkt->
size;
669 uint32_t chunk_size, r_mask, g_mask, b_mask;
670 int chunk_type, chunk_start;
676 "Frame should have at least 12 bytes, got %d instead\n",
683 magic = bytestream2_get_be32(&bc);
684 if ((magic & ~0xF) !=
MKBETAG(
'G',
'2',
'M',
'0') ||
685 (magic & 0xF) < 2 || (magic & 0xF) > 4) {
690 if ((magic & 0xF) != 4) {
696 chunk_size = bytestream2_get_le32(&bc) - 1;
697 chunk_type = bytestream2_get_byte(&bc);
701 chunk_size, chunk_type);
704 switch (chunk_type) {
708 if (chunk_size < 21) {
713 c->
width = bytestream2_get_be32(&bc);
714 c->
height = bytestream2_get_be32(&bc);
718 "Invalid frame dimensions %dx%d\n",
731 "Unknown compression method %d\n",
741 "Invalid tile dimensions %dx%d\n",
748 c->
bpp = bytestream2_get_byte(&bc);
751 (chunk_size - 21) < 16) {
753 "Display info: missing bitmasks!\n");
757 r_mask = bytestream2_get_be32(&bc);
758 g_mask = bytestream2_get_be32(&bc);
759 b_mask = bytestream2_get_be32(&bc);
760 if (r_mask != 0xFF0000 || g_mask != 0xFF00 || b_mask != 0xFF) {
762 "Invalid or unsupported bitmasks: R=%"PRIX32
", G=%"PRIX32
", B=%"PRIX32
"\n",
763 r_mask, g_mask, b_mask);
781 "No display info - skipping tile\n");
784 if (chunk_size < 2) {
789 c->
tile_x = bytestream2_get_byte(&bc);
790 c->
tile_y = bytestream2_get_byte(&bc);
793 "Invalid tile pos %d,%d (in %dx%d grid)\n",
801 "ePIC j-b compression is not implemented yet\n");
814 if (chunk_size < 5) {
819 c->
cursor_x = bytestream2_get_be16(&bc);
820 c->
cursor_y = bytestream2_get_be16(&bc);
823 if (chunk_size < 8) {
853 for (i = 0; i < avctx->
height; i++)
859 *got_picture_ptr = 1;