FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
pngenc.c File Reference
#include "avcodec.h"
#include "internal.h"
#include "bytestream.h"
#include "lossless_videoencdsp.h"
#include "png.h"
#include "apng.h"
#include "libavutil/avassert.h"
#include "libavutil/crc.h"
#include "libavutil/libm.h"
#include "libavutil/opt.h"
#include "libavutil/color_utils.h"
#include "libavutil/stereo3d.h"
#include <zlib.h>

Go to the source code of this file.

Data Structures

struct  APNGFctlChunk
 
struct  PNGEncContext
 

Macros

#define IOBUF_SIZE   4096
 
#define AV_WB32_PNG(buf, n)   AV_WB32(buf, lrint((n) * 100000))
 
#define OFFSET(x)   offsetof(PNGEncContext, x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Functions

static void png_get_interlaced_row (uint8_t *dst, int row_size, int bits_per_pixel, int pass, const uint8_t *src, int width)
 
static void sub_png_paeth_prediction (uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
 
static void sub_left_prediction (PNGEncContext *c, uint8_t *dst, const uint8_t *src, int bpp, int size)
 
static void png_filter_row (PNGEncContext *c, uint8_t *dst, int filter_type, uint8_t *src, uint8_t *top, int size, int bpp)
 
static uint8_tpng_choose_filter (PNGEncContext *s, uint8_t *dst, uint8_t *src, uint8_t *top, int size, int bpp)
 
static void png_write_chunk (uint8_t **f, uint32_t tag, const uint8_t *buf, int length)
 
static void png_write_image_data (AVCodecContext *avctx, const uint8_t *buf, int length)
 
static int png_write_row (AVCodecContext *avctx, const uint8_t *data, int size)
 
static int png_get_chrm (enum AVColorPrimaries prim, uint8_t *buf)
 
static int png_get_gama (enum AVColorTransferCharacteristic trc, uint8_t *buf)
 
static int encode_headers (AVCodecContext *avctx, const AVFrame *pict)
 
static int encode_frame (AVCodecContext *avctx, const AVFrame *pict)
 
static int encode_png (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
 
static int apng_do_inverse_blend (AVFrame *output, const AVFrame *input, APNGFctlChunk *fctl_chunk, uint8_t bpp)
 
static int apng_encode_frame (AVCodecContext *avctx, const AVFrame *pict, APNGFctlChunk *best_fctl_chunk, APNGFctlChunk *best_last_fctl_chunk)
 
static int encode_apng (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
 
static av_cold int png_enc_init (AVCodecContext *avctx)
 
static av_cold int png_enc_close (AVCodecContext *avctx)
 

Variables

static const AVOption options []
 
static const AVClass pngenc_class
 
static const AVClass apngenc_class
 
AVCodec ff_png_encoder
 
AVCodec ff_apng_encoder
 

Macro Definition Documentation

#define IOBUF_SIZE   4096

Definition at line 38 of file pngenc.c.

Referenced by encode_apng(), encode_frame(), encode_png(), and png_write_row().

#define AV_WB32_PNG (   buf,
  n 
)    AV_WB32(buf, lrint((n) * 100000))

Definition at line 292 of file pngenc.c.

Referenced by png_get_chrm(), and png_get_gama().

#define OFFSET (   x)    offsetof(PNGEncContext, x)

Definition at line 1111 of file pngenc.c.

Definition at line 1112 of file pngenc.c.

Function Documentation

static void png_get_interlaced_row ( uint8_t dst,
int  row_size,
int  bits_per_pixel,
int  pass,
const uint8_t src,
int  width 
)
static

Definition at line 82 of file pngenc.c.

Referenced by encode_frame().

static void sub_png_paeth_prediction ( uint8_t dst,
uint8_t src,
uint8_t top,
int  w,
int  bpp 
)
static

Definition at line 121 of file pngenc.c.

Referenced by png_filter_row().

static void sub_left_prediction ( PNGEncContext c,
uint8_t dst,
const uint8_t src,
int  bpp,
int  size 
)
static

Definition at line 149 of file pngenc.c.

Referenced by png_filter_row().

static void png_filter_row ( PNGEncContext c,
uint8_t dst,
int  filter_type,
uint8_t src,
uint8_t top,
int  size,
int  bpp 
)
static

Definition at line 165 of file pngenc.c.

Referenced by png_choose_filter().

static uint8_t* png_choose_filter ( PNGEncContext s,
uint8_t dst,
uint8_t src,
uint8_t top,
int  size,
int  bpp 
)
static

Definition at line 194 of file pngenc.c.

Referenced by encode_frame().

static void png_write_chunk ( uint8_t **  f,
uint32_t  tag,
const uint8_t buf,
int  length 
)
static

Definition at line 224 of file pngenc.c.

Referenced by encode_apng(), encode_headers(), encode_png(), and png_write_image_data().

static void png_write_image_data ( AVCodecContext avctx,
const uint8_t buf,
int  length 
)
static

Definition at line 243 of file pngenc.c.

Referenced by encode_frame(), and png_write_row().

static int png_write_row ( AVCodecContext avctx,
const uint8_t data,
int  size 
)
static

Definition at line 271 of file pngenc.c.

Referenced by encode_frame().

static int png_get_chrm ( enum AVColorPrimaries  prim,
uint8_t buf 
)
static

Definition at line 293 of file pngenc.c.

Referenced by encode_headers().

static int png_get_gama ( enum AVColorTransferCharacteristic  trc,
uint8_t buf 
)
static

Definition at line 335 of file pngenc.c.

Referenced by encode_headers().

static int encode_headers ( AVCodecContext avctx,
const AVFrame pict 
)
static

Definition at line 345 of file pngenc.c.

Referenced by encode_apng(), and encode_png().

static int encode_frame ( AVCodecContext avctx,
const AVFrame pict 
)
static

Definition at line 431 of file pngenc.c.

Referenced by apng_encode_frame(), and encode_png().

static int encode_png ( AVCodecContext avctx,
AVPacket pkt,
const AVFrame pict,
int got_packet 
)
static

Definition at line 524 of file pngenc.c.

static int apng_do_inverse_blend ( AVFrame output,
const AVFrame input,
APNGFctlChunk fctl_chunk,
uint8_t  bpp 
)
static

Definition at line 569 of file pngenc.c.

Referenced by apng_encode_frame().

static int apng_encode_frame ( AVCodecContext avctx,
const AVFrame pict,
APNGFctlChunk best_fctl_chunk,
APNGFctlChunk best_last_fctl_chunk 
)
static

Definition at line 712 of file pngenc.c.

Referenced by encode_apng().

static int encode_apng ( AVCodecContext avctx,
AVPacket pkt,
const AVFrame pict,
int got_packet 
)
static

Definition at line 841 of file pngenc.c.

static av_cold int png_enc_init ( AVCodecContext avctx)
static

Definition at line 989 of file pngenc.c.

static av_cold int png_enc_close ( AVCodecContext avctx)
static

Definition at line 1098 of file pngenc.c.

Variable Documentation

const AVOption options[]
static
Initial value:
= {
{"dpi", "Set image resolution (in dots per inch)", OFFSET(dpi), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 0x10000, VE},
{"dpm", "Set image resolution (in dots per meter)", OFFSET(dpm), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 0x10000, VE},
{ "pred", "Prediction method", OFFSET(filter_type), AV_OPT_TYPE_INT, { .i64 = PNG_FILTER_VALUE_NONE }, PNG_FILTER_VALUE_NONE, PNG_FILTER_VALUE_MIXED, VE, "pred" },
{ "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_NONE }, INT_MIN, INT_MAX, VE, "pred" },
{ "sub", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_SUB }, INT_MIN, INT_MAX, VE, "pred" },
{ "up", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_UP }, INT_MIN, INT_MAX, VE, "pred" },
{ "avg", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_AVG }, INT_MIN, INT_MAX, VE, "pred" },
{ "paeth", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_PAETH }, INT_MIN, INT_MAX, VE, "pred" },
{ "mixed", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_MIXED }, INT_MIN, INT_MAX, VE, "pred" },
{ NULL},
}
#define PNG_FILTER_VALUE_AVG
Definition: png.h:41
#define NULL
Definition: coverity.c:32
#define OFFSET(x)
Definition: pngenc.c:1111
#define PNG_FILTER_VALUE_PAETH
Definition: png.h:42
#define PNG_FILTER_VALUE_MIXED
Definition: png.h:43
#define PNG_FILTER_VALUE_SUB
Definition: png.h:39
#define PNG_FILTER_VALUE_UP
Definition: png.h:40
#define VE
Definition: pngenc.c:1112
#define PNG_FILTER_VALUE_NONE
Definition: png.h:38

Definition at line 1113 of file pngenc.c.

const AVClass pngenc_class
static
Initial value:
= {
.class_name = "PNG encoder",
.item_name = av_default_item_name,
.option = options,
}
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
av_default_item_name
static const AVOption options[]
Definition: pngenc.c:1113

Definition at line 1126 of file pngenc.c.

const AVClass apngenc_class
static
Initial value:
= {
.class_name = "APNG encoder",
.item_name = av_default_item_name,
.option = options,
}
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
av_default_item_name
static const AVOption options[]
Definition: pngenc.c:1113

Definition at line 1133 of file pngenc.c.

AVCodec ff_png_encoder
Initial value:
= {
.name = "png",
.long_name = NULL_IF_CONFIG_SMALL("PNG (Portable Network Graphics) image"),
.priv_data_size = sizeof(PNGEncContext),
.close = png_enc_close,
.encode2 = encode_png,
.pix_fmts = (const enum AVPixelFormat[]) {
},
.priv_class = &pngenc_class,
}
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:64
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static int encode_png(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
Definition: pngenc.c:524
static const AVClass pngenc_class
Definition: pngenc.c:1126
#define AV_CODEC_CAP_INTRA_ONLY
Codec is intra only.
Definition: avcodec.h:1087
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:73
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: pixfmt.h:217
16 bits gray, 16 bits alpha (big-endian)
Definition: pixfmt.h:226
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:1057
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:94
alias for AV_PIX_FMT_YA8
Definition: pixfmt.h:157
Y , 16bpp, big-endian.
Definition: pixfmt.h:98
static av_cold int png_enc_init(AVCodecContext *avctx)
Definition: pngenc.c:989
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:262
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:72
Y , 8bpp.
Definition: pixfmt.h:70
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:110
static av_cold int png_enc_close(AVCodecContext *avctx)
Definition: pngenc.c:1098
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60

Definition at line 1140 of file pngenc.c.

AVCodec ff_apng_encoder
Initial value:
= {
.name = "apng",
.long_name = NULL_IF_CONFIG_SMALL("APNG (Animated Portable Network Graphics) image"),
.priv_data_size = sizeof(PNGEncContext),
.close = png_enc_close,
.encode2 = encode_apng,
.capabilities = AV_CODEC_CAP_DELAY,
.pix_fmts = (const enum AVPixelFormat[]) {
},
.priv_class = &apngenc_class,
}
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:64
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static const AVClass apngenc_class
Definition: pngenc.c:1133
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: avcodec.h:1019
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:73
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: pixfmt.h:217
16 bits gray, 16 bits alpha (big-endian)
Definition: pixfmt.h:226
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:94
alias for AV_PIX_FMT_YA8
Definition: pixfmt.h:157
static int encode_apng(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
Definition: pngenc.c:841
Y , 16bpp, big-endian.
Definition: pixfmt.h:98
static av_cold int png_enc_init(AVCodecContext *avctx)
Definition: pngenc.c:989
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:262
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:72
Y , 8bpp.
Definition: pixfmt.h:70
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:110
static av_cold int png_enc_close(AVCodecContext *avctx)
Definition: pngenc.c:1098
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60

Definition at line 1161 of file pngenc.c.