Otclient  14/8/2020
apngloader.cpp File Reference
#include "apngloader.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <memory>
#include <sstream>
#include <zlib.h>
Include dependency graph for apngloader.cpp:

Go to the source code of this file.

Macros

#define swap16(data)   (((data >> 8) & 255) | ((data & 255) << 8))
 
#define swap32(data)   ((swap16(data) << 16) | swap16(data >> 16))
 
#define PNG_ZBUF_SIZE   32768
 
#define PNG_DISPOSE_OP_NONE   0x00
 
#define PNG_DISPOSE_OP_BACKGROUND   0x01
 
#define PNG_DISPOSE_OP_PREVIOUS   0x02
 
#define PNG_BLEND_OP_SOURCE   0x00
 
#define PNG_BLEND_OP_OVER   0x01
 
#define notabc(c)   ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
 
#define ROWBYTES(pixel_bits, width)
 

Functions

unsigned int read32 (std::istream &f1)
 
unsigned short read16 (std::istream &f1)
 
unsigned short readshort (unsigned char *p)
 
void read_sub_row (unsigned char *row, unsigned int rowbytes, unsigned int bpp)
 
void read_up_row (unsigned char *row, unsigned char *prev_row, unsigned int rowbytes, unsigned int bpp)
 
void read_average_row (unsigned char *row, unsigned char *prev_row, unsigned int rowbytes, unsigned int bpp)
 
void read_paeth_row (unsigned char *row, unsigned char *prev_row, unsigned int rowbytes, unsigned int bpp)
 
void unpack (z_stream &zstream, unsigned char *dst, unsigned int dst_size, unsigned char *src, unsigned int src_size, unsigned int h, unsigned int rowbytes, unsigned char bpp)
 
void compose0 (unsigned char *dst1, unsigned int dstbytes1, unsigned char *dst2, unsigned int dstbytes2, unsigned char *src, unsigned int srcbytes, unsigned int w, unsigned int h, unsigned int bop, unsigned char depth)
 
void compose2 (unsigned char *dst1, unsigned int dstbytes1, unsigned char *dst2, unsigned int dstbytes2, unsigned char *src, unsigned int srcbytes, unsigned int w, unsigned int h, unsigned int bop, unsigned char depth)
 
void compose3 (unsigned char *dst1, unsigned int dstbytes1, unsigned char *dst2, unsigned int dstbytes2, unsigned char *src, unsigned int srcbytes, unsigned int w, unsigned int h, unsigned int bop, unsigned char depth)
 
void compose4 (unsigned char *dst, unsigned int dstbytes, unsigned char *src, unsigned int srcbytes, unsigned int w, unsigned int h, unsigned int bop, unsigned char depth)
 
void compose6 (unsigned char *dst, unsigned int dstbytes, unsigned char *src, unsigned int srcbytes, unsigned int w, unsigned int h, unsigned int bop, unsigned char depth)
 
int load_apng (std::stringstream &file, struct apng_data *apng)
 
void write_chunk (std::ostream &f, const char *name, unsigned char *data, unsigned int length)
 
void write_IDATs (std::ostream &f, unsigned char *data, unsigned int length, unsigned int idat_size)
 
void save_png (std::stringstream &f, unsigned int width, unsigned int height, int channels, unsigned char *pixels)
 
void free_apng (struct apng_data *apng)
 

Variables

unsigned char png_sign [8] = {137, 80, 78, 71, 13, 10, 26, 10}
 
int mask4 [2] ={240,15}
 
int shift4 [2] ={4,0}
 
int mask2 [4] ={192,48,12,3}
 
int shift2 [4] ={6,4,2,0}
 
int mask1 [8] ={128,64,32,16,8,4,2,1}
 
int shift1 [8] ={7,6,5,4,3,2,1,0}
 
unsigned int keep_original = 1
 
unsigned char pal [256][3]
 
unsigned char trns [256]
 
unsigned int palsize
 
unsigned int trnssize
 
unsigned int hasTRNS
 
unsigned short trns1
 
