70 0xff, 0xff, 0x0f, 0xcc, 0x33, 0xff, 0x55,
75 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff
82 int bits_per_pixel,
int pass,
83 int color_type,
const uint8_t *src)
85 int x,
mask, dsp_mask, j, src_x,
b, bpp;
91 switch(bits_per_pixel) {
95 memset(dst, 0, (width + 7) >> 3);
97 for(x = 0; x <
width; x++) {
99 if ((dsp_mask << j) & 0x80) {
100 b = (src[src_x >> 3] >> (7 - (src_x & 7))) & 1;
101 dst[x >> 3] |= b << (7 - j);
103 if ((mask << j) & 0x80)
108 bpp = bits_per_pixel >> 3;
112 for(x = 0; x <
width; x++) {
114 if ((dsp_mask << j) & 0x80) {
115 *(uint32_t *)d = (s[3] << 24) | (s[0] << 16) | (s[1] << 8) | s[2];
118 if ((mask << j) & 0x80)
122 for(x = 0; x <
width; x++) {
124 if ((dsp_mask << j) & 0x80) {
128 if ((mask << j) & 0x80)
139 for(i = 0; i < w; i++) {
140 int a,
b, c, p, pa, pb, pc;
153 if (pa <= pb && pa <= pc)
163 #define UNROLL1(bpp, op) {\
165 if(bpp >= 2) g = dst[1];\
166 if(bpp >= 3) b = dst[2];\
167 if(bpp >= 4) a = dst[3];\
168 for(; i < size; i+=bpp) {\
169 dst[i+0] = r = op(r, src[i+0], last[i+0]);\
170 if(bpp == 1) continue;\
171 dst[i+1] = g = op(g, src[i+1], last[i+1]);\
172 if(bpp == 2) continue;\
173 dst[i+2] = b = op(b, src[i+2], last[i+2]);\
174 if(bpp == 3) continue;\
175 dst[i+3] = a = op(a, src[i+3], last[i+3]);\
179 #define UNROLL_FILTER(op)\
180 if(bpp == 1) UNROLL1(1, op)\
181 else if(bpp == 2) UNROLL1(2, op)\
182 else if(bpp == 3) UNROLL1(3, op)\
183 else if(bpp == 4) UNROLL1(4, op)\
185 for (; i < size; i += bpp) {\
187 for (j = 0; j < bpp; j++)\
188 dst[i+j] = op(dst[i+j-bpp], src[i+j], last[i+j]);\
196 int i, p,
r,
g,
b,
a;
198 switch(filter_type) {
200 memcpy(dst, src, size);
203 for(i = 0; i < bpp; i++) {
208 for(; i <
size; i+=bpp) {
209 int s = *(
int*)(src+i);
210 p = ((s&0x7f7f7f7f) + (p&0x7f7f7f7f)) ^ ((s^p)&0x80808080);
214 #define OP_SUB(x,s,l) x+s
222 for(i = 0; i < bpp; i++) {
226 #define OP_AVG(x,s,l) (((x + l) >> 1) + s) & 0xff
230 for(i = 0; i < bpp; i++) {
234 if(bpp > 1 && size > 4) {
236 int w = bpp==4 ? size : size-3;
248 unsigned int r,
g,
b,
a;
250 for(j = 0;j <
width; j++) {
259 *(uint32_t *)dst = (a << 24) | (r << 16) | (g << 8) |
b;
276 for(i=0; i<
size; i+=3) {
369 while (s->
zstream.avail_in > 0) {
370 ret = inflate(&s->
zstream, Z_PARTIAL_FLUSH);
371 if (ret != Z_OK && ret != Z_STREAM_END) {
374 if (s->
zstream.avail_out == 0) {
381 if (ret == Z_STREAM_END && s->
zstream.avail_in > 0) {
390 void *
data,
int *got_frame,
394 int buf_size = avpkt->
size;
399 uint32_t
tag, length;
420 ret = inflateInit(&s->
zstream);
426 length = bytestream2_get_be32(&s->
gb);
427 if (length > 0x7fffffff)
429 tag = bytestream2_get_le32(&s->
gb);
430 av_dlog(avctx,
"png: tag=%c%c%c%c length=%u\n",
433 ((tag >> 16) & 0xff),
434 ((tag >> 24) & 0xff), length);
436 case MKTAG(
'I',
'H',
'D',
'R'):
439 s->
width = bytestream2_get_be32(&s->
gb);
440 s->
height = bytestream2_get_be32(&s->
gb);
452 av_dlog(avctx,
"width=%d height=%d depth=%d color_type=%d compression_type=%d filter_type=%d interlace_type=%d\n",
456 case MKTAG(
'I',
'D',
'A',
'T'):
518 av_dlog(avctx,
"row_size=%d crow_size =%d\n",
524 memcpy(p->
data[1], s->
palette, 256 *
sizeof(uint32_t));
550 case MKTAG(
'P',
'L',
'T',
'E'):
554 if ((length % 3) != 0 || length > 256 * 3)
559 r = bytestream2_get_byte(&s->
gb);
560 g = bytestream2_get_byte(&s->
gb);
561 b = bytestream2_get_byte(&s->
gb);
562 s->
palette[i] = (0xff << 24) | (r << 16) | (g << 8) | b;
571 case MKTAG(
't',
'R',
'N',
'S'):
580 for(i=0;i<length;i++) {
581 v = bytestream2_get_byte(&s->
gb);
587 case MKTAG(
'I',
'E',
'N',
'D'):
607 for(j=0; j < s->
height; j++) {
608 for(i=0; i < s->
width * s->
bpp; i++) {
#define PNG_FILTER_VALUE_AVG
static void png_handle_row(PNGDecContext *s)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
This structure describes decoded (raw) audio or video data.
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
packed RGB 8:8:8, 24bpp, RGBRGB...
AVFrame * coded_frame
the picture in the bitstream
void(* add_bytes_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", 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)
#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 FFSWAP(type, a, b)
#define PNG_COLOR_TYPE_RGB_ALPHA
8 bit with PIX_FMT_RGB32 palette
AVFrame * current_picture
#define MKTAG(a, b, c, d)
int interlaced_frame
The content of the picture is interlaced.
static int init(AVCodecParserContext *s)
void(* add_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
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)
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
static void png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type, uint8_t *src, uint8_t *last, int size, int bpp)
int width
picture width / height.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Get a buffer for a frame.
static av_always_inline int bytestream2_tell(GetByteContext *g)
static av_cold int png_dec_init(AVCodecContext *avctx)
#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)
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.
struct PNGDecContext PNGDecContext
void ff_pngdsp_init(PNGDSPContext *dsp)
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...
static av_cold int png_dec_end(AVCodecContext *avctx)
common internal api header.
#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...
static const uint8_t png_pass_dsp_ymask[NB_PASSES]
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)
int key_frame
1 -> keyframe, 0-> not
int ff_png_pass_row_size(int pass, int bits_per_pixel, int width)
static void png_put_interlaced_row(uint8_t *dst, int width, int bits_per_pixel, int pass, int color_type, const uint8_t *src)
void * ff_png_zalloc(void *opaque, unsigned int items, unsigned int size)
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
This structure stores compressed data.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define UNROLL_FILTER(op)
static void deloco_rgb24(uint8_t *dst, int size)