FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
pngdec.c File Reference
#include "config_components.h"
#include "libavutil/avassert.h"
#include "libavutil/bprint.h"
#include "libavutil/crc.h"
#include "libavutil/csp.h"
#include "libavutil/imgutils.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mastering_display_metadata.h"
#include "libavutil/mem.h"
#include "libavutil/pixfmt.h"
#include "libavutil/rational.h"
#include "libavutil/stereo3d.h"
#include "avcodec.h"
#include "bytestream.h"
#include "codec_internal.h"
#include "decode.h"
#include "apng.h"
#include "png.h"
#include "pngdsp.h"
#include "progressframe.h"
#include "thread.h"
#include "zlib_wrapper.h"
#include <zlib.h>

Go to the source code of this file.

Data Structures

struct  PNGDecContext
 

Macros

#define UNROLL1(bpp, op)
 
#define UNROLL_FILTER(op)
 
#define OP_SUB(x, s, l)   ((x) + (s))
 
#define OP_AVG(x, s, l)   (((((x) + (l)) >> 1) + (s)) & 0xff)
 
#define YUV2RGB(NAME, TYPE)
 
#define FAST_DIV255(x)   ((((x) + 128) * 257) >> 16)
 

Enumerations

enum  PNGHeaderState { PNG_IHDR = 1 << 0, PNG_PLTE = 1 << 1 }
 
enum  PNGImageState { PNG_IDAT = 1 << 0, PNG_ALLIMAGE = 1 << 1 }
 

Functions

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_add_png_paeth_prediction (uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
 
void ff_png_filter_row (PNGDSPContext *dsp, uint8_t *dst, int filter_type, uint8_t *src, uint8_t *last, int size, int bpp)
 
static int percent_missing (PNGDecContext *s)
 
static void png_handle_row (PNGDecContext *s, uint8_t *dst, ptrdiff_t dst_stride)
 
static int png_decode_idat (PNGDecContext *s, GetByteContext *gb, uint8_t *dst, ptrdiff_t dst_stride)
 
static int decode_zbuf (AVBPrint *bp, const uint8_t *data, const uint8_t *data_end, void *logctx)
 
static char * iso88591_to_utf8 (const char *in, size_t size_in)
 
static int decode_text_chunk (PNGDecContext *s, GetByteContext *gb, int compressed)
 
static int decode_ihdr_chunk (AVCodecContext *avctx, PNGDecContext *s, GetByteContext *gb)
 
static int decode_phys_chunk (AVCodecContext *avctx, PNGDecContext *s, GetByteContext *gb)
 
static int populate_avctx_color_fields (AVCodecContext *avctx, AVFrame *frame)
 
static int decode_idat_chunk (AVCodecContext *avctx, PNGDecContext *s, GetByteContext *gb, AVFrame *p)
 
static int decode_plte_chunk (AVCodecContext *avctx, PNGDecContext *s, GetByteContext *gb)
 
static int decode_trns_chunk (AVCodecContext *avctx, PNGDecContext *s, GetByteContext *gb)
 
static int decode_iccp_chunk (PNGDecContext *s, GetByteContext *gb)
 
static int decode_sbit_chunk (AVCodecContext *avctx, PNGDecContext *s, GetByteContext *gb)
 
static void handle_small_bpp (PNGDecContext *s, AVFrame *p)
 
static int decode_fctl_chunk (AVCodecContext *avctx, PNGDecContext *s, GetByteContext *gb)
 
static void handle_p_frame_png (PNGDecContext *s, AVFrame *p)
 
static int handle_p_frame_apng (AVCodecContext *avctx, PNGDecContext *s, AVFrame *p)
 
static void apng_reset_background (PNGDecContext *s, const AVFrame *p)
 
static int decode_frame_common (AVCodecContext *avctx, PNGDecContext *s, AVFrame *p, const AVPacket *avpkt)
 
static void clear_frame_metadata (PNGDecContext *s)
 
static int output_frame (PNGDecContext *s, AVFrame *f)
 
static av_cold int png_dec_init (AVCodecContext *avctx)
 
static av_cold int png_dec_end (AVCodecContext *avctx)
 

Variables

static const uint8_t png_pass_mask [NB_PASSES]
 
static const uint8_t png_pass_dsp_ymask [NB_PASSES]
 
static const uint8_t png_pass_dsp_mask [NB_PASSES]
 

Macro Definition Documentation

◆ UNROLL1

#define UNROLL1 (   bpp,
  op 
)
Value:
{ \
r = dst[0]; \
if (bpp >= 2) \
g = dst[1]; \
if (bpp >= 3) \
b = dst[2]; \
if (bpp >= 4) \
a = dst[3]; \
for (; i <= size - bpp; i += bpp) { \
dst[i + 0] = r = op(r, src[i + 0], last[i + 0]); \
if (bpp == 1) \
continue; \
dst[i + 1] = g = op(g, src[i + 1], last[i + 1]); \
if (bpp == 2) \
continue; \
dst[i + 2] = b = op(b, src[i + 2], last[i + 2]); \
if (bpp == 3) \
continue; \
dst[i + 3] = a = op(a, src[i + 3], last[i + 3]); \
} \
}

