38 #define IOBUF_SIZE 4096
80 int bits_per_pixel,
int pass,
83 int x,
mask, dst_x, j,
b, bpp;
86 static const int masks[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
89 switch (bits_per_pixel) {
91 memset(dst, 0, row_size);
93 for (x = 0; x <
width; x++) {
95 if ((mask << j) & 0x80) {
96 b = (src[x >> 3] >> (7 - j)) & 1;
97 dst[dst_x >> 3] |= b << (7 - (dst_x & 7));
103 bpp = bits_per_pixel >> 3;
106 for (x = 0; x <
width; x++) {
108 if ((mask << j) & 0x80) {
122 for (i = 0; i < w; i++) {
123 int a,
b,
c, p, pa, pb, pc;
136 if (pa <= pb && pa <= pc)
152 memcpy(dst, src, bpp);
155 unaligned_w =
FFMIN(32 - bpp, size);
156 for (x = 0; x < unaligned_w; x++)
157 *dst++ = *src1++ - *src2++;
167 switch (filter_type) {
169 memcpy(dst, src, size);
178 for (i = 0; i < bpp; i++)
179 dst[i] = src[i] - (top[i] >> 1);
180 for (; i <
size; i++)
181 dst[i] = src[i] - ((src[i - bpp] + top[i]) >> 1);
184 for (i = 0; i < bpp; i++)
185 dst[i] = src[i] - top[i];
200 int cost, bcost = INT_MAX;
201 uint8_t *buf1 = dst, *buf2 = dst + size + 16;
202 for (pred = 0; pred < 5; pred++) {
206 for (i = 0; i <=
size; i++)
207 cost += abs((int8_t) buf1[i]);
228 bytestream_put_be32(f, length);
230 crc =
av_crc(crc_table, crc, tagbuf, 4);
233 crc =
av_crc(crc_table, crc, buf, length);
234 memcpy(*f, buf, length);
237 bytestream_put_be32(f, ~crc);
252 bytestream_put_be32(&s->
bytestream, length + 4);
258 crc =
av_crc(crc_table, crc, buf, length);
275 while (s->
zstream.avail_in > 0) {
279 if (s->
zstream.avail_out == 0) {
289 #define AV_WB32_PNG(buf, n) AV_WB32(buf, lrint((n) * 100000))
292 double rx, ry, gx, gy, bx, by, wx = 0.3127, wy = 0.3290;
295 rx = 0.640; ry = 0.330;
296 gx = 0.300; gy = 0.600;
297 bx = 0.150; by = 0.060;
300 rx = 0.670; ry = 0.330;
301 gx = 0.210; gy = 0.710;
302 bx = 0.140; by = 0.080;
303 wx = 0.310; wy = 0.316;
306 rx = 0.640; ry = 0.330;
307 gx = 0.290; gy = 0.600;
308 bx = 0.150; by = 0.060;
312 rx = 0.630; ry = 0.340;
313 gx = 0.310; gy = 0.595;
314 bx = 0.155; by = 0.070;
317 rx = 0.708; ry = 0.292;
318 gx = 0.170; gy = 0.797;
319 bx = 0.131; by = 0.046;
373 switch (stereo3d->
type) {
381 av_log(avctx,
AV_LOG_WARNING,
"Only side-by-side stereo3d flag can be defined within sTER chunk\n");
400 int has_alpha,
alpha, i;
405 palette = (uint32_t *)pict->
data[1];
407 alpha_ptr = s->
buf + 256 * 3;
409 for (i = 0; i < 256; i++) {
414 *alpha_ptr++ =
alpha;
415 bytestream_put_be24(&ptr, v);
418 MKTAG(
'P',
'L',
'T',
'E'), s->
buf, 256 * 3);
421 MKTAG(
't',
'R',
'N',
'S'), s->
buf + 256 * 3, 256);
434 uint8_t *ptr, *top, *crow_buf, *crow;
447 crow_buf = crow_base + 15;
449 progressive_buf =
av_malloc(row_size + 1);
451 if (!progressive_buf || !top_buf) {
463 for (pass = 0; pass <
NB_PASSES; pass++) {
467 if (pass_row_size > 0) {
469 for (y = 0; y < pict->
height; y++)
479 top = progressive_buf;
485 for (y = 0; y < pict->
height; y++) {
496 if (ret == Z_OK || ret == Z_STREAM_END) {
503 if (ret == Z_STREAM_END)
522 const AVFrame *pict,
int *got_packet)
527 size_t max_packet_size;
536 if (max_packet_size > INT_MAX)
573 unsigned int leftmost_x = input->
width;
574 unsigned int rightmost_x = 0;
575 unsigned int topmost_y = input->
height;
576 unsigned int bottommost_y = 0;
579 ptrdiff_t input_linesize = input->
linesize[0];
580 ptrdiff_t output_linesize = output->
linesize[0];
583 for (y = 0; y < input->
height; ++y) {
584 for (x = 0; x < input->
width; ++x) {
585 if (!memcmp(input_data + bpp * x, output_data + bpp * x, bpp))
590 if (x >= rightmost_x)
594 if (y >= bottommost_y)
595 bottommost_y = y + 1;
598 input_data += input_linesize;
599 output_data += output_linesize;
602 if (leftmost_x == input->
width && rightmost_x == 0) {
605 leftmost_x = topmost_y = 0;
606 rightmost_x = bottommost_y = 1;
611 output_data = output->
data[0];
612 for (y = topmost_y; y < bottommost_y; ++y) {
614 input->
data[0] + input_linesize * y + bpp * leftmost_x,
615 bpp * (rightmost_x - leftmost_x));
616 output_data += output_linesize;
619 size_t transparent_palette_index;
630 palette = (uint32_t*)input->
data[1];
631 for (transparent_palette_index = 0; transparent_palette_index < 256; ++transparent_palette_index)
632 if (palette[transparent_palette_index] >> 24 == 0)
641 for (y = topmost_y; y < bottommost_y; ++y) {
642 uint8_t *foreground = input->
data[0] + input_linesize * y + bpp * leftmost_x;
643 uint8_t *background = output->
data[0] + output_linesize * y + bpp * leftmost_x;
644 output_data = output->
data[0] + output_linesize * (y - topmost_y);
645 for (x = leftmost_x; x < rightmost_x; ++x, foreground += bpp, background += bpp, output_data += bpp) {
646 if (!memcmp(foreground, background, bpp)) {
648 if (transparent_palette_index == 256) {
653 *output_data = transparent_palette_index;
655 memset(output_data, 0, bpp);
666 if (((uint16_t*)foreground)[3] == 0xffff ||
667 ((uint16_t*)background)[3] == 0)
672 if (((uint16_t*)foreground)[1] == 0xffff ||
673 ((uint16_t*)background)[1] == 0)
678 if (foreground[3] == 0xff || background[3] == 0)
683 if (foreground[1] == 0xff || background[1] == 0)
688 if (palette[*foreground] >> 24 == 0xff ||
689 palette[*background] >> 24 == 0)
694 memmove(output_data, foreground, bpp);
699 output->
width = rightmost_x - leftmost_x;
700 output->
height = bottommost_y - topmost_y;
717 uint8_t *original_bytestream, *original_bytestream_end;
718 uint8_t *temp_bytestream = 0, *temp_bytestream_end;
719 uint32_t best_sequence_number;
721 size_t best_bytestream_size = SIZE_MAX;
747 temp_bytestream =
av_malloc(original_bytestream_end - original_bytestream);
748 temp_bytestream_end = temp_bytestream + (original_bytestream_end - original_bytestream);
749 if (!temp_bytestream) {
763 uint32_t original_sequence_number = s->
sequence_number, sequence_number;
765 size_t bytestream_size;
777 size_t row_start = diffFrame->
linesize[0] * y + bpp * last_fctl_chunk.
x_offset;
778 memset(diffFrame->
data[0] + row_start, 0, bpp * last_fctl_chunk.
width);
800 bytestream_size = s->
bytestream - bytestream_start;
805 if (bytestream_size < best_bytestream_size) {
806 *best_fctl_chunk = fctl_chunk;
807 *best_last_fctl_chunk = last_fctl_chunk;
809 best_sequence_number = sequence_number;
811 best_bytestream_size = bytestream_size;
813 if (best_bytestream == original_bytestream) {
825 s->
bytestream = original_bytestream + best_bytestream_size;
827 if (best_bytestream != original_bytestream)
828 memcpy(original_bytestream, best_bytestream, best_bytestream_size);
839 const AVFrame *pict,
int *got_packet)
844 size_t max_packet_size;
854 "Input contains more than one unique palette. APNG does not support multiple palettes.\n");
866 if (max_packet_size > INT_MAX)
982 int compression_level;
1001 #if FF_API_CODED_FRAME
1010 #if FF_API_PRIVATE_OPT
1025 }
else if (s->
dpi) {
1026 s->
dpm = s->
dpi * 10000 / 254;
1080 ? Z_DEFAULT_COMPRESSION
1082 if (deflateInit2(&s->
zstream, compression_level, Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY) != Z_OK)
1099 #define OFFSET(x) offsetof(PNGEncContext, x)
1100 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1103 {
"dpm",
"Set image resolution (in dots per meter)",
OFFSET(dpm),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 0x10000,
VE},
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
APNGFctlChunk last_frame_fctl
#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
#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.
#define LIBAVUTIL_VERSION_INT
packed RGB 8:8:8, 24bpp, RGBRGB...
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)
void(* diff_bytes)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, intptr_t w)
#define PNG_COLOR_TYPE_RGB
static const AVClass pngenc_class
#define PNG_COLOR_TYPE_GRAY_ALPHA
Views are next to each other.
#define PNG_COLOR_TYPE_PALETTE
AVColorTransferCharacteristic
Color Transfer Characteristic.
av_cold void ff_huffyuvencdsp_init(HuffYUVEncDSPContext *c)
#define AV_CODEC_CAP_INTRA_ONLY
Codec is intra only.
size_t last_frame_packet_size
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 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 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)
static void deflate(uint8_t *dst, const uint8_t *p1, int width, int threshold, const uint8_t *coordinates[], int coord)
static int apng_encode_frame(AVCodecContext *avctx, const AVFrame *pict, APNGFctlChunk *best_fctl_chunk, APNGFctlChunk *best_last_fctl_chunk)
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Structure to hold side data for an AVFrame.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
AVColorPrimaries
Chromaticity coordinates of the source primaries.
#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.
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)
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int flags
Additional information about the frame packing.
16 bits gray, 16 bits 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]
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#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)
int flags
AV_CODEC_FLAG_*.
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.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
int flags
A combination of AV_PKT_FLAG values.
uint8_t * bytestream_start
enum AVPictureType pict_type
Picture type of the frame.
static int output_data(MLPDecodeContext *m, unsigned int substr, AVFrame *frame, int *got_frame_ptr)
Write the audio data into the output buffer.
#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[]
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.
uint8_t * last_frame_packet
static volatile int checksum
static int encode_apng(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
static const float pred[4]
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
static int png_get_gama(enum AVColorTransferCharacteristic trc, uint8_t *buf)
enum AVStereo3DType type
How views are packed within the video.
Libavcodec external API header.
functionally identical to above
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.
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)
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
static int encode_frame(AVCodecContext *avctx, const AVFrame *pict)
static enum AVPixelFormat pix_fmts[]
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
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)
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
#define PNG_FILTER_VALUE_NONE
Video is not stereoscopic (and metadata has to be there).
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
void ff_png_zfree(void *opaque, void *ptr)
#define MKBETAG(a, b, c, d)
#define FF_ENABLE_DEPRECATION_WARNINGS
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)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
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 int apng_do_inverse_blend(AVFrame *output, const AVFrame *input, APNGFctlChunk *fctl_chunk, uint8_t bpp)
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)
Stereoscopic 3d metadata.
AVPixelFormat
Pixel format.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define FF_MIN_BUFFER_SIZE
static void sub_left_prediction(PNGEncContext *c, uint8_t *dst, const uint8_t *src, int bpp, int size)