74 0x01, 0x01, 0x11, 0x11, 0x55, 0x55, 0xff,
79 0xff, 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
84 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff
91 int bits_per_pixel,
int pass,
94 int x,
mask, dsp_mask, j, src_x,
b, bpp;
101 switch (bits_per_pixel) {
104 for (x = 0; x <
width; x++) {
106 if ((dsp_mask << j) & 0x80) {
107 b = (src[src_x >> 3] >> (7 - (src_x & 7))) & 1;
108 dst[x >> 3] &= 0xFF7F>>j;
109 dst[x >> 3] |= b << (7 - j);
111 if ((mask << j) & 0x80)
117 for (x = 0; x <
width; x++) {
118 int j2 = 2 * (x & 3);
120 if ((dsp_mask << j) & 0x80) {
121 b = (src[src_x >> 2] >> (6 - 2*(src_x & 3))) & 3;
122 dst[x >> 2] &= 0xFF3F>>j2;
123 dst[x >> 2] |= b << (6 - j2);
125 if ((mask << j) & 0x80)
131 for (x = 0; x <
width; x++) {
134 if ((dsp_mask << j) & 0x80) {
135 b = (src[src_x >> 1] >> (4 - 4*(src_x & 1))) & 15;
136 dst[x >> 1] &= 0xFF0F>>j2;
137 dst[x >> 1] |= b << (4 - j2);
139 if ((mask << j) & 0x80)
144 bpp = bits_per_pixel >> 3;
147 for (x = 0; x <
width; x++) {
149 if ((dsp_mask << j) & 0x80) {
153 if ((mask << j) & 0x80)
164 for (i = 0; i < w; i++) {
165 int a,
b,
c, p, pa, pb, pc;
178 if (pa <= pb && pa <= pc)
188 #define UNROLL1(bpp, op) \
197 for (; i <= size - bpp; i += bpp) { \
198 dst[i + 0] = r = op(r, src[i + 0], last[i + 0]); \
201 dst[i + 1] = g = op(g, src[i + 1], last[i + 1]); \
204 dst[i + 2] = b = op(b, src[i + 2], last[i + 2]); \
207 dst[i + 3] = a = op(a, src[i + 3], last[i + 3]); \
211 #define UNROLL_FILTER(op) \
214 } else if (bpp == 2) { \
216 } else if (bpp == 3) { \
218 } else if (bpp == 4) { \
221 for (; i < size; i++) { \
222 dst[i] = op(dst[i - bpp], src[i], last[i]); \
229 int i, p,
r,
g,
b,
a;
231 switch (filter_type) {
233 memcpy(dst, src, size);
236 for (i = 0; i < bpp; i++)
240 for (; i <
size; i += bpp) {
241 unsigned s = *(
int *)(src + i);
242 p = ((s & 0x7f7f7f7f) + (p & 0x7f7f7f7f)) ^ ((s ^ p) & 0x80808080);
243 *(
int *)(dst + i) = p;
246 #define OP_SUB(x, s, l) ((x) + (s))
254 for (i = 0; i < bpp; i++) {
258 #define OP_AVG(x, s, l) (((((x) + (l)) >> 1) + (s)) & 0xff)
262 for (i = 0; i < bpp; i++) {
266 if (bpp > 2 && size > 4) {
269 int w = bpp == 4 ? size : size - 3;
280 #define YUV2RGB(NAME, TYPE) \
281 static void deloco_ ## NAME(TYPE *dst, int size, int alpha) \
284 for (i = 0; i < size; i += 3 + alpha) { \
285 int g = dst [i + 1]; \
300 if (!s->interlace_type) {
301 ptr = s->image_buf + s->image_linesize * s->y;
303 last_row = s->last_row;
305 last_row = ptr - s->image_linesize;
308 last_row, s->row_size, s->bpp);
311 if (s->bit_depth == 16) {
312 deloco_rgb16((uint16_t *)(ptr - s->image_linesize), s->row_size / 2,
315 deloco_rgb8(ptr - s->image_linesize, s->row_size,
320 if (s->y == s->height) {
323 if (s->bit_depth == 16) {
324 deloco_rgb16((uint16_t *)ptr, s->row_size / 2,
327 deloco_rgb8(ptr, s->row_size,
335 ptr = s->image_buf + s->image_linesize * s->y;
341 png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
342 s->last_row, s->pass_row_size, s->bpp);
344 FFSWAP(
unsigned int, s->last_row_size, s->tmp_row_size);
349 s->color_type, s->last_row);
352 if (s->y == s->height) {
353 memset(s->last_row, 0, s->row_size);
364 s->crow_size = s->pass_row_size + 1;
365 if (s->pass_row_size != 0)
384 while (s->
zstream.avail_in > 0) {
385 ret = inflate(&s->
zstream, Z_PARTIAL_FLUSH);
386 if (ret != Z_OK && ret != Z_STREAM_END) {
390 if (s->
zstream.avail_out == 0) {
397 if (ret == Z_STREAM_END && s->
zstream.avail_in > 0) {
399 "%d undecompressed bytes left in buffer\n", s->
zstream.avail_in);
416 zstream.opaque = NULL;
417 if (inflateInit(&zstream) != Z_OK)
419 zstream.next_in = (
unsigned char *)data;
420 zstream.avail_in = data_end -
data;
423 while (zstream.avail_in > 0) {
429 zstream.next_out =
buf;
430 zstream.avail_out = buf_size;
431 ret = inflate(&zstream, Z_PARTIAL_FLUSH);
432 if (ret != Z_OK && ret != Z_STREAM_END) {
436 bp->len += zstream.next_out -
buf;
437 if (ret == Z_STREAM_END)
440 inflateEnd(&zstream);
441 bp->str[bp->len] = 0;
445 inflateEnd(&zstream);
455 for (i = 0; i < size_in; i++)
456 extra += in[i] >= 0x80;
457 if (size_in == SIZE_MAX || extra > SIZE_MAX - size_in - 1)
459 q = out =
av_malloc(size_in + extra + 1);
462 for (i = 0; i < size_in; i++) {
464 *(q++) = 0xC0 | (in[i] >> 6);
465 *(q++) = 0x80 | (in[i] & 0x3F);
481 const uint8_t *keyword_end = memchr(keyword, 0, data_end - keyword);
482 uint8_t *kw_utf8 = NULL, *text, *txt_utf8 = NULL;
488 data = keyword_end + 1;
491 if (data == data_end)
504 text_len = data_end - text;
511 if (!(kw_utf8 && txt_utf8)) {
523 void *
data,
int *got_frame,
528 int buf_size = avpkt->
size;
542 sig = bytestream2_get_be64(&s->
gb);
555 ret = inflateInit(&s->
zstream);
569 length = bytestream2_get_be32(&s->
gb);
574 tag = bytestream2_get_le32(&s->
gb);
579 ((tag >> 16) & 0xff),
580 ((tag >> 24) & 0xff), length);
582 case MKTAG(
'I',
'H',
'D',
'R'):
585 s->
width = bytestream2_get_be32(&s->
gb);
586 s->
height = bytestream2_get_be32(&s->
gb);
601 "compression_type=%d filter_type=%d interlace_type=%d\n",
605 case MKTAG(
'p',
'H',
'Y',
's'):
617 case MKTAG(
'I',
'D',
'A',
'T'):
663 "and color type %d\n",
686 av_dlog(avctx,
"row_size=%d crow_size =%d\n",
692 memcpy(p->
data[1], s->
palette, 256 *
sizeof(uint32_t));
718 case MKTAG(
'P',
'L',
'T',
'E'):
722 if ((length % 3) != 0 || length > 256 * 3)
726 for (i = 0; i <
n; i++) {
727 r = bytestream2_get_byte(&s->
gb);
728 g = bytestream2_get_byte(&s->
gb);
729 b = bytestream2_get_byte(&s->
gb);
730 s->
palette[i] = (0xFF
U << 24) | (r << 16) | (g << 8) | b;
738 case MKTAG(
't',
'R',
'N',
'S'):
747 for (i = 0; i <
length; i++) {
748 v = bytestream2_get_byte(&s->
gb);
754 case MKTAG(
't',
'E',
'X',
't'):
759 case MKTAG(
'z',
'T',
'X',
't'):
764 case MKTAG(
'I',
'E',
'N',
'D'):
784 for (j = 0; j < s->
height; j++) {
786 for (k = 7; k >= 1; k--)
787 if ((s->
width&7) >= k)
788 pd[8*i + k - 1] = (pd[i]>>8-k) & 1;
789 for (i--; i >= 0; i--) {
790 pd[8*i + 7]= pd[i] & 1;
791 pd[8*i + 6]= (pd[i]>>1) & 1;
792 pd[8*i + 5]= (pd[i]>>2) & 1;
793 pd[8*i + 4]= (pd[i]>>3) & 1;
794 pd[8*i + 3]= (pd[i]>>4) & 1;
795 pd[8*i + 2]= (pd[i]>>5) & 1;
796 pd[8*i + 1]= (pd[i]>>6) & 1;
797 pd[8*i + 0]= pd[i]>>7;
805 for (j = 0; j < s->
height; j++) {
808 if ((s->
width&3) >= 3) pd[4*i + 2]= (pd[i] >> 2) & 3;
809 if ((s->
width&3) >= 2) pd[4*i + 1]= (pd[i] >> 4) & 3;
810 if ((s->
width&3) >= 1) pd[4*i + 0]= pd[i] >> 6;
811 for (i--; i >= 0; i--) {
812 pd[4*i + 3]= pd[i] & 3;
813 pd[4*i + 2]= (pd[i]>>2) & 3;
814 pd[4*i + 1]= (pd[i]>>4) & 3;
815 pd[4*i + 0]= pd[i]>>6;
818 if ((s->
width&3) >= 3) pd[4*i + 2]= ((pd[i]>>2) & 3)*0x55;
819 if ((s->
width&3) >= 2) pd[4*i + 1]= ((pd[i]>>4) & 3)*0x55;
820 if ((s->
width&3) >= 1) pd[4*i + 0]= ( pd[i]>>6 )*0x55;
821 for (i--; i >= 0; i--) {
822 pd[4*i + 3]= ( pd[i] & 3)*0x55;
823 pd[4*i + 2]= ((pd[i]>>2) & 3)*0x55;
824 pd[4*i + 1]= ((pd[i]>>4) & 3)*0x55;
825 pd[4*i + 0]= ( pd[i]>>6 )*0x55;
834 for (j = 0; j < s->
height; j++) {
837 if (s->
width&1) pd[2*i+0]= pd[i]>>4;
838 for (i--; i >= 0; i--) {
839 pd[2*i + 1] = pd[i] & 15;
840 pd[2*i + 0] = pd[i] >> 4;
843 if (s->
width & 1) pd[2*i + 0]= (pd[i] >> 4) * 0x11;
844 for (i--; i >= 0; i--) {
845 pd[2*i + 1] = (pd[i] & 15) * 0x11;
846 pd[2*i + 0] = (pd[i] >> 4) * 0x11;
865 for (j = 0; j < s->
height; j++) {
866 for (i = 0; i < s->
width * s->
bpp; i++)