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