Libav
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 Libav.
6  *
7  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/avstring.h"
23 #include "libavutil/imgutils.h"
24 #include "libavutil/stereo3d.h"
25 
26 #include "avcodec.h"
27 #include "bytestream.h"
28 #include "internal.h"
29 #include "png.h"
30 #include "pngdsp.h"
31 
32 /* TODO:
33  * - add 2, 4 and 16 bit depth support
34  */
35 
36 #include <zlib.h>
37 
38 typedef struct PNGDecContext {
40 
43 
44  int state;
45  int width, height;
46  int bit_depth;
51  int channels;
53  int bpp;
54 
57  uint32_t palette[256];
61  int pass;
62  int crow_size; /* compressed row size (include filter type) */
63  int row_size; /* decompressed row size */
64  int pass_row_size; /* decompress row size of the current pass */
65  int y;
66  z_stream zstream;
68 
69 /* Mask to determine which y pixels can be written in a pass */
71  0xff, 0xff, 0x0f, 0xcc, 0x33, 0xff, 0x55,
72 };
73 
74 /* Mask to determine which pixels to overwrite while displaying */
76  0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff
77 };
78 
79 /* NOTE: we try to construct a good looking image at each pass. width
80  * is the original image width. We also do pixel format conversion at
81  * this stage */
82 static void png_put_interlaced_row(uint8_t *dst, int width,
83  int bits_per_pixel, int pass,
84  int color_type, const uint8_t *src)
85 {
86  int x, mask, dsp_mask, j, src_x, b, bpp;
87  uint8_t *d;
88  const uint8_t *s;
89 
90  mask = ff_png_pass_mask[pass];
91  dsp_mask = png_pass_dsp_mask[pass];
92 
93  switch (bits_per_pixel) {
94  case 1:
95  /* we must initialize the line to zero before writing to it */
96  if (pass == 0)
97  memset(dst, 0, (width + 7) >> 3);
98  src_x = 0;
99  for (x = 0; x < width; x++) {
100  j = (x & 7);
101  if ((dsp_mask << j) & 0x80) {
102  b = (src[src_x >> 3] >> (7 - (src_x & 7))) & 1;
103  dst[x >> 3] |= b << (7 - j);
104  }
105  if ((mask << j) & 0x80)
106  src_x++;
107  }
108  break;
109  default:
110  bpp = bits_per_pixel >> 3;
111  d = dst;
112  s = src;
113  if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
114  for (x = 0; x < width; x++) {
115  j = x & 7;
116  if ((dsp_mask << j) & 0x80) {
117  *(uint32_t *)d = (s[3] << 24) | (s[0] << 16) | (s[1] << 8) | s[2];
118  }
119  d += bpp;
120  if ((mask << j) & 0x80)
121  s += bpp;
122  }
123  } else {
124  for (x = 0; x < width; x++) {
125  j = x & 7;
126  if ((dsp_mask << j) & 0x80) {
127  memcpy(d, s, bpp);
128  }
129  d += bpp;
130  if ((mask << j) & 0x80)
131  s += bpp;
132  }
133  }
134  break;
135  }
136 }
137 
139  int w, int bpp)
140 {
141  int i;
142  for (i = 0; i < w; i++) {
143  int a, b, c, p, pa, pb, pc;
144 
145  a = dst[i - bpp];
146  b = top[i];
147  c = top[i - bpp];
148 
149  p = b - c;
150  pc = a - c;
151 
152  pa = abs(p);
153  pb = abs(pc);
154  pc = abs(p + pc);
155 
156  if (pa <= pb && pa <= pc)
157  p = a;
158  else if (pb <= pc)
159  p = b;
160  else
161  p = c;
162  dst[i] = p + src[i];
163  }
164 }
165 
166 #define UNROLL1(bpp, op) \
167  { \
168  r = dst[0]; \
169  if (bpp >= 2) \
170  g = dst[1]; \
171  if (bpp >= 3) \
172  b = dst[2]; \
173  if (bpp >= 4) \
174  a = dst[3]; \
175  for (; i < size; i += bpp) { \
176  dst[i + 0] = r = op(r, src[i + 0], last[i + 0]); \
177  if (bpp == 1) \
178  continue; \
179  dst[i + 1] = g = op(g, src[i + 1], last[i + 1]); \
180  if (bpp == 2) \
181  continue; \
182  dst[i + 2] = b = op(b, src[i + 2], last[i + 2]); \
183  if (bpp == 3) \
184  continue; \
185  dst[i + 3] = a = op(a, src[i + 3], last[i + 3]); \
186  } \
187  }
188 
189 #define UNROLL_FILTER(op) \
190  if (bpp == 1) { \
191  UNROLL1(1, op) \
192  } else if (bpp == 2) { \
193  UNROLL1(2, op) \
194  } else if (bpp == 3) { \
195  UNROLL1(3, op) \
196  } else if (bpp == 4) { \
197  UNROLL1(4, op) \
198  } else { \
199  for (; i < size; i += bpp) { \
200  int j; \
201  for (j = 0; j < bpp; j++) \
202  dst[i + j] = op(dst[i + j - bpp], src[i + j], last[i + j]); \
203  } \
204  }
205 
206 /* NOTE: 'dst' can be equal to 'last' */
208  uint8_t *src, uint8_t *last, int size, int bpp)
209 {
210  int i, p, r, g, b, a;
211 
212  switch (filter_type) {
214  memcpy(dst, src, size);
215  break;
217  for (i = 0; i < bpp; i++)
218  dst[i] = src[i];
219  if (bpp == 4) {
220  p = *(int *)dst;
221  for (; i < size; i += bpp) {
222  int s = *(int *)(src + i);
223  p = ((s & 0x7f7f7f7f) + (p & 0x7f7f7f7f)) ^ ((s ^ p) & 0x80808080);
224  *(int *)(dst + i) = p;
225  }
226  } else {
227 #define OP_SUB(x, s, l) x + s
229  }
230  break;
231  case PNG_FILTER_VALUE_UP:
232  dsp->add_bytes_l2(dst, src, last, size);
233  break;
235  for (i = 0; i < bpp; i++) {
236  p = (last[i] >> 1);
237  dst[i] = p + src[i];
238  }
239 #define OP_AVG(x, s, l) (((x + l) >> 1) + s) & 0xff
241  break;
243  for (i = 0; i < bpp; i++) {
244  p = last[i];
245  dst[i] = p + src[i];
246  }
247  if (bpp > 2 && size > 4) {
248  /* would write off the end of the array if we let it process
249  * the last pixel with bpp=3 */
250  int w = bpp == 4 ? size : size - 3;
251  dsp->add_paeth_prediction(dst + i, src + i, last + i, w - i, bpp);
252  i = w;
253  }
254  ff_add_png_paeth_prediction(dst + i, src + i, last + i, size - i, bpp);
255  break;
256  }
257 }
258 
260  const uint8_t *src,
261  int width, int loco)
262 {
263  int j;
264  unsigned int r, g, b, a;
265 
266  for (j = 0; j < width; j++) {
267  r = src[0];
268  g = src[1];
269  b = src[2];
270  a = src[3];
271  if (loco) {
272  r = (r + g) & 0xff;
273  b = (b + g) & 0xff;
274  }
275  *(uint32_t *) dst = (a << 24) | (r << 16) | (g << 8) | b;
276  dst += 4;
277  src += 4;
278  }
279 }
280 
281 static void convert_to_rgb32(uint8_t *dst, const uint8_t *src,
282  int width, int loco)
283 {
284  if (loco)
285  convert_to_rgb32_loco(dst, src, width, 1);
286  else
287  convert_to_rgb32_loco(dst, src, width, 0);
288 }
289 
290 static void deloco_rgb24(uint8_t *dst, int size)
291 {
292  int i;
293  for (i = 0; i < size; i += 3) {
294  int g = dst[i + 1];
295  dst[i + 0] += g;
296  dst[i + 2] += g;
297  }
298 }
299 
300 /* process exactly one decompressed row */
302 {
303  uint8_t *ptr, *last_row;
304  int got_line;
305 
306  if (!s->interlace_type) {
307  ptr = s->image_buf + s->image_linesize * s->y;
308  /* need to swap bytes correctly for RGB_ALPHA */
310  png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
311  s->last_row, s->row_size, s->bpp);
312  convert_to_rgb32(ptr, s->tmp_row, s->width,
314  FFSWAP(uint8_t *, s->last_row, s->tmp_row);
315  } else {
316  /* in normal case, we avoid one copy */
317  if (s->y == 0)
318  last_row = s->last_row;
319  else
320  last_row = ptr - s->image_linesize;
321 
322  png_filter_row(&s->dsp, ptr, s->crow_buf[0], s->crow_buf + 1,
323  last_row, s->row_size, s->bpp);
324  }
325  /* loco lags by 1 row so that it doesn't interfere with top prediction */
326  if (s->filter_type == PNG_FILTER_TYPE_LOCO &&
327  s->color_type == PNG_COLOR_TYPE_RGB && s->y > 0)
328  deloco_rgb24(ptr - s->image_linesize, s->row_size);
329  s->y++;
330  if (s->y == s->height) {
331  s->state |= PNG_ALLIMAGE;
332  if (s->filter_type == PNG_FILTER_TYPE_LOCO &&
334  deloco_rgb24(ptr, s->row_size);
335  }
336  } else {
337  got_line = 0;
338  for (;;) {
339  ptr = s->image_buf + s->image_linesize * s->y;
340  if ((ff_png_pass_ymask[s->pass] << (s->y & 7)) & 0x80) {
341  /* if we already read one row, it is time to stop to
342  * wait for the next one */
343  if (got_line)
344  break;
345  png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
346  s->last_row, s->pass_row_size, s->bpp);
347  FFSWAP(uint8_t *, s->last_row, s->tmp_row);
348  got_line = 1;
349  }
350  if ((png_pass_dsp_ymask[s->pass] << (s->y & 7)) & 0x80) {
351  /* NOTE: RGB32 is handled directly in png_put_interlaced_row */
353  s->color_type, s->last_row);
354  }
355  s->y++;
356  if (s->y == s->height) {
357  for (;;) {
358  if (s->pass == NB_PASSES - 1) {
359  s->state |= PNG_ALLIMAGE;
360  goto the_end;
361  } else {
362  s->pass++;
363  s->y = 0;
365  s->bits_per_pixel,
366  s->width);
367  s->crow_size = s->pass_row_size + 1;
368  if (s->pass_row_size != 0)
369  break;
370  /* skip pass if empty row */
371  }
372  }
373  }
374  }
375 the_end:;
376  }
377 }
378 
379 static int png_decode_idat(PNGDecContext *s, int length)
380 {
381  int ret;
382  s->zstream.avail_in = FFMIN(length, bytestream2_get_bytes_left(&s->gb));
383  s->zstream.next_in = s->gb.buffer;
384  bytestream2_skip(&s->gb, length);
385 
386  /* decode one line if possible */
387  while (s->zstream.avail_in > 0) {
388  ret = inflate(&s->zstream, Z_PARTIAL_FLUSH);
389  if (ret != Z_OK && ret != Z_STREAM_END) {
390  return -1;
391  }
392  if (s->zstream.avail_out == 0) {
393  if (!(s->state & PNG_ALLIMAGE)) {
394  png_handle_row(s);
395  }
396  s->zstream.avail_out = s->crow_size;
397  s->zstream.next_out = s->crow_buf;
398  }
399  if (ret == Z_STREAM_END && s->zstream.avail_in > 0) {
401  "%d undecompressed bytes left in buffer\n", s->zstream.avail_in);
402  return 0;
403  }
404  }
405  return 0;
406 }
407 
408 static int decode_frame(AVCodecContext *avctx,
409  void *data, int *got_frame,
410  AVPacket *avpkt)
411 {
412  PNGDecContext *const s = avctx->priv_data;
413  const uint8_t *buf = avpkt->data;
414  int buf_size = avpkt->size;
415  AVFrame *p = data;
416  uint8_t *crow_buf_base = NULL;
417  uint32_t tag, length;
418  int ret;
419 
420  /* check signature */
421  if (buf_size < 8) {
422  av_log(avctx, AV_LOG_ERROR, "Not enough data %d\n",
423  buf_size);
424  return AVERROR_INVALIDDATA;
425  }
426  if (memcmp(buf, ff_pngsig, 8) != 0 &&
427  memcmp(buf, ff_mngsig, 8) != 0) {
428  char signature[5 * 8 + 1] = { 0 };
429  int i;
430  for (i = 0; i < 8; i++) {
431  av_strlcatf(signature + i * 5, sizeof(signature) - i * 5,
432  " 0x%02x", buf[i]);
433  }
434  av_log(avctx, AV_LOG_ERROR, "Invalid PNG signature %s\n",
435  signature);
436  return AVERROR_INVALIDDATA;
437  }
438 
439  bytestream2_init(&s->gb, buf + 8, buf_size - 8);
440  s->y = s->state = 0;
441 
442  /* init the zlib */
443  s->zstream.zalloc = ff_png_zalloc;
444  s->zstream.zfree = ff_png_zfree;
445  s->zstream.opaque = NULL;
446  ret = inflateInit(&s->zstream);
447  if (ret != Z_OK)
448  return -1;
449  for (;;) {
450  if (bytestream2_get_bytes_left(&s->gb) <= 0)
451  goto fail;
452  length = bytestream2_get_be32(&s->gb);
453  if (length > 0x7fffffff)
454  goto fail;
455  tag = bytestream2_get_le32(&s->gb);
456  ff_dlog(avctx, "png: tag=%c%c%c%c length=%u\n",
457  (tag & 0xff),
458  ((tag >> 8) & 0xff),
459  ((tag >> 16) & 0xff),
460  ((tag >> 24) & 0xff), length);
461  switch (tag) {
462  case MKTAG('I', 'H', 'D', 'R'):
463  if (length != 13)
464  goto fail;
465  s->width = bytestream2_get_be32(&s->gb);
466  s->height = bytestream2_get_be32(&s->gb);
467  if (av_image_check_size(s->width, s->height, 0, avctx)) {
468  s->width = s->height = 0;
469  goto fail;
470  }
471  s->bit_depth = bytestream2_get_byte(&s->gb);
472  s->color_type = bytestream2_get_byte(&s->gb);
473  s->compression_type = bytestream2_get_byte(&s->gb);
474  s->filter_type = bytestream2_get_byte(&s->gb);
475  s->interlace_type = bytestream2_get_byte(&s->gb);
476  bytestream2_skip(&s->gb, 4); /* crc */
477  s->state |= PNG_IHDR;
478  ff_dlog(avctx, "width=%d height=%d depth=%d color_type=%d "
479  "compression_type=%d filter_type=%d interlace_type=%d\n",
480  s->width, s->height, s->bit_depth, s->color_type,
482  break;
483  case MKTAG('I', 'D', 'A', 'T'):
484  if (!(s->state & PNG_IHDR))
485  goto fail;
486  if (!(s->state & PNG_IDAT)) {
487  /* init image info */
488  avctx->width = s->width;
489  avctx->height = s->height;
490 
492  s->bits_per_pixel = s->bit_depth * s->channels;
493  s->bpp = (s->bits_per_pixel + 7) >> 3;
494  s->row_size = (avctx->width * s->bits_per_pixel + 7) >> 3;
495 
496  if (s->bit_depth == 8 &&
498  avctx->pix_fmt = AV_PIX_FMT_RGB24;
499  } else if (s->bit_depth == 8 &&
501  avctx->pix_fmt = AV_PIX_FMT_RGB32;
502  } else if (s->bit_depth == 8 &&
504  avctx->pix_fmt = AV_PIX_FMT_GRAY8;
505  } else if (s->bit_depth == 16 &&
507  avctx->pix_fmt = AV_PIX_FMT_GRAY16BE;
508  } else if (s->bit_depth == 16 &&
510  avctx->pix_fmt = AV_PIX_FMT_RGB48BE;
511  } else if (s->bit_depth == 1 &&
513  avctx->pix_fmt = AV_PIX_FMT_MONOBLACK;
514  } else if (s->bit_depth == 8 &&
516  avctx->pix_fmt = AV_PIX_FMT_PAL8;
517  } else if (s->bit_depth == 8 &&
519  avctx->pix_fmt = AV_PIX_FMT_YA8;
520  } else if (s->bit_depth == 16 &&
522  avctx->pix_fmt = AV_PIX_FMT_YA16BE;
523  } else {
524  goto fail;
525  }
526 
527  if (ff_get_buffer(avctx, p, AV_GET_BUFFER_FLAG_REF) < 0) {
528  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
529  goto fail;
530  }
532  p->key_frame = 1;
534 
535  /* compute the compressed row size */
536  if (!s->interlace_type) {
537  s->crow_size = s->row_size + 1;
538  } else {
539  s->pass = 0;
541  s->bits_per_pixel,
542  s->width);
543  s->crow_size = s->pass_row_size + 1;
544  }
545  ff_dlog(avctx, "row_size=%d crow_size =%d\n",
546  s->row_size, s->crow_size);
547  s->image_buf = p->data[0];
548  s->image_linesize = p->linesize[0];
549  /* copy the palette if needed */
551  memcpy(p->data[1], s->palette, 256 * sizeof(uint32_t));
552  /* empty row is used if differencing to the first row */
553  s->last_row = av_mallocz(s->row_size);
554  if (!s->last_row)
555  goto fail;
556  if (s->interlace_type ||
558  s->tmp_row = av_malloc(s->row_size);
559  if (!s->tmp_row)
560  goto fail;
561  }
562  /* compressed row */
563  crow_buf_base = av_malloc(s->row_size + 16);
564  if (!crow_buf_base)
565  goto fail;
566 
567  /* we want crow_buf+1 to be 16-byte aligned */
568  s->crow_buf = crow_buf_base + 15;
569  s->zstream.avail_out = s->crow_size;
570  s->zstream.next_out = s->crow_buf;
571  }
572  s->state |= PNG_IDAT;
573  if (png_decode_idat(s, length) < 0)
574  goto fail;
575  bytestream2_skip(&s->gb, 4); /* crc */
576  break;
577  case MKTAG('P', 'L', 'T', 'E'):
578  {
579  int n, i, r, g, b;
580 
581  if ((length % 3) != 0 || length > 256 * 3)
582  goto skip_tag;
583  /* read the palette */
584  n = length / 3;
585  for (i = 0; i < n; i++) {
586  r = bytestream2_get_byte(&s->gb);
587  g = bytestream2_get_byte(&s->gb);
588  b = bytestream2_get_byte(&s->gb);
589  s->palette[i] = (0xff << 24) | (r << 16) | (g << 8) | b;
590  }
591  for (; i < 256; i++)
592  s->palette[i] = (0xff << 24);
593  s->state |= PNG_PLTE;
594  bytestream2_skip(&s->gb, 4); /* crc */
595  }
596  break;
597  case MKTAG('t', 'R', 'N', 'S'):
598  {
599  int v, i;
600 
601  /* read the transparency. XXX: Only palette mode supported */
603  length > 256 ||
604  !(s->state & PNG_PLTE))
605  goto skip_tag;
606  for (i = 0; i < length; i++) {
607  v = bytestream2_get_byte(&s->gb);
608  s->palette[i] = (s->palette[i] & 0x00ffffff) | (v << 24);
609  }
610  bytestream2_skip(&s->gb, 4); /* crc */
611  }
612  break;
613  case MKTAG('s', 'T', 'E', 'R'): {
614  int mode = bytestream2_get_byte(&s->gb);
616  if (!stereo3d)
617  goto the_end;
618 
619  if (mode == 0 || mode == 1) {
620  stereo3d->type = AV_STEREO3D_SIDEBYSIDE;
621  stereo3d->flags = mode ? 0 : AV_STEREO3D_FLAG_INVERT;
622  } else {
623  av_log(avctx, AV_LOG_WARNING,
624  "Unknown value in sTER chunk (%d)\n", mode);
625  }
626  bytestream2_skip(&s->gb, 4); /* crc */
627  break;
628  }
629  case MKTAG('I', 'E', 'N', 'D'):
630  if (!(s->state & PNG_ALLIMAGE))
631  goto fail;
632  bytestream2_skip(&s->gb, 4); /* crc */
633  goto exit_loop;
634  default:
635  /* skip tag */
636 skip_tag:
637  bytestream2_skip(&s->gb, length + 4);
638  break;
639  }
640  }
641 exit_loop:
642  /* handle P-frames only if a predecessor frame is available */
643  if (s->prev->data[0]) {
644  if (!(avpkt->flags & AV_PKT_FLAG_KEY)) {
645  int i, j;
646  uint8_t *pd = p->data[0];
647  uint8_t *pd_last = s->prev->data[0];
648 
649  for (j = 0; j < s->height; j++) {
650  for (i = 0; i < s->width * s->bpp; i++)
651  pd[i] += pd_last[i];
652  pd += s->image_linesize;
653  pd_last += s->image_linesize;
654  }
655  }
656  }
657 
658  av_frame_unref(s->prev);
659  if ((ret = av_frame_ref(s->prev, p)) < 0)
660  goto fail;
661 
662  *got_frame = 1;
663 
664  ret = bytestream2_tell(&s->gb);
665 the_end:
666  inflateEnd(&s->zstream);
667  av_free(crow_buf_base);
668  s->crow_buf = NULL;
669  av_freep(&s->last_row);
670  av_freep(&s->tmp_row);
671  return ret;
672 fail:
673  ret = -1;
674  goto the_end;
675 }
676 
678 {
679  PNGDecContext *s = avctx->priv_data;
680 
681  avctx->color_range = AVCOL_RANGE_JPEG;
682 
683  s->prev = av_frame_alloc();
684  if (!s->prev)
685  return AVERROR(ENOMEM);
686 
687  ff_pngdsp_init(&s->dsp);
688 
689  return 0;
690 }
691 
693 {
694  PNGDecContext *s = avctx->priv_data;
695 
696  av_frame_free(&s->prev);
697 
698  return 0;
699 }
700 
702  .name = "png",
703  .long_name = NULL_IF_CONFIG_SMALL("PNG (Portable Network Graphics) image"),
704  .type = AVMEDIA_TYPE_VIDEO,
705  .id = AV_CODEC_ID_PNG,
706  .priv_data_size = sizeof(PNGDecContext),
707  .init = png_dec_init,
708  .close = png_dec_end,
709  .decode = decode_frame,
710  .capabilities = AV_CODEC_CAP_DR1 /*| AV_CODEC_CAP_DRAW_HORIZ_BAND*/,
711 };
AVFrame * prev
Definition: pngdec.c:42
#define PNG_FILTER_VALUE_AVG
Definition: png.h:41
static void png_handle_row(PNGDecContext *s)
Definition: pngdec.c:301
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
int size
This structure describes decoded (raw) audio or video data.
Definition: frame.h:140
int width
Definition: pngdec.c:45
8 bits gray, 8 bits alpha
Definition: pixfmt.h:143
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:130
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:61
int pass_row_size
Definition: pngdec.c:64
uint8_t * tmp_row
Definition: pngdec.c:60
#define PNG_PLTE
Definition: png.h:48
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:2127
int size
Definition: avcodec.h:1347
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, 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)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1621
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:132
#define PNG_COLOR_TYPE_RGB
Definition: png.h:33
void(* add_bytes_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
Definition: pngdsp.h:28
#define PNG_COLOR_TYPE_GRAY_ALPHA
Definition: png.h:35
AVCodec.
Definition: avcodec.h:3120
#define PNG_COLOR_TYPE_PALETTE
Definition: png.h:32
#define PNG_IHDR
Definition: png.h:45
int filter_type
Definition: pngdec.c:50
void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
Definition: pngdec.c:138
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:202
#define PNG_FILTER_VALUE_PAETH
Definition: png.h:42
AVCodec ff_png_decoder
Definition: pngdec.c:701
int state
Definition: pngdec.c:44
static const char signature[]
Definition: ipmovie.c:525
uint8_t
#define av_cold
Definition: attributes.h:66
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:68
#define PNG_COLOR_TYPE_RGB_ALPHA
Definition: png.h:34
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:70
Stereo 3D type: this structure describes how two videos are packed within a single video surface...
Definition: stereo3d.h:123
#define b
Definition: input.c:52
#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:199
const char data[16]
Definition: mxf.c:70
uint8_t * data
Definition: avcodec.h:1346
const uint8_t * buffer
Definition: bytestream.h:33
uint32_t tag
Definition: movenc.c:854
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:263
#define r
Definition: input.c:51
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1378
#define src
Definition: vp8dsp.c:254
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:124
static const uint8_t png_pass_dsp_mask[NB_PASSES]
Definition: pngdec.c:75
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:190
int flags
Additional information about the frame packing.
Definition: stereo3d.h:132
16 bits gray, 16 bits alpha (big-endian)
Definition: pixfmt.h:205
static const uint16_t mask[17]
Definition: lzw.c:38
#define OP_SUB(x, s, l)
#define AVERROR(e)
Definition: error.h:43
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:161
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:80
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:148
uint8_t * crow_buf
Definition: pngdec.c:58
g
Definition: yuv2rgb.c:546
int pass
Definition: pngdec.c:61
int ff_png_get_nb_channels(int color_type)
Definition: png.c:58
int height
Definition: pngdec.c:45
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:151
const char * name
Name of the codec implementation.
Definition: avcodec.h:3127
int bits_per_pixel
Definition: pngdec.c:52
GetByteContext gb
Definition: pngdec.c:41
#define NB_PASSES
Definition: png.h:50
#define fail()
Definition: checkasm.h:80
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1352
z_stream zstream
Definition: pngdec.c:66
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:223
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:201
#define FFMIN(a, b)
Definition: common.h:66
#define PNG_FILTER_VALUE_SUB
Definition: png.h:39
const uint8_t ff_mngsig[8]
Definition: png.c:26
uint32_t palette[256]
Definition: pngdec.c:57
#define PNG_COLOR_TYPE_GRAY
Definition: png.h:31
static void png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type, uint8_t *src, uint8_t *last, int size, int bpp)
Definition: pngdec.c:207
int width
picture width / height.
Definition: avcodec.h:1580
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
Definition: avconv.c:1288
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
Definition: stereo3d.h:114
uint8_t * last_row
Definition: pngdec.c:59
av_cold void ff_pngdsp_init(PNGDSPContext *dsp)
Definition: pngdsp.c:43
int channels
Definition: pngdec.c:51
the normal 2^n-1 "JPEG" YUV ranges
Definition: pixfmt.h:365
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:185
static av_cold int png_dec_init(AVCodecContext *avctx)
Definition: pngdec.c:677
NULL
Definition: eval.c:55
enum AVStereo3DType type
How views are packed within the video.
Definition: stereo3d.h:127
Libavcodec external API header.
#define ff_dlog(ctx,...)
Definition: internal.h:60
static int skip_tag(AVIOContext *in, int32_t tag_name)
Definition: ismindex.c:132
#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:158
#define PNG_FILTER_TYPE_LOCO
Definition: png.h:37
main external API structure.
Definition: avcodec.h:1409
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:242
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:589
const uint8_t ff_png_pass_mask[NB_PASSES]
Definition: png.c:44
int interlace_type
Definition: pngdec.c:49
const uint8_t ff_png_pass_ymask[NB_PASSES]
Definition: png.c:29
int image_linesize
Definition: pngdec.c:56
Y , 16bpp, big-endian.
Definition: pixfmt.h:94
#define OP_AVG(x, s, l)
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:99
uint8_t * image_buf
Definition: pngdec.c:55
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:302
AVStereo3D * av_stereo3d_create_side_data(AVFrame *frame)
Allocate a complete AVFrameSideData and add it to the frame.
Definition: stereo3d.c:33
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:146
Views are next to each other.
Definition: stereo3d.h:45
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:69
#define PNG_IDAT
Definition: png.h:46
Y , 8bpp.
Definition: pixfmt.h:67
static av_cold int png_dec_end(AVCodecContext *avctx)
Definition: pngdec.c:692
void(* add_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
Definition: pngdsp.h:33
common internal api header.
#define PNG_FILTER_VALUE_NONE
Definition: png.h:38
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:106
static const uint8_t png_pass_dsp_ymask[NB_PASSES]
Definition: pngdec.c:70
const uint8_t ff_pngsig[8]
Definition: png.c:25
void ff_png_zfree(void *opaque, void *ptr)
Definition: png.c:53
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:582
static void convert_to_rgb32(uint8_t *dst, const uint8_t *src, int width, int loco)
Definition: pngdec.c:281
static av_always_inline void convert_to_rgb32_loco(uint8_t *dst, const uint8_t *src, int width, int loco)
Definition: pngdec.c:259
void * priv_data
Definition: avcodec.h:1451
static int png_decode_idat(PNGDecContext *s, int length)
Definition: pngdec.c:379
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:196
int row_size
Definition: pngdec.c:63
PNGDSPContext dsp
Definition: pngdec.c:39
int compression_type
Definition: pngdec.c:48
int ff_png_pass_row_size(int pass, int bits_per_pixel, int width)
Definition: png.c:71
int bit_depth
Definition: pngdec.c:46
int color_type
Definition: pngdec.c:47
#define av_always_inline
Definition: attributes.h:40
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:82
#define FFSWAP(type, a, b)
Definition: common.h:69
int crow_size
Definition: pngdec.c:62
#define MKTAG(a, b, c, d)
Definition: common.h:256
void * ff_png_zalloc(void *opaque, unsigned int items, unsigned int size)
Definition: png.c:48
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: pngdec.c:408
This structure stores compressed data.
Definition: avcodec.h:1323
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:1183
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:211
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:838
#define UNROLL_FILTER(op)
Definition: pngdec.c:189
static void deloco_rgb24(uint8_t *dst, int size)
Definition: pngdec.c:290