Commit 7e086528aecc3093d88d7e5379d5329a711266f6

Authored by Peter Zhigalov
1 parent 725a57ab

Обновил LodePNG до версии 20160124

src_winapi/libs/lodepng.cpp
1 1 /*
2   -LodePNG version 20150418
  2 +LodePNG version 20160124
3 3  
4   -Copyright (c) 2005-2015 Lode Vandevenne
  4 +Copyright (c) 2005-2016 Lode Vandevenne
5 5  
6 6 This software is provided 'as-is', without any express or implied
7 7 warranty. In no event will the authors be held liable for any damages
... ... @@ -42,7 +42,7 @@ Rename this file to lodepng.cpp to use it for C++, or to lodepng.c to use it for
42 42 #pragma warning( disable : 4996 ) /*VS does not like fopen, but fopen_s is not standard C so unusable here*/
43 43 #endif /*_MSC_VER */
44 44  
45   -const char* LODEPNG_VERSION_STRING = "20150418";
  45 +const char* LODEPNG_VERSION_STRING = "20160124";
46 46  
47 47 /*
48 48 This source file is built up in the following large parts. The code sections
... ... @@ -251,17 +251,6 @@ static void ucvector_init(ucvector* p)
251 251 p->data = NULL;
252 252 p->size = p->allocsize = 0;
253 253 }
254   -
255   -#ifdef LODEPNG_COMPILE_DECODER
256   -/*resize and give all new elements the value*/
257   -static unsigned ucvector_resizev(ucvector* p, size_t size, unsigned char value)
258   -{
259   - size_t oldsize = p->size, i;
260   - if(!ucvector_resize(p, size)) return 0;
261   - for(i = oldsize; i < size; ++i) p->data[i] = value;
262   - return 1;
263   -}
264   -#endif /*LODEPNG_COMPILE_DECODER*/
265 254 #endif /*LODEPNG_COMPILE_PNG*/
266 255  
267 256 #ifdef LODEPNG_COMPILE_ZLIB
... ... @@ -549,7 +538,7 @@ static unsigned HuffmanTree_make2DTree(HuffmanTree* tree)
549 538 uninited, a value >= numcodes is an address to another bit, a value < numcodes
550 539 is a code. The 2 rows are the 2 possible bit values (0 or 1), there are as
551 540 many columns as codes - 1.
552   - A good huffmann tree has N * 2 - 1 nodes, of which N - 1 are internal nodes.
  541 + A good huffman tree has N * 2 - 1 nodes, of which N - 1 are internal nodes.
553 542 Here, the internal nodes are stored (what their 0 and 1 option point to).
554 543 There is only memory for such good tree currently, if there are more nodes
555 544 (due to too long length codes), error 55 will happen
... ... @@ -779,7 +768,7 @@ unsigned lodepng_huffman_code_lengths(unsigned* lengths, const unsigned* frequen
779 768 {
780 769 if(frequencies[i] > 0)
781 770 {
782   - leaves[numpresent].weight = frequencies[i];
  771 + leaves[numpresent].weight = (int)frequencies[i];
783 772 leaves[numpresent].index = i;
784 773 ++numpresent;
785 774 }
... ... @@ -832,7 +821,7 @@ unsigned lodepng_huffman_code_lengths(unsigned* lengths, const unsigned* frequen
832 821 }
833 822  
834 823 /*each boundaryPM call adds one chain to the last list, and we need 2 * numpresent - 2 chains.*/
835   - for(i = 2; i != 2 * numpresent - 2; ++i) boundaryPM(&lists, leaves, numpresent, maxbitlen - 1, i);
  824 + for(i = 2; i != 2 * numpresent - 2; ++i) boundaryPM(&lists, leaves, numpresent, (int)maxbitlen - 1, (int)i);
836 825  
837 826 for(node = lists.chains1[maxbitlen - 1]; node; node = node->tail)
838 827 {
... ... @@ -1302,21 +1291,17 @@ static void addHuffmanSymbol(size_t* bp, ucvector* compressed, unsigned code, un
1302 1291 given array must be sorted (if no value is smaller, it returns the size of the given array)*/
1303 1292 static size_t searchCodeIndex(const unsigned* array, size_t array_size, size_t value)
1304 1293 {
1305   - /*linear search implementation*/
1306   - /*for(size_t i = 1; i < array_size; ++i) if(array[i] > value) return i - 1;
1307   - return array_size - 1;*/
1308   -
1309   - /*binary search implementation (not that much faster) (precondition: array_size > 0)*/
1310   - size_t left = 1;
  1294 + /*binary search (only small gain over linear). TODO: use CPU log2 instruction for getting symbols instead*/
  1295 + size_t left = 1;
1311 1296 size_t right = array_size - 1;
1312   - while(left <= right)
1313   - {
1314   - size_t mid = (left + right) / 2;
1315   - if(array[mid] <= value) left = mid + 1; /*the value to find is more to the right*/
1316   - else if(array[mid - 1] > value) right = mid - 1; /*the value to find is more to the left*/
1317   - else return mid - 1;
  1297 +
  1298 + while(left <= right) {
  1299 + size_t mid = (left + right) >> 1;
  1300 + if (array[mid] >= value) right = mid - 1;
  1301 + else left = mid + 1;
1318 1302 }
1319   - return array_size - 1;
  1303 + if(left >= array_size || array[left] > value) left--;
  1304 + return left;
1320 1305 }
1321 1306  
1322 1307 static void addLengthDistance(uivector* values, size_t length, size_t distance)
... ... @@ -1651,10 +1636,10 @@ static unsigned deflateNoCompression(ucvector* out, const unsigned char* data, s
1651 1636 if(datasize - datapos < 65535) LEN = (unsigned)datasize - datapos;
1652 1637 NLEN = 65535 - LEN;
1653 1638  
1654   - ucvector_push_back(out, (unsigned char)(LEN % 256));
1655   - ucvector_push_back(out, (unsigned char)(LEN / 256));
1656   - ucvector_push_back(out, (unsigned char)(NLEN % 256));
1657   - ucvector_push_back(out, (unsigned char)(NLEN / 256));
  1639 + ucvector_push_back(out, (unsigned char)(LEN & 255));
  1640 + ucvector_push_back(out, (unsigned char)(LEN >> 8));
  1641 + ucvector_push_back(out, (unsigned char)(NLEN & 255));
  1642 + ucvector_push_back(out, (unsigned char)(NLEN >> 8));
1658 1643  
1659 1644 /*Decompressed data*/
1660 1645 for(j = 0; j < 65535 && datapos < datasize; ++j)
... ... @@ -1768,7 +1753,7 @@ static unsigned deflateDynamic(ucvector* out, size_t* bp, Hash* hash,
1768 1753 else
1769 1754 {
1770 1755 if(!uivector_resize(&lz77_encoded, datasize)) ERROR_BREAK(83 /*alloc fail*/);
1771   - for(i = datapos; i < dataend; ++i) lz77_encoded.data[i] = data[i]; /*no LZ77, but still will be Huffman compressed*/
  1756 + for(i = datapos; i < dataend; ++i) lz77_encoded.data[i - datapos] = data[i]; /*no LZ77, but still will be Huffman compressed*/
1772 1757 }
1773 1758  
1774 1759 if(!uivector_resizev(&frequencies_ll, 286, 0)) ERROR_BREAK(83 /*alloc fail*/);
... ... @@ -2186,8 +2171,8 @@ unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, const unsig
2186 2171 /*ucvector-controlled version of the output buffer, for dynamic array*/
2187 2172 ucvector_init_buffer(&outv, *out, *outsize);
2188 2173  
2189   - ucvector_push_back(&outv, (unsigned char)(CMFFLG / 256));
2190   - ucvector_push_back(&outv, (unsigned char)(CMFFLG % 256));
  2174 + ucvector_push_back(&outv, (unsigned char)(CMFFLG >> 8));
  2175 + ucvector_push_back(&outv, (unsigned char)(CMFFLG & 255));
2191 2176  
2192 2177 error = deflate(&deflatedata, &deflatesize, in, insize, settings);
2193 2178  
... ... @@ -2296,6 +2281,8 @@ const LodePNGDecompressSettings lodepng_default_decompress_settings = {0, 0, 0,
2296 2281 /* / CRC32 / */
2297 2282 /* ////////////////////////////////////////////////////////////////////////// */
2298 2283  
  2284 +
  2285 +#ifndef LODEPNG_NO_COMPILE_CRC
2299 2286 /* CRC polynomial: 0xedb88320 */
2300 2287 static unsigned lodepng_crc32_table[256] = {
2301 2288 0u, 1996959894u, 3993919788u, 2567524794u, 124634137u, 1886057615u, 3915621685u, 2657392035u,
... ... @@ -2333,17 +2320,19 @@ static unsigned lodepng_crc32_table[256] = {
2333 2320 };
2334 2321  
2335 2322 /*Return the CRC of the bytes buf[0..len-1].*/
2336   -unsigned lodepng_crc32(const unsigned char* buf, size_t len)
  2323 +unsigned lodepng_crc32(const unsigned char* data, size_t length)
2337 2324 {
2338   - unsigned c = 0xffffffffL;
2339   - size_t n;
2340   -
2341   - for(n = 0; n < len; ++n)
  2325 + unsigned r = 0xffffffffu;
  2326 + size_t i;
  2327 + for(i = 0; i < length; ++i)
2342 2328 {
2343   - c = lodepng_crc32_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);
  2329 + r = lodepng_crc32_table[(r ^ data[i]) & 0xff] ^ (r >> 8);
2344 2330 }
2345   - return c ^ 0xffffffffL;
  2331 + return r ^ 0xffffffffu;
2346 2332 }
  2333 +#else /* !LODEPNG_NO_COMPILE_CRC */
  2334 +unsigned lodepng_crc32(const unsigned char* data, size_t length);
  2335 +#endif /* !LODEPNG_NO_COMPILE_CRC */
2347 2336  
2348 2337 /* ////////////////////////////////////////////////////////////////////////// */
2349 2338 /* / Reading and writing single bits and bytes from/to stream for LodePNG / */
... ... @@ -2595,10 +2584,15 @@ static int lodepng_color_mode_equal(const LodePNGColorMode* a, const LodePNGColo
2595 2584 if(a->key_g != b->key_g) return 0;
2596 2585 if(a->key_b != b->key_b) return 0;
2597 2586 }
2598   - if(a->palettesize != b->palettesize) return 0;
2599   - for(i = 0; i != a->palettesize * 4; ++i)
2600   - {
2601   - if(a->palette[i] != b->palette[i]) return 0;
  2587 + /*if one of the palette sizes is 0, then we consider it to be the same as the
  2588 + other: it means that e.g. the palette was not given by the user and should be
  2589 + considered the same as the palette inside the PNG.*/
  2590 + if(1/*a->palettesize != 0 && b->palettesize != 0*/) {
  2591 + if(a->palettesize != b->palettesize) return 0;
  2592 + for(i = 0; i != a->palettesize * 4; ++i)
  2593 + {
  2594 + if(a->palette[i] != b->palette[i]) return 0;
  2595 + }
2602 2596 }
2603 2597 return 1;
2604 2598 }
... ... @@ -2676,12 +2670,18 @@ unsigned lodepng_can_have_alpha(const LodePNGColorMode* info)
2676 2670  
2677 2671 size_t lodepng_get_raw_size(unsigned w, unsigned h, const LodePNGColorMode* color)
2678 2672 {
2679   - return (w * h * lodepng_get_bpp(color) + 7) / 8;
  2673 + /*will not overflow for any color type if roughly w * h < 268435455*/
  2674 + int bpp = lodepng_get_bpp(color);
  2675 + size_t n = w * h;
  2676 + return ((n / 8) * bpp) + ((n & 7) * bpp + 7) / 8;
2680 2677 }
2681 2678  
2682 2679 size_t lodepng_get_raw_size_lct(unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth)
2683 2680 {
2684   - return (w * h * lodepng_get_bpp_lct(colortype, bitdepth) + 7) / 8;
  2681 + /*will not overflow for any color type if roughly w * h < 268435455*/
  2682 + int bpp = lodepng_get_bpp_lct(colortype, bitdepth);
  2683 + size_t n = w * h;
  2684 + return ((n / 8) * bpp) + ((n & 7) * bpp + 7) / 8;
2685 2685 }
2686 2686  
2687 2687  
... ... @@ -2690,7 +2690,10 @@ size_t lodepng_get_raw_size_lct(unsigned w, unsigned h, LodePNGColorType colorty
2690 2690 /*in an idat chunk, each scanline is a multiple of 8 bits, unlike the lodepng output buffer*/
2691 2691 static size_t lodepng_get_raw_size_idat(unsigned w, unsigned h, const LodePNGColorMode* color)
2692 2692 {
2693   - return h * ((w * lodepng_get_bpp(color) + 7) / 8);
  2693 + /*will not overflow for any color type if roughly w * h < 268435455*/
  2694 + int bpp = lodepng_get_bpp(color);
  2695 + size_t line = ((w / 8) * bpp) + ((w & 7) * bpp + 7) / 8;
  2696 + return h * line;
2694 2697 }
2695 2698 #endif /*LODEPNG_COMPILE_DECODER*/
2696 2699 #endif /*LODEPNG_COMPILE_PNG*/
... ... @@ -3393,30 +3396,31 @@ static void getPixelColorRGBA16(unsigned short* r, unsigned short* g, unsigned s
3393 3396 }
3394 3397 else if(mode->colortype == LCT_RGB)
3395 3398 {
3396   - *r = 256 * in[i * 6 + 0] + in[i * 6 + 1];
3397   - *g = 256 * in[i * 6 + 2] + in[i * 6 + 3];
3398   - *b = 256 * in[i * 6 + 4] + in[i * 6 + 5];
3399   - if(mode->key_defined && 256U * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r
3400   - && 256U * in[i * 6 + 2] + in[i * 6 + 3] == mode->key_g
3401   - && 256U * in[i * 6 + 4] + in[i * 6 + 5] == mode->key_b) *a = 0;
  3399 + *r = 256u * in[i * 6 + 0] + in[i * 6 + 1];
  3400 + *g = 256u * in[i * 6 + 2] + in[i * 6 + 3];
  3401 + *b = 256u * in[i * 6 + 4] + in[i * 6 + 5];
  3402 + if(mode->key_defined
  3403 + && 256u * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r
  3404 + && 256u * in[i * 6 + 2] + in[i * 6 + 3] == mode->key_g
  3405 + && 256u * in[i * 6 + 4] + in[i * 6 + 5] == mode->key_b) *a = 0;
3402 3406 else *a = 65535;
3403 3407 }
3404 3408 else if(mode->colortype == LCT_GREY_ALPHA)
3405 3409 {
3406   - *r = *g = *b = 256 * in[i * 4 + 0] + in[i * 4 + 1];
3407   - *a = 256 * in[i * 4 + 2] + in[i * 4 + 3];
  3410 + *r = *g = *b = 256u * in[i * 4 + 0] + in[i * 4 + 1];
  3411 + *a = 256u * in[i * 4 + 2] + in[i * 4 + 3];
3408 3412 }
3409 3413 else if(mode->colortype == LCT_RGBA)
3410 3414 {
3411   - *r = 256 * in[i * 8 + 0] + in[i * 8 + 1];
3412   - *g = 256 * in[i * 8 + 2] + in[i * 8 + 3];
3413   - *b = 256 * in[i * 8 + 4] + in[i * 8 + 5];
3414   - *a = 256 * in[i * 8 + 6] + in[i * 8 + 7];
  3415 + *r = 256u * in[i * 8 + 0] + in[i * 8 + 1];
  3416 + *g = 256u * in[i * 8 + 2] + in[i * 8 + 3];
  3417 + *b = 256u * in[i * 8 + 4] + in[i * 8 + 5];
  3418 + *a = 256u * in[i * 8 + 6] + in[i * 8 + 7];
3415 3419 }
3416 3420 }
3417 3421  
3418 3422 unsigned lodepng_convert(unsigned char* out, const unsigned char* in,
3419   - LodePNGColorMode* mode_out, const LodePNGColorMode* mode_in,
  3423 + const LodePNGColorMode* mode_out, const LodePNGColorMode* mode_in,
3420 3424 unsigned w, unsigned h)
3421 3425 {
3422 3426 size_t i;
... ... @@ -3432,12 +3436,22 @@ unsigned lodepng_convert(unsigned char* out, const unsigned char* in,
3432 3436  
3433 3437 if(mode_out->colortype == LCT_PALETTE)
3434 3438 {
  3439 + size_t palettesize = mode_out->palettesize;
  3440 + const unsigned char* palette = mode_out->palette;
3435 3441 size_t palsize = 1u << mode_out->bitdepth;
3436   - if(mode_out->palettesize < palsize) palsize = mode_out->palettesize;
  3442 + /*if the user specified output palette but did not give the values, assume
  3443 + they want the values of the input color type (assuming that one is palette).
  3444 + Note that we never create a new palette ourselves.*/
  3445 + if(palettesize == 0)
  3446 + {
  3447 + palettesize = mode_in->palettesize;
  3448 + palette = mode_in->palette;
  3449 + }
  3450 + if(palettesize < palsize) palsize = palettesize;
3437 3451 color_tree_init(&tree);
3438 3452 for(i = 0; i != palsize; ++i)
3439 3453 {
3440   - unsigned char* p = &mode_out->palette[i * 4];
  3454 + const unsigned char* p = &palette[i * 4];
3441 3455 color_tree_add(&tree, p[0], p[1], p[2], p[3], (unsigned)i);
3442 3456 }
3443 3457 }
... ... @@ -3465,7 +3479,7 @@ unsigned lodepng_convert(unsigned char* out, const unsigned char* in,
3465 3479 for(i = 0; i != numpixels; ++i)
3466 3480 {
3467 3481 getPixelColorRGBA8(&r, &g, &b, &a, in, i, mode_in);
3468   - rgba8ToPixel(out, i, mode_out, &tree, r, g, b, a);
  3482 + CERROR_TRY_RETURN(rgba8ToPixel(out, i, mode_out, &tree, r, g, b, a));
3469 3483 }
3470 3484 }
3471 3485  
... ... @@ -3474,7 +3488,7 @@ unsigned lodepng_convert(unsigned char* out, const unsigned char* in,
3474 3488 color_tree_cleanup(&tree);
3475 3489 }
3476 3490  
3477   - return 0; /*no error (this function currently never has one, but maybe OOM detection added later.)*/
  3491 + return 0; /*no error*/
3478 3492 }
3479 3493  
3480 3494 #ifdef LODEPNG_COMPILE_ENCODER
... ... @@ -3838,7 +3852,11 @@ unsigned lodepng_inspect(unsigned* w, unsigned* h, LodePNGState* state,
3838 3852 {
3839 3853 CERROR_RETURN_ERROR(state->error, 28); /*error: the first 8 bytes are not the correct PNG signature*/
3840 3854 }
3841   - if(in[12] != 'I' || in[13] != 'H' || in[14] != 'D' || in[15] != 'R')
  3855 + if(lodepng_chunk_length(in + 8) != 13)
  3856 + {
  3857 + CERROR_RETURN_ERROR(state->error, 94); /*error: header size must be 13 bytes*/
  3858 + }
  3859 + if(!lodepng_chunk_type_equals(in + 8, "IHDR"))
3842 3860 {
3843 3861 CERROR_RETURN_ERROR(state->error, 29); /*error: it doesn't start with a IHDR chunk!*/
3844 3862 }
... ... @@ -3913,13 +3931,13 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
3913 3931 case 3:
3914 3932 if(precon)
3915 3933 {
3916   - for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i] + precon[i] / 2;
3917   - for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + ((recon[i - bytewidth] + precon[i]) / 2);
  3934 + for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i] + (precon[i] >> 1);
  3935 + for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + ((recon[i - bytewidth] + precon[i]) >> 1);
3918 3936 }
3919 3937 else
3920 3938 {
3921 3939 for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i];
3922   - for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + recon[i - bytewidth] / 2;
  3940 + for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + (recon[i - bytewidth] >> 1);
3923 3941 }
3924 3942 break;
3925 3943 case 4:
... ... @@ -4094,7 +4112,7 @@ static unsigned postProcessScanlines(unsigned char* out, unsigned char* in,
4094 4112 CERROR_TRY_RETURN(unfilter(in, in, w, h, bpp));
4095 4113 removePaddingBits(out, in, w * bpp, ((w * bpp + 7) / 8) * 8, h);
4096 4114 }
4097   - /*we can immediatly filter into the out buffer, no other steps needed*/
  4115 + /*we can immediately filter into the out buffer, no other steps needed*/
4098 4116 else CERROR_TRY_RETURN(unfilter(out, in, w, h, bpp));
4099 4117 }
4100 4118 else /*interlace_method is 1 (Adam7)*/
... ... @@ -4600,13 +4618,13 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
4600 4618 /*Adam-7 interlaced: predicted size is the sum of the 7 sub-images sizes*/
4601 4619 const LodePNGColorMode* color = &state->info_png.color;
4602 4620 predict = 0;
4603   - predict += lodepng_get_raw_size_idat((*w + 7) / 8, (*h + 7) / 8, color) + (*h + 7) / 8;
4604   - if(*w > 4) predict += lodepng_get_raw_size_idat((*w + 3) / 8, (*h + 7) / 8, color) + (*h + 7) / 8;
4605   - predict += lodepng_get_raw_size_idat((*w + 3) / 4, (*h + 3) / 8, color) + (*h + 3) / 8;
4606   - if(*w > 2) predict += lodepng_get_raw_size_idat((*w + 1) / 4, (*h + 3) / 4, color) + (*h + 3) / 4;
4607   - predict += lodepng_get_raw_size_idat((*w + 1) / 2, (*h + 1) / 4, color) + (*h + 1) / 4;
4608   - if(*w > 1) predict += lodepng_get_raw_size_idat((*w + 0) / 2, (*h + 1) / 2, color) + (*h + 1) / 2;
4609   - predict += lodepng_get_raw_size_idat((*w + 0) / 1, (*h + 0) / 2, color) + (*h + 0) / 2;
  4621 + predict += lodepng_get_raw_size_idat((*w + 7) >> 3, (*h + 7) >> 3, color) + ((*h + 7) >> 3);
  4622 + if(*w > 4) predict += lodepng_get_raw_size_idat((*w + 3) >> 3, (*h + 7) >> 3, color) + ((*h + 7) >> 3);
  4623 + predict += lodepng_get_raw_size_idat((*w + 3) >> 2, (*h + 3) >> 3, color) + ((*h + 3) >> 3);
  4624 + if(*w > 2) predict += lodepng_get_raw_size_idat((*w + 1) >> 2, (*h + 3) >> 2, color) + ((*h + 3) >> 2);
  4625 + predict += lodepng_get_raw_size_idat((*w + 1) >> 1, (*h + 1) >> 2, color) + ((*h + 1) >> 2);
  4626 + if(*w > 1) predict += lodepng_get_raw_size_idat((*w + 0) >> 1, (*h + 1) >> 1, color) + ((*h + 1) >> 1);
  4627 + predict += lodepng_get_raw_size_idat((*w + 0), (*h + 0) >> 1, color) + ((*h + 0) >> 1);
4610 4628 }
4611 4629 if(!state->error && !ucvector_reserve(&scanlines, predict)) state->error = 83; /*alloc fail*/
4612 4630 if(!state->error)
... ... @@ -4620,11 +4638,10 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
4620 4638 if(!state->error)
4621 4639 {
4622 4640 size_t outsize = lodepng_get_raw_size(*w, *h, &state->info_png.color);
4623   - ucvector outv;
4624   - ucvector_init(&outv);
4625   - if(!ucvector_resizev(&outv, outsize, 0)) state->error = 83; /*alloc fail*/
4626   - if(!state->error) state->error = postProcessScanlines(outv.data, scanlines.data, *w, *h, &state->info_png);
4627   - *out = outv.data;
  4641 + *out = (unsigned char*)lodepng_malloc(outsize);
  4642 + if(!*out) state->error = 83; /*alloc fail*/
  4643 + for(i = 0; i < outsize; i++) (*out)[i] = 0;
  4644 + if(!state->error) state->error = postProcessScanlines(*out, scanlines.data, *w, *h, &state->info_png);
4628 4645 }
4629 4646 ucvector_cleanup(&scanlines);
4630 4647 }
... ... @@ -4854,20 +4871,20 @@ static unsigned addChunk_tRNS(ucvector* out, const LodePNGColorMode* info)
4854 4871 {
4855 4872 if(info->key_defined)
4856 4873 {
4857   - ucvector_push_back(&tRNS, (unsigned char)(info->key_r / 256));
4858   - ucvector_push_back(&tRNS, (unsigned char)(info->key_r % 256));
  4874 + ucvector_push_back(&tRNS, (unsigned char)(info->key_r >> 8));
  4875 + ucvector_push_back(&tRNS, (unsigned char)(info->key_r & 255));
4859 4876 }
4860 4877 }
4861 4878 else if(info->colortype == LCT_RGB)
4862 4879 {
4863 4880 if(info->key_defined)
4864 4881 {
4865   - ucvector_push_back(&tRNS, (unsigned char)(info->key_r / 256));
4866   - ucvector_push_back(&tRNS, (unsigned char)(info->key_r % 256));
4867   - ucvector_push_back(&tRNS, (unsigned char)(info->key_g / 256));
4868   - ucvector_push_back(&tRNS, (unsigned char)(info->key_g % 256));
4869   - ucvector_push_back(&tRNS, (unsigned char)(info->key_b / 256));
4870   - ucvector_push_back(&tRNS, (unsigned char)(info->key_b % 256));
  4882 + ucvector_push_back(&tRNS, (unsigned char)(info->key_r >> 8));
  4883 + ucvector_push_back(&tRNS, (unsigned char)(info->key_r & 255));
  4884 + ucvector_push_back(&tRNS, (unsigned char)(info->key_g >> 8));
  4885 + ucvector_push_back(&tRNS, (unsigned char)(info->key_g & 255));
  4886 + ucvector_push_back(&tRNS, (unsigned char)(info->key_b >> 8));
  4887 + ucvector_push_back(&tRNS, (unsigned char)(info->key_b & 255));
4871 4888 }
4872 4889 }
4873 4890  
... ... @@ -4992,21 +5009,21 @@ static unsigned addChunk_bKGD(ucvector* out, const LodePNGInfo* info)
4992 5009 ucvector_init(&bKGD);
4993 5010 if(info->color.colortype == LCT_GREY || info->color.colortype == LCT_GREY_ALPHA)
4994 5011 {
4995   - ucvector_push_back(&bKGD, (unsigned char)(info->background_r / 256));
4996   - ucvector_push_back(&bKGD, (unsigned char)(info->background_r % 256));
  5012 + ucvector_push_back(&bKGD, (unsigned char)(info->background_r >> 8));
  5013 + ucvector_push_back(&bKGD, (unsigned char)(info->background_r & 255));
4997 5014 }
4998 5015 else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_RGBA)
4999 5016 {
5000   - ucvector_push_back(&bKGD, (unsigned char)(info->background_r / 256));
5001   - ucvector_push_back(&bKGD, (unsigned char)(info->background_r % 256));
5002   - ucvector_push_back(&bKGD, (unsigned char)(info->background_g / 256));
5003   - ucvector_push_back(&bKGD, (unsigned char)(info->background_g % 256));
5004   - ucvector_push_back(&bKGD, (unsigned char)(info->background_b / 256));
5005   - ucvector_push_back(&bKGD, (unsigned char)(info->background_b % 256));
  5017 + ucvector_push_back(&bKGD, (unsigned char)(info->background_r >> 8));
  5018 + ucvector_push_back(&bKGD, (unsigned char)(info->background_r & 255));
  5019 + ucvector_push_back(&bKGD, (unsigned char)(info->background_g >> 8));
  5020 + ucvector_push_back(&bKGD, (unsigned char)(info->background_g & 255));
  5021 + ucvector_push_back(&bKGD, (unsigned char)(info->background_b >> 8));
  5022 + ucvector_push_back(&bKGD, (unsigned char)(info->background_b & 255));
5006 5023 }
5007 5024 else if(info->color.colortype == LCT_PALETTE)
5008 5025 {
5009   - ucvector_push_back(&bKGD, (unsigned char)(info->background_r % 256)); /*palette index*/
  5026 + ucvector_push_back(&bKGD, (unsigned char)(info->background_r & 255)); /*palette index*/
5010 5027 }
5011 5028  
5012 5029 error = addChunk(out, "bKGD", bKGD.data, bKGD.size);
... ... @@ -5020,8 +5037,8 @@ static unsigned addChunk_tIME(ucvector* out, const LodePNGTime* time)
5020 5037 unsigned error = 0;
5021 5038 unsigned char* data = (unsigned char*)lodepng_malloc(7);
5022 5039 if(!data) return 83; /*alloc fail*/
5023   - data[0] = (unsigned char)(time->year / 256);
5024   - data[1] = (unsigned char)(time->year % 256);
  5040 + data[0] = (unsigned char)(time->year >> 8);
  5041 + data[1] = (unsigned char)(time->year & 255);
5025 5042 data[2] = (unsigned char)time->month;
5026 5043 data[3] = (unsigned char)time->day;
5027 5044 data[4] = (unsigned char)time->hour;
... ... @@ -5076,13 +5093,13 @@ static void filterScanline(unsigned char* out, const unsigned char* scanline, co
5076 5093 case 3: /*Average*/
5077 5094 if(prevline)
5078 5095 {
5079   - for(i = 0; i != bytewidth; ++i) out[i] = scanline[i] - prevline[i] / 2;
5080   - for(i = bytewidth; i < length; ++i) out[i] = scanline[i] - ((scanline[i - bytewidth] + prevline[i]) / 2);
  5096 + for(i = 0; i != bytewidth; ++i) out[i] = scanline[i] - (prevline[i] >> 1);
  5097 + for(i = bytewidth; i < length; ++i) out[i] = scanline[i] - ((scanline[i - bytewidth] + prevline[i]) >> 1);
5081 5098 }
5082 5099 else
5083 5100 {
5084 5101 for(i = 0; i != bytewidth; ++i) out[i] = scanline[i];
5085   - for(i = bytewidth; i < length; ++i) out[i] = scanline[i] - scanline[i - bytewidth] / 2;
  5102 + for(i = bytewidth; i < length; ++i) out[i] = scanline[i] - (scanline[i - bytewidth] >> 1);
5086 5103 }
5087 5104 break;
5088 5105 case 4: /*Paeth*/
... ... @@ -5167,14 +5184,14 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w,
5167 5184 {
5168 5185 /*adaptive filtering*/
5169 5186 size_t sum[5];
5170   - ucvector attempt[5]; /*five filtering attempts, one for each filter type*/
  5187 + unsigned char* attempt[5]; /*five filtering attempts, one for each filter type*/
5171 5188 size_t smallest = 0;
5172 5189 unsigned char type, bestType = 0;
5173 5190  
5174 5191 for(type = 0; type != 5; ++type)
5175 5192 {
5176   - ucvector_init(&attempt[type]);
5177   - if(!ucvector_resize(&attempt[type], linebytes)) return 83; /*alloc fail*/
  5193 + attempt[type] = (unsigned char*)lodepng_malloc(linebytes);
  5194 + if(!attempt[type]) return 83; /*alloc fail*/
5178 5195 }
5179 5196  
5180 5197 if(!error)
... ... @@ -5184,13 +5201,13 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w,
5184 5201 /*try the 5 filter types*/
5185 5202 for(type = 0; type != 5; ++type)
5186 5203 {
5187   - filterScanline(attempt[type].data, &in[y * linebytes], prevline, linebytes, bytewidth, type);
  5204 + filterScanline(attempt[type], &in[y * linebytes], prevline, linebytes, bytewidth, type);
5188 5205  
5189 5206 /*calculate the sum of the result*/
5190 5207 sum[type] = 0;
5191 5208 if(type == 0)
5192 5209 {
5193   - for(x = 0; x != linebytes; ++x) sum[type] += (unsigned char)(attempt[type].data[x]);
  5210 + for(x = 0; x != linebytes; ++x) sum[type] += (unsigned char)(attempt[type][x]);
5194 5211 }
5195 5212 else
5196 5213 {
... ... @@ -5199,7 +5216,7 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w,
5199 5216 /*For differences, each byte should be treated as signed, values above 127 are negative
5200 5217 (converted to signed char). Filtertype 0 isn't a difference though, so use unsigned there.
5201 5218 This means filtertype 0 is almost never chosen, but that is justified.*/
5202   - unsigned char s = attempt[type].data[x];
  5219 + unsigned char s = attempt[type][x];
5203 5220 sum[type] += s < 128 ? s : (255U - s);
5204 5221 }
5205 5222 }
... ... @@ -5216,24 +5233,24 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w,
5216 5233  
5217 5234 /*now fill the out values*/
5218 5235 out[y * (linebytes + 1)] = bestType; /*the first byte of a scanline will be the filter type*/
5219   - for(x = 0; x != linebytes; ++x) out[y * (linebytes + 1) + 1 + x] = attempt[bestType].data[x];
  5236 + for(x = 0; x != linebytes; ++x) out[y * (linebytes + 1) + 1 + x] = attempt[bestType][x];
5220 5237 }
5221 5238 }
5222 5239  
5223   - for(type = 0; type != 5; ++type) ucvector_cleanup(&attempt[type]);
  5240 + for(type = 0; type != 5; ++type) lodepng_free(attempt[type]);
5224 5241 }
5225 5242 else if(strategy == LFS_ENTROPY)
5226 5243 {
5227 5244 float sum[5];
5228   - ucvector attempt[5]; /*five filtering attempts, one for each filter type*/
  5245 + unsigned char* attempt[5]; /*five filtering attempts, one for each filter type*/
5229 5246 float smallest = 0;
5230 5247 unsigned type, bestType = 0;
5231 5248 unsigned count[256];
5232 5249  
5233 5250 for(type = 0; type != 5; ++type)
5234 5251 {
5235   - ucvector_init(&attempt[type]);
5236   - if(!ucvector_resize(&attempt[type], linebytes)) return 83; /*alloc fail*/
  5252 + attempt[type] = (unsigned char*)lodepng_malloc(linebytes);
  5253 + if(!attempt[type]) return 83; /*alloc fail*/
5237 5254 }
5238 5255  
5239 5256 for(y = 0; y != h; ++y)
... ... @@ -5241,9 +5258,9 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w,
5241 5258 /*try the 5 filter types*/
5242 5259 for(type = 0; type != 5; ++type)
5243 5260 {
5244   - filterScanline(attempt[type].data, &in[y * linebytes], prevline, linebytes, bytewidth, type);
  5261 + filterScanline(attempt[type], &in[y * linebytes], prevline, linebytes, bytewidth, type);
5245 5262 for(x = 0; x != 256; ++x) count[x] = 0;
5246   - for(x = 0; x != linebytes; ++x) ++count[attempt[type].data[x]];
  5263 + for(x = 0; x != linebytes; ++x) ++count[attempt[type][x]];
5247 5264 ++count[type]; /*the filter type itself is part of the scanline*/
5248 5265 sum[type] = 0;
5249 5266 for(x = 0; x != 256; ++x)
... ... @@ -5263,10 +5280,10 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w,
5263 5280  
5264 5281 /*now fill the out values*/
5265 5282 out[y * (linebytes + 1)] = bestType; /*the first byte of a scanline will be the filter type*/
5266   - for(x = 0; x != linebytes; ++x) out[y * (linebytes + 1) + 1 + x] = attempt[bestType].data[x];
  5283 + for(x = 0; x != linebytes; ++x) out[y * (linebytes + 1) + 1 + x] = attempt[bestType][x];
5267 5284 }
5268 5285  
5269   - for(type = 0; type != 5; ++type) ucvector_cleanup(&attempt[type]);
  5286 + for(type = 0; type != 5; ++type) lodepng_free(attempt[type]);
5270 5287 }
5271 5288 else if(strategy == LFS_PREDEFINED)
5272 5289 {
... ... @@ -5286,7 +5303,7 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w,
5286 5303 deflate the scanline after every filter attempt to see which one deflates best.
5287 5304 This is very slow and gives only slightly smaller, sometimes even larger, result*/
5288 5305 size_t size[5];
5289   - ucvector attempt[5]; /*five filtering attempts, one for each filter type*/
  5306 + unsigned char* attempt[5]; /*five filtering attempts, one for each filter type*/
5290 5307 size_t smallest = 0;
5291 5308 unsigned type = 0, bestType = 0;
5292 5309 unsigned char* dummy;
... ... @@ -5302,20 +5319,20 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w,
5302 5319 zlibsettings.custom_deflate = 0;
5303 5320 for(type = 0; type != 5; ++type)
5304 5321 {
5305   - ucvector_init(&attempt[type]);
5306   - ucvector_resize(&attempt[type], linebytes); /*todo: give error if resize failed*/
  5322 + attempt[type] = (unsigned char*)lodepng_malloc(linebytes);
  5323 + if(!attempt[type]) return 83; /*alloc fail*/
5307 5324 }
5308 5325 for(y = 0; y != h; ++y) /*try the 5 filter types*/
5309 5326 {
5310 5327 for(type = 0; type != 5; ++type)
5311 5328 {
5312   - unsigned testsize = (unsigned)attempt[type].size;
  5329 + unsigned testsize = (unsigned)linebytes;
5313 5330 /*if(testsize > 8) testsize /= 8;*/ /*it already works good enough by testing a part of the row*/
5314 5331  
5315   - filterScanline(attempt[type].data, &in[y * linebytes], prevline, linebytes, bytewidth, type);
  5332 + filterScanline(attempt[type], &in[y * linebytes], prevline, linebytes, bytewidth, type);
5316 5333 size[type] = 0;
5317 5334 dummy = 0;
5318   - zlib_compress(&dummy, &size[type], attempt[type].data, testsize, &zlibsettings);
  5335 + zlib_compress(&dummy, &size[type], attempt[type], testsize, &zlibsettings);
5319 5336 lodepng_free(dummy);
5320 5337 /*check if this is smallest size (or if type == 0 it's the first case so always store the values)*/
5321 5338 if(type == 0 || size[type] < smallest)
... ... @@ -5326,9 +5343,9 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w,
5326 5343 }
5327 5344 prevline = &in[y * linebytes];
5328 5345 out[y * (linebytes + 1)] = bestType; /*the first byte of a scanline will be the filter type*/
5329   - for(x = 0; x != linebytes; ++x) out[y * (linebytes + 1) + 1 + x] = attempt[bestType].data[x];
  5346 + for(x = 0; x != linebytes; ++x) out[y * (linebytes + 1) + 1 + x] = attempt[bestType][x];
5330 5347 }
5331   - for(type = 0; type != 5; ++type) ucvector_cleanup(&attempt[type]);
  5348 + for(type = 0; type != 5; ++type) free(attempt[type]);
5332 5349 }
5333 5350 else return 88; /* unknown filter strategy */
5334 5351  
... ... @@ -5453,7 +5470,7 @@ static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const
5453 5470 }
5454 5471 else
5455 5472 {
5456   - /*we can immediatly filter into the out buffer, no other steps needed*/
  5473 + /*we can immediately filter into the out buffer, no other steps needed*/
5457 5474 error = filter(*out, in, w, h, &info_png->color, settings);
5458 5475 }
5459 5476 }
... ... @@ -5856,8 +5873,7 @@ const char* lodepng_error_text(unsigned code)
5856 5873 case 43: return "bKGD chunk has wrong size for palette image";
5857 5874 case 44: return "bKGD chunk has wrong size for greyscale image";
5858 5875 case 45: return "bKGD chunk has wrong size for RGB image";
5859   - /*the input data is empty, maybe a PNG file doesn't exist or is in the wrong path*/
5860   - case 48: return "empty input or file doesn't exist";
  5876 + case 48: return "empty input buffer given to decoder. Maybe caused by non-existing file?";
5861 5877 case 49: return "jumped past memory while generating dynamic huffman tree";
5862 5878 case 50: return "jumped past memory while generating dynamic huffman tree";
5863 5879 case 51: return "jumped past memory while inflating huffman block";
... ... @@ -5907,6 +5923,7 @@ const char* lodepng_error_text(unsigned code)
5907 5923 case 91: return "invalid decompressed idat size";
5908 5924 case 92: return "too many pixels, not supported";
5909 5925 case 93: return "zero width or height is invalid";
  5926 + case 94: return "header chunk must have a size of 13 bytes";
5910 5927 }
5911 5928 return "unknown error code";
5912 5929 }
... ... @@ -5923,9 +5940,10 @@ namespace lodepng
5923 5940 {
5924 5941  
5925 5942 #ifdef LODEPNG_COMPILE_DISK
5926   -void load_file(std::vector<unsigned char>& buffer, const std::string& filename)
  5943 +unsigned load_file(std::vector<unsigned char>& buffer, const std::string& filename)
5927 5944 {
5928 5945 std::ifstream file(filename.c_str(), std::ios::in|std::ios::binary|std::ios::ate);
  5946 + if(!file) return 78;
5929 5947  
5930 5948 /*get filesize*/
5931 5949 std::streamsize size = 0;
... ... @@ -5935,13 +5953,17 @@ void load_file(std::vector&lt;unsigned char&gt;&amp; buffer, const std::string&amp; filename)
5935 5953 /*read contents of the file into the vector*/
5936 5954 buffer.resize(size_t(size));
5937 5955 if(size > 0) file.read((char*)(&buffer[0]), size);
  5956 +
  5957 + return 0; /* OK */
5938 5958 }
5939 5959  
5940 5960 /*write given buffer to the file, overwriting the file, it doesn't append to it.*/
5941   -void save_file(const std::vector<unsigned char>& buffer, const std::string& filename)
  5961 +unsigned save_file(const std::vector<unsigned char>& buffer, const std::string& filename)
5942 5962 {
5943 5963 std::ofstream file(filename.c_str(), std::ios::out|std::ios::binary);
  5964 + if(!file) return 79;
5944 5965 file.write(buffer.empty() ? 0 : (char*)&buffer[0], std::streamsize(buffer.size()));
  5966 + return 0;
5945 5967 }
5946 5968 #endif /* LODEPNG_COMPILE_DISK */
5947 5969  
... ... @@ -5999,7 +6021,7 @@ State::State()
5999 6021 lodepng_state_init(this);
6000 6022 }
6001 6023  
6002   -State::State(const State& other) : LodePNGState(other)
  6024 +State::State(const State& other)
6003 6025 {
6004 6026 lodepng_state_init(this);
6005 6027 lodepng_state_copy(this, &other);
... ... @@ -6068,7 +6090,8 @@ unsigned decode(std::vector&lt;unsigned char&gt;&amp; out, unsigned&amp; w, unsigned&amp; h, const
6068 6090 LodePNGColorType colortype, unsigned bitdepth)
6069 6091 {
6070 6092 std::vector<unsigned char> buffer;
6071   - load_file(buffer, filename);
  6093 + unsigned error = load_file(buffer, filename);
  6094 + if(error) return error;
6072 6095 return decode(out, w, h, buffer, colortype, bitdepth);
6073 6096 }
6074 6097 #endif /* LODEPNG_COMPILE_DECODER */
... ... @@ -6127,7 +6150,7 @@ unsigned encode(const std::string&amp; filename,
6127 6150 {
6128 6151 std::vector<unsigned char> buffer;
6129 6152 unsigned error = encode(buffer, in, w, h, colortype, bitdepth);
6130   - if(!error) save_file(buffer, filename);
  6153 + if(!error) error = save_file(buffer, filename);
6131 6154 return error;
6132 6155 }
6133 6156  
... ...
src_winapi/libs/lodepng.h
1 1 /*
2   -LodePNG version 20150418
  2 +LodePNG version 20160124
3 3  
4   -Copyright (c) 2005-2015 Lode Vandevenne
  4 +Copyright (c) 2005-2016 Lode Vandevenne
5 5  
6 6 This software is provided 'as-is', without any express or implied
7 7 warranty. In no event will the authors be held liable for any damages
... ... @@ -31,15 +31,11 @@ freely, subject to the following restrictions:
31 31 #define LODEPNG_NO_COMPILE_DISK
32 32 #define LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS
33 33 #define LODEPNG_NO_COMPILE_ERROR_TEXT
  34 +#define LODEPNG_NO_COMPILE_CPP
34 35 /* End defines for FEM Draw project */
35 36  
36 37 #include <string.h> /*for size_t*/
37 38  
38   -#ifdef __cplusplus
39   -#include <vector>
40   -#include <string>
41   -#endif /*__cplusplus*/
42   -
43 39 extern const char* LODEPNG_VERSION_STRING;
44 40  
45 41 /*
... ... @@ -48,6 +44,8 @@ to disable code sections, which can give faster compile time and smaller binary.
48 44 The "NO_COMPILE" defines are designed to be used to pass as defines to the
49 45 compiler command to disable them without modifying this header, e.g.
50 46 -DLODEPNG_NO_COMPILE_ZLIB for gcc.
  47 +In addition to those below, you can also define LODEPNG_NO_COMPILE_CRC to
  48 +allow implementing a custom lodepng_crc32.
51 49 */
52 50 /*deflate & zlib. If disabled, you must specify alternative zlib functions in
53 51 the custom_zlib field of the compress and decompress settings*/
... ... @@ -91,6 +89,11 @@ source files with custom allocators.*/
91 89 #endif
92 90 #endif
93 91  
  92 +#ifdef LODEPNG_COMPILE_CPP
  93 +#include <vector>
  94 +#include <string>
  95 +#endif /*LODEPNG_COMPILE_CPP*/
  96 +
94 97 #ifdef LODEPNG_COMPILE_PNG
95 98 /*The PNG color types (also used for raw).*/
96 99 typedef enum LodePNGColorType
... ... @@ -513,7 +516,7 @@ For 16-bit per channel colors, uses big endian format like PNG does.
513 516 Return value is LodePNG error code
514 517 */
515 518 unsigned lodepng_convert(unsigned char* out, const unsigned char* in,
516   - LodePNGColorMode* mode_out, const LodePNGColorMode* mode_in,
  519 + const LodePNGColorMode* mode_out, const LodePNGColorMode* mode_in,
517 520 unsigned w, unsigned h);
518 521  
519 522 #ifdef LODEPNG_COMPILE_DECODER
... ... @@ -545,7 +548,7 @@ typedef enum LodePNGFilterStrategy
545 548 {
546 549 /*every filter at zero*/
547 550 LFS_ZERO,
548   - /*Use filter that gives minumum sum, as described in the official PNG filter heuristic.*/
  551 + /*Use filter that gives minimum sum, as described in the official PNG filter heuristic.*/
549 552 LFS_MINSUM,
550 553 /*Use the filter type that gives smallest Shannon entropy for this scanline. Depending
551 554 on the image, this is better or worse than minsum.*/
... ... @@ -853,16 +856,16 @@ unsigned encode(std::vector&lt;unsigned char&gt;&amp; out,
853 856  
854 857 #ifdef LODEPNG_COMPILE_DISK
855 858 /*
856   -Load a file from disk into an std::vector. If the vector is empty, then either
857   -the file doesn't exist or is an empty file.
  859 +Load a file from disk into an std::vector.
  860 +return value: error code (0 means ok)
858 861 */
859   -void load_file(std::vector<unsigned char>& buffer, const std::string& filename);
  862 +unsigned load_file(std::vector<unsigned char>& buffer, const std::string& filename);
860 863  
861 864 /*
862 865 Save the binary data in an std::vector to a file on disk. The file is overwritten
863 866 without warning.
864 867 */
865   -void save_file(const std::vector<unsigned char>& buffer, const std::string& filename);
  868 +unsigned save_file(const std::vector<unsigned char>& buffer, const std::string& filename);
866 869 #endif /* LODEPNG_COMPILE_DISK */
867 870 #endif /* LODEPNG_COMPILE_PNG */
868 871  
... ... @@ -893,7 +896,7 @@ unsigned compress(std::vector&lt;unsigned char&gt;&amp; out, const std::vector&lt;unsigned ch
893 896 /*
894 897 TODO:
895 898 [.] test if there are no memory leaks or security exploits - done a lot but needs to be checked often
896   -[.] check compatibility with vareous compilers - done but needs to be redone for every newer version
  899 +[.] check compatibility with various compilers - done but needs to be redone for every newer version
897 900 [X] converting color to 16-bit per channel types
898 901 [ ] read all public PNG chunk types (but never let the color profile and gamma ones touch RGB values)
899 902 [ ] make sure encoder generates no chunks with size > (2^31)-1
... ... @@ -903,6 +906,7 @@ TODO:
903 906 [ ] don't stop decoding on errors like 69, 57, 58 (make warnings)
904 907 [ ] let the C++ wrapper catch exceptions coming from the standard library and return LodePNG error codes
905 908 [ ] allow user to provide custom color conversion functions, e.g. for premultiplied alpha, padding bits or not, ...
  909 +[ ] allow user to give data (void*) to custom allocator
906 910 */
907 911  
908 912 #endif /*LODEPNG_H inclusion guard*/
... ... @@ -932,8 +936,9 @@ LodePNG Documentation
932 936 10. examples
933 937 10.1. decoder C++ example
934 938 10.2. decoder C example
935   - 11. changes
936   - 12. contact information
  939 + 11. state settings reference
  940 + 12. changes
  941 + 13. contact information
937 942  
938 943  
939 944 1. about
... ... @@ -1559,8 +1564,49 @@ int main(int argc, char *argv[])
1559 1564 return 0;
1560 1565 }
1561 1566  
1562   -
1563   -11. changes
  1567 +11. state settings reference
  1568 +----------------------------
  1569 +
  1570 +A quick reference of some settings to set on the LodePNGState
  1571 +
  1572 +For decoding:
  1573 +
  1574 +state.decoder.zlibsettings.ignore_adler32: ignore ADLER32 checksums
  1575 +state.decoder.zlibsettings.custom_...: use custom inflate function
  1576 +state.decoder.ignore_crc: ignore CRC checksums
  1577 +state.decoder.color_convert: convert internal PNG color to chosen one
  1578 +state.decoder.read_text_chunks: whether to read in text metadata chunks
  1579 +state.decoder.remember_unknown_chunks: whether to read in unknown chunks
  1580 +state.info_raw.colortype: desired color type for decoded image
  1581 +state.info_raw.bitdepth: desired bit depth for decoded image
  1582 +state.info_raw....: more color settings, see struct LodePNGColorMode
  1583 +state.info_png....: no settings for decoder but ouput, see struct LodePNGInfo
  1584 +
  1585 +For encoding:
  1586 +
  1587 +state.encoder.zlibsettings.btype: disable compression by setting it to 0
  1588 +state.encoder.zlibsettings.use_lz77: use LZ77 in compression
  1589 +state.encoder.zlibsettings.windowsize: tweak LZ77 windowsize
  1590 +state.encoder.zlibsettings.minmatch: tweak min LZ77 length to match
  1591 +state.encoder.zlibsettings.nicematch: tweak LZ77 match where to stop searching
  1592 +state.encoder.zlibsettings.lazymatching: try one more LZ77 matching
  1593 +state.encoder.zlibsettings.custom_...: use custom deflate function
  1594 +state.encoder.auto_convert: choose optimal PNG color type, if 0 uses info_png
  1595 +state.encoder.filter_palette_zero: PNG filter strategy for palette
  1596 +state.encoder.filter_strategy: PNG filter strategy to encode with
  1597 +state.encoder.force_palette: add palette even if not encoding to one
  1598 +state.encoder.add_id: add LodePNG identifier and version as a text chunk
  1599 +state.encoder.text_compression: use compressed text chunks for metadata
  1600 +state.info_raw.colortype: color type of raw input image you provide
  1601 +state.info_raw.bitdepth: bit depth of raw input image you provide
  1602 +state.info_raw: more color settings, see struct LodePNGColorMode
  1603 +state.info_png.color.colortype: desired color type if auto_convert is false
  1604 +state.info_png.color.bitdepth: desired bit depth if auto_convert is false
  1605 +state.info_png.color....: more color settings, see struct LodePNGColorMode
  1606 +state.info_png....: more PNG related settings, see struct LodePNGInfo
  1607 +
  1608 +
  1609 +12. changes
1564 1610 -----------
1565 1611  
1566 1612 The version number of LodePNG is the date of the change given in the format
... ... @@ -1569,6 +1615,8 @@ yyyymmdd.
1569 1615 Some changes aren't backwards compatible. Those are indicated with a (!)
1570 1616 symbol.
1571 1617  
  1618 +*) 08 dec 2015: Made load_file function return error if file can't be opened.
  1619 +*) 24 okt 2015: Bugfix with decoding to palette output.
1572 1620 *) 18 apr 2015: Boundary PM instead of just package-merge for faster encoding.
1573 1621 *) 23 aug 2014: Reduced needless memory usage of decoder.
1574 1622 *) 28 jun 2014: Removed fix_png setting, always support palette OOB for
... ... @@ -1594,7 +1642,7 @@ symbol.
1594 1642 *) 22 apr 2012 (!): Made interface more consistent, renaming a lot. Removed
1595 1643 redundant C++ codec classes. Reduced amount of structs. Everything changed,
1596 1644 but it is cleaner now imho and functionality remains the same. Also fixed
1597   - several bugs and shrinked the implementation code. Made new samples.
  1645 + several bugs and shrunk the implementation code. Made new samples.
1598 1646 *) 6 nov 2011 (!): By default, the encoder now automatically chooses the best
1599 1647 PNG color model and bit depth, based on the amount and type of colors of the
1600 1648 raw image. For this, autoLeaveOutAlphaChannel replaced by auto_choose_color.
... ... @@ -1629,7 +1677,7 @@ symbol.
1629 1677 *) 20 jan 2008: support for unknown chunks allowing using LodePNG for an editor.
1630 1678 *) 18 jan 2008: support for tIME and pHYs chunks added to encoder and decoder.
1631 1679 *) 17 jan 2008: ability to encode and decode compressed zTXt chunks added
1632   - Also vareous fixes, such as in the deflate and the padding bits code.
  1680 + Also various fixes, such as in the deflate and the padding bits code.
1633 1681 *) 13 jan 2008: Added ability to encode Adam7-interlaced images. Improved
1634 1682 filtering code of encoder.
1635 1683 *) 07 jan 2008: (!) changed LodePNG to use ISO C90 instead of C++. A
... ... @@ -1700,7 +1748,7 @@ symbol.
1700 1748 *) 12 aug 2005: Initial release (C++, decoder only)
1701 1749  
1702 1750  
1703   -12. contact information
  1751 +13. contact information
1704 1752 -----------------------
1705 1753  
1706 1754 Feel free to contact me with suggestions, problems, comments, ... concerning
... ... @@ -1712,5 +1760,5 @@ Domain: gmail dot com.
1712 1760 Account: lode dot vandevenne.
1713 1761  
1714 1762  
1715   -Copyright (c) 2005-2015 Lode Vandevenne
  1763 +Copyright (c) 2005-2016 Lode Vandevenne
1716 1764 */
... ...