80 0x01, 0x01, 0x11, 0x11, 0x55, 0x55, 0xff,
85 0xff, 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
90 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff
97 int bits_per_pixel,
int pass,
100 int x,
mask, dsp_mask, j, src_x,
b, bpp;
107 switch (bits_per_pixel) {
110 for (x = 0; x <
width; x++) {
112 if ((dsp_mask << j) & 0x80) {
113 b = (src[src_x >> 3] >> (7 - (src_x & 7))) & 1;
114 dst[x >> 3] &= 0xFF7F>>j;
115 dst[x >> 3] |= b << (7 - j);
117 if ((mask << j) & 0x80)
123 for (x = 0; x <
width; x++) {
124 int j2 = 2 * (x & 3);
126 if ((dsp_mask << j) & 0x80) {
127 b = (src[src_x >> 2] >> (6 - 2*(src_x & 3))) & 3;
128 dst[x >> 2] &= 0xFF3F>>j2;
129 dst[x >> 2] |= b << (6 - j2);
131 if ((mask << j) & 0x80)
137 for (x = 0; x <
width; x++) {
140 if ((dsp_mask << j) & 0x80) {
141 b = (src[src_x >> 1] >> (4 - 4*(src_x & 1))) & 15;
142 dst[x >> 1] &= 0xFF0F>>j2;
143 dst[x >> 1] |= b << (4 - j2);
145 if ((mask << j) & 0x80)
150 bpp = bits_per_pixel >> 3;
153 for (x = 0; x <
width; x++) {
155 if ((dsp_mask << j) & 0x80) {
159 if ((mask << j) & 0x80)
170 for (i = 0; i < w; i++) {
171 int a,
b,
c, p, pa, pb, pc;
184 if (pa <= pb && pa <= pc)
194 #define UNROLL1(bpp, op) \
203 for (; i <= size - bpp; i += bpp) { \
204 dst[i + 0] = r = op(r, src[i + 0], last[i + 0]); \
207 dst[i + 1] = g = op(g, src[i + 1], last[i + 1]); \
210 dst[i + 2] = b = op(b, src[i + 2], last[i + 2]); \
213 dst[i + 3] = a = op(a, src[i + 3], last[i + 3]); \
217 #define UNROLL_FILTER(op) \
220 } else if (bpp == 2) { \
222 } else if (bpp == 3) { \
224 } else if (bpp == 4) { \
227 for (; i < size; i++) { \
228 dst[i] = op(dst[i - bpp], src[i], last[i]); \
235 int i, p,
r,
g,
b,
a;
237 switch (filter_type) {
239 memcpy(dst, src, size);
242 for (i = 0; i < bpp; i++)
246 for (; i <
size; i += bpp) {
247 unsigned s = *(
int *)(src + i);
248 p = ((s & 0x7f7f7f7f) + (p & 0x7f7f7f7f)) ^ ((s ^ p) & 0x80808080);
249 *(
int *)(dst + i) = p;
252 #define OP_SUB(x, s, l) ((x) + (s))
260 for (i = 0; i < bpp; i++) {
264 #define OP_AVG(x, s, l) (((((x) + (l)) >> 1) + (s)) & 0xff)
268 for (i = 0; i < bpp; i++) {
272 if (bpp > 2 && size > 4) {
275 int w = bpp == 4 ? size : size - 3;
288 #define YUV2RGB(NAME, TYPE) \
289 static void deloco_ ## NAME(TYPE *dst, int size, int alpha) \
292 for (i = 0; i < size; i += 3 + alpha) { \
293 int g = dst [i + 1]; \
308 if (!s->interlace_type) {
309 ptr = s->image_buf + s->image_linesize * (s->y + s->y_offset) + s->x_offset * s->bpp;
311 last_row = s->last_row;
313 last_row = ptr - s->image_linesize;
316 last_row, s->row_size, s->bpp);
319 if (s->bit_depth == 16) {
320 deloco_rgb16((uint16_t *)(ptr - s->image_linesize), s->row_size / 2,
323 deloco_rgb8(ptr - s->image_linesize, s->row_size,
328 if (s->y == s->cur_h) {
331 if (s->bit_depth == 16) {
332 deloco_rgb16((uint16_t *)ptr, s->row_size / 2,
335 deloco_rgb8(ptr, s->row_size,
343 ptr = s->image_buf + s->image_linesize * (s->y + s->y_offset) + s->x_offset * s->bpp;
349 png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
350 s->last_row, s->pass_row_size, s->bpp);
352 FFSWAP(
unsigned int, s->last_row_size, s->tmp_row_size);
357 s->color_type, s->last_row);
360 if (s->y == s->cur_h) {
361 memset(s->last_row, 0, s->row_size);
372 s->crow_size = s->pass_row_size + 1;
373 if (s->pass_row_size != 0)
392 while (s->
zstream.avail_in > 0) {
393 ret = inflate(&s->
zstream, Z_PARTIAL_FLUSH);
394 if (ret != Z_OK && ret != Z_STREAM_END) {
398 if (s->
zstream.avail_out == 0) {
405 if (ret == Z_STREAM_END && s->
zstream.avail_in > 0) {
407 "%d undecompressed bytes left in buffer\n", s->
zstream.avail_in);
424 zstream.opaque = NULL;
425 if (inflateInit(&zstream) != Z_OK)
427 zstream.next_in = (
unsigned char *)data;
428 zstream.avail_in = data_end -
data;
431 while (zstream.avail_in > 0) {
437 zstream.next_out =
buf;
438 zstream.avail_out = buf_size;
439 ret = inflate(&zstream, Z_PARTIAL_FLUSH);
440 if (ret != Z_OK && ret != Z_STREAM_END) {
444 bp->len += zstream.next_out -
buf;
445 if (ret == Z_STREAM_END)
448 inflateEnd(&zstream);
449 bp->str[bp->len] = 0;
453 inflateEnd(&zstream);
463 for (i = 0; i < size_in; i++)
464 extra += in[i] >= 0x80;
465 if (size_in == SIZE_MAX || extra > SIZE_MAX - size_in - 1)
467 q = out =
av_malloc(size_in + extra + 1);
470 for (i = 0; i < size_in; i++) {
472 *(q++) = 0xC0 | (in[i] >> 6);
473 *(q++) = 0x80 | (in[i] & 0x3F);
489 const uint8_t *keyword_end = memchr(keyword, 0, data_end - keyword);
490 uint8_t *kw_utf8 = NULL, *text, *txt_utf8 = NULL;
496 data = keyword_end + 1;
499 if (data == data_end)
512 text_len = data_end - text;
519 if (!(kw_utf8 && txt_utf8)) {
557 "compression_type=%d filter_type=%d interlace_type=%d\n",
630 "and color type %d\n",
653 av_dlog(avctx,
"row_size=%d crow_size =%d\n",
659 memcpy(p->
data[1], s->
palette, 256 *
sizeof(uint32_t));
693 if ((length % 3) != 0 || length > 256 * 3)
697 for (i = 0; i <
n; i++) {
698 r = bytestream2_get_byte(&s->
gb);
699 g = bytestream2_get_byte(&s->
gb);
700 b = bytestream2_get_byte(&s->
gb);
701 s->
palette[i] = (0xFF
U << 24) | (r << 16) | (g << 8) | b;
721 for (i = 0; i <
length; i++) {
722 v = bytestream2_get_byte(&s->
gb);
735 for (j = 0; j < s->
height; j++) {
737 for (k = 7; k >= 1; k--)
738 if ((s->
width&7) >= k)
739 pd[8*i + k - 1] = (pd[i]>>8-k) & 1;
740 for (i--; i >= 0; i--) {
741 pd[8*i + 7]= pd[i] & 1;
742 pd[8*i + 6]= (pd[i]>>1) & 1;
743 pd[8*i + 5]= (pd[i]>>2) & 1;
744 pd[8*i + 4]= (pd[i]>>3) & 1;
745 pd[8*i + 3]= (pd[i]>>4) & 1;
746 pd[8*i + 2]= (pd[i]>>5) & 1;
747 pd[8*i + 1]= (pd[i]>>6) & 1;
748 pd[8*i + 0]= pd[i]>>7;
755 for (j = 0; j < s->
height; j++) {
758 if ((s->
width&3) >= 3) pd[4*i + 2]= (pd[i] >> 2) & 3;
759 if ((s->
width&3) >= 2) pd[4*i + 1]= (pd[i] >> 4) & 3;
760 if ((s->
width&3) >= 1) pd[4*i + 0]= pd[i] >> 6;
761 for (i--; i >= 0; i--) {
762 pd[4*i + 3]= pd[i] & 3;
763 pd[4*i + 2]= (pd[i]>>2) & 3;
764 pd[4*i + 1]= (pd[i]>>4) & 3;
765 pd[4*i + 0]= pd[i]>>6;
768 if ((s->
width&3) >= 3) pd[4*i + 2]= ((pd[i]>>2) & 3)*0x55;
769 if ((s->
width&3) >= 2) pd[4*i + 1]= ((pd[i]>>4) & 3)*0x55;
770 if ((s->
width&3) >= 1) pd[4*i + 0]= ( pd[i]>>6 )*0x55;
771 for (i--; i >= 0; i--) {
772 pd[4*i + 3]= ( pd[i] & 3)*0x55;
773 pd[4*i + 2]= ((pd[i]>>2) & 3)*0x55;
774 pd[4*i + 1]= ((pd[i]>>4) & 3)*0x55;
775 pd[4*i + 0]= ( pd[i]>>6 )*0x55;
783 for (j = 0; j < s->
height; j++) {
786 if (s->
width&1) pd[2*i+0]= pd[i]>>4;
787 for (i--; i >= 0; i--) {
788 pd[2*i + 1] = pd[i] & 15;
789 pd[2*i + 0] = pd[i] >> 4;
792 if (s->
width & 1) pd[2*i + 0]= (pd[i] >> 4) * 0x11;
793 for (i--; i >= 0; i--) {
794 pd[2*i + 1] = (pd[i] & 15) * 0x11;
795 pd[2*i + 0] = (pd[i] >> 4) * 0x11;
806 uint32_t sequence_number;
811 sequence_number = bytestream2_get_be32(&s->
gb);
812 s->
cur_w = bytestream2_get_be32(&s->
gb);
813 s->
cur_h = bytestream2_get_be32(&s->
gb);
821 if (sequence_number == 0 &&
832 if (sequence_number == 0) {
853 for (j = 0; j < s->
height; j++) {
854 for (i = 0; i < ls; i++)
863 #define FAST_DIV255(x) ((((x) + 128) * 257) >> 16)
887 for (i = 0; i < ls; i++)
918 pd[i+ri] = pd_last_region[i+ri];
919 pd[i+gi] = pd_last_region[i+gi];
920 pd[i+bi] = pd_last_region[i+bi];
926 pd[i+ri] =
FAST_DIV255(alpha * pd[i+ri] + (255 - alpha) * pd_last_region[i+ri]);
927 pd[i+gi] =
FAST_DIV255(alpha * pd[i+gi] + (255 - alpha) * pd_last_region[i+gi]);
928 pd[i+bi] =
FAST_DIV255(alpha * pd[i+bi] + (255 - alpha) * pd_last_region[i+bi]);
951 for (i = 0; i < ls; i++)
965 int decode_next_dat = 0;
985 length = bytestream2_get_be32(&s->
gb);
990 tag = bytestream2_get_le32(&s->
gb);
995 ((tag >> 16) & 0xff),
996 ((tag >> 24) & 0xff), length);
998 case MKTAG(
'I',
'H',
'D',
'R'):
1002 case MKTAG(
'p',
'H',
'Y',
's'):
1006 case MKTAG(
'f',
'c',
'T',
'L'):
1011 decode_next_dat = 1;
1013 case MKTAG(
'f',
'd',
'A',
'T'):
1016 if (!decode_next_dat)
1018 bytestream2_get_be32(&s->
gb);
1021 case MKTAG(
'I',
'D',
'A',
'T'):
1027 case MKTAG(
'P',
'L',
'T',
'E'):
1031 case MKTAG(
't',
'R',
'N',
'S'):
1035 case MKTAG(
't',
'E',
'X',
't'):
1040 case MKTAG(
'z',
'T',
'X',
't'):
1045 case MKTAG(
'I',
'E',
'N',
'D'):
1076 else if (CONFIG_APNG_DECODER &&
1094 #if CONFIG_PNG_DECODER
1096 void *
data,
int *got_frame,
1101 int buf_size = avpkt->
size;
1113 sig = bytestream2_get_be64(&s->
gb);
1126 ret = inflateInit(&s->
zstream);
1148 #if CONFIG_APNG_DECODER
1150 void *data,
int *got_frame,
1179 if ((ret = inflateInit(&s->
zstream)) != Z_OK) {
1275 #if CONFIG_APNG_DECODER
1284 .
decode = decode_frame_apng,
1291 #if CONFIG_PNG_DECODER
1300 .
decode = decode_frame_png,