FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
pngdec.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 //#define DEBUG
23 
24 #include "config_components.h"
25 
26 #include "libavutil/avassert.h"
27 #include "libavutil/bprint.h"
28 #include "libavutil/crc.h"
29 #include "libavutil/csp.h"
30 #include "libavutil/imgutils.h"
31 #include "libavutil/intreadwrite.h"
33 #include "libavutil/mem.h"
34 #include "libavutil/pixfmt.h"
35 #include "libavutil/rational.h"
36 #include "libavutil/stereo3d.h"
37 
38 #include "avcodec.h"
39 #include "bytestream.h"
40 #include "codec_internal.h"
41 #include "decode.h"
42 #include "apng.h"
43 #include "png.h"
44 #include "pngdsp.h"
45 #include "progressframe.h"
46 #include "thread.h"
47 #include "zlib_wrapper.h"
48 
49 #include <zlib.h>
50 
52  PNG_IHDR = 1 << 0,
53  PNG_PLTE = 1 << 1,
54 };
55 
57  PNG_IDAT = 1 << 0,
58  PNG_ALLIMAGE = 1 << 1,
59 };
60 
61 typedef struct PNGDecContext {
64 
68 
70 
71  uint8_t iccp_name[82];
72  uint8_t *iccp_data;
73  size_t iccp_data_len;
74 
76 
77  int have_chrm;
78  uint32_t white_point[2];
79  uint32_t display_primaries[3][2];
80  int gamma;
81  int have_srgb;
82  int have_cicp;
86  int have_clli;
87  uint32_t clli_max;
88  uint32_t clli_avg;
89  /* Mastering Display Color Volume */
90  int have_mdcv;
91  uint16_t mdcv_primaries[3][2];
92  uint16_t mdcv_white_point[2];
93  uint32_t mdcv_max_lum;
94  uint32_t mdcv_min_lum;
95 
98  int width, height;
99  int cur_w, cur_h;
107  int channels;
109  int bpp;
110  int has_trns;
113 
114  uint32_t palette[256];
115  uint8_t *crow_buf;
116  uint8_t *last_row;
117  unsigned int last_row_size;
118  uint8_t *tmp_row;
119  unsigned int tmp_row_size;
120  uint8_t *buffer;
122  int pass;
123  int crow_size; /* compressed row size (include filter type) */
124  int row_size; /* decompressed row size */
125  int pass_row_size; /* decompress row size of the current pass */
126  int y;
128 } PNGDecContext;
129 
130 /* Mask to determine which pixels are valid in a pass */
131 static const uint8_t png_pass_mask[NB_PASSES] = {
132  0x01, 0x01, 0x11, 0x11, 0x55, 0x55, 0xff,
133 };
134 
135 /* Mask to determine which y pixels can be written in a pass */
136 static const uint8_t png_pass_dsp_ymask[NB_PASSES] = {
137  0xff, 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
138 };
139 
140 /* Mask to determine which pixels to overwrite while displaying */
141 static const uint8_t png_pass_dsp_mask[NB_PASSES] = {
142  0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff
143 };
144 
145 /* NOTE: we try to construct a good looking image at each pass. width
146  * is the original image width. We also do pixel format conversion at
147  * this stage */
148 static void png_put_interlaced_row(uint8_t *dst, int width,
149  int bits_per_pixel, int pass,
150  int color_type, const uint8_t *src)
151 {
152  int x, mask, dsp_mask, j, src_x, b, bpp;
153  uint8_t *d;
154  const uint8_t *s;
155 
156  mask = png_pass_mask[pass];
157  dsp_mask = png_pass_dsp_mask[pass];
158 
159  switch (bits_per_pixel) {
160  case 1:
161  src_x = 0;
162  for (x = 0; x < width; x++) {
163  j = (x & 7);
164  if ((dsp_mask << j) & 0x80) {
165  b = (src[src_x >> 3] >> (7 - (src_x & 7))) & 1;
166  dst[x >> 3] &= 0xFF7F>>j;
167  dst[x >> 3] |= b << (7 - j);
168  }
169  if ((mask << j) & 0x80)
170  src_x++;
171  }
172  break;
173  case 2:
174  src_x = 0;
175  for (x = 0; x < width; x++) {
176  int j2 = 2 * (x & 3);
177  j = (x & 7);
178  if ((dsp_mask << j) & 0x80) {
179  b = (src[src_x >> 2] >> (6 - 2*(src_x & 3))) & 3;
180  dst[x >> 2] &= 0xFF3F>>j2;
181  dst[x >> 2] |= b << (6 - j2);
182  }
183  if ((mask << j) & 0x80)
184  src_x++;
185  }
186  break;
187  case 4:
188  src_x = 0;
189  for (x = 0; x < width; x++) {
190  int j2 = 4*(x&1);
191  j = (x & 7);
192  if ((dsp_mask << j) & 0x80) {
193  b = (src[src_x >> 1] >> (4 - 4*(src_x & 1))) & 15;
194  dst[x >> 1] &= 0xFF0F>>j2;
195  dst[x >> 1] |= b << (4 - j2);
196  }
197  if ((mask << j) & 0x80)
198  src_x++;
199  }
200  break;
201  default:
202  bpp = bits_per_pixel >> 3;
203  d = dst;
204  s = src;
205  for (x = 0; x < width; x++) {
206  j = x & 7;
207  if ((dsp_mask << j) & 0x80) {
208  memcpy(d, s, bpp);
209  }
210  d += bpp;
211  if ((mask << j) & 0x80)
212  s += bpp;
213  }
214  break;
215  }
216 }
217 
218 void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top,
219  int w, int bpp)
220 {
221  int i;
222  for (i = 0; i < w; i++) {
223  int a, b, c, p, pa, pb, pc;
224 
225  a = dst[i - bpp];
226  b = top[i];
227  c = top[i - bpp];
228 
229  p = b - c;
230  pc = a - c;
231 
232  pa = abs(p);
233  pb = abs(pc);
234  pc = abs(p + pc);
235 
236  if (pa <= pb && pa <= pc)
237  p = a;
238  else if (pb <= pc)
239  p = b;
240  else
241  p = c;
242  dst[i] = p + src[i];
243  }
244 }
245 
246 #define UNROLL1(bpp, op) \
247  { \
248  r = dst[0]; \
249  if (bpp >= 2) \
250  g = dst[1]; \
251  if (bpp >= 3) \
252  b = dst[2]; \
253  if (bpp >= 4) \
254  a = dst[3]; \
255  for (; i <= size - bpp; i += bpp) { \
256  dst[i + 0] = r = op(r, src[i + 0], last[i + 0]); \
257  if (bpp == 1) \
258  continue; \
259  dst[i + 1] = g = op(g, src[i + 1], last[i + 1]); \
260  if (bpp == 2) \
261  continue; \
262  dst[i + 2] = b = op(b, src[i + 2], last[i + 2]); \
263  if (bpp == 3) \
264  continue; \
265  dst[i + 3] = a = op(a, src[i + 3], last[i + 3]); \
266  } \
267  }
268 
269 #define UNROLL_FILTER(op) \
270  if (bpp == 1) { \
271  UNROLL1(1, op) \
272  } else if (bpp == 2) { \
273  UNROLL1(2, op) \
274  } else if (bpp == 3) { \
275  UNROLL1(3, op) \
276  } else if (bpp == 4) { \
277  UNROLL1(4, op) \
278  } \
279  for (; i < size; i++) { \
280  dst[i] = op(dst[i - bpp], src[i], last[i]); \
281  }
282 
283 /* NOTE: 'dst' can be equal to 'last' */
284 void ff_png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type,
285  uint8_t *src, uint8_t *last, int size, int bpp)
286 {
287  int i, p, r, g, b, a;
288 
289  switch (filter_type) {
291  memcpy(dst, src, size);
292  break;
294  for (i = 0; i < bpp; i++)
295  dst[i] = src[i];
296  if (bpp == 4) {
297  p = *(int *)dst;
298  for (; i < size; i += bpp) {
299  unsigned s = *(int *)(src + i);
300  p = ((s & 0x7f7f7f7f) + (p & 0x7f7f7f7f)) ^ ((s ^ p) & 0x80808080);
301  *(int *)(dst + i) = p;
302  }
303  } else {
304 #define OP_SUB(x, s, l) ((x) + (s))
306  }
307  break;
308  case PNG_FILTER_VALUE_UP:
309  dsp->add_bytes_l2(dst, src, last, size);
310  break;
312  for (i = 0; i < bpp; i++) {
313  p = (last[i] >> 1);
314  dst[i] = p + src[i];
315  }
316 #define OP_AVG(x, s, l) (((((x) + (l)) >> 1) + (s)) & 0xff)
318  break;
320  for (i = 0; i < bpp; i++) {
321  p = last[i];
322  dst[i] = p + src[i];
323  }
324  if (bpp > 2 && size > 4) {
325  /* would write off the end of the array if we let it process
326  * the last pixel with bpp=3 */
327  int w = (bpp & 3) ? size - 3 : size;
328 
329  if (w > i) {
330  dsp->add_paeth_prediction(dst + i, src + i, last + i, size - i, bpp);
331  i = w;
332  }
333  }
334  ff_add_png_paeth_prediction(dst + i, src + i, last + i, size - i, bpp);
335  break;
336  }
337 }
338 
339 /* This used to be called "deloco" in FFmpeg
340  * and is actually an inverse reversible colorspace transformation */
341 #define YUV2RGB(NAME, TYPE) \
342 static void deloco_ ## NAME(TYPE *dst, int size, int alpha) \
343 { \
344  int i; \
345  for (i = 0; i < size - 2; i += 3 + alpha) { \
346  int g = dst [i + 1]; \
347  dst[i + 0] += g; \
348  dst[i + 2] += g; \
349  } \
350 }
351 
352 YUV2RGB(rgb8, uint8_t)
353 YUV2RGB(rgb16, uint16_t)
354 
356 {
357  if (s->interlace_type) {
358  return 100 - 100 * s->pass / (NB_PASSES - 1);
359  } else {
360  return 100 - 100 * s->y / s->cur_h;
361  }
362 }
363 
364 /* process exactly one decompressed row */
365 static void png_handle_row(PNGDecContext *s, uint8_t *dst, ptrdiff_t dst_stride)
366 {
367  uint8_t *ptr, *last_row;
368  int got_line;
369 
370  if (!s->interlace_type) {
371  ptr = dst + dst_stride * (s->y + s->y_offset) + s->x_offset * s->bpp;
372  if (s->y == 0)
373  last_row = s->last_row;
374  else
375  last_row = ptr - dst_stride;
376 
377  ff_png_filter_row(&s->dsp, ptr, s->crow_buf[0], s->crow_buf + 1,
378  last_row, s->row_size, s->bpp);
379  /* loco lags by 1 row so that it doesn't interfere with top prediction */
380  if (s->filter_type == PNG_FILTER_TYPE_LOCO && s->y > 0) {
381  if (s->bit_depth == 16) {
382  deloco_rgb16((uint16_t *)(ptr - dst_stride), s->row_size / 2,
383  s->color_type == PNG_COLOR_TYPE_RGB_ALPHA);
384  } else {
385  deloco_rgb8(ptr - dst_stride, s->row_size,
386  s->color_type == PNG_COLOR_TYPE_RGB_ALPHA);
387  }
388  }
389  s->y++;
390  if (s->y == s->cur_h) {
391  s->pic_state |= PNG_ALLIMAGE;
392  if (s->filter_type == PNG_FILTER_TYPE_LOCO) {
393  if (s->bit_depth == 16) {
394  deloco_rgb16((uint16_t *)ptr, s->row_size / 2,
395  s->color_type == PNG_COLOR_TYPE_RGB_ALPHA);
396  } else {
397  deloco_rgb8(ptr, s->row_size,
398  s->color_type == PNG_COLOR_TYPE_RGB_ALPHA);
399  }
400  }
401  }
402  } else {
403  got_line = 0;
404  for (;;) {
405  ptr = dst + dst_stride * (s->y + s->y_offset) + s->x_offset * s->bpp;
406  if ((ff_png_pass_ymask[s->pass] << (s->y & 7)) & 0x80) {
407  /* if we already read one row, it is time to stop to
408  * wait for the next one */
409  if (got_line)
410  break;
411  ff_png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
412  s->last_row, s->pass_row_size, s->bpp);
413  FFSWAP(uint8_t *, s->last_row, s->tmp_row);
414  FFSWAP(unsigned int, s->last_row_size, s->tmp_row_size);
415  got_line = 1;
416  }
417  if ((png_pass_dsp_ymask[s->pass] << (s->y & 7)) & 0x80) {
418  png_put_interlaced_row(ptr, s->cur_w, s->bits_per_pixel, s->pass,
419  s->color_type, s->last_row);
420  }
421  s->y++;
422  if (s->y == s->cur_h) {
423  memset(s->last_row, 0, s->row_size);
424  for (;;) {
425  if (s->pass == NB_PASSES - 1) {
426  s->pic_state |= PNG_ALLIMAGE;
427  goto the_end;
428  } else {
429  s->pass++;
430  s->y = 0;
431  s->pass_row_size = ff_png_pass_row_size(s->pass,
432  s->bits_per_pixel,
433  s->cur_w);
434  s->crow_size = s->pass_row_size + 1;
435  if (s->pass_row_size != 0)
436  break;
437  /* skip pass if empty row */
438  }
439  }
440  }
441  }
442 the_end:;
443  }
444 }
445 
447  uint8_t *dst, ptrdiff_t dst_stride)
448 {
449  z_stream *const zstream = &s->zstream.zstream;
450  int ret;
451  zstream->avail_in = bytestream2_get_bytes_left(gb);
452  zstream->next_in = gb->buffer;
453 
454  /* decode one line if possible */
455  while (zstream->avail_in > 0) {
456  ret = inflate(zstream, Z_PARTIAL_FLUSH);
457  if (ret != Z_OK && ret != Z_STREAM_END) {
458  av_log(s->avctx, AV_LOG_ERROR, "inflate returned error %d\n", ret);
459  return AVERROR_EXTERNAL;
460  }
461  if (zstream->avail_out == 0) {
462  if (!(s->pic_state & PNG_ALLIMAGE)) {
463  png_handle_row(s, dst, dst_stride);
464  }
465  zstream->avail_out = s->crow_size;
466  zstream->next_out = s->crow_buf;
467  }
468  if (ret == Z_STREAM_END && zstream->avail_in > 0) {
469  av_log(s->avctx, AV_LOG_WARNING,
470  "%d undecompressed bytes left in buffer\n", zstream->avail_in);
471  return 0;
472  }
473  }
474  return 0;
475 }
476 
477 static int decode_zbuf(AVBPrint *bp, const uint8_t *data,
478  const uint8_t *data_end, void *logctx)
479 {
480  FFZStream z;
481  z_stream *const zstream = &z.zstream;
482  unsigned char *buf;
483  unsigned buf_size;
484  int ret = ff_inflate_init(&z, logctx);
485  if (ret < 0)
486  return ret;
487 
488  zstream->next_in = data;
489  zstream->avail_in = data_end - data;
491 
492  while (zstream->avail_in > 0) {
493  av_bprint_get_buffer(bp, 2, &buf, &buf_size);
494  if (buf_size < 2) {
495  ret = AVERROR(ENOMEM);
496  goto fail;
497  }
498  zstream->next_out = buf;
499  zstream->avail_out = buf_size - 1;
500  ret = inflate(zstream, Z_PARTIAL_FLUSH);
501  if (ret != Z_OK && ret != Z_STREAM_END) {
503  goto fail;
504  }
505  bp->len += zstream->next_out - buf;
506  if (ret == Z_STREAM_END)
507  break;
508  }
509  ff_inflate_end(&z);
510  bp->str[bp->len] = 0;
511  return 0;
512 
513 fail:
514  ff_inflate_end(&z);
516  return ret;
517 }
518 
519 static char *iso88591_to_utf8(const char *in, size_t size_in)
520 {
521  size_t extra = 0, i;
522  char *out, *q;
523 
524  for (i = 0; i < size_in; i++)
525  extra += !!(in[i] & 0x80);
526  if (size_in == SIZE_MAX || extra > SIZE_MAX - size_in - 1)
527  return NULL;
528  q = out = av_malloc(size_in + extra + 1);
529  if (!out)
530  return NULL;
531  for (i = 0; i < size_in; i++) {
532  if (in[i] & 0x80) {
533  *(q++) = 0xC0 | (in[i] >> 6);
534  *(q++) = 0x80 | (in[i] & 0x3F);
535  } else {
536  *(q++) = in[i];
537  }
538  }
539  *(q++) = 0;
540  return out;
541 }
542 
543 static int decode_text_chunk(PNGDecContext *s, GetByteContext *gb, int compressed)
544 {
545  int ret, method;
546  const uint8_t *data = gb->buffer;
547  const uint8_t *data_end = gb->buffer_end;
548  const char *keyword = data;
549  const char *keyword_end = memchr(keyword, 0, data_end - data);
550  char *kw_utf8 = NULL, *txt_utf8 = NULL;
551  const char *text;
552  unsigned text_len;
553  AVBPrint bp;
554 
555  if (!keyword_end)
556  return AVERROR_INVALIDDATA;
557  data = keyword_end + 1;
558 
559  if (compressed) {
560  if (data == data_end)
561  return AVERROR_INVALIDDATA;
562  method = *(data++);
563  if (method)
564  return AVERROR_INVALIDDATA;
565  if ((ret = decode_zbuf(&bp, data, data_end, s->avctx)) < 0)
566  return ret;
567  text = bp.str;
568  text_len = bp.len;
569  } else {
570  text = data;
571  text_len = data_end - data;
572  }
573 
574  txt_utf8 = iso88591_to_utf8(text, text_len);
575  if (compressed)
576  av_bprint_finalize(&bp, NULL);
577  if (!txt_utf8)
578  return AVERROR(ENOMEM);
579  kw_utf8 = iso88591_to_utf8(keyword, keyword_end - keyword);
580  if (!kw_utf8) {
581  av_free(txt_utf8);
582  return AVERROR(ENOMEM);
583  }
584 
585  av_dict_set(&s->frame_metadata, kw_utf8, txt_utf8,
587  return 0;
588 }
589 
591  GetByteContext *gb)
592 {
593  if (bytestream2_get_bytes_left(gb) != 13)
594  return AVERROR_INVALIDDATA;
595 
596  if (s->pic_state & PNG_IDAT) {
597  av_log(avctx, AV_LOG_ERROR, "IHDR after IDAT\n");
598  return AVERROR_INVALIDDATA;
599  }
600 
601  if (s->hdr_state & PNG_IHDR) {
602  av_log(avctx, AV_LOG_ERROR, "Multiple IHDR\n");
603  return AVERROR_INVALIDDATA;
604  }
605 
606  s->width = s->cur_w = bytestream2_get_be32(gb);
607  s->height = s->cur_h = bytestream2_get_be32(gb);
608  if (av_image_check_size(s->width, s->height, 0, avctx)) {
609  s->cur_w = s->cur_h = s->width = s->height = 0;
610  av_log(avctx, AV_LOG_ERROR, "Invalid image size\n");
611  return AVERROR_INVALIDDATA;
612  }
613  s->bit_depth = bytestream2_get_byte(gb);
614  if (s->bit_depth != 1 && s->bit_depth != 2 && s->bit_depth != 4 &&
615  s->bit_depth != 8 && s->bit_depth != 16) {
616  av_log(avctx, AV_LOG_ERROR, "Invalid bit depth\n");
617  goto error;
618  }
619  s->color_type = bytestream2_get_byte(gb);
620  s->compression_type = bytestream2_get_byte(gb);
621  if (s->compression_type) {
622  av_log(avctx, AV_LOG_ERROR, "Invalid compression method %d\n", s->compression_type);
623  goto error;
624  }
625  s->filter_type = bytestream2_get_byte(gb);
626  s->interlace_type = bytestream2_get_byte(gb);
627  s->hdr_state |= PNG_IHDR;
628  if (avctx->debug & FF_DEBUG_PICT_INFO)
629  av_log(avctx, AV_LOG_DEBUG, "width=%d height=%d depth=%d color_type=%d "
630  "compression_type=%d filter_type=%d interlace_type=%d\n",
631  s->width, s->height, s->bit_depth, s->color_type,
632  s->compression_type, s->filter_type, s->interlace_type);
633 
634  return 0;
635 error:
636  s->cur_w = s->cur_h = s->width = s->height = 0;
637  s->bit_depth = 8;
638  return AVERROR_INVALIDDATA;
639 }
640 
642  GetByteContext *gb)
643 {
644  if (s->pic_state & PNG_IDAT) {
645  av_log(avctx, AV_LOG_ERROR, "pHYs after IDAT\n");
646  return AVERROR_INVALIDDATA;
647  }
648  avctx->sample_aspect_ratio.num = bytestream2_get_be32(gb);
649  avctx->sample_aspect_ratio.den = bytestream2_get_be32(gb);
650  if (avctx->sample_aspect_ratio.num < 0 || avctx->sample_aspect_ratio.den < 0)
651  avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
652  bytestream2_skip(gb, 1); /* unit specifier */
653 
654  return 0;
655 }
656 
657 /*
658  * This populates AVCodecContext fields so it must be called before
659  * ff_thread_finish_setup() to avoid a race condition with respect to the
660  * generic copying of avctx fields.
661  */
663 {
664  PNGDecContext *s = avctx->priv_data;
665  int ret;
666 
667  if (s->have_cicp) {
668  if (s->cicp_primaries >= AVCOL_PRI_NB)
669  av_log(avctx, AV_LOG_WARNING, "unrecognized cICP primaries\n");
670  else
671  avctx->color_primaries = frame->color_primaries = s->cicp_primaries;
672  if (s->cicp_trc >= AVCOL_TRC_NB)
673  av_log(avctx, AV_LOG_WARNING, "unrecognized cICP transfer\n");
674  else
675  avctx->color_trc = frame->color_trc = s->cicp_trc;
676  if (s->cicp_range == 0) {
677  av_log(avctx, AV_LOG_WARNING, "tv-range cICP tag found. Colors may be wrong\n");
678  avctx->color_range = frame->color_range = AVCOL_RANGE_MPEG;
679  } else if (s->cicp_range != 1) {
680  /* we already printed a warning when parsing the cICP chunk */
681  avctx->color_range = frame->color_range = AVCOL_RANGE_UNSPECIFIED;
682  }
683  } else if (s->iccp_data) {
684  AVFrameSideData *sd;
686  s->iccp_data_len, &sd);
687  if (ret < 0)
688  return ret;
689  if (sd) {
690  memcpy(sd->data, s->iccp_data, s->iccp_data_len);
691  av_dict_set(&sd->metadata, "name", s->iccp_name, 0);
692  }
693  } else if (s->have_srgb) {
694  avctx->color_primaries = frame->color_primaries = AVCOL_PRI_BT709;
695  avctx->color_trc = frame->color_trc = AVCOL_TRC_IEC61966_2_1;
696  } else if (s->have_chrm) {
698  enum AVColorPrimaries prim;
699  desc.wp.x = av_make_q(s->white_point[0], 100000);
700  desc.wp.y = av_make_q(s->white_point[1], 100000);
701  desc.prim.r.x = av_make_q(s->display_primaries[0][0], 100000);
702  desc.prim.r.y = av_make_q(s->display_primaries[0][1], 100000);
703  desc.prim.g.x = av_make_q(s->display_primaries[1][0], 100000);
704  desc.prim.g.y = av_make_q(s->display_primaries[1][1], 100000);
705  desc.prim.b.x = av_make_q(s->display_primaries[2][0], 100000);
706  desc.prim.b.y = av_make_q(s->display_primaries[2][1], 100000);
708  if (prim != AVCOL_PRI_UNSPECIFIED)
709  avctx->color_primaries = frame->color_primaries = prim;
710  else
711  av_log(avctx, AV_LOG_WARNING, "unknown cHRM primaries\n");
712  }
713 
714  /* these chunks override gAMA */
715  if (s->iccp_data || s->have_srgb || s->have_cicp) {
716  av_dict_set(&s->frame_metadata, "gamma", NULL, 0);
717  } else if (s->gamma) {
718  /*
719  * These values are 100000/2.2, 100000/2.8, 100000/2.6, and
720  * 100000/1.0 respectively. 45455, 35714, and 38462, and 100000.
721  * There's a 0.001 gamma tolerance here in case of floating
722  * point issues when the PNG was written.
723  *
724  * None of the other enums have a pure gamma curve so it makes
725  * sense to leave those to sRGB and cICP.
726  */
727  if (s->gamma > 45355 && s->gamma < 45555)
728  avctx->color_trc = frame->color_trc = AVCOL_TRC_GAMMA22;
729  else if (s->gamma > 35614 && s->gamma < 35814)
730  avctx->color_trc = frame->color_trc = AVCOL_TRC_GAMMA28;
731  else if (s->gamma > 38362 && s->gamma < 38562)
732  avctx->color_trc = frame->color_trc = AVCOL_TRC_SMPTE428;
733  else if (s->gamma > 99900 && s->gamma < 100100)
734  avctx->color_trc = frame->color_trc = AVCOL_TRC_LINEAR;
735  }
736 
737  /* PNG only supports RGB */
738  avctx->colorspace = frame->colorspace = AVCOL_SPC_RGB;
739  if (!s->have_cicp || s->cicp_range == 1)
740  avctx->color_range = frame->color_range = AVCOL_RANGE_JPEG;
741 
742  /*
743  * tRNS sets alpha depth to full, so we ignore sBIT if set.
744  * As a result we must wait until now to set
745  * avctx->bits_per_raw_sample in case tRNS appears after sBIT
746  */
747  if (!s->has_trns && s->significant_bits > 0)
748  avctx->bits_per_raw_sample = s->significant_bits;
749 
750  if (s->have_clli) {
752 
753  ret = ff_decode_content_light_new(avctx, frame, &clli);
754  if (ret < 0)
755  return ret;
756 
757  if (clli) {
758  /*
759  * 0.0001 divisor value
760  * see: https://www.w3.org/TR/png-3/#cLLI-chunk
761  */
762  clli->MaxCLL = s->clli_max / 10000;
763  clli->MaxFALL = s->clli_avg / 10000;
764  }
765  }
766 
767  if (s->have_mdcv) {
769 
770  ret = ff_decode_mastering_display_new(avctx, frame, &mdcv);
771  if (ret < 0)
772  return ret;
773 
774  if (mdcv) {
775  mdcv->has_primaries = 1;
776  for (int i = 0; i < 3; i++) {
777  mdcv->display_primaries[i][0] = av_make_q(s->mdcv_primaries[i][0], 50000);
778  mdcv->display_primaries[i][1] = av_make_q(s->mdcv_primaries[i][1], 50000);
779  }
780  mdcv->white_point[0] = av_make_q(s->mdcv_white_point[0], 50000);
781  mdcv->white_point[1] = av_make_q(s->mdcv_white_point[1], 50000);
782  mdcv->has_luminance = 1;
783  mdcv->max_luminance = av_make_q(s->mdcv_max_lum, 10000);
784  mdcv->min_luminance = av_make_q(s->mdcv_min_lum, 10000);
785  }
786  }
787 
788  return 0;
789 }
790 
792  GetByteContext *gb, AVFrame *p)
793 {
794  int ret;
795  size_t byte_depth = s->bit_depth > 8 ? 2 : 1;
796 
797  if (!p)
798  return AVERROR_INVALIDDATA;
799  if (!(s->hdr_state & PNG_IHDR)) {
800  av_log(avctx, AV_LOG_ERROR, "IDAT without IHDR\n");
801  return AVERROR_INVALIDDATA;
802  }
803  if (!(s->pic_state & PNG_IDAT)) {
804  /* init image info */
805  ret = ff_set_dimensions(avctx, s->width, s->height);
806  if (ret < 0)
807  return ret;
808 
809  s->channels = ff_png_get_nb_channels(s->color_type);
810  s->bits_per_pixel = s->bit_depth * s->channels;
811  s->bpp = (s->bits_per_pixel + 7) >> 3;
812  s->row_size = (s->cur_w * s->bits_per_pixel + 7) >> 3;
813 
814  if ((s->bit_depth == 2 || s->bit_depth == 4 || s->bit_depth == 8) &&
815  s->color_type == PNG_COLOR_TYPE_RGB) {
816  avctx->pix_fmt = AV_PIX_FMT_RGB24;
817  } else if ((s->bit_depth == 2 || s->bit_depth == 4 || s->bit_depth == 8) &&
818  s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
819  avctx->pix_fmt = AV_PIX_FMT_RGBA;
820  } else if ((s->bit_depth == 2 || s->bit_depth == 4 || s->bit_depth == 8) &&
821  s->color_type == PNG_COLOR_TYPE_GRAY) {
822  avctx->pix_fmt = AV_PIX_FMT_GRAY8;
823  } else if (s->bit_depth == 16 &&
824  s->color_type == PNG_COLOR_TYPE_GRAY) {
825  avctx->pix_fmt = AV_PIX_FMT_GRAY16BE;
826  } else if (s->bit_depth == 16 &&
827  s->color_type == PNG_COLOR_TYPE_RGB) {
828  avctx->pix_fmt = AV_PIX_FMT_RGB48BE;
829  } else if (s->bit_depth == 16 &&
830  s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
831  avctx->pix_fmt = AV_PIX_FMT_RGBA64BE;
832  } else if ((s->bits_per_pixel == 1 || s->bits_per_pixel == 2 || s->bits_per_pixel == 4 || s->bits_per_pixel == 8) &&
833  s->color_type == PNG_COLOR_TYPE_PALETTE) {
835  } else if (s->bit_depth == 1 && s->bits_per_pixel == 1 && avctx->codec_id != AV_CODEC_ID_APNG) {
836  avctx->pix_fmt = AV_PIX_FMT_MONOBLACK;
837  } else if (s->bit_depth == 8 &&
838  s->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
839  avctx->pix_fmt = AV_PIX_FMT_YA8;
840  } else if (s->bit_depth == 16 &&
841  s->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
842  avctx->pix_fmt = AV_PIX_FMT_YA16BE;
843  } else {
845  "Bit depth %d color type %d",
846  s->bit_depth, s->color_type);
847  return AVERROR_PATCHWELCOME;
848  }
849 
850  if (s->has_trns && s->color_type != PNG_COLOR_TYPE_PALETTE) {
851  switch (avctx->pix_fmt) {
852  case AV_PIX_FMT_RGB24:
853  avctx->pix_fmt = AV_PIX_FMT_RGBA;
854  break;
855 
856  case AV_PIX_FMT_RGB48BE:
857  avctx->pix_fmt = AV_PIX_FMT_RGBA64BE;
858  break;
859 
860  case AV_PIX_FMT_GRAY8:
861  avctx->pix_fmt = AV_PIX_FMT_YA8;
862  break;
863 
864  case AV_PIX_FMT_GRAY16BE:
865  avctx->pix_fmt = AV_PIX_FMT_YA16BE;
866  break;
867 
868  default:
869  avpriv_request_sample(avctx, "bit depth %d "
870  "and color type %d with TRNS",
871  s->bit_depth, s->color_type);
872  return AVERROR_INVALIDDATA;
873  }
874 
875  s->bpp += byte_depth;
876  }
877 
878  ff_progress_frame_unref(&s->picture);
879  if (s->dispose_op == APNG_DISPOSE_OP_PREVIOUS) {
880  /* We only need a buffer for the current picture. */
881  ret = ff_thread_get_buffer(avctx, p, 0);
882  if (ret < 0)
883  return ret;
884  } else if (s->dispose_op == APNG_DISPOSE_OP_BACKGROUND) {
885  /* We need a buffer for the current picture as well as
886  * a buffer for the reference to retain. */
887  ret = ff_progress_frame_get_buffer(avctx, &s->picture,
889  if (ret < 0)
890  return ret;
891  ret = ff_thread_get_buffer(avctx, p, 0);
892  if (ret < 0)
893  return ret;
894  } else {
895  /* The picture output this time and the reference to retain coincide. */
896  ret = ff_progress_frame_get_buffer(avctx, &s->picture,
898  if (ret < 0)
899  return ret;
900  ret = av_frame_ref(p, s->picture.f);
901  if (ret < 0)
902  return ret;
903  }
904 
906  p->flags |= AV_FRAME_FLAG_KEY;
907  p->flags |= AV_FRAME_FLAG_INTERLACED * !!s->interlace_type;
908 
909  if ((ret = populate_avctx_color_fields(avctx, p)) < 0)
910  return ret;
911  ff_thread_finish_setup(avctx);
912 
913  /* compute the compressed row size */
914  if (!s->interlace_type) {
915  s->crow_size = s->row_size + 1;
916  } else {
917  s->pass = 0;
918  s->pass_row_size = ff_png_pass_row_size(s->pass,
919  s->bits_per_pixel,
920  s->cur_w);
921  s->crow_size = s->pass_row_size + 1;
922  }
923  ff_dlog(avctx, "row_size=%d crow_size =%d\n",
924  s->row_size, s->crow_size);
925 
926  /* copy the palette if needed */
927  if (avctx->pix_fmt == AV_PIX_FMT_PAL8)
928  memcpy(p->data[1], s->palette, 256 * sizeof(uint32_t));
929  /* empty row is used if differencing to the first row */
930  av_fast_padded_mallocz(&s->last_row, &s->last_row_size, s->row_size);
931  if (!s->last_row)
932  return AVERROR_INVALIDDATA;
933  if (s->interlace_type ||
934  s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
935  av_fast_padded_malloc(&s->tmp_row, &s->tmp_row_size, s->row_size);
936  if (!s->tmp_row)
937  return AVERROR_INVALIDDATA;
938  }
939  /* compressed row */
940  av_fast_padded_malloc(&s->buffer, &s->buffer_size, s->row_size + 16);
941  if (!s->buffer)
942  return AVERROR(ENOMEM);
943 
944  /* we want crow_buf+1 to be 16-byte aligned */
945  s->crow_buf = s->buffer + 15;
946  s->zstream.zstream.avail_out = s->crow_size;
947  s->zstream.zstream.next_out = s->crow_buf;
948  }
949 
950  s->pic_state |= PNG_IDAT;
951 
952  /* set image to non-transparent bpp while decompressing */
953  if (s->has_trns && s->color_type != PNG_COLOR_TYPE_PALETTE)
954  s->bpp -= byte_depth;
955 
956  ret = png_decode_idat(s, gb, p->data[0], p->linesize[0]);
957 
958  if (s->has_trns && s->color_type != PNG_COLOR_TYPE_PALETTE)
959  s->bpp += byte_depth;
960 
961  if (ret < 0)
962  return ret;
963 
964  return 0;
965 }
966 
968  GetByteContext *gb)
969 {
970  int length = bytestream2_get_bytes_left(gb);
971  int n, i, r, g, b;
972 
973  if ((length % 3) != 0 || length > 256 * 3)
974  return AVERROR_INVALIDDATA;
975  /* read the palette */
976  n = length / 3;
977  for (i = 0; i < n; i++) {
978  r = bytestream2_get_byte(gb);
979  g = bytestream2_get_byte(gb);
980  b = bytestream2_get_byte(gb);
981  s->palette[i] = (0xFFU << 24) | (r << 16) | (g << 8) | b;
982  }
983  for (; i < 256; i++)
984  s->palette[i] = (0xFFU << 24);
985  s->hdr_state |= PNG_PLTE;
986 
987  return 0;
988 }
989 
991  GetByteContext *gb)
992 {
993  int length = bytestream2_get_bytes_left(gb);
994  int v, i;
995 
996  if (!(s->hdr_state & PNG_IHDR)) {
997  av_log(avctx, AV_LOG_ERROR, "trns before IHDR\n");
998  return AVERROR_INVALIDDATA;
999  }
1000 
1001  if (s->pic_state & PNG_IDAT) {
1002  av_log(avctx, AV_LOG_ERROR, "trns after IDAT\n");
1003  return AVERROR_INVALIDDATA;
1004  }
1005 
1006  if (s->color_type == PNG_COLOR_TYPE_PALETTE) {
1007  if (length > 256 || !(s->hdr_state & PNG_PLTE))
1008  return AVERROR_INVALIDDATA;
1009 
1010  for (i = 0; i < length; i++) {
1011  unsigned v = bytestream2_get_byte(gb);
1012  s->palette[i] = (s->palette[i] & 0x00ffffff) | (v << 24);
1013  }
1014  } else if (s->color_type == PNG_COLOR_TYPE_GRAY || s->color_type == PNG_COLOR_TYPE_RGB) {
1015  if ((s->color_type == PNG_COLOR_TYPE_GRAY && length != 2) ||
1016  (s->color_type == PNG_COLOR_TYPE_RGB && length != 6) ||
1017  s->bit_depth == 1)
1018  return AVERROR_INVALIDDATA;
1019 
1020  for (i = 0; i < length / 2; i++) {
1021  /* only use the least significant bits */
1022  v = av_zero_extend(bytestream2_get_be16(gb), s->bit_depth);
1023 
1024  if (s->bit_depth > 8)
1025  AV_WB16(&s->transparent_color_be[2 * i], v);
1026  else
1027  s->transparent_color_be[i] = v;
1028  }
1029  } else {
1030  return AVERROR_INVALIDDATA;
1031  }
1032 
1033  s->has_trns = 1;
1034 
1035  return 0;
1036 }
1037 
1039 {
1040  int ret, cnt = 0;
1041  AVBPrint bp;
1042 
1043  while ((s->iccp_name[cnt++] = bytestream2_get_byte(gb)) && cnt < 81);
1044  if (cnt > 80) {
1045  av_log(s->avctx, AV_LOG_ERROR, "iCCP with invalid name!\n");
1047  goto fail;
1048  }
1049 
1050  if (bytestream2_get_byte(gb) != 0) {
1051  av_log(s->avctx, AV_LOG_ERROR, "iCCP with invalid compression!\n");
1053  goto fail;
1054  }
1055 
1056  if ((ret = decode_zbuf(&bp, gb->buffer, gb->buffer_end, s->avctx)) < 0)
1057  return ret;
1058 
1059  av_freep(&s->iccp_data);
1060  ret = av_bprint_finalize(&bp, (char **)&s->iccp_data);
1061  if (ret < 0)
1062  return ret;
1063  s->iccp_data_len = bp.len;
1064 
1065  return 0;
1066 fail:
1067  s->iccp_name[0] = 0;
1068  return ret;
1069 }
1070 
1072  GetByteContext *gb)
1073 {
1074  int bits = 0;
1075  int channels;
1076  int remainder = bytestream2_get_bytes_left(gb);
1077 
1078  if (!(s->hdr_state & PNG_IHDR)) {
1079  av_log(avctx, AV_LOG_ERROR, "sBIT before IHDR\n");
1080  return AVERROR_INVALIDDATA;
1081  }
1082 
1083  if (s->pic_state & PNG_IDAT) {
1084  av_log(avctx, AV_LOG_WARNING, "Ignoring illegal sBIT chunk after IDAT\n");
1085  return 0;
1086  }
1087 
1088  channels = s->color_type & PNG_COLOR_MASK_PALETTE ? 3 : ff_png_get_nb_channels(s->color_type);
1089 
1090  if (remainder != channels) {
1091  av_log(avctx, AV_LOG_WARNING, "Invalid sBIT size: %d, expected: %d\n", remainder, channels);
1092  /* not enough space left in chunk to read info */
1093  if (remainder < channels)
1094  return 0;
1095  }
1096 
1097  for (int i = 0; i < channels; i++) {
1098  int b = bytestream2_get_byteu(gb);
1099  bits = FFMAX(b, bits);
1100  }
1101 
1102  if (bits <= 0 || bits > (s->color_type & PNG_COLOR_MASK_PALETTE ? 8 : s->bit_depth)) {
1103  av_log(avctx, AV_LOG_WARNING, "Invalid significant bits: %d\n", bits);
1104  return 0;
1105  }
1106  s->significant_bits = bits;
1107 
1108  return 0;
1109 }
1110 
1112 {
1113  if (s->bits_per_pixel == 1 && s->color_type == PNG_COLOR_TYPE_PALETTE) {
1114  int i, j, k;
1115  uint8_t *pd = p->data[0];
1116  for (j = 0; j < s->height; j++) {
1117  i = s->width / 8;
1118  for (k = 7; k >= 1; k--)
1119  if ((s->width&7) >= k)
1120  pd[8*i + k - 1] = (pd[i]>>8-k) & 1;
1121  for (i--; i >= 0; i--) {
1122  pd[8*i + 7]= pd[i] & 1;
1123  pd[8*i + 6]= (pd[i]>>1) & 1;
1124  pd[8*i + 5]= (pd[i]>>2) & 1;
1125  pd[8*i + 4]= (pd[i]>>3) & 1;
1126  pd[8*i + 3]= (pd[i]>>4) & 1;
1127  pd[8*i + 2]= (pd[i]>>5) & 1;
1128  pd[8*i + 1]= (pd[i]>>6) & 1;
1129  pd[8*i + 0]= pd[i]>>7;
1130  }
1131  pd += p->linesize[0];
1132  }
1133  } else if (s->bits_per_pixel == 2) {
1134  int i, j;
1135  uint8_t *pd = p->data[0];
1136  for (j = 0; j < s->height; j++) {
1137  i = s->width / 4;
1138  if (s->color_type == PNG_COLOR_TYPE_PALETTE) {
1139  if ((s->width&3) >= 3) pd[4*i + 2]= (pd[i] >> 2) & 3;
1140  if ((s->width&3) >= 2) pd[4*i + 1]= (pd[i] >> 4) & 3;
1141  if ((s->width&3) >= 1) pd[4*i + 0]= pd[i] >> 6;
1142  for (i--; i >= 0; i--) {
1143  pd[4*i + 3]= pd[i] & 3;
1144  pd[4*i + 2]= (pd[i]>>2) & 3;
1145  pd[4*i + 1]= (pd[i]>>4) & 3;
1146  pd[4*i + 0]= pd[i]>>6;
1147  }
1148  } else {
1149  if ((s->width&3) >= 3) pd[4*i + 2]= ((pd[i]>>2) & 3)*0x55;
1150  if ((s->width&3) >= 2) pd[4*i + 1]= ((pd[i]>>4) & 3)*0x55;
1151  if ((s->width&3) >= 1) pd[4*i + 0]= ( pd[i]>>6 )*0x55;
1152  for (i--; i >= 0; i--) {
1153  pd[4*i + 3]= ( pd[i] & 3)*0x55;
1154  pd[4*i + 2]= ((pd[i]>>2) & 3)*0x55;
1155  pd[4*i + 1]= ((pd[i]>>4) & 3)*0x55;
1156  pd[4*i + 0]= ( pd[i]>>6 )*0x55;
1157  }
1158  }
1159  pd += p->linesize[0];
1160  }
1161  } else if (s->bits_per_pixel == 4) {
1162  int i, j;
1163  uint8_t *pd = p->data[0];
1164  for (j = 0; j < s->height; j++) {
1165  i = s->width/2;
1166  if (s->color_type == PNG_COLOR_TYPE_PALETTE) {
1167  if (s->width&1) pd[2*i+0]= pd[i]>>4;
1168  for (i--; i >= 0; i--) {
1169  pd[2*i + 1] = pd[i] & 15;
1170  pd[2*i + 0] = pd[i] >> 4;
1171  }
1172  } else {
1173  if (s->width & 1) pd[2*i + 0]= (pd[i] >> 4) * 0x11;
1174  for (i--; i >= 0; i--) {
1175  pd[2*i + 1] = (pd[i] & 15) * 0x11;
1176  pd[2*i + 0] = (pd[i] >> 4) * 0x11;
1177  }
1178  }
1179  pd += p->linesize[0];
1180  }
1181  }
1182 }
1183 
1185  GetByteContext *gb)
1186 {
1187  uint32_t sequence_number;
1188  int cur_w, cur_h, x_offset, y_offset, dispose_op, blend_op;
1189 
1191  return AVERROR_INVALIDDATA;
1192 
1193  if (!(s->hdr_state & PNG_IHDR)) {
1194  av_log(avctx, AV_LOG_ERROR, "fctl before IHDR\n");
1195  return AVERROR_INVALIDDATA;
1196  }
1197 
1198  if (s->pic_state & PNG_IDAT) {
1199  av_log(avctx, AV_LOG_ERROR, "fctl after IDAT\n");
1200  return AVERROR_INVALIDDATA;
1201  }
1202 
1203  sequence_number = bytestream2_get_be32(gb);
1204  cur_w = bytestream2_get_be32(gb);
1205  cur_h = bytestream2_get_be32(gb);
1206  x_offset = bytestream2_get_be32(gb);
1207  y_offset = bytestream2_get_be32(gb);
1208  bytestream2_skip(gb, 4); /* delay_num (2), delay_den (2) */
1209  dispose_op = bytestream2_get_byte(gb);
1210  blend_op = bytestream2_get_byte(gb);
1211 
1212  if (sequence_number == 0 &&
1213  (cur_w != s->width ||
1214  cur_h != s->height ||
1215  x_offset != 0 ||
1216  y_offset != 0) ||
1217  cur_w <= 0 || cur_h <= 0 ||
1218  x_offset < 0 || y_offset < 0 ||
1219  cur_w > s->width - x_offset|| cur_h > s->height - y_offset)
1220  return AVERROR_INVALIDDATA;
1221 
1222  if (blend_op != APNG_BLEND_OP_OVER && blend_op != APNG_BLEND_OP_SOURCE) {
1223  av_log(avctx, AV_LOG_ERROR, "Invalid blend_op %d\n", blend_op);
1224  return AVERROR_INVALIDDATA;
1225  }
1226 
1227  if ((sequence_number == 0 || !s->last_picture.f) &&
1228  dispose_op == APNG_DISPOSE_OP_PREVIOUS) {
1229  // No previous frame to revert to for the first frame
1230  // Spec says to just treat it as a APNG_DISPOSE_OP_BACKGROUND
1231  dispose_op = APNG_DISPOSE_OP_BACKGROUND;
1232  }
1233 
1234  if (blend_op == APNG_BLEND_OP_OVER && !s->has_trns && (
1235  avctx->pix_fmt == AV_PIX_FMT_RGB24 ||
1236  avctx->pix_fmt == AV_PIX_FMT_RGB48BE ||
1237  avctx->pix_fmt == AV_PIX_FMT_GRAY8 ||
1238  avctx->pix_fmt == AV_PIX_FMT_GRAY16BE ||
1239  avctx->pix_fmt == AV_PIX_FMT_MONOBLACK
1240  )) {
1241  // APNG_BLEND_OP_OVER is the same as APNG_BLEND_OP_SOURCE when there is no alpha channel
1242  blend_op = APNG_BLEND_OP_SOURCE;
1243  }
1244 
1245  s->cur_w = cur_w;
1246  s->cur_h = cur_h;
1247  s->x_offset = x_offset;
1248  s->y_offset = y_offset;
1249  s->dispose_op = dispose_op;
1250  s->blend_op = blend_op;
1251 
1252  return 0;
1253 }
1254 
1256 {
1257  int i, j;
1258  uint8_t *pd = p->data[0];
1259  uint8_t *pd_last = s->last_picture.f->data[0];
1260  int ls = av_image_get_linesize(p->format, s->width, 0);
1261 
1262  ls = FFMIN(ls, s->width * s->bpp);
1263 
1264  ff_progress_frame_await(&s->last_picture, INT_MAX);
1265  for (j = 0; j < s->height; j++) {
1266  for (i = 0; i < ls; i++)
1267  pd[i] += pd_last[i];
1268  pd += p->linesize[0];
1269  pd_last += s->last_picture.f->linesize[0];
1270  }
1271 }
1272 
1273 // divide by 255 and round to nearest
1274 // apply a fast variant: (X+127)/255 = ((X+127)*257+257)>>16 = ((X+128)*257)>>16
1275 #define FAST_DIV255(x) ((((x) + 128) * 257) >> 16)
1276 
1278  AVFrame *p)
1279 {
1280  uint8_t *dst = p->data[0];
1281  ptrdiff_t dst_stride = p->linesize[0];
1282  const uint8_t *src = s->last_picture.f->data[0];
1283  ptrdiff_t src_stride = s->last_picture.f->linesize[0];
1284  const int bpp = s->color_type == PNG_COLOR_TYPE_PALETTE ? 4 : s->bpp;
1285 
1286  size_t x, y;
1287 
1288  if (s->blend_op == APNG_BLEND_OP_OVER &&
1289  avctx->pix_fmt != AV_PIX_FMT_RGBA &&
1290  avctx->pix_fmt != AV_PIX_FMT_GRAY8A) {
1291  avpriv_request_sample(avctx, "Blending with pixel format %s",
1292  av_get_pix_fmt_name(avctx->pix_fmt));
1293  return AVERROR_PATCHWELCOME;
1294  }
1295 
1296  ff_progress_frame_await(&s->last_picture, INT_MAX);
1297 
1298  // copy unchanged rectangles from the last frame
1299  for (y = 0; y < s->y_offset; y++)
1300  memcpy(dst + y * dst_stride, src + y * src_stride, p->width * bpp);
1301  for (y = s->y_offset; y < s->y_offset + s->cur_h; y++) {
1302  memcpy(dst + y * dst_stride, src + y * src_stride, s->x_offset * bpp);
1303  memcpy(dst + y * dst_stride + (s->x_offset + s->cur_w) * bpp,
1304  src + y * src_stride + (s->x_offset + s->cur_w) * bpp,
1305  (p->width - s->cur_w - s->x_offset) * bpp);
1306  }
1307  for (y = s->y_offset + s->cur_h; y < p->height; y++)
1308  memcpy(dst + y * dst_stride, src + y * src_stride, p->width * bpp);
1309 
1310  if (s->blend_op == APNG_BLEND_OP_OVER) {
1311  // Perform blending
1312  for (y = s->y_offset; y < s->y_offset + s->cur_h; ++y) {
1313  uint8_t *foreground = dst + dst_stride * y + bpp * s->x_offset;
1314  const uint8_t *background = src + src_stride * y + bpp * s->x_offset;
1315  for (x = s->x_offset; x < s->x_offset + s->cur_w; ++x, foreground += bpp, background += bpp) {
1316  size_t b;
1317  uint8_t foreground_alpha, background_alpha, output_alpha;
1318  uint8_t output[10];
1319 
1320  // Since we might be blending alpha onto alpha, we use the following equations:
1321  // output_alpha = foreground_alpha + (1 - foreground_alpha) * background_alpha
1322  // output = (foreground_alpha * foreground + (1 - foreground_alpha) * background_alpha * background) / output_alpha
1323 
1324  switch (avctx->pix_fmt) {
1325  case AV_PIX_FMT_RGBA:
1326  foreground_alpha = foreground[3];
1327  background_alpha = background[3];
1328  break;
1329 
1330  case AV_PIX_FMT_GRAY8A:
1331  foreground_alpha = foreground[1];
1332  background_alpha = background[1];
1333  break;
1334  }
1335 
1336  if (foreground_alpha == 255)
1337  continue;
1338 
1339  if (foreground_alpha == 0) {
1340  memcpy(foreground, background, bpp);
1341  continue;
1342  }
1343 
1344  output_alpha = foreground_alpha + FAST_DIV255((255 - foreground_alpha) * background_alpha);
1345 
1346  av_assert0(bpp <= 10);
1347 
1348  for (b = 0; b < bpp - 1; ++b) {
1349  if (output_alpha == 0) {
1350  output[b] = 0;
1351  } else if (background_alpha == 255) {
1352  output[b] = FAST_DIV255(foreground_alpha * foreground[b] + (255 - foreground_alpha) * background[b]);
1353  } else {
1354  output[b] = (255 * foreground_alpha * foreground[b] + (255 - foreground_alpha) * background_alpha * background[b]) / (255 * output_alpha);
1355  }
1356  }
1357  output[b] = output_alpha;
1358  memcpy(foreground, output, bpp);
1359  }
1360  }
1361  }
1362 
1363  return 0;
1364 }
1365 
1367 {
1368  // need to reset a rectangle to black
1369  av_unused int ret = av_frame_copy(s->picture.f, p);
1370  const int bpp = s->color_type == PNG_COLOR_TYPE_PALETTE ? 4 : s->bpp;
1371  const ptrdiff_t dst_stride = s->picture.f->linesize[0];
1372  uint8_t *dst = s->picture.f->data[0] + s->y_offset * dst_stride + bpp * s->x_offset;
1373 
1374  av_assert1(ret >= 0);
1375 
1376  for (size_t y = 0; y < s->cur_h; y++) {
1377  memset(dst, 0, bpp * s->cur_w);
1378  dst += dst_stride;
1379  }
1380 }
1381 
1383  AVFrame *p, const AVPacket *avpkt)
1384 {
1385  const AVCRC *crc_tab = av_crc_get_table(AV_CRC_32_IEEE_LE);
1386  uint32_t tag, length;
1387  int decode_next_dat = 0;
1388  int i, ret;
1389 
1390  for (;;) {
1391  GetByteContext gb_chunk;
1392 
1393  length = bytestream2_get_bytes_left(&s->gb);
1394  if (length <= 0) {
1395 
1396  if (avctx->codec_id == AV_CODEC_ID_PNG &&
1397  avctx->skip_frame == AVDISCARD_ALL) {
1398  return 0;
1399  }
1400 
1401  if (CONFIG_APNG_DECODER && avctx->codec_id == AV_CODEC_ID_APNG && length == 0) {
1402  if (!(s->pic_state & PNG_IDAT))
1403  return 0;
1404  else
1405  goto exit_loop;
1406  }
1407  av_log(avctx, AV_LOG_ERROR, "%d bytes left\n", length);
1408  if ( s->pic_state & PNG_ALLIMAGE
1410  goto exit_loop;
1412  goto fail;
1413  }
1414 
1415  length = bytestream2_get_be32(&s->gb);
1416  if (length > 0x7fffffff || length + 8 > bytestream2_get_bytes_left(&s->gb)) {
1417  av_log(avctx, AV_LOG_ERROR, "chunk too big\n");
1419  goto fail;
1420  }
1421  if (avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_IGNORE_ERR)) {
1422  uint32_t crc_sig = AV_RB32(s->gb.buffer + length + 4);
1423  uint32_t crc_cal = ~av_crc(crc_tab, UINT32_MAX, s->gb.buffer, length + 4);
1424  if (crc_sig ^ crc_cal) {
1425  av_log(avctx, AV_LOG_ERROR, "CRC mismatch in chunk");
1426  if (avctx->err_recognition & AV_EF_EXPLODE) {
1427  av_log(avctx, AV_LOG_ERROR, ", quitting\n");
1429  goto fail;
1430  }
1431  av_log(avctx, AV_LOG_ERROR, ", skipping\n");
1432  bytestream2_skip(&s->gb, length + 8); /* tag */
1433  continue;
1434  }
1435  }
1436  tag = bytestream2_get_le32(&s->gb);
1437  if (avctx->debug & FF_DEBUG_STARTCODE)
1438  av_log(avctx, AV_LOG_DEBUG, "png: tag=%s length=%u\n",
1439  av_fourcc2str(tag), length);
1440 
1441  bytestream2_init(&gb_chunk, s->gb.buffer, length);
1442  bytestream2_skip(&s->gb, length + 4);
1443 
1444  if (avctx->codec_id == AV_CODEC_ID_PNG &&
1445  avctx->skip_frame == AVDISCARD_ALL) {
1446  switch(tag) {
1447  case MKTAG('I', 'H', 'D', 'R'):
1448  case MKTAG('p', 'H', 'Y', 's'):
1449  case MKTAG('t', 'E', 'X', 't'):
1450  case MKTAG('I', 'D', 'A', 'T'):
1451  case MKTAG('t', 'R', 'N', 'S'):
1452  case MKTAG('s', 'R', 'G', 'B'):
1453  case MKTAG('c', 'I', 'C', 'P'):
1454  case MKTAG('c', 'H', 'R', 'M'):
1455  case MKTAG('g', 'A', 'M', 'A'):
1456  break;
1457  default:
1458  continue;
1459  }
1460  }
1461 
1462  switch (tag) {
1463  case MKTAG('I', 'H', 'D', 'R'):
1464  if ((ret = decode_ihdr_chunk(avctx, s, &gb_chunk)) < 0)
1465  goto fail;
1466  break;
1467  case MKTAG('p', 'H', 'Y', 's'):
1468  if ((ret = decode_phys_chunk(avctx, s, &gb_chunk)) < 0)
1469  goto fail;
1470  break;
1471  case MKTAG('f', 'c', 'T', 'L'):
1472  if (!CONFIG_APNG_DECODER || avctx->codec_id != AV_CODEC_ID_APNG)
1473  continue;
1474  if ((ret = decode_fctl_chunk(avctx, s, &gb_chunk)) < 0)
1475  goto fail;
1476  decode_next_dat = 1;
1477  break;
1478  case MKTAG('f', 'd', 'A', 'T'):
1479  if (!CONFIG_APNG_DECODER || avctx->codec_id != AV_CODEC_ID_APNG)
1480  continue;
1481  if (!decode_next_dat || bytestream2_get_bytes_left(&gb_chunk) < 4) {
1483  goto fail;
1484  }
1485  bytestream2_get_be32(&gb_chunk);
1486  /* fallthrough */
1487  case MKTAG('I', 'D', 'A', 'T'):
1488  if (CONFIG_APNG_DECODER && avctx->codec_id == AV_CODEC_ID_APNG && !decode_next_dat)
1489  continue;
1490  if ((ret = decode_idat_chunk(avctx, s, &gb_chunk, p)) < 0)
1491  goto fail;
1492  break;
1493  case MKTAG('P', 'L', 'T', 'E'):
1494  decode_plte_chunk(avctx, s, &gb_chunk);
1495  break;
1496  case MKTAG('t', 'R', 'N', 'S'):
1497  decode_trns_chunk(avctx, s, &gb_chunk);
1498  break;
1499  case MKTAG('t', 'E', 'X', 't'):
1500  if (decode_text_chunk(s, &gb_chunk, 0) < 0)
1501  av_log(avctx, AV_LOG_WARNING, "Broken tEXt chunk\n");
1502  break;
1503  case MKTAG('z', 'T', 'X', 't'):
1504  if (decode_text_chunk(s, &gb_chunk, 1) < 0)
1505  av_log(avctx, AV_LOG_WARNING, "Broken zTXt chunk\n");
1506  break;
1507  case MKTAG('s', 'T', 'E', 'R'): {
1508  int mode = bytestream2_get_byte(&gb_chunk);
1509 
1510  if (mode == 0 || mode == 1) {
1511  s->stereo_mode = mode;
1512  } else {
1513  av_log(avctx, AV_LOG_WARNING,
1514  "Unknown value in sTER chunk (%d)\n", mode);
1515  }
1516  break;
1517  }
1518  case MKTAG('c', 'I', 'C', 'P'):
1519  s->cicp_primaries = bytestream2_get_byte(&gb_chunk);
1520  s->cicp_trc = bytestream2_get_byte(&gb_chunk);
1521  if (bytestream2_get_byte(&gb_chunk) != 0)
1522  av_log(avctx, AV_LOG_WARNING, "nonzero cICP matrix\n");
1523  s->cicp_range = bytestream2_get_byte(&gb_chunk);
1524  if (s->cicp_range != 0 && s->cicp_range != 1)
1525  av_log(avctx, AV_LOG_WARNING, "invalid cICP range: %d\n", s->cicp_range);
1526  s->have_cicp = 1;
1527  break;
1528  case MKTAG('s', 'R', 'G', 'B'):
1529  /* skip rendering intent byte */
1530  bytestream2_skip(&gb_chunk, 1);
1531  s->have_srgb = 1;
1532  break;
1533  case MKTAG('i', 'C', 'C', 'P'): {
1534  if ((ret = decode_iccp_chunk(s, &gb_chunk)) < 0)
1535  goto fail;
1536  break;
1537  }
1538  case MKTAG('c', 'H', 'R', 'M'): {
1539  s->have_chrm = 1;
1540 
1541  s->white_point[0] = bytestream2_get_be32(&gb_chunk);
1542  s->white_point[1] = bytestream2_get_be32(&gb_chunk);
1543 
1544  /* RGB Primaries */
1545  for (i = 0; i < 3; i++) {
1546  s->display_primaries[i][0] = bytestream2_get_be32(&gb_chunk);
1547  s->display_primaries[i][1] = bytestream2_get_be32(&gb_chunk);
1548  }
1549 
1550  break;
1551  }
1552  case MKTAG('s', 'B', 'I', 'T'):
1553  if ((ret = decode_sbit_chunk(avctx, s, &gb_chunk)) < 0)
1554  goto fail;
1555  break;
1556  case MKTAG('g', 'A', 'M', 'A'): {
1557  AVBPrint bp;
1558  char *gamma_str;
1559  s->gamma = bytestream2_get_be32(&gb_chunk);
1560 
1562  av_bprintf(&bp, "%i/%i", s->gamma, 100000);
1563  ret = av_bprint_finalize(&bp, &gamma_str);
1564  if (ret < 0)
1565  return ret;
1566 
1567  av_dict_set(&s->frame_metadata, "gamma", gamma_str, AV_DICT_DONT_STRDUP_VAL);
1568 
1569  break;
1570  }
1571  case MKTAG('c', 'L', 'L', 'i'): /* legacy spelling, for backwards compat */
1572  case MKTAG('c', 'L', 'L', 'I'):
1573  if (bytestream2_get_bytes_left(&gb_chunk) != 8) {
1574  av_log(avctx, AV_LOG_WARNING, "Invalid cLLI chunk size: %d\n", bytestream2_get_bytes_left(&gb_chunk));
1575  break;
1576  }
1577  s->have_clli = 1;
1578  s->clli_max = bytestream2_get_be32u(&gb_chunk);
1579  s->clli_avg = bytestream2_get_be32u(&gb_chunk);
1580  break;
1581  case MKTAG('m', 'D', 'C', 'v'): /* legacy spelling, for backward compat */
1582  case MKTAG('m', 'D', 'C', 'V'):
1583  if (bytestream2_get_bytes_left(&gb_chunk) != 24) {
1584  av_log(avctx, AV_LOG_WARNING, "Invalid mDCV chunk size: %d\n", bytestream2_get_bytes_left(&gb_chunk));
1585  break;
1586  }
1587  s->have_mdcv = 1;
1588  for (int i = 0; i < 3; i++) {
1589  s->mdcv_primaries[i][0] = bytestream2_get_be16u(&gb_chunk);
1590  s->mdcv_primaries[i][1] = bytestream2_get_be16u(&gb_chunk);
1591  }
1592  s->mdcv_white_point[0] = bytestream2_get_be16u(&gb_chunk);
1593  s->mdcv_white_point[1] = bytestream2_get_be16u(&gb_chunk);
1594  s->mdcv_max_lum = bytestream2_get_be32u(&gb_chunk);
1595  s->mdcv_min_lum = bytestream2_get_be32u(&gb_chunk);
1596  break;
1597  case MKTAG('I', 'E', 'N', 'D'):
1598  if (!(s->pic_state & PNG_ALLIMAGE))
1599  av_log(avctx, AV_LOG_ERROR, "IEND without all image\n");
1600  if (!(s->pic_state & (PNG_ALLIMAGE|PNG_IDAT))) {
1602  goto fail;
1603  }
1604  goto exit_loop;
1605  }
1606  }
1607 exit_loop:
1608 
1609  if (!p)
1610  return AVERROR_INVALIDDATA;
1611 
1612  if (avctx->codec_id == AV_CODEC_ID_PNG &&
1613  avctx->skip_frame == AVDISCARD_ALL) {
1614  return 0;
1615  }
1616 
1619  goto fail;
1620  }
1621 
1622  if (s->bits_per_pixel <= 4)
1623  handle_small_bpp(s, p);
1624 
1625  if (s->color_type == PNG_COLOR_TYPE_PALETTE && avctx->codec_id == AV_CODEC_ID_APNG) {
1626  for (int y = 0; y < s->height; y++) {
1627  uint8_t *row = &p->data[0][p->linesize[0] * y];
1628 
1629  for (int x = s->width - 1; x >= 0; x--) {
1630  const uint8_t idx = row[x];
1631 
1632  row[4*x+2] = s->palette[idx] & 0xFF;
1633  row[4*x+1] = (s->palette[idx] >> 8 ) & 0xFF;
1634  row[4*x+0] = (s->palette[idx] >> 16) & 0xFF;
1635  row[4*x+3] = s->palette[idx] >> 24;
1636  }
1637  }
1638  }
1639 
1640  /* apply transparency if needed */
1641  if (s->has_trns && s->color_type != PNG_COLOR_TYPE_PALETTE) {
1642  size_t byte_depth = s->bit_depth > 8 ? 2 : 1;
1643  size_t raw_bpp = s->bpp - byte_depth;
1644  ptrdiff_t x, y;
1645 
1646  av_assert0(s->bit_depth > 1);
1647 
1648  for (y = 0; y < s->height; ++y) {
1649  uint8_t *row = &p->data[0][p->linesize[0] * y];
1650 
1651  if (s->bpp == 2 && byte_depth == 1) {
1652  uint8_t *pixel = &row[2 * s->width - 1];
1653  uint8_t *rowp = &row[1 * s->width - 1];
1654  int tcolor = s->transparent_color_be[0];
1655  for (x = s->width; x > 0; --x) {
1656  *pixel-- = *rowp == tcolor ? 0 : 0xff;
1657  *pixel-- = *rowp--;
1658  }
1659  } else if (s->bpp == 4 && byte_depth == 1) {
1660  uint8_t *pixel = &row[4 * s->width - 1];
1661  uint8_t *rowp = &row[3 * s->width - 1];
1662  int tcolor = AV_RL24(s->transparent_color_be);
1663  for (x = s->width; x > 0; --x) {
1664  *pixel-- = AV_RL24(rowp-2) == tcolor ? 0 : 0xff;
1665  *pixel-- = *rowp--;
1666  *pixel-- = *rowp--;
1667  *pixel-- = *rowp--;
1668  }
1669  } else {
1670  /* since we're updating in-place, we have to go from right to left */
1671  for (x = s->width; x > 0; --x) {
1672  uint8_t *pixel = &row[s->bpp * (x - 1)];
1673  memmove(pixel, &row[raw_bpp * (x - 1)], raw_bpp);
1674 
1675  if (!memcmp(pixel, s->transparent_color_be, raw_bpp)) {
1676  memset(&pixel[raw_bpp], 0, byte_depth);
1677  } else {
1678  memset(&pixel[raw_bpp], 0xff, byte_depth);
1679  }
1680  }
1681  }
1682  }
1683  }
1684 
1685  /* handle P-frames only if a predecessor frame is available */
1686  if (s->last_picture.f) {
1687  if ( !(avpkt->flags & AV_PKT_FLAG_KEY) && avctx->codec_tag != AV_RL32("MPNG")
1688  && s->last_picture.f->width == p->width
1689  && s->last_picture.f->height== p->height
1690  && s->last_picture.f->format== p->format
1691  ) {
1692  if (CONFIG_PNG_DECODER && avctx->codec_id != AV_CODEC_ID_APNG)
1693  handle_p_frame_png(s, p);
1694  else if (CONFIG_APNG_DECODER &&
1695  avctx->codec_id == AV_CODEC_ID_APNG &&
1696  (ret = handle_p_frame_apng(avctx, s, p)) < 0)
1697  goto fail;
1698  }
1699  }
1700  if (CONFIG_APNG_DECODER && s->dispose_op == APNG_DISPOSE_OP_BACKGROUND)
1702 
1703  ret = 0;
1704 fail:
1705  if (s->picture.f)
1706  ff_progress_frame_report(&s->picture, INT_MAX);
1707 
1708  return ret;
1709 }
1710 
1712 {
1713  av_freep(&s->iccp_data);
1714  s->iccp_data_len = 0;
1715  s->iccp_name[0] = 0;
1716 
1717  s->stereo_mode = -1;
1718 
1719  s->have_chrm = 0;
1720  s->have_srgb = 0;
1721  s->have_cicp = 0;
1722 
1723  av_dict_free(&s->frame_metadata);
1724 }
1725 
1727 {
1728  int ret;
1729 
1730  if (s->stereo_mode >= 0) {
1732  if (!stereo3d) {
1733  ret = AVERROR(ENOMEM);
1734  goto fail;
1735  }
1736 
1737  stereo3d->type = AV_STEREO3D_SIDEBYSIDE;
1738  stereo3d->flags = s->stereo_mode ? 0 : AV_STEREO3D_FLAG_INVERT;
1739  }
1740 
1741  FFSWAP(AVDictionary*, f->metadata, s->frame_metadata);
1742 
1743  return 0;
1744 fail:
1745  av_frame_unref(f);
1746  return ret;
1747 }
1748 
1749 #if CONFIG_PNG_DECODER
1750 static int decode_frame_png(AVCodecContext *avctx, AVFrame *p,
1751  int *got_frame, AVPacket *avpkt)
1752 {
1753  PNGDecContext *const s = avctx->priv_data;
1754  const uint8_t *buf = avpkt->data;
1755  int buf_size = avpkt->size;
1756  int64_t sig;
1757  int ret;
1758 
1760 
1761  bytestream2_init(&s->gb, buf, buf_size);
1762 
1763  /* check signature */
1764  sig = bytestream2_get_be64(&s->gb);
1765  if (sig != PNGSIG &&
1766  sig != MNGSIG) {
1767  av_log(avctx, AV_LOG_ERROR, "Invalid PNG signature 0x%08"PRIX64".\n", sig);
1768  return AVERROR_INVALIDDATA;
1769  }
1770 
1771  s->y = s->has_trns = 0;
1772  s->hdr_state = 0;
1773  s->pic_state = 0;
1774 
1775  /* Reset z_stream */
1776  ret = inflateReset(&s->zstream.zstream);
1777  if (ret != Z_OK)
1778  return AVERROR_EXTERNAL;
1779 
1780  if ((ret = decode_frame_common(avctx, s, p, avpkt)) < 0)
1781  goto the_end;
1782 
1783  if (avctx->skip_frame == AVDISCARD_ALL) {
1784  *got_frame = 0;
1785  ret = bytestream2_tell(&s->gb);
1786  goto the_end;
1787  }
1788 
1789  ret = output_frame(s, p);
1790  if (ret < 0)
1791  goto the_end;
1792 
1793  if (!(avctx->active_thread_type & FF_THREAD_FRAME)) {
1794  ff_progress_frame_unref(&s->last_picture);
1795  FFSWAP(ProgressFrame, s->picture, s->last_picture);
1796  }
1797 
1798  *got_frame = 1;
1799 
1800  ret = bytestream2_tell(&s->gb);
1801 the_end:
1802  s->crow_buf = NULL;
1803  return ret;
1804 }
1805 #endif
1806 
1807 #if CONFIG_APNG_DECODER
1808 static int decode_frame_apng(AVCodecContext *avctx, AVFrame *p,
1809  int *got_frame, AVPacket *avpkt)
1810 {
1811  PNGDecContext *const s = avctx->priv_data;
1812  int ret;
1813 
1815 
1816  if (!(s->hdr_state & PNG_IHDR)) {
1817  if (!avctx->extradata_size)
1818  return AVERROR_INVALIDDATA;
1819 
1820  if ((ret = inflateReset(&s->zstream.zstream)) != Z_OK)
1821  return AVERROR_EXTERNAL;
1822  bytestream2_init(&s->gb, avctx->extradata, avctx->extradata_size);
1823  if ((ret = decode_frame_common(avctx, s, NULL, avpkt)) < 0)
1824  return ret;
1825  }
1826 
1827  /* reset state for a new frame */
1828  if ((ret = inflateReset(&s->zstream.zstream)) != Z_OK)
1829  return AVERROR_EXTERNAL;
1830  s->y = 0;
1831  s->pic_state = 0;
1832  bytestream2_init(&s->gb, avpkt->data, avpkt->size);
1833  if ((ret = decode_frame_common(avctx, s, p, avpkt)) < 0)
1834  return ret;
1835 
1836  if (!(s->pic_state & PNG_ALLIMAGE))
1837  av_log(avctx, AV_LOG_WARNING, "Frame did not contain a complete image\n");
1838  if (!(s->pic_state & (PNG_ALLIMAGE|PNG_IDAT)))
1839  return AVERROR_INVALIDDATA;
1840 
1841  ret = output_frame(s, p);
1842  if (ret < 0)
1843  return ret;
1844 
1845  if (!(avctx->active_thread_type & FF_THREAD_FRAME)) {
1846  if (s->dispose_op != APNG_DISPOSE_OP_PREVIOUS)
1847  FFSWAP(ProgressFrame, s->picture, s->last_picture);
1848  ff_progress_frame_unref(&s->picture);
1849  }
1850 
1851  *got_frame = 1;
1852  return bytestream2_tell(&s->gb);
1853 }
1854 #endif
1855 
1856 #if HAVE_THREADS
1858 {
1859  PNGDecContext *psrc = src->priv_data;
1860  PNGDecContext *pdst = dst->priv_data;
1861  const ProgressFrame *src_frame;
1862 
1863  if (dst == src)
1864  return 0;
1865 
1866  if (CONFIG_APNG_DECODER && dst->codec_id == AV_CODEC_ID_APNG) {
1867 
1868  pdst->width = psrc->width;
1869  pdst->height = psrc->height;
1870  pdst->bit_depth = psrc->bit_depth;
1871  pdst->color_type = psrc->color_type;
1872  pdst->compression_type = psrc->compression_type;
1873  pdst->interlace_type = psrc->interlace_type;
1874  pdst->filter_type = psrc->filter_type;
1875  pdst->has_trns = psrc->has_trns;
1876  memcpy(pdst->transparent_color_be, psrc->transparent_color_be, sizeof(pdst->transparent_color_be));
1877 
1878  memcpy(pdst->palette, psrc->palette, sizeof(pdst->palette));
1879 
1880  pdst->hdr_state |= psrc->hdr_state;
1881  }
1882 
1883  src_frame = psrc->dispose_op == APNG_DISPOSE_OP_PREVIOUS ?
1884  &psrc->last_picture : &psrc->picture;
1885 
1886  ff_progress_frame_replace(&pdst->last_picture, src_frame);
1887 
1888  return 0;
1889 }
1890 #endif
1891 
1893 {
1894  PNGDecContext *s = avctx->priv_data;
1895 
1896  s->avctx = avctx;
1897 
1898  ff_pngdsp_init(&s->dsp);
1899 
1900  return ff_inflate_init(&s->zstream, avctx);
1901 }
1902 
1904 {
1905  PNGDecContext *s = avctx->priv_data;
1906 
1907  ff_progress_frame_unref(&s->last_picture);
1908  ff_progress_frame_unref(&s->picture);
1909  av_freep(&s->buffer);
1910  s->buffer_size = 0;
1911  av_freep(&s->last_row);
1912  s->last_row_size = 0;
1913  av_freep(&s->tmp_row);
1914  s->tmp_row_size = 0;
1915 
1916  av_freep(&s->iccp_data);
1917  av_dict_free(&s->frame_metadata);
1918  ff_inflate_end(&s->zstream);
1919 
1920  return 0;
1921 }
1922 
1923 #if CONFIG_APNG_DECODER
1924 const FFCodec ff_apng_decoder = {
1925  .p.name = "apng",
1926  CODEC_LONG_NAME("APNG (Animated Portable Network Graphics) image"),
1927  .p.type = AVMEDIA_TYPE_VIDEO,
1928  .p.id = AV_CODEC_ID_APNG,
1929  .priv_data_size = sizeof(PNGDecContext),
1930  .init = png_dec_init,
1931  .close = png_dec_end,
1932  FF_CODEC_DECODE_CB(decode_frame_apng),
1934  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
1935  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
1938 };
1939 #endif
1940 
1941 #if CONFIG_PNG_DECODER
1942 const FFCodec ff_png_decoder = {
1943  .p.name = "png",
1944  CODEC_LONG_NAME("PNG (Portable Network Graphics) image"),
1945  .p.type = AVMEDIA_TYPE_VIDEO,
1946  .p.id = AV_CODEC_ID_PNG,
1947  .priv_data_size = sizeof(PNGDecContext),
1948  .init = png_dec_init,
1949  .close = png_dec_end,
1950  FF_CODEC_DECODE_CB(decode_frame_png),
1952  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
1953  .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |
1957 };
1958 #endif
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:32
PNG_PLTE
@ PNG_PLTE
Definition: pngdec.c:53
PNGDSPContext
Definition: pngdsp.h:27
AVMasteringDisplayMetadata::has_primaries
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
Definition: mastering_display_metadata.h:62
ff_progress_frame_report
void ff_progress_frame_report(ProgressFrame *f, int n)
Notify later decoding threads when part of their reference frame is ready.
Definition: decode.c:1893
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
AV_BPRINT_SIZE_UNLIMITED
#define AV_BPRINT_SIZE_UNLIMITED
AVMasteringDisplayMetadata::max_luminance
AVRational max_luminance
Max luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:57
PNGDecContext::clli_max
uint32_t clli_max
Definition: pngdec.c:87
AV_EF_EXPLODE
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: defs.h:51
clear_frame_metadata
static void clear_frame_metadata(PNGDecContext *s)
Definition: pngdec.c:1711
ff_add_png_paeth_prediction
void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
Definition: pngdec.c:218
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
PNGDecContext::have_srgb
int have_srgb
Definition: pngdec.c:81
PNGDecContext::cicp_range
enum AVColorRange cicp_range
Definition: pngdec.c:85
r
const char * r
Definition: vf_curves.c:127
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
AV_PIX_FMT_YA8
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
Definition: pixfmt.h:140
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:699
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:627
out
FILE * out
Definition: movenc.c:55
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
GetByteContext
Definition: bytestream.h:33
PNG_ALLIMAGE
@ PNG_ALLIMAGE
Definition: pngdec.c:58
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
PNGDecContext::last_row_size
unsigned int last_row_size
Definition: pngdec.c:117
APNG_FCTL_CHUNK_SIZE
#define APNG_FCTL_CHUNK_SIZE
Definition: apng.h:42
decode_phys_chunk
static int decode_phys_chunk(AVCodecContext *avctx, PNGDecContext *s, GetByteContext *gb)
Definition: pngdec.c:641
AVCOL_TRC_LINEAR
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
Definition: pixfmt.h:636
PNGDecContext::bit_depth
int bit_depth
Definition: pngdec.c:102
ff_png_get_nb_channels
int ff_png_get_nb_channels(int color_type)
Definition: png.c:41
AVMasteringDisplayMetadata::display_primaries
AVRational display_primaries[3][2]
CIE 1931 xy chromaticity coords of color primaries (r, g, b order).
Definition: mastering_display_metadata.h:42
PNGDSPContext::add_paeth_prediction
void(* add_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
Definition: pngdsp.h:33
AVMasteringDisplayMetadata::has_luminance
int has_luminance
Flag indicating whether the luminance (min_ and max_) have been set.
Definition: mastering_display_metadata.h:67
AVCodecContext::err_recognition
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:1438
rational.h
int64_t
long long int64_t
Definition: coverity.c:34
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
PNGDecContext::crow_size
int crow_size
Definition: pngdec.c:123
av_unused
#define av_unused
Definition: attributes.h:131
mask
int mask
Definition: mediacodecdec_common.c:154
decode_text_chunk
static int decode_text_chunk(PNGDecContext *s, GetByteContext *gb, int compressed)
Definition: pngdec.c:543
PNGDecContext::mdcv_white_point
uint16_t mdcv_white_point[2]
Definition: pngdec.c:92
AVContentLightMetadata::MaxCLL
unsigned MaxCLL
Max content light level (cd/m^2).
Definition: mastering_display_metadata.h:111
mode
Definition: swscale.c:52
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:410
AVCOL_TRC_NB
@ AVCOL_TRC_NB
Not part of ABI.
Definition: pixfmt.h:649
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:202
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:692
AVFrame::width
int width
Definition: frame.h:482
w
uint8_t w
Definition: llviddspenc.c:38
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:733
AVPacket::data
uint8_t * data
Definition: packet.h:539
PNGDecContext::have_clli
int have_clli
Definition: pngdec.c:86
b
#define b
Definition: input.c:41
ff_progress_frame_get_buffer
int ff_progress_frame_get_buffer(AVCodecContext *avctx, ProgressFrame *f, int flags)
This function sets up the ProgressFrame, i.e.
Definition: decode.c:1848
data
const char data[16]
Definition: mxf.c:149
FFCodec
Definition: codec_internal.h:127
PNGDecContext::row_size
int row_size
Definition: pngdec.c:124
FFZStream::zstream
z_stream zstream
Definition: zlib_wrapper.h:28
AVCOL_SPC_RGB
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
Definition: pixfmt.h:657
PNGDecContext::width
int width
Definition: pngdec.c:98
AVDictionary
Definition: dict.c:34
AVFrame::flags
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:690
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:602
PNGDecContext::picture
ProgressFrame picture
Definition: pngdec.c:67
AV_CODEC_ID_APNG
@ AV_CODEC_ID_APNG
Definition: codec_id.h:269
PNGDecContext::tmp_row_size
unsigned int tmp_row_size
Definition: pngdec.c:119
PNGDecContext::color_type
int color_type
Definition: pngdec.c:103
PNGDecContext::cur_h
int cur_h
Definition: pngdec.c:99
ff_set_dimensions
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:94
APNG_DISPOSE_OP_BACKGROUND
@ APNG_DISPOSE_OP_BACKGROUND
Definition: apng.h:32
PNGDecContext::bits_per_pixel
int bits_per_pixel
Definition: pngdec.c:108
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:594
thread.h
PNGDecContext::gamma
int gamma
Definition: pngdec.c:80
FF_DEBUG_PICT_INFO
#define FF_DEBUG_PICT_INFO
Definition: avcodec.h:1415
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:431
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
NB_PASSES
#define NB_PASSES
Definition: png.h:47
PNGDecContext::blend_op
uint8_t blend_op
Definition: pngdec.c:101
AVContentLightMetadata
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
Definition: mastering_display_metadata.h:107
crc.h
AV_PIX_FMT_GRAY16BE
@ AV_PIX_FMT_GRAY16BE
Y , 16bpp, big-endian.
Definition: pixfmt.h:104
AV_STEREO3D_SIDEBYSIDE
@ AV_STEREO3D_SIDEBYSIDE
Views are next to each other.
Definition: stereo3d.h:64
bytestream2_skip
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:168
FAST_DIV255
#define FAST_DIV255(x)
Definition: pngdec.c:1275
PNGImageState
PNGImageState
Definition: pngdec.c:56
PNG_FILTER_TYPE_LOCO
#define PNG_FILTER_TYPE_LOCO
Definition: png.h:39
PNGDecContext::mdcv_max_lum
uint32_t mdcv_max_lum
Definition: pngdec.c:93
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
AVCOL_TRC_IEC61966_2_1
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
Definition: pixfmt.h:641
PNGDecContext::pass_row_size
int pass_row_size
Definition: pngdec.c:125
ff_png_pass_row_size
int ff_png_pass_row_size(int pass, int bits_per_pixel, int width)
Definition: png.c:54
AVCodecContext::skip_frame
enum AVDiscard skip_frame
Skip decoding for selected frames.
Definition: avcodec.h:1841
fail
#define fail()
Definition: checkasm.h:193
inflate
static void inflate(uint8_t *dst, const uint8_t *p1, int width, int threshold, const uint8_t *coordinates[], int coord, int maxc)
Definition: vf_neighbor.c:194
png_dec_end
static av_cold int png_dec_end(AVCodecContext *avctx)
Definition: pngdec.c:1903
OP_AVG
#define OP_AVG(x, s, l)
AVCOL_TRC_GAMMA28
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
Definition: pixfmt.h:633
PNGDecContext::pic_state
enum PNGImageState pic_state
Definition: pngdec.c:97
decode_idat_chunk
static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, GetByteContext *gb, AVFrame *p)
Definition: pngdec.c:791
png_pass_dsp_ymask
static const uint8_t png_pass_dsp_ymask[NB_PASSES]
Definition: pngdec.c:136
AVRational::num
int num
Numerator.
Definition: rational.h:59
progressframe.h
PNG_COLOR_TYPE_RGB_ALPHA
#define PNG_COLOR_TYPE_RGB_ALPHA
Definition: png.h:36
PNGDecContext::crow_buf
uint8_t * crow_buf
Definition: pngdec.c:115
AVCOL_TRC_GAMMA22
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:632
AV_DICT_DONT_STRDUP_VAL
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
Definition: dict.h:79
PNGDecContext::last_row
uint8_t * last_row
Definition: pngdec.c:116
PNGDecContext::height
int height
Definition: pngdec.c:98
avassert.h
FF_CODEC_CAP_USES_PROGRESSFRAMES
#define FF_CODEC_CAP_USES_PROGRESSFRAMES
The decoder might make use of the ProgressFrame API.
Definition: codec_internal.h:68
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:685
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
pngdsp.h
zlib_wrapper.h
av_cold
#define av_cold
Definition: attributes.h:90
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:661
PNGDecContext::have_cicp
int have_cicp
Definition: pngdec.c:82
YUV2RGB
#define YUV2RGB(NAME, TYPE)
Definition: pngdec.c:341
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:538
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:311
stereo3d.h
AVMasteringDisplayMetadata::white_point
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
Definition: mastering_display_metadata.h:47
intreadwrite.h
PNGDecContext::tmp_row
uint8_t * tmp_row
Definition: pngdec.c:118
s
#define s(width, name)
Definition: cbs_vp9.c:198
PNGDecContext::clli_avg
uint32_t clli_avg
Definition: pngdec.c:88
AVCOL_PRI_NB
@ AVCOL_PRI_NB
Not part of ABI.
Definition: pixfmt.h:620
ff_apng_decoder
const FFCodec ff_apng_decoder
PNGDecContext::y_offset
int y_offset
Definition: pngdec.c:100
PNGDecContext::palette
uint32_t palette[256]
Definition: pngdec.c:114
g
const char * g
Definition: vf_curves.c:128
AV_GET_BUFFER_FLAG_REF
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:431
APNG_BLEND_OP_SOURCE
@ APNG_BLEND_OP_SOURCE
Definition: apng.h:37
ff_thread_get_buffer
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
Definition: pthread_frame.c:1053
GetByteContext::buffer
const uint8_t * buffer
Definition: bytestream.h:34
PNG_COLOR_TYPE_RGB
#define PNG_COLOR_TYPE_RGB
Definition: png.h:35
ff_png_decoder
const FFCodec ff_png_decoder
bits
uint8_t bits
Definition: vp3data.h:128
AV_EF_IGNORE_ERR
#define AV_EF_IGNORE_ERR
ignore errors and continue
Definition: defs.h:53
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
PNGDecContext::hdr_state
enum PNGHeaderState hdr_state
Definition: pngdec.c:96
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1593
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:230
PNGDecContext::iccp_data
uint8_t * iccp_data
Definition: pngdec.c:72
ff_progress_frame_unref
void ff_progress_frame_unref(ProgressFrame *f)
Give up a reference to the underlying frame contained in a ProgressFrame and reset the ProgressFrame,...
Definition: decode.c:1876
ff_progress_frame_await
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before ff_progress_frame_await() has been called on them. reget_buffer() and buffer age optimizations no longer work. *The contents of buffers must not be written to after ff_progress_frame_report() has been called on them. This includes draw_edges(). Porting codecs to frame threading
channels
channels
Definition: aptx.h:31
decode.h
percent_missing
static int percent_missing(PNGDecContext *s)
Definition: pngdec.c:355
APNG_BLEND_OP_OVER
@ APNG_BLEND_OP_OVER
Definition: apng.h:38
av_csp_primaries_id_from_desc
enum AVColorPrimaries av_csp_primaries_id_from_desc(const AVColorPrimariesDesc *prm)
Detects which enum AVColorPrimaries constant corresponds to the given complete gamut description.
Definition: csp.c:110
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:605
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:100
ff_decode_mastering_display_new
int ff_decode_mastering_display_new(const AVCodecContext *avctx, AVFrame *frame, AVMasteringDisplayMetadata **mdm)
Wrapper around av_mastering_display_metadata_create_side_data(), which rejects side data overridden b...
Definition: decode.c:2178
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:461
AVStereo3D::flags
int flags
Additional information about the frame packing.
Definition: stereo3d.h:212
AV_CODEC_ID_PNG
@ AV_CODEC_ID_PNG
Definition: codec_id.h:113
if
if(ret)
Definition: filter_design.txt:179
PNGDecContext
Definition: pngdec.c:61
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:110
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:221
AV_PIX_FMT_GRAY8A
@ AV_PIX_FMT_GRAY8A
alias for AV_PIX_FMT_YA8
Definition: pixfmt.h:143
PNGDecContext::cicp_primaries
enum AVColorPrimaries cicp_primaries
Definition: pngdec.c:83
NULL
#define NULL
Definition: coverity.c:32
PNGDecContext::filter_type
int filter_type
Definition: pngdec.c:106
png_decode_idat
static int png_decode_idat(PNGDecContext *s, GetByteContext *gb, uint8_t *dst, ptrdiff_t dst_stride)
Definition: pngdec.c:446
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
png_dec_init
static av_cold int png_dec_init(AVCodecContext *avctx)
Definition: pngdec.c:1892
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:709
apng.h
pixel
uint8_t pixel
Definition: tiny_ssim.c:41
AV_WB16
#define AV_WB16(p, v)
Definition: intreadwrite.h:401
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
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:83
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition: pixfmt.h:604
PNGDecContext::channels
int channels
Definition: pngdec.c:107
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:279
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
APNG_DISPOSE_OP_PREVIOUS
@ APNG_DISPOSE_OP_PREVIOUS
Definition: apng.h:33
PNG_COLOR_TYPE_GRAY
#define PNG_COLOR_TYPE_GRAY
Definition: png.h:33
abs
#define abs(x)
Definition: cuda_runtime.h:35
UPDATE_THREAD_CONTEXT
#define UPDATE_THREAD_CONTEXT(func)
Definition: codec_internal.h:305
decode_sbit_chunk
static int decode_sbit_chunk(AVCodecContext *avctx, PNGDecContext *s, GetByteContext *gb)
Definition: pngdec.c:1071
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
AV_EF_CRCCHECK
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
Definition: defs.h:48
apng_reset_background
static void apng_reset_background(PNGDecContext *s, const AVFrame *p)
Definition: pngdec.c:1366
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:699
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
output_frame
static int output_frame(PNGDecContext *s, AVFrame *f)
Definition: pngdec.c:1726
png_pass_mask
static const uint8_t png_pass_mask[NB_PASSES]
Definition: pngdec.c:131
bytestream2_get_bytes_left
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:158
bytestream2_tell
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:192
PNGDecContext::pass
int pass
Definition: pngdec.c:122
PNGDecContext::iccp_name
uint8_t iccp_name[82]
Definition: pngdec.c:71
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:28
handle_small_bpp
static void handle_small_bpp(PNGDecContext *s, AVFrame *p)
Definition: pngdec.c:1111
PNG_FILTER_VALUE_NONE
#define PNG_FILTER_VALUE_NONE
Definition: png.h:40
f
f
Definition: af_crystalizer.c:122
AVFrame::pict_type
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:512
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:75
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
PNGDecContext::gb
GetByteContext gb
Definition: pngdec.c:65
AVPacket::size
int size
Definition: packet.h:540
handle_p_frame_png
static void handle_p_frame_png(PNGDecContext *s, AVFrame *p)
Definition: pngdec.c:1255
height
#define height
Definition: dsp.h:85
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:401
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:240
codec_internal.h
PNGDecContext::white_point
uint32_t white_point[2]
Definition: pngdec.c:78
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
av_frame_copy
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:1035
png_put_interlaced_row
static void png_put_interlaced_row(uint8_t *dst, int width, int bits_per_pixel, int pass, int color_type, const uint8_t *src)
Definition: pngdec.c:148
AV_PIX_FMT_YA16BE
@ AV_PIX_FMT_YA16BE
16 bits gray, 16 bits alpha (big-endian)
Definition: pixfmt.h:209
PNG_FILTER_VALUE_AVG
#define PNG_FILTER_VALUE_AVG
Definition: png.h:43
size
int size
Definition: twinvq_data.h:10344
av_make_q
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
ff_frame_new_side_data
int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, size_t size, AVFrameSideData **psd)
Wrapper around av_frame_new_side_data, which rejects side data overridden by the demuxer.
Definition: decode.c:2099
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:96
FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters even if the frame is skipped due to the skip_frame sett...
Definition: codec_internal.h:54
avpriv_report_missing_feature
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
AVFrameSideData::data
uint8_t * data
Definition: frame.h:267
PNG_FILTER_VALUE_PAETH
#define PNG_FILTER_VALUE_PAETH
Definition: png.h:44
AV_RL24
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_RL24
Definition: bytestream.h:93
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:497
PNGDecContext::buffer
uint8_t * buffer
Definition: pngdec.c:120
PNGDecContext::zstream
FFZStream zstream
Definition: pngdec.c:127
PNG_FILTER_VALUE_UP
#define PNG_FILTER_VALUE_UP
Definition: png.h:42
FF_COMPLIANCE_NORMAL
#define FF_COMPLIANCE_NORMAL
Definition: defs.h:60
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
PNGDecContext::dispose_op
uint8_t dispose_op
Definition: pngdec.c:101
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
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:545
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:223
decode_trns_chunk
static int decode_trns_chunk(AVCodecContext *avctx, PNGDecContext *s, GetByteContext *gb)
Definition: pngdec.c:990
av_zero_extend
#define av_zero_extend
Definition: common.h:151
AV_STEREO3D_FLAG_INVERT
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
Definition: stereo3d.h:194
PNGSIG
#define PNGSIG
Definition: png.h:49
PNGDecContext::buffer_size
int buffer_size
Definition: pngdec.c:121
populate_avctx_color_fields
static int populate_avctx_color_fields(AVCodecContext *avctx, AVFrame *frame)
Definition: pngdec.c:662
FF_THREAD_FRAME
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:1612
PNGDecContext::stereo_mode
int stereo_mode
Definition: pngdec.c:75
ff_pngdsp_init
av_cold void ff_pngdsp_init(PNGDSPContext *dsp)
Definition: pngdsp.c:56
av_image_get_linesize
int av_image_get_linesize(enum AVPixelFormat pix_fmt, int width, int plane)
Compute the size of an image line with format pix_fmt and width width for the plane plane.
Definition: imgutils.c:76
PNGDecContext::frame_metadata
AVDictionary * frame_metadata
Definition: pngdec.c:69
PNGDecContext::significant_bits
int significant_bits
Definition: pngdec.c:112
PNGDSPContext::add_bytes_l2
void(* add_bytes_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
Definition: pngdsp.h:28
PNG_FILTER_VALUE_SUB
#define PNG_FILTER_VALUE_SUB
Definition: png.h:41
bprint.h
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:109
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVCodecContext::extradata
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition: avcodec.h:537
PNGDecContext::x_offset
int x_offset
Definition: pngdec.c:100
PNGDecContext::display_primaries
uint32_t display_primaries[3][2]
Definition: pngdec.c:79
PNGDecContext::mdcv_primaries
uint16_t mdcv_primaries[3][2]
Definition: pngdec.c:91
av_bprint_get_buffer
void av_bprint_get_buffer(AVBPrint *buf, unsigned size, unsigned char **mem, unsigned *actual_size)
Allocate bytes in the buffer for external use.
Definition: bprint.c:223
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
png_handle_row
static void png_handle_row(PNGDecContext *s, uint8_t *dst, ptrdiff_t dst_stride)
Definition: pngdec.c:365
av_fast_padded_malloc
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
Definition: utils.c:52
FF_DEBUG_STARTCODE
#define FF_DEBUG_STARTCODE
Definition: avcodec.h:1422
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
decode_fctl_chunk
static int decode_fctl_chunk(AVCodecContext *avctx, PNGDecContext *s, GetByteContext *gb)
Definition: pngdec.c:1184
decode_plte_chunk
static int decode_plte_chunk(AVCodecContext *avctx, PNGDecContext *s, GetByteContext *gb)
Definition: pngdec.c:967
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:623
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
AVMasteringDisplayMetadata
Mastering display metadata capable of representing the color volume of the display used to master the...
Definition: mastering_display_metadata.h:38
ff_inflate_end
void ff_inflate_end(FFZStream *zstream)
Wrapper around inflateEnd().
GetByteContext::buffer_end
const uint8_t * buffer_end
Definition: bytestream.h:34
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:671
AV_FRAME_FLAG_INTERLACED
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition: frame.h:669
PNGDecContext::avctx
AVCodecContext * avctx
Definition: pngdec.c:63
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:716
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:81
avcodec.h
PNGHeaderState
PNGHeaderState
Definition: pngdec.c:51
AV_PIX_FMT_PAL8
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:84
tag
uint32_t tag
Definition: movenc.c:1879
ret
ret
Definition: filter_design.txt:187
pixfmt.h
close
static void close(AVCodecParserContext *s)
Definition: ffv1_parser.c:73
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
PNGDecContext::iccp_data_len
size_t iccp_data_len
Definition: pngdec.c:73
AVCodecContext::strict_std_compliance
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:1397
AVStereo3D::type
enum AVStereo3DType type
How views are packed within the video.
Definition: stereo3d.h:207
ff_decode_content_light_new
int ff_decode_content_light_new(const AVCodecContext *avctx, AVFrame *frame, AVContentLightMetadata **clm)
Wrapper around av_content_light_metadata_create_side_data(), which rejects side data overridden by th...
Definition: decode.c:2223
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:99
ff_thread_finish_setup
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call ff_thread_finish_setup() afterwards. If some code can 't be moved
PNGDecContext::compression_type
int compression_type
Definition: pngdec.c:104
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
U
#define U(x)
Definition: vpx_arith.h:37
ff_progress_frame_replace
void ff_progress_frame_replace(ProgressFrame *dst, const ProgressFrame *src)
Do nothing if dst and src already refer to the same AVFrame; otherwise unreference dst and if src is ...
Definition: decode.c:1883
iso88591_to_utf8
static char * iso88591_to_utf8(const char *in, size_t size_in)
Definition: pngdec.c:519
PNG_IHDR
@ PNG_IHDR
Definition: pngdec.c:52
ff_png_filter_row
void ff_png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type, uint8_t *src, uint8_t *last, int size, int bpp)
Definition: pngdec.c:284
AVCodecContext
main external API structure.
Definition: avcodec.h:451
AVFrame::height
int height
Definition: frame.h:482
AVCodecContext::active_thread_type
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:1620
decode_frame_common
static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s, AVFrame *p, const AVPacket *avpkt)
Definition: pngdec.c:1382
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
UNROLL_FILTER
#define UNROLL_FILTER(op)
Definition: pngdec.c:269
AVRational::den
int den
Denominator.
Definition: rational.h:60
mode
mode
Definition: ebur128.h:83
PNGDecContext::last_picture
ProgressFrame last_picture
Definition: pngdec.c:66
PNGDecContext::mdcv_min_lum
uint32_t mdcv_min_lum
Definition: pngdec.c:94
PNGDecContext::transparent_color_be
uint8_t transparent_color_be[6]
Definition: pngdec.c:111
update_thread_context
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call have update_thread_context() run it in the next thread. Add AV_CODEC_CAP_FRAME_THREADS to the codec capabilities. There will be very little speed gain at this point but it should work. Use ff_thread_get_buffer()(or ff_progress_frame_get_buffer() in case you have inter-frame dependencies and use the ProgressFrame API) to allocate frame buffers. Call ff_progress_frame_report() after some part of the current picture has decoded. A good place to put this is where draw_horiz_band() is called - add this if it isn 't called anywhere
av_fast_padded_mallocz
void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_padded_malloc except that buffer will always be 0-initialized after call.
Definition: utils.c:65
PNGDecContext::have_chrm
int have_chrm
Definition: pngdec.c:77
png_pass_dsp_mask
static const uint8_t png_pass_dsp_mask[NB_PASSES]
Definition: pngdec.c:141
AVCodecContext::discard_damaged_percentage
int discard_damaged_percentage
The percentage of damaged samples to discard a frame.
Definition: avcodec.h:1999
PNG_COLOR_MASK_PALETTE
#define PNG_COLOR_MASK_PALETTE
Definition: png.h:29
AVMasteringDisplayMetadata::min_luminance
AVRational min_luminance
Min luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:52
AVCodecContext::debug
int debug
debug
Definition: avcodec.h:1414
PNG_IDAT
@ PNG_IDAT
Definition: pngdec.c:57
AV_CRC_32_IEEE_LE
@ AV_CRC_32_IEEE_LE
Definition: crc.h:53
decode_iccp_chunk
static int decode_iccp_chunk(PNGDecContext *s, GetByteContext *gb)
Definition: pngdec.c:1038
desc
const char * desc
Definition: libsvtav1.c:79
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
FFZStream
Definition: zlib_wrapper.h:27
mem.h
mastering_display_metadata.h
decode_ihdr_chunk
static int decode_ihdr_chunk(AVCodecContext *avctx, PNGDecContext *s, GetByteContext *gb)
Definition: pngdec.c:590
PNGDecContext::dsp
PNGDSPContext dsp
Definition: pngdec.c:62
av_stereo3d_create_side_data
AVStereo3D * av_stereo3d_create_side_data(AVFrame *frame)
Allocate a complete AVFrameSideData and add it to the frame.
Definition: stereo3d.c:54
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:36
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:265
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVCodecContext::codec_tag
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:476
ProgressFrame
The ProgressFrame structure.
Definition: progressframe.h:73
AVPacket
This structure stores compressed data.
Definition: packet.h:516
AVContentLightMetadata::MaxFALL
unsigned MaxFALL
Max average light level per frame (cd/m^2).
Definition: mastering_display_metadata.h:116
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:478
png.h
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:88
ff_inflate_init
int ff_inflate_init(FFZStream *zstream, void *logctx)
Wrapper around inflateInit().
bytestream.h
imgutils.h
bytestream2_init
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:137
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:455
PNG_COLOR_TYPE_GRAY_ALPHA
#define PNG_COLOR_TYPE_GRAY_ALPHA
Definition: png.h:37
AVFrameSideData::metadata
AVDictionary * metadata
Definition: frame.h:269
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
AVCOL_TRC_SMPTE428
@ AVCOL_TRC_SMPTE428
SMPTE ST 428-1.
Definition: pixfmt.h:646
MNGSIG
#define MNGSIG
Definition: png.h:50
PNGDecContext::cicp_trc
enum AVColorTransferCharacteristic cicp_trc
Definition: pngdec.c:84
PNGDecContext::interlace_type
int interlace_type
Definition: pngdec.c:105
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:203
handle_p_frame_apng
static int handle_p_frame_apng(AVCodecContext *avctx, PNGDecContext *s, AVFrame *p)
Definition: pngdec.c:1277
PNGDecContext::y
int y
Definition: pngdec.c:126
av_image_check_size
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:318
OP_SUB
#define OP_SUB(x, s, l)
width
#define width
Definition: dsp.h:85
PNGDecContext::have_mdcv
int have_mdcv
Definition: pngdec.c:90
AVColorRange
AVColorRange
Visual content value range.
Definition: pixfmt.h:698
decode_zbuf
static int decode_zbuf(AVBPrint *bp, const uint8_t *data, const uint8_t *data_end, void *logctx)
Definition: pngdec.c:477
PNGDecContext::cur_w
int cur_w
Definition: pngdec.c:99
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:656
PNG_COLOR_TYPE_PALETTE
#define PNG_COLOR_TYPE_PALETTE
Definition: png.h:34
src
#define src
Definition: vp8dsp.c:248
AV_DICT_DONT_STRDUP_KEY
#define AV_DICT_DONT_STRDUP_KEY
Take ownership of a key that's been allocated with av_malloc() or another memory allocation function.
Definition: dict.h:77
PNGDecContext::bpp
int bpp
Definition: pngdec.c:109
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:3168
PNGDecContext::has_trns
int has_trns
Definition: pngdec.c:110
av_fourcc2str
#define av_fourcc2str(fourcc)
Definition: avutil.h:348