115 0x01, 0x01, 0x11, 0x11, 0x55, 0x55, 0xff,
120 0xff, 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
125 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff
132 int bits_per_pixel,
int pass,
135 int x,
mask, dsp_mask, j, src_x,
b, bpp;
142 switch (bits_per_pixel) {
145 for (x = 0; x <
width; x++) {
147 if ((dsp_mask << j) & 0x80) {
148 b = (
src[src_x >> 3] >> (7 - (src_x & 7))) & 1;
149 dst[x >> 3] &= 0xFF7F>>j;
150 dst[x >> 3] |=
b << (7 - j);
152 if ((
mask << j) & 0x80)
158 for (x = 0; x <
width; x++) {
159 int j2 = 2 * (x & 3);
161 if ((dsp_mask << j) & 0x80) {
162 b = (
src[src_x >> 2] >> (6 - 2*(src_x & 3))) & 3;
163 dst[x >> 2] &= 0xFF3F>>j2;
164 dst[x >> 2] |=
b << (6 - j2);
166 if ((
mask << j) & 0x80)
172 for (x = 0; x <
width; x++) {
175 if ((dsp_mask << j) & 0x80) {
176 b = (
src[src_x >> 1] >> (4 - 4*(src_x & 1))) & 15;
177 dst[x >> 1] &= 0xFF0F>>j2;
178 dst[x >> 1] |=
b << (4 - j2);
180 if ((
mask << j) & 0x80)
185 bpp = bits_per_pixel >> 3;
188 for (x = 0; x <
width; x++) {
190 if ((dsp_mask << j) & 0x80) {
194 if ((
mask << j) & 0x80)
205 for (
i = 0;
i <
w;
i++) {
206 int a,
b,
c, p, pa, pb, pc;
219 if (pa <= pb && pa <= pc)
229 #define UNROLL1(bpp, op) \
238 for (; i <= size - bpp; i += bpp) { \
239 dst[i + 0] = r = op(r, src[i + 0], last[i + 0]); \
242 dst[i + 1] = g = op(g, src[i + 1], last[i + 1]); \
245 dst[i + 2] = b = op(b, src[i + 2], last[i + 2]); \
248 dst[i + 3] = a = op(a, src[i + 3], last[i + 3]); \
252 #define UNROLL_FILTER(op) \
255 } else if (bpp == 2) { \
257 } else if (bpp == 3) { \
259 } else if (bpp == 4) { \
262 for (; i < size; i++) { \
263 dst[i] = op(dst[i - bpp], src[i], last[i]); \
270 int i, p,
r,
g,
b,
a;
272 switch (filter_type) {
277 for (
i = 0;
i < bpp;
i++)
281 for (;
i <
size;
i += bpp) {
282 unsigned s = *(
int *)(
src +
i);
283 p = ((
s & 0x7f7f7f7f) + (p & 0x7f7f7f7f)) ^ ((
s ^ p) & 0x80808080);
284 *(
int *)(dst +
i) = p;
287 #define OP_SUB(x, s, l) ((x) + (s))
295 for (
i = 0;
i < bpp;
i++) {
299 #define OP_AVG(x, s, l) (((((x) + (l)) >> 1) + (s)) & 0xff)
303 for (
i = 0;
i < bpp;
i++) {
307 if (bpp > 2 &&
size > 4) {
324 #define YUV2RGB(NAME, TYPE) \
325 static void deloco_ ## NAME(TYPE *dst, int size, int alpha) \
328 for (i = 0; i < size - 2; i += 3 + alpha) { \
329 int g = dst [i + 1]; \
340 if (
s->interlace_type) {
343 return 100 - 100 *
s->y /
s->cur_h;
353 if (!
s->interlace_type) {
354 ptr = dst + dst_stride * (
s->y +
s->y_offset) +
355 (
s->subframe_packed ? 0 :
s->x_offset *
s->bpp);
357 last_row =
s->last_row;
359 last_row = ptr - dst_stride;
362 last_row,
s->row_size,
s->bpp);
365 if (
s->bit_depth == 16) {
366 deloco_rgb16((uint16_t *)(ptr - dst_stride),
s->row_size / 2,
369 deloco_rgb8(ptr - dst_stride,
s->row_size,
374 if (
s->y ==
s->cur_h) {
377 if (
s->bit_depth == 16) {
378 deloco_rgb16((uint16_t *)ptr,
s->row_size / 2,
381 deloco_rgb8(ptr,
s->row_size,
389 ptr = dst + dst_stride * (
s->y +
s->y_offset) +
s->x_offset *
s->bpp;
396 s->last_row,
s->pass_row_size,
s->bpp);
398 FFSWAP(
unsigned int,
s->last_row_size,
s->tmp_row_size);
403 s->color_type,
s->last_row);
406 if (
s->y ==
s->cur_h) {
407 memset(
s->last_row, 0,
s->row_size);
418 s->crow_size =
s->pass_row_size + 1;
419 if (
s->pass_row_size != 0)
431 uint8_t *dst, ptrdiff_t dst_stride)
435 s->zstream.next_in =
s->gb.buffer;
439 while (
s->zstream.avail_in > 0) {
440 ret =
inflate(&
s->zstream, Z_PARTIAL_FLUSH);
441 if (ret != Z_OK && ret != Z_STREAM_END) {
445 if (
s->zstream.avail_out == 0) {
449 s->zstream.avail_out =
s->crow_size;
450 s->zstream.next_out =
s->crow_buf;
452 if (ret == Z_STREAM_END &&
s->zstream.avail_in > 0) {
454 "%d undecompressed bytes left in buffer\n",
s->zstream.avail_in);
471 zstream.opaque =
NULL;
472 if (inflateInit(&zstream) != Z_OK)
474 zstream.next_in =
data;
475 zstream.avail_in = data_end -
data;
478 while (zstream.avail_in > 0) {
484 zstream.next_out = buf;
485 zstream.avail_out = buf_size - 1;
486 ret =
inflate(&zstream, Z_PARTIAL_FLUSH);
487 if (ret != Z_OK && ret != Z_STREAM_END) {
491 bp->len += zstream.next_out - buf;
492 if (ret == Z_STREAM_END)
495 inflateEnd(&zstream);
496 bp->str[bp->len] = 0;
500 inflateEnd(&zstream);
510 for (
i = 0;
i < size_in;
i++)
511 extra +=
in[
i] >= 0x80;
512 if (size_in == SIZE_MAX || extra > SIZE_MAX - size_in - 1)
517 for (
i = 0;
i < size_in;
i++) {
519 *(q++) = 0xC0 | (
in[
i] >> 6);
520 *(q++) = 0x80 | (
in[
i] & 0x3F);
535 const uint8_t *keyword_end = memchr(keyword, 0, data_end - keyword);
542 data = keyword_end + 1;
545 if (
data == data_end)
558 text_len = data_end - text;
565 if (!(kw_utf8 && txt_utf8)) {
592 s->width =
s->cur_w = bytestream2_get_be32(&
s->gb);
593 s->height =
s->cur_h = bytestream2_get_be32(&
s->gb);
595 s->cur_w =
s->cur_h =
s->width =
s->height = 0;
599 s->bit_depth = bytestream2_get_byte(&
s->gb);
600 if (
s->bit_depth != 1 &&
s->bit_depth != 2 &&
s->bit_depth != 4 &&
601 s->bit_depth != 8 &&
s->bit_depth != 16) {
605 s->color_type = bytestream2_get_byte(&
s->gb);
606 s->compression_type = bytestream2_get_byte(&
s->gb);
607 if (
s->compression_type) {
611 s->filter_type = bytestream2_get_byte(&
s->gb);
612 s->interlace_type = bytestream2_get_byte(&
s->gb);
617 "compression_type=%d filter_type=%d interlace_type=%d\n",
618 s->width,
s->height,
s->bit_depth,
s->color_type,
619 s->compression_type,
s->filter_type,
s->interlace_type);
623 s->cur_w =
s->cur_h =
s->width =
s->height = 0;
648 size_t byte_depth =
s->bit_depth > 8 ? 2 : 1;
663 s->bits_per_pixel =
s->bit_depth *
s->channels;
664 s->bpp = (
s->bits_per_pixel + 7) >> 3;
665 s->row_size = (
s->cur_w *
s->bits_per_pixel + 7) >> 3;
671 s->bits_per_pixel <= 4 && !
s->interlace_type;
673 if ((
s->bit_depth == 2 ||
s->bit_depth == 4 ||
s->bit_depth == 8) &&
676 }
else if ((
s->bit_depth == 2 ||
s->bit_depth == 4 ||
s->bit_depth == 8) &&
679 }
else if ((
s->bit_depth == 2 ||
s->bit_depth == 4 ||
s->bit_depth == 8) &&
682 }
else if (
s->bit_depth == 16 &&
685 }
else if (
s->bit_depth == 16 &&
688 }
else if (
s->bit_depth == 16 &&
691 }
else if ((
s->bits_per_pixel == 1 ||
s->bits_per_pixel == 2 ||
s->bits_per_pixel == 4 ||
s->bits_per_pixel == 8) &&
696 }
else if (
s->bit_depth == 8 &&
699 }
else if (
s->bit_depth == 16 &&
704 "Bit depth %d color type %d",
705 s->bit_depth,
s->color_type);
729 "and color type %d with TRNS",
730 s->bit_depth,
s->color_type);
734 s->bpp += byte_depth;
748 if (!
s->interlace_type) {
749 s->crow_size =
s->row_size + 1;
755 s->crow_size =
s->pass_row_size + 1;
757 ff_dlog(avctx,
"row_size=%d crow_size =%d\n",
758 s->row_size,
s->crow_size);
762 memcpy(p->
data[1],
s->palette, 256 *
sizeof(uint32_t));
767 if (
s->interlace_type ||
779 s->crow_buf =
s->buffer + 15;
780 s->zstream.avail_out =
s->crow_size;
781 s->zstream.next_out =
s->crow_buf;
788 s->bpp -= byte_depth;
793 s->bpp += byte_depth;
808 if ((length % 3) != 0 || length > 256 * 3)
812 for (
i = 0;
i < n;
i++) {
813 r = bytestream2_get_byte(&
s->gb);
814 g = bytestream2_get_byte(&
s->gb);
815 b = bytestream2_get_byte(&
s->gb);
816 s->palette[
i] = (0xFFU << 24) | (
r << 16) | (
g << 8) |
b;
819 s->palette[
i] = (0xFFU << 24);
842 if (length > 256 || !(
s->hdr_state &
PNG_PLTE))
845 for (
i = 0;
i < length;
i++) {
846 unsigned v = bytestream2_get_byte(&
s->gb);
847 s->palette[
i] = (
s->palette[
i] & 0x00ffffff) | (v << 24);
855 for (
i = 0;
i < length / 2;
i++) {
859 if (
s->bit_depth > 8)
860 AV_WB16(&
s->transparent_color_be[2 *
i], v);
862 s->transparent_color_be[
i] = v;
879 while ((
s->iccp_name[cnt++] = bytestream2_get_byte(&
s->gb)) && cnt < 81);
886 length =
FFMAX(length - cnt, 0);
888 if (bytestream2_get_byte(&
s->gb) != 0) {
894 length =
FFMAX(length - 1, 0);
896 if ((ret =
decode_zbuf(&bp,
s->gb.buffer,
s->gb.buffer + length)) < 0)
903 s->iccp_data_len = bp.len;
921 for (k = 7; k >= 1; k--)
923 pd[8*
i + k - 1] = (pd[
i]>>8-k) & 1;
924 for (
i--;
i >= 0;
i--) {
925 pd[8*
i + 7]= pd[
i] & 1;
926 pd[8*
i + 6]= (pd[
i]>>1) & 1;
927 pd[8*
i + 5]= (pd[
i]>>2) & 1;
928 pd[8*
i + 4]= (pd[
i]>>3) & 1;
929 pd[8*
i + 3]= (pd[
i]>>4) & 1;
930 pd[8*
i + 2]= (pd[
i]>>5) & 1;
931 pd[8*
i + 1]= (pd[
i]>>6) & 1;
932 pd[8*
i + 0]= pd[
i]>>7;
934 }
else if (
s->bits_per_pixel == 2) {
939 if ((
width&3) >= 3) pd[4*
i + 2]= (pd[
i] >> 2) & 3;
940 if ((
width&3) >= 2) pd[4*
i + 1]= (pd[
i] >> 4) & 3;
941 if ((
width&3) >= 1) pd[4*
i + 0]= pd[
i] >> 6;
942 for (
i--;
i >= 0;
i--) {
943 pd[4*
i + 3]= pd[
i] & 3;
944 pd[4*
i + 2]= (pd[
i]>>2) & 3;
945 pd[4*
i + 1]= (pd[
i]>>4) & 3;
946 pd[4*
i + 0]= pd[
i]>>6;
949 if ((
width&3) >= 3) pd[4*
i + 2]= ((pd[
i]>>2) & 3)*0x55;
950 if ((
width&3) >= 2) pd[4*
i + 1]= ((pd[
i]>>4) & 3)*0x55;
951 if ((
width&3) >= 1) pd[4*
i + 0]= ( pd[
i]>>6 )*0x55;
952 for (
i--;
i >= 0;
i--) {
953 pd[4*
i + 3]= ( pd[
i] & 3)*0x55;
954 pd[4*
i + 2]= ((pd[
i]>>2) & 3)*0x55;
955 pd[4*
i + 1]= ((pd[
i]>>4) & 3)*0x55;
956 pd[4*
i + 0]= ( pd[
i]>>6 )*0x55;
959 }
else if (
s->bits_per_pixel == 4) {
964 if (
width&1) pd[2*
i+0]= pd[
i]>>4;
965 for (
i--;
i >= 0;
i--) {
966 pd[2*
i + 1] = pd[
i] & 15;
967 pd[2*
i + 0] = pd[
i] >> 4;
970 if (
width & 1) pd[2*
i + 0]= (pd[
i] >> 4) * 0x11;
971 for (
i--;
i >= 0;
i--) {
972 pd[2*
i + 1] = (pd[
i] & 15) * 0x11;
973 pd[2*
i + 0] = (pd[
i] >> 4) * 0x11;
983 for (
int j = 0; j <
s->height; j++) {
996 const int bpp =
s->channels;
999 for (
int j = 0; j <
s->cur_h; j++) {
1002 memmove(pd +
s->x_offset * bpp, pd,
s->cur_w * bpp);
1010 uint32_t sequence_number;
1011 int cur_w, cur_h, x_offset, y_offset, dispose_op, blend_op;
1026 s->last_w =
s->cur_w;
1027 s->last_h =
s->cur_h;
1028 s->last_x_offset =
s->x_offset;
1029 s->last_y_offset =
s->y_offset;
1030 s->last_dispose_op =
s->dispose_op;
1032 sequence_number = bytestream2_get_be32(&
s->gb);
1033 cur_w = bytestream2_get_be32(&
s->gb);
1034 cur_h = bytestream2_get_be32(&
s->gb);
1035 x_offset = bytestream2_get_be32(&
s->gb);
1036 y_offset = bytestream2_get_be32(&
s->gb);
1038 dispose_op = bytestream2_get_byte(&
s->gb);
1039 blend_op = bytestream2_get_byte(&
s->gb);
1042 if (sequence_number == 0 &&
1043 (cur_w !=
s->width ||
1044 cur_h !=
s->height ||
1047 cur_w <= 0 || cur_h <= 0 ||
1048 x_offset < 0 || y_offset < 0 ||
1049 cur_w >
s->width - x_offset|| cur_h >
s->height - y_offset)
1057 if ((sequence_number == 0 || !
s->last_picture.f) &&
1078 s->x_offset = x_offset;
1079 s->y_offset = y_offset;
1080 s->dispose_op = dispose_op;
1081 s->blend_op = blend_op;
1090 uint8_t *pd_last =
s->last_picture.f->data[0];
1094 for (j = 0; j <
s->height; j++) {
1095 for (
i = 0;
i < ls;
i++)
1096 pd[
i] += pd_last[
i];
1098 pd_last +=
s->last_picture.f->linesize[0];
1104 #define FAST_DIV255(x) ((((x) + 128) * 257) >> 16)
1110 ptrdiff_t dst_stride = p->
linesize[0];
1112 ptrdiff_t src_stride =
s->last_picture.f->linesize[0];
1131 if (!
s->background_buf)
1134 memcpy(
s->background_buf,
src, src_stride * p->
height);
1136 for (y =
s->last_y_offset; y < s->last_y_offset +
s->last_h; y++) {
1137 memset(
s->background_buf + src_stride * y +
1138 s->bpp *
s->last_x_offset, 0,
s->bpp *
s->last_w);
1141 src =
s->background_buf;
1145 for (y = 0; y <
s->y_offset; y++)
1146 memcpy(dst + y * dst_stride,
src + y * src_stride, p->
width *
s->bpp);
1147 for (y =
s->y_offset; y < s->y_offset +
s->cur_h; y++) {
1148 memcpy(dst + y * dst_stride,
src + y * src_stride,
s->x_offset *
s->bpp);
1149 memcpy(dst + y * dst_stride + (
s->x_offset +
s->cur_w) *
s->bpp,
1150 src + y * src_stride + (
s->x_offset +
s->cur_w) *
s->bpp,
1151 (p->
width -
s->cur_w -
s->x_offset) *
s->bpp);
1153 for (y =
s->y_offset +
s->cur_h; y < p->
height; y++)
1154 memcpy(dst + y * dst_stride,
src + y * src_stride, p->
width *
s->bpp);
1158 for (y =
s->y_offset; y < s->y_offset +
s->cur_h; ++y) {
1159 uint8_t *foreground = dst + dst_stride * y +
s->bpp *
s->x_offset;
1160 const uint8_t *background =
src + src_stride * y +
s->bpp *
s->x_offset;
1161 for (x =
s->x_offset; x < s->x_offset +
s->cur_w; ++x, foreground +=
s->bpp, background +=
s->bpp) {
1163 uint8_t foreground_alpha, background_alpha, output_alpha;
1172 foreground_alpha = foreground[3];
1173 background_alpha = background[3];
1177 foreground_alpha = foreground[1];
1178 background_alpha = background[1];
1182 foreground_alpha =
s->palette[foreground[0]] >> 24;
1183 background_alpha =
s->palette[background[0]] >> 24;
1187 if (foreground_alpha == 255)
1190 if (foreground_alpha == 0) {
1191 memcpy(foreground, background,
s->bpp);
1201 output_alpha = foreground_alpha +
FAST_DIV255((255 - foreground_alpha) * background_alpha);
1205 for (
b = 0;
b <
s->bpp - 1; ++
b) {
1206 if (output_alpha == 0) {
1208 }
else if (background_alpha == 255) {
1209 output[
b] =
FAST_DIV255(foreground_alpha * foreground[
b] + (255 - foreground_alpha) * background[
b]);
1211 output[
b] = (255 * foreground_alpha * foreground[
b] + (255 - foreground_alpha) * background_alpha * background[
b]) / (255 * output_alpha);
1214 output[
b] = output_alpha;
1215 memcpy(foreground, output,
s->bpp);
1227 uint32_t
tag, length;
1228 int decode_next_dat = 0;
1254 length = bytestream2_get_be32(&
s->gb);
1261 uint32_t crc_sig =
AV_RB32(
s->gb.buffer + length + 4);
1262 uint32_t crc_cal = ~
av_crc(crc_tab, UINT32_MAX,
s->gb.buffer, length + 4);
1263 if (crc_sig ^ crc_cal) {
1275 tag = bytestream2_get_le32(&
s->gb);
1283 case MKTAG(
'I',
'H',
'D',
'R'):
1284 case MKTAG(
'p',
'H',
'Y',
's'):
1285 case MKTAG(
't',
'E',
'X',
't'):
1286 case MKTAG(
'I',
'D',
'A',
'T'):
1287 case MKTAG(
't',
'R',
'N',
'S'):
1295 case MKTAG(
'I',
'H',
'D',
'R'):
1299 case MKTAG(
'p',
'H',
'Y',
's'):
1303 case MKTAG(
'f',
'c',
'T',
'L'):
1308 decode_next_dat = 1;
1310 case MKTAG(
'f',
'd',
'A',
'T'):
1313 if (!decode_next_dat || length < 4) {
1317 bytestream2_get_be32(&
s->gb);
1320 case MKTAG(
'I',
'D',
'A',
'T'):
1326 case MKTAG(
'P',
'L',
'T',
'E'):
1330 case MKTAG(
't',
'R',
'N',
'S'):
1334 case MKTAG(
't',
'E',
'X',
't'):
1339 case MKTAG(
'z',
'T',
'X',
't'):
1344 case MKTAG(
's',
'T',
'E',
'R'): {
1345 int mode = bytestream2_get_byte(&
s->gb);
1348 s->stereo_mode =
mode;
1351 "Unknown value in sTER chunk (%d)\n",
mode);
1356 case MKTAG(
'i',
'C',
'C',
'P'): {
1361 case MKTAG(
'c',
'H',
'R',
'M'): {
1364 s->white_point[0] = bytestream2_get_be32(&
s->gb);
1365 s->white_point[1] = bytestream2_get_be32(&
s->gb);
1368 for (
i = 0;
i < 3;
i++) {
1369 s->display_primaries[
i][0] = bytestream2_get_be32(&
s->gb);
1370 s->display_primaries[
i][1] = bytestream2_get_be32(&
s->gb);
1376 case MKTAG(
'g',
'A',
'M',
'A'): {
1379 int num = bytestream2_get_be32(&
s->gb);
1392 case MKTAG(
'I',
'E',
'N',
'D'):
1421 if (
s->bits_per_pixel <= 4) {
1430 size_t byte_depth =
s->bit_depth > 8 ? 2 : 1;
1431 size_t raw_bpp =
s->bpp - byte_depth;
1436 for (y = 0; y <
s->height; ++y) {
1439 if (
s->bpp == 2 && byte_depth == 1) {
1441 uint8_t *rowp = &row[1 *
s->width - 1];
1442 int tcolor =
s->transparent_color_be[0];
1443 for (x =
s->width; x > 0; --x) {
1444 *
pixel-- = *rowp == tcolor ? 0 : 0xff;
1447 }
else if (
s->bpp == 4 && byte_depth == 1) {
1449 uint8_t *rowp = &row[3 *
s->width - 1];
1450 int tcolor =
AV_RL24(
s->transparent_color_be);
1451 for (x =
s->width; x > 0; --x) {
1459 for (x =
s->width; x > 0; --x) {
1461 memmove(
pixel, &row[raw_bpp * (x - 1)], raw_bpp);
1463 if (!memcmp(
pixel,
s->transparent_color_be, raw_bpp)) {
1464 memset(&
pixel[raw_bpp], 0, byte_depth);
1466 memset(&
pixel[raw_bpp], 0xff, byte_depth);
1474 if (
s->last_picture.f->data[0]) {
1476 &&
s->last_picture.f->width == p->
width
1477 &&
s->last_picture.f->height== p->
height
1478 &&
s->last_picture.f->format== p->
format
1500 s->iccp_data_len = 0;
1501 s->iccp_name[0] = 0;
1503 s->stereo_mode = -1;
1525 memcpy(sd->
data,
s->iccp_data,
s->iccp_data_len);
1530 if (
s->stereo_mode >= 0) {
1552 for (
int i = 0;
i < 3;
i++) {
1568 #if CONFIG_PNG_DECODER
1570 void *
data,
int *got_frame,
1575 int buf_size = avpkt->
size;
1586 sig = bytestream2_get_be64(&
s->gb);
1593 s->y =
s->has_trns = 0;
1600 s->zstream.opaque =
NULL;
1601 ret = inflateInit(&
s->zstream);
1629 inflateEnd(&
s->zstream);
1635 #if CONFIG_APNG_DECODER
1637 void *
data,
int *got_frame,
1661 if ((ret = inflateInit(&
s->zstream)) != Z_OK) {
1696 inflateEnd(&
s->zstream);
1739 if (src_frame && src_frame->
f->
data[0]) {
1758 if (!
s->last_picture.f || !
s->picture.f) {
1780 s->last_row_size = 0;
1782 s->tmp_row_size = 0;
1791 #if CONFIG_APNG_DECODER
1800 .
decode = decode_frame_apng,
1808 #if CONFIG_PNG_DECODER
1817 .
decode = decode_frame_png,
@ APNG_DISPOSE_OP_BACKGROUND
@ APNG_DISPOSE_OP_PREVIOUS
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
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define FF_DEBUG_STARTCODE
#define FF_THREAD_FRAME
Decode more than one frame at once.
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
#define AV_EF_IGNORE_ERR
ignore errors and continue
#define FF_DEBUG_PICT_INFO
#define AV_EF_EXPLODE
abort decoding on minor error detection
#define FF_COMPLIANCE_NORMAL
static av_cold int init(AVCodecContext *avctx)
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
void av_bprint_get_buffer(AVBPrint *buf, unsigned size, unsigned char **mem, unsigned *actual_size)
Allocate bytes in the buffer for external use.
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
#define AV_BPRINT_SIZE_UNLIMITED
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 FFSWAP(type, a, b)
#define MKTAG(a, b, c, d)
#define CONFIG_PNG_DECODER
#define CONFIG_APNG_DECODER
Public header for CRC hash function implementation.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
mode
Use these values in ebur128_init (or'ed).
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
@ AVDISCARD_ALL
discard all
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_padded_malloc except that buffer will always be 0-initialized after call.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define AV_DICT_DONT_STRDUP_KEY
Take ownership of a key that's been allocated with av_malloc() or another memory allocation function.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, buffer_size_t size)
Add a new side data to a frame.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
@ AV_FRAME_DATA_ICC_PROFILE
The data contains an ICC profile as an opaque octet buffer following the format described by ISO 1507...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static AVRational av_make_q(int num, int den)
Create an AVRational.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
#define av_fourcc2str(fourcc)
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
int av_image_get_linesize(enum AVPixelFormat pix_fmt, int width, int plane)
Compute the size of an image line with format pix_fmt and width width for the plane plane.
@ AV_PICTURE_TYPE_I
Intra.
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
AVStereo3D * av_stereo3d_create_side_data(AVFrame *frame)
Allocate a complete AVFrameSideData and add it to the frame.
@ AV_STEREO3D_SIDEBYSIDE
Views are next to each other.
static int skip_tag(AVIOContext *in, int32_t tag_name)
#define FF_CODEC_CAP_ALLOCATE_PROGRESS
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters even if the frame is skipped due to the skip_frame sett...
#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.
int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
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 ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
static const uint16_t mask[17]
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
@ AVCOL_RANGE_JPEG
Full range content.
@ AV_PIX_FMT_GRAY16BE
Y , 16bpp, big-endian.
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
@ AV_PIX_FMT_YA16BE
16 bits gray, 16 bits alpha (big-endian)
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
@ AV_PIX_FMT_GRAY8A
alias for AV_PIX_FMT_YA8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_RGB48BE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
@ AV_PIX_FMT_RGBA64BE
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
const uint8_t ff_png_pass_ymask[NB_PASSES]
int ff_png_pass_row_size(int pass, int bits_per_pixel, int width)
int ff_png_get_nb_channels(int color_type)
void * ff_png_zalloc(void *opaque, unsigned int items, unsigned int size)
void ff_png_zfree(void *opaque, void *ptr)
#define PNG_COLOR_TYPE_RGB
#define PNG_COLOR_TYPE_RGB_ALPHA
#define PNG_COLOR_TYPE_GRAY_ALPHA
#define PNG_FILTER_VALUE_AVG
#define PNG_FILTER_VALUE_UP
#define PNG_COLOR_TYPE_GRAY
#define PNG_COLOR_TYPE_PALETTE
#define PNG_FILTER_VALUE_PAETH
#define PNG_FILTER_VALUE_NONE
#define PNG_FILTER_TYPE_LOCO
#define PNG_FILTER_VALUE_SUB
static int decode_ihdr_chunk(AVCodecContext *avctx, PNGDecContext *s, uint32_t length)
static void handle_small_bpp(PNGDecContext *s, AVFrame *p)
static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s, AVFrame *p, const AVPacket *avpkt)
#define UNROLL_FILTER(op)
static int decode_zbuf(AVBPrint *bp, const uint8_t *data, const uint8_t *data_end)
static const uint8_t png_pass_mask[NB_PASSES]
void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
static void unpack_small_row(PNGDecContext *s, uint8_t *pd, int width)
static int output_frame(PNGDecContext *s, AVFrame *f, const AVFrame *src)
static int decode_fctl_chunk(AVCodecContext *avctx, PNGDecContext *s, uint32_t length)
static int decode_text_chunk(PNGDecContext *s, uint32_t length, int compressed)
static uint8_t * iso88591_to_utf8(const uint8_t *in, size_t size_in)
static av_cold int png_dec_end(AVCodecContext *avctx)
void ff_png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type, uint8_t *src, uint8_t *last, int size, int bpp)
static void png_handle_row(PNGDecContext *s, uint8_t *dst, ptrdiff_t dst_stride)
static const uint8_t png_pass_dsp_ymask[NB_PASSES]
static int decode_phys_chunk(AVCodecContext *avctx, PNGDecContext *s)
static void png_put_interlaced_row(uint8_t *dst, int width, int bits_per_pixel, int pass, int color_type, const uint8_t *src)
static av_cold int png_dec_init(AVCodecContext *avctx)
static void handle_p_frame_png(PNGDecContext *s, AVFrame *p)
static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, uint32_t length, AVFrame *p)
static int decode_trns_chunk(AVCodecContext *avctx, PNGDecContext *s, uint32_t length)
static int percent_missing(PNGDecContext *s)
static void clear_frame_metadata(PNGDecContext *s)
static void handle_small_bpp_apng(PNGDecContext *s, AVFrame *p)
#define YUV2RGB(NAME, TYPE)
static int png_decode_idat(PNGDecContext *s, int length, uint8_t *dst, ptrdiff_t dst_stride)
static const uint8_t png_pass_dsp_mask[NB_PASSES]
static int decode_plte_chunk(AVCodecContext *avctx, PNGDecContext *s, uint32_t length)
static int decode_iccp_chunk(PNGDecContext *s, int length)
static int handle_p_frame_apng(AVCodecContext *avctx, PNGDecContext *s, AVFrame *p)
av_cold void ff_pngdsp_init(PNGDSPContext *dsp)
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
FF_ENABLE_DEPRECATION_WARNINGS int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
void ff_thread_await_progress(ThreadFrame *f, int n, int field)
Wait for earlier decoding threads to finish reference pictures.
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
int active_thread_type
Which multithreading methods are in use by the codec.
int discard_damaged_percentage
The percentage of damaged samples to discard a frame.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
enum AVDiscard skip_frame
Skip decoding for selected frames.
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
const char * name
Name of the codec implementation.
Structure to hold side data for an AVFrame.
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 interlaced_frame
The content of the picture is interlaced.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
enum AVPictureType pict_type
Picture type of the frame.
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
Rational number (pair of numerator and denominator).
Stereo 3D type: this structure describes how two videos are packed within a single video surface,...
enum AVStereo3DType type
How views are packed within the video.
int flags
Additional information about the frame packing.
void(* add_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
void(* add_bytes_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
AVDictionary * frame_metadata
unsigned background_buf_allocated
uint8_t transparent_color_be[6]
unsigned int tmp_row_size
enum PNGImageState pic_state
uint32_t display_primaries[3][2]
enum PNGHeaderState hdr_state
unsigned int last_row_size
#define avpriv_request_sample(...)
static void error(const char *err)
static void inflate(uint8_t *dst, const uint8_t *p1, int width, int threshold, const uint8_t *coordinates[], int coord, int maxc)