Classes | Macros | Typedefs | Functions | Variables
lodepng.cpp File Reference
#include "lodepng.h"
#include "portable.h"

Go to the source code of this file.

Classes

struct  vector
 
struct  uivector
 
struct  ucvector
 
struct  Coin
 
struct  HuffmanTree
 

Macros

#define USE_BRUTE_FORCE_ENCODING   1
 
#define VERSION_STRING   "20080927"
 
#define FIRST_LENGTH_CODE_INDEX   257
 
#define LAST_LENGTH_CODE_INDEX   285
 
#define NUM_DEFLATE_CODE_SYMBOLS   288 /*256 literals, the end code, some length codes, and 2 unused codes*/
 
#define NUM_DISTANCE_SYMBOLS   32 /*the distance codes have their own symbols, 30 used, 2 unused*/
 
#define NUM_CODE_LENGTH_CODES   19 /*the code length codes. 0-15: code lengths, 16: copy previous 3-6 times, 17: 3-10 zeros, 18: 11-138 zeros*/
 
#define encodeLZ77   encodeLZ77_brute
 

Typedefs

typedef struct vector vector
 
typedef struct uivector uivector
 
typedef struct ucvector ucvector
 
typedef struct Coin Coin
 
typedef struct HuffmanTree HuffmanTree
 

Functions

static unsigned vector_resize (vector *p, size_t size)
 
static unsigned vector_resized (vector *p, size_t size, void dtor(void *))
 
static void vector_cleanup (void *p)
 
static void vector_cleanupd (vector *p, void dtor(void *))
 
static void vector_init (vector *p, unsigned typesize)
 
static void vector_swap (vector *p, vector *q)
 
static void * vector_get (vector *p, size_t index)
 
static void uivector_cleanup (void *p)
 
static unsigned uivector_resize (uivector *p, size_t size)
 
static unsigned uivector_resizev (uivector *p, size_t size, unsigned value)
 
static void uivector_init (uivector *p)
 
static unsigned uivector_push_back (uivector *p, unsigned c)
 
static unsigned uivector_copy (uivector *p, const uivector *q)
 
static void uivector_swap (uivector *p, uivector *q)
 
static void ucvector_cleanup (void *p)
 
static unsigned ucvector_resize (ucvector *p, size_t size)
 
static void ucvector_init (ucvector *p)
 
static void ucvector_init_buffer (ucvector *p, unsigned char *buffer, size_t size)
 
static unsigned ucvector_push_back (ucvector *p, unsigned char c)
 
static void addBitToStream (size_t *bitpointer, ucvector *bitstream, unsigned char bit)
 
static void addBitsToStream (size_t *bitpointer, ucvector *bitstream, unsigned value, size_t nbits)
 
static void addBitsToStreamReversed (size_t *bitpointer, ucvector *bitstream, unsigned value, size_t nbits)
 
static void Coin_init (Coin *c)
 
static void Coin_cleanup (void *c)
 
static void Coin_copy (Coin *c1, const Coin *c2)
 
static void addCoins (Coin *c1, const Coin *c2)
 
static void Coin_sort (Coin *data, size_t amount)
 
static void HuffmanTree_init (HuffmanTree *tree)
 
static void HuffmanTree_cleanup (HuffmanTree *tree)
 
static unsigned HuffmanTree_make2DTree (HuffmanTree *tree)
 
static unsigned HuffmanTree_makeFromLengths2 (HuffmanTree *tree)
 
static unsigned HuffmanTree_makeFromLengths (HuffmanTree *tree, const unsigned *bitlen, size_t numcodes, unsigned maxbitlen)
 
static unsigned HuffmanTree_fillInCoins (vector *coins, const unsigned *frequencies, unsigned numcodes, size_t sum)
 
static unsigned HuffmanTree_makeFromFrequencies (HuffmanTree *tree, const unsigned *frequencies, size_t numcodes, unsigned maxbitlen)
 
static unsigned HuffmanTree_getCode (const HuffmanTree *tree, unsigned index)
 
static unsigned HuffmanTree_getLength (const HuffmanTree *tree, unsigned index)
 
static unsigned generateFixedTree (HuffmanTree *tree)
 
static unsigned generateDistanceTree (HuffmanTree *tree)
 
static void addHuffmanSymbol (size_t *bp, ucvector *compressed, unsigned code, unsigned bitlen)
 
static size_t searchCodeIndex (const unsigned *array, size_t array_size, size_t value)
 
static void addLengthDistance (uivector *values, size_t length, size_t distance)
 
static unsigned encodeLZ77_brute (uivector *out, const unsigned char *in, size_t size, unsigned windowSize)
 
static unsigned deflateNoCompression (ucvector *out, const unsigned char *data, size_t datasize)
 
static void writeLZ77data (size_t *bp, ucvector *out, const uivector *lz77_encoded, const HuffmanTree *codes, const HuffmanTree *codesD)
 
static unsigned deflateDynamic (ucvector *out, const unsigned char *data, size_t datasize, const LodeZlib_DeflateSettings *settings)
 
static unsigned deflateFixed (ucvector *out, const unsigned char *data, size_t datasize, const LodeZlib_DeflateSettings *settings)
 
unsigned LodeFlate_deflate (ucvector *out, const unsigned char *data, size_t datasize, const LodeZlib_DeflateSettings *settings)
 
static unsigned update_adler32 (unsigned adler, const unsigned char *data, unsigned len)
 
static unsigned adler32 (const unsigned char *data, unsigned len)
 
void LodeZlib_add32bitInt (ucvector *buffer, unsigned value)
 
unsigned LodeZlib_read32bitInt (const unsigned char *buffer)
 
unsigned LodeZlib_compress (unsigned char **out, size_t *outsize, const unsigned char *in, size_t insize, const LodeZlib_DeflateSettings *settings)
 
void LodeZlib_DeflateSettings_init (LodeZlib_DeflateSettings *settings)
 
static unsigned LodePNG_compress (unsigned char **out, size_t *outsize, const unsigned char *in, size_t insize, const LodeZlib_DeflateSettings *settings)
 
static void Crc32_make_crc_table (void)
 
static unsigned Crc32_update_crc (const unsigned char *buf, unsigned int crc, size_t len)
 
static unsigned Crc32_crc (const unsigned char *buf, size_t len)
 
static unsigned char readBitFromReversedStream (size_t *bitpointer, const unsigned char *bitstream)
 
static unsigned readBitsFromReversedStream (size_t *bitpointer, const unsigned char *bitstream, size_t nbits)
 
static void setBitOfReversedStream (size_t *bitpointer, unsigned char *bitstream, unsigned char bit)
 
static unsigned LodePNG_read32bitInt (const unsigned char *buffer)
 
static void LodePNG_set32bitInt (unsigned char *buffer, unsigned value)
 
static void LodePNG_add32bitInt (ucvector *buffer, unsigned value)
 
unsigned LodePNG_chunk_length (const unsigned char *chunk)
 
void LodePNG_chunk_type (char type[5], const unsigned char *chunk)
 
unsigned char LodePNG_chunk_type_equals (const unsigned char *chunk, const char *type)
 
unsigned char LodePNG_chunk_critical (const unsigned char *chunk)
 
unsigned char LodePNG_chunk_private (const unsigned char *chunk)
 
unsigned char LodePNG_chunk_safetocopy (const unsigned char *chunk)
 
unsigned char * LodePNG_chunk_data (unsigned char *chunk)
 
const unsigned char * LodePNG_chunk_data_const (const unsigned char *chunk)
 
unsigned LodePNG_chunk_check_crc (const unsigned char *chunk)
 
void LodePNG_chunk_generate_crc (unsigned char *chunk)
 
unsigned char * LodePNG_chunk_next (unsigned char *chunk)
 
const unsigned char * LodePNG_chunk_next_const (const unsigned char *chunk)
 
unsigned LodePNG_append_chunk (unsigned char **out, size_t *outlength, const unsigned char *chunk)
 
unsigned LodePNG_create_chunk (unsigned char **out, size_t *outlength, unsigned length, const char *type, const unsigned char *data)
 
static unsigned checkColorValidity (unsigned colorType, unsigned bd)
 
static unsigned getNumColorChannels (unsigned colorType)
 
static unsigned getBpp (unsigned colorType, unsigned bitDepth)
 
void LodePNG_InfoColor_init (LodePNG_InfoColor *info)
 
void LodePNG_InfoColor_cleanup (LodePNG_InfoColor *info)
 
void LodePNG_InfoColor_clearPalette (LodePNG_InfoColor *info)
 
unsigned LodePNG_InfoColor_addPalette (LodePNG_InfoColor *info, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
 
unsigned LodePNG_InfoColor_getBpp (const LodePNG_InfoColor *info)
 
unsigned LodePNG_InfoColor_getChannels (const LodePNG_InfoColor *info)
 
unsigned LodePNG_InfoColor_isGreyscaleType (const LodePNG_InfoColor *info)
 
unsigned LodePNG_InfoColor_isAlphaType (const LodePNG_InfoColor *info)
 
unsigned LodePNG_InfoColor_equal (const LodePNG_InfoColor *info1, const LodePNG_InfoColor *info2)
 
void LodePNG_InfoPng_init (LodePNG_InfoPng *info)
 
void LodePNG_InfoPng_cleanup (LodePNG_InfoPng *info)
 
unsigned LodePNG_InfoPng_copy (LodePNG_InfoPng *dest, const LodePNG_InfoPng *source)
 
void LodePNG_InfoPng_swap (LodePNG_InfoPng *a, LodePNG_InfoPng *b)
 
unsigned LodePNG_InfoColor_copy (LodePNG_InfoColor *dest, const LodePNG_InfoColor *source)
 
void LodePNG_InfoRaw_init (LodePNG_InfoRaw *info)
 
void LodePNG_InfoRaw_cleanup (LodePNG_InfoRaw *info)
 
unsigned LodePNG_InfoRaw_copy (LodePNG_InfoRaw *dest, const LodePNG_InfoRaw *source)
 
unsigned LodePNG_convert (unsigned char *out, const unsigned char *in, LodePNG_InfoColor *infoOut, LodePNG_InfoColor *infoIn, unsigned w, unsigned h)
 
static int paethPredictor (int a, int b, int c)
 
static void Adam7_getpassvalues (unsigned passw[7], unsigned passh[7], size_t filter_passstart[8], size_t padded_passstart[8], size_t passstart[8], unsigned w, unsigned h, unsigned bpp)
 
static unsigned addChunk (ucvector *out, const char *chunkName, const unsigned char *data, size_t length)
 
static void writeSignature (ucvector *out)
 
static unsigned addChunk_IHDR (ucvector *out, unsigned w, unsigned h, unsigned bitDepth, unsigned colorType, unsigned interlaceMethod)
 
static unsigned addChunk_PLTE (ucvector *out, const LodePNG_InfoColor *info)
 
static unsigned addChunk_tRNS (ucvector *out, const LodePNG_InfoColor *info)
 
static unsigned addChunk_IDAT (ucvector *out, const unsigned char *data, size_t datasize, LodeZlib_DeflateSettings *zlibsettings)
 
static unsigned addChunk_IEND (ucvector *out)
 
static void filterScanline (unsigned char *out, const unsigned char *scanline, const unsigned char *prevline, size_t length, size_t bytewidth, unsigned char filterType)
 
static unsigned filter (unsigned char *out, const unsigned char *in, unsigned w, unsigned h, const LodePNG_InfoColor *info)
 
static void addPaddingBits (unsigned char *out, const unsigned char *in, size_t olinebits, size_t ilinebits, unsigned h)
 
static void Adam7_interlace (unsigned char *out, const unsigned char *in, unsigned w, unsigned h, unsigned bpp)
 
static unsigned preProcessScanlines (unsigned char **out, size_t *outsize, const unsigned char *in, const LodePNG_InfoPng *infoPng)
 
static unsigned isPaletteFullyOpaque (const unsigned char *palette, size_t palettesize)
 
static unsigned isFullyOpaque (const unsigned char *image, unsigned w, unsigned h, const LodePNG_InfoColor *info)
 
void LodePNG_encode (LodePNG_Encoder *encoder, unsigned char **out, size_t *outsize, const unsigned char *image, unsigned w, unsigned h)
 
unsigned LodePNG_encode32 (unsigned char **out, size_t *outsize, const unsigned char *image, unsigned w, unsigned h)
 
unsigned LodePNG_encode32f (const char *filename, const unsigned char *image, unsigned w, unsigned h)
 
void LodePNG_EncodeSettings_init (LodePNG_EncodeSettings *settings)
 
void LodePNG_Encoder_init (LodePNG_Encoder *encoder)
 
void LodePNG_Encoder_cleanup (LodePNG_Encoder *encoder)
 
void LodePNG_Encoder_copy (LodePNG_Encoder *dest, const LodePNG_Encoder *source)
 
unsigned LodePNG_loadFile (unsigned char **out, size_t *outsize, const char *filename)
 
unsigned LodePNG_saveFile (const unsigned char *buffer, size_t buffersize, const char *filename)
 

Variables

static const unsigned LENGTHBASE [29] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258}
 
static const unsigned LENGTHEXTRA [29] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0}
 
static const unsigned DISTANCEBASE [30] = {1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577}
 
static const unsigned DISTANCEEXTRA [30] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13}
 
static const unsigned CLCL [NUM_CODE_LENGTH_CODES] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}
 
static const size_t MAX_SUPPORTED_DEFLATE_LENGTH = 258
 
const LodeZlib_DeflateSettings LodeZlib_defaultDeflateSettings = {2, 1, 2048}
 
static unsigned Crc32_crc_table_computed = 0
 
static unsigned Crc32_crc_table [256]
 
static const unsigned ADAM7_IX [7] = { 0, 4, 0, 2, 0, 1, 0 }
 
static const unsigned ADAM7_IY [7] = { 0, 0, 4, 0, 2, 0, 1 }
 
static const unsigned ADAM7_DX [7] = { 8, 8, 4, 4, 2, 2, 1 }
 
static const unsigned ADAM7_DY [7] = { 8, 8, 8, 4, 4, 2, 2 }
 

Macro Definition Documentation

#define encodeLZ77   encodeLZ77_brute

Definition at line 1039 of file lodepng.cpp.

#define FIRST_LENGTH_CODE_INDEX   257

Definition at line 347 of file lodepng.cpp.

#define LAST_LENGTH_CODE_INDEX   285

Definition at line 348 of file lodepng.cpp.

#define NUM_CODE_LENGTH_CODES   19 /*the code length codes. 0-15: code lengths, 16: copy previous 3-6 times, 17: 3-10 zeros, 18: 11-138 zeros*/

Definition at line 351 of file lodepng.cpp.

#define NUM_DEFLATE_CODE_SYMBOLS   288 /*256 literals, the end code, some length codes, and 2 unused codes*/

Definition at line 349 of file lodepng.cpp.

#define NUM_DISTANCE_SYMBOLS   32 /*the distance codes have their own symbols, 30 used, 2 unused*/

Definition at line 350 of file lodepng.cpp.

#define USE_BRUTE_FORCE_ENCODING   1

Definition at line 34 of file lodepng.cpp.

#define VERSION_STRING   "20080927"

Definition at line 36 of file lodepng.cpp.

Typedef Documentation

typedef struct Coin Coin
typedef struct HuffmanTree HuffmanTree
typedef struct ucvector ucvector
typedef struct uivector uivector
typedef struct vector vector

Function Documentation

static void Adam7_getpassvalues ( unsigned  passw[7],
unsigned  passh[7],
size_t  filter_passstart[8],
size_t  padded_passstart[8],
size_t  passstart[8],
unsigned  w,
unsigned  h,
unsigned  bpp 
)
static

Definition at line 2570 of file lodepng.cpp.

2571 {
2572  /*the passstart values have 8 values: the 8th one actually indicates the byte after the end of the 7th (= last) pass*/
2573  unsigned i;
2574 
2575  /*calculate width and height in pixels of each pass*/
2576  for(i = 0; i < 7; i++)
2577  {
2578  passw[i] = (w + ADAM7_DX[i] - ADAM7_IX[i] - 1) / ADAM7_DX[i];
2579  passh[i] = (h + ADAM7_DY[i] - ADAM7_IY[i] - 1) / ADAM7_DY[i];
2580  if(passw[i] == 0) passh[i] = 0;
2581  if(passh[i] == 0) passw[i] = 0;
2582  }
2583 
2584  filter_passstart[0] = padded_passstart[0] = passstart[0] = 0;
2585  for(i = 0; i < 7; i++)
2586  {
2587  filter_passstart[i + 1] = filter_passstart[i] + ((passw[i] && passh[i]) ? passh[i] * (1 + (passw[i] * bpp + 7) / 8) : 0); /*if passw[i] is 0, it's 0 bytes, not 1 (no filtertype-byte)*/
2588  padded_passstart[i + 1] = padded_passstart[i] + passh[i] * ((passw[i] * bpp + 7) / 8); /*bits padded if needed to fill full byte at end of each scanline*/
2589  passstart[i + 1] = passstart[i] + (passh[i] * passw[i] * bpp + 7) / 8; /*only padded at end of reduced image*/
2590  }
2591 }
static const unsigned ADAM7_DY[7]
Definition: lodepng.cpp:2568
static const unsigned ADAM7_DX[7]
Definition: lodepng.cpp:2567
static const unsigned ADAM7_IX[7]
Definition: lodepng.cpp:2565
static const unsigned ADAM7_IY[7]
Definition: lodepng.cpp:2566
static void Adam7_interlace ( unsigned char *  out,
const unsigned char *  in,
unsigned  w,
unsigned  h,
unsigned  bpp 
)
static

Definition at line 3712 of file lodepng.cpp.

3713 {
3714  /*Note: this function works on image buffers WITHOUT padding bits at end of scanlines with non-multiple-of-8 bit amounts, only between reduced images is padding*/
3715  unsigned passw[7], passh[7]; size_t filter_passstart[8], padded_passstart[8], passstart[8];
3716  unsigned i;
3717 
3718  Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp);
3719 
3720  if(bpp >= 8)
3721  {
3722  for(i = 0; i < 7; i++)
3723  {
3724  unsigned x, y, b;
3725  size_t bytewidth = bpp / 8;
3726  for(y = 0; y < passh[i]; y++)
3727  for(x = 0; x < passw[i]; x++)
3728  {
3729  size_t pixelinstart = ((ADAM7_IY[i] + y * ADAM7_DY[i]) * w + ADAM7_IX[i] + x * ADAM7_DX[i]) * bytewidth;
3730  size_t pixeloutstart = passstart[i] + (y * passw[i] + x) * bytewidth;
3731  for(b = 0; b < bytewidth; b++)
3732  {
3733  out[pixeloutstart + b] = in[pixelinstart + b];
3734  }
3735  }
3736  }
3737  }
3738  else /*bpp < 8: Adam7 with pixels < 8 bit is a bit trickier: with bit pointers*/
3739  {
3740  for(i = 0; i < 7; i++)
3741  {
3742  unsigned x, y, b;
3743  unsigned ilinebits = bpp * passw[i];
3744  unsigned olinebits = bpp * w;
3745  size_t obp, ibp; /*bit pointers (for out and in buffer)*/
3746  for(y = 0; y < passh[i]; y++)
3747  for(x = 0; x < passw[i]; x++)
3748  {
3749  ibp = (ADAM7_IY[i] + y * ADAM7_DY[i]) * olinebits + (ADAM7_IX[i] + x * ADAM7_DX[i]) * bpp;
3750  obp = (8 * passstart[i]) + (y * ilinebits + x * bpp);
3751  for(b = 0; b < bpp; b++)
3752  {
3753  unsigned char bit = readBitFromReversedStream(&ibp, in);
3754  setBitOfReversedStream(&obp, out, bit);
3755  }
3756  }
3757  }
3758  }
3759 }
static const unsigned ADAM7_DY[7]
Definition: lodepng.cpp:2568
static const unsigned ADAM7_DX[7]
Definition: lodepng.cpp:2567
static const unsigned ADAM7_IX[7]
Definition: lodepng.cpp:2565
static void Adam7_getpassvalues(unsigned passw[7], unsigned passh[7], size_t filter_passstart[8], size_t padded_passstart[8], size_t passstart[8], unsigned w, unsigned h, unsigned bpp)
Definition: lodepng.cpp:2570
static unsigned char readBitFromReversedStream(size_t *bitpointer, const unsigned char *bitstream)
Definition: lodepng.cpp:1808
UWORD32 in[16]
Definition: md5.h:44
static const unsigned ADAM7_IY[7]
Definition: lodepng.cpp:2566
static bool * b
Definition: config.cpp:1043
static void setBitOfReversedStream(size_t *bitpointer, unsigned char *bitstream, unsigned char bit)
Definition: lodepng.cpp:1832
list x
Definition: train.py:276
static void addBitsToStream ( size_t *  bitpointer,
ucvector bitstream,
unsigned  value,
size_t  nbits 
)
static

Definition at line 314 of file lodepng.cpp.

315 {
316  size_t i;
317  for(i = 0; i < nbits; i++) addBitToStream(bitpointer, bitstream, (unsigned char)((value >> i) & 1));
318 }
static void addBitsToStreamReversed ( size_t *  bitpointer,
ucvector bitstream,
unsigned  value,
size_t  nbits 
)
static

