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;
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++) {
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)
163 for(i = 0; i < w; i++) {
164 int a,
b,
c, p, pa, pb, pc;
177 if (pa <= pb && pa <= pc)
187 #define UNROLL1(bpp, op) {\
189 if(bpp >= 2) g = dst[1];\
190 if(bpp >= 3) b = dst[2];\
191 if(bpp >= 4) a = dst[3];\
192 for(; i <= size - bpp; i+=bpp) {\
193 dst[i+0] = r = op(r, src[i+0], last[i+0]);\
194 if(bpp == 1) continue;\
195 dst[i+1] = g = op(g, src[i+1], last[i+1]);\
196 if(bpp == 2) continue;\
197 dst[i+2] = b = op(b, src[i+2], last[i+2]);\
198 if(bpp == 3) continue;\
199 dst[i+3] = a = op(a, src[i+3], last[i+3]);\
203 #define UNROLL_FILTER(op)\
204 if(bpp == 1) UNROLL1(1, op)\
205 else if(bpp == 2) UNROLL1(2, op)\
206 else if(bpp == 3) UNROLL1(3, op)\
207 else if(bpp == 4) UNROLL1(4, op)\
208 for (; i < size; i++) {\
209 dst[i] = op(dst[i-bpp], src[i], last[i]);\
216 int i, p,
r,
g,
b,
a;
218 switch(filter_type) {
220 memcpy(dst, src, size);
223 for(i = 0; i < bpp; i++) {
228 for(; i <
size; i+=bpp) {
229 int s = *(
int*)(src+i);
230 p = ((s&0x7f7f7f7f) + (p&0x7f7f7f7f)) ^ ((s^p)&0x80808080);
234 #define OP_SUB(x,s,l) x+s
242 for(i = 0; i < bpp; i++) {
246 #define OP_AVG(x,s,l) (((x + l) >> 1) + s) & 0xff
250 for(i = 0; i < bpp; i++) {
254 if(bpp > 2 && size > 4) {
256 int w = bpp==4 ? size : size-3;
267 #define YUV2RGB(NAME, TYPE) \
268 static void deloco_ ## NAME(TYPE *dst, int size, int alpha) \
271 for (i = 0; i < size; i += 3 + alpha) { \
287 if (!s->interlace_type) {
288 ptr = s->image_buf + s->image_linesize * s->y;
290 last_row = s->last_row;
292 last_row = ptr - s->image_linesize;
295 last_row, s->row_size, s->bpp);
298 if (s->bit_depth == 16) {
299 deloco_rgb16((uint16_t *)(ptr - s->image_linesize), s->row_size / 2,
302 deloco_rgb8(ptr - s->image_linesize, s->row_size,
307 if (s->y == s->height) {
310 if (s->bit_depth == 16) {
311 deloco_rgb16((uint16_t *)ptr, s->row_size / 2,
314 deloco_rgb8(ptr, s->row_size,
322 ptr = s->image_buf + s->image_linesize * s->y;
328 png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
329 s->last_row, s->pass_row_size, s->bpp);
335 s->color_type, s->last_row);
338 if (s->y == s->height) {
339 memset(s->last_row, 0, s->row_size);
350 s->crow_size = s->pass_row_size + 1;
351 if (s->pass_row_size != 0)
370 while (s->
zstream.avail_in > 0) {
371 ret = inflate(&s->
zstream, Z_PARTIAL_FLUSH);
372 if (ret != Z_OK && ret != Z_STREAM_END) {
376 if (s->
zstream.avail_out == 0) {
397 zstream.opaque =
NULL;
398 if (inflateInit(&zstream) != Z_OK)
400 zstream.next_in = (
unsigned char *)data;
401 zstream.avail_in = data_end -
data;
404 while (zstream.avail_in > 0) {
410 zstream.next_out = buf;
411 zstream.avail_out = buf_size;
412 ret = inflate(&zstream, Z_PARTIAL_FLUSH);
413 if (ret != Z_OK && ret != Z_STREAM_END) {
417 bp->len += zstream.next_out - buf;
418 if (ret == Z_STREAM_END)
421 inflateEnd(&zstream);
422 bp->str[bp->len] = 0;
426 inflateEnd(&zstream);
436 for (i = 0; i < size_in; i++)
437 extra += in[i] >= 0x80;
438 if (size_in == SIZE_MAX || extra > SIZE_MAX - size_in - 1)
440 q = out =
av_malloc(size_in + extra + 1);
443 for (i = 0; i < size_in; i++) {
445 *(q++) = 0xC0 | (in[i] >> 6);
446 *(q++) = 0x80 | (in[i] & 0x3F);
460 const uint8_t *data_end = data + length;
462 const uint8_t *keyword_end = memchr(keyword, 0, data_end - keyword);
469 data = keyword_end + 1;
472 if (data == data_end)
485 text_len = data_end - text;
492 if (!(kw_utf8 && txt_utf8)) {
504 void *
data,
int *got_frame,
508 int buf_size = avpkt->
size;
514 uint32_t
tag, length;
525 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);
581 av_log(avctx,
AV_LOG_DEBUG,
"width=%d height=%d depth=%d color_type=%d compression_type=%d filter_type=%d interlace_type=%d\n",
585 case MKTAG(
'p',
'H',
'Y',
's'):
597 case MKTAG(
'I',
'D',
'A',
'T'):
640 "and color type %d\n",
666 av_dlog(avctx,
"row_size=%d crow_size =%d\n",
672 memcpy(p->
data[1], s->
palette, 256 *
sizeof(uint32_t));
698 case MKTAG(
'P',
'L',
'T',
'E'):
702 if ((length % 3) != 0 || length > 256 * 3)
707 r = bytestream2_get_byte(&s->
gb);
708 g = bytestream2_get_byte(&s->
gb);
709 b = bytestream2_get_byte(&s->
gb);
710 s->
palette[i] = (0xFF
U << 24) | (r << 16) | (g << 8) | b;
719 case MKTAG(
't',
'R',
'N',
'S'):
728 for(i=0;i<length;i++) {
729 v = bytestream2_get_byte(&s->
gb);
735 case MKTAG(
't',
'E',
'X',
't'):
740 case MKTAG(
'z',
'T',
'X',
't'):
745 case MKTAG(
'I',
'E',
'N',
'D'):
765 for(j=0; j < s->
height; j++) {
766 for(i=s->
width/8-1; i>=0; i--) {
768 pd[8*i+6]= (pd[i]>>1)&1;
769 pd[8*i+5]= (pd[i]>>2)&1;
770 pd[8*i+4]= (pd[i]>>3)&1;
771 pd[8*i+3]= (pd[i]>>4)&1;
772 pd[8*i+2]= (pd[i]>>5)&1;
773 pd[8*i+1]= (pd[i]>>6)&1;
782 for(j=0; j < s->
height; j++) {
785 if ((s->
width&3) >= 3) pd[4*i+2]= (pd[i]>>2)&3;
786 if ((s->
width&3) >= 2) pd[4*i+1]= (pd[i]>>4)&3;
787 if ((s->
width&3) >= 1) pd[4*i+0]= pd[i]>>6;
788 for(i--; i>=0; i--) {
790 pd[4*i+2]= (pd[i]>>2)&3;
791 pd[4*i+1]= (pd[i]>>4)&3;
795 if ((s->
width&3) >= 3) pd[4*i+2]= ((pd[i]>>2)&3)*0x55;
796 if ((s->
width&3) >= 2) pd[4*i+1]= ((pd[i]>>4)&3)*0x55;
797 if ((s->
width&3) >= 1) pd[4*i+0]= ( pd[i]>>6 )*0x55;
798 for(i--; i>=0; i--) {
799 pd[4*i+3]= ( pd[i] &3)*0x55;
800 pd[4*i+2]= ((pd[i]>>2)&3)*0x55;
801 pd[4*i+1]= ((pd[i]>>4)&3)*0x55;
802 pd[4*i+0]= ( pd[i]>>6 )*0x55;
811 for(j=0; j < s->
height; j++) {
814 if (s->
width&1) pd[2*i+0]= pd[i]>>4;
815 for(i--; i>=0; i--) {
820 if (s->
width&1) pd[2*i+0]= (pd[i]>>4)*0x11;
821 for(i--; i>=0; i--) {
822 pd[2*i+1]= (pd[i]&15)*0x11;
823 pd[2*i+0]= (pd[i]>>4)*0x11;
841 for(j=0; j < s->
height; j++) {
842 for(i=0; i < s->
width * s->
bpp; i++) {