StuBS
PNG Class Reference

Portable Network Graphics file format. More...

#include <utils/png.h>

Classes

struct  huffman_tree
 

Public Types

enum  error {
  PNG_EOK = 0 ,
  PNG_ENOMEM = 1 ,
  PNG_ENOTFOUND = 2 ,
  PNG_ENOTPNG = 3 ,
  PNG_EMALFORMED = 4 ,
  PNG_EUNSUPPORTED = 5 ,
  PNG_EUNINTERLACED = 6 ,
  PNG_EUNFORMAT = 7 ,
  PNG_EPARAM = 8 ,
  PNG_EIOERROR = 9
}
 
enum  format {
  BADFORMAT ,
  RGB8 ,
  RGB16 ,
  RGBA8 ,
  RGBA16 ,
  LUMINANCE1 ,
  LUMINANCE2 ,
  LUMINANCE4 ,
  LUMINANCE8 ,
  LUMINANCE_ALPHA1 ,
  LUMINANCE_ALPHA2 ,
  LUMINANCE_ALPHA4 ,
  LUMINANCE_ALPHA8
}
 

Public Member Functions

 PNG (const unsigned char *buffer, unsigned long size)
 Load PNG image from memory.
 
 PNG (const char *path)
 Load PNG image from file system.
 
 ~PNG ()
 Free memory reserved for PNG image.
 
unsigned get_width () const
 Width of image (pixels)
 
unsigned get_height () const
 Height of image (pixels)
 
unsigned get_bpp () const
 Bits per pixel.
 
unsigned get_bitdepth () const
 Depth of color (bits pro color channel)
 
unsigned get_components () const
 Number of components per pixel.
 
unsigned get_pixelsize () const
 Number of bytes per pixel.
 
enum format get_format () const
 Retrieve the format.
 
const unsigned char * get_buffer ()
 Image buffer address.
 
unsigned get_size ()
 Size of image buffer.
 

Protected Member Functions

enum error header ()
 Extract header (image attributes)
 
enum error decode ()
 Decode whole image.
 

Protected Attributes

enum error error
 
unsigned error_line
 

Private Types

enum  color {
  COLOR_LUM = 0 ,
  COLOR_RGB = 2 ,
  COLOR_LUMA = 4 ,
  COLOR_RGBA = 6
}
 
enum  {
  STATE_ERROR = -1 ,
  STATE_DECODED = 0 ,
  STATE_HEADER = 1 ,
  STATE_NEW = 2
}
 

Private Member Functions

void free_source ()
 
void huffman_tree_create_lengths (struct huffman_tree *tree, const unsigned *bitlen)
 
unsigned huffman_decode_symbol (const unsigned char *in, unsigned long *bp, const struct huffman_tree *codetree, unsigned long inlength)
 
void get_tree_inflate_dynamic (struct huffman_tree *codetree, struct huffman_tree *codetreeD, struct huffman_tree *codelengthcodetree, const unsigned char *in, unsigned long *bp, unsigned long inlength)
 
void inflate_huffman (unsigned char *out, unsigned long outsize, const unsigned char *in, unsigned long *bp, unsigned long *pos, unsigned long inlength, unsigned btype)
 
void inflate_uncompressed (unsigned char *out, unsigned long outsize, const unsigned char *in, unsigned long *bp, unsigned long *pos, unsigned long inlength)
 
enum error uz_inflate_data (unsigned char *out, unsigned long outsize, const unsigned char *in, unsigned long insize, unsigned long inpos)
 
enum error uz_inflate (unsigned char *out, unsigned long outsize, const unsigned char *in, unsigned long insize)
 
void unfilter_scanline (unsigned char *recon, const unsigned char *scanline, const unsigned char *precon, unsigned long bytewidth, unsigned char filterType, unsigned long length)
 
void unfilter (unsigned char *out, const unsigned char *in, unsigned w, unsigned h, unsigned bpp)
 
void post_process_scanlines (unsigned char *out, unsigned char *in, const PNG *info_png)
 