Definition at line 320 of file lodepng.cpp.

321 {
322  size_t i;
323  for(i = 0; i < nbits; i++) addBitToStream(bitpointer, bitstream, (unsigned char)((value >> (nbits - 1 - i)) & 1));
324 }
static void addBitToStream ( size_t *  bitpointer,
ucvector bitstream,
unsigned char  bit 
)
static

Definition at line 307 of file lodepng.cpp.

308 {
309  if((*bitpointer) % 8 == 0) ucvector_push_back(bitstream, 0); /*add a new byte at the end*/
310  (bitstream->data[bitstream->size - 1]) |= (bit << ((*bitpointer) & 0x7)); /*earlier bit of huffman code is in a lesser significant bit of an earlier byte*/
311  (*bitpointer)++;
312 }
static unsigned ucvector_push_back(ucvector *p, unsigned char c)
Definition: lodepng.cpp:258
unsigned char * data
Definition: lodepng.cpp:201
size_t size
Definition: lodepng.cpp:202
static unsigned addChunk ( ucvector out,
const char *  chunkName,
const unsigned char *  data,
size_t  length 
)
static

Definition at line 3277 of file lodepng.cpp.

3278 {
3279  unsigned error = LodePNG_create_chunk(&out->data, &out->size, (unsigned)length, chunkName, data);
3280  if(error) return error;
3281  out->allocsize = out->size; /*fix the allocsize again*/
3282  return 0;
3283 }
unsigned LodePNG_create_chunk(unsigned char **out, size_t *outlength, unsigned length, const char *type, const unsigned char *data)
Definition: lodepng.cpp:1956
error
Definition: include.cc:26
size_t allocsize
Definition: lodepng.cpp:203
unsigned char * data
Definition: lodepng.cpp:201
size_t size
Definition: lodepng.cpp:202
static unsigned addChunk_IDAT ( ucvector out,
const unsigned char *  data,
size_t  datasize,
LodeZlib_DeflateSettings zlibsettings 
)
static

Definition at line 3368 of file lodepng.cpp.

3369 {
3370  ucvector zlibdata;
3371  unsigned error = 0;
3372 
3373  /*compress with the Zlib compressor*/
3374  ucvector_init(&zlibdata);
3375  error = LodePNG_compress(&zlibdata.data, &zlibdata.size, data, datasize, zlibsettings);
3376  if(!error) error = addChunk(out, "IDAT", zlibdata.data, zlibdata.size);
3377  ucvector_cleanup(&zlibdata);
3378 
3379  return error;
3380 }
error
Definition: include.cc:26
static unsigned addChunk(ucvector *out, const char *chunkName, const unsigned char *data, size_t length)
Definition: lodepng.cpp:3277
unsigned char * data
Definition: lodepng.cpp:201
static unsigned LodePNG_compress(unsigned char **out, size_t *outsize, const unsigned char *in, size_t insize, const LodeZlib_DeflateSettings *settings)
Definition: lodepng.cpp:1752
static void ucvector_cleanup(void *p)
Definition: lodepng.cpp:206
static void ucvector_init(ucvector *p)
Definition: lodepng.cpp:243
size_t size
Definition: lodepng.cpp:202
static unsigned addChunk_IEND ( ucvector out)
static

Definition at line 3382 of file lodepng.cpp.

3383 {
3384  unsigned error = 0;
3385  error = addChunk(out, "IEND", 0, 0);
3386  return error;
3387 }
error
Definition: include.cc:26
static unsigned addChunk(ucvector *out, const char *chunkName, const unsigned char *data, size_t length)
Definition: lodepng.cpp:3277
static unsigned addChunk_IHDR ( ucvector out,
unsigned  w,
unsigned  h,
unsigned  bitDepth,
unsigned  colorType,
unsigned  interlaceMethod 
)
static

Definition at line 3298 of file lodepng.cpp.

3299 {
3300  unsigned error = 0;
3301  ucvector header;
3302  ucvector_init(&header);
3303 
3304  LodePNG_add32bitInt(&header, w); /*width*/
3305  LodePNG_add32bitInt(&header, h); /*height*/
3306  ucvector_push_back(&header, (unsigned char)bitDepth); /*bit depth*/
3307  ucvector_push_back(&header, (unsigned char)colorType); /*color type*/
3308  ucvector_push_back(&header, 0); /*compression method*/
3309  ucvector_push_back(&header, 0); /*filter method*/
3310  ucvector_push_back(&header, interlaceMethod); /*interlace method*/
3311 
3312  error = addChunk(out, "IHDR", header.data, header.size);
3313  ucvector_cleanup(&header);
3314 
3315  return error;
3316 }
static void LodePNG_add32bitInt(ucvector *buffer, unsigned value)
Definition: lodepng.cpp:1854
error
Definition: include.cc:26
static unsigned ucvector_push_back(ucvector *p, unsigned char c)
Definition: lodepng.cpp:258
static unsigned addChunk(ucvector *out, const char *chunkName, const unsigned char *data, size_t length)
Definition: lodepng.cpp:3277
unsigned char * data
Definition: lodepng.cpp:201
static void ucvector_cleanup(void *p)
Definition: lodepng.cpp:206
static void ucvector_init(ucvector *p)
Definition: lodepng.cpp:243
size_t size
Definition: lodepng.cpp:202
static unsigned addChunk_PLTE ( ucvector out,
const LodePNG_InfoColor info 
)
static

Definition at line 3318 of file lodepng.cpp.

3319 {
3320  unsigned error = 0;
3321  size_t i;
3322  ucvector PLTE;
3323  ucvector_init(&PLTE);
3324  for(i = 0; i < info->palettesize * 4; i++) if(i % 4 != 3) ucvector_push_back(&PLTE, info->palette[i]); /*add all channels except alpha channel*/
3325  error = addChunk(out, "PLTE", PLTE.data, PLTE.size);
3326  ucvector_cleanup(&PLTE);
3327 
3328  return error;
3329 }
size_t palettesize
Definition: lodepng.h:132
error
Definition: include.cc:26
static unsigned ucvector_push_back(ucvector *p, unsigned char c)
Definition: lodepng.cpp:258
static unsigned addChunk(ucvector *out, const char *chunkName, const unsigned char *data, size_t length)
Definition: lodepng.cpp:3277
unsigned char * data
Definition: lodepng.cpp:201
static void ucvector_cleanup(void *p)
Definition: lodepng.cpp:206
static void ucvector_init(ucvector *p)
Definition: lodepng.cpp:243
size_t size
Definition: lodepng.cpp:202
unsigned char * palette
Definition: lodepng.h:131
static unsigned addChunk_tRNS ( ucvector out,
const LodePNG_InfoColor info 
)
static

Definition at line 3331 of file lodepng.cpp.

3332 {
3333  unsigned error = 0;
3334  size_t i;
3335  ucvector tRNS;
3336  ucvector_init(&tRNS);
3337  if(info->colorType == 3)
3338  {
3339  for(i = 0; i < info->palettesize; i++) ucvector_push_back(&tRNS, info->palette[4 * i + 3]); /*add only alpha channel*/
3340  }
3341  else if(info->colorType == 0)
3342  {
3343  if(info->key_defined)
3344  {
3345  ucvector_push_back(&tRNS, (unsigned char)(info->key_r / 256));
3346  ucvector_push_back(&tRNS, (unsigned char)(info->key_r % 256));
3347  }
3348  }
3349  else if(info->colorType == 2)
3350  {
3351  if(info->key_defined)
3352  {
3353  ucvector_push_back(&tRNS, (unsigned char)(info->key_r / 256));
3354  ucvector_push_back(&tRNS, (unsigned char)(info->key_r % 256));
3355  ucvector_push_back(&tRNS, (unsigned char)(info->key_g / 256));
3356  ucvector_push_back(&tRNS, (unsigned char)(info->key_g % 256));
3357  ucvector_push_back(&tRNS, (unsigned char)(info->key_b / 256));
3358  ucvector_push_back(&tRNS, (unsigned char)(info->key_b % 256));
3359  }
3360  }
3361 
3362  error = addChunk(out, "tRNS", tRNS.data, tRNS.size);
3363  ucvector_cleanup(&tRNS);
3364 
3365  return error;
3366 }
size_t palettesize
Definition: lodepng.h:132
unsigned colorType
Definition: lodepng.h:127
error
Definition: include.cc:26
static unsigned ucvector_push_back(ucvector *p, unsigned char c)
Definition: lodepng.cpp:258
unsigned key_r
Definition: lodepng.h:136
static unsigned addChunk(ucvector *out, const char *chunkName, const unsigned char *data, size_t length)
Definition: lodepng.cpp:3277
unsigned char * data
Definition: lodepng.cpp:201
static void ucvector_cleanup(void *p)
Definition: lodepng.cpp:206
static void ucvector_init(ucvector *p)
Definition: lodepng.cpp:243
unsigned key_defined
Definition: lodepng.h:135
size_t size
Definition: lodepng.cpp:202
unsigned key_g
Definition: lodepng.h:137
unsigned key_b
Definition: lodepng.h:138
unsigned char * palette
Definition: lodepng.h:131
static void addCoins ( Coin c1,
const Coin c2 
)
static

Definition at line 390 of file lodepng.cpp.

391 {
392  unsigned i;
393  for(i = 0; i < c2->symbols.size; i++) uivector_push_back(&c1->symbols, c2->symbols.data[i]);
394  c1->weight += c2->weight;
395 }
unsigned * data
Definition: lodepng.cpp:126
size_t size
Definition: lodepng.cpp:127
static unsigned uivector_push_back(uivector *p, unsigned c)
Definition: lodepng.cpp:171
float weight
Definition: lodepng.cpp:371
uivector symbols
Definition: lodepng.cpp:370
static void addHuffmanSymbol ( size_t *  bp,
ucvector compressed,
unsigned  code,
unsigned  bitlen 
)
static

Definition at line 994 of file lodepng.cpp.

995 {
996  addBitsToStreamReversed(bp, compressed, code, bitlen);
997 }
CodeOutputInterface * code
static void addBitsToStreamReversed(size_t *bitpointer, ucvector *bitstream, unsigned value, size_t nbits)
Definition: lodepng.cpp:320
static void addLengthDistance ( uivector values,
size_t  length,
size_t  distance 
)
static

Definition at line 1019 of file lodepng.cpp.

1020 {
1021  /*values in encoded vector are those used by deflate:
1022  0-255: literal bytes
1023  256: end
1024  257-285: length/distance pair (length code, followed by extra length bits, distance code, extra distance bits)
1025  286-287: invalid*/
1026 
1027  unsigned length_code = (unsigned)searchCodeIndex(LENGTHBASE, 29, length);
1028  unsigned extra_length = (unsigned)(length - LENGTHBASE[length_code]);
1029  unsigned dist_code = (unsigned)searchCodeIndex(DISTANCEBASE, 30, distance);
1030  unsigned extra_distance = (unsigned)(distance - DISTANCEBASE[dist_code]);
1031 
1032  uivector_push_back(values, length_code + FIRST_LENGTH_CODE_INDEX);
1033  uivector_push_back(values, extra_length);
1034  uivector_push_back(values, dist_code);
1035  uivector_push_back(values, extra_distance);
1036 }
static size_t searchCodeIndex(const unsigned *array, size_t array_size, size_t value)
Definition: lodepng.cpp:1000
static const unsigned DISTANCEBASE[30]
Definition: lodepng.cpp:358
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
static unsigned uivector_push_back(uivector *p, unsigned c)
Definition: lodepng.cpp:171
static const unsigned LENGTHBASE[29]
Definition: lodepng.cpp:354
#define FIRST_LENGTH_CODE_INDEX
Definition: lodepng.cpp:347
static void addPaddingBits ( unsigned char *  out,
const unsigned char *  in,
size_t  olinebits,
size_t  ilinebits,
unsigned  h 
)
static

Definition at line 3692 of file lodepng.cpp.

3693 {
3694  /*The opposite of the removePaddingBits function
3695  olinebits must be >= ilinebits*/
3696  unsigned y;
3697  size_t diff = olinebits - ilinebits;
3698  size_t obp = 0, ibp = 0; /*bit pointers*/
3699  for(y = 0; y < h; y++)
3700  {
3701  size_t x;
3702  for(x = 0; x < ilinebits; x++)
3703  {
3704  unsigned char bit = readBitFromReversedStream(&ibp, in);
3705  setBitOfReversedStream(&obp, out, bit);
3706  }
3707  /*obp += diff; --> no, fill in some value in the padding bits too, to avoid "Use of uninitialised value of size ###" warning from valgrind*/
3708  for(x = 0; x < diff; x++) setBitOfReversedStream(&obp, out, 0);
3709  }
3710 }
static unsigned char readBitFromReversedStream(size_t *bitpointer, const unsigned char *bitstream)
Definition: lodepng.cpp:1808
UWORD32 in[16]
Definition: md5.h:44
static void setBitOfReversedStream(size_t *bitpointer, unsigned char *bitstream, unsigned char bit)
Definition: lodepng.cpp:1832
list x
Definition: train.py:276
static unsigned adler32 ( const unsigned char *  data,
unsigned  len 
)
static

Definition at line 1582 of file lodepng.cpp.

1583 {
1584  return update_adler32(1L, data, len);
1585 }
static unsigned update_adler32(unsigned adler, const unsigned char *data, unsigned len)
Definition: lodepng.cpp:1558
static unsigned checkColorValidity ( unsigned  colorType,
unsigned  bd 
)
static

Definition at line 1991 of file lodepng.cpp.

1992 {
1993  switch(colorType)
1994  {
1995  case 0: if(!(bd == 1 || bd == 2 || bd == 4 || bd == 8 || bd == 16)) return 37; break; /*grey*/
1996  case 2: if(!( bd == 8 || bd == 16)) return 37; break; /*RGB*/
1997  case 3: if(!(bd == 1 || bd == 2 || bd == 4 || bd == 8 )) return 37; break; /*palette*/
1998  case 4: if(!( bd == 8 || bd == 16)) return 37; break; /*grey + alpha*/
1999  case 6: if(!( bd == 8 || bd == 16)) return 37; break; /*RGBA*/
2000  default: return 31;
2001  }
2002  return 0; /*allowed color type / bits combination*/
2003 }
static void Coin_cleanup ( void *  c)
static

Definition at line 379 of file lodepng.cpp.

380 {
381  uivector_cleanup(&((Coin*)c)->symbols);
382 }
static void uivector_cleanup(void *p)
Definition: lodepng.cpp:131
static void Coin_copy ( Coin c1,
const Coin c2 
)
static

Definition at line 384 of file lodepng.cpp.

385 {
386  c1->weight = c2->weight;
387  uivector_copy(&c1->symbols, &c2->symbols);
388 }
static unsigned uivector_copy(uivector *p, const uivector *q)
Definition: lodepng.cpp:178
float weight
Definition: lodepng.cpp:371
uivector symbols
Definition: lodepng.cpp:370
static void Coin_init ( Coin c)
static

Definition at line 374 of file lodepng.cpp.

375 {
376  uivector_init(&c->symbols);
377 }
static void uivector_init(uivector *p)
Definition: lodepng.cpp:164
uivector symbols
Definition: lodepng.cpp:370
static void Coin_sort ( Coin data,
size_t  amount 
)
static

Definition at line 397 of file lodepng.cpp.

398 {
399  size_t gap = amount;
400  unsigned char swapped = 0;
401  while(gap > 1 || swapped)
402  {
403  size_t i;
404  gap = (gap * 10) / 13; /*shrink factor 1.3*/
405  if(gap == 9 || gap == 10) gap = 11; /*combsort11*/
406  if(gap < 1) gap = 1;
407  swapped = 0;
408  for(i = 0; i < amount - gap; i++)
409  {
410  size_t j = i + gap;
411  if(data[j].weight < data[i].weight)
412  {
413  float temp = data[j].weight; data[j].weight = data[i].weight; data[i].weight = temp;
414  uivector_swap(&data[i].symbols, &data[j].symbols);
415  swapped = 1;
416  }
417  }
418  }
419 }
weight
Definition: test.py:257
float weight
Definition: lodepng.cpp:371
static void uivector_swap(uivector *p, uivector *q)
Definition: lodepng.cpp:186
static unsigned Crc32_crc ( const unsigned char *  buf,
size_t  len 
)
static

Definition at line 1799 of file lodepng.cpp.

1800 {
1801  return Crc32_update_crc(buf, 0xffffffffu, len) ^ 0xffffffffu;
1802 }
static unsigned Crc32_update_crc(const unsigned char *buf, unsigned int crc, size_t len)
Definition: lodepng.cpp:1785
UWORD32 buf[4]
Definition: md5.h:42
static void Crc32_make_crc_table ( void  )
static

Definition at line 1766 of file lodepng.cpp.

1767 {
1768  unsigned int c, k, n;
1769  for(n = 0; n < 256; n++)
1770  {
1771  c = n;
1772  for(k = 0; k < 8; k++)
1773  {
1774  if(c & 1) c = (unsigned int)(0xedb88320L ^ (c >> 1));
1775  else c = c >> 1;
1776  }
1777  Crc32_crc_table[n] = c;
1778  }
1780 }
static unsigned Crc32_crc_table[256]
Definition: lodepng.cpp:1763
std::void_t< T > n
static unsigned Crc32_crc_table_computed
Definition: lodepng.cpp:1762
static unsigned Crc32_update_crc ( const unsigned char *  buf,
unsigned int  crc,
size_t  len 
)
static

Definition at line 1785 of file lodepng.cpp.

1786 {
1787  unsigned int c = crc;
1788  size_t n;
1789 
1791  for(n = 0; n < len; n++)
1792  {
1793  c = Crc32_crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);
1794  }
1795  return c;
1796 }
static void Crc32_make_crc_table(void)
Definition: lodepng.cpp:1766
static unsigned Crc32_crc_table[256]
Definition: lodepng.cpp:1763
std::void_t< T > n
static unsigned Crc32_crc_table_computed
Definition: lodepng.cpp:1762
UWORD32 buf[4]
Definition: md5.h:42
static unsigned deflateDynamic ( ucvector out,
const unsigned char *  data,
size_t  datasize,
const LodeZlib_DeflateSettings settings 
)
static

Definition at line 1327 of file lodepng.cpp.

1328 {
1329  /*
1330  after the BFINAL and BTYPE, the dynamic block consists out of the following:
1331  - 5 bits HLIT, 5 bits HDIST, 4 bits HCLEN
1332  - (HCLEN+4)*3 bits code lengths of code length alphabet
1333  - HLIT + 257 code lenghts of lit/length alphabet (encoded using the code length alphabet, + possible repetition codes 16, 17, 18)
1334  - HDIST + 1 code lengths of distance alphabet (encoded using the code length alphabet, + possible repetition codes 16, 17, 18)
1335  - compressed data
1336  - 256 (end code)
1337  */
1338 
1339  unsigned error = 0;
1340 
1341  uivector lz77_encoded;
1342  HuffmanTree codes; /*tree for literal values and length codes*/
1343  HuffmanTree codesD; /*tree for distance codes*/
1344  HuffmanTree codelengthcodes;
1345  uivector frequencies;
1346  uivector frequenciesD;
1347  uivector amounts; /*the amounts in the "normal" order*/
1348  uivector lldl;
1349  uivector lldll; /*lit/len & dist code lenghts*/
1350  uivector clcls;
1351 
1352  unsigned BFINAL = 1; /*make only one block... the first and final one*/
1353  size_t numcodes, numcodesD, i, bp = 0; /*the bit pointer*/
1354  unsigned HLIT, HDIST, HCLEN;
1355 
1356  uivector_init(&lz77_encoded);
1357  HuffmanTree_init(&codes);
1358  HuffmanTree_init(&codesD);
1359  HuffmanTree_init(&codelengthcodes);
1360  uivector_init(&frequencies);
1361  uivector_init(&frequenciesD);
1362  uivector_init(&amounts);
1363  uivector_init(&lldl);
1364  uivector_init(&lldll);
1365  uivector_init(&clcls);
1366 
1367  while(!error) /*the goto-avoiding while construct: break out to go to the cleanup phase, a break at the end makes sure the while is never repeated*/
1368  {
1369  if(settings->useLZ77)
1370  {
1371  error = encodeLZ77(&lz77_encoded, data, datasize, settings->windowSize); /*LZ77 encoded*/
1372  if(error) break;
1373  }
1374  else
1375  {
1376  if(!uivector_resize(&lz77_encoded, datasize)) { error = 9923; break; }
1377  for(i = 0; i < datasize; i++) lz77_encoded.data[i] = data[i]; /*no LZ77, but still will be Huffman compressed*/
1378  }
1379 
1380  if(!uivector_resizev(&frequencies, 286, 0)) { error = 9924; break; }
1381  if(!uivector_resizev(&frequenciesD, 30, 0)) { error = 9925; break; }
1382  for(i = 0; i < lz77_encoded.size; i++)
1383  {
1384  unsigned symbol = lz77_encoded.data[i];
1385  frequencies.data[symbol]++;
1386  if(symbol > 256)
1387  {
1388  unsigned dist = lz77_encoded.data[i + 2];
1389  frequenciesD.data[dist]++;
1390  i += 3;
1391  }
1392  }
1393  frequencies.data[256] = 1; /*there will be exactly 1 end code, at the end of the block*/
1394 
1395  error = HuffmanTree_makeFromFrequencies(&codes, frequencies.data, frequencies.size, 15);
1396  if(error) break;
1397  error = HuffmanTree_makeFromFrequencies(&codesD, frequenciesD.data, frequenciesD.size, 15);
1398  if(error) break;
1399 
1400  addBitToStream(&bp, out, BFINAL);
1401  addBitToStream(&bp, out, 0); /*first bit of BTYPE "dynamic"*/
1402  addBitToStream(&bp, out, 1); /*second bit of BTYPE "dynamic"*/
1403 
1404  numcodes = codes.numcodes; if(numcodes > 286) numcodes = 286;
1405  numcodesD = codesD.numcodes; if(numcodesD > 30) numcodesD = 30;
1406  for(i = 0; i < numcodes; i++) uivector_push_back(&lldll, HuffmanTree_getLength(&codes, (unsigned)i));
1407  for(i = 0; i < numcodesD; i++) uivector_push_back(&lldll, HuffmanTree_getLength(&codesD, (unsigned)i));
1408 
1409  /*make lldl smaller by using repeat codes 16 (copy length 3-6 times), 17 (3-10 zeros), 18 (11-138 zeros)*/
1410  for(i = 0; i < (unsigned)lldll.size; i++)
1411  {
1412  unsigned j = 0;
1413  while(i + j + 1 < (unsigned)lldll.size && lldll.data[i + j + 1] == lldll.data[i]) j++;
1414 
1415  if(lldll.data[i] == 0 && j >= 2)
1416  {
1417  j++; /*include the first zero*/
1418  if(j <= 10) { uivector_push_back(&lldl, 17); uivector_push_back(&lldl, j - 3); }
1419  else
1420  {
1421  if(j > 138) j = 138;
1422  uivector_push_back(&lldl, 18); uivector_push_back(&lldl, j - 11);
1423  }
1424  i += (j - 1);
1425  }
1426  else if(j >= 3)
1427  {
1428  size_t k;
1429  unsigned num = j / 6, rest = j % 6;
1430  uivector_push_back(&lldl, lldll.data[i]);
1431  for(k = 0; k < num; k++) { uivector_push_back(&lldl, 16); uivector_push_back(&lldl, 6 - 3); }
1432  if(rest >= 3) { uivector_push_back(&lldl, 16); uivector_push_back(&lldl, rest - 3); }
1433  else j -= rest;
1434  i += j;
1435  }
1436  else uivector_push_back(&lldl, lldll.data[i]);
1437  }
1438 
1439  /*generate huffmantree for the length codes of lit/len and dist codes*/
1440  if(!uivector_resizev(&amounts, 19, 0)) { error = 9926; break; } /*16 possible lengths (0-15) and 3 repeat codes (16, 17 and 18)*/
1441  for(i = 0; i < lldl.size; i++)
1442  {
1443  amounts.data[lldl.data[i]]++;
1444  if(lldl.data[i] >= 16) i++; /*after a repeat code come the bits that specify the amount, those don't need to be in the amounts calculation*/
1445  }
1446 
1447  error = HuffmanTree_makeFromFrequencies(&codelengthcodes, amounts.data, amounts.size, 7);
1448  if(error) break;
1449 
1450  if(!uivector_resize(&clcls, 19)) { error = 9927; break; }
1451  for(i = 0; i < 19; i++) clcls.data[i] = HuffmanTree_getLength(&codelengthcodes, CLCL[i]); /*lenghts of code length tree is in the order as specified by deflate*/
1452  while(clcls.data[clcls.size - 1] == 0 && clcls.size > 4)
1453  {
1454  if(!uivector_resize(&clcls, clcls.size - 1)) { error = 9928; break; } /*remove zeros at the end, but minimum size must be 4*/
1455  }
1456  if(error) break;
1457 
1458  /*write the HLIT, HDIST and HCLEN values*/
1459  HLIT = (unsigned)(numcodes - 257);
1460  HDIST = (unsigned)(numcodesD - 1);
1461  HCLEN = (unsigned)clcls.size - 4;
1462  addBitsToStream(&bp, out, HLIT, 5);
1463  addBitsToStream(&bp, out, HDIST, 5);
1464  addBitsToStream(&bp, out, HCLEN, 4);
1465 
1466  /*write the code lenghts of the code length alphabet*/
1467  for(i = 0; i < HCLEN + 4; i++) addBitsToStream(&bp, out, clcls.data[i], 3);
1468 
1469  /*write the lenghts of the lit/len AND the dist alphabet*/
1470  for(i = 0; i < lldl.size; i++)
1471  {
1472  addHuffmanSymbol(&bp, out, HuffmanTree_getCode(&codelengthcodes, lldl.data[i]), HuffmanTree_getLength(&codelengthcodes, lldl.data[i]));
1473  /*extra bits of repeat codes*/
1474  if(lldl.data[i] == 16) addBitsToStream(&bp, out, lldl.data[++i], 2);
1475  else if(lldl.data[i] == 17) addBitsToStream(&bp, out, lldl.data[++i], 3);
1476  else if(lldl.data[i] == 18) addBitsToStream(&bp, out, lldl.data[++i], 7);
1477  }
1478 
1479  /*write the compressed data symbols*/
1480  writeLZ77data(&bp, out, &lz77_encoded, &codes, &codesD);
1481  if(HuffmanTree_getLength(&codes, 256) == 0) { error = 64; break; } /*the length of the end code 256 must be larger than 0*/
1482  addHuffmanSymbol(&bp, out, HuffmanTree_getCode(&codes, 256), HuffmanTree_getLength(&codes, 256)); /*end code*/
1483 
1484  break; /*end of error-while*/
1485  }
1486 
1487  /*cleanup*/
1488  uivector_cleanup(&lz77_encoded);
1489  HuffmanTree_cleanup(&codes);
1490  HuffmanTree_cleanup(&codesD);
1491  HuffmanTree_cleanup(&codelengthcodes);
1492  uivector_cleanup(&frequencies);
1493  uivector_cleanup(&frequenciesD);
1494  uivector_cleanup(&amounts);
1495  uivector_cleanup(&lldl);
1496  uivector_cleanup(&lldll);
1497  uivector_cleanup(&clcls);
1498 
1499  return error;
1500 }
static unsigned HuffmanTree_makeFromFrequencies(HuffmanTree *tree, const unsigned *frequencies, size_t numcodes, unsigned maxbitlen)
Definition: lodepng.cpp:555
static void addBitsToStream(size_t *bitpointer, ucvector *bitstream, unsigned value, size_t nbits)
Definition: lodepng.cpp:314
static unsigned HuffmanTree_getLength(const HuffmanTree *tree, unsigned index)
Definition: lodepng.cpp:642
unsigned numcodes
Definition: lodepng.cpp:428
static unsigned uivector_resize(uivector *p, size_t size)
Definition: lodepng.cpp:138
unsigned * data
Definition: lodepng.cpp:126
error
Definition: include.cc:26
static void writeLZ77data(size_t *bp, ucvector *out, const uivector *lz77_encoded, const HuffmanTree *codes, const HuffmanTree *codesD)
Definition: lodepng.cpp:1301
size_t size
Definition: lodepng.cpp:127
static void uivector_cleanup(void *p)
Definition: lodepng.cpp:131
static void HuffmanTree_init(HuffmanTree *tree)
Definition: lodepng.cpp:444
static void addBitToStream(size_t *bitpointer, ucvector *bitstream, unsigned char bit)
Definition: lodepng.cpp:307
static unsigned uivector_push_back(uivector *p, unsigned c)
Definition: lodepng.cpp:171
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
static void uivector_init(uivector *p)
Definition: lodepng.cpp:164
#define encodeLZ77
Definition: lodepng.cpp:1039
static unsigned HuffmanTree_getCode(const HuffmanTree *tree, unsigned index)
Definition: lodepng.cpp:641
static void addHuffmanSymbol(size_t *bp, ucvector *compressed, unsigned code, unsigned bitlen)
Definition: lodepng.cpp:994
static void HuffmanTree_cleanup(HuffmanTree *tree)
Definition: lodepng.cpp:451
static unsigned uivector_resizev(uivector *p, size_t size, unsigned value)
Definition: lodepng.cpp:156
static const unsigned CLCL[NUM_CODE_LENGTH_CODES]
Definition: lodepng.cpp:362
static unsigned deflateFixed ( ucvector out,
const unsigned char *  data,
size_t  datasize,
const LodeZlib_DeflateSettings settings 
)
static

Definition at line 1502 of file lodepng.cpp.

1503 {
1504  HuffmanTree codes; /*tree for literal values and length codes*/
1505  HuffmanTree codesD; /*tree for distance codes*/
1506 
1507  unsigned BFINAL = 1; /*make only one block... the first and final one*/
1508  unsigned error = 0;
1509  size_t i, bp = 0; /*the bit pointer*/
1510 
1511  HuffmanTree_init(&codes);
1512  HuffmanTree_init(&codesD);
1513 
1514  generateFixedTree(&codes);
1515  generateDistanceTree(&codesD);
1516 
1517  addBitToStream(&bp, out, BFINAL);
1518  addBitToStream(&bp, out, 1); /*first bit of BTYPE*/
1519  addBitToStream(&bp, out, 0); /*second bit of BTYPE*/
1520 
1521  if(settings->useLZ77) /*LZ77 encoded*/
1522  {
1523  uivector lz77_encoded;
1524  uivector_init(&lz77_encoded);
1525  error = encodeLZ77(&lz77_encoded, data, datasize, settings->windowSize);
1526  if(!error) writeLZ77data(&bp, out, &lz77_encoded, &codes, &codesD);
1527  uivector_cleanup(&lz77_encoded);
1528  }
1529  else /*no LZ77, but still will be Huffman compressed*/
1530  {
1531  for(i = 0; i < datasize; i++) addHuffmanSymbol(&bp, out, HuffmanTree_getCode(&codes, data[i]), HuffmanTree_getLength(&codes, data[i]));
1532  }
1533  if(!error) addHuffmanSymbol(&bp, out, HuffmanTree_getCode(&codes, 256), HuffmanTree_getLength(&codes, 256)); /*"end" code*/
1534 
1535  /*cleanup*/
1536  HuffmanTree_cleanup(&codes);
1537  HuffmanTree_cleanup(&codesD);
1538 
1539  return error;
1540 }
static unsigned HuffmanTree_getLength(const HuffmanTree *tree, unsigned index)
Definition: lodepng.cpp:642
error
Definition: include.cc:26
static void writeLZ77data(size_t *bp, ucvector *out, const uivector *lz77_encoded, const HuffmanTree *codes, const HuffmanTree *codesD)
Definition: lodepng.cpp:1301
static unsigned generateDistanceTree(HuffmanTree *tree)
Definition: lodepng.cpp:668
static void uivector_cleanup(void *p)
Definition: lodepng.cpp:131
static void HuffmanTree_init(HuffmanTree *tree)
Definition: lodepng.cpp:444
static void addBitToStream(size_t *bitpointer, ucvector *bitstream, unsigned char bit)
Definition: lodepng.cpp:307
static unsigned generateFixedTree(HuffmanTree *tree)
Definition: lodepng.cpp:646
static void uivector_init(uivector *p)
Definition: lodepng.cpp:164
#define encodeLZ77
Definition: lodepng.cpp:1039
static unsigned HuffmanTree_getCode(const HuffmanTree *tree, unsigned index)
Definition: lodepng.cpp:641
static void addHuffmanSymbol(size_t *bp, ucvector *compressed, unsigned code, unsigned bitlen)
Definition: lodepng.cpp:994
static void HuffmanTree_cleanup(HuffmanTree *tree)
Definition: lodepng.cpp:451
static unsigned deflateNoCompression ( ucvector out,
const unsigned char *  data,
size_t  datasize 
)
static

Definition at line 1264 of file lodepng.cpp.

1265 {
1266  /*non compressed deflate block data: 1 bit BFINAL,2 bits BTYPE,(5 bits): it jumps to start of next byte, 2 bytes LEN, 2 bytes NLEN, LEN bytes literal DATA*/
1267 
1268  size_t i, j, numdeflateblocks = datasize / 65536 + 1;
1269  unsigned datapos = 0;
1270  for(i = 0; i < numdeflateblocks; i++)
1271  {
1272  unsigned BFINAL, BTYPE, LEN, NLEN;
1273  unsigned char firstbyte;
1274 
1275  BFINAL = (i == numdeflateblocks - 1);
1276  BTYPE = 0;
1277 
1278  firstbyte = (unsigned char)(BFINAL + ((BTYPE & 1) << 1) + ((BTYPE & 2) << 1));
1279  ucvector_push_back(out, firstbyte);
1280 
1281  LEN = 65535;
1282  if(datasize - datapos < 65535) LEN = (unsigned)datasize - datapos;
1283  NLEN = 65535 - LEN;
1284 
1285  ucvector_push_back(out, (unsigned char)(LEN % 256));
1286  ucvector_push_back(out, (unsigned char)(LEN / 256));
1287  ucvector_push_back(out, (unsigned char)(NLEN % 256));
1288  ucvector_push_back(out, (unsigned char)(NLEN / 256));
1289 
1290  /*Decompressed data*/
1291  for(j = 0; j < 65535 && datapos < datasize; j++)
1292  {
1293  ucvector_push_back(out, data[datapos++]);
1294  }
1295  }
1296 
1297  return 0;
1298 }
static unsigned ucvector_push_back(ucvector *p, unsigned char c)
Definition: lodepng.cpp:258
#define LEN(x)
static unsigned encodeLZ77_brute ( uivector out,
const unsigned char *  in,
size_t  size,
unsigned  windowSize 
)
static

search for the longest string

encode it as length/distance pair or literal value

Definition at line 1041 of file lodepng.cpp.

1042 {
1043  size_t pos;
1044  /*using pointer instead of vector for input makes it faster when NOT using optimization when compiling; no influence if optimization is used*/
1045  for(pos = 0; pos < size; pos++)
1046  {
1047  /*Phase 1: doxygen images often have long runs of the same color, try to find them*/
1048  const int minLength = 4; // Minimum length for a run to make sense
1049 
1050  if(pos < size - minLength * 4)
1051  {
1052  size_t p, fp;
1053  size_t current_length;
1054 
1055  /*RGBA pixel run?*/
1056  p = pos;
1057  fp = pos + 4;
1058  current_length = 0;
1059 
1060  while(fp < size && in[p] == in[fp] && current_length < MAX_SUPPORTED_DEFLATE_LENGTH)
1061  {
1062  ++p;
1063  ++fp;
1064  ++current_length;
1065  }
1066 
1067  if (current_length > (minLength - 1 ) * 4) /*worth using?*/
1068  {
1069  uivector_push_back(out, in[pos ]);
1070  uivector_push_back(out, in[pos + 1]);
1071  uivector_push_back(out, in[pos + 2]);
1072  uivector_push_back(out, in[pos + 3]);
1073  addLengthDistance(out, current_length, 4);
1074 
1075  pos += current_length + 4 - 1; /*-1 for loop's pos++*/
1076  continue;
1077  }
1078 
1079  /*RGB pixel run?*/
1080  p = pos;
1081  fp = pos + 3;
1082  current_length = 0;
1083 
1084  while(fp < size && in[p] == in[fp] && current_length < MAX_SUPPORTED_DEFLATE_LENGTH)
1085  {
1086  ++p;
1087  ++fp;
1088  ++current_length;
1089  }
1090 
1091  if (current_length > (minLength - 1 ) * 3) /*worth using?*/
1092  {
1093  uivector_push_back(out, in[pos ]);
1094  uivector_push_back(out, in[pos + 1]);
1095  uivector_push_back(out, in[pos + 2]);
1096  addLengthDistance(out, current_length, 3);
1097 
1098  pos += current_length + 3 - 1; /*-1 for loop's pos++*/
1099  continue;
1100  }
1101  }
1102 
1103  size_t length = 0, offset = 0; /*the length and offset found for the current position*/
1104  size_t max_offset = pos < windowSize ? pos : windowSize; /*how far back to test*/
1105  size_t current_offset;
1106 
1107  /**search for the longest string**/
1108  for(current_offset = 1; current_offset < max_offset; current_offset++) /*search backwards through all possible distances (=offsets)*/
1109  {
1110  size_t backpos = pos - current_offset;
1111  if(in[backpos] == in[pos])
1112  {
1113  /*test the next characters*/
1114  size_t current_length = 1;
1115  size_t backtest = backpos + 1;
1116  size_t foretest = pos + 1;
1117  while(foretest < size && in[backtest] == in[foretest] && current_length < MAX_SUPPORTED_DEFLATE_LENGTH) /*maximum supporte length by deflate is max length*/
1118  {
1119  if(backpos >= pos) backpos -= current_offset; /*continue as if we work on the decoded bytes after pos by jumping back before pos*/
1120  current_length++;
1121  backtest++;
1122  foretest++;
1123  }
1124  if(current_length > length)
1125  {
1126  length = current_length; /*the longest length*/
1127  offset = current_offset; /*the offset that is related to this longest length*/
1128  if(current_length == MAX_SUPPORTED_DEFLATE_LENGTH) break; /*you can jump out of this for loop once a length of max length is found (gives significant speed gain)*/
1129  }
1130  }
1131  }
1132 
1133  /**encode it as length/distance pair or literal value**/
1134  if(length < 3) /*only lengths of 3 or higher are supported as length/distance pair*/
1135  {
1136  uivector_push_back(out, in[pos]);
1137  }
1138  else
1139  {
1140  addLengthDistance(out, length, offset);
1141  pos += (length - 1);
1142  }
1143  } /*end of the loop through each character of input*/
1144 
1145  return 0;
1146 }
UWORD32 in[16]
Definition: md5.h:44
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
static void addLengthDistance(uivector *values, size_t length, size_t distance)
Definition: lodepng.cpp:1019
p
Definition: test.py:223
static unsigned uivector_push_back(uivector *p, unsigned c)
Definition: lodepng.cpp:171
static const size_t MAX_SUPPORTED_DEFLATE_LENGTH
Definition: lodepng.cpp:991
static unsigned filter ( unsigned char *  out,
const unsigned char *  in,
unsigned  w,
unsigned  h,
const LodePNG_InfoColor info 
)
static

Definition at line 3576 of file lodepng.cpp.

