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