FFmpeg  2.6.9
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
pngdec.c
Go to the documentation of this file.
1 /*
2  * PNG image format
3  * Copyright (c) 2003 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 //#define DEBUG
23 
24 #include "libavutil/bprint.h"
25 #include "libavutil/imgutils.h"
26 #include "avcodec.h"
27 #include "bytestream.h"
28 #include "internal.h"
29 #include "apng.h"
30 #include "png.h"
31 #include "pngdsp.h"
32 #include "thread.h"
33 
34 #include <zlib.h>
35 
36 typedef struct PNGDecContext {
39 
44 
45  int state;
46  int width, height;
47  int cur_w, cur_h;
50  int bit_depth;
55  int channels;
57  int bpp;
58 
59  int frame_id;
62  uint32_t palette[256];
65  unsigned int last_row_size;
67  unsigned int tmp_row_size;
70  int pass;
71  int crow_size; /* compressed row size (include filter type) */
72  int row_size; /* decompressed row size */
73  int pass_row_size; /* decompress row size of the current pass */
74  int y;
75  z_stream zstream;
77 
78 /* Mask to determine which pixels are valid in a pass */
79 static const uint8_t png_pass_mask[NB_PASSES] = {
80  0x01, 0x01, 0x11, 0x11, 0x55, 0x55, 0xff,
81 };
82 
83 /* Mask to determine which y pixels can be written in a pass */
85  0xff, 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
86 };
87 
88 /* Mask to determine which pixels to overwrite while displaying */
90  0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff
91 };
92 
93 /* NOTE: we try to construct a good looking image at each pass. width
94  * is the original image width. We also do pixel format conversion at
95  * this stage */
96 static void png_put_interlaced_row(uint8_t *dst, int width,
97  int bits_per_pixel, int pass,
98  int color_type, const uint8_t *src)
99 {
100  int x, mask, dsp_mask, j, src_x, b, bpp;
101  uint8_t *d;
102  const uint8_t *s;
103 
104  mask = png_pass_mask[pass];
105  dsp_mask = png_pass_dsp_mask[pass];
106 
107  switch (bits_per_pixel) {
108  case 1:
109  src_x = 0;
110  for (x = 0; x < width; x++) {
111  j = (x & 7);
112  if ((dsp_mask << j) & 0x80) {
113  b = (src[src_x >> 3] >> (7 - (src_x & 7))) & 1;
114  dst[x >> 3] &= 0xFF7F>>j;
115  dst[x >> 3] |= b << (7 - j);
116  }
117  if ((mask << j) & 0x80)
118  src_x++;
119  }
120  break;
121  case 2:
122  src_x = 0;
123  for (x = 0; x < width; x++) {
124  int j2 = 2 * (x & 3);
125  j = (x & 7);
126  if ((dsp_mask << j) & 0x80) {
127  b = (src[src_x >> 2] >> (6 - 2*(src_x & 3))) & 3;
128  dst[x >> 2] &= 0xFF3F>>j2;
129  dst[x >> 2] |= b << (6 - j2);
130  }
131  if ((mask << j) & 0x80)
132  src_x++;
133  }
134  break;
135  case 4:
136  src_x = 0;
137  for (x = 0; x < width; x++) {
138  int j2 = 4*(x&1);
139  j = (x & 7);
140  if ((dsp_mask << j) & 0x80) {
141  b = (src[src_x >> 1] >> (4 - 4*(src_x & 1))) & 15;
142  dst[x >> 1] &= 0xFF0F>>j2;
143  dst[x >> 1] |= b << (4 - j2);
144  }
145  if ((mask << j) & 0x80)
146  src_x++;
147  }
148  break;
149  default:
150  bpp = bits_per_pixel >> 3;
151  d = dst;
152  s = src;
153  for (x = 0; x < width; x++) {
154  j = x & 7;
155  if ((dsp_mask << j) & 0x80) {
156  memcpy(d, s, bpp);
157  }
158  d += bpp;
159  if ((mask << j) & 0x80)
160  s += bpp;
161  }
162  break;
163  }
164 }
165 
167  int w, int bpp)
168 {
169  int i;
170  for (i = 0; i < w; i++) {
171  int a, b, c, p, pa, pb, pc;
172 
173  a = dst[i - bpp];
174  b = top[i];
175  c = top[i - bpp];
176 
177  p = b - c;
178  pc = a - c;
179 
180  pa = abs(p);
181  pb = abs(pc);
182  pc = abs(p + pc);
183 
184  if (pa <= pb && pa <= pc)
185  p = a;
186  else if (pb <= pc)
187  p = b;
188  else
189  p = c;
190  dst[i] = p + src[i];
191  }
192 }
193 
194 #define UNROLL1(bpp, op) \
195  { \
196  r = dst[0]; \
197  if (bpp >= 2) \
198  g = dst[1]; \
199  if (bpp >= 3) \
200  b = dst[2]; \
201  if (bpp >= 4) \
202  a = dst[3]; \
203  for (; i <= size - bpp; i += bpp) { \
204  dst[i + 0] = r = op(r, src[i + 0], last[i + 0]); \
205  if (bpp == 1) \
206  continue; \
207  dst[i + 1] = g = op(g, src[i + 1], last[i + 1]); \
208  if (bpp == 2) \
209  continue; \
210  dst[i + 2] = b = op(b, src[i + 2], last[i + 2]); \
211  if (bpp == 3) \
212  continue; \
213  dst[i + 3] = a = op(a, src[i + 3], last[i + 3]); \
214  } \
215  }
216 
217 #define UNROLL_FILTER(op) \
218  if (bpp == 1) { \
219  UNROLL1(1, op) \
220  } else if (bpp == 2) { \
221  UNROLL1(2, op) \
222  } else if (bpp == 3) { \
223  UNROLL1(3, op) \
224  } else if (bpp == 4) { \
225  UNROLL1(4, op) \
226  } \
227  for (; i < size; i++) { \
228  dst[i] = op(dst[i - bpp], src[i], last[i]); \
229  }
230 
231 /* NOTE: 'dst' can be equal to 'last' */
232 static void png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type,
233  uint8_t *src, uint8_t *last, int size, int bpp)
234 {
235  int i, p, r, g, b, a;
236 
237  switch (filter_type) {
239  memcpy(dst, src, size);
240  break;
242  for (i = 0; i < bpp; i++)
243  dst[i] = src[i];
244  if (bpp == 4) {
245  p = *(int *)dst;
246  for (; i < size; i += bpp) {
247  unsigned s = *(int *)(src + i);
248  p = ((s & 0x7f7f7f7f) + (p & 0x7f7f7f7f)) ^ ((s ^ p) & 0x80808080);
249  *(int *)(dst + i) = p;
250  }
251  } else {
252 #define OP_SUB(x, s, l) ((x) + (s))
254  }
255  break;
256  case PNG_FILTER_VALUE_UP:
257  dsp->add_bytes_l2(dst, src, last, size);
258  break;
260  for (i = 0; i < bpp; i++) {
261  p = (last[i] >> 1);
262  dst[i] = p + src[i];
263  }
264 #define OP_AVG(x, s, l) (((((x) + (l)) >> 1) + (s)) & 0xff)
266  break;
268  for (i = 0; i < bpp; i++) {
269  p = last[i];
270  dst[i] = p + src[i];
271  }
272  if (bpp > 2 && size > 4) {
273  /* would write off the end of the array if we let it process
274  * the last pixel with bpp=3 */
275  int w = (bpp & 3) ? size - 3 : size;
276 
277  if (w > i) {
278  dsp->add_paeth_prediction(dst + i, src + i, last + i, size - i, bpp);
279  i = w;
280  }
281  }
282  ff_add_png_paeth_prediction(dst + i, src + i, last + i, size - i, bpp);
283  break;
284  }
285 }
286 
287 /* This used to be called "deloco" in FFmpeg
288  * and is actually an inverse reversible colorspace transformation */
289 #define YUV2RGB(NAME, TYPE) \
290 static void deloco_ ## NAME(TYPE *dst, int size, int alpha) \
291 { \
292  int i; \
293  for (i = 0; i < size; i += 3 + alpha) { \
294  int g = dst [i + 1]; \
295  dst[i + 0] += g; \
296  dst[i + 2] += g; \
297  } \
298 }
299 
300 YUV2RGB(rgb8, uint8_t)
301 YUV2RGB(rgb16, uint16_t)
302 
303 /* process exactly one decompressed row */
305 {
306  uint8_t *ptr, *last_row;
307  int got_line;
308 
309  if (!s->interlace_type) {
310  ptr = s->image_buf + s->image_linesize * (s->y + s->y_offset) + s->x_offset * s->bpp;
311  if (s->y == 0)
312  last_row = s->last_row;
313  else
314  last_row = ptr - s->image_linesize;
315 
316  png_filter_row(&s->dsp, ptr, s->crow_buf[0], s->crow_buf + 1,
317  last_row, s->row_size, s->bpp);
318  /* loco lags by 1 row so that it doesn't interfere with top prediction */
319  if (s->filter_type == PNG_FILTER_TYPE_LOCO && s->y > 0) {
320  if (s->bit_depth == 16) {
321  deloco_rgb16((uint16_t *)(ptr - s->image_linesize), s->row_size / 2,
322  s->color_type == PNG_COLOR_TYPE_RGB_ALPHA);
323  } else {
324  deloco_rgb8(ptr - s->image_linesize, s->row_size,
325  s->color_type == PNG_COLOR_TYPE_RGB_ALPHA);
326  }
327  }
328  s->y++;
329  if (s->y == s->cur_h) {
330  s->state |= PNG_ALLIMAGE;
331  if (s->filter_type == PNG_FILTER_TYPE_LOCO) {
332  if (s->bit_depth == 16) {
333  deloco_rgb16((uint16_t *)ptr, s->row_size / 2,
334  s->color_type == PNG_COLOR_TYPE_RGB_ALPHA);
335  } else {
336  deloco_rgb8(ptr, s->row_size,
337  s->color_type == PNG_COLOR_TYPE_RGB_ALPHA);
338  }
339  }
340  }
341  } else {
342  got_line = 0;
343  for (;;) {
344  ptr = s->image_buf + s->image_linesize * (s->y + s->y_offset) + s->x_offset * s->bpp;
345  if ((ff_png_pass_ymask[s->pass] << (s->y & 7)) & 0x80) {
346  /* if we already read one row, it is time to stop to
347  * wait for the next one */
348  if (got_line)
349  break;
350  png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
351  s->last_row, s->pass_row_size, s->bpp);
352  FFSWAP(uint8_t *, s->last_row, s->tmp_row);
353  FFSWAP(unsigned int, s->last_row_size, s->tmp_row_size);
354  got_line = 1;
355  }
356  if ((png_pass_dsp_ymask[s->pass] << (s->y & 7)) & 0x80) {
357  png_put_interlaced_row(ptr, s->cur_w, s->bits_per_pixel, s->pass,
358  s->color_type, s->last_row);
359  }
360  s->y++;
361  if (s->y == s->cur_h) {
362  memset(s->last_row, 0, s->row_size);
363  for (;;) {
364  if (s->pass == NB_PASSES - 1) {
365  s->state |= PNG_ALLIMAGE;
366  goto the_end;
367  } else {
368  s->pass++;
369  s->y = 0;
370  s->pass_row_size = ff_png_pass_row_size(s->pass,
371  s->bits_per_pixel,
372  s->cur_w);
373  s->crow_size = s->pass_row_size + 1;
374  if (s->pass_row_size != 0)
375  break;
376  /* skip pass if empty row */
377  }
378  }
379  }
380  }
381 the_end:;
382  }
383 }
384 
386 {
387  int ret;
388  s->zstream.avail_in = FFMIN(length, bytestream2_get_bytes_left(&s->gb));
389  s->zstream.next_in = (unsigned char *)s->gb.buffer;
390  bytestream2_skip(&s->gb, length);
391 
392  /* decode one line if possible */
393  while (s->zstream.avail_in > 0) {
394  ret = inflate(&s->zstream, Z_PARTIAL_FLUSH);
395  if (ret != Z_OK && ret != Z_STREAM_END) {
396  av_log(s->avctx, AV_LOG_ERROR, "inflate returned error %d\n", ret);
397  return AVERROR_EXTERNAL;
398  }
399  if (s->zstream.avail_out == 0) {
400  if (!(s->state & PNG_ALLIMAGE)) {
401  png_handle_row(s);
402  }
403  s->zstream.avail_out = s->crow_size;
404  s->zstream.next_out = s->crow_buf;
405  }
406  if (ret == Z_STREAM_END && s->zstream.avail_in > 0) {
408  "%d undecompressed bytes left in buffer\n", s->zstream.avail_in);
409  return 0;
410  }
411  }
412  return 0;
413 }
414 
415 static int decode_zbuf(AVBPrint *bp, const uint8_t *data,
416  const uint8_t *data_end)
417 {
418  z_stream zstream;
419  unsigned char *buf;
420  unsigned buf_size;
421  int ret;
422 
423  zstream.zalloc = ff_png_zalloc;
424  zstream.zfree = ff_png_zfree;
425  zstream.opaque = NULL;
426  if (inflateInit(&zstream) != Z_OK)
427  return AVERROR_EXTERNAL;
428  zstream.next_in = (unsigned char *)data;
429  zstream.avail_in = data_end - data;
430  av_bprint_init(bp, 0, -1);
431 
432  while (zstream.avail_in > 0) {
433  av_bprint_get_buffer(bp, 1, &buf, &buf_size);
434  if (!buf_size) {
435  ret = AVERROR(ENOMEM);
436  goto fail;
437  }
438  zstream.next_out = buf;
439  zstream.avail_out = buf_size;
440  ret = inflate(&zstream, Z_PARTIAL_FLUSH);
441  if (ret != Z_OK && ret != Z_STREAM_END) {
442  ret = AVERROR_EXTERNAL;
443  goto fail;
444  }
445  bp->len += zstream.next_out - buf;
446  if (ret == Z_STREAM_END)
447  break;
448  }
449  inflateEnd(&zstream);
450  bp->str[bp->len] = 0;
451  return 0;
452 
453 fail:
454  inflateEnd(&zstream);
456  return ret;
457 }
458 
459 static uint8_t *iso88591_to_utf8(const uint8_t *in, size_t size_in)
460 {
461  size_t extra = 0, i;
462  uint8_t *out, *q;
463 
464  for (i = 0; i < size_in; i++)
465  extra += in[i] >= 0x80;
466  if (size_in == SIZE_MAX || extra > SIZE_MAX - size_in - 1)
467  return NULL;
468  q = out = av_malloc(size_in + extra + 1);
469  if (!out)
470  return NULL;
471  for (i = 0; i < size_in; i++) {
472  if (in[i] >= 0x80) {
473  *(q++) = 0xC0 | (in[i] >> 6);
474  *(q++) = 0x80 | (in[i] & 0x3F);
475  } else {
476  *(q++) = in[i];
477  }
478  }
479  *(q++) = 0;
480  return out;
481 }
482 
483 static int decode_text_chunk(PNGDecContext *s, uint32_t length, int compressed,
484  AVDictionary **dict)
485 {
486  int ret, method;
487  const uint8_t *data = s->gb.buffer;
488  const uint8_t *data_end = data + length;
489  const uint8_t *keyword = data;
490  const uint8_t *keyword_end = memchr(keyword, 0, data_end - keyword);
491  uint8_t *kw_utf8 = NULL, *text, *txt_utf8 = NULL;
492  unsigned text_len;
493  AVBPrint bp;
494 
495  if (!keyword_end)
496  return AVERROR_INVALIDDATA;
497  data = keyword_end + 1;
498 
499  if (compressed) {
500  if (data == data_end)
501  return AVERROR_INVALIDDATA;
502  method = *(data++);
503  if (method)
504  return AVERROR_INVALIDDATA;
505  if ((ret = decode_zbuf(&bp, data, data_end)) < 0)
506  return ret;
507  text_len = bp.len;
508  av_bprint_finalize(&bp, (char **)&text);
509  if (!text)
510  return AVERROR(ENOMEM);
511  } else {
512  text = (uint8_t *)data;
513  text_len = data_end - text;
514  }
515 
516  kw_utf8 = iso88591_to_utf8(keyword, keyword_end - keyword);
517  txt_utf8 = iso88591_to_utf8(text, text_len);
518  if (text != data)
519  av_free(text);
520  if (!(kw_utf8 && txt_utf8)) {
521  av_free(kw_utf8);
522  av_free(txt_utf8);
523  return AVERROR(ENOMEM);
524  }
525 
526  av_dict_set(dict, kw_utf8, txt_utf8,
528  return 0;
529 }
530 
532  uint32_t length)
533 {
534  if (length != 13)
535  return AVERROR_INVALIDDATA;
536 
537  if (s->state & PNG_IDAT) {
538  av_log(avctx, AV_LOG_ERROR, "IHDR after IDAT\n");
539  return AVERROR_INVALIDDATA;
540  }
541 
542  if (s->state & PNG_IHDR) {
543  av_log(avctx, AV_LOG_ERROR, "Multiple IHDR\n");
544  return AVERROR_INVALIDDATA;
545  }
546 
547  s->width = s->cur_w = bytestream2_get_be32(&s->gb);
548  s->height = s->cur_h = bytestream2_get_be32(&s->gb);
549  if (av_image_check_size(s->width, s->height, 0, avctx)) {
550  s->width = s->height = 0;
551  av_log(avctx, AV_LOG_ERROR, "Invalid image size\n");
552  return AVERROR_INVALIDDATA;
553  }
554  s->bit_depth = bytestream2_get_byte(&s->gb);
555  s->color_type = bytestream2_get_byte(&s->gb);
556  s->compression_type = bytestream2_get_byte(&s->gb);
557  s->filter_type = bytestream2_get_byte(&s->gb);
558  s->interlace_type = bytestream2_get_byte(&s->gb);
559  bytestream2_skip(&s->gb, 4); /* crc */
560  s->state |= PNG_IHDR;
561  if (avctx->debug & FF_DEBUG_PICT_INFO)
562  av_log(avctx, AV_LOG_DEBUG, "width=%d height=%d depth=%d color_type=%d "
563  "compression_type=%d filter_type=%d interlace_type=%d\n",
564  s->width, s->height, s->bit_depth, s->color_type,
566 
567  return 0;
568 }
569 
571 {
572  if (s->state & PNG_IDAT) {
573  av_log(avctx, AV_LOG_ERROR, "pHYs after IDAT\n");
574  return AVERROR_INVALIDDATA;
575  }
576  avctx->sample_aspect_ratio.num = bytestream2_get_be32(&s->gb);
577  avctx->sample_aspect_ratio.den = bytestream2_get_be32(&s->gb);
578  if (avctx->sample_aspect_ratio.num < 0 || avctx->sample_aspect_ratio.den < 0)
579  avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
580  bytestream2_skip(&s->gb, 1); /* unit specifier */
581  bytestream2_skip(&s->gb, 4); /* crc */
582 
583  return 0;
584 }
585 
587  uint32_t length, AVFrame *p)
588 {
589  int ret;
590 
591  if (!(s->state & PNG_IHDR)) {
592  av_log(avctx, AV_LOG_ERROR, "IDAT without IHDR\n");
593  return AVERROR_INVALIDDATA;
594  }
595  if (!(s->state & PNG_IDAT)) {
596  /* init image info */
597  avctx->width = s->width;
598  avctx->height = s->height;
599 
601  s->bits_per_pixel = s->bit_depth * s->channels;
602  s->bpp = (s->bits_per_pixel + 7) >> 3;
603  s->row_size = (s->cur_w * s->bits_per_pixel + 7) >> 3;
604 
605  if ((s->bit_depth == 2 || s->bit_depth == 4 || s->bit_depth == 8) &&
607  avctx->pix_fmt = AV_PIX_FMT_RGB24;
608  } else if ((s->bit_depth == 2 || s->bit_depth == 4 || s->bit_depth == 8) &&
610  avctx->pix_fmt = AV_PIX_FMT_RGBA;
611  } else if ((s->bit_depth == 2 || s->bit_depth == 4 || s->bit_depth == 8) &&
613  avctx->pix_fmt = AV_PIX_FMT_GRAY8;
614  } else if (s->bit_depth == 16 &&
616  avctx->pix_fmt = AV_PIX_FMT_GRAY16BE;
617  } else if (s->bit_depth == 16 &&
619  avctx->pix_fmt = AV_PIX_FMT_RGB48BE;
620  } else if (s->bit_depth == 16 &&
622  avctx->pix_fmt = AV_PIX_FMT_RGBA64BE;
623  } else if ((s->bits_per_pixel == 1 || s->bits_per_pixel == 2 || s->bits_per_pixel == 4 || s->bits_per_pixel == 8) &&
625  avctx->pix_fmt = AV_PIX_FMT_PAL8;
626  } else if (s->bit_depth == 1 && s->bits_per_pixel == 1 && avctx->codec_id != AV_CODEC_ID_APNG) {
627  avctx->pix_fmt = AV_PIX_FMT_MONOBLACK;
628  } else if (s->bit_depth == 8 &&
630  avctx->pix_fmt = AV_PIX_FMT_YA8;
631  } else if (s->bit_depth == 16 &&
633  avctx->pix_fmt = AV_PIX_FMT_YA16BE;
634  } else {
635  av_log(avctx, AV_LOG_ERROR, "unsupported bit depth %d "
636  "and color type %d\n",
637  s->bit_depth, s->color_type);
638  return AVERROR_INVALIDDATA;
639  }
640 
641  if ((ret = ff_thread_get_buffer(avctx, &s->picture, AV_GET_BUFFER_FLAG_REF)) < 0)
642  return ret;
643  ff_thread_finish_setup(avctx);
644 
646  p->key_frame = 1;
648 
649  /* compute the compressed row size */
650  if (!s->interlace_type) {
651  s->crow_size = s->row_size + 1;
652  } else {
653  s->pass = 0;
655  s->bits_per_pixel,
656  s->cur_w);
657  s->crow_size = s->pass_row_size + 1;
658  }
659  av_dlog(avctx, "row_size=%d crow_size =%d\n",
660  s->row_size, s->crow_size);
661  s->image_buf = p->data[0];
662  s->image_linesize = p->linesize[0];
663  /* copy the palette if needed */
664  if (avctx->pix_fmt == AV_PIX_FMT_PAL8)
665  memcpy(p->data[1], s->palette, 256 * sizeof(uint32_t));
666  /* empty row is used if differencing to the first row */
668  if (!s->last_row)
669  return AVERROR_INVALIDDATA;
670  if (s->interlace_type ||
673  if (!s->tmp_row)
674  return AVERROR_INVALIDDATA;
675  }
676  /* compressed row */
678  if (!s->buffer)
679  return AVERROR(ENOMEM);
680 
681  /* we want crow_buf+1 to be 16-byte aligned */
682  s->crow_buf = s->buffer + 15;
683  s->zstream.avail_out = s->crow_size;
684  s->zstream.next_out = s->crow_buf;
685  }
686  s->state |= PNG_IDAT;
687  if ((ret = png_decode_idat(s, length)) < 0)
688  return ret;
689  bytestream2_skip(&s->gb, 4); /* crc */
690 
691  return 0;
692 }
693 
695  uint32_t length)
696 {
697  int n, i, r, g, b;
698 
699  if ((length % 3) != 0 || length > 256 * 3)
700  return AVERROR_INVALIDDATA;
701  /* read the palette */
702  n = length / 3;
703  for (i = 0; i < n; i++) {
704  r = bytestream2_get_byte(&s->gb);
705  g = bytestream2_get_byte(&s->gb);
706  b = bytestream2_get_byte(&s->gb);
707  s->palette[i] = (0xFFU << 24) | (r << 16) | (g << 8) | b;
708  }
709  for (; i < 256; i++)
710  s->palette[i] = (0xFFU << 24);
711  s->state |= PNG_PLTE;
712  bytestream2_skip(&s->gb, 4); /* crc */
713 
714  return 0;
715 }
716 
718  uint32_t length)
719 {
720  int v, i;
721 
722  /* read the transparency. XXX: Only palette mode supported */
724  length > 256 ||
725  !(s->state & PNG_PLTE))
726  return AVERROR_INVALIDDATA;
727  for (i = 0; i < length; i++) {
728  v = bytestream2_get_byte(&s->gb);
729  s->palette[i] = (s->palette[i] & 0x00ffffff) | (v << 24);
730  }
731  bytestream2_skip(&s->gb, 4); /* crc */
732 
733  return 0;
734 }
735 
737 {
738  if (s->bits_per_pixel == 1 && s->color_type == PNG_COLOR_TYPE_PALETTE) {
739  int i, j, k;
740  uint8_t *pd = p->data[0];
741  for (j = 0; j < s->height; j++) {
742  i = s->width / 8;
743  for (k = 7; k >= 1; k--)
744  if ((s->width&7) >= k)
745  pd[8*i + k - 1] = (pd[i]>>8-k) & 1;
746  for (i--; i >= 0; i--) {
747  pd[8*i + 7]= pd[i] & 1;
748  pd[8*i + 6]= (pd[i]>>1) & 1;
749  pd[8*i + 5]= (pd[i]>>2) & 1;
750  pd[8*i + 4]= (pd[i]>>3) & 1;
751  pd[8*i + 3]= (pd[i]>>4) & 1;
752  pd[8*i + 2]= (pd[i]>>5) & 1;
753  pd[8*i + 1]= (pd[i]>>6) & 1;
754  pd[8*i + 0]= pd[i]>>7;
755  }
756  pd += s->image_linesize;
757  }
758  } else if (s->bits_per_pixel == 2) {
759  int i, j;
760  uint8_t *pd = p->data[0];
761  for (j = 0; j < s->height; j++) {
762  i = s->width / 4;
764  if ((s->width&3) >= 3) pd[4*i + 2]= (pd[i] >> 2) & 3;
765  if ((s->width&3) >= 2) pd[4*i + 1]= (pd[i] >> 4) & 3;
766  if ((s->width&3) >= 1) pd[4*i + 0]= pd[i] >> 6;
767  for (i--; i >= 0; i--) {
768  pd[4*i + 3]= pd[i] & 3;
769  pd[4*i + 2]= (pd[i]>>2) & 3;
770  pd[4*i + 1]= (pd[i]>>4) & 3;
771  pd[4*i + 0]= pd[i]>>6;
772  }
773  } else {
774  if ((s->width&3) >= 3) pd[4*i + 2]= ((pd[i]>>2) & 3)*0x55;
775  if ((s->width&3) >= 2) pd[4*i + 1]= ((pd[i]>>4) & 3)*0x55;
776  if ((s->width&3) >= 1) pd[4*i + 0]= ( pd[i]>>6 )*0x55;
777  for (i--; i >= 0; i--) {
778  pd[4*i + 3]= ( pd[i] & 3)*0x55;
779  pd[4*i + 2]= ((pd[i]>>2) & 3)*0x55;
780  pd[4*i + 1]= ((pd[i]>>4) & 3)*0x55;
781  pd[4*i + 0]= ( pd[i]>>6 )*0x55;
782  }
783  }
784  pd += s->image_linesize;
785  }
786  } else if (s->bits_per_pixel == 4) {
787  int i, j;
788  uint8_t *pd = p->data[0];
789  for (j = 0; j < s->height; j++) {
790  i = s->width/2;
792  if (s->width&1) pd[2*i+0]= pd[i]>>4;
793  for (i--; i >= 0; i--) {
794  pd[2*i + 1] = pd[i] & 15;
795  pd[2*i + 0] = pd[i] >> 4;
796  }
797  } else {
798  if (s->width & 1) pd[2*i + 0]= (pd[i] >> 4) * 0x11;
799  for (i--; i >= 0; i--) {
800  pd[2*i + 1] = (pd[i] & 15) * 0x11;
801  pd[2*i + 0] = (pd[i] >> 4) * 0x11;
802  }
803  }
804  pd += s->image_linesize;
805  }
806  }
807 }
808 
810  uint32_t length)
811 {
812  uint32_t sequence_number;
813  int cur_w, cur_h, x_offset, y_offset, dispose_op, blend_op;
814 
815  if (length != 26)
816  return AVERROR_INVALIDDATA;
817 
818  if (!(s->state & PNG_IHDR)) {
819  av_log(avctx, AV_LOG_ERROR, "fctl before IHDR\n");
820  return AVERROR_INVALIDDATA;
821  }
822 
823  sequence_number = bytestream2_get_be32(&s->gb);
824  cur_w = bytestream2_get_be32(&s->gb);
825  cur_h = bytestream2_get_be32(&s->gb);
826  x_offset = bytestream2_get_be32(&s->gb);
827  y_offset = bytestream2_get_be32(&s->gb);
828  bytestream2_skip(&s->gb, 4); /* delay_num (2), delay_den (2) */
829  dispose_op = bytestream2_get_byte(&s->gb);
830  blend_op = bytestream2_get_byte(&s->gb);
831  bytestream2_skip(&s->gb, 4); /* crc */
832 
833  if (sequence_number == 0 &&
834  (cur_w != s->width ||
835  cur_h != s->height ||
836  x_offset != 0 ||
837  y_offset != 0) ||
838  cur_w <= 0 || cur_h <= 0 ||
839  x_offset < 0 || y_offset < 0 ||
840  cur_w > s->width - x_offset|| cur_h > s->height - y_offset)
841  return AVERROR_INVALIDDATA;
842 
843  /* always (re)start with a clean frame */
844  if (sequence_number == 0) {
846  s->frame_id = 0;
847  } else {
848  s->frame_id++;
849  if (s->frame_id == 1 && s->dispose_op == APNG_DISPOSE_OP_PREVIOUS)
850  /* previous for the second frame is the first frame */
852  }
853 
854  s->cur_w = cur_w;
855  s->cur_h = cur_h;
856  s->x_offset = x_offset;
857  s->y_offset = y_offset;
858  s->dispose_op = dispose_op;
859  s->blend_op = blend_op;
860 
861  return 0;
862 }
863 
865 {
866  int i, j;
867  uint8_t *pd = p->data[0];
868  uint8_t *pd_last = s->last_picture.f->data[0];
869  int ls = FFMIN(av_image_get_linesize(p->format, s->width, 0), s->width * s->bpp);
870 
871  ff_thread_await_progress(&s->last_picture, INT_MAX, 0);
872  for (j = 0; j < s->height; j++) {
873  for (i = 0; i < ls; i++)
874  pd[i] += pd_last[i];
875  pd += s->image_linesize;
876  pd_last += s->image_linesize;
877  }
878 }
879 
880 // divide by 255 and round to nearest
881 // apply a fast variant: (X+127)/255 = ((X+127)*257+257)>>16 = ((X+128)*257)>>16
882 #define FAST_DIV255(x) ((((x) + 128) * 257) >> 16)
883 
885  AVFrame *p)
886 {
887  int i, j;
888  uint8_t *pd = p->data[0];
889  uint8_t *pd_last = s->last_picture.f->data[0];
890  uint8_t *pd_last_region = s->dispose_op == APNG_DISPOSE_OP_PREVIOUS ?
891  s->previous_picture.f->data[0] : s->last_picture.f->data[0];
892  int ls = FFMIN(av_image_get_linesize(p->format, s->width, 0), s->width * s->bpp);
893 
894  if (ls < 0)
895  return ls;
896 
897  if (s->blend_op == APNG_BLEND_OP_OVER &&
898  avctx->pix_fmt != AV_PIX_FMT_RGBA && avctx->pix_fmt != AV_PIX_FMT_ARGB) {
899  avpriv_request_sample(avctx, "Blending with pixel format %s",
900  av_get_pix_fmt_name(avctx->pix_fmt));
901  return AVERROR_PATCHWELCOME;
902  }
903 
904  ff_thread_await_progress(&s->last_picture, INT_MAX, 0);
907 
908  for (j = 0; j < s->y_offset; j++) {
909  memcpy(pd, pd_last, ls);
910  pd += s->image_linesize;
911  pd_last += s->image_linesize;
912  }
913 
915  uint8_t ri, gi, bi, ai;
916 
917  pd_last_region += s->y_offset * s->image_linesize;
918  if (avctx->pix_fmt == AV_PIX_FMT_RGBA) {
919  ri = 0;
920  gi = 1;
921  bi = 2;
922  ai = 3;
923  } else {
924  ri = 3;
925  gi = 2;
926  bi = 1;
927  ai = 0;
928  }
929 
930  for (j = s->y_offset; j < s->y_offset + s->cur_h; j++) {
931  i = s->x_offset * s->bpp;
932  if (i)
933  memcpy(pd, pd_last, i);
934  for (; i < (s->x_offset + s->cur_w) * s->bpp; i += s->bpp) {
935  uint8_t alpha = pd[i+ai];
936 
937  /* output = alpha * foreground + (1-alpha) * background */
938  switch (alpha) {
939  case 0:
940  pd[i+ri] = pd_last_region[i+ri];
941  pd[i+gi] = pd_last_region[i+gi];
942  pd[i+bi] = pd_last_region[i+bi];
943  pd[i+ai] = 0xff;
944  break;
945  case 255:
946  break;
947  default:
948  pd[i+ri] = FAST_DIV255(alpha * pd[i+ri] + (255 - alpha) * pd_last_region[i+ri]);
949  pd[i+gi] = FAST_DIV255(alpha * pd[i+gi] + (255 - alpha) * pd_last_region[i+gi]);
950  pd[i+bi] = FAST_DIV255(alpha * pd[i+bi] + (255 - alpha) * pd_last_region[i+bi]);
951  pd[i+ai] = 0xff;
952  break;
953  }
954  }
955  if (ls - i)
956  memcpy(pd+i, pd_last+i, ls - i);
957  pd += s->image_linesize;
958  pd_last += s->image_linesize;
959  pd_last_region += s->image_linesize;
960  }
961  } else {
962  for (j = s->y_offset; j < s->y_offset + s->cur_h; j++) {
963  int end_offset = (s->x_offset + s->cur_w) * s->bpp;
964  int end_len = ls - end_offset;
965  if (s->x_offset)
966  memcpy(pd, pd_last, s->x_offset * s->bpp);
967  if (end_len)
968  memcpy(pd+end_offset, pd_last+end_offset, end_len);
969  pd += s->image_linesize;
970  pd_last += s->image_linesize;
971  }
972  }
973 
974  for (j = s->y_offset + s->cur_h; j < s->height; j++) {
975  memcpy(pd, pd_last, ls);
976  pd += s->image_linesize;
977  pd_last += s->image_linesize;
978  }
979 
980  return 0;
981 }
982 
984  AVFrame *p, AVPacket *avpkt)
985 {
986  AVDictionary *metadata = NULL;
987  uint32_t tag, length;
988  int decode_next_dat = 0;
989  int ret;
990  AVFrame *ref;
991 
992  for (;;) {
993  length = bytestream2_get_bytes_left(&s->gb);
994  if (length <= 0) {
995  if (CONFIG_APNG_DECODER && avctx->codec_id == AV_CODEC_ID_APNG && length == 0) {
996  if (!(s->state & PNG_IDAT))
997  return 0;
998  else
999  goto exit_loop;
1000  }
1001  av_log(avctx, AV_LOG_ERROR, "%d bytes left\n", length);
1002  if ( s->state & PNG_ALLIMAGE
1004  goto exit_loop;
1005  ret = AVERROR_INVALIDDATA;
1006  goto fail;
1007  }
1008 
1009  length = bytestream2_get_be32(&s->gb);
1010  if (length > 0x7fffffff || length > bytestream2_get_bytes_left(&s->gb)) {
1011  av_log(avctx, AV_LOG_ERROR, "chunk too big\n");
1012  ret = AVERROR_INVALIDDATA;
1013  goto fail;
1014  }
1015  tag = bytestream2_get_le32(&s->gb);
1016  if (avctx->debug & FF_DEBUG_STARTCODE)
1017  av_log(avctx, AV_LOG_DEBUG, "png: tag=%c%c%c%c length=%u\n",
1018  (tag & 0xff),
1019  ((tag >> 8) & 0xff),
1020  ((tag >> 16) & 0xff),
1021  ((tag >> 24) & 0xff), length);
1022  switch (tag) {
1023  case MKTAG('I', 'H', 'D', 'R'):
1024  if ((ret = decode_ihdr_chunk(avctx, s, length)) < 0)
1025  goto fail;
1026  break;
1027  case MKTAG('p', 'H', 'Y', 's'):
1028  if ((ret = decode_phys_chunk(avctx, s)) < 0)
1029  goto fail;
1030  break;
1031  case MKTAG('f', 'c', 'T', 'L'):
1032  if (!CONFIG_APNG_DECODER || avctx->codec_id != AV_CODEC_ID_APNG)
1033  goto skip_tag;
1034  if ((ret = decode_fctl_chunk(avctx, s, length)) < 0)
1035  goto fail;
1036  decode_next_dat = 1;
1037  break;
1038  case MKTAG('f', 'd', 'A', 'T'):
1039  if (!CONFIG_APNG_DECODER || avctx->codec_id != AV_CODEC_ID_APNG)
1040  goto skip_tag;
1041  if (!decode_next_dat) {
1042  ret = AVERROR_INVALIDDATA;
1043  goto fail;
1044  }
1045  bytestream2_get_be32(&s->gb);
1046  length -= 4;
1047  /* fallthrough */
1048  case MKTAG('I', 'D', 'A', 'T'):
1049  if (CONFIG_APNG_DECODER && avctx->codec_id == AV_CODEC_ID_APNG && !decode_next_dat)
1050  goto skip_tag;
1051  if ((ret = decode_idat_chunk(avctx, s, length, p)) < 0)
1052  goto fail;
1053  break;
1054  case MKTAG('P', 'L', 'T', 'E'):
1055  if (decode_plte_chunk(avctx, s, length) < 0)
1056  goto skip_tag;
1057  break;
1058  case MKTAG('t', 'R', 'N', 'S'):
1059  if (decode_trns_chunk(avctx, s, length) < 0)
1060  goto skip_tag;
1061  break;
1062  case MKTAG('t', 'E', 'X', 't'):
1063  if (decode_text_chunk(s, length, 0, &metadata) < 0)
1064  av_log(avctx, AV_LOG_WARNING, "Broken tEXt chunk\n");
1065  bytestream2_skip(&s->gb, length + 4);
1066  break;
1067  case MKTAG('z', 'T', 'X', 't'):
1068  if (decode_text_chunk(s, length, 1, &metadata) < 0)
1069  av_log(avctx, AV_LOG_WARNING, "Broken zTXt chunk\n");
1070  bytestream2_skip(&s->gb, length + 4);
1071  break;
1072  case MKTAG('I', 'E', 'N', 'D'):
1073  if (!(s->state & PNG_ALLIMAGE))
1074  av_log(avctx, AV_LOG_ERROR, "IEND without all image\n");
1075  if (!(s->state & (PNG_ALLIMAGE|PNG_IDAT))) {
1076  ret = AVERROR_INVALIDDATA;
1077  goto fail;
1078  }
1079  bytestream2_skip(&s->gb, 4); /* crc */
1080  goto exit_loop;
1081  default:
1082  /* skip tag */
1083 skip_tag:
1084  bytestream2_skip(&s->gb, length + 4);
1085  break;
1086  }
1087  }
1088 exit_loop:
1089 
1090  if (s->bits_per_pixel <= 4)
1091  handle_small_bpp(s, p);
1092 
1093  /* handle p-frames only if a predecessor frame is available */
1094  ref = s->dispose_op == APNG_DISPOSE_OP_PREVIOUS ?
1095  s->previous_picture.f : s->last_picture.f;
1096  if (ref->data[0] && s->last_picture.f->data[0]) {
1097  if ( !(avpkt->flags & AV_PKT_FLAG_KEY) && avctx->codec_tag != AV_RL32("MPNG")
1098  && ref->width == p->width
1099  && ref->height== p->height
1100  && ref->format== p->format
1101  ) {
1102  if (CONFIG_PNG_DECODER && avctx->codec_id != AV_CODEC_ID_APNG)
1103  handle_p_frame_png(s, p);
1104  else if (CONFIG_APNG_DECODER &&
1105  avctx->codec_id == AV_CODEC_ID_APNG &&
1106  (ret = handle_p_frame_apng(avctx, s, p)) < 0)
1107  goto fail;
1108  }
1109  }
1110  ff_thread_report_progress(&s->picture, INT_MAX, 0);
1111 
1112  av_frame_set_metadata(p, metadata);
1113  metadata = NULL;
1114  return 0;
1115 
1116 fail:
1117  av_dict_free(&metadata);
1118  ff_thread_report_progress(&s->picture, INT_MAX, 0);
1119  return ret;
1120 }
1121 
1122 #if CONFIG_PNG_DECODER
1123 static int decode_frame_png(AVCodecContext *avctx,
1124  void *data, int *got_frame,
1125  AVPacket *avpkt)
1126 {
1127  PNGDecContext *const s = avctx->priv_data;
1128  const uint8_t *buf = avpkt->data;
1129  int buf_size = avpkt->size;
1130  AVFrame *p;
1131  int64_t sig;
1132  int ret;
1133 
1136  p = s->picture.f;
1137 
1138  bytestream2_init(&s->gb, buf, buf_size);
1139 
1140  /* check signature */
1141  sig = bytestream2_get_be64(&s->gb);
1142  if (sig != PNGSIG &&
1143  sig != MNGSIG) {
1144  av_log(avctx, AV_LOG_ERROR, "Invalid PNG signature (%d).\n", buf_size);
1145  return AVERROR_INVALIDDATA;
1146  }
1147 
1148  s->y = s->state = 0;
1149 
1150  /* init the zlib */
1151  s->zstream.zalloc = ff_png_zalloc;
1152  s->zstream.zfree = ff_png_zfree;
1153  s->zstream.opaque = NULL;
1154  ret = inflateInit(&s->zstream);
1155  if (ret != Z_OK) {
1156  av_log(avctx, AV_LOG_ERROR, "inflateInit returned error %d\n", ret);
1157  return AVERROR_EXTERNAL;
1158  }
1159 
1160  if ((ret = decode_frame_common(avctx, s, p, avpkt)) < 0)
1161  goto the_end;
1162 
1163  if ((ret = av_frame_ref(data, s->picture.f)) < 0)
1164  return ret;
1165 
1166  *got_frame = 1;
1167 
1168  ret = bytestream2_tell(&s->gb);
1169 the_end:
1170  inflateEnd(&s->zstream);
1171  s->crow_buf = NULL;
1172  return ret;
1173 }
1174 #endif
1175 
1176 #if CONFIG_APNG_DECODER
1177 static int decode_frame_apng(AVCodecContext *avctx,
1178  void *data, int *got_frame,
1179  AVPacket *avpkt)
1180 {
1181  PNGDecContext *const s = avctx->priv_data;
1182  int ret;
1183  AVFrame *p;
1184  ThreadFrame tmp;
1185 
1187  tmp = s->previous_picture;
1189  s->last_picture = s->picture;
1190  s->picture = tmp;
1191  p = s->picture.f;
1192 
1193  if (!(s->state & PNG_IHDR)) {
1194  if (!avctx->extradata_size)
1195  return AVERROR_INVALIDDATA;
1196 
1197  /* only init fields, there is no zlib use in extradata */
1198  s->zstream.zalloc = ff_png_zalloc;
1199  s->zstream.zfree = ff_png_zfree;
1200 
1201  bytestream2_init(&s->gb, avctx->extradata, avctx->extradata_size);
1202  if ((ret = decode_frame_common(avctx, s, p, avpkt)) < 0)
1203  goto end;
1204  }
1205 
1206  /* reset state for a new frame */
1207  if ((ret = inflateInit(&s->zstream)) != Z_OK) {
1208  av_log(avctx, AV_LOG_ERROR, "inflateInit returned error %d\n", ret);
1209  ret = AVERROR_EXTERNAL;
1210  goto end;
1211  }
1212  s->y = 0;
1213  s->state &= ~(PNG_IDAT | PNG_ALLIMAGE);
1214  bytestream2_init(&s->gb, avpkt->data, avpkt->size);
1215  if ((ret = decode_frame_common(avctx, s, p, avpkt)) < 0)
1216  goto end;
1217 
1218  if (!(s->state & PNG_ALLIMAGE))
1219  av_log(avctx, AV_LOG_WARNING, "Frame did not contain a complete image\n");
1220  if (!(s->state & (PNG_ALLIMAGE|PNG_IDAT))) {
1221  ret = AVERROR_INVALIDDATA;
1222  goto end;
1223  }
1224  if ((ret = av_frame_ref(data, s->picture.f)) < 0)
1225  goto end;
1226 
1227  *got_frame = 1;
1228  ret = bytestream2_tell(&s->gb);
1229 
1230 end:
1231  inflateEnd(&s->zstream);
1232  return ret;
1233 }
1234 #endif
1235 
1237 {
1238  PNGDecContext *psrc = src->priv_data;
1239  PNGDecContext *pdst = dst->priv_data;
1240  int ret;
1241 
1242  if (dst == src)
1243  return 0;
1244 
1245  pdst->frame_id = psrc->frame_id;
1246 
1247  ff_thread_release_buffer(dst, &pdst->picture);
1248  if (psrc->picture.f->data[0] &&
1249  (ret = ff_thread_ref_frame(&pdst->picture, &psrc->picture)) < 0)
1250  return ret;
1253  if (psrc->last_picture.f->data[0])
1254  return ff_thread_ref_frame(&pdst->last_picture, &psrc->last_picture);
1255  }
1256 
1257  return 0;
1258 }
1259 
1261 {
1262  PNGDecContext *s = avctx->priv_data;
1263 
1264  s->avctx = avctx;
1266  s->last_picture.f = av_frame_alloc();
1267  s->picture.f = av_frame_alloc();
1268  if (!s->previous_picture.f || !s->last_picture.f || !s->picture.f) {
1271  av_frame_free(&s->picture.f);
1272  return AVERROR(ENOMEM);
1273  }
1274 
1275  if (!avctx->internal->is_copy) {
1276  avctx->internal->allocate_progress = 1;
1277  ff_pngdsp_init(&s->dsp);
1278  }
1279 
1280  return 0;
1281 }
1282 
1284 {
1285  PNGDecContext *s = avctx->priv_data;
1286 
1291  ff_thread_release_buffer(avctx, &s->picture);
1292  av_frame_free(&s->picture.f);
1293  av_freep(&s->buffer);
1294  s->buffer_size = 0;
1295  av_freep(&s->last_row);
1296  s->last_row_size = 0;
1297  av_freep(&s->tmp_row);
1298  s->tmp_row_size = 0;
1299 
1300  return 0;
1301 }
1302 
1303 #if CONFIG_APNG_DECODER
1304 AVCodec ff_apng_decoder = {
1305  .name = "apng",
1306  .long_name = NULL_IF_CONFIG_SMALL("APNG (Animated Portable Network Graphics) image"),
1307  .type = AVMEDIA_TYPE_VIDEO,
1308  .id = AV_CODEC_ID_APNG,
1309  .priv_data_size = sizeof(PNGDecContext),
1310  .init = png_dec_init,
1311  .close = png_dec_end,
1312  .decode = decode_frame_apng,
1314  .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
1315  .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS /*| CODEC_CAP_DRAW_HORIZ_BAND*/,
1316 };
1317 #endif
1318 
1319 #if CONFIG_PNG_DECODER
1320 AVCodec ff_png_decoder = {
1321  .name = "png",
1322  .long_name = NULL_IF_CONFIG_SMALL("PNG (Portable Network Graphics) image"),
1323  .type = AVMEDIA_TYPE_VIDEO,
1324  .id = AV_CODEC_ID_PNG,
1325  .priv_data_size = sizeof(PNGDecContext),
1326  .init = png_dec_init,
1327  .close = png_dec_end,
1328  .decode = decode_frame_png,
1330  .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
1331  .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS /*| CODEC_CAP_DRAW_HORIZ_BAND*/,
1332 };
1333 #endif
static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, uint32_t length, AVFrame *p)
Definition: pngdec.c:586
static int decode_fctl_chunk(AVCodecContext *avctx, PNGDecContext *s, uint32_t length)
Definition: pngdec.c:809
#define PNG_FILTER_VALUE_AVG
Definition: png.h:41
static void png_handle_row(PNGDecContext *s)
Definition: pngdec.c:304
ThreadFrame previous_picture
Definition: pngdec.c:41
#define NULL
Definition: coverity.c:32
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:75
float v
const char * s
Definition: avisynth_c.h:669
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
This structure describes decoded (raw) audio or video data.
Definition: frame.h:163
int width
Definition: pngdec.c:46
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
unsigned int tmp_row_size
Definition: pngdec.c:67
8bit gray, 8bit alpha
Definition: pixfmt.h:148
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:181
AVFrame * f
Definition: thread.h:36
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:70
const char * g
Definition: vf_curves.c:108
int pass_row_size
Definition: pngdec.c:73
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
uint8_t * tmp_row
Definition: pngdec.c:66
void(* add_bytes_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
Definition: pngdsp.h:28
#define PNG_PLTE
Definition: png.h:48
int num
numerator
Definition: rational.h:44
static int decode_text_chunk(PNGDecContext *s, uint32_t length, int compressed, AVDictionary **dict)
Definition: pngdec.c:483
int size
Definition: avcodec.h:1161
const char * b
Definition: vf_curves.c:109
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
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:1621
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1442
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 FF_INPUT_BUFFER_PADDING_SIZE at the end w...
Definition: utils.c:139
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
#define PNG_COLOR_TYPE_RGB
Definition: png.h:33
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: avcodec.h:3173
#define PNG_COLOR_TYPE_PALETTE
Definition: png.h:32
#define PNG_IHDR
Definition: png.h:45
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
int filter_type
Definition: pngdec.c:54
void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
Definition: pngdec.c:166
#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:75
#define PNG_FILTER_VALUE_PAETH
Definition: png.h:42
int state
Definition: pngdec.c:45
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
if()
Definition: avfilter.c:975
int y_offset
Definition: pngdec.c:48
uint8_t
#define av_cold
Definition: attributes.h:74
#define av_malloc(s)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:135
#define PNG_COLOR_TYPE_RGB_ALPHA
Definition: png.h:34
8 bit with PIX_FMT_RGB32 palette
Definition: pixfmt.h:79
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:67
Multithreading support functions.
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:257
#define PNG_ALLIMAGE
Definition: png.h:47
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:278
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1353
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:787
static int decode_phys_chunk(AVCodecContext *avctx, PNGDecContext *s)
Definition: pngdec.c:570
uint8_t * data
Definition: avcodec.h:1160
int frame_id
Definition: pngdec.c:59
const uint8_t * buffer
Definition: bytestream.h:34
static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
Definition: pngdec.c:1236
uint32_t tag
Definition: movenc.c:1332
int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src)
Definition: utils.c:3660
void av_frame_set_metadata(AVFrame *frame, AVDictionary *val)
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:359
ptrdiff_t size
Definition: opengl_enc.c:101
unsigned int last_row_size
Definition: pngdec.c:65
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...
int cur_h
Definition: pngdec.c:47
#define av_log(a,...)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1206
static int decode_plte_chunk(AVCodecContext *avctx, PNGDecContext *s, uint32_t length)
Definition: pngdec.c:694
#define U(x)
Definition: vp56_arith.h:37
void(* add_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
Definition: pngdsp.h:33
static double alpha(void *priv, double x, double y)
Definition: vf_geq.c:98
int width
width and height of the video frame
Definition: frame.h:212
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:175
static const uint8_t png_pass_dsp_mask[NB_PASSES]
Definition: pngdec.c:89
16bit gray, 16bit alpha (big-endian)
Definition: pixfmt.h:239
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:983
static const uint16_t mask[17]
Definition: lzw.c:38
#define OP_SUB(x, s, l)
int is_copy
Whether the parent AVCodecContext is a copy of the context which had init() called on it...
Definition: internal.h:74
#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:148
static void handle_p_frame_png(PNGDecContext *s, AVFrame *p)
Definition: pngdec.c:864
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:180
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
#define CONFIG_APNG_DECODER
Definition: config.h:577
uint8_t * crow_buf
Definition: pngdec.c:63
const char * r
Definition: vf_curves.c:107
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:196
int pass
Definition: pngdec.c:70
#define FF_COMPLIANCE_NORMAL
Definition: avcodec.h:2544
int ff_png_get_nb_channels(int color_type)
Definition: png.c:49
ThreadFrame picture
Definition: pngdec.c:43
int height
Definition: pngdec.c:46
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:194
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:154
#define PNGSIG
Definition: png.h:52
GLsizei GLsizei * length
Definition: opengl_enc.c:115
const char * name
Name of the codec implementation.
Definition: avcodec.h:3180
int bits_per_pixel
Definition: pngdec.c:56
GetByteContext gb
Definition: pngdec.c:40
Libavcodec external API header.
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:99
#define NB_PASSES
Definition: png.h:50
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:100
uint8_t blend_op
Definition: pngdec.c:49
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1166
#define pass
Definition: fft_template.c:509
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
Definition: internal.h:219
z_stream zstream
Definition: pngdec.c:75
#define FF_DEBUG_STARTCODE
Definition: avcodec.h:2577
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:241
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:234
#define FFMIN(a, b)
Definition: common.h:81
#define PNG_FILTER_VALUE_SUB
Definition: png.h:39
uint32_t palette[256]
Definition: pngdec.c:62
#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:78
#define PNG_COLOR_TYPE_GRAY
Definition: png.h:31
ret
Definition: avfilter.c:974
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:232
int width
picture width / height.
Definition: avcodec.h:1412
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
uint8_t * last_row
Definition: pngdec.c:64
#define AV_RL32
Definition: intreadwrite.h:146
int n
Definition: avisynth_c.h:589
AVCodecContext * avctx
Definition: pngdec.c:38
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:415
int channels
Definition: pngdec.c:55
static int decode_ihdr_chunk(AVCodecContext *avctx, PNGDecContext *s, uint32_t length)
Definition: pngdec.c:531
static uint8_t * iso88591_to_utf8(const uint8_t *in, size_t size_in)
Definition: pngdec.c:459
#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:224
static av_cold int png_dec_init(AVCodecContext *avctx)
Definition: pngdec.c:1260
AVS_Value src
Definition: avisynth_c.h:524
int buffer_size
Definition: pngdec.c:69
static int skip_tag(AVIOContext *in, int32_t tag_name)
Definition: ismindex.c:134
enum AVCodecID codec_id
Definition: avcodec.h:1256
#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:191
#define PNG_FILTER_TYPE_LOCO
Definition: png.h:37
int debug
debug
Definition: avcodec.h:2563
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:1239
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1271
int interlace_type
Definition: pngdec.c:53
void * buf
Definition: avisynth_c.h:595
const uint8_t ff_png_pass_ymask[NB_PASSES]
Definition: png.c:25
int image_linesize
Definition: pngdec.c:61
int extradata_size
Definition: avcodec.h:1354
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:69
BYTE int const BYTE int int int height
Definition: avisynth_c.h:714
Y , 16bpp, big-endian.
Definition: pixfmt.h:104
rational number numerator/denominator
Definition: rational.h:43
int cur_w
Definition: pngdec.c:47
#define CONFIG_PNG_DECODER
Definition: config.h:701
#define OP_AVG(x, s, l)
uint8_t * image_buf
Definition: pngdec.c:60
int allocate_progress
Whether to allocate progress for frame threading.
Definition: internal.h:89
uint8_t dispose_op
Definition: pngdec.c:49
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:174
#define FAST_DIV255(x)
Definition: pngdec.c:882
#define FF_DEBUG_PICT_INFO
Definition: avcodec.h:2564
static int handle_p_frame_apng(AVCodecContext *avctx, PNGDecContext *s, AVFrame *p)
Definition: pngdec.c:884
#define YUV2RGB(NAME, TYPE)
Definition: pngdec.c:289
static const uint8_t png_pass_mask[NB_PASSES]
Definition: pngdec.c:79
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
Definition: ccaption_dec.c:520
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:78
#define PNG_IDAT
Definition: png.h:46
Y , 8bpp.
Definition: pixfmt.h:76
static av_cold int png_dec_end(AVCodecContext *avctx)
Definition: pngdec.c:1283
common internal api header.
static void handle_small_bpp(PNGDecContext *s, AVFrame *p)
Definition: pngdec.c:736
#define CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:864
#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:717
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:116
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:151
static const uint8_t png_pass_dsp_ymask[NB_PASSES]
Definition: pngdec.c:84
int den
denominator
Definition: rational.h:45
void ff_png_zfree(void *opaque, void *ptr)
Definition: png.c:44
void * priv_data
Definition: avcodec.h:1281
static int png_decode_idat(PNGDecContext *s, int length)
Definition: pngdec.c:385
uint8_t * buffer
Definition: pngdec.c:68
#define av_free(p)
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:1289
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:229
int row_size
Definition: pngdec.c:72
APNG common header.
PNGDSPContext dsp
Definition: pngdec.c:37
int compression_type
Definition: pngdec.c:52
int ff_png_pass_row_size(int pass, int bits_per_pixel, int width)
Definition: png.c:62
int height
Definition: frame.h:212
int bit_depth
Definition: pngdec.c:50
#define av_freep(p)
int color_type
Definition: pngdec.c:51
static int init_thread_copy(AVCodecContext *avctx)
Definition: alac.c:645
ThreadFrame last_picture
Definition: pngdec.c:42
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:96
#define FFSWAP(type, a, b)
Definition: common.h:84
int crow_size
Definition: pngdec.c:71
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:1950
int x_offset
Definition: pngdec.c:48
#define MKTAG(a, b, c, d)
Definition: common.h:319
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: avcodec.h:1137
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:967
int strict_std_compliance
strictly follow the standard (MPEG4, ...).
Definition: avcodec.h:2541
#define UNROLL_FILTER(op)
Definition: pngdec.c:217
#define MNGSIG
Definition: png.h:53
static int width