enum format determine_format ()
 

Static Private Member Functions

static void huffman_tree_init (struct huffman_tree *tree, unsigned *buffer, unsigned numcodes, unsigned maxbitlen)
 
static void remove_padding_bits (unsigned char *out, const unsigned char *in, unsigned long olinebits, unsigned long ilinebits, unsigned h)
 

Private Attributes

unsigned width = 0
 
unsigned height = 0
 
enum color color_type
 
unsigned color_depth
 
enum format format = BADFORMAT
 
unsigned char * buffer = nullptr
 
unsigned long size = 0
 
enum PNG:: { ... }  state
 
struct { 
 
const unsigned char * buffer
 
unsigned long size
 
char owning
 
source 
 

Detailed Description

Portable Network Graphics file format.

!


Class Documentation

◆ PNG::huffman_tree

struct PNG::huffman_tree
Class Members
unsigned * tree2d
unsigned maxbitlen maximum number of bits a single code can get
unsigned numcodes number of symbols in the alphabet = number of codes

Member Enumeration Documentation

◆ error

enum PNG::error
Enumerator
PNG_EOK 

success (no error)

PNG_ENOMEM 

memory allocation failed

PNG_ENOTFOUND 

resource not found (file missing)

PNG_ENOTPNG 

image data does not have a PNG header

PNG_EMALFORMED 

image data is not a valid PNG image

PNG_EUNSUPPORTED 

critical PNG chunk type is not supported

PNG_EUNINTERLACED 

image interlacing is not supported

PNG_EUNFORMAT 

image color format is not supported

PNG_EPARAM 

invalid parameter to method call

PNG_EIOERROR 

Filesystem issues.

◆ format

Enumerator
BADFORMAT 

Invalid format.

RGB8 

24bit RGB (8bit per color)

RGB16 

48bit RGB (16bit per color)

RGBA8 

32bit RGB (including alpha channel)

RGBA16 

64bit RGB (including alpha channel)

LUMINANCE1 

Monochrome (black-white)

LUMINANCE2 

four shades of gray (2bit gray scale)

LUMINANCE4 

16 shades of gray (4bit gray scale)

LUMINANCE8 

8bit gray scale

LUMINANCE_ALPHA1 

Monochrome (black-white) with alpha channel.

LUMINANCE_ALPHA2 

2bit gray scale with alpha channel

LUMINANCE_ALPHA4 

4bit gray scale with alpha channel

LUMINANCE_ALPHA8 

8bit gray scale with alpha channel

◆ color

enum PNG::color
private
Enumerator
COLOR_LUM 
COLOR_RGB 
COLOR_LUMA 
COLOR_RGBA 

◆ anonymous enum

anonymous enum
private
Enumerator
STATE_ERROR 
STATE_DECODED 
STATE_HEADER 
STATE_NEW 

Constructor & Destructor Documentation

◆ PNG() [1/2]

PNG::PNG ( const unsigned char *  buffer,
unsigned long  size 
)

Load PNG image from memory.

Parameters
bufferpointer to memory buffer
sizesize of memory buffer

◆ PNG() [2/2]

PNG::PNG ( const char *  path)
explicit

Load PNG image from file system.

Parameters
pathpath to file

◆ ~PNG()

PNG::~PNG ( )

Free memory reserved for PNG image.

Member Function Documentation

◆ free_source()

void PNG::free_source ( )
private

◆ huffman_tree_init()

void PNG::huffman_tree_init ( struct huffman_tree tree,
unsigned *  buffer,
unsigned  numcodes,
unsigned  maxbitlen 
)
staticprivate

◆ huffman_tree_create_lengths()

void PNG::huffman_tree_create_lengths ( struct huffman_tree tree,
const unsigned *  bitlen 
)
private

◆ huffman_decode_symbol()

unsigned PNG::huffman_decode_symbol ( const unsigned char *  in,
unsigned long *  bp,
const struct huffman_tree codetree,
unsigned long  inlength 
)
private

◆ get_tree_inflate_dynamic()

void PNG::get_tree_inflate_dynamic ( struct huffman_tree codetree,
struct huffman_tree codetreeD,
struct huffman_tree codelengthcodetree,
const unsigned char *  in,
unsigned long *  bp,
unsigned long  inlength 
)
private

◆ inflate_huffman()

void PNG::inflate_huffman ( unsigned char *  out,
unsigned long  outsize,
const unsigned char *  in,
unsigned long *  bp,
unsigned long *  pos,
unsigned long  inlength,
unsigned  btype 
)
private

◆ inflate_uncompressed()

void PNG::inflate_uncompressed ( unsigned char *  out,
unsigned long  outsize,
const unsigned char *  in,
unsigned long *  bp,
unsigned long *  pos,
unsigned long  inlength 
)
private

◆ uz_inflate_data()

enum PNG::error PNG::uz_inflate_data ( unsigned char *  out,
unsigned long  outsize,
const unsigned char *  in,
unsigned long  insize,
unsigned long  inpos 
)
private

◆ uz_inflate()

enum PNG::error PNG::uz_inflate ( unsigned char *  out,
unsigned long  outsize,
const unsigned char *  in,
unsigned long  insize 
)
private

◆ unfilter_scanline()

void PNG::unfilter_scanline ( unsigned char *  recon,
const unsigned char *  scanline,
const unsigned char *  precon,
unsigned long  bytewidth,
unsigned char  filterType,
unsigned long  length 
)
private

◆ unfilter()

void PNG::unfilter ( unsigned char *  out,
const unsigned char *  in,
unsigned  w,
unsigned  h,
unsigned  bpp 
)
private

◆ remove_padding_bits()

void PNG::remove_padding_bits ( unsigned char *  out,
const unsigned char *  in,
unsigned long  olinebits,
unsigned long  ilinebits,
unsigned  h 
)
staticprivate

◆ post_process_scanlines()

void PNG::post_process_scanlines ( unsigned char *  out,
unsigned char *  in,
const PNG info_png 
)
private

◆ determine_format()

enum PNG::format PNG::determine_format ( )
private

◆ header()

enum PNG::error PNG::header ( )
protected

Extract header (image attributes)

◆ decode()

enum PNG::error PNG::decode ( )
protected

Decode whole image.

◆ get_width()

unsigned PNG::get_width ( ) const
inline

Width of image (pixels)

◆ get_height()

unsigned PNG::get_height ( ) const
inline

Height of image (pixels)

◆ get_bpp()

unsigned PNG::get_bpp ( ) const
inline

Bits per pixel.

◆ get_bitdepth()

unsigned PNG::get_bitdepth ( ) const
inline

Depth of color (bits pro color channel)

◆ get_components()

unsigned PNG::get_components ( ) const
inline

Number of components per pixel.

◆ get_pixelsize()

unsigned PNG::get_pixelsize ( ) const
inline

Number of bytes per pixel.

◆ get_format()

enum format PNG::get_format ( ) const
inline

Retrieve the format.

◆ get_buffer()

const unsigned char * PNG::get_buffer ( )
inline

Image buffer address.

Returns
Pointer to image buffer

◆ get_size()

unsigned PNG::get_size ( )
inline

Size of image buffer.

Returns
Total size of image buffer in bytes

Member Data Documentation

◆ width

unsigned PNG::width = 0
private

◆ height

unsigned PNG::height = 0
private

◆ color_type

enum color PNG::color_type
private

◆ color_depth

unsigned PNG::color_depth
private

◆ format

enum format PNG::format = BADFORMAT
private

◆ buffer

unsigned char* PNG::buffer = nullptr
private

◆ size

unsigned long PNG::size = 0
private

◆ []

enum { ... } PNG::state

◆ [struct]

struct { ... } PNG::source

◆ error

enum error PNG::error
protected

◆ error_line

unsigned PNG::error_line
protected

The documentation for this class was generated from the following files: