]> git.sesse.net Git - ffmpeg/blob - libavcodec/pngdec.c
vda: remove async decoder leftovers
[ffmpeg] / libavcodec / pngdec.c
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 {
37     PNGDSPContext dsp;
38
39     GetByteContext gb;
40     AVFrame *prev;
41
42     int state;
43     int width, height;
44     int bit_depth;
45     int color_type;
46     int compression_type;
47     int interlace_type;
48     int filter_type;
49     int channels;
50     int bits_per_pixel;
51     int bpp;
52
53     uint8_t *image_buf;
54     int image_linesize;
55     uint32_t palette[256];
56     uint8_t *crow_buf;
57     uint8_t *last_row;
58     uint8_t *tmp_row;
59     int pass;
60     int crow_size; /* compressed row size (include filter type) */
61     int row_size; /* decompressed row size */
62     int pass_row_size; /* decompress row size of the current pass */
63     int y;
64     z_stream zstream;
65 } PNGDecContext;
66
67 /* Mask to determine which y pixels can be written in a pass */
68 static const uint8_t png_pass_dsp_ymask[NB_PASSES] = {
69     0xff, 0xff, 0x0f, 0xcc, 0x33, 0xff, 0x55,
70 };
71
72 /* Mask to determine which pixels to overwrite while displaying */
73 static const uint8_t png_pass_dsp_mask[NB_PASSES] = {
74     0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff
75 };
76
77 /* NOTE: we try to construct a good looking image at each pass. width
78    is the original image width. We also do pixel format conversion at
79    this stage */
80 static void png_put_interlaced_row(uint8_t *dst, int width,
81                                    int bits_per_pixel, int pass,
82                                    int color_type, const uint8_t *src)
83 {
84     int x, mask, dsp_mask, j, src_x, b, bpp;
85     uint8_t *d;
86     const uint8_t *s;
87
88     mask     = ff_png_pass_mask[pass];
89     dsp_mask = png_pass_dsp_mask[pass];
90
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) {
199     case PNG_FILTER_VALUE_NONE:
200         memcpy(dst, src, size);
201         break;
202     case PNG_FILTER_VALUE_SUB:
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
215             UNROLL_FILTER(OP_SUB);
216         }
217         break;
218     case PNG_FILTER_VALUE_UP:
219         dsp->add_bytes_l2(dst, src, last, size);
220         break;
221     case PNG_FILTER_VALUE_AVG:
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
227         UNROLL_FILTER(OP_AVG);
228         break;
229     case PNG_FILTER_VALUE_PAETH:
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,
246                                                    const uint8_t *src,
247                                                    int width, int loco)
248 {
249     int j;
250     unsigned int r, g, b, a;
251
252     for (j = 0; j < width; j++) {
253         r = src[0];
254         g = src[1];
255         b = src[2];
256         a = src[3];
257         if (loco) {
258             r = (r + g) & 0xff;
259             b = (b + g) & 0xff;
260         }
261         *(uint32_t *)dst = (a << 24) | (r << 16) | (g << 8) | b;
262         dst += 4;
263         src += 4;
264     }
265 }
266
267 static void convert_to_rgb32(uint8_t *dst, const uint8_t *src, int width, int loco)
268 {
269     if (loco)
270         convert_to_rgb32_loco(dst, src, width, 1);
271     else
272         convert_to_rgb32_loco(dst, src, width, 0);
273 }
274
275 static void deloco_rgb24(uint8_t *dst, int size)
276 {
277     int i;
278     for (i = 0; i < size; i += 3) {
279         int g = dst[i + 1];
280         dst[i + 0] += g;
281         dst[i + 2] += g;
282     }
283 }
284
285 /* process exactly one decompressed row */
286 static void png_handle_row(PNGDecContext *s)
287 {
288     uint8_t *ptr, *last_row;
289     int got_line;
290
291     if (!s->interlace_type) {
292         ptr = s->image_buf + s->image_linesize * s->y;
293         /* need to swap bytes correctly for RGB_ALPHA */
294         if (s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
295             png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
296                            s->last_row, s->row_size, s->bpp);
297             convert_to_rgb32(ptr, s->tmp_row, s->width, s->filter_type == PNG_FILTER_TYPE_LOCO);
298             FFSWAP(uint8_t*, s->last_row, s->tmp_row);
299         } else {
300             /* in normal case, we avoid one copy */
301             if (s->y == 0)
302                 last_row = s->last_row;
303             else
304                 last_row = ptr - s->image_linesize;
305
306             png_filter_row(&s->dsp, ptr, s->crow_buf[0], s->crow_buf + 1,
307                            last_row, s->row_size, s->bpp);
308         }
309         /* loco lags by 1 row so that it doesn't interfere with top prediction */
310         if (s->filter_type == PNG_FILTER_TYPE_LOCO &&
311             s->color_type == PNG_COLOR_TYPE_RGB && s->y > 0)
312             deloco_rgb24(ptr - s->image_linesize, s->row_size);
313         s->y++;
314         if (s->y == s->height) {
315             s->state |= PNG_ALLIMAGE;
316             if (s->filter_type == PNG_FILTER_TYPE_LOCO &&
317                 s->color_type == PNG_COLOR_TYPE_RGB)
318                 deloco_rgb24(ptr, s->row_size);
319         }
320     } else {
321         got_line = 0;
322         for (;;) {
323             ptr = s->image_buf + s->image_linesize * s->y;
324             if ((ff_png_pass_ymask[s->pass] << (s->y & 7)) & 0x80) {
325                 /* if we already read one row, it is time to stop to
326                    wait for the next one */
327                 if (got_line)
328                     break;
329                 png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
330                                s->last_row, s->pass_row_size, s->bpp);
331                 FFSWAP(uint8_t*, s->last_row, s->tmp_row);
332                 got_line = 1;
333             }
334             if ((png_pass_dsp_ymask[s->pass] << (s->y & 7)) & 0x80) {
335                 /* NOTE: RGB32 is handled directly in png_put_interlaced_row */
336                 png_put_interlaced_row(ptr, s->width, s->bits_per_pixel, s->pass,
337                                        s->color_type, s->last_row);
338             }
339             s->y++;
340             if (s->y == s->height) {
341                 for (;;) {
342                     if (s->pass == NB_PASSES - 1) {
343                         s->state |= PNG_ALLIMAGE;
344                         goto the_end;
345                     } else {
346                         s->pass++;
347                         s->y = 0;
348                         s->pass_row_size = ff_png_pass_row_size(s->pass,
349                                                              s->bits_per_pixel,
350                                                              s->width);
351                         s->crow_size = s->pass_row_size + 1;
352                         if (s->pass_row_size != 0)
353                             break;
354                         /* skip pass if empty row */
355                     }
356                 }
357             }
358         }
359     the_end: ;
360     }
361 }
362
363 static int png_decode_idat(PNGDecContext *s, int length)
364 {
365     int ret;
366     s->zstream.avail_in = FFMIN(length, bytestream2_get_bytes_left(&s->gb));
367     s->zstream.next_in  = s->gb.buffer;
368     bytestream2_skip(&s->gb, length);
369
370     /* decode one line if possible */
371     while (s->zstream.avail_in > 0) {
372         ret = inflate(&s->zstream, Z_PARTIAL_FLUSH);
373         if (ret != Z_OK && ret != Z_STREAM_END) {
374             return -1;
375         }
376         if (s->zstream.avail_out == 0) {
377             if (!(s->state & PNG_ALLIMAGE)) {
378                 png_handle_row(s);
379             }
380             s->zstream.avail_out = s->crow_size;
381             s->zstream.next_out  = s->crow_buf;
382         }
383     }
384     return 0;
385 }
386
387 static int decode_frame(AVCodecContext *avctx,
388                         void *data, int *got_frame,
389                         AVPacket *avpkt)
390 {
391     PNGDecContext * const s = avctx->priv_data;
392     const uint8_t *buf      = avpkt->data;
393     int buf_size            = avpkt->size;
394     AVFrame *p              = data;
395     uint8_t *crow_buf_base  = NULL;
396     uint32_t tag, length;
397     int ret;
398
399     /* check signature */
400     if (buf_size < 8 ||
401         memcmp(buf, ff_pngsig, 8) != 0 &&
402         memcmp(buf, ff_mngsig, 8) != 0)
403         return -1;
404
405     bytestream2_init(&s->gb, buf + 8, buf_size - 8);
406     s->y = s->state = 0;
407
408     /* init the zlib */
409     s->zstream.zalloc = ff_png_zalloc;
410     s->zstream.zfree  = ff_png_zfree;
411     s->zstream.opaque = NULL;
412     ret = inflateInit(&s->zstream);
413     if (ret != Z_OK)
414         return -1;
415     for (;;) {
416         if (bytestream2_get_bytes_left(&s->gb) <= 0)
417             goto fail;
418         length = bytestream2_get_be32(&s->gb);
419         if (length > 0x7fffffff)
420             goto fail;
421         tag = bytestream2_get_le32(&s->gb);
422         av_dlog(avctx, "png: tag=%c%c%c%c length=%u\n",
423                 (tag & 0xff),
424                 ((tag >> 8) & 0xff),
425                 ((tag >> 16) & 0xff),
426                 ((tag >> 24) & 0xff), length);
427         switch (tag) {
428         case MKTAG('I', 'H', 'D', 'R'):
429             if (length != 13)
430                 goto fail;
431             s->width  = bytestream2_get_be32(&s->gb);
432             s->height = bytestream2_get_be32(&s->gb);
433             if (av_image_check_size(s->width, s->height, 0, avctx)) {
434                 s->width = s->height = 0;
435                 goto fail;
436             }
437             s->bit_depth        = bytestream2_get_byte(&s->gb);
438             s->color_type       = bytestream2_get_byte(&s->gb);
439             s->compression_type = bytestream2_get_byte(&s->gb);
440             s->filter_type      = bytestream2_get_byte(&s->gb);
441             s->interlace_type   = bytestream2_get_byte(&s->gb);
442             bytestream2_skip(&s->gb, 4); /* crc */
443             s->state |= PNG_IHDR;
444             av_dlog(avctx, "width=%d height=%d depth=%d color_type=%d "
445                     "compression_type=%d filter_type=%d interlace_type=%d\n",
446                     s->width, s->height, s->bit_depth, s->color_type,
447                     s->compression_type, s->filter_type, s->interlace_type);
448             break;
449         case MKTAG('I', 'D', 'A', 'T'):
450             if (!(s->state & PNG_IHDR))
451                 goto fail;
452             if (!(s->state & PNG_IDAT)) {
453                 /* init image info */
454                 avctx->width  = s->width;
455                 avctx->height = s->height;
456
457                 s->channels       = ff_png_get_nb_channels(s->color_type);
458                 s->bits_per_pixel = s->bit_depth * s->channels;
459                 s->bpp            = (s->bits_per_pixel + 7) >> 3;
460                 s->row_size       = (avctx->width * s->bits_per_pixel + 7) >> 3;
461
462                 if (s->bit_depth == 8 &&
463                     s->color_type == PNG_COLOR_TYPE_RGB) {
464                     avctx->pix_fmt = AV_PIX_FMT_RGB24;
465                 } else if (s->bit_depth == 8 &&
466                            s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
467                     avctx->pix_fmt = AV_PIX_FMT_RGB32;
468                 } else if (s->bit_depth == 8 &&
469                            s->color_type == PNG_COLOR_TYPE_GRAY) {
470                     avctx->pix_fmt = AV_PIX_FMT_GRAY8;
471                 } else if (s->bit_depth == 16 &&
472                            s->color_type == PNG_COLOR_TYPE_GRAY) {
473                     avctx->pix_fmt = AV_PIX_FMT_GRAY16BE;
474                 } else if (s->bit_depth == 16 &&
475                            s->color_type == PNG_COLOR_TYPE_RGB) {
476                     avctx->pix_fmt = AV_PIX_FMT_RGB48BE;
477                 } else if (s->bit_depth == 1 &&
478                            s->color_type == PNG_COLOR_TYPE_GRAY) {
479                     avctx->pix_fmt = AV_PIX_FMT_MONOBLACK;
480                 } else if (s->bit_depth == 8 &&
481                            s->color_type == PNG_COLOR_TYPE_PALETTE) {
482                     avctx->pix_fmt = AV_PIX_FMT_PAL8;
483                 } else if (s->bit_depth == 8 &&
484                            s->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
485                     avctx->pix_fmt = AV_PIX_FMT_Y400A;
486                 } else {
487                     goto fail;
488                 }
489
490                 if (ff_get_buffer(avctx, p, AV_GET_BUFFER_FLAG_REF) < 0) {
491                     av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
492                     goto fail;
493                 }
494                 p->pict_type        = AV_PICTURE_TYPE_I;
495                 p->key_frame        = 1;
496                 p->interlaced_frame = !!s->interlace_type;
497
498                 /* compute the compressed row size */
499                 if (!s->interlace_type) {
500                     s->crow_size = s->row_size + 1;
501                 } else {
502                     s->pass = 0;
503                     s->pass_row_size = ff_png_pass_row_size(s->pass,
504                                                          s->bits_per_pixel,
505                                                          s->width);
506                     s->crow_size = s->pass_row_size + 1;
507                 }
508                 av_dlog(avctx, "row_size=%d crow_size =%d\n",
509                         s->row_size, s->crow_size);
510                 s->image_buf      = p->data[0];
511                 s->image_linesize = p->linesize[0];
512                 /* copy the palette if needed */
513                 if (s->color_type == PNG_COLOR_TYPE_PALETTE)
514                     memcpy(p->data[1], s->palette, 256 * sizeof(uint32_t));
515                 /* empty row is used if differencing to the first row */
516                 s->last_row = av_mallocz(s->row_size);
517                 if (!s->last_row)
518                     goto fail;
519                 if (s->interlace_type ||
520                     s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
521                     s->tmp_row = av_malloc(s->row_size);
522                     if (!s->tmp_row)
523                         goto fail;
524                 }
525                 /* compressed row */
526                 crow_buf_base = av_malloc(s->row_size + 16);
527                 if (!crow_buf_base)
528                     goto fail;
529
530                 /* we want crow_buf+1 to be 16-byte aligned */
531                 s->crow_buf          = crow_buf_base + 15;
532                 s->zstream.avail_out = s->crow_size;
533                 s->zstream.next_out  = s->crow_buf;
534             }
535             s->state |= PNG_IDAT;
536             if (png_decode_idat(s, length) < 0)
537                 goto fail;
538             bytestream2_skip(&s->gb, 4); /* crc */
539             break;
540         case MKTAG('P', 'L', 'T', 'E'):
541             {
542                 int n, i, r, g, b;
543
544                 if ((length % 3) != 0 || length > 256 * 3)
545                     goto skip_tag;
546                 /* read the palette */
547                 n = length / 3;
548                 for (i = 0; i < n; i++) {
549                     r = bytestream2_get_byte(&s->gb);
550                     g = bytestream2_get_byte(&s->gb);
551                     b = bytestream2_get_byte(&s->gb);
552                     s->palette[i] = (0xff << 24) | (r << 16) | (g << 8) | b;
553                 }
554                 for (; i < 256; i++) {
555                     s->palette[i] = (0xff << 24);
556                 }
557                 s->state |= PNG_PLTE;
558                 bytestream2_skip(&s->gb, 4); /* crc */
559             }
560             break;
561         case MKTAG('t', 'R', 'N', 'S'):
562             {
563                 int v, i;
564
565                 /* read the transparency. XXX: Only palette mode supported */
566                 if (s->color_type != PNG_COLOR_TYPE_PALETTE ||
567                     length > 256 ||
568                     !(s->state & PNG_PLTE))
569                     goto skip_tag;
570                 for (i = 0; i < length; i++) {
571                     v = bytestream2_get_byte(&s->gb);
572                     s->palette[i] = (s->palette[i] & 0x00ffffff) | (v << 24);
573                 }
574                 bytestream2_skip(&s->gb, 4); /* crc */
575             }
576             break;
577         case MKTAG('I', 'E', 'N', 'D'):
578             if (!(s->state & PNG_ALLIMAGE))
579                 goto fail;
580             bytestream2_skip(&s->gb, 4); /* crc */
581             goto exit_loop;
582         default:
583             /* skip tag */
584         skip_tag:
585             bytestream2_skip(&s->gb, length + 4);
586             break;
587         }
588     }
589  exit_loop:
590      /* handle p-frames only if a predecessor frame is available */
591      if (s->prev->data[0]) {
592          if (!(avpkt->flags & AV_PKT_FLAG_KEY)) {
593             int i, j;
594             uint8_t *pd      = p->data[0];
595             uint8_t *pd_last = s->prev->data[0];
596
597             for (j = 0; j < s->height; j++) {
598                 for (i = 0; i < s->width * s->bpp; i++) {
599                     pd[i] += pd_last[i];
600                 }
601                 pd      += s->image_linesize;
602                 pd_last += s->image_linesize;
603             }
604         }
605     }
606
607      av_frame_unref(s->prev);
608      if ((ret = av_frame_ref(s->prev, p)) < 0)
609          goto fail;
610
611     *got_frame = 1;
612
613     ret = bytestream2_tell(&s->gb);
614  the_end:
615     inflateEnd(&s->zstream);
616     av_free(crow_buf_base);
617     s->crow_buf = NULL;
618     av_freep(&s->last_row);
619     av_freep(&s->tmp_row);
620     return ret;
621  fail:
622     ret = -1;
623     goto the_end;
624 }
625
626 static av_cold int png_dec_init(AVCodecContext *avctx)
627 {
628     PNGDecContext *s = avctx->priv_data;
629
630     s->prev = av_frame_alloc();
631     if (!s->prev)
632         return AVERROR(ENOMEM);
633
634     ff_pngdsp_init(&s->dsp);
635
636     return 0;
637 }
638
639 static av_cold int png_dec_end(AVCodecContext *avctx)
640 {
641     PNGDecContext *s = avctx->priv_data;
642
643     av_frame_free(&s->prev);
644
645     return 0;
646 }
647
648 AVCodec ff_png_decoder = {
649     .name           = "png",
650     .type           = AVMEDIA_TYPE_VIDEO,
651     .id             = AV_CODEC_ID_PNG,
652     .priv_data_size = sizeof(PNGDecContext),
653     .init           = png_dec_init,
654     .close          = png_dec_end,
655     .decode         = decode_frame,
656     .capabilities   = CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/,
657     .long_name      = NULL_IF_CONFIG_SMALL("PNG (Portable Network Graphics) image"),
658 };