69 0xff, 0xff, 0x0f, 0xcc, 0x33, 0xff, 0x55,
74 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff
81 int bits_per_pixel,
int pass,
82 int color_type,
const uint8_t *src)
84 int x,
mask, dsp_mask, j, src_x,
b, bpp;
90 switch(bits_per_pixel) {
94 memset(dst, 0, (width + 7) >> 3);
96 for(x = 0; x <
width; x++) {
98 if ((dsp_mask << j) & 0x80) {
99 b = (src[src_x >> 3] >> (7 - (src_x & 7))) & 1;
100 dst[x >> 3] |= b << (7 - j);
102 if ((mask << j) & 0x80)
107 bpp = bits_per_pixel >> 3;
111 for(x = 0; x <
width; x++) {
113 if ((dsp_mask << j) & 0x80) {
114 *(uint32_t *)d = (s[3] << 24) | (s[0] << 16) | (s[1] << 8) | s[2];
117 if ((mask << j) & 0x80)
121 for(x = 0; x <
width; x++) {
123 if ((dsp_mask << j) & 0x80) {
127 if ((mask << j) & 0x80)
138 for(i = 0; i < w; i++) {
139 int a,
b, c, p, pa, pb, pc;
152 if (pa <= pb && pa <= pc)
162 #define UNROLL1(bpp, op) {\
164 if(bpp >= 2) g = dst[1];\
165 if(bpp >= 3) b = dst[2];\
166 if(bpp >= 4) a = dst[3];\
167 for(; i < size; i+=bpp) {\
168 dst[i+0] = r = op(r, src[i+0], last[i+0]);\
169 if(bpp == 1) continue;\
170 dst[i+1] = g = op(g, src[i+1], last[i+1]);\
171 if(bpp == 2) continue;\
172 dst[i+2] = b = op(b, src[i+2], last[i+2]);\
173 if(bpp == 3) continue;\
174 dst[i+3] = a = op(a, src[i+3], last[i+3]);\
178 #define UNROLL_FILTER(op)\
179 if(bpp == 1) UNROLL1(1, op)\
180 else if(bpp == 2) UNROLL1(2, op)\
181 else if(bpp == 3) UNROLL1(3, op)\
182 else if(bpp == 4) UNROLL1(4, op)\
184 for (; i < size; i += bpp) {\
186 for (j = 0; j < bpp; j++)\
187 dst[i+j] = op(dst[i+j-bpp], src[i+j], last[i+j]);\
193 uint8_t *src, uint8_t *last,
int size,
int bpp)
195 int i, p,
r,
g,
b,
a;
197 switch(filter_type) {
199 memcpy(dst, src, size);
202 for(i = 0; i < bpp; i++) {
207 for(; i <
size; i+=bpp) {
208 int s = *(
int*)(src+i);
209 p = ((s&0x7f7f7f7f) + (p&0x7f7f7f7f)) ^ ((s^p)&0x80808080);
213 #define OP_SUB(x,s,l) x+s
221 for(i = 0; i < bpp; i++) {
225 #define OP_AVG(x,s,l) (((x + l) >> 1) + s) & 0xff
229 for(i = 0; i < bpp; i++) {
233 if(bpp > 1 && size > 4) {
235 int w = bpp==4 ? size : size-3;
247 unsigned int r,
g,
b,
a;
249 for(j = 0;j <
width; j++) {
258 *(uint32_t *)dst = (a << 24) | (r << 16) | (g << 8) |
b;
275 for(i=0; i<
size; i+=3) {
285 uint8_t *ptr, *last_row;
368 while (s->
zstream.avail_in > 0) {
369 ret = inflate(&s->
zstream, Z_PARTIAL_FLUSH);
370 if (ret != Z_OK && ret != Z_STREAM_END) {
373 if (s->
zstream.avail_out == 0) {
380 if (ret == Z_STREAM_END && s->
zstream.avail_in > 0) {
389 void *
data,
int *data_size,
392 const uint8_t *buf = avpkt->
data;
393 int buf_size = avpkt->
size;
397 uint8_t *crow_buf_base =
NULL;
398 uint32_t
tag, length;
419 ret = inflateInit(&s->
zstream);
425 length = bytestream2_get_be32(&s->
gb);
426 if (length > 0x7fffffff)
428 tag = bytestream2_get_le32(&s->
gb);
429 av_dlog(avctx,
"png: tag=%c%c%c%c length=%u\n",
432 ((tag >> 16) & 0xff),
433 ((tag >> 24) & 0xff), length);
435 case MKTAG(
'I',
'H',
'D',
'R'):
438 s->
width = bytestream2_get_be32(&s->
gb);
439 s->
height = bytestream2_get_be32(&s->
gb);
451 av_dlog(avctx,
"width=%d height=%d depth=%d color_type=%d compression_type=%d filter_type=%d interlace_type=%d\n",
455 case MKTAG(
'I',
'D',
'A',
'T'):
517 av_dlog(avctx,
"row_size=%d crow_size =%d\n",
523 memcpy(p->
data[1], s->
palette, 256 *
sizeof(uint32_t));
549 case MKTAG(
'P',
'L',
'T',
'E'):
553 if ((length % 3) != 0 || length > 256 * 3)
558 r = bytestream2_get_byte(&s->
gb);
559 g = bytestream2_get_byte(&s->
gb);
560 b = bytestream2_get_byte(&s->
gb);
561 s->
palette[i] = (0xff << 24) | (r << 16) | (g << 8) | b;
570 case MKTAG(
't',
'R',
'N',
'S'):
579 for(i=0;i<length;i++) {
580 v = bytestream2_get_byte(&s->
gb);
586 case MKTAG(
'I',
'E',
'N',
'D'):
606 for(j=0; j < s->
height; j++) {
607 for(i=0; i < s->
width * s->
bpp; i++) {
#define PNG_FILTER_VALUE_AVG
static void png_handle_row(PNGDecContext *s)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int(* get_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called at the beginning of each frame to get a buffer for it.
enum PixelFormat pix_fmt
Pixel format, see PIX_FMT_xxx.
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
AVFrame * coded_frame
the picture in the bitstream
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define PNG_COLOR_TYPE_RGB
#define PNG_COLOR_TYPE_GRAY_ALPHA
#define PNG_COLOR_TYPE_PALETTE
void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
#define PNG_FILTER_VALUE_PAETH
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
#define PNG_COLOR_TYPE_RGB_ALPHA
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
AVFrame * current_picture
int interlaced_frame
The content of the picture is interlaced.
av_cold void dsputil_init(DSPContext *c, AVCodecContext *avctx)
static int init(AVCodecParserContext *s)
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
void(* add_png_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
void(* add_bytes_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
static const uint8_t png_pass_dsp_mask[NB_PASSES]
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
static const uint16_t mask[17]
int reference
is this picture used as reference The values for this are the same as the MpegEncContext.picture_structure variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#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)
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
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.
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
enum AVPictureType pict_type
Picture type of the frame, see ?_TYPE below.
#define PNG_FILTER_VALUE_SUB
const uint8_t ff_mngsig[8]
#define PNG_COLOR_TYPE_GRAY
int width
picture width / height.
struct AVFrame AVFrame
Audio Video Frame.
#define av_dlog(pctx,...)
av_dlog macros Useful to print debug messages that shouldn't get compiled in normally.
static av_always_inline int bytestream2_tell(GetByteContext *g)
static av_cold int png_dec_init(AVCodecContext *avctx)
static void png_filter_row(DSPContext *dsp, uint8_t *dst, int filter_type, uint8_t *src, uint8_t *last, int size, int bpp)
#define PNG_FILTER_VALUE_UP
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
#define PNG_FILTER_TYPE_LOCO
main external API structure.
static void close(AVCodecParserContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const uint8_t ff_png_pass_mask[NB_PASSES]
const uint8_t ff_png_pass_ymask[NB_PASSES]
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
struct PNGDecContext PNGDecContext
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static av_cold int png_dec_end(AVCodecContext *avctx)
#define PNG_FILTER_VALUE_NONE
static const uint8_t png_pass_dsp_ymask[NB_PASSES]
8 bit with PIX_FMT_RGB32 palette
const uint8_t ff_pngsig[8]
void ff_png_zfree(void *opaque, void *ptr)
static void convert_to_rgb32(uint8_t *dst, const uint8_t *src, int width, int loco)
static av_always_inline void convert_to_rgb32_loco(uint8_t *dst, const uint8_t *src, int width, int loco)
static int png_decode_idat(PNGDecContext *s, int length)
packed RGB 8:8:8, 24bpp, RGBRGB...
int key_frame
1 -> keyframe, 0-> not
int ff_png_pass_row_size(int pass, int bits_per_pixel, int width)
void avcodec_get_frame_defaults(AVFrame *pic)
Set the fields of the given AVFrame to default values.
static void png_put_interlaced_row(uint8_t *dst, int width, int bits_per_pixel, int pass, int color_type, const uint8_t *src)
#define FFSWAP(type, a, b)
#define MKTAG(a, b, c, d)
void * ff_png_zalloc(void *opaque, unsigned int items, unsigned int size)
#define UNROLL_FILTER(op)
static void deloco_rgb24(uint8_t *dst, int size)