3577 {
3578  /*
3579  For PNG filter method 0
3580  out must be a buffer with as size: h + (w * h * bpp + 7) / 8, because there are the scanlines with 1 extra byte per scanline
3581 
3582  There is a nice heuristic described here: http://www.cs.toronto.edu/~cosmin/pngtech/optipng.html. It says:
3583  * If the image type is Palette, or the bit depth is smaller than 8, then do not filter the image (i.e. use fixed filtering, with the filter None).
3584  * (The other case) If the image type is Grayscale or RGB (with or without Alpha), and the bit depth is not smaller than 8, then use adaptive filtering heuristic as follows: independently for each row, apply all five filters and select the filter that produces the smallest sum of absolute values per row.
3585 
3586  Here the above method is used mostly. Note though that it appears to be better to use the adaptive filtering on the plasma 8-bit palette example, but that image isn't the best reference for palette images in general.
3587  */
3588 
3589  unsigned bpp = LodePNG_InfoColor_getBpp(info);
3590  size_t linebytes = (w * bpp + 7) / 8; /*the width of a scanline in bytes, not including the filter type*/
3591  size_t bytewidth = (bpp + 7) / 8; /*bytewidth is used for filtering, is 1 when bpp < 8, number of bytes per pixel otherwise*/
3592  const unsigned char* prevline = 0;
3593  unsigned x, y;
3594  unsigned heuristic;
3595  unsigned error = 0;
3596 
3597  if(bpp == 0) return 31; /*invalid color type*/
3598 
3599  /*choose heuristic as described above*/
3600  if(info->colorType == 3 || info->bitDepth < 8) heuristic = 0;
3601  else heuristic = 1;
3602 
3603  if(heuristic == 0) /*None filtertype for everything*/
3604  {
3605  for(y = 0; y < h; y++)
3606  {
3607  size_t outindex = (1 + linebytes) * y; /*the extra filterbyte added to each row*/
3608  size_t inindex = linebytes * y;
3609  const unsigned TYPE = 0;
3610  out[outindex] = TYPE; /*filter type byte*/
3611  filterScanline(&out[outindex + 1], &in[inindex], prevline, linebytes, bytewidth, TYPE);
3612  prevline = &in[inindex];
3613  }
3614  }
3615  else if(heuristic == 1) /*adaptive filtering*/
3616  {
3617  size_t sum[5];
3618  ucvector attempt[5]; /*five filtering attempts, one for each filter type*/
3619  size_t smallest = 0;
3620  unsigned type, bestType = 0;
3621 
3622  for(type = 0; type < 5; type++) ucvector_init(&attempt[type]);
3623  for(type = 0; type < 5; type++)
3624  {
3625  if(!ucvector_resize(&attempt[type], linebytes)) { error = 9949; break; }
3626  }
3627 
3628  if(!error)
3629  {
3630  for(y = 0; y < h; y++)
3631  {
3632  /*try the 5 filter types*/
3633  for(type = 0; type < 5; type++)
3634  {
3635  filterScanline(attempt[type].data, &in[y * linebytes], prevline, linebytes, bytewidth, type);
3636 
3637  /*calculate the sum of the result*/
3638  sum[type] = 0;
3639  for(x = 0; x < attempt[type].size; x+=3) sum[type] += attempt[type].data[x]; /*note that not all pixels are checked to speed this up while still having probably the best choice*/
3640 
3641  /*check if this is smallest sum (or if type == 0 it's the first case so always store the values)*/
3642  if(type == 0 || sum[type] < smallest)
3643  {
3644  bestType = type;
3645  smallest = sum[type];
3646  }
3647  }
3648 
3649  prevline = &in[y * linebytes];
3650 
3651  /*now fill the out values*/
3652  out[y * (linebytes + 1)] = bestType; /*the first byte of a scanline will be the filter type*/
3653  for(x = 0; x < linebytes; x++) out[y * (linebytes + 1) + 1 + x] = attempt[bestType].data[x];
3654  }
3655  }
3656 
3657  for(type = 0; type < 5; type++) ucvector_cleanup(&attempt[type]);
3658  }
3659  #if 0 /*deflate the scanline with a fixed tree after every filter attempt to see which one deflates best. This is slow, and _does not work as expected_: the heuristic gives smaller result!*/
3660  else if(heuristic == 2) /*adaptive filtering by using deflate*/
3661  {
3662  size_t size[5];
3663  ucvector attempt[5]; /*five filtering attempts, one for each filter type*/
3664  size_t smallest;
3665  unsigned type = 0, bestType = 0;
3666  unsigned char* dummy;
3668  deflatesettings.btype = 1; /*use fixed tree on the attempts so that the tree is not adapted to the filtertype on purpose, to simulate the true case where the tree is the same for the whole image*/
3669  for(type = 0; type < 5; type++) { ucvector_init(&attempt[type]); ucvector_resize(&attempt[type], linebytes); }
3670  for(y = 0; y < h; y++) /*try the 5 filter types*/
3671  {
3672  for(type = 0; type < 5; type++)
3673  {
3674  filterScanline(attempt[type].data, &in[y * linebytes], prevline, linebytes, bytewidth, type);
3675  size[type] = 0; dummy = 0;
3676  LodePNG_compress(&dummy, &size[type], attempt[type].data, attempt[type].size, &deflatesettings);
3677  free(dummy);
3678  /*check if this is smallest size (or if type == 0 it's the first case so always store the values)*/
3679  if(type == 0 || size[type] < smallest) { bestType = type; smallest = size[type]; }
3680  }
3681  prevline = &in[y * linebytes];
3682  out[y * (linebytes + 1)] = bestType; /*the first byte of a scanline will be the filter type*/
3683  for(x = 0; x < linebytes; x++) out[y * (linebytes + 1) + 1 + x] = attempt[bestType].data[x];
3684  }
3685  for(type = 0; type < 5; type++) ucvector_cleanup(&attempt[type]);
3686  }
3687  #endif
3688 
3689  return error;
3690 }
unsigned LodePNG_InfoColor_getBpp(const LodePNG_InfoColor *info)
Definition: lodepng.cpp:2066
unsigned colorType
Definition: lodepng.h:127
const LodeZlib_DeflateSettings LodeZlib_defaultDeflateSettings
Definition: lodepng.cpp:1704
unsigned bitDepth
Definition: lodepng.h:128
error
Definition: include.cc:26
UWORD32 in[16]
Definition: md5.h:44
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
unsigned char * data
Definition: lodepng.cpp:201
static unsigned LodePNG_compress(unsigned char **out, size_t *outsize, const unsigned char *in, size_t insize, const LodeZlib_DeflateSettings *settings)
Definition: lodepng.cpp:1752
static void ucvector_cleanup(void *p)
Definition: lodepng.cpp:206
static void ucvector_init(ucvector *p)
Definition: lodepng.cpp:243
size_t size
Definition: lodepng.cpp:202
static QCString type
Definition: declinfo.cpp:672
static unsigned ucvector_resize(ucvector *p, size_t size)
Definition: lodepng.cpp:213
cet::LibraryManager dummy("noplugin")
list x
Definition: train.py:276
static void filterScanline(unsigned char *out, const unsigned char *scanline, const unsigned char *prevline, size_t length, size_t bytewidth, unsigned char filterType)
Definition: lodepng.cpp:3532
static void filterScanline ( unsigned char *  out,
const unsigned char *  scanline,
const unsigned char *  prevline,
size_t  length,
size_t  bytewidth,
unsigned char  filterType 
)
static

Definition at line 3532 of file lodepng.cpp.

3533 {
3534  size_t i;
3535  switch(filterType)
3536  {
3537  case 0:
3538  for(i = 0; i < length; i++) out[i] = scanline[i];
3539  break;
3540  case 1:
3541  for(i = 0; i < bytewidth; i++) out[i] = scanline[i];
3542  for(i = bytewidth; i < length; i++) out[i] = scanline[i] - scanline[i - bytewidth];
3543  break;
3544  case 2:
3545  if(prevline) for(i = 0; i < length; i++) out[i] = scanline[i] - prevline[i];
3546  else for(i = 0; i < length; i++) out[i] = scanline[i];
3547  break;
3548  case 3:
3549  if(prevline)
3550  {
3551  for(i = 0; i < bytewidth; i++) out[i] = scanline[i] - prevline[i] / 2;
3552  for(i = bytewidth; i < length; i++) out[i] = scanline[i] - ((scanline[i - bytewidth] + prevline[i]) / 2);
3553  }
3554  else
3555  {
3556  for(i = 0; i < length; i++) out[i] = scanline[i];
3557  for(i = bytewidth; i < length; i++) out[i] = scanline[i] - scanline[i - bytewidth] / 2;
3558  }
3559  break;
3560  case 4:
3561  if(prevline)
3562  {
3563  for(i = 0; i < bytewidth; i++) out[i] = (unsigned char)(scanline[i] - paethPredictor(0, prevline[i], 0));
3564  for(i = bytewidth; i < length; i++) out[i] = (unsigned char)(scanline[i] - paethPredictor(scanline[i - bytewidth], prevline[i], prevline[i - bytewidth]));
3565  }
3566  else
3567  {
3568  for(i = 0; i < bytewidth; i++) out[i] = scanline[i];
3569  for(i = bytewidth; i < length; i++) out[i] = (unsigned char)(scanline[i] - paethPredictor(scanline[i - bytewidth], 0, 0));
3570  }
3571  break;
3572  default: return; /*unexisting filter type given*/
3573  }
3574 }
static int paethPredictor(int a, int b, int c)
Definition: lodepng.cpp:2551
static unsigned generateDistanceTree ( HuffmanTree tree)
static

Definition at line 668 of file lodepng.cpp.

669 {
670  unsigned i, error = 0;
671  uivector bitlen;
672  uivector_init(&bitlen);
673  if(!uivector_resize(&bitlen, NUM_DISTANCE_SYMBOLS)) error = 9910;
674 
675  /*there are 32 distance codes, but 30-31 are unused*/
676  if(!error)
677  {
678  for(i = 0; i < NUM_DISTANCE_SYMBOLS; i++) bitlen.data[i] = 5;
679  error = HuffmanTree_makeFromLengths(tree, bitlen.data, NUM_DISTANCE_SYMBOLS, 15);
680  }
681  uivector_cleanup(&bitlen);
682  return error;
683 }
static unsigned uivector_resize(uivector *p, size_t size)
Definition: lodepng.cpp:138
unsigned * data
Definition: lodepng.cpp:126
error
Definition: include.cc:26
static void uivector_cleanup(void *p)
Definition: lodepng.cpp:131
#define NUM_DISTANCE_SYMBOLS
Definition: lodepng.cpp:350
static void uivector_init(uivector *p)
Definition: lodepng.cpp:164
static unsigned HuffmanTree_makeFromLengths(HuffmanTree *tree, const unsigned *bitlen, size_t numcodes, unsigned maxbitlen)
Definition: lodepng.cpp:527
static unsigned generateFixedTree ( HuffmanTree tree)
static

Definition at line 646 of file lodepng.cpp.

647 {
648  unsigned i, error = 0;
649  uivector bitlen;
650  uivector_init(&bitlen);
651  if(!uivector_resize(&bitlen, NUM_DEFLATE_CODE_SYMBOLS)) error = 9909;
652 
653  if(!error)
654  {
655  /*288 possible codes: 0-255=literals, 256=endcode, 257-285=lengthcodes, 286-287=unused*/
656  for(i = 0; i <= 143; i++) bitlen.data[i] = 8;
657  for(i = 144; i <= 255; i++) bitlen.data[i] = 9;
658  for(i = 256; i <= 279; i++) bitlen.data[i] = 7;
659  for(i = 280; i <= 287; i++) bitlen.data[i] = 8;
660 
661  error = HuffmanTree_makeFromLengths(tree, bitlen.data, NUM_DEFLATE_CODE_SYMBOLS, 15);
662  }
663 
664  uivector_cleanup(&bitlen);
665  return error;
666 }
static unsigned uivector_resize(uivector *p, size_t size)
Definition: lodepng.cpp:138
#define NUM_DEFLATE_CODE_SYMBOLS
Definition: lodepng.cpp:349
unsigned * data
Definition: lodepng.cpp:126
error
Definition: include.cc:26
static void uivector_cleanup(void *p)
Definition: lodepng.cpp:131
static void uivector_init(uivector *p)
Definition: lodepng.cpp:164
static unsigned HuffmanTree_makeFromLengths(HuffmanTree *tree, const unsigned *bitlen, size_t numcodes, unsigned maxbitlen)
Definition: lodepng.cpp:527
static unsigned getBpp ( unsigned  colorType,
unsigned  bitDepth 
)
static

Definition at line 2018 of file lodepng.cpp.

2019 {
2020  return getNumColorChannels(colorType) * bitDepth; /*bits per pixel is amount of channels * bits per channel*/
2021 }
static unsigned getNumColorChannels(unsigned colorType)
Definition: lodepng.cpp:2005
static unsigned getNumColorChannels ( unsigned  colorType)
static

Definition at line 2005 of file lodepng.cpp.

2006 {
2007  switch(colorType)
2008  {
2009  case 0: return 1; /*grey*/
2010  case 2: return 3; /*RGB*/
2011  case 3: return 1; /*palette*/
2012  case 4: return 2; /*grey + alpha*/
2013  case 6: return 4; /*RGBA*/
2014  }
2015  return 0; /*unexisting color type*/
2016 }
static void HuffmanTree_cleanup ( HuffmanTree tree)
static

Definition at line 451 of file lodepng.cpp.

452 {
453  uivector_cleanup(&tree->tree2d);
454  uivector_cleanup(&tree->tree1d);
455  uivector_cleanup(&tree->lengths);
456 }
uivector tree2d
Definition: lodepng.cpp:424
static void uivector_cleanup(void *p)
Definition: lodepng.cpp:131
uivector tree1d
Definition: lodepng.cpp:425
uivector lengths
Definition: lodepng.cpp:426
static unsigned HuffmanTree_fillInCoins ( vector coins,
const unsigned *  frequencies,
unsigned  numcodes,
size_t  sum 
)
static

Definition at line 538 of file lodepng.cpp.

539 {
540  unsigned i;
541  for(i = 0; i < numcodes; i++)
542  {
543  Coin* coin;
544  if(frequencies[i] == 0) continue; /*it's important to exclude symbols that aren't present*/
545  if(!vector_resize(coins, coins->size + 1)) { vector_cleanup(coins); return 9904; }
546  coin = (Coin*)(vector_get(coins, coins->size - 1));
547  Coin_init(coin);
548  coin->weight = frequencies[i] / (float)sum;
549  uivector_push_back(&coin->symbols, i);
550  }
551  if(coins->size) Coin_sort((Coin*)coins->data, coins->size);
552  return 0;
553 }
static unsigned vector_resize(vector *p, size_t size)
Definition: lodepng.cpp:60
static void Coin_sort(Coin *data, size_t amount)
Definition: lodepng.cpp:397
void * data
Definition: lodepng.cpp:54
static void Coin_init(Coin *c)
Definition: lodepng.cpp:374
size_t size
Definition: lodepng.cpp:55
static void vector_cleanup(void *p)
Definition: lodepng.cpp:85
static unsigned uivector_push_back(uivector *p, unsigned c)
Definition: lodepng.cpp:171
static void * vector_get(vector *p, size_t index)
Definition: lodepng.cpp:114
float weight
Definition: lodepng.cpp:371
uivector symbols
Definition: lodepng.cpp:370
static unsigned HuffmanTree_getCode ( const HuffmanTree tree,
unsigned  index 
)
static

Definition at line 641 of file lodepng.cpp.

641 { return tree->tree1d.data[index]; }
unsigned * data
Definition: lodepng.cpp:126
uivector tree1d
Definition: lodepng.cpp:425
static unsigned HuffmanTree_getLength ( const HuffmanTree tree,
unsigned  index 
)
static

Definition at line 642 of file lodepng.cpp.

642 { return tree->lengths.data[index]; }
unsigned * data
Definition: lodepng.cpp:126
uivector lengths
Definition: lodepng.cpp:426
static void HuffmanTree_init ( HuffmanTree tree)
static

Definition at line 444 of file lodepng.cpp.

445 {
446  uivector_init(&tree->tree2d);
447  uivector_init(&tree->tree1d);
448  uivector_init(&tree->lengths);
449 }
uivector tree2d
Definition: lodepng.cpp:424
uivector tree1d
Definition: lodepng.cpp:425
uivector lengths
Definition: lodepng.cpp:426
static void uivector_init(uivector *p)
Definition: lodepng.cpp:164
static unsigned HuffmanTree_make2DTree ( HuffmanTree tree)
static

Definition at line 459 of file lodepng.cpp.

460 {
461  unsigned nodefilled = 0; /*up to which node it is filled*/
462  unsigned treepos = 0; /*position in the tree (1 of the numcodes columns)*/
463  unsigned n, i;
464 
465  if(!uivector_resize(&tree->tree2d, tree->numcodes * 2)) return 9901; /*if failed return not enough memory error*/
466  /*convert tree1d[] to tree2d[][]. In the 2D array, a value of 32767 means uninited, a value >= numcodes is an address to another bit, a value < numcodes is a code. The 2 rows are the 2 possible bit values (0 or 1), there are as many columns as codes - 1
467  a good huffmann tree has N * 2 - 1 nodes, of which N - 1 are internal nodes. Here, the internal nodes are stored (what their 0 and 1 option point to). There is only memory for such good tree currently, if there are more nodes (due to too long length codes), error 55 will happen*/
468  for(n = 0; n < tree->numcodes * 2; n++) tree->tree2d.data[n] = 32767; /*32767 here means the tree2d isn't filled there yet*/
469 
470  for(n = 0; n < tree->numcodes; n++) /*the codes*/
471  for(i = 0; i < tree->lengths.data[n]; i++) /*the bits for this code*/
472  {
473  unsigned char bit = (unsigned char)((tree->tree1d.data[n] >> (tree->lengths.data[n] - i - 1)) & 1);
474  if(treepos > tree->numcodes - 2) return 55; /*error 55: oversubscribed; see description in header*/
475  if(tree->tree2d.data[2 * treepos + bit] == 32767) /*not yet filled in*/
476  {
477  if(i + 1 == tree->lengths.data[n]) /*last bit*/
478  {
479  tree->tree2d.data[2 * treepos + bit] = n; /*put the current code in it*/
480  treepos = 0;
481  }
482  else /*put address of the next step in here, first that address has to be found of course (it's just nodefilled + 1)...*/
483  {
484  nodefilled++;
485  tree->tree2d.data[2 * treepos + bit] = nodefilled + tree->numcodes; /*addresses encoded with numcodes added to it*/
486  treepos = nodefilled;
487  }
488  }
489  else treepos = tree->tree2d.data[2 * treepos + bit] - tree->numcodes;
490  }
491  for(n = 0; n < tree->numcodes * 2; n++) if(tree->tree2d.data[n] == 32767) tree->tree2d.data[n] = 0; /*remove possible remaining 32767's*/
492 
493  return 0;
494 }
uivector tree2d
Definition: lodepng.cpp:424
unsigned numcodes
Definition: lodepng.cpp:428
static unsigned uivector_resize(uivector *p, size_t size)
Definition: lodepng.cpp:138
unsigned * data
Definition: lodepng.cpp:126
std::void_t< T > n
uivector tree1d
Definition: lodepng.cpp:425
uivector lengths
Definition: lodepng.cpp:426
static unsigned HuffmanTree_makeFromFrequencies ( HuffmanTree tree,
const unsigned *  frequencies,
size_t  numcodes,
unsigned  maxbitlen 
)
static

Definition at line 555 of file lodepng.cpp.

556 {
557  unsigned i, j;
558  size_t sum = 0, numpresent = 0;
559  unsigned error = 0;
560 
561  vector prev_row; /*type Coin, the previous row of coins*/
562  vector coins; /*type Coin, the coins of the currently calculated row*/
563 
564  tree->maxbitlen = maxbitlen;
565 
566  for(i = 0; i < numcodes; i++)
567  {
568  if(frequencies[i] > 0)
569  {
570  numpresent++;
571  sum += frequencies[i];
572  }
573  }
574 
575  if(numcodes == 0) return 80; /*error: a tree of 0 symbols is not supposed to be made*/
576  tree->numcodes = (unsigned)numcodes; /*number of symbols*/
577  uivector_resize(&tree->lengths, 0);
578  if(!uivector_resizev(&tree->lengths, tree->numcodes, 0)) return 9905;
579 
580  if(numpresent == 0) /*there are no symbols at all, in that case add one symbol of value 0 to the tree (see RFC 1951 section 3.2.7) */
581  {
582  tree->lengths.data[0] = 1;
583  return HuffmanTree_makeFromLengths2(tree);
584  }
585  else if(numpresent == 1) /*the package merge algorithm gives wrong results if there's only one symbol (theoretically 0 bits would then suffice, but we need a proper symbol for zlib)*/
586  {
587  for(i = 0; i < numcodes; i++) if(frequencies[i]) tree->lengths.data[i] = 1;
588  return HuffmanTree_makeFromLengths2(tree);
589  }
590 
591  vector_init(&coins, sizeof(Coin));
592  vector_init(&prev_row, sizeof(Coin));
593 
594  /*Package-Merge algorithm represented by coin collector's problem
595  For every symbol, maxbitlen coins will be created*/
596 
597  /*first row, lowest denominator*/
598  error = HuffmanTree_fillInCoins(&coins, frequencies, tree->numcodes, sum);
599  if(!error)
600  {
601  for(j = 1; j <= maxbitlen && !error; j++) /*each of the remaining rows*/
602  {
603  vector_swap(&coins, &prev_row); /*swap instead of copying*/
604  if(!vector_resized(&coins, 0, Coin_cleanup)) { error = 9906; break; }
605 
606  for(i = 0; i + 1 < prev_row.size; i += 2)
607  {
608  if(!vector_resize(&coins, coins.size + 1)) { error = 9907; break; }
609  Coin_init((Coin*)vector_get(&coins, coins.size - 1));
610  Coin_copy((Coin*)vector_get(&coins, coins.size - 1), (Coin*)vector_get(&prev_row, i));
611  addCoins((Coin*)vector_get(&coins, coins.size - 1), (Coin*)vector_get(&prev_row, i + 1)); /*merge the coins into packages*/
612  }
613  if(j < maxbitlen)
614  {
615  error = HuffmanTree_fillInCoins(&coins, frequencies, tree->numcodes, sum);
616  }
617  }
618  }
619 
620  if(!error)
621  {
622  /*keep the coins with lowest weight, so that they add up to the amount of symbols - 1*/
623  vector_resized(&coins, numpresent - 1, Coin_cleanup);
624 
625  /*calculate the lenghts of each symbol, as the amount of times a coin of each symbol is used*/
626  for(i = 0; i < coins.size; i++)
627  {
628  Coin* coin = (Coin*)vector_get(&coins, i);
629  for(j = 0; j < coin->symbols.size; j++) tree->lengths.data[coin->symbols.data[j]]++;
630  }
631 
632  error = HuffmanTree_makeFromLengths2(tree);
633  }
634 
635  vector_cleanupd(&coins, Coin_cleanup);
636  vector_cleanupd(&prev_row, Coin_cleanup);
637 
638  return error;
639 }
unsigned numcodes
Definition: lodepng.cpp:428
static unsigned vector_resize(vector *p, size_t size)
Definition: lodepng.cpp:60
static unsigned uivector_resize(uivector *p, size_t size)
Definition: lodepng.cpp:138
unsigned * data
Definition: lodepng.cpp:126
error
Definition: include.cc:26
static unsigned HuffmanTree_makeFromLengths2(HuffmanTree *tree)
Definition: lodepng.cpp:496
static void Coin_init(Coin *c)
Definition: lodepng.cpp:374
size_t size
Definition: lodepng.cpp:127
static void Coin_cleanup(void *c)
Definition: lodepng.cpp:379
size_t size
Definition: lodepng.cpp:55
uivector lengths
Definition: lodepng.cpp:426
static void vector_swap(vector *p, vector *q)
Definition: lodepng.cpp:105
static void * vector_get(vector *p, size_t index)
Definition: lodepng.cpp:114
static unsigned vector_resized(vector *p, size_t size, void dtor(void *))
Definition: lodepng.cpp:78
static void addCoins(Coin *c1, const Coin *c2)
Definition: lodepng.cpp:390
unsigned maxbitlen
Definition: lodepng.cpp:427
static void vector_cleanupd(vector *p, void dtor(void *))
Definition: lodepng.cpp:92
uivector symbols
Definition: lodepng.cpp:370
static unsigned uivector_resizev(uivector *p, size_t size, unsigned value)
Definition: lodepng.cpp:156
static unsigned HuffmanTree_fillInCoins(vector *coins, const unsigned *frequencies, unsigned numcodes, size_t sum)
Definition: lodepng.cpp:538
static void vector_init(vector *p, unsigned typesize)
Definition: lodepng.cpp:98
static void Coin_copy(Coin *c1, const Coin *c2)
Definition: lodepng.cpp:384
static unsigned HuffmanTree_makeFromLengths ( HuffmanTree tree,
const unsigned *  bitlen,
size_t  numcodes,
unsigned  maxbitlen 
)
static

