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)
121 switch(filter_type) {
123 memcpy(dst, src, size);
127 memcpy(dst, src, bpp);
133 for(i = 0; i < bpp; i++)
134 dst[i] = src[i] - (top[i] >> 1);
136 dst[i] = src[i] - ((src[i-bpp] + top[i]) >> 1);
139 for(i = 0; i < bpp; i++)
140 dst[i] = src[i] - top[i];
155 int cost, bcost = INT_MAX;
156 uint8_t *buf1 = dst, *buf2 = dst + size + 16;
157 for(pred=0; pred<5; pred++) {
161 for(i=0; i<=
size; i++)
162 cost += abs((int8_t)buf1[i]);
182 bytestream_put_be32(f, length);
183 crc =
crc32(0, Z_NULL, 0);
185 crc =
crc32(crc, tagbuf, 4);
188 crc =
crc32(crc, buf, length);
189 memcpy(*f, buf, length);
192 bytestream_put_be32(f, crc);
202 while (s->
zstream.avail_in > 0) {
203 ret = deflate(&s->
zstream, Z_NO_FLUSH);
206 if (s->
zstream.avail_out == 0) {
217 const AVFrame *pict,
int *got_packet)
220 const AVFrame *
const p = pict;
222 int bits_per_pixel, pass_row_size, enc_row_size;
223 int64_t max_packet_size;
224 int compression_level;
226 uint8_t *crow_base = NULL, *crow_buf, *crow;
227 uint8_t *progressive_buf = NULL;
272 row_size = (avctx->
width * bits_per_pixel + 7) >> 3;
278 Z_DEFAULT_COMPRESSION :
280 ret = deflateInit2(&s->
zstream, compression_level,
281 Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY);
285 enc_row_size = deflateBound(&s->
zstream, row_size);
286 max_packet_size = avctx->
height * (int64_t)(enc_row_size +
289 if (max_packet_size > INT_MAX)
301 crow_buf = crow_base + 15;
302 if (is_progressive) {
303 progressive_buf =
av_malloc(row_size + 1);
304 if (!progressive_buf)
307 if (is_progressive) {
319 s->
buf[8] = bit_depth;
320 s->
buf[9] = color_type;
323 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)
469 s->
dpm = s->
dpi * 10000 / 254;
481 #define OFFSET(x) offsetof(PNGEncContext, x)
482 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM