Go to the documentation of this file.
   46 #define EPIC_PIX_STACK_SIZE 1024 
   47 #define EPIC_PIX_STACK_MAX  (EPIC_PIX_STACK_SIZE - 1) 
   65      8,  6,  6,  7,  6,  5,  8,  7,
 
   66      7,  7,  9,  9,  8, 10, 12, 20,
 
   67     13, 12, 11, 11, 12, 25, 18, 19,
 
   68     15, 20, 29, 26, 31, 30, 29, 26,
 
   69     28, 28, 32, 36, 46, 39, 32, 34,
 
   70     44, 35, 28, 28, 40, 55, 41, 44,
 
   71     48, 49, 52, 52, 52, 31, 39, 57,
 
   72     61, 56, 50, 60, 46, 51, 52, 50,
 
   76      9,  9,  9, 12, 11, 12, 24, 13,
 
   77     13, 24, 50, 33, 28, 33, 50, 50,
 
   78     50, 50, 50, 50, 50, 50, 50, 50,
 
   79     50, 50, 50, 50, 50, 50, 50, 50,
 
   80     50, 50, 50, 50, 50, 50, 50, 50,
 
   81     50, 50, 50, 50, 50, 50, 50, 50,
 
   82     50, 50, 50, 50, 50, 50, 50, 50,
 
   83     50, 50, 50, 50, 50, 50, 50, 50,
 
   97 #define EPIC_HASH_SIZE 256 
  189                          c->idsp.idct_permutation);
 
  198     for (
i = 0; 
i < 2; 
i++) {
 
  207                          uint8_t *
dst, 
int *dst_size)
 
  209     const uint8_t *src_end = 
src + src_size;
 
  210     uint8_t *dst_start = 
dst;
 
  212     while (
src < src_end) {
 
  217         if (x == 0xFF && !*
src)
 
  220     *dst_size = 
dst - dst_start;
 
  224                             int plane, int16_t *
block)
 
  227     const int is_chroma = !!plane;
 
  233     c->bdsp.clear_block(
block);
 
  234     dc = 
get_vlc2(gb, 
c->dc_vlc[is_chroma].table, 9, 2);
 
  239     dc                = 
dc * qmat[0] + 
c->prev_dc[plane];
 
  241     c->prev_dc[plane] = 
dc;
 
  271                            const uint8_t *
src, 
int src_size,
 
  272                            uint8_t *
dst, 
int dst_stride,
 
  273                            const uint8_t *
mask, 
int mask_stride, 
int num_mbs,
 
  277     int mb_w, mb_h, mb_x, mb_y, 
i, j;
 
  281     const int ridx = swapuv ? 2 : 0;
 
  293     mb_h  = (
height + 15) >> 4;
 
  296         num_mbs = mb_w * mb_h * 4;
 
  298     for (
i = 0; 
i < 3; 
i++)
 
  299         c->prev_dc[
i] = 1024;
 
  302     c->bdsp.clear_blocks(
c->block[0]);
 
  303     for (mb_y = 0; mb_y < mb_h; mb_y++) {
 
  304         for (mb_x = 0; mb_x < mb_w; mb_x++) {
 
  306                 !
mask[mb_x * 2 +     mask_stride] &&
 
  307                 !
mask[mb_x * 2 + 1 + mask_stride]) {
 
  311             for (j = 0; j < 2; j++) {
 
  312                 for (
i = 0; 
i < 2; 
i++) {
 
  313                     if (
mask && !
mask[mb_x * 2 + 
i + j * mask_stride])
 
  317                                                 c->block[
i + j * 2])) != 0)
 
  319                     c->idsp.idct(
c->block[
i + j * 2]);
 
  322             for (
i = 1; 
i < 3; 
i++) {
 
  325                 c->idsp.idct(
c->block[
i + 3]);
 
  328             for (j = 0; j < 16; j++) {
 
  329                 uint8_t *
out = 
dst + bx * 3 + (by + j) * dst_stride;
 
  330                 for (
i = 0; 
i < 16; 
i++) {
 
  333                     Y = 
c->block[(j >> 3) * 2 + (
i >> 3)][(
i & 7) + (j & 7) * 8];
 
  334                     U = 
c->block[4][(
i >> 1) + (j >> 1) * 8] - 128;
 
  335                     V = 
c->block[5][(
i >> 1) + (j >> 1) * 8] - 128;
 
  347             mask += mask_stride * 2;
 
  353 #define LOAD_NEIGHBOURS(x)      \ 
  354     W   = curr_row[(x)   - 1];  \ 
  355     N   = above_row[(x)];       \ 
  356     WW  = curr_row[(x)   - 2];  \ 
  357     NW  = above_row[(x)  - 1];  \ 
  358     NE  = above_row[(x)  + 1];  \ 
  359     NN  = above2_row[(x)];      \ 
  360     NNW = above2_row[(x) - 1];  \ 
  361     NWW = above_row[(x)  - 2];  \ 
  362     NNE = above2_row[(x) + 1] 
  364 #define UPDATE_NEIGHBOURS(x)    \ 
  370     NE  = above_row[(x)  + 1];  \ 
  371     NNE = above2_row[(x) + 1] 
  382     h = (
h * 33) ^ ((
key >> 24) & 0xFF); 
 
  383     h = (
h * 33) ^ ((
key >> 16) & 0xFF);
 
  384     h = (
h * 33) ^ ((
key >>  8) & 0xFF);
 
  385     h = (
h * 33) ^  (
key        & 0xFF);
 
  400     for (
i = 0; 
i < 
hash->bucket_fill[idx]; 
i++)
 
  412     if (
hash->bucket_size[idx] > INT_MAX / 
sizeof(**
hash->bucket))
 
  415     if (!(
hash->bucket_fill[idx] < 
hash->bucket_size[idx])) {
 
  416         int new_size = 
hash->bucket_size[idx] + 16;
 
  421         hash->bucket_size[idx] = new_size;
 
  424     ret = &
hash->bucket[idx][
hash->bucket_fill[idx]++];
 
  425     memset(
ret, 0, 
sizeof(*
ret));
 
  446     hash_elem->
list = new_elem;
 
  467         for (j = 0; j < 
hash->bucket_fill[
i]; j++) {
 
  476         hash->bucket_size[
i] =
 
  477         hash->bucket_fill[
i] = 0;
 
  485     for (
i = 0; 
i < 
dc->stack_pos; 
i++)
 
  489     return i != 
dc->stack_pos;
 
  492 #define TOSIGNED(val) (((val) >> 1) ^ -((val) & 1)) 
  495                                              int N, 
int W, 
int NW)
 
  502                                        const uint32_t *curr_row,
 
  503                                        const uint32_t *above_row)
 
  507     int GN, GW, GNW, 
R, 
G, 
B;
 
  512         NW = above_row[x - 1];
 
  523                                            ((NW >> 
R_shift) & 0xFF) - GNW);
 
  528                                            ((NW >> 
B_shift) & 0xFF) - GNW);
 
  531             pred = curr_row[x - 1];
 
  545     if (
R<0 || 
G<0 || B<0 || R > 255 || 
G > 255 || 
B > 255) {
 
  554                               uint32_t *pPix, uint32_t 
pix)
 
  565                              const uint32_t *curr_row,
 
  566                              const uint32_t *above_row, uint32_t *pPix)
 
  579         pix = curr_row[x - 1];
 
  586         if (!
dc->stack_pos || 
dc->stack[0] != 
pix) {
 
  596                                   const uint32_t *curr_row,
 
  597                                   const uint32_t *above_row,
 
  598                                   const uint32_t *above2_row,
 
  599                                   uint32_t *pPix, 
int *pRun)
 
  601     int idx, got_pixel = 0, WWneW, old_WWneW = 0;
 
  602     uint32_t 
W, WW, 
N, 
NN, NW, NE, NWW, NNW, NNE;
 
  608     if (
dc->next_run_pos == x) {
 
  612         idx = (WW  != 
W)  << 7 |
 
  637             NWneW = *pRun ? NWneW : NW != 
W;
 
  640             switch (((NW != 
N) << 2) | (NWneW << 1) | WWneW) {
 
  649                           (*pRun ? old_WWneW : WW != 
W) << 7 |
 
  674         if (x + *pRun >= tile_width - 1)
 
  679         if (!NWneW && NW == 
N && 
N == NE) {
 
  681             int start_pos = x + *pRun;
 
  684             uint32_t 
pix = above_row[start_pos + 1];
 
  685             for (
pos = start_pos + 2; 
pos < tile_width; 
pos++)
 
  686                 if (!(above_row[
pos] == 
pix))
 
  688             run = 
pos - start_pos - 1;
 
  699                                                : &
dc->runlen_zeroes[
pos])) {
 
  707             if (x + *pRun >= tile_width - 1)
 
  726     dc->next_run_pos = x + *pRun;
 
  731                                uint32_t *pPix, uint32_t 
pix)
 
  742                                    int tile_width, 
const uint32_t *curr_row,
 
  743                                    const uint32_t *above_row, uint32_t *pPix)
 
  749         uint32_t NW = above_row[x - 1];
 
  758     if (
pos < tile_width - 1 && y) {
 
  759         uint32_t NE = above_row[
pos + 1];
 
  774     if (!hash_elem || !hash_elem->
list)
 
  799                             int tile_width, 
int stride)
 
  803     uint32_t *curr_row = 
NULL, *above_row = 
NULL, *above2_row;
 
  805     for (y = 0; y < tile_height; y++, 
out += 
stride) {
 
  806         above2_row = above_row;
 
  807         above_row  = curr_row;
 
  808         curr_row   = (uint32_t *) 
out;
 
  810         for (x = 0, 
dc->next_run_pos = 0; x < tile_width;) {
 
  814             pix = curr_row[x - 1]; 
 
  816             if (y >= 1 && x >= 2 &&
 
  817                 pix != curr_row[x - 2]  && 
pix != above_row[x - 1] &&
 
  818                 pix != above_row[x - 2] && 
pix != above_row[x] &&
 
  826                 if (y < 2 || x < 2 || x == tile_width - 1) {
 
  838                                                            tile_width, curr_row,
 
  840                     uint32_t ref_pix = curr_row[x - 1];
 
  855                 for (; 
run > 0; x++, 
run--)
 
  865                                const uint8_t *
src, 
size_t src_size,
 
  868     uint8_t prefix, 
mask = 0x80;
 
  869     int extrabytes, tile_width, tile_height, awidth, aheight;
 
  879     for (extrabytes = 0; (prefix & 
mask) && (extrabytes < 7); extrabytes++)
 
  881     if (extrabytes > 3 || src_size < extrabytes) {
 
  886     els_dsize = prefix & ((0x80 >> extrabytes) - 1); 
 
  887     while (extrabytes-- > 0) {
 
  888         els_dsize = (els_dsize << 8) | *
src++;
 
  892     if (src_size < els_dsize) {
 
  894                els_dsize, src_size);
 
  898     tile_width  = 
FFMIN(
c->width  - tile_x * 
c->tile_width,  
c->tile_width);
 
  899     tile_height = 
FFMIN(
c->height - tile_y * 
c->tile_height, 
c->tile_height);
 
  900     awidth      = 
FFALIGN(tile_width,  16);
 
  901     aheight     = 
FFALIGN(tile_height, 16);
 
  910         uint8_t tr_r, tr_g, tr_b, *buf;
 
  913         memset(&
c->ec, 0, 
sizeof(
c->ec));
 
  921         if (
c->ec.els_ctx.err != 0) {
 
  923                    "ePIC: couldn't decode transparency pixel!\n");
 
  936                    "ePIC: tile decoding failed, frame=%"PRId64
", tile_x=%d, tile_y=%d\n",
 
  942         dst = 
c->framebuf + tile_x * 
c->tile_width * 3 +
 
  943               tile_y * 
c->tile_height * 
c->framebuf_stride;
 
  945         for (j = 0; j < tile_height; j++) {
 
  947             in  = (uint32_t *) buf;
 
  948             for (
i = 0; 
i < tile_width; 
i++) {
 
  954             buf += 
c->epic_buf_stride;
 
  955             dst += 
c->framebuf_stride;
 
  958         if (src_size > els_dsize) {
 
  961             int bstride = 
FFALIGN(tile_width, 16) >> 3;
 
  963             int estride = 
c->epic_buf_stride >> 2;
 
  966             src_size -= els_dsize;
 
  968             in = (uint32_t *) 
c->epic_buf;
 
  971             memset(
c->kempf_flags, 0,
 
  972                    (aheight >> 3) * bstride * 
sizeof(*
c->kempf_flags));
 
  973             for (j = 0; j < tile_height; j += 8) {
 
  974                 for (
i = 0; 
i < tile_width; 
i += 8) {
 
  975                     c->kempf_flags[(
i >> 3) + (j >> 3) * bstride] = 0;
 
  976                     for (k = 0; k < 8 * 8; k++) {
 
  977                         if (in[
i + (k & 7) + (k >> 3) * estride] == tr) {
 
  978                             c->kempf_flags[(
i >> 3) + (j >> 3) * bstride] = 1;
 
  987             memset(
c->jpeg_tile, 0, 
c->tile_stride * aheight);
 
  989                             c->jpeg_tile, 
c->tile_stride,
 
  990                             c->kempf_flags, bstride, nblocks, 
c->swapuv);
 
  992             in  = (uint32_t *) 
c->epic_buf;
 
  993             dst = 
c->framebuf + tile_x * 
c->tile_width * 3 +
 
  994                   tile_y * 
c->tile_height * 
c->framebuf_stride;
 
  996             for (j = 0; j < tile_height; j++) {
 
  997                 for (
i = 0; 
i < tile_width; 
i++)
 
  999                         memcpy(
dst + 
i * 3, jpg + 
i * 3, 3);
 
 1000                 in  += 
c->epic_buf_stride >> 2;
 
 1001                 dst += 
c->framebuf_stride;
 
 1002                 jpg += 
c->tile_stride;
 
 1006         dst = 
c->framebuf + tile_x * 
c->tile_width * 3 +
 
 1007               tile_y * 
c->tile_height * 
c->framebuf_stride;
 
 1009                                dst, 
c->framebuf_stride, 
NULL, 0, 0, 
c->swapuv);
 
 1017                               const uint8_t *jpeg_tile, 
int tile_stride,
 
 1019                               const uint8_t *pal, 
int npal, 
int tidx)
 
 1029     if (npal <= 2)       nb = 1;
 
 1030     else if (npal <= 4)  nb = 2;
 
 1031     else if (npal <= 16) nb = 4;
 
 1040                 memcpy(
dst + 
i * 3, pal + col * 3, 3);
 
 1042                 memcpy(
dst + 
i * 3, jpeg_tile + 
i * 3, 3);
 
 1051                              const uint8_t *
src, 
int src_size)
 
 1054     int hdr, zsize, npal, tidx = -1, 
ret;
 
 1055     const uint8_t *src_end = 
src + src_size;
 
 1056     uint8_t pal[768], transp[3];
 
 1057     uLongf dlen = (
c->tile_width + 1) * 
c->tile_height;
 
 1059     int nblocks, cblocks, bstride;
 
 1060     int bits, bitbuf, coded;
 
 1061     uint8_t *
dst = 
c->framebuf + tile_x * 
c->tile_width * 3 +
 
 1062                    tile_y * 
c->tile_height * 
c->framebuf_stride;
 
 1067     width  = 
FFMIN(
c->width  - tile_x * 
c->tile_width,  
c->tile_width);
 
 1068     height = 
FFMIN(
c->height - tile_y * 
c->tile_height, 
c->tile_height);
 
 1071     sub_type = hdr >> 5;
 
 1072     if (sub_type == 0) {
 
 1073         memcpy(transp, 
src, 3);
 
 1075         for (
int j = 0; j < 
height; j++, 
dst += 
c->framebuf_stride)
 
 1077                 memcpy(
dst + 
i * 3, transp, 3);
 
 1079     } 
else if (sub_type == 1) {
 
 1081                                dst, 
c->framebuf_stride, 
NULL, 0, 0, 0);
 
 1084     if (sub_type != 2) {
 
 1085         memcpy(transp, 
src, 3);
 
 1089     if (src_end - 
src < npal * 3)
 
 1091     memcpy(pal, 
src, npal * 3);
 
 1093     if (sub_type != 2) {
 
 1094         for (
int i = 0; 
i < npal; 
i++) {
 
 1095             if (!memcmp(pal + 
i * 3, transp, 3)) {
 
 1102     if (src_end - 
src < 2)
 
 1104     zsize = (
src[0] << 8) | 
src[1];
 
 1107     if (src_end - 
src < zsize + (sub_type != 2))
 
 1110     ret = uncompress(
c->kempf_buf, &dlen, 
src, zsize);
 
 1115     if (sub_type == 2) {
 
 1121     nblocks = *
src++ + 1;
 
 1138             if (cblocks > nblocks)
 
 1140             c->kempf_flags[j * 2 +      
i * 2      * bstride] =
 
 1141             c->kempf_flags[j * 2 + 1 +  
i * 2      * bstride] =
 
 1142             c->kempf_flags[j * 2 +     (
i * 2 + 1) * bstride] =
 
 1143             c->kempf_flags[j * 2 + 1 + (
i * 2 + 1) * bstride] = coded;
 
 1147     memset(
c->jpeg_tile, 0, 
c->tile_stride * 
height);
 
 1149                     c->jpeg_tile, 
c->tile_stride,
 
 1150                     c->kempf_flags, bstride, nblocks * 4, 0);
 
 1153                       c->jpeg_tile, 
c->tile_stride,
 
 1163     c->framebuf_stride = 
FFALIGN(
c->width + 15, 16) * 3;
 
 1164     aligned_height = 
c->height + 15;
 
 1166     av_fast_mallocz(&
c->framebuf, &
c->framebuf_allocated, 
c->framebuf_stride * aligned_height);
 
 1170     if (!
c->synth_tile || !
c->jpeg_tile ||
 
 1171         (
c->compression == 2 && !
c->epic_buf_base) ||
 
 1172         c->old_tile_w < 
c->tile_width ||
 
 1173         c->old_tile_h < 
c->tile_height) {
 
 1174         c->tile_stride     = 
FFALIGN(
c->tile_width, 16) * 3;
 
 1175         c->epic_buf_stride = 
FFALIGN(
c->tile_width * 4, 16);
 
 1176         aligned_height     = 
FFALIGN(
c->tile_height,    16);
 
 1183         c->synth_tile  = 
av_mallocz(
c->tile_stride      * aligned_height);
 
 1184         c->jpeg_tile   = 
av_mallocz(
c->tile_stride      * aligned_height);
 
 1185         c->kempf_buf   = 
av_mallocz((
c->tile_width + 1) * aligned_height +
 
 1187         c->kempf_flags = 
av_mallocz(
c->tile_width       * aligned_height);
 
 1188         if (!
c->synth_tile || !
c->jpeg_tile ||
 
 1189             !
c->kempf_buf || !
c->kempf_flags)
 
 1191         if (
c->compression == 2) {
 
 1192             c->epic_buf_base = 
av_mallocz(
c->epic_buf_stride * aligned_height + 4);
 
 1193             if (!
c->epic_buf_base)
 
 1195             c->epic_buf = 
c->epic_buf_base + 4;
 
 1208     uint32_t cur_size, cursor_w, cursor_h, cursor_stride;
 
 1209     uint32_t cursor_hot_x, cursor_hot_y;
 
 1210     int cursor_fmt, err;
 
 1212     cur_size     = bytestream2_get_be32(gb);
 
 1213     cursor_w     = bytestream2_get_byte(gb);
 
 1214     cursor_h     = bytestream2_get_byte(gb);
 
 1215     cursor_hot_x = bytestream2_get_byte(gb);
 
 1216     cursor_hot_y = bytestream2_get_byte(gb);
 
 1217     cursor_fmt   = bytestream2_get_byte(gb);
 
 1219     cursor_stride = 
FFALIGN(cursor_w, cursor_fmt==1 ? 32 : 1) * 4;
 
 1221     if (cursor_w < 1 || cursor_w > 256 ||
 
 1222         cursor_h < 1 || cursor_h > 256) {
 
 1224                cursor_w, cursor_h);
 
 1227     if (cursor_hot_x > cursor_w || cursor_hot_y > cursor_h) {
 
 1229                cursor_hot_x, cursor_hot_y);
 
 1230         cursor_hot_x = 
FFMIN(cursor_hot_x, cursor_w - 1);
 
 1231         cursor_hot_y = 
FFMIN(cursor_hot_y, cursor_h - 1);
 
 1234         c->cursor_w * 
c->cursor_h / 4 > cur_size) {
 
 1239     if (cursor_fmt != 1 && cursor_fmt != 32) {
 
 1245     if ((err = 
av_reallocp(&
c->cursor, cursor_stride * cursor_h)) < 0) {
 
 1250     c->cursor_w      = cursor_w;
 
 1251     c->cursor_h      = cursor_h;
 
 1252     c->cursor_hot_x  = cursor_hot_x;
 
 1253     c->cursor_hot_y  = cursor_hot_y;
 
 1254     c->cursor_fmt    = cursor_fmt;
 
 1255     c->cursor_stride = cursor_stride;
 
 1258     switch (
c->cursor_fmt) {
 
 1260         for (j = 0; j < 
c->cursor_h; j++) {
 
 1261             for (
i = 0; 
i < 
c->cursor_w; 
i += 32) {
 
 1262                 bits = bytestream2_get_be32(gb);
 
 1263                 for (k = 0; k < 32; k++) {
 
 1264                     dst[0] = !!(
bits & 0x80000000);
 
 1272         for (j = 0; j < 
c->cursor_h; j++) {
 
 1273             for (
i = 0; 
i < 
c->cursor_w; 
i += 32) {
 
 1274                 bits = bytestream2_get_be32(gb);
 
 1275                 for (k = 0; k < 32; k++) {
 
 1276                     int mask_bit = !!(
bits & 0x80000000);
 
 1277                     switch (
dst[0] * 2 + mask_bit) {
 
 1305         for (j = 0; j < 
c->cursor_h; j++) {
 
 1306             for (
i = 0; 
i < 
c->cursor_w; 
i++) {
 
 1307                 int val = bytestream2_get_be32(gb);
 
 1321 #define APPLY_ALPHA(src, new, alpha) \ 
 1322     src = (src * (256 - alpha) + new * alpha) >> 8 
 1328     const uint8_t *cursor;
 
 1333     x = 
c->cursor_x - 
c->cursor_hot_x;
 
 1334     y = 
c->cursor_y - 
c->cursor_hot_y;
 
 1340     if (x + 
w > 
c->width)
 
 1342     if (y + 
h > 
c->height)
 
 1356         cursor += -y * 
c->cursor_stride;
 
 1361     for (j = 0; j < 
h; j++) {
 
 1362         for (
i = 0; 
i < 
w; 
i++) {
 
 1363             uint8_t 
alpha = cursor[
i * 4];
 
 1369         cursor += 
c->cursor_stride;
 
 1374                             int *got_picture_ptr, 
AVPacket *avpkt)
 
 1376     const uint8_t *buf = avpkt->
data;
 
 1377     int buf_size = avpkt->
size;
 
 1382     uint32_t chunk_size, r_mask, g_mask, b_mask;
 
 1387     if (buf_size < 12) {
 
 1389                "Frame should have at least 12 bytes, got %d instead\n",
 
 1396     magic = bytestream2_get_be32(&bc);
 
 1397     if ((magic & ~0xF) != 
MKBETAG(
'G', 
'2', 
'M', 
'0') ||
 
 1398         (magic & 0xF) < 2 || (magic & 0xF) > 5) {
 
 1403     c->swapuv = magic == 
MKBETAG(
'G', 
'2', 
'M', 
'2');
 
 1406         chunk_size  = bytestream2_get_le32(&bc) - 1;
 
 1407         chunk_type  = bytestream2_get_byte(&bc);
 
 1411                    chunk_size, chunk_type);
 
 1414         switch (chunk_type) {
 
 1418             if (chunk_size < 21) {
 
 1423             c->width  = bytestream2_get_be32(&bc);
 
 1424             c->height = bytestream2_get_be32(&bc);
 
 1425             if (
c->width < 16 || 
c->height < 16) {
 
 1427                        "Invalid frame dimensions %dx%d\n",
 
 1428                        c->width, 
c->height);
 
 1432             if (
c->width != avctx->
width || 
c->height != avctx->
height) {
 
 1437             c->compression = bytestream2_get_be32(&bc);
 
 1438             if (
c->compression != 2 && 
c->compression != 3) {
 
 1444             c->tile_width  = bytestream2_get_be32(&bc);
 
 1445             c->tile_height = bytestream2_get_be32(&bc);
 
 1446             if (
c->tile_width <= 0 || 
c->tile_height <= 0 ||
 
 1447                 ((
c->tile_width | 
c->tile_height) & 0xF) ||
 
 1448                 c->tile_width * (uint64_t)
c->tile_height >= INT_MAX / 4 ||
 
 1452                        "Invalid tile dimensions %dx%d\n",
 
 1453                        c->tile_width, 
c->tile_height);
 
 1457             c->tiles_x = (
c->width  + 
c->tile_width  - 1) / 
c->tile_width;
 
 1458             c->tiles_y = (
c->height + 
c->tile_height - 1) / 
c->tile_height;
 
 1459             c->bpp     = bytestream2_get_byte(&bc);
 
 1462                     (chunk_size - 21) < 16) {
 
 1464                            "Display info: missing bitmasks!\n");
 
 1468                 r_mask = bytestream2_get_be32(&bc);
 
 1469                 g_mask = bytestream2_get_be32(&bc);
 
 1470                 b_mask = bytestream2_get_be32(&bc);
 
 1471                 if (r_mask != 0xFF0000 || g_mask != 0xFF00 || b_mask != 0xFF) {
 
 1473                                                   "Bitmasks: R=%"PRIX32
", G=%"PRIX32
", B=%"PRIX32,
 
 1474                                                   r_mask, g_mask, b_mask);
 
 1490             if (!
c->tiles_x || !
c->tiles_y) {
 
 1492                        "No display info - skipping tile\n");
 
 1495             if (chunk_size < 2) {
 
 1500             c->tile_x = bytestream2_get_byte(&bc);
 
 1501             c->tile_y = bytestream2_get_byte(&bc);
 
 1502             if (
c->tile_x >= 
c->tiles_x || 
c->tile_y >= 
c->tiles_y) {
 
 1504                        "Invalid tile pos %d,%d (in %dx%d grid)\n",
 
 1505                        c->tile_x, 
c->tile_y, 
c->tiles_x, 
c->tiles_y);
 
 1509             switch (
c->compression) {
 
 1513                                           chunk_size - 2, avctx);
 
 1521             if (
ret && 
c->framebuf)
 
 1523                        c->tile_x, 
c->tile_y);
 
 1526             if (chunk_size < 5) {
 
 1531             c->cursor_x = bytestream2_get_be16(&bc);
 
 1532             c->cursor_y = bytestream2_get_be16(&bc);
 
 1535             if (chunk_size < 8) {
 
 1558     if (
c->width && 
c->height && 
c->framebuf) {
 
 1570                    c->framebuf + 
i * 
c->framebuf_stride,
 
 1574         *got_picture_ptr = 1;
 
 1602     c->orig_width  = avctx->
width;
 
 1603     c->orig_height = avctx->
height;
 
 1622     c->framebuf_allocated = 0;
 
  
#define EPIC_PIX_STACK_SIZE
unsigned ff_els_decode_unsigned(ElsDecCtx *ctx, ElsUnsignedRung *ur)
static int epic_add_pixel_to_cache(ePICPixHash *hash, uint32_t key, uint32_t pix)
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
struct ePICPixListElem * list
int ff_els_decode_bit(ElsDecCtx *ctx, uint8_t *rung)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
static int chunk_start(AVFormatContext *s)
static int get_bits_left(GetBitContext *gb)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static av_always_inline int bytestream2_tell(const GetByteContext *g)
void ff_els_decoder_init(ElsDecCtx *ctx, const uint8_t *in, size_t data_size)
static int jpg_decode_block(JPGContext *c, GetBitContext *gb, int plane, int16_t *block)
This structure describes decoded (raw) audio or video data.
uint8_t permutated_scantable[64]
static int epic_predict_from_NW_NE(ePICContext *dc, int x, int y, int run, int tile_width, const uint32_t *curr_row, const uint32_t *above_row, uint32_t *pPix)
const uint8_t ff_mjpeg_val_dc[]
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
const uint8_t ff_mjpeg_bits_ac_chrominance[]
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
static int rle(uint8_t *dst, const uint8_t *src, int compressed_size, int uncompressed_size)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static void jpg_unescape(const uint8_t *src, int src_size, uint8_t *dst, int *dst_size)
static av_cold int g2m_decode_init(AVCodecContext *avctx)
av_cold void ff_permute_scantable(uint8_t dst[64], const uint8_t src[64], const uint8_t permutation[64])
static av_cold void close(AVCodecParserContext *s)
int bucket_size[EPIC_HASH_SIZE]
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static ePICPixHashElem * epic_hash_find(const ePICPixHash *hash, uint32_t key)
AVCodec p
The public AVCodec.
static int epic_decode_tile(ePICContext *dc, uint8_t *out, int tile_height, int tile_width, int stride)
uint8_t prev_row_rung[14]
static double val(void *priv, double ch)
static int epic_handle_edges(ePICContext *dc, int x, int y, const uint32_t *curr_row, const uint32_t *above_row, uint32_t *pPix)
static void g2m_paint_cursor(G2MContext *c, uint8_t *dst, int stride)
int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enum AVPixelFormat pix_fmt, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of a plane of an image with...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
#define FF_CODEC_DECODE_CB(func)
av_cold void ff_blockdsp_init(BlockDSPContext *c)
uint8_t nw_pred_rung[256]
static FFFrameBucket * bucket(FFFrameQueue *fq, size_t idx)
#define APPLY_ALPHA(src, new, alpha)
int64_t max_pixels
The number of pixels per image to maximally accept.
static int epic_decode_from_cache(ePICContext *dc, uint32_t W, uint32_t *pPix)
#define CODEC_LONG_NAME(str)
static av_cold int g2m_decode_end(AVCodecContext *avctx)
static int epic_jb_decode_tile(G2MContext *c, int tile_x, int tile_y, const uint8_t *src, size_t src_size, AVCodecContext *avctx)
ePICPixHashElem * bucket[EPIC_HASH_SIZE]
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
ElsUnsignedRung unsigned_rung
static ePICPixHashElem * epic_hash_add(ePICPixHash *hash, uint32_t key)
const FFCodec ff_g2m_decoder
static av_cold int jpg_init(AVCodecContext *avctx, JPGContext *c)
@ AV_PICTURE_TYPE_I
Intra.
void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size)
Allocate and clear a buffer, reusing the given one if large enough.
#define FF_PTR_ADD(ptr, off)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining list
#define EPIC_PIX_STACK_MAX
static int g2m_load_cursor(AVCodecContext *avctx, G2MContext *c, GetByteContext *gb)
const uint8_t ff_mjpeg_val_ac_chrominance[]
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
static int epic_predict_pixel2(ePICContext *dc, uint8_t *rung, uint32_t *pPix, uint32_t pix)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static int g2m_decode_frame(AVCodecContext *avctx, AVFrame *pic, int *got_picture_ptr, AVPacket *avpkt)
enum AVPictureType pict_type
Picture type of the frame.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
const uint8_t ff_mjpeg_val_ac_luminance[]
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled top and top right vectors is used as motion vector prediction the used motion vector is the sum of the predictor and(mvx_diff, mvy_diff) *mv_scale Intra DC Prediction block[y][x] dc[1]
#define DECLARE_ALIGNED(n, t, v)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const uint8_t ff_mjpeg_bits_ac_luminance[]
struct ePICPixListElem * next
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
#define MKBETAG(a, b, c, d)
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static int get_xbits(GetBitContext *s, int n)
Read MPEG-1 dc-style VLC (sign bit + mantissa with no MSB).
void ff_els_decoder_uninit(ElsUnsignedRung *rung)
unsigned int framebuf_allocated
int bucket_fill[EPIC_HASH_SIZE]
static int kempf_decode_tile(G2MContext *c, int tile_x, int tile_y, const uint8_t *src, int src_size)
#define i(width, name, range_min, range_max)
static int djb2_hash(uint32_t key)
static av_cold void jpg_free_context(JPGContext *ctx)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
const char * name
Name of the codec implementation.
static const uint8_t luma_quant[64]
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
const uint8_t ff_zigzag_direct[64]
int64_t frame_num
Frame counter, set by libavcodec.
void ff_vlc_free(VLC *vlc)
static int kempf_restore_buf(const uint8_t *src, int len, uint8_t *dst, int stride, const uint8_t *jpeg_tile, int tile_stride, int width, int height, const uint8_t *pal, int npal, int tidx)
static const float pred[4]
#define AV_INPUT_BUFFER_PADDING_SIZE
uint8_t ne_pred_rung[256]
main external API structure.
static void epic_hash_init(ePICPixHash *hash)
static int g2m_init_buffers(G2MContext *c)
uint8_t runlen_zeroes[14]
static int epic_predict_pixel(ePICContext *dc, uint8_t *rung, uint32_t *pPix, uint32_t pix)
const uint8_t ff_mjpeg_bits_dc_chrominance[]
#define UPDATE_NEIGHBOURS(x)
static int jpg_decode_data(JPGContext *c, int width, int height, const uint8_t *src, int src_size, uint8_t *dst, int dst_stride, const uint8_t *mask, int mask_stride, int num_mbs, int swapuv)
#define LOAD_NEIGHBOURS(x)
@ AV_PICTURE_TYPE_P
Predicted.
static const uint8_t chroma_quant[64]
#define avpriv_request_sample(...)
static int epic_cache_entries_for_pixel(const ePICPixHash *hash, uint32_t pix)
const FF_VISIBILITY_PUSH_HIDDEN uint8_t ff_mjpeg_bits_dc_luminance[]
static const int16_t alpha[]
int ff_mjpeg_build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table, int is_ac, void *logctx)
This structure stores compressed data.
static int epic_decode_component_pred(ePICContext *dc, int N, int W, int NW)
static int epic_decode_run_length(ePICContext *dc, int x, int y, int tile_width, const uint32_t *curr_row, const uint32_t *above_row, const uint32_t *above2_row, uint32_t *pPix, int *pRun)
int width
picture width / height.
uint32_t stack[EPIC_PIX_STACK_SIZE]
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
The exact code depends on how similar the blocks are and how related they are to the block
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static void epic_free_pixel_cache(ePICPixHash *hash)
static uint32_t epic_decode_pixel_pred(ePICContext *dc, int x, int y, const uint32_t *curr_row, const uint32_t *above_row)
static void yuv2rgb(uint8_t *out, int ridx, int Y, int U, int V)
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
static int is_pixel_on_stack(const ePICContext *dc, uint32_t pix)