37 #define IOBUF_SIZE 4096
54 int bits_per_pixel,
int pass,
57 int x,
mask, dst_x, j,
b, bpp;
61 mask = (
int[]){0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}[
pass];
62 switch(bits_per_pixel) {
64 memset(dst, 0, row_size);
66 for(x = 0; x <
width; x++) {
68 if ((mask << j) & 0x80) {
69 b = (src[x >> 3] >> (7 - j)) & 1;
70 dst[dst_x >> 3] |= b << (7 - (dst_x & 7));
76 bpp = bits_per_pixel >> 3;
79 for(x = 0; x <
width; x++) {
81 if ((mask << j) & 0x80) {
94 for(i = 0; i < w; i++) {
95 int a,
b,
c, p, pa, pb, pc;
108 if (pa <= pb && pa <= pc)
123 switch(filter_type) {
125 memcpy(dst, src, size);
129 memcpy(dst, src, bpp);
135 for(i = 0; i < bpp; i++)
136 dst[i] = src[i] - (top[i] >> 1);
138 dst[i] = src[i] - ((src[i-bpp] + top[i]) >> 1);
141 for(i = 0; i < bpp; i++)
142 dst[i] = src[i] - top[i];
157 int cost, bcost = INT_MAX;
159 for(pred=0; pred<5; pred++) {
163 for(i=0; i<=
size; i++)
164 cost += abs((int8_t)buf1[i]);
179 const uint8_t *buf,
int length)
184 bytestream_put_be32(f, length);
185 crc = crc32(0, Z_NULL, 0);
187 crc = crc32(crc, tagbuf, 4);
190 crc = crc32(crc, buf, length);
191 memcpy(*f, buf, length);
194 bytestream_put_be32(f, crc);
204 while (s->
zstream.avail_in > 0) {
205 ret = deflate(&s->
zstream, Z_NO_FLUSH);
208 if (s->
zstream.avail_out == 0) {
219 const AVFrame *pict,
int *got_packet)
223 int bit_depth, color_type,
y,
len, row_size, ret, is_progressive;
224 int bits_per_pixel, pass_row_size, enc_row_size;
225 int64_t max_packet_size;
226 int compression_level;
278 row_size = (avctx->
width * bits_per_pixel + 7) >> 3;
284 Z_DEFAULT_COMPRESSION :
286 ret = deflateInit2(&s->
zstream, compression_level,
287 Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY);
291 enc_row_size = deflateBound(&s->
zstream, row_size);
292 max_packet_size = avctx->
height * (int64_t)(enc_row_size +
295 if (max_packet_size > INT_MAX)
307 crow_buf = crow_base + 15;
308 if (is_progressive) {
309 progressive_buf =
av_malloc(row_size + 1);
310 if (!progressive_buf)
313 if (is_progressive) {
325 s->
buf[8] = bit_depth;
326 s->
buf[9] = color_type;
329 s->
buf[12] = is_progressive;
340 int has_alpha,
alpha, i;
345 palette = (uint32_t *)p->
data[1];
347 alpha_ptr = s->
buf + 256 * 3;
349 for(i = 0; i < 256; i++) {
354 *alpha_ptr++ =
alpha;
355 bytestream_put_be24(&ptr, v);
366 if (is_progressive) {
369 for(pass = 0; pass <
NB_PASSES; pass++) {
373 if (pass_row_size > 0) {
375 for(y = 0; y < avctx->
height; y++) {
380 bits_per_pixel, pass,
382 crow =
png_choose_filter(s, crow_buf, progressive_buf, top, pass_row_size, bits_per_pixel>>3);
384 top = progressive_buf;
391 for(y = 0; y < avctx->
height; y++) {
400 ret = deflate(&s->
zstream, Z_FINISH);
401 if (ret == Z_OK || ret == Z_STREAM_END) {
408 if (ret == Z_STREAM_END)