35 #define IOBUF_SIZE 4096
54 int bits_per_pixel,
int pass,
57 int x,
mask, dst_x, j,
b, bpp;
60 static const int masks[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
63 switch (bits_per_pixel) {
65 memset(dst, 0, row_size);
67 for (x = 0; x <
width; x++) {
69 if ((mask << j) & 0x80) {
70 b = (src[x >> 3] >> (7 - j)) & 1;
71 dst[dst_x >> 3] |= b << (7 - (dst_x & 7));
77 bpp = bits_per_pixel >> 3;
80 for (x = 0; x <
width; x++) {
82 if ((mask << j) & 0x80) {
96 for (i = 0; i < w; i++) {
97 int a,
b,
c, p, pa, pb, pc;
110 if (pa <= pb && pa <= pc)
122 const uint8_t *src1 = src + bpp;
126 memcpy(dst, src, bpp);
129 unaligned_w =
FFMIN(32 - bpp, size);
130 for (x = 0; x < unaligned_w; x++)
131 *dst++ = *src1++ - *src2++;
141 switch (filter_type) {
143 memcpy(dst, src, size);
152 for (i = 0; i < bpp; i++)
153 dst[i] = src[i] - (top[i] >> 1);
154 for (; i <
size; i++)
155 dst[i] = src[i] - ((src[i - bpp] + top[i]) >> 1);
158 for (i = 0; i < bpp; i++)
159 dst[i] = src[i] - top[i];
174 int cost, bcost = INT_MAX;
175 uint8_t *buf1 = dst, *buf2 = dst + size + 16;
176 for (pred = 0; pred < 5; pred++) {
180 for (i = 0; i <=
size; i++)
181 cost += abs((int8_t) buf1[i]);
201 bytestream_put_be32(f, length);
202 crc =
crc32(0, Z_NULL, 0);
204 crc =
crc32(crc, tagbuf, 4);
207 crc =
crc32(crc, buf, length);
208 memcpy(*f, buf, length);
211 bytestream_put_be32(f, crc);
221 while (s->
zstream.avail_in > 0) {
222 ret = deflate(&s->
zstream, Z_NO_FLUSH);
225 if (s->
zstream.avail_out == 0) {
236 #define AV_WB32_PNG(buf, n) AV_WB32(buf, lrint((n) * 100000))
239 double rx, ry, gx, gy, bx, by, wx = 0.3127, wy = 0.3290;
242 rx = 0.640; ry = 0.330;
243 gx = 0.300; gy = 0.600;
244 bx = 0.150; by = 0.060;
247 rx = 0.670; ry = 0.330;
248 gx = 0.210; gy = 0.710;
249 bx = 0.140; by = 0.080;
250 wx = 0.310; wy = 0.316;
253 rx = 0.640; ry = 0.330;
254 gx = 0.290; gy = 0.600;
255 bx = 0.150; by = 0.060;
259 rx = 0.630; ry = 0.340;
260 gx = 0.310; gy = 0.595;
261 bx = 0.155; by = 0.070;
264 rx = 0.708; ry = 0.292;
265 gx = 0.170; gy = 0.797;
266 bx = 0.131; by = 0.046;
290 const AVFrame *pict,
int *got_packet)
295 int bits_per_pixel, pass_row_size, enc_row_size;
296 int64_t max_packet_size;
297 int compression_level;
298 uint8_t *ptr, *top, *crow_buf, *crow;
349 row_size = (avctx->
width * bits_per_pixel + 7) >> 3;
355 ? Z_DEFAULT_COMPRESSION
357 ret = deflateInit2(&s->
zstream, compression_level,
358 Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY);
362 enc_row_size = deflateBound(&s->
zstream, row_size);
363 max_packet_size = avctx->
height * (int64_t)(enc_row_size +
366 if (max_packet_size > INT_MAX)
379 crow_buf = crow_base + 15;
380 if (is_progressive) {
381 progressive_buf =
av_malloc(row_size + 1);
382 if (!progressive_buf)
385 if (is_progressive) {
397 s->
buf[8] = bit_depth;
398 s->
buf[9] = color_type;
401 s->
buf[12] = is_progressive;
430 int has_alpha,
alpha, i;
435 palette = (uint32_t *)p->
data[1];
437 alpha_ptr = s->
buf + 256 * 3;
439 for (i = 0; i < 256; i++) {
444 *alpha_ptr++ =
alpha;
445 bytestream_put_be24(&ptr, v);
448 MKTAG(
'P',
'L',
'T',
'E'), s->
buf, 256 * 3);
451 MKTAG(
't',
'R',
'N',
'S'), s->
buf + 256 * 3, 256);
458 if (is_progressive) {
461 for (pass = 0; pass <
NB_PASSES; pass++) {
465 if (pass_row_size > 0) {
467 for (y = 0; y < avctx->
height; y++)
472 bits_per_pixel, pass,
475 top, pass_row_size, bits_per_pixel >> 3);
477 top = progressive_buf;
483 for (y = 0; y < avctx->
height; y++) {
486 row_size, bits_per_pixel >> 3);
493 ret = deflate(&s->
zstream, Z_FINISH);
494 if (ret == Z_OK || ret == Z_STREAM_END) {
501 if (ret == Z_STREAM_END)
565 s->
dpm = s->
dpi * 10000 / 254;
577 #define OFFSET(x) offsetof(PNGEncContext, x)
578 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM