Lines Matching full:in
7 warranty. In no event will the authors be held liable for any damages
16 in a product, an acknowledgment in the product documentation would be
27 The manual and changelog are in the header file "lodepng.h"
50 This source file is built up in the following large parts. The code sections
51 with the "LODEPNG_COMPILE_" #defines divide this up further in an intermixed way.
64 /*The malloc, realloc and free functions defined here with "lodepng_" in front
66 platform if needed. Everything else in the code calls these. Pass
68 #define LODEPNG_COMPILE_ALLOCATORS in the header, to disable the ones here and
69 define them in your own project's source files without needing to change
100 /* inline is not available in C90, but use it when supported by the compiler */
107 /* restrict is not available in C90, but use it when supported by the compiler */
133 /* avoid warning about unused function in case of disabled COMPILE... macros */ in lodepng_strlen()
147 *result = a + b; /* Unsigned addition is well defined and safe in C90 */ in lodepng_addofl()
156 *result = a * b; /* Unsigned multiplication is well defined and safe in C90 */ in lodepng_mulofl()
172 Often in case of an error a value is assigned to a variable and then it breaks
206 -All of them wrap dynamic arrays or text strings in a similar way.
207 -LodePNG was originally written in C++. The vectors replace the std::vectors that were used in the …
209 -They're not used in the interface, only internally in this file as static functions.
210 -As with many other structs in this file, the init and cleanup functions serve as ctor and dtor.
218 size_t size; /*size in number of unsigned longs*/
219 size_t allocsize; /*allocated size in bytes*/
301 static char* alloc_string_sized(const char* in, size_t insize) { in alloc_string_sized() argument
304 lodepng_memcpy(out, in, insize); in alloc_string_sized()
311 static char* alloc_string(const char* in) { in alloc_string() argument
312 return alloc_string_sized(in, lodepng_strlen(in)); in alloc_string()
432 /* TODO: increase output size only once here rather than in each WRITEBIT */ in writeBits()
444 /* TODO: increase output size only once here rather than in each WRITEBIT */ in writeBitsReversed()
454 size_t size; /*size of data in bytes*/
455 size_t bitsize; /*size of data in bits, end of valid bp values, should be 8*size*/
460 /* data size argument is in bytes. Returns error if size too large causing overflow */
465 /* size in bits, return error if overflow (if size_t is 32 bit this supports up to 500MB) */ in LodePNGBitReader_init()
477 Ensures the reader can at least read nbits bits in one or more readBits calls,
646 /*the order in which "code length alphabet code lengths" are stored as specified by deflate, out of…
660 unsigned numcodes; /*number of symbols in the alphabet = number of codes*/
685 which is possible in case of only 0 or 1 present symbols. */
696 /* compute maxlens: max total bit length of symbols sharing prefix in the first table*/ in HuffmanTree_makeTable()
702 …if(l <= FIRSTBITS) continue; /*symbols that fit in first table don't increase secondary table size… in HuffmanTree_makeTable()
723 /*fill in the first table for long symbols: max prefix size and pointer to secondary tables*/ in HuffmanTree_makeTable()
734 /*fill in the first table for short symbols, or secondary table for long symbols*/ in HuffmanTree_makeTable()
739 …/*reverse bits, because the huffman bits are given in MSB first order but the bit reader reads LSB… in HuffmanTree_makeTable()
745 /*short symbol, fully in first table, replicated num times if l < FIRSTBITS*/ in HuffmanTree_makeTable()
756 … /*long symbol, shares prefix with other long symbols in first lookup table, needs second lookup*/ in HuffmanTree_makeTable()
762 unsigned start = tree->table_value[index]; /*starting index in secondary table*/ in HuffmanTree_makeTable()
763 …unsigned num = 1u << (tablelen - (l - FIRSTBITS)); /*amount of entries of this symbol in secondary… in HuffmanTree_makeTable()
776 /* In case of exactly 1 symbol, in theory the huffman symbol needs 0 bits, in HuffmanTree_makeTable()
777 but deflate uses 1 bit instead. In case of 0 symbols, no symbols can in HuffmanTree_makeTable()
779 codes are never used). In both cases, not all symbols of the table will be in HuffmanTree_makeTable()
780 filled in. Fill them in with an invalid symbol value so returning them from in HuffmanTree_makeTable()
806 numcodes, lengths and maxbitlen must already be filled in correctly. return
846 given the code lengths (as stored in the PNG file), generate the tree as defined
847 by Deflate. maxbitlen is the maximum bits that a code in the tree can have.
868 int weight; /*the sum of all weights in this chain*/
869 unsigned index; /*index of this leaf node (called "count" in the paper)*/
870 struct BPMNode* tail; /*the next nodes in this chain (null if last)*/
888 /*creates a new chain node with the given parameters, from the memory in the lists */
895 /*mark only those that are in use*/ in bpmnode_create()
957 /*in the end we are only interested in the chain of the last list, so no in boundaryPM()
993 symbol, it'd give it the theoretical 0 bits but in practice zlib wants 1 bit*/ in lodepng_huffman_code_lengths()
1078 /*get the distance code tree of a deflated block with fixed tree, as specified in the deflate speci…
1120 /*get the tree of a deflated block with fixed tree, as specified in the deflate specification
1131 …/*make sure that length values that aren't filled in will be 0, or a wrong tree will be generated*/ in getTreeInflateDynamic()
1135 …/*see comments in deflateDynamic for explanation of the context and these variables, it is analogo… in getTreeInflateDynamic()
1179 …/*i is the current symbol we're reading in the part that contains the code lengths of lit/len and … in getTreeInflateDynamic()
1190 unsigned replength = 3; /*read in the 2 bits that indicate repeat length (3-6)*/ in getTreeInflateDynamic()
1199 /*repeat this value in the next lengths*/ in getTreeInflateDynamic()
1207 unsigned replength = 3; /*read in the bits that indicate repeat length*/ in getTreeInflateDynamic()
1210 /*repeat this value in the next lengths*/ in getTreeInflateDynamic()
1219 unsigned replength = 11; /*read in the bits that indicate repeat length*/ in getTreeInflateDynamic()
1222 /*repeat this value in the next lengths*/ in getTreeInflateDynamic()
1235 /*return error code 10 or 11 depending on the situation that happened in huffmanDecodeSymbol in getTreeInflateDynamic()
1316 /*part 5: fill in all the out[n] values based on the length and dist*/ in inflateHuffmanBlock()
1339 /*return error code 10 or 11 depending on the situation that happened in huffmanDecodeSymbol in inflateHuffmanBlock()
1376 /*read the literal data: LEN bytes are now stored in the out buffer*/ in inflateNoCompression()
1377 if(bytepos + LEN > size) return 23; /*error: reading outside of in buffer*/ in inflateNoCompression()
1388 const unsigned char* in, size_t insize, in lodepng_inflatev() argument
1392 unsigned error = LodePNGBitReader_init(&reader, in, insize); in lodepng_inflatev()
1413 const unsigned char* in, size_t insize, in lodepng_inflate() argument
1416 unsigned error = lodepng_inflatev(&v, in, insize, settings); in lodepng_inflate()
1422 static unsigned inflatev(ucvector* out, const unsigned char* in, size_t insize, in inflatev() argument
1425 unsigned error = settings->custom_inflate(&out->data, &out->size, in, insize, settings); in inflatev()
1435 return lodepng_inflatev(out, in, insize, settings); in inflatev()
1449 /*search the index in the array, that has the largest value smaller than or equal to the given valu…
1466 /*values in encoded vector are those used by deflate: in addLengthDistance()
1548 effect on speed in traversing the chain, and causes more time spend on in getHash()
1585 is in the form of unsigned integers with codes representing for example literal bytes, or
1588 sliding window (of windowsize) is used, and all past bytes in that window can be used as
1593 … const unsigned char* in, size_t inpos, size_t insize, unsigned windowsize, in encodeLZ77() argument
1604 unsigned offset; /*the offset represents the distance in LZ77 terminology*/ in encodeLZ77()
1620 size_t wpos = pos & (windowsize - 1); /*position for in 'circular' hash buffers*/ in encodeLZ77()
1623 hashval = getHash(in, insize, pos); in encodeLZ77()
1626 if(numzeros == 0) numzeros = countZeros(in, insize, pos); in encodeLZ77()
1627 else if(pos + numzeros > insize || in[pos + numzeros - 1] != 0) --numzeros; in encodeLZ77()
1640 …lastptr = &in[insize < pos + MAX_SUPPORTED_DEFLATE_LENGTH ? insize : pos + MAX_SUPPORTED_DEFLATE_L… in encodeLZ77()
1652 foreptr = &in[pos]; in encodeLZ77()
1653 backptr = &in[pos - current_offset]; in encodeLZ77()
1655 /*common case in PNGs is lots of zeros. Quickly skip over them as a speedup*/ in encodeLZ77()
1667 current_length = (unsigned)(foreptr - &in[pos]); in encodeLZ77()
1685 … /*outdated hash value, happens if particular value was not encountered in whole last window*/ in encodeLZ77()
1702 if(!uivector_push_back(out, in[pos - 1])) ERROR_BREAK(83 /*alloc fail*/); in encodeLZ77()
1716 if(!uivector_push_back(out, in[pos])) ERROR_BREAK(83 /*alloc fail*/); in encodeLZ77()
1720 if(!uivector_push_back(out, in[pos])) ERROR_BREAK(83 /*alloc fail*/); in encodeLZ77()
1726 hashval = getHash(in, insize, pos); in encodeLZ77()
1728 if(numzeros == 0) numzeros = countZeros(in, insize, pos); in encodeLZ77()
1729 else if(pos + numzeros > insize || in[pos + numzeros - 1] != 0) --numzeros; in encodeLZ77()
1812 A block is compressed as follows: The PNG data is lz77 encoded, resulting in in deflateDynamic()
1822 … encoded data, represented with integers since there will also be length and distance codes in it*/ in deflateDynamic()
1836 …tree_cl in CLCL_ORDER, then due to the huffman compression of huffman tree representations ("two l… in deflateDynamic()
1890 …/*2, not 1, is chosen for mincodes: some buggy PNG decoders require at least 2 symbols in the dist… in deflateDynamic()
1896 /*store the code lengths of both generated trees in bitlen_lld*/ in deflateDynamic()
1947 those don't need to be in the frequencies_cl calculation*/ in deflateDynamic()
1983 or in the loop for numcodes_cl above, which saves space. */ in deflateDynamic()
2073 static unsigned lodepng_deflatev(ucvector* out, const unsigned char* in, size_t insize, in lodepng_deflatev() argument
2083 else if(settings->btype == 0) return deflateNoCompression(out, in, insize); in lodepng_deflatev()
2104 … if(settings->btype == 1) error = deflateFixed(&writer, &hash, in, start, end, settings, final); in lodepng_deflatev()
2105 …else if(settings->btype == 2) error = deflateDynamic(&writer, &hash, in, start, end, settings, fin… in lodepng_deflatev()
2115 const unsigned char* in, size_t insize, in lodepng_deflate() argument
2118 unsigned error = lodepng_deflatev(&v, in, insize, settings); in lodepng_deflate()
2125 const unsigned char* in, size_t insize, in deflate() argument
2128 unsigned error = settings->custom_deflate(out, outsize, in, insize, settings); in deflate()
2132 return lodepng_deflate(out, outsize, in, insize, settings); in deflate()
2174 const unsigned char* in, size_t insize, in lodepng_zlib_decompressv() argument
2181 if((in[0] * 256 + in[1]) % 31 != 0) { in lodepng_zlib_decompressv()
2182 …/*error: 256 * in[0] + in[1] must be a multiple of 31, the FCHECK value is supposed to be made tha… in lodepng_zlib_decompressv()
2186 CM = in[0] & 15; in lodepng_zlib_decompressv()
2187 CINFO = (in[0] >> 4) & 15; in lodepng_zlib_decompressv()
2188 /*FCHECK = in[1] & 31;*/ /*FCHECK is already tested above*/ in lodepng_zlib_decompressv()
2189 FDICT = (in[1] >> 5) & 1; in lodepng_zlib_decompressv()
2190 /*FLEVEL = (in[1] >> 6) & 3;*/ /*FLEVEL is not used here*/ in lodepng_zlib_decompressv()
2202 error = inflatev(out, in + 2, insize - 2, settings); in lodepng_zlib_decompressv()
2206 unsigned ADLER32 = lodepng_read32bitInt(&in[insize - 4]); in lodepng_zlib_decompressv()
2215 unsigned lodepng_zlib_decompress(unsigned char** out, size_t* outsize, const unsigned char* in, in lodepng_zlib_decompress() argument
2218 unsigned error = lodepng_zlib_decompressv(&v, in, insize, settings); in lodepng_zlib_decompress()
2226 … const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) { in zlib_decompress() argument
2229 error = settings->custom_zlib(out, outsize, in, insize, settings); in zlib_decompress()
2243 error = lodepng_zlib_decompressv(&v, in, insize, settings); in zlib_decompress()
2254 unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, const unsigned char* in, in lodepng_zlib_compress() argument
2261 error = deflate(&deflatedata, &deflatesize, in, insize, settings); in lodepng_zlib_compress()
2272 unsigned ADLER32 = adler32(in, (unsigned)insize); in lodepng_zlib_compress()
2292 static unsigned zlib_compress(unsigned char** out, size_t* outsize, const unsigned char* in, in zlib_compress() argument
2295 unsigned error = settings->custom_zlib(out, outsize, in, insize, settings); in zlib_compress()
2299 return lodepng_zlib_compress(out, outsize, in, insize, settings); in zlib_compress()
2309 … const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) { in zlib_decompress() argument
2312 return settings->custom_zlib(out, outsize, in, insize, settings); in zlib_decompress()
2316 static unsigned zlib_compress(unsigned char** out, size_t* outsize, const unsigned char* in, in zlib_compress() argument
2319 return settings->custom_zlib(out, outsize, in, insize, settings); in zlib_compress()
2333 …/*compress with dynamic huffman tree (not in the mathematical sense, just not the predefined one)*/ in lodepng_compress_settings_init()
2455 /*the current bit in bitstream may be 0 or 1 for this to work*/ in setBitOfReversedStream()
2587 set data or crc yet. Returns the start of the chunk in chunk. The start of
2682 …/*if the palette is already allocated, it will have size 1024 so no reallocation needed in that ca… in lodepng_color_mode_alloc_palette()
2808 /*in an idat chunk, each scanline is a multiple of 8 bits, unlike the lodepng output buffer,
2809 and in addition has one extra byte per line: the filter byte. So this gives a larger
2821 you can safely compute in a size_t (but not an unsigned):
2823 -amount of bytes in IDAT (including filter, padding and Adam7 bytes)
2824 -amount of bytes in raw color model
2831 size_t line; /* bytes per line in worst case */ in lodepng_pixel_overflow()
2841 if(lodepng_mulofl(line, h, &total)) return 1; /* Total bytes in worst case */ in lodepng_pixel_overflow()
3094 /*index: bitgroup index, bits: bitgroup size(1, 2 or 4), in: bitgroup value, out: octet array to ad…
3095 static void addColorBits(unsigned char* out, size_t index, unsigned bits, unsigned in) { in addColorBits() argument
3097 …/*p = the partial index in the byte, e.g. with 4 palettebits it is 0 for first half or 1 for secon… in addColorBits()
3099 in &= (1u << bits) - 1u; /*filter out any other bits of the input value*/ in addColorBits()
3100 in = in << (bits * (m - p)); in addColorBits()
3101 if(p == 0) out[index * bits / 8u] = in; in addColorBits()
3102 else out[index * bits / 8u] |= in; in addColorBits()
3115 int index; /*the payload. Only has a meaningful value if this is in the last level*/
3194 if(index < 0) return 82; /*color not in palette*/ in rgba8ToPixel()
3259 const unsigned char* in, size_t i, in getPixelColorRGBA8() argument
3263 *r = *g = *b = in[i]; in getPixelColorRGBA8()
3267 *r = *g = *b = in[i * 2 + 0]; in getPixelColorRGBA8()
3268 if(mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r) *a = 0; in getPixelColorRGBA8()
3273 unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth); in getPixelColorRGBA8()
3280 *r = in[i * 3 + 0]; *g = in[i * 3 + 1]; *b = in[i * 3 + 2]; in getPixelColorRGBA8()
3284 *r = in[i * 6 + 0]; in getPixelColorRGBA8()
3285 *g = in[i * 6 + 2]; in getPixelColorRGBA8()
3286 *b = in[i * 6 + 4]; in getPixelColorRGBA8()
3287 if(mode->key_defined && 256U * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r in getPixelColorRGBA8()
3288 && 256U * in[i * 6 + 2] + in[i * 6 + 3] == mode->key_g in getPixelColorRGBA8()
3289 && 256U * in[i * 6 + 4] + in[i * 6 + 5] == mode->key_b) *a = 0; in getPixelColorRGBA8()
3294 if(mode->bitdepth == 8) index = in[i]; in getPixelColorRGBA8()
3297 index = readBitsFromReversedStream(&j, in, mode->bitdepth); in getPixelColorRGBA8()
3306 *r = *g = *b = in[i * 2 + 0]; in getPixelColorRGBA8()
3307 *a = in[i * 2 + 1]; in getPixelColorRGBA8()
3309 *r = *g = *b = in[i * 4 + 0]; in getPixelColorRGBA8()
3310 *a = in[i * 4 + 2]; in getPixelColorRGBA8()
3314 *r = in[i * 4 + 0]; in getPixelColorRGBA8()
3315 *g = in[i * 4 + 1]; in getPixelColorRGBA8()
3316 *b = in[i * 4 + 2]; in getPixelColorRGBA8()
3317 *a = in[i * 4 + 3]; in getPixelColorRGBA8()
3319 *r = in[i * 8 + 0]; in getPixelColorRGBA8()
3320 *g = in[i * 8 + 2]; in getPixelColorRGBA8()
3321 *b = in[i * 8 + 4]; in getPixelColorRGBA8()
3322 *a = in[i * 8 + 6]; in getPixelColorRGBA8()
3332 const unsigned char* LODEPNG_RESTRICT in, in getPixelColorsRGBA8() argument
3339 buffer[0] = buffer[1] = buffer[2] = in[i]; in getPixelColorsRGBA8()
3350 buffer[0] = buffer[1] = buffer[2] = in[i * 2]; in getPixelColorsRGBA8()
3351 … buffer[3] = mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r ? 0 : 255; in getPixelColorsRGBA8()
3357 unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth); in getPixelColorsRGBA8()
3365 lodepng_memcpy(buffer, &in[i * 3], 3); in getPixelColorsRGBA8()
3376 buffer[0] = in[i * 6 + 0]; in getPixelColorsRGBA8()
3377 buffer[1] = in[i * 6 + 2]; in getPixelColorsRGBA8()
3378 buffer[2] = in[i * 6 + 4]; in getPixelColorsRGBA8()
3380 && 256U * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r in getPixelColorsRGBA8()
3381 && 256U * in[i * 6 + 2] + in[i * 6 + 3] == mode->key_g in getPixelColorsRGBA8()
3382 && 256U * in[i * 6 + 4] + in[i * 6 + 5] == mode->key_b ? 0 : 255; in getPixelColorsRGBA8()
3388 unsigned index = in[i]; in getPixelColorsRGBA8()
3395 unsigned index = readBitsFromReversedStream(&j, in, mode->bitdepth); in getPixelColorsRGBA8()
3403 buffer[0] = buffer[1] = buffer[2] = in[i * 2 + 0]; in getPixelColorsRGBA8()
3404 buffer[3] = in[i * 2 + 1]; in getPixelColorsRGBA8()
3408 buffer[0] = buffer[1] = buffer[2] = in[i * 4 + 0]; in getPixelColorsRGBA8()
3409 buffer[3] = in[i * 4 + 2]; in getPixelColorsRGBA8()
3414 lodepng_memcpy(buffer, in, numpixels * 4); in getPixelColorsRGBA8()
3417 buffer[0] = in[i * 8 + 0]; in getPixelColorsRGBA8()
3418 buffer[1] = in[i * 8 + 2]; in getPixelColorsRGBA8()
3419 buffer[2] = in[i * 8 + 4]; in getPixelColorsRGBA8()
3420 buffer[3] = in[i * 8 + 6]; in getPixelColorsRGBA8()
3428 const unsigned char* LODEPNG_RESTRICT in, in getPixelColorsRGB8() argument
3435 buffer[0] = buffer[1] = buffer[2] = in[i]; in getPixelColorsRGB8()
3439 buffer[0] = buffer[1] = buffer[2] = in[i * 2]; in getPixelColorsRGB8()
3445 unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth); in getPixelColorsRGB8()
3451 lodepng_memcpy(buffer, in, numpixels * 3); in getPixelColorsRGB8()
3454 buffer[0] = in[i * 6 + 0]; in getPixelColorsRGB8()
3455 buffer[1] = in[i * 6 + 2]; in getPixelColorsRGB8()
3456 buffer[2] = in[i * 6 + 4]; in getPixelColorsRGB8()
3462 unsigned index = in[i]; in getPixelColorsRGB8()
3469 unsigned index = readBitsFromReversedStream(&j, in, mode->bitdepth); in getPixelColorsRGB8()
3477 buffer[0] = buffer[1] = buffer[2] = in[i * 2 + 0]; in getPixelColorsRGB8()
3481 buffer[0] = buffer[1] = buffer[2] = in[i * 4 + 0]; in getPixelColorsRGB8()
3487 lodepng_memcpy(buffer, &in[i * 4], 3); in getPixelColorsRGB8()
3491 buffer[0] = in[i * 8 + 0]; in getPixelColorsRGB8()
3492 buffer[1] = in[i * 8 + 2]; in getPixelColorsRGB8()
3493 buffer[2] = in[i * 8 + 4]; in getPixelColorsRGB8()
3502 const unsigned char* in, size_t i, const LodePNGColorMode* mode) { in getPixelColorRGBA16() argument
3504 *r = *g = *b = 256 * in[i * 2 + 0] + in[i * 2 + 1]; in getPixelColorRGBA16()
3505 if(mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r) *a = 0; in getPixelColorRGBA16()
3508 *r = 256u * in[i * 6 + 0] + in[i * 6 + 1]; in getPixelColorRGBA16()
3509 *g = 256u * in[i * 6 + 2] + in[i * 6 + 3]; in getPixelColorRGBA16()
3510 *b = 256u * in[i * 6 + 4] + in[i * 6 + 5]; in getPixelColorRGBA16()
3512 && 256u * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r in getPixelColorRGBA16()
3513 && 256u * in[i * 6 + 2] + in[i * 6 + 3] == mode->key_g in getPixelColorRGBA16()
3514 && 256u * in[i * 6 + 4] + in[i * 6 + 5] == mode->key_b) *a = 0; in getPixelColorRGBA16()
3517 *r = *g = *b = 256u * in[i * 4 + 0] + in[i * 4 + 1]; in getPixelColorRGBA16()
3518 *a = 256u * in[i * 4 + 2] + in[i * 4 + 3]; in getPixelColorRGBA16()
3520 *r = 256u * in[i * 8 + 0] + in[i * 8 + 1]; in getPixelColorRGBA16()
3521 *g = 256u * in[i * 8 + 2] + in[i * 8 + 3]; in getPixelColorRGBA16()
3522 *b = 256u * in[i * 8 + 4] + in[i * 8 + 5]; in getPixelColorRGBA16()
3523 *a = 256u * in[i * 8 + 6] + in[i * 8 + 7]; in getPixelColorRGBA16()
3527 unsigned lodepng_convert(unsigned char* out, const unsigned char* in, in lodepng_convert() argument
3541 lodepng_memcpy(out, in, numbytes); in lodepng_convert()
3556 equal, so copy literally. This to preserve the exact indices that were in the PNG in lodepng_convert()
3557 even in case there are duplicate colors in the palette.*/ in lodepng_convert()
3560 lodepng_memcpy(out, in, numbytes); in lodepng_convert()
3577 getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode_in); in lodepng_convert()
3581 getPixelColorsRGBA8(out, numpixels, in, mode_in); in lodepng_convert()
3583 getPixelColorsRGB8(out, numpixels, in, mode_in); in lodepng_convert()
3587 getPixelColorRGBA8(&r, &g, &b, &a, in, i, mode_in); in lodepng_convert()
3603 their bitdepth. In case of single channel (gray or palette), only the r channel is used. Slow
3605 this is for bKGD, supporting alpha may prevent it from finding a color in the palette, from the
3640 /* a 16-bit color cannot be in the palette */ in lodepng_convert_rgb()
3696 const unsigned char* in, unsigned w, unsigned h, in lodepng_compute_color_stats() argument
3720 /*If the stats was already filled in from previous data, fill its palette in tree in lodepng_compute_color_stats()
3740 getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode_in); in lodepng_compute_color_stats()
3756 getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode_in); in lodepng_compute_color_stats()
3786 getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode_in); in lodepng_compute_color_stats()
3798 getPixelColorRGBA8(&r, &g, &b, &a, in, i, mode_in); in lodepng_compute_color_stats()
3856 getPixelColorRGBA8(&r, &g, &b, &a, in, i, mode_in); in lodepng_compute_color_stats()
3901 Minimal PNG color model means the color type and bit depth that gives smallest amount of bits in th…
3994 Outputs various dimensions and positions in the image related to the Adam7 reduced images.
4013 /*calculate width and height in pixels of each pass*/ in Adam7_getpassvalues()
4039 /*read the information from the header and store it in the LodePNGInfo. return value is error*/
4041 const unsigned char* in, size_t insize) { in lodepng_inspect() argument
4044 if(insize == 0 || in == 0) { in lodepng_inspect()
4056 if(in[0] != 137 || in[1] != 80 || in[2] != 78 || in[3] != 71 in lodepng_inspect()
4057 || in[4] != 13 || in[5] != 10 || in[6] != 26 || in[7] != 10) { in lodepng_inspect()
4060 if(lodepng_chunk_length(in + 8) != 13) { in lodepng_inspect()
4063 if(!lodepng_chunk_type_equals(in + 8, "IHDR")) { in lodepng_inspect()
4067 /*read the values given in the header*/ in lodepng_inspect()
4068 width = lodepng_read32bitInt(&in[16]); in lodepng_inspect()
4069 height = lodepng_read32bitInt(&in[20]); in lodepng_inspect()
4073 info->color.bitdepth = in[24]; in lodepng_inspect()
4074 info->color.colortype = (LodePNGColorType)in[25]; in lodepng_inspect()
4075 info->compression_method = in[26]; in lodepng_inspect()
4076 info->filter_method = in[27]; in lodepng_inspect()
4077 info->interlace_method = in[28]; in lodepng_inspect()
4086 /*error: only compression method 0 is allowed in the specification*/ in lodepng_inspect()
4088 /*error: only filter method 0 is allowed in the specification*/ in lodepng_inspect()
4090 /*error: only interlace methods 0 and 1 exist in the specification*/ in lodepng_inspect()
4094 unsigned CRC = lodepng_read32bitInt(&in[29]); in lodepng_inspect()
4095 unsigned checksum = lodepng_crc32(&in[12], 17); in lodepng_inspect()
4111 …the incoming scanlines do NOT include the filtertype byte, that one is given in the parameter filt… in unfilterScanline()
4201 static unsigned unfilter(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, unsig… in unfilter() argument
4205 …out must have enough bytes allocated already, in must have the scanlines + 1 filtertype byte per s… in unfilter()
4207 …in and out are allowed to be the same memory address (but aren't the same size since in has the ex… in unfilter()
4215 /*the width of a scanline in bytes, not including the filter type*/ in unfilter()
4221 unsigned char filterType = in[inindex]; in unfilter()
4223 …CERROR_TRY_RETURN(unfilterScanline(&out[outindex], &in[inindex + 1], prevline, bytewidth, filterTy… in unfilter()
4232 in: Adam7 interlaced image, with no padding bits between scanlines, but between
4236 out has the following size in bits: w * h * bpp.
4237 in is possibly bigger due to padding bits between reduced images.
4238 out must be big enough AND must be 0 everywhere if bpp < 8 in the current implementation
4242 static void Adam7_deinterlace(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, … in Adam7_deinterlace() argument
4259 out[pixeloutstart + b] = in[pixelinstart + b]; in Adam7_deinterlace()
4268 size_t obp, ibp; /*bit pointers (for out and in buffer)*/ in Adam7_deinterlace()
4274 unsigned char bit = readBitFromReversedStream(&ibp, in); in Adam7_deinterlace()
4282 static void removePaddingBits(unsigned char* out, const unsigned char* in, in removePaddingBits() argument
4288 in and out are allowed to be the same buffer, in may also be higher but still overlapping; in must in removePaddingBits()
4290 …also used to move bits after earlier such operations happened, e.g. in a sequence of reduced image… in removePaddingBits()
4291 only useful if (ilinebits - olinebits) is a value in the range 1..7 in removePaddingBits()
4299 unsigned char bit = readBitFromReversedStream(&ibp, in); in removePaddingBits()
4306 /*out must be buffer big enough to contain full image, and in must contain the full decompressed da…
4309 static unsigned postProcessScanlines(unsigned char* out, unsigned char* in, in postProcessScanlines() argument
4316 NOTE: the in buffer will be overwritten with intermediate data! in postProcessScanlines()
4323 CERROR_TRY_RETURN(unfilter(in, in, w, h, bpp)); in postProcessScanlines()
4324 removePaddingBits(out, in, w * bpp, ((w * bpp + 7u) / 8u) * 8u, h); in postProcessScanlines()
4327 else CERROR_TRY_RETURN(unfilter(out, in, w, h, bpp)); in postProcessScanlines()
4335 …CERROR_TRY_RETURN(unfilter(&in[padded_passstart[i]], &in[filter_passstart[i]], passw[i], passh[i],… in postProcessScanlines()
4336 …/*TODO: possible efficiency improvement: if in this reduced image the bits fit nicely in 1 scanlin… in postProcessScanlines()
4339 /*remove padding bits in scanlines; after this there still may be padding in postProcessScanlines()
4341 removePaddingBits(&in[passstart[i]], &in[padded_passstart[i]], passw[i] * bpp, in postProcessScanlines()
4346 Adam7_deinterlace(out, in, w, h, bpp); in postProcessScanlines()
4416 /*the values are truncated to bitdepth in the PNG file*/ in readChunk_bKGD()
4423 /*the values are truncated to bitdepth in the PNG file*/ in readChunk_bKGD()
4478 /*copy the object to change parameters in it*/ in readChunk_zTXt()
4526 /*copy the object to change parameters in it*/ in readChunk_iTXt()
4671 /*copy the object to change parameters in it*/ in readChunk_iCCP()
4708 const unsigned char* in, size_t insize) { in lodepng_inspect_chunk() argument
4709 const unsigned char* chunk = in + pos; in lodepng_inspect_chunk()
4719 if(data + chunkLength + 4 > in + insize) return 30; in lodepng_inspect_chunk()
4759 /*read a PNG, the result will be in the same color type as the PNG (hence "generic")*/
4762 const unsigned char* in, size_t insize) { in decodeGeneric() argument
4778 /* safe output values in case error happens */ in decodeGeneric()
4782 …state->error = lodepng_inspect(w, h, state, in, insize); /*reads header and resets other parameter… in decodeGeneric()
4793 chunk = &in[33]; /*first byte of the first chunk after the header*/ in decodeGeneric()
4796 IDAT data is put at the start of the in buffer*/ in decodeGeneric()
4799 const unsigned char* data; /*the data in the chunk*/ in decodeGeneric()
4801 /*error: size of the in buffer too small to contain next chunk*/ in decodeGeneric()
4802 if((size_t)((chunk - in) + 12) > insize || chunk < in) { in decodeGeneric()
4815 if((size_t)((chunk - in) + chunkLength + 12) > insize || (chunk + chunkLength + 12) < in) { in decodeGeneric()
4816 … CERROR_BREAK(state->error, 64); /*error: size of the in buffer too small to contain next chunk*/ in decodeGeneric()
4845 … in without 'LODEPNG_COMPILE_ANCILLARY_CHUNKS' because it contains essential color information that in decodeGeneric()
4911 if(!IEND) chunk = lodepng_chunk_next_const(chunk, in + insize); in decodeGeneric()
4956 const unsigned char* in, size_t insize) { in lodepng_decode() argument
4958 decodeGeneric(out, w, h, state, in, insize); in lodepng_decode()
4972 …/*TODO: check if this works according to the statement in the documentation: "The converter can co… in lodepng_decode()
4991 …igned lodepng_decode_memory(unsigned char** out, unsigned* w, unsigned* h, const unsigned char* in, in lodepng_decode_memory() argument
5003 error = lodepng_decode(out, w, h, &state, in, insize); in lodepng_decode_memory()
5008 unsigned lodepng_decode32(unsigned char** out, unsigned* w, unsigned* h, const unsigned char* in, s… in lodepng_decode32() argument
5009 return lodepng_decode_memory(out, w, h, in, insize, LCT_RGBA, 8); in lodepng_decode32()
5012 unsigned lodepng_decode24(unsigned char** out, unsigned* w, unsigned* h, const unsigned char* in, s… in lodepng_decode24() argument
5013 return lodepng_decode_memory(out, w, h, in, insize, LCT_RGB, 8); in lodepng_decode24()
5022 /* safe output values in case error happens */ in lodepng_decode_file()
5447 static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, in filter() argument
5456 /*the width of a scanline in bytes, not including the filter type*/ in filter()
5490 filterScanline(&out[outindex + 1], &in[inindex], prevline, linebytes, bytewidth, type); in filter()
5491 prevline = &in[inindex]; in filter()
5509 filterScanline(attempt[type], &in[y * linebytes], prevline, linebytes, bytewidth, type); in filter()
5531 prevline = &in[y * linebytes]; in filter()
5556 filterScanline(attempt[type], &in[y * linebytes], prevline, linebytes, bytewidth, type); in filter()
5570 prevline = &in[y * linebytes]; in filter()
5585 filterScanline(&out[outindex + 1], &in[inindex], prevline, linebytes, bytewidth, type); in filter()
5586 prevline = &in[inindex]; in filter()
5601 better result with dynamic tree anyway. Using the fixed tree sometimes gives worse, but in rare in filter()
5618 filterScanline(attempt[type], &in[y * linebytes], prevline, linebytes, bytewidth, type); in filter()
5629 prevline = &in[y * linebytes]; in filter()
5641 static void addPaddingBits(unsigned char* out, const unsigned char* in, in addPaddingBits() argument
5651 unsigned char bit = readBitFromReversedStream(&ibp, in); in addPaddingBits()
5654 /*obp += diff; --> no, fill in some value in the padding bits too, to avoid in addPaddingBits()
5661 in: non-interlaced image with size w*h
5667 in has the following size in bits: w * h * bpp.
5671 static void Adam7_interlace(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, un… in Adam7_interlace() argument
5687 out[pixeloutstart + b] = in[pixelinstart + b]; in Adam7_interlace()
5696 size_t obp, ibp; /*bit pointers (for out and in buffer)*/ in Adam7_interlace()
5702 unsigned char bit = readBitFromReversedStream(&ibp, in); in Adam7_interlace()
5710 /*out must be buffer big enough to contain uncompressed IDAT chunk data, and in must contain the fu…
5712 static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const unsigned char* in, in preProcessScanlines() argument
5734 addPaddingBits(padded, in, ((w * bpp + 7u) / 8u) * 8u, w * bpp, h); in preProcessScanlines()
5740 error = filter(*out, in, w, h, &info_png->color, settings); in preProcessScanlines()
5760 Adam7_interlace(adam7, in, w, h, bpp); in preProcessScanlines()
5811 /* See comment in isGrayICCProfile*/ in isRGBICCProfile()
5906 or in case of auto_convert, it wasn't possible to find appropriate model*/ in lodepng_encode()
5971 /*force_palette means: write suggested palette for truecolor in PLTE chunk*/ in lodepng_encode()
6023 /*LodePNG version id in text chunk*/ in lodepng_encode()
6139 This returns the description of a numerical error code in English. This is also
6147 …case 11: return "error in code tree made it jump outside of huffman tree"; /*while huffman decodin… in lodepng_error_text()
6151 /*this error could happen if there are only 0 or 1 symbols present in the huffman code:*/ in lodepng_error_text()
6157 case 21: return "NLEN is not ones complement of LEN in a deflate block"; in lodepng_error_text()
6162 happen in a normal, well encoded, PNG image.*/ in lodepng_error_text()
6164 case 23: return "end of in buffer memory reached while inflating"; in lodepng_error_text()
6165 case 24: return "invalid FCHECK in zlib header"; in lodepng_error_text()
6166 case 25: return "invalid compression method in zlib header"; in lodepng_error_text()
6167 case 26: return "FDICT encountered in zlib header while it's not used for PNG"; in lodepng_error_text()
6194 case 54: return "repeat symbol in tree while there was no value symbol yet"; in lodepng_error_text()
6197 given lengths. They call this an oversubscribed dynamic bit lengths tree in zlib.*/ in lodepng_error_text()
6203 case 60: return "invalid window size given in the settings of the encoder (must be 0-32768)"; in lodepng_error_text()
6204 …case 61: return "invalid BTYPE given in the settings of the encoder (only 0, 1 and 2 are allowed)"; in lodepng_error_text()
6209 …/*this would result in the inability of a deflated block to ever contain an end code. It must be a… in lodepng_error_text()
6210 case 64: return "the length of the END symbol 256 in the Huffman tree is 0"; in lodepng_error_text()
6216 …case 72: return "while decoding, invalid compression method encountering in zTXt or iTXt chunk (it… in lodepng_error_text()
6222 case 77: return "integer overflow in buffer size"; in lodepng_error_text()
6227 …case 82: return "color conversion to palette requested while a color isn't in palette, or index ou… in lodepng_error_text()
6230 case 86: return "impossible offset in lz77 encoding (internal bug)"; in lodepng_error_text()
6234 …/*the windowsize in the LodePNGCompressSettings. Requiring POT(==> & instead of %) makes encoding … in lodepng_error_text()
6248 case 103: return "invalid palette index in bKGD chunk. Maybe it came before PLTE chunk?"; in lodepng_error_text()
6252 …case 107: return "color convert from palette mode requested without setting the palette data in it… in lodepng_error_text()
6254 /*this limit can be configured in LodePNGDecompressSettings*/ in lodepng_error_text()
6258 /*max text size limit can be configured in LodePNGDecoderSettings. This error prevents in lodepng_error_text()
6261 /*max ICC size limit can be configured in LodePNGDecoderSettings. This error prevents in lodepng_error_text()
6294 unsigned decompress(std::vector<unsigned char>& out, const unsigned char* in, size_t insize, in decompress() argument
6298 unsigned error = zlib_decompress(&buffer, &buffersize, 0, in, insize, &settings); in decompress()
6306 unsigned decompress(std::vector<unsigned char>& out, const std::vector<unsigned char>& in, in decompress() argument
6308 return decompress(out, in.empty() ? 0 : &in[0], in.size(), settings); in decompress()
6313 unsigned compress(std::vector<unsigned char>& out, const unsigned char* in, size_t insize, in compress() argument
6317 unsigned error = zlib_compress(&buffer, &buffersize, in, insize, &settings); in compress()
6325 unsigned compress(std::vector<unsigned char>& out, const std::vector<unsigned char>& in, in compress() argument
6327 return compress(out, in.empty() ? 0 : &in[0], in.size(), settings); in compress()
6355 unsigned decode(std::vector<unsigned char>& out, unsigned& w, unsigned& h, const unsigned char* in, in decode() argument
6358 unsigned error = lodepng_decode_memory(&buffer, &w, &h, in, insize, colortype, bitdepth); in decode()
6371 … const std::vector<unsigned char>& in, LodePNGColorType colortype, unsigned bitdepth) { in decode() argument
6372 return decode(out, w, h, in.empty() ? 0 : &in[0], (unsigned)in.size(), colortype, bitdepth); in decode()
6377 const unsigned char* in, size_t insize) { in decode() argument
6379 unsigned error = lodepng_decode(&buffer, &w, &h, &state, in, insize); in decode()
6390 const std::vector<unsigned char>& in) { in decode() argument
6391 return decode(out, w, h, state, in.empty() ? 0 : &in[0], in.size()); in decode()
6398 /* safe output values in case error happens */ in decode()
6408 unsigned encode(std::vector<unsigned char>& out, const unsigned char* in, unsigned w, unsigned h, in encode() argument
6412 unsigned error = lodepng_encode_memory(&buffer, &buffersize, in, w, h, colortype, bitdepth); in encode()
6421 const std::vector<unsigned char>& in, unsigned w, unsigned h, in encode() argument
6423 if(lodepng_get_raw_size_lct(w, h, colortype, bitdepth) > in.size()) return 84; in encode()
6424 return encode(out, in.empty() ? 0 : &in[0], w, h, colortype, bitdepth); in encode()
6428 const unsigned char* in, unsigned w, unsigned h, in encode() argument
6432 unsigned error = lodepng_encode(&buffer, &buffersize, in, w, h, &state); in encode()
6441 const std::vector<unsigned char>& in, unsigned w, unsigned h, in encode() argument
6443 if(lodepng_get_raw_size(w, h, &state.info_raw) > in.size()) return 84; in encode()
6444 return encode(out, in.empty() ? 0 : &in[0], w, h, state); in encode()
6449 const unsigned char* in, unsigned w, unsigned h, in encode() argument
6452 unsigned error = encode(buffer, in, w, h, colortype, bitdepth); in encode()
6458 const std::vector<unsigned char>& in, unsigned w, unsigned h, in encode() argument
6460 if(lodepng_get_raw_size_lct(w, h, colortype, bitdepth) > in.size()) return 84; in encode()
6461 return encode(filename, in.empty() ? 0 : &in[0], w, h, colortype, bitdepth); in encode()