FFmpeg  2.1.1
pngenc.c
Go to the documentation of this file.
1 /*
2  * PNG image format
3  * Copyright (c) 2003 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #include "avcodec.h"
22 #include "internal.h"
23 #include "bytestream.h"
24 #include "dsputil.h"
25 #include "png.h"
26 
27 #include "libavutil/avassert.h"
28 #include "libavutil/opt.h"
29 
30 #include <zlib.h>
31 
32 #define IOBUF_SIZE 4096
33 
34 typedef struct PNGEncContext {
35  AVClass *class;
37 
42 
44 
45  z_stream zstream;
47  int dpi; ///< Physical pixel density, in dots per inch, if set
48  int dpm; ///< Physical pixel density, in dots per meter, if set
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, int w, int bpp)
91 {
92  int i;
93  for(i = 0; i < w; i++) {
94  int a, b, c, p, pa, pb, pc;
95 
96  a = src[i - bpp];
97  b = top[i];
98  c = top[i - bpp];
99 
100  p = b - c;
101  pc = a - c;
102 
103  pa = abs(p);
104  pb = abs(pc);
105  pc = abs(p + pc);
106 
107  if (pa <= pb && pa <= pc)
108  p = a;
109  else if (pb <= pc)
110  p = b;
111  else
112  p = c;
113  dst[i] = src[i] - p;
114  }
115 }
116 
117 static void png_filter_row(DSPContext *dsp, uint8_t *dst, int filter_type,
118  uint8_t *src, uint8_t *top, int size, int bpp)
119 {
120  int i;
121 
122  switch(filter_type) {
124  memcpy(dst, src, size);
125  break;
127  dsp->diff_bytes(dst, src, src-bpp, size);
128  memcpy(dst, src, bpp);
129  break;
130  case PNG_FILTER_VALUE_UP:
131  dsp->diff_bytes(dst, src, top, size);
132  break;
134  for(i = 0; i < bpp; i++)
135  dst[i] = src[i] - (top[i] >> 1);
136  for(; i < size; i++)
137  dst[i] = src[i] - ((src[i-bpp] + top[i]) >> 1);
138  break;
140  for(i = 0; i < bpp; i++)
141  dst[i] = src[i] - top[i];
142  sub_png_paeth_prediction(dst+i, src+i, top+i, size-i, bpp);
143  break;
144  }
145 }
146 
148  uint8_t *src, uint8_t *top, int size, int bpp)
149 {
150  int pred = s->filter_type;
151  av_assert0(bpp || !pred);
152  if(!top && pred)
153  pred = PNG_FILTER_VALUE_SUB;
154  if(pred == PNG_FILTER_VALUE_MIXED) {
155  int i;
156  int cost, bcost = INT_MAX;
157  uint8_t *buf1 = dst, *buf2 = dst + size + 16;
158  for(pred=0; pred<5; pred++) {
159  png_filter_row(&s->dsp, buf1+1, pred, src, top, size, bpp);
160  buf1[0] = pred;
161  cost = 0;
162  for(i=0; i<=size; i++)
163  cost += abs((int8_t)buf1[i]);
164  if(cost < bcost) {
165  bcost = cost;
166  FFSWAP(uint8_t*, buf1, buf2);
167  }
168  }
169  return buf2;
170  } else {
171  png_filter_row(&s->dsp, dst+1, pred, src, top, size, bpp);
172  dst[0] = pred;
173  return dst;
174  }
175 }
176 
177 static void png_write_chunk(uint8_t **f, uint32_t tag,
178  const uint8_t *buf, int length)
179 {
180  uint32_t crc;
181  uint8_t tagbuf[4];
182 
183  bytestream_put_be32(f, length);
184  crc = crc32(0, Z_NULL, 0);
185  AV_WL32(tagbuf, tag);
186  crc = crc32(crc, tagbuf, 4);
187  bytestream_put_be32(f, av_bswap32(tag));
188  if (length > 0) {
189  crc = crc32(crc, buf, length);
190  memcpy(*f, buf, length);
191  *f += length;
192  }
193  bytestream_put_be32(f, crc);
194 }
195 
196 /* XXX: do filtering */
197 static int png_write_row(PNGEncContext *s, const uint8_t *data, int size)
198 {
199  int ret;
200 
201  s->zstream.avail_in = size;
202  s->zstream.next_in = (uint8_t *)data;
203  while (s->zstream.avail_in > 0) {
204  ret = deflate(&s->zstream, Z_NO_FLUSH);
205  if (ret != Z_OK)
206  return -1;
207  if (s->zstream.avail_out == 0) {
208  if(s->bytestream_end - s->bytestream > IOBUF_SIZE + 100)
209  png_write_chunk(&s->bytestream, MKTAG('I', 'D', 'A', 'T'), s->buf, IOBUF_SIZE);
210  s->zstream.avail_out = IOBUF_SIZE;
211  s->zstream.next_out = s->buf;
212  }
213  }
214  return 0;
215 }
216 
218  const AVFrame *pict, int *got_packet)
219 {
220  PNGEncContext *s = avctx->priv_data;
221  AVFrame * const p= &s->picture;
222  int bit_depth, color_type, y, len, row_size, ret, is_progressive;
223  int bits_per_pixel, pass_row_size, enc_row_size;
224  int64_t max_packet_size;
225  int compression_level;
226  uint8_t *ptr, *top;
227  uint8_t *crow_base = NULL, *crow_buf, *crow;
228  uint8_t *progressive_buf = NULL;
229  uint8_t *top_buf = NULL;
230 
231  *p = *pict;
233  p->key_frame= 1;
234 
235  is_progressive = !!(avctx->flags & CODEC_FLAG_INTERLACED_DCT);
236  switch(avctx->pix_fmt) {
237  case AV_PIX_FMT_RGBA64BE:
238  bit_depth = 16;
239  color_type = PNG_COLOR_TYPE_RGB_ALPHA;
240  break;
241  case AV_PIX_FMT_RGB48BE:
242  bit_depth = 16;
243  color_type = PNG_COLOR_TYPE_RGB;
244  break;
245  case AV_PIX_FMT_RGBA:
246  bit_depth = 8;
247  color_type = PNG_COLOR_TYPE_RGB_ALPHA;
248  break;
249  case AV_PIX_FMT_RGB24:
250  bit_depth = 8;
251  color_type = PNG_COLOR_TYPE_RGB;
252  break;
253  case AV_PIX_FMT_GRAY16BE:
254  bit_depth = 16;
255  color_type = PNG_COLOR_TYPE_GRAY;
256  break;
257  case AV_PIX_FMT_GRAY8:
258  bit_depth = 8;
259  color_type = PNG_COLOR_TYPE_GRAY;
260  break;
261  case AV_PIX_FMT_GRAY8A:
262  bit_depth = 8;
263  color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
264  break;
266  bit_depth = 1;
267  color_type = PNG_COLOR_TYPE_GRAY;
268  break;
269  case AV_PIX_FMT_PAL8:
270  bit_depth = 8;
271  color_type = PNG_COLOR_TYPE_PALETTE;
272  break;
273  default:
274  return -1;
275  }
276  bits_per_pixel = ff_png_get_nb_channels(color_type) * bit_depth;
277  row_size = (avctx->width * bits_per_pixel + 7) >> 3;
278 
279  s->zstream.zalloc = ff_png_zalloc;
280  s->zstream.zfree = ff_png_zfree;
281  s->zstream.opaque = NULL;
282  compression_level = avctx->compression_level == FF_COMPRESSION_DEFAULT ?
283  Z_DEFAULT_COMPRESSION :
284  av_clip(avctx->compression_level, 0, 9);
285  ret = deflateInit2(&s->zstream, compression_level,
286  Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY);
287  if (ret != Z_OK)
288  return -1;
289 
290  enc_row_size = deflateBound(&s->zstream, row_size);
291  max_packet_size = avctx->height * (int64_t)(enc_row_size +
292  ((enc_row_size + IOBUF_SIZE - 1) / IOBUF_SIZE) * 12)
294  if (max_packet_size > INT_MAX)
295  return AVERROR(ENOMEM);
296  if ((ret = ff_alloc_packet2(avctx, pkt, max_packet_size)) < 0)
297  return ret;
298 
299  s->bytestream_start =
300  s->bytestream = pkt->data;
301  s->bytestream_end = pkt->data + pkt->size;
302 
303  crow_base = av_malloc((row_size + 32) << (s->filter_type == PNG_FILTER_VALUE_MIXED));
304  if (!crow_base)
305  goto fail;
306  crow_buf = crow_base + 15; // pixel data should be aligned, but there's a control byte before it
307  if (is_progressive) {
308  progressive_buf = av_malloc(row_size + 1);
309  if (!progressive_buf)
310  goto fail;
311  }
312  if (is_progressive) {
313  top_buf = av_malloc(row_size + 1);
314  if (!top_buf)
315  goto fail;
316  }
317 
318  /* write png header */
320  s->bytestream += 8;
321 
322  AV_WB32(s->buf, avctx->width);
323  AV_WB32(s->buf + 4, avctx->height);
324  s->buf[8] = bit_depth;
325  s->buf[9] = color_type;
326  s->buf[10] = 0; /* compression type */
327  s->buf[11] = 0; /* filter type */
328  s->buf[12] = is_progressive; /* interlace type */
329 
330  png_write_chunk(&s->bytestream, MKTAG('I', 'H', 'D', 'R'), s->buf, 13);
331 
332  if (s->dpm) {
333  AV_WB32(s->buf, s->dpm);
334  AV_WB32(s->buf + 4, s->dpm);
335  s->buf[8] = 1; /* unit specifier is meter */
336  } else {
337  AV_WB32(s->buf, avctx->sample_aspect_ratio.num);
338  AV_WB32(s->buf + 4, avctx->sample_aspect_ratio.den);
339  s->buf[8] = 0; /* unit specifier is unknown */
340  }
341  png_write_chunk(&s->bytestream, MKTAG('p', 'H', 'Y', 's'), s->buf, 9);
342 
343  /* put the palette if needed */
344  if (color_type == PNG_COLOR_TYPE_PALETTE) {
345  int has_alpha, alpha, i;
346  unsigned int v;
347  uint32_t *palette;
348  uint8_t *alpha_ptr;
349 
350  palette = (uint32_t *)p->data[1];
351  ptr = s->buf;
352  alpha_ptr = s->buf + 256 * 3;
353  has_alpha = 0;
354  for(i = 0; i < 256; i++) {
355  v = palette[i];
356  alpha = v >> 24;
357  if (alpha != 0xff)
358  has_alpha = 1;
359  *alpha_ptr++ = alpha;
360  bytestream_put_be24(&ptr, v);
361  }
362  png_write_chunk(&s->bytestream, MKTAG('P', 'L', 'T', 'E'), s->buf, 256 * 3);
363  if (has_alpha) {
364  png_write_chunk(&s->bytestream, MKTAG('t', 'R', 'N', 'S'), s->buf + 256 * 3, 256);
365  }
366  }
367 
368  /* now put each row */
369  s->zstream.avail_out = IOBUF_SIZE;
370  s->zstream.next_out = s->buf;
371  if (is_progressive) {
372  int pass;
373 
374  for(pass = 0; pass < NB_PASSES; pass++) {
375  /* NOTE: a pass is completely omitted if no pixels would be
376  output */
377  pass_row_size = ff_png_pass_row_size(pass, bits_per_pixel, avctx->width);
378  if (pass_row_size > 0) {
379  top = NULL;
380  for(y = 0; y < avctx->height; y++) {
381  if ((ff_png_pass_ymask[pass] << (y & 7)) & 0x80) {
382  ptr = p->data[0] + y * p->linesize[0];
383  FFSWAP(uint8_t*, progressive_buf, top_buf);
384  png_get_interlaced_row(progressive_buf, pass_row_size,
385  bits_per_pixel, pass,
386  ptr, avctx->width);
387  crow = png_choose_filter(s, crow_buf, progressive_buf, top, pass_row_size, bits_per_pixel>>3);
388  png_write_row(s, crow, pass_row_size + 1);
389  top = progressive_buf;
390  }
391  }
392  }
393  }
394  } else {
395  top = NULL;
396  for(y = 0; y < avctx->height; y++) {
397  ptr = p->data[0] + y * p->linesize[0];
398  crow = png_choose_filter(s, crow_buf, ptr, top, row_size, bits_per_pixel>>3);
399  png_write_row(s, crow, row_size + 1);
400  top = ptr;
401  }
402  }
403  /* compress last bytes */
404  for(;;) {
405  ret = deflate(&s->zstream, Z_FINISH);
406  if (ret == Z_OK || ret == Z_STREAM_END) {
407  len = IOBUF_SIZE - s->zstream.avail_out;
408  if (len > 0 && s->bytestream_end - s->bytestream > len + 100) {
409  png_write_chunk(&s->bytestream, MKTAG('I', 'D', 'A', 'T'), s->buf, len);
410  }
411  s->zstream.avail_out = IOBUF_SIZE;
412  s->zstream.next_out = s->buf;
413  if (ret == Z_STREAM_END)
414  break;
415  } else {
416  goto fail;
417  }
418  }
419  png_write_chunk(&s->bytestream, MKTAG('I', 'E', 'N', 'D'), NULL, 0);
420 
421  pkt->size = s->bytestream - s->bytestream_start;
422  pkt->flags |= AV_PKT_FLAG_KEY;
423  *got_packet = 1;
424  ret = 0;
425 
426  the_end:
427  av_free(crow_base);
428  av_free(progressive_buf);
429  av_free(top_buf);
430  deflateEnd(&s->zstream);
431  return ret;
432  fail:
433  ret = -1;
434  goto the_end;
435 }
436 
438  PNGEncContext *s = avctx->priv_data;
439 
440  switch(avctx->pix_fmt) {
441  case AV_PIX_FMT_RGBA:
442  avctx->bits_per_coded_sample = 32;
443  break;
444  case AV_PIX_FMT_RGB24:
445  avctx->bits_per_coded_sample = 24;
446  break;
447  case AV_PIX_FMT_GRAY8:
448  avctx->bits_per_coded_sample = 0x28;
449  break;
451  avctx->bits_per_coded_sample = 1;
452  break;
453  case AV_PIX_FMT_PAL8:
454  avctx->bits_per_coded_sample = 8;
455  }
456 
458  avctx->coded_frame= &s->picture;
459  ff_dsputil_init(&s->dsp, avctx);
460 
462  if(avctx->pix_fmt == AV_PIX_FMT_MONOBLACK)
464 
465  if (s->dpi && s->dpm) {
466  av_log(avctx, AV_LOG_ERROR, "Only one of 'dpi' or 'dpm' options should be set\n");
467  return AVERROR(EINVAL);
468  } else if (s->dpi) {
469  s->dpm = s->dpi * 10000 / 254;
470  }
471 
472  return 0;
473 }
474 
475 #define OFFSET(x) offsetof(PNGEncContext, x)
476 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
477 static const AVOption options[] = {
478  {"dpi", "Set image resolution (in dots per inch)", OFFSET(dpi), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 0x10000, VE},
479  {"dpm", "Set image resolution (in dots per meter)", OFFSET(dpm), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 0x10000, VE},
480  { NULL }
481 };
482 
483 static const AVClass pngenc_class = {
484  .class_name = "PNG encoder",
485  .item_name = av_default_item_name,
486  .option = options,
487  .version = LIBAVUTIL_VERSION_INT,
488 };
489 
491  .name = "png",
492  .long_name = NULL_IF_CONFIG_SMALL("PNG (Portable Network Graphics) image"),
493  .type = AVMEDIA_TYPE_VIDEO,
494  .id = AV_CODEC_ID_PNG,
495  .priv_data_size = sizeof(PNGEncContext),
496  .init = png_enc_init,
497  .encode2 = encode_frame,
499  .pix_fmts = (const enum AVPixelFormat[]){
506  },
507  .priv_class = &pngenc_class,
508 };
#define PNG_FILTER_VALUE_AVG
Definition: png.h:41
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and/or allocate data.
Definition: utils.c:1500
av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx)
Definition: dsputil.c:2678
float v
const char * s
Definition: avisynth_c.h:668
int size
This structure describes decoded (raw) audio or video data.
Definition: frame.h:96
BYTE int const BYTE int int row_size
Definition: avisynth_c.h:713
AVOption.
Definition: opt.h:253
static uint8_t * png_choose_filter(PNGEncContext *s, uint8_t *dst, uint8_t *src, uint8_t *top, int size, int bpp)
Definition: pngenc.c:147
#define LIBAVUTIL_VERSION_INT
Definition: avcodec.h:820
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define AV_WL32(p, darg)
Definition: intreadwrite.h:282
uint8_t * bytestream
Definition: pngenc.c:38
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: avcodec.h:4536
int num
numerator
Definition: rational.h:44
int size
Definition: avcodec.h:1064
const char * b
Definition: vf_curves.c:105
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
Definition: avcodec.h:1517
#define pass
Definition: fft.c:511
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1342
8bit gray, 8bit alpha
Definition: avcodec.h:4611
#define PNG_COLOR_TYPE_RGB
Definition: png.h:33
static const AVClass pngenc_class
Definition: pngenc.c:483
Pixel format.
Definition: avcodec.h:4533
#define PNG_COLOR_TYPE_GRAY_ALPHA
Definition: png.h:35
AVCodec.
Definition: avcodec.h:2922
#define av_cold
Definition: avcodec.h:653
Y , 8bpp.
Definition: avcodec.h:4542
#define PNG_COLOR_TYPE_PALETTE
Definition: png.h:32
AVFrame picture
Definition: pngenc.c:41
#define OFFSET(x)
Definition: pngenc.c:475
int filter_type
Definition: pngenc.c:43
#define PNG_FILTER_VALUE_PAETH
Definition: png.h:42
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
Definition: avcodec.h:4579
const char * av_default_item_name(void *ctx)
Return the context name.
Definition: log.c:145
uint8_t
#define PNG_COLOR_TYPE_RGB_ALPHA
Definition: png.h:34
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:55
#define CODEC_CAP_INTRA_ONLY
Codec is intra only.
Definition: avcodec.h:831
static void sub_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
Definition: pngenc.c:90
const char * name
Name of the codec implementation.
Definition: avcodec.h:2929
const char data[16]
Definition: mxf.c:68
uint32_t tag
Definition: movenc.c:961
#define AV_WB32(p, darg)
Definition: intreadwrite.h:265
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:2563
#define FFSWAP(type, a, b)
Definition: avcodec.h:928
const OptionDef options[]
Definition: ffserver.c:4682
#define PNG_FILTER_VALUE_MIXED
Definition: png.h:43
#define FF_COMPRESSION_DEFAULT
Definition: avcodec.h:1227
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1113
void(* diff_bytes)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w)
Definition: dsputil.h:195
static double alpha(void *priv, double x, double y)
Definition: vf_geq.c:98
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: avcodec.h:4147
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:219
static void png_get_interlaced_row(uint8_t *dst, int row_size, int bits_per_pixel, int pass, const uint8_t *src, int width)
Definition: pngenc.c:51
static const uint16_t mask[17]
Definition: lzw.c:37
z_stream zstream
Definition: pngenc.c:45
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:151
int dpm
Physical pixel density, in dots per meter, if set.
Definition: pngenc.c:48
int ff_png_get_nb_channels(int color_type)
Definition: png.c:49
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1234
#define PNGSIG
Definition: png.h:52
Libavcodec external API header.
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
#define NB_PASSES
Definition: png.h:50
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1069
static unsigned crc32(const uint8_t *data, unsigned size)
Definition: crypto_bench.c:232
goto fail
Definition: avfilter.c:963
uint8_t * bytestream_start
Definition: pngenc.c:39
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:167
#define PNG_FILTER_VALUE_SUB
Definition: png.h:39
float y
#define FF_MIN_BUFFER_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
Definition: avcodec.h:587
static void png_write_chunk(uint8_t **f, uint32_t tag, const uint8_t *buf, int length)
Definition: pngenc.c:177
#define PNG_COLOR_TYPE_GRAY
Definition: png.h:31
ret
Definition: avfilter.c:961
int width
picture width / height.
Definition: avcodec.h:1314
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
#define CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
Definition: avcodec.h:711
int AC3_NAME() encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
static const float pred[4]
Definition: siprdata.h:259
#define IOBUF_SIZE
Definition: pngenc.c:32
static int width
Definition: utils.c:158
AVCodec ff_png_encoder
Definition: pngenc.c:490
AVS_Value src
Definition: avisynth_c.h:523
int compression_level
Definition: avcodec.h:1226
#define PNG_FILTER_VALUE_UP
Definition: png.h:40
main external API structure.
Definition: avcodec.h:1146
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: avcodec.h:4684
void * buf
Definition: avisynth_c.h:594
const uint8_t ff_png_pass_ymask[NB_PASSES]
Definition: png.c:25
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
Definition: utils.c:1046
Describe the class of an AVClass context structure.
Definition: log.h:50
#define MKTAG(a, b, c, d)
AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2588
uint8_t * data
Definition: avcodec.h:1063
int dpi
Physical pixel density, in dots per inch, if set.
Definition: pngenc.c:47
#define VE
Definition: pngenc.c:476
static av_cold int png_enc_init(AVCodecContext *avctx)
Definition: pngenc.c:437
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:124
uint8_t * bytestream_end
Definition: pngenc.c:40
#define AV_WB64(p, darg)
Definition: intreadwrite.h:303
void * priv_data
Definition: avcodec.h:1182
uint8_t buf[IOBUF_SIZE]
Definition: pngenc.c:46
int palette
Definition: v4l.c:60
common internal api header.
#define CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:811
#define PNG_FILTER_VALUE_NONE
Definition: png.h:38
static double c[64]
int prediction_method
prediction method (needed for huffyuv)
Definition: avcodec.h:1498
int den
denominator
Definition: rational.h:45
void ff_png_zfree(void *opaque, void *ptr)
Definition: png.c:44
DSP utils.
static void png_filter_row(DSPContext *dsp, uint8_t *dst, int filter_type, uint8_t *src, uint8_t *top, int size, int bpp)
Definition: pngenc.c:117
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
Definition: avcodec.h:4544
int len
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: avcodec.h:4563
int key_frame
1 -&gt; keyframe, 0-&gt; not
Definition: frame.h:162
static int png_write_row(PNGEncContext *s, const uint8_t *data, int size)
Definition: pngenc.c:197
#define AVERROR(e)
int ff_png_pass_row_size(int pass, int bits_per_pixel, int width)
Definition: png.c:62
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
static AVPacket pkt
Definition: demuxing.c:52
const char int length
Definition: avisynth_c.h:668
8 bit with PIX_FMT_RGB32 palette
Definition: avcodec.h:4545
DSPContext dsp
Definition: pngenc.c:36
void * ff_png_zalloc(void *opaque, unsigned int items, unsigned int size)
Definition: png.c:39
This structure stores compressed data.
Definition: avcodec.h:1040
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:107
Y , 16bpp, big-endian.
Definition: avcodec.h:4567
DSPContext.
Definition: dsputil.h:124
#define av_bswap32
Definition: bswap.h:33