Definition at line 527 of file lodepng.cpp.

528 {
529  unsigned i;
530  if(!uivector_resize(&tree->lengths, numcodes)) return 9903;
531  for(i = 0; i < numcodes; i++) tree->lengths.data[i] = bitlen[i];
532  tree->numcodes = (unsigned)numcodes; /*number of symbols*/
533  tree->maxbitlen = maxbitlen;
534  return HuffmanTree_makeFromLengths2(tree);
535 }
unsigned numcodes
Definition: lodepng.cpp:428
static unsigned uivector_resize(uivector *p, size_t size)
Definition: lodepng.cpp:138
unsigned * data
Definition: lodepng.cpp:126
static unsigned HuffmanTree_makeFromLengths2(HuffmanTree *tree)
Definition: lodepng.cpp:496
uivector lengths
Definition: lodepng.cpp:426
unsigned maxbitlen
Definition: lodepng.cpp:427
static unsigned HuffmanTree_makeFromLengths2 ( HuffmanTree tree)
static

Definition at line 496 of file lodepng.cpp.

497 {
498  uivector blcount;
499  uivector nextcode;
500  unsigned bits, n, error = 0;
501 
502  uivector_init(&blcount);
503  uivector_init(&nextcode);
504  if(!uivector_resize(&tree->tree1d, tree->numcodes)
505  || !uivector_resizev(&blcount, tree->maxbitlen + 1, 0)
506  || !uivector_resizev(&nextcode, tree->maxbitlen + 1, 0))
507  error = 9902;
508 
509  if(!error)
510  {
511  /*step 1: count number of instances of each code length*/
512  for(bits = 0; bits < tree->numcodes; bits++) blcount.data[tree->lengths.data[bits]]++;
513  /*step 2: generate the nextcode values*/
514  for(bits = 1; bits <= tree->maxbitlen; bits++) nextcode.data[bits] = (nextcode.data[bits - 1] + blcount.data[bits - 1]) << 1;
515  /*step 3: generate all the codes*/
516  for(n = 0; n < tree->numcodes; n++) if(tree->lengths.data[n] != 0) tree->tree1d.data[n] = nextcode.data[tree->lengths.data[n]]++;
517  }
518 
519  uivector_cleanup(&blcount);
520  uivector_cleanup(&nextcode);
521 
522  if(!error) return HuffmanTree_make2DTree(tree);
523  else return error;
524 }
unsigned numcodes
Definition: lodepng.cpp:428
static unsigned uivector_resize(uivector *p, size_t size)
Definition: lodepng.cpp:138
unsigned * data
Definition: lodepng.cpp:126
error
Definition: include.cc:26
static void uivector_cleanup(void *p)
Definition: lodepng.cpp:131
std::void_t< T > n
uivector tree1d
Definition: lodepng.cpp:425
uivector lengths
Definition: lodepng.cpp:426
static unsigned HuffmanTree_make2DTree(HuffmanTree *tree)
Definition: lodepng.cpp:459
static void uivector_init(uivector *p)
Definition: lodepng.cpp:164
unsigned maxbitlen
Definition: lodepng.cpp:427
static unsigned uivector_resizev(uivector *p, size_t size, unsigned value)
Definition: lodepng.cpp:156
static unsigned isFullyOpaque ( const unsigned char *  image,
unsigned  w,
unsigned  h,
const LodePNG_InfoColor info 
)
static

Definition at line 3857 of file lodepng.cpp.

3858 {
3859  /*TODO: When the user specified a color key for the input image, then this function must also check for pixels that are the same as the color key and treat those as transparent.*/
3860 
3861  unsigned i, numpixels = w * h;
3862  if(info->colorType == 6)
3863  {
3864  if(info->bitDepth == 8)
3865  {
3866  for(i = 0; i < numpixels; i++) if(image[i * 4 + 3] != 255) return 0;
3867  }
3868  else
3869  {
3870  for(i = 0; i < numpixels; i++) if(image[i * 8 + 6] != 255 || image[i * 8 + 7] != 255) return 0;
3871  }
3872  return 1; /*no single pixel with alpha channel other than 255 found*/
3873  }
3874  else if(info->colorType == 4)
3875  {
3876  if(info->bitDepth == 8)
3877  {
3878  for(i = 0; i < numpixels; i++) if(image[i * 2 + 1] != 255) return 0;
3879  }
3880  else
3881  {
3882  for(i = 0; i < numpixels; i++) if(image[i * 4 + 2] != 255 || image[i * 4 + 3] != 255) return 0;
3883  }
3884  return 1; /*no single pixel with alpha channel other than 255 found*/
3885  }
3886  else if(info->colorType == 3)
3887  {
3888  /*when there's a palette, we could check every pixel for translucency, but much quicker is to just check the palette*/
3889  return(isPaletteFullyOpaque(info->palette, info->palettesize));
3890  }
3891 
3892  return 0; /*color type that isn't supported by this function yet, so assume there is transparency to be safe*/
3893 }
size_t palettesize
Definition: lodepng.h:132
unsigned colorType
Definition: lodepng.h:127
unsigned bitDepth
Definition: lodepng.h:128
static unsigned isPaletteFullyOpaque(const unsigned char *palette, size_t palettesize)
Definition: lodepng.cpp:3846
unsigned char * palette
Definition: lodepng.h:131
static unsigned isPaletteFullyOpaque ( const unsigned char *  palette,
size_t  palettesize 
)
static

Definition at line 3846 of file lodepng.cpp.

3847 {
3848  size_t i;
3849  for(i = 0; i < palettesize; i++)
3850  {
3851  if(palette[4 * i + 3] != 255) return 0;
3852  }
3853  return 1;
3854 }
static Color palette[]
Definition: image.cpp:156
unsigned LodeFlate_deflate ( ucvector out,
const unsigned char *  data,
size_t  datasize,
const LodeZlib_DeflateSettings settings 
)

Definition at line 1542 of file lodepng.cpp.

1543 {
1544  unsigned error = 0;
1545  if(settings->btype == 0) error = deflateNoCompression(out, data, datasize);
1546  else if(settings->btype == 1) error = deflateFixed(out, data, datasize, settings);
1547  else if(settings->btype == 2) error = deflateDynamic(out, data, datasize, settings);
1548  else error = 61;
1549  return error;
1550 }
error
Definition: include.cc:26
static unsigned deflateNoCompression(ucvector *out, const unsigned char *data, size_t datasize)
Definition: lodepng.cpp:1264
static unsigned deflateDynamic(ucvector *out, const unsigned char *data, size_t datasize, const LodeZlib_DeflateSettings *settings)
Definition: lodepng.cpp:1327
static unsigned deflateFixed(ucvector *out, const unsigned char *data, size_t datasize, const LodeZlib_DeflateSettings *settings)
Definition: lodepng.cpp:1502
static void LodePNG_add32bitInt ( ucvector buffer,
unsigned  value 
)
static

Definition at line 1854 of file lodepng.cpp.

1855 {
1856  ucvector_resize(buffer, buffer->size + 4);
1857  LodePNG_set32bitInt(&buffer->data[buffer->size - 4], value);
1858 }
unsigned char * data
Definition: lodepng.cpp:201
static void LodePNG_set32bitInt(unsigned char *buffer, unsigned value)
Definition: lodepng.cpp:1845
size_t size
Definition: lodepng.cpp:202
static unsigned ucvector_resize(ucvector *p, size_t size)
Definition: lodepng.cpp:213
unsigned LodePNG_append_chunk ( unsigned char **  out,
size_t *  outlength,
const unsigned char *  chunk 
)

Definition at line 1937 of file lodepng.cpp.

1938 {
1939  unsigned i;
1940  unsigned total_chunk_length = LodePNG_chunk_length(chunk) + 12;
1941  unsigned char *chunk_start, *new_buffer;
1942  size_t new_length = (*outlength) + total_chunk_length;
1943  if(new_length < total_chunk_length || new_length < (*outlength)) return 77; /*integer overflow happened*/
1944 
1945  new_buffer = (unsigned char*)realloc(*out, new_length);
1946  if(!new_buffer) return 9929;
1947  (*out) = new_buffer;
1948  (*outlength) = new_length;
1949  chunk_start = &(*out)[new_length - total_chunk_length];
1950 
1951  for(i = 0; i < total_chunk_length; i++) chunk_start[i] = chunk[i];
1952 
1953  return 0;
1954 }
unsigned LodePNG_chunk_length(const unsigned char *chunk)
Definition: lodepng.cpp:1865
unsigned LodePNG_chunk_check_crc ( const unsigned char *  chunk)

Definition at line 1909 of file lodepng.cpp.

1910 {
1911  unsigned length = LodePNG_chunk_length(chunk);
1912  unsigned CRC = LodePNG_read32bitInt(&chunk[length + 8]);
1913  unsigned checksum = Crc32_crc(&chunk[4], length + 4); /*the CRC is taken of the data and the 4 chunk type letters, not the length*/
1914  if(CRC != checksum) return 1;
1915  else return 0;
1916 }
unsigned LodePNG_chunk_length(const unsigned char *chunk)
Definition: lodepng.cpp:1865
static unsigned LodePNG_read32bitInt(const unsigned char *buffer)
Definition: lodepng.cpp:1840
static unsigned Crc32_crc(const unsigned char *buf, size_t len)
Definition: lodepng.cpp:1799
unsigned char LodePNG_chunk_critical ( const unsigned char *  chunk)

Definition at line 1884 of file lodepng.cpp.

1885 {
1886  return((chunk[4] & 32) == 0);
1887 }
unsigned char* LodePNG_chunk_data ( unsigned char *  chunk)

Definition at line 1899 of file lodepng.cpp.

1900 {
1901  return &chunk[8];
1902 }
const unsigned char* LodePNG_chunk_data_const ( const unsigned char *  chunk)

Definition at line 1904 of file lodepng.cpp.

1905 {
1906  return &chunk[8];
1907 }
void LodePNG_chunk_generate_crc ( unsigned char *  chunk)

Definition at line 1918 of file lodepng.cpp.

1919 {
1920  unsigned length = LodePNG_chunk_length(chunk);
1921  unsigned CRC = Crc32_crc(&chunk[4], length + 4);
1922  LodePNG_set32bitInt(chunk + 8 + length, CRC);
1923 }
static void LodePNG_set32bitInt(unsigned char *buffer, unsigned value)
Definition: lodepng.cpp:1845
unsigned LodePNG_chunk_length(const unsigned char *chunk)
Definition: lodepng.cpp:1865
static unsigned Crc32_crc(const unsigned char *buf, size_t len)
Definition: lodepng.cpp:1799
unsigned LodePNG_chunk_length ( const unsigned char *  chunk)

Definition at line 1865 of file lodepng.cpp.

1866 {
1867  return LodePNG_read32bitInt(&chunk[0]);
1868 }
static unsigned LodePNG_read32bitInt(const unsigned char *buffer)
Definition: lodepng.cpp:1840
unsigned char* LodePNG_chunk_next ( unsigned char *  chunk)

Definition at line 1925 of file lodepng.cpp.

1926 {
1927  unsigned total_chunk_length = LodePNG_chunk_length(chunk) + 12;
1928  return &chunk[total_chunk_length];
1929 }
unsigned LodePNG_chunk_length(const unsigned char *chunk)
Definition: lodepng.cpp:1865
const unsigned char* LodePNG_chunk_next_const ( const unsigned char *  chunk)

Definition at line 1931 of file lodepng.cpp.

1932 {
1933  unsigned total_chunk_length = LodePNG_chunk_length(chunk) + 12;
1934  return &chunk[total_chunk_length];
1935 }
unsigned LodePNG_chunk_length(const unsigned char *chunk)
Definition: lodepng.cpp:1865
unsigned char LodePNG_chunk_private ( const unsigned char *  chunk)

Definition at line 1889 of file lodepng.cpp.

1890 {
1891  return((chunk[6] & 32) != 0);
1892 }
unsigned char LodePNG_chunk_safetocopy ( const unsigned char *  chunk)

Definition at line 1894 of file lodepng.cpp.

1895 {
1896  return((chunk[7] & 32) != 0);
1897 }
void LodePNG_chunk_type ( char  type[5],
const unsigned char *  chunk 
)

Definition at line 1870 of file lodepng.cpp.

1871 {
1872  unsigned i;
1873  for(i = 0; i < 4; i++) type[i] = chunk[4 + i];
1874  type[4] = 0; /*null termination char*/
1875 }
unsigned char LodePNG_chunk_type_equals ( const unsigned char *  chunk,
const char *  type 
)

Definition at line 1877 of file lodepng.cpp.

1878 {
1879  if(strlen(type) != 4) return 0;
1880  return (chunk[4] == type[0] && chunk[5] == type[1] && chunk[6] == type[2] && chunk[7] == type[3]);
1881 }
static unsigned LodePNG_compress ( unsigned char **  out,
size_t *  outsize,
const unsigned char *  in,
size_t  insize,
const LodeZlib_DeflateSettings settings 
)
static

Definition at line 1752 of file lodepng.cpp.

1753 {
1754  return LodeZlib_compress(out, outsize, in, insize, settings);
1755 }
UWORD32 in[16]
Definition: md5.h:44
unsigned LodeZlib_compress(unsigned char **out, size_t *outsize, const unsigned char *in, size_t insize, const LodeZlib_DeflateSettings *settings)
Definition: lodepng.cpp:1651
unsigned LodePNG_convert ( unsigned char *  out,
const unsigned char *  in,
LodePNG_InfoColor infoOut,
LodePNG_InfoColor infoIn,
unsigned  w,
unsigned  h 
)

Definition at line 2361 of file lodepng.cpp.

2362 {
2363  const size_t numpixels = w * h; /*amount of pixels*/
2364  const unsigned OUT_BYTES = LodePNG_InfoColor_getBpp(infoOut) / 8; /*bytes per pixel in the output image*/
2365  const unsigned OUT_ALPHA = LodePNG_InfoColor_isAlphaType(infoOut); /*use 8-bit alpha channel*/
2366  size_t i, c, bp = 0; /*bitpointer, used by less-than-8-bit color types*/
2367 
2368  /*cases where in and out already have the same format*/
2369  if(LodePNG_InfoColor_equal(infoIn, infoOut))
2370  {
2371  size_t i, size = (w * h * LodePNG_InfoColor_getBpp(infoIn) + 7) / 8;
2372  for(i = 0; i < size; i++) out[i] = in[i];
2373  return 0;
2374  }
2375 
2376  if((infoOut->colorType == 2 || infoOut->colorType == 6) && infoOut->bitDepth == 8)
2377  {
2378  if(infoIn->bitDepth == 8)
2379  {
2380  switch(infoIn->colorType)
2381  {
2382  case 0: /*greyscale color*/
2383  for(i = 0; i < numpixels; i++)
2384  {
2385  if(OUT_ALPHA) out[OUT_BYTES * i + 3] = 255;
2386  out[OUT_BYTES * i + 0] = out[OUT_BYTES * i + 1] = out[OUT_BYTES * i + 2] = in[i];
2387  if(OUT_ALPHA && infoIn->key_defined && in[i] == infoIn->key_r) out[OUT_BYTES * i + 3] = 0;
2388  }
2389  break;
2390  case 2: /*RGB color*/
2391  for(i = 0; i < numpixels; i++)
2392  {
2393  if(OUT_ALPHA) out[OUT_BYTES * i + 3] = 255;
2394  for(c = 0; c < 3; c++) out[OUT_BYTES * i + c] = in[3 * i + c];
2395  if(OUT_ALPHA && infoIn->key_defined == 1 && in[3 * i + 0] == infoIn->key_r && in[3 * i + 1] == infoIn->key_g && in[3 * i + 2] == infoIn->key_b) out[OUT_BYTES * i + 3] = 0;
2396  }
2397  break;
2398  case 3: /*indexed color (palette)*/
2399  for(i = 0; i < numpixels; i++)
2400  {
2401  if(OUT_ALPHA) out[OUT_BYTES * i + 3] = 255;
2402  if(in[i] >= infoIn->palettesize) return 46;
2403  for(c = 0; c < OUT_BYTES; c++) out[OUT_BYTES * i + c] = infoIn->palette[4 * in[i] + c]; /*get rgb colors from the palette*/
2404  }
2405  break;
2406  case 4: /*greyscale with alpha*/
2407  for(i = 0; i < numpixels; i++)
2408  {
2409  out[OUT_BYTES * i + 0] = out[OUT_BYTES * i + 1] = out[OUT_BYTES * i + 2] = in[2 * i + 0];
2410  if(OUT_ALPHA) out[OUT_BYTES * i + 3] = in[2 * i + 1];
2411  }
2412  break;
2413  case 6: /*RGB with alpha*/
2414  for(i = 0; i < numpixels; i++)
2415  {
2416  for(c = 0; c < OUT_BYTES; c++) out[OUT_BYTES * i + c] = in[4 * i + c];
2417  }
2418  break;
2419  default: break;
2420  }
2421  }
2422  else if(infoIn->bitDepth == 16)
2423  {
2424  switch(infoIn->colorType)
2425  {
2426  case 0: /*greyscale color*/
2427  for(i = 0; i < numpixels; i++)
2428  {
2429  if(OUT_ALPHA) out[OUT_BYTES * i + 3] = 255;
2430  out[OUT_BYTES * i + 0] = out[OUT_BYTES * i + 1] = out[OUT_BYTES * i + 2] = in[2 * i];
2431  if(OUT_ALPHA && infoIn->key_defined && 256U * in[i] + in[i + 1] == infoIn->key_r) out[OUT_BYTES * i + 3] = 0;
2432  }
2433  break;
2434  case 2: /*RGB color*/
2435  for(i = 0; i < numpixels; i++)
2436  {
2437  if(OUT_ALPHA) out[OUT_BYTES * i + 3] = 255;
2438  for(c = 0; c < 3; c++) out[OUT_BYTES * i + c] = in[6 * i + 2 * c];
2439  if(OUT_ALPHA && infoIn->key_defined && 256U * in[6 * i + 0] + in[6 * i + 1] == infoIn->key_r && 256U * in[6 * i + 2] + in[6 * i + 3] == infoIn->key_g && 256U * in[6 * i + 4] + in[6 * i + 5] == infoIn->key_b) out[OUT_BYTES * i + 3] = 0;
2440  }
2441  break;
2442  case 4: /*greyscale with alpha*/
2443  for(i = 0; i < numpixels; i++)
2444  {
2445  out[OUT_BYTES * i + 0] = out[OUT_BYTES * i + 1] = out[OUT_BYTES * i + 2] = in[4 * i]; /*most significant byte*/
2446  if(OUT_ALPHA) out[OUT_BYTES * i + 3] = in[4 * i + 2];
2447  }
2448  break;
2449  case 6: /*RGB with alpha*/
2450  for(i = 0; i < numpixels; i++)
2451  {
2452  for(c = 0; c < OUT_BYTES; c++) out[OUT_BYTES * i + c] = in[8 * i + 2 * c];
2453  }
2454  break;
2455  default: break;
2456  }
2457  }
2458  else /*infoIn->bitDepth is less than 8 bit per channel*/
2459  {
2460  switch(infoIn->colorType)
2461  {
2462  case 0: /*greyscale color*/
2463  for(i = 0; i < numpixels; i++)
2464  {
2465  unsigned value = readBitsFromReversedStream(&bp, in, infoIn->bitDepth);
2466  if(OUT_ALPHA) out[OUT_BYTES * i + 3] = 255;
2467  if(OUT_ALPHA && infoIn->key_defined && value && ((1U << infoIn->bitDepth) - 1U) == infoIn->key_r && ((1U << infoIn->bitDepth) - 1U)) out[OUT_BYTES * i + 3] = 0;
2468  value = (value * 255) / ((1 << infoIn->bitDepth) - 1); /*scale value from 0 to 255*/
2469  out[OUT_BYTES * i + 0] = out[OUT_BYTES * i + 1] = out[OUT_BYTES * i + 2] = (unsigned char)(value);
2470  }
2471  break;
2472  case 3: /*indexed color (palette)*/
2473  for(i = 0; i < numpixels; i++)
2474  {
2475  unsigned value = readBitsFromReversedStream(&bp, in, infoIn->bitDepth);
2476  if(OUT_ALPHA) out[OUT_BYTES * i + 3] = 255;
2477  if(value >= infoIn->palettesize) return 47;
2478  for(c = 0; c < OUT_BYTES; c++) out[OUT_BYTES * i + c] = infoIn->palette[4 * value + c]; /*get rgb colors from the palette*/
2479  }
2480  break;
2481  default: break;
2482  }
2483  }
2484  }
2485  else if(LodePNG_InfoColor_isGreyscaleType(infoOut) && infoOut->bitDepth == 8) /*conversion from greyscale to greyscale*/
2486  {
2487  if(!LodePNG_InfoColor_isGreyscaleType(infoIn)) return 62;
2488  if(infoIn->bitDepth == 8)
2489  {
2490  switch(infoIn->colorType)
2491  {
2492  case 0: /*greyscale color*/
2493  for(i = 0; i < numpixels; i++)
2494  {
2495  if(OUT_ALPHA) out[OUT_BYTES * i + 1] = 255;
2496  out[OUT_BYTES * i] = in[i];
2497  if(OUT_ALPHA && infoIn->key_defined && in[i] == infoIn->key_r) out[OUT_BYTES * i + 1] = 0;
2498  }
2499  break;
2500  case 4: /*greyscale with alpha*/
2501  for(i = 0; i < numpixels; i++)
2502  {
2503  out[OUT_BYTES * i + 0] = in[2 * i + 0];
2504  if(OUT_ALPHA) out[OUT_BYTES * i + 1] = in[2 * i + 1];
2505  }
2506  break;
2507  default: return 31;
2508  }
2509  }
2510  else if(infoIn->bitDepth == 16)
2511  {
2512  switch(infoIn->colorType)
2513  {
2514  case 0: /*greyscale color*/
2515  for(i = 0; i < numpixels; i++)
2516  {
2517  if(OUT_ALPHA) out[OUT_BYTES * i + 1] = 255;
2518  out[OUT_BYTES * i] = in[2 * i];
2519  if(OUT_ALPHA && infoIn->key_defined && 256U * in[i] + in[i + 1] == infoIn->key_r) out[OUT_BYTES * i + 1] = 0;
2520  }
2521  break;
2522  case 4: /*greyscale with alpha*/
2523  for(i = 0; i < numpixels; i++)
2524  {
2525  out[OUT_BYTES * i] = in[4 * i]; /*most significant byte*/
2526  if(OUT_ALPHA) out[OUT_BYTES * i + 1] = in[4 * i + 2]; /*most significant byte*/
2527  }
2528  break;
2529  default: return 31;
2530  }
2531  }
2532  else /*infoIn->bitDepth is less than 8 bit per channel*/
2533  {
2534  if(infoIn->colorType != 0) return 31; /*colorType 0 is the only greyscale type with < 8 bits per channel*/
2535  for(i = 0; i < numpixels; i++)
2536  {
2537  unsigned value = readBitsFromReversedStream(&bp, in, infoIn->bitDepth);
2538  if(OUT_ALPHA) out[OUT_BYTES * i + 1] = 255;
2539  if(OUT_ALPHA && infoIn->key_defined && value && ((1U << infoIn->bitDepth) - 1U) == infoIn->key_r && ((1U << infoIn->bitDepth) - 1U)) out[OUT_BYTES * i + 1] = 0;
2540  value = (value * 255) / ((1 << infoIn->bitDepth) - 1); /*scale value from 0 to 255*/
2541  out[OUT_BYTES * i] = (unsigned char)(value);
2542  }
2543  }
2544  }
2545  else return 59;
2546 
2547  return 0;
2548 }
size_t palettesize
Definition: lodepng.h:132
unsigned LodePNG_InfoColor_getBpp(const LodePNG_InfoColor *info)
Definition: lodepng.cpp:2066
unsigned colorType
Definition: lodepng.h:127
unsigned bitDepth
Definition: lodepng.h:128
unsigned key_r
Definition: lodepng.h:136
UWORD32 in[16]
Definition: md5.h:44
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
static unsigned readBitsFromReversedStream(size_t *bitpointer, const unsigned char *bitstream, size_t nbits)
Definition: lodepng.cpp:1815
unsigned key_defined
Definition: lodepng.h:135
unsigned key_g
Definition: lodepng.h:137
unsigned LodePNG_InfoColor_isGreyscaleType(const LodePNG_InfoColor *info)
Definition: lodepng.cpp:2068
unsigned LodePNG_InfoColor_equal(const LodePNG_InfoColor *info1, const LodePNG_InfoColor *info2)
Definition: lodepng.cpp:2071
unsigned key_b
Definition: lodepng.h:138
unsigned LodePNG_InfoColor_isAlphaType(const LodePNG_InfoColor *info)
Definition: lodepng.cpp:2069
unsigned char * palette
Definition: lodepng.h:131
unsigned LodePNG_create_chunk ( unsigned char **  out,
size_t *  outlength,
unsigned  length,
const char *  type,
const unsigned char *  data 
)

Definition at line 1956 of file lodepng.cpp.

1957 {
1958  unsigned i;
1959  unsigned char *chunk, *new_buffer;
1960  size_t new_length = (*outlength) + length + 12;
1961  if(new_length < length + 12 || new_length < (*outlength)) return 77; /*integer overflow happened*/
1962  new_buffer = (unsigned char*)realloc(*out, new_length);
1963  if(!new_buffer) return 9930;
1964  (*out) = new_buffer;
1965  (*outlength) = new_length;
1966  chunk = &(*out)[(*outlength) - length - 12];
1967 
1968  /*1: length*/
1969  LodePNG_set32bitInt(chunk, (unsigned)length);
1970 
1971  /*2: chunk name (4 letters)*/
1972  chunk[4] = type[0];
1973  chunk[5] = type[1];
1974  chunk[6] = type[2];
1975  chunk[7] = type[3];
1976 
1977  /*3: the data*/
1978  for(i = 0; i < length; i++) chunk[8 + i] = data[i];
1979 
1980  /*4: CRC (of the chunkname characters and the data)*/
1982 
1983  return 0;
1984 }
static void LodePNG_set32bitInt(unsigned char *buffer, unsigned value)
Definition: lodepng.cpp:1845
void LodePNG_chunk_generate_crc(unsigned char *chunk)
Definition: lodepng.cpp:1918
void LodePNG_encode ( LodePNG_Encoder encoder,
unsigned char **  out,
size_t *  outsize,
const unsigned char *  image,
unsigned  w,
unsigned  h 
)

Definition at line 3910 of file lodepng.cpp.

3911 {
3913  ucvector outv;
3914  unsigned char* data = 0; /*uncompressed version of the IDAT chunk data*/
3915  size_t datasize = 0;
3916 
3917  /*provide some proper output values if error will happen*/
3918  *out = 0;
3919  *outsize = 0;
3920  encoder->error = 0;
3921 
3922  info = encoder->infoPng; /*UNSAFE copy to avoid having to cleanup! but we will only change primitive parameters, and not invoke the cleanup function nor touch the palette's buffer so we use it safely*/
3923  info.width = w;
3924  info.height = h;
3925 
3926  if(encoder->settings.autoLeaveOutAlphaChannel && isFullyOpaque(image, w, h, &encoder->infoRaw.color))
3927  {
3928  /*go to a color type without alpha channel*/
3929  if(info.color.colorType == 6) info.color.colorType = 2;
3930  else if(info.color.colorType == 4) info.color.colorType = 0;
3931  }
3932 
3933  if(encoder->settings.zlibsettings.windowSize > 32768) { encoder->error = 60; return; } /*error: windowsize larger than allowed*/
3934  if(encoder->settings.zlibsettings.btype > 2) { encoder->error = 61; return; } /*error: unexisting btype*/
3935  if(encoder->infoPng.interlaceMethod > 1) { encoder->error = 71; return; } /*error: unexisting interlace mode*/
3936  if((encoder->error = checkColorValidity(info.color.colorType, info.color.bitDepth))) return; /*error: unexisting color type given*/
3937  if((encoder->error = checkColorValidity(encoder->infoRaw.color.colorType, encoder->infoRaw.color.bitDepth))) return; /*error: unexisting color type given*/
3938 
3939  if(!LodePNG_InfoColor_equal(&encoder->infoRaw.color, &info.color))
3940  {
3941  unsigned char* converted;
3942  size_t size = (w * h * LodePNG_InfoColor_getBpp(&info.color) + 7) / 8;
3943 
3944  if((info.color.colorType != 6 && info.color.colorType != 2) || (info.color.bitDepth != 8)) { encoder->error = 59; return; } /*for the output image, only these types are supported*/
3945  converted = (unsigned char*)malloc(size);
3946  if(!converted && size) encoder->error = 9955; /*error: malloc failed*/
3947  if(!encoder->error) encoder->error = LodePNG_convert(converted, image, &info.color, &encoder->infoRaw.color, w, h);
3948  if(!encoder->error) preProcessScanlines(&data, &datasize, converted, &info);/*filter(data.data, converted.data, w, h, LodePNG_InfoColor_getBpp(&info.color));*/
3949  free(converted);
3950  }
3951  else preProcessScanlines(&data, &datasize, image, &info);/*filter(data.data, image, w, h, LodePNG_InfoColor_getBpp(&info.color));*/
3952 
3953  ucvector_init(&outv);
3954  while(!encoder->error) /*not really a while loop, this is only used to break out if an error happens to avoid goto's to do the ucvector cleanup*/
3955  {
3956 #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
3957  size_t i;
3958 #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
3959  /*write signature and chunks*/
3960  writeSignature(&outv);
3961  /*IHDR*/
3962  addChunk_IHDR(&outv, w, h, info.color.bitDepth, info.color.colorType, info.interlaceMethod);
3963 #ifdef LODEPNG_COMPILE_UNKNOWN_CHUNKS
3964  /*unknown chunks between IHDR and PLTE*/
3965  if(info.unknown_chunks.data[0]) { encoder->error = addUnknownChunks(&outv, info.unknown_chunks.data[0], info.unknown_chunks.datasize[0]); if(encoder->error) break; }
3966 #endif /*LODEPNG_COMPILE_UNKNOWN_CHUNKS*/
3967  /*PLTE*/
3968  if(info.color.colorType == 3)
3969  {
3970  if(info.color.palettesize == 0 || info.color.palettesize > 256) { encoder->error = 68; break; }
3971  addChunk_PLTE(&outv, &info.color);
3972  }
3973  if(encoder->settings.force_palette && (info.color.colorType == 2 || info.color.colorType == 6))
3974  {
3975  if(info.color.palettesize == 0 || info.color.palettesize > 256) { encoder->error = 68; break; }
3976  addChunk_PLTE(&outv, &info.color);
3977  }
3978  /*tRNS*/
3979  if(info.color.colorType == 3 && !isPaletteFullyOpaque(info.color.palette, info.color.palettesize)) addChunk_tRNS(&outv, &info.color);
3980  if((info.color.colorType == 0 || info.color.colorType == 2) && info.color.key_defined) addChunk_tRNS(&outv, &info.color);
3981 #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
3982  /*bKGD (must come between PLTE and the IDAt chunks*/
3983  if(info.background_defined) addChunk_bKGD(&outv, &info);
3984  /*pHYs (must come before the IDAT chunks)*/
3985  if(info.phys_defined) addChunk_pHYs(&outv, &info);
3986 #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
3987 #ifdef LODEPNG_COMPILE_UNKNOWN_CHUNKS
3988  /*unknown chunks between PLTE and IDAT*/
3989  if(info.unknown_chunks.data[1]) { encoder->error = addUnknownChunks(&outv, info.unknown_chunks.data[1], info.unknown_chunks.datasize[1]); if(encoder->error) break; }
3990 #endif /*LODEPNG_COMPILE_UNKNOWN_CHUNKS*/
3991  /*IDAT (multiple IDAT chunks must be consecutive)*/
3992  encoder->error = addChunk_IDAT(&outv, data, datasize, &encoder->settings.zlibsettings);
3993  if(encoder->error) break;
3994 #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
3995  /*tIME*/
3996  if(info.time_defined) addChunk_tIME(&outv, &info.time);
3997  /*tEXt and/or zTXt*/
3998  for(i = 0; i < info.text.num; i++)
3999  {
4000  if(strlen(info.text.keys[i]) > 79) { encoder->error = 66; break; }
4001  if(strlen(info.text.keys[i]) < 1) { encoder->error = 67; break; }
4002  if(encoder->settings.text_compression)
4003  addChunk_zTXt(&outv, info.text.keys[i], info.text.strings[i], &encoder->settings.zlibsettings);
4004  else
4005  addChunk_tEXt(&outv, info.text.keys[i], info.text.strings[i]);
4006  }
4007  /*LodePNG version id in text chunk*/
4008  if(encoder->settings.add_id)
4009  {
4010  unsigned alread_added_id_text = 0;
4011  for(i = 0; i < info.text.num; i++)
4012  if(!strcmp(info.text.keys[i], "LodePNG")) { alread_added_id_text = 1; break; }
4013  if(alread_added_id_text == 0)
4014  addChunk_tEXt(&outv, "LodePNG", VERSION_STRING); /*it's shorter as tEXt than as zTXt chunk*/
4015  }
4016  /*iTXt*/
4017  for(i = 0; i < info.itext.num; i++)
4018  {
4019  if(strlen(info.itext.keys[i]) > 79) { encoder->error = 66; break; }
4020  if(strlen(info.itext.keys[i]) < 1) { encoder->error = 67; break; }
4021  addChunk_iTXt(&outv, encoder->settings.text_compression,
4022  info.itext.keys[i], info.itext.langtags[i], info.itext.transkeys[i], info.itext.strings[i],
4023  &encoder->settings.zlibsettings);
4024  }
4025 #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
4026 #ifdef LODEPNG_COMPILE_UNKNOWN_CHUNKS
4027  /*unknown chunks between IDAT and IEND*/
4028  if(info.unknown_chunks.data[2]) { encoder->error = addUnknownChunks(&outv, info.unknown_chunks.data[2], info.unknown_chunks.datasize[2]); if(encoder->error) break; }
4029 #endif /*LODEPNG_COMPILE_UNKNOWN_CHUNKS*/
4030  /*IEND*/
4031  addChunk_IEND(&outv);
4032 
4033  break; /*this isn't really a while loop; no error happened so break out now!*/
4034  }
4035 
4036  free(data);
4037  /*instead of cleaning the vector up, give it to the output*/
4038  *out = outv.data;
4039  *outsize = outv.size;
4040 }
size_t palettesize
Definition: lodepng.h:132
static unsigned isFullyOpaque(const unsigned char *image, unsigned w, unsigned h, const LodePNG_InfoColor *info)
Definition: lodepng.cpp:3857
unsigned LodePNG_InfoColor_getBpp(const LodePNG_InfoColor *info)
Definition: lodepng.cpp:2066
unsigned colorType
Definition: lodepng.h:127
LodePNG_InfoRaw infoRaw
Definition: lodepng.h:342
unsigned bitDepth
Definition: lodepng.h:128
unsigned interlaceMethod
Definition: lodepng.h:224
LodePNG_InfoColor color
Definition: lodepng.h:225
static unsigned isPaletteFullyOpaque(const unsigned char *palette, size_t palettesize)
Definition: lodepng.cpp:3846
LodePNG_EncodeSettings settings
Definition: lodepng.h:340
unsigned force_palette
Definition: lodepng.h:329
static unsigned addChunk_PLTE(ucvector *out, const LodePNG_InfoColor *info)
Definition: lodepng.cpp:3318
static unsigned addChunk_tRNS(ucvector *out, const LodePNG_InfoColor *info)
Definition: lodepng.cpp:3331
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
unsigned char * data
Definition: lodepng.cpp:201
LodeZlib_DeflateSettings zlibsettings
Definition: lodepng.h:326
static unsigned checkColorValidity(unsigned colorType, unsigned bd)
Definition: lodepng.cpp:1991
static void writeSignature(ucvector *out)
Definition: lodepng.cpp:3285
LodePNG_InfoColor color
Definition: lodepng.h:266
static unsigned addChunk_IEND(ucvector *out)
Definition: lodepng.cpp:3382
static void ucvector_init(ucvector *p)
Definition: lodepng.cpp:243
unsigned height
Definition: lodepng.h:221
static unsigned preProcessScanlines(unsigned char **out, size_t *outsize, const unsigned char *in, const LodePNG_InfoPng *infoPng)
Definition: lodepng.cpp:3762
static unsigned addChunk_IDAT(ucvector *out, const unsigned char *data, size_t datasize, LodeZlib_DeflateSettings *zlibsettings)
Definition: lodepng.cpp:3368
LodePNG_InfoPng infoPng
Definition: lodepng.h:341
unsigned key_defined
Definition: lodepng.h:135
unsigned LodePNG_convert(unsigned char *out, const unsigned char *in, LodePNG_InfoColor *infoOut, LodePNG_InfoColor *infoIn, unsigned w, unsigned h)
Definition: lodepng.cpp:2361
unsigned width
Definition: lodepng.h:220
size_t size
Definition: lodepng.cpp:202
int strcmp(const String &s1, const String &s2)
Definition: relates.cpp:14
unsigned LodePNG_InfoColor_equal(const LodePNG_InfoColor *info1, const LodePNG_InfoColor *info2)
Definition: lodepng.cpp:2071
static unsigned addChunk_IHDR(ucvector *out, unsigned w, unsigned h, unsigned bitDepth, unsigned colorType, unsigned interlaceMethod)
Definition: lodepng.cpp:3298
unsigned char * palette
Definition: lodepng.h:131
unsigned autoLeaveOutAlphaChannel
Definition: lodepng.h:328
#define VERSION_STRING
Definition: lodepng.cpp:36
unsigned error
Definition: lodepng.h:343
unsigned LodePNG_encode32 ( unsigned char **  out,
size_t *  outsize,
const unsigned char *  image,
unsigned  w,
unsigned  h 
)

Definition at line 4042 of file lodepng.cpp.

4043 {
4044  unsigned error;
4046  LodePNG_Encoder_init(&encoder);
4047  LodePNG_encode(&encoder, out, outsize, image, w, h);
4048  error = encoder.error;
4049  LodePNG_Encoder_cleanup(&encoder);
4050  return error;
4051 }
void LodePNG_Encoder_init(LodePNG_Encoder *encoder)
Definition: lodepng.cpp:4076
error
Definition: include.cc:26
void LodePNG_encode(LodePNG_Encoder *encoder, unsigned char **out, size_t *outsize, const unsigned char *image, unsigned w, unsigned h)
Definition: lodepng.cpp:3910
void LodePNG_Encoder_cleanup(LodePNG_Encoder *encoder)
Definition: lodepng.cpp:4084
static QFile::EncoderFn encoder
Definition: qfile.cpp:470
unsigned error
Definition: lodepng.h:343
unsigned LodePNG_encode32f ( const char *  filename,
const unsigned char *  image,
unsigned  w,
unsigned  h 
)

Definition at line 4054 of file lodepng.cpp.

4055 {
4056  unsigned char* buffer;
4057  size_t buffersize;
4058  unsigned error = LodePNG_encode32(&buffer, &buffersize, image, w, h);
4059  LodePNG_saveFile(buffer, buffersize, filename);
4060  free(buffer);
4061  return error;
4062 }
error
Definition: include.cc:26
string filename
Definition: train.py:213
unsigned LodePNG_saveFile(const unsigned char *buffer, size_t buffersize, const char *filename)
Definition: lodepng.cpp:4141
unsigned LodePNG_encode32(unsigned char **out, size_t *outsize, const unsigned char *image, unsigned w, unsigned h)
Definition: lodepng.cpp:4042
void LodePNG_Encoder_cleanup ( LodePNG_Encoder encoder)

Definition at line 4084 of file lodepng.cpp.

4085 {
4086  LodePNG_InfoPng_cleanup(&encoder->infoPng);
4087  LodePNG_InfoRaw_cleanup(&encoder->infoRaw);
4088 }
LodePNG_InfoRaw infoRaw
Definition: lodepng.h:342
void LodePNG_InfoPng_cleanup(LodePNG_InfoPng *info)
Definition: lodepng.cpp:2284
LodePNG_InfoPng infoPng
Definition: lodepng.h:341
void LodePNG_InfoRaw_cleanup(LodePNG_InfoRaw *info)
Definition: lodepng.cpp:2339
void LodePNG_Encoder_copy ( LodePNG_Encoder dest,
const LodePNG_Encoder source 
)

Definition at line 4090 of file lodepng.cpp.

4091 {
4093  *dest = *source;
4094  LodePNG_InfoPng_init(&dest->infoPng);
4095  LodePNG_InfoRaw_init(&dest->infoRaw);
4096  dest->error = LodePNG_InfoPng_copy(&dest->infoPng, &source->infoPng); if(dest->error) return;
4097  dest->error = LodePNG_InfoRaw_copy(&dest->infoRaw, &source->infoRaw); if(dest->error) return;
4098 }
unsigned LodePNG_InfoPng_copy(LodePNG_InfoPng *dest, const LodePNG_InfoPng *source)
Definition: lodepng.cpp:2296
LodePNG_InfoRaw infoRaw
Definition: lodepng.h:342
void LodePNG_Encoder_cleanup(LodePNG_Encoder *encoder)
Definition: lodepng.cpp:4084
void LodePNG_InfoRaw_init(LodePNG_InfoRaw *info)
Definition: lodepng.cpp:2334
LodePNG_InfoPng infoPng
Definition: lodepng.h:341
unsigned LodePNG_InfoRaw_copy(LodePNG_InfoRaw *dest, const LodePNG_InfoRaw *source)
Definition: lodepng.cpp:2344
void LodePNG_InfoPng_init(LodePNG_InfoPng *info)
Definition: lodepng.cpp:2262
unsigned error
Definition: lodepng.h:343
void LodePNG_Encoder_init ( LodePNG_Encoder encoder)

Definition at line 4076 of file lodepng.cpp.

4077 {
4079  LodePNG_InfoPng_init(&encoder->infoPng);
4080  LodePNG_InfoRaw_init(&encoder->infoRaw);
4081  encoder->error = 1;
4082 }
LodePNG_InfoRaw infoRaw
Definition: lodepng.h:342
LodePNG_EncodeSettings settings
Definition: lodepng.h:340
void LodePNG_InfoRaw_init(LodePNG_InfoRaw *info)
Definition: lodepng.cpp:2334
LodePNG_InfoPng infoPng
Definition: lodepng.h:341
void LodePNG_InfoPng_init(LodePNG_InfoPng *info)
Definition: lodepng.cpp:2262
unsigned error
Definition: lodepng.h:343
void LodePNG_EncodeSettings_init(LodePNG_EncodeSettings *settings)
Definition: lodepng.cpp:4065
void LodePNG_EncodeSettings_init ( LodePNG_EncodeSettings settings)

Definition at line 4065 of file lodepng.cpp.

4066 {
4068  settings->autoLeaveOutAlphaChannel = 1;
4069  settings->force_palette = 0;
4070 #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
4071  settings->add_id = 1;
4072  settings->text_compression = 0;
4073 #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
4074 }
void LodeZlib_DeflateSettings_init(LodeZlib_DeflateSettings *settings)
Definition: lodepng.cpp:1697
unsigned force_palette
Definition: lodepng.h:329
LodeZlib_DeflateSettings zlibsettings
Definition: lodepng.h:326
unsigned autoLeaveOutAlphaChannel
Definition: lodepng.h:328
unsigned LodePNG_InfoColor_addPalette ( LodePNG_InfoColor info,
unsigned char  r,
unsigned char  g,
unsigned char  b,
unsigned char  a 
)

Definition at line 2046 of file lodepng.cpp.

2047 {
2048  unsigned char* data;
2049  /*the same resize technique as C++ std::vectors is used, and here it's made so that for a palette with the max of 256 colors, it'll have the exact alloc size*/
2050  if(!(info->palettesize & (info->palettesize - 1))) /*if palettesize is 0 or a power of two*/
2051  {
2052  /*allocated data must be at least 4* palettesize (for 4 color bytes)*/
2053  size_t alloc_size = info->palettesize == 0 ? 4 : info->palettesize * 4 * 2;
2054  data = (unsigned char*)realloc(info->palette, alloc_size);
2055  if(!data) return 9931;
2056  else info->palette = data;
2057  }
2058  info->palette[4 * info->palettesize + 0] = r;
2059  info->palette[4 * info->palettesize + 1] = g;
2060  info->palette[4 * info->palettesize + 2] = b;
2061  info->palette[4 * info->palettesize + 3] = a;
2062  info->palettesize++;
2063  return 0;
2064 }
size_t palettesize
Definition: lodepng.h:132
static constexpr double g
Definition: Units.h:144
const double a
static bool * b
Definition: config.cpp:1043
unsigned char * palette
Definition: lodepng.h:131
void LodePNG_InfoColor_cleanup ( LodePNG_InfoColor info)

Definition at line 2035 of file lodepng.cpp.

2036 {
2038 }
void LodePNG_InfoColor_clearPalette(LodePNG_InfoColor *info)
Definition: lodepng.cpp:2040
void LodePNG_InfoColor_clearPalette ( LodePNG_InfoColor info)

Definition at line 2040 of file lodepng.cpp.

2041 {
2042  if(info->palette) free(info->palette);
2043  info->palettesize = 0;
2044 }
size_t palettesize
Definition: lodepng.h:132
unsigned char * palette
Definition: lodepng.h:131
unsigned LodePNG_InfoColor_copy ( LodePNG_InfoColor dest,
const LodePNG_InfoColor source 
)

Definition at line 2323 of file lodepng.cpp.

2324 {
2325  size_t i;
2327  *dest = *source;
2328  dest->palette = (unsigned char*)malloc(source->palettesize * 4);
2329  if(!dest->palette && source->palettesize) return 9935;
2330  for(i = 0; i < source->palettesize * 4; i++) dest->palette[i] = source->palette[i];
2331  return 0;
2332 }
size_t palettesize
Definition: lodepng.h:132
void LodePNG_InfoColor_cleanup(LodePNG_InfoColor *info)
Definition: lodepng.cpp:2035
unsigned char * palette
Definition: lodepng.h:131
unsigned LodePNG_InfoColor_equal ( const LodePNG_InfoColor info1,
const LodePNG_InfoColor info2 
)

Definition at line 2071 of file lodepng.cpp.

2072 {
2073  return info1->colorType == info2->colorType
2074  && info1->bitDepth == info2->bitDepth; /*palette and color key not compared*/
2075 }
unsigned colorType
Definition: lodepng.h:127
unsigned bitDepth
Definition: lodepng.h:128
unsigned LodePNG_InfoColor_getBpp ( const LodePNG_InfoColor info)

Definition at line 2066 of file lodepng.cpp.

2066 { return getBpp(info->colorType, info->bitDepth); } /*calculate bits per pixel out of colorType and bitDepth*/
unsigned colorType
Definition: lodepng.h:127
unsigned bitDepth
Definition: lodepng.h:128
static unsigned getBpp(unsigned colorType, unsigned bitDepth)
Definition: lodepng.cpp:2018
unsigned LodePNG_InfoColor_getChannels ( const LodePNG_InfoColor info)

Definition at line 2067 of file lodepng.cpp.

2067 { return getNumColorChannels(info->colorType); }
unsigned colorType
Definition: lodepng.h:127
static unsigned getNumColorChannels(unsigned colorType)
Definition: lodepng.cpp:2005
void LodePNG_InfoColor_init ( LodePNG_InfoColor info)

Definition at line 2025 of file lodepng.cpp.

2026 {
2027  info->key_defined = 0;
2028  info->key_r = info->key_g = info->key_b = 0;
2029  info->colorType = 6;
2030  info->bitDepth = 8;
2031  info->palette = 0;
2032  info->palettesize = 0;
2033 }
size_t palettesize
Definition: lodepng.h:132
unsigned colorType
Definition: lodepng.h:127
unsigned bitDepth
Definition: lodepng.h:128
unsigned key_r
Definition: lodepng.h:136
unsigned key_defined
Definition: lodepng.h:135
unsigned key_g
Definition: lodepng.h:137
unsigned key_b
Definition: lodepng.h:138
unsigned char * palette
Definition: lodepng.h:131
unsigned LodePNG_InfoColor_isAlphaType ( const LodePNG_InfoColor info)

Definition at line 2069 of file lodepng.cpp.

2069 { return (info->colorType & 4) != 0; }
unsigned colorType
Definition: lodepng.h:127
unsigned LodePNG_InfoColor_isGreyscaleType ( const LodePNG_InfoColor info)

Definition at line 2068 of file lodepng.cpp.

2068 { return info->colorType == 0 || info->colorType == 4; }
unsigned colorType
Definition: lodepng.h:127
void LodePNG_InfoPng_cleanup ( LodePNG_InfoPng info)

Definition at line 2284 of file lodepng.cpp.

2285 {
2287 #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
2288  LodePNG_Text_cleanup(&info->text);
2289  LodePNG_IText_cleanup(&info->itext);
2290 #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
2291 #ifdef LODEPNG_COMPILE_UNKNOWN_CHUNKS
2292  LodePNG_UnknownChunks_cleanup(&info->unknown_chunks);
2293 #endif /*LODEPNG_COMPILE_UNKNOWN_CHUNKS*/
2294 }
LodePNG_InfoColor color
Definition: lodepng.h:225
void LodePNG_InfoColor_cleanup(LodePNG_InfoColor *info)
Definition: lodepng.cpp:2035
unsigned LodePNG_InfoPng_copy ( LodePNG_InfoPng dest,
const LodePNG_InfoPng source 
)

Definition at line 2296 of file lodepng.cpp.

2297 {
2298  unsigned error = 0;
2300  *dest = *source;
2301  LodePNG_InfoColor_init(&dest->color);
2302  error = LodePNG_InfoColor_copy(&dest->color, &source->color); if(error) return error;
2303 
2304 #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
2305  error = LodePNG_Text_copy(&dest->text, &source->text); if(error) return error;
2306  error = LodePNG_IText_copy(&dest->itext, &source->itext); if(error) return error;
2307 #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
2308 
2309 #ifdef LODEPNG_COMPILE_UNKNOWN_CHUNKS
2310  LodePNG_UnknownChunks_init(&dest->unknown_chunks);
2311  error = LodePNG_UnknownChunks_copy(&dest->unknown_chunks, &source->unknown_chunks); if(error) return error;
2312 #endif /*LODEPNG_COMPILE_UNKNOWN_CHUNKS*/
2313  return error;
2314 }
LodePNG_InfoColor color
Definition: lodepng.h:225
void LodePNG_InfoColor_init(LodePNG_InfoColor *info)
Definition: lodepng.cpp:2025
error
Definition: include.cc:26
void LodePNG_InfoPng_cleanup(LodePNG_InfoPng *info)
Definition: lodepng.cpp:2284
unsigned LodePNG_InfoColor_copy(LodePNG_InfoColor *dest, const LodePNG_InfoColor *source)
Definition: lodepng.cpp:2323
void LodePNG_InfoPng_init ( LodePNG_InfoPng info)

Definition at line 2262 of file lodepng.cpp.

2263 {
2264  info->width = info->height = 0;
2265  LodePNG_InfoColor_init(&info->color);
2266  info->interlaceMethod = 0;
2267  info->compressionMethod = 0;
2268  info->filterMethod = 0;
2269 #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
2270  info->background_defined = 0;
2271  info->background_r = info->background_g = info->background_b = 0;
2272 
2273  LodePNG_Text_init(&info->text);
2274  LodePNG_IText_init(&info->itext);
2275 
2276  info->time_defined = 0;
2277  info->phys_defined = 0;
2278 #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
2279 #ifdef LODEPNG_COMPILE_UNKNOWN_CHUNKS
2280  LodePNG_UnknownChunks_init(&info->unknown_chunks);
2281 #endif /*LODEPNG_COMPILE_UNKNOWN_CHUNKS*/
2282 }
unsigned compressionMethod
Definition: lodepng.h:222
unsigned interlaceMethod
Definition: lodepng.h:224
LodePNG_InfoColor color
Definition: lodepng.h:225
void LodePNG_InfoColor_init(LodePNG_InfoColor *info)
Definition: lodepng.cpp:2025
unsigned filterMethod
Definition: lodepng.h:223
unsigned height
Definition: lodepng.h:221
unsigned width
Definition: lodepng.h:220
void LodePNG_InfoPng_swap ( LodePNG_InfoPng a,
LodePNG_InfoPng b 
)

Definition at line 2316 of file lodepng.cpp.

2317 {
2318  LodePNG_InfoPng temp = *a;
2319  *a = *b;
2320  *b = temp;
2321 }
const double a
static bool * b
Definition: config.cpp:1043
void LodePNG_InfoRaw_cleanup ( LodePNG_InfoRaw info)

Definition at line 2339 of file lodepng.cpp.

2340 {
2342 }
void LodePNG_InfoColor_cleanup(LodePNG_InfoColor *info)
Definition: lodepng.cpp:2035
LodePNG_InfoColor color
Definition: lodepng.h:266
unsigned LodePNG_InfoRaw_copy ( LodePNG_InfoRaw dest,
const LodePNG_InfoRaw source 
)

Definition at line 2344 of file lodepng.cpp.

2345 {
2346  unsigned error = 0;
2348  *dest = *source;
2349  LodePNG_InfoColor_init(&dest->color);
2350  error = LodePNG_InfoColor_copy(&dest->color, &source->color);
2351  return error;
2352 }
void LodePNG_InfoColor_init(LodePNG_InfoColor *info)
Definition: lodepng.cpp:2025
error
Definition: include.cc:26
LodePNG_InfoColor color
Definition: lodepng.h:266
unsigned LodePNG_InfoColor_copy(LodePNG_InfoColor *dest, const LodePNG_InfoColor *source)
Definition: lodepng.cpp:2323
void LodePNG_InfoRaw_cleanup(LodePNG_InfoRaw *info)
Definition: lodepng.cpp:2339
void LodePNG_InfoRaw_init ( LodePNG_InfoRaw info)

Definition at line 2334 of file lodepng.cpp.

2335 {
2336  LodePNG_InfoColor_init(&info->color);
2337 }
void LodePNG_InfoColor_init(LodePNG_InfoColor *info)
Definition: lodepng.cpp:2025
LodePNG_InfoColor color
Definition: lodepng.h:266
unsigned LodePNG_loadFile ( unsigned char **  out,
size_t *  outsize,
const char *  filename 
)

Definition at line 4110 of file lodepng.cpp.

4111 {
4112  FILE* file;
4113  long size;
4114 
4115  /*provide some proper output values if error will happen*/
4116  *out = 0;
4117  *outsize = 0;
4118 
4119  file = portable_fopen(filename, "rb");
4120  if(!file) return 78;
4121 
4122  /*get filesize:*/
4123  fseek(file , 0 , SEEK_END);
4124  size = ftell(file);
4125  rewind(file);
4126 
4127  /*read contents of the file into the vector*/
4128  if (size>0)
4129  {
4130  *outsize = 0;
4131  *out = (unsigned char*)malloc((size_t)size);
4132  if(size && (*out)) (*outsize) = fread(*out, 1, (size_t)size, file);
4133  }
4134 
4135  fclose(file);
4136  if(!(*out) && size) return 80; /*the above malloc failed*/
4137  return 0;
4138 }
string filename
Definition: train.py:213
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
FILE * portable_fopen(const char *fileName, const char *mode)
Definition: portable.cpp:344
static unsigned LodePNG_read32bitInt ( const unsigned char *  buffer)
static

Definition at line 1840 of file lodepng.cpp.

1841 {
1842  return (buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3];
1843 }
unsigned LodePNG_saveFile ( const unsigned char *  buffer,
size_t  buffersize,
const char *  filename 
)

Definition at line 4141 of file lodepng.cpp.

4142 {
4143  FILE* file;
4144  file = portable_fopen(filename, "wb" );
4145  if(!file) return 79;
4146  fwrite((char*)buffer , 1 , buffersize, file);
4147  fclose(file);
4148  return 0;
4149 }
string filename
Definition: train.py:213
FILE * portable_fopen(const char *fileName, const char *mode)
Definition: portable.cpp:344
static void LodePNG_set32bitInt ( unsigned char *  buffer,
unsigned  value 
)
static

Definition at line 1845 of file lodepng.cpp.

1846 {
1847  buffer[0] = (unsigned char)((value >> 24) & 0xff);
1848  buffer[1] = (unsigned char)((value >> 16) & 0xff);
1849  buffer[2] = (unsigned char)((value >> 8) & 0xff);
1850  buffer[3] = (unsigned char)((value ) & 0xff);
1851 }
void LodeZlib_add32bitInt ( ucvector buffer,
unsigned  value 
)

Definition at line 1592 of file lodepng.cpp.

1593 {
1594  ucvector_push_back(buffer, (unsigned char)((value >> 24) & 0xff));
1595  ucvector_push_back(buffer, (unsigned char)((value >> 16) & 0xff));
1596  ucvector_push_back(buffer, (unsigned char)((value >> 8) & 0xff));
1597  ucvector_push_back(buffer, (unsigned char)((value ) & 0xff));
1598 }
static unsigned ucvector_push_back(ucvector *p, unsigned char c)
Definition: lodepng.cpp:258
unsigned LodeZlib_compress ( unsigned char **  out,
size_t *  outsize,
const unsigned char *  in,
size_t  insize,
const LodeZlib_DeflateSettings settings 
)

Definition at line 1651 of file lodepng.cpp.

1652 {
1653  /*initially, *out must be NULL and outsize 0, if you just give some random *out that's pointing to a non allocated buffer, this'll crash*/
1654  ucvector deflatedata, outv;
1655  size_t i;
1656  unsigned error;
1657 
1658  unsigned ADLER32;
1659  /*zlib data: 1 byte CMF (CM+CINFO), 1 byte FLG, deflate data, 4 byte ADLER32 checksum of the Decompressed data*/
1660  unsigned CMF = 120; /*0b01111000: CM 8, CINFO 7. With CINFO 7, any window size up to 32768 can be used.*/
1661  unsigned FLEVEL = 0;
1662  unsigned FDICT = 0;
1663  unsigned CMFFLG = 256 * CMF + FDICT * 32 + FLEVEL * 64;
1664  unsigned FCHECK = 31 - CMFFLG % 31;
1665  CMFFLG += FCHECK;
1666 
1667  ucvector_init_buffer(&outv, *out, *outsize); /*ucvector-controlled version of the output buffer, for dynamic array*/
1668 
1669  ucvector_push_back(&outv, (unsigned char)(CMFFLG / 256));
1670  ucvector_push_back(&outv, (unsigned char)(CMFFLG % 256));
1671 
1672  ucvector_init(&deflatedata);
1673  error = LodeFlate_deflate(&deflatedata, in, insize, settings);
1674 
1675  if(!error)
1676  {
1677  ADLER32 = adler32(in, (unsigned)insize);
1678  for(i = 0; i < deflatedata.size; i++) ucvector_push_back(&outv, deflatedata.data[i]);
1679  ucvector_cleanup(&deflatedata);
1680  LodeZlib_add32bitInt(&outv, ADLER32);
1681  }
1682 
1683  *out = outv.data;
1684  *outsize = outv.size;
1685 
1686  return error;
1687 }
void LodeZlib_add32bitInt(ucvector *buffer, unsigned value)
Definition: lodepng.cpp:1592
error
Definition: include.cc:26
static unsigned ucvector_push_back(ucvector *p, unsigned char c)
Definition: lodepng.cpp:258
UWORD32 in[16]
Definition: md5.h:44
unsigned char * data
Definition: lodepng.cpp:201
static void ucvector_cleanup(void *p)
Definition: lodepng.cpp:206
static void ucvector_init(ucvector *p)
Definition: lodepng.cpp:243
unsigned LodeFlate_deflate(ucvector *out, const unsigned char *data, size_t datasize, const LodeZlib_DeflateSettings *settings)
Definition: lodepng.cpp:1542
static void ucvector_init_buffer(ucvector *p, unsigned char *buffer, size_t size)
Definition: lodepng.cpp:251
static unsigned adler32(const unsigned char *data, unsigned len)
Definition: lodepng.cpp:1582
size_t size
Definition: lodepng.cpp:202
void LodeZlib_DeflateSettings_init ( LodeZlib_DeflateSettings settings)

Definition at line 1697 of file lodepng.cpp.

1698 {
1699  settings->btype = 2; /*compress with dynamic huffman tree (not in the mathematical sense, just not the predefined one)*/
1700  settings->useLZ77 = 1;
1701  settings->windowSize = 2048; /*this is a good tradeoff between speed and compression ratio*/
1702 }
unsigned LodeZlib_read32bitInt ( const unsigned char *  buffer)

Definition at line 1601 of file lodepng.cpp.

1602 {
1603  return (buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3];
1604 }
static int paethPredictor ( int  a,
int  b,
int  c 
)
static

Definition at line 2551 of file lodepng.cpp.

2552 {
2553  int p = a + b - c;
2554  int pa = p > a ? p - a : a - p;
2555  int pb = p > b ? p - b : b - p;
2556  int pc = p > c ? p - c : c - p;
2557 
2558  if(pa <= pb && pa <= pc) return a;
2559  else if(pb <= pc) return b;
2560  else return c;
2561 }
const double a
p
Definition: test.py:223
static bool * b
Definition: config.cpp:1043
static constexpr double pb
Definition: Units.h:82
static unsigned preProcessScanlines ( unsigned char **  out,
size_t *  outsize,
const unsigned char *  in,
const LodePNG_InfoPng infoPng 
)
static

Definition at line 3762 of file lodepng.cpp.