Definition at line 246 of file pngdec.c.

◆ UNROLL_FILTER

#define UNROLL_FILTER (   op)
Value:
if (bpp == 1) { \
UNROLL1(1, op) \
} else if (bpp == 2) { \
UNROLL1(2, op) \
} else if (bpp == 3) { \
UNROLL1(3, op) \
} else if (bpp == 4) { \
UNROLL1(4, op) \
} \
for (; i < size; i++) { \
dst[i] = op(dst[i - bpp], src[i], last[i]); \
}

Definition at line 269 of file pngdec.c.

◆ OP_SUB

#define OP_SUB (   x,
  s,
 
)    ((x) + (s))

◆ OP_AVG

#define OP_AVG (   x,
  s,
 
)    (((((x) + (l)) >> 1) + (s)) & 0xff)

◆ YUV2RGB

#define YUV2RGB (   NAME,
  TYPE 
)
Value:
static void deloco_ ## NAME(TYPE *dst, int size, int alpha) \
{ \
int i; \
for (i = 0; i < size - 2; i += 3 + alpha) { \
int g = dst [i + 1]; \
dst[i + 0] += g; \
dst[i + 2] += g; \
} \
}

Definition at line 341 of file pngdec.c.

◆ FAST_DIV255

#define FAST_DIV255 (   x)    ((((x) + 128) * 257) >> 16)

Definition at line 1273 of file pngdec.c.

Enumeration Type Documentation

◆ PNGHeaderState

Enumerator
PNG_IHDR 
PNG_PLTE 

Definition at line 51 of file pngdec.c.

◆ PNGImageState

Enumerator
PNG_IDAT 
PNG_ALLIMAGE 

Definition at line 56 of file pngdec.c.

Function Documentation

◆ png_put_interlaced_row()

static void png_put_interlaced_row ( uint8_t *  dst,
int  width,
int  bits_per_pixel,
int  pass,
int  color_type,
const uint8_t *  src 
)
static

Definition at line 148 of file pngdec.c.

Referenced by png_handle_row().

◆ ff_add_png_paeth_prediction()

void ff_add_png_paeth_prediction ( uint8_t *  dst,
uint8_t *  src,
uint8_t *  top,
int  w,
int  bpp 
)

Definition at line 218 of file pngdec.c.

Referenced by ff_png_filter_row(), and ff_pngdsp_init().

◆ ff_png_filter_row()

void ff_png_filter_row ( PNGDSPContext dsp,
uint8_t *  dst,
int  filter_type,
uint8_t *  src,
uint8_t *  last,
int  size,
int  bpp 
)

Definition at line 284 of file pngdec.c.

Referenced by handle_row(), and png_handle_row().

◆ percent_missing()

static int percent_missing ( PNGDecContext s)
static

Definition at line 355 of file pngdec.c.

Referenced by decode_frame_common().

◆ png_handle_row()

static void png_handle_row ( PNGDecContext s,
uint8_t *  dst,
ptrdiff_t  dst_stride 
)
static

Definition at line 365 of file pngdec.c.

Referenced by png_decode_idat().

◆ png_decode_idat()

static int png_decode_idat ( PNGDecContext s,
GetByteContext gb,
uint8_t *  dst,
ptrdiff_t  dst_stride 
)
static

Definition at line 446 of file pngdec.c.

Referenced by decode_idat_chunk().

◆ decode_zbuf()

static int decode_zbuf ( AVBPrint *  bp,
const uint8_t *  data,
const uint8_t *  data_end,
void *  logctx 
)
static

Definition at line 477 of file pngdec.c.

Referenced by decode_iccp_chunk(), and decode_text_chunk().

◆ iso88591_to_utf8()

static char* iso88591_to_utf8 ( const char *  in,
size_t  size_in 
)
static

Definition at line 519 of file pngdec.c.

Referenced by decode_text_chunk().

◆ decode_text_chunk()

static int decode_text_chunk ( PNGDecContext s,
GetByteContext gb,
int  compressed 
)
static

Definition at line 543 of file pngdec.c.

Referenced by decode_frame_common().

◆ decode_ihdr_chunk()

static int decode_ihdr_chunk ( AVCodecContext avctx,
PNGDecContext s,
GetByteContext gb 
)
static

Definition at line 590 of file pngdec.c.

Referenced by decode_frame_common().

◆ decode_phys_chunk()

