46 #define EPIC_PIX_STACK_SIZE 1024
47 #define EPIC_PIX_STACK_MAX (EPIC_PIX_STACK_SIZE - 1)
64 8, 6, 5, 8, 12, 20, 26, 31,
65 6, 6, 7, 10, 13, 29, 30, 28,
66 7, 7, 8, 12, 20, 29, 35, 28,
67 7, 9, 11, 15, 26, 44, 40, 31,
68 9, 11, 19, 28, 34, 55, 52, 39,
69 12, 18, 28, 32, 41, 52, 57, 46,
70 25, 32, 39, 44, 52, 61, 60, 51,
71 36, 46, 48, 49, 56, 50, 52, 50
75 9, 9, 12, 24, 50, 50, 50, 50,
76 9, 11, 13, 33, 50, 50, 50, 50,
77 12, 13, 28, 50, 50, 50, 50, 50,
78 24, 33, 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,
96 #define EPIC_HASH_SIZE 256
196 for (
i = 0;
i < 2;
i++) {
210 while (
src < src_end) {
215 if (x == 0xFF && !*
src)
218 *dst_size = dst - dst_start;
222 int plane, int16_t *
block)
225 const int is_chroma = !!plane;
231 c->bdsp.clear_block(
block);
232 dc =
get_vlc2(gb,
c->dc_vlc[is_chroma].table, 9, 2);
237 dc =
dc * qmat[0] +
c->prev_dc[plane];
239 c->prev_dc[plane] =
dc;
275 int mb_w, mb_h, mb_x, mb_y,
i, j;
279 const int ridx = swapuv ? 2 : 0;
291 mb_h = (
height + 15) >> 4;
294 num_mbs = mb_w * mb_h * 4;
296 for (
i = 0;
i < 3;
i++)
297 c->prev_dc[
i] = 1024;
300 c->bdsp.clear_blocks(
c->block[0]);
301 for (mb_y = 0; mb_y < mb_h; mb_y++) {
302 for (mb_x = 0; mb_x < mb_w; mb_x++) {
304 !
mask[mb_x * 2 + mask_stride] &&
305 !
mask[mb_x * 2 + 1 + mask_stride]) {
309 for (j = 0; j < 2; j++) {
310 for (
i = 0;
i < 2;
i++) {
311 if (
mask && !
mask[mb_x * 2 +
i + j * mask_stride])
315 c->block[
i + j * 2])) != 0)
317 c->idsp.idct(
c->block[
i + j * 2]);
320 for (
i = 1;
i < 3;
i++) {
323 c->idsp.idct(
c->block[
i + 3]);
326 for (j = 0; j < 16; j++) {
327 uint8_t *
out = dst + bx * 3 + (by + j) * dst_stride;
328 for (
i = 0;
i < 16;
i++) {
331 Y =
c->block[(j >> 3) * 2 + (
i >> 3)][(
i & 7) + (j & 7) * 8];
332 U =
c->block[4][(
i >> 1) + (j >> 1) * 8] - 128;
333 V =
c->block[5][(
i >> 1) + (j >> 1) * 8] - 128;
345 mask += mask_stride * 2;
351 #define LOAD_NEIGHBOURS(x) \
352 W = curr_row[(x) - 1]; \
353 N = above_row[(x)]; \
354 WW = curr_row[(x) - 2]; \
355 NW = above_row[(x) - 1]; \
356 NE = above_row[(x) + 1]; \
357 NN = above2_row[(x)]; \
358 NNW = above2_row[(x) - 1]; \
359 NWW = above_row[(x) - 2]; \
360 NNE = above2_row[(x) + 1]
362 #define UPDATE_NEIGHBOURS(x) \
368 NE = above_row[(x) + 1]; \
369 NNE = above2_row[(x) + 1]
380 h = (
h * 33) ^ ((
key >> 24) & 0xFF);
381 h = (
h * 33) ^ ((
key >> 16) & 0xFF);
382 h = (
h * 33) ^ ((
key >> 8) & 0xFF);
383 h = (
h * 33) ^ (
key & 0xFF);
398 for (
i = 0;
i <
hash->bucket_fill[idx];
i++)
410 if (
hash->bucket_size[idx] > INT_MAX /
sizeof(**
hash->bucket))
413 if (!(
hash->bucket_fill[idx] <
hash->bucket_size[idx])) {
414 int new_size =
hash->bucket_size[idx] + 16;
419 hash->bucket_size[idx] = new_size;
422 ret = &
hash->bucket[idx][
hash->bucket_fill[idx]++];
423 memset(ret, 0,
sizeof(*ret));
442 new_elem->
pixel = pix;
444 hash_elem->
list = new_elem;
465 for (j = 0; j <
hash->bucket_fill[
i]; j++) {
474 hash->bucket_size[
i] =
475 hash->bucket_fill[
i] = 0;
483 for (
i = 0;
i <
dc->stack_pos;
i++)
484 if (
dc->stack[
i] == pix)
487 return i !=
dc->stack_pos;
490 #define TOSIGNED(val) (((val) >> 1) ^ -((val) & 1))
493 int N,
int W,
int NW)
500 const uint32_t *curr_row,
501 const uint32_t *above_row)
505 int GN, GW, GNW,
R,
G,
B;
510 NW = above_row[x - 1];
521 ((NW >>
R_shift) & 0xFF) - GNW);
526 ((NW >>
B_shift) & 0xFF) - GNW);
529 pred = curr_row[x - 1];
543 if (
R<0 ||
G<0 || B<0 || R > 255 ||
G > 255 ||
B > 255) {
552 uint32_t *pPix, uint32_t pix)
563 const uint32_t *curr_row,
564 const uint32_t *above_row, uint32_t *pPix)
577 pix = curr_row[x - 1];
584 if (!
dc->stack_pos ||
dc->stack[0] != pix) {
594 const uint32_t *curr_row,
595 const uint32_t *above_row,
596 const uint32_t *above2_row,
597 uint32_t *pPix,
int *pRun)
599 int idx, got_pixel = 0, WWneW, old_WWneW = 0;
600 uint32_t
W, WW,
N,
NN, NW, NE, NWW, NNW, NNE;
606 if (
dc->next_run_pos == x) {
610 idx = (WW !=
W) << 7 |
635 NWneW = *pRun ? NWneW : NW !=
W;
638 switch (((NW !=
N) << 2) | (NWneW << 1) | WWneW) {
647 (*pRun ? old_WWneW : WW !=
W) << 7 |
672 if (x + *pRun >= tile_width - 1)
677 if (!NWneW && NW ==
N &&
N == NE) {
679 int start_pos = x + *pRun;
682 uint32_t pix = above_row[start_pos + 1];
683 for (
pos = start_pos + 2;
pos < tile_width;
pos++)
684 if (!(above_row[
pos] == pix))
686 run =
pos - start_pos - 1;
697 : &
dc->runlen_zeroes[
pos])) {
705 if (x + *pRun >= tile_width - 1)
724 dc->next_run_pos = x + *pRun;
729 uint32_t *pPix, uint32_t pix)
740 int tile_width,
const uint32_t *curr_row,
741 const uint32_t *above_row, uint32_t *pPix)
747 uint32_t NW = above_row[x - 1];
756 if (
pos < tile_width - 1 && y) {
757 uint32_t NE = above_row[
pos + 1];
772 if (!hash_elem || !hash_elem->
list)
775 list = hash_elem->
list;
780 if (list != hash_elem->
list) {
783 hash_elem->
list = list;
797 int tile_width,
int stride)
801 uint32_t *curr_row =
NULL, *above_row =
NULL, *above2_row;
803 for (y = 0; y < tile_height; y++,
out +=
stride) {
804 above2_row = above_row;
805 above_row = curr_row;
806 curr_row = (uint32_t *)
out;
808 for (x = 0,
dc->next_run_pos = 0; x < tile_width;) {
812 pix = curr_row[x - 1];
814 if (y >= 1 && x >= 2 &&
815 pix != curr_row[x - 2] && pix != above_row[x - 1] &&
816 pix != above_row[x - 2] && pix != above_row[x] &&
824 if (y < 2 || x < 2 || x == tile_width - 1) {
830 above2_row, &pix, &
run);
836 tile_width, curr_row,
838 uint32_t ref_pix = curr_row[x - 1];
853 for (;
run > 0; x++,
run--)
867 int extrabytes, tile_width, tile_height, awidth, aheight;
877 for (extrabytes = 0; (prefix &
mask) && (extrabytes < 7); extrabytes++)
879 if (extrabytes > 3 || src_size < extrabytes) {
884 els_dsize = prefix & ((0x80 >> extrabytes) - 1);
885 while (extrabytes-- > 0) {
886 els_dsize = (els_dsize << 8) | *
src++;
890 if (src_size < els_dsize) {
892 els_dsize, src_size);
896 tile_width =
FFMIN(
c->width - tile_x *
c->tile_width,
c->tile_width);
897 tile_height =
FFMIN(
c->height - tile_y *
c->tile_height,
c->tile_height);
898 awidth =
FFALIGN(tile_width, 16);
899 aheight =
FFALIGN(tile_height, 16);
908 uint8_t tr_r, tr_g, tr_b, *buf;
911 memset(&
c->ec, 0,
sizeof(
c->ec));
919 if (
c->ec.els_ctx.err != 0) {
921 "ePIC: couldn't decode transparency pixel!\n");
934 "ePIC: tile decoding failed, frame=%d, tile_x=%d, tile_y=%d\n",
940 dst =
c->framebuf + tile_x *
c->tile_width * 3 +
941 tile_y *
c->tile_height *
c->framebuf_stride;
943 for (j = 0; j < tile_height; j++) {
945 in = (uint32_t *) buf;
946 for (
i = 0;
i < tile_width;
i++) {
952 buf +=
c->epic_buf_stride;
953 dst +=
c->framebuf_stride;
956 if (src_size > els_dsize) {
959 int bstride =
FFALIGN(tile_width, 16) >> 3;
961 int estride =
c->epic_buf_stride >> 2;
964 src_size -= els_dsize;
966 in = (uint32_t *)
c->epic_buf;
969 memset(
c->kempf_flags, 0,
970 (aheight >> 3) * bstride *
sizeof(*
c->kempf_flags));
971 for (j = 0; j < tile_height; j += 8) {
972 for (
i = 0;
i < tile_width;
i += 8) {
973 c->kempf_flags[(
i >> 3) + (j >> 3) * bstride] = 0;
974 for (k = 0; k < 8 * 8; k++) {
975 if (
in[
i + (k & 7) + (k >> 3) * estride] == tr) {
976 c->kempf_flags[(
i >> 3) + (j >> 3) * bstride] = 1;
985 memset(
c->jpeg_tile, 0,
c->tile_stride * aheight);
987 c->jpeg_tile,
c->tile_stride,
988 c->kempf_flags, bstride, nblocks,
c->swapuv);
990 in = (uint32_t *)
c->epic_buf;
991 dst =
c->framebuf + tile_x *
c->tile_width * 3 +
992 tile_y *
c->tile_height *
c->framebuf_stride;
994 for (j = 0; j < tile_height; j++) {
995 for (
i = 0;
i < tile_width;
i++)
997 memcpy(dst +
i * 3, jpg +
i * 3, 3);
998 in +=
c->epic_buf_stride >> 2;
999 dst +=
c->framebuf_stride;
1000 jpg +=
c->tile_stride;
1004 dst =
c->framebuf + tile_x *
c->tile_width * 3 +
1005 tile_y *
c->tile_height *
c->framebuf_stride;
1007 dst,
c->framebuf_stride,
NULL, 0, 0,
c->swapuv);
1015 const uint8_t *jpeg_tile,
int tile_stride,
1017 const uint8_t *pal,
int npal,
int tidx)
1027 if (npal <= 2) nb = 1;
1028 else if (npal <= 4) nb = 2;
1029 else if (npal <= 16) nb = 4;
1038 memcpy(dst +
i * 3, pal + col * 3, 3);
1040 memcpy(dst +
i * 3, jpeg_tile +
i * 3, 3);
1052 int hdr, zsize, npal, tidx = -1, ret;
1056 uLongf dlen = (
c->tile_width + 1) *
c->tile_height;
1058 int nblocks, cblocks, bstride;
1059 int bits, bitbuf, coded;
1060 uint8_t *dst =
c->framebuf + tile_x *
c->tile_width * 3 +
1061 tile_y *
c->tile_height *
c->framebuf_stride;
1066 width =
FFMIN(
c->width - tile_x *
c->tile_width,
c->tile_width);
1067 height =
FFMIN(
c->height - tile_y *
c->tile_height,
c->tile_height);
1070 sub_type = hdr >> 5;
1071 if (sub_type == 0) {
1073 memcpy(transp,
src, 3);
1075 for (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 (
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 if (!
c->framebuf ||
c->old_width <
c->width ||
c->old_height <
c->height) {
1164 c->framebuf_stride =
FFALIGN(
c->width + 15, 16) * 3;
1165 aligned_height =
c->height + 15;
1171 if (!
c->synth_tile || !
c->jpeg_tile ||
1172 (
c->compression == 2 && !
c->epic_buf_base) ||
1173 c->old_tile_w <
c->tile_width ||
1174 c->old_tile_h <
c->tile_height) {
1175 c->tile_stride =
FFALIGN(
c->tile_width, 16) * 3;
1176 c->epic_buf_stride =
FFALIGN(
c->tile_width * 4, 16);
1177 aligned_height =
FFALIGN(
c->tile_height, 16);
1184 c->synth_tile =
av_mallocz(
c->tile_stride * aligned_height);
1185 c->jpeg_tile =
av_mallocz(
c->tile_stride * aligned_height);
1186 c->kempf_buf =
av_mallocz((
c->tile_width + 1) * aligned_height +
1188 c->kempf_flags =
av_mallocz(
c->tile_width * aligned_height);
1189 if (!
c->synth_tile || !
c->jpeg_tile ||
1190 !
c->kempf_buf || !
c->kempf_flags)
1192 if (
c->compression == 2) {
1193 c->epic_buf_base =
av_mallocz(
c->epic_buf_stride * aligned_height + 4);
1194 if (!
c->epic_buf_base)
1196 c->epic_buf =
c->epic_buf_base + 4;
1209 uint32_t cur_size, cursor_w, cursor_h, cursor_stride;
1210 uint32_t cursor_hot_x, cursor_hot_y;
1211 int cursor_fmt, err;
1213 cur_size = bytestream2_get_be32(gb);
1214 cursor_w = bytestream2_get_byte(gb);
1215 cursor_h = bytestream2_get_byte(gb);
1216 cursor_hot_x = bytestream2_get_byte(gb);
1217 cursor_hot_y = bytestream2_get_byte(gb);
1218 cursor_fmt = bytestream2_get_byte(gb);
1220 cursor_stride =
FFALIGN(cursor_w, cursor_fmt==1 ? 32 : 1) * 4;
1222 if (cursor_w < 1 || cursor_w > 256 ||
1223 cursor_h < 1 || cursor_h > 256) {
1225 cursor_w, cursor_h);
1228 if (cursor_hot_x > cursor_w || cursor_hot_y > cursor_h) {
1230 cursor_hot_x, cursor_hot_y);
1231 cursor_hot_x =
FFMIN(cursor_hot_x, cursor_w - 1);
1232 cursor_hot_y =
FFMIN(cursor_hot_y, cursor_h - 1);
1235 c->cursor_w *
c->cursor_h / 4 > cur_size) {
1240 if (cursor_fmt != 1 && cursor_fmt != 32) {
1246 if ((err =
av_reallocp(&
c->cursor, cursor_stride * cursor_h)) < 0) {
1251 c->cursor_w = cursor_w;
1252 c->cursor_h = cursor_h;
1253 c->cursor_hot_x = cursor_hot_x;
1254 c->cursor_hot_y = cursor_hot_y;
1255 c->cursor_fmt = cursor_fmt;
1256 c->cursor_stride = cursor_stride;
1259 switch (
c->cursor_fmt) {
1261 for (j = 0; j <
c->cursor_h; j++) {
1262 for (
i = 0;
i <
c->cursor_w;
i += 32) {
1263 bits = bytestream2_get_be32(gb);
1264 for (k = 0; k < 32; k++) {
1265 dst[0] = !!(
bits & 0x80000000);
1273 for (j = 0; j <
c->cursor_h; j++) {
1274 for (
i = 0;
i <
c->cursor_w;
i += 32) {
1275 bits = bytestream2_get_be32(gb);
1276 for (k = 0; k < 32; k++) {
1277 int mask_bit = !!(
bits & 0x80000000);
1278 switch (dst[0] * 2 + mask_bit) {
1306 for (j = 0; j <
c->cursor_h; j++) {
1307 for (
i = 0;
i <
c->cursor_w;
i++) {
1308 int val = bytestream2_get_be32(gb);
1322 #define APPLY_ALPHA(src, new, alpha) \
1323 src = (src * (256 - alpha) + new * alpha) >> 8
1334 x =
c->cursor_x -
c->cursor_hot_x;
1335 y =
c->cursor_y -
c->cursor_hot_y;
1341 if (x +
w >
c->width)
1343 if (y +
h >
c->height)
1357 cursor += -y *
c->cursor_stride;
1362 for (j = 0; j <
h; j++) {
1363 for (
i = 0;
i <
w;
i++) {
1370 cursor +=
c->cursor_stride;
1375 int *got_picture_ptr,
AVPacket *avpkt)
1378 int buf_size = avpkt->
size;
1384 uint32_t chunk_size, r_mask, g_mask, b_mask;
1389 if (buf_size < 12) {
1391 "Frame should have at least 12 bytes, got %d instead\n",
1398 magic = bytestream2_get_be32(&bc);
1399 if ((magic & ~0xF) !=
MKBETAG(
'G',
'2',
'M',
'0') ||
1400 (magic & 0xF) < 2 || (magic & 0xF) > 5) {
1405 c->swapuv = magic ==
MKBETAG(
'G',
'2',
'M',
'2');
1408 chunk_size = bytestream2_get_le32(&bc) - 1;
1409 chunk_type = bytestream2_get_byte(&bc);
1413 chunk_size, chunk_type);
1416 switch (chunk_type) {
1420 if (chunk_size < 21) {
1425 c->width = bytestream2_get_be32(&bc);
1426 c->height = bytestream2_get_be32(&bc);
1427 if (
c->width < 16 ||
c->height < 16) {
1429 "Invalid frame dimensions %dx%d\n",
1430 c->width,
c->height);
1434 if (
c->width != avctx->
width ||
c->height != avctx->
height) {
1439 c->compression = bytestream2_get_be32(&bc);
1440 if (
c->compression != 2 &&
c->compression != 3) {
1446 c->tile_width = bytestream2_get_be32(&bc);
1447 c->tile_height = bytestream2_get_be32(&bc);
1448 if (
c->tile_width <= 0 ||
c->tile_height <= 0 ||
1449 ((
c->tile_width |
c->tile_height) & 0xF) ||
1450 c->tile_width * (uint64_t)
c->tile_height >= INT_MAX / 4 ||
1454 "Invalid tile dimensions %dx%d\n",
1455 c->tile_width,
c->tile_height);
1459 c->tiles_x = (
c->width +
c->tile_width - 1) /
c->tile_width;
1460 c->tiles_y = (
c->height +
c->tile_height - 1) /
c->tile_height;
1461 c->bpp = bytestream2_get_byte(&bc);
1464 (chunk_size - 21) < 16) {
1466 "Display info: missing bitmasks!\n");
1470 r_mask = bytestream2_get_be32(&bc);
1471 g_mask = bytestream2_get_be32(&bc);
1472 b_mask = bytestream2_get_be32(&bc);
1473 if (r_mask != 0xFF0000 || g_mask != 0xFF00 || b_mask != 0xFF) {
1475 "Bitmasks: R=%"PRIX32
", G=%"PRIX32
", B=%"PRIX32,
1476 r_mask, g_mask, b_mask);
1492 if (!
c->tiles_x || !
c->tiles_y) {
1494 "No display info - skipping tile\n");
1497 if (chunk_size < 2) {
1502 c->tile_x = bytestream2_get_byte(&bc);
1503 c->tile_y = bytestream2_get_byte(&bc);
1504 if (
c->tile_x >=
c->tiles_x ||
c->tile_y >=
c->tiles_y) {
1506 "Invalid tile pos %d,%d (in %dx%d grid)\n",
1507 c->tile_x,
c->tile_y,
c->tiles_x,
c->tiles_y);
1511 switch (
c->compression) {
1515 chunk_size - 2, avctx);
1523 if (ret &&
c->framebuf)
1525 c->tile_x,
c->tile_y);
1528 if (chunk_size < 5) {
1533 c->cursor_x = bytestream2_get_be16(&bc);
1534 c->cursor_y = bytestream2_get_be16(&bc);
1537 if (chunk_size < 8) {
1560 if (
c->width &&
c->height &&
c->framebuf) {
1569 c->framebuf +
i *
c->framebuf_stride,
1573 *got_picture_ptr = 1;
1593 if ((ret =
jpg_init(avctx, &
c->jc)) != 0) {
1602 c->orig_width = avctx->
width;
1603 c->orig_height = avctx->
height;
static double val(void *priv, double ch)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> dc
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
void ff_free_vlc(VLC *vlc)
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static av_always_inline int bytestream2_tell(GetByteContext *g)
#define MKBETAG(a, b, c, d)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
void ff_els_decoder_init(ElsDecCtx *ctx, const uint8_t *in, size_t data_size)
int ff_els_decode_bit(ElsDecCtx *ctx, uint8_t *rung)
void ff_els_decoder_uninit(ElsUnsignedRung *rung)
unsigned ff_els_decode_unsigned(ElsDecCtx *ctx, ElsUnsignedRung *ur)
Entropy Logarithmic-Scale binary arithmetic coder.
static int rle(uint8_t *dst, const uint8_t *src, int compressed_size, int uncompressed_size)
static FFFrameBucket * bucket(FFFrameQueue *fq, size_t idx)
static const uint8_t chroma_quant[64]
static int epic_decode_component_pred(ePICContext *dc, int N, int W, int NW)
#define LOAD_NEIGHBOURS(x)
static int epic_predict_pixel(ePICContext *dc, uint8_t *rung, uint32_t *pPix, uint32_t pix)
static void g2m_paint_cursor(G2MContext *c, uint8_t *dst, int stride)
static int epic_handle_edges(ePICContext *dc, int x, int y, const uint32_t *curr_row, const uint32_t *above_row, uint32_t *pPix)
#define EPIC_PIX_STACK_MAX
static ePICPixHashElem * epic_hash_add(ePICPixHash *hash, uint32_t key)
static const uint8_t luma_quant[64]
static int djb2_hash(uint32_t key)
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)
static int kempf_decode_tile(G2MContext *c, int tile_x, int tile_y, const uint8_t *src, int src_size)
static int is_pixel_on_stack(const ePICContext *dc, uint32_t pix)
static ePICPixHashElem * epic_hash_find(const ePICPixHash *hash, uint32_t key)
static int epic_add_pixel_to_cache(ePICPixHash *hash, uint32_t key, uint32_t pix)
static int g2m_load_cursor(AVCodecContext *avctx, G2MContext *c, GetByteContext *gb)
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 av_cold int g2m_decode_end(AVCodecContext *avctx)
static av_cold int jpg_init(AVCodecContext *avctx, JPGContext *c)
static int g2m_init_buffers(G2MContext *c)
static av_cold void jpg_free_context(JPGContext *ctx)
static int epic_jb_decode_tile(G2MContext *c, int tile_x, int tile_y, const uint8_t *src, size_t src_size, AVCodecContext *avctx)
#define EPIC_PIX_STACK_SIZE
static int epic_decode_from_cache(ePICContext *dc, uint32_t W, uint32_t *pPix)
static int epic_cache_entries_for_pixel(const ePICPixHash *hash, uint32_t pix)
static void jpg_unescape(const uint8_t *src, int src_size, uint8_t *dst, int *dst_size)
static int g2m_decode_frame(AVCodecContext *avctx, void *data, int *got_picture_ptr, AVPacket *avpkt)
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)
static void epic_hash_init(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 epic_free_pixel_cache(ePICPixHash *hash)
#define APPLY_ALPHA(src, new, alpha)
static av_cold int g2m_decode_init(AVCodecContext *avctx)
#define UPDATE_NEIGHBOURS(x)
static int jpg_decode_block(JPGContext *c, GetBitContext *gb, int plane, int16_t *block)
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)
static void yuv2rgb(uint8_t *out, int ridx, int Y, int U, int V)
static int epic_decode_tile(ePICContext *dc, uint8_t *out, int tile_height, int tile_width, int stride)
static int epic_predict_pixel2(ePICContext *dc, uint8_t *rung, uint32_t *pPix, uint32_t pix)
bitstream reader API header.
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
static int get_bits_left(GetBitContext *gb)
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int get_xbits(GetBitContext *s, int n)
Read MPEG-1 dc-style VLC (sign bit + mantissa with no MSB).
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
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...
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
av_cold void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
static const int16_t alpha[]
const uint8_t avpriv_mjpeg_val_dc[12]
const uint8_t avpriv_mjpeg_bits_ac_chrominance[17]
const uint8_t avpriv_mjpeg_val_ac_chrominance[]
const uint8_t avpriv_mjpeg_bits_dc_luminance[17]
const uint8_t avpriv_mjpeg_val_ac_luminance[]
const uint8_t avpriv_mjpeg_bits_dc_chrominance[17]
const uint8_t avpriv_mjpeg_bits_ac_luminance[17]
av_cold void ff_blockdsp_init(BlockDSPContext *c, AVCodecContext *avctx)
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
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.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define FF_PTR_ADD(ptr, off)
static const uint16_t mask[17]
const uint8_t ff_zigzag_direct[64]
MJPEG encoder and decoder.
int ff_mjpeg_build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table, int is_ac, void *logctx)
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
#define FF_ARRAY_ELEMS(a)
static const float pred[4]
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
int64_t max_pixels
The number of pixels per image to maximally accept.
int frame_number
Frame counter, set by libavcodec.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int key_frame
1 -> keyframe, 0-> not
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
enum AVPictureType pict_type
Picture type of the frame.
This structure stores compressed data.
uint8_t prev_row_rung[14]
uint8_t runlen_zeroes[14]
uint8_t ne_pred_rung[256]
ElsUnsignedRung unsigned_rung
uint32_t stack[EPIC_PIX_STACK_SIZE]
uint8_t nw_pred_rung[256]
struct ePICPixListElem * list
int bucket_size[EPIC_HASH_SIZE]
int bucket_fill[EPIC_HASH_SIZE]
ePICPixHashElem * bucket[EPIC_HASH_SIZE]
struct ePICPixListElem * next
#define avpriv_request_sample(...)
static int chunk_start(AVFormatContext *s)