]> git.sesse.net Git - ffmpeg/blob - libavcodec/pngenc.c
Merge commit '802987f8c7033ec8b82b35438d3822cf7f761166'
[ffmpeg] / libavcodec / pngenc.c
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 #include "avcodec.h"
23 #include "internal.h"
24 #include "bytestream.h"
25 #include "huffyuvencdsp.h"
26 #include "png.h"
27
28 #include "libavutil/avassert.h"
29 #include "libavutil/opt.h"
30
31 #include <zlib.h>
32
33 #define IOBUF_SIZE 4096
34
35 typedef struct PNGEncContext {
36     AVClass *class;
37     HuffYUVEncDSPContext hdsp;
38
39     uint8_t *bytestream;
40     uint8_t *bytestream_start;
41     uint8_t *bytestream_end;
42
43     int filter_type;
44
45     z_stream zstream;
46     uint8_t buf[IOBUF_SIZE];
47     int dpi;                     ///< Physical pixel density, in dots per inch, if set
48     int dpm;                     ///< Physical pixel density, in dots per meter, if set
49 } PNGEncContext;
50
51 static void png_get_interlaced_row(uint8_t *dst, int row_size,
52                                    int bits_per_pixel, int pass,
53                                    const uint8_t *src, int width)
54 {
55     int x, mask, dst_x, j, b, bpp;
56     uint8_t *d;
57     const uint8_t *s;
58     static const int masks[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
59
60     mask = masks[pass];
61     switch (bits_per_pixel) {
62     case 1:
63         memset(dst, 0, row_size);
64         dst_x = 0;
65         for (x = 0; x < width; x++) {
66             j = (x & 7);
67             if ((mask << j) & 0x80) {
68                 b = (src[x >> 3] >> (7 - j)) & 1;
69                 dst[dst_x >> 3] |= b << (7 - (dst_x & 7));
70                 dst_x++;
71             }
72         }
73         break;
74     default:
75         bpp = bits_per_pixel >> 3;
76         d = dst;
77         s = src;
78         for (x = 0; x < width; x++) {
79             j = x & 7;
80             if ((mask << j) & 0x80) {
81                 memcpy(d, s, bpp);
82                 d += bpp;
83             }
84             s += bpp;
85         }
86         break;
87     }
88 }
89
90 static void sub_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top,
91                                      int w, int bpp)
92 {
93     int i;
94     for (i = 0; i < w; i++) {
95         int a, b, c, p, pa, pb, pc;
96
97         a = src[i - bpp];
98         b = top[i];
99         c = top[i - bpp];
100
101         p  = b - c;
102         pc = a - c;
103
104         pa = abs(p);
105         pb = abs(pc);
106         pc = abs(p + pc);
107
108         if (pa <= pb && pa <= pc)
109             p = a;
110         else if (pb <= pc)
111             p = b;
112         else
113             p = c;
114         dst[i] = src[i] - p;
115     }
116 }
117
118 static void sub_left_prediction(PNGEncContext *c, uint8_t *dst, const uint8_t *src, int bpp, int size)
119 {
120     const uint8_t *src1 = src + bpp;
121     const uint8_t *src2 = src;
122     int x, unaligned_w;
123
124     memcpy(dst, src, bpp);
125     dst += bpp;
126     size -= bpp;
127     unaligned_w = FFMIN(32 - bpp, size);
128     for (x = 0; x < unaligned_w; x++)
129         *dst++ = *src1++ - *src2++;
130     size -= unaligned_w;
131     c->hdsp.diff_bytes(dst, src1, src2, size);
132 }
133
134 static void png_filter_row(PNGEncContext *c, uint8_t *dst, int filter_type,
135                            uint8_t *src, uint8_t *top, int size, int bpp)
136 {
137     int i;
138
139     switch (filter_type) {
140     case PNG_FILTER_VALUE_NONE:
141         memcpy(dst, src, size);
142         break;
143     case PNG_FILTER_VALUE_SUB:
144         sub_left_prediction(c, dst, src, bpp, size);
145         break;
146     case PNG_FILTER_VALUE_UP:
147         c->hdsp.diff_bytes(dst, src, top, size);
148         break;
149     case PNG_FILTER_VALUE_AVG:
150         for (i = 0; i < bpp; i++)
151             dst[i] = src[i] - (top[i] >> 1);
152         for (; i < size; i++)
153             dst[i] = src[i] - ((src[i - bpp] + top[i]) >> 1);
154         break;
155     case PNG_FILTER_VALUE_PAETH:
156         for (i = 0; i < bpp; i++)
157             dst[i] = src[i] - top[i];
158         sub_png_paeth_prediction(dst + i, src + i, top + i, size - i, bpp);
159         break;
160     }
161 }
162
163 static uint8_t *png_choose_filter(PNGEncContext *s, uint8_t *dst,
164                                   uint8_t *src, uint8_t *top, int size, int bpp)
165 {
166     int pred = s->filter_type;
167     av_assert0(bpp || !pred);
168     if (!top && pred)
169         pred = PNG_FILTER_VALUE_SUB;
170     if (pred == PNG_FILTER_VALUE_MIXED) {
171         int i;
172         int cost, bcost = INT_MAX;
173         uint8_t *buf1 = dst, *buf2 = dst + size + 16;
174         for (pred = 0; pred < 5; pred++) {
175             png_filter_row(s, buf1 + 1, pred, src, top, size, bpp);
176             buf1[0] = pred;
177             cost = 0;
178             for (i = 0; i <= size; i++)
179                 cost += abs((int8_t) buf1[i]);
180             if (cost < bcost) {
181                 bcost = cost;
182                 FFSWAP(uint8_t *, buf1, buf2);
183             }
184         }
185         return buf2;
186     } else {
187         png_filter_row(s, dst + 1, pred, src, top, size, bpp);
188         dst[0] = pred;
189         return dst;
190     }
191 }
192
193 static void png_write_chunk(uint8_t **f, uint32_t tag,
194                             const uint8_t *buf, int length)
195 {
196     uint32_t crc;
197     uint8_t tagbuf[4];
198
199     bytestream_put_be32(f, length);
200     crc = crc32(0, Z_NULL, 0);
201     AV_WL32(tagbuf, tag);
202     crc = crc32(crc, tagbuf, 4);
203     bytestream_put_be32(f, av_bswap32(tag));
204     if (length > 0) {
205         crc = crc32(crc, buf, length);
206         memcpy(*f, buf, length);
207         *f += length;
208     }
209     bytestream_put_be32(f, crc);
210 }
211
212 /* XXX: do filtering */
213 static int png_write_row(PNGEncContext *s, const uint8_t *data, int size)
214 {
215     int ret;
216
217     s->zstream.avail_in = size;
218     s->zstream.next_in  = data;
219     while (s->zstream.avail_in > 0) {
220         ret = deflate(&s->zstream, Z_NO_FLUSH);
221         if (ret != Z_OK)
222             return -1;
223         if (s->zstream.avail_out == 0) {
224             if (s->bytestream_end - s->bytestream > IOBUF_SIZE + 100)
225                 png_write_chunk(&s->bytestream,
226                                 MKTAG('I', 'D', 'A', 'T'), s->buf, IOBUF_SIZE);
227             s->zstream.avail_out = IOBUF_SIZE;
228             s->zstream.next_out  = s->buf;
229         }
230     }
231     return 0;
232 }
233
234 #define AV_WB32_PNG(buf, n) (AV_WB32(buf, round((n) * 100000)))
235 static int png_get_chrm(enum AVColorPrimaries prim,  uint8_t *buf)
236 {
237     double rx, ry, gx, gy, bx, by, wx = 0.3127, wy = 0.3290;
238     switch (prim) {
239         case AVCOL_PRI_BT709:
240             rx = 0.640; ry = 0.330;
241             gx = 0.300; gy = 0.600;
242             bx = 0.150; by = 0.060;
243             break;
244         case AVCOL_PRI_BT470M:
245             rx = 0.670; ry = 0.330;
246             gx = 0.210; gy = 0.710;
247             bx = 0.140; by = 0.080;
248             wx = 0.310; wy = 0.316;
249             break;
250         case AVCOL_PRI_BT470BG:
251             rx = 0.640; ry = 0.330;
252             gx = 0.290; gy = 0.600;
253             bx = 0.150; by = 0.060;
254             break;
255         case AVCOL_PRI_SMPTE170M:
256         case AVCOL_PRI_SMPTE240M:
257             rx = 0.630; ry = 0.340;
258             gx = 0.310; gy = 0.595;
259             bx = 0.155; by = 0.070;
260             break;
261         case AVCOL_PRI_BT2020:
262             rx = 0.708; ry = 0.292;
263             gx = 0.170; gy = 0.797;
264             bx = 0.131; by = 0.046;
265             break;
266         default:
267             return 0;
268     }
269
270     AV_WB32_PNG(buf     , wx); AV_WB32_PNG(buf + 4 , wy);
271     AV_WB32_PNG(buf + 8 , rx); AV_WB32_PNG(buf + 12, ry);
272     AV_WB32_PNG(buf + 16, gx); AV_WB32_PNG(buf + 20, gy);
273     AV_WB32_PNG(buf + 24, bx); AV_WB32_PNG(buf + 28, by);
274     return 1;
275 }
276
277 static int png_get_gama(enum AVColorTransferCharacteristic trc, uint8_t *buf)
278 {
279     double gamma;
280     switch (trc) {
281         case AVCOL_TRC_BT709:
282         case AVCOL_TRC_SMPTE170M:
283         case AVCOL_TRC_SMPTE240M:
284         case AVCOL_TRC_BT1361_ECG:
285         case AVCOL_TRC_BT2020_10:
286         case AVCOL_TRC_BT2020_12:
287             /* these share a segmented TRC, but gamma 1.961 is a close
288               approximation, and also more correct for decoding content */
289             gamma = 1.961;
290             break;
291         case AVCOL_TRC_GAMMA22:
292         case AVCOL_TRC_IEC61966_2_1:
293             gamma = 2.2;
294             break;
295         case AVCOL_TRC_GAMMA28:
296             gamma = 2.8;
297             break;
298         case AVCOL_TRC_LINEAR:
299             gamma = 1.0;
300             break;
301         default:
302             return 0;
303     }
304
305     AV_WB32_PNG(buf, 1.0 / gamma);
306     return 1;
307 }
308
309 static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
310                         const AVFrame *pict, int *got_packet)
311 {
312     PNGEncContext *s       = avctx->priv_data;
313     const AVFrame *const p = pict;
314     int bit_depth, color_type, y, len, row_size, ret, is_progressive;
315     int bits_per_pixel, pass_row_size, enc_row_size;
316     int64_t max_packet_size;
317     int compression_level;
318     uint8_t *ptr, *top, *crow_buf, *crow;
319     uint8_t *crow_base       = NULL;
320     uint8_t *progressive_buf = NULL;
321     uint8_t *top_buf         = NULL;
322
323     is_progressive = !!(avctx->flags & CODEC_FLAG_INTERLACED_DCT);
324     switch (avctx->pix_fmt) {
325     case AV_PIX_FMT_RGBA64BE:
326         bit_depth = 16;
327         color_type = PNG_COLOR_TYPE_RGB_ALPHA;
328         break;
329     case AV_PIX_FMT_RGB48BE:
330         bit_depth = 16;
331         color_type = PNG_COLOR_TYPE_RGB;
332         break;
333     case AV_PIX_FMT_RGBA:
334         bit_depth  = 8;
335         color_type = PNG_COLOR_TYPE_RGB_ALPHA;
336         break;
337     case AV_PIX_FMT_RGB24:
338         bit_depth  = 8;
339         color_type = PNG_COLOR_TYPE_RGB;
340         break;
341     case AV_PIX_FMT_GRAY16BE:
342         bit_depth  = 16;
343         color_type = PNG_COLOR_TYPE_GRAY;
344         break;
345     case AV_PIX_FMT_GRAY8:
346         bit_depth  = 8;
347         color_type = PNG_COLOR_TYPE_GRAY;
348         break;
349     case AV_PIX_FMT_GRAY8A:
350         bit_depth = 8;
351         color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
352         break;
353     case AV_PIX_FMT_YA16BE:
354         bit_depth = 16;
355         color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
356         break;
357     case AV_PIX_FMT_MONOBLACK:
358         bit_depth  = 1;
359         color_type = PNG_COLOR_TYPE_GRAY;
360         break;
361     case AV_PIX_FMT_PAL8:
362         bit_depth  = 8;
363         color_type = PNG_COLOR_TYPE_PALETTE;
364         break;
365     default:
366         return -1;
367     }
368     bits_per_pixel = ff_png_get_nb_channels(color_type) * bit_depth;
369     row_size       = (avctx->width * bits_per_pixel + 7) >> 3;
370
371     s->zstream.zalloc = ff_png_zalloc;
372     s->zstream.zfree  = ff_png_zfree;
373     s->zstream.opaque = NULL;
374     compression_level = avctx->compression_level == FF_COMPRESSION_DEFAULT
375                       ? Z_DEFAULT_COMPRESSION
376                       : av_clip(avctx->compression_level, 0, 9);
377     ret = deflateInit2(&s->zstream, compression_level,
378                        Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY);
379     if (ret != Z_OK)
380         return -1;
381
382     enc_row_size    = deflateBound(&s->zstream, row_size);
383     max_packet_size = avctx->height * (int64_t)(enc_row_size +
384                                        ((enc_row_size + IOBUF_SIZE - 1) / IOBUF_SIZE) * 12)
385                       + FF_MIN_BUFFER_SIZE;
386     if (max_packet_size > INT_MAX)
387         return AVERROR(ENOMEM);
388     if ((ret = ff_alloc_packet2(avctx, pkt, max_packet_size)) < 0)
389         return ret;
390
391     s->bytestream_start =
392     s->bytestream       = pkt->data;
393     s->bytestream_end   = pkt->data + pkt->size;
394
395     crow_base = av_malloc((row_size + 32) << (s->filter_type == PNG_FILTER_VALUE_MIXED));
396     if (!crow_base)
397         goto fail;
398     // pixel data should be aligned, but there's a control byte before it
399     crow_buf = crow_base + 15;
400     if (is_progressive) {
401         progressive_buf = av_malloc(row_size + 1);
402         if (!progressive_buf)
403             goto fail;
404     }
405     if (is_progressive) {
406         top_buf = av_malloc(row_size + 1);
407         if (!top_buf)
408             goto fail;
409     }
410
411     /* write png header */
412     AV_WB64(s->bytestream, PNGSIG);
413     s->bytestream += 8;
414
415     AV_WB32(s->buf, avctx->width);
416     AV_WB32(s->buf + 4, avctx->height);
417     s->buf[8]  = bit_depth;
418     s->buf[9]  = color_type;
419     s->buf[10] = 0; /* compression type */
420     s->buf[11] = 0; /* filter type */
421     s->buf[12] = is_progressive; /* interlace type */
422
423     png_write_chunk(&s->bytestream, MKTAG('I', 'H', 'D', 'R'), s->buf, 13);
424
425     if (s->dpm) {
426       AV_WB32(s->buf, s->dpm);
427       AV_WB32(s->buf + 4, s->dpm);
428       s->buf[8] = 1; /* unit specifier is meter */
429     } else {
430       AV_WB32(s->buf, avctx->sample_aspect_ratio.num);
431       AV_WB32(s->buf + 4, avctx->sample_aspect_ratio.den);
432       s->buf[8] = 0; /* unit specifier is unknown */
433     }
434     png_write_chunk(&s->bytestream, MKTAG('p', 'H', 'Y', 's'), s->buf, 9);
435
436     /* write colorspace information */
437     if (pict->color_primaries == AVCOL_PRI_BT709 &&
438         pict->color_trc == AVCOL_TRC_IEC61966_2_1) {
439         s->buf[0] = 1; /* rendering intent, relative colorimetric by default */
440         png_write_chunk(&s->bytestream, MKTAG('s', 'R', 'G', 'B'), s->buf, 1);
441     }
442
443     if (png_get_chrm(pict->color_primaries, s->buf))
444         png_write_chunk(&s->bytestream, MKTAG('c', 'H', 'R', 'M'), s->buf, 32);
445     if (png_get_gama(pict->color_trc, s->buf))
446         png_write_chunk(&s->bytestream, MKTAG('g', 'A', 'M', 'A'), s->buf, 4);
447
448     /* put the palette if needed */
449     if (color_type == PNG_COLOR_TYPE_PALETTE) {
450         int has_alpha, alpha, i;
451         unsigned int v;
452         uint32_t *palette;
453         uint8_t *alpha_ptr;
454
455         palette   = (uint32_t *)p->data[1];
456         ptr       = s->buf;
457         alpha_ptr = s->buf + 256 * 3;
458         has_alpha = 0;
459         for (i = 0; i < 256; i++) {
460             v     = palette[i];
461             alpha = v >> 24;
462             if (alpha != 0xff)
463                 has_alpha = 1;
464             *alpha_ptr++ = alpha;
465             bytestream_put_be24(&ptr, v);
466         }
467         png_write_chunk(&s->bytestream,
468                         MKTAG('P', 'L', 'T', 'E'), s->buf, 256 * 3);
469         if (has_alpha) {
470             png_write_chunk(&s->bytestream,
471                             MKTAG('t', 'R', 'N', 'S'), s->buf + 256 * 3, 256);
472         }
473     }
474
475     /* now put each row */
476     s->zstream.avail_out = IOBUF_SIZE;
477     s->zstream.next_out  = s->buf;
478     if (is_progressive) {
479         int pass;
480
481         for (pass = 0; pass < NB_PASSES; pass++) {
482             /* NOTE: a pass is completely omitted if no pixels would be
483              * output */
484             pass_row_size = ff_png_pass_row_size(pass, bits_per_pixel, avctx->width);
485             if (pass_row_size > 0) {
486                 top = NULL;
487                 for (y = 0; y < avctx->height; y++)
488                     if ((ff_png_pass_ymask[pass] << (y & 7)) & 0x80) {
489                         ptr = p->data[0] + y * p->linesize[0];
490                         FFSWAP(uint8_t *, progressive_buf, top_buf);
491                         png_get_interlaced_row(progressive_buf, pass_row_size,
492                                                bits_per_pixel, pass,
493                                                ptr, avctx->width);
494                         crow = png_choose_filter(s, crow_buf, progressive_buf,
495                                                  top, pass_row_size, bits_per_pixel >> 3);
496                         png_write_row(s, crow, pass_row_size + 1);
497                         top = progressive_buf;
498                     }
499             }
500         }
501     } else {
502         top = NULL;
503         for (y = 0; y < avctx->height; y++) {
504             ptr = p->data[0] + y * p->linesize[0];
505             crow = png_choose_filter(s, crow_buf, ptr, top,
506                                      row_size, bits_per_pixel >> 3);
507             png_write_row(s, crow, row_size + 1);
508             top = ptr;
509         }
510     }
511     /* compress last bytes */
512     for (;;) {
513         ret = deflate(&s->zstream, Z_FINISH);
514         if (ret == Z_OK || ret == Z_STREAM_END) {
515             len = IOBUF_SIZE - s->zstream.avail_out;
516             if (len > 0 && s->bytestream_end - s->bytestream > len + 100) {
517                 png_write_chunk(&s->bytestream, MKTAG('I', 'D', 'A', 'T'), s->buf, len);
518             }
519             s->zstream.avail_out = IOBUF_SIZE;
520             s->zstream.next_out  = s->buf;
521             if (ret == Z_STREAM_END)
522                 break;
523         } else {
524             goto fail;
525         }
526     }
527     png_write_chunk(&s->bytestream, MKTAG('I', 'E', 'N', 'D'), NULL, 0);
528
529     pkt->size   = s->bytestream - s->bytestream_start;
530     pkt->flags |= AV_PKT_FLAG_KEY;
531     *got_packet = 1;
532     ret         = 0;
533
534 the_end:
535     av_free(crow_base);
536     av_free(progressive_buf);
537     av_free(top_buf);
538     deflateEnd(&s->zstream);
539     return ret;
540 fail:
541     ret = -1;
542     goto the_end;
543 }
544
545 static av_cold int png_enc_init(AVCodecContext *avctx)
546 {
547     PNGEncContext *s = avctx->priv_data;
548
549     switch (avctx->pix_fmt) {
550     case AV_PIX_FMT_RGBA:
551         avctx->bits_per_coded_sample = 32;
552         break;
553     case AV_PIX_FMT_RGB24:
554         avctx->bits_per_coded_sample = 24;
555         break;
556     case AV_PIX_FMT_GRAY8:
557         avctx->bits_per_coded_sample = 0x28;
558         break;
559     case AV_PIX_FMT_MONOBLACK:
560         avctx->bits_per_coded_sample = 1;
561         break;
562     case AV_PIX_FMT_PAL8:
563         avctx->bits_per_coded_sample = 8;
564     }
565
566     avctx->coded_frame = av_frame_alloc();
567     if (!avctx->coded_frame)
568         return AVERROR(ENOMEM);
569
570     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
571     avctx->coded_frame->key_frame = 1;
572
573     ff_huffyuvencdsp_init(&s->hdsp);
574
575     s->filter_type = av_clip(avctx->prediction_method,
576                              PNG_FILTER_VALUE_NONE,
577                              PNG_FILTER_VALUE_MIXED);
578     if (avctx->pix_fmt == AV_PIX_FMT_MONOBLACK)
579         s->filter_type = PNG_FILTER_VALUE_NONE;
580
581     if (s->dpi && s->dpm) {
582       av_log(avctx, AV_LOG_ERROR, "Only one of 'dpi' or 'dpm' options should be set\n");
583       return AVERROR(EINVAL);
584     } else if (s->dpi) {
585       s->dpm = s->dpi * 10000 / 254;
586     }
587
588     return 0;
589 }
590
591 static av_cold int png_enc_close(AVCodecContext *avctx)
592 {
593     av_frame_free(&avctx->coded_frame);
594     return 0;
595 }
596
597 #define OFFSET(x) offsetof(PNGEncContext, x)
598 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
599 static const AVOption options[] = {
600     {"dpi", "Set image resolution (in dots per inch)",  OFFSET(dpi), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 0x10000, VE},
601     {"dpm", "Set image resolution (in dots per meter)", OFFSET(dpm), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 0x10000, VE},
602     { NULL }
603 };
604
605 static const AVClass pngenc_class = {
606     .class_name = "PNG encoder",
607     .item_name  = av_default_item_name,
608     .option     = options,
609     .version    = LIBAVUTIL_VERSION_INT,
610 };
611
612 AVCodec ff_png_encoder = {
613     .name           = "png",
614     .long_name      = NULL_IF_CONFIG_SMALL("PNG (Portable Network Graphics) image"),
615     .type           = AVMEDIA_TYPE_VIDEO,
616     .id             = AV_CODEC_ID_PNG,
617     .priv_data_size = sizeof(PNGEncContext),
618     .init           = png_enc_init,
619     .close          = png_enc_close,
620     .encode2        = encode_frame,
621     .capabilities   = CODEC_CAP_FRAME_THREADS | CODEC_CAP_INTRA_ONLY,
622     .pix_fmts       = (const enum AVPixelFormat[]) {
623         AV_PIX_FMT_RGB24, AV_PIX_FMT_RGBA,
624         AV_PIX_FMT_RGB48BE, AV_PIX_FMT_RGBA64BE,
625         AV_PIX_FMT_PAL8,
626         AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY8A,
627         AV_PIX_FMT_GRAY16BE, AV_PIX_FMT_YA16BE,
628         AV_PIX_FMT_MONOBLACK, AV_PIX_FMT_NONE
629     },
630     .priv_class     = &pngenc_class,
631 };