static int decode_phys_chunk ( AVCodecContext avctx,
PNGDecContext s,
GetByteContext gb 
)
static

Definition at line 641 of file pngdec.c.

Referenced by decode_frame_common().

◆ populate_avctx_color_fields()

static int populate_avctx_color_fields ( AVCodecContext avctx,
AVFrame frame 
)
static

Definition at line 662 of file pngdec.c.

Referenced by decode_idat_chunk().

◆ decode_idat_chunk()

static int decode_idat_chunk ( AVCodecContext avctx,
PNGDecContext s,
GetByteContext gb,
AVFrame p 
)
static

Definition at line 791 of file pngdec.c.

Referenced by decode_frame_common().

◆ decode_plte_chunk()

static int decode_plte_chunk ( AVCodecContext avctx,
PNGDecContext s,
GetByteContext gb 
)
static

Definition at line 967 of file pngdec.c.

Referenced by decode_frame_common().

◆ decode_trns_chunk()

static int decode_trns_chunk ( AVCodecContext avctx,
PNGDecContext s,
GetByteContext gb 
)
static

Definition at line 990 of file pngdec.c.

Referenced by decode_frame_common().

◆ decode_iccp_chunk()

static int decode_iccp_chunk ( PNGDecContext s,
GetByteContext gb 
)
static

Definition at line 1038 of file pngdec.c.

Referenced by decode_frame_common().

◆ decode_sbit_chunk()

static int decode_sbit_chunk ( AVCodecContext avctx,
PNGDecContext s,
GetByteContext gb 
)
static

Definition at line 1071 of file pngdec.c.

Referenced by decode_frame_common().

◆ handle_small_bpp()

static void handle_small_bpp ( PNGDecContext s,
AVFrame p 
)
static

Definition at line 1109 of file pngdec.c.

Referenced by decode_frame_common().

◆ decode_fctl_chunk()

static int decode_fctl_chunk ( AVCodecContext avctx,
PNGDecContext s,
GetByteContext gb 
)
static

Definition at line 1182 of file pngdec.c.

Referenced by decode_frame_common().

◆ handle_p_frame_png()

static void handle_p_frame_png ( PNGDecContext s,
AVFrame p 
)
static

Definition at line 1253 of file pngdec.c.

Referenced by decode_frame_common().

◆ handle_p_frame_apng()

static int handle_p_frame_apng ( AVCodecContext avctx,
PNGDecContext s,
AVFrame p 
)
static

Definition at line 1275 of file pngdec.c.

Referenced by decode_frame_common().

◆ apng_reset_background()

static void apng_reset_background ( PNGDecContext s,
const AVFrame p 
)
static

Definition at line 1364 of file pngdec.c.

Referenced by decode_frame_common().

◆ decode_frame_common()

static int decode_frame_common ( AVCodecContext avctx,
PNGDecContext s,
AVFrame p,
const AVPacket avpkt 
)
static

Definition at line 1380 of file pngdec.c.

◆ clear_frame_metadata()

static void clear_frame_metadata ( PNGDecContext s)
static

Definition at line 1709 of file pngdec.c.

◆ output_frame()

static int output_frame ( PNGDecContext s,
AVFrame f 
)
static

Definition at line 1724 of file pngdec.c.

◆ png_dec_init()

static av_cold int png_dec_init ( AVCodecContext avctx)
static

Definition at line 1890 of file pngdec.c.

◆ png_dec_end()

static av_cold int png_dec_end ( AVCodecContext avctx)
static

Definition at line 1901 of file pngdec.c.

Variable Documentation

◆ png_pass_mask

const uint8_t png_pass_mask[NB_PASSES]
static
Initial value:
= {
0x01, 0x01, 0x11, 0x11, 0x55, 0x55, 0xff,
}

Definition at line 131 of file pngdec.c.

Referenced by png_put_interlaced_row().

◆ png_pass_dsp_ymask

const uint8_t png_pass_dsp_ymask[NB_PASSES]
static
Initial value:
= {
0xff, 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
}

Definition at line 136 of file pngdec.c.

Referenced by png_handle_row().

◆ png_pass_dsp_mask

const uint8_t png_pass_dsp_mask[NB_PASSES]
static
Initial value:
= {
0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff
}

Definition at line 141 of file pngdec.c.

Referenced by png_put_interlaced_row().

r
const char * r
Definition: vf_curves.c:127
b
#define b
Definition: input.c:41
g
const char * g
Definition: vf_curves.c:128
op
static int op(uint8_t **dst, const uint8_t *dst_end, GetByteContext *gb, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
Definition: anm.c:76
TYPE
#define TYPE
Definition: ffv1dec.c:116
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
size
int size
Definition: twinvq_data.h:10344
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
src
#define src
Definition: vp8dsp.c:248