Go to the documentation of this file.
24 #include "config_components.h"
117 0x01, 0x01, 0x11, 0x11, 0x55, 0x55, 0xff,
122 0xff, 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
127 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff
134 int bits_per_pixel,
int pass,
135 int color_type,
const uint8_t *
src)
137 int x,
mask, dsp_mask, j, src_x,
b, bpp;
144 switch (bits_per_pixel) {
147 for (x = 0; x <
width; x++) {
149 if ((dsp_mask << j) & 0x80) {
150 b = (
src[src_x >> 3] >> (7 - (src_x & 7))) & 1;
151 dst[x >> 3] &= 0xFF7F>>j;
152 dst[x >> 3] |=
b << (7 - j);
154 if ((
mask << j) & 0x80)
160 for (x = 0; x <
width; x++) {
161 int j2 = 2 * (x & 3);
163 if ((dsp_mask << j) & 0x80) {
164 b = (
src[src_x >> 2] >> (6 - 2*(src_x & 3))) & 3;
165 dst[x >> 2] &= 0xFF3F>>j2;
166 dst[x >> 2] |=
b << (6 - j2);
168 if ((
mask << j) & 0x80)
174 for (x = 0; x <
width; x++) {
177 if ((dsp_mask << j) & 0x80) {
178 b = (
src[src_x >> 1] >> (4 - 4*(src_x & 1))) & 15;
179 dst[x >> 1] &= 0xFF0F>>j2;
180 dst[x >> 1] |=
b << (4 - j2);
182 if ((
mask << j) & 0x80)
187 bpp = bits_per_pixel >> 3;
190 for (x = 0; x <
width; x++) {
192 if ((dsp_mask << j) & 0x80) {
196 if ((
mask << j) & 0x80)
207 for (
i = 0;
i <
w;
i++) {
208 int a,
b,
c, p, pa, pb, pc;
221 if (pa <= pb && pa <= pc)
231 #define UNROLL1(bpp, op) \
240 for (; i <= size - bpp; i += bpp) { \
241 dst[i + 0] = r = op(r, src[i + 0], last[i + 0]); \
244 dst[i + 1] = g = op(g, src[i + 1], last[i + 1]); \
247 dst[i + 2] = b = op(b, src[i + 2], last[i + 2]); \
250 dst[i + 3] = a = op(a, src[i + 3], last[i + 3]); \
254 #define UNROLL_FILTER(op) \
257 } else if (bpp == 2) { \
259 } else if (bpp == 3) { \
261 } else if (bpp == 4) { \
264 for (; i < size; i++) { \
265 dst[i] = op(dst[i - bpp], src[i], last[i]); \
270 uint8_t *
src, uint8_t *last,
int size,
int bpp)
272 int i, p,
r,
g,
b,
a;
274 switch (filter_type) {
279 for (
i = 0;
i < bpp;
i++)
283 for (;
i <
size;
i += bpp) {
284 unsigned s = *(
int *)(
src +
i);
285 p = ((
s & 0x7f7f7f7f) + (p & 0x7f7f7f7f)) ^ ((
s ^ p) & 0x80808080);
286 *(
int *)(dst +
i) = p;
289 #define OP_SUB(x, s, l) ((x) + (s))
297 for (
i = 0;
i < bpp;
i++) {
301 #define OP_AVG(x, s, l) (((((x) + (l)) >> 1) + (s)) & 0xff)
305 for (
i = 0;
i < bpp;
i++) {
309 if (bpp > 2 &&
size > 4) {
326 #define YUV2RGB(NAME, TYPE) \
327 static void deloco_ ## NAME(TYPE *dst, int size, int alpha) \
330 for (i = 0; i < size; i += 3 + alpha) { \
331 int g = dst [i + 1]; \
342 if (
s->interlace_type) {
345 return 100 - 100 *
s->y /
s->cur_h;
352 uint8_t *ptr, *last_row;
355 if (!
s->interlace_type) {
356 ptr = dst + dst_stride * (
s->y +
s->y_offset) +
s->x_offset *
s->bpp;
358 last_row =
s->last_row;
360 last_row = ptr - dst_stride;
363 last_row,
s->row_size,
s->bpp);
366 if (
s->bit_depth == 16) {
367 deloco_rgb16((uint16_t *)(ptr - dst_stride),
s->row_size / 2,
370 deloco_rgb8(ptr - dst_stride,
s->row_size,
375 if (
s->y ==
s->cur_h) {
378 if (
s->bit_depth == 16) {
379 deloco_rgb16((uint16_t *)ptr,
s->row_size / 2,
382 deloco_rgb8(ptr,
s->row_size,
390 ptr = dst + dst_stride * (
s->y +
s->y_offset) +
s->x_offset *
s->bpp;
397 s->last_row,
s->pass_row_size,
s->bpp);
398 FFSWAP(uint8_t *,
s->last_row,
s->tmp_row);
399 FFSWAP(
unsigned int,
s->last_row_size,
s->tmp_row_size);
404 s->color_type,
s->last_row);
407 if (
s->y ==
s->cur_h) {
408 memset(
s->last_row, 0,
s->row_size);
419 s->crow_size =
s->pass_row_size + 1;
420 if (
s->pass_row_size != 0)
432 uint8_t *dst, ptrdiff_t dst_stride)
434 z_stream *
const zstream = &
s->zstream.zstream;
437 zstream->next_in = gb->
buffer;
440 while (zstream->avail_in > 0) {
442 if (
ret != Z_OK &&
ret != Z_STREAM_END) {
446 if (zstream->avail_out == 0) {
450 zstream->avail_out =
s->crow_size;
451 zstream->next_out =
s->crow_buf;
453 if (
ret == Z_STREAM_END && zstream->avail_in > 0) {
455 "%d undecompressed bytes left in buffer\n", zstream->avail_in);
463 const uint8_t *data_end,
void *logctx)
466 z_stream *
const zstream = &z.
zstream;
473 zstream->next_in =
data;
474 zstream->avail_in = data_end -
data;
477 while (zstream->avail_in > 0) {
483 zstream->next_out = buf;
484 zstream->avail_out = buf_size - 1;
486 if (
ret != Z_OK &&
ret != Z_STREAM_END) {
490 bp->len += zstream->next_out - buf;
491 if (
ret == Z_STREAM_END)
495 bp->str[bp->len] = 0;
509 for (
i = 0;
i < size_in;
i++)
510 extra += in[
i] >= 0x80;
511 if (size_in == SIZE_MAX || extra > SIZE_MAX - size_in - 1)
516 for (
i = 0;
i < size_in;
i++) {
518 *(q++) = 0xC0 | (in[
i] >> 6);
519 *(q++) = 0x80 | (in[
i] & 0x3F);
533 const uint8_t *keyword =
data;
534 const uint8_t *keyword_end = memchr(keyword, 0, data_end - keyword);
535 uint8_t *kw_utf8 =
NULL, *text, *txt_utf8 =
NULL;
541 data = keyword_end + 1;
544 if (
data == data_end)
556 text = (uint8_t *)
data;
557 text_len = data_end - text;
564 if (!(kw_utf8 && txt_utf8)) {
591 s->width =
s->cur_w = bytestream2_get_be32(gb);
592 s->height =
s->cur_h = bytestream2_get_be32(gb);
594 s->cur_w =
s->cur_h =
s->width =
s->height = 0;
598 s->bit_depth = bytestream2_get_byte(gb);
599 if (
s->bit_depth != 1 &&
s->bit_depth != 2 &&
s->bit_depth != 4 &&
600 s->bit_depth != 8 &&
s->bit_depth != 16) {
604 s->color_type = bytestream2_get_byte(gb);
605 s->compression_type = bytestream2_get_byte(gb);
606 if (
s->compression_type) {
610 s->filter_type = bytestream2_get_byte(gb);
611 s->interlace_type = bytestream2_get_byte(gb);
615 "compression_type=%d filter_type=%d interlace_type=%d\n",
616 s->width,
s->height,
s->bit_depth,
s->color_type,
617 s->compression_type,
s->filter_type,
s->interlace_type);
621 s->cur_w =
s->cur_h =
s->width =
s->height = 0;
646 size_t byte_depth =
s->bit_depth > 8 ? 2 : 1;
659 s->bits_per_pixel =
s->bit_depth *
s->channels;
660 s->bpp = (
s->bits_per_pixel + 7) >> 3;
661 s->row_size = (
s->cur_w *
s->bits_per_pixel + 7) >> 3;
663 if ((
s->bit_depth == 2 ||
s->bit_depth == 4 ||
s->bit_depth == 8) &&
666 }
else if ((
s->bit_depth == 2 ||
s->bit_depth == 4 ||
s->bit_depth == 8) &&
669 }
else if ((
s->bit_depth == 2 ||
s->bit_depth == 4 ||
s->bit_depth == 8) &&
672 }
else if (
s->bit_depth == 16 &&
675 }
else if (
s->bit_depth == 16 &&
678 }
else if (
s->bit_depth == 16 &&
681 }
else if ((
s->bits_per_pixel == 1 ||
s->bits_per_pixel == 2 ||
s->bits_per_pixel == 4 ||
s->bits_per_pixel == 8) &&
686 }
else if (
s->bit_depth == 8 &&
689 }
else if (
s->bit_depth == 16 &&
694 "Bit depth %d color type %d",
695 s->bit_depth,
s->color_type);
719 "and color type %d with TRNS",
720 s->bit_depth,
s->color_type);
724 s->bpp += byte_depth;
739 if (!
s->interlace_type) {
740 s->crow_size =
s->row_size + 1;
746 s->crow_size =
s->pass_row_size + 1;
748 ff_dlog(avctx,
"row_size=%d crow_size =%d\n",
749 s->row_size,
s->crow_size);
753 memcpy(p->
data[1],
s->palette, 256 *
sizeof(uint32_t));
758 if (
s->interlace_type ||
770 s->crow_buf =
s->buffer + 15;
771 s->zstream.zstream.avail_out =
s->crow_size;
772 s->zstream.zstream.next_out =
s->crow_buf;
779 s->bpp -= byte_depth;
784 s->bpp += byte_depth;
798 if ((length % 3) != 0 || length > 256 * 3)
802 for (
i = 0;
i < n;
i++) {
803 r = bytestream2_get_byte(gb);
804 g = bytestream2_get_byte(gb);
805 b = bytestream2_get_byte(gb);
806 s->palette[
i] = (0xFF
U << 24) | (
r << 16) | (
g << 8) |
b;
809 s->palette[
i] = (0xFFU << 24);
832 if (length > 256 || !(
s->hdr_state &
PNG_PLTE))
835 for (
i = 0;
i < length;
i++) {
836 unsigned v = bytestream2_get_byte(gb);
837 s->palette[
i] = (
s->palette[
i] & 0x00ffffff) | (v << 24);
845 for (
i = 0;
i < length / 2;
i++) {
849 if (
s->bit_depth > 8)
850 AV_WB16(&
s->transparent_color_be[2 *
i], v);
852 s->transparent_color_be[
i] = v;
868 while ((
s->iccp_name[cnt++] = bytestream2_get_byte(gb)) && cnt < 81);
875 if (bytestream2_get_byte(gb) != 0) {
888 s->iccp_data_len = bp.len;
900 uint8_t *pd = p->
data[0];
901 for (j = 0; j <
s->height; j++) {
903 for (k = 7; k >= 1; k--)
904 if ((
s->width&7) >= k)
905 pd[8*
i + k - 1] = (pd[
i]>>8-k) & 1;
906 for (
i--;
i >= 0;
i--) {
907 pd[8*
i + 7]= pd[
i] & 1;
908 pd[8*
i + 6]= (pd[
i]>>1) & 1;
909 pd[8*
i + 5]= (pd[
i]>>2) & 1;
910 pd[8*
i + 4]= (pd[
i]>>3) & 1;
911 pd[8*
i + 3]= (pd[
i]>>4) & 1;
912 pd[8*
i + 2]= (pd[
i]>>5) & 1;
913 pd[8*
i + 1]= (pd[
i]>>6) & 1;
914 pd[8*
i + 0]= pd[
i]>>7;
918 }
else if (
s->bits_per_pixel == 2) {
920 uint8_t *pd = p->
data[0];
921 for (j = 0; j <
s->height; j++) {
924 if ((
s->width&3) >= 3) pd[4*
i + 2]= (pd[
i] >> 2) & 3;
925 if ((
s->width&3) >= 2) pd[4*
i + 1]= (pd[
i] >> 4) & 3;
926 if ((
s->width&3) >= 1) pd[4*
i + 0]= pd[
i] >> 6;
927 for (
i--;
i >= 0;
i--) {
928 pd[4*
i + 3]= pd[
i] & 3;
929 pd[4*
i + 2]= (pd[
i]>>2) & 3;
930 pd[4*
i + 1]= (pd[
i]>>4) & 3;
931 pd[4*
i + 0]= pd[
i]>>6;
934 if ((
s->width&3) >= 3) pd[4*
i + 2]= ((pd[
i]>>2) & 3)*0x55;
935 if ((
s->width&3) >= 2) pd[4*
i + 1]= ((pd[
i]>>4) & 3)*0x55;
936 if ((
s->width&3) >= 1) pd[4*
i + 0]= ( pd[
i]>>6 )*0x55;
937 for (
i--;
i >= 0;
i--) {
938 pd[4*
i + 3]= ( pd[
i] & 3)*0x55;
939 pd[4*
i + 2]= ((pd[
i]>>2) & 3)*0x55;
940 pd[4*
i + 1]= ((pd[
i]>>4) & 3)*0x55;
941 pd[4*
i + 0]= ( pd[
i]>>6 )*0x55;
946 }
else if (
s->bits_per_pixel == 4) {
948 uint8_t *pd = p->
data[0];
949 for (j = 0; j <
s->height; j++) {
952 if (
s->width&1) pd[2*
i+0]= pd[
i]>>4;
953 for (
i--;
i >= 0;
i--) {
954 pd[2*
i + 1] = pd[
i] & 15;
955 pd[2*
i + 0] = pd[
i] >> 4;
958 if (
s->width & 1) pd[2*
i + 0]= (pd[
i] >> 4) * 0x11;
959 for (
i--;
i >= 0;
i--) {
960 pd[2*
i + 1] = (pd[
i] & 15) * 0x11;
961 pd[2*
i + 0] = (pd[
i] >> 4) * 0x11;
972 uint32_t sequence_number;
973 int cur_w, cur_h, x_offset, y_offset, dispose_op, blend_op;
988 s->last_w =
s->cur_w;
989 s->last_h =
s->cur_h;
990 s->last_x_offset =
s->x_offset;
991 s->last_y_offset =
s->y_offset;
992 s->last_dispose_op =
s->dispose_op;
994 sequence_number = bytestream2_get_be32(gb);
995 cur_w = bytestream2_get_be32(gb);
996 cur_h = bytestream2_get_be32(gb);
997 x_offset = bytestream2_get_be32(gb);
998 y_offset = bytestream2_get_be32(gb);
1000 dispose_op = bytestream2_get_byte(gb);
1001 blend_op = bytestream2_get_byte(gb);
1003 if (sequence_number == 0 &&
1004 (cur_w !=
s->width ||
1005 cur_h !=
s->height ||
1008 cur_w <= 0 || cur_h <= 0 ||
1009 x_offset < 0 || y_offset < 0 ||
1010 cur_w >
s->width - x_offset|| cur_h >
s->height - y_offset)
1018 if ((sequence_number == 0 || !
s->last_picture.f->data[0]) &&
1038 s->x_offset = x_offset;
1039 s->y_offset = y_offset;
1040 s->dispose_op = dispose_op;
1041 s->blend_op = blend_op;
1049 uint8_t *pd = p->
data[0];
1050 uint8_t *pd_last =
s->last_picture.f->data[0];
1053 ls =
FFMIN(ls,
s->width *
s->bpp);
1056 for (j = 0; j <
s->height; j++) {
1057 for (
i = 0;
i < ls;
i++)
1058 pd[
i] += pd_last[
i];
1060 pd_last +=
s->last_picture.f->linesize[0];
1066 #define FAST_DIV255(x) ((((x) + 128) * 257) >> 16)
1071 uint8_t *dst = p->
data[0];
1072 ptrdiff_t dst_stride = p->
linesize[0];
1073 const uint8_t *
src =
s->last_picture.f->data[0];
1074 ptrdiff_t src_stride =
s->last_picture.f->linesize[0];
1093 if (!
s->background_buf)
1096 memcpy(
s->background_buf,
src, src_stride * p->
height);
1098 for (y =
s->last_y_offset; y < s->last_y_offset +
s->last_h; y++) {
1099 memset(
s->background_buf + src_stride * y +
1100 bpp *
s->last_x_offset, 0, bpp *
s->last_w);
1103 src =
s->background_buf;
1107 for (y = 0; y <
s->y_offset; y++)
1108 memcpy(dst + y * dst_stride,
src + y * src_stride, p->
width * bpp);
1109 for (y =
s->y_offset; y < s->y_offset +
s->cur_h; y++) {
1110 memcpy(dst + y * dst_stride,
src + y * src_stride,
s->x_offset * bpp);
1111 memcpy(dst + y * dst_stride + (
s->x_offset +
s->cur_w) * bpp,
1112 src + y * src_stride + (
s->x_offset +
s->cur_w) * bpp,
1113 (p->
width -
s->cur_w -
s->x_offset) * bpp);
1115 for (y =
s->y_offset +
s->cur_h; y < p->
height; y++)
1116 memcpy(dst + y * dst_stride,
src + y * src_stride, p->
width * bpp);
1120 for (y =
s->y_offset; y < s->y_offset +
s->cur_h; ++y) {
1121 uint8_t *foreground = dst + dst_stride * y + bpp *
s->x_offset;
1122 const uint8_t *background =
src + src_stride * y + bpp *
s->x_offset;
1123 for (x =
s->x_offset; x < s->x_offset +
s->cur_w; ++x, foreground += bpp, background += bpp) {
1125 uint8_t foreground_alpha, background_alpha, output_alpha;
1134 foreground_alpha = foreground[3];
1135 background_alpha = background[3];
1139 foreground_alpha = foreground[1];
1140 background_alpha = background[1];
1144 if (foreground_alpha == 255)
1147 if (foreground_alpha == 0) {
1148 memcpy(foreground, background, bpp);
1152 output_alpha = foreground_alpha +
FAST_DIV255((255 - foreground_alpha) * background_alpha);
1156 for (
b = 0;
b < bpp - 1; ++
b) {
1157 if (output_alpha == 0) {
1159 }
else if (background_alpha == 255) {
1160 output[
b] =
FAST_DIV255(foreground_alpha * foreground[
b] + (255 - foreground_alpha) * background[
b]);
1162 output[
b] = (255 * foreground_alpha * foreground[
b] + (255 - foreground_alpha) * background_alpha * background[
b]) / (255 * output_alpha);
1166 memcpy(foreground,
output, bpp);
1178 uint32_t
tag, length;
1179 int decode_next_dat = 0;
1207 length = bytestream2_get_be32(&
s->gb);
1214 uint32_t crc_sig =
AV_RB32(
s->gb.buffer + length + 4);
1215 uint32_t crc_cal = ~
av_crc(crc_tab, UINT32_MAX,
s->gb.buffer, length + 4);
1216 if (crc_sig ^ crc_cal) {
1227 tag = bytestream2_get_le32(&
s->gb);
1238 case MKTAG(
'I',
'H',
'D',
'R'):
1239 case MKTAG(
'p',
'H',
'Y',
's'):
1240 case MKTAG(
't',
'E',
'X',
't'):
1241 case MKTAG(
'I',
'D',
'A',
'T'):
1242 case MKTAG(
't',
'R',
'N',
'S'):
1250 case MKTAG(
'I',
'H',
'D',
'R'):
1254 case MKTAG(
'p',
'H',
'Y',
's'):
1258 case MKTAG(
'f',
'c',
'T',
'L'):
1263 decode_next_dat = 1;
1265 case MKTAG(
'f',
'd',
'A',
'T'):
1272 bytestream2_get_be32(&gb_chunk);
1274 case MKTAG(
'I',
'D',
'A',
'T'):
1280 case MKTAG(
'P',
'L',
'T',
'E'):
1283 case MKTAG(
't',
'R',
'N',
'S'):
1286 case MKTAG(
't',
'E',
'X',
't'):
1290 case MKTAG(
'z',
'T',
'X',
't'):
1294 case MKTAG(
's',
'T',
'E',
'R'): {
1295 int mode = bytestream2_get_byte(&gb_chunk);
1298 s->stereo_mode =
mode;
1301 "Unknown value in sTER chunk (%d)\n",
mode);
1305 case MKTAG(
'i',
'C',
'C',
'P'): {
1310 case MKTAG(
'c',
'H',
'R',
'M'): {
1313 s->white_point[0] = bytestream2_get_be32(&gb_chunk);
1314 s->white_point[1] = bytestream2_get_be32(&gb_chunk);
1317 for (
i = 0;
i < 3;
i++) {
1318 s->display_primaries[
i][0] = bytestream2_get_be32(&gb_chunk);
1319 s->display_primaries[
i][1] = bytestream2_get_be32(&gb_chunk);
1324 case MKTAG(
'g',
'A',
'M',
'A'): {
1327 int num = bytestream2_get_be32(&gb_chunk);
1339 case MKTAG(
'I',
'E',
'N',
'D'):
1359 if (
s->bits_per_pixel <= 4)
1363 for (
int y = 0; y <
s->height; y++) {
1366 for (
int x =
s->width - 1; x >= 0; x--) {
1367 const uint8_t idx = row[x];
1369 row[4*x+2] =
s->palette[idx] & 0xFF;
1370 row[4*x+1] = (
s->palette[idx] >> 8 ) & 0xFF;
1371 row[4*x+0] = (
s->palette[idx] >> 16) & 0xFF;
1372 row[4*x+3] =
s->palette[idx] >> 24;
1379 size_t byte_depth =
s->bit_depth > 8 ? 2 : 1;
1380 size_t raw_bpp =
s->bpp - byte_depth;
1385 for (y = 0; y <
s->height; ++y) {
1388 if (
s->bpp == 2 && byte_depth == 1) {
1389 uint8_t *
pixel = &row[2 *
s->width - 1];
1390 uint8_t *rowp = &row[1 *
s->width - 1];
1391 int tcolor =
s->transparent_color_be[0];
1392 for (x =
s->width; x > 0; --x) {
1393 *
pixel-- = *rowp == tcolor ? 0 : 0xff;
1396 }
else if (
s->bpp == 4 && byte_depth == 1) {
1397 uint8_t *
pixel = &row[4 *
s->width - 1];
1398 uint8_t *rowp = &row[3 *
s->width - 1];
1399 int tcolor =
AV_RL24(
s->transparent_color_be);
1400 for (x =
s->width; x > 0; --x) {
1408 for (x =
s->width; x > 0; --x) {
1409 uint8_t *
pixel = &row[
s->bpp * (x - 1)];
1410 memmove(
pixel, &row[raw_bpp * (x - 1)], raw_bpp);
1412 if (!memcmp(
pixel,
s->transparent_color_be, raw_bpp)) {
1413 memset(&
pixel[raw_bpp], 0, byte_depth);
1415 memset(&
pixel[raw_bpp], 0xff, byte_depth);
1423 if (
s->last_picture.f->data[0]) {
1425 &&
s->last_picture.f->width == p->
width
1426 &&
s->last_picture.f->height== p->
height
1427 &&
s->last_picture.f->format== p->
format
1431 else if (CONFIG_APNG_DECODER &&
1449 s->iccp_data_len = 0;
1450 s->iccp_name[0] = 0;
1452 s->stereo_mode = -1;
1474 memcpy(sd->
data,
s->iccp_data,
s->iccp_data_len);
1479 if (
s->stereo_mode >= 0) {
1501 for (
int i = 0;
i < 3;
i++) {
1517 #if CONFIG_PNG_DECODER
1522 const uint8_t *buf = avpkt->
data;
1523 int buf_size = avpkt->
size;
1533 sig = bytestream2_get_be64(&
s->gb);
1540 s->y =
s->has_trns = 0;
1545 ret = inflateReset(&
s->zstream.zstream);
1576 #if CONFIG_APNG_DECODER
1590 if ((
ret = inflateReset(&
s->zstream.zstream)) != Z_OK)
1598 if ((
ret = inflateReset(&
s->zstream.zstream)) != Z_OK)
1667 if (src_frame && src_frame->
f->
data[0]) {
1686 if (!
s->last_picture.f || !
s->picture.f)
1705 s->last_row_size = 0;
1707 s->tmp_row_size = 0;
1717 #if CONFIG_APNG_DECODER
1734 #if CONFIG_PNG_DECODER
static void error(const char *err)
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_BPRINT_SIZE_UNLIMITED
static void clear_frame_metadata(PNGDecContext *s)
void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
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
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
void ff_thread_release_ext_buffer(AVCodecContext *avctx, ThreadFrame *f)
Unref a ThreadFrame.
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, size_t size)
Add a new side data to a frame.
unsigned int last_row_size
#define APNG_FCTL_CHUNK_SIZE
static int decode_phys_chunk(AVCodecContext *avctx, PNGDecContext *s, GetByteContext *gb)
int ff_png_get_nb_channels(int color_type)
@ APNG_DISPOSE_OP_BACKGROUND
void(* add_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
static int decode_text_chunk(PNGDecContext *s, GetByteContext *gb, int compressed)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
@ 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...
@ AVCOL_RANGE_JPEG
Full range content.
static int output_frame(PNGDecContext *s, AVFrame *f, const AVFrame *src)
static uint8_t * iso88591_to_utf8(const uint8_t *in, size_t size_in)
unsigned int tmp_row_size
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before ff_thread_await_progress() has been called on them. reget_buffer() and buffer age optimizations no longer work. *The contents of buffers must not be written to after ff_thread_report_progress() has been called on them. This includes draw_edges(). Porting codecs to frame threading
#define FF_DEBUG_PICT_INFO
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
@ AV_PIX_FMT_GRAY16BE
Y , 16bpp, big-endian.
@ AV_STEREO3D_SIDEBYSIDE
Views are next to each other.
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define PNG_FILTER_TYPE_LOCO
AVCodec p
The public AVCodec.
int ff_png_pass_row_size(int pass, int bits_per_pixel, int width)
enum AVDiscard skip_frame
Skip decoding for selected frames.
static void inflate(uint8_t *dst, const uint8_t *p1, int width, int threshold, const uint8_t *coordinates[], int coord, int maxc)
static av_cold int png_dec_end(AVCodecContext *avctx)
enum PNGImageState pic_state
int key_frame
1 -> keyframe, 0-> not
static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, GetByteContext *gb, AVFrame *p)
static const uint8_t png_pass_dsp_ymask[NB_PASSES]
#define PNG_COLOR_TYPE_RGB_ALPHA
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
#define YUV2RGB(NAME, TYPE)
static const uint16_t mask[17]
#define FF_CODEC_DECODE_CB(func)
const FFCodec ff_apng_decoder
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
#define PNG_COLOR_TYPE_RGB
const FFCodec ff_png_decoder
#define av_assert0(cond)
assert() equivalent, that is always enabled.
enum PNGHeaderState hdr_state
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static int percent_missing(PNGDecContext *s)
@ APNG_DISPOSE_OP_PREVIOUS
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
int flags
Additional information about the frame packing.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
@ AVDISCARD_ALL
discard all
@ AV_PIX_FMT_GRAY8A
alias for AV_PIX_FMT_YA8
static int png_decode_idat(PNGDecContext *s, GetByteContext *gb, uint8_t *dst, ptrdiff_t dst_stride)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static av_cold int png_dec_init(AVCodecContext *avctx)
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Rational number (pair of numerator and denominator).
unsigned background_buf_allocated
@ 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_PICTURE_TYPE_I
Intra.
@ AV_FRAME_DATA_ICC_PROFILE
The data contains an ICC profile as an opaque octet buffer following the format described by ISO 1507...
#define PNG_COLOR_TYPE_GRAY
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
#define AV_EF_EXPLODE
abort decoding on minor error detection
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
const uint8_t ff_png_pass_ymask[NB_PASSES]
static const uint8_t png_pass_mask[NB_PASSES]
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
static av_always_inline int bytestream2_tell(GetByteContext *g)
static void handle_small_bpp(PNGDecContext *s, AVFrame *p)
#define PNG_FILTER_VALUE_NONE
enum AVPictureType pict_type
Picture type of the frame.
@ 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.
#define AV_EF_IGNORE_ERR
ignore errors and continue
void av_bprint_get_buffer(AVBPrint *buf, unsigned size, unsigned char **mem, unsigned *actual_size)
Allocate bytes in the buffer for external use.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static void handle_p_frame_png(PNGDecContext *s, AVFrame *p)
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
static void png_put_interlaced_row(uint8_t *dst, int width, int bits_per_pixel, int pass, int color_type, const uint8_t *src)
@ AV_PIX_FMT_YA16BE
16 bits gray, 16 bits alpha (big-endian)
#define PNG_FILTER_VALUE_AVG
static AVRational av_make_q(int num, int den)
Create an AVRational.
#define FF_CODEC_CAP_ALLOCATE_PROGRESS
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
#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...
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define PNG_FILTER_VALUE_PAETH
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_RL24
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
#define PNG_FILTER_VALUE_UP
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
#define AVERROR_EXTERNAL
Generic error in an external library.
int flags
A combination of AV_PKT_FLAG values.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
static int decode_trns_chunk(AVCodecContext *avctx, PNGDecContext *s, GetByteContext *gb)
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
#define FF_COMPLIANCE_NORMAL
#define FF_THREAD_FRAME
Decode more than one frame at once.
av_cold void ff_pngdsp_init(PNGDSPContext *dsp)
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.
AVDictionary * frame_metadata
int interlaced_frame
The content of the picture is interlaced.
void(* add_bytes_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
#define PNG_FILTER_VALUE_SUB
@ 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...
#define i(width, name, range_min, range_max)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
uint32_t display_primaries[3][2]
static void png_handle_row(PNGDecContext *s, uint8_t *dst, ptrdiff_t dst_stride)
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...
#define FF_DEBUG_STARTCODE
static int decode_iccp_chunk(PNGDecContext *s, GetByteContext *gb, AVFrame *f)
static int decode_fctl_chunk(AVCodecContext *avctx, PNGDecContext *s, GetByteContext *gb)
static int decode_plte_chunk(AVCodecContext *avctx, PNGDecContext *s, GetByteContext *gb)
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
const char * name
Name of the codec implementation.
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call have update_thread_context() run it in the next thread. Add AV_CODEC_CAP_FRAME_THREADS to the codec capabilities. There will be very little speed gain at this point but it should work. If there are inter-frame dependencies
void ff_inflate_end(FFZStream *zstream)
Wrapper around inflateEnd().
const uint8_t * buffer_end
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around ff_get_buffer() for frame-multithreaded codecs.
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
#define FFSWAP(type, a, b)
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
enum AVStereo3DType type
How views are packed within the video.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call ff_thread_finish_setup() afterwards. If some code can 't be moved
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
void ff_png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type, uint8_t *src, uint8_t *last, int size, int bpp)
main external API structure.
int active_thread_type
Which multithreading methods are in use by the codec.
static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s, AVFrame *p, const AVPacket *avpkt)
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
#define UNROLL_FILTER(op)
uint8_t transparent_color_be[6]
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.
static const uint8_t png_pass_dsp_mask[NB_PASSES]
int discard_damaged_percentage
The percentage of damaged samples to discard a frame.
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.
static int decode_ihdr_chunk(AVCodecContext *avctx, PNGDecContext *s, GetByteContext *gb)
AVStereo3D * av_stereo3d_create_side_data(AVFrame *frame)
Allocate a complete AVFrameSideData and add it to the frame.
#define avpriv_request_sample(...)
Structure to hold side data for an AVFrame.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
This structure stores compressed data.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
int ff_inflate_init(FFZStream *zstream, void *logctx)
Wrapper around inflateInit().
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...
#define PNG_COLOR_TYPE_GRAY_ALPHA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define MKTAG(a, b, c, d)
Stereo 3D type: this structure describes how two videos are packed within a single video surface,...
static int handle_p_frame_apng(AVCodecContext *avctx, PNGDecContext *s, AVFrame *p)
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...
static int decode_zbuf(AVBPrint *bp, const uint8_t *data, const uint8_t *data_end, void *logctx)
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
#define PNG_COLOR_TYPE_PALETTE
#define AV_DICT_DONT_STRDUP_KEY
Take ownership of a key that's been allocated with av_malloc() or another memory allocation function.
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.
#define av_fourcc2str(fourcc)