36 #define IOBUF_SIZE 4096 53 int bits_per_pixel,
int pass,
56 int x,
mask, dst_x, j,
b, bpp;
61 switch (bits_per_pixel) {
63 memset(dst, 0, row_size);
65 for (x = 0; x <
width; x++) {
67 if ((mask << j) & 0x80) {
68 b = (src[x >> 3] >> (7 - j)) & 1;
69 dst[dst_x >> 3] |= b << (7 - (dst_x & 7));
75 bpp = bits_per_pixel >> 3;
78 for (x = 0; x <
width; x++) {
80 if ((mask << j) & 0x80) {
94 for (i = 0; i < w; i++) {
95 int a,
b, c, p, pa, pb, pc;
108 if (pa <= pb && pa <= pc)
123 switch (filter_type) {
125 memcpy(dst, src, size);
129 memcpy(dst, src, bpp);
135 for (i = 0; i < bpp; i++)
136 dst[i] = src[i] - (top[i] >> 1);
137 for (; i <
size; i++)
138 dst[i] = src[i] - ((src[i - bpp] + top[i]) >> 1);
141 for (i = 0; i < bpp; i++)
142 dst[i] = src[i] - top[i];
152 assert(bpp || !pred);
157 int cost, bcost = INT_MAX;
158 uint8_t *buf1 = dst, *buf2 = dst + size + 16;
159 for (pred = 0; pred < 5; pred++) {
163 for (i = 0; i <=
size; i++)
164 cost += abs((int8_t) buf1[i]);
185 for (j = 0; j <
width; j++) {
186 v = ((
const uint32_t *) src)[j];
201 bytestream_put_be32(f, length);
202 crc = crc32(0, Z_NULL, 0);
204 crc = crc32(crc, tagbuf, 4);
207 crc = crc32(crc, buf, length);
208 memcpy(*f, buf, length);
211 bytestream_put_be32(f, crc);
221 while (s->
zstream.avail_in > 0) {
222 ret = deflate(&s->
zstream, Z_NO_FLUSH);
225 if (s->
zstream.avail_out == 0) {
237 const AVFrame *pict,
int *got_packet)
242 int bit_depth, color_type, y,
len, row_size, ret, is_progressive;
243 int bits_per_pixel, pass_row_size, enc_row_size, max_packet_size;
244 int compression_level;
245 uint8_t *ptr, *top, *crow_buf, *crow;
289 row_size = (avctx->
width * bits_per_pixel + 7) >> 3;
295 ? Z_DEFAULT_COMPRESSION
297 ret = deflateInit2(&s->
zstream, compression_level,
298 Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY);
302 enc_row_size = deflateBound(&s->
zstream, row_size);
303 max_packet_size = avctx->
height * (enc_row_size +
321 crow_buf = crow_base + 15;
322 if (is_progressive) {
323 progressive_buf =
av_malloc(row_size + 1);
324 if (!progressive_buf)
344 s->
buf[8] = bit_depth;
345 s->
buf[9] = color_type;
348 s->
buf[12] = is_progressive;
354 int has_alpha, alpha, i;
359 palette = (uint32_t *)p->
data[1];
361 alpha_ptr = s->
buf + 256 * 3;
363 for (i = 0; i < 256; i++) {
366 if (alpha && alpha != 0xff)
368 *alpha_ptr++ = alpha;
369 bytestream_put_be24(&ptr, v);
372 MKTAG(
'P',
'L',
'T',
'E'), s->
buf, 256 * 3);
375 MKTAG(
't',
'R',
'N',
'S'), s->
buf + 256 * 3, 256);
384 switch (stereo3d->
type) {
393 "Only side-by-side stereo3d flag can be defined within sTER chunk\n");
401 if (is_progressive) {
404 for (pass = 0; pass <
NB_PASSES; pass++) {
408 if (pass_row_size > 0) {
410 for (y = 0; y < avctx->
height; y++)
419 bits_per_pixel, pass,
422 top, pass_row_size, bits_per_pixel >> 3);
424 top = progressive_buf;
430 for (y = 0; y < avctx->
height; y++) {
438 row_size, bits_per_pixel >> 3);
445 ret = deflate(&s->
zstream, Z_FINISH);
446 if (ret == Z_OK || ret == Z_STREAM_END) {
453 if (ret == Z_STREAM_END)
482 #if FF_API_CODED_FRAME 491 #if FF_API_PRIVATE_OPT 506 #define OFFSET(x) offsetof(PNGEncContext, x) 507 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM 532 .priv_class = &png_class,
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
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define FF_COMPRESSION_DEFAULT
This structure describes decoded (raw) audio or video data.
void(* diff_bytes)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
static uint8_t * png_choose_filter(PNGEncContext *s, uint8_t *dst, uint8_t *src, uint8_t *top, int size, int bpp)
#define AV_LOG_WARNING
Something somehow does not look correct.
packed RGB 8:8:8, 24bpp, RGBRGB...
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
#define PNG_COLOR_TYPE_RGB
#define PNG_COLOR_TYPE_PALETTE
av_cold void ff_huffyuvencdsp_init(HuffYUVEncDSPContext *c)
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
#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 PNG_COLOR_TYPE_RGB_ALPHA
8 bits with AV_PIX_FMT_RGB32 palette
Stereo 3D type: this structure describes how two videos are packed within a single video surface...
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...
#define AV_INPUT_BUFFER_MIN_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
#define PNG_FILTER_VALUE_MIXED
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
int flags
Additional information about the frame packing.
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]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int ff_png_get_nb_channels(int color_type)
int flags
AV_CODEC_FLAG_*.
const char * name
Name of the codec implementation.
Video is not stereoscopic (and metadata has to be there).
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
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[]
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
static const float pred[4]
enum AVStereo3DType type
How views are packed within the video.
Libavcodec external API header.
attribute_deprecated int prediction_method
#define PNG_FILTER_VALUE_UP
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
const uint8_t ff_png_pass_mask[NB_PASSES]
const uint8_t ff_png_pass_ymask[NB_PASSES]
Describe the class of an AVClass context structure.
static av_cold int png_enc_init(AVCodecContext *avctx)
static void convert_from_rgb32(uint8_t *dst, const uint8_t *src, int width)
static enum AVPixelFormat pix_fmts[]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Views are next to each other.
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
#define FF_DISABLE_DEPRECATION_WARNINGS
#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...
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
const uint8_t ff_pngsig[8]
void ff_png_zfree(void *opaque, void *ptr)
static av_cold int init(AVCodecParserContext *s)
#define FF_ENABLE_DEPRECATION_WARNINGS
int key_frame
1 -> keyframe, 0-> not
static int png_write_row(PNGEncContext *s, const uint8_t *data, int size)
int ff_png_pass_row_size(int pass, int bits_per_pixel, int width)
static const AVClass png_class
#define FFSWAP(type, a, b)
#define MKTAG(a, b, c, d)
void * ff_png_zalloc(void *opaque, unsigned int items, unsigned int size)
Stereoscopic 3d metadata.
AVPixelFormat
Pixel format.
This structure stores compressed data.