3763 {
3764  /*
3765  This function converts the pure 2D image with the PNG's colortype, into filtered-padded-interlaced data. Steps:
3766  *) if no Adam7: 1) add padding bits (= possible extra bits per scanline if bpp < 8) 2) filter
3767  *) if adam7: 1) Adam7_interlace 2) 7x add padding bits 3) 7x filter
3768  */
3769  unsigned bpp = LodePNG_InfoColor_getBpp(&infoPng->color);
3770  unsigned w = infoPng->width;
3771  unsigned h = infoPng->height;
3772  unsigned error = 0;
3773 
3774  if(infoPng->interlaceMethod == 0)
3775  {
3776  *outsize = h + (h * ((w * bpp + 7) / 8)); /*image size plus an extra byte per scanline + possible padding bits*/
3777  *out = (unsigned char*)malloc(*outsize);
3778  if(!(*out) && (*outsize)) error = 9950;
3779 
3780  if(!error)
3781  {
3782  if(bpp < 8 && w * bpp != ((w * bpp + 7) / 8) * 8) /*non multiple of 8 bits per scanline, padding bits needed per scanline*/
3783  {
3784  ucvector padded;
3785  ucvector_init(&padded);
3786  if(!ucvector_resize(&padded, h * ((w * bpp + 7) / 8))) error = 9951;
3787  if(!error)
3788  {
3789  addPaddingBits(padded.data, in, ((w * bpp + 7) / 8) * 8, w * bpp, h);
3790  error = filter(*out, padded.data, w, h, &infoPng->color);
3791  }
3792  ucvector_cleanup(&padded);
3793  }
3794  else error = filter(*out, in, w, h, &infoPng->color); /*we can immediately filter into the out buffer, no other steps needed*/
3795  }
3796  }
3797  else /*interlaceMethod is 1 (Adam7)*/
3798  {
3799  unsigned char* adam7 = (unsigned char*)malloc((h * w * bpp + 7) / 8);
3800  if(!adam7 && ((h * w * bpp + 7) / 8)) error = 9952; /*malloc failed*/
3801 
3802  while(!error) /*not a real while loop, used to break out to cleanup to avoid a goto*/
3803  {
3804  unsigned passw[7], passh[7]; size_t filter_passstart[8], padded_passstart[8], passstart[8];
3805  unsigned i;
3806 
3807  Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp);
3808 
3809  *outsize = filter_passstart[7]; /*image size plus an extra byte per scanline + possible padding bits*/
3810  *out = (unsigned char*)malloc(*outsize);
3811  if(!(*out) && (*outsize)) { error = 9953; break; }
3812 
3813  Adam7_interlace(adam7, in, w, h, bpp);
3814 
3815  for(i = 0; i < 7; i++)
3816  {
3817  if(bpp < 8)
3818  {
3819  ucvector padded;
3820  ucvector_init(&padded);
3821  if(!ucvector_resize(&padded, h * ((w * bpp + 7) / 8))) error = 9954;
3822  if(!error)
3823  {
3824  addPaddingBits(&padded.data[padded_passstart[i]], &adam7[passstart[i]], ((passw[i] * bpp + 7) / 8) * 8, passw[i] * bpp, passh[i]);
3825  error = filter(&(*out)[filter_passstart[i]], &padded.data[padded_passstart[i]], passw[i], passh[i], &infoPng->color);
3826  }
3827 
3828  ucvector_cleanup(&padded);
3829  }
3830  else
3831  {
3832  error = filter(&(*out)[filter_passstart[i]], &adam7[padded_passstart[i]], passw[i], passh[i], &infoPng->color);
3833  }
3834  }
3835 
3836  break;
3837  }
3838 
3839  free(adam7);
3840  }
3841 
3842  return error;
3843 }
static void Adam7_interlace(unsigned char *out, const unsigned char *in, unsigned w, unsigned h, unsigned bpp)
Definition: lodepng.cpp:3712
unsigned LodePNG_InfoColor_getBpp(const LodePNG_InfoColor *info)
Definition: lodepng.cpp:2066
unsigned interlaceMethod
Definition: lodepng.h:224
LodePNG_InfoColor color
Definition: lodepng.h:225
static void addPaddingBits(unsigned char *out, const unsigned char *in, size_t olinebits, size_t ilinebits, unsigned h)
Definition: lodepng.cpp:3692
error
Definition: include.cc:26
static void Adam7_getpassvalues(unsigned passw[7], unsigned passh[7], size_t filter_passstart[8], size_t padded_passstart[8], size_t passstart[8], unsigned w, unsigned h, unsigned bpp)
Definition: lodepng.cpp:2570
UWORD32 in[16]
Definition: md5.h:44
unsigned char * data
Definition: lodepng.cpp:201
static void ucvector_cleanup(void *p)
Definition: lodepng.cpp:206
static void ucvector_init(ucvector *p)
Definition: lodepng.cpp:243
unsigned height
Definition: lodepng.h:221
unsigned width
Definition: lodepng.h:220
static unsigned ucvector_resize(ucvector *p, size_t size)
Definition: lodepng.cpp:213
static unsigned filter(unsigned char *out, const unsigned char *in, unsigned w, unsigned h, const LodePNG_InfoColor *info)
Definition: lodepng.cpp:3576
static unsigned char readBitFromReversedStream ( size_t *  bitpointer,
const unsigned char *  bitstream 
)
static

Definition at line 1808 of file lodepng.cpp.

1809 {
1810  unsigned char result = (unsigned char)((bitstream[(*bitpointer) >> 3] >> (7 - ((*bitpointer) & 0x7))) & 1);
1811  (*bitpointer)++;
1812  return result;
1813 }
static QCString result
static unsigned readBitsFromReversedStream ( size_t *  bitpointer,
const unsigned char *  bitstream,
size_t  nbits 
)
static

Definition at line 1815 of file lodepng.cpp.

1816 {
1817  unsigned result = 0;
1818  size_t i;
1819  for(i = nbits - 1; i < nbits; i--) result += (unsigned)readBitFromReversedStream(bitpointer, bitstream) << i;
1820  return result;
1821 }
static QCString result
static unsigned char readBitFromReversedStream(size_t *bitpointer, const unsigned char *bitstream)
Definition: lodepng.cpp:1808
static size_t searchCodeIndex ( const unsigned *  array,
size_t  array_size,
size_t  value 
)
static

Definition at line 1000 of file lodepng.cpp.

1001 {
1002  /*linear search implementation*/
1003  /*for(size_t i = 1; i < array_size; i++) if(array[i] > value) return i - 1;
1004  return array_size - 1;*/
1005 
1006  /*binary search implementation (not that much faster) (precondition: array_size > 0)*/
1007  size_t left = 1;
1008  size_t right = array_size - 1;
1009  while(left <= right)
1010  {
1011  size_t mid = (left + right) / 2;
1012  if(array[mid] <= value) left = mid + 1; /*the value to find is more to the right*/
1013  else if(array[mid - 1] > value) right = mid - 1; /*the value to find is more to the left*/
1014  else return mid - 1;
1015  }
1016  return array_size - 1;
1017 }
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:228
static void setBitOfReversedStream ( size_t *  bitpointer,
unsigned char *  bitstream,
unsigned char  bit 
)
static

Definition at line 1832 of file lodepng.cpp.

1833 {
1834  /*the current bit in bitstream may be 0 or 1 for this to work*/
1835  if(bit == 0) bitstream[(*bitpointer) >> 3] &= (unsigned char)(~(1 << (7 - ((*bitpointer) & 0x7))));
1836  else bitstream[(*bitpointer) >> 3] |= (1 << (7 - ((*bitpointer) & 0x7)));
1837  (*bitpointer)++;
1838 }
static void ucvector_cleanup ( void *  p)
static

Definition at line 206 of file lodepng.cpp.

207 {
208  ((ucvector*)p)->size = ((ucvector*)p)->allocsize = 0;
209  free(((ucvector*)p)->data);
210  ((ucvector*)p)->data = NULL;
211 }
p
Definition: test.py:223
static void ucvector_init ( ucvector p)
static

Definition at line 243 of file lodepng.cpp.

244 {
245  p->data = NULL;
246  p->size = p->allocsize = 0;
247 }
size_t allocsize
Definition: lodepng.cpp:203
unsigned char * data
Definition: lodepng.cpp:201
size_t size
Definition: lodepng.cpp:202
static void ucvector_init_buffer ( ucvector p,
unsigned char *  buffer,
size_t  size 
)
static

Definition at line 251 of file lodepng.cpp.

252 {
253  p->data = buffer;
254  p->allocsize = p->size = size;
255 }
size_t allocsize
Definition: lodepng.cpp:203
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
unsigned char * data
Definition: lodepng.cpp:201
size_t size
Definition: lodepng.cpp:202
static unsigned ucvector_push_back ( ucvector p,
unsigned char  c 
)
static

Definition at line 258 of file lodepng.cpp.

259 {
260  if(!ucvector_resize(p, p->size + 1)) return 0;
261  p->data[p->size - 1] = c;
262  return 1;
263 }
unsigned char * data
Definition: lodepng.cpp:201
size_t size
Definition: lodepng.cpp:202
static unsigned ucvector_resize(ucvector *p, size_t size)
Definition: lodepng.cpp:213
static unsigned ucvector_resize ( ucvector p,
size_t  size 
)
static

Definition at line 213 of file lodepng.cpp.

214 {
215  if(size * sizeof(unsigned) > p->allocsize)
216  {
217  size_t newsize = size * sizeof(unsigned) * 2;
218  void* data = realloc(p->data, newsize);
219  if(data)
220  {
221  p->allocsize = newsize;
222  p->data = (unsigned char*)data;
223  p->size = size;
224  }
225  else return 0; /*error: not enough memory*/
226  }
227  else p->size = size;
228  return 1;
229 }
size_t allocsize
Definition: lodepng.cpp:203
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
unsigned char * data
Definition: lodepng.cpp:201
size_t size
Definition: lodepng.cpp:202
static void uivector_cleanup ( void *  p)
static

Definition at line 131 of file lodepng.cpp.

132 {
133  ((uivector*)p)->size = ((uivector*)p)->allocsize = 0;
134  free(((uivector*)p)->data);
135  ((uivector*)p)->data = NULL;
136 }
p
Definition: test.py:223
static unsigned uivector_copy ( uivector p,
const uivector q 
)
static

Definition at line 178 of file lodepng.cpp.

179 {
180  size_t i;
181  if(!uivector_resize(p, q->size)) return 0;
182  for(i = 0; i < q->size; i++) p->data[i] = q->data[i];
183  return 1;
184 }
static unsigned uivector_resize(uivector *p, size_t size)
Definition: lodepng.cpp:138
unsigned * data
Definition: lodepng.cpp:126
size_t size
Definition: lodepng.cpp:127
static void uivector_init ( uivector p)
static

Definition at line 164 of file lodepng.cpp.

165 {
166  p->data = NULL;
167  p->size = p->allocsize = 0;
168 }
size_t allocsize
Definition: lodepng.cpp:128
unsigned * data
Definition: lodepng.cpp:126
size_t size
Definition: lodepng.cpp:127
static unsigned uivector_push_back ( uivector p,
unsigned  c 
)
static

Definition at line 171 of file lodepng.cpp.

172 {
173  if(!uivector_resize(p, p->size + 1)) return 0;
174  p->data[p->size - 1] = c;
175  return 1;
176 }
static unsigned uivector_resize(uivector *p, size_t size)
Definition: lodepng.cpp:138
unsigned * data
Definition: lodepng.cpp:126
size_t size
Definition: lodepng.cpp:127
static unsigned uivector_resize ( uivector p,
size_t  size 
)
static

Definition at line 138 of file lodepng.cpp.

139 {
140  if(size * sizeof(unsigned) > p->allocsize)
141  {
142  size_t newsize = size * sizeof(unsigned) * 2;
143  void* data = realloc(p->data, newsize);
144  if(data)
145  {
146  p->allocsize = newsize;
147  p->data = (unsigned*)data;
148  p->size = size;
149  }
150  else return 0;
151  }
152  else p->size = size;
153  return 1;
154 }
size_t allocsize
Definition: lodepng.cpp:128
unsigned * data
Definition: lodepng.cpp:126
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
size_t size
Definition: lodepng.cpp:127
static unsigned uivector_resizev ( uivector p,
size_t  size,
unsigned  value 
)
static

Definition at line 156 of file lodepng.cpp.

157 {
158  size_t oldsize = p->size, i;
159  if(!uivector_resize(p, size)) return 0;
160  for(i = oldsize; i < size; i++) p->data[i] = value;
161  return 1;
162 }
static unsigned uivector_resize(uivector *p, size_t size)
Definition: lodepng.cpp:138
unsigned * data
Definition: lodepng.cpp:126
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
size_t size
Definition: lodepng.cpp:127
static void uivector_swap ( uivector p,
uivector q 
)
static

Definition at line 186 of file lodepng.cpp.

187 {
188  size_t tmp;
189  unsigned* tmpp;
190  tmp = p->size; p->size = q->size; q->size = tmp;
191  tmp = p->allocsize; p->allocsize = q->allocsize; q->allocsize = tmp;
192  tmpp = p->data; p->data = q->data; q->data = tmpp;
193 }
size_t allocsize
Definition: lodepng.cpp:128
unsigned * data
Definition: lodepng.cpp:126
size_t size
Definition: lodepng.cpp:127
string tmp
Definition: languages.py:63
static unsigned update_adler32 ( unsigned  adler,
const unsigned char *  data,
unsigned  len 
)
static

Definition at line 1558 of file lodepng.cpp.

1559 {
1560  unsigned s1 = adler & 0xffff;
1561  unsigned s2 = (adler >> 16) & 0xffff;
1562 
1563  while(len > 0)
1564  {
1565  /*at least 5550 sums can be done before the sums overflow, saving us from a lot of module divisions*/
1566  unsigned amount = len > 5550 ? 5550 : len;
1567  len -= amount;
1568  while(amount > 0)
1569  {
1570  s1 = (s1 + *data++);
1571  s2 = (s2 + s1);
1572  amount--;
1573  }
1574  s1 %= 65521;
1575  s2 %= 65521;
1576  }
1577 
1578  return (s2 << 16) | s1;
1579 }
static void vector_cleanup ( void *  p)
static

Definition at line 85 of file lodepng.cpp.

86 {
87  ((vector*)p)->size = ((vector*)p)->allocsize = 0;
88  free(((vector*)p)->data);
89  ((vector*)p)->data = NULL;
90 }
p
Definition: test.py:223
static void vector_cleanupd ( vector p,
void   dtorvoid * 
)
static

Definition at line 92 of file lodepng.cpp.

93 {
94  vector_resized(p, 0, dtor);
95  vector_cleanup(p);
96 }
static void vector_cleanup(void *p)
Definition: lodepng.cpp:85
static unsigned vector_resized(vector *p, size_t size, void dtor(void *))
Definition: lodepng.cpp:78
static void* vector_get ( vector p,
size_t  index 
)
static

Definition at line 114 of file lodepng.cpp.

115 {
116  return &((char*)p->data)[index * p->typesize];
117 }
void * data
Definition: lodepng.cpp:54
unsigned typesize
Definition: lodepng.cpp:57
static void vector_init ( vector p,
unsigned  typesize 
)
static

Definition at line 98 of file lodepng.cpp.

99 {
100  p->data = NULL;
101  p->size = p->allocsize = 0;
102  p->typesize = typesize;
103 }
void * data
Definition: lodepng.cpp:54
size_t allocsize
Definition: lodepng.cpp:56
size_t size
Definition: lodepng.cpp:55
unsigned typesize
Definition: lodepng.cpp:57
static unsigned vector_resize ( vector p,
size_t  size 
)
static

Definition at line 60 of file lodepng.cpp.

61 {
62  if(size * p->typesize > p->allocsize)
63  {
64  size_t newsize = size * p->typesize * 2;
65  void* data = realloc(p->data, newsize);
66  if(data)
67  {
68  p->allocsize = newsize;
69  p->data = data;
70  p->size = size;
71  }
72  else return 0;
73  }
74  else p->size = size;
75  return 1;
76 }
void * data
Definition: lodepng.cpp:54
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
size_t allocsize
Definition: lodepng.cpp:56
size_t size
Definition: lodepng.cpp:55
unsigned typesize
Definition: lodepng.cpp:57
static unsigned vector_resized ( vector p,
size_t  size,
void   dtorvoid * 
)
static

Definition at line 78 of file lodepng.cpp.

79 {
80  size_t i;
81  if(size < p->size) for(i = size; i < p->size; i++) dtor(&((char*)(p->data))[i * p->typesize]);
82  return vector_resize(p, size);
83 }
static unsigned vector_resize(vector *p, size_t size)
Definition: lodepng.cpp:60
void * data
Definition: lodepng.cpp:54
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
size_t size
Definition: lodepng.cpp:55
unsigned typesize
Definition: lodepng.cpp:57
static void vector_swap ( vector p,
vector q 
)
static

Definition at line 105 of file lodepng.cpp.

106 {
107  size_t tmp;
108  void* tmpp;
109  tmp = p->size; p->size = q->size; q->size = tmp;
110  tmp = p->allocsize; p->allocsize = q->allocsize; q->allocsize = tmp;
111  tmpp = p->data; p->data = q->data; q->data = tmpp;
112 }
void * data
Definition: lodepng.cpp:54
size_t allocsize
Definition: lodepng.cpp:56
size_t size
Definition: lodepng.cpp:55
string tmp
Definition: languages.py:63
static void writeLZ77data ( size_t *  bp,
ucvector out,
const uivector lz77_encoded,
const HuffmanTree codes,
const HuffmanTree codesD 
)
static

Definition at line 1301 of file lodepng.cpp.

1302 {
1303  size_t i = 0;
1304  for(i = 0; i < lz77_encoded->size; i++)
1305  {
1306  unsigned val = lz77_encoded->data[i];
1307  addHuffmanSymbol(bp, out, HuffmanTree_getCode(codes, val), HuffmanTree_getLength(codes, val));
1308  if(val > 256) /*for a length code, 3 more things have to be added*/
1309  {
1310  unsigned length_index = val - FIRST_LENGTH_CODE_INDEX;
1311  unsigned n_length_extra_bits = LENGTHEXTRA[length_index];
1312  unsigned length_extra_bits = lz77_encoded->data[++i];
1313 
1314  unsigned distance_code = lz77_encoded->data[++i];
1315 
1316  unsigned distance_index = distance_code;
1317  unsigned n_distance_extra_bits = DISTANCEEXTRA[distance_index];
1318  unsigned distance_extra_bits = lz77_encoded->data[++i];
1319 
1320  addBitsToStream(bp, out, length_extra_bits, n_length_extra_bits);
1321  addHuffmanSymbol(bp, out, HuffmanTree_getCode(codesD, distance_code), HuffmanTree_getLength(codesD, distance_code));
1322  addBitsToStream(bp, out, distance_extra_bits, n_distance_extra_bits);
1323  }
1324  }
1325 }
static void addBitsToStream(size_t *bitpointer, ucvector *bitstream, unsigned value, size_t nbits)
Definition: lodepng.cpp:314
static unsigned HuffmanTree_getLength(const HuffmanTree *tree, unsigned index)
Definition: lodepng.cpp:642
unsigned * data
Definition: lodepng.cpp:126
size_t size
Definition: lodepng.cpp:127
static const unsigned DISTANCEEXTRA[30]
Definition: lodepng.cpp:360
static const unsigned LENGTHEXTRA[29]
Definition: lodepng.cpp:356
static unsigned HuffmanTree_getCode(const HuffmanTree *tree, unsigned index)
Definition: lodepng.cpp:641
#define FIRST_LENGTH_CODE_INDEX
Definition: lodepng.cpp:347
static void addHuffmanSymbol(size_t *bp, ucvector *compressed, unsigned code, unsigned bitlen)
Definition: lodepng.cpp:994
static void writeSignature ( ucvector out)
static

Definition at line 3285 of file lodepng.cpp.

3286 {
3287  /*8 bytes PNG signature*/
3288  ucvector_push_back(out, 137);
3289  ucvector_push_back(out, 80);
3290  ucvector_push_back(out, 78);
3291  ucvector_push_back(out, 71);
3292  ucvector_push_back(out, 13);
3293  ucvector_push_back(out, 10);
3294  ucvector_push_back(out, 26);
3295  ucvector_push_back(out, 10);
3296 }
static unsigned ucvector_push_back(ucvector *p, unsigned char c)
Definition: lodepng.cpp:258

Variable Documentation

const unsigned ADAM7_DX[7] = { 8, 8, 4, 4, 2, 2, 1 }
static

Definition at line 2567 of file lodepng.cpp.

const unsigned ADAM7_DY[7] = { 8, 8, 8, 4, 4, 2, 2 }
static

Definition at line 2568 of file lodepng.cpp.

const unsigned ADAM7_IX[7] = { 0, 4, 0, 2, 0, 1, 0 }
static

Definition at line 2565 of file lodepng.cpp.

const unsigned ADAM7_IY[7] = { 0, 0, 4, 0, 2, 0, 1 }
static

Definition at line 2566 of file lodepng.cpp.

const unsigned CLCL[NUM_CODE_LENGTH_CODES] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}
static

Definition at line 362 of file lodepng.cpp.

unsigned Crc32_crc_table[256]
static

Definition at line 1763 of file lodepng.cpp.

unsigned Crc32_crc_table_computed = 0
static

Definition at line 1762 of file lodepng.cpp.

const unsigned DISTANCEBASE[30] = {1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577}
static

Definition at line 358 of file lodepng.cpp.

const unsigned DISTANCEEXTRA[30] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13}
static

Definition at line 360 of file lodepng.cpp.

const unsigned LENGTHBASE[29] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258}
static

Definition at line 354 of file lodepng.cpp.

const unsigned LENGTHEXTRA[29] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0}
static

Definition at line 356 of file lodepng.cpp.

const LodeZlib_DeflateSettings LodeZlib_defaultDeflateSettings = {2, 1, 2048}

Definition at line 1704 of file lodepng.cpp.

const size_t MAX_SUPPORTED_DEFLATE_LENGTH = 258
static

Definition at line 991 of file lodepng.cpp.