32 #define IOBUF_SIZE 4096
51 int bits_per_pixel,
int pass,
54 int x,
mask, dst_x, j,
b, bpp;
57 static const int masks[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
60 switch(bits_per_pixel) {
62 memset(dst, 0, row_size);
64 for(x = 0; x <
width; x++) {
66 if ((mask << j) & 0x80) {
67 b = (src[x >> 3] >> (7 - j)) & 1;
68 dst[dst_x >> 3] |= b << (7 - (dst_x & 7));
74 bpp = bits_per_pixel >> 3;
77 for(x = 0; x <
width; x++) {
79 if ((mask << j) & 0x80) {
92 for(i = 0; i < w; i++) {
93 int a,
b,
c, p, pa, pb, pc;
106 if (pa <= pb && pa <= pc)
118 const uint8_t *src1 = src + bpp;
122 memcpy(dst, src, bpp);
125 unaligned_w =
FFMIN(32 - bpp, size);
126 for (x = 0; x < unaligned_w; x++)
127 *dst++ = *src1++ - *src2++;
137 switch(filter_type) {
139 memcpy(dst, src, size);
148 for(i = 0; i < bpp; i++)
149 dst[i] = src[i] - (top[i] >> 1);
151 dst[i] = src[i] - ((src[i-bpp] + top[i]) >> 1);
154 for(i = 0; i < bpp; i++)
155 dst[i] = src[i] - top[i];
170 int cost, bcost = INT_MAX;
171 uint8_t *buf1 = dst, *buf2 = dst + size + 16;
172 for(pred=0; pred<5; pred++) {
176 for(i=0; i<=
size; i++)
177 cost += abs((int8_t)buf1[i]);
197 bytestream_put_be32(f, length);
198 crc =
crc32(0, Z_NULL, 0);
200 crc =
crc32(crc, tagbuf, 4);
203 crc =
crc32(crc, buf, length);
204 memcpy(*f, buf, length);
207 bytestream_put_be32(f, crc);
217 while (s->
zstream.avail_in > 0) {
218 ret = deflate(&s->
zstream, Z_NO_FLUSH);
221 if (s->
zstream.avail_out == 0) {
232 const AVFrame *pict,
int *got_packet)
235 const AVFrame *
const p = pict;
237 int bits_per_pixel, pass_row_size, enc_row_size;
238 int64_t max_packet_size;
239 int compression_level;
241 uint8_t *crow_base = NULL, *crow_buf, *crow;
242 uint8_t *progressive_buf = NULL;
287 row_size = (avctx->
width * bits_per_pixel + 7) >> 3;
293 Z_DEFAULT_COMPRESSION :
295 ret = deflateInit2(&s->
zstream, compression_level,
296 Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY);
300 enc_row_size = deflateBound(&s->
zstream, row_size);
301 max_packet_size = avctx->
height * (int64_t)(enc_row_size +
304 if (max_packet_size > INT_MAX)
316 crow_buf = crow_base + 15;
317 if (is_progressive) {
318 progressive_buf =
av_malloc(row_size + 1);
319 if (!progressive_buf)
322 if (is_progressive) {
334 s->
buf[8] = bit_depth;
335 s->
buf[9] = color_type;
338 s->
buf[12] = is_progressive;
355 int has_alpha,
alpha, i;
360 palette = (uint32_t *)p->
data[1];
362 alpha_ptr = s->
buf + 256 * 3;
364 for(i = 0; i < 256; i++) {
369 *alpha_ptr++ =
alpha;
370 bytestream_put_be24(&ptr, v);
381 if (is_progressive) {
384 for(pass = 0; pass <
NB_PASSES; pass++) {
388 if (pass_row_size > 0) {
390 for(y = 0; y < avctx->
height; y++) {
395 bits_per_pixel, pass,
397 crow =
png_choose_filter(s, crow_buf, progressive_buf, top, pass_row_size, bits_per_pixel>>3);
399 top = progressive_buf;
406 for(y = 0; y < avctx->
height; y++) {
415 ret = deflate(&s->
zstream, Z_FINISH);
416 if (ret == Z_OK || ret == Z_STREAM_END) {
423 if (ret == Z_STREAM_END)
484 s->
dpm = s->
dpi * 10000 / 254;
496 #define OFFSET(x) offsetof(PNGEncContext, x)
497 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM