FFmpeg  4.3.8
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 "libavutil/avassert.h"
25 #include "libavutil/bprint.h"
26 #include "libavutil/crc.h"
27 #include "libavutil/imgutils.h"
28 #include "libavutil/intreadwrite.h"
29 #include "libavutil/stereo3d.h"
31 
32 #include "avcodec.h"
33 #include "bytestream.h"
34 #include "internal.h"
35 #include "apng.h"
36 #include "png.h"
37 #include "pngdsp.h"
38 #include "thread.h"
39 
40 #include <zlib.h>
41 
43  PNG_IHDR = 1 << 0,
44  PNG_PLTE = 1 << 1,
45 };
46 
48  PNG_IDAT = 1 << 0,
49  PNG_ALLIMAGE = 1 << 1,
50 };
51 
52 typedef struct PNGDecContext {
55 
60 
63  int width, height;
64  int cur_w, cur_h;
65  int last_w, last_h;
70  int bit_depth;
75  int channels;
77  int bpp;
78  int has_trns;
80 
83  uint32_t palette[256];
86  unsigned int last_row_size;
88  unsigned int tmp_row_size;
91  int pass;
92  int crow_size; /* compressed row size (include filter type) */
93  int row_size; /* decompressed row size */
94  int pass_row_size; /* decompress row size of the current pass */
95  int y;
96  z_stream zstream;
98 
99 /* Mask to determine which pixels are valid in a pass */
100 static const uint8_t png_pass_mask[NB_PASSES] = {
101  0x01, 0x01, 0x11, 0x11, 0x55, 0x55, 0xff,
102 };
103 
104 /* Mask to determine which y pixels can be written in a pass */
106  0xff, 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
107 };
108 
109 /* Mask to determine which pixels to overwrite while displaying */
111  0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff
112 };
113 
114 /* NOTE: we try to construct a good looking image at each pass. width
115  * is the original image width. We also do pixel format conversion at
116  * this stage */
117 static void png_put_interlaced_row(uint8_t *dst, int width,
118  int bits_per_pixel, int pass,
119  int color_type, const uint8_t *src)
120 {
121  int x, mask, dsp_mask, j, src_x, b, bpp;
122  uint8_t *d;
123  const uint8_t *s;
124 
125  mask = png_pass_mask[pass];
126  dsp_mask = png_pass_dsp_mask[pass];
127 
128  switch (bits_per_pixel) {
129  case 1:
130  src_x = 0;
131  for (x = 0; x < width; x++) {
132  j = (x & 7);
133  if ((dsp_mask << j) & 0x80) {
134  b = (src[src_x >> 3] >> (7 - (src_x & 7))) & 1;
135  dst[x >> 3] &= 0xFF7F>>j;
136  dst[x >> 3] |= b << (7 - j);
137  }
138  if ((mask << j) & 0x80)
139  src_x++;
140  }
141  break;
142  case 2:
143  src_x = 0;
144  for (x = 0; x < width; x++) {
145  int j2 = 2 * (x & 3);
146  j = (x & 7);
147  if ((dsp_mask << j) & 0x80) {
148  b = (src[src_x >> 2] >> (6 - 2*(src_x & 3))) & 3;
149  dst[x >> 2] &= 0xFF3F>>j2;
150  dst[x >> 2] |= b << (6 - j2);
151  }
152  if ((mask << j) & 0x80)
153  src_x++;
154  }
155  break;
156  case 4:
157  src_x = 0;
158  for (x = 0; x < width; x++) {
159  int j2 = 4*(x&1);
160  j = (x & 7);
161  if ((dsp_mask << j) & 0x80) {
162  b = (src[src_x >> 1] >> (4 - 4*(src_x & 1))) & 15;
163  dst[x >> 1] &= 0xFF0F>>j2;
164  dst[x >> 1] |= b << (4 - j2);
165  }
166  if ((mask << j) & 0x80)
167  src_x++;
168  }
169  break;
170  default:
171  bpp = bits_per_pixel >> 3;
172  d = dst;
173  s = src;
174  for (x = 0; x < width; x++) {
175  j = x & 7;
176  if ((dsp_mask << j) & 0x80) {
177  memcpy(d, s, bpp);
178  }
179  d += bpp;
180  if ((mask << j) & 0x80)
181  s += bpp;
182  }
183  break;
184  }
185 }
186 
188  int w, int bpp)
189 {
190  int i;
191  for (i = 0; i < w; i++) {
192  int a, b, c, p, pa, pb, pc;
193 
194  a = dst[i - bpp];
195  b = top[i];
196  c = top[i - bpp];
197 
198  p = b - c;
199  pc = a - c;
200 
201  pa = abs(p);
202  pb = abs(pc);
203  pc = abs(p + pc);
204 
205  if (pa <= pb && pa <= pc)
206  p = a;
207  else if (pb <= pc)
208  p = b;
209  else
210  p = c;
211  dst[i] = p + src[i];
212  }
213 }
214 
215 #define UNROLL1(bpp, op) \
216  { \
217  r = dst[0]; \
218  if (bpp >= 2) \
219  g = dst[1]; \
220  if (bpp >= 3) \
221  b = dst[2]; \
222  if (bpp >= 4) \
223  a = dst[3]; \
224  for (; i <= size - bpp; i += bpp) { \
225  dst[i + 0] = r = op(r, src[i + 0], last[i + 0]); \
226  if (bpp == 1) \
227  continue; \
228  dst[i + 1] = g = op(g, src[i + 1], last[i + 1]); \
229  if (bpp == 2) \
230  continue; \
231  dst[i + 2] = b = op(b, src[i + 2], last[i + 2]); \
232  if (bpp == 3) \
233  continue; \
234  dst[i + 3] = a = op(a, src[i + 3], last[i + 3]); \
235  } \
236  }
237 
238 #define UNROLL_FILTER(op) \
239  if (bpp == 1) { \
240  UNROLL1(1, op) \
241  } else if (bpp == 2) { \
242  UNROLL1(2, op) \
243  } else if (bpp == 3) { \
244  UNROLL1(3, op) \
245  } else if (bpp == 4) { \
246  UNROLL1(4, op) \
247  } \
248  for (; i < size; i++) { \
249  dst[i] = op(dst[i - bpp], src[i], last[i]); \
250  }
251 
252 /* NOTE: 'dst' can be equal to 'last' */
254  uint8_t *src, uint8_t *last, int size, int bpp)
255 {
256  int i, p, r, g, b, a;
257 
258  switch (filter_type) {
260  memcpy(dst, src, size);
261  break;
263  for (i = 0; i < bpp; i++)
264  dst[i] = src[i];
265  if (bpp == 4) {
266  p = *(int *)dst;
267  for (; i < size; i += bpp) {
268  unsigned s = *(int *)(src + i);
269  p = ((s & 0x7f7f7f7f) + (p & 0x7f7f7f7f)) ^ ((s ^ p) & 0x80808080);
270  *(int *)(dst + i) = p;
271  }
272  } else {
273 #define OP_SUB(x, s, l) ((x) + (s))
275  }
276  break;
277  case PNG_FILTER_VALUE_UP:
278  dsp->add_bytes_l2(dst, src, last, size);
279  break;
281  for (i = 0; i < bpp; i++) {
282  p = (last[i] >> 1);
283  dst[i] = p + src[i];
284  }
285 #define OP_AVG(x, s, l) (((((x) + (l)) >> 1) + (s)) & 0xff)
287  break;
289  for (i = 0; i < bpp; i++) {
290  p = last[i];
291  dst[i] = p + src[i];
292  }
293  if (bpp > 2 && size > 4) {
294  /* would write off the end of the array if we let it process
295  * the last pixel with bpp=3 */
296  int w = (bpp & 3) ? size - 3 : size;
297 
298  if (w > i) {
299  dsp->add_paeth_prediction(dst + i, src + i, last + i, size - i, bpp);
300  i = w;
301  }
302  }
303  ff_add_png_paeth_prediction(dst + i, src + i, last + i, size - i, bpp);
304  break;
305  }
306 }
307 
308 /* This used to be called "deloco" in FFmpeg
309  * and is actually an inverse reversible colorspace transformation */
310 #define YUV2RGB(NAME, TYPE) \
311 static void deloco_ ## NAME(TYPE *dst, int size, int alpha) \
312 { \
313  int i; \
314  for (i = 0; i < size - 2; i += 3 + alpha) { \
315  int g = dst [i + 1]; \
316  dst[i + 0] += g; \
317  dst[i + 2] += g; \
318  } \
319 }
320 
321 YUV2RGB(rgb8, uint8_t)
322 YUV2RGB(rgb16, uint16_t)
323 
325 {
326  if (s->interlace_type) {
327  return 100 - 100 * s->pass / (NB_PASSES - 1);
328  } else {
329  return 100 - 100 * s->y / s->cur_h;
330  }
331 }
332 
333 /* process exactly one decompressed row */
335 {
336  uint8_t *ptr, *last_row;
337  int got_line;
338 
339  if (!s->interlace_type) {
340  ptr = s->image_buf + s->image_linesize * (s->y + s->y_offset) + s->x_offset * s->bpp;
341  if (s->y == 0)
342  last_row = s->last_row;
343  else
344  last_row = ptr - s->image_linesize;
345 
346  png_filter_row(&s->dsp, ptr, s->crow_buf[0], s->crow_buf + 1,
347  last_row, s->row_size, s->bpp);
348  /* loco lags by 1 row so that it doesn't interfere with top prediction */
349  if (s->filter_type == PNG_FILTER_TYPE_LOCO && s->y > 0) {
350  if (s->bit_depth == 16) {
351  deloco_rgb16((uint16_t *)(ptr - s->image_linesize), s->row_size / 2,
353  } else {
354  deloco_rgb8(ptr - s->image_linesize, s->row_size,
356  }
357  }
358  s->y++;
359  if (s->y == s->cur_h) {
360  s->pic_state |= PNG_ALLIMAGE;
361  if (s->filter_type == PNG_FILTER_TYPE_LOCO) {
362  if (s->bit_depth == 16) {
363  deloco_rgb16((uint16_t *)ptr, s->row_size / 2,
365  } else {
366  deloco_rgb8(ptr, s->row_size,
368  }
369  }
370  }
371  } else {
372  got_line = 0;
373  for (;;) {
374  ptr = s->image_buf + s->image_linesize * (s->y + s->y_offset) + s->x_offset * s->bpp;
375  if ((ff_png_pass_ymask[s->pass] << (s->y & 7)) & 0x80) {
376  /* if we already read one row, it is time to stop to
377  * wait for the next one */
378  if (got_line)
379  break;
380  png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
381  s->last_row, s->pass_row_size, s->bpp);
382  FFSWAP(uint8_t *, s->last_row, s->tmp_row);
383  FFSWAP(unsigned int, s->last_row_size, s->tmp_row_size);
384  got_line = 1;
385  }
386  if ((png_pass_dsp_ymask[s->pass] << (s->y & 7)) & 0x80) {
388  s->color_type, s->last_row);
389  }
390  s->y++;
391  if (s->y == s->cur_h) {
392  memset(s->last_row, 0, s->row_size);
393  for (;;) {
394  if (s->pass == NB_PASSES - 1) {
395  s->pic_state |= PNG_ALLIMAGE;
396  goto the_end;
397  } else {
398  s->pass++;
399  s->y = 0;
401  s->bits_per_pixel,
402  s->cur_w);
403  s->crow_size = s->pass_row_size + 1;
404  if (s->pass_row_size != 0)
405  break;
406  /* skip pass if empty row */
407  }
408  }
409  }
410  }
411 the_end:;
412  }
413 }
414 
415 static int png_decode_idat(PNGDecContext *s, int length)
416 {
417  int ret;
418  s->zstream.avail_in = FFMIN(length, bytestream2_get_bytes_left(&s->gb));
419  s->zstream.next_in = s->gb.buffer;
420  bytestream2_skip(&s->gb, length);
421 
422  /* decode one line if possible */
423  while (s->zstream.avail_in > 0) {
424  ret = inflate(&s->zstream, Z_PARTIAL_FLUSH);
425  if (ret != Z_OK && ret != Z_STREAM_END) {
426  av_log(s->avctx, AV_LOG_ERROR, "inflate returned error %d\n", ret);
427  return AVERROR_EXTERNAL;
428  }
429  if (s->zstream.avail_out == 0) {
430  if (!(s->pic_state & PNG_ALLIMAGE)) {
431  png_handle_row(s);
432  }
433  s->zstream.avail_out = s->crow_size;
434  s->zstream.next_out = s->crow_buf;
435  }
436  if (ret == Z_STREAM_END && s->zstream.avail_in > 0) {
438  "%d undecompressed bytes left in buffer\n", s->zstream.avail_in);
439  return 0;
440  }
441  }
442  return 0;
443 }
444 
445 static int decode_zbuf(AVBPrint *bp, const uint8_t *data,
446  const uint8_t *data_end)
447 {
448  z_stream zstream;
449  unsigned char *buf;
450  unsigned buf_size;
451  int ret;
452 
453  zstream.zalloc = ff_png_zalloc;
454  zstream.zfree = ff_png_zfree;
455  zstream.opaque = NULL;
456  if (inflateInit(&zstream) != Z_OK)
457  return AVERROR_EXTERNAL;
458  zstream.next_in = data;
459  zstream.avail_in = data_end - data;
461 
462  while (zstream.avail_in > 0) {
463  av_bprint_get_buffer(bp, 2, &buf, &buf_size);
464  if (buf_size < 2) {
465  ret = AVERROR(ENOMEM);
466  goto fail;
467  }
468  zstream.next_out = buf;
469  zstream.avail_out = buf_size - 1;
470  ret = inflate(&zstream, Z_PARTIAL_FLUSH);
471  if (ret != Z_OK && ret != Z_STREAM_END) {
472  ret = AVERROR_EXTERNAL;
473  goto fail;
474  }
475  bp->len += zstream.next_out - buf;
476  if (ret == Z_STREAM_END)
477  break;
478  }
479  inflateEnd(&zstream);
480  bp->str[bp->len] = 0;
481  return 0;
482 
483 fail:
484  inflateEnd(&zstream);
486  return ret;
487 }
488 
489 static uint8_t *iso88591_to_utf8(const uint8_t *in, size_t size_in)
490 {
491  size_t extra = 0, i;
492  uint8_t *out, *q;
493 
494  for (i = 0; i < size_in; i++)
495  extra += in[i] >= 0x80;
496  if (size_in == SIZE_MAX || extra > SIZE_MAX - size_in - 1)
497  return NULL;
498  q = out = av_malloc(size_in + extra + 1);
499  if (!out)
500  return NULL;
501  for (i = 0; i < size_in; i++) {
502  if (in[i] >= 0x80) {
503  *(q++) = 0xC0 | (in[i] >> 6);
504  *(q++) = 0x80 | (in[i] & 0x3F);
505  } else {
506  *(q++) = in[i];
507  }
508  }
509  *(q++) = 0;
510  return out;
511 }
512 
513 static int decode_text_chunk(PNGDecContext *s, uint32_t length, int compressed,
514  AVDictionary **dict)
515 {
516  int ret, method;
517  const uint8_t *data = s->gb.buffer;
518  const uint8_t *data_end = data + length;
519  const uint8_t *keyword = data;
520  const uint8_t *keyword_end = memchr(keyword, 0, data_end - keyword);
521  uint8_t *kw_utf8 = NULL, *text, *txt_utf8 = NULL;
522  unsigned text_len;
523  AVBPrint bp;
524 
525  if (!keyword_end)
526  return AVERROR_INVALIDDATA;
527  data = keyword_end + 1;
528 
529  if (compressed) {
530  if (data == data_end)
531  return AVERROR_INVALIDDATA;
532  method = *(data++);
533  if (method)
534  return AVERROR_INVALIDDATA;
535  if ((ret = decode_zbuf(&bp, data, data_end)) < 0)
536  return ret;
537  text_len = bp.len;
538  ret = av_bprint_finalize(&bp, (char **)&text);
539  if (ret < 0)
540  return ret;
541  } else {
542  text = (uint8_t *)data;
543  text_len = data_end - text;
544  }
545 
546  kw_utf8 = iso88591_to_utf8(keyword, keyword_end - keyword);
547  txt_utf8 = iso88591_to_utf8(text, text_len);
548  if (text != data)
549  av_free(text);
550  if (!(kw_utf8 && txt_utf8)) {
551  av_free(kw_utf8);
552  av_free(txt_utf8);
553  return AVERROR(ENOMEM);
554  }
555 
556  av_dict_set(dict, kw_utf8, txt_utf8,
558  return 0;
559 }
560 
562  uint32_t length)
563 {
564  if (length != 13)
565  return AVERROR_INVALIDDATA;
566 
567  if (s->pic_state & PNG_IDAT) {
568  av_log(avctx, AV_LOG_ERROR, "IHDR after IDAT\n");
569  return AVERROR_INVALIDDATA;
570  }
571 
572  if (s->hdr_state & PNG_IHDR) {
573  av_log(avctx, AV_LOG_ERROR, "Multiple IHDR\n");
574  return AVERROR_INVALIDDATA;
575  }
576 
577  s->width = s->cur_w = bytestream2_get_be32(&s->gb);
578  s->height = s->cur_h = bytestream2_get_be32(&s->gb);
579  if (av_image_check_size(s->width, s->height, 0, avctx)) {
580  s->cur_w = s->cur_h = s->width = s->height = 0;
581  av_log(avctx, AV_LOG_ERROR, "Invalid image size\n");
582  return AVERROR_INVALIDDATA;
583  }
584  s->bit_depth = bytestream2_get_byte(&s->gb);
585  if (s->bit_depth != 1 && s->bit_depth != 2 && s->bit_depth != 4 &&
586  s->bit_depth != 8 && s->bit_depth != 16) {
587  av_log(avctx, AV_LOG_ERROR, "Invalid bit depth\n");
588  goto error;
589  }
590  s->color_type = bytestream2_get_byte(&s->gb);
591  s->compression_type = bytestream2_get_byte(&s->gb);
592  if (s->compression_type) {
593  av_log(avctx, AV_LOG_ERROR, "Invalid compression method %d\n", s->compression_type);
594  goto error;
595  }
596  s->filter_type = bytestream2_get_byte(&s->gb);
597  s->interlace_type = bytestream2_get_byte(&s->gb);
598  bytestream2_skip(&s->gb, 4); /* crc */
599  s->hdr_state |= PNG_IHDR;
600  if (avctx->debug & FF_DEBUG_PICT_INFO)
601  av_log(avctx, AV_LOG_DEBUG, "width=%d height=%d depth=%d color_type=%d "
602  "compression_type=%d filter_type=%d interlace_type=%d\n",
603  s->width, s->height, s->bit_depth, s->color_type,
605 
606  return 0;
607 error:
608  s->cur_w = s->cur_h = s->width = s->height = 0;
609  s->bit_depth = 8;
610  return AVERROR_INVALIDDATA;
611 }
612 
614 {
615  if (s->pic_state & PNG_IDAT) {
616  av_log(avctx, AV_LOG_ERROR, "pHYs after IDAT\n");
617  return AVERROR_INVALIDDATA;
618  }
619  avctx->sample_aspect_ratio.num = bytestream2_get_be32(&s->gb);
620  avctx->sample_aspect_ratio.den = bytestream2_get_be32(&s->gb);
621  if (avctx->sample_aspect_ratio.num < 0 || avctx->sample_aspect_ratio.den < 0)
622  avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
623  bytestream2_skip(&s->gb, 1); /* unit specifier */
624  bytestream2_skip(&s->gb, 4); /* crc */
625 
626  return 0;
627 }
628 
630  uint32_t length, AVFrame *p)
631 {
632  int ret;
633  size_t byte_depth = s->bit_depth > 8 ? 2 : 1;
634 
635  if (!p)
636  return AVERROR_INVALIDDATA;
637  if (!(s->hdr_state & PNG_IHDR)) {
638  av_log(avctx, AV_LOG_ERROR, "IDAT without IHDR\n");
639  return AVERROR_INVALIDDATA;
640  }
641  if (!(s->pic_state & PNG_IDAT)) {
642  /* init image info */
643  ret = ff_set_dimensions(avctx, s->width, s->height);
644  if (ret < 0)
645  return ret;
646 
648  s->bits_per_pixel = s->bit_depth * s->channels;
649  s->bpp = (s->bits_per_pixel + 7) >> 3;
650  s->row_size = (s->cur_w * s->bits_per_pixel + 7) >> 3;
651 
652  if ((s->bit_depth == 2 || s->bit_depth == 4 || s->bit_depth == 8) &&
654  avctx->pix_fmt = AV_PIX_FMT_RGB24;
655  } else if ((s->bit_depth == 2 || s->bit_depth == 4 || s->bit_depth == 8) &&
657  avctx->pix_fmt = AV_PIX_FMT_RGBA;
658  } else if ((s->bit_depth == 2 || s->bit_depth == 4 || s->bit_depth == 8) &&
660  avctx->pix_fmt = AV_PIX_FMT_GRAY8;
661  } else if (s->bit_depth == 16 &&
663  avctx->pix_fmt = AV_PIX_FMT_GRAY16BE;
664  } else if (s->bit_depth == 16 &&
666  avctx->pix_fmt = AV_PIX_FMT_RGB48BE;
667  } else if (s->bit_depth == 16 &&
669  avctx->pix_fmt = AV_PIX_FMT_RGBA64BE;
670  } else if ((s->bits_per_pixel == 1 || s->bits_per_pixel == 2 || s->bits_per_pixel == 4 || s->bits_per_pixel == 8) &&
672  avctx->pix_fmt = AV_PIX_FMT_PAL8;
673  } else if (s->bit_depth == 1 && s->bits_per_pixel == 1 && avctx->codec_id != AV_CODEC_ID_APNG) {
674  avctx->pix_fmt = AV_PIX_FMT_MONOBLACK;
675  } else if (s->bit_depth == 8 &&
677  avctx->pix_fmt = AV_PIX_FMT_YA8;
678  } else if (s->bit_depth == 16 &&
680  avctx->pix_fmt = AV_PIX_FMT_YA16BE;
681  } else {
683  "Bit depth %d color type %d",
684  s->bit_depth, s->color_type);
685  return AVERROR_PATCHWELCOME;
686  }
687 
688  if (s->has_trns && s->color_type != PNG_COLOR_TYPE_PALETTE) {
689  switch (avctx->pix_fmt) {
690  case AV_PIX_FMT_RGB24:
691  avctx->pix_fmt = AV_PIX_FMT_RGBA;
692  break;
693 
694  case AV_PIX_FMT_RGB48BE:
695  avctx->pix_fmt = AV_PIX_FMT_RGBA64BE;
696  break;
697 
698  case AV_PIX_FMT_GRAY8:
699  avctx->pix_fmt = AV_PIX_FMT_YA8;
700  break;
701 
702  case AV_PIX_FMT_GRAY16BE:
703  avctx->pix_fmt = AV_PIX_FMT_YA16BE;
704  break;
705 
706  default:
707  avpriv_request_sample(avctx, "bit depth %d "
708  "and color type %d with TRNS",
709  s->bit_depth, s->color_type);
710  return AVERROR_INVALIDDATA;
711  }
712 
713  s->bpp += byte_depth;
714  }
715 
716  if ((ret = ff_thread_get_buffer(avctx, &s->picture, AV_GET_BUFFER_FLAG_REF)) < 0)
717  return ret;
720  if ((ret = ff_thread_get_buffer(avctx, &s->previous_picture, AV_GET_BUFFER_FLAG_REF)) < 0)
721  return ret;
722  }
724  p->key_frame = 1;
726 
727  ff_thread_finish_setup(avctx);
728 
729  /* compute the compressed row size */
730  if (!s->interlace_type) {
731  s->crow_size = s->row_size + 1;
732  } else {
733  s->pass = 0;
735  s->bits_per_pixel,
736  s->cur_w);
737  s->crow_size = s->pass_row_size + 1;
738  }
739  ff_dlog(avctx, "row_size=%d crow_size =%d\n",
740  s->row_size, s->crow_size);
741  s->image_buf = p->data[0];
742  s->image_linesize = p->linesize[0];
743  /* copy the palette if needed */
744  if (avctx->pix_fmt == AV_PIX_FMT_PAL8)
745  memcpy(p->data[1], s->palette, 256 * sizeof(uint32_t));
746  /* empty row is used if differencing to the first row */
748  if (!s->last_row)
749  return AVERROR_INVALIDDATA;
750  if (s->interlace_type ||
753  if (!s->tmp_row)
754  return AVERROR_INVALIDDATA;
755  }
756  /* compressed row */
758  if (!s->buffer)
759  return AVERROR(ENOMEM);
760 
761  /* we want crow_buf+1 to be 16-byte aligned */
762  s->crow_buf = s->buffer + 15;
763  s->zstream.avail_out = s->crow_size;
764  s->zstream.next_out = s->crow_buf;
765  }
766 
767  s->pic_state |= PNG_IDAT;
768 
769  /* set image to non-transparent bpp while decompressing */
771  s->bpp -= byte_depth;
772 
773  ret = png_decode_idat(s, length);
774 
776  s->bpp += byte_depth;
777 
778  if (ret < 0)
779  return ret;
780 
781  bytestream2_skip(&s->gb, 4); /* crc */
782 
783  return 0;
784 }
785 
787  uint32_t length)
788 {
789  int n, i, r, g, b;
790 
791  if ((length % 3) != 0 || length > 256 * 3)
792  return AVERROR_INVALIDDATA;
793  /* read the palette */
794  n = length / 3;
795  for (i = 0; i < n; i++) {
796  r = bytestream2_get_byte(&s->gb);
797  g = bytestream2_get_byte(&s->gb);
798  b = bytestream2_get_byte(&s->gb);
799  s->palette[i] = (0xFFU << 24) | (r << 16) | (g << 8) | b;
800  }
801  for (; i < 256; i++)
802  s->palette[i] = (0xFFU << 24);
803  s->hdr_state |= PNG_PLTE;
804  bytestream2_skip(&s->gb, 4); /* crc */
805 
806  return 0;
807 }
808 
810  uint32_t length)
811 {
812  int v, i;
813 
814  if (!(s->hdr_state & PNG_IHDR)) {
815  av_log(avctx, AV_LOG_ERROR, "trns before IHDR\n");
816  return AVERROR_INVALIDDATA;
817  }
818 
819  if (s->pic_state & PNG_IDAT) {
820  av_log(avctx, AV_LOG_ERROR, "trns after IDAT\n");
821  return AVERROR_INVALIDDATA;
822  }
823 
825  if (length > 256 || !(s->hdr_state & PNG_PLTE))
826  return AVERROR_INVALIDDATA;
827 
828  for (i = 0; i < length; i++) {
829  unsigned v = bytestream2_get_byte(&s->gb);
830  s->palette[i] = (s->palette[i] & 0x00ffffff) | (v << 24);
831  }
832  } else if (s->color_type == PNG_COLOR_TYPE_GRAY || s->color_type == PNG_COLOR_TYPE_RGB) {
833  if ((s->color_type == PNG_COLOR_TYPE_GRAY && length != 2) ||
834  (s->color_type == PNG_COLOR_TYPE_RGB && length != 6) ||
835  s->bit_depth == 1)
836  return AVERROR_INVALIDDATA;
837 
838  for (i = 0; i < length / 2; i++) {
839  /* only use the least significant bits */
840  v = av_mod_uintp2(bytestream2_get_be16(&s->gb), s->bit_depth);
841 
842  if (s->bit_depth > 8)
843  AV_WB16(&s->transparent_color_be[2 * i], v);
844  else
845  s->transparent_color_be[i] = v;
846  }
847  } else {
848  return AVERROR_INVALIDDATA;
849  }
850 
851  bytestream2_skip(&s->gb, 4); /* crc */
852  s->has_trns = 1;
853 
854  return 0;
855 }
856 
857 static int decode_iccp_chunk(PNGDecContext *s, int length, AVFrame *f)
858 {
859  int ret, cnt = 0;
860  uint8_t *data, profile_name[82];
861  AVBPrint bp;
862  AVFrameSideData *sd;
863 
864  while ((profile_name[cnt++] = bytestream2_get_byte(&s->gb)) && cnt < 81);
865  if (cnt > 80) {
866  av_log(s->avctx, AV_LOG_ERROR, "iCCP with invalid name!\n");
867  return AVERROR_INVALIDDATA;
868  }
869 
870  length = FFMAX(length - cnt, 0);
871 
872  if (bytestream2_get_byte(&s->gb) != 0) {
873  av_log(s->avctx, AV_LOG_ERROR, "iCCP with invalid compression!\n");
874  return AVERROR_INVALIDDATA;
875  }
876 
877  length = FFMAX(length - 1, 0);
878 
879  if ((ret = decode_zbuf(&bp, s->gb.buffer, s->gb.buffer + length)) < 0)
880  return ret;
881 
882  ret = av_bprint_finalize(&bp, (char **)&data);
883  if (ret < 0)
884  return ret;
885 
887  if (!sd) {
888  av_free(data);
889  return AVERROR(ENOMEM);
890  }
891 
892  av_dict_set(&sd->metadata, "name", profile_name, 0);
893  memcpy(sd->data, data, bp.len);
894  av_free(data);
895 
896  /* ICC compressed data and CRC */
897  bytestream2_skip(&s->gb, length + 4);
898 
899  return 0;
900 }
901 
903 {
904  if (s->bits_per_pixel == 1 && s->color_type == PNG_COLOR_TYPE_PALETTE) {
905  int i, j, k;
906  uint8_t *pd = p->data[0];
907  for (j = 0; j < s->height; j++) {
908  i = s->width / 8;
909  for (k = 7; k >= 1; k--)
910  if ((s->width&7) >= k)
911  pd[8*i + k - 1] = (pd[i]>>8-k) & 1;
912  for (i--; i >= 0; i--) {
913  pd[8*i + 7]= pd[i] & 1;
914  pd[8*i + 6]= (pd[i]>>1) & 1;
915  pd[8*i + 5]= (pd[i]>>2) & 1;
916  pd[8*i + 4]= (pd[i]>>3) & 1;
917  pd[8*i + 3]= (pd[i]>>4) & 1;
918  pd[8*i + 2]= (pd[i]>>5) & 1;
919  pd[8*i + 1]= (pd[i]>>6) & 1;
920  pd[8*i + 0]= pd[i]>>7;
921  }
922  pd += s->image_linesize;
923  }
924  } else if (s->bits_per_pixel == 2) {
925  int i, j;
926  uint8_t *pd = p->data[0];
927  for (j = 0; j < s->height; j++) {
928  i = s->width / 4;
930  if ((s->width&3) >= 3) pd[4*i + 2]= (pd[i] >> 2) & 3;
931  if ((s->width&3) >= 2) pd[4*i + 1]= (pd[i] >> 4) & 3;
932  if ((s->width&3) >= 1) pd[4*i + 0]= pd[i] >> 6;
933  for (i--; i >= 0; i--) {
934  pd[4*i + 3]= pd[i] & 3;
935  pd[4*i + 2]= (pd[i]>>2) & 3;
936  pd[4*i + 1]= (pd[i]>>4) & 3;
937  pd[4*i + 0]= pd[i]>>6;
938  }
939  } else {
940  if ((s->width&3) >= 3) pd[4*i + 2]= ((pd[i]>>2) & 3)*0x55;
941  if ((s->width&3) >= 2) pd[4*i + 1]= ((pd[i]>>4) & 3)*0x55;
942  if ((s->width&3) >= 1) pd[4*i + 0]= ( pd[i]>>6 )*0x55;
943  for (i--; i >= 0; i--) {
944  pd[4*i + 3]= ( pd[i] & 3)*0x55;
945  pd[4*i + 2]= ((pd[i]>>2) & 3)*0x55;
946  pd[4*i + 1]= ((pd[i]>>4) & 3)*0x55;
947  pd[4*i + 0]= ( pd[i]>>6 )*0x55;
948  }
949  }
950  pd += s->image_linesize;
951  }
952  } else if (s->bits_per_pixel == 4) {
953  int i, j;
954  uint8_t *pd = p->data[0];
955  for (j = 0; j < s->height; j++) {
956  i = s->width/2;
958  if (s->width&1) pd[2*i+0]= pd[i]>>4;
959  for (i--; i >= 0; i--) {
960  pd[2*i + 1] = pd[i] & 15;
961  pd[2*i + 0] = pd[i] >> 4;
962  }
963  } else {
964  if (s->width & 1) pd[2*i + 0]= (pd[i] >> 4) * 0x11;
965  for (i--; i >= 0; i--) {
966  pd[2*i + 1] = (pd[i] & 15) * 0x11;
967  pd[2*i + 0] = (pd[i] >> 4) * 0x11;
968  }
969  }
970  pd += s->image_linesize;
971  }
972  }
973 }
974 
976  uint32_t length)
977 {
978  uint32_t sequence_number;
980 
981  if (length != 26)
982  return AVERROR_INVALIDDATA;
983 
984  if (!(s->hdr_state & PNG_IHDR)) {
985  av_log(avctx, AV_LOG_ERROR, "fctl before IHDR\n");
986  return AVERROR_INVALIDDATA;
987  }
988 
989  if (s->pic_state & PNG_IDAT) {
990  av_log(avctx, AV_LOG_ERROR, "fctl after IDAT\n");
991  return AVERROR_INVALIDDATA;
992  }
993 
994  s->last_w = s->cur_w;
995  s->last_h = s->cur_h;
996  s->last_x_offset = s->x_offset;
997  s->last_y_offset = s->y_offset;
998  s->last_dispose_op = s->dispose_op;
999 
1000  sequence_number = bytestream2_get_be32(&s->gb);
1001  cur_w = bytestream2_get_be32(&s->gb);
1002  cur_h = bytestream2_get_be32(&s->gb);
1003  x_offset = bytestream2_get_be32(&s->gb);
1004  y_offset = bytestream2_get_be32(&s->gb);
1005  bytestream2_skip(&s->gb, 4); /* delay_num (2), delay_den (2) */
1006  dispose_op = bytestream2_get_byte(&s->gb);
1007  blend_op = bytestream2_get_byte(&s->gb);
1008  bytestream2_skip(&s->gb, 4); /* crc */
1009 
1010  if (sequence_number == 0 &&
1011  (cur_w != s->width ||
1012  cur_h != s->height ||
1013  x_offset != 0 ||
1014  y_offset != 0) ||
1015  cur_w <= 0 || cur_h <= 0 ||
1016  x_offset < 0 || y_offset < 0 ||
1017  cur_w > s->width - x_offset|| cur_h > s->height - y_offset)
1018  return AVERROR_INVALIDDATA;
1019 
1020  if (blend_op != APNG_BLEND_OP_OVER && blend_op != APNG_BLEND_OP_SOURCE) {
1021  av_log(avctx, AV_LOG_ERROR, "Invalid blend_op %d\n", blend_op);
1022  return AVERROR_INVALIDDATA;
1023  }
1024 
1025  if ((sequence_number == 0 || !s->previous_picture.f->data[0]) &&
1026  dispose_op == APNG_DISPOSE_OP_PREVIOUS) {
1027  // No previous frame to revert to for the first frame
1028  // Spec says to just treat it as a APNG_DISPOSE_OP_BACKGROUND
1029  dispose_op = APNG_DISPOSE_OP_BACKGROUND;
1030  }
1031 
1032  if (blend_op == APNG_BLEND_OP_OVER && !s->has_trns && (
1033  avctx->pix_fmt == AV_PIX_FMT_RGB24 ||
1034  avctx->pix_fmt == AV_PIX_FMT_RGB48BE ||
1035  avctx->pix_fmt == AV_PIX_FMT_PAL8 ||
1036  avctx->pix_fmt == AV_PIX_FMT_GRAY8 ||
1037  avctx->pix_fmt == AV_PIX_FMT_GRAY16BE ||
1038  avctx->pix_fmt == AV_PIX_FMT_MONOBLACK
1039  )) {
1040  // APNG_BLEND_OP_OVER is the same as APNG_BLEND_OP_SOURCE when there is no alpha channel
1041  blend_op = APNG_BLEND_OP_SOURCE;
1042  }
1043 
1044  s->cur_w = cur_w;
1045  s->cur_h = cur_h;
1046  s->x_offset = x_offset;
1047  s->y_offset = y_offset;
1048  s->dispose_op = dispose_op;
1049  s->blend_op = blend_op;
1050 
1051  return 0;
1052 }
1053 
1055 {
1056  int i, j;
1057  uint8_t *pd = p->data[0];
1058  uint8_t *pd_last = s->last_picture.f->data[0];
1059  int ls = FFMIN(av_image_get_linesize(p->format, s->width, 0), s->width * s->bpp);
1060 
1061  ff_thread_await_progress(&s->last_picture, INT_MAX, 0);
1062  for (j = 0; j < s->height; j++) {
1063  for (i = 0; i < ls; i++)
1064  pd[i] += pd_last[i];
1065  pd += s->image_linesize;
1066  pd_last += s->image_linesize;
1067  }
1068 }
1069 
1070 // divide by 255 and round to nearest
1071 // apply a fast variant: (X+127)/255 = ((X+127)*257+257)>>16 = ((X+128)*257)>>16
1072 #define FAST_DIV255(x) ((((x) + 128) * 257) >> 16)
1073 
1075  AVFrame *p)
1076 {
1077  size_t x, y;
1078  uint8_t *buffer;
1079 
1080  if (s->blend_op == APNG_BLEND_OP_OVER &&
1081  avctx->pix_fmt != AV_PIX_FMT_RGBA &&
1082  avctx->pix_fmt != AV_PIX_FMT_GRAY8A &&
1083  avctx->pix_fmt != AV_PIX_FMT_PAL8) {
1084  avpriv_request_sample(avctx, "Blending with pixel format %s",
1085  av_get_pix_fmt_name(avctx->pix_fmt));
1086  return AVERROR_PATCHWELCOME;
1087  }
1088 
1089  buffer = av_malloc_array(s->image_linesize, s->height);
1090  if (!buffer)
1091  return AVERROR(ENOMEM);
1092 
1093 
1094  // Do the disposal operation specified by the last frame on the frame
1096  ff_thread_await_progress(&s->last_picture, INT_MAX, 0);
1097  memcpy(buffer, s->last_picture.f->data[0], s->image_linesize * s->height);
1098 
1100  for (y = s->last_y_offset; y < s->last_y_offset + s->last_h; ++y)
1101  memset(buffer + s->image_linesize * y + s->bpp * s->last_x_offset, 0, s->bpp * s->last_w);
1102 
1103  memcpy(s->previous_picture.f->data[0], buffer, s->image_linesize * s->height);
1105  } else {
1106  ff_thread_await_progress(&s->previous_picture, INT_MAX, 0);
1107  memcpy(buffer, s->previous_picture.f->data[0], s->image_linesize * s->height);
1108  }
1109 
1110  // Perform blending
1111  if (s->blend_op == APNG_BLEND_OP_SOURCE) {
1112  for (y = s->y_offset; y < s->y_offset + s->cur_h; ++y) {
1113  size_t row_start = s->image_linesize * y + s->bpp * s->x_offset;
1114  memcpy(buffer + row_start, p->data[0] + row_start, s->bpp * s->cur_w);
1115  }
1116  } else { // APNG_BLEND_OP_OVER
1117  for (y = s->y_offset; y < s->y_offset + s->cur_h; ++y) {
1118  uint8_t *foreground = p->data[0] + s->image_linesize * y + s->bpp * s->x_offset;
1119  uint8_t *background = buffer + s->image_linesize * y + s->bpp * s->x_offset;
1120  for (x = s->x_offset; x < s->x_offset + s->cur_w; ++x, foreground += s->bpp, background += s->bpp) {
1121  size_t b;
1122  uint8_t foreground_alpha, background_alpha, output_alpha;
1123  uint8_t output[10];
1124 
1125  // Since we might be blending alpha onto alpha, we use the following equations:
1126  // output_alpha = foreground_alpha + (1 - foreground_alpha) * background_alpha
1127  // output = (foreground_alpha * foreground + (1 - foreground_alpha) * background_alpha * background) / output_alpha
1128 
1129  switch (avctx->pix_fmt) {
1130  case AV_PIX_FMT_RGBA:
1131  foreground_alpha = foreground[3];
1132  background_alpha = background[3];
1133  break;
1134 
1135  case AV_PIX_FMT_GRAY8A:
1136  foreground_alpha = foreground[1];
1137  background_alpha = background[1];
1138  break;
1139 
1140  case AV_PIX_FMT_PAL8:
1141  foreground_alpha = s->palette[foreground[0]] >> 24;
1142  background_alpha = s->palette[background[0]] >> 24;
1143  break;
1144  }
1145 
1146  if (foreground_alpha == 0)
1147  continue;
1148 
1149  if (foreground_alpha == 255) {
1150  memcpy(background, foreground, s->bpp);
1151  continue;
1152  }
1153 
1154  if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
1155  // TODO: Alpha blending with PAL8 will likely need the entire image converted over to RGBA first
1156  avpriv_request_sample(avctx, "Alpha blending palette samples");
1157  background[0] = foreground[0];
1158  continue;
1159  }
1160 
1161  output_alpha = foreground_alpha + FAST_DIV255((255 - foreground_alpha) * background_alpha);
1162 
1163  av_assert0(s->bpp <= 10);
1164 
1165  for (b = 0; b < s->bpp - 1; ++b) {
1166  if (output_alpha == 0) {
1167  output[b] = 0;
1168  } else if (background_alpha == 255) {
1169  output[b] = FAST_DIV255(foreground_alpha * foreground[b] + (255 - foreground_alpha) * background[b]);
1170  } else {
1171  output[b] = (255 * foreground_alpha * foreground[b] + (255 - foreground_alpha) * background_alpha * background[b]) / (255 * output_alpha);
1172  }
1173  }
1174  output[b] = output_alpha;
1175  memcpy(background, output, s->bpp);
1176  }
1177  }
1178  }
1179 
1180  // Copy blended buffer into the frame and free
1181  memcpy(p->data[0], buffer, s->image_linesize * s->height);
1182  av_free(buffer);
1183 
1184  return 0;
1185 }
1186 
1188  AVFrame *p, AVPacket *avpkt)
1189 {
1190  const AVCRC *crc_tab = av_crc_get_table(AV_CRC_32_IEEE_LE);
1191  AVDictionary **metadatap = NULL;
1192  uint32_t tag, length;
1193  int decode_next_dat = 0;
1194  int i, ret;
1195 
1196  for (;;) {
1197  length = bytestream2_get_bytes_left(&s->gb);
1198  if (length <= 0) {
1199 
1200  if (avctx->codec_id == AV_CODEC_ID_PNG &&
1201  avctx->skip_frame == AVDISCARD_ALL) {
1202  return 0;
1203  }
1204 
1205  if (CONFIG_APNG_DECODER && avctx->codec_id == AV_CODEC_ID_APNG && length == 0) {
1206  if (!(s->pic_state & PNG_IDAT))
1207  return 0;
1208  else
1209  goto exit_loop;
1210  }
1211  av_log(avctx, AV_LOG_ERROR, "%d bytes left\n", length);
1212  if ( s->pic_state & PNG_ALLIMAGE
1214  goto exit_loop;
1215  ret = AVERROR_INVALIDDATA;
1216  goto fail;
1217  }
1218 
1219  length = bytestream2_get_be32(&s->gb);
1220  if (length > 0x7fffffff || length > bytestream2_get_bytes_left(&s->gb)) {
1221  av_log(avctx, AV_LOG_ERROR, "chunk too big\n");
1222  ret = AVERROR_INVALIDDATA;
1223  goto fail;
1224  }
1225  if (avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_IGNORE_ERR)) {
1226  uint32_t crc_sig = AV_RB32(s->gb.buffer + length + 4);
1227  uint32_t crc_cal = ~av_crc(crc_tab, UINT32_MAX, s->gb.buffer, length + 4);
1228  if (crc_sig ^ crc_cal) {
1229  av_log(avctx, AV_LOG_ERROR, "CRC mismatch in chunk");
1230  if (avctx->err_recognition & AV_EF_EXPLODE) {
1231  av_log(avctx, AV_LOG_ERROR, ", quitting\n");
1232  ret = AVERROR_INVALIDDATA;
1233  goto fail;
1234  }
1235  av_log(avctx, AV_LOG_ERROR, ", skipping\n");
1236  bytestream2_skip(&s->gb, 4); /* tag */
1237  goto skip_tag;
1238  }
1239  }
1240  tag = bytestream2_get_le32(&s->gb);
1241  if (avctx->debug & FF_DEBUG_STARTCODE)
1242  av_log(avctx, AV_LOG_DEBUG, "png: tag=%s length=%u\n",
1243  av_fourcc2str(tag), length);
1244 
1245  if (avctx->codec_id == AV_CODEC_ID_PNG &&
1246  avctx->skip_frame == AVDISCARD_ALL) {
1247  switch(tag) {
1248  case MKTAG('I', 'H', 'D', 'R'):
1249  case MKTAG('p', 'H', 'Y', 's'):
1250  case MKTAG('t', 'E', 'X', 't'):
1251  case MKTAG('I', 'D', 'A', 'T'):
1252  case MKTAG('t', 'R', 'N', 'S'):
1253  break;
1254  default:
1255  goto skip_tag;
1256  }
1257  }
1258 
1259  metadatap = &p->metadata;
1260  switch (tag) {
1261  case MKTAG('I', 'H', 'D', 'R'):
1262  if ((ret = decode_ihdr_chunk(avctx, s, length)) < 0)
1263  goto fail;
1264  break;
1265  case MKTAG('p', 'H', 'Y', 's'):
1266  if ((ret = decode_phys_chunk(avctx, s)) < 0)
1267  goto fail;
1268  break;
1269  case MKTAG('f', 'c', 'T', 'L'):
1270  if (!CONFIG_APNG_DECODER || avctx->codec_id != AV_CODEC_ID_APNG)
1271  goto skip_tag;
1272  if ((ret = decode_fctl_chunk(avctx, s, length)) < 0)
1273  goto fail;
1274  decode_next_dat = 1;
1275  break;
1276  case MKTAG('f', 'd', 'A', 'T'):
1277  if (!CONFIG_APNG_DECODER || avctx->codec_id != AV_CODEC_ID_APNG)
1278  goto skip_tag;
1279  if (!decode_next_dat || length < 4) {
1280  ret = AVERROR_INVALIDDATA;
1281  goto fail;
1282  }
1283  bytestream2_get_be32(&s->gb);
1284  length -= 4;
1285  /* fallthrough */
1286  case MKTAG('I', 'D', 'A', 'T'):
1287  if (CONFIG_APNG_DECODER && avctx->codec_id == AV_CODEC_ID_APNG && !decode_next_dat)
1288  goto skip_tag;
1289  if ((ret = decode_idat_chunk(avctx, s, length, p)) < 0)
1290  goto fail;
1291  break;
1292  case MKTAG('P', 'L', 'T', 'E'):
1293  if (decode_plte_chunk(avctx, s, length) < 0)
1294  goto skip_tag;
1295  break;
1296  case MKTAG('t', 'R', 'N', 'S'):
1297  if (decode_trns_chunk(avctx, s, length) < 0)
1298  goto skip_tag;
1299  break;
1300  case MKTAG('t', 'E', 'X', 't'):
1301  if (decode_text_chunk(s, length, 0, metadatap) < 0)
1302  av_log(avctx, AV_LOG_WARNING, "Broken tEXt chunk\n");
1303  bytestream2_skip(&s->gb, length + 4);
1304  break;
1305  case MKTAG('z', 'T', 'X', 't'):
1306  if (decode_text_chunk(s, length, 1, metadatap) < 0)
1307  av_log(avctx, AV_LOG_WARNING, "Broken zTXt chunk\n");
1308  bytestream2_skip(&s->gb, length + 4);
1309  break;
1310  case MKTAG('s', 'T', 'E', 'R'): {
1311  int mode = bytestream2_get_byte(&s->gb);
1313  if (!stereo3d) {
1314  ret = AVERROR(ENOMEM);
1315  goto fail;
1316  }
1317 
1318  if (mode == 0 || mode == 1) {
1319  stereo3d->type = AV_STEREO3D_SIDEBYSIDE;
1320  stereo3d->flags = mode ? 0 : AV_STEREO3D_FLAG_INVERT;
1321  } else {
1322  av_log(avctx, AV_LOG_WARNING,
1323  "Unknown value in sTER chunk (%d)\n", mode);
1324  }
1325  bytestream2_skip(&s->gb, 4); /* crc */
1326  break;
1327  }
1328  case MKTAG('i', 'C', 'C', 'P'): {
1329  if ((ret = decode_iccp_chunk(s, length, p)) < 0)
1330  goto fail;
1331  break;
1332  }
1333  case MKTAG('c', 'H', 'R', 'M'): {
1335  if (!mdm) {
1336  ret = AVERROR(ENOMEM);
1337  goto fail;
1338  }
1339 
1340  mdm->white_point[0] = av_make_q(bytestream2_get_be32(&s->gb), 100000);
1341  mdm->white_point[1] = av_make_q(bytestream2_get_be32(&s->gb), 100000);
1342 
1343  /* RGB Primaries */
1344  for (i = 0; i < 3; i++) {
1345  mdm->display_primaries[i][0] = av_make_q(bytestream2_get_be32(&s->gb), 100000);
1346  mdm->display_primaries[i][1] = av_make_q(bytestream2_get_be32(&s->gb), 100000);
1347  }
1348 
1349  mdm->has_primaries = 1;
1350  bytestream2_skip(&s->gb, 4); /* crc */
1351  break;
1352  }
1353  case MKTAG('g', 'A', 'M', 'A'): {
1354  AVBPrint bp;
1355  char *gamma_str;
1356  int num = bytestream2_get_be32(&s->gb);
1357 
1359  av_bprintf(&bp, "%i/%i", num, 100000);
1360  ret = av_bprint_finalize(&bp, &gamma_str);
1361  if (ret < 0)
1362  return ret;
1363 
1364  av_dict_set(&p->metadata, "gamma", gamma_str, AV_DICT_DONT_STRDUP_VAL);
1365 
1366  bytestream2_skip(&s->gb, 4); /* crc */
1367  break;
1368  }
1369  case MKTAG('I', 'E', 'N', 'D'):
1370  if (!(s->pic_state & PNG_ALLIMAGE))
1371  av_log(avctx, AV_LOG_ERROR, "IEND without all image\n");
1372  if (!(s->pic_state & (PNG_ALLIMAGE|PNG_IDAT))) {
1373  ret = AVERROR_INVALIDDATA;
1374  goto fail;
1375  }
1376  bytestream2_skip(&s->gb, 4); /* crc */
1377  goto exit_loop;
1378  default:
1379  /* skip tag */
1380 skip_tag:
1381  bytestream2_skip(&s->gb, length + 4);
1382  break;
1383  }
1384  }
1385 exit_loop:
1386 
1387  if (!p)
1388  return AVERROR_INVALIDDATA;
1389 
1390  if (avctx->codec_id == AV_CODEC_ID_PNG &&
1391  avctx->skip_frame == AVDISCARD_ALL) {
1392  return 0;
1393  }
1394 
1396  return AVERROR_INVALIDDATA;
1397 
1398  if (s->bits_per_pixel <= 4)
1399  handle_small_bpp(s, p);
1400 
1401  /* apply transparency if needed */
1402  if (s->has_trns && s->color_type != PNG_COLOR_TYPE_PALETTE) {
1403  size_t byte_depth = s->bit_depth > 8 ? 2 : 1;
1404  size_t raw_bpp = s->bpp - byte_depth;
1405  unsigned x, y;
1406 
1407  av_assert0(s->bit_depth > 1);
1408 
1409  for (y = 0; y < s->height; ++y) {
1410  uint8_t *row = &s->image_buf[s->image_linesize * y];
1411 
1412  if (s->bpp == 2 && byte_depth == 1) {
1413  uint8_t *pixel = &row[2 * s->width - 1];
1414  uint8_t *rowp = &row[1 * s->width - 1];
1415  int tcolor = s->transparent_color_be[0];
1416  for (x = s->width; x > 0; --x) {
1417  *pixel-- = *rowp == tcolor ? 0 : 0xff;
1418  *pixel-- = *rowp--;
1419  }
1420  } else if (s->bpp == 4 && byte_depth == 1) {
1421  uint8_t *pixel = &row[4 * s->width - 1];
1422  uint8_t *rowp = &row[3 * s->width - 1];
1423  int tcolor = AV_RL24(s->transparent_color_be);
1424  for (x = s->width; x > 0; --x) {
1425  *pixel-- = AV_RL24(rowp-2) == tcolor ? 0 : 0xff;
1426  *pixel-- = *rowp--;
1427  *pixel-- = *rowp--;
1428  *pixel-- = *rowp--;
1429  }
1430  } else {
1431  /* since we're updating in-place, we have to go from right to left */
1432  for (x = s->width; x > 0; --x) {
1433  uint8_t *pixel = &row[s->bpp * (x - 1)];
1434  memmove(pixel, &row[raw_bpp * (x - 1)], raw_bpp);
1435 
1436  if (!memcmp(pixel, s->transparent_color_be, raw_bpp)) {
1437  memset(&pixel[raw_bpp], 0, byte_depth);
1438  } else {
1439  memset(&pixel[raw_bpp], 0xff, byte_depth);
1440  }
1441  }
1442  }
1443  }
1444  }
1445 
1446  /* handle P-frames only if a predecessor frame is available */
1447  if (s->last_picture.f->data[0]) {
1448  if ( !(avpkt->flags & AV_PKT_FLAG_KEY) && avctx->codec_tag != AV_RL32("MPNG")
1449  && s->last_picture.f->width == p->width
1450  && s->last_picture.f->height== p->height
1451  && s->last_picture.f->format== p->format
1452  ) {
1453  if (CONFIG_PNG_DECODER && avctx->codec_id != AV_CODEC_ID_APNG)
1454  handle_p_frame_png(s, p);
1455  else if (CONFIG_APNG_DECODER &&
1456  s->previous_picture.f->width == p->width &&
1457  s->previous_picture.f->height== p->height &&
1458  s->previous_picture.f->format== p->format &&
1459  avctx->codec_id == AV_CODEC_ID_APNG &&
1460  (ret = handle_p_frame_apng(avctx, s, p)) < 0)
1461  goto fail;
1462  }
1463  }
1464  ff_thread_report_progress(&s->picture, INT_MAX, 0);
1466 
1467  return 0;
1468 
1469 fail:
1470  ff_thread_report_progress(&s->picture, INT_MAX, 0);
1472  return ret;
1473 }
1474 
1475 #if CONFIG_PNG_DECODER
1476 static int decode_frame_png(AVCodecContext *avctx,
1477  void *data, int *got_frame,
1478  AVPacket *avpkt)
1479 {
1480  PNGDecContext *const s = avctx->priv_data;
1481  const uint8_t *buf = avpkt->data;
1482  int buf_size = avpkt->size;
1483  AVFrame *p;
1484  int64_t sig;
1485  int ret;
1486 
1489  p = s->picture.f;
1490 
1491  bytestream2_init(&s->gb, buf, buf_size);
1492 
1493  /* check signature */
1494  sig = bytestream2_get_be64(&s->gb);
1495  if (sig != PNGSIG &&
1496  sig != MNGSIG) {
1497  av_log(avctx, AV_LOG_ERROR, "Invalid PNG signature 0x%08"PRIX64".\n", sig);
1498  return AVERROR_INVALIDDATA;
1499  }
1500 
1501  s->y = s->has_trns = 0;
1502  s->hdr_state = 0;
1503  s->pic_state = 0;
1504 
1505  /* init the zlib */
1506  s->zstream.zalloc = ff_png_zalloc;
1507  s->zstream.zfree = ff_png_zfree;
1508  s->zstream.opaque = NULL;
1509  ret = inflateInit(&s->zstream);
1510  if (ret != Z_OK) {
1511  av_log(avctx, AV_LOG_ERROR, "inflateInit returned error %d\n", ret);
1512  return AVERROR_EXTERNAL;
1513  }
1514 
1515  if ((ret = decode_frame_common(avctx, s, p, avpkt)) < 0)
1516  goto the_end;
1517 
1518  if (avctx->skip_frame == AVDISCARD_ALL) {
1519  *got_frame = 0;
1520  ret = bytestream2_tell(&s->gb);
1521  goto the_end;
1522  }
1523 
1524  if ((ret = av_frame_ref(data, s->picture.f)) < 0)
1525  goto the_end;
1526 
1527  *got_frame = 1;
1528 
1529  ret = bytestream2_tell(&s->gb);
1530 the_end:
1531  inflateEnd(&s->zstream);
1532  s->crow_buf = NULL;
1533  return ret;
1534 }
1535 #endif
1536 
1537 #if CONFIG_APNG_DECODER
1538 static int decode_frame_apng(AVCodecContext *avctx,
1539  void *data, int *got_frame,
1540  AVPacket *avpkt)
1541 {
1542  PNGDecContext *const s = avctx->priv_data;
1543  int ret;
1544  AVFrame *p;
1545 
1548  p = s->picture.f;
1549 
1550  if (!(s->hdr_state & PNG_IHDR)) {
1551  if (!avctx->extradata_size)
1552  return AVERROR_INVALIDDATA;
1553 
1554  /* only init fields, there is no zlib use in extradata */
1555  s->zstream.zalloc = ff_png_zalloc;
1556  s->zstream.zfree = ff_png_zfree;
1557 
1558  bytestream2_init(&s->gb, avctx->extradata, avctx->extradata_size);
1559  if ((ret = decode_frame_common(avctx, s, NULL, avpkt)) < 0)
1560  goto end;
1561  }
1562 
1563  /* reset state for a new frame */
1564  if ((ret = inflateInit(&s->zstream)) != Z_OK) {
1565  av_log(avctx, AV_LOG_ERROR, "inflateInit returned error %d\n", ret);
1566  ret = AVERROR_EXTERNAL;
1567  goto end;
1568  }
1569  s->y = 0;
1570  s->pic_state = 0;
1571  bytestream2_init(&s->gb, avpkt->data, avpkt->size);
1572  if ((ret = decode_frame_common(avctx, s, p, avpkt)) < 0)
1573  goto end;
1574 
1575  if (!(s->pic_state & PNG_ALLIMAGE))
1576  av_log(avctx, AV_LOG_WARNING, "Frame did not contain a complete image\n");
1577  if (!(s->pic_state & (PNG_ALLIMAGE|PNG_IDAT))) {
1578  ret = AVERROR_INVALIDDATA;
1579  goto end;
1580  }
1581  if ((ret = av_frame_ref(data, s->picture.f)) < 0)
1582  goto end;
1583 
1584  *got_frame = 1;
1585  ret = bytestream2_tell(&s->gb);
1586 
1587 end:
1588  inflateEnd(&s->zstream);
1589  return ret;
1590 }
1591 #endif
1592 
1593 #if CONFIG_LSCR_DECODER
1594 static int decode_frame_lscr(AVCodecContext *avctx,
1595  void *data, int *got_frame,
1596  AVPacket *avpkt)
1597 {
1598  PNGDecContext *const s = avctx->priv_data;
1599  GetByteContext *gb = &s->gb;
1600  AVFrame *frame = data;
1601  int ret, nb_blocks, offset = 0;
1602 
1603  if (avpkt->size < 2)
1604  return AVERROR_INVALIDDATA;
1605 
1606  bytestream2_init(gb, avpkt->data, avpkt->size);
1607 
1608  if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0)
1609  return ret;
1610 
1611  nb_blocks = bytestream2_get_le16(gb);
1612  if (bytestream2_get_bytes_left(gb) < 2 + nb_blocks * (12 + 8))
1613  return AVERROR_INVALIDDATA;
1614 
1615  if (s->last_picture.f->data[0]) {
1616  ret = av_frame_copy(frame, s->last_picture.f);
1617  if (ret < 0)
1618  return ret;
1619  }
1620 
1621  for (int b = 0; b < nb_blocks; b++) {
1622  int x, y, x2, y2, w, h, left;
1623  uint32_t csize, size;
1624 
1625  s->zstream.zalloc = ff_png_zalloc;
1626  s->zstream.zfree = ff_png_zfree;
1627  s->zstream.opaque = NULL;
1628 
1629  if ((ret = inflateInit(&s->zstream)) != Z_OK) {
1630  av_log(avctx, AV_LOG_ERROR, "inflateInit returned error %d\n", ret);
1631  ret = AVERROR_EXTERNAL;
1632  goto end;
1633  }
1634 
1635  bytestream2_seek(gb, 2 + b * 12, SEEK_SET);
1636 
1637  x = bytestream2_get_le16(gb);
1638  y = bytestream2_get_le16(gb);
1639  x2 = bytestream2_get_le16(gb);
1640  y2 = bytestream2_get_le16(gb);
1641  s->width = s->cur_w = w = x2-x;
1642  s->height = s->cur_h = h = y2-y;
1643 
1644  if (w <= 0 || x < 0 || x >= avctx->width || w + x > avctx->width ||
1645  h <= 0 || y < 0 || y >= avctx->height || h + y > avctx->height) {
1646  ret = AVERROR_INVALIDDATA;
1647  goto end;
1648  }
1649 
1650  size = bytestream2_get_le32(gb);
1651 
1652  frame->key_frame = (nb_blocks == 1) &&
1653  (w == avctx->width) &&
1654  (h == avctx->height) &&
1655  (x == 0) && (y == 0);
1656 
1657  bytestream2_seek(gb, 2 + nb_blocks * 12 + offset, SEEK_SET);
1658  csize = bytestream2_get_be32(gb);
1659  if (bytestream2_get_le32(gb) != MKTAG('I', 'D', 'A', 'T')) {
1660  ret = AVERROR_INVALIDDATA;
1661  goto end;
1662  }
1663 
1664  offset += size;
1665  left = size;
1666 
1667  s->y = 0;
1668  s->row_size = w * 3;
1669 
1670  av_fast_padded_malloc(&s->buffer, &s->buffer_size, s->row_size + 16);
1671  if (!s->buffer) {
1672  ret = AVERROR(ENOMEM);
1673  goto end;
1674  }
1675 
1677  if (!s->last_row) {
1678  ret = AVERROR(ENOMEM);
1679  goto end;
1680  }
1681 
1682  s->crow_size = w * 3 + 1;
1683  s->crow_buf = s->buffer + 15;
1684  s->zstream.avail_out = s->crow_size;
1685  s->zstream.next_out = s->crow_buf;
1686  s->image_buf = frame->data[0] + (avctx->height - y - 1) * frame->linesize[0] + x * 3;
1687  s->image_linesize =-frame->linesize[0];
1688  s->bpp = 3;
1689  s->pic_state = 0;
1690 
1691  while (left > 16) {
1692  ret = png_decode_idat(s, csize);
1693  if (ret < 0)
1694  goto end;
1695  left -= csize + 16;
1696  if (left > 16) {
1697  bytestream2_skip(gb, 4);
1698  csize = bytestream2_get_be32(gb);
1699  if (bytestream2_get_le32(gb) != MKTAG('I', 'D', 'A', 'T')) {
1700  ret = AVERROR_INVALIDDATA;
1701  goto end;
1702  }
1703  }
1704  }
1705 
1706  inflateEnd(&s->zstream);
1707  }
1708 
1710 
1712  if ((ret = av_frame_ref(s->last_picture.f, frame)) < 0)
1713  return ret;
1714 
1715  *got_frame = 1;
1716 end:
1717  inflateEnd(&s->zstream);
1718 
1719  if (ret < 0)
1720  return ret;
1721  return avpkt->size;
1722 }
1723 
1724 static void decode_flush(AVCodecContext *avctx)
1725 {
1726  PNGDecContext *s = avctx->priv_data;
1727 
1729 }
1730 
1731 #endif
1732 
1733 #if HAVE_THREADS
1734 static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
1735 {
1736  PNGDecContext *psrc = src->priv_data;
1737  PNGDecContext *pdst = dst->priv_data;
1738  int ret;
1739 
1740  if (dst == src)
1741  return 0;
1742 
1743  ff_thread_release_buffer(dst, &pdst->picture);
1744  if (psrc->picture.f->data[0] &&
1745  (ret = ff_thread_ref_frame(&pdst->picture, &psrc->picture)) < 0)
1746  return ret;
1748  pdst->width = psrc->width;
1749  pdst->height = psrc->height;
1750  pdst->bit_depth = psrc->bit_depth;
1751  pdst->color_type = psrc->color_type;
1752  pdst->compression_type = psrc->compression_type;
1753  pdst->interlace_type = psrc->interlace_type;
1754  pdst->filter_type = psrc->filter_type;
1755  pdst->cur_w = psrc->cur_w;
1756  pdst->cur_h = psrc->cur_h;
1757  pdst->x_offset = psrc->x_offset;
1758  pdst->y_offset = psrc->y_offset;
1759  pdst->has_trns = psrc->has_trns;
1760  memcpy(pdst->transparent_color_be, psrc->transparent_color_be, sizeof(pdst->transparent_color_be));
1761 
1762  pdst->dispose_op = psrc->dispose_op;
1763 
1764  memcpy(pdst->palette, psrc->palette, sizeof(pdst->palette));
1765 
1766  pdst->hdr_state |= psrc->hdr_state;
1767 
1769  if (psrc->last_picture.f->data[0] &&
1770  (ret = ff_thread_ref_frame(&pdst->last_picture, &psrc->last_picture)) < 0)
1771  return ret;
1772 
1774  if (psrc->previous_picture.f->data[0] &&
1775  (ret = ff_thread_ref_frame(&pdst->previous_picture, &psrc->previous_picture)) < 0)
1776  return ret;
1777  }
1778 
1779  return 0;
1780 }
1781 #endif
1782 
1784 {
1785  PNGDecContext *s = avctx->priv_data;
1786 
1787  avctx->color_range = AVCOL_RANGE_JPEG;
1788 
1789  if (avctx->codec_id == AV_CODEC_ID_LSCR)
1790  avctx->pix_fmt = AV_PIX_FMT_BGR24;
1791 
1792  s->avctx = avctx;
1794  s->last_picture.f = av_frame_alloc();
1795  s->picture.f = av_frame_alloc();
1796  if (!s->previous_picture.f || !s->last_picture.f || !s->picture.f) {
1799  av_frame_free(&s->picture.f);
1800  return AVERROR(ENOMEM);
1801  }
1802 
1803  ff_pngdsp_init(&s->dsp);
1804 
1805  return 0;
1806 }
1807 
1809 {
1810  PNGDecContext *s = avctx->priv_data;
1811 
1816  ff_thread_release_buffer(avctx, &s->picture);
1817  av_frame_free(&s->picture.f);
1818  av_freep(&s->buffer);
1819  s->buffer_size = 0;
1820  av_freep(&s->last_row);
1821  s->last_row_size = 0;
1822  av_freep(&s->tmp_row);
1823  s->tmp_row_size = 0;
1824 
1825  return 0;
1826 }
1827 
1828 #if CONFIG_APNG_DECODER
1830  .name = "apng",
1831  .long_name = NULL_IF_CONFIG_SMALL("APNG (Animated Portable Network Graphics) image"),
1832  .type = AVMEDIA_TYPE_VIDEO,
1833  .id = AV_CODEC_ID_APNG,
1834  .priv_data_size = sizeof(PNGDecContext),
1835  .init = png_dec_init,
1836  .close = png_dec_end,
1837  .decode = decode_frame_apng,
1838  .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
1839  .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS /*| AV_CODEC_CAP_DRAW_HORIZ_BAND*/,
1840  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
1842 };
1843 #endif
1844 
1845 #if CONFIG_PNG_DECODER
1847  .name = "png",
1848  .long_name = NULL_IF_CONFIG_SMALL("PNG (Portable Network Graphics) image"),
1849  .type = AVMEDIA_TYPE_VIDEO,
1850  .id = AV_CODEC_ID_PNG,
1851  .priv_data_size = sizeof(PNGDecContext),
1852  .init = png_dec_init,
1853  .close = png_dec_end,
1854  .decode = decode_frame_png,
1855  .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
1856  .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS /*| AV_CODEC_CAP_DRAW_HORIZ_BAND*/,
1859 };
1860 #endif
1861 
1862 #if CONFIG_LSCR_DECODER
1864  .name = "lscr",
1865  .long_name = NULL_IF_CONFIG_SMALL("LEAD Screen Capture"),
1866  .type = AVMEDIA_TYPE_VIDEO,
1867  .id = AV_CODEC_ID_LSCR,
1868  .priv_data_size = sizeof(PNGDecContext),
1869  .init = png_dec_init,
1870  .close = png_dec_end,
1871  .decode = decode_frame_lscr,
1872  .flush = decode_flush,
1873  .capabilities = AV_CODEC_CAP_DR1 /*| AV_CODEC_CAP_DRAW_HORIZ_BAND*/,
1876 };
1877 #endif
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
Definition: stereo3d.h:167
static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, uint32_t length, AVFrame *p)
Definition: pngdec.c:629
static int decode_fctl_chunk(AVCodecContext *avctx, PNGDecContext *s, uint32_t length)
Definition: pngdec.c:975
#define PNG_FILTER_VALUE_AVG
Definition: png.h:41
static void png_handle_row(PNGDecContext *s)
Definition: pngdec.c:334
ThreadFrame previous_picture
Definition: pngdec.c:57
#define NULL
Definition: coverity.c:32
int last_y_offset
Definition: pngdec.c:67
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
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:94
int size
This structure describes decoded (raw) audio or video data.
Definition: frame.h:300
int width
Definition: pngdec.c:63
static void flush(AVCodecContext *avctx)
unsigned int tmp_row_size
Definition: pngdec.c:88
8 bits gray, 8 bits alpha
Definition: pixfmt.h:143
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
AVFrame * f
Definition: thread.h:35
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
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:104
const char * g
Definition: vf_curves.c:115
int pass_row_size
Definition: pngdec.c:94
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
AVDictionary * metadata
Definition: frame.h:210
uint8_t * tmp_row
Definition: pngdec.c:87
#define avpriv_request_sample(...)
PNGHeaderState
Definition: pngdec.c:42
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:1161
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
int num
Numerator.
Definition: rational.h:59
static int decode_text_chunk(PNGDecContext *s, uint32_t length, int compressed, AVDictionary **dict)
Definition: pngdec.c:513
int size
Definition: packet.h:356
const char * b
Definition: vf_curves.c:116
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:905
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:736
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:133
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:70
enum PNGImageState pic_state
Definition: pngdec.c:62
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
discard all
Definition: avcodec.h:236
Views are next to each other.
Definition: stereo3d.h:67
#define PNG_COLOR_TYPE_RGB
Definition: png.h:33
static void error(const char *err)
void(* add_bytes_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
Definition: pngdsp.h:28
void ff_thread_await_progress(ThreadFrame *f, int n, int field)
Wait for earlier decoding threads to finish reference pictures.
#define PNG_COLOR_TYPE_GRAY_ALPHA
Definition: png.h:35
AVCodec.
Definition: codec.h:190
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
#define PNG_COLOR_TYPE_PALETTE
Definition: png.h:32
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
int filter_type
Definition: pngdec.c:74
void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
Definition: pngdec.c:187
#define AV_DICT_DONT_STRDUP_KEY
Take ownership of a key that&#39;s been allocated with av_malloc() or another memory allocation function...
Definition: dict.h:73
#define PNG_FILTER_VALUE_PAETH
Definition: png.h:42
enum AVDiscard skip_frame
Skip decoding for selected frames.
Definition: avcodec.h:2004
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
static int percent_missing(PNGDecContext *s)
Definition: pngdec.c:324
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:40
int y_offset
Definition: pngdec.c:66
uint8_t
#define av_cold
Definition: attributes.h:88
#define av_malloc(s)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:190
#define PNG_COLOR_TYPE_RGB_ALPHA
Definition: png.h:34
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:77
Stereo 3D type: this structure describes how two videos are packed within a single video surface...
Definition: stereo3d.h:176
#define FF_DEBUG_PICT_INFO
Definition: avcodec.h:1612
#define f(width, name)
Definition: cbs_vp9.c:255
#define AV_RB32
Definition: intreadwrite.h:130
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:92
Multithreading support functions.
AVCodec ff_apng_decoder
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:205
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:444
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:627
static AVFrame * frame
Public header for CRC hash function implementation.
static int decode_phys_chunk(AVCodecContext *avctx, PNGDecContext *s)
Definition: pngdec.c:613
const char data[16]
Definition: mxf.c:91
Structure to hold side data for an AVFrame.
Definition: frame.h:206
uint8_t * data
Definition: packet.h:355
const uint8_t * buffer
Definition: bytestream.h:34
uint32_t tag
Definition: movenc.c:1532
int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src)
Definition: utils.c:1894
#define ff_dlog(a,...)
AVDictionary * metadata
metadata.
Definition: frame.h:586
static int decode_iccp_chunk(PNGDecContext *s, int length, AVFrame *f)
Definition: pngdec.c:857
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:447
AVCodec ff_lscr_decoder
unsigned int last_row_size
Definition: pngdec.c:86
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
#define AV_WB16(p, v)
Definition: intreadwrite.h:405
int cur_h
Definition: pngdec.c:64
#define av_log(a,...)
#define FF_CODEC_CAP_ALLOCATE_PROGRESS
Definition: internal.h:75
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:388
static int decode_plte_chunk(AVCodecContext *avctx, PNGDecContext *s, uint32_t length)
Definition: pngdec.c:786
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:154
#define U(x)
Definition: vp56_arith.h:37
#define src
Definition: vp8dsp.c:254
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
int width
Definition: frame.h:358
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static const uint8_t png_pass_dsp_mask[NB_PASSES]
Definition: pngdec.c:110
int flags
Additional information about the frame packing.
Definition: stereo3d.h:185
16 bits gray, 16 bits alpha (big-endian)
Definition: pixfmt.h:212
#define AV_BPRINT_SIZE_UNLIMITED
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s, AVFrame *p, AVPacket *avpkt)
Definition: pngdec.c:1187
static const uint16_t mask[17]
Definition: lzw.c:38
#define OP_SUB(x, s, l)
#define AVERROR(e)
Definition: error.h:43
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:164
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
static void handle_p_frame_png(PNGDecContext *s, AVFrame *p)
Definition: pngdec.c:1054
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:188
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
#define CONFIG_APNG_DECODER
Definition: config.h:740
uint8_t * crow_buf
Definition: pngdec.c:84
const char * r
Definition: vf_curves.c:114
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
int pass
Definition: pngdec.c:91
int ff_png_get_nb_channels(int color_type)
Definition: png.c:49
ThreadFrame picture
Definition: pngdec.c:59
int height
Definition: pngdec.c:63
#define av_fourcc2str(fourcc)
Definition: avutil.h:348
#define PNGSIG
Definition: png.h:47
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
Definition: codec.h:197
int bits_per_pixel
Definition: pngdec.c:76
GetByteContext gb
Definition: pngdec.c:56
static const uint8_t offset[127][2]
Definition: vf_spp.c:93
#define FFMAX(a, b)
Definition: common.h:94
#define NB_PASSES
Definition: png.h:45
#define fail()
Definition: checkasm.h:123
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:106
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:800
uint8_t blend_op
Definition: pngdec.c:68
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:361
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
Definition: internal.h:227
AVStereo3D * av_stereo3d_create_side_data(AVFrame *frame)
Allocate a complete AVFrameSideData and add it to the frame.
Definition: stereo3d.c:33
z_stream zstream
Definition: pngdec.c:96
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:282
AVMasteringDisplayMetadata * av_mastering_display_metadata_create_side_data(AVFrame *frame)
Allocate a complete AVMasteringDisplayMetadata and add it to the frame.
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:383
alias for AV_PIX_FMT_YA8
Definition: pixfmt.h:146
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:1655
#define FFMIN(a, b)
Definition: common.h:96
#define PNG_FILTER_VALUE_SUB
Definition: png.h:39
uint32_t palette[256]
Definition: pngdec.c:83
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that&#39;s been allocated with av_malloc() or another memory allocation functio...
Definition: dict.h:76
#define PNG_COLOR_TYPE_GRAY
Definition: png.h:31
static void png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type, uint8_t *src, uint8_t *last, int size, int bpp)
Definition: pngdec.c:253
int width
picture width / height.
Definition: avcodec.h:699
uint8_t w
Definition: llviddspenc.c:38
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
Definition: crc.c:392
#define s(width, name)
Definition: cbs_vp9.c:257
uint8_t * last_row
Definition: pngdec.c:85
The data contains an ICC profile as an opaque octet buffer following the format described by ISO 1507...
Definition: frame.h:143
#define AV_RL32
Definition: intreadwrite.h:146
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: avcodec.h:1666
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
AVCodecContext * avctx
Definition: pngdec.c:54
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_cold void ff_pngdsp_init(PNGDSPContext *dsp)
Definition: pngdsp.c:43
static int decode_zbuf(AVBPrint *bp, const uint8_t *data, const uint8_t *data_end)
Definition: pngdec.c:445
int channels
Definition: pngdec.c:75
the normal 2^n-1 "JPEG" YUV ranges
Definition: pixfmt.h:535
static int decode_ihdr_chunk(AVCodecContext *avctx, PNGDecContext *s, uint32_t length)
Definition: pngdec.c:561
static uint8_t * iso88591_to_utf8(const uint8_t *in, size_t size_in)
Definition: pngdec.c:489
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:188
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:373
static av_cold int png_dec_init(AVCodecContext *avctx)
Definition: pngdec.c:1783
enum AVStereo3DType type
How views are packed within the video.
Definition: stereo3d.h:180
int discard_damaged_percentage
The percentage of damaged samples to discard a frame.
Definition: avcodec.h:2336
Libavcodec external API header.
enum PNGHeaderState hdr_state
Definition: pngdec.c:61
int buffer_size
Definition: pngdec.c:90
static int skip_tag(AVIOContext *in, int32_t tag_name)
Definition: ismindex.c:132
enum AVCodecID codec_id
Definition: avcodec.h:536
#define PNG_FILTER_VALUE_UP
Definition: png.h:40
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:331
#define PNG_FILTER_TYPE_LOCO
Definition: png.h:37
uint8_t last_dispose_op
Definition: pngdec.c:69
#define abs(x)
Definition: cuda_runtime.h:35
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
int debug
debug
Definition: avcodec.h:1611
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
main external API structure.
Definition: avcodec.h:526
long long int64_t
Definition: coverity.c:34
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> (&#39;D&#39;<<24) + (&#39;C&#39;<<16) + (&#39;B&#39;<<8) + &#39;A&#39;).
Definition: avcodec.h:551
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1854
uint8_t * data
Definition: frame.h:208
int interlace_type
Definition: pngdec.c:73
PNGImageState
Definition: pngdec.c:47
const uint8_t ff_png_pass_ymask[NB_PASSES]
Definition: png.c:25
int image_linesize
Definition: pngdec.c:82
int extradata_size
Definition: avcodec.h:628
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:70
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, int size)
Add a new side data to a frame.
Definition: frame.c:727
#define FF_COMPLIANCE_NORMAL
Definition: avcodec.h:1592
Y , 16bpp, big-endian.
Definition: pixfmt.h:97
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:198
Rational number (pair of numerator and denominator).
Definition: rational.h:58
Mastering display metadata capable of representing the color volume of the display used to master the...
int cur_w
Definition: pngdec.c:64
#define CONFIG_PNG_DECODER
Definition: config.h:899
uint8_t transparent_color_be[6]
Definition: pngdec.c:79
#define OP_AVG(x, s, l)
#define AV_EF_IGNORE_ERR
ignore errors and continue
Definition: avcodec.h:1668
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data...
Definition: avcodec.h:1663
uint8_t * image_buf
Definition: pngdec.c:81
uint8_t dispose_op
Definition: pngdec.c:68
AVRational display_primaries[3][2]
CIE 1931 xy chromaticity coords of color primaries (r, g, b order).
uint8_t pixel
Definition: tiny_ssim.c:42
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:554
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define AV_RL24
Definition: intreadwrite.h:78
int last_x_offset
Definition: pngdec.c:67
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:314
#define FAST_DIV255(x)
Definition: pngdec.c:1072
static int handle_p_frame_apng(AVCodecContext *avctx, PNGDecContext *s, AVFrame *p)
Definition: pngdec.c:1074
#define YUV2RGB(NAME, TYPE)
Definition: pngdec.c:310
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition: crc.c:374
static const uint8_t png_pass_mask[NB_PASSES]
Definition: pngdec.c:100
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:76
Y , 8bpp.
Definition: pixfmt.h:74
static av_cold int png_dec_end(AVCodecContext *avctx)
Definition: pngdec.c:1808
void(* add_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
Definition: pngdsp.h:33
common internal api header.
static void handle_small_bpp(PNGDecContext *s, AVFrame *p)
Definition: pngdec.c:902
if(ret< 0)
Definition: vf_mcdeint.c:279
#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: internal.h:60
#define PNG_FILTER_VALUE_NONE
Definition: png.h:38
static double c[64]
static int decode_trns_chunk(AVCodecContext *avctx, PNGDecContext *s, uint32_t length)
Definition: pngdec.c:809
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:102
int last_w
Definition: pngdec.c:65
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:82
static const uint8_t png_pass_dsp_ymask[NB_PASSES]
Definition: pngdec.c:105
Stereoscopic video.
int den
Denominator.
Definition: rational.h:60
void ff_png_zfree(void *opaque, void *ptr)
Definition: png.c:44
void * priv_data
Definition: avcodec.h:553
static int png_decode_idat(PNGDecContext *s, int length)
Definition: pngdec.c:415
uint8_t * buffer
Definition: pngdec.c:89
#define av_free(p)
#define FF_DEBUG_STARTCODE
Definition: avcodec.h:1625
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:378
int row_size
Definition: pngdec.c:93
APNG common header.
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
Definition: bytestream.h:208
PNGDSPContext dsp
Definition: pngdec.c:53
int compression_type
Definition: pngdec.c:72
int last_h
Definition: pngdec.c:65
int ff_png_pass_row_size(int pass, int bits_per_pixel, int width)
Definition: png.c:62
int height
Definition: frame.h:358
FILE * out
Definition: movenc.c:54
int bit_depth
Definition: pngdec.c:70
#define av_freep(p)
int color_type
Definition: pngdec.c:71
ThreadFrame last_picture
Definition: pngdec.c:58
#define av_malloc_array(a, b)
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:117
#define FFSWAP(type, a, b)
Definition: common.h:99
int crow_size
Definition: pngdec.c:92
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:2465
static void decode_flush(AVCodecContext *avctx)
Definition: agm.c:1261
int x_offset
Definition: pngdec.c:66
#define MKTAG(a, b, c, d)
Definition: common.h:406
void * ff_png_zalloc(void *opaque, unsigned int items, unsigned int size)
Definition: png.c:39
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:57
This structure stores compressed data.
Definition: packet.h:332
int has_trns
Definition: pngdec.c:78
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:509
mode
Use these values in ebur128_init (or&#39;ed).
Definition: ebur128.h:83
uint32_t AVCRC
Definition: crc.h:47
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:50
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:1589
AVCodec ff_png_decoder
Predicted.
Definition: avutil.h:275
#define UNROLL_FILTER(op)
Definition: pngdec.c:238
#define MNGSIG
Definition: png.h:48