Lines Matching full:if

15     claim that you wrote the original software. If you use this software
32 #if LV_USE_LODEPNG
46 #if defined(_MSC_VER) && (_MSC_VER >= 1310) /*Visual Studio: A few warning types are not desired he…
70 platform if needed. Everything else in the code calls these. Pass
74 lodepng source code. Don't forget to remove "static" if you copypaste them
81 if(size > LODEPNG_MAX_ALLOC) return 0; in lodepng_malloc()
90 if(new_size > LODEPNG_MAX_ALLOC) return 0; in lodepng_realloc()
108 #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || (defined(__cplusplus) && (__cpl…
115 #if (defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))) ||\
152 #if defined(LODEPNG_COMPILE_PNG) || defined(LODEPNG_COMPILE_DECODER)
153 /* Safely check if adding two integers will overflow (no undefined
163 /* Safely check if multiplying two integers will overflow (no undefined
172 /* Safely check if a + b > c, even if overflow could happen. */
176 if(lodepng_addofl(a, b, &d)) return 1; in lodepng_gtofl()
188 Example: if(!uivector_resize(&lz77_encoded, datasize)) ERROR_BREAK(83);
204 /*Try the code, if it returns error, also return the error.*/
207 if(error) return error;\
241 /*returns 1 if success, 0 if failure ==> nothing done*/
245 if(allocsize > p->allocsize) { in uivector_resize()
248 if(data) { in uivector_resize()
264 /*returns 1 if success, 0 if failure ==> nothing done*/
267 if(!uivector_resize(p, p->size + 1)) return 0; in uivector_push_back()
283 /*returns 1 if success, 0 if failure ==> nothing done*/
286 if(size > p->allocsize) { in ucvector_reserve()
289 if(data) { in ucvector_reserve()
298 /*returns 1 if success, 0 if failure ==> nothing done*/
329 if(out) { in alloc_string_sized()
346 #if defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_PNG)
354 #if defined(LODEPNG_COMPILE_PNG) || defined(LODEPNG_COMPILE_ENCODER)
376 if(res != LV_FS_RES_OK) return -1; in lodepng_filesize()
378 if(lv_fs_seek(&f, 0, LV_FS_SEEK_END) != 0) { in lodepng_filesize()
393 if(res != LV_FS_RES_OK) return 78; in lodepng_buffer_file()
399 if(res != LV_FS_RES_OK) return 78; in lodepng_buffer_file()
400 if(br != size) return 78; in lodepng_buffer_file()
408 if(size < 0) return 78; in lodepng_load_file()
412 if(!(*out) && size > 0) return 83; /*the above malloc failed*/ in lodepng_load_file()
422 if(res != LV_FS_RES_OK) return 79; in lodepng_save_file()
455 if(((writer->bp) & 7u) == 0) {\
456 if(!ucvector_resize(writer->data, writer->data->size + 1)) return;\
466 if(nbits == 1) { /* compiler should statically compile this case if nbits == 1 */ in writeBits()
499 /* data size argument is in bytes. Returns error if size too large causing overflow */
505 /* size in bits, return error if overflow (if size_t is 32 bit this supports up to 500MB) */ in LodePNGBitReader_init()
506 if(lodepng_mulofl(size, 8u, &reader->bitsize)) return 105; in LodePNGBitReader_init()
509 if(lodepng_addofl(reader->bitsize, 64u, &temp)) return 105; in LodePNGBitReader_init()
518 safely even if not enough bits are available.
528 if(start + 1u < size) { in ensureBits9()
534 if(start + 0u < size) reader->buffer = reader->data[start + 0]; in ensureBits9()
545 if(start + 2u < size) { in ensureBits17()
552 if(start + 0u < size) reader->buffer |= reader->data[start + 0]; in ensureBits17()
553 if(start + 1u < size) reader->buffer |= ((unsigned)reader->data[start + 1] << 8u); in ensureBits17()
564 if(start + 3u < size) { in ensureBits25()
571 if(start + 0u < size) reader->buffer |= reader->data[start + 0]; in ensureBits25()
572 if(start + 1u < size) reader->buffer |= ((unsigned)reader->data[start + 1] << 8u); in ensureBits25()
573 if(start + 2u < size) reader->buffer |= ((unsigned)reader->data[start + 2] << 16u); in ensureBits25()
584 if(start + 4u < size) { in ensureBits32()
592 if(start + 0u < size) reader->buffer |= reader->data[start + 0]; in ensureBits32()
593 if(start + 1u < size) reader->buffer |= ((unsigned)reader->data[start + 1] << 8u); in ensureBits32()
594 if(start + 2u < size) reader->buffer |= ((unsigned)reader->data[start + 2] << 16u); in ensureBits32()
595 if(start + 3u < size) reader->buffer |= ((unsigned)reader->data[start + 3] << 24u); in ensureBits32()
685 …unsigned char * table_len; /*length of symbol from lookup table, or max length if secondary lookup…
686 …short * table_value; /*value of symbol from lookup table, or pointer to secondary table if needed*/
720 if(!maxlens) return 83; /*alloc fail*/ in HuffmanTree_makeTable()
728if(l <= FIRSTBITS) continue; /*symbols that fit in first table don't increase secondary table size… in HuffmanTree_makeTable()
737 if(l > FIRSTBITS) size += (((size_t)1) << (l - FIRSTBITS)); in HuffmanTree_makeTable()
741 if(!tree->table_len || !tree->table_value) { in HuffmanTree_makeTable()
753 if(l <= FIRSTBITS) continue; in HuffmanTree_makeTable()
765 if(l == 0) continue; in HuffmanTree_makeTable()
771 if(l <= FIRSTBITS) { in HuffmanTree_makeTable()
772 /*short symbol, fully in first table, replicated num times if l < FIRSTBITS*/ in HuffmanTree_makeTable()
778if(tree->table_len[index] != 16) return 55; /*invalid tree: long symbol shares prefix with short s… in HuffmanTree_makeTable()
793 if(maxlen < l) return 55; /*invalid tree: long symbol shares prefix with short symbol*/ in HuffmanTree_makeTable()
803 if(numpresent < 2) { in HuffmanTree_makeTable()
806 appear at all, but such huffman tree could still exist (e.g. if distance in HuffmanTree_makeTable()
811 if(tree->table_len[i] == 16) { in HuffmanTree_makeTable()
822 If that is not the case (due to too long length codes), the table will not in HuffmanTree_makeTable()
826 if(tree->table_len[i] == 16) return 55; in HuffmanTree_makeTable()
848 if(!tree->codes || !blcount || !nextcode) error = 83; /*alloc fail*/ in HuffmanTree_makeFromLengths2()
850 if(!error) { in HuffmanTree_makeFromLengths2()
860 if(tree->lengths[n] != 0) { in HuffmanTree_makeFromLengths2()
871 if(!error) error = HuffmanTree_makeTable(tree); in HuffmanTree_makeFromLengths2()
885 if(!tree->lengths) return 83; /*alloc fail*/ in HuffmanTree_makeFromLengths()
901 struct BPMNode * tail; /*the next nodes in this chain (null if last)*/
926 if(lists->nextfree >= lists->numfree) { in bpmnode_create()
937 if(!lists->memory[i].in_use) lists->freelist[lists->numfree++] = &lists->memory[i]; in bpmnode_create()
963 if(i < q && (j >= r || a[i].weight <= a[j].weight)) b[k] = a[i++]; in bpmnode_sort()
969 if(counter & 1) lodepng_memcpy(leaves, mem, sizeof(*leaves) * num); in bpmnode_sort()
978 if(c == 0) { in boundaryPM()
979 if(lastindex >= numpresent) return; in boundaryPM()
987 if(lastindex < numpresent && sum > leaves[lastindex].weight) { in boundaryPM()
993 need to recurse if we're at the last one (this gives measurable speedup)*/ in boundaryPM()
994 if(num + 1 < (int)(2 * numpresent - 2)) { in boundaryPM()
1009 if(numcodes == 0) return 80; /*error: a tree of 0 symbols is not supposed to be made*/ in lodepng_huffman_code_lengths()
1010 if((1u << maxbitlen) < (unsigned)numcodes) return 80; /*error: represent all symbols*/ in lodepng_huffman_code_lengths()
1013 if(!leaves) return 83; /*alloc fail*/ in lodepng_huffman_code_lengths()
1016 if(frequencies[i] > 0) { in lodepng_huffman_code_lengths()
1028 Package-Merge code below also doesn't work correctly if there's only one in lodepng_huffman_code_lengths()
1030 if(numpresent == 0) { in lodepng_huffman_code_lengths()
1033 else if(numpresent == 1) { in lodepng_huffman_code_lengths()
1051if(!lists.memory || !lists.freelist || !lists.chains0 || !lists.chains1) error = 83; /*alloc fail*/ in lodepng_huffman_code_lengths()
1053 if(!error) { in lodepng_huffman_code_lengths()
1089 if(!tree->lengths) return 83; /*alloc fail*/ in HuffmanTree_makeFromFrequencies()
1094 if(!error) error = HuffmanTree_makeFromLengths2(tree); in HuffmanTree_makeFromFrequencies()
1104 if(!bitlen) return 83; /*alloc fail*/ in generateFixedLitLenTree()
1123 if(!bitlen) return 83; /*alloc fail*/ in generateFixedDistanceTree()
1143 if(l <= FIRSTBITS) { in huffmanDecodeSymbol()
1167 if(error) return error; in getTreeInflateFixed()
1186if(reader->bitsize - reader->bp < 14) return 49; /*error: the bit pointer is or will go past the m… in getTreeInflateDynamic()
1197 if(!bitlen_cl) return 83 /*alloc fail*/; in getTreeInflateDynamic()
1203 if(lodepng_gtofl(reader->bp, HCLEN * 3, reader->bitsize)) { in getTreeInflateDynamic()
1215 if(error) break; in getTreeInflateDynamic()
1220 if(!bitlen_ll || !bitlen_d) ERROR_BREAK(83 /*alloc fail*/); in getTreeInflateDynamic()
1230 if(code <= 15) { /*a length code*/ in getTreeInflateDynamic()
1231 if(i < HLIT) bitlen_ll[i] = code; in getTreeInflateDynamic()
1235 else if(code == 16) { /*repeat previous*/ in getTreeInflateDynamic()
1239 if(i == 0) ERROR_BREAK(54); /*can't repeat previous if i is 0*/ in getTreeInflateDynamic()
1243 if(i < HLIT + 1) value = bitlen_ll[i - 1]; in getTreeInflateDynamic()
1247if(i >= HLIT + HDIST) ERROR_BREAK(13); /*error: i is larger than the amount of codes*/ in getTreeInflateDynamic()
1248 if(i < HLIT) bitlen_ll[i] = value; in getTreeInflateDynamic()
1253 else if(code == 17) { /*repeat "0" 3-10 times*/ in getTreeInflateDynamic()
1259if(i >= HLIT + HDIST) ERROR_BREAK(14); /*error: i is larger than the amount of codes*/ in getTreeInflateDynamic()
1261 if(i < HLIT) bitlen_ll[i] = 0; in getTreeInflateDynamic()
1266 else if(code == 18) { /*repeat "0" 11-138 times*/ in getTreeInflateDynamic()
1272if(i >= HLIT + HDIST) ERROR_BREAK(15); /*error: i is larger than the amount of codes*/ in getTreeInflateDynamic()
1274 if(i < HLIT) bitlen_ll[i] = 0; in getTreeInflateDynamic()
1279 else { /*if(code == INVALIDSYMBOL)*/ in getTreeInflateDynamic()
1282 /*check if any of the ensureBits above went out of bounds*/ in getTreeInflateDynamic()
1283 if(reader->bp > reader->bitsize) { in getTreeInflateDynamic()
1290 if(error) break; in getTreeInflateDynamic()
1292if(bitlen_ll[256] == 0) ERROR_BREAK(64); /*the length of the end code 256 must be larger than 0*/ in getTreeInflateDynamic()
1296 if(error) break; in getTreeInflateDynamic()
1321 if(!ucvector_reserve(out, out->size + reserved_size)) return 83; /*alloc fail*/ in inflateHuffmanBlock()
1326 if(btype == 1) error = getTreeInflateFixed(&tree_ll, &tree_d); in inflateHuffmanBlock()
1327 else /*if(btype == 2)*/ error = getTreeInflateDynamic(&tree_ll, &tree_d, reader); in inflateHuffmanBlock()
1333 …/* ensure enough bits for 2 huffman code reads (15 bits each): if the first is a literal, a second… in inflateHuffmanBlock()
1337 if(code_ll <= 255) { in inflateHuffmanBlock()
1338 /*slightly faster code path if multiple literals in a row*/ in inflateHuffmanBlock()
1342 if(code_ll <= 255) { /*literal symbol*/ in inflateHuffmanBlock()
1345 … else if(code_ll >= FIRST_LENGTH_CODE_INDEX && code_ll <= LAST_LENGTH_CODE_INDEX) { /*length code*/ in inflateHuffmanBlock()
1355 if(numextrabits_l != 0) { in inflateHuffmanBlock()
1364 if(code_d > 29) { in inflateHuffmanBlock()
1365 if(code_d <= 31) { in inflateHuffmanBlock()
1368 else { /* if(code_d == INVALIDSYMBOL) */ in inflateHuffmanBlock()
1376 if(numextrabits_d != 0) { in inflateHuffmanBlock()
1383 if(distance > start) ERROR_BREAK(52); /*too long backward distance*/ in inflateHuffmanBlock()
1387 if(distance < length) { in inflateHuffmanBlock()
1399 else if(code_ll == 256) { in inflateHuffmanBlock()
1402 else { /*if(code_ll == INVALIDSYMBOL)*/ in inflateHuffmanBlock()
1405 if(out->allocsize - out->size < reserved_size) { in inflateHuffmanBlock()
1406 if(!ucvector_reserve(out, out->size + reserved_size)) ERROR_BREAK(83); /*alloc fail*/ in inflateHuffmanBlock()
1408 /*check if any of the ensureBits above went out of bounds*/ in inflateHuffmanBlock()
1409 if(reader->bp > reader->bitsize) { in inflateHuffmanBlock()
1415 if(max_output_size && out->size > max_output_size) { in inflateHuffmanBlock()
1437 if(bytepos + 4 >= size) return 52; /*error, bit pointer will jump past memory*/ in inflateNoCompression()
1443 /*check if 16-bit NLEN is really the one's complement of LEN*/ in inflateNoCompression()
1444 if(!settings->ignore_nlen && LEN + NLEN != 65535) { in inflateNoCompression()
1448 if(!ucvector_resize(out, out->size + LEN)) return 83; /*alloc fail*/ in inflateNoCompression()
1451 if(bytepos + LEN > size) return 23; /*error: reading outside of in buffer*/ in inflateNoCompression()
1454 if(LEN) { in inflateNoCompression()
1472 if(error) return error; in lodepng_inflatev()
1476 if(reader.bitsize - reader.bp < 3) return 52; /*error, bit pointer will jump past memory*/ in lodepng_inflatev()
1481 if(BTYPE == 3) return 20; /*error: invalid BTYPE*/ in lodepng_inflatev()
1482 else if(BTYPE == 0) error = inflateNoCompression(out, &reader, settings); /*no compression*/ in lodepng_inflatev()
1484if(!error && settings->max_output_size && out->size > settings->max_output_size) error = 109; in lodepng_inflatev()
1485 if(error) break; in lodepng_inflatev()
1505 if(settings->custom_inflate) { in inflatev()
1508 if(error) { in inflatev()
1511 …/*if there's a max output size, and the custom zlib returned error, then indicate that error inste… in inflatev()
1512 if(settings->max_output_size && out->size > settings->max_output_size) error = 109; in inflatev()
1532 given array must be sorted (if no value is smaller, it returns the size of the given array)*/
1541 if(array[mid] >= value) right = mid - 1; in searchCodeIndex()
1544 if(left >= array_size || array[left] > value) left--; in searchCodeIndex()
1564 if(ok) { in addLengthDistance()
1578 int * head; /*hash value to head circular pos - can be outdated if went around window*/
1601if(!hash->head || !hash->chain || !hash->val || !hash->headz || !hash->chainz || !hash->zeros) { in hash_init()
1632 if(pos + 2 < size) { in getHash()
1643 if(pos >= size) return 0; in getHash()
1654 if(end > data + size) end = data + size; in countZeros()
1665 if(hash->head[hashval] != -1) hash->chain[wpos] = hash->head[hashval]; in updateHashChain()
1669 if(hash->headz[numzeros] != -1) hash->chainz[wpos] = hash->headz[numzeros]; in updateHashChain()
1692 …unsigned usezeros = 1; /*not sure if setting it to false for windowsize < 8192 is better or worse*/ in encodeLZ77()
1705if(windowsize == 0 || windowsize > 32768) return 60; /*error: windowsize smaller/larger than allow… in encodeLZ77()
1706 if((windowsize & (windowsize - 1)) != 0) return 90; /*error: must be power of two*/ in encodeLZ77()
1708 if(nicematch > MAX_SUPPORTED_DEFLATE_LENGTH) nicematch = MAX_SUPPORTED_DEFLATE_LENGTH; in encodeLZ77()
1716 if(usezeros && hashval == 0) { in encodeLZ77()
1717 if(numzeros == 0) numzeros = countZeros(in, insize, pos); in encodeLZ77()
1718 else if(pos + numzeros > insize || in[pos + numzeros - 1] != 0) --numzeros; in encodeLZ77()
1737 if(chainlength++ >= maxchainlength) break; in encodeLZ77()
1740if(current_offset < prev_offset) break; /*stop when went completely around the circular buffer*/ in encodeLZ77()
1742 if(current_offset > 0) { in encodeLZ77()
1748 if(numzeros >= 3) { in encodeLZ77()
1750 if(skip > numzeros) skip = numzeros; in encodeLZ77()
1761 if(current_length > length) { in encodeLZ77()
1765 out if length is MAX_SUPPORTED_DEFLATE_LENGTH*/ in encodeLZ77()
1766 if(current_length >= nicematch) break; in encodeLZ77()
1770 if(hashpos == hash->chain[hashpos]) break; in encodeLZ77()
1772 if(numzeros >= 3 && length > numzeros) { in encodeLZ77()
1774 if(hash->zeros[hashpos] != numzeros) break; in encodeLZ77()
1778 … /*outdated hash value, happens if particular value was not encountered in whole last window*/ in encodeLZ77()
1779 if(hash->val[hashpos] != (int)hashval) break; in encodeLZ77()
1783 if(lazymatching) { in encodeLZ77()
1784if(!lazy && length >= 3 && length <= maxlazymatch && length < MAX_SUPPORTED_DEFLATE_LENGTH) { in encodeLZ77()
1790 if(lazy) { in encodeLZ77()
1792 if(pos == 0) ERROR_BREAK(81); in encodeLZ77()
1793 if(length > lazylength + 1) { in encodeLZ77()
1795 if(!uivector_push_back(out, in[pos - 1])) ERROR_BREAK(83 /*alloc fail*/); in encodeLZ77()
1806if(length >= 3 && offset > windowsize) ERROR_BREAK(86 /*too big (or overflown negative) offset*/); in encodeLZ77()
1809 if(length < 3) { /*only lengths of 3 or higher are supported as length/distance pair*/ in encodeLZ77()
1810 if(!uivector_push_back(out, in[pos])) ERROR_BREAK(83 /*alloc fail*/); in encodeLZ77()
1812 else if(length < minmatch || (length == 3 && offset > 4096)) { in encodeLZ77()
1815 if(!uivector_push_back(out, in[pos])) ERROR_BREAK(83 /*alloc fail*/); in encodeLZ77()
1823 if(usezeros && hashval == 0) { in encodeLZ77()
1824 if(numzeros == 0) numzeros = countZeros(in, insize, pos); in encodeLZ77()
1825 else if(pos + numzeros > insize || in[pos + numzeros - 1] != 0) --numzeros; in encodeLZ77()
1856 if(datasize - datapos < 65535u) LEN = (unsigned)datasize - datapos; in deflateNoCompression()
1859 if(!ucvector_resize(out, out->size + LEN + 5)) return 83; /*alloc fail*/ in deflateNoCompression()
1886 if(val > 256) { /*for a length code, 3 more things have to be added*/ in writeLZ77data()
1935If we could call "bitlen_cl" the code length code lengths ("clcl"), that is the bit lengths of cod… in deflateDynamic()
1957 if(!frequencies_ll || !frequencies_d || !frequencies_cl) error = 83; /*alloc fail*/ in deflateDynamic()
1966 if(settings->use_lz77) { in deflateDynamic()
1969 if(error) break; in deflateDynamic()
1972 if(!uivector_resize(&lz77_encoded, datasize)) ERROR_BREAK(83 /*alloc fail*/); in deflateDynamic()
1981 if(symbol > 256) { in deflateDynamic()
1991 if(error) break; in deflateDynamic()
1994 if(error) break; in deflateDynamic()
2003 if(!bitlen_lld || !bitlen_lld_e) ERROR_BREAK(83); /*alloc fail*/ in deflateDynamic()
2015 if(bitlen_lld[i] == 0 && j >= 2) { /*repeat code for zeroes*/ in deflateDynamic()
2017 if(j <= 10) { /*repeat code 17 supports max 10 zeroes*/ in deflateDynamic()
2022 if(j > 138) j = 138; in deflateDynamic()
2028 else if(j >= 3) { /*repeat code for value other than zero*/ in deflateDynamic()
2036 if(rest >= 3) { in deflateDynamic()
2053 if(bitlen_lld_e[i] >= 16) ++i; in deflateDynamic()
2058 if(error) break; in deflateDynamic()
2103 if(bitlen_lld_e[i] == 16) writeBits(writer, bitlen_lld_e[++i], 2); in deflateDynamic()
2104 else if(bitlen_lld_e[i] == 17) writeBits(writer, bitlen_lld_e[++i], 3); in deflateDynamic()
2105 else if(bitlen_lld_e[i] == 18) writeBits(writer, bitlen_lld_e[++i], 7); in deflateDynamic()
2111 if(tree_ll.lengths[256] == 0) ERROR_BREAK(64); in deflateDynamic()
2149 if(!error) error = generateFixedDistanceTree(&tree_d); in deflateFixed()
2151 if(!error) { in deflateFixed()
2156 if(settings->use_lz77) { /*LZ77 encoded*/ in deflateFixed()
2161 if(!error) writeLZ77data(writer, &lz77_encoded, &tree_ll, &tree_d); in deflateFixed()
2170 if(!error) writeBitsReversed(writer, tree_ll.codes[256], tree_ll.lengths[256]); in deflateFixed()
2190 if(settings->btype > 2) return 61; in lodepng_deflatev()
2191 else if(settings->btype == 0) return deflateNoCompression(out, in, insize); in lodepng_deflatev()
2192 else if(settings->btype == 1) blocksize = insize; in lodepng_deflatev()
2193 else { /*if(settings->btype == 2)*/ in lodepng_deflatev()
2196 if(blocksize < 65536) blocksize = 65536; in lodepng_deflatev()
2197 if(blocksize > 262144) blocksize = 262144; in lodepng_deflatev()
2201 if(numdeflateblocks == 0) numdeflateblocks = 1; in lodepng_deflatev()
2205 if(!error) { in lodepng_deflatev()
2210 if(end > insize) end = insize; in lodepng_deflatev()
2212if(settings->btype == 1) error = deflateFixed(&writer, &hash, in, start, end, settings, final); in lodepng_deflatev()
2213 …else if(settings->btype == 2) error = deflateDynamic(&writer, &hash, in, start, end, settings, fin… in lodepng_deflatev()
2237 if(settings->custom_deflate) { in deflate()
2293 if(insize < 2) return 53; /*error, size of zlib data too small*/ in lodepng_zlib_decompressv()
2295 if((in[0] * 256 + in[1]) % 31 != 0) { in lodepng_zlib_decompressv()
2306 if(CM != 8 || CINFO > 7) { in lodepng_zlib_decompressv()
2310 if(FDICT != 0) { in lodepng_zlib_decompressv()
2317 if(error) return error; in lodepng_zlib_decompressv()
2319 if(!settings->ignore_adler32) { in lodepng_zlib_decompressv()
2322if(checksum != ADLER32) return 58; /*error, adler checksum not correct, data must be corrupted*/ in lodepng_zlib_decompressv()
2339 /*expected_size is expected output size, to avoid intermediate allocations. Set to 0 if not known. …
2344 if(settings->custom_zlib) { in zlib_decompress()
2346 if(error) { in zlib_decompress()
2349 …/*if there's a max output size, and the custom zlib returned error, then indicate that error inste… in zlib_decompress()
2350 if(settings->max_output_size && *outsize > settings->max_output_size) error = 109; in zlib_decompress()
2355 if(expected_size) { in zlib_decompress()
2383 if(!error) { in lodepng_zlib_compress()
2386 if(!*out) error = 83; /*alloc fail*/ in lodepng_zlib_compress()
2389 if(!error) { in lodepng_zlib_compress()
2413 if(settings->custom_zlib) { in zlib_compress()
2431 if(!settings->custom_zlib) return 87; /*no custom zlib function provided */ in zlib_decompress()
2440 if(!settings->custom_zlib) return 87; /*no custom zlib function provided */ in zlib_compress()
2860if(bit == 0) bitstream[(*bitpointer) >> 3u] &= (unsigned char)(~(1u << (7u - ((*bitpointer) & 7u))… in setBitOfReversedStream()
2883 if(lodepng_strlen(type) != 4) return 0; in lodepng_chunk_type_equals()
2918 if(CRC != checksum) return 1; in lodepng_chunk_check_crc()
2932 if(chunk >= end || available_size < 12) return end; /*too small to contain a chunk*/ in lodepng_chunk_next()
2933 if(chunk[0] == 0x89 && chunk[1] == 0x50 && chunk[2] == 0x4e && chunk[3] == 0x47 in lodepng_chunk_next()
2940 if(lodepng_addofl(lodepng_chunk_length(chunk), 12, &total_chunk_length)) return end; in lodepng_chunk_next()
2941 if(total_chunk_length > available_size) return end; /*outside of range*/ in lodepng_chunk_next()
2949 if(chunk >= end || available_size < 12) return end; /*too small to contain a chunk*/ in lodepng_chunk_next_const()
2950 if(chunk[0] == 0x89 && chunk[1] == 0x50 && chunk[2] == 0x4e && chunk[3] == 0x47 in lodepng_chunk_next_const()
2957 if(lodepng_addofl(lodepng_chunk_length(chunk), 12, &total_chunk_length)) return end; in lodepng_chunk_next_const()
2958 if(total_chunk_length > available_size) return end; /*outside of range*/ in lodepng_chunk_next_const()
2966 if(chunk >= end || end - chunk < 12) return 0; /* past file end: chunk + 12 > end */ in lodepng_chunk_find()
2967 if(lodepng_chunk_type_equals(chunk, type)) return chunk; in lodepng_chunk_find()
2976 if(chunk >= end || end - chunk < 12) return 0; /* past file end: chunk + 12 > end */ in lodepng_chunk_find_const()
2977 if(lodepng_chunk_type_equals(chunk, type)) return chunk; in lodepng_chunk_find_const()
2988 if(lodepng_addofl(lodepng_chunk_length(chunk), 12, &total_chunk_length)) return 77; in lodepng_chunk_append()
2989 if(lodepng_addofl(*outsize, total_chunk_length, &new_length)) return 77; in lodepng_chunk_append()
2992 if(!new_buffer) return 83; /*alloc fail*/ in lodepng_chunk_append()
3011 if(lodepng_addofl(new_length, length, &new_length)) return 77; in lodepng_chunk_init()
3012 if(lodepng_addofl(new_length, 12, &new_length)) return 77; in lodepng_chunk_init()
3013 if(!ucvector_resize(out, new_length)) return 83; /*alloc fail*/ in lodepng_chunk_init()
3055 /*checks if the colortype is valid and the bitdepth bd is allowed for this colortype.
3061 if(!(bd == 1 || bd == 2 || bd == 4 || bd == 8 || bd == 16)) return 37; in checkColorValidity()
3064 if(!(bd == 8 || bd == 16)) return 37; in checkColorValidity()
3067 if(!(bd == 1 || bd == 2 || bd == 4 || bd == 8)) return 37; in checkColorValidity()
3070 if(!(bd == 8 || bd == 16)) return 37; in checkColorValidity()
3073 if(!(bd == 8 || bd == 16)) return 37; in checkColorValidity()
3121 /*allocates palette memory if needed, and initializes all colors to black*/
3125 …/*if the palette is already allocated, it will have size 1024 so no reallocation needed in that ca… in lodepng_color_mode_alloc_palette()
3127 if(!info->palette) info->palette = (unsigned char *)lodepng_malloc(1024); in lodepng_color_mode_alloc_palette()
3128 if(!info->palette) return; /*alloc fail*/ in lodepng_color_mode_alloc_palette()
3149 if(source->palette) { in lodepng_color_mode_copy()
3151 if(!dest->palette && source->palettesize) return 83; /*alloc fail*/ in lodepng_color_mode_copy()
3169 if(a->colortype != b->colortype) return 0; in lodepng_color_mode_equal()
3170 if(a->bitdepth != b->bitdepth) return 0; in lodepng_color_mode_equal()
3171 if(a->key_defined != b->key_defined) return 0; in lodepng_color_mode_equal()
3172 if(a->key_defined) { in lodepng_color_mode_equal()
3173 if(a->key_r != b->key_r) return 0; in lodepng_color_mode_equal()
3174 if(a->key_g != b->key_g) return 0; in lodepng_color_mode_equal()
3175 if(a->key_b != b->key_b) return 0; in lodepng_color_mode_equal()
3177 if(a->palettesize != b->palettesize) return 0; in lodepng_color_mode_equal()
3179 if(a->palette[i] != b->palette[i]) return 0; in lodepng_color_mode_equal()
3186 if(info->palette) lodepng_free(info->palette); in lodepng_palette_clear()
3194 if(!info->palette) { /*allocate palette if empty*/ in lodepng_palette_add()
3196 if(!info->palette) return 83; /*alloc fail*/ in lodepng_palette_add()
3198 if(info->palettesize >= 256) { in lodepng_palette_add()
3239 if(info->palette[i * 4 + 3] < 255) return 1; in lodepng_has_palette_alpha()
3279 This check is overcautious rather than precise. If this check indicates no overflow,
3284 Returns 1 if overflow possible, 0 if not.
3293 if(lodepng_mulofl((size_t)w, (size_t)h, &numpixels)) return 1; in lodepng_pixel_overflow()
3294if(lodepng_mulofl(numpixels, 8, &total)) return 1; /* bit pointer with 8-bit color, or 8 bytes per… in lodepng_pixel_overflow()
3297 if(lodepng_mulofl((size_t)(w / 8u), bpp, &line)) return 1; in lodepng_pixel_overflow()
3298 if(lodepng_addofl(line, ((w & 7u) * bpp + 7u) / 8u, &line)) return 1; in lodepng_pixel_overflow()
3300if(lodepng_addofl(line, 5, &line)) return 1; /* 5 bytes overhead per line: 1 filterbyte, 4 for Ada… in lodepng_pixel_overflow()
3301 if(lodepng_mulofl(line, h, &total)) return 1; /* Total bytes in worst case */ in lodepng_pixel_overflow()
3333 if(!dest->unknown_chunks_data[i] && dest->unknown_chunks_size[i]) return 83; /*alloc fail*/ in LodePNGUnknownChunks_copy()
3379 if(new_keys) info->text_keys = new_keys; in lodepng_add_text_sized()
3380 if(new_strings) info->text_strings = new_strings; in lodepng_add_text_sized()
3382 if(!new_keys || !new_strings) return 83; /*alloc fail*/ in lodepng_add_text_sized()
3387if(!info->text_keys[info->text_num - 1] || !info->text_strings[info->text_num - 1]) return 83; /*a… in lodepng_add_text_sized()
3456 if(new_keys) info->itext_keys = new_keys; in lodepng_add_itext_sized()
3457 if(new_langtags) info->itext_langtags = new_langtags; in lodepng_add_itext_sized()
3458 if(new_transkeys) info->itext_transkeys = new_transkeys; in lodepng_add_itext_sized()
3459 if(new_strings) info->itext_strings = new_strings; in lodepng_add_itext_sized()
3461 if(!new_keys || !new_langtags || !new_transkeys || !new_strings) return 83; /*alloc fail*/ in lodepng_add_itext_sized()
3483 if(profile_size == 0) return 100; /*invalid ICC profile size*/ in lodepng_assign_icc()
3488 if(!info->iccp_name || !info->iccp_profile) return 83; /*alloc fail*/ in lodepng_assign_icc()
3498 if(info->iccp_name) lodepng_clear_icc(info); in lodepng_set_icc()
3567 if(source->iccp_defined) { in lodepng_info_copy()
3587 if(p == 0) out[index * bits / 8u] = in; in addColorBits()
3601 int index; /*the payload. Only has a meaningful value if this is in the last level*/
3614 if(tree->children[i]) { in color_tree_cleanup()
3621 /*returns -1 if color not present, its index otherwise*/
3627 if(!tree->children[i]) return -1; in color_tree_get()
3642 Returns error code, or 0 if ok*/
3649 if(!tree->children[i]) { in color_tree_add()
3651 if(!tree->children[i]) return 83; /*alloc fail*/ in color_tree_add()
3665 if(mode->colortype == LCT_GREY) { in rgba8ToPixel()
3667 if(mode->bitdepth == 8) out[i] = gray; in rgba8ToPixel()
3668 else if(mode->bitdepth == 16) out[i * 2 + 0] = out[i * 2 + 1] = gray; in rgba8ToPixel()
3675 else if(mode->colortype == LCT_RGB) { in rgba8ToPixel()
3676 if(mode->bitdepth == 8) { in rgba8ToPixel()
3687 else if(mode->colortype == LCT_PALETTE) { in rgba8ToPixel()
3689 if(index < 0) return 82; /*color not in palette*/ in rgba8ToPixel()
3690 if(mode->bitdepth == 8) out[i] = index; in rgba8ToPixel()
3693 else if(mode->colortype == LCT_GREY_ALPHA) { in rgba8ToPixel()
3695 if(mode->bitdepth == 8) { in rgba8ToPixel()
3699 else if(mode->bitdepth == 16) { in rgba8ToPixel()
3704 else if(mode->colortype == LCT_RGBA) { in rgba8ToPixel()
3705 if(mode->bitdepth == 8) { in rgba8ToPixel()
3727 if(mode->colortype == LCT_GREY) { in rgba16ToPixel()
3732 else if(mode->colortype == LCT_RGB) { in rgba16ToPixel()
3740 else if(mode->colortype == LCT_GREY_ALPHA) { in rgba16ToPixel()
3747 else if(mode->colortype == LCT_RGBA) { in rgba16ToPixel()
3765 if(mode->colortype == LCT_GREY) { in getPixelColorRGBA8()
3766 if(mode->bitdepth == 8) { in getPixelColorRGBA8()
3768 if(mode->key_defined && *r == mode->key_r) *a = 0; in getPixelColorRGBA8()
3771 else if(mode->bitdepth == 16) { in getPixelColorRGBA8()
3773 if(mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r) *a = 0; in getPixelColorRGBA8()
3781 if(mode->key_defined && value == mode->key_r) *a = 0; in getPixelColorRGBA8()
3785 else if(mode->colortype == LCT_RGB) { in getPixelColorRGBA8()
3786 if(mode->bitdepth == 8) { in getPixelColorRGBA8()
3790if(mode->key_defined && *r == mode->key_r && *g == mode->key_g && *b == mode->key_b) *a = 0; in getPixelColorRGBA8()
3797 if(mode->key_defined && 256U * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r in getPixelColorRGBA8()
3803 else if(mode->colortype == LCT_PALETTE) { in getPixelColorRGBA8()
3805 if(mode->bitdepth == 8) index = in[i]; in getPixelColorRGBA8()
3816 else if(mode->colortype == LCT_GREY_ALPHA) { in getPixelColorRGBA8()
3817 if(mode->bitdepth == 8) { in getPixelColorRGBA8()
3826 else if(mode->colortype == LCT_RGBA) { in getPixelColorRGBA8()
3827 if(mode->bitdepth == 8) { in getPixelColorRGBA8()
3852 if(mode->colortype == LCT_GREY) { in getPixelColorsRGBA8()
3853 if(mode->bitdepth == 8) { in getPixelColorsRGBA8()
3858 if(mode->key_defined) { in getPixelColorsRGBA8()
3861 if(buffer[0] == mode->key_r) buffer[3] = 0; in getPixelColorsRGBA8()
3865 else if(mode->bitdepth == 16) { in getPixelColorsRGBA8()
3881 else if(mode->colortype == LCT_RGB) { in getPixelColorsRGBA8()
3882 if(mode->bitdepth == 8) { in getPixelColorsRGBA8()
3887 if(mode->key_defined) { in getPixelColorsRGBA8()
3890if(buffer[0] == mode->key_r && buffer[1] == mode->key_g && buffer[2] == mode->key_b) buffer[3] = 0; in getPixelColorsRGBA8()
3906 else if(mode->colortype == LCT_PALETTE) { in getPixelColorsRGBA8()
3907 if(mode->bitdepth == 8) { in getPixelColorsRGBA8()
3923 else if(mode->colortype == LCT_GREY_ALPHA) { in getPixelColorsRGBA8()
3924 if(mode->bitdepth == 8) { in getPixelColorsRGBA8()
3937 else if(mode->colortype == LCT_RGBA) { in getPixelColorsRGBA8()
3938 if(mode->bitdepth == 8) { in getPixelColorsRGBA8()
3959 if(mode->colortype == LCT_GREY) { in getPixelColorsRGB8()
3960 if(mode->bitdepth == 8) { in getPixelColorsRGB8()
3965 else if(mode->bitdepth == 16) { in getPixelColorsRGB8()
3979 else if(mode->colortype == LCT_RGB) { in getPixelColorsRGB8()
3980 if(mode->bitdepth == 8) { in getPixelColorsRGB8()
3991 else if(mode->colortype == LCT_PALETTE) { in getPixelColorsRGB8()
3992 if(mode->bitdepth == 8) { in getPixelColorsRGB8()
4008 else if(mode->colortype == LCT_GREY_ALPHA) { in getPixelColorsRGB8()
4009 if(mode->bitdepth == 8) { in getPixelColorsRGB8()
4020 else if(mode->colortype == LCT_RGBA) { in getPixelColorsRGB8()
4021 if(mode->bitdepth == 8) { in getPixelColorsRGB8()
4041 if(mode->colortype == LCT_GREY) { in getPixelColorRGBA16()
4043 if(mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r) *a = 0; in getPixelColorRGBA16()
4046 else if(mode->colortype == LCT_RGB) { in getPixelColorRGBA16()
4050 if(mode->key_defined in getPixelColorRGBA16()
4056 else if(mode->colortype == LCT_GREY_ALPHA) { in getPixelColorRGBA16()
4060 else if(mode->colortype == LCT_RGBA) { in getPixelColorRGBA16()
4077 if(mode_in->colortype == LCT_PALETTE && !mode_in->palette) { in lodepng_convert()
4078 return 107; /* error: must provide palette if input mode is palette */ in lodepng_convert()
4081 if(lodepng_color_mode_equal(mode_out, mode_in)) { in lodepng_convert()
4087 if(mode_out->colortype == LCT_PALETTE) { in lodepng_convert()
4091 /*if the user specified output palette but did not give the values, assume in lodepng_convert()
4094 if(palettesize == 0) { in lodepng_convert()
4097 /*if the input was also palette with same bitdepth, then the color types are also in lodepng_convert()
4100 if(mode_in->colortype == LCT_PALETTE && mode_in->bitdepth == mode_out->bitdepth) { in lodepng_convert()
4106 if(palettesize < palsize) palsize = palettesize; in lodepng_convert()
4111 if(error) break; in lodepng_convert()
4115 if(!error) { in lodepng_convert()
4116 if(mode_in->bitdepth == 16 && mode_out->bitdepth == 16) { in lodepng_convert()
4123 else if(mode_out->bitdepth == 8 && mode_out->colortype == LCT_RGBA) { in lodepng_convert()
4126 else if(mode_out->bitdepth == 8 && mode_out->colortype == LCT_RGB) { in lodepng_convert()
4134 if(error) break; in lodepng_convert()
4139 if(mode_out->colortype == LCT_PALETTE) { in lodepng_convert()
4162 if(mode_in->colortype == LCT_GREY || mode_in->colortype == LCT_GREY_ALPHA) { in lodepng_convert_rgb()
4165 else if(mode_in->colortype == LCT_RGB || mode_in->colortype == LCT_RGBA) { in lodepng_convert_rgb()
4170 else if(mode_in->colortype == LCT_PALETTE) { in lodepng_convert_rgb()
4171 if(r_in >= mode_in->palettesize) return 82; in lodepng_convert_rgb()
4181 if(mode_out->colortype == LCT_GREY || mode_out->colortype == LCT_GREY_ALPHA) { in lodepng_convert_rgb()
4184 else if(mode_out->colortype == LCT_RGB || mode_out->colortype == LCT_RGBA) { in lodepng_convert_rgb()
4189 else if(mode_out->colortype == LCT_PALETTE) { in lodepng_convert_rgb()
4192 if((r >> 8) != (r & 255) || (g >> 8) != (g & 255) || (b >> 8) != (b & 255)) return 82; in lodepng_convert_rgb()
4195 if((r >> 8) == mode_out->palette[j + 0] && (g >> 8) == mode_out->palette[j + 1] && in lodepng_convert_rgb()
4242 if(value == 0 || value == 255) return 1; in getValueRequiredBits()
4244 if(value % 17 == 0) return value % 85 == 0 ? 2 : 4; in getValueRequiredBits()
4258 /* mark things as done already if it would be impossible to have a more expensive case */ in lodepng_compute_color_stats()
4266 if(bpp <= 8) maxnumcolors = LODEPNG_MIN(257, stats->numcolors + (1u << bpp)); in lodepng_compute_color_stats()
4270 /*if palette not allowed, no need to compute numcolors*/ in lodepng_compute_color_stats()
4271 if(!stats->allow_palette) numcolors_done = 1; in lodepng_compute_color_stats()
4275 /*If the stats was already filled in from previous data, fill its palette in tree in lodepng_compute_color_stats()
4276 and mark things as done already if we know they are the most expensive case already*/ in lodepng_compute_color_stats()
4277 if(stats->alpha) alpha_done = 1; in lodepng_compute_color_stats()
4278 if(stats->colored) colored_done = 1; in lodepng_compute_color_stats()
4279 if(stats->bits == 16) numcolors_done = 1; in lodepng_compute_color_stats()
4280 if(stats->bits >= bpp) bits_done = 1; in lodepng_compute_color_stats()
4281 if(stats->numcolors >= maxnumcolors) numcolors_done = 1; in lodepng_compute_color_stats()
4283 if(!numcolors_done) { in lodepng_compute_color_stats()
4287 if(error) goto cleanup; in lodepng_compute_color_stats()
4291 /*Check if the 16-bit input is truly 16-bit*/ in lodepng_compute_color_stats()
4292 if(mode_in->bitdepth == 16 && !sixteen) { in lodepng_compute_color_stats()
4296 if((r & 255) != ((r >> 8) & 255) || (g & 255) != ((g >> 8) & 255) || in lodepng_compute_color_stats()
4307 if(sixteen) { in lodepng_compute_color_stats()
4313 if(!colored_done && (r != g || r != b)) { in lodepng_compute_color_stats()
4318 if(!alpha_done) { in lodepng_compute_color_stats()
4320 if(a != 65535 && (a != 0 || (stats->key && !matchkey))) { in lodepng_compute_color_stats()
4325 else if(a == 0 && !stats->alpha && !stats->key) { in lodepng_compute_color_stats()
4331 else if(a == 65535 && stats->key && matchkey) { in lodepng_compute_color_stats()
4332 /* Color key cannot be used if an opaque pixel also has that RGB color. */ in lodepng_compute_color_stats()
4338 if(alpha_done && numcolors_done && colored_done && bits_done) break; in lodepng_compute_color_stats()
4341 if(stats->key && !stats->alpha) { in lodepng_compute_color_stats()
4344 if(a != 0 && r == stats->key_r && g == stats->key_g && b == stats->key_b) { in lodepng_compute_color_stats()
4345 /* Color key cannot be used if an opaque pixel also has that RGB color. */ in lodepng_compute_color_stats()
4358 if(!bits_done && stats->bits < 8) { in lodepng_compute_color_stats()
4361 if(bits > stats->bits) stats->bits = bits; in lodepng_compute_color_stats()
4365 if(!colored_done && (r != g || r != b)) { in lodepng_compute_color_stats()
4368if(stats->bits < 8) stats->bits = 8; /*PNG has no colored modes with less than 8-bit per channel*/ in lodepng_compute_color_stats()
4371 if(!alpha_done) { in lodepng_compute_color_stats()
4373 if(a != 255 && (a != 0 || (stats->key && !matchkey))) { in lodepng_compute_color_stats()
4377if(stats->bits < 8) stats->bits = 8; /*PNG has no alphachannel modes with less than 8-bit per chan… in lodepng_compute_color_stats()
4379 else if(a == 0 && !stats->alpha && !stats->key) { in lodepng_compute_color_stats()
4385 else if(a == 255 && stats->key && matchkey) { in lodepng_compute_color_stats()
4386 /* Color key cannot be used if an opaque pixel also has that RGB color. */ in lodepng_compute_color_stats()
4390if(stats->bits < 8) stats->bits = 8; /*PNG has no alphachannel modes with less than 8-bit per chan… in lodepng_compute_color_stats()
4394 if(!numcolors_done) { in lodepng_compute_color_stats()
4395 if(!color_tree_has(&tree, r, g, b, a)) { in lodepng_compute_color_stats()
4397 if(error) goto cleanup; in lodepng_compute_color_stats()
4398 if(stats->numcolors < 256) { in lodepng_compute_color_stats()
4411 if(alpha_done && numcolors_done && colored_done && bits_done) break; in lodepng_compute_color_stats()
4414 if(stats->key && !stats->alpha) { in lodepng_compute_color_stats()
4417 if(a != 0 && r == stats->key_r && g == stats->key_g && b == stats->key_b) { in lodepng_compute_color_stats()
4418 /* Color key cannot be used if an opaque pixel also has that RGB color. */ in lodepng_compute_color_stats()
4422if(stats->bits < 8) stats->bits = 8; /*PNG has no alphachannel modes with less than 8-bit per chan… in lodepng_compute_color_stats()
4469 e.g. gray if only grayscale pixels, palette if less than 256 colors, color key if only single trans…
4470 This is used if auto_convert is enabled (it is by default).
4488 if(key && numpixels <= 16) { in auto_choose_color()
4491 if(bits < 8) bits = 8; /*PNG has no alphachannel modes with less than 8-bit per channel*/ in auto_choose_color()
4495 if(!stats->allow_greyscale) gray_ok = 0; in auto_choose_color()
4496 if(!gray_ok && bits < 8) bits = 8; in auto_choose_color()
4501if(numpixels < n * 2) palette_ok = 0; /*don't add palette overhead if image has only a few pixels*/ in auto_choose_color()
4502 if(gray_ok && !alpha && bits <= palettebits) palette_ok = 0; /*gray is less overhead*/ in auto_choose_color()
4503 if(!stats->allow_palette) palette_ok = 0; in auto_choose_color()
4505 if(palette_ok) { in auto_choose_color()
4510 if(error) break; in auto_choose_color()
4516 if(mode_in->colortype == LCT_PALETTE && mode_in->palettesize >= mode_out->palettesize in auto_choose_color()
4518 …/*If input should have same palette colors, keep original to preserve its order and prevent conver… in auto_choose_color()
4527 if(key) { in auto_choose_color()
4550 /* return input value associated with smallest of pa, pb, pc (with certain priority if equal) */ in paethPredictor()
4551 if(pb < pa) { in paethPredictor()
4577 "padded" is only relevant if bpp is less than 8 and a scanline or image does not
4590 if(passw[i] == 0) passh[i] = 0; in Adam7_getpassvalues()
4591 if(passh[i] == 0) passw[i] = 0; in Adam7_getpassvalues()
4596 /*if passw[i] is 0, it's 0 bytes, not 1 (no filtertype-byte)*/ in Adam7_getpassvalues()
4599 /*bits padded if needed to fill full byte at end of each scanline*/ in Adam7_getpassvalues()
4618 if(insize == 0 || in == 0) { in lodepng_inspect()
4621 if(insize < 33) { in lodepng_inspect()
4630 if(in[0] != 137 || in[1] != 80 || in[2] != 78 || in[3] != 71 in lodepng_inspect()
4634 if(lodepng_chunk_length(in + 8) != 13) { in lodepng_inspect()
4637 if(!lodepng_chunk_type_equals(in + 8, "IHDR")) { in lodepng_inspect()
4645 if(w) *w = width; in lodepng_inspect()
4646 if(h) *h = height; in lodepng_inspect()
4656 if(width == 0 || height == 0) CERROR_RETURN_ERROR(state->error, 93); in lodepng_inspect()
4659 if(state->error) return state->error; in lodepng_inspect()
4661 if(info->compression_method != 0) CERROR_RETURN_ERROR(state->error, 32); in lodepng_inspect()
4663 if(info->filter_method != 0) CERROR_RETURN_ERROR(state->error, 33); in lodepng_inspect()
4665 if(info->interlace_method > 1) CERROR_RETURN_ERROR(state->error, 34); in lodepng_inspect()
4667 if(!state->decoder.ignore_crc) { in lodepng_inspect()
4670 if(CRC != checksum) { in lodepng_inspect()
4702 if(precon) { in unfilterScanline()
4710 if(precon) { in unfilterScanline()
4715 if(bytewidth >= 4) { in unfilterScanline()
4726 else if(bytewidth >= 3) { in unfilterScanline()
4736 else if(bytewidth >= 2) { in unfilterScanline()
4754 if(precon) { in unfilterScanline()
4757 if(bytewidth == 8) { in unfilterScanline()
4805 else if(bytewidth == 6) { in unfilterScanline()
4842 else if(bytewidth == 4) { in unfilterScanline()
4868 else if(bytewidth == 3) { in unfilterScanline()
4890 else if(bytewidth == 2) { in unfilterScanline()
4906 else if(bytewidth == 1) { in unfilterScanline()
4982 out must be big enough AND must be 0 everywhere if bpp < 8 in the current implementation
4984 NOTE: comments about padding bits are only relevant if bpp < 8
4994 if(bpp >= 8) { in Adam7_deinterlace()
5032 …After filtering there are still padding bits if scanlines have non multiple of 8 bit amounts. They… in removePaddingBits()
5038 only useful if (ilinebits - olinebits) is a value in the range 1..7 in removePaddingBits()
5062 … *) if no Adam7: 1) unfilter 2) remove padding bits (= possible extra bits per scanline if bpp < 8) in postProcessScanlines()
5063 *) if adam7: 1) 7x unfilter 2) 7x remove padding bits 3) Adam7_deinterlace in postProcessScanlines()
5067 if(bpp == 0) return 31; /*error: invalid colortype*/ in postProcessScanlines()
5069 if(info_png->interlace_method == 0) { in postProcessScanlines()
5070 if(bpp < 8 && w * bpp != ((w * bpp + 7u) / 8u) * 8u) { in postProcessScanlines()
5086 …/*TODO: possible efficiency improvement: if in this reduced image the bits fit nicely in 1 scanlin… in postProcessScanlines()
5088 if(bpp < 8) { in postProcessScanlines()
5106if(color->palettesize == 0 || color->palettesize > 256) return 38; /*error: palette too small or b… in readChunk_PLTE()
5108 if(!color->palette && color->palettesize) { in readChunk_PLTE()
5126 if(color->colortype == LCT_PALETTE) { in readChunk_tRNS()
5128 if(chunkLength > color->palettesize) return 39; in readChunk_tRNS()
5132 else if(color->colortype == LCT_GREY) { in readChunk_tRNS()
5134 if(chunkLength != 2) return 30; in readChunk_tRNS()
5139 else if(color->colortype == LCT_RGB) { in readChunk_tRNS()
5141 if(chunkLength != 6) return 41; in readChunk_tRNS()
5158 if(info->color.colortype == LCT_PALETTE) { in readChunk_bKGD()
5160 if(chunkLength != 1) return 43; in readChunk_bKGD()
5163 if(data[0] >= info->color.palettesize) return 103; in readChunk_bKGD()
5168 else if(info->color.colortype == LCT_GREY || info->color.colortype == LCT_GREY_ALPHA) { in readChunk_bKGD()
5170 if(chunkLength != 2) return 44; in readChunk_bKGD()
5176 else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_RGBA) { in readChunk_bKGD()
5178 if(chunkLength != 6) return 45; in readChunk_bKGD()
5201 /*even though it's not allowed by the standard, no error is thrown if in readChunk_tEXt()
5202 there's no null termination char, if the text is empty*/ in readChunk_tEXt()
5203 if(length < 1 || length > 79) CERROR_BREAK(error, 89); /*keyword too short or long*/ in readChunk_tEXt()
5206 if(!key) CERROR_BREAK(error, 83); /*alloc fail*/ in readChunk_tEXt()
5215 if(!str) CERROR_BREAK(error, 83); /*alloc fail*/ in readChunk_tEXt()
5247 if(length + 2 >= chunkLength) CERROR_BREAK(error, 75); /*no null termination, corrupt?*/ in readChunk_zTXt()
5248 if(length < 1 || length > 79) CERROR_BREAK(error, 89); /*keyword too short or long*/ in readChunk_zTXt()
5251 if(!key) CERROR_BREAK(error, 83); /*alloc fail*/ in readChunk_zTXt()
5256if(data[length + 1] != 0) CERROR_BREAK(error, 72); /*the 0 byte indicating compression must be 0*/ in readChunk_zTXt()
5259 if(string2_begin > chunkLength) CERROR_BREAK(error, 75); /*no null termination, corrupt?*/ in readChunk_zTXt()
5263 /*will fail if zlib error, e.g. if length is too small*/ in readChunk_zTXt()
5267 if(error && size > zlibsettings.max_output_size) error = 112; in readChunk_zTXt()
5268 if(error) break; in readChunk_zTXt()
5293 /*Quick check if the chunk length isn't too small. Even without check in readChunk_iTXt()
5294 …it'd still fail with other error checks below if it's too short. This just gives a different error… in readChunk_iTXt()
5295 if(chunkLength < 5) CERROR_BREAK(error, 30); /*iTXt chunk too short*/ in readChunk_iTXt()
5299if(length + 3 >= chunkLength) CERROR_BREAK(error, 75); /*no null termination char, corrupt?*/ in readChunk_iTXt()
5300 if(length < 1 || length > 79) CERROR_BREAK(error, 89); /*keyword too short or long*/ in readChunk_iTXt()
5303 if(!key) CERROR_BREAK(error, 83); /*alloc fail*/ in readChunk_iTXt()
5310if(data[length + 2] != 0) CERROR_BREAK(error, 72); /*the 0 byte indicating compression must be 0*/ in readChunk_iTXt()
5312 /*even though it's not allowed by the standard, no error is thrown if in readChunk_iTXt()
5313 there's no null termination char, if the text is empty for the next 3 texts*/ in readChunk_iTXt()
5321 if(!langtag) CERROR_BREAK(error, 83); /*alloc fail*/ in readChunk_iTXt()
5332 if(!transkey) CERROR_BREAK(error, 83); /*alloc fail*/ in readChunk_iTXt()
5342 if(compressed) { in readChunk_iTXt()
5346 /*will fail if zlib error, e.g. if length is too small*/ in readChunk_iTXt()
5350 if(error && size > zlibsettings.max_output_size) error = 112; in readChunk_iTXt()
5351if(!error) error = lodepng_add_itext_sized(info, key, langtag, transkey, (char *)str, size); in readChunk_iTXt()
5370 if(chunkLength != 7) return 73; /*invalid tIME chunk size*/ in readChunk_tIME()
5385 if(chunkLength != 9) return 74; /*invalid pHYs chunk size*/ in readChunk_pHYs()
5397 if(chunkLength != 4) return 96; /*invalid gAMA chunk size*/ in readChunk_gAMA()
5407 if(chunkLength != 32) return 97; /*invalid cHRM chunk size*/ in readChunk_cHRM()
5424 if(chunkLength != 1) return 98; /*invalid sRGB chunk size (this one is never ignored)*/ in readChunk_sRGB()
5444 if(info->iccp_name) lodepng_clear_icc(info); in readChunk_iCCP()
5447 if(length + 2 >= chunkLength) return 75; /*no null termination, corrupt?*/ in readChunk_iCCP()
5448 if(length < 1 || length > 79) return 89; /*keyword too short or long*/ in readChunk_iCCP()
5451 if(!info->iccp_name) return 83; /*alloc fail*/ in readChunk_iCCP()
5456 if(data[length + 1] != 0) return 72; /*the 0 byte indicating compression must be 0*/ in readChunk_iCCP()
5459 if(string2_begin > chunkLength) return 75; /*no null termination, corrupt?*/ in readChunk_iCCP()
5467 if(error && size > zlibsettings.max_output_size) error = 113; in readChunk_iCCP()
5469 if(!error && !info->iccp_profile_size) error = 100; /*invalid ICC profile size*/ in readChunk_iCCP()
5477 if(info->color.colortype == LCT_GREY) { in readChunk_sBIT()
5479 if(chunkLength != 1) return 114; in readChunk_sBIT()
5480 if(data[0] == 0 || data[0] > bitdepth) return 115; in readChunk_sBIT()
5484 else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_PALETTE) { in readChunk_sBIT()
5486 if(chunkLength != 3) return 114; in readChunk_sBIT()
5487 if(data[0] == 0 || data[1] == 0 || data[2] == 0) return 115; in readChunk_sBIT()
5488 if(data[0] > bitdepth || data[1] > bitdepth || data[2] > bitdepth) return 115; in readChunk_sBIT()
5494 else if(info->color.colortype == LCT_GREY_ALPHA) { in readChunk_sBIT()
5496 if(chunkLength != 2) return 114; in readChunk_sBIT()
5497 if(data[0] == 0 || data[1] == 0) return 115; in readChunk_sBIT()
5498 if(data[0] > bitdepth || data[1] > bitdepth) return 115; in readChunk_sBIT()
5503 else if(info->color.colortype == LCT_RGBA) { in readChunk_sBIT()
5505 if(chunkLength != 4) return 114; in readChunk_sBIT()
5506 if(data[0] == 0 || data[1] == 0 || data[2] == 0 || data[3] == 0) return 115; in readChunk_sBIT()
5507if(data[0] > bitdepth || data[1] > bitdepth || data[2] > bitdepth || data[3] > bitdepth) return 11… in readChunk_sBIT()
5528 if(pos + 4 > insize) return 30; in lodepng_inspect_chunk()
5530 if(chunkLength > 2147483647) return 63; in lodepng_inspect_chunk()
5532 if(chunkLength + 12 > insize - pos) return 30; in lodepng_inspect_chunk()
5534 if(lodepng_chunk_type_equals(chunk, "PLTE")) { in lodepng_inspect_chunk()
5537 else if(lodepng_chunk_type_equals(chunk, "tRNS")) { in lodepng_inspect_chunk()
5541 else if(lodepng_chunk_type_equals(chunk, "bKGD")) { in lodepng_inspect_chunk()
5544 else if(lodepng_chunk_type_equals(chunk, "tEXt")) { in lodepng_inspect_chunk()
5547 else if(lodepng_chunk_type_equals(chunk, "zTXt")) { in lodepng_inspect_chunk()
5550 else if(lodepng_chunk_type_equals(chunk, "iTXt")) { in lodepng_inspect_chunk()
5553 else if(lodepng_chunk_type_equals(chunk, "tIME")) { in lodepng_inspect_chunk()
5556 else if(lodepng_chunk_type_equals(chunk, "pHYs")) { in lodepng_inspect_chunk()
5559 else if(lodepng_chunk_type_equals(chunk, "gAMA")) { in lodepng_inspect_chunk()
5562 else if(lodepng_chunk_type_equals(chunk, "cHRM")) { in lodepng_inspect_chunk()
5565 else if(lodepng_chunk_type_equals(chunk, "sRGB")) { in lodepng_inspect_chunk()
5568 else if(lodepng_chunk_type_equals(chunk, "iCCP")) { in lodepng_inspect_chunk()
5571 else if(lodepng_chunk_type_equals(chunk, "sBIT")) { in lodepng_inspect_chunk()
5580 if(!error && !unhandled && !state->decoder.ignore_crc) { in lodepng_inspect_chunk()
5581 if(lodepng_chunk_check_crc(chunk)) return 57; /*invalid CRC*/ in lodepng_inspect_chunk()
5612 if(state->error) return; in decodeGeneric()
5614 if(lodepng_pixel_overflow(*w, *h, &state->info_png.color, &state->info_raw)) { in decodeGeneric()
5620 if(!idat) CERROR_RETURN(state->error, 83); /*alloc fail*/ in decodeGeneric()
5632 if(chunk < in || pos + 12 > insize) { in decodeGeneric()
5633 if(state->decoder.ignore_end) break; /*other errors may still happen though*/ in decodeGeneric()
5640 if(chunkLength > 2147483647) { in decodeGeneric()
5641 if(state->decoder.ignore_end) break; /*other errors may still happen though*/ in decodeGeneric()
5645 if(pos + (size_t)chunkLength + 12 > insize || pos + (size_t)chunkLength + 12 < pos) { in decodeGeneric()
5654 if(lodepng_chunk_type_equals(chunk, "IDAT")) { in decodeGeneric()
5656 if(lodepng_addofl(idatsize, chunkLength, &newsize)) CERROR_BREAK(state->error, 95); in decodeGeneric()
5657 if(newsize > insize) CERROR_BREAK(state->error, 95); in decodeGeneric()
5664 else if(lodepng_chunk_type_equals(chunk, "IEND")) { in decodeGeneric()
5668 else if(lodepng_chunk_type_equals(chunk, "PLTE")) { in decodeGeneric()
5671 if(state->error) break; in decodeGeneric()
5676 else if(lodepng_chunk_type_equals(chunk, "tRNS")) { in decodeGeneric()
5681 if(state->error) break; in decodeGeneric()
5685 else if(lodepng_chunk_type_equals(chunk, "bKGD")) { in decodeGeneric()
5687 if(state->error) break; in decodeGeneric()
5689 else if(lodepng_chunk_type_equals(chunk, "tEXt")) { in decodeGeneric()
5691 if(state->decoder.read_text_chunks) { in decodeGeneric()
5693 if(state->error) break; in decodeGeneric()
5696 else if(lodepng_chunk_type_equals(chunk, "zTXt")) { in decodeGeneric()
5698 if(state->decoder.read_text_chunks) { in decodeGeneric()
5700 if(state->error) break; in decodeGeneric()
5703 else if(lodepng_chunk_type_equals(chunk, "iTXt")) { in decodeGeneric()
5705 if(state->decoder.read_text_chunks) { in decodeGeneric()
5707 if(state->error) break; in decodeGeneric()
5710 else if(lodepng_chunk_type_equals(chunk, "tIME")) { in decodeGeneric()
5712 if(state->error) break; in decodeGeneric()
5714 else if(lodepng_chunk_type_equals(chunk, "pHYs")) { in decodeGeneric()
5716 if(state->error) break; in decodeGeneric()
5718 else if(lodepng_chunk_type_equals(chunk, "gAMA")) { in decodeGeneric()
5720 if(state->error) break; in decodeGeneric()
5722 else if(lodepng_chunk_type_equals(chunk, "cHRM")) { in decodeGeneric()
5724 if(state->error) break; in decodeGeneric()
5726 else if(lodepng_chunk_type_equals(chunk, "sRGB")) { in decodeGeneric()
5728 if(state->error) break; in decodeGeneric()
5730 else if(lodepng_chunk_type_equals(chunk, "iCCP")) { in decodeGeneric()
5732 if(state->error) break; in decodeGeneric()
5734 else if(lodepng_chunk_type_equals(chunk, "sBIT")) { in decodeGeneric()
5736 if(state->error) break; in decodeGeneric()
5741 if(!state->decoder.ignore_critical && !lodepng_chunk_ancillary(chunk)) { in decodeGeneric()
5747 if(state->decoder.remember_unknown_chunks) { in decodeGeneric()
5750 if(state->error) break; in decodeGeneric()
5755if(!state->decoder.ignore_crc && !unknown) { /*check CRC if wanted, only on known chunk types*/ in decodeGeneric()
5756 if(lodepng_chunk_check_crc(chunk)) CERROR_BREAK(state->error, 57); /*invalid CRC*/ in decodeGeneric()
5759 if(!IEND) chunk = lodepng_chunk_next_const(chunk, in + insize); in decodeGeneric()
5762if(!state->error && state->info_png.color.colortype == LCT_PALETTE && !state->info_png.color.palet… in decodeGeneric()
5763 state->error = 106; /* error: PNG file must have PLTE chunk if color type is palette */ in decodeGeneric()
5766 if(!state->error) { in decodeGeneric()
5768 If the decompressed size does not match the prediction, the image must be corrupt.*/ in decodeGeneric()
5769 if(state->info_png.interlace_method == 0) { in decodeGeneric()
5778if(*w > 4) expected_size += lodepng_get_raw_size_idat((*w + 3) >> 3, (*h + 7) >> 3, bpp); in decodeGeneric()
5780if(*w > 2) expected_size += lodepng_get_raw_size_idat((*w + 1) >> 2, (*h + 3) >> 2, bpp); in decodeGeneric()
5782if(*w > 1) expected_size += lodepng_get_raw_size_idat((*w + 0) >> 1, (*h + 1) >> 1, bpp); in decodeGeneric()
5789if(!state->error && scanlines_size != expected_size) state->error = 91; /*decompressed size doesn'… in decodeGeneric()
5792 if(!state->error) { in decodeGeneric()
5794 if(decoded) { in decodeGeneric()
5800 if(!state->error) { in decodeGeneric()
5814 if(state->error) return state->error; in lodepng_decode()
5815if(!state->decoder.color_convert || lodepng_color_mode_equal(&state->info_raw, &state->info_png.co… in lodepng_decode()
5819 if(!state->decoder.color_convert) { in lodepng_decode()
5821 if(state->error) return state->error; in lodepng_decode()
5827 …/*TODO: check if this works according to the statement in the documentation: "The converter can co… in lodepng_decode()
5829 if(!(state->info_raw.colortype == LCT_RGB || state->info_raw.colortype == LCT_RGBA) in lodepng_decode()
5835 if(new_buf == NULL) { in lodepng_decode()
5842 if (state->error) { in lodepng_decode()
5893 if(!error) error = lodepng_decode_memory(out, w, h, buffer, buffersize, colortype, bitdepth); in lodepng_decode_file()
5926 #if defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ENCODER)
5954 if(dest->error) return; in lodepng_state_copy()
5956 if(dest->error) return; in lodepng_state_copy()
5973 if(!ucvector_resize(out, out->size + 8)) return 83; /*alloc fail*/ in writeSignature()
5997 /* only adds the chunk if needed (there is a key or palette with alpha) */
6003 if(info->palettesize == 0 || info->palettesize > 256) { in addChunk_PLTE()
6024 if(info->colortype == LCT_PALETTE) { in addChunk_tRNS()
6028 if(info->palette[4 * (i - 1) + 3] != 255) break; in addChunk_tRNS()
6031 if(amount) { in addChunk_tRNS()
6037 else if(info->colortype == LCT_GREY) { in addChunk_tRNS()
6038 if(info->key_defined) { in addChunk_tRNS()
6044 else if(info->colortype == LCT_RGB) { in addChunk_tRNS()
6045 if(info->key_defined) { in addChunk_tRNS()
6056 if(chunk) lodepng_chunk_generate_crc(chunk); in addChunk_tRNS()
6068 if(!error) { in addChunk_IDAT()
6087 if(keysize < 1 || keysize > 79) return 89; /*error: invalid keyword size*/ in addChunk_tEXt()
6105 if(keysize < 1 || keysize > 79) return 89; /*error: invalid keyword size*/ in addChunk_zTXt()
6109 if(!error) { in addChunk_zTXt()
6113 if(!error) { in addChunk_zTXt()
6135 if(keysize < 1 || keysize > 79) return 89; /*error: invalid keyword size*/ in addChunk_iTXt()
6137 if(compress) { in addChunk_iTXt()
6141 if(!error) { in addChunk_iTXt()
6145 if(!error) { in addChunk_iTXt()
6158 if(compress) { in addChunk_iTXt()
6174 if(info->color.colortype == LCT_GREY || info->color.colortype == LCT_GREY_ALPHA) { in addChunk_bKGD()
6179 else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_RGBA) { in addChunk_bKGD()
6188 else if(info->color.colortype == LCT_PALETTE) { in addChunk_bKGD()
6192 if(chunk) lodepng_chunk_generate_crc(chunk); in addChunk_bKGD()
6261 if(keysize < 1 || keysize > 79) return 89; /*error: invalid keyword size*/ in addChunk_iCCP()
6264 if(!error) { in addChunk_iCCP()
6268 if(!error) { in addChunk_iCCP()
6284 if(info->color.colortype == LCT_GREY) { in addChunk_sBIT()
6285 if(info->sbit_r == 0 || info->sbit_r > bitdepth) return 115; in addChunk_sBIT()
6289 else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_PALETTE) { in addChunk_sBIT()
6290 if(info->sbit_r == 0 || info->sbit_g == 0 || info->sbit_b == 0) return 115; in addChunk_sBIT()
6291if(info->sbit_r > bitdepth || info->sbit_g > bitdepth || info->sbit_b > bitdepth) return 115; in addChunk_sBIT()
6297 else if(info->color.colortype == LCT_GREY_ALPHA) { in addChunk_sBIT()
6298 if(info->sbit_r == 0 || info->sbit_a == 0) return 115; in addChunk_sBIT()
6299 if(info->sbit_r > bitdepth || info->sbit_a > bitdepth) return 115; in addChunk_sBIT()
6304 else if(info->color.colortype == LCT_RGBA) { in addChunk_sBIT()
6305 if(info->sbit_r == 0 || info->sbit_g == 0 || info->sbit_b == 0 || info->sbit_a == 0 || in addChunk_sBIT()
6316 if(chunk) lodepng_chunk_generate_crc(chunk); in addChunk_sBIT()
6335 if(prevline) { in filterScanline()
6343 if(prevline) { in filterScanline()
6353 if(prevline) { in filterScanline()
6375 if(i >= 65536) { in ilog2()
6379 if(i >= 256) { in ilog2()
6383 if(i >= 16) { in ilog2()
6387 if(i >= 4) { in ilog2()
6391 if(i >= 2) { in ilog2()
6401 if(i == 0) return 0; in ilog2i()
6430 …* If the image type is Palette, or the bit depth is smaller than 8, then do not filter the image … in filter()
6432 …* (The other case) If the image type is Grayscale or RGB (with or without Alpha), and the bit dept… in filter()
6435 This heuristic is used if filter strategy is LFS_MINSUM and filter_palette_zero is true. in filter()
6437If filter_palette_zero is true and filter_strategy is not LFS_MINSUM, the above heuristic is follo… in filter()
6441 if(settings->filter_palette_zero && in filter()
6444 if(bpp == 0) return 31; /*error: invalid color type*/ in filter()
6446 if(strategy >= LFS_ZERO && strategy <= LFS_FOUR) { in filter()
6456 else if(strategy == LFS_MINSUM) { in filter()
6464 if(!attempt[type]) error = 83; /*alloc fail*/ in filter()
6467 if(!error) { in filter()
6475 if(type == 0) { in filter()
6488 … /*check if this is smallest sum (or if type == 0 it's the first case so always store the values)*/ in filter()
6489 if(type == 0 || sum < smallest) { in filter()
6505 else if(strategy == LFS_ENTROPY) { in filter()
6513 if(!attempt[type]) error = 83; /*alloc fail*/ in filter()
6516 if(!error) { in filter()
6528 … /*check if this is smallest sum (or if type == 0 it's the first case so always store the values)*/ in filter()
6529 if(type == 0 || sum > bestSum) { in filter()
6545 else if(strategy == LFS_PREDEFINED) { in filter()
6555 else if(strategy == LFS_BRUTE_FORCE) { in filter()
6577 if(!attempt[type]) error = 83; /*alloc fail*/ in filter()
6579 if(!error) { in filter()
6583 … /*if(testsize > 8) testsize /= 8;*/ /*it already works good enough by testing a part of the row*/ in filter()
6590 …/*check if this is smallest size (or if type == 0 it's the first case so always store the values)*/ in filter()
6591 if(type == 0 || size[type] < smallest) { in filter()
6637 NOTE: comments about padding bits are only relevant if bpp < 8
6647 if(bpp >= 8) { in Adam7_interlace()
6688 *) if no Adam7: 1) add padding bits (= possible extra bits per scanline if bpp < 8) 2) filter in preProcessScanlines()
6689 *) if adam7: 1) Adam7_interlace 2) 7x add padding bits 3) 7x filter in preProcessScanlines()
6694 if(info_png->interlace_method == 0) { in preProcessScanlines()
6697 if(!(*out) && (*outsize)) error = 83; /*alloc fail*/ in preProcessScanlines()
6699 if(!error) { in preProcessScanlines()
6701 if(bpp < 8 && w * bpp != ((w * bpp + 7u) / 8u) * 8u) { in preProcessScanlines()
6703 if(!padded) error = 83; /*alloc fail*/ in preProcessScanlines()
6704 if(!error) { in preProcessScanlines()
6725 if(!(*out)) error = 83; /*alloc fail*/ in preProcessScanlines()
6728 if(!adam7 && passstart[7]) error = 83; /*alloc fail*/ in preProcessScanlines()
6730 if(!error) { in preProcessScanlines()
6735 if(bpp < 8) { in preProcessScanlines()
6737 if(!padded) ERROR_BREAK(83); /*alloc fail*/ in preProcessScanlines()
6749 if(error) break; in preProcessScanlines()
6774 It is a gray profile if bytes 16-19 are "GRAY", rgb profile if bytes 16-19 in isGrayICCProfile()
6778 requires using a non-gray color model if there is an ICC profile with "RGB " in isGrayICCProfile()
6779 (sadly limiting compression opportunities if the input data is grayscale RGB in isGrayICCProfile()
6780 data), and requires using a gray color model if it is "GRAY". in isGrayICCProfile()
6782 if(size < 20) return 0; in isGrayICCProfile()
6789 if(size < 20) return 0; in isRGBICCProfile()
6808 /*provide some proper output values if error will happen*/ in lodepng_encode()
6814 if((info_png->color.colortype == LCT_PALETTE || state->encoder.force_palette) in lodepng_encode()
6816 /*this error is returned even if auto_convert is enabled and thus encoder could in lodepng_encode()
6823 if(state->encoder.zlibsettings.btype > 2) { in lodepng_encode()
6827 if(info_png->interlace_method > 1) { in lodepng_encode()
6832 if(state->error) goto cleanup; /*error: invalid color type given*/ in lodepng_encode()
6834 if(state->error) goto cleanup; /*error: invalid color type given*/ in lodepng_encode()
6838 if(state->encoder.auto_convert) { in lodepng_encode()
6843 if(info_png->iccp_defined && in lodepng_encode()
6846 if the palette has only gray colors, so disallow it.*/ in lodepng_encode()
6849 if(info_png->iccp_defined && in lodepng_encode()
6856 if(state->error) goto cleanup; in lodepng_encode()
6858 if(info_png->background_defined) { in lodepng_encode()
6865 if(state->error) goto cleanup; in lodepng_encode()
6869 if(state->error) goto cleanup; in lodepng_encode()
6871 if(info_png->sbit_defined) { in lodepng_encode()
6872 …/*if sbit is defined, due to strict requirements of which sbit values can be present for which col… in lodepng_encode()
6875 auto_choose_color if knowledge about sbit is used beforehand in lodepng_encode()
6883 if(info.color.colortype == LCT_PALETTE && in lodepng_encode()
6891 if(info.color.colortype == LCT_RGB && in lodepng_encode()
6895 /*going from 8-bit RGBA to palette is also ok but only if sbit_a is exactly 8*/ in lodepng_encode()
6896 if(info.color.colortype == LCT_RGBA && auto_color.colortype == LCT_PALETTE && in lodepng_encode()
6900 /*going from 16-bit RGB(A) to 8-bit RGB(A) is ok if all sbit values are <= 8*/ in lodepng_encode()
6901if((info.color.colortype == LCT_RGB || info.color.colortype == LCT_RGBA) && info.color.bitdepth ==… in lodepng_encode()
6906 /*going to less channels is ok if all bit values are equal (all possible values in sbit, in lodepng_encode()
6909 info.colortype. Palette is not used here. This conversion is not allowed if in lodepng_encode()
6914 if(info.color.colortype != LCT_PALETTE && auto_color.colortype != LCT_PALETTE && in lodepng_encode()
6920 if(state->encoder.force_palette) { in lodepng_encode()
6921 if(info.color.colortype != LCT_GREY && info.color.colortype != LCT_GREY_ALPHA && in lodepng_encode()
6928 if(allow_convert) { in lodepng_encode()
6932 if(info_png->background_defined) { in lodepng_encode()
6933 if(lodepng_convert_rgb(&info.background_r, &info.background_g, &info.background_b, in lodepng_encode()
6943 if(info_png->iccp_defined) { in lodepng_encode()
6947 if(!gray_icc && !rgb_icc) { in lodepng_encode()
6951 if(gray_icc != gray_png) { in lodepng_encode()
6959 if(!lodepng_color_mode_equal(&state->info_raw, &info.color)) { in lodepng_encode()
6964 if(!converted && size) state->error = 83; /*alloc fail*/ in lodepng_encode()
6965 if(!state->error) { in lodepng_encode()
6968 if(!state->error) { in lodepng_encode()
6972 if(state->error) goto cleanup; in lodepng_encode()
6976 if(state->error) goto cleanup; in lodepng_encode()
6985 if(state->error) goto cleanup; in lodepng_encode()
6988 if(state->error) goto cleanup; in lodepng_encode()
6991 if(info.unknown_chunks_data[0]) { in lodepng_encode()
6993 if(state->error) goto cleanup; in lodepng_encode()
6996 if(info.iccp_defined) { in lodepng_encode()
6998 if(state->error) goto cleanup; in lodepng_encode()
7000 if(info.srgb_defined) { in lodepng_encode()
7002 if(state->error) goto cleanup; in lodepng_encode()
7004 if(info.gama_defined) { in lodepng_encode()
7006 if(state->error) goto cleanup; in lodepng_encode()
7008 if(info.chrm_defined) { in lodepng_encode()
7010 if(state->error) goto cleanup; in lodepng_encode()
7012 if(info_png->sbit_defined) { in lodepng_encode()
7014 if(state->error) goto cleanup; in lodepng_encode()
7018 if(info.color.colortype == LCT_PALETTE) { in lodepng_encode()
7020 if(state->error) goto cleanup; in lodepng_encode()
7022if(state->encoder.force_palette && (info.color.colortype == LCT_RGB || info.color.colortype == LCT… in lodepng_encode()
7025 if(state->error) goto cleanup; in lodepng_encode()
7027 /*tRNS (this will only add if when necessary) */ in lodepng_encode()
7029 if(state->error) goto cleanup; in lodepng_encode()
7032 if(info.background_defined) { in lodepng_encode()
7034 if(state->error) goto cleanup; in lodepng_encode()
7037 if(info.phys_defined) { in lodepng_encode()
7039 if(state->error) goto cleanup; in lodepng_encode()
7043 if(info.unknown_chunks_data[1]) { in lodepng_encode()
7045 if(state->error) goto cleanup; in lodepng_encode()
7050 if(state->error) goto cleanup; in lodepng_encode()
7053 if(info.time_defined) { in lodepng_encode()
7055 if(state->error) goto cleanup; in lodepng_encode()
7059 if(lodepng_strlen(info.text_keys[i]) > 79) { in lodepng_encode()
7063 if(lodepng_strlen(info.text_keys[i]) < 1) { in lodepng_encode()
7067 if(state->encoder.text_compression) { in lodepng_encode()
7069 if(state->error) goto cleanup; in lodepng_encode()
7073 if(state->error) goto cleanup; in lodepng_encode()
7077 if(state->encoder.add_id) { in lodepng_encode()
7082 if(k[0] == 'L' && k[1] == 'o' && k[2] == 'd' && k[3] == 'e' && in lodepng_encode()
7088 if(already_added_id_text == 0) { in lodepng_encode()
7090 if(state->error) goto cleanup; in lodepng_encode()
7095 if(lodepng_strlen(info.itext_keys[i]) > 79) { in lodepng_encode()
7099 if(lodepng_strlen(info.itext_keys[i]) < 1) { in lodepng_encode()
7107 if(state->error) goto cleanup; in lodepng_encode()
7111 if(info.unknown_chunks_data[2]) { in lodepng_encode()
7113 if(state->error) goto cleanup; in lodepng_encode()
7117 if(state->error) goto cleanup; in lodepng_encode()
7165 if(!error) error = lodepng_save_file(buffer, buffersize, filename); in lodepng_encode_file()
7220 /*this error could happen if there are only 0 or 1 symbols present in the huffman code:*/ in lodepng_error_text()
7235 …This can happen if the inflated deflate data is longer than the amount of bytes required to fill up in lodepng_error_text()
7367 … return "must provide custom zlib function pointer if LODEPNG_COMPILE_ZLIB is not defined"; in lodepng_error_text()
7406 return "PNG file must have PLTE chunk if color type is palette"; in lodepng_error_text()
7449 if(size < 0) return 78; in load_file()
7469 if(buffer) { in decompress()
7490 if(buffer) { in compress()
7537 if(buffer && !error) { in decode()
7560 if(buffer && !error) { in decode()
7583 if(error) return error; in decode()
7596 if(buffer) { in encode()
7607 if(lodepng_get_raw_size_lct(w, h, colortype, bitdepth) > in.size()) return 84; in encode()
7618 if(buffer) { in encode()
7629 if(lodepng_get_raw_size(w, h, &state.info_raw) > in.size()) return 84; in encode()
7640 if(!error) error = save_file(buffer, filename); in encode()
7648 if(lodepng_get_raw_size_lct(w, h, colortype, bitdepth) > in.size()) return 84; in encode()