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) { \
196 for (; i <= size - bpp; i += bpp) { \
197 dst[i + 0] = r = op(r, src[i + 0], last[i + 0]); \
200 dst[i + 1] = g = op(g, src[i + 1], last[i + 1]); \
203 dst[i + 2] = b = op(b, src[i + 2], last[i + 2]); \
206 dst[i + 3] = a = op(a, src[i + 3], last[i + 3]); \
210 #define UNROLL_FILTER(op)\
211 if (bpp == 1) UNROLL1(1, op)\
212 else if (bpp == 2) UNROLL1(2, op)\
213 else if (bpp == 3) UNROLL1(3, op)\
214 else if (bpp == 4) UNROLL1(4, op)\
215 for (; i < size; i++) {\
216 dst[i] = op(dst[i - bpp], src[i], last[i]);\
223 int i, p,
r,
g,
b,
a;
225 switch (filter_type) {
227 memcpy(dst, src, size);
230 for (i = 0; i < bpp; i++)
234 for (; i <
size; i += bpp) {
235 unsigned s = *(
int *)(src + i);
236 p = ((s & 0x7f7f7f7f) + (p & 0x7f7f7f7f)) ^ ((s ^ p) & 0x80808080);
237 *(
int *)(dst + i) = p;
240 #define OP_SUB(x, s, l) ((x) + (s))
248 for (i = 0; i < bpp; i++) {
252 #define OP_AVG(x, s, l) (((((x) + (l)) >> 1) + (s)) & 0xff)
256 for (i = 0; i < bpp; i++) {
260 if (bpp > 2 && size > 4) {
263 int w = bpp == 4 ? size : size - 3;
274 #define YUV2RGB(NAME, TYPE) \
275 static void deloco_ ## NAME(TYPE *dst, int size, int alpha) \
278 for (i = 0; i < size; i += 3 + alpha) { \
279 int g = dst [i + 1]; \
294 if (!s->interlace_type) {
295 ptr = s->image_buf + s->image_linesize * s->y;
297 last_row = s->last_row;
299 last_row = ptr - s->image_linesize;
302 last_row, s->row_size, s->bpp);
305 if (s->bit_depth == 16) {
306 deloco_rgb16((uint16_t *)(ptr - s->image_linesize), s->row_size / 2,
309 deloco_rgb8(ptr - s->image_linesize, s->row_size,
314 if (s->y == s->height) {
317 if (s->bit_depth == 16) {
318 deloco_rgb16((uint16_t *)ptr, s->row_size / 2,
321 deloco_rgb8(ptr, s->row_size,
329 ptr = s->image_buf + s->image_linesize * s->y;
335 png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
336 s->last_row, s->pass_row_size, s->bpp);
338 FFSWAP(
unsigned int, s->last_row_size, s->tmp_row_size);
343 s->color_type, s->last_row);
346 if (s->y == s->height) {
347 memset(s->last_row, 0, s->row_size);
358 s->crow_size = s->pass_row_size + 1;
359 if (s->pass_row_size != 0)
378 while (s->
zstream.avail_in > 0) {
379 ret = inflate(&s->
zstream, Z_PARTIAL_FLUSH);
380 if (ret != Z_OK && ret != Z_STREAM_END) {
384 if (s->
zstream.avail_out == 0) {
391 if (ret == Z_STREAM_END && s->
zstream.avail_in > 0) {
393 "%d undecompressed bytes left in buffer\n", s->
zstream.avail_in);
410 zstream.opaque = NULL;
411 if (inflateInit(&zstream) != Z_OK)
413 zstream.next_in = (
unsigned char *)data;
414 zstream.avail_in = data_end -
data;
417 while (zstream.avail_in > 0) {
423 zstream.next_out =
buf;
424 zstream.avail_out = buf_size;
425 ret = inflate(&zstream, Z_PARTIAL_FLUSH);
426 if (ret != Z_OK && ret != Z_STREAM_END) {
430 bp->len += zstream.next_out -
buf;
431 if (ret == Z_STREAM_END)
434 inflateEnd(&zstream);
435 bp->str[bp->len] = 0;
439 inflateEnd(&zstream);
449 for (i = 0; i < size_in; i++)
450 extra += in[i] >= 0x80;
451 if (size_in == SIZE_MAX || extra > SIZE_MAX - size_in - 1)
453 q = out =
av_malloc(size_in + extra + 1);
456 for (i = 0; i < size_in; i++) {
458 *(q++) = 0xC0 | (in[i] >> 6);
459 *(q++) = 0x80 | (in[i] & 0x3F);
475 const uint8_t *keyword_end = memchr(keyword, 0, data_end - keyword);
476 uint8_t *kw_utf8 = NULL, *text, *txt_utf8 = NULL;
482 data = keyword_end + 1;
485 if (data == data_end)
498 text_len = data_end - text;
505 if (!(kw_utf8 && txt_utf8)) {
517 void *
data,
int *got_frame,
522 int buf_size = avpkt->
size;
536 sig = bytestream2_get_be64(&s->
gb);
549 ret = inflateInit(&s->
zstream);
563 length = bytestream2_get_be32(&s->
gb);
568 tag = bytestream2_get_le32(&s->
gb);
573 ((tag >> 16) & 0xff),
574 ((tag >> 24) & 0xff), length);
576 case MKTAG(
'I',
'H',
'D',
'R'):
579 s->
width = bytestream2_get_be32(&s->
gb);
580 s->
height = bytestream2_get_be32(&s->
gb);
595 "compression_type=%d filter_type=%d interlace_type=%d\n",
599 case MKTAG(
'p',
'H',
'Y',
's'):
611 case MKTAG(
'I',
'D',
'A',
'T'):
654 "and color type %d\n",
677 av_dlog(avctx,
"row_size=%d crow_size =%d\n",
683 memcpy(p->
data[1], s->
palette, 256 *
sizeof(uint32_t));
709 case MKTAG(
'P',
'L',
'T',
'E'):
713 if ((length % 3) != 0 || length > 256 * 3)
717 for (i = 0; i <
n; i++) {
718 r = bytestream2_get_byte(&s->
gb);
719 g = bytestream2_get_byte(&s->
gb);
720 b = bytestream2_get_byte(&s->
gb);
721 s->
palette[i] = (0xFF
U << 24) | (r << 16) | (g << 8) | b;
729 case MKTAG(
't',
'R',
'N',
'S'):
738 for (i = 0; i <
length; i++) {
739 v = bytestream2_get_byte(&s->
gb);
745 case MKTAG(
't',
'E',
'X',
't'):
750 case MKTAG(
'z',
'T',
'X',
't'):
755 case MKTAG(
'I',
'E',
'N',
'D'):
775 for (j = 0; j < s->
height; j++) {
777 for (k = 7; k >= 1; k--)
778 if ((s->
width&7) >= k)
779 pd[8*i + k - 1] = (pd[i]>>8-k) & 1;
780 for (i--; i >= 0; i--) {
781 pd[8*i + 7]= pd[i] & 1;
782 pd[8*i + 6]= (pd[i]>>1) & 1;
783 pd[8*i + 5]= (pd[i]>>2) & 1;
784 pd[8*i + 4]= (pd[i]>>3) & 1;
785 pd[8*i + 3]= (pd[i]>>4) & 1;
786 pd[8*i + 2]= (pd[i]>>5) & 1;
787 pd[8*i + 1]= (pd[i]>>6) & 1;
788 pd[8*i + 0]= pd[i]>>7;
796 for (j = 0; j < s->
height; j++) {
799 if ((s->
width&3) >= 3) pd[4*i + 2]= (pd[i] >> 2) & 3;
800 if ((s->
width&3) >= 2) pd[4*i + 1]= (pd[i] >> 4) & 3;
801 if ((s->
width&3) >= 1) pd[4*i + 0]= pd[i] >> 6;
802 for (i--; i >= 0; i--) {
803 pd[4*i + 3]= pd[i] & 3;
804 pd[4*i + 2]= (pd[i]>>2) & 3;
805 pd[4*i + 1]= (pd[i]>>4) & 3;
806 pd[4*i + 0]= pd[i]>>6;
809 if ((s->
width&3) >= 3) pd[4*i + 2]= ((pd[i]>>2) & 3)*0x55;
810 if ((s->
width&3) >= 2) pd[4*i + 1]= ((pd[i]>>4) & 3)*0x55;
811 if ((s->
width&3) >= 1) pd[4*i + 0]= ( pd[i]>>6 )*0x55;
812 for (i--; i >= 0; i--) {
813 pd[4*i + 3]= ( pd[i] & 3)*0x55;
814 pd[4*i + 2]= ((pd[i]>>2) & 3)*0x55;
815 pd[4*i + 1]= ((pd[i]>>4) & 3)*0x55;
816 pd[4*i + 0]= ( pd[i]>>6 )*0x55;
825 for (j = 0; j < s->
height; j++) {
828 if (s->
width&1) pd[2*i+0]= pd[i]>>4;
829 for (i--; i >= 0; i--) {
830 pd[2*i + 1] = pd[i] & 15;
831 pd[2*i + 0] = pd[i] >> 4;
834 if (s->
width & 1) pd[2*i + 0]= (pd[i] >> 4) * 0x11;
835 for (i--; i >= 0; i--) {
836 pd[2*i + 1] = (pd[i] & 15) * 0x11;
837 pd[2*i + 0] = (pd[i] >> 4) * 0x11;
856 for (j = 0; j < s->
height; j++) {
857 for (i = 0; i < s->
width * s->
bpp; i++)