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 #include "libavutil/imgutils.h"
22 #include "avcodec.h"
23 #include "bytestream.h"
24 #include "internal.h"
25 #include "png.h"
26 #include "pngdsp.h"
27 
28 /* TODO:
29  * - add 2, 4 and 16 bit depth support
30  */
31 
32 #include <zlib.h>
33 
34 //#define DEBUG
35 
36 typedef struct PNGDecContext {
38 
42 
43  int state;
44  int width, height;
45  int bit_depth;
50  int channels;
52  int bpp;
53 
56  uint32_t palette[256];
60  int pass;
61  int crow_size; /* compressed row size (include filter type) */
62  int row_size; /* decompressed row size */
63  int pass_row_size; /* decompress row size of the current pass */
64  int y;
65  z_stream zstream;
67 
68 /* Mask to determine which y pixels can be written in a pass */
70  0xff, 0xff, 0x0f, 0xcc, 0x33, 0xff, 0x55,
71 };
72 
73 /* Mask to determine which pixels to overwrite while displaying */
75  0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff
76 };
77 
78 /* NOTE: we try to construct a good looking image at each pass. width
79  is the original image width. We also do pixel format conversion at
80  this stage */
81 static void png_put_interlaced_row(uint8_t *dst, int width,
82  int bits_per_pixel, int pass,
83  int color_type, const uint8_t *src)
84 {
85  int x, mask, dsp_mask, j, src_x, b, bpp;
86  uint8_t *d;
87  const uint8_t *s;
88 
89  mask = ff_png_pass_mask[pass];
90  dsp_mask = png_pass_dsp_mask[pass];
91  switch(bits_per_pixel) {
92  case 1:
93  /* we must initialize the line to zero before writing to it */
94  if (pass == 0)
95  memset(dst, 0, (width + 7) >> 3);
96  src_x = 0;
97  for(x = 0; x < width; x++) {
98  j = (x & 7);
99  if ((dsp_mask << j) & 0x80) {
100  b = (src[src_x >> 3] >> (7 - (src_x & 7))) & 1;
101  dst[x >> 3] |= b << (7 - j);
102  }
103  if ((mask << j) & 0x80)
104  src_x++;
105  }
106  break;
107  default:
108  bpp = bits_per_pixel >> 3;
109  d = dst;
110  s = src;
111  if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
112  for(x = 0; x < width; x++) {
113  j = x & 7;
114  if ((dsp_mask << j) & 0x80) {
115  *(uint32_t *)d = (s[3] << 24) | (s[0] << 16) | (s[1] << 8) | s[2];
116  }
117  d += bpp;
118  if ((mask << j) & 0x80)
119  s += bpp;
120  }
121  } else {
122  for(x = 0; x < width; x++) {
123  j = x & 7;
124  if ((dsp_mask << j) & 0x80) {
125  memcpy(d, s, bpp);
126  }
127  d += bpp;
128  if ((mask << j) & 0x80)
129  s += bpp;
130  }
131  }
132  break;
133  }
134 }
135 
136 void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
137 {
138  int i;
139  for(i = 0; i < w; i++) {
140  int a, b, c, p, pa, pb, pc;
141 
142  a = dst[i - bpp];
143  b = top[i];
144  c = top[i - bpp];
145 
146  p = b - c;
147  pc = a - c;
148 
149  pa = abs(p);
150  pb = abs(pc);
151  pc = abs(p + pc);
152 
153  if (pa <= pb && pa <= pc)
154  p = a;
155  else if (pb <= pc)
156  p = b;
157  else
158  p = c;
159  dst[i] = p + src[i];
160  }
161 }
162 
163 #define UNROLL1(bpp, op) {\
164  r = dst[0];\
165  if(bpp >= 2) g = dst[1];\
166  if(bpp >= 3) b = dst[2];\
167  if(bpp >= 4) a = dst[3];\
168  for(; i < size; i+=bpp) {\
169  dst[i+0] = r = op(r, src[i+0], last[i+0]);\
170  if(bpp == 1) continue;\
171  dst[i+1] = g = op(g, src[i+1], last[i+1]);\
172  if(bpp == 2) continue;\
173  dst[i+2] = b = op(b, src[i+2], last[i+2]);\
174  if(bpp == 3) continue;\
175  dst[i+3] = a = op(a, src[i+3], last[i+3]);\
176  }\
177 }
178 
179 #define UNROLL_FILTER(op)\
180  if(bpp == 1) UNROLL1(1, op)\
181  else if(bpp == 2) UNROLL1(2, op)\
182  else if(bpp == 3) UNROLL1(3, op)\
183  else if(bpp == 4) UNROLL1(4, op)\
184  else {\
185  for (; i < size; i += bpp) {\
186  int j;\
187  for (j = 0; j < bpp; j++)\
188  dst[i+j] = op(dst[i+j-bpp], src[i+j], last[i+j]);\
189  }\
190  }
191 
192 /* NOTE: 'dst' can be equal to 'last' */
193 static void png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type,
194  uint8_t *src, uint8_t *last, int size, int bpp)
195 {
196  int i, p, r, g, b, a;
197 
198  switch(filter_type) {
200  memcpy(dst, src, size);
201  break;
203  for(i = 0; i < bpp; i++) {
204  dst[i] = src[i];
205  }
206  if(bpp == 4) {
207  p = *(int*)dst;
208  for(; i < size; i+=bpp) {
209  int s = *(int*)(src+i);
210  p = ((s&0x7f7f7f7f) + (p&0x7f7f7f7f)) ^ ((s^p)&0x80808080);
211  *(int*)(dst+i) = p;
212  }
213  } else {
214 #define OP_SUB(x,s,l) x+s
216  }
217  break;
218  case PNG_FILTER_VALUE_UP:
219  dsp->add_bytes_l2(dst, src, last, size);
220  break;
222  for(i = 0; i < bpp; i++) {
223  p = (last[i] >> 1);
224  dst[i] = p + src[i];
225  }
226 #define OP_AVG(x,s,l) (((x + l) >> 1) + s) & 0xff
228  break;
230  for(i = 0; i < bpp; i++) {
231  p = last[i];
232  dst[i] = p + src[i];
233  }
234  if(bpp > 1 && size > 4) {
235  // would write off the end of the array if we let it process the last pixel with bpp=3
236  int w = bpp==4 ? size : size-3;
237  dsp->add_paeth_prediction(dst+i, src+i, last+i, w-i, bpp);
238  i = w;
239  }
240  ff_add_png_paeth_prediction(dst+i, src+i, last+i, size-i, bpp);
241  break;
242  }
243 }
244 
245 static av_always_inline void convert_to_rgb32_loco(uint8_t *dst, const uint8_t *src, int width, int loco)
246 {
247  int j;
248  unsigned int r, g, b, a;
249 
250  for(j = 0;j < width; j++) {
251  r = src[0];
252  g = src[1];
253  b = src[2];
254  a = src[3];
255  if(loco) {
256  r = (r+g)&0xff;
257  b = (b+g)&0xff;
258  }
259  *(uint32_t *)dst = (a << 24) | (r << 16) | (g << 8) | b;
260  dst += 4;
261  src += 4;
262  }
263 }
264 
265 static void convert_to_rgb32(uint8_t *dst, const uint8_t *src, int width, int loco)
266 {
267  if(loco)
268  convert_to_rgb32_loco(dst, src, width, 1);
269  else
270  convert_to_rgb32_loco(dst, src, width, 0);
271 }
272 
273 static void deloco_rgb24(uint8_t *dst, int size)
274 {
275  int i;
276  for(i=0; i<size; i+=3) {
277  int g = dst[i+1];
278  dst[i+0] += g;
279  dst[i+2] += g;
280  }
281 }
282 
283 /* process exactly one decompressed row */
285 {
286  uint8_t *ptr, *last_row;
287  int got_line;
288 
289  if (!s->interlace_type) {
290  ptr = s->image_buf + s->image_linesize * s->y;
291  /* need to swap bytes correctly for RGB_ALPHA */
293  png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
294  s->last_row, s->row_size, s->bpp);
296  FFSWAP(uint8_t*, s->last_row, s->tmp_row);
297  } else {
298  /* in normal case, we avoid one copy */
299  if (s->y == 0)
300  last_row = s->last_row;
301  else
302  last_row = ptr - s->image_linesize;
303 
304  png_filter_row(&s->dsp, ptr, s->crow_buf[0], s->crow_buf + 1,
305  last_row, s->row_size, s->bpp);
306  }
307  /* loco lags by 1 row so that it doesn't interfere with top prediction */
308  if (s->filter_type == PNG_FILTER_TYPE_LOCO &&
309  s->color_type == PNG_COLOR_TYPE_RGB && s->y > 0)
310  deloco_rgb24(ptr - s->image_linesize, s->row_size);
311  s->y++;
312  if (s->y == s->height) {
313  s->state |= PNG_ALLIMAGE;
314  if (s->filter_type == PNG_FILTER_TYPE_LOCO &&
316  deloco_rgb24(ptr, s->row_size);
317  }
318  } else {
319  got_line = 0;
320  for(;;) {
321  ptr = s->image_buf + s->image_linesize * s->y;
322  if ((ff_png_pass_ymask[s->pass] << (s->y & 7)) & 0x80) {
323  /* if we already read one row, it is time to stop to
324  wait for the next one */
325  if (got_line)
326  break;
327  png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
328  s->last_row, s->pass_row_size, s->bpp);
329  FFSWAP(uint8_t*, s->last_row, s->tmp_row);
330  got_line = 1;
331  }
332  if ((png_pass_dsp_ymask[s->pass] << (s->y & 7)) & 0x80) {
333  /* NOTE: RGB32 is handled directly in png_put_interlaced_row */
335  s->color_type, s->last_row);
336  }
337  s->y++;
338  if (s->y == s->height) {
339  for(;;) {
340  if (s->pass == NB_PASSES - 1) {
341  s->state |= PNG_ALLIMAGE;
342  goto the_end;
343  } else {
344  s->pass++;
345  s->y = 0;
347  s->bits_per_pixel,
348  s->width);
349  s->crow_size = s->pass_row_size + 1;
350  if (s->pass_row_size != 0)
351  break;
352  /* skip pass if empty row */
353  }
354  }
355  }
356  }
357  the_end: ;
358  }
359 }
360 
361 static int png_decode_idat(PNGDecContext *s, int length)
362 {
363  int ret;
364  s->zstream.avail_in = FFMIN(length, bytestream2_get_bytes_left(&s->gb));
365  s->zstream.next_in = s->gb.buffer;
366  bytestream2_skip(&s->gb, length);
367 
368  /* decode one line if possible */
369  while (s->zstream.avail_in > 0) {
370  ret = inflate(&s->zstream, Z_PARTIAL_FLUSH);
371  if (ret != Z_OK && ret != Z_STREAM_END) {
372  return -1;
373  }
374  if (s->zstream.avail_out == 0) {
375  if (!(s->state & PNG_ALLIMAGE)) {
376  png_handle_row(s);
377  }
378  s->zstream.avail_out = s->crow_size;
379  s->zstream.next_out = s->crow_buf;
380  }
381  if (ret == Z_STREAM_END && s->zstream.avail_in > 0) {
382  av_log(NULL, AV_LOG_WARNING, "%d undecompressed bytes left in buffer\n", s->zstream.avail_in);
383  return 0;
384  }
385  }
386  return 0;
387 }
388 
389 static int decode_frame(AVCodecContext *avctx,
390  void *data, int *got_frame,
391  AVPacket *avpkt)
392 {
393  const uint8_t *buf = avpkt->data;
394  int buf_size = avpkt->size;
395  PNGDecContext * const s = avctx->priv_data;
396  AVFrame *picture = data;
397  AVFrame *p;
398  uint8_t *crow_buf_base = NULL;
399  uint32_t tag, length;
400  int ret;
401 
403  avctx->coded_frame= s->current_picture;
404  p = s->current_picture;
405 
406  /* check signature */
407  if (buf_size < 8 ||
408  memcmp(buf, ff_pngsig, 8) != 0 &&
409  memcmp(buf, ff_mngsig, 8) != 0)
410  return -1;
411 
412  bytestream2_init(&s->gb, buf + 8, buf_size - 8);
413  s->y=
414  s->state=0;
415 // memset(s, 0, sizeof(PNGDecContext));
416  /* init the zlib */
417  s->zstream.zalloc = ff_png_zalloc;
418  s->zstream.zfree = ff_png_zfree;
419  s->zstream.opaque = NULL;
420  ret = inflateInit(&s->zstream);
421  if (ret != Z_OK)
422  return -1;
423  for(;;) {
424  if (bytestream2_get_bytes_left(&s->gb) <= 0)
425  goto fail;
426  length = bytestream2_get_be32(&s->gb);
427  if (length > 0x7fffffff)
428  goto fail;
429  tag = bytestream2_get_le32(&s->gb);
430  av_dlog(avctx, "png: tag=%c%c%c%c length=%u\n",
431  (tag & 0xff),
432  ((tag >> 8) & 0xff),
433  ((tag >> 16) & 0xff),
434  ((tag >> 24) & 0xff), length);
435  switch(tag) {
436  case MKTAG('I', 'H', 'D', 'R'):
437  if (length != 13)
438  goto fail;
439  s->width = bytestream2_get_be32(&s->gb);
440  s->height = bytestream2_get_be32(&s->gb);
441  if(av_image_check_size(s->width, s->height, 0, avctx)){
442  s->width= s->height= 0;
443  goto fail;
444  }
445  s->bit_depth = bytestream2_get_byte(&s->gb);
446  s->color_type = bytestream2_get_byte(&s->gb);
447  s->compression_type = bytestream2_get_byte(&s->gb);
448  s->filter_type = bytestream2_get_byte(&s->gb);
449  s->interlace_type = bytestream2_get_byte(&s->gb);
450  bytestream2_skip(&s->gb, 4); /* crc */
451  s->state |= PNG_IHDR;
452  av_dlog(avctx, "width=%d height=%d depth=%d color_type=%d compression_type=%d filter_type=%d interlace_type=%d\n",
453  s->width, s->height, s->bit_depth, s->color_type,
455  break;
456  case MKTAG('I', 'D', 'A', 'T'):
457  if (!(s->state & PNG_IHDR))
458  goto fail;
459  if (!(s->state & PNG_IDAT)) {
460  /* init image info */
461  avctx->width = s->width;
462  avctx->height = s->height;
463 
465  s->bits_per_pixel = s->bit_depth * s->channels;
466  s->bpp = (s->bits_per_pixel + 7) >> 3;
467  s->row_size = (avctx->width * s->bits_per_pixel + 7) >> 3;
468 
469  if (s->bit_depth == 8 &&
471  avctx->pix_fmt = AV_PIX_FMT_RGB24;
472  } else if (s->bit_depth == 8 &&
474  avctx->pix_fmt = AV_PIX_FMT_RGB32;
475  } else if (s->bit_depth == 8 &&
477  avctx->pix_fmt = AV_PIX_FMT_GRAY8;
478  } else if (s->bit_depth == 16 &&
480  avctx->pix_fmt = AV_PIX_FMT_GRAY16BE;
481  } else if (s->bit_depth == 16 &&
483  avctx->pix_fmt = AV_PIX_FMT_RGB48BE;
484  } else if (s->bit_depth == 1 &&
486  avctx->pix_fmt = AV_PIX_FMT_MONOBLACK;
487  } else if (s->bit_depth == 8 &&
489  avctx->pix_fmt = AV_PIX_FMT_PAL8;
490  } else if (s->bit_depth == 8 &&
492  avctx->pix_fmt = AV_PIX_FMT_Y400A;
493  } else {
494  goto fail;
495  }
496  if(p->data[0])
497  avctx->release_buffer(avctx, p);
498 
499  p->reference= 0;
500  if(ff_get_buffer(avctx, p) < 0){
501  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
502  goto fail;
503  }
505  p->key_frame= 1;
507 
508  /* compute the compressed row size */
509  if (!s->interlace_type) {
510  s->crow_size = s->row_size + 1;
511  } else {
512  s->pass = 0;
514  s->bits_per_pixel,
515  s->width);
516  s->crow_size = s->pass_row_size + 1;
517  }
518  av_dlog(avctx, "row_size=%d crow_size =%d\n",
519  s->row_size, s->crow_size);
520  s->image_buf = p->data[0];
521  s->image_linesize = p->linesize[0];
522  /* copy the palette if needed */
524  memcpy(p->data[1], s->palette, 256 * sizeof(uint32_t));
525  /* empty row is used if differencing to the first row */
526  s->last_row = av_mallocz(s->row_size);
527  if (!s->last_row)
528  goto fail;
529  if (s->interlace_type ||
531  s->tmp_row = av_malloc(s->row_size);
532  if (!s->tmp_row)
533  goto fail;
534  }
535  /* compressed row */
536  crow_buf_base = av_malloc(s->row_size + 16);
537  if (!crow_buf_base)
538  goto fail;
539 
540  /* we want crow_buf+1 to be 16-byte aligned */
541  s->crow_buf = crow_buf_base + 15;
542  s->zstream.avail_out = s->crow_size;
543  s->zstream.next_out = s->crow_buf;
544  }
545  s->state |= PNG_IDAT;
546  if (png_decode_idat(s, length) < 0)
547  goto fail;
548  bytestream2_skip(&s->gb, 4); /* crc */
549  break;
550  case MKTAG('P', 'L', 'T', 'E'):
551  {
552  int n, i, r, g, b;
553 
554  if ((length % 3) != 0 || length > 256 * 3)
555  goto skip_tag;
556  /* read the palette */
557  n = length / 3;
558  for(i=0;i<n;i++) {
559  r = bytestream2_get_byte(&s->gb);
560  g = bytestream2_get_byte(&s->gb);
561  b = bytestream2_get_byte(&s->gb);
562  s->palette[i] = (0xff << 24) | (r << 16) | (g << 8) | b;
563  }
564  for(;i<256;i++) {
565  s->palette[i] = (0xff << 24);
566  }
567  s->state |= PNG_PLTE;
568  bytestream2_skip(&s->gb, 4); /* crc */
569  }
570  break;
571  case MKTAG('t', 'R', 'N', 'S'):
572  {
573  int v, i;
574 
575  /* read the transparency. XXX: Only palette mode supported */
577  length > 256 ||
578  !(s->state & PNG_PLTE))
579  goto skip_tag;
580  for(i=0;i<length;i++) {
581  v = bytestream2_get_byte(&s->gb);
582  s->palette[i] = (s->palette[i] & 0x00ffffff) | (v << 24);
583  }
584  bytestream2_skip(&s->gb, 4); /* crc */
585  }
586  break;
587  case MKTAG('I', 'E', 'N', 'D'):
588  if (!(s->state & PNG_ALLIMAGE))
589  goto fail;
590  bytestream2_skip(&s->gb, 4); /* crc */
591  goto exit_loop;
592  default:
593  /* skip tag */
594  skip_tag:
595  bytestream2_skip(&s->gb, length + 4);
596  break;
597  }
598  }
599  exit_loop:
600  /* handle p-frames only if a predecessor frame is available */
601  if(s->last_picture->data[0] != NULL) {
602  if(!(avpkt->flags & AV_PKT_FLAG_KEY)) {
603  int i, j;
604  uint8_t *pd = s->current_picture->data[0];
605  uint8_t *pd_last = s->last_picture->data[0];
606 
607  for(j=0; j < s->height; j++) {
608  for(i=0; i < s->width * s->bpp; i++) {
609  pd[i] += pd_last[i];
610  }
611  pd += s->image_linesize;
612  pd_last += s->image_linesize;
613  }
614  }
615  }
616 
617  *picture= *s->current_picture;
618  *got_frame = 1;
619 
620  ret = bytestream2_tell(&s->gb);
621  the_end:
622  inflateEnd(&s->zstream);
623  av_free(crow_buf_base);
624  s->crow_buf = NULL;
625  av_freep(&s->last_row);
626  av_freep(&s->tmp_row);
627  return ret;
628  fail:
629  ret = -1;
630  goto the_end;
631 }
632 
634  PNGDecContext *s = avctx->priv_data;
635 
636  s->current_picture = &s->picture1;
637  s->last_picture = &s->picture2;
640  ff_pngdsp_init(&s->dsp);
641 
642  return 0;
643 }
644 
646 {
647  PNGDecContext *s = avctx->priv_data;
648 
649  if (s->picture1.data[0])
650  avctx->release_buffer(avctx, &s->picture1);
651  if (s->picture2.data[0])
652  avctx->release_buffer(avctx, &s->picture2);
653 
654  return 0;
655 }
656 
658  .name = "png",
659  .type = AVMEDIA_TYPE_VIDEO,
660  .id = AV_CODEC_ID_PNG,
661  .priv_data_size = sizeof(PNGDecContext),
662  .init = png_dec_init,
663  .close = png_dec_end,
664  .decode = decode_frame,
665  .capabilities = CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/,
666  .long_name = NULL_IF_CONFIG_SMALL("PNG (Portable Network Graphics) image"),
667 };
#define PNG_FILTER_VALUE_AVG
Definition: png.h:41
static void png_handle_row(PNGDecContext *s)
Definition: pngdec.c:284
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:61
int size
This structure describes decoded (raw) audio or video data.
Definition: avcodec.h:989
int width
Definition: pngdec.c:44
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
Definition: avcodec.h:2259
misc image utilities
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:67
int pass_row_size
Definition: pngdec.c:63
AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2725
uint8_t * tmp_row
Definition: pngdec.c:59
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 size
Definition: avcodec.h:916
#define pass
Definition: fft.c:334
AVFrame picture1
Definition: pngdec.c:40
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1533
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:130
8bit gray, 8bit alpha
Definition: pixfmt.h:138
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
#define PNG_COLOR_TYPE_GRAY_ALPHA
Definition: png.h:35
AVCodec.
Definition: avcodec.h:2960
#define PNG_COLOR_TYPE_PALETTE
Definition: png.h:32
#define PNG_IHDR
Definition: png.h:45
int filter_type
Definition: pngdec.c:49
void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
Definition: pngdec.c:136
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:151
#define PNG_FILTER_VALUE_PAETH
Definition: png.h:42
AVCodec ff_png_decoder
Definition: pngdec.c:657
int state
Definition: pngdec.c:43
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:228
uint8_t
#define PNG_COLOR_TYPE_RGB_ALPHA
Definition: png.h:34
8 bit with PIX_FMT_RGB32 palette
Definition: pixfmt.h:76
#define b
Definition: input.c:52
#define PNG_ALLIMAGE
Definition: png.h:47
const char data[16]
Definition: mxf.c:66
uint8_t * data
Definition: avcodec.h:915
const uint8_t * buffer
Definition: bytestream.h:33
uint32_t tag
Definition: movenc.c:802
AVFrame * current_picture
Definition: pngdec.c:41
int interlaced_frame
The content of the picture is interlaced.
Definition: avcodec.h:1232
static int init(AVCodecParserContext *s)
Definition: h264_parser.c:335
#define r
Definition: input.c:51
void(* add_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
Definition: pngdsp.h:33
static const uint8_t png_pass_dsp_mask[NB_PASSES]
Definition: pngdec.c:74
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:139
static const uint16_t mask[17]
Definition: lzw.c:38
int reference
is this picture used as reference The values for this are the same as the MpegEncContext.picture_structure variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
Definition: avcodec.h:1132
#define OP_SUB(x, s, l)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:159
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:88
uint8_t * crow_buf
Definition: pngdec.c:57
g
Definition: yuv2rgb.c:540
int pass
Definition: pngdec.c:60
int ff_png_get_nb_channels(int color_type)
Definition: png.c:58
int height
Definition: pngdec.c:44
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:149
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:146
const char * name
Name of the codec implementation.
Definition: avcodec.h:2967
int bits_per_pixel
Definition: pngdec.c:51
GetByteContext gb
Definition: pngdec.c:39
#define NB_PASSES
Definition: png.h:50
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:921
z_stream zstream
Definition: pngdec.c:65
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:220
static AVFrame * picture
enum AVPictureType pict_type
Picture type of the frame, see ?_TYPE below.
Definition: avcodec.h:1065
#define PNG_FILTER_VALUE_SUB
Definition: png.h:39
AVFrame * last_picture
Definition: pngdec.c:41
const uint8_t ff_mngsig[8]
Definition: png.c:26
uint32_t palette[256]
Definition: pngdec.c:56
#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:193
int width
picture width / height.
Definition: avcodec.h:1508
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Get a buffer for a frame.
Definition: utils.c:464
uint8_t * last_row
Definition: pngdec.c:58
int channels
Definition: pngdec.c:50
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:183
static av_cold int png_dec_init(AVCodecContext *avctx)
Definition: pngdec.c:633
NULL
Definition: eval.c:52
static int width
Definition: utils.c:156
external API header
#define PNG_FILTER_VALUE_UP
Definition: png.h:40
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
Definition: avcodec.h:1008
#define PNG_FILTER_TYPE_LOCO
Definition: png.h:37
main external API structure.
Definition: avcodec.h:1339
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:326
const uint8_t ff_png_pass_mask[NB_PASSES]
Definition: png.c:44
int interlace_type
Definition: pngdec.c:48
const uint8_t ff_png_pass_ymask[NB_PASSES]
Definition: png.c:29
int image_linesize
Definition: pngdec.c:55
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
Definition: utils.c:602
Y , 16bpp, big-endian.
Definition: pixfmt.h:98
#define OP_AVG(x, s, l)
struct PNGDecContext PNGDecContext
uint8_t * image_buf
Definition: pngdec.c:54
void ff_pngdsp_init(PNGDSPContext *dsp)
Definition: pngdsp.c:42
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: avcodec.h:997
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:75
#define PNG_IDAT
Definition: png.h:46
Y , 8bpp.
Definition: pixfmt.h:73
static av_cold int png_dec_end(AVCodecContext *avctx)
Definition: pngdec.c:645
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:108
static const uint8_t png_pass_dsp_ymask[NB_PASSES]
Definition: pngdec.c:69
const uint8_t ff_pngsig[8]
Definition: png.c:25
void ff_png_zfree(void *opaque, void *ptr)
Definition: png.c:53
static void convert_to_rgb32(uint8_t *dst, const uint8_t *src, int width, int loco)
Definition: pngdec.c:265
static av_always_inline void convert_to_rgb32_loco(uint8_t *dst, const uint8_t *src, int width, int loco)
Definition: pngdec.c:245
void * priv_data
Definition: avcodec.h:1382
static int png_decode_idat(PNGDecContext *s, int length)
Definition: pngdec.c:361
int key_frame
1 -> keyframe, 0-> not
Definition: avcodec.h:1058
int row_size
Definition: pngdec.c:62
PNGDSPContext dsp
Definition: pngdec.c:37
int compression_type
Definition: pngdec.c:47
int ff_png_pass_row_size(int pass, int bits_per_pixel, int width)
Definition: png.c:71
int bit_depth
Definition: pngdec.c:45
int color_type
Definition: pngdec.c:46
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:81
int crow_size
Definition: pngdec.c:61
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:389
This structure stores compressed data.
Definition: avcodec.h:898
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:158
#define UNROLL_FILTER(op)
Definition: pngdec.c:179
AVFrame picture2
Definition: pngdec.c:40
static void deloco_rgb24(uint8_t *dst, int size)
Definition: pngdec.c:273