FFmpeg
pngenc.c
Go to the documentation of this file.
1 /*
2  * PNG image format
3  * Copyright (c) 2003 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "avcodec.h"
23 #include "codec_internal.h"
24 #include "encode.h"
25 #include "bytestream.h"
26 #include "lossless_videoencdsp.h"
27 #include "png.h"
28 #include "apng.h"
29 #include "zlib_wrapper.h"
30 
31 #include "libavutil/avassert.h"
32 #include "libavutil/crc.h"
33 #include "libavutil/csp.h"
34 #include "libavutil/libm.h"
35 #include "libavutil/opt.h"
36 #include "libavutil/rational.h"
37 #include "libavutil/stereo3d.h"
38 
39 #include <zlib.h>
40 
41 #define IOBUF_SIZE 4096
42 
43 typedef struct APNGFctlChunk {
44  uint32_t sequence_number;
45  uint32_t width, height;
46  uint32_t x_offset, y_offset;
47  uint16_t delay_num, delay_den;
48  uint8_t dispose_op, blend_op;
50 
51 typedef struct PNGEncContext {
52  AVClass *class;
54 
55  uint8_t *bytestream;
56  uint8_t *bytestream_start;
57  uint8_t *bytestream_end;
58 
60 
62  uint8_t buf[IOBUF_SIZE];
63  int dpi; ///< Physical pixel density, in dots per inch, if set
64  int dpm; ///< Physical pixel density, in dots per meter, if set
65 
67  int bit_depth;
70 
71  // APNG
72  uint32_t palette_checksum; // Used to ensure a single unique palette
73  uint32_t sequence_number;
75  uint8_t *extra_data;
77 
84 
85 static void png_get_interlaced_row(uint8_t *dst, int row_size,
86  int bits_per_pixel, int pass,
87  const uint8_t *src, int width)
88 {
89  int x, mask, dst_x, j, b, bpp;
90  uint8_t *d;
91  const uint8_t *s;
92  static const int masks[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
93 
94  mask = masks[pass];
95  switch (bits_per_pixel) {
96  case 1:
97  memset(dst, 0, row_size);
98  dst_x = 0;
99  for (x = 0; x < width; x++) {
100  j = (x & 7);
101  if ((mask << j) & 0x80) {
102  b = (src[x >> 3] >> (7 - j)) & 1;
103  dst[dst_x >> 3] |= b << (7 - (dst_x & 7));
104  dst_x++;
105  }
106  }
107  break;
108  default:
109  bpp = bits_per_pixel >> 3;
110  d = dst;
111  s = src;
112  for (x = 0; x < width; x++) {
113  j = x & 7;
114  if ((mask << j) & 0x80) {
115  memcpy(d, s, bpp);
116  d += bpp;
117  }
118  s += bpp;
119  }
120  break;
121  }
122 }
123 
124 static void sub_png_paeth_prediction(uint8_t *dst, const uint8_t *src, const uint8_t *top,
125  int w, int bpp)
126 {
127  int i;
128  for (i = 0; i < w; i++) {
129  int a, b, c, p, pa, pb, pc;
130 
131  a = src[i - bpp];
132  b = top[i];
133  c = top[i - bpp];
134 
135  p = b - c;
136  pc = a - c;
137 
138  pa = abs(p);
139  pb = abs(pc);
140  pc = abs(p + pc);
141 
142  if (pa <= pb && pa <= pc)
143  p = a;
144  else if (pb <= pc)
145  p = b;
146  else
147  p = c;
148  dst[i] = src[i] - p;
149  }
150 }
151 
152 static void sub_left_prediction(PNGEncContext *c, uint8_t *dst, const uint8_t *src, int bpp, int size)
153 {
154  const uint8_t *src1 = src + bpp;
155  const uint8_t *src2 = src;
156  int x, unaligned_w;
157 
158  memcpy(dst, src, bpp);
159  dst += bpp;
160  size -= bpp;
161  unaligned_w = FFMIN(32 - bpp, size);
162  for (x = 0; x < unaligned_w; x++)
163  *dst++ = *src1++ - *src2++;
164  size -= unaligned_w;
165  c->llvidencdsp.diff_bytes(dst, src1, src2, size);
166 }
167 
168 static void png_filter_row(PNGEncContext *c, uint8_t *dst, int filter_type,
169  const uint8_t *src, const uint8_t *top, int size, int bpp)
170 {
171  int i;
172 
173  switch (filter_type) {
175  memcpy(dst, src, size);
176  break;
178  sub_left_prediction(c, dst, src, bpp, size);
179  break;
180  case PNG_FILTER_VALUE_UP:
181  c->llvidencdsp.diff_bytes(dst, src, top, size);
182  break;
184  for (i = 0; i < bpp; i++)
185  dst[i] = src[i] - (top[i] >> 1);
186  for (; i < size; i++)
187  dst[i] = src[i] - ((src[i - bpp] + top[i]) >> 1);
188  break;
190  for (i = 0; i < bpp; i++)
191  dst[i] = src[i] - top[i];
192  sub_png_paeth_prediction(dst + i, src + i, top + i, size - i, bpp);
193  break;
194  }
195 }
196 
197 static uint8_t *png_choose_filter(PNGEncContext *s, uint8_t *dst,
198  const uint8_t *src, const uint8_t *top, int size, int bpp)
199 {
200  int pred = s->filter_type;
201  av_assert0(bpp || !pred);
202  if (!top && pred)
204  if (pred == PNG_FILTER_VALUE_MIXED) {
205  int i;
206  int cost, bcost = INT_MAX;
207  uint8_t *buf1 = dst, *buf2 = dst + size + 16;
208  for (pred = 0; pred < 5; pred++) {
209  png_filter_row(s, buf1 + 1, pred, src, top, size, bpp);
210  buf1[0] = pred;
211  cost = 0;
212  for (i = 0; i <= size; i++)
213  cost += abs((int8_t) buf1[i]);
214  if (cost < bcost) {
215  bcost = cost;
216  FFSWAP(uint8_t *, buf1, buf2);
217  }
218  }
219  return buf2;
220  } else {
221  png_filter_row(s, dst + 1, pred, src, top, size, bpp);
222  dst[0] = pred;
223  return dst;
224  }
225 }
226 
227 static void png_write_chunk(uint8_t **f, uint32_t tag,
228  const uint8_t *buf, int length)
229 {
230  const AVCRC *crc_table = av_crc_get_table(AV_CRC_32_IEEE_LE);
231  uint32_t crc = ~0U;
232  uint8_t tagbuf[4];
233 
234  bytestream_put_be32(f, length);
235  AV_WL32(tagbuf, tag);
236  crc = av_crc(crc_table, crc, tagbuf, 4);
237  bytestream_put_be32(f, av_bswap32(tag));
238  if (length > 0) {
239  crc = av_crc(crc_table, crc, buf, length);
240  if (*f != buf)
241  memcpy(*f, buf, length);
242  *f += length;
243  }
244  bytestream_put_be32(f, ~crc);
245 }
246 
248  const uint8_t *buf, int length)
249 {
250  PNGEncContext *s = avctx->priv_data;
251  const AVCRC *crc_table = av_crc_get_table(AV_CRC_32_IEEE_LE);
252  uint32_t crc = ~0U;
253 
254  if (avctx->codec_id == AV_CODEC_ID_PNG || avctx->frame_num == 0) {
255  png_write_chunk(&s->bytestream, MKTAG('I', 'D', 'A', 'T'), buf, length);
256  return;
257  }
258 
259  bytestream_put_be32(&s->bytestream, length + 4);
260 
261  bytestream_put_be32(&s->bytestream, MKBETAG('f', 'd', 'A', 'T'));
262  bytestream_put_be32(&s->bytestream, s->sequence_number);
263  crc = av_crc(crc_table, crc, s->bytestream - 8, 8);
264 
265  crc = av_crc(crc_table, crc, buf, length);
266  memcpy(s->bytestream, buf, length);
267  s->bytestream += length;
268 
269  bytestream_put_be32(&s->bytestream, ~crc);
270 
271  ++s->sequence_number;
272 }
273 
274 /* XXX: do filtering */
275 static int png_write_row(AVCodecContext *avctx, const uint8_t *data, int size)
276 {
277  PNGEncContext *s = avctx->priv_data;
278  z_stream *const zstream = &s->zstream.zstream;
279  int ret;
280 
281  zstream->avail_in = size;
282  zstream->next_in = data;
283  while (zstream->avail_in > 0) {
284  ret = deflate(zstream, Z_NO_FLUSH);
285  if (ret != Z_OK)
286  return -1;
287  if (zstream->avail_out == 0) {
288  if (s->bytestream_end - s->bytestream > IOBUF_SIZE + 100)
289  png_write_image_data(avctx, s->buf, IOBUF_SIZE);
290  zstream->avail_out = IOBUF_SIZE;
291  zstream->next_out = s->buf;
292  }
293  }
294  return 0;
295 }
296 
297 #define AV_WB32_PNG(buf, n) AV_WB32(buf, lrint((n) * 100000))
298 #define AV_WB32_PNG_D(buf, d) AV_WB32_PNG(buf, av_q2d(d))
299 static int png_get_chrm(enum AVColorPrimaries prim, uint8_t *buf)
300 {
302  if (!desc)
303  return 0;
304 
305  AV_WB32_PNG_D(buf, desc->wp.x);
306  AV_WB32_PNG_D(buf + 4, desc->wp.y);
307  AV_WB32_PNG_D(buf + 8, desc->prim.r.x);
308  AV_WB32_PNG_D(buf + 12, desc->prim.r.y);
309  AV_WB32_PNG_D(buf + 16, desc->prim.g.x);
310  AV_WB32_PNG_D(buf + 20, desc->prim.g.y);
311  AV_WB32_PNG_D(buf + 24, desc->prim.b.x);
312  AV_WB32_PNG_D(buf + 28, desc->prim.b.y);
313 
314  return 1;
315 }
316 
317 static int png_get_gama(enum AVColorTransferCharacteristic trc, uint8_t *buf)
318 {
319  double gamma = av_csp_approximate_trc_gamma(trc);
320  if (gamma <= 1e-6)
321  return 0;
322 
323  AV_WB32_PNG(buf, 1.0 / gamma);
324  return 1;
325 }
326 
328 {
329  z_stream *const zstream = &s->zstream.zstream;
330  const AVDictionaryEntry *entry;
331  const char *name;
332  uint8_t *start, *buf;
333  int ret;
334 
335  if (!sd || !sd->size)
336  return 0;
337  zstream->next_in = sd->data;
338  zstream->avail_in = sd->size;
339 
340  /* write the chunk contents first */
341  start = s->bytestream + 8; /* make room for iCCP tag + length */
342  buf = start;
343 
344  /* profile description */
345  entry = av_dict_get(sd->metadata, "name", NULL, 0);
346  name = (entry && entry->value[0]) ? entry->value : "icc";
347  for (int i = 0;; i++) {
348  char c = (i == 79) ? 0 : name[i];
349  bytestream_put_byte(&buf, c);
350  if (!c)
351  break;
352  }
353 
354  /* compression method and profile data */
355  bytestream_put_byte(&buf, 0);
356  zstream->next_out = buf;
357  zstream->avail_out = s->bytestream_end - buf;
358  ret = deflate(zstream, Z_FINISH);
359  deflateReset(zstream);
360  if (ret != Z_STREAM_END)
361  return AVERROR_EXTERNAL;
362 
363  /* rewind to the start and write the chunk header/crc */
364  png_write_chunk(&s->bytestream, MKTAG('i', 'C', 'C', 'P'), start,
365  zstream->next_out - start);
366  return 0;
367 }
368 
369 static int encode_headers(AVCodecContext *avctx, const AVFrame *pict)
370 {
371  AVFrameSideData *side_data;
372  PNGEncContext *s = avctx->priv_data;
373  int ret;
374 
375  /* write png header */
376  AV_WB32(s->buf, avctx->width);
377  AV_WB32(s->buf + 4, avctx->height);
378  s->buf[8] = s->bit_depth;
379  s->buf[9] = s->color_type;
380  s->buf[10] = 0; /* compression type */
381  s->buf[11] = 0; /* filter type */
382  s->buf[12] = s->is_progressive; /* interlace type */
383  png_write_chunk(&s->bytestream, MKTAG('I', 'H', 'D', 'R'), s->buf, 13);
384 
385  /* write physical information */
386  if (s->dpm) {
387  AV_WB32(s->buf, s->dpm);
388  AV_WB32(s->buf + 4, s->dpm);
389  s->buf[8] = 1; /* unit specifier is meter */
390  } else {
391  AV_WB32(s->buf, avctx->sample_aspect_ratio.num);
392  AV_WB32(s->buf + 4, avctx->sample_aspect_ratio.den);
393  s->buf[8] = 0; /* unit specifier is unknown */
394  }
395  png_write_chunk(&s->bytestream, MKTAG('p', 'H', 'Y', 's'), s->buf, 9);
396 
397  /* write stereoscopic information */
399  if (side_data) {
400  AVStereo3D *stereo3d = (AVStereo3D *)side_data->data;
401  switch (stereo3d->type) {
403  s->buf[0] = ((stereo3d->flags & AV_STEREO3D_FLAG_INVERT) == 0) ? 1 : 0;
404  png_write_chunk(&s->bytestream, MKTAG('s', 'T', 'E', 'R'), s->buf, 1);
405  break;
406  case AV_STEREO3D_2D:
407  break;
408  default:
409  av_log(avctx, AV_LOG_WARNING, "Only side-by-side stereo3d flag can be defined within sTER chunk\n");
410  break;
411  }
412  }
413 
415  if ((ret = png_write_iccp(s, side_data)))
416  return ret;
417 
418  /* write colorspace information */
419  if (pict->color_primaries == AVCOL_PRI_BT709 &&
421  s->buf[0] = 1; /* rendering intent, relative colorimetric by default */
422  png_write_chunk(&s->bytestream, MKTAG('s', 'R', 'G', 'B'), s->buf, 1);
423  } else if (pict->color_trc != AVCOL_TRC_UNSPECIFIED && !side_data) {
424  /*
425  * Avoid writing cICP if the transfer is unknown. Known primaries
426  * with unknown transfer can be handled by cHRM.
427  *
428  * We also avoid writing cICP if an ICC Profile is present, because
429  * the standard requires that cICP overrides iCCP.
430  *
431  * These values match H.273 so no translation is needed.
432  */
433  s->buf[0] = pict->color_primaries;
434  s->buf[1] = pict->color_trc;
435  s->buf[2] = 0; /* colorspace = RGB */
436  s->buf[3] = pict->color_range == AVCOL_RANGE_MPEG ? 0 : 1;
437  png_write_chunk(&s->bytestream, MKTAG('c', 'I', 'C', 'P'), s->buf, 4);
438  }
439 
440  if (png_get_chrm(pict->color_primaries, s->buf))
441  png_write_chunk(&s->bytestream, MKTAG('c', 'H', 'R', 'M'), s->buf, 32);
442  if (png_get_gama(pict->color_trc, s->buf))
443  png_write_chunk(&s->bytestream, MKTAG('g', 'A', 'M', 'A'), s->buf, 4);
444 
445  /* put the palette if needed, must be after colorspace information */
446  if (s->color_type == PNG_COLOR_TYPE_PALETTE) {
447  int has_alpha, alpha, i;
448  unsigned int v;
449  uint32_t *palette;
450  uint8_t *ptr, *alpha_ptr;
451 
452  palette = (uint32_t *)pict->data[1];
453  ptr = s->buf;
454  alpha_ptr = s->buf + 256 * 3;
455  has_alpha = 0;
456  for (i = 0; i < 256; i++) {
457  v = palette[i];
458  alpha = v >> 24;
459  if (alpha != 0xff)
460  has_alpha = 1;
461  *alpha_ptr++ = alpha;
462  bytestream_put_be24(&ptr, v);
463  }
464  png_write_chunk(&s->bytestream,
465  MKTAG('P', 'L', 'T', 'E'), s->buf, 256 * 3);
466  if (has_alpha) {
467  png_write_chunk(&s->bytestream,
468  MKTAG('t', 'R', 'N', 'S'), s->buf + 256 * 3, 256);
469  }
470  }
471 
472  return 0;
473 }
474 
475 static int encode_frame(AVCodecContext *avctx, const AVFrame *pict)
476 {
477  PNGEncContext *s = avctx->priv_data;
478  z_stream *const zstream = &s->zstream.zstream;
479  const AVFrame *const p = pict;
480  int y, len, ret;
481  int row_size, pass_row_size;
482  uint8_t *crow_buf, *crow;
483  uint8_t *crow_base = NULL;
484  uint8_t *progressive_buf = NULL;
485  uint8_t *top_buf = NULL;
486 
487  row_size = (pict->width * s->bits_per_pixel + 7) >> 3;
488 
489  crow_base = av_malloc((row_size + 32) << (s->filter_type == PNG_FILTER_VALUE_MIXED));
490  if (!crow_base) {
491  ret = AVERROR(ENOMEM);
492  goto the_end;
493  }
494  // pixel data should be aligned, but there's a control byte before it
495  crow_buf = crow_base + 15;
496  if (s->is_progressive) {
497  progressive_buf = av_malloc(row_size + 1);
498  top_buf = av_malloc(row_size + 1);
499  if (!progressive_buf || !top_buf) {
500  ret = AVERROR(ENOMEM);
501  goto the_end;
502  }
503  }
504 
505  /* put each row */
506  zstream->avail_out = IOBUF_SIZE;
507  zstream->next_out = s->buf;
508  if (s->is_progressive) {
509  int pass;
510 
511  for (pass = 0; pass < NB_PASSES; pass++) {
512  /* NOTE: a pass is completely omitted if no pixels would be
513  * output */
514  pass_row_size = ff_png_pass_row_size(pass, s->bits_per_pixel, pict->width);
515  if (pass_row_size > 0) {
516  uint8_t *top = NULL;
517  for (y = 0; y < pict->height; y++)
518  if ((ff_png_pass_ymask[pass] << (y & 7)) & 0x80) {
519  const uint8_t *ptr = p->data[0] + y * p->linesize[0];
520  FFSWAP(uint8_t *, progressive_buf, top_buf);
521  png_get_interlaced_row(progressive_buf, pass_row_size,
522  s->bits_per_pixel, pass,
523  ptr, pict->width);
524  crow = png_choose_filter(s, crow_buf, progressive_buf,
525  top, pass_row_size, s->bits_per_pixel >> 3);
526  png_write_row(avctx, crow, pass_row_size + 1);
527  top = progressive_buf;
528  }
529  }
530  }
531  } else {
532  const uint8_t *top = NULL;
533  for (y = 0; y < pict->height; y++) {
534  const uint8_t *ptr = p->data[0] + y * p->linesize[0];
535  crow = png_choose_filter(s, crow_buf, ptr, top,
536  row_size, s->bits_per_pixel >> 3);
537  png_write_row(avctx, crow, row_size + 1);
538  top = ptr;
539  }
540  }
541  /* compress last bytes */
542  for (;;) {
543  ret = deflate(zstream, Z_FINISH);
544  if (ret == Z_OK || ret == Z_STREAM_END) {
545  len = IOBUF_SIZE - zstream->avail_out;
546  if (len > 0 && s->bytestream_end - s->bytestream > len + 100) {
547  png_write_image_data(avctx, s->buf, len);
548  }
549  zstream->avail_out = IOBUF_SIZE;
550  zstream->next_out = s->buf;
551  if (ret == Z_STREAM_END)
552  break;
553  } else {
554  ret = -1;
555  goto the_end;
556  }
557  }
558 
559  ret = 0;
560 
561 the_end:
562  av_freep(&crow_base);
563  av_freep(&progressive_buf);
564  av_freep(&top_buf);
565  deflateReset(zstream);
566  return ret;
567 }
568 
569 static int add_icc_profile_size(AVCodecContext *avctx, const AVFrame *pict,
570  uint64_t *max_packet_size)
571 {
572  PNGEncContext *s = avctx->priv_data;
573  const AVFrameSideData *sd;
574  const int hdr_size = 128;
575  uint64_t new_pkt_size;
576  uLong bound;
577 
578  if (!pict)
579  return 0;
581  if (!sd || !sd->size)
582  return 0;
583  if (sd->size != (uLong) sd->size)
584  return AVERROR_INVALIDDATA;
585 
586  bound = deflateBound(&s->zstream.zstream, sd->size);
587  if (bound > INT32_MAX - hdr_size)
588  return AVERROR_INVALIDDATA;
589 
590  new_pkt_size = *max_packet_size + bound + hdr_size;
591  if (new_pkt_size < *max_packet_size)
592  return AVERROR_INVALIDDATA;
593  *max_packet_size = new_pkt_size;
594  return 0;
595 }
596 
597 static int encode_png(AVCodecContext *avctx, AVPacket *pkt,
598  const AVFrame *pict, int *got_packet)
599 {
600  PNGEncContext *s = avctx->priv_data;
601  int ret;
602  int enc_row_size;
603  uint64_t max_packet_size;
604 
605  enc_row_size = deflateBound(&s->zstream.zstream,
606  (avctx->width * s->bits_per_pixel + 7) >> 3);
607  max_packet_size =
608  AV_INPUT_BUFFER_MIN_SIZE + // headers
609  avctx->height * (
610  enc_row_size +
611  12 * (((int64_t)enc_row_size + IOBUF_SIZE - 1) / IOBUF_SIZE) // IDAT * ceil(enc_row_size / IOBUF_SIZE)
612  );
613  if ((ret = add_icc_profile_size(avctx, pict, &max_packet_size)))
614  return ret;
615  ret = ff_alloc_packet(avctx, pkt, max_packet_size);
616  if (ret < 0)
617  return ret;
618 
619  s->bytestream_start =
620  s->bytestream = pkt->data;
621  s->bytestream_end = pkt->data + pkt->size;
622 
623  AV_WB64(s->bytestream, PNGSIG);
624  s->bytestream += 8;
625 
626  ret = encode_headers(avctx, pict);
627  if (ret < 0)
628  return ret;
629 
630  ret = encode_frame(avctx, pict);
631  if (ret < 0)
632  return ret;
633 
634  png_write_chunk(&s->bytestream, MKTAG('I', 'E', 'N', 'D'), NULL, 0);
635 
636  pkt->size = s->bytestream - s->bytestream_start;
638  *got_packet = 1;
639 
640  return 0;
641 }
642 
644  APNGFctlChunk *fctl_chunk, uint8_t bpp)
645 {
646  // output: background, input: foreground
647  // output the image such that when blended with the background, will produce the foreground
648 
649  unsigned int x, y;
650  unsigned int leftmost_x = input->width;
651  unsigned int rightmost_x = 0;
652  unsigned int topmost_y = input->height;
653  unsigned int bottommost_y = 0;
654  const uint8_t *input_data = input->data[0];
655  uint8_t *output_data = output->data[0];
656  ptrdiff_t input_linesize = input->linesize[0];
657  ptrdiff_t output_linesize = output->linesize[0];
658 
659  // Find bounding box of changes
660  for (y = 0; y < input->height; ++y) {
661  for (x = 0; x < input->width; ++x) {
662  if (!memcmp(input_data + bpp * x, output_data + bpp * x, bpp))
663  continue;
664 
665  if (x < leftmost_x)
666  leftmost_x = x;
667  if (x >= rightmost_x)
668  rightmost_x = x + 1;
669  if (y < topmost_y)
670  topmost_y = y;
671  if (y >= bottommost_y)
672  bottommost_y = y + 1;
673  }
674 
675  input_data += input_linesize;
676  output_data += output_linesize;
677  }
678 
679  if (leftmost_x == input->width && rightmost_x == 0) {
680  // Empty frame
681  // APNG does not support empty frames, so we make it a 1x1 frame
682  leftmost_x = topmost_y = 0;
683  rightmost_x = bottommost_y = 1;
684  }
685 
686  // Do actual inverse blending
687  if (fctl_chunk->blend_op == APNG_BLEND_OP_SOURCE) {
688  output_data = output->data[0];
689  for (y = topmost_y; y < bottommost_y; ++y) {
690  memcpy(output_data,
691  input->data[0] + input_linesize * y + bpp * leftmost_x,
692  bpp * (rightmost_x - leftmost_x));
693  output_data += output_linesize;
694  }
695  } else { // APNG_BLEND_OP_OVER
696  size_t transparent_palette_index;
697  uint32_t *palette;
698 
699  switch (input->format) {
700  case AV_PIX_FMT_RGBA64BE:
701  case AV_PIX_FMT_YA16BE:
702  case AV_PIX_FMT_RGBA:
703  case AV_PIX_FMT_GRAY8A:
704  break;
705 
706  case AV_PIX_FMT_PAL8:
707  palette = (uint32_t*)input->data[1];
708  for (transparent_palette_index = 0; transparent_palette_index < 256; ++transparent_palette_index)
709  if (palette[transparent_palette_index] >> 24 == 0)
710  break;
711  break;
712 
713  default:
714  // No alpha, so blending not possible
715  return -1;
716  }
717 
718  for (y = topmost_y; y < bottommost_y; ++y) {
719  const uint8_t *foreground = input->data[0] + input_linesize * y + bpp * leftmost_x;
720  uint8_t *background = output->data[0] + output_linesize * y + bpp * leftmost_x;
721  output_data = output->data[0] + output_linesize * (y - topmost_y);
722  for (x = leftmost_x; x < rightmost_x; ++x, foreground += bpp, background += bpp, output_data += bpp) {
723  if (!memcmp(foreground, background, bpp)) {
724  if (input->format == AV_PIX_FMT_PAL8) {
725  if (transparent_palette_index == 256) {
726  // Need fully transparent colour, but none exists
727  return -1;
728  }
729 
730  *output_data = transparent_palette_index;
731  } else {
732  memset(output_data, 0, bpp);
733  }
734  continue;
735  }
736 
737  // Check for special alpha values, since full inverse
738  // alpha-on-alpha blending is rarely possible, and when
739  // possible, doesn't compress much better than
740  // APNG_BLEND_OP_SOURCE blending
741  switch (input->format) {
742  case AV_PIX_FMT_RGBA64BE:
743  if (((uint16_t*)foreground)[3] == 0xffff ||
744  ((uint16_t*)background)[3] == 0)
745  break;
746  return -1;
747 
748  case AV_PIX_FMT_YA16BE:
749  if (((uint16_t*)foreground)[1] == 0xffff ||
750  ((uint16_t*)background)[1] == 0)
751  break;
752  return -1;
753 
754  case AV_PIX_FMT_RGBA:
755  if (foreground[3] == 0xff || background[3] == 0)
756  break;
757  return -1;
758 
759  case AV_PIX_FMT_GRAY8A:
760  if (foreground[1] == 0xff || background[1] == 0)
761  break;
762  return -1;
763 
764  case AV_PIX_FMT_PAL8:
765  if (palette[*foreground] >> 24 == 0xff ||
766  palette[*background] >> 24 == 0)
767  break;
768  return -1;
769  }
770 
771  memmove(output_data, foreground, bpp);
772  }
773  }
774  }
775 
776  output->width = rightmost_x - leftmost_x;
777  output->height = bottommost_y - topmost_y;
778  fctl_chunk->width = output->width;
779  fctl_chunk->height = output->height;
780  fctl_chunk->x_offset = leftmost_x;
781  fctl_chunk->y_offset = topmost_y;
782 
783  return 0;
784 }
785 
786 static int apng_encode_frame(AVCodecContext *avctx, const AVFrame *pict,
787  APNGFctlChunk *best_fctl_chunk, APNGFctlChunk *best_last_fctl_chunk)
788 {
789  PNGEncContext *s = avctx->priv_data;
790  int ret;
791  unsigned int y;
792  AVFrame* diffFrame;
793  uint8_t bpp = (s->bits_per_pixel + 7) >> 3;
794  uint8_t *original_bytestream, *original_bytestream_end;
795  uint8_t *temp_bytestream = 0, *temp_bytestream_end;
796  uint32_t best_sequence_number;
797  uint8_t *best_bytestream;
798  size_t best_bytestream_size = SIZE_MAX;
799  APNGFctlChunk last_fctl_chunk = *best_last_fctl_chunk;
800  APNGFctlChunk fctl_chunk = *best_fctl_chunk;
801 
802  if (avctx->frame_num == 0) {
803  best_fctl_chunk->width = pict->width;
804  best_fctl_chunk->height = pict->height;
805  best_fctl_chunk->x_offset = 0;
806  best_fctl_chunk->y_offset = 0;
807  best_fctl_chunk->blend_op = APNG_BLEND_OP_SOURCE;
808  return encode_frame(avctx, pict);
809  }
810 
811  diffFrame = av_frame_alloc();
812  if (!diffFrame)
813  return AVERROR(ENOMEM);
814 
815  diffFrame->format = pict->format;
816  diffFrame->width = pict->width;
817  diffFrame->height = pict->height;
818  if ((ret = av_frame_get_buffer(diffFrame, 0)) < 0)
819  goto fail;
820 
821  original_bytestream = s->bytestream;
822  original_bytestream_end = s->bytestream_end;
823 
824  temp_bytestream = av_malloc(original_bytestream_end - original_bytestream);
825  if (!temp_bytestream) {
826  ret = AVERROR(ENOMEM);
827  goto fail;
828  }
829  temp_bytestream_end = temp_bytestream + (original_bytestream_end - original_bytestream);
830 
831  for (last_fctl_chunk.dispose_op = 0; last_fctl_chunk.dispose_op < 3; ++last_fctl_chunk.dispose_op) {
832  // 0: APNG_DISPOSE_OP_NONE
833  // 1: APNG_DISPOSE_OP_BACKGROUND
834  // 2: APNG_DISPOSE_OP_PREVIOUS
835 
836  for (fctl_chunk.blend_op = 0; fctl_chunk.blend_op < 2; ++fctl_chunk.blend_op) {
837  // 0: APNG_BLEND_OP_SOURCE
838  // 1: APNG_BLEND_OP_OVER
839 
840  uint32_t original_sequence_number = s->sequence_number, sequence_number;
841  uint8_t *bytestream_start = s->bytestream;
842  size_t bytestream_size;
843 
844  // Do disposal
845  if (last_fctl_chunk.dispose_op != APNG_DISPOSE_OP_PREVIOUS) {
846  diffFrame->width = pict->width;
847  diffFrame->height = pict->height;
848  ret = av_frame_copy(diffFrame, s->last_frame);
849  if (ret < 0)
850  goto fail;
851 
852  if (last_fctl_chunk.dispose_op == APNG_DISPOSE_OP_BACKGROUND) {
853  for (y = last_fctl_chunk.y_offset; y < last_fctl_chunk.y_offset + last_fctl_chunk.height; ++y) {
854  size_t row_start = diffFrame->linesize[0] * y + bpp * last_fctl_chunk.x_offset;
855  memset(diffFrame->data[0] + row_start, 0, bpp * last_fctl_chunk.width);
856  }
857  }
858  } else {
859  if (!s->prev_frame)
860  continue;
861 
862  diffFrame->width = pict->width;
863  diffFrame->height = pict->height;
864  ret = av_frame_copy(diffFrame, s->prev_frame);
865  if (ret < 0)
866  goto fail;
867  }
868 
869  // Do inverse blending
870  if (apng_do_inverse_blend(diffFrame, pict, &fctl_chunk, bpp) < 0)
871  continue;
872 
873  // Do encoding
874  ret = encode_frame(avctx, diffFrame);
875  sequence_number = s->sequence_number;
876  s->sequence_number = original_sequence_number;
877  bytestream_size = s->bytestream - bytestream_start;
878  s->bytestream = bytestream_start;
879  if (ret < 0)
880  goto fail;
881 
882  if (bytestream_size < best_bytestream_size) {
883  *best_fctl_chunk = fctl_chunk;
884  *best_last_fctl_chunk = last_fctl_chunk;
885 
886  best_sequence_number = sequence_number;
887  best_bytestream = s->bytestream;
888  best_bytestream_size = bytestream_size;
889 
890  if (best_bytestream == original_bytestream) {
891  s->bytestream = temp_bytestream;
892  s->bytestream_end = temp_bytestream_end;
893  } else {
894  s->bytestream = original_bytestream;
895  s->bytestream_end = original_bytestream_end;
896  }
897  }
898  }
899  }
900 
901  s->sequence_number = best_sequence_number;
902  s->bytestream = original_bytestream + best_bytestream_size;
903  s->bytestream_end = original_bytestream_end;
904  if (best_bytestream != original_bytestream)
905  memcpy(original_bytestream, best_bytestream, best_bytestream_size);
906 
907  ret = 0;
908 
909 fail:
910  av_freep(&temp_bytestream);
911  av_frame_free(&diffFrame);
912  return ret;
913 }
914 
916  const AVFrame *pict, int *got_packet)
917 {
918  PNGEncContext *s = avctx->priv_data;
919  int ret;
920  int enc_row_size;
921  uint64_t max_packet_size;
922  APNGFctlChunk fctl_chunk = {0};
923 
924  if (pict && s->color_type == PNG_COLOR_TYPE_PALETTE) {
925  uint32_t checksum = ~av_crc(av_crc_get_table(AV_CRC_32_IEEE_LE), ~0U, pict->data[1], 256 * sizeof(uint32_t));
926 
927  if (avctx->frame_num == 0) {
928  s->palette_checksum = checksum;
929  } else if (checksum != s->palette_checksum) {
930  av_log(avctx, AV_LOG_ERROR,
931  "Input contains more than one unique palette. APNG does not support multiple palettes.\n");
932  return -1;
933  }
934  }
935 
936  enc_row_size = deflateBound(&s->zstream.zstream,
937  (avctx->width * s->bits_per_pixel + 7) >> 3);
938  max_packet_size =
939  AV_INPUT_BUFFER_MIN_SIZE + // headers
940  avctx->height * (
941  enc_row_size +
942  (4 + 12) * (((int64_t)enc_row_size + IOBUF_SIZE - 1) / IOBUF_SIZE) // fdAT * ceil(enc_row_size / IOBUF_SIZE)
943  );
944  if ((ret = add_icc_profile_size(avctx, pict, &max_packet_size)))
945  return ret;
946  if (max_packet_size > INT_MAX)
947  return AVERROR(ENOMEM);
948 
949  if (avctx->frame_num == 0) {
950  if (!pict)
951  return AVERROR(EINVAL);
952 
953  s->bytestream = s->extra_data = av_malloc(AV_INPUT_BUFFER_MIN_SIZE);
954  if (!s->extra_data)
955  return AVERROR(ENOMEM);
956 
957  ret = encode_headers(avctx, pict);
958  if (ret < 0)
959  return ret;
960 
961  s->extra_data_size = s->bytestream - s->extra_data;
962 
963  s->last_frame_packet = av_malloc(max_packet_size);
964  if (!s->last_frame_packet)
965  return AVERROR(ENOMEM);
966  } else if (s->last_frame) {
967  ret = ff_get_encode_buffer(avctx, pkt, s->last_frame_packet_size, 0);
968  if (ret < 0)
969  return ret;
970 
971  memcpy(pkt->data, s->last_frame_packet, s->last_frame_packet_size);
972  pkt->pts = s->last_frame->pts;
973  pkt->duration = s->last_frame->duration;
974 
975  ret = ff_encode_reordered_opaque(avctx, pkt, s->last_frame);
976  if (ret < 0)
977  return ret;
978  }
979 
980  if (pict) {
981  s->bytestream_start =
982  s->bytestream = s->last_frame_packet;
983  s->bytestream_end = s->bytestream + max_packet_size;
984 
985  // We're encoding the frame first, so we have to do a bit of shuffling around
986  // to have the image data write to the correct place in the buffer
987  fctl_chunk.sequence_number = s->sequence_number;
988  ++s->sequence_number;
989  s->bytestream += APNG_FCTL_CHUNK_SIZE + 12;
990 
991  ret = apng_encode_frame(avctx, pict, &fctl_chunk, &s->last_frame_fctl);
992  if (ret < 0)
993  return ret;
994 
995  fctl_chunk.delay_num = 0; // delay filled in during muxing
996  fctl_chunk.delay_den = 0;
997  } else {
998  s->last_frame_fctl.dispose_op = APNG_DISPOSE_OP_NONE;
999  }
1000 
1001  if (s->last_frame) {
1002  uint8_t* last_fctl_chunk_start = pkt->data;
1003  uint8_t buf[APNG_FCTL_CHUNK_SIZE];
1004  if (!s->extra_data_updated) {
1005  uint8_t *side_data = av_packet_new_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, s->extra_data_size);
1006  if (!side_data)
1007  return AVERROR(ENOMEM);
1008  memcpy(side_data, s->extra_data, s->extra_data_size);
1009  s->extra_data_updated = 1;
1010  }
1011 
1012  AV_WB32(buf + 0, s->last_frame_fctl.sequence_number);
1013  AV_WB32(buf + 4, s->last_frame_fctl.width);
1014  AV_WB32(buf + 8, s->last_frame_fctl.height);
1015  AV_WB32(buf + 12, s->last_frame_fctl.x_offset);
1016  AV_WB32(buf + 16, s->last_frame_fctl.y_offset);
1017  AV_WB16(buf + 20, s->last_frame_fctl.delay_num);
1018  AV_WB16(buf + 22, s->last_frame_fctl.delay_den);
1019  buf[24] = s->last_frame_fctl.dispose_op;
1020  buf[25] = s->last_frame_fctl.blend_op;
1021  png_write_chunk(&last_fctl_chunk_start, MKTAG('f', 'c', 'T', 'L'), buf, sizeof(buf));
1022 
1023  *got_packet = 1;
1024  }
1025 
1026  if (pict) {
1027  if (!s->last_frame) {
1028  s->last_frame = av_frame_alloc();
1029  if (!s->last_frame)
1030  return AVERROR(ENOMEM);
1031  } else if (s->last_frame_fctl.dispose_op != APNG_DISPOSE_OP_PREVIOUS) {
1032  if (!s->prev_frame) {
1033  s->prev_frame = av_frame_alloc();
1034  if (!s->prev_frame)
1035  return AVERROR(ENOMEM);
1036 
1037  s->prev_frame->format = pict->format;
1038  s->prev_frame->width = pict->width;
1039  s->prev_frame->height = pict->height;
1040  if ((ret = av_frame_get_buffer(s->prev_frame, 0)) < 0)
1041  return ret;
1042  }
1043 
1044  // Do disposal, but not blending
1045  av_frame_copy(s->prev_frame, s->last_frame);
1046  if (s->last_frame_fctl.dispose_op == APNG_DISPOSE_OP_BACKGROUND) {
1047  uint32_t y;
1048  uint8_t bpp = (s->bits_per_pixel + 7) >> 3;
1049  for (y = s->last_frame_fctl.y_offset; y < s->last_frame_fctl.y_offset + s->last_frame_fctl.height; ++y) {
1050  size_t row_start = s->prev_frame->linesize[0] * y + bpp * s->last_frame_fctl.x_offset;
1051  memset(s->prev_frame->data[0] + row_start, 0, bpp * s->last_frame_fctl.width);
1052  }
1053  }
1054  }
1055 
1056  av_frame_unref(s->last_frame);
1057  ret = av_frame_ref(s->last_frame, pict);
1058  if (ret < 0)
1059  return ret;
1060 
1061  s->last_frame_fctl = fctl_chunk;
1062  s->last_frame_packet_size = s->bytestream - s->bytestream_start;
1063  } else {
1064  av_frame_free(&s->last_frame);
1065  }
1066 
1067  return 0;
1068 }
1069 
1071 {
1072  PNGEncContext *s = avctx->priv_data;
1073  int compression_level;
1074 
1075  switch (avctx->pix_fmt) {
1076  case AV_PIX_FMT_RGBA:
1077  avctx->bits_per_coded_sample = 32;
1078  break;
1079  case AV_PIX_FMT_RGB24:
1080  avctx->bits_per_coded_sample = 24;
1081  break;
1082  case AV_PIX_FMT_GRAY8:
1083  avctx->bits_per_coded_sample = 0x28;
1084  break;
1085  case AV_PIX_FMT_MONOBLACK:
1086  avctx->bits_per_coded_sample = 1;
1087  break;
1088  case AV_PIX_FMT_PAL8:
1089  avctx->bits_per_coded_sample = 8;
1090  }
1091 
1092  ff_llvidencdsp_init(&s->llvidencdsp);
1093 
1094  if (avctx->pix_fmt == AV_PIX_FMT_MONOBLACK)
1095  s->filter_type = PNG_FILTER_VALUE_NONE;
1096 
1097  if (s->dpi && s->dpm) {
1098  av_log(avctx, AV_LOG_ERROR, "Only one of 'dpi' or 'dpm' options should be set\n");
1099  return AVERROR(EINVAL);
1100  } else if (s->dpi) {
1101  s->dpm = s->dpi * 10000 / 254;
1102  }
1103 
1104  s->is_progressive = !!(avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT);
1105  switch (avctx->pix_fmt) {
1106  case AV_PIX_FMT_RGBA64BE:
1107  s->bit_depth = 16;
1108  s->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
1109  break;
1110  case AV_PIX_FMT_RGB48BE:
1111  s->bit_depth = 16;
1112  s->color_type = PNG_COLOR_TYPE_RGB;
1113  break;
1114  case AV_PIX_FMT_RGBA:
1115  s->bit_depth = 8;
1116  s->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
1117  break;
1118  case AV_PIX_FMT_RGB24:
1119  s->bit_depth = 8;
1120  s->color_type = PNG_COLOR_TYPE_RGB;
1121  break;
1122  case AV_PIX_FMT_GRAY16BE:
1123  s->bit_depth = 16;
1124  s->color_type = PNG_COLOR_TYPE_GRAY;
1125  break;
1126  case AV_PIX_FMT_GRAY8:
1127  s->bit_depth = 8;
1128  s->color_type = PNG_COLOR_TYPE_GRAY;
1129  break;
1130  case AV_PIX_FMT_GRAY8A:
1131  s->bit_depth = 8;
1132  s->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
1133  break;
1134  case AV_PIX_FMT_YA16BE:
1135  s->bit_depth = 16;
1136  s->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
1137  break;
1138  case AV_PIX_FMT_MONOBLACK:
1139  s->bit_depth = 1;
1140  s->color_type = PNG_COLOR_TYPE_GRAY;
1141  break;
1142  case AV_PIX_FMT_PAL8:
1143  s->bit_depth = 8;
1144  s->color_type = PNG_COLOR_TYPE_PALETTE;
1145  break;
1146  default:
1147  return -1;
1148  }
1149  s->bits_per_pixel = ff_png_get_nb_channels(s->color_type) * s->bit_depth;
1150 
1151  compression_level = avctx->compression_level == FF_COMPRESSION_DEFAULT
1152  ? Z_DEFAULT_COMPRESSION
1153  : av_clip(avctx->compression_level, 0, 9);
1154  return ff_deflate_init(&s->zstream, compression_level, avctx);
1155 }
1156 
1158 {
1159  PNGEncContext *s = avctx->priv_data;
1160 
1161  ff_deflate_end(&s->zstream);
1162  av_frame_free(&s->last_frame);
1163  av_frame_free(&s->prev_frame);
1164  av_freep(&s->last_frame_packet);
1165  av_freep(&s->extra_data);
1166  s->extra_data_size = 0;
1167  return 0;
1168 }
1169 
1170 #define OFFSET(x) offsetof(PNGEncContext, x)
1171 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1172 static const AVOption options[] = {
1173  {"dpi", "Set image resolution (in dots per inch)", OFFSET(dpi), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 0x10000, VE},
1174  {"dpm", "Set image resolution (in dots per meter)", OFFSET(dpm), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 0x10000, VE},
1175  { "pred", "Prediction method", OFFSET(filter_type), AV_OPT_TYPE_INT, { .i64 = PNG_FILTER_VALUE_NONE }, PNG_FILTER_VALUE_NONE, PNG_FILTER_VALUE_MIXED, VE, "pred" },
1176  { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_NONE }, INT_MIN, INT_MAX, VE, "pred" },
1177  { "sub", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_SUB }, INT_MIN, INT_MAX, VE, "pred" },
1178  { "up", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_UP }, INT_MIN, INT_MAX, VE, "pred" },
1179  { "avg", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_AVG }, INT_MIN, INT_MAX, VE, "pred" },
1180  { "paeth", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_PAETH }, INT_MIN, INT_MAX, VE, "pred" },
1181  { "mixed", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_MIXED }, INT_MIN, INT_MAX, VE, "pred" },
1182  { NULL},
1183 };
1184 
1185 static const AVClass pngenc_class = {
1186  .class_name = "(A)PNG encoder",
1187  .item_name = av_default_item_name,
1188  .option = options,
1189  .version = LIBAVUTIL_VERSION_INT,
1190 };
1191 
1193  .p.name = "png",
1194  CODEC_LONG_NAME("PNG (Portable Network Graphics) image"),
1195  .p.type = AVMEDIA_TYPE_VIDEO,
1196  .p.id = AV_CODEC_ID_PNG,
1197  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
1199  .priv_data_size = sizeof(PNGEncContext),
1200  .init = png_enc_init,
1201  .close = png_enc_close,
1203  .p.pix_fmts = (const enum AVPixelFormat[]) {
1210  },
1211  .p.priv_class = &pngenc_class,
1212  .caps_internal = FF_CODEC_CAP_ICC_PROFILES,
1213 };
1214 
1216  .p.name = "apng",
1217  CODEC_LONG_NAME("APNG (Animated Portable Network Graphics) image"),
1218  .p.type = AVMEDIA_TYPE_VIDEO,
1219  .p.id = AV_CODEC_ID_APNG,
1220  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
1222  .priv_data_size = sizeof(PNGEncContext),
1223  .init = png_enc_init,
1224  .close = png_enc_close,
1226  .p.pix_fmts = (const enum AVPixelFormat[]) {
1233  },
1234  .p.priv_class = &pngenc_class,
1235  .caps_internal = FF_CODEC_CAP_ICC_PROFILES,
1236 };
AVFrame::color_trc
enum AVColorTransferCharacteristic color_trc
Definition: frame.h:596
ff_encode_reordered_opaque
int ff_encode_reordered_opaque(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame)
Propagate user opaque values from the frame to avctx/pkt as needed.
Definition: encode.c:198
APNG_DISPOSE_OP_BACKGROUND
@ APNG_DISPOSE_OP_BACKGROUND
Definition: apng.h:32
encode_frame
static int encode_frame(AVCodecContext *avctx, const AVFrame *pict)
Definition: pngenc.c:475
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AVFrame::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: frame.h:592
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
av_clip
#define av_clip
Definition: common.h:95
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
PNGEncContext::buf
uint8_t buf[IOBUF_SIZE]
Definition: pngenc.c:62
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:426
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:558
libm.h
ff_png_encoder
const FFCodec ff_png_encoder
Definition: pngenc.c:1192
av_frame_get_buffer
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:242
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:682
AV_WB32_PNG
#define AV_WB32_PNG(buf, n)
Definition: pngenc.c:297
AVColorPrimariesDesc
Struct that contains both white point location and primaries location, providing the complete descrip...
Definition: csp.h:78
AVCRC
uint32_t AVCRC
Definition: crc.h:46
png_get_chrm
static int png_get_chrm(enum AVColorPrimaries prim, uint8_t *buf)
Definition: pngenc.c:299
APNG_FCTL_CHUNK_SIZE
#define APNG_FCTL_CHUNK_SIZE
Definition: apng.h:42
ff_png_get_nb_channels
int ff_png_get_nb_channels(int color_type)
Definition: png.c:41
PNGEncContext::bits_per_pixel
int bits_per_pixel
Definition: pngenc.c:69
src1
const pixel * src1
Definition: h264pred_template.c:421
rational.h
PNGEncContext::last_frame
AVFrame * last_frame
Definition: pngenc.c:79
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:225
AVFrame::color_primaries
enum AVColorPrimaries color_primaries
Definition: frame.h:594
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:99
apng_encode_frame
static int apng_encode_frame(AVCodecContext *avctx, const AVFrame *pict, APNGFctlChunk *best_fctl_chunk, APNGFctlChunk *best_last_fctl_chunk)
Definition: pngenc.c:786
APNGFctlChunk::delay_num
uint16_t delay_num
Definition: pngenc.c:47
test::height
int height
Definition: vc1dsp.c:39
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:330
AV_PIX_FMT_RGBA64BE
@ AV_PIX_FMT_RGBA64BE
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:195
AVFrame::width
int width
Definition: frame.h:402
PNG_FILTER_VALUE_MIXED
#define PNG_FILTER_VALUE_MIXED
Definition: png.h:45
w
uint8_t w
Definition: llviddspenc.c:38
AVPacket::data
uint8_t * data
Definition: packet.h:374
AVOption
AVOption.
Definition: opt.h:251
encode.h
b
#define b
Definition: input.c:41
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:561
data
const char data[16]
Definition: mxf.c:146
png_write_row
static int png_write_row(AVCodecContext *avctx, const uint8_t *data, int size)
Definition: pngenc.c:275
FFCodec
Definition: codec_internal.h:127
output_data
static int output_data(MLPDecodeContext *m, unsigned int substr, AVFrame *frame, int *got_frame_ptr)
Write the audio data into the output buffer.
Definition: mlpdec.c:1087
PNGEncContext::dpm
int dpm
Physical pixel density, in dots per meter, if set.
Definition: pngenc.c:64
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:392
png_get_gama
static int png_get_gama(enum AVColorTransferCharacteristic trc, uint8_t *buf)
Definition: pngenc.c:317
PNGEncContext::last_frame_packet
uint8_t * last_frame_packet
Definition: pngenc.c:81
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:533
ff_deflate_end
void ff_deflate_end(FFZStream *zstream)
Wrapper around deflateEnd().
AV_CODEC_ID_APNG
@ AV_CODEC_ID_APNG
Definition: codec_id.h:268
FF_COMPRESSION_DEFAULT
#define FF_COMPRESSION_DEFAULT
Definition: avcodec.h:499
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:429
AV_WB64
#define AV_WB64(p, v)
Definition: intreadwrite.h:433
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:351
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
NB_PASSES
#define NB_PASSES
Definition: png.h:47
crc.h
ff_apng_encoder
const FFCodec ff_apng_encoder
Definition: pngenc.c:1215
sub_png_paeth_prediction
static void sub_png_paeth_prediction(uint8_t *dst, const uint8_t *src, const uint8_t *top, int w, int bpp)
Definition: pngenc.c:124
AV_PIX_FMT_GRAY16BE
@ AV_PIX_FMT_GRAY16BE
Y , 16bpp, big-endian.
Definition: pixfmt.h:97
AV_STEREO3D_SIDEBYSIDE
@ AV_STEREO3D_SIDEBYSIDE
Views are next to each other.
Definition: stereo3d.h:64
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
PNGEncContext::prev_frame
AVFrame * prev_frame
Definition: pngenc.c:78
AVCOL_TRC_IEC61966_2_1
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
Definition: pixfmt.h:572
ff_png_pass_row_size
int ff_png_pass_row_size(int pass, int bits_per_pixel, int width)
Definition: png.c:54
fail
#define fail()
Definition: checkasm.h:134
AV_STEREO3D_2D
@ AV_STEREO3D_2D
Video is not stereoscopic (and metadata has to be there).
Definition: stereo3d.h:52
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:506
APNGFctlChunk::blend_op
uint8_t blend_op
Definition: pngenc.c:48
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:315
AVRational::num
int num
Numerator.
Definition: rational.h:59
encode_png
static int encode_png(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
Definition: pngenc.c:597
PNG_COLOR_TYPE_RGB_ALPHA
#define PNG_COLOR_TYPE_RGB_ALPHA
Definition: png.h:36
AV_CODEC_FLAG_INTERLACED_DCT
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
Definition: avcodec.h:309
png_filter_row
static void png_filter_row(PNGEncContext *c, uint8_t *dst, int filter_type, const uint8_t *src, const uint8_t *top, int size, int bpp)
Definition: pngenc.c:168
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:87
av_bswap32
#define av_bswap32
Definition: bswap.h:33
avassert.h
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
zlib_wrapper.h
AVFrameSideData::size
size_t size
Definition: frame.h:239
av_cold
#define av_cold
Definition: attributes.h:90
encode_apng
static int encode_apng(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
Definition: pngenc.c:915
mask
static const uint16_t mask[17]
Definition: lzw.c:38
av_dict_get
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:60
PNGEncContext::bytestream_end
uint8_t * bytestream_end
Definition: pngenc.c:57
width
#define width
stereo3d.h
s
#define s(width, name)
Definition: cbs_vp9.c:256
av_csp_primaries_desc_from_id
const AVColorPrimariesDesc * av_csp_primaries_desc_from_id(enum AVColorPrimaries prm)
Retrieves a complete gamut description from an enum constant describing the color primaries.
Definition: csp.c:90
png_write_chunk
static void png_write_chunk(uint8_t **f, uint32_t tag, const uint8_t *buf, int length)
Definition: pngenc.c:227
PNG_COLOR_TYPE_RGB
#define PNG_COLOR_TYPE_RGB
Definition: png.h:35
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition: codec.h:156
APNG_BLEND_OP_SOURCE
@ APNG_BLEND_OP_SOURCE
Definition: apng.h:37
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AV_INPUT_BUFFER_MIN_SIZE
#define AV_INPUT_BUFFER_MIN_SIZE
Definition: avcodec.h:191
png_write_image_data
static void png_write_image_data(AVCodecContext *avctx, const uint8_t *buf, int length)
Definition: pngenc.c:247
pass
#define pass
Definition: fft_template.c:608
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:436
AVStereo3D::flags
int flags
Additional information about the frame packing.
Definition: stereo3d.h:182
AV_CODEC_ID_PNG
@ AV_CODEC_ID_PNG
Definition: codec_id.h:113
PNGEncContext
Definition: pngenc.c:51
APNGFctlChunk::y_offset
uint32_t y_offset
Definition: pngenc.c:46
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:107
AV_PIX_FMT_GRAY8A
@ AV_PIX_FMT_GRAY8A
alias for AV_PIX_FMT_YA8
Definition: pixfmt.h:136
input_data
static void input_data(MLPEncodeContext *ctx, const void *samples, int nb_samples)
Wrapper function for inputting data in two different bit-depths.
Definition: mlpenc.c:1235
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
APNGFctlChunk::delay_den
uint16_t delay_den
Definition: pngenc.c:47
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
apng.h
AV_WB16
#define AV_WB16(p, v)
Definition: intreadwrite.h:405
APNG_DISPOSE_OP_PREVIOUS
@ APNG_DISPOSE_OP_PREVIOUS
Definition: apng.h:33
IOBUF_SIZE
#define IOBUF_SIZE
Definition: pngenc.c:41
AV_PIX_FMT_MONOBLACK
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
Definition: pixfmt.h:76
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition: pixfmt.h:535
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
apng_do_inverse_blend
static int apng_do_inverse_blend(AVFrame *output, const AVFrame *input, APNGFctlChunk *fctl_chunk, uint8_t bpp)
Definition: pngenc.c:643
APNGFctlChunk::width
uint32_t width
Definition: pngenc.c:45
png_enc_close
static av_cold int png_enc_close(AVCodecContext *avctx)
Definition: pngenc.c:1157
AV_FRAME_DATA_ICC_PROFILE
@ AV_FRAME_DATA_ICC_PROFILE
The data contains an ICC profile as an opaque octet buffer following the format described by ISO 1507...
Definition: frame.h:144
PNG_COLOR_TYPE_GRAY
#define PNG_COLOR_TYPE_GRAY
Definition: png.h:33
deflate
static void deflate(uint8_t *dst, const uint8_t *p1, int width, int threshold, const uint8_t *coordinates[], int coord, int maxc)
Definition: vf_neighbor.c:162
PNGEncContext::filter_type
int filter_type
Definition: pngenc.c:59
abs
#define abs(x)
Definition: cuda_runtime.h:35
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
PNGEncContext::extra_data_updated
int extra_data_updated
Definition: pngenc.c:74
APNGFctlChunk
Definition: pngenc.c:43
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
ff_png_pass_ymask
const uint8_t ff_png_pass_ymask[NB_PASSES]
Definition: png.c:27
ff_llvidencdsp_init
av_cold void ff_llvidencdsp_init(LLVidEncDSPContext *c)
Definition: lossless_videoencdsp.c:91
add_icc_profile_size
static int add_icc_profile_size(AVCodecContext *avctx, const AVFrame *pict, uint64_t *max_packet_size)
Definition: pngenc.c:569
APNGFctlChunk::sequence_number
uint32_t sequence_number
Definition: pngenc.c:44
AV_WB32
#define AV_WB32(p, v)
Definition: intreadwrite.h:419
PNGEncContext::zstream
FFZStream zstream
Definition: pngenc.c:61
test::width
int width
Definition: vc1dsp.c:38
PNG_FILTER_VALUE_NONE
#define PNG_FILTER_VALUE_NONE
Definition: png.h:40
f
f
Definition: af_crystalizer.c:122
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVPacket::size
int size
Definition: packet.h:375
av_frame_ref
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:344
codec_internal.h
av_frame_copy
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:762
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
AV_PIX_FMT_YA16BE
@ AV_PIX_FMT_YA16BE
16 bits gray, 16 bits alpha (big-endian)
Definition: pixfmt.h:202
PNGEncContext::last_frame_packet_size
size_t last_frame_packet_size
Definition: pngenc.c:82
PNG_FILTER_VALUE_AVG
#define PNG_FILTER_VALUE_AVG
Definition: png.h:43
size
int size
Definition: twinvq_data.h:10344
av_csp_approximate_trc_gamma
double av_csp_approximate_trc_gamma(enum AVColorTransferCharacteristic trc)
Determine a suitable 'gamma' value to match the supplied AVColorTransferCharacteristic.
Definition: csp.c:149
MKBETAG
#define MKBETAG(a, b, c, d)
Definition: macros.h:56
PNGEncContext::llvidencdsp
LLVidEncDSPContext llvidencdsp
Definition: pngenc.c:53
AVFrameSideData::data
uint8_t * data
Definition: frame.h:238
PNG_FILTER_VALUE_PAETH
#define PNG_FILTER_VALUE_PAETH
Definition: png.h:44
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:417
PNGEncContext::extra_data
uint8_t * extra_data
Definition: pngenc.c:75
png_choose_filter
static uint8_t * png_choose_filter(PNGEncContext *s, uint8_t *dst, const uint8_t *src, const uint8_t *top, int size, int bpp)
Definition: pngenc.c:197
PNG_FILTER_VALUE_UP
#define PNG_FILTER_VALUE_UP
Definition: png.h:42
APNG_DISPOSE_OP_NONE
@ APNG_DISPOSE_OP_NONE
Definition: apng.h:31
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
csp.h
av_crc_get_table
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition: crc.c:374
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
OFFSET
#define OFFSET(x)
Definition: pngenc.c:1170
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:380
AV_STEREO3D_FLAG_INVERT
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
Definition: stereo3d.h:164
input
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
Definition: filter_design.txt:172
PNGSIG
#define PNGSIG
Definition: png.h:49
lossless_videoencdsp.h
AVCodecContext::bits_per_coded_sample
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:1480
PNG_FILTER_VALUE_SUB
#define PNG_FILTER_VALUE_SUB
Definition: png.h:41
AV_PIX_FMT_RGB48BE
@ AV_PIX_FMT_RGB48BE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:102
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:367
options
static const AVOption options[]
Definition: pngenc.c:1172
src2
const pixel * src2
Definition: h264pred_template.c:422
AV_FRAME_DATA_STEREO3D
@ AV_FRAME_DATA_STEREO3D
Stereoscopic 3d metadata.
Definition: frame.h:64
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:478
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:191
len
int len
Definition: vorbis_enc_data.h:426
AVCodecContext::height
int height
Definition: avcodec.h:598
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:635
LLVidEncDSPContext
Definition: lossless_videoencdsp.h:25
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:644
FF_CODEC_CAP_ICC_PROFILES
#define FF_CODEC_CAP_ICC_PROFILES
Codec supports embedded ICC profiles (AV_FRAME_DATA_ICC_PROFILE).
Definition: codec_internal.h:82
sub_left_prediction
static void sub_left_prediction(PNGEncContext *c, uint8_t *dst, const uint8_t *src, int bpp, int size)
Definition: pngenc.c:152
PNGEncContext::color_type
int color_type
Definition: pngenc.c:68
avcodec.h
AV_PIX_FMT_PAL8
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:77
AVCodecContext::frame_num
int64_t frame_num
Frame counter, set by libavcodec.
Definition: avcodec.h:2065
bound
static double bound(const double threshold, const double val)
Definition: af_dynaudnorm.c:413
tag
uint32_t tag
Definition: movenc.c:1641
ret
ret
Definition: filter_design.txt:187
pred
static const float pred[4]
Definition: siprdata.h:259
PNGEncContext::extra_data_size
int extra_data_size
Definition: pngenc.c:76
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
AVStereo3D::type
enum AVStereo3DType type
How views are packed within the video.
Definition: stereo3d.h:177
PNGEncContext::bit_depth
int bit_depth
Definition: pngenc.c:67
PNGEncContext::bytestream_start
uint8_t * bytestream_start
Definition: pngenc.c:56
U
#define U(x)
Definition: vpx_arith.h:37
AVCodecContext
main external API structure.
Definition: avcodec.h:426
AVFrame::height
int height
Definition: frame.h:402
AV_WB32_PNG_D
#define AV_WB32_PNG_D(buf, d)
Definition: pngenc.c:298
av_packet_new_side_data
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
Definition: avpacket.c:230
ff_get_encode_buffer
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Definition: encode.c:79
av_crc
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
Definition: crc.c:392
AV_PKT_DATA_NEW_EXTRADATA
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
Definition: packet.h:56
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
png_get_interlaced_row
static void png_get_interlaced_row(uint8_t *dst, int row_size, int bits_per_pixel, int pass, const uint8_t *src, int width)
Definition: pngenc.c:85
AV_CODEC_CAP_DELAY
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:76
AV_CRC_32_IEEE_LE
@ AV_CRC_32_IEEE_LE
Definition: crc.h:53
PNGEncContext::last_frame_fctl
APNGFctlChunk last_frame_fctl
Definition: pngenc.c:80
desc
const char * desc
Definition: libsvtav1.c:83
PNGEncContext::dpi
int dpi
Physical pixel density, in dots per inch, if set.
Definition: pngenc.c:63
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
FFZStream
Definition: zlib_wrapper.h:27
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:236
png_enc_init
static av_cold int png_enc_init(AVCodecContext *avctx)
Definition: pngenc.c:1070
AVDictionaryEntry
Definition: dict.h:89
png_write_iccp
static int png_write_iccp(PNGEncContext *s, const AVFrameSideData *sd)
Definition: pngenc.c:327
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
AVPacket
This structure stores compressed data.
Definition: packet.h:351
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:453
png.h
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
d
d
Definition: ffmpeg_filter.c:156
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:598
bytestream.h
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:375
PNG_COLOR_TYPE_GRAY_ALPHA
#define PNG_COLOR_TYPE_GRAY_ALPHA
Definition: png.h:37
AVFrameSideData::metadata
AVDictionary * metadata
Definition: frame.h:240
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
APNGFctlChunk::height
uint32_t height
Definition: pngenc.c:45
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
MKTAG
#define MKTAG(a, b, c, d)
Definition: macros.h:55
AVStereo3D
Stereo 3D type: this structure describes how two videos are packed within a single video surface,...
Definition: stereo3d.h:173
AVDictionaryEntry::value
char * value
Definition: dict.h:91
PNGEncContext::bytestream
uint8_t * bytestream
Definition: pngenc.c:55
PNGEncContext::is_progressive
int is_progressive
Definition: pngenc.c:66
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
VE
#define VE
Definition: pngenc.c:1171
ff_alloc_packet
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
Definition: encode.c:35
encode_headers
static int encode_headers(AVCodecContext *avctx, const AVFrame *pict)
Definition: pngenc.c:369
APNGFctlChunk::dispose_op
uint8_t dispose_op
Definition: pngenc.c:48
AVCodecContext::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
Definition: avcodec.h:795
PNGEncContext::palette_checksum
uint32_t palette_checksum
Definition: pngenc.c:72
PNG_COLOR_TYPE_PALETTE
#define PNG_COLOR_TYPE_PALETTE
Definition: png.h:34
APNGFctlChunk::x_offset
uint32_t x_offset
Definition: pngenc.c:46
ff_deflate_init
int ff_deflate_init(FFZStream *zstream, int level, void *logctx)
Wrapper around deflateInit().
PNGEncContext::sequence_number
uint32_t sequence_number
Definition: pngenc.c:73
AVCodecContext::compression_level
int compression_level
Definition: avcodec.h:498
pngenc_class
static const AVClass pngenc_class
Definition: pngenc.c:1185