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 & 3) ? size - 3 : size;
289 #define YUV2RGB(NAME, TYPE) \
290 static void deloco_ ## NAME(TYPE *dst, int size, int alpha) \
293 for (i = 0; i < size; i += 3 + alpha) { \
294 int g = dst [i + 1]; \
309 if (!s->interlace_type) {
310 ptr = s->image_buf + s->image_linesize * (s->y + s->y_offset) + s->x_offset * s->bpp;
312 last_row = s->last_row;
314 last_row = ptr - s->image_linesize;
317 last_row, s->row_size, s->bpp);
320 if (s->bit_depth == 16) {
321 deloco_rgb16((uint16_t *)(ptr - s->image_linesize), s->row_size / 2,
324 deloco_rgb8(ptr - s->image_linesize, s->row_size,
329 if (s->y == s->cur_h) {
332 if (s->bit_depth == 16) {
333 deloco_rgb16((uint16_t *)ptr, s->row_size / 2,
336 deloco_rgb8(ptr, s->row_size,
344 ptr = s->image_buf + s->image_linesize * (s->y + s->y_offset) + s->x_offset * s->bpp;
350 png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
351 s->last_row, s->pass_row_size, s->bpp);
353 FFSWAP(
unsigned int, s->last_row_size, s->tmp_row_size);
358 s->color_type, s->last_row);
361 if (s->y == s->cur_h) {
362 memset(s->last_row, 0, s->row_size);
373 s->crow_size = s->pass_row_size + 1;
374 if (s->pass_row_size != 0)
393 while (s->
zstream.avail_in > 0) {
394 ret = inflate(&s->
zstream, Z_PARTIAL_FLUSH);
395 if (ret != Z_OK && ret != Z_STREAM_END) {
399 if (s->
zstream.avail_out == 0) {
406 if (ret == Z_STREAM_END && s->
zstream.avail_in > 0) {
408 "%d undecompressed bytes left in buffer\n", s->
zstream.avail_in);
425 zstream.opaque =
NULL;
426 if (inflateInit(&zstream) != Z_OK)
428 zstream.next_in = (
unsigned char *)data;
429 zstream.avail_in = data_end -
data;
432 while (zstream.avail_in > 0) {
438 zstream.next_out =
buf;
439 zstream.avail_out = buf_size;
440 ret = inflate(&zstream, Z_PARTIAL_FLUSH);
441 if (ret != Z_OK && ret != Z_STREAM_END) {
445 bp->len += zstream.next_out -
buf;
446 if (ret == Z_STREAM_END)
449 inflateEnd(&zstream);
450 bp->str[bp->len] = 0;
454 inflateEnd(&zstream);
464 for (i = 0; i < size_in; i++)
465 extra += in[i] >= 0x80;
466 if (size_in == SIZE_MAX || extra > SIZE_MAX - size_in - 1)
468 q = out =
av_malloc(size_in + extra + 1);
471 for (i = 0; i < size_in; i++) {
473 *(q++) = 0xC0 | (in[i] >> 6);
474 *(q++) = 0x80 | (in[i] & 0x3F);
490 const uint8_t *keyword_end = memchr(keyword, 0, data_end - keyword);
497 data = keyword_end + 1;
500 if (data == data_end)
513 text_len = data_end - text;
520 if (!(kw_utf8 && txt_utf8)) {
558 "compression_type=%d filter_type=%d interlace_type=%d\n",
631 "and color type %d\n",
654 av_dlog(avctx,
"row_size=%d crow_size =%d\n",
660 memcpy(p->
data[1], s->
palette, 256 *
sizeof(uint32_t));
694 if ((length % 3) != 0 || length > 256 * 3)
698 for (i = 0; i <
n; i++) {
699 r = bytestream2_get_byte(&s->
gb);
700 g = bytestream2_get_byte(&s->
gb);
701 b = bytestream2_get_byte(&s->
gb);
702 s->
palette[i] = (0xFF
U << 24) | (r << 16) | (g << 8) | b;
722 for (i = 0; i <
length; i++) {
723 v = bytestream2_get_byte(&s->
gb);
736 for (j = 0; j < s->
height; j++) {
738 for (k = 7; k >= 1; k--)
739 if ((s->
width&7) >= k)
740 pd[8*i + k - 1] = (pd[i]>>8-k) & 1;
741 for (i--; i >= 0; i--) {
742 pd[8*i + 7]= pd[i] & 1;
743 pd[8*i + 6]= (pd[i]>>1) & 1;
744 pd[8*i + 5]= (pd[i]>>2) & 1;
745 pd[8*i + 4]= (pd[i]>>3) & 1;
746 pd[8*i + 3]= (pd[i]>>4) & 1;
747 pd[8*i + 2]= (pd[i]>>5) & 1;
748 pd[8*i + 1]= (pd[i]>>6) & 1;
749 pd[8*i + 0]= pd[i]>>7;
756 for (j = 0; j < s->
height; j++) {
759 if ((s->
width&3) >= 3) pd[4*i + 2]= (pd[i] >> 2) & 3;
760 if ((s->
width&3) >= 2) pd[4*i + 1]= (pd[i] >> 4) & 3;
761 if ((s->
width&3) >= 1) pd[4*i + 0]= pd[i] >> 6;
762 for (i--; i >= 0; i--) {
763 pd[4*i + 3]= pd[i] & 3;
764 pd[4*i + 2]= (pd[i]>>2) & 3;
765 pd[4*i + 1]= (pd[i]>>4) & 3;
766 pd[4*i + 0]= pd[i]>>6;
769 if ((s->
width&3) >= 3) pd[4*i + 2]= ((pd[i]>>2) & 3)*0x55;
770 if ((s->
width&3) >= 2) pd[4*i + 1]= ((pd[i]>>4) & 3)*0x55;
771 if ((s->
width&3) >= 1) pd[4*i + 0]= ( pd[i]>>6 )*0x55;
772 for (i--; i >= 0; i--) {
773 pd[4*i + 3]= ( pd[i] & 3)*0x55;
774 pd[4*i + 2]= ((pd[i]>>2) & 3)*0x55;
775 pd[4*i + 1]= ((pd[i]>>4) & 3)*0x55;
776 pd[4*i + 0]= ( pd[i]>>6 )*0x55;
784 for (j = 0; j < s->
height; j++) {
787 if (s->
width&1) pd[2*i+0]= pd[i]>>4;
788 for (i--; i >= 0; i--) {
789 pd[2*i + 1] = pd[i] & 15;
790 pd[2*i + 0] = pd[i] >> 4;
793 if (s->
width & 1) pd[2*i + 0]= (pd[i] >> 4) * 0x11;
794 for (i--; i >= 0; i--) {
795 pd[2*i + 1] = (pd[i] & 15) * 0x11;
796 pd[2*i + 0] = (pd[i] >> 4) * 0x11;
807 uint32_t sequence_number;
812 sequence_number = bytestream2_get_be32(&s->
gb);
813 s->
cur_w = bytestream2_get_be32(&s->
gb);
814 s->
cur_h = bytestream2_get_be32(&s->
gb);
822 if (sequence_number == 0 &&
833 if (sequence_number == 0) {
854 for (j = 0; j < s->
height; j++) {
855 for (i = 0; i < ls; i++)
864 #define FAST_DIV255(x) ((((x) + 128) * 257) >> 16)
891 memcpy(pd, pd_last, ls);
915 memcpy(pd, pd_last, i);
922 pd[i+ri] = pd_last_region[i+ri];
923 pd[i+gi] = pd_last_region[i+gi];
924 pd[i+bi] = pd_last_region[i+bi];
930 pd[i+ri] =
FAST_DIV255(alpha * pd[i+ri] + (255 - alpha) * pd_last_region[i+ri]);
931 pd[i+gi] =
FAST_DIV255(alpha * pd[i+gi] + (255 - alpha) * pd_last_region[i+gi]);
932 pd[i+bi] =
FAST_DIV255(alpha * pd[i+bi] + (255 - alpha) * pd_last_region[i+bi]);
938 memcpy(pd+i, pd_last+i, ls - i);
946 int end_len = ls - end_offset;
950 memcpy(pd+end_offset, pd_last+end_offset, end_len);
957 memcpy(pd, pd_last, ls);
970 int decode_next_dat = 0;
990 length = bytestream2_get_be32(&s->
gb);
995 tag = bytestream2_get_le32(&s->
gb);
1000 ((tag >> 16) & 0xff),
1001 ((tag >> 24) & 0xff), length);
1003 case MKTAG(
'I',
'H',
'D',
'R'):
1007 case MKTAG(
'p',
'H',
'Y',
's'):
1011 case MKTAG(
'f',
'c',
'T',
'L'):
1016 decode_next_dat = 1;
1018 case MKTAG(
'f',
'd',
'A',
'T'):
1021 if (!decode_next_dat)
1023 bytestream2_get_be32(&s->
gb);
1026 case MKTAG(
'I',
'D',
'A',
'T'):
1032 case MKTAG(
'P',
'L',
'T',
'E'):
1036 case MKTAG(
't',
'R',
'N',
'S'):
1040 case MKTAG(
't',
'E',
'X',
't'):
1045 case MKTAG(
'z',
'T',
'X',
't'):
1050 case MKTAG(
'I',
'E',
'N',
'D'):
1081 else if (CONFIG_APNG_DECODER &&
1099 #if CONFIG_PNG_DECODER
1101 void *
data,
int *got_frame,
1106 int buf_size = avpkt->
size;
1118 sig = bytestream2_get_be64(&s->
gb);
1131 ret = inflateInit(&s->
zstream);
1153 #if CONFIG_APNG_DECODER
1155 void *data,
int *got_frame,
1184 if ((ret = inflateInit(&s->
zstream)) != Z_OK) {
1280 #if CONFIG_APNG_DECODER
1289 .
decode = decode_frame_apng,
1296 #if CONFIG_PNG_DECODER
1305 .
decode = decode_frame_png,