52      8,  6,  5,  8, 12, 20, 26, 31,
 
   53      6,  6,  7, 10, 13, 29, 30, 28,
 
   54      7,  7,  8, 12, 20, 29, 35, 28,
 
   55      7,  9, 11, 15, 26, 44, 40, 31,
 
   56      9, 11, 19, 28, 34, 55, 52, 39,
 
   57     12, 18, 28, 32, 41, 52, 57, 46,
 
   58     25, 32, 39, 44, 52, 61, 60, 51,
 
   59     36, 46, 48, 49, 56, 50, 52, 50
 
   63      9,  9, 12, 24, 50, 50, 50, 50,
 
   64      9, 11, 13, 33, 50, 50, 50, 50,
 
   65     12, 13, 28, 50, 50, 50, 50, 50,
 
   66     24, 33, 50, 50, 50, 50, 50, 50,
 
   67     50, 50, 50, 50, 50, 50, 50, 50,
 
   68     50, 50, 50, 50, 50, 50, 50, 50,
 
   69     50, 50, 50, 50, 50, 50, 50, 50,
 
   70     50, 50, 50, 50, 50, 50, 50, 50,
 
  111                              const uint8_t *val_table, 
int nb_codes,
 
  114     uint8_t  huff_size[256] = { 0 };
 
  115     uint16_t huff_code[256];
 
  116     uint16_t huff_sym[256];
 
  121     for (i = 0; i < 256; i++)
 
  122         huff_sym[i] = i + 16 * is_ac;
 
  125         huff_sym[0] = 16 * 256;
 
  128                               huff_code, 2, 2, huff_sym, 2, 2, 0);
 
  163     for (i = 0; i < 2; i++) {
 
  174     const uint8_t *src_end = src + src_size;
 
  177     while (src < src_end) {
 
  182         if (x == 0xFF && !*src)
 
  185     *dst_size = dst - dst_start;
 
  189                             int plane, int16_t *
block)
 
  192     const int is_chroma = !!plane;
 
  201     dc = dc * qmat[0] + c->
prev_dc[plane];
 
  227     out[0] = av_clip_uint8(Y + (             91881 * V + 32768 >> 16));
 
  228     out[1] = av_clip_uint8(Y + (-22554 * U - 46802 * V + 32768 >> 16));
 
  229     out[2] = av_clip_uint8(Y + (116130 * U             + 32768 >> 16));
 
  240     int mb_w, mb_h, mb_x, mb_y, i, j;
 
  255     mb_h  = (height + 15) >> 4;
 
  258         num_mbs = mb_w * mb_h;
 
  260     for (i = 0; i < 3; i++)
 
  263     for (mb_y = 0; mb_y < mb_h; mb_y++) {
 
  264         for (mb_x = 0; mb_x < mb_w; mb_x++) {
 
  265             if (mask && !mask[mb_x]) {
 
  269             for (j = 0; j < 2; j++) {
 
  270                 for (i = 0; i < 2; i++) {
 
  272                                                 c->
block[i + j * 2])) != 0)
 
  277             for (i = 1; i < 3; i++) {
 
  283             for (j = 0; j < 16; j++) {
 
  284                 uint8_t *
out = dst + bx * 3 + (by + j) * dst_stride;
 
  285                 for (i = 0; i < 16; i++) {
 
  288                     Y = c->
block[(j >> 3) * 2 + (i >> 3)][(i & 7) + (j & 7) * 8];
 
  289                     U = c->
block[4 ^ swapuv][(i >> 1) + (j >> 1) * 8] - 128;
 
  290                     V = c->
block[5 ^ swapuv][(i >> 1) + (j >> 1) * 8] - 128;
 
  310                               const uint8_t *jpeg_tile, 
int tile_stride,
 
  312                               const uint8_t *pal, 
int npal, 
int tidx)
 
  319     if (npal <= 2)       nb = 1;
 
  320     else if (npal <= 4)  nb = 2;
 
  321     else if (npal <= 16) nb = 4;
 
  324     for (j = 0; j < 
height; j++, dst += 
stride, jpeg_tile += tile_stride) {
 
  327         for (i = 0; i < 
width; i++) {
 
  330                 memcpy(dst + i * 3, pal + col * 3, 3);
 
  332                 memcpy(dst + i * 3, jpeg_tile + i * 3, 3);
 
  341     int hdr, zsize, npal, tidx = -1, 
ret;
 
  343     const uint8_t *src_end = src + src_size;
 
  347     int nblocks, cblocks, bstride;
 
  348     int bits, bitbuf, coded;
 
  362         memcpy(transp, src, 3);
 
  365             for (i = 0; i < 
width; i++)
 
  366                 memcpy(dst + i * 3, transp, 3);
 
  368     } 
else if (sub_type == 1) {
 
  374         memcpy(transp, src, 3);
 
  378     memcpy(pal, src, npal * 3); src += npal * 3;
 
  380         for (i = 0; i < npal; i++) {
 
  381             if (!memcmp(pal + i * 3, transp, 3)) {
 
  388     if (src_end - src < 2)
 
  390     zsize = (src[0] << 8) | src[1]; src += 2;
 
  392     if (src_end - src < zsize)
 
  402                           NULL, 0, width, height, pal, npal, tidx);
 
  406     nblocks = *src++ + 1;
 
  408     bstride = 
FFALIGN(width, 16) >> 4;
 
  411     for (i = 0; i < (FFALIGN(height, 16) >> 4); i++) {
 
  412         for (j = 0; j < (FFALIGN(width, 16) >> 4); j++) {
 
  421             if (cblocks > nblocks)
 
  434                       width, height, pal, npal, tidx);
 
  479     uint32_t cur_size, cursor_w, cursor_h, cursor_stride;
 
  480     uint32_t cursor_hot_x, cursor_hot_y;
 
  484     cur_size      = bytestream2_get_be32(gb);
 
  485     cursor_w      = bytestream2_get_byte(gb);
 
  486     cursor_h      = bytestream2_get_byte(gb);
 
  487     cursor_hot_x  = bytestream2_get_byte(gb);
 
  488     cursor_hot_y  = bytestream2_get_byte(gb);
 
  489     cursor_fmt    = bytestream2_get_byte(gb);
 
  491     cursor_stride = cursor_w * 4;
 
  493     if (cursor_w < 1 || cursor_w > 256 ||
 
  494         cursor_h < 1 || cursor_h > 256) {
 
  499     if (cursor_hot_x > cursor_w || cursor_hot_y > cursor_h) {
 
  501                cursor_hot_x, cursor_hot_y);
 
  502         cursor_hot_x = 
FFMIN(cursor_hot_x, cursor_w - 1);
 
  503         cursor_hot_y = 
FFMIN(cursor_hot_y, cursor_h - 1);
 
  511     if (cursor_fmt != 1 && cursor_fmt != 32) {
 
  517     if (cursor_fmt == 1 && cursor_w % 32) {
 
  540             for (i = 0; i < c->
cursor_w; i += 32) {
 
  541                 bits = bytestream2_get_be32(gb);
 
  542                 for (k = 0; k < 32; k++) {
 
  543                     dst[0] = !!(bits & 0x80000000);
 
  552             for (i = 0; i < c->
cursor_w; i += 32) {
 
  553                 bits = bytestream2_get_be32(gb);
 
  554                 for (k = 0; k < 32; k++) {
 
  555                     int mask_bit = !!(bits & 0x80000000);
 
  556                     switch (dst[0] * 2 + mask_bit) {
 
  558                         dst[0] = 0xFF; dst[1] = 0x00;
 
  559                         dst[2] = 0x00; dst[3] = 0x00;
 
  562                         dst[0] = 0xFF; dst[1] = 0xFF;
 
  563                         dst[2] = 0xFF; dst[3] = 0xFF;
 
  566                         dst[0] = 0x00; dst[1] = 0x00;
 
  567                         dst[2] = 0x00; dst[3] = 0x00;
 
  580                 int val = bytestream2_get_be32(gb);
 
  594 #define APPLY_ALPHA(src, new, alpha) \ 
  595     src = (src * (256 - alpha) + new * alpha) >> 8 
  613     if (x + w > c->
width)
 
  632     for (j = 0; j < h; j++) {
 
  633         for (i = 0; i < w; i++) {
 
  635             APPLY_ALPHA(dst[i * 3 + 0], cursor[i * 4 + 1], alpha);
 
  636             APPLY_ALPHA(dst[i * 3 + 1], cursor[i * 4 + 2], alpha);
 
  637             APPLY_ALPHA(dst[i * 3 + 2], cursor[i * 4 + 3], alpha);
 
  645                             int *got_picture_ptr, 
AVPacket *avpkt)
 
  648     int buf_size = avpkt->
size;
 
  661                "Frame should have at least 12 bytes, got %d instead\n",
 
  668     magic = bytestream2_get_be32(&bc);
 
  669     if ((magic & ~0xF) != 
MKBETAG(
'G', 
'2', 
'M', 
'0') ||
 
  670         (magic & 0xF) < 2 || (magic & 0xF) > 4) {
 
  675     if ((magic & 0xF) != 4) {
 
  681         chunk_size = bytestream2_get_le32(&bc) - 1;
 
  682         chunk_type = bytestream2_get_byte(&bc);
 
  685                    chunk_size, chunk_type);
 
  688         switch (chunk_type) {
 
  691             if (chunk_size < 21) {
 
  696             c->
width  = bytestream2_get_be32(&bc);
 
  697             c->
height = bytestream2_get_be32(&bc);
 
  701                        "Invalid frame dimensions %dx%d\n",
 
  711                        "Unknown compression method %d\n",
 
  719                        "Invalid tile dimensions %dx%d\n",
 
  726             c->
bpp = bytestream2_get_byte(&bc);
 
  738                        "No frame header - skipping tile\n");
 
  742             if (chunk_size < 2) {
 
  747             c->
tile_x = bytestream2_get_byte(&bc);
 
  748             c->
tile_y = bytestream2_get_byte(&bc);
 
  751                        "Invalid tile pos %d,%d (in %dx%d grid)\n",
 
  760                        "ePIC j-b compression is not implemented yet\n");
 
  774             if (chunk_size < 5) {
 
  779             c->
cursor_x = bytestream2_get_be16(&bc);
 
  780             c->
cursor_y = bytestream2_get_be16(&bc);
 
  784             if (chunk_size < 8) {
 
  816         for (i = 0; i < avctx->
height; i++)
 
  822         *got_picture_ptr = 1;