34 #define IOBUF_SIZE 4096
51 int bits_per_pixel,
int pass,
52 const uint8_t *src,
int width)
54 int x,
mask, dst_x, j,
b, bpp;
59 switch(bits_per_pixel) {
61 memset(dst, 0, row_size);
63 for(x = 0; x <
width; x++) {
65 if ((mask << j) & 0x80) {
66 b = (src[x >> 3] >> (7 - j)) & 1;
67 dst[dst_x >> 3] |= b << (7 - (dst_x & 7));
73 bpp = bits_per_pixel >> 3;
76 for(x = 0; x <
width; x++) {
78 if ((mask << j) & 0x80) {
91 for(i = 0; i < w; i++) {
92 int a,
b, c, p, pa, pb, pc;
105 if (pa <= pb && pa <= pc)
116 uint8_t *src, uint8_t *top,
int size,
int bpp)
120 switch(filter_type) {
122 memcpy(dst, src, size);
126 memcpy(dst, src, bpp);
132 for(i = 0; i < bpp; i++)
133 dst[i] = src[i] - (top[i] >> 1);
135 dst[i] = src[i] - ((src[i-bpp] + top[i]) >> 1);
138 for(i = 0; i < bpp; i++)
139 dst[i] = src[i] - top[i];
146 uint8_t *src, uint8_t *top,
int size,
int bpp)
149 assert(bpp || !pred);
154 int cost, bcost = INT_MAX;
155 uint8_t *buf1 = dst, *buf2 = dst + size + 16;
156 for(pred=0; pred<5; pred++) {
160 for(i=0; i<=
size; i++)
161 cost += abs((int8_t)buf1[i]);
164 FFSWAP(uint8_t*, buf1, buf2);
182 for(j = 0; j <
width; j++) {
183 v = ((
const uint32_t *)src)[j];
193 const uint8_t *buf,
int length)
198 bytestream_put_be32(f, length);
199 crc = crc32(0, Z_NULL, 0);
201 crc = crc32(crc, tagbuf, 4);
204 crc = crc32(crc, buf, length);
205 memcpy(*f, buf, length);
208 bytestream_put_be32(f, crc);
217 s->
zstream.next_in = (uint8_t *)data;
218 while (s->
zstream.avail_in > 0) {
219 ret = deflate(&s->
zstream, Z_NO_FLUSH);
222 if (s->
zstream.avail_out == 0) {
236 int bit_depth, color_type, y,
len, row_size, ret, is_progressive;
237 int bits_per_pixel, pass_row_size;
238 int compression_level;
240 uint8_t *crow_base =
NULL, *crow_buf, *crow;
241 uint8_t *progressive_buf =
NULL;
242 uint8_t *rgba_buf =
NULL;
243 uint8_t *top_buf =
NULL;
279 row_size = (avctx->
width * bits_per_pixel + 7) >> 3;
285 Z_DEFAULT_COMPRESSION :
287 ret = deflateInit2(&s->
zstream, compression_level,
288 Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY);
294 crow_buf = crow_base + 15;
295 if (is_progressive) {
296 progressive_buf =
av_malloc(row_size + 1);
297 if (!progressive_buf)
317 s->
buf[8] = bit_depth;
318 s->
buf[9] = color_type;
321 s->
buf[12] = is_progressive;
327 int has_alpha, alpha, i;
332 palette = (uint32_t *)p->
data[1];
334 alpha_ptr = s->
buf + 256 * 3;
336 for(i = 0; i < 256; i++) {
339 if (alpha && alpha != 0xff)
341 *alpha_ptr++ = alpha;
342 bytestream_put_be24(&ptr, v);
353 if (is_progressive) {
356 for(pass = 0; pass <
NB_PASSES; pass++) {
360 if (pass_row_size > 0) {
362 for(y = 0; y < avctx->
height; y++) {
365 FFSWAP(uint8_t*, progressive_buf, top_buf);
371 bits_per_pixel, pass,
373 crow =
png_choose_filter(s, crow_buf, progressive_buf, top, pass_row_size, bits_per_pixel>>3);
375 top = progressive_buf;
382 for(y = 0; y < avctx->
height; y++) {
385 FFSWAP(uint8_t*, rgba_buf, top_buf);
396 ret = deflate(&s->
zstream, Z_FINISH);
397 if (ret == Z_OK || ret == Z_STREAM_END) {
404 if (ret == Z_STREAM_END)