34 #define IOBUF_SIZE 4096
51 int bits_per_pixel,
int pass,
54 int x,
mask, dst_x, j,
b, bpp;
59 switch(bits_per_pixel) {
61 memset(dst, 0, row_size);
63 for(x = 0; x <
width; x++) {
65 if ((mask << j) & 0x80) {
66 b = (src[x >> 3] >> (7 - j)) & 1;
67 dst[dst_x >> 3] |= b << (7 - (dst_x & 7));
73 bpp = bits_per_pixel >> 3;
76 for(x = 0; x <
width; x++) {
78 if ((mask << j) & 0x80) {
91 for(i = 0; i < w; i++) {
92 int a,
b, c, p, pa, pb, pc;
105 if (pa <= pb && pa <= pc)
120 switch(filter_type) {
122 memcpy(dst, src, size);
126 memcpy(dst, src, bpp);
132 for(i = 0; i < bpp; i++)
133 dst[i] = src[i] - (top[i] >> 1);
135 dst[i] = src[i] - ((src[i-bpp] + top[i]) >> 1);
138 for(i = 0; i < bpp; i++)
139 dst[i] = src[i] - top[i];
149 assert(bpp || !pred);
154 int cost, bcost = INT_MAX;
155 uint8_t *buf1 = dst, *buf2 = dst + size + 16;
156 for(pred=0; pred<5; pred++) {
160 for(i=0; i<=
size; i++)
161 cost += abs((int8_t)buf1[i]);
182 for(j = 0; j <
width; j++) {
183 v = ((
const uint32_t *)src)[j];
193 const uint8_t *buf,
int length)
198 bytestream_put_be32(f, length);
199 crc = crc32(0, Z_NULL, 0);
201 crc = crc32(crc, tagbuf, 4);
204 crc = crc32(crc, buf, length);
205 memcpy(*f, buf, length);
208 bytestream_put_be32(f, crc);
218 while (s->
zstream.avail_in > 0) {
219 ret = deflate(&s->
zstream, Z_NO_FLUSH);
222 if (s->
zstream.avail_out == 0) {
233 const AVFrame *pict,
int *got_packet)
237 int bit_depth, color_type, y,
len, row_size, ret, is_progressive;
238 int bits_per_pixel, pass_row_size, enc_row_size, max_packet_size;
239 int compression_level;
276 row_size = (avctx->
width * bits_per_pixel + 7) >> 3;
282 Z_DEFAULT_COMPRESSION :
284 ret = deflateInit2(&s->
zstream, compression_level,
285 Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY);
289 enc_row_size = deflateBound(&s->
zstream, row_size);
290 max_packet_size = avctx->
height * (enc_row_size +
307 crow_buf = crow_base + 15;
308 if (is_progressive) {
309 progressive_buf =
av_malloc(row_size + 1);
310 if (!progressive_buf)
330 s->
buf[8] = bit_depth;
331 s->
buf[9] = color_type;
334 s->
buf[12] = is_progressive;
340 int has_alpha, alpha, i;
345 palette = (uint32_t *)p->
data[1];
347 alpha_ptr = s->
buf + 256 * 3;
349 for(i = 0; i < 256; i++) {
352 if (alpha && alpha != 0xff)
354 *alpha_ptr++ = alpha;
355 bytestream_put_be24(&ptr, v);
366 if (is_progressive) {
369 for(pass = 0; pass <
NB_PASSES; pass++) {
373 if (pass_row_size > 0) {
375 for(y = 0; y < avctx->
height; y++) {
384 bits_per_pixel, pass,
386 crow =
png_choose_filter(s, crow_buf, progressive_buf, top, pass_row_size, bits_per_pixel>>3);
388 top = progressive_buf;
395 for(y = 0; y < avctx->
height; y++) {
409 ret = deflate(&s->
zstream, Z_FINISH);
410 if (ret == Z_OK || ret == Z_STREAM_END) {
417 if (ret == Z_STREAM_END)
#define CODEC_FLAG_INTERLACED_DCT
#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 ...
av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx)
This structure describes decoded (raw) audio or video data.
struct PNGEncContext PNGEncContext
static uint8_t * png_choose_filter(PNGEncContext *s, uint8_t *dst, uint8_t *src, uint8_t *top, int size, int bpp)
packed RGB 8:8:8, 24bpp, RGBRGB...
AVFrame * coded_frame
the picture in the bitstream
#define FF_MIN_BUFFER_SIZE
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
#define PNG_FILTER_VALUE_PAETH
#define FFSWAP(type, a, b)
#define PNG_COLOR_TYPE_RGB_ALPHA
8 bit with PIX_FMT_RGB32 palette
static void sub_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
#define MKTAG(a, b, c, d)
#define PNG_FILTER_VALUE_MIXED
static int init(AVCodecParserContext *s)
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
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)
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
int flags
A combination of AV_PKT_FLAG values.
#define FF_COMPRESSION_DEFAULT
uint8_t * bytestream_start
enum AVPictureType pict_type
Picture type of the frame, see ?_TYPE below.
#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 float pred[4]
#define PNG_FILTER_VALUE_UP
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
main external API structure.
const uint8_t ff_png_pass_mask[NB_PASSES]
const uint8_t ff_png_pass_ymask[NB_PASSES]
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
static av_cold int png_enc_init(AVCodecContext *avctx)
static void convert_from_rgb32(uint8_t *dst, const uint8_t *src, int width)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
void(* diff_bytes)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
#define PNG_FILTER_VALUE_NONE
int prediction_method
prediction method (needed for huffyuv)
const uint8_t ff_pngsig[8]
void ff_png_zfree(void *opaque, void *ptr)
static void png_filter_row(DSPContext *dsp, uint8_t *dst, int filter_type, uint8_t *src, uint8_t *top, int size, int bpp)
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)
void * ff_png_zalloc(void *opaque, unsigned int items, unsigned int size)
AVPixelFormat
Pixel format.
This structure stores compressed data.