37 #define IOBUF_SIZE 4096
65 int bits_per_pixel,
int pass,
68 int x,
mask, dst_x, j,
b, bpp;
71 static const int masks[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
74 switch (bits_per_pixel) {
76 memset(dst, 0, row_size);
78 for (x = 0; x <
width; x++) {
80 if ((mask << j) & 0x80) {
81 b = (src[x >> 3] >> (7 - j)) & 1;
82 dst[dst_x >> 3] |= b << (7 - (dst_x & 7));
88 bpp = bits_per_pixel >> 3;
91 for (x = 0; x <
width; x++) {
93 if ((mask << j) & 0x80) {
107 for (i = 0; i < w; i++) {
108 int a,
b,
c, p, pa, pb, pc;
121 if (pa <= pb && pa <= pc)
133 const uint8_t *src1 = src + bpp;
137 memcpy(dst, src, bpp);
140 unaligned_w =
FFMIN(32 - bpp, size);
141 for (x = 0; x < unaligned_w; x++)
142 *dst++ = *src1++ - *src2++;
152 switch (filter_type) {
154 memcpy(dst, src, size);
163 for (i = 0; i < bpp; i++)
164 dst[i] = src[i] - (top[i] >> 1);
165 for (; i <
size; i++)
166 dst[i] = src[i] - ((src[i - bpp] + top[i]) >> 1);
169 for (i = 0; i < bpp; i++)
170 dst[i] = src[i] - top[i];
185 int cost, bcost = INT_MAX;
186 uint8_t *buf1 = dst, *buf2 = dst + size + 16;
187 for (pred = 0; pred < 5; pred++) {
191 for (i = 0; i <=
size; i++)
192 cost += abs((int8_t) buf1[i]);
213 bytestream_put_be32(f, length);
215 crc =
av_crc(crc_table, crc, tagbuf, 4);
218 crc =
av_crc(crc_table, crc, buf, length);
219 memcpy(*f, buf, length);
222 bytestream_put_be32(f, ~crc);
237 bytestream_put_be32(&s->
bytestream, length + 4);
243 crc =
av_crc(crc_table, crc, buf, length);
260 while (s->
zstream.avail_in > 0) {
261 ret = deflate(&s->
zstream, Z_NO_FLUSH);
264 if (s->
zstream.avail_out == 0) {
274 #define AV_WB32_PNG(buf, n) AV_WB32(buf, lrint((n) * 100000))
277 double rx, ry, gx, gy, bx, by, wx = 0.3127, wy = 0.3290;
280 rx = 0.640; ry = 0.330;
281 gx = 0.300; gy = 0.600;
282 bx = 0.150; by = 0.060;
285 rx = 0.670; ry = 0.330;
286 gx = 0.210; gy = 0.710;
287 bx = 0.140; by = 0.080;
288 wx = 0.310; wy = 0.316;
291 rx = 0.640; ry = 0.330;
292 gx = 0.290; gy = 0.600;
293 bx = 0.150; by = 0.060;
297 rx = 0.630; ry = 0.340;
298 gx = 0.310; gy = 0.595;
299 bx = 0.155; by = 0.070;
302 rx = 0.708; ry = 0.292;
303 gx = 0.170; gy = 0.797;
304 bx = 0.131; by = 0.046;
367 int has_alpha,
alpha, i;
372 palette = (uint32_t *)pict->
data[1];
374 alpha_ptr = s->
buf + 256 * 3;
376 for (i = 0; i < 256; i++) {
381 *alpha_ptr++ =
alpha;
382 bytestream_put_be24(&ptr, v);
385 MKTAG(
'P',
'L',
'T',
'E'), s->
buf, 256 * 3);
388 MKTAG(
't',
'R',
'N',
'S'), s->
buf + 256 * 3, 256);
401 uint8_t *ptr, *top, *crow_buf, *crow;
414 crow_buf = crow_base + 15;
416 progressive_buf =
av_malloc(row_size + 1);
418 if (!progressive_buf || !top_buf) {
430 for (pass = 0; pass <
NB_PASSES; pass++) {
434 if (pass_row_size > 0) {
436 for (y = 0; y < avctx->
height; y++)
446 top = progressive_buf;
452 for (y = 0; y < avctx->
height; y++) {
462 ret = deflate(&s->
zstream, Z_FINISH);
463 if (ret == Z_OK || ret == Z_STREAM_END) {
470 if (ret == Z_STREAM_END)
489 const AVFrame *pict,
int *got_packet)
494 size_t max_packet_size;
503 if (max_packet_size > INT_MAX)
534 const AVFrame *pict,
int *got_packet)
539 size_t max_packet_size;
549 "Input contains more than one unique palette. APNG does not support multiple palettes.\n");
561 if (max_packet_size > INT_MAX)
611 int compression_level;
649 s->
dpm = s->
dpi * 10000 / 254;
703 ? Z_DEFAULT_COMPRESSION
705 if (deflateInit2(&s->
zstream, compression_level, Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY) != Z_OK)
720 #define OFFSET(x) offsetof(PNGEncContext, x)
721 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
static void png_filter_row(PNGEncContext *c, uint8_t *dst, int filter_type, uint8_t *src, uint8_t *top, int size, int bpp)
#define PNG_FILTER_VALUE_AVG
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and/or allocate data.
#define FF_COMPRESSION_DEFAULT
This structure describes decoded (raw) audio or video data.
BYTE int const BYTE int int row_size
ptrdiff_t const GLvoid * data
static uint8_t * png_choose_filter(PNGEncContext *s, uint8_t *dst, uint8_t *src, uint8_t *top, int size, int bpp)
#define LIBAVUTIL_VERSION_INT
packed RGB 8:8:8, 24bpp, RGBRGB...
AVFrame * coded_frame
the picture in the bitstream
static av_cold int init(AVCodecContext *avctx)
static const AVClass apngenc_class
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static int encode_png(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
#define PNG_COLOR_TYPE_RGB
static const AVClass pngenc_class
#define PNG_COLOR_TYPE_GRAY_ALPHA
#define PNG_COLOR_TYPE_PALETTE
AVColorTransferCharacteristic
Color Transfer Characteristic.
av_cold void ff_huffyuvencdsp_init(HuffYUVEncDSPContext *c)
#define PNG_FILTER_VALUE_PAETH
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
double avpriv_get_gamma_from_trc(enum AVColorTransferCharacteristic trc)
Determine a suitable 'gamma' value to match the supplied AVColorTransferCharacteristic.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define PNG_COLOR_TYPE_RGB_ALPHA
8 bit with AV_PIX_FMT_RGB32 palette
#define CODEC_CAP_INTRA_ONLY
Codec is intra only.
HuffYUVEncDSPContext hdsp
static void sub_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
AVColorPrimaries
Chromaticity coordinates of the source primaries.
#define PNG_FILTER_VALUE_MIXED
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
uint32_t palette_checksum
also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
static double alpha(void *priv, double x, double y)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
16bit gray, 16bit alpha (big-endian)
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 const uint16_t mask[17]
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
void(* diff_bytes)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int dpm
Physical pixel density, in dots per meter, if set.
int ff_png_get_nb_channels(int color_type)
#define AV_WB32_PNG(buf, n)
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
simple assert() macros that are a bit more flexible than ISO C assert().
static int encode_headers(AVCodecContext *avctx, const AVFrame *pict)
const char * name
Name of the codec implementation.
Libavcodec external API header.
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
int flags
A combination of AV_PKT_FLAG values.
uint8_t * bytestream_start
enum AVPictureType pict_type
Picture type of the frame.
#define PNG_FILTER_VALUE_SUB
#define FF_MIN_BUFFER_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
static void png_write_chunk(uint8_t **f, uint32_t tag, const uint8_t *buf, int length)
#define PNG_COLOR_TYPE_GRAY
int width
picture width / height.
static const AVOption options[]
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
#define CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
static int encode_apng(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
static const float pred[4]
static int png_get_gama(enum AVColorTransferCharacteristic trc, uint8_t *buf)
functionally identical to above
#define PNG_FILTER_VALUE_UP
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static void png_write_image_data(AVCodecContext *avctx, const uint8_t *buf, int length)
main external API structure.
const uint8_t ff_png_pass_ymask[NB_PASSES]
Replacements for frequently missing libm functions.
Describe the class of an AVClass context structure.
int dpi
Physical pixel density, in dots per inch, if set.
static av_cold int png_enc_init(AVCodecContext *avctx)
static int encode_frame(AVCodecContext *avctx, const AVFrame *pict)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
static int png_write_row(AVCodecContext *avctx, const uint8_t *data, int size)
IEC 61966-2-1 (sRGB or sYCC)
common internal api header.
#define CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define PNG_FILTER_VALUE_NONE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
int prediction_method
prediction method (needed for huffyuv)
void ff_png_zfree(void *opaque, void *ptr)
#define MKBETAG(a, b, c, d)
int key_frame
1 -> keyframe, 0-> not
static int png_get_chrm(enum AVColorPrimaries prim, uint8_t *buf)
enum AVColorPrimaries color_primaries
int ff_png_pass_row_size(int pass, int bits_per_pixel, int width)
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
int frame_number
Frame counter, set by libavcodec.
enum AVColorTransferCharacteristic color_trc
static av_cold int png_enc_close(AVCodecContext *avctx)
#define FFSWAP(type, a, b)
#define MKTAG(a, b, c, d)
void * ff_png_zalloc(void *opaque, unsigned int items, unsigned int size)
AVPixelFormat
Pixel format.
This structure stores compressed data.
static void sub_left_prediction(PNGEncContext *c, uint8_t *dst, const uint8_t *src, int bpp, int size)