unsigned short trns2
 
unsigned short trns3
 

Macro Definition Documentation

◆ notabc

#define notabc (   c)    ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))

Definition at line 58 of file apngloader.cpp.

◆ PNG_BLEND_OP_OVER

#define PNG_BLEND_OP_OVER   0x01

Definition at line 56 of file apngloader.cpp.

◆ PNG_BLEND_OP_SOURCE

#define PNG_BLEND_OP_SOURCE   0x00

Definition at line 55 of file apngloader.cpp.

◆ PNG_DISPOSE_OP_BACKGROUND

#define PNG_DISPOSE_OP_BACKGROUND   0x01

Definition at line 52 of file apngloader.cpp.

◆ PNG_DISPOSE_OP_NONE

#define PNG_DISPOSE_OP_NONE   0x00

Definition at line 51 of file apngloader.cpp.

◆ PNG_DISPOSE_OP_PREVIOUS

#define PNG_DISPOSE_OP_PREVIOUS   0x02

Definition at line 53 of file apngloader.cpp.

◆ PNG_ZBUF_SIZE

#define PNG_ZBUF_SIZE   32768

Definition at line 49 of file apngloader.cpp.

◆ ROWBYTES

#define ROWBYTES (   pixel_bits,
  width 
)
Value:
((pixel_bits) >= 8 ? \
((width) * (((unsigned int)(pixel_bits)) >> 3)) : \
(( ((width) * ((unsigned int)(pixel_bits))) + 7) >> 3) )

Definition at line 60 of file apngloader.cpp.

◆ swap16

#define swap16 (   data)    (((data >> 8) & 255) | ((data & 255) << 8))

Definition at line 45 of file apngloader.cpp.

◆ swap32

#define swap32 (   data)    ((swap16(data) << 16) | swap16(data >> 16))

Definition at line 46 of file apngloader.cpp.

Function Documentation

◆ compose0()

void compose0 ( unsigned char *  dst1,
unsigned int  dstbytes1,
unsigned char *  dst2,
unsigned int  dstbytes2,
unsigned char *  src,
unsigned int  srcbytes,
unsigned int  w,
unsigned int  h,
unsigned int  bop,
unsigned char  depth 
)

Definition at line 198 of file apngloader.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compose2()

void compose2 ( unsigned char *  dst1,
unsigned int  dstbytes1,
unsigned char *  dst2,
unsigned int  dstbytes2,
unsigned char *  src,
unsigned int  srcbytes,
unsigned int  w,
unsigned int  h,
unsigned int  bop,
unsigned char  depth 
)

Definition at line 240 of file apngloader.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compose3()

void compose3 ( unsigned char *  dst1,
unsigned int  dstbytes1,
unsigned char *  dst2,
unsigned int  dstbytes2,
unsigned char *  src,
unsigned int  srcbytes,
unsigned int  w,
unsigned int  h,
unsigned int  bop,
unsigned char  depth 
)

Definition at line 312 of file apngloader.cpp.

Here is the caller graph for this function:

◆ compose4()

void compose4 ( unsigned char *  dst,
unsigned int  dstbytes,
unsigned char *  src,
unsigned int  srcbytes,
unsigned int  w,
unsigned int  h,
unsigned int  bop,
unsigned char  depth 
)

Definition at line 389 of file apngloader.cpp.

Here is the caller graph for this function:

◆ compose6()

void compose6 ( unsigned char *  dst,
unsigned int  dstbytes,
unsigned char *  src,
unsigned int  srcbytes,
unsigned int  w,
unsigned int  h,
unsigned int  bop,
unsigned char  depth 
)

Definition at line 449 of file apngloader.cpp.

Here is the caller graph for this function:

◆ free_apng()

void free_apng ( struct apng_data apng)

Definition at line 1149 of file apngloader.cpp.

Here is the caller graph for this function:

◆ load_apng()

int load_apng ( std::stringstream &  file,
struct apng_data apng 
)

Definition at line 513 of file apngloader.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read16()

unsigned short read16 ( std::istream &  f1)

