75 0x01, 0x01, 0x11, 0x11, 0x55, 0x55, 0xff,
80 0xff, 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
85 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff
92 int bits_per_pixel,
int pass,
93 int color_type,
const uint8_t *src)
95 int x,
mask, dsp_mask, j, src_x,
b, bpp;
102 switch (bits_per_pixel) {
105 for (x = 0; x <
width; x++) {
107 if ((dsp_mask << j) & 0x80) {
108 b = (src[src_x >> 3] >> (7 - (src_x & 7))) & 1;
109 dst[x >> 3] &= 0xFF7F>>j;
110 dst[x >> 3] |= b << (7 - j);
112 if ((mask << j) & 0x80)
118 for (x = 0; x <
width; x++) {
119 int j2 = 2 * (x & 3);
121 if ((dsp_mask << j) & 0x80) {
122 b = (src[src_x >> 2] >> (6 - 2*(src_x & 3))) & 3;
123 dst[x >> 2] &= 0xFF3F>>j2;
124 dst[x >> 2] |= b << (6 - j2);
126 if ((mask << j) & 0x80)
132 for (x = 0; x <
width; x++) {
135 if ((dsp_mask << j) & 0x80) {
136 b = (src[src_x >> 1] >> (4 - 4*(src_x & 1))) & 15;
137 dst[x >> 1] &= 0xFF0F>>j2;
138 dst[x >> 1] |= b << (4 - j2);
140 if ((mask << j) & 0x80)
145 bpp = bits_per_pixel >> 3;
148 for (x = 0; x <
width; x++) {
150 if ((dsp_mask << j) & 0x80) {
154 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) {\
190 if(bpp >= 2) g = dst[1];\
191 if(bpp >= 3) b = dst[2];\
192 if(bpp >= 4) a = dst[3];\
193 for(; i <= size - bpp; i+=bpp) {\
194 dst[i+0] = r = op(r, src[i+0], last[i+0]);\
195 if(bpp == 1) continue;\
196 dst[i+1] = g = op(g, src[i+1], last[i+1]);\
197 if(bpp == 2) continue;\
198 dst[i+2] = b = op(b, src[i+2], last[i+2]);\
199 if(bpp == 3) continue;\
200 dst[i+3] = a = op(a, src[i+3], last[i+3]);\
204 #define UNROLL_FILTER(op)\
205 if(bpp == 1) UNROLL1(1, op)\
206 else if(bpp == 2) UNROLL1(2, op)\
207 else if(bpp == 3) UNROLL1(3, op)\
208 else if(bpp == 4) UNROLL1(4, op)\
209 for (; i < size; i++) {\
210 dst[i] = op(dst[i-bpp], src[i], last[i]);\
217 int i, p,
r,
g,
b,
a;
219 switch (filter_type) {
221 memcpy(dst, src, size);
224 for (i = 0; i < bpp; i++) {
229 for (; i <
size; i += bpp) {
230 int s = *(
int*)(src + i);
231 p = ((s & 0x7f7f7f7f) + (p & 0x7f7f7f7f)) ^ ((s ^ p) & 0x80808080);
232 *(
int*)(dst + i) = p;
235 #define OP_SUB(x,s,l) x+s
243 for (i = 0; i < bpp; i++) {
247 #define OP_AVG(x,s,l) (((x + l) >> 1) + s) & 0xff
251 for (i = 0; i < bpp; i++) {
255 if (bpp > 2 && size > 4) {
257 int w = bpp == 4 ? size : size - 3;
268 #define YUV2RGB(NAME, TYPE) \
269 static void deloco_ ## NAME(TYPE *dst, int size, int alpha) \
272 for (i = 0; i < size; i += 3 + alpha) { \
288 if (!s->interlace_type) {
289 ptr = s->image_buf + s->image_linesize * s->y;
291 last_row = s->last_row;
293 last_row = ptr - s->image_linesize;
296 last_row, s->row_size, s->bpp);
299 if (s->bit_depth == 16) {
300 deloco_rgb16((uint16_t *)(ptr - s->image_linesize), s->row_size / 2,
303 deloco_rgb8(ptr - s->image_linesize, s->row_size,
308 if (s->y == s->height) {
311 if (s->bit_depth == 16) {
312 deloco_rgb16((uint16_t *)ptr, s->row_size / 2,
315 deloco_rgb8(ptr, s->row_size,
323 ptr = s->image_buf + s->image_linesize * s->y;
329 png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
330 s->last_row, s->pass_row_size, s->bpp);
336 s->color_type, s->last_row);
339 if (s->y == s->height) {
340 memset(s->last_row, 0, s->row_size);
351 s->crow_size = s->pass_row_size + 1;
352 if (s->pass_row_size != 0)
371 while (s->
zstream.avail_in > 0) {
372 ret = inflate(&s->
zstream, Z_PARTIAL_FLUSH);
373 if (ret != Z_OK && ret != Z_STREAM_END) {
377 if (s->
zstream.avail_out == 0) {
398 zstream.opaque =
NULL;
399 if (inflateInit(&zstream) != Z_OK)
401 zstream.next_in = (
unsigned char *)data;
402 zstream.avail_in = data_end -
data;
405 while (zstream.avail_in > 0) {
411 zstream.next_out = buf;
412 zstream.avail_out = buf_size;
413 ret = inflate(&zstream, Z_PARTIAL_FLUSH);
414 if (ret != Z_OK && ret != Z_STREAM_END) {
418 bp->len += zstream.next_out - buf;
419 if (ret == Z_STREAM_END)
422 inflateEnd(&zstream);
423 bp->str[bp->len] = 0;
427 inflateEnd(&zstream);
437 for (i = 0; i < size_in; i++)
438 extra += in[i] >= 0x80;
439 if (size_in == SIZE_MAX || extra > SIZE_MAX - size_in - 1)
441 q = out =
av_malloc(size_in + extra + 1);
444 for (i = 0; i < size_in; i++) {
446 *(q++) = 0xC0 | (in[i] >> 6);
447 *(q++) = 0x80 | (in[i] & 0x3F);
461 const uint8_t *data_end = data + length;
463 const uint8_t *keyword_end = memchr(keyword, 0, data_end - keyword);
470 data = keyword_end + 1;
473 if (data == data_end)
486 text_len = data_end - text;
493 if (!(kw_utf8 && txt_utf8)) {
505 void *
data,
int *got_frame,
510 int buf_size = avpkt->
size;
515 uint32_t
tag, length;
526 sig = bytestream2_get_be64(&s->
gb);
539 ret = inflateInit(&s->
zstream);
550 length = bytestream2_get_be32(&s->
gb);
555 tag = bytestream2_get_le32(&s->
gb);
560 ((tag >> 16) & 0xff),
561 ((tag >> 24) & 0xff), length);
563 case MKTAG(
'I',
'H',
'D',
'R'):
566 s->
width = bytestream2_get_be32(&s->
gb);
567 s->
height = bytestream2_get_be32(&s->
gb);
582 "compression_type=%d filter_type=%d interlace_type=%d\n",
586 case MKTAG(
'p',
'H',
'Y',
's'):
598 case MKTAG(
'I',
'D',
'A',
'T'):
641 "and color type %d\n",
667 av_dlog(avctx,
"row_size=%d crow_size =%d\n",
673 memcpy(p->
data[1], s->
palette, 256 *
sizeof(uint32_t));
699 case MKTAG(
'P',
'L',
'T',
'E'):
703 if ((length % 3) != 0 || length > 256 * 3)
707 for (i = 0; i < n; i++) {
708 r = bytestream2_get_byte(&s->
gb);
709 g = bytestream2_get_byte(&s->
gb);
710 b = bytestream2_get_byte(&s->
gb);
711 s->
palette[i] = (0xFF
U << 24) | (r << 16) | (g << 8) | b;
713 for (; i < 256; i++) {
720 case MKTAG(
't',
'R',
'N',
'S'):
729 for (i = 0; i < length; i++) {
730 v = bytestream2_get_byte(&s->
gb);
736 case MKTAG(
't',
'E',
'X',
't'):
741 case MKTAG(
'z',
'T',
'X',
't'):
746 case MKTAG(
'I',
'E',
'N',
'D'):
766 for (j = 0; j < s->
height; j++) {
768 for (k = 7; k >= 1; k--)
769 if ((s->
width&7) >= k)
770 pd[8*i + k - 1] = (pd[i]>>8-k) & 1;
771 for (i--; i >= 0; i--) {
772 pd[8*i + 7]= pd[i] & 1;
773 pd[8*i + 6]= (pd[i]>>1) & 1;
774 pd[8*i + 5]= (pd[i]>>2) & 1;
775 pd[8*i + 4]= (pd[i]>>3) & 1;
776 pd[8*i + 3]= (pd[i]>>4) & 1;
777 pd[8*i + 2]= (pd[i]>>5) & 1;
778 pd[8*i + 1]= (pd[i]>>6) & 1;
779 pd[8*i + 0]= pd[i]>>7;
787 for (j = 0; j < s->
height; j++) {
790 if ((s->
width&3) >= 3) pd[4*i + 2]= (pd[i] >> 2) & 3;
791 if ((s->
width&3) >= 2) pd[4*i + 1]= (pd[i] >> 4) & 3;
792 if ((s->
width&3) >= 1) pd[4*i + 0]= pd[i] >> 6;
793 for (i--; i >= 0; i--) {
794 pd[4*i + 3]= pd[i] & 3;
795 pd[4*i + 2]= (pd[i]>>2) & 3;
796 pd[4*i + 1]= (pd[i]>>4) & 3;
797 pd[4*i + 0]= pd[i]>>6;
800 if ((s->
width&3) >= 3) pd[4*i + 2]= ((pd[i]>>2) & 3)*0x55;
801 if ((s->
width&3) >= 2) pd[4*i + 1]= ((pd[i]>>4) & 3)*0x55;
802 if ((s->
width&3) >= 1) pd[4*i + 0]= ( pd[i]>>6 )*0x55;
803 for (i--; i >= 0; i--) {
804 pd[4*i + 3]= ( pd[i] & 3)*0x55;
805 pd[4*i + 2]= ((pd[i]>>2) & 3)*0x55;
806 pd[4*i + 1]= ((pd[i]>>4) & 3)*0x55;
807 pd[4*i + 0]= ( pd[i]>>6 )*0x55;
816 for (j = 0; j < s->
height; j++) {
819 if (s->
width&1) pd[2*i+0]= pd[i]>>4;
820 for (i--; i >= 0; i--) {
821 pd[2*i + 1] = pd[i] & 15;
822 pd[2*i + 0] = pd[i] >> 4;
825 if (s->
width & 1) pd[2*i + 0]= (pd[i] >> 4) * 0x11;
826 for (i--; i >= 0; i--) {
827 pd[2*i + 1] = (pd[i] & 15) * 0x11;
828 pd[2*i + 0] = (pd[i] >> 4) * 0x11;
846 for (j = 0; j < s->
height; j++) {
847 for (i = 0; i < s->
width * s->
bpp; i++) {