FFmpeg
Loading...
Searching...
No Matches
pngenc.c File Reference
#include "avcodec.h"
#include "codec_internal.h"
#include "encode.h"
#include "exif_internal.h"
#include "bytestream.h"
#include "lossless_videoencdsp.h"
#include "png.h"
#include "apng.h"
#include "zlib_wrapper.h"
#include "libavutil/avassert.h"
#include "libavutil/buffer.h"
#include "libavutil/crc.h"
#include "libavutil/csp.h"
#include "libavutil/libm.h"
#include "libavutil/mastering_display_metadata.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/rational.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 PNG_LRINT(d, divisor)
 
#define PNG_Q2D(q, divisor)
 
#define AV_WB32_PNG_D(buf, q)
 
#define OFFSET(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, const uint8_t *src, const 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, const uint8_t *src, const uint8_t *top, int size, int bpp)
 
static uint8_t * png_choose_filter (PNGEncContext *s, uint8_t *dst, const uint8_t *src, const 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 png_write_iccp (PNGEncContext *s, const AVFrameSideData *sd)
 
static int encode_headers (AVCodecContext *avctx, const AVFrame *pict)
 
static int encode_frame (AVCodecContext *avctx, const AVFrame *pict)
 
static int add_icc_profile_size (AVCodecContext *avctx, const AVFrame *pict, uint64_t *max_packet_size)
 
static int add_exif_profile_size (AVCodecContext *avctx, const AVFrame *pict, uint64_t *max_packet_size)
 
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
 
const FFCodec ff_png_encoder
 
const FFCodec ff_apng_encoder
 

Macro Definition Documentation

◆ IOBUF_SIZE

#define IOBUF_SIZE   4096

Definition at line 45 of file pngenc.c.

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

◆ PNG_LRINT

#define PNG_LRINT ( d,
divisor )
Value:
lrint((d) * (divisor))
#define lrint
Definition tablegen.h:53

Definition at line 305 of file pngenc.c.

Referenced by png_get_gama().

◆ PNG_Q2D

#define PNG_Q2D ( q,
divisor )
Value:
PNG_LRINT(av_q2d(q), (divisor))
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition rational.h:104
#define PNG_LRINT(d, divisor)
Definition pngenc.c:305

Definition at line 306 of file pngenc.c.

Referenced by encode_headers().

◆ AV_WB32_PNG_D

#define AV_WB32_PNG_D ( buf,
q )
Value:
AV_WB32(buf, PNG_Q2D(q, 100000))
#define AV_WB32(p, v)
#define PNG_Q2D(q, divisor)
Definition pngenc.c:306

Definition at line 307 of file pngenc.c.

Referenced by png_get_chrm().

◆ OFFSET

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

Definition at line 1267 of file pngenc.c.

◆ VE

Definition at line 1268 of file pngenc.c.

Function Documentation

◆ png_get_interlaced_row()

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 91 of file pngenc.c.

Referenced by encode_frame().

◆ sub_png_paeth_prediction()

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

Definition at line 130 of file pngenc.c.

Referenced by png_filter_row().

◆ sub_left_prediction()

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

Definition at line 158 of file pngenc.c.

Referenced by png_filter_row().

◆ png_filter_row()

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

Definition at line 174 of file pngenc.c.

Referenced by png_choose_filter().

◆ png_choose_filter()

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

Definition at line 205 of file pngenc.c.

Referenced by encode_frame().

◆ png_write_chunk()

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

◆ png_write_image_data()

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

Definition at line 255 of file pngenc.c.

Referenced by encode_frame(), and png_write_row().

◆ png_write_row()

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

Definition at line 283 of file pngenc.c.

Referenced by encode_frame().

◆ png_get_chrm()

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

Definition at line 308 of file pngenc.c.

Referenced by encode_headers().

◆ png_get_gama()

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

Definition at line 326 of file pngenc.c.

Referenced by encode_headers().

◆ png_write_iccp()

static int png_write_iccp ( PNGEncContext * s,
const AVFrameSideData * sd )
static

Definition at line 336 of file pngenc.c.

Referenced by encode_headers().

◆ encode_headers()

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

Definition at line 378 of file pngenc.c.

Referenced by encode_apng(), and encode_png().

◆ encode_frame()

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

Definition at line 521 of file pngenc.c.

Referenced by apng_encode_frame(), and encode_png().

◆ add_icc_profile_size()

static int add_icc_profile_size ( AVCodecContext * avctx,
const AVFrame * pict,
uint64_t * max_packet_size )
static

Definition at line 615 of file pngenc.c.

Referenced by encode_apng(), and encode_png().

◆ add_exif_profile_size()

static int add_exif_profile_size ( AVCodecContext * avctx,
const AVFrame * pict,
uint64_t * max_packet_size )
static

Definition at line 643 of file pngenc.c.

Referenced by encode_apng(), and encode_png().

◆ encode_png()

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

Definition at line 676 of file pngenc.c.

◆ apng_do_inverse_blend()

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

Definition at line 726 of file pngenc.c.

Referenced by apng_encode_frame().

◆ 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 872 of file pngenc.c.

Referenced by encode_apng().

◆ encode_apng()

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

Definition at line 1005 of file pngenc.c.

◆ png_enc_init()

static av_cold int png_enc_init ( AVCodecContext * avctx)
static

Definition at line 1166 of file pngenc.c.

◆ png_enc_close()

static av_cold int png_enc_close ( AVCodecContext * avctx)
static

Definition at line 1253 of file pngenc.c.

Variable Documentation

◆ options

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_PAETH }, PNG_FILTER_VALUE_NONE, PNG_FILTER_VALUE_MIXED, VE, .unit = "pred" },
{ "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_NONE }, INT_MIN, INT_MAX, VE, .unit = "pred" },
{ "sub", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_SUB }, INT_MIN, INT_MAX, VE, .unit = "pred" },
{ "up", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_UP }, INT_MIN, INT_MAX, VE, .unit = "pred" },
{ "avg", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_AVG }, INT_MIN, INT_MAX, VE, .unit = "pred" },
{ "paeth", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_PAETH }, INT_MIN, INT_MAX, VE, .unit = "pred" },
{ "mixed", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PNG_FILTER_VALUE_MIXED }, INT_MIN, INT_MAX, VE, .unit = "pred" },
{ NULL},
}
#define VE
Definition amfenc_av1.c:30
#define NULL
Definition coverity.c:32
#define OFFSET(x)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
#define PNG_FILTER_VALUE_MIXED
Definition png.h:45
#define PNG_FILTER_VALUE_AVG
Definition png.h:43
#define PNG_FILTER_VALUE_UP
Definition png.h:42
#define PNG_FILTER_VALUE_PAETH
Definition png.h:44
#define PNG_FILTER_VALUE_NONE
Definition png.h:40
#define PNG_FILTER_VALUE_SUB
Definition png.h:41

Definition at line 1269 of file pngenc.c.

◆ pngenc_class

const AVClass pngenc_class
static
Initial value:
= {
.class_name = "(A)PNG encoder",
.item_name = av_default_item_name,
.option = options,
}
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
#define LIBAVUTIL_VERSION_INT
Definition version.h:85

Definition at line 1282 of file pngenc.c.

◆ ff_png_encoder

const FFCodec ff_png_encoder
Initial value:
= {
.p.name = "png",
CODEC_LONG_NAME("PNG (Portable Network Graphics) image"),
.p.type = AVMEDIA_TYPE_VIDEO,
.p.id = AV_CODEC_ID_PNG,
.priv_data_size = sizeof(PNGEncContext),
.alpha_modes = AVALPHA_MODE_STRAIGHT,
.p.priv_class = &pngenc_class,
.caps_internal = FF_CODEC_CAP_ICC_PROFILES,
}
static av_cold void close(AVCodecParserContext *s)
Definition apv_parser.c:197
#define CODEC_PIXFMTS(...)
#define FF_CODEC_CAP_ICC_PROFILES
Codec supports embedded ICC profiles (AV_FRAME_DATA_ICC_PROFILE).
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition codec.h:147
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition codec.h:98
@ AV_CODEC_ID_PNG
Definition codec_id.h:111
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
@ AVALPHA_MODE_STRAIGHT
Alpha channel is independent of color values.
Definition pixfmt.h:819
@ AV_PIX_FMT_GRAY16BE
Y , 16bpp, big-endian.
Definition pixfmt.h:104
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition pixfmt.h:75
@ AV_PIX_FMT_YA16BE
16 bits gray, 16 bits alpha (big-endian)
Definition pixfmt.h:209
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
Definition pixfmt.h:83
@ AV_PIX_FMT_GRAY8A
alias for AV_PIX_FMT_YA8
Definition pixfmt.h:143
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition pixfmt.h:81
@ AV_PIX_FMT_RGB48BE
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:109
@ AV_PIX_FMT_RGBA64BE
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:202
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition pixfmt.h:100
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition pixfmt.h:84
static av_cold int png_enc_init(AVCodecContext *avctx)
Definition pngenc.c:1166
static int encode_png(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
Definition pngenc.c:676
static const AVClass pngenc_class
Definition pngenc.c:1282
static av_cold int png_enc_close(AVCodecContext *avctx)
Definition pngenc.c:1253

Definition at line 1289 of file pngenc.c.

◆ ff_apng_encoder

const FFCodec ff_apng_encoder
Initial value:
= {
.p.name = "apng",
CODEC_LONG_NAME("APNG (Animated Portable Network Graphics) image"),
.p.type = AVMEDIA_TYPE_VIDEO,
.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
.priv_data_size = sizeof(PNGEncContext),
.alpha_modes = AVALPHA_MODE_STRAIGHT,
.p.priv_class = &pngenc_class,
.caps_internal = FF_CODEC_CAP_ICC_PROFILES,
}
#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 codec.h:79
@ AV_CODEC_ID_APNG
Definition codec_id.h:260
static int encode_apng(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
Definition pngenc.c:1005

Definition at line 1311 of file pngenc.c.