Definition at line 93 of file apngloader.cpp.

Here is the caller graph for this function:

◆ read32()

unsigned int read32 ( std::istream &  f1)

Definition at line 83 of file apngloader.cpp.

Here is the caller graph for this function:

◆ read_average_row()

void read_average_row ( unsigned char *  row,
unsigned char *  prev_row,
unsigned int  rowbytes,
unsigned int  bpp 
)

Definition at line 123 of file apngloader.cpp.

Here is the caller graph for this function:

◆ read_paeth_row()

void read_paeth_row ( unsigned char *  row,
unsigned char *  prev_row,
unsigned int  rowbytes,
unsigned int  bpp 
)

Definition at line 141 of file apngloader.cpp.

Here is the caller graph for this function:

◆ read_sub_row()

void read_sub_row ( unsigned char *  row,
unsigned int  rowbytes,
unsigned int  bpp 
)

Definition at line 106 of file apngloader.cpp.

Here is the caller graph for this function:

◆ read_up_row()

void read_up_row ( unsigned char *  row,
unsigned char *  prev_row,
unsigned int  rowbytes,
unsigned int  bpp 
)

Definition at line 114 of file apngloader.cpp.

Here is the caller graph for this function:

◆ readshort()

unsigned short readshort ( unsigned char *  p)

Definition at line 101 of file apngloader.cpp.

Here is the caller graph for this function:

◆ save_png()

void save_png ( std::stringstream &  f,
unsigned int  width,
unsigned int  height,
int  channels,
unsigned char *  pixels 
)

Definition at line 922 of file apngloader.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unpack()

void unpack ( z_stream &  zstream,
unsigned char *  dst,
unsigned int  dst_size,
unsigned char *  src,
unsigned int  src_size,
unsigned int  h,
unsigned int  rowbytes,
unsigned char  bpp 
)

Definition at line 170 of file apngloader.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_chunk()

void write_chunk ( std::ostream &  f,
const char *  name,
unsigned char *  data,
unsigned int  length 
)

Definition at line 867 of file apngloader.cpp.

Here is the caller graph for this function:

◆ write_IDATs()

void write_IDATs ( std::ostream &  f,
unsigned char *  data,
unsigned int  length,
unsigned int  idat_size 
)

Definition at line 885 of file apngloader.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ hasTRNS

unsigned int hasTRNS

Definition at line 80 of file apngloader.cpp.

◆ keep_original

unsigned int keep_original = 1

Definition at line 76 of file apngloader.cpp.

◆ mask1

int mask1[8] ={128,64,32,16,8,4,2,1}

Definition at line 73 of file apngloader.cpp.

◆ mask2

int mask2[4] ={192,48,12,3}

Definition at line 70 of file apngloader.cpp.

◆ mask4

int mask4[2] ={240,15}

Definition at line 67 of file apngloader.cpp.

◆ pal

unsigned char pal[256][3]

Definition at line 77 of file apngloader.cpp.

◆ palsize

unsigned int palsize

Definition at line 79 of file apngloader.cpp.

◆ png_sign

unsigned char png_sign[8] = {137, 80, 78, 71, 13, 10, 26, 10}

Definition at line 65 of file apngloader.cpp.

◆ shift1

int shift1[8] ={7,6,5,4,3,2,1,0}

Definition at line 74 of file apngloader.cpp.

◆ shift2

int shift2[4] ={6,4,2,0}

Definition at line 71 of file apngloader.cpp.

◆ shift4

int shift4[2] ={4,0}

Definition at line 68 of file apngloader.cpp.

◆ trns

unsigned char trns[256]

Definition at line 78 of file apngloader.cpp.

◆ trns1

unsigned short trns1

Definition at line 81 of file apngloader.cpp.

◆ trns2

unsigned short trns2

Definition at line 81 of file apngloader.cpp.

◆ trns3

unsigned short trns3

Definition at line 81 of file apngloader.cpp.

◆ trnssize

unsigned int trnssize

Definition at line 79 of file apngloader.cpp.