pax_global_header00006660000000000000000000000064142534421770014523gustar00rootroot0000000000000052 comment=b4ed2cd7ecf61d29076169b49199371456d4f90b lodepng-0.0~git20220618.b4ed2cd/000077500000000000000000000000001425344217700157475ustar00rootroot00000000000000lodepng-0.0~git20220618.b4ed2cd/LICENSE000066400000000000000000000015661425344217700167640ustar00rootroot00000000000000Copyright (c) 2005-2018 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. lodepng-0.0~git20220618.b4ed2cd/Makefile000066400000000000000000000021571425344217700174140ustar00rootroot00000000000000# This makefile only makes the unit test, benchmark and pngdetail and showpng # utilities. It does not make the PNG codec itself as shared or static library. # That is because: # LodePNG itself has only 1 source file (lodepng.cpp, can be renamed to # lodepng.c) and is intended to be included as source file in other projects and # their build system directly. CC ?= gcc CXX ?= g++ override CFLAGS := -W -Wall -Wextra -ansi -pedantic -O3 -Wno-unused-function $(CFLAGS) override CXXFLAGS := -W -Wall -Wextra -ansi -pedantic -O3 $(CXXFLAGS) all: unittest benchmark pngdetail showpng %.o: %.cpp @mkdir -p `dirname $@` $(CXX) -I ./ $(CXXFLAGS) -c $< -o $@ unittest: lodepng.o lodepng_util.o lodepng_unittest.o $(CXX) $^ $(CXXFLAGS) -o $@ benchmark: lodepng.o lodepng_benchmark.o $(CXX) $^ $(CXXFLAGS) -lSDL2 -o $@ pngdetail: lodepng.o lodepng_util.o pngdetail.o $(CXX) $^ $(CXXFLAGS) -o $@ showpng: lodepng.o examples/example_sdl.o $(CXX) -I ./ $^ $(CXXFLAGS) -lSDL2 -o $@ clean: rm -f unittest benchmark pngdetail showpng lodepng_unittest.o lodepng_benchmark.o lodepng.o lodepng_util.o pngdetail.o examples/example_sdl.o lodepng-0.0~git20220618.b4ed2cd/README.md000066400000000000000000000042761425344217700172370ustar00rootroot00000000000000LodePNG ------- PNG encoder and decoder in C and C++, without dependencies Home page: http://lodev.org/lodepng/ ### Documentation Detailed documentation is included in a large comment in the second half of the header file `lodepng.h`. Source code examples using LodePNG can be found in the examples directory. An FAQ can be found on http://lodev.org/lodepng/ ### Building Only two files are needed to encode and decode PNGs: * `lodepng.cpp` (or renamed to `lodepng.c`) * `lodepng.h` All other files are just source code examples, tests, misc utilities, etc..., which are normally not needed in projects using this. You can include the files directly in your project's source tree and its makefile, IDE project file, or other build system. No library is necessary. In addition to C++, LodePNG also supports ANSI C (C89), with all the same functionality: C++ only adds extra convenience API. For C, rename `lodepng.cpp` to `lodepng.c`. Consider using git submodules to include LodePNG in your project. ### Compiling in C++ If you have a hypothetical `your_program.cpp` that #includes and uses `lodepng.h`, you can build as follows: `g++ your_program.cpp lodepng.cpp -Wall -Wextra -pedantic -ansi -O3` or: `clang++ your_program.cpp lodepng.cpp -Wall -Wextra -pedantic -ansi -O3` This shows compiler flags it was designed for, but normally one would use the compiler or build system of their project instead of those commands, and other C++ compilers are supported. ### Compiling in C Rename `lodepng.cpp` to `lodepng.c` for this. If you have a hypothetical your_program.c that #includes and uses lodepng.h, you can build as follows: `gcc your_program.c lodepng.c -ansi -pedantic -Wall -Wextra -O3` or `clang your_program.c lodepng.c -ansi -pedantic -Wall -Wextra -O3` This shows compiler flags it was designed for, but normally one would use the compiler or build system of their project instead of those commands, and other C compilers are supported. ### Makefile There is a Makefile, but this is not intended for using LodePNG itself since the way to use that one is to include its source files in your program. The Makefile only builds development and testing utilities. It can be used as follows: `make -j` lodepng-0.0~git20220618.b4ed2cd/examples/000077500000000000000000000000001425344217700175655ustar00rootroot00000000000000lodepng-0.0~git20220618.b4ed2cd/examples/example_4bit_palette.cpp000066400000000000000000000073241425344217700243720ustar00rootroot00000000000000/* LodePNG Examples Copyright (c) 2005-2012 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ //g++ lodepng.cpp example_4bit_palette.cpp -ansi -pedantic -Wall -Wextra -O3 /* LodePNG 4-bit palette example. This example encodes a 511x511 PNG with a 4-bit palette. Both image and palette contain sine waves, resulting in a sort of plasma. The 511 (rather than power of two 512) size is of course chosen on purpose to confirm that scanlines not filling up an entire byte size are working. NOTE: a PNG image with a translucent palette is perfectly valid. However there exist some programs that cannot correctly read those, including, surprisingly, Gimp 2.8 image editor (until you set mode to RGB). */ #include #include #include "lodepng.h" int main(int argc, char *argv[]) { //check if user gave a filename if(argc < 2) { std::cout << "please provide a filename to save to" << std::endl; return 0; } //create encoder and set settings and info (optional) lodepng::State state; //generate palette for(int i = 0; i < 16; i++) { unsigned char r = 127 * (1 + std::sin(5 * i * 6.28318531 / 16)); unsigned char g = 127 * (1 + std::sin(2 * i * 6.28318531 / 16)); unsigned char b = 127 * (1 + std::sin(3 * i * 6.28318531 / 16)); unsigned char a = 63 * (1 + std::sin(8 * i * 6.28318531 / 16)) + 128; /*alpha channel of the palette (tRNS chunk)*/ //palette must be added both to input and output color mode, because in this //sample both the raw image and the expected PNG image use that palette. lodepng_palette_add(&state.info_png.color, r, g, b, a); lodepng_palette_add(&state.info_raw, r, g, b, a); } //both the raw image and the encoded image must get colorType 3 (palette) state.info_png.color.colortype = LCT_PALETTE; //if you comment this line, and create the above palette in info_raw instead, then you get the same image in a RGBA PNG. state.info_png.color.bitdepth = 4; state.info_raw.colortype = LCT_PALETTE; state.info_raw.bitdepth = 4; state.encoder.auto_convert = 0; //we specify ourselves exactly what output PNG color mode we want //generate some image const unsigned w = 511; const unsigned h = 511; std::vector image; image.resize((w * h * 4 + 7) / 8, 0); for(unsigned y = 0; y < h; y++) for(unsigned x = 0; x < w; x++) { size_t byte_index = (y * w + x) / 2; bool byte_half = (y * w + x) % 2 == 1; int color = (int)(4 * ((1 + std::sin(2.0 * 6.28318531 * x / (double)w)) + (1 + std::sin(2.0 * 6.28318531 * y / (double)h))) ); image[byte_index] |= (unsigned char)(color << (byte_half ? 0 : 4)); } //encode and save std::vector buffer; unsigned error = lodepng::encode(buffer, image.empty() ? 0 : &image[0], w, h, state); if(error) { std::cout << "encoder error " << error << ": "<< lodepng_error_text(error) << std::endl; return 0; } lodepng::save_file(buffer, argv[1]); } lodepng-0.0~git20220618.b4ed2cd/examples/example_bmp2png.cpp000066400000000000000000000106421425344217700233540ustar00rootroot00000000000000/* LodePNG Examples Copyright (c) 2005-2010 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ /* Load a BMP image and convert it to a PNG image. This example also shows how to use other data with the same memory structure as BMP, such as the image format native to win32, GDI (HBITMAP, BITMAPINFO, ...) often encountered if you're programming for Windows in Visual Studio. This example only supports uncompressed 24-bit RGB or 32-bit RGBA bitmaps. For other types of BMP's, use a full fledged BMP decoder, or convert the bitmap to 24-bit or 32-bit format. NOTE: it overwrites the output file without warning if it exists! */ //g++ lodepng.cpp example_bmp2png.cpp -ansi -pedantic -Wall -Wextra -O3 #include "lodepng.h" #include //returns 0 if all went ok, non-0 if error //output image is always given in RGBA (with alpha channel), even if it's a BMP without alpha channel unsigned decodeBMP(std::vector& image, unsigned& w, unsigned& h, const std::vector& bmp) { static const unsigned MINHEADER = 54; //minimum BMP header size if(bmp.size() < MINHEADER) return -1; if(bmp[0] != 'B' || bmp[1] != 'M') return 1; //It's not a BMP file if it doesn't start with marker 'BM' unsigned pixeloffset = bmp[10] + 256 * bmp[11]; //where the pixel data starts //read width and height from BMP header w = bmp[18] + bmp[19] * 256; h = bmp[22] + bmp[23] * 256; //read number of channels from BMP header if(bmp[28] != 24 && bmp[28] != 32) return 2; //only 24-bit and 32-bit BMPs are supported. unsigned numChannels = bmp[28] / 8; //The amount of scanline bytes is width of image times channels, with extra bytes added if needed //to make it a multiple of 4 bytes. unsigned scanlineBytes = w * numChannels; if(scanlineBytes % 4 != 0) scanlineBytes = (scanlineBytes / 4) * 4 + 4; unsigned dataSize = scanlineBytes * h; if(bmp.size() < dataSize + pixeloffset) return 3; //BMP file too small to contain all pixels image.resize(w * h * 4); /* There are 3 differences between BMP and the raw image buffer for LodePNG: -it's upside down -it's in BGR instead of RGB format (or BRGA instead of RGBA) -each scanline has padding bytes to make it a multiple of 4 if needed The 2D for loop below does all these 3 conversions at once. */ for(unsigned y = 0; y < h; y++) for(unsigned x = 0; x < w; x++) { //pixel start byte position in the BMP unsigned bmpos = pixeloffset + (h - y - 1) * scanlineBytes + numChannels * x; //pixel start byte position in the new raw image unsigned newpos = 4 * y * w + 4 * x; if(numChannels == 3) { image[newpos + 0] = bmp[bmpos + 2]; //R image[newpos + 1] = bmp[bmpos + 1]; //G image[newpos + 2] = bmp[bmpos + 0]; //B image[newpos + 3] = 255; //A } else { image[newpos + 0] = bmp[bmpos + 2]; //R image[newpos + 1] = bmp[bmpos + 1]; //G image[newpos + 2] = bmp[bmpos + 0]; //B image[newpos + 3] = bmp[bmpos + 3]; //A } } return 0; } int main(int argc, char *argv[]) { if(argc < 3) { std::cout << "Please provide input BMP and output PNG file names" << std::endl; return 0; } std::vector bmp; lodepng::load_file(bmp, argv[1]); std::vector image; unsigned w, h; unsigned error = decodeBMP(image, w, h, bmp); if(error) { std::cout << "BMP decoding error " << error << std::endl; return 0; } std::vector png; error = lodepng::encode(png, image, w, h); if(error) { std::cout << "PNG encoding error " << error << ": " << lodepng_error_text(error) << std::endl; return 0; } lodepng::save_file(png, argv[2]); } lodepng-0.0~git20220618.b4ed2cd/examples/example_decode.c000066400000000000000000000053621425344217700226750ustar00rootroot00000000000000/* LodePNG Examples Copyright (c) 2005-2012 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "lodepng.h" #include #include /* 3 ways to decode a PNG from a file to RGBA pixel data (and 2 in-memory ways). */ /* Example 1 Decode from disk to raw pixels with a single function call */ void decodeOneStep(const char* filename) { unsigned error; unsigned char* image = 0; unsigned width, height; error = lodepng_decode32_file(&image, &width, &height, filename); if(error) printf("error %u: %s\n", error, lodepng_error_text(error)); /*use image here*/ free(image); } /* Example 2 Load PNG file from disk to memory first, then decode to raw pixels in memory. */ void decodeTwoSteps(const char* filename) { unsigned error; unsigned char* image = 0; unsigned width, height; unsigned char* png = 0; size_t pngsize; error = lodepng_load_file(&png, &pngsize, filename); if(!error) error = lodepng_decode32(&image, &width, &height, png, pngsize); if(error) printf("error %u: %s\n", error, lodepng_error_text(error)); free(png); /*use image here*/ free(image); } /* Example 3 Load PNG file from disk using a State, normally needed for more advanced usage. */ void decodeWithState(const char* filename) { unsigned error; unsigned char* image = 0; unsigned width, height; unsigned char* png = 0; size_t pngsize; LodePNGState state; lodepng_state_init(&state); /*optionally customize the state*/ error = lodepng_load_file(&png, &pngsize, filename); if(!error) error = lodepng_decode(&image, &width, &height, &state, png, pngsize); if(error) printf("error %u: %s\n", error, lodepng_error_text(error)); free(png); /*use image here*/ /*state contains extra information about the PNG such as text chunks, ...*/ lodepng_state_cleanup(&state); free(image); } int main(int argc, char *argv[]) { const char* filename = argc > 1 ? argv[1] : "test.png"; decodeOneStep(filename); return 0; } lodepng-0.0~git20220618.b4ed2cd/examples/example_decode.cpp000066400000000000000000000062431425344217700232340ustar00rootroot00000000000000/* LodePNG Examples Copyright (c) 2005-2012 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "lodepng.h" #include /* 3 ways to decode a PNG from a file to RGBA pixel data (and 2 in-memory ways). */ //g++ lodepng.cpp example_decode.cpp -ansi -pedantic -Wall -Wextra -O3 //Example 1 //Decode from disk to raw pixels with a single function call void decodeOneStep(const char* filename) { std::vector image; //the raw pixels unsigned width, height; //decode unsigned error = lodepng::decode(image, width, height, filename); //if there's an error, display it if(error) std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl; //the pixels are now in the vector "image", 4 bytes per pixel, ordered RGBARGBA..., use it as texture, draw it, ... } //Example 2 //Load PNG file from disk to memory first, then decode to raw pixels in memory. void decodeTwoSteps(const char* filename) { std::vector png; std::vector image; //the raw pixels unsigned width, height; //load and decode unsigned error = lodepng::load_file(png, filename); if(!error) error = lodepng::decode(image, width, height, png); //if there's an error, display it if(error) std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl; //the pixels are now in the vector "image", 4 bytes per pixel, ordered RGBARGBA..., use it as texture, draw it, ... } //Example 3 //Load PNG file from disk using a State, normally needed for more advanced usage. void decodeWithState(const char* filename) { std::vector png; std::vector image; //the raw pixels unsigned width, height; lodepng::State state; //optionally customize this one unsigned error = lodepng::load_file(png, filename); //load the image file with given filename if(!error) error = lodepng::decode(image, width, height, state, png); //if there's an error, display it if(error) std::cout << "decoder error " << error << ": "<< lodepng_error_text(error) << std::endl; //the pixels are now in the vector "image", 4 bytes per pixel, ordered RGBARGBA..., use it as texture, draw it, ... //State state contains extra information about the PNG such as text chunks, ... } int main(int argc, char *argv[]) { const char* filename = argc > 1 ? argv[1] : "test.png"; decodeOneStep(filename); } lodepng-0.0~git20220618.b4ed2cd/examples/example_encode.c000066400000000000000000000066141425344217700227100ustar00rootroot00000000000000/* LodePNG Examples Copyright (c) 2005-2012 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "lodepng.h" #include #include /* 3 ways to encode a PNG from RGBA pixel data to a file (and 2 in-memory ways). NOTE: these samples overwrite the file or test.png without warning! */ /* Example 1 Encode from raw pixels to disk with a single function call The image argument has width * height RGBA pixels or width * height * 4 bytes */ void encodeOneStep(const char* filename, const unsigned char* image, unsigned width, unsigned height) { /*Encode the image*/ unsigned error = lodepng_encode32_file(filename, image, width, height); /*if there's an error, display it*/ if(error) printf("error %u: %s\n", error, lodepng_error_text(error)); } /* Example 2 Encode from raw pixels to an in-memory PNG file first, then write it to disk The image argument has width * height RGBA pixels or width * height * 4 bytes */ void encodeTwoSteps(const char* filename, const unsigned char* image, unsigned width, unsigned height) { unsigned char* png; size_t pngsize; unsigned error = lodepng_encode32(&png, &pngsize, image, width, height); if(!error) lodepng_save_file(png, pngsize, filename); /*if there's an error, display it*/ if(error) printf("error %u: %s\n", error, lodepng_error_text(error)); free(png); } /* Example 3 Save a PNG file to disk using a State, normally needed for more advanced usage. The image argument has width * height RGBA pixels or width * height * 4 bytes */ void encodeWithState(const char* filename, const unsigned char* image, unsigned width, unsigned height) { unsigned error; unsigned char* png; size_t pngsize; LodePNGState state; lodepng_state_init(&state); /*optionally customize the state*/ error = lodepng_encode(&png, &pngsize, image, width, height, &state); if(!error) lodepng_save_file(png, pngsize, filename); /*if there's an error, display it*/ if(error) printf("error %u: %s\n", error, lodepng_error_text(error)); lodepng_state_cleanup(&state); free(png); } int main(int argc, char *argv[]) { const char* filename = argc > 1 ? argv[1] : "test.png"; /*generate some image*/ unsigned width = 512, height = 512; unsigned char* image = malloc(width * height * 4); unsigned x, y; for(y = 0; y < height; y++) for(x = 0; x < width; x++) { image[4 * width * y + 4 * x + 0] = 255 * !(x & y); image[4 * width * y + 4 * x + 1] = x ^ y; image[4 * width * y + 4 * x + 2] = x | y; image[4 * width * y + 4 * x + 3] = 255; } /*run an example*/ encodeOneStep(filename, image, width, height); free(image); return 0; } lodepng-0.0~git20220618.b4ed2cd/examples/example_encode.cpp000066400000000000000000000070351425344217700232460ustar00rootroot00000000000000/* LodePNG Examples Copyright (c) 2005-2012 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "lodepng.h" #include /* 3 ways to encode a PNG from RGBA pixel data to a file (and 2 in-memory ways). NOTE: these samples overwrite the file or test.png without warning! */ //g++ lodepng.cpp examples/example_encode.cpp -I./ -ansi -pedantic -Wall -Wextra -O3 //Example 1 //Encode from raw pixels to disk with a single function call //The image argument has width * height RGBA pixels or width * height * 4 bytes void encodeOneStep(const char* filename, std::vector& image, unsigned width, unsigned height) { //Encode the image unsigned error = lodepng::encode(filename, image, width, height); //if there's an error, display it if(error) std::cout << "encoder error " << error << ": "<< lodepng_error_text(error) << std::endl; } //Example 2 //Encode from raw pixels to an in-memory PNG file first, then write it to disk //The image argument has width * height RGBA pixels or width * height * 4 bytes void encodeTwoSteps(const char* filename, std::vector& image, unsigned width, unsigned height) { std::vector png; unsigned error = lodepng::encode(png, image, width, height); if(!error) lodepng::save_file(png, filename); //if there's an error, display it if(error) std::cout << "encoder error " << error << ": "<< lodepng_error_text(error) << std::endl; } //Example 3 //Save a PNG file to disk using a State, normally needed for more advanced usage. //The image argument has width * height RGBA pixels or width * height * 4 bytes void encodeWithState(const char* filename, std::vector& image, unsigned width, unsigned height) { std::vector png; lodepng::State state; //optionally customize this one unsigned error = lodepng::encode(png, image, width, height, state); if(!error) lodepng::save_file(png, filename); //if there's an error, display it if(error) std::cout << "encoder error " << error << ": "<< lodepng_error_text(error) << std::endl; } //saves image to filename given as argument. Warning, this overwrites the file without warning! int main(int argc, char *argv[]) { //NOTE: this sample will overwrite the file or test.png without warning! const char* filename = argc > 1 ? argv[1] : "test.png"; //generate some image unsigned width = 512, height = 512; std::vector image; image.resize(width * height * 4); for(unsigned y = 0; y < height; y++) for(unsigned x = 0; x < width; x++) { image[4 * width * y + 4 * x + 0] = 255 * !(x & y); image[4 * width * y + 4 * x + 1] = x ^ y; image[4 * width * y + 4 * x + 2] = x | y; image[4 * width * y + 4 * x + 3] = 255; } encodeOneStep(filename, image, width, height); } lodepng-0.0~git20220618.b4ed2cd/examples/example_encode_type.cpp000066400000000000000000000047751425344217700243170ustar00rootroot00000000000000/* LodePNG Examples Copyright (c) 2005-2015 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ //g++ -I ./ lodepng.cpp examples/example_encode_type.cpp -ansi -pedantic -Wall -Wextra -O3 /* This example shows how to enforce a certain color type of the PNG image when encoding a PNG (because by default, LodePNG automatically chooses an optimal color type, no matter what your raw data's color type is) */ #include #include #include "lodepng.h" int main(int argc, char *argv[]) { //check if user gave a filename if(argc < 2) { std::cout << "please provide a filename to save to" << std::endl; return 0; } //generate some image const unsigned w = 256; const unsigned h = 256; std::vector image(w * h * 4); for(unsigned y = 0; y < h; y++) for(unsigned x = 0; x < w; x++) { int index = y * w * 4 + x * 4; image[index + 0] = 0; image[index + 1] = 0; image[index + 2] = 0; image[index + 3] = 255; } // we're going to encode with a state rather than a convenient function, because enforcing a color type requires setting options lodepng::State state; // input color type state.info_raw.colortype = LCT_RGBA; state.info_raw.bitdepth = 8; // output color type state.info_png.color.colortype = LCT_RGBA; state.info_png.color.bitdepth = 8; state.encoder.auto_convert = 0; // without this, it would ignore the output color type specified above and choose an optimal one instead //encode and save std::vector buffer; unsigned error = lodepng::encode(buffer, &image[0], w, h, state); if(error) std::cout << "encoder error " << error << ": "<< lodepng_error_text(error) << std::endl; else lodepng::save_file(buffer, argv[1]); } lodepng-0.0~git20220618.b4ed2cd/examples/example_gzip.cpp000066400000000000000000000050461425344217700227620ustar00rootroot00000000000000/* LodePNG Examples Copyright (c) 2005-2012 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "lodepng.h" #include #include /* Encodes given file as a gzip file. See also the gzip specification, RFC 1952: http://www.gzip.org/zlib/rfc-gzip.html */ //g++ lodepng.cpp example_gzip.cpp -ansi -pedantic -Wall -Wextra -O3 //saves image to filename given as argument. Warning, this overwrites the file without warning! int main(int argc, char *argv[]) { if(argc < 2) { std::cout << "Please provide input filename (output is input with .gz)" << std::endl; return 0; } //NOTE: this sample will overwrite the output file without warning! std::string infilename = argv[1]; std::string outfilename = infilename + ".gz"; std::vector in; lodepng::load_file(in, infilename); size_t outsize = 10; unsigned char* out = (unsigned char*)malloc(outsize); out[0] = 31; //ID1 out[1] = 139; //ID2 out[2] = 8; //CM out[3] = 0; //FLG //MTIME out[4] = 0; out[5] = 0; out[6] = 0; out[7] = 0; out[8] = 2; //2 = slow, 4 = fast compression out[9] = 255; //OS unknown lodepng_deflate(&out, &outsize, &in[0], in.size(), &lodepng_default_compress_settings); unsigned crc = lodepng_crc32(&in[0], in.size()); size_t footer = outsize; outsize += 8; out = (unsigned char*)realloc(out, outsize); //CRC out[footer + 0] = crc % 256; out[footer + 1] = (crc >> 8) % 256; out[footer + 2] = (crc >> 16) % 256; out[footer + 3] = (crc >> 24) % 256; //ISIZE out[footer + 4] = in.size() % 256; out[footer + 5] = (in.size() >> 8) % 256; out[footer + 6] = (in.size() >> 16) % 256; out[footer + 7] = (in.size() >> 24) % 256; lodepng_save_file(out, outsize, outfilename.c_str()); free(out); } lodepng-0.0~git20220618.b4ed2cd/examples/example_opengl.cpp000066400000000000000000000117431425344217700232760ustar00rootroot00000000000000/* LodePNG Examples Copyright (c) 2005-2012 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ //Compile command for Linux: //g++ lodepng.cpp example_opengl.cpp -lSDL -lGL -O3 /* LodePNG OpenGL example. Decodes a PNG and shows it in OpenGL. PNG filename should be given as a command line parameter. It's written for the most basic old OpenGL version, and a correction for non power of two textures had to be added. Only very few lines on the sample are about loading the PNG. Most of the sample lines show a way to render a texture in 2D in OpenGL. No fancy 3D graphics are shown, it only shows the image statically. The sample shows LodePNG can be used to load PNG images as textures in OpenGL. */ #include "lodepng.h" #include #include #include int main(int argc, char *argv[]) { if(argc < 2) { std::cout << "Please provide a filename." << std::endl; return 1; } const char* filename = argv[1]; // Load file and decode image. std::vector image; unsigned width, height; unsigned error = lodepng::decode(image, width, height, filename); // If there's an error, display it. if(error != 0) { std::cout << "error " << error << ": " << lodepng_error_text(error) << std::endl; return 1; } // Here the PNG is loaded in "image". All the rest of the code is SDL and OpenGL stuff. int screenw = width; if(screenw > 1024) screenw = 1024; int screenh = height; if(screenh > 768) screenw = 768; if(SDL_Init(SDL_INIT_VIDEO) < 0) { std::cout << "Error: Unable to init SDL: " << SDL_GetError() << std::endl; return 1; } SDL_Surface* scr = SDL_SetVideoMode(screenw, screenh, 32, SDL_OPENGL); if(scr == 0) { std::cout << "Error: Unable to set video. SDL error message: " << SDL_GetError() << std::endl; return 1; } // The official code for "Setting Your Raster Position to a Pixel Location" (i.e. set up a camera for 2D screen) glViewport(0, 0, screenw, screenh); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, screenw, screenh, 0, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Make some OpenGL properties better for 2D and enable alpha channel. glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glDisable(GL_ALPHA_TEST); if(glGetError() != GL_NO_ERROR) { std::cout << "Error initing GL" << std::endl; return 1; } // Texture size must be power of two for the primitive OpenGL version this is written for. Find next power of two. size_t u2 = 1; while(u2 < width) u2 *= 2; size_t v2 = 1; while(v2 < height) v2 *= 2; // Ratio for power of two version compared to actual version, to render the non power of two image with proper size. double u3 = (double)width / u2; double v3 = (double)height / v2; // Make power of two version of the image. std::vector image2(u2 * v2 * 4); for(size_t y = 0; y < height; y++) for(size_t x = 0; x < width; x++) for(size_t c = 0; c < 4; c++) { image2[4 * u2 * y + 4 * x + c] = image[4 * width * y + 4 * x + c]; } // Enable the texture for OpenGL. glEnable(GL_TEXTURE_2D); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); //GL_NEAREST = no smoothing glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 4, u2, v2, 0, GL_RGBA, GL_UNSIGNED_BYTE, &image2[0]); bool done = false; SDL_Event event = {0}; glColor4ub(255, 255, 255, 255); while(!done) { // Quit the loop when receiving quit event. while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) done = 1; } // Draw the texture on a quad, using u3 and v3 to correct non power of two texture size. glBegin(GL_QUADS); glTexCoord2d( 0, 0); glVertex2f( 0, 0); glTexCoord2d(u3, 0); glVertex2f(width, 0); glTexCoord2d(u3, v3); glVertex2f(width, height); glTexCoord2d( 0, v3); glVertex2f( 0, height); glEnd(); // Redraw and clear screen. SDL_GL_SwapBuffers(); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Limit frames per second, to not heat up the CPU and GPU too much. SDL_Delay(16); } } lodepng-0.0~git20220618.b4ed2cd/examples/example_optimize_png.cpp000066400000000000000000000113321425344217700245100ustar00rootroot00000000000000/* LodePNG Examples Copyright (c) 2005-2012 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ /* This example saves the PNG with the best compression LodePNG can do, and with unnecessary chunks removed. It tries out several combinations of settings and keeps the smallest one. NOTE: This is not as good as a true PNG optimizer like optipng or pngcrush. */ //g++ lodepng.cpp example_optimize_png.cpp -ansi -pedantic -Wall -Wextra -O3 #include "lodepng.h" #include int main(int argc, char *argv[]) { std::vector image; unsigned w, h; std::vector buffer; unsigned error; //check if user gave a filename if(argc < 3) { std::cout << "please provide in and out filename" << std::endl; return 0; } lodepng::load_file(buffer, argv[1]); error = lodepng::decode(image, w, h, buffer); if(error) { std::cout << "decoding error " << error << ": " << lodepng_error_text(error) << std::endl; return 0; } size_t origsize = buffer.size(); std::cout << "Original size: " << origsize << " (" << (origsize / 1024) << "K)" << std::endl; buffer.clear(); //Now encode as hard as possible with several filter types and window sizes lodepng::State state; state.encoder.filter_palette_zero = 0; //We try several filter types, including zero, allow trying them all on palette images too. state.encoder.add_id = false; //Don't add LodePNG version chunk to save more bytes state.encoder.text_compression = 1; //Not needed because we don't add text chunks, but this demonstrates another optimization setting state.encoder.zlibsettings.nicematch = 258; //Set this to the max possible, otherwise it can hurt compression state.encoder.zlibsettings.lazymatching = 1; //Definitely use lazy matching for better compression state.encoder.zlibsettings.windowsize = 32768; //Use maximum possible window size for best compression size_t bestsize = 0; bool inited = false; int beststrategy = 0; LodePNGFilterStrategy strategies[4] = { LFS_ZERO, LFS_MINSUM, LFS_ENTROPY, LFS_BRUTE_FORCE }; std::string strategynames[4] = { "LFS_ZERO", "LFS_MINSUM", "LFS_ENTROPY", "LFS_BRUTE_FORCE" }; // min match 3 allows all deflate lengths. min match 6 is similar to "Z_FILTERED" of zlib. int minmatches[2] = { 3, 6 }; int bestminmatch = 0; int autoconverts[2] = { 0, 1 }; std::string autoconvertnames[2] = { "0", "1" }; int bestautoconvert = 0; int bestblocktype = 0; // Try out all combinations of everything for(int i = 0; i < 4; i++) //filter strategy for(int j = 0; j < 2; j++) //min match for(int k = 0; k < 2; k++) //block type (for small images only) for(int l = 0; l < 2; l++) { //color convert strategy if(bestsize > 3000 && (k > 0 || l > 0)) continue; /* these only make sense on small images */ std::vector temp; state.encoder.filter_strategy = strategies[i]; state.encoder.zlibsettings.minmatch = minmatches[j]; state.encoder.zlibsettings.btype = k == 0 ? 2 : 1; state.encoder.auto_convert = autoconverts[l]; error = lodepng::encode(temp, image, w, h, state); if(error) { std::cout << "encoding error " << error << ": " << lodepng_error_text(error) << std::endl; return 0; } if(!inited || temp.size() < bestsize) { bestsize = temp.size(); beststrategy = i; bestminmatch = state.encoder.zlibsettings.minmatch; bestautoconvert = l; bestblocktype = state.encoder.zlibsettings.btype; temp.swap(buffer); inited = true; } } std::cout << "Chosen filter strategy: " << strategynames[beststrategy] << std::endl; std::cout << "Chosen min match: " << bestminmatch << std::endl; std::cout << "Chosen block type: " << bestblocktype << std::endl; std::cout << "Chosen auto convert: " << autoconvertnames[bestautoconvert] << std::endl; lodepng::save_file(buffer, argv[2]); std::cout << "New size: " << buffer.size() << " (" << (buffer.size() / 1024) << "K)" << std::endl; } lodepng-0.0~git20220618.b4ed2cd/examples/example_png2bmp.cpp000066400000000000000000000113041425344217700233500ustar00rootroot00000000000000/* LodePNG Examples Copyright (c) 2005-2012 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "lodepng.h" #include /* This example converts a PNG file to a BMP file. NOTE: it overwrites the output file without warning if it exists! Give the PNG and the BMP file names as command line arguments. */ /* g++ lodepng.cpp example_png2bmp.cpp -Wall -Wextra -pedantic -ansi -lSDL -O3 */ //Input image must be RGB buffer (3 bytes per pixel), but you can easily make it //support RGBA input and output by changing the inputChannels and/or outputChannels //in the function to 4. void encodeBMP(std::vector& bmp, const unsigned char* image, int w, int h) { //3 bytes per pixel used for both input and output. int inputChannels = 3; int outputChannels = 3; //bytes 0-13 bmp.push_back('B'); bmp.push_back('M'); //0: bfType bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); //2: bfSize; size not yet known for now, filled in later. bmp.push_back(0); bmp.push_back(0); //6: bfReserved1 bmp.push_back(0); bmp.push_back(0); //8: bfReserved2 bmp.push_back(54 % 256); bmp.push_back(54 / 256); bmp.push_back(0); bmp.push_back(0); //10: bfOffBits (54 header bytes) //bytes 14-53 bmp.push_back(40); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); //14: biSize bmp.push_back(w % 256); bmp.push_back(w / 256); bmp.push_back(0); bmp.push_back(0); //18: biWidth bmp.push_back(h % 256); bmp.push_back(h / 256); bmp.push_back(0); bmp.push_back(0); //22: biHeight bmp.push_back(1); bmp.push_back(0); //26: biPlanes bmp.push_back(outputChannels * 8); bmp.push_back(0); //28: biBitCount bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); //30: biCompression bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); //34: biSizeImage bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); //38: biXPelsPerMeter bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); //42: biYPelsPerMeter bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); //46: biClrUsed bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); //50: biClrImportant /* Convert the input RGBRGBRGB pixel buffer to the BMP pixel buffer format. There are 3 differences with the input buffer: -BMP stores the rows inversed, from bottom to top -BMP stores the color channels in BGR instead of RGB order -BMP requires each row to have a multiple of 4 bytes, so sometimes padding bytes are added between rows */ int imagerowbytes = outputChannels * w; imagerowbytes = imagerowbytes % 4 == 0 ? imagerowbytes : imagerowbytes + (4 - imagerowbytes % 4); //must be multiple of 4 for(int y = h - 1; y >= 0; y--) { //the rows are stored inversed in bmp int c = 0; for(int x = 0; x < imagerowbytes; x++) { if(x < w * outputChannels) { int inc = c; //Convert RGB(A) into BGR(A) if(c == 0) inc = 2; else if(c == 2) inc = 0; bmp.push_back(image[inputChannels * (w * y + x / outputChannels) + inc]); } else bmp.push_back(0); c++; if(c >= outputChannels) c = 0; } } // Fill in the size bmp[2] = bmp.size() % 256; bmp[3] = (bmp.size() / 256) % 256; bmp[4] = (bmp.size() / 65536) % 256; bmp[5] = bmp.size() / 16777216; } int main(int argc, char *argv[]) { if(argc < 3) { std::cout << "Please provide input PNG and output BMP file names" << std::endl; return 0; } const char* infile = argv[1]; const char* outfile = argv[2]; std::vector image; //the raw pixels unsigned width, height; unsigned error = lodepng::decode(image, width, height, infile, LCT_RGB, 8); if(error) { std::cout << "error " << error << ": " << lodepng_error_text(error) << std::endl; return 0; } std::vector bmp; encodeBMP(bmp, &image[0], width, height); lodepng::save_file(bmp, outfile); } lodepng-0.0~git20220618.b4ed2cd/examples/example_png_info.cpp000066400000000000000000000240671425344217700236140ustar00rootroot00000000000000/* LodePNG Examples Copyright (c) 2005-2012 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ //g++ lodepng.cpp example_png_info.cpp -ansi -pedantic -Wall -Wextra -lSDL -O3 /* This sample shows a lot of information in the console about a PNG file, including color type, text chunks, the names of all chunks in the image, etc... */ #include "lodepng.h" #include /* Display general info about the PNG. */ void displayPNGInfo(const LodePNGInfo& info) { const LodePNGColorMode& color = info.color; std::cout << "Compression method: " << info.compression_method << std::endl; std::cout << "Filter method: " << info.filter_method << std::endl; std::cout << "Interlace method: " << info.interlace_method << std::endl; std::cout << "Color type: " << color.colortype << std::endl; std::cout << "Bit depth: " << color.bitdepth << std::endl; std::cout << "Bits per pixel: " << lodepng_get_bpp(&color) << std::endl; std::cout << "Channels per pixel: " << lodepng_get_channels(&color) << std::endl; std::cout << "Is greyscale type: " << lodepng_is_greyscale_type(&color) << std::endl; std::cout << "Can have alpha: " << lodepng_can_have_alpha(&color) << std::endl; std::cout << "Palette size: " << color.palettesize << std::endl; std::cout << "Has color key: " << color.key_defined << std::endl; if(color.key_defined) { std::cout << "Color key r: " << color.key_r << std::endl; std::cout << "Color key g: " << color.key_g << std::endl; std::cout << "Color key b: " << color.key_b << std::endl; } std::cout << "Texts: " << info.text_num << std::endl; for(size_t i = 0; i < info.text_num; i++) { std::cout << "Text: " << info.text_keys[i] << ": " << info.text_strings[i] << std::endl << std::endl; } std::cout << "International texts: " << info.itext_num << std::endl; for(size_t i = 0; i < info.itext_num; i++) { std::cout << "Text: " << info.itext_keys[i] << ", " << info.itext_langtags[i] << ", " << info.itext_transkeys[i] << ": " << info.itext_strings[i] << std::endl << std::endl; } std::cout << "Time defined: " << info.time_defined << std::endl; if(info.time_defined) { const LodePNGTime& time = info.time; std::cout << "year: " << time.year << std::endl; std::cout << "month: " << time.month << std::endl; std::cout << "day: " << time.day << std::endl; std::cout << "hour: " << time.hour << std::endl; std::cout << "minute: " << time.minute << std::endl; std::cout << "second: " << time.second << std::endl; } std::cout << "Physics defined: " << info.phys_defined << std::endl; if(info.phys_defined) { std::cout << "physics X: " << info.phys_x << std::endl; std::cout << "physics Y: " << info.phys_y << std::endl; std::cout << "physics unit: " << info.phys_unit << std::endl; } } /* Display the names and sizes of all chunks in the PNG file. */ void displayChunkNames(const std::vector& buffer) { // Listing chunks is based on the original file, not the decoded png info. const unsigned char *chunk, *end; end = &buffer.back() + 1; chunk = &buffer.front() + 8; std::cout << std::endl << "Chunks:" << std::endl; std::cout << " type: length(s)"; std::string last_type; while(chunk < end && end - chunk >= 8) { char type[5]; lodepng_chunk_type(type, chunk); if(std::string(type).size() != 4) { std::cout << "this is probably not a PNG" << std::endl; return; } if(last_type != type) { std::cout << std::endl; std::cout << " " << type << ": "; } last_type = type; std::cout << lodepng_chunk_length(chunk) << ", "; chunk = lodepng_chunk_next_const(chunk, end); } std::cout << std::endl; } /* Show ASCII art preview of the image */ void displayAsciiArt(const std::vector& image, unsigned w, unsigned h) { if(w > 0 && h > 0) { std::cout << std::endl << "ASCII Art Preview: " << std::endl; unsigned w2 = 48; if(w < w2) w2 = w; unsigned h2 = h * w2 / w; h2 = (h2 * 2) / 3; //compensate for non-square characters in terminal if(h2 > (w2 * 2)) h2 = w2 * 2; //avoid too large output std::cout << '+'; for(unsigned x = 0; x < w2; x++) std::cout << '-'; std::cout << '+' << std::endl; for(unsigned y = 0; y < h2; y++) { std::cout << "|"; for(unsigned x = 0; x < w2; x++) { unsigned x2 = x * w / w2; unsigned y2 = y * h / h2; int r = image[y2 * w * 4 + x2 * 4 + 0]; int g = image[y2 * w * 4 + x2 * 4 + 1]; int b = image[y2 * w * 4 + x2 * 4 + 2]; int a = image[y2 * w * 4 + x2 * 4 + 3]; int lightness = ((r + g + b) / 3) * a / 255; int min = (r < g && r < b) ? r : (g < b ? g : b); int max = (r > g && r > b) ? r : (g > b ? g : b); int saturation = max - min; int letter = 'i'; //i for grey, or r,y,g,c,b,m for colors if(saturation > 32) { int h = lightness >= (min + max) / 2; if(h) letter = (min == r ? 'c' : (min == g ? 'm' : 'y')); else letter = (max == r ? 'r' : (max == g ? 'g' : 'b')); } int symbol = ' '; if(lightness > 224) symbol = '@'; else if(lightness > 128) symbol = letter - 32; else if(lightness > 32) symbol = letter; else if(lightness > 16) symbol = '.'; std::cout << (char)symbol; } std::cout << "|"; std::cout << std::endl; } std::cout << '+'; for(unsigned x = 0; x < w2; x++) std::cout << '-'; std::cout << '+' << std::endl; } } /* Show the filtertypes of each scanline in this PNG image. */ void displayFilterTypes(const std::vector& buffer, bool ignore_checksums) { //Get color type and interlace type lodepng::State state; if(ignore_checksums) { state.decoder.ignore_crc = 1; state.decoder.zlibsettings.ignore_adler32 = 1; } unsigned w, h; unsigned error; error = lodepng_inspect(&w, &h, &state, &buffer[0], buffer.size()); if(error) { std::cout << "inspect error " << error << ": " << lodepng_error_text(error) << std::endl; return; } if(state.info_png.interlace_method == 1) { std::cout << "showing filtertypes for interlaced PNG not supported by this example" << std::endl; return; } //Read literal data from all IDAT chunks const unsigned char *chunk, *begin, *end; end = &buffer.back() + 1; begin = chunk = &buffer.front() + 8; std::vector zdata; while(chunk < end && end - chunk >= 8) { char type[5]; lodepng_chunk_type(type, chunk); if(std::string(type).size() != 4) { std::cout << "this is probably not a PNG" << std::endl; return; } if(std::string(type) == "IDAT") { const unsigned char* cdata = lodepng_chunk_data_const(chunk); unsigned clength = lodepng_chunk_length(chunk); if(chunk + clength + 12 > end || clength > buffer.size() || chunk + clength + 12 < begin) { std::cout << "invalid chunk length" << std::endl; return; } for(unsigned i = 0; i < clength; i++) { zdata.push_back(cdata[i]); } } chunk = lodepng_chunk_next_const(chunk, end); } //Decompress all IDAT data std::vector data; error = lodepng::decompress(data, &zdata[0], zdata.size()); if(error) { std::cout << "decompress error " << error << ": " << lodepng_error_text(error) << std::endl; return; } //A line is 1 filter byte + all pixels size_t linebytes = 1 + lodepng_get_raw_size(w, 1, &state.info_png.color); if(linebytes == 0) { std::cout << "error: linebytes is 0" << std::endl; return; } std::cout << "Filter types: "; for(size_t i = 0; i < data.size(); i += linebytes) { std::cout << (int)(data[i]) << " "; } std::cout << std::endl; } /* Main */ int main(int argc, char *argv[]) /*list the chunks*/ { bool ignore_checksums = false; std::string filename = ""; for (int i = 1; i < argc; i++) { if(std::string(argv[i]) == "--ignore_checksums") ignore_checksums = true; else filename = argv[i]; } if(filename == "") { std::cout << "Please provide a filename to preview" << std::endl; return 0; } std::vector buffer; std::vector image; unsigned w, h; lodepng::load_file(buffer, filename); //load the image file with given filename lodepng::State state; if(ignore_checksums) { state.decoder.ignore_crc = 1; state.decoder.zlibsettings.ignore_adler32 = 1; } unsigned error = lodepng::decode(image, w, h, state, buffer); if(error) { std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl; return 0; } std::cout << "Filesize: " << buffer.size() << " (" << buffer.size() / 1024 << "K)" << std::endl; std::cout << "Width: " << w << std::endl; std::cout << "Height: " << h << std::endl; std::cout << "Num pixels: " << w * h << std::endl; if(w > 0 && h > 0) { std::cout << "Top left pixel color:" << " r: " << (int)image[0] << " g: " << (int)image[1] << " b: " << (int)image[2] << " a: " << (int)image[3] << std::endl; } displayPNGInfo(state.info_png); std::cout << std::endl; displayChunkNames(buffer); std::cout << std::endl; displayFilterTypes(buffer, ignore_checksums); std::cout << std::endl; displayAsciiArt(image, w, h); } lodepng-0.0~git20220618.b4ed2cd/examples/example_reencode.cpp000066400000000000000000000042521425344217700235730ustar00rootroot00000000000000/* LodePNG Examples Copyright (c) 2005-2010 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ /* LodePNG decode-encode: decodes the image, then encodes it again, with all the same information, chunks, color types, etc... as the original image had. This sample shows how LodePNG can be used for a conforming PNG editor. */ //g++ lodepng.cpp example_reencode.cpp -ansi -pedantic -Wall -Wextra -lSDL -O3 -o reencode #include "lodepng.h" #include int main(int argc, char *argv[]) { std::vector image; unsigned w, h; std::vector buffer; lodepng::State state; unsigned error; //check if user gave a filename if(argc < 3) { std::cout << "please provide in and out filename" << std::endl; return 0; } state.decoder.color_convert = 0; state.decoder.remember_unknown_chunks = 1; //make it reproduce even unknown chunks in the saved image lodepng::load_file(buffer, argv[1]); error = lodepng::decode(image, w, h, state, buffer); if(error) { std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl; return 0; } buffer.clear(); state.encoder.text_compression = 1; error = lodepng::encode(buffer, image, w, h, state); if(error) { std::cout << "encoder error " << error << ": " << lodepng_error_text(error) << std::endl; return 0; } lodepng::save_file(buffer, argv[2]); } lodepng-0.0~git20220618.b4ed2cd/examples/example_sdl.c000066400000000000000000000106461425344217700222350ustar00rootroot00000000000000/* LodePNG Examples Copyright (c) 2005-2012 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ /* Compile command for Linux: gcc lodepng.c example_sdl.c -ansi -pedantic -Wall -Wextra -lSDL2 -O3 -o showpng */ /* LodePNG SDL example This example displays a PNG with a checkerboard pattern to show tranparency. It requires the SDL2 library to compile and run. If multiple filenames are given to the command line, it shows all of them. Press any key to see next image, or esc to quit. */ #include "lodepng.h" #include /*shows image with SDL. Returns 1 if user wants to fully quit, 0 if user wants to see next image.*/ int show(const char* filename) { unsigned error; unsigned char* image; unsigned w, h, x, y; int done; size_t jump = 1; SDL_Window* sdl_window; SDL_Renderer* sdl_renderer; SDL_Texture* sdl_texture; SDL_Event sdl_event; size_t screenw, screenh, pitch; Uint32* sdl_pixels; printf("showing %s\n", filename); /*load the PNG in one function call*/ error = lodepng_decode32_file(&image, &w, &h, filename); /*stop if there is an error*/ if(error) { printf("decoder error %u: %s\n", error, lodepng_error_text(error)); return 0; } /* avoid too large window size by downscaling large image */ if(w / 1024 >= jump) jump = w / 1024 + 1; if(h / 1024 >= jump) jump = h / 1024 + 1; screenw = w / jump; screenh = h / jump; pitch = screenw * sizeof(Uint32); /* init SDL */ SDL_CreateWindowAndRenderer(screenw, screenh, SDL_WINDOW_OPENGL, &sdl_window, &sdl_renderer); SDL_SetWindowTitle(sdl_window, filename); if(!sdl_window) { printf("Error, no SDL screen\n"); return 0; } sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screenw, screenh); sdl_pixels = (Uint32*)malloc(screenw * screenh * sizeof(Uint32)); if(!sdl_pixels) { printf("Failed to allocate pixels\n"); return 0; } /* plot the pixels of the PNG file */ for(y = 0; y + jump - 1 < h; y += jump) for(x = 0; x + jump - 1 < w; x += jump) { /* get RGBA components */ Uint32 r = image[4 * y * w + 4 * x + 0]; /* red */ Uint32 g = image[4 * y * w + 4 * x + 1]; /* green */ Uint32 b = image[4 * y * w + 4 * x + 2]; /* blue */ Uint32 a = image[4 * y * w + 4 * x + 3]; /* alpha */ /* make translucency visible by placing checkerboard pattern behind image */ int checkerColor = 191 + 64 * (((x / 16) % 2) == ((y / 16) % 2)); r = (a * r + (255 - a) * checkerColor) / 255; g = (a * g + (255 - a) * checkerColor) / 255; b = (a * b + (255 - a) * checkerColor) / 255; /* give the color value to the pixel of the screenbuffer */ sdl_pixels[(y * screenw + x) / jump] = 65536 * r + 256 * g + b; } /* render the pixels to the screen */ SDL_UpdateTexture(sdl_texture, NULL, sdl_pixels, pitch); SDL_RenderClear(sdl_renderer); SDL_RenderCopy(sdl_renderer, sdl_texture, NULL, NULL); SDL_RenderPresent(sdl_renderer); /* pause until you press escape and meanwhile redraw screen */ done = 0; while(done == 0) { while(SDL_PollEvent(&sdl_event)) { if(sdl_event.type == SDL_QUIT) done = 2; else if(SDL_GetKeyboardState(NULL)[SDLK_ESCAPE]) done = 2; else if(sdl_event.type == SDL_KEYDOWN) done = 1; /* press any other key for next image */ } SDL_Delay(5); /* pause 5 ms so it consumes less processing power */ } SDL_Quit(); free(sdl_pixels); return done == 2 ? 1 : 0; } int main(int argc, char* argv[]) { int i; if(argc <= 1) printf("Please enter PNG file name(s) to display\n");; for(i = 1; i < argc; i++) { if(show(argv[i])) return 0; } return 0; } lodepng-0.0~git20220618.b4ed2cd/examples/example_sdl.cpp000066400000000000000000000107271425344217700225750ustar00rootroot00000000000000/* LodePNG Examples Copyright (c) 2005-2012 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ //Compile command for Linux: //g++ lodepng.cpp example_sdl.cpp -lSDL2 -O3 -o showpng /* LodePNG SDL example This example displays a PNG with a checkerboard pattern to show tranparency. It requires the SDL2 library to compile and run. If multiple filenames are given to the command line, it shows all of them. Press any key to see next image, or esc to quit. */ #include "lodepng.h" #include #include int show(const std::string& caption, const unsigned char* rgba, unsigned w, unsigned h) { //avoid too large window size by downscaling large image unsigned jump = 1; if(w / 1024 >= jump) jump = w / 1024 + 1; if(h / 1024 >= jump) jump = h / 1024 + 1; size_t screenw = w / jump; size_t screenh = h / jump; size_t pitch = screenw * sizeof(Uint32); //init SDL SDL_Window* sdl_window; SDL_Renderer* sdl_renderer; SDL_CreateWindowAndRenderer(screenw, screenh, SDL_WINDOW_OPENGL, &sdl_window, &sdl_renderer); SDL_SetWindowTitle(sdl_window, caption.c_str()); if(!sdl_window) { std::cout << "error, no SDL screen" << std::endl; return 0; } SDL_Texture* sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screenw, screenh); std::vector sdl_pixels(screenw * screenh * sizeof(Uint32)); //plot the pixels of the PNG file for(unsigned y = 0; y + jump - 1 < h; y += jump) for(unsigned x = 0; x + jump - 1 < w; x += jump) { //get RGBA components Uint32 r = rgba[4 * y * w + 4 * x + 0]; //red Uint32 g = rgba[4 * y * w + 4 * x + 1]; //green Uint32 b = rgba[4 * y * w + 4 * x + 2]; //blue Uint32 a = rgba[4 * y * w + 4 * x + 3]; //alpha //make translucency visible by placing checkerboard pattern behind image int checkerColor = 191 + 64 * (((x / 16) % 2) == ((y / 16) % 2)); r = (a * r + (255 - a) * checkerColor) / 255; g = (a * g + (255 - a) * checkerColor) / 255; b = (a * b + (255 - a) * checkerColor) / 255; //give the color value to the pixel of the screenbuffer sdl_pixels[(y * screenw + x) / jump] = 65536 * r + 256 * g + b; } // render the pixels to the screen SDL_UpdateTexture(sdl_texture, NULL, sdl_pixels.data(), pitch); SDL_RenderClear(sdl_renderer); SDL_RenderCopy(sdl_renderer, sdl_texture, NULL, NULL); SDL_RenderPresent(sdl_renderer); //pause until you press escape and meanwhile redraw screen SDL_Event event; int done = 0; while(done == 0) { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) done = 2; else if(SDL_GetKeyboardState(NULL)[SDLK_ESCAPE]) done = 2; else if(event.type == SDL_KEYDOWN) done = 1; //press any other key for next image } SDL_Delay(5); //pause 5 ms so it consumes less processing power } SDL_Quit(); return done == 2 ? 1 : 0; } /*shows image with SDL. Returns 1 if user wants to fully quit, 0 if user wants to see next image.*/ int showfile(const char* filename) { std::cout << "showing " << filename << std::endl; std::vector buffer, image; lodepng::load_file(buffer, filename); //load the image file with given filename unsigned w, h; unsigned error = lodepng::decode(image, w, h, buffer); //decode the png //stop if there is an error if(error) { std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl; return 0; } return show(filename, &image[0], w, h); } int main(int argc, char* argv[]) { if(argc <= 1) std::cout << "Please enter PNG file name(s) to display" << std::endl; for(int i = 1; i < argc; i++) { if(showfile(argv[i])) return 0; } } lodepng-0.0~git20220618.b4ed2cd/lodepng.cpp000066400000000000000000010265111425344217700201110ustar00rootroot00000000000000/* LodePNG version 20220618 Copyright (c) 2005-2022 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ /* The manual and changelog are in the header file "lodepng.h" Rename this file to lodepng.cpp to use it for C++, or to lodepng.c to use it for C. */ #include "lodepng.h" #ifdef LODEPNG_COMPILE_DISK #include /* LONG_MAX */ #include /* file handling */ #endif /* LODEPNG_COMPILE_DISK */ #ifdef LODEPNG_COMPILE_ALLOCATORS #include /* allocations */ #endif /* LODEPNG_COMPILE_ALLOCATORS */ #if defined(_MSC_VER) && (_MSC_VER >= 1310) /*Visual Studio: A few warning types are not desired here.*/ #pragma warning( disable : 4244 ) /*implicit conversions: not warned by gcc -Wall -Wextra and requires too much casts*/ #pragma warning( disable : 4996 ) /*VS does not like fopen, but fopen_s is not standard C so unusable here*/ #endif /*_MSC_VER */ const char* LODEPNG_VERSION_STRING = "20220618"; /* This source file is divided into the following large parts. The code sections with the "LODEPNG_COMPILE_" #defines divide this up further in an intermixed way. -Tools for C and common code for PNG and Zlib -C Code for Zlib (huffman, deflate, ...) -C Code for PNG (file format chunks, adam7, PNG filters, color conversions, ...) -The C++ wrapper around all of the above */ /* ////////////////////////////////////////////////////////////////////////// */ /* ////////////////////////////////////////////////////////////////////////// */ /* // Tools for C, and common code for PNG and Zlib. // */ /* ////////////////////////////////////////////////////////////////////////// */ /* ////////////////////////////////////////////////////////////////////////// */ /*The malloc, realloc and free functions defined here with "lodepng_" in front of the name, so that you can easily change them to others related to your platform if needed. Everything else in the code calls these. Pass -DLODEPNG_NO_COMPILE_ALLOCATORS to the compiler, or comment out #define LODEPNG_COMPILE_ALLOCATORS in the header, to disable the ones here and define them in your own project's source files without needing to change lodepng source code. Don't forget to remove "static" if you copypaste them from here.*/ #ifdef LODEPNG_COMPILE_ALLOCATORS static void* lodepng_malloc(size_t size) { #ifdef LODEPNG_MAX_ALLOC if(size > LODEPNG_MAX_ALLOC) return 0; #endif return malloc(size); } /* NOTE: when realloc returns NULL, it leaves the original memory untouched */ static void* lodepng_realloc(void* ptr, size_t new_size) { #ifdef LODEPNG_MAX_ALLOC if(new_size > LODEPNG_MAX_ALLOC) return 0; #endif return realloc(ptr, new_size); } static void lodepng_free(void* ptr) { free(ptr); } #else /*LODEPNG_COMPILE_ALLOCATORS*/ /* TODO: support giving additional void* payload to the custom allocators */ void* lodepng_malloc(size_t size); void* lodepng_realloc(void* ptr, size_t new_size); void lodepng_free(void* ptr); #endif /*LODEPNG_COMPILE_ALLOCATORS*/ /* convince the compiler to inline a function, for use when this measurably improves performance */ /* inline is not available in C90, but use it when supported by the compiler */ #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || (defined(__cplusplus) && (__cplusplus >= 199711L)) #define LODEPNG_INLINE inline #else #define LODEPNG_INLINE /* not available */ #endif /* restrict is not available in C90, but use it when supported by the compiler */ #if (defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))) ||\ (defined(_MSC_VER) && (_MSC_VER >= 1400)) || \ (defined(__WATCOMC__) && (__WATCOMC__ >= 1250) && !defined(__cplusplus)) #define LODEPNG_RESTRICT __restrict #else #define LODEPNG_RESTRICT /* not available */ #endif /* Replacements for C library functions such as memcpy and strlen, to support platforms where a full C library is not available. The compiler can recognize them and compile to something as fast. */ static void lodepng_memcpy(void* LODEPNG_RESTRICT dst, const void* LODEPNG_RESTRICT src, size_t size) { size_t i; for(i = 0; i < size; i++) ((char*)dst)[i] = ((const char*)src)[i]; } static void lodepng_memset(void* LODEPNG_RESTRICT dst, int value, size_t num) { size_t i; for(i = 0; i < num; i++) ((char*)dst)[i] = (char)value; } /* does not check memory out of bounds, do not use on untrusted data */ static size_t lodepng_strlen(const char* a) { const char* orig = a; /* avoid warning about unused function in case of disabled COMPILE... macros */ (void)(&lodepng_strlen); while(*a) a++; return (size_t)(a - orig); } #define LODEPNG_MAX(a, b) (((a) > (b)) ? (a) : (b)) #define LODEPNG_MIN(a, b) (((a) < (b)) ? (a) : (b)) #define LODEPNG_ABS(x) ((x) < 0 ? -(x) : (x)) #if defined(LODEPNG_COMPILE_PNG) || defined(LODEPNG_COMPILE_DECODER) /* Safely check if adding two integers will overflow (no undefined behavior, compiler removing the code, etc...) and output result. */ static int lodepng_addofl(size_t a, size_t b, size_t* result) { *result = a + b; /* Unsigned addition is well defined and safe in C90 */ return *result < a; } #endif /*defined(LODEPNG_COMPILE_PNG) || defined(LODEPNG_COMPILE_DECODER)*/ #ifdef LODEPNG_COMPILE_DECODER /* Safely check if multiplying two integers will overflow (no undefined behavior, compiler removing the code, etc...) and output result. */ static int lodepng_mulofl(size_t a, size_t b, size_t* result) { *result = a * b; /* Unsigned multiplication is well defined and safe in C90 */ return (a != 0 && *result / a != b); } #ifdef LODEPNG_COMPILE_ZLIB /* Safely check if a + b > c, even if overflow could happen. */ static int lodepng_gtofl(size_t a, size_t b, size_t c) { size_t d; if(lodepng_addofl(a, b, &d)) return 1; return d > c; } #endif /*LODEPNG_COMPILE_ZLIB*/ #endif /*LODEPNG_COMPILE_DECODER*/ /* Often in case of an error a value is assigned to a variable and then it breaks out of a loop (to go to the cleanup phase of a function). This macro does that. It makes the error handling code shorter and more readable. Example: if(!uivector_resize(&lz77_encoded, datasize)) ERROR_BREAK(83); */ #define CERROR_BREAK(errorvar, code){\ errorvar = code;\ break;\ } /*version of CERROR_BREAK that assumes the common case where the error variable is named "error"*/ #define ERROR_BREAK(code) CERROR_BREAK(error, code) /*Set error var to the error code, and return it.*/ #define CERROR_RETURN_ERROR(errorvar, code){\ errorvar = code;\ return code;\ } /*Try the code, if it returns error, also return the error.*/ #define CERROR_TRY_RETURN(call){\ unsigned error = call;\ if(error) return error;\ } /*Set error var to the error code, and return from the void function.*/ #define CERROR_RETURN(errorvar, code){\ errorvar = code;\ return;\ } /* About uivector, ucvector and string: -All of them wrap dynamic arrays or text strings in a similar way. -LodePNG was originally written in C++. The vectors replace the std::vectors that were used in the C++ version. -The string tools are made to avoid problems with compilers that declare things like strncat as deprecated. -They're not used in the interface, only internally in this file as static functions. -As with many other structs in this file, the init and cleanup functions serve as ctor and dtor. */ #ifdef LODEPNG_COMPILE_ZLIB #ifdef LODEPNG_COMPILE_ENCODER /*dynamic vector of unsigned ints*/ typedef struct uivector { unsigned* data; size_t size; /*size in number of unsigned longs*/ size_t allocsize; /*allocated size in bytes*/ } uivector; static void uivector_cleanup(void* p) { ((uivector*)p)->size = ((uivector*)p)->allocsize = 0; lodepng_free(((uivector*)p)->data); ((uivector*)p)->data = NULL; } /*returns 1 if success, 0 if failure ==> nothing done*/ static unsigned uivector_resize(uivector* p, size_t size) { size_t allocsize = size * sizeof(unsigned); if(allocsize > p->allocsize) { size_t newsize = allocsize + (p->allocsize >> 1u); void* data = lodepng_realloc(p->data, newsize); if(data) { p->allocsize = newsize; p->data = (unsigned*)data; } else return 0; /*error: not enough memory*/ } p->size = size; return 1; /*success*/ } static void uivector_init(uivector* p) { p->data = NULL; p->size = p->allocsize = 0; } /*returns 1 if success, 0 if failure ==> nothing done*/ static unsigned uivector_push_back(uivector* p, unsigned c) { if(!uivector_resize(p, p->size + 1)) return 0; p->data[p->size - 1] = c; return 1; } #endif /*LODEPNG_COMPILE_ENCODER*/ #endif /*LODEPNG_COMPILE_ZLIB*/ /* /////////////////////////////////////////////////////////////////////////// */ /*dynamic vector of unsigned chars*/ typedef struct ucvector { unsigned char* data; size_t size; /*used size*/ size_t allocsize; /*allocated size*/ } ucvector; /*returns 1 if success, 0 if failure ==> nothing done*/ static unsigned ucvector_reserve(ucvector* p, size_t size) { if(size > p->allocsize) { size_t newsize = size + (p->allocsize >> 1u); void* data = lodepng_realloc(p->data, newsize); if(data) { p->allocsize = newsize; p->data = (unsigned char*)data; } else return 0; /*error: not enough memory*/ } return 1; /*success*/ } /*returns 1 if success, 0 if failure ==> nothing done*/ static unsigned ucvector_resize(ucvector* p, size_t size) { p->size = size; return ucvector_reserve(p, size); } static ucvector ucvector_init(unsigned char* buffer, size_t size) { ucvector v; v.data = buffer; v.allocsize = v.size = size; return v; } /* ////////////////////////////////////////////////////////////////////////// */ #ifdef LODEPNG_COMPILE_PNG #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS /*free string pointer and set it to NULL*/ static void string_cleanup(char** out) { lodepng_free(*out); *out = NULL; } /*also appends null termination character*/ static char* alloc_string_sized(const char* in, size_t insize) { char* out = (char*)lodepng_malloc(insize + 1); if(out) { lodepng_memcpy(out, in, insize); out[insize] = 0; } return out; } /* dynamically allocates a new string with a copy of the null terminated input text */ static char* alloc_string(const char* in) { return alloc_string_sized(in, lodepng_strlen(in)); } #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ #endif /*LODEPNG_COMPILE_PNG*/ /* ////////////////////////////////////////////////////////////////////////// */ #if defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_PNG) static unsigned lodepng_read32bitInt(const unsigned char* buffer) { return (((unsigned)buffer[0] << 24u) | ((unsigned)buffer[1] << 16u) | ((unsigned)buffer[2] << 8u) | (unsigned)buffer[3]); } #endif /*defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_PNG)*/ #if defined(LODEPNG_COMPILE_PNG) || defined(LODEPNG_COMPILE_ENCODER) /*buffer must have at least 4 allocated bytes available*/ static void lodepng_set32bitInt(unsigned char* buffer, unsigned value) { buffer[0] = (unsigned char)((value >> 24) & 0xff); buffer[1] = (unsigned char)((value >> 16) & 0xff); buffer[2] = (unsigned char)((value >> 8) & 0xff); buffer[3] = (unsigned char)((value ) & 0xff); } #endif /*defined(LODEPNG_COMPILE_PNG) || defined(LODEPNG_COMPILE_ENCODER)*/ /* ////////////////////////////////////////////////////////////////////////// */ /* / File IO / */ /* ////////////////////////////////////////////////////////////////////////// */ #ifdef LODEPNG_COMPILE_DISK /* returns negative value on error. This should be pure C compatible, so no fstat. */ static long lodepng_filesize(const char* filename) { FILE* file; long size; file = fopen(filename, "rb"); if(!file) return -1; if(fseek(file, 0, SEEK_END) != 0) { fclose(file); return -1; } size = ftell(file); /* It may give LONG_MAX as directory size, this is invalid for us. */ if(size == LONG_MAX) size = -1; fclose(file); return size; } /* load file into buffer that already has the correct allocated size. Returns error code.*/ static unsigned lodepng_buffer_file(unsigned char* out, size_t size, const char* filename) { FILE* file; size_t readsize; file = fopen(filename, "rb"); if(!file) return 78; readsize = fread(out, 1, size, file); fclose(file); if(readsize != size) return 78; return 0; } unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename) { long size = lodepng_filesize(filename); if(size < 0) return 78; *outsize = (size_t)size; *out = (unsigned char*)lodepng_malloc((size_t)size); if(!(*out) && size > 0) return 83; /*the above malloc failed*/ return lodepng_buffer_file(*out, (size_t)size, filename); } /*write given buffer to the file, overwriting the file, it doesn't append to it.*/ unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename) { FILE* file; file = fopen(filename, "wb" ); if(!file) return 79; fwrite(buffer, 1, buffersize, file); fclose(file); return 0; } #endif /*LODEPNG_COMPILE_DISK*/ /* ////////////////////////////////////////////////////////////////////////// */ /* ////////////////////////////////////////////////////////////////////////// */ /* // End of common code and tools. Begin of Zlib related code. // */ /* ////////////////////////////////////////////////////////////////////////// */ /* ////////////////////////////////////////////////////////////////////////// */ #ifdef LODEPNG_COMPILE_ZLIB #ifdef LODEPNG_COMPILE_ENCODER typedef struct { ucvector* data; unsigned char bp; /*ok to overflow, indicates bit pos inside byte*/ } LodePNGBitWriter; static void LodePNGBitWriter_init(LodePNGBitWriter* writer, ucvector* data) { writer->data = data; writer->bp = 0; } /*TODO: this ignores potential out of memory errors*/ #define WRITEBIT(writer, bit){\ /* append new byte */\ if(((writer->bp) & 7u) == 0) {\ if(!ucvector_resize(writer->data, writer->data->size + 1)) return;\ writer->data->data[writer->data->size - 1] = 0;\ }\ (writer->data->data[writer->data->size - 1]) |= (bit << ((writer->bp) & 7u));\ ++writer->bp;\ } /* LSB of value is written first, and LSB of bytes is used first */ static void writeBits(LodePNGBitWriter* writer, unsigned value, size_t nbits) { if(nbits == 1) { /* compiler should statically compile this case if nbits == 1 */ WRITEBIT(writer, value); } else { /* TODO: increase output size only once here rather than in each WRITEBIT */ size_t i; for(i = 0; i != nbits; ++i) { WRITEBIT(writer, (unsigned char)((value >> i) & 1)); } } } /* This one is to use for adding huffman symbol, the value bits are written MSB first */ static void writeBitsReversed(LodePNGBitWriter* writer, unsigned value, size_t nbits) { size_t i; for(i = 0; i != nbits; ++i) { /* TODO: increase output size only once here rather than in each WRITEBIT */ WRITEBIT(writer, (unsigned char)((value >> (nbits - 1u - i)) & 1u)); } } #endif /*LODEPNG_COMPILE_ENCODER*/ #ifdef LODEPNG_COMPILE_DECODER typedef struct { const unsigned char* data; size_t size; /*size of data in bytes*/ size_t bitsize; /*size of data in bits, end of valid bp values, should be 8*size*/ size_t bp; unsigned buffer; /*buffer for reading bits. NOTE: 'unsigned' must support at least 32 bits*/ } LodePNGBitReader; /* data size argument is in bytes. Returns error if size too large causing overflow */ static unsigned LodePNGBitReader_init(LodePNGBitReader* reader, const unsigned char* data, size_t size) { size_t temp; reader->data = data; reader->size = size; /* size in bits, return error if overflow (if size_t is 32 bit this supports up to 500MB) */ if(lodepng_mulofl(size, 8u, &reader->bitsize)) return 105; /*ensure incremented bp can be compared to bitsize without overflow even when it would be incremented 32 too much and trying to ensure 32 more bits*/ if(lodepng_addofl(reader->bitsize, 64u, &temp)) return 105; reader->bp = 0; reader->buffer = 0; return 0; /*ok*/ } /* ensureBits functions: Ensures the reader can at least read nbits bits in one or more readBits calls, safely even if not enough bits are available. The nbits parameter is unused but is given for documentation purposes, error checking for amount of bits must be done beforehand. */ /*See ensureBits documentation above. This one ensures up to 9 bits */ static LODEPNG_INLINE void ensureBits9(LodePNGBitReader* reader, size_t nbits) { size_t start = reader->bp >> 3u; size_t size = reader->size; if(start + 1u < size) { reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u); reader->buffer >>= (reader->bp & 7u); } else { reader->buffer = 0; if(start + 0u < size) reader->buffer = reader->data[start + 0]; reader->buffer >>= (reader->bp & 7u); } (void)nbits; } /*See ensureBits documentation above. This one ensures up to 17 bits */ static LODEPNG_INLINE void ensureBits17(LodePNGBitReader* reader, size_t nbits) { size_t start = reader->bp >> 3u; size_t size = reader->size; if(start + 2u < size) { reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u) | ((unsigned)reader->data[start + 2] << 16u); reader->buffer >>= (reader->bp & 7u); } else { reader->buffer = 0; if(start + 0u < size) reader->buffer |= reader->data[start + 0]; if(start + 1u < size) reader->buffer |= ((unsigned)reader->data[start + 1] << 8u); reader->buffer >>= (reader->bp & 7u); } (void)nbits; } /*See ensureBits documentation above. This one ensures up to 25 bits */ static LODEPNG_INLINE void ensureBits25(LodePNGBitReader* reader, size_t nbits) { size_t start = reader->bp >> 3u; size_t size = reader->size; if(start + 3u < size) { reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u) | ((unsigned)reader->data[start + 2] << 16u) | ((unsigned)reader->data[start + 3] << 24u); reader->buffer >>= (reader->bp & 7u); } else { reader->buffer = 0; if(start + 0u < size) reader->buffer |= reader->data[start + 0]; if(start + 1u < size) reader->buffer |= ((unsigned)reader->data[start + 1] << 8u); if(start + 2u < size) reader->buffer |= ((unsigned)reader->data[start + 2] << 16u); reader->buffer >>= (reader->bp & 7u); } (void)nbits; } /*See ensureBits documentation above. This one ensures up to 32 bits */ static LODEPNG_INLINE void ensureBits32(LodePNGBitReader* reader, size_t nbits) { size_t start = reader->bp >> 3u; size_t size = reader->size; if(start + 4u < size) { reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u) | ((unsigned)reader->data[start + 2] << 16u) | ((unsigned)reader->data[start + 3] << 24u); reader->buffer >>= (reader->bp & 7u); reader->buffer |= (((unsigned)reader->data[start + 4] << 24u) << (8u - (reader->bp & 7u))); } else { reader->buffer = 0; if(start + 0u < size) reader->buffer |= reader->data[start + 0]; if(start + 1u < size) reader->buffer |= ((unsigned)reader->data[start + 1] << 8u); if(start + 2u < size) reader->buffer |= ((unsigned)reader->data[start + 2] << 16u); if(start + 3u < size) reader->buffer |= ((unsigned)reader->data[start + 3] << 24u); reader->buffer >>= (reader->bp & 7u); } (void)nbits; } /* Get bits without advancing the bit pointer. Must have enough bits available with ensureBits. Max nbits is 31. */ static LODEPNG_INLINE unsigned peekBits(LodePNGBitReader* reader, size_t nbits) { /* The shift allows nbits to be only up to 31. */ return reader->buffer & ((1u << nbits) - 1u); } /* Must have enough bits available with ensureBits */ static LODEPNG_INLINE void advanceBits(LodePNGBitReader* reader, size_t nbits) { reader->buffer >>= nbits; reader->bp += nbits; } /* Must have enough bits available with ensureBits */ static LODEPNG_INLINE unsigned readBits(LodePNGBitReader* reader, size_t nbits) { unsigned result = peekBits(reader, nbits); advanceBits(reader, nbits); return result; } #endif /*LODEPNG_COMPILE_DECODER*/ static unsigned reverseBits(unsigned bits, unsigned num) { /*TODO: implement faster lookup table based version when needed*/ unsigned i, result = 0; for(i = 0; i < num; i++) result |= ((bits >> (num - i - 1u)) & 1u) << i; return result; } /* ////////////////////////////////////////////////////////////////////////// */ /* / Deflate - Huffman / */ /* ////////////////////////////////////////////////////////////////////////// */ #define FIRST_LENGTH_CODE_INDEX 257 #define LAST_LENGTH_CODE_INDEX 285 /*256 literals, the end code, some length codes, and 2 unused codes*/ #define NUM_DEFLATE_CODE_SYMBOLS 288 /*the distance codes have their own symbols, 30 used, 2 unused*/ #define NUM_DISTANCE_SYMBOLS 32 /*the code length codes. 0-15: code lengths, 16: copy previous 3-6 times, 17: 3-10 zeros, 18: 11-138 zeros*/ #define NUM_CODE_LENGTH_CODES 19 /*the base lengths represented by codes 257-285*/ static const unsigned LENGTHBASE[29] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258}; /*the extra bits used by codes 257-285 (added to base length)*/ static const unsigned LENGTHEXTRA[29] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0}; /*the base backwards distances (the bits of distance codes appear after length codes and use their own huffman tree)*/ static const unsigned DISTANCEBASE[30] = {1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577}; /*the extra bits of backwards distances (added to base)*/ static const unsigned DISTANCEEXTRA[30] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13}; /*the order in which "code length alphabet code lengths" are stored as specified by deflate, out of this the huffman tree of the dynamic huffman tree lengths is generated*/ static const unsigned CLCL_ORDER[NUM_CODE_LENGTH_CODES] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; /* ////////////////////////////////////////////////////////////////////////// */ /* Huffman tree struct, containing multiple representations of the tree */ typedef struct HuffmanTree { unsigned* codes; /*the huffman codes (bit patterns representing the symbols)*/ unsigned* lengths; /*the lengths of the huffman codes*/ unsigned maxbitlen; /*maximum number of bits a single code can get*/ unsigned numcodes; /*number of symbols in the alphabet = number of codes*/ /* for reading only */ unsigned char* table_len; /*length of symbol from lookup table, or max length if secondary lookup needed*/ unsigned short* table_value; /*value of symbol from lookup table, or pointer to secondary table if needed*/ } HuffmanTree; static void HuffmanTree_init(HuffmanTree* tree) { tree->codes = 0; tree->lengths = 0; tree->table_len = 0; tree->table_value = 0; } static void HuffmanTree_cleanup(HuffmanTree* tree) { lodepng_free(tree->codes); lodepng_free(tree->lengths); lodepng_free(tree->table_len); lodepng_free(tree->table_value); } /* amount of bits for first huffman table lookup (aka root bits), see HuffmanTree_makeTable and huffmanDecodeSymbol.*/ /* values 8u and 9u work the fastest */ #define FIRSTBITS 9u /* a symbol value too big to represent any valid symbol, to indicate reading disallowed huffman bits combination, which is possible in case of only 0 or 1 present symbols. */ #define INVALIDSYMBOL 65535u /* make table for huffman decoding */ static unsigned HuffmanTree_makeTable(HuffmanTree* tree) { static const unsigned headsize = 1u << FIRSTBITS; /*size of the first table*/ static const unsigned mask = (1u << FIRSTBITS) /*headsize*/ - 1u; size_t i, numpresent, pointer, size; /*total table size*/ unsigned* maxlens = (unsigned*)lodepng_malloc(headsize * sizeof(unsigned)); if(!maxlens) return 83; /*alloc fail*/ /* compute maxlens: max total bit length of symbols sharing prefix in the first table*/ lodepng_memset(maxlens, 0, headsize * sizeof(*maxlens)); for(i = 0; i < tree->numcodes; i++) { unsigned symbol = tree->codes[i]; unsigned l = tree->lengths[i]; unsigned index; if(l <= FIRSTBITS) continue; /*symbols that fit in first table don't increase secondary table size*/ /*get the FIRSTBITS MSBs, the MSBs of the symbol are encoded first. See later comment about the reversing*/ index = reverseBits(symbol >> (l - FIRSTBITS), FIRSTBITS); maxlens[index] = LODEPNG_MAX(maxlens[index], l); } /* compute total table size: size of first table plus all secondary tables for symbols longer than FIRSTBITS */ size = headsize; for(i = 0; i < headsize; ++i) { unsigned l = maxlens[i]; if(l > FIRSTBITS) size += (1u << (l - FIRSTBITS)); } tree->table_len = (unsigned char*)lodepng_malloc(size * sizeof(*tree->table_len)); tree->table_value = (unsigned short*)lodepng_malloc(size * sizeof(*tree->table_value)); if(!tree->table_len || !tree->table_value) { lodepng_free(maxlens); /* freeing tree->table values is done at a higher scope */ return 83; /*alloc fail*/ } /*initialize with an invalid length to indicate unused entries*/ for(i = 0; i < size; ++i) tree->table_len[i] = 16; /*fill in the first table for long symbols: max prefix size and pointer to secondary tables*/ pointer = headsize; for(i = 0; i < headsize; ++i) { unsigned l = maxlens[i]; if(l <= FIRSTBITS) continue; tree->table_len[i] = l; tree->table_value[i] = pointer; pointer += (1u << (l - FIRSTBITS)); } lodepng_free(maxlens); /*fill in the first table for short symbols, or secondary table for long symbols*/ numpresent = 0; for(i = 0; i < tree->numcodes; ++i) { unsigned l = tree->lengths[i]; unsigned symbol, reverse; if(l == 0) continue; symbol = tree->codes[i]; /*the huffman bit pattern. i itself is the value.*/ /*reverse bits, because the huffman bits are given in MSB first order but the bit reader reads LSB first*/ reverse = reverseBits(symbol, l); numpresent++; if(l <= FIRSTBITS) { /*short symbol, fully in first table, replicated num times if l < FIRSTBITS*/ unsigned num = 1u << (FIRSTBITS - l); unsigned j; for(j = 0; j < num; ++j) { /*bit reader will read the l bits of symbol first, the remaining FIRSTBITS - l bits go to the MSB's*/ unsigned index = reverse | (j << l); if(tree->table_len[index] != 16) return 55; /*invalid tree: long symbol shares prefix with short symbol*/ tree->table_len[index] = l; tree->table_value[index] = i; } } else { /*long symbol, shares prefix with other long symbols in first lookup table, needs second lookup*/ /*the FIRSTBITS MSBs of the symbol are the first table index*/ unsigned index = reverse & mask; unsigned maxlen = tree->table_len[index]; /*log2 of secondary table length, should be >= l - FIRSTBITS*/ unsigned tablelen = maxlen - FIRSTBITS; unsigned start = tree->table_value[index]; /*starting index in secondary table*/ unsigned num = 1u << (tablelen - (l - FIRSTBITS)); /*amount of entries of this symbol in secondary table*/ unsigned j; if(maxlen < l) return 55; /*invalid tree: long symbol shares prefix with short symbol*/ for(j = 0; j < num; ++j) { unsigned reverse2 = reverse >> FIRSTBITS; /* l - FIRSTBITS bits */ unsigned index2 = start + (reverse2 | (j << (l - FIRSTBITS))); tree->table_len[index2] = l; tree->table_value[index2] = i; } } } if(numpresent < 2) { /* In case of exactly 1 symbol, in theory the huffman symbol needs 0 bits, but deflate uses 1 bit instead. In case of 0 symbols, no symbols can appear at all, but such huffman tree could still exist (e.g. if distance codes are never used). In both cases, not all symbols of the table will be filled in. Fill them in with an invalid symbol value so returning them from huffmanDecodeSymbol will cause error. */ for(i = 0; i < size; ++i) { if(tree->table_len[i] == 16) { /* As length, use a value smaller than FIRSTBITS for the head table, and a value larger than FIRSTBITS for the secondary table, to ensure valid behavior for advanceBits when reading this symbol. */ tree->table_len[i] = (i < headsize) ? 1 : (FIRSTBITS + 1); tree->table_value[i] = INVALIDSYMBOL; } } } else { /* A good huffman tree has N * 2 - 1 nodes, of which N - 1 are internal nodes. If that is not the case (due to too long length codes), the table will not have been fully used, and this is an error (not all bit combinations can be decoded): an oversubscribed huffman tree, indicated by error 55. */ for(i = 0; i < size; ++i) { if(tree->table_len[i] == 16) return 55; } } return 0; } /* Second step for the ...makeFromLengths and ...makeFromFrequencies functions. numcodes, lengths and maxbitlen must already be filled in correctly. return value is error. */ static unsigned HuffmanTree_makeFromLengths2(HuffmanTree* tree) { unsigned* blcount; unsigned* nextcode; unsigned error = 0; unsigned bits, n; tree->codes = (unsigned*)lodepng_malloc(tree->numcodes * sizeof(unsigned)); blcount = (unsigned*)lodepng_malloc((tree->maxbitlen + 1) * sizeof(unsigned)); nextcode = (unsigned*)lodepng_malloc((tree->maxbitlen + 1) * sizeof(unsigned)); if(!tree->codes || !blcount || !nextcode) error = 83; /*alloc fail*/ if(!error) { for(n = 0; n != tree->maxbitlen + 1; n++) blcount[n] = nextcode[n] = 0; /*step 1: count number of instances of each code length*/ for(bits = 0; bits != tree->numcodes; ++bits) ++blcount[tree->lengths[bits]]; /*step 2: generate the nextcode values*/ for(bits = 1; bits <= tree->maxbitlen; ++bits) { nextcode[bits] = (nextcode[bits - 1] + blcount[bits - 1]) << 1u; } /*step 3: generate all the codes*/ for(n = 0; n != tree->numcodes; ++n) { if(tree->lengths[n] != 0) { tree->codes[n] = nextcode[tree->lengths[n]]++; /*remove superfluous bits from the code*/ tree->codes[n] &= ((1u << tree->lengths[n]) - 1u); } } } lodepng_free(blcount); lodepng_free(nextcode); if(!error) error = HuffmanTree_makeTable(tree); return error; } /* given the code lengths (as stored in the PNG file), generate the tree as defined by Deflate. maxbitlen is the maximum bits that a code in the tree can have. return value is error. */ static unsigned HuffmanTree_makeFromLengths(HuffmanTree* tree, const unsigned* bitlen, size_t numcodes, unsigned maxbitlen) { unsigned i; tree->lengths = (unsigned*)lodepng_malloc(numcodes * sizeof(unsigned)); if(!tree->lengths) return 83; /*alloc fail*/ for(i = 0; i != numcodes; ++i) tree->lengths[i] = bitlen[i]; tree->numcodes = (unsigned)numcodes; /*number of symbols*/ tree->maxbitlen = maxbitlen; return HuffmanTree_makeFromLengths2(tree); } #ifdef LODEPNG_COMPILE_ENCODER /*BPM: Boundary Package Merge, see "A Fast and Space-Economical Algorithm for Length-Limited Coding", Jyrki Katajainen, Alistair Moffat, Andrew Turpin, 1995.*/ /*chain node for boundary package merge*/ typedef struct BPMNode { int weight; /*the sum of all weights in this chain*/ unsigned index; /*index of this leaf node (called "count" in the paper)*/ struct BPMNode* tail; /*the next nodes in this chain (null if last)*/ int in_use; } BPMNode; /*lists of chains*/ typedef struct BPMLists { /*memory pool*/ unsigned memsize; BPMNode* memory; unsigned numfree; unsigned nextfree; BPMNode** freelist; /*two heads of lookahead chains per list*/ unsigned listsize; BPMNode** chains0; BPMNode** chains1; } BPMLists; /*creates a new chain node with the given parameters, from the memory in the lists */ static BPMNode* bpmnode_create(BPMLists* lists, int weight, unsigned index, BPMNode* tail) { unsigned i; BPMNode* result; /*memory full, so garbage collect*/ if(lists->nextfree >= lists->numfree) { /*mark only those that are in use*/ for(i = 0; i != lists->memsize; ++i) lists->memory[i].in_use = 0; for(i = 0; i != lists->listsize; ++i) { BPMNode* node; for(node = lists->chains0[i]; node != 0; node = node->tail) node->in_use = 1; for(node = lists->chains1[i]; node != 0; node = node->tail) node->in_use = 1; } /*collect those that are free*/ lists->numfree = 0; for(i = 0; i != lists->memsize; ++i) { if(!lists->memory[i].in_use) lists->freelist[lists->numfree++] = &lists->memory[i]; } lists->nextfree = 0; } result = lists->freelist[lists->nextfree++]; result->weight = weight; result->index = index; result->tail = tail; return result; } /*sort the leaves with stable mergesort*/ static void bpmnode_sort(BPMNode* leaves, size_t num) { BPMNode* mem = (BPMNode*)lodepng_malloc(sizeof(*leaves) * num); size_t width, counter = 0; for(width = 1; width < num; width *= 2) { BPMNode* a = (counter & 1) ? mem : leaves; BPMNode* b = (counter & 1) ? leaves : mem; size_t p; for(p = 0; p < num; p += 2 * width) { size_t q = (p + width > num) ? num : (p + width); size_t r = (p + 2 * width > num) ? num : (p + 2 * width); size_t i = p, j = q, k; for(k = p; k < r; k++) { if(i < q && (j >= r || a[i].weight <= a[j].weight)) b[k] = a[i++]; else b[k] = a[j++]; } } counter++; } if(counter & 1) lodepng_memcpy(leaves, mem, sizeof(*leaves) * num); lodepng_free(mem); } /*Boundary Package Merge step, numpresent is the amount of leaves, and c is the current chain.*/ static void boundaryPM(BPMLists* lists, BPMNode* leaves, size_t numpresent, int c, int num) { unsigned lastindex = lists->chains1[c]->index; if(c == 0) { if(lastindex >= numpresent) return; lists->chains0[c] = lists->chains1[c]; lists->chains1[c] = bpmnode_create(lists, leaves[lastindex].weight, lastindex + 1, 0); } else { /*sum of the weights of the head nodes of the previous lookahead chains.*/ int sum = lists->chains0[c - 1]->weight + lists->chains1[c - 1]->weight; lists->chains0[c] = lists->chains1[c]; if(lastindex < numpresent && sum > leaves[lastindex].weight) { lists->chains1[c] = bpmnode_create(lists, leaves[lastindex].weight, lastindex + 1, lists->chains1[c]->tail); return; } lists->chains1[c] = bpmnode_create(lists, sum, lastindex, lists->chains1[c - 1]); /*in the end we are only interested in the chain of the last list, so no need to recurse if we're at the last one (this gives measurable speedup)*/ if(num + 1 < (int)(2 * numpresent - 2)) { boundaryPM(lists, leaves, numpresent, c - 1, num); boundaryPM(lists, leaves, numpresent, c - 1, num); } } } unsigned lodepng_huffman_code_lengths(unsigned* lengths, const unsigned* frequencies, size_t numcodes, unsigned maxbitlen) { unsigned error = 0; unsigned i; size_t numpresent = 0; /*number of symbols with non-zero frequency*/ BPMNode* leaves; /*the symbols, only those with > 0 frequency*/ if(numcodes == 0) return 80; /*error: a tree of 0 symbols is not supposed to be made*/ if((1u << maxbitlen) < (unsigned)numcodes) return 80; /*error: represent all symbols*/ leaves = (BPMNode*)lodepng_malloc(numcodes * sizeof(*leaves)); if(!leaves) return 83; /*alloc fail*/ for(i = 0; i != numcodes; ++i) { if(frequencies[i] > 0) { leaves[numpresent].weight = (int)frequencies[i]; leaves[numpresent].index = i; ++numpresent; } } lodepng_memset(lengths, 0, numcodes * sizeof(*lengths)); /*ensure at least two present symbols. There should be at least one symbol according to RFC 1951 section 3.2.7. Some decoders incorrectly require two. To make these work as well ensure there are at least two symbols. The Package-Merge code below also doesn't work correctly if there's only one symbol, it'd give it the theoretical 0 bits but in practice zlib wants 1 bit*/ if(numpresent == 0) { lengths[0] = lengths[1] = 1; /*note that for RFC 1951 section 3.2.7, only lengths[0] = 1 is needed*/ } else if(numpresent == 1) { lengths[leaves[0].index] = 1; lengths[leaves[0].index == 0 ? 1 : 0] = 1; } else { BPMLists lists; BPMNode* node; bpmnode_sort(leaves, numpresent); lists.listsize = maxbitlen; lists.memsize = 2 * maxbitlen * (maxbitlen + 1); lists.nextfree = 0; lists.numfree = lists.memsize; lists.memory = (BPMNode*)lodepng_malloc(lists.memsize * sizeof(*lists.memory)); lists.freelist = (BPMNode**)lodepng_malloc(lists.memsize * sizeof(BPMNode*)); lists.chains0 = (BPMNode**)lodepng_malloc(lists.listsize * sizeof(BPMNode*)); lists.chains1 = (BPMNode**)lodepng_malloc(lists.listsize * sizeof(BPMNode*)); if(!lists.memory || !lists.freelist || !lists.chains0 || !lists.chains1) error = 83; /*alloc fail*/ if(!error) { for(i = 0; i != lists.memsize; ++i) lists.freelist[i] = &lists.memory[i]; bpmnode_create(&lists, leaves[0].weight, 1, 0); bpmnode_create(&lists, leaves[1].weight, 2, 0); for(i = 0; i != lists.listsize; ++i) { lists.chains0[i] = &lists.memory[0]; lists.chains1[i] = &lists.memory[1]; } /*each boundaryPM call adds one chain to the last list, and we need 2 * numpresent - 2 chains.*/ for(i = 2; i != 2 * numpresent - 2; ++i) boundaryPM(&lists, leaves, numpresent, (int)maxbitlen - 1, (int)i); for(node = lists.chains1[maxbitlen - 1]; node; node = node->tail) { for(i = 0; i != node->index; ++i) ++lengths[leaves[i].index]; } } lodepng_free(lists.memory); lodepng_free(lists.freelist); lodepng_free(lists.chains0); lodepng_free(lists.chains1); } lodepng_free(leaves); return error; } /*Create the Huffman tree given the symbol frequencies*/ static unsigned HuffmanTree_makeFromFrequencies(HuffmanTree* tree, const unsigned* frequencies, size_t mincodes, size_t numcodes, unsigned maxbitlen) { unsigned error = 0; while(!frequencies[numcodes - 1] && numcodes > mincodes) --numcodes; /*trim zeroes*/ tree->lengths = (unsigned*)lodepng_malloc(numcodes * sizeof(unsigned)); if(!tree->lengths) return 83; /*alloc fail*/ tree->maxbitlen = maxbitlen; tree->numcodes = (unsigned)numcodes; /*number of symbols*/ error = lodepng_huffman_code_lengths(tree->lengths, frequencies, numcodes, maxbitlen); if(!error) error = HuffmanTree_makeFromLengths2(tree); return error; } #endif /*LODEPNG_COMPILE_ENCODER*/ /*get the literal and length code tree of a deflated block with fixed tree, as per the deflate specification*/ static unsigned generateFixedLitLenTree(HuffmanTree* tree) { unsigned i, error = 0; unsigned* bitlen = (unsigned*)lodepng_malloc(NUM_DEFLATE_CODE_SYMBOLS * sizeof(unsigned)); if(!bitlen) return 83; /*alloc fail*/ /*288 possible codes: 0-255=literals, 256=endcode, 257-285=lengthcodes, 286-287=unused*/ for(i = 0; i <= 143; ++i) bitlen[i] = 8; for(i = 144; i <= 255; ++i) bitlen[i] = 9; for(i = 256; i <= 279; ++i) bitlen[i] = 7; for(i = 280; i <= 287; ++i) bitlen[i] = 8; error = HuffmanTree_makeFromLengths(tree, bitlen, NUM_DEFLATE_CODE_SYMBOLS, 15); lodepng_free(bitlen); return error; } /*get the distance code tree of a deflated block with fixed tree, as specified in the deflate specification*/ static unsigned generateFixedDistanceTree(HuffmanTree* tree) { unsigned i, error = 0; unsigned* bitlen = (unsigned*)lodepng_malloc(NUM_DISTANCE_SYMBOLS * sizeof(unsigned)); if(!bitlen) return 83; /*alloc fail*/ /*there are 32 distance codes, but 30-31 are unused*/ for(i = 0; i != NUM_DISTANCE_SYMBOLS; ++i) bitlen[i] = 5; error = HuffmanTree_makeFromLengths(tree, bitlen, NUM_DISTANCE_SYMBOLS, 15); lodepng_free(bitlen); return error; } #ifdef LODEPNG_COMPILE_DECODER /* returns the code. The bit reader must already have been ensured at least 15 bits */ static unsigned huffmanDecodeSymbol(LodePNGBitReader* reader, const HuffmanTree* codetree) { unsigned short code = peekBits(reader, FIRSTBITS); unsigned short l = codetree->table_len[code]; unsigned short value = codetree->table_value[code]; if(l <= FIRSTBITS) { advanceBits(reader, l); return value; } else { advanceBits(reader, FIRSTBITS); value += peekBits(reader, l - FIRSTBITS); advanceBits(reader, codetree->table_len[value] - FIRSTBITS); return codetree->table_value[value]; } } #endif /*LODEPNG_COMPILE_DECODER*/ #ifdef LODEPNG_COMPILE_DECODER /* ////////////////////////////////////////////////////////////////////////// */ /* / Inflator (Decompressor) / */ /* ////////////////////////////////////////////////////////////////////////// */ /*get the tree of a deflated block with fixed tree, as specified in the deflate specification Returns error code.*/ static unsigned getTreeInflateFixed(HuffmanTree* tree_ll, HuffmanTree* tree_d) { unsigned error = generateFixedLitLenTree(tree_ll); if(error) return error; return generateFixedDistanceTree(tree_d); } /*get the tree of a deflated block with dynamic tree, the tree itself is also Huffman compressed with a known tree*/ static unsigned getTreeInflateDynamic(HuffmanTree* tree_ll, HuffmanTree* tree_d, LodePNGBitReader* reader) { /*make sure that length values that aren't filled in will be 0, or a wrong tree will be generated*/ unsigned error = 0; unsigned n, HLIT, HDIST, HCLEN, i; /*see comments in deflateDynamic for explanation of the context and these variables, it is analogous*/ unsigned* bitlen_ll = 0; /*lit,len code lengths*/ unsigned* bitlen_d = 0; /*dist code lengths*/ /*code length code lengths ("clcl"), the bit lengths of the huffman tree used to compress bitlen_ll and bitlen_d*/ unsigned* bitlen_cl = 0; HuffmanTree tree_cl; /*the code tree for code length codes (the huffman tree for compressed huffman trees)*/ if(reader->bitsize - reader->bp < 14) return 49; /*error: the bit pointer is or will go past the memory*/ ensureBits17(reader, 14); /*number of literal/length codes + 257. Unlike the spec, the value 257 is added to it here already*/ HLIT = readBits(reader, 5) + 257; /*number of distance codes. Unlike the spec, the value 1 is added to it here already*/ HDIST = readBits(reader, 5) + 1; /*number of code length codes. Unlike the spec, the value 4 is added to it here already*/ HCLEN = readBits(reader, 4) + 4; bitlen_cl = (unsigned*)lodepng_malloc(NUM_CODE_LENGTH_CODES * sizeof(unsigned)); if(!bitlen_cl) return 83 /*alloc fail*/; HuffmanTree_init(&tree_cl); while(!error) { /*read the code length codes out of 3 * (amount of code length codes) bits*/ if(lodepng_gtofl(reader->bp, HCLEN * 3, reader->bitsize)) { ERROR_BREAK(50); /*error: the bit pointer is or will go past the memory*/ } for(i = 0; i != HCLEN; ++i) { ensureBits9(reader, 3); /*out of bounds already checked above */ bitlen_cl[CLCL_ORDER[i]] = readBits(reader, 3); } for(i = HCLEN; i != NUM_CODE_LENGTH_CODES; ++i) { bitlen_cl[CLCL_ORDER[i]] = 0; } error = HuffmanTree_makeFromLengths(&tree_cl, bitlen_cl, NUM_CODE_LENGTH_CODES, 7); if(error) break; /*now we can use this tree to read the lengths for the tree that this function will return*/ bitlen_ll = (unsigned*)lodepng_malloc(NUM_DEFLATE_CODE_SYMBOLS * sizeof(unsigned)); bitlen_d = (unsigned*)lodepng_malloc(NUM_DISTANCE_SYMBOLS * sizeof(unsigned)); if(!bitlen_ll || !bitlen_d) ERROR_BREAK(83 /*alloc fail*/); lodepng_memset(bitlen_ll, 0, NUM_DEFLATE_CODE_SYMBOLS * sizeof(*bitlen_ll)); lodepng_memset(bitlen_d, 0, NUM_DISTANCE_SYMBOLS * sizeof(*bitlen_d)); /*i is the current symbol we're reading in the part that contains the code lengths of lit/len and dist codes*/ i = 0; while(i < HLIT + HDIST) { unsigned code; ensureBits25(reader, 22); /* up to 15 bits for huffman code, up to 7 extra bits below*/ code = huffmanDecodeSymbol(reader, &tree_cl); if(code <= 15) /*a length code*/ { if(i < HLIT) bitlen_ll[i] = code; else bitlen_d[i - HLIT] = code; ++i; } else if(code == 16) /*repeat previous*/ { unsigned replength = 3; /*read in the 2 bits that indicate repeat length (3-6)*/ unsigned value; /*set value to the previous code*/ if(i == 0) ERROR_BREAK(54); /*can't repeat previous if i is 0*/ replength += readBits(reader, 2); if(i < HLIT + 1) value = bitlen_ll[i - 1]; else value = bitlen_d[i - HLIT - 1]; /*repeat this value in the next lengths*/ for(n = 0; n < replength; ++n) { if(i >= HLIT + HDIST) ERROR_BREAK(13); /*error: i is larger than the amount of codes*/ if(i < HLIT) bitlen_ll[i] = value; else bitlen_d[i - HLIT] = value; ++i; } } else if(code == 17) /*repeat "0" 3-10 times*/ { unsigned replength = 3; /*read in the bits that indicate repeat length*/ replength += readBits(reader, 3); /*repeat this value in the next lengths*/ for(n = 0; n < replength; ++n) { if(i >= HLIT + HDIST) ERROR_BREAK(14); /*error: i is larger than the amount of codes*/ if(i < HLIT) bitlen_ll[i] = 0; else bitlen_d[i - HLIT] = 0; ++i; } } else if(code == 18) /*repeat "0" 11-138 times*/ { unsigned replength = 11; /*read in the bits that indicate repeat length*/ replength += readBits(reader, 7); /*repeat this value in the next lengths*/ for(n = 0; n < replength; ++n) { if(i >= HLIT + HDIST) ERROR_BREAK(15); /*error: i is larger than the amount of codes*/ if(i < HLIT) bitlen_ll[i] = 0; else bitlen_d[i - HLIT] = 0; ++i; } } else /*if(code == INVALIDSYMBOL)*/ { ERROR_BREAK(16); /*error: tried to read disallowed huffman symbol*/ } /*check if any of the ensureBits above went out of bounds*/ if(reader->bp > reader->bitsize) { /*return error code 10 or 11 depending on the situation that happened in huffmanDecodeSymbol (10=no endcode, 11=wrong jump outside of tree)*/ /* TODO: revise error codes 10,11,50: the above comment is no longer valid */ ERROR_BREAK(50); /*error, bit pointer jumps past memory*/ } } if(error) break; if(bitlen_ll[256] == 0) ERROR_BREAK(64); /*the length of the end code 256 must be larger than 0*/ /*now we've finally got HLIT and HDIST, so generate the code trees, and the function is done*/ error = HuffmanTree_makeFromLengths(tree_ll, bitlen_ll, NUM_DEFLATE_CODE_SYMBOLS, 15); if(error) break; error = HuffmanTree_makeFromLengths(tree_d, bitlen_d, NUM_DISTANCE_SYMBOLS, 15); break; /*end of error-while*/ } lodepng_free(bitlen_cl); lodepng_free(bitlen_ll); lodepng_free(bitlen_d); HuffmanTree_cleanup(&tree_cl); return error; } /*inflate a block with dynamic of fixed Huffman tree. btype must be 1 or 2.*/ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader, unsigned btype, size_t max_output_size) { unsigned error = 0; HuffmanTree tree_ll; /*the huffman tree for literal and length codes*/ HuffmanTree tree_d; /*the huffman tree for distance codes*/ const size_t reserved_size = 260; /* must be at least 258 for max length, and a few extra for adding a few extra literals */ int done = 0; if(!ucvector_reserve(out, out->size + reserved_size)) return 83; /*alloc fail*/ HuffmanTree_init(&tree_ll); HuffmanTree_init(&tree_d); if(btype == 1) error = getTreeInflateFixed(&tree_ll, &tree_d); else /*if(btype == 2)*/ error = getTreeInflateDynamic(&tree_ll, &tree_d, reader); while(!error && !done) /*decode all symbols until end reached, breaks at end code*/ { /*code_ll is literal, length or end code*/ unsigned code_ll; /* ensure enough bits for 2 huffman code reads (15 bits each): if the first is a literal, a second literal is read at once. This appears to be slightly faster, than ensuring 20 bits here for 1 huffman symbol and the potential 5 extra bits for the length symbol.*/ ensureBits32(reader, 30); code_ll = huffmanDecodeSymbol(reader, &tree_ll); if(code_ll <= 255) { /*slightly faster code path if multiple literals in a row*/ out->data[out->size++] = (unsigned char)code_ll; code_ll = huffmanDecodeSymbol(reader, &tree_ll); } if(code_ll <= 255) /*literal symbol*/ { out->data[out->size++] = (unsigned char)code_ll; } else if(code_ll >= FIRST_LENGTH_CODE_INDEX && code_ll <= LAST_LENGTH_CODE_INDEX) /*length code*/ { unsigned code_d, distance; unsigned numextrabits_l, numextrabits_d; /*extra bits for length and distance*/ size_t start, backward, length; /*part 1: get length base*/ length = LENGTHBASE[code_ll - FIRST_LENGTH_CODE_INDEX]; /*part 2: get extra bits and add the value of that to length*/ numextrabits_l = LENGTHEXTRA[code_ll - FIRST_LENGTH_CODE_INDEX]; if(numextrabits_l != 0) { /* bits already ensured above */ ensureBits25(reader, 5); length += readBits(reader, numextrabits_l); } /*part 3: get distance code*/ ensureBits32(reader, 28); /* up to 15 for the huffman symbol, up to 13 for the extra bits */ code_d = huffmanDecodeSymbol(reader, &tree_d); if(code_d > 29) { if(code_d <= 31) { ERROR_BREAK(18); /*error: invalid distance code (30-31 are never used)*/ } else /* if(code_d == INVALIDSYMBOL) */{ ERROR_BREAK(16); /*error: tried to read disallowed huffman symbol*/ } } distance = DISTANCEBASE[code_d]; /*part 4: get extra bits from distance*/ numextrabits_d = DISTANCEEXTRA[code_d]; if(numextrabits_d != 0) { /* bits already ensured above */ distance += readBits(reader, numextrabits_d); } /*part 5: fill in all the out[n] values based on the length and dist*/ start = out->size; if(distance > start) ERROR_BREAK(52); /*too long backward distance*/ backward = start - distance; out->size += length; if(distance < length) { size_t forward; lodepng_memcpy(out->data + start, out->data + backward, distance); start += distance; for(forward = distance; forward < length; ++forward) { out->data[start++] = out->data[backward++]; } } else { lodepng_memcpy(out->data + start, out->data + backward, length); } } else if(code_ll == 256) { done = 1; /*end code, finish the loop*/ } else /*if(code_ll == INVALIDSYMBOL)*/ { ERROR_BREAK(16); /*error: tried to read disallowed huffman symbol*/ } if(out->allocsize - out->size < reserved_size) { if(!ucvector_reserve(out, out->size + reserved_size)) ERROR_BREAK(83); /*alloc fail*/ } /*check if any of the ensureBits above went out of bounds*/ if(reader->bp > reader->bitsize) { /*return error code 10 or 11 depending on the situation that happened in huffmanDecodeSymbol (10=no endcode, 11=wrong jump outside of tree)*/ /* TODO: revise error codes 10,11,50: the above comment is no longer valid */ ERROR_BREAK(51); /*error, bit pointer jumps past memory*/ } if(max_output_size && out->size > max_output_size) { ERROR_BREAK(109); /*error, larger than max size*/ } } HuffmanTree_cleanup(&tree_ll); HuffmanTree_cleanup(&tree_d); return error; } static unsigned inflateNoCompression(ucvector* out, LodePNGBitReader* reader, const LodePNGDecompressSettings* settings) { size_t bytepos; size_t size = reader->size; unsigned LEN, NLEN, error = 0; /*go to first boundary of byte*/ bytepos = (reader->bp + 7u) >> 3u; /*read LEN (2 bytes) and NLEN (2 bytes)*/ if(bytepos + 4 >= size) return 52; /*error, bit pointer will jump past memory*/ LEN = (unsigned)reader->data[bytepos] + ((unsigned)reader->data[bytepos + 1] << 8u); bytepos += 2; NLEN = (unsigned)reader->data[bytepos] + ((unsigned)reader->data[bytepos + 1] << 8u); bytepos += 2; /*check if 16-bit NLEN is really the one's complement of LEN*/ if(!settings->ignore_nlen && LEN + NLEN != 65535) { return 21; /*error: NLEN is not one's complement of LEN*/ } if(!ucvector_resize(out, out->size + LEN)) return 83; /*alloc fail*/ /*read the literal data: LEN bytes are now stored in the out buffer*/ if(bytepos + LEN > size) return 23; /*error: reading outside of in buffer*/ /*out->data can be NULL (when LEN is zero), and arithmetics on NULL ptr is undefined*/ if (LEN) { lodepng_memcpy(out->data + out->size - LEN, reader->data + bytepos, LEN); bytepos += LEN; } reader->bp = bytepos << 3u; return error; } static unsigned lodepng_inflatev(ucvector* out, const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) { unsigned BFINAL = 0; LodePNGBitReader reader; unsigned error = LodePNGBitReader_init(&reader, in, insize); if(error) return error; while(!BFINAL) { unsigned BTYPE; if(reader.bitsize - reader.bp < 3) return 52; /*error, bit pointer will jump past memory*/ ensureBits9(&reader, 3); BFINAL = readBits(&reader, 1); BTYPE = readBits(&reader, 2); if(BTYPE == 3) return 20; /*error: invalid BTYPE*/ else if(BTYPE == 0) error = inflateNoCompression(out, &reader, settings); /*no compression*/ else error = inflateHuffmanBlock(out, &reader, BTYPE, settings->max_output_size); /*compression, BTYPE 01 or 10*/ if(!error && settings->max_output_size && out->size > settings->max_output_size) error = 109; if(error) break; } return error; } unsigned lodepng_inflate(unsigned char** out, size_t* outsize, const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) { ucvector v = ucvector_init(*out, *outsize); unsigned error = lodepng_inflatev(&v, in, insize, settings); *out = v.data; *outsize = v.size; return error; } static unsigned inflatev(ucvector* out, const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) { if(settings->custom_inflate) { unsigned error = settings->custom_inflate(&out->data, &out->size, in, insize, settings); out->allocsize = out->size; if(error) { /*the custom inflate is allowed to have its own error codes, however, we translate it to code 110*/ error = 110; /*if there's a max output size, and the custom zlib returned error, then indicate that error instead*/ if(settings->max_output_size && out->size > settings->max_output_size) error = 109; } return error; } else { return lodepng_inflatev(out, in, insize, settings); } } #endif /*LODEPNG_COMPILE_DECODER*/ #ifdef LODEPNG_COMPILE_ENCODER /* ////////////////////////////////////////////////////////////////////////// */ /* / Deflator (Compressor) / */ /* ////////////////////////////////////////////////////////////////////////// */ static const size_t MAX_SUPPORTED_DEFLATE_LENGTH = 258; /*search the index in the array, that has the largest value smaller than or equal to the given value, given array must be sorted (if no value is smaller, it returns the size of the given array)*/ static size_t searchCodeIndex(const unsigned* array, size_t array_size, size_t value) { /*binary search (only small gain over linear). TODO: use CPU log2 instruction for getting symbols instead*/ size_t left = 1; size_t right = array_size - 1; while(left <= right) { size_t mid = (left + right) >> 1; if(array[mid] >= value) right = mid - 1; else left = mid + 1; } if(left >= array_size || array[left] > value) left--; return left; } static void addLengthDistance(uivector* values, size_t length, size_t distance) { /*values in encoded vector are those used by deflate: 0-255: literal bytes 256: end 257-285: length/distance pair (length code, followed by extra length bits, distance code, extra distance bits) 286-287: invalid*/ unsigned length_code = (unsigned)searchCodeIndex(LENGTHBASE, 29, length); unsigned extra_length = (unsigned)(length - LENGTHBASE[length_code]); unsigned dist_code = (unsigned)searchCodeIndex(DISTANCEBASE, 30, distance); unsigned extra_distance = (unsigned)(distance - DISTANCEBASE[dist_code]); size_t pos = values->size; /*TODO: return error when this fails (out of memory)*/ unsigned ok = uivector_resize(values, values->size + 4); if(ok) { values->data[pos + 0] = length_code + FIRST_LENGTH_CODE_INDEX; values->data[pos + 1] = extra_length; values->data[pos + 2] = dist_code; values->data[pos + 3] = extra_distance; } } /*3 bytes of data get encoded into two bytes. The hash cannot use more than 3 bytes as input because 3 is the minimum match length for deflate*/ static const unsigned HASH_NUM_VALUES = 65536; static const unsigned HASH_BIT_MASK = 65535; /*HASH_NUM_VALUES - 1, but C90 does not like that as initializer*/ typedef struct Hash { int* head; /*hash value to head circular pos - can be outdated if went around window*/ /*circular pos to prev circular pos*/ unsigned short* chain; int* val; /*circular pos to hash value*/ /*TODO: do this not only for zeros but for any repeated byte. However for PNG it's always going to be the zeros that dominate, so not important for PNG*/ int* headz; /*similar to head, but for chainz*/ unsigned short* chainz; /*those with same amount of zeros*/ unsigned short* zeros; /*length of zeros streak, used as a second hash chain*/ } Hash; static unsigned hash_init(Hash* hash, unsigned windowsize) { unsigned i; hash->head = (int*)lodepng_malloc(sizeof(int) * HASH_NUM_VALUES); hash->val = (int*)lodepng_malloc(sizeof(int) * windowsize); hash->chain = (unsigned short*)lodepng_malloc(sizeof(unsigned short) * windowsize); hash->zeros = (unsigned short*)lodepng_malloc(sizeof(unsigned short) * windowsize); hash->headz = (int*)lodepng_malloc(sizeof(int) * (MAX_SUPPORTED_DEFLATE_LENGTH + 1)); hash->chainz = (unsigned short*)lodepng_malloc(sizeof(unsigned short) * windowsize); if(!hash->head || !hash->chain || !hash->val || !hash->headz|| !hash->chainz || !hash->zeros) { return 83; /*alloc fail*/ } /*initialize hash table*/ for(i = 0; i != HASH_NUM_VALUES; ++i) hash->head[i] = -1; for(i = 0; i != windowsize; ++i) hash->val[i] = -1; for(i = 0; i != windowsize; ++i) hash->chain[i] = i; /*same value as index indicates uninitialized*/ for(i = 0; i <= MAX_SUPPORTED_DEFLATE_LENGTH; ++i) hash->headz[i] = -1; for(i = 0; i != windowsize; ++i) hash->chainz[i] = i; /*same value as index indicates uninitialized*/ return 0; } static void hash_cleanup(Hash* hash) { lodepng_free(hash->head); lodepng_free(hash->val); lodepng_free(hash->chain); lodepng_free(hash->zeros); lodepng_free(hash->headz); lodepng_free(hash->chainz); } static unsigned getHash(const unsigned char* data, size_t size, size_t pos) { unsigned result = 0; if(pos + 2 < size) { /*A simple shift and xor hash is used. Since the data of PNGs is dominated by zeroes due to the filters, a better hash does not have a significant effect on speed in traversing the chain, and causes more time spend on calculating the hash.*/ result ^= ((unsigned)data[pos + 0] << 0u); result ^= ((unsigned)data[pos + 1] << 4u); result ^= ((unsigned)data[pos + 2] << 8u); } else { size_t amount, i; if(pos >= size) return 0; amount = size - pos; for(i = 0; i != amount; ++i) result ^= ((unsigned)data[pos + i] << (i * 8u)); } return result & HASH_BIT_MASK; } static unsigned countZeros(const unsigned char* data, size_t size, size_t pos) { const unsigned char* start = data + pos; const unsigned char* end = start + MAX_SUPPORTED_DEFLATE_LENGTH; if(end > data + size) end = data + size; data = start; while(data != end && *data == 0) ++data; /*subtracting two addresses returned as 32-bit number (max value is MAX_SUPPORTED_DEFLATE_LENGTH)*/ return (unsigned)(data - start); } /*wpos = pos & (windowsize - 1)*/ static void updateHashChain(Hash* hash, size_t wpos, unsigned hashval, unsigned short numzeros) { hash->val[wpos] = (int)hashval; if(hash->head[hashval] != -1) hash->chain[wpos] = hash->head[hashval]; hash->head[hashval] = (int)wpos; hash->zeros[wpos] = numzeros; if(hash->headz[numzeros] != -1) hash->chainz[wpos] = hash->headz[numzeros]; hash->headz[numzeros] = (int)wpos; } /* LZ77-encode the data. Return value is error code. The input are raw bytes, the output is in the form of unsigned integers with codes representing for example literal bytes, or length/distance pairs. It uses a hash table technique to let it encode faster. When doing LZ77 encoding, a sliding window (of windowsize) is used, and all past bytes in that window can be used as the "dictionary". A brute force search through all possible distances would be slow, and this hash technique is one out of several ways to speed this up. */ static unsigned encodeLZ77(uivector* out, Hash* hash, const unsigned char* in, size_t inpos, size_t insize, unsigned windowsize, unsigned minmatch, unsigned nicematch, unsigned lazymatching) { size_t pos; unsigned i, error = 0; /*for large window lengths, assume the user wants no compression loss. Otherwise, max hash chain length speedup.*/ unsigned maxchainlength = windowsize >= 8192 ? windowsize : windowsize / 8u; unsigned maxlazymatch = windowsize >= 8192 ? MAX_SUPPORTED_DEFLATE_LENGTH : 64; unsigned usezeros = 1; /*not sure if setting it to false for windowsize < 8192 is better or worse*/ unsigned numzeros = 0; unsigned offset; /*the offset represents the distance in LZ77 terminology*/ unsigned length; unsigned lazy = 0; unsigned lazylength = 0, lazyoffset = 0; unsigned hashval; unsigned current_offset, current_length; unsigned prev_offset; const unsigned char *lastptr, *foreptr, *backptr; unsigned hashpos; if(windowsize == 0 || windowsize > 32768) return 60; /*error: windowsize smaller/larger than allowed*/ if((windowsize & (windowsize - 1)) != 0) return 90; /*error: must be power of two*/ if(nicematch > MAX_SUPPORTED_DEFLATE_LENGTH) nicematch = MAX_SUPPORTED_DEFLATE_LENGTH; for(pos = inpos; pos < insize; ++pos) { size_t wpos = pos & (windowsize - 1); /*position for in 'circular' hash buffers*/ unsigned chainlength = 0; hashval = getHash(in, insize, pos); if(usezeros && hashval == 0) { if(numzeros == 0) numzeros = countZeros(in, insize, pos); else if(pos + numzeros > insize || in[pos + numzeros - 1] != 0) --numzeros; } else { numzeros = 0; } updateHashChain(hash, wpos, hashval, numzeros); /*the length and offset found for the current position*/ length = 0; offset = 0; hashpos = hash->chain[wpos]; lastptr = &in[insize < pos + MAX_SUPPORTED_DEFLATE_LENGTH ? insize : pos + MAX_SUPPORTED_DEFLATE_LENGTH]; /*search for the longest string*/ prev_offset = 0; for(;;) { if(chainlength++ >= maxchainlength) break; current_offset = (unsigned)(hashpos <= wpos ? wpos - hashpos : wpos - hashpos + windowsize); if(current_offset < prev_offset) break; /*stop when went completely around the circular buffer*/ prev_offset = current_offset; if(current_offset > 0) { /*test the next characters*/ foreptr = &in[pos]; backptr = &in[pos - current_offset]; /*common case in PNGs is lots of zeros. Quickly skip over them as a speedup*/ if(numzeros >= 3) { unsigned skip = hash->zeros[hashpos]; if(skip > numzeros) skip = numzeros; backptr += skip; foreptr += skip; } while(foreptr != lastptr && *backptr == *foreptr) /*maximum supported length by deflate is max length*/ { ++backptr; ++foreptr; } current_length = (unsigned)(foreptr - &in[pos]); if(current_length > length) { length = current_length; /*the longest length*/ offset = current_offset; /*the offset that is related to this longest length*/ /*jump out once a length of max length is found (speed gain). This also jumps out if length is MAX_SUPPORTED_DEFLATE_LENGTH*/ if(current_length >= nicematch) break; } } if(hashpos == hash->chain[hashpos]) break; if(numzeros >= 3 && length > numzeros) { hashpos = hash->chainz[hashpos]; if(hash->zeros[hashpos] != numzeros) break; } else { hashpos = hash->chain[hashpos]; /*outdated hash value, happens if particular value was not encountered in whole last window*/ if(hash->val[hashpos] != (int)hashval) break; } } if(lazymatching) { if(!lazy && length >= 3 && length <= maxlazymatch && length < MAX_SUPPORTED_DEFLATE_LENGTH) { lazy = 1; lazylength = length; lazyoffset = offset; continue; /*try the next byte*/ } if(lazy) { lazy = 0; if(pos == 0) ERROR_BREAK(81); if(length > lazylength + 1) { /*push the previous character as literal*/ if(!uivector_push_back(out, in[pos - 1])) ERROR_BREAK(83 /*alloc fail*/); } else { length = lazylength; offset = lazyoffset; hash->head[hashval] = -1; /*the same hashchain update will be done, this ensures no wrong alteration*/ hash->headz[numzeros] = -1; /*idem*/ --pos; } } } if(length >= 3 && offset > windowsize) ERROR_BREAK(86 /*too big (or overflown negative) offset*/); /*encode it as length/distance pair or literal value*/ if(length < 3) /*only lengths of 3 or higher are supported as length/distance pair*/ { if(!uivector_push_back(out, in[pos])) ERROR_BREAK(83 /*alloc fail*/); } else if(length < minmatch || (length == 3 && offset > 4096)) { /*compensate for the fact that longer offsets have more extra bits, a length of only 3 may be not worth it then*/ if(!uivector_push_back(out, in[pos])) ERROR_BREAK(83 /*alloc fail*/); } else { addLengthDistance(out, length, offset); for(i = 1; i < length; ++i) { ++pos; wpos = pos & (windowsize - 1); hashval = getHash(in, insize, pos); if(usezeros && hashval == 0) { if(numzeros == 0) numzeros = countZeros(in, insize, pos); else if(pos + numzeros > insize || in[pos + numzeros - 1] != 0) --numzeros; } else { numzeros = 0; } updateHashChain(hash, wpos, hashval, numzeros); } } } /*end of the loop through each character of input*/ return error; } /* /////////////////////////////////////////////////////////////////////////// */ static unsigned deflateNoCompression(ucvector* out, const unsigned char* data, size_t datasize) { /*non compressed deflate block data: 1 bit BFINAL,2 bits BTYPE,(5 bits): it jumps to start of next byte, 2 bytes LEN, 2 bytes NLEN, LEN bytes literal DATA*/ size_t i, numdeflateblocks = (datasize + 65534u) / 65535u; unsigned datapos = 0; for(i = 0; i != numdeflateblocks; ++i) { unsigned BFINAL, BTYPE, LEN, NLEN; unsigned char firstbyte; size_t pos = out->size; BFINAL = (i == numdeflateblocks - 1); BTYPE = 0; LEN = 65535; if(datasize - datapos < 65535u) LEN = (unsigned)datasize - datapos; NLEN = 65535 - LEN; if(!ucvector_resize(out, out->size + LEN + 5)) return 83; /*alloc fail*/ firstbyte = (unsigned char)(BFINAL + ((BTYPE & 1u) << 1u) + ((BTYPE & 2u) << 1u)); out->data[pos + 0] = firstbyte; out->data[pos + 1] = (unsigned char)(LEN & 255); out->data[pos + 2] = (unsigned char)(LEN >> 8u); out->data[pos + 3] = (unsigned char)(NLEN & 255); out->data[pos + 4] = (unsigned char)(NLEN >> 8u); lodepng_memcpy(out->data + pos + 5, data + datapos, LEN); datapos += LEN; } return 0; } /* write the lz77-encoded data, which has lit, len and dist codes, to compressed stream using huffman trees. tree_ll: the tree for lit and len codes. tree_d: the tree for distance codes. */ static void writeLZ77data(LodePNGBitWriter* writer, const uivector* lz77_encoded, const HuffmanTree* tree_ll, const HuffmanTree* tree_d) { size_t i = 0; for(i = 0; i != lz77_encoded->size; ++i) { unsigned val = lz77_encoded->data[i]; writeBitsReversed(writer, tree_ll->codes[val], tree_ll->lengths[val]); if(val > 256) /*for a length code, 3 more things have to be added*/ { unsigned length_index = val - FIRST_LENGTH_CODE_INDEX; unsigned n_length_extra_bits = LENGTHEXTRA[length_index]; unsigned length_extra_bits = lz77_encoded->data[++i]; unsigned distance_code = lz77_encoded->data[++i]; unsigned distance_index = distance_code; unsigned n_distance_extra_bits = DISTANCEEXTRA[distance_index]; unsigned distance_extra_bits = lz77_encoded->data[++i]; writeBits(writer, length_extra_bits, n_length_extra_bits); writeBitsReversed(writer, tree_d->codes[distance_code], tree_d->lengths[distance_code]); writeBits(writer, distance_extra_bits, n_distance_extra_bits); } } } /*Deflate for a block of type "dynamic", that is, with freely, optimally, created huffman trees*/ static unsigned deflateDynamic(LodePNGBitWriter* writer, Hash* hash, const unsigned char* data, size_t datapos, size_t dataend, const LodePNGCompressSettings* settings, unsigned final) { unsigned error = 0; /* A block is compressed as follows: The PNG data is lz77 encoded, resulting in literal bytes and length/distance pairs. This is then huffman compressed with two huffman trees. One huffman tree is used for the lit and len values ("ll"), another huffman tree is used for the dist values ("d"). These two trees are stored using their code lengths, and to compress even more these code lengths are also run-length encoded and huffman compressed. This gives a huffman tree of code lengths "cl". The code lengths used to describe this third tree are the code length code lengths ("clcl"). */ /*The lz77 encoded data, represented with integers since there will also be length and distance codes in it*/ uivector lz77_encoded; HuffmanTree tree_ll; /*tree for lit,len values*/ HuffmanTree tree_d; /*tree for distance codes*/ HuffmanTree tree_cl; /*tree for encoding the code lengths representing tree_ll and tree_d*/ unsigned* frequencies_ll = 0; /*frequency of lit,len codes*/ unsigned* frequencies_d = 0; /*frequency of dist codes*/ unsigned* frequencies_cl = 0; /*frequency of code length codes*/ unsigned* bitlen_lld = 0; /*lit,len,dist code lengths (int bits), literally (without repeat codes).*/ unsigned* bitlen_lld_e = 0; /*bitlen_lld encoded with repeat codes (this is a rudimentary run length compression)*/ size_t datasize = dataend - datapos; /* If we could call "bitlen_cl" the the code length code lengths ("clcl"), that is the bit lengths of codes to represent tree_cl in CLCL_ORDER, then due to the huffman compression of huffman tree representations ("two levels"), there are some analogies: bitlen_lld is to tree_cl what data is to tree_ll and tree_d. bitlen_lld_e is to bitlen_lld what lz77_encoded is to data. bitlen_cl is to bitlen_lld_e what bitlen_lld is to lz77_encoded. */ unsigned BFINAL = final; size_t i; size_t numcodes_ll, numcodes_d, numcodes_lld, numcodes_lld_e, numcodes_cl; unsigned HLIT, HDIST, HCLEN; uivector_init(&lz77_encoded); HuffmanTree_init(&tree_ll); HuffmanTree_init(&tree_d); HuffmanTree_init(&tree_cl); /* could fit on stack, but >1KB is on the larger side so allocate instead */ frequencies_ll = (unsigned*)lodepng_malloc(286 * sizeof(*frequencies_ll)); frequencies_d = (unsigned*)lodepng_malloc(30 * sizeof(*frequencies_d)); frequencies_cl = (unsigned*)lodepng_malloc(NUM_CODE_LENGTH_CODES * sizeof(*frequencies_cl)); if(!frequencies_ll || !frequencies_d || !frequencies_cl) error = 83; /*alloc fail*/ /*This while loop never loops due to a break at the end, it is here to allow breaking out of it to the cleanup phase on error conditions.*/ while(!error) { lodepng_memset(frequencies_ll, 0, 286 * sizeof(*frequencies_ll)); lodepng_memset(frequencies_d, 0, 30 * sizeof(*frequencies_d)); lodepng_memset(frequencies_cl, 0, NUM_CODE_LENGTH_CODES * sizeof(*frequencies_cl)); if(settings->use_lz77) { error = encodeLZ77(&lz77_encoded, hash, data, datapos, dataend, settings->windowsize, settings->minmatch, settings->nicematch, settings->lazymatching); if(error) break; } else { if(!uivector_resize(&lz77_encoded, datasize)) ERROR_BREAK(83 /*alloc fail*/); for(i = datapos; i < dataend; ++i) lz77_encoded.data[i - datapos] = data[i]; /*no LZ77, but still will be Huffman compressed*/ } /*Count the frequencies of lit, len and dist codes*/ for(i = 0; i != lz77_encoded.size; ++i) { unsigned symbol = lz77_encoded.data[i]; ++frequencies_ll[symbol]; if(symbol > 256) { unsigned dist = lz77_encoded.data[i + 2]; ++frequencies_d[dist]; i += 3; } } frequencies_ll[256] = 1; /*there will be exactly 1 end code, at the end of the block*/ /*Make both huffman trees, one for the lit and len codes, one for the dist codes*/ error = HuffmanTree_makeFromFrequencies(&tree_ll, frequencies_ll, 257, 286, 15); if(error) break; /*2, not 1, is chosen for mincodes: some buggy PNG decoders require at least 2 symbols in the dist tree*/ error = HuffmanTree_makeFromFrequencies(&tree_d, frequencies_d, 2, 30, 15); if(error) break; numcodes_ll = LODEPNG_MIN(tree_ll.numcodes, 286); numcodes_d = LODEPNG_MIN(tree_d.numcodes, 30); /*store the code lengths of both generated trees in bitlen_lld*/ numcodes_lld = numcodes_ll + numcodes_d; bitlen_lld = (unsigned*)lodepng_malloc(numcodes_lld * sizeof(*bitlen_lld)); /*numcodes_lld_e never needs more size than bitlen_lld*/ bitlen_lld_e = (unsigned*)lodepng_malloc(numcodes_lld * sizeof(*bitlen_lld_e)); if(!bitlen_lld || !bitlen_lld_e) ERROR_BREAK(83); /*alloc fail*/ numcodes_lld_e = 0; for(i = 0; i != numcodes_ll; ++i) bitlen_lld[i] = tree_ll.lengths[i]; for(i = 0; i != numcodes_d; ++i) bitlen_lld[numcodes_ll + i] = tree_d.lengths[i]; /*run-length compress bitlen_ldd into bitlen_lld_e by using repeat codes 16 (copy length 3-6 times), 17 (3-10 zeroes), 18 (11-138 zeroes)*/ for(i = 0; i != numcodes_lld; ++i) { unsigned j = 0; /*amount of repetitions*/ while(i + j + 1 < numcodes_lld && bitlen_lld[i + j + 1] == bitlen_lld[i]) ++j; if(bitlen_lld[i] == 0 && j >= 2) /*repeat code for zeroes*/ { ++j; /*include the first zero*/ if(j <= 10) /*repeat code 17 supports max 10 zeroes*/ { bitlen_lld_e[numcodes_lld_e++] = 17; bitlen_lld_e[numcodes_lld_e++] = j - 3; } else /*repeat code 18 supports max 138 zeroes*/ { if(j > 138) j = 138; bitlen_lld_e[numcodes_lld_e++] = 18; bitlen_lld_e[numcodes_lld_e++] = j - 11; } i += (j - 1); } else if(j >= 3) /*repeat code for value other than zero*/ { size_t k; unsigned num = j / 6u, rest = j % 6u; bitlen_lld_e[numcodes_lld_e++] = bitlen_lld[i]; for(k = 0; k < num; ++k) { bitlen_lld_e[numcodes_lld_e++] = 16; bitlen_lld_e[numcodes_lld_e++] = 6 - 3; } if(rest >= 3) { bitlen_lld_e[numcodes_lld_e++] = 16; bitlen_lld_e[numcodes_lld_e++] = rest - 3; } else j -= rest; i += j; } else /*too short to benefit from repeat code*/ { bitlen_lld_e[numcodes_lld_e++] = bitlen_lld[i]; } } /*generate tree_cl, the huffmantree of huffmantrees*/ for(i = 0; i != numcodes_lld_e; ++i) { ++frequencies_cl[bitlen_lld_e[i]]; /*after a repeat code come the bits that specify the number of repetitions, those don't need to be in the frequencies_cl calculation*/ if(bitlen_lld_e[i] >= 16) ++i; } error = HuffmanTree_makeFromFrequencies(&tree_cl, frequencies_cl, NUM_CODE_LENGTH_CODES, NUM_CODE_LENGTH_CODES, 7); if(error) break; /*compute amount of code-length-code-lengths to output*/ numcodes_cl = NUM_CODE_LENGTH_CODES; /*trim zeros at the end (using CLCL_ORDER), but minimum size must be 4 (see HCLEN below)*/ while(numcodes_cl > 4u && tree_cl.lengths[CLCL_ORDER[numcodes_cl - 1u]] == 0) { numcodes_cl--; } /* Write everything into the output After the BFINAL and BTYPE, the dynamic block consists out of the following: - 5 bits HLIT, 5 bits HDIST, 4 bits HCLEN - (HCLEN+4)*3 bits code lengths of code length alphabet - HLIT + 257 code lengths of lit/length alphabet (encoded using the code length alphabet, + possible repetition codes 16, 17, 18) - HDIST + 1 code lengths of distance alphabet (encoded using the code length alphabet, + possible repetition codes 16, 17, 18) - compressed data - 256 (end code) */ /*Write block type*/ writeBits(writer, BFINAL, 1); writeBits(writer, 0, 1); /*first bit of BTYPE "dynamic"*/ writeBits(writer, 1, 1); /*second bit of BTYPE "dynamic"*/ /*write the HLIT, HDIST and HCLEN values*/ /*all three sizes take trimmed ending zeroes into account, done either by HuffmanTree_makeFromFrequencies or in the loop for numcodes_cl above, which saves space. */ HLIT = (unsigned)(numcodes_ll - 257); HDIST = (unsigned)(numcodes_d - 1); HCLEN = (unsigned)(numcodes_cl - 4); writeBits(writer, HLIT, 5); writeBits(writer, HDIST, 5); writeBits(writer, HCLEN, 4); /*write the code lengths of the code length alphabet ("bitlen_cl")*/ for(i = 0; i != numcodes_cl; ++i) writeBits(writer, tree_cl.lengths[CLCL_ORDER[i]], 3); /*write the lengths of the lit/len AND the dist alphabet*/ for(i = 0; i != numcodes_lld_e; ++i) { writeBitsReversed(writer, tree_cl.codes[bitlen_lld_e[i]], tree_cl.lengths[bitlen_lld_e[i]]); /*extra bits of repeat codes*/ if(bitlen_lld_e[i] == 16) writeBits(writer, bitlen_lld_e[++i], 2); else if(bitlen_lld_e[i] == 17) writeBits(writer, bitlen_lld_e[++i], 3); else if(bitlen_lld_e[i] == 18) writeBits(writer, bitlen_lld_e[++i], 7); } /*write the compressed data symbols*/ writeLZ77data(writer, &lz77_encoded, &tree_ll, &tree_d); /*error: the length of the end code 256 must be larger than 0*/ if(tree_ll.lengths[256] == 0) ERROR_BREAK(64); /*write the end code*/ writeBitsReversed(writer, tree_ll.codes[256], tree_ll.lengths[256]); break; /*end of error-while*/ } /*cleanup*/ uivector_cleanup(&lz77_encoded); HuffmanTree_cleanup(&tree_ll); HuffmanTree_cleanup(&tree_d); HuffmanTree_cleanup(&tree_cl); lodepng_free(frequencies_ll); lodepng_free(frequencies_d); lodepng_free(frequencies_cl); lodepng_free(bitlen_lld); lodepng_free(bitlen_lld_e); return error; } static unsigned deflateFixed(LodePNGBitWriter* writer, Hash* hash, const unsigned char* data, size_t datapos, size_t dataend, const LodePNGCompressSettings* settings, unsigned final) { HuffmanTree tree_ll; /*tree for literal values and length codes*/ HuffmanTree tree_d; /*tree for distance codes*/ unsigned BFINAL = final; unsigned error = 0; size_t i; HuffmanTree_init(&tree_ll); HuffmanTree_init(&tree_d); error = generateFixedLitLenTree(&tree_ll); if(!error) error = generateFixedDistanceTree(&tree_d); if(!error) { writeBits(writer, BFINAL, 1); writeBits(writer, 1, 1); /*first bit of BTYPE*/ writeBits(writer, 0, 1); /*second bit of BTYPE*/ if(settings->use_lz77) /*LZ77 encoded*/ { uivector lz77_encoded; uivector_init(&lz77_encoded); error = encodeLZ77(&lz77_encoded, hash, data, datapos, dataend, settings->windowsize, settings->minmatch, settings->nicematch, settings->lazymatching); if(!error) writeLZ77data(writer, &lz77_encoded, &tree_ll, &tree_d); uivector_cleanup(&lz77_encoded); } else /*no LZ77, but still will be Huffman compressed*/ { for(i = datapos; i < dataend; ++i) { writeBitsReversed(writer, tree_ll.codes[data[i]], tree_ll.lengths[data[i]]); } } /*add END code*/ if(!error) writeBitsReversed(writer,tree_ll.codes[256], tree_ll.lengths[256]); } /*cleanup*/ HuffmanTree_cleanup(&tree_ll); HuffmanTree_cleanup(&tree_d); return error; } static unsigned lodepng_deflatev(ucvector* out, const unsigned char* in, size_t insize, const LodePNGCompressSettings* settings) { unsigned error = 0; size_t i, blocksize, numdeflateblocks; Hash hash; LodePNGBitWriter writer; LodePNGBitWriter_init(&writer, out); if(settings->btype > 2) return 61; else if(settings->btype == 0) return deflateNoCompression(out, in, insize); else if(settings->btype == 1) blocksize = insize; else /*if(settings->btype == 2)*/ { /*on PNGs, deflate blocks of 65-262k seem to give most dense encoding*/ blocksize = insize / 8u + 8; if(blocksize < 65536) blocksize = 65536; if(blocksize > 262144) blocksize = 262144; } numdeflateblocks = (insize + blocksize - 1) / blocksize; if(numdeflateblocks == 0) numdeflateblocks = 1; error = hash_init(&hash, settings->windowsize); if(!error) { for(i = 0; i != numdeflateblocks && !error; ++i) { unsigned final = (i == numdeflateblocks - 1); size_t start = i * blocksize; size_t end = start + blocksize; if(end > insize) end = insize; if(settings->btype == 1) error = deflateFixed(&writer, &hash, in, start, end, settings, final); else if(settings->btype == 2) error = deflateDynamic(&writer, &hash, in, start, end, settings, final); } } hash_cleanup(&hash); return error; } unsigned lodepng_deflate(unsigned char** out, size_t* outsize, const unsigned char* in, size_t insize, const LodePNGCompressSettings* settings) { ucvector v = ucvector_init(*out, *outsize); unsigned error = lodepng_deflatev(&v, in, insize, settings); *out = v.data; *outsize = v.size; return error; } static unsigned deflate(unsigned char** out, size_t* outsize, const unsigned char* in, size_t insize, const LodePNGCompressSettings* settings) { if(settings->custom_deflate) { unsigned error = settings->custom_deflate(out, outsize, in, insize, settings); /*the custom deflate is allowed to have its own error codes, however, we translate it to code 111*/ return error ? 111 : 0; } else { return lodepng_deflate(out, outsize, in, insize, settings); } } #endif /*LODEPNG_COMPILE_DECODER*/ /* ////////////////////////////////////////////////////////////////////////// */ /* / Adler32 / */ /* ////////////////////////////////////////////////////////////////////////// */ static unsigned update_adler32(unsigned adler, const unsigned char* data, unsigned len) { unsigned s1 = adler & 0xffffu; unsigned s2 = (adler >> 16u) & 0xffffu; while(len != 0u) { unsigned i; /*at least 5552 sums can be done before the sums overflow, saving a lot of module divisions*/ unsigned amount = len > 5552u ? 5552u : len; len -= amount; for(i = 0; i != amount; ++i) { s1 += (*data++); s2 += s1; } s1 %= 65521u; s2 %= 65521u; } return (s2 << 16u) | s1; } /*Return the adler32 of the bytes data[0..len-1]*/ static unsigned adler32(const unsigned char* data, unsigned len) { return update_adler32(1u, data, len); } /* ////////////////////////////////////////////////////////////////////////// */ /* / Zlib / */ /* ////////////////////////////////////////////////////////////////////////// */ #ifdef LODEPNG_COMPILE_DECODER static unsigned lodepng_zlib_decompressv(ucvector* out, const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) { unsigned error = 0; unsigned CM, CINFO, FDICT; if(insize < 2) return 53; /*error, size of zlib data too small*/ /*read information from zlib header*/ if((in[0] * 256 + in[1]) % 31 != 0) { /*error: 256 * in[0] + in[1] must be a multiple of 31, the FCHECK value is supposed to be made that way*/ return 24; } CM = in[0] & 15; CINFO = (in[0] >> 4) & 15; /*FCHECK = in[1] & 31;*/ /*FCHECK is already tested above*/ FDICT = (in[1] >> 5) & 1; /*FLEVEL = (in[1] >> 6) & 3;*/ /*FLEVEL is not used here*/ if(CM != 8 || CINFO > 7) { /*error: only compression method 8: inflate with sliding window of 32k is supported by the PNG spec*/ return 25; } if(FDICT != 0) { /*error: the specification of PNG says about the zlib stream: "The additional flags shall not specify a preset dictionary."*/ return 26; } error = inflatev(out, in + 2, insize - 2, settings); if(error) return error; if(!settings->ignore_adler32) { unsigned ADLER32 = lodepng_read32bitInt(&in[insize - 4]); unsigned checksum = adler32(out->data, (unsigned)(out->size)); if(checksum != ADLER32) return 58; /*error, adler checksum not correct, data must be corrupted*/ } return 0; /*no error*/ } unsigned lodepng_zlib_decompress(unsigned char** out, size_t* outsize, const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) { ucvector v = ucvector_init(*out, *outsize); unsigned error = lodepng_zlib_decompressv(&v, in, insize, settings); *out = v.data; *outsize = v.size; return error; } /*expected_size is expected output size, to avoid intermediate allocations. Set to 0 if not known. */ static unsigned zlib_decompress(unsigned char** out, size_t* outsize, size_t expected_size, const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) { unsigned error; if(settings->custom_zlib) { error = settings->custom_zlib(out, outsize, in, insize, settings); if(error) { /*the custom zlib is allowed to have its own error codes, however, we translate it to code 110*/ error = 110; /*if there's a max output size, and the custom zlib returned error, then indicate that error instead*/ if(settings->max_output_size && *outsize > settings->max_output_size) error = 109; } } else { ucvector v = ucvector_init(*out, *outsize); if(expected_size) { /*reserve the memory to avoid intermediate reallocations*/ ucvector_resize(&v, *outsize + expected_size); v.size = *outsize; } error = lodepng_zlib_decompressv(&v, in, insize, settings); *out = v.data; *outsize = v.size; } return error; } #endif /*LODEPNG_COMPILE_DECODER*/ #ifdef LODEPNG_COMPILE_ENCODER unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, const unsigned char* in, size_t insize, const LodePNGCompressSettings* settings) { size_t i; unsigned error; unsigned char* deflatedata = 0; size_t deflatesize = 0; error = deflate(&deflatedata, &deflatesize, in, insize, settings); *out = NULL; *outsize = 0; if(!error) { *outsize = deflatesize + 6; *out = (unsigned char*)lodepng_malloc(*outsize); if(!*out) error = 83; /*alloc fail*/ } if(!error) { unsigned ADLER32 = adler32(in, (unsigned)insize); /*zlib data: 1 byte CMF (CM+CINFO), 1 byte FLG, deflate data, 4 byte ADLER32 checksum of the Decompressed data*/ unsigned CMF = 120; /*0b01111000: CM 8, CINFO 7. With CINFO 7, any window size up to 32768 can be used.*/ unsigned FLEVEL = 0; unsigned FDICT = 0; unsigned CMFFLG = 256 * CMF + FDICT * 32 + FLEVEL * 64; unsigned FCHECK = 31 - CMFFLG % 31; CMFFLG += FCHECK; (*out)[0] = (unsigned char)(CMFFLG >> 8); (*out)[1] = (unsigned char)(CMFFLG & 255); for(i = 0; i != deflatesize; ++i) (*out)[i + 2] = deflatedata[i]; lodepng_set32bitInt(&(*out)[*outsize - 4], ADLER32); } lodepng_free(deflatedata); return error; } /* compress using the default or custom zlib function */ static unsigned zlib_compress(unsigned char** out, size_t* outsize, const unsigned char* in, size_t insize, const LodePNGCompressSettings* settings) { if(settings->custom_zlib) { unsigned error = settings->custom_zlib(out, outsize, in, insize, settings); /*the custom zlib is allowed to have its own error codes, however, we translate it to code 111*/ return error ? 111 : 0; } else { return lodepng_zlib_compress(out, outsize, in, insize, settings); } } #endif /*LODEPNG_COMPILE_ENCODER*/ #else /*no LODEPNG_COMPILE_ZLIB*/ #ifdef LODEPNG_COMPILE_DECODER static unsigned zlib_decompress(unsigned char** out, size_t* outsize, size_t expected_size, const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) { if(!settings->custom_zlib) return 87; /*no custom zlib function provided */ (void)expected_size; return settings->custom_zlib(out, outsize, in, insize, settings); } #endif /*LODEPNG_COMPILE_DECODER*/ #ifdef LODEPNG_COMPILE_ENCODER static unsigned zlib_compress(unsigned char** out, size_t* outsize, const unsigned char* in, size_t insize, const LodePNGCompressSettings* settings) { if(!settings->custom_zlib) return 87; /*no custom zlib function provided */ return settings->custom_zlib(out, outsize, in, insize, settings); } #endif /*LODEPNG_COMPILE_ENCODER*/ #endif /*LODEPNG_COMPILE_ZLIB*/ /* ////////////////////////////////////////////////////////////////////////// */ #ifdef LODEPNG_COMPILE_ENCODER /*this is a good tradeoff between speed and compression ratio*/ #define DEFAULT_WINDOWSIZE 2048 void lodepng_compress_settings_init(LodePNGCompressSettings* settings) { /*compress with dynamic huffman tree (not in the mathematical sense, just not the predefined one)*/ settings->btype = 2; settings->use_lz77 = 1; settings->windowsize = DEFAULT_WINDOWSIZE; settings->minmatch = 3; settings->nicematch = 128; settings->lazymatching = 1; settings->custom_zlib = 0; settings->custom_deflate = 0; settings->custom_context = 0; } const LodePNGCompressSettings lodepng_default_compress_settings = {2, 1, DEFAULT_WINDOWSIZE, 3, 128, 1, 0, 0, 0}; #endif /*LODEPNG_COMPILE_ENCODER*/ #ifdef LODEPNG_COMPILE_DECODER void lodepng_decompress_settings_init(LodePNGDecompressSettings* settings) { settings->ignore_adler32 = 0; settings->ignore_nlen = 0; settings->max_output_size = 0; settings->custom_zlib = 0; settings->custom_inflate = 0; settings->custom_context = 0; } const LodePNGDecompressSettings lodepng_default_decompress_settings = {0, 0, 0, 0, 0, 0}; #endif /*LODEPNG_COMPILE_DECODER*/ /* ////////////////////////////////////////////////////////////////////////// */ /* ////////////////////////////////////////////////////////////////////////// */ /* // End of Zlib related code. Begin of PNG related code. // */ /* ////////////////////////////////////////////////////////////////////////// */ /* ////////////////////////////////////////////////////////////////////////// */ #ifdef LODEPNG_COMPILE_PNG /* ////////////////////////////////////////////////////////////////////////// */ /* / CRC32 / */ /* ////////////////////////////////////////////////////////////////////////// */ #ifdef LODEPNG_COMPILE_CRC /* CRC polynomial: 0xedb88320 */ static unsigned lodepng_crc32_table[256] = { 0u, 1996959894u, 3993919788u, 2567524794u, 124634137u, 1886057615u, 3915621685u, 2657392035u, 249268274u, 2044508324u, 3772115230u, 2547177864u, 162941995u, 2125561021u, 3887607047u, 2428444049u, 498536548u, 1789927666u, 4089016648u, 2227061214u, 450548861u, 1843258603u, 4107580753u, 2211677639u, 325883990u, 1684777152u, 4251122042u, 2321926636u, 335633487u, 1661365465u, 4195302755u, 2366115317u, 997073096u, 1281953886u, 3579855332u, 2724688242u, 1006888145u, 1258607687u, 3524101629u, 2768942443u, 901097722u, 1119000684u, 3686517206u, 2898065728u, 853044451u, 1172266101u, 3705015759u, 2882616665u, 651767980u, 1373503546u, 3369554304u, 3218104598u, 565507253u, 1454621731u, 3485111705u, 3099436303u, 671266974u, 1594198024u, 3322730930u, 2970347812u, 795835527u, 1483230225u, 3244367275u, 3060149565u, 1994146192u, 31158534u, 2563907772u, 4023717930u, 1907459465u, 112637215u, 2680153253u, 3904427059u, 2013776290u, 251722036u, 2517215374u, 3775830040u, 2137656763u, 141376813u, 2439277719u, 3865271297u, 1802195444u, 476864866u, 2238001368u, 4066508878u, 1812370925u, 453092731u, 2181625025u, 4111451223u, 1706088902u, 314042704u, 2344532202u, 4240017532u, 1658658271u, 366619977u, 2362670323u, 4224994405u, 1303535960u, 984961486u, 2747007092u, 3569037538u, 1256170817u, 1037604311u, 2765210733u, 3554079995u, 1131014506u, 879679996u, 2909243462u, 3663771856u, 1141124467u, 855842277u, 2852801631u, 3708648649u, 1342533948u, 654459306u, 3188396048u, 3373015174u, 1466479909u, 544179635u, 3110523913u, 3462522015u, 1591671054u, 702138776u, 2966460450u, 3352799412u, 1504918807u, 783551873u, 3082640443u, 3233442989u, 3988292384u, 2596254646u, 62317068u, 1957810842u, 3939845945u, 2647816111u, 81470997u, 1943803523u, 3814918930u, 2489596804u, 225274430u, 2053790376u, 3826175755u, 2466906013u, 167816743u, 2097651377u, 4027552580u, 2265490386u, 503444072u, 1762050814u, 4150417245u, 2154129355u, 426522225u, 1852507879u, 4275313526u, 2312317920u, 282753626u, 1742555852u, 4189708143u, 2394877945u, 397917763u, 1622183637u, 3604390888u, 2714866558u, 953729732u, 1340076626u, 3518719985u, 2797360999u, 1068828381u, 1219638859u, 3624741850u, 2936675148u, 906185462u, 1090812512u, 3747672003u, 2825379669u, 829329135u, 1181335161u, 3412177804u, 3160834842u, 628085408u, 1382605366u, 3423369109u, 3138078467u, 570562233u, 1426400815u, 3317316542u, 2998733608u, 733239954u, 1555261956u, 3268935591u, 3050360625u, 752459403u, 1541320221u, 2607071920u, 3965973030u, 1969922972u, 40735498u, 2617837225u, 3943577151u, 1913087877u, 83908371u, 2512341634u, 3803740692u, 2075208622u, 213261112u, 2463272603u, 3855990285u, 2094854071u, 198958881u, 2262029012u, 4057260610u, 1759359992u, 534414190u, 2176718541u, 4139329115u, 1873836001u, 414664567u, 2282248934u, 4279200368u, 1711684554u, 285281116u, 2405801727u, 4167216745u, 1634467795u, 376229701u, 2685067896u, 3608007406u, 1308918612u, 956543938u, 2808555105u, 3495958263u, 1231636301u, 1047427035u, 2932959818u, 3654703836u, 1088359270u, 936918000u, 2847714899u, 3736837829u, 1202900863u, 817233897u, 3183342108u, 3401237130u, 1404277552u, 615818150u, 3134207493u, 3453421203u, 1423857449u, 601450431u, 3009837614u, 3294710456u, 1567103746u, 711928724u, 3020668471u, 3272380065u, 1510334235u, 755167117u }; /*Return the CRC of the bytes buf[0..len-1].*/ unsigned lodepng_crc32(const unsigned char* data, size_t length) { unsigned r = 0xffffffffu; size_t i; for(i = 0; i < length; ++i) { r = lodepng_crc32_table[(r ^ data[i]) & 0xffu] ^ (r >> 8u); } return r ^ 0xffffffffu; } #else /* LODEPNG_COMPILE_CRC */ /*in this case, the function is only declared here, and must be defined externally so that it will be linked in*/ unsigned lodepng_crc32(const unsigned char* data, size_t length); #endif /* LODEPNG_COMPILE_CRC */ /* ////////////////////////////////////////////////////////////////////////// */ /* / Reading and writing PNG color channel bits / */ /* ////////////////////////////////////////////////////////////////////////// */ /* The color channel bits of less-than-8-bit pixels are read with the MSB of bytes first, so LodePNGBitWriter and LodePNGBitReader can't be used for those. */ static unsigned char readBitFromReversedStream(size_t* bitpointer, const unsigned char* bitstream) { unsigned char result = (unsigned char)((bitstream[(*bitpointer) >> 3] >> (7 - ((*bitpointer) & 0x7))) & 1); ++(*bitpointer); return result; } /* TODO: make this faster */ static unsigned readBitsFromReversedStream(size_t* bitpointer, const unsigned char* bitstream, size_t nbits) { unsigned result = 0; size_t i; for(i = 0 ; i < nbits; ++i) { result <<= 1u; result |= (unsigned)readBitFromReversedStream(bitpointer, bitstream); } return result; } static void setBitOfReversedStream(size_t* bitpointer, unsigned char* bitstream, unsigned char bit) { /*the current bit in bitstream may be 0 or 1 for this to work*/ if(bit == 0) bitstream[(*bitpointer) >> 3u] &= (unsigned char)(~(1u << (7u - ((*bitpointer) & 7u)))); else bitstream[(*bitpointer) >> 3u] |= (1u << (7u - ((*bitpointer) & 7u))); ++(*bitpointer); } /* ////////////////////////////////////////////////////////////////////////// */ /* / PNG chunks / */ /* ////////////////////////////////////////////////////////////////////////// */ unsigned lodepng_chunk_length(const unsigned char* chunk) { return lodepng_read32bitInt(&chunk[0]); } void lodepng_chunk_type(char type[5], const unsigned char* chunk) { unsigned i; for(i = 0; i != 4; ++i) type[i] = (char)chunk[4 + i]; type[4] = 0; /*null termination char*/ } unsigned char lodepng_chunk_type_equals(const unsigned char* chunk, const char* type) { if(lodepng_strlen(type) != 4) return 0; return (chunk[4] == type[0] && chunk[5] == type[1] && chunk[6] == type[2] && chunk[7] == type[3]); } unsigned char lodepng_chunk_ancillary(const unsigned char* chunk) { return((chunk[4] & 32) != 0); } unsigned char lodepng_chunk_private(const unsigned char* chunk) { return((chunk[6] & 32) != 0); } unsigned char lodepng_chunk_safetocopy(const unsigned char* chunk) { return((chunk[7] & 32) != 0); } unsigned char* lodepng_chunk_data(unsigned char* chunk) { return &chunk[8]; } const unsigned char* lodepng_chunk_data_const(const unsigned char* chunk) { return &chunk[8]; } unsigned lodepng_chunk_check_crc(const unsigned char* chunk) { unsigned length = lodepng_chunk_length(chunk); unsigned CRC = lodepng_read32bitInt(&chunk[length + 8]); /*the CRC is taken of the data and the 4 chunk type letters, not the length*/ unsigned checksum = lodepng_crc32(&chunk[4], length + 4); if(CRC != checksum) return 1; else return 0; } void lodepng_chunk_generate_crc(unsigned char* chunk) { unsigned length = lodepng_chunk_length(chunk); unsigned CRC = lodepng_crc32(&chunk[4], length + 4); lodepng_set32bitInt(chunk + 8 + length, CRC); } unsigned char* lodepng_chunk_next(unsigned char* chunk, unsigned char* end) { size_t available_size = (size_t)(end - chunk); if(chunk >= end || available_size < 12) return end; /*too small to contain a chunk*/ if(chunk[0] == 0x89 && chunk[1] == 0x50 && chunk[2] == 0x4e && chunk[3] == 0x47 && chunk[4] == 0x0d && chunk[5] == 0x0a && chunk[6] == 0x1a && chunk[7] == 0x0a) { /* Is PNG magic header at start of PNG file. Jump to first actual chunk. */ return chunk + 8; } else { size_t total_chunk_length; if(lodepng_addofl(lodepng_chunk_length(chunk), 12, &total_chunk_length)) return end; if(total_chunk_length > available_size) return end; /*outside of range*/ return chunk + total_chunk_length; } } const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk, const unsigned char* end) { size_t available_size = (size_t)(end - chunk); if(chunk >= end || available_size < 12) return end; /*too small to contain a chunk*/ if(chunk[0] == 0x89 && chunk[1] == 0x50 && chunk[2] == 0x4e && chunk[3] == 0x47 && chunk[4] == 0x0d && chunk[5] == 0x0a && chunk[6] == 0x1a && chunk[7] == 0x0a) { /* Is PNG magic header at start of PNG file. Jump to first actual chunk. */ return chunk + 8; } else { size_t total_chunk_length; if(lodepng_addofl(lodepng_chunk_length(chunk), 12, &total_chunk_length)) return end; if(total_chunk_length > available_size) return end; /*outside of range*/ return chunk + total_chunk_length; } } unsigned char* lodepng_chunk_find(unsigned char* chunk, unsigned char* end, const char type[5]) { for(;;) { if(chunk >= end || end - chunk < 12) return 0; /* past file end: chunk + 12 > end */ if(lodepng_chunk_type_equals(chunk, type)) return chunk; chunk = lodepng_chunk_next(chunk, end); } } const unsigned char* lodepng_chunk_find_const(const unsigned char* chunk, const unsigned char* end, const char type[5]) { for(;;) { if(chunk >= end || end - chunk < 12) return 0; /* past file end: chunk + 12 > end */ if(lodepng_chunk_type_equals(chunk, type)) return chunk; chunk = lodepng_chunk_next_const(chunk, end); } } unsigned lodepng_chunk_append(unsigned char** out, size_t* outsize, const unsigned char* chunk) { unsigned i; size_t total_chunk_length, new_length; unsigned char *chunk_start, *new_buffer; if(lodepng_addofl(lodepng_chunk_length(chunk), 12, &total_chunk_length)) return 77; if(lodepng_addofl(*outsize, total_chunk_length, &new_length)) return 77; new_buffer = (unsigned char*)lodepng_realloc(*out, new_length); if(!new_buffer) return 83; /*alloc fail*/ (*out) = new_buffer; (*outsize) = new_length; chunk_start = &(*out)[new_length - total_chunk_length]; for(i = 0; i != total_chunk_length; ++i) chunk_start[i] = chunk[i]; return 0; } /*Sets length and name and allocates the space for data and crc but does not set data or crc yet. Returns the start of the chunk in chunk. The start of the data is at chunk + 8. To finalize chunk, add the data, then use lodepng_chunk_generate_crc */ static unsigned lodepng_chunk_init(unsigned char** chunk, ucvector* out, unsigned length, const char* type) { size_t new_length = out->size; if(lodepng_addofl(new_length, length, &new_length)) return 77; if(lodepng_addofl(new_length, 12, &new_length)) return 77; if(!ucvector_resize(out, new_length)) return 83; /*alloc fail*/ *chunk = out->data + new_length - length - 12u; /*1: length*/ lodepng_set32bitInt(*chunk, length); /*2: chunk name (4 letters)*/ lodepng_memcpy(*chunk + 4, type, 4); return 0; } /* like lodepng_chunk_create but with custom allocsize */ static unsigned lodepng_chunk_createv(ucvector* out, unsigned length, const char* type, const unsigned char* data) { unsigned char* chunk; CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, length, type)); /*3: the data*/ lodepng_memcpy(chunk + 8, data, length); /*4: CRC (of the chunkname characters and the data)*/ lodepng_chunk_generate_crc(chunk); return 0; } unsigned lodepng_chunk_create(unsigned char** out, size_t* outsize, unsigned length, const char* type, const unsigned char* data) { ucvector v = ucvector_init(*out, *outsize); unsigned error = lodepng_chunk_createv(&v, length, type, data); *out = v.data; *outsize = v.size; return error; } /* ////////////////////////////////////////////////////////////////////////// */ /* / Color types, channels, bits / */ /* ////////////////////////////////////////////////////////////////////////// */ /*checks if the colortype is valid and the bitdepth bd is allowed for this colortype. Return value is a LodePNG error code.*/ static unsigned checkColorValidity(LodePNGColorType colortype, unsigned bd) { switch(colortype) { case LCT_GREY: if(!(bd == 1 || bd == 2 || bd == 4 || bd == 8 || bd == 16)) return 37; break; case LCT_RGB: if(!( bd == 8 || bd == 16)) return 37; break; case LCT_PALETTE: if(!(bd == 1 || bd == 2 || bd == 4 || bd == 8 )) return 37; break; case LCT_GREY_ALPHA: if(!( bd == 8 || bd == 16)) return 37; break; case LCT_RGBA: if(!( bd == 8 || bd == 16)) return 37; break; case LCT_MAX_OCTET_VALUE: return 31; /* invalid color type */ default: return 31; /* invalid color type */ } return 0; /*allowed color type / bits combination*/ } static unsigned getNumColorChannels(LodePNGColorType colortype) { switch(colortype) { case LCT_GREY: return 1; case LCT_RGB: return 3; case LCT_PALETTE: return 1; case LCT_GREY_ALPHA: return 2; case LCT_RGBA: return 4; case LCT_MAX_OCTET_VALUE: return 0; /* invalid color type */ default: return 0; /*invalid color type*/ } } static unsigned lodepng_get_bpp_lct(LodePNGColorType colortype, unsigned bitdepth) { /*bits per pixel is amount of channels * bits per channel*/ return getNumColorChannels(colortype) * bitdepth; } /* ////////////////////////////////////////////////////////////////////////// */ void lodepng_color_mode_init(LodePNGColorMode* info) { info->key_defined = 0; info->key_r = info->key_g = info->key_b = 0; info->colortype = LCT_RGBA; info->bitdepth = 8; info->palette = 0; info->palettesize = 0; } /*allocates palette memory if needed, and initializes all colors to black*/ static void lodepng_color_mode_alloc_palette(LodePNGColorMode* info) { size_t i; /*if the palette is already allocated, it will have size 1024 so no reallocation needed in that case*/ /*the palette must have room for up to 256 colors with 4 bytes each.*/ if(!info->palette) info->palette = (unsigned char*)lodepng_malloc(1024); if(!info->palette) return; /*alloc fail*/ for(i = 0; i != 256; ++i) { /*Initialize all unused colors with black, the value used for invalid palette indices. This is an error according to the PNG spec, but common PNG decoders make it black instead. That makes color conversion slightly faster due to no error handling needed.*/ info->palette[i * 4 + 0] = 0; info->palette[i * 4 + 1] = 0; info->palette[i * 4 + 2] = 0; info->palette[i * 4 + 3] = 255; } } void lodepng_color_mode_cleanup(LodePNGColorMode* info) { lodepng_palette_clear(info); } unsigned lodepng_color_mode_copy(LodePNGColorMode* dest, const LodePNGColorMode* source) { lodepng_color_mode_cleanup(dest); lodepng_memcpy(dest, source, sizeof(LodePNGColorMode)); if(source->palette) { dest->palette = (unsigned char*)lodepng_malloc(1024); if(!dest->palette && source->palettesize) return 83; /*alloc fail*/ lodepng_memcpy(dest->palette, source->palette, source->palettesize * 4); } return 0; } LodePNGColorMode lodepng_color_mode_make(LodePNGColorType colortype, unsigned bitdepth) { LodePNGColorMode result; lodepng_color_mode_init(&result); result.colortype = colortype; result.bitdepth = bitdepth; return result; } static int lodepng_color_mode_equal(const LodePNGColorMode* a, const LodePNGColorMode* b) { size_t i; if(a->colortype != b->colortype) return 0; if(a->bitdepth != b->bitdepth) return 0; if(a->key_defined != b->key_defined) return 0; if(a->key_defined) { if(a->key_r != b->key_r) return 0; if(a->key_g != b->key_g) return 0; if(a->key_b != b->key_b) return 0; } if(a->palettesize != b->palettesize) return 0; for(i = 0; i != a->palettesize * 4; ++i) { if(a->palette[i] != b->palette[i]) return 0; } return 1; } void lodepng_palette_clear(LodePNGColorMode* info) { if(info->palette) lodepng_free(info->palette); info->palette = 0; info->palettesize = 0; } unsigned lodepng_palette_add(LodePNGColorMode* info, unsigned char r, unsigned char g, unsigned char b, unsigned char a) { if(!info->palette) /*allocate palette if empty*/ { lodepng_color_mode_alloc_palette(info); if(!info->palette) return 83; /*alloc fail*/ } if(info->palettesize >= 256) { return 108; /*too many palette values*/ } info->palette[4 * info->palettesize + 0] = r; info->palette[4 * info->palettesize + 1] = g; info->palette[4 * info->palettesize + 2] = b; info->palette[4 * info->palettesize + 3] = a; ++info->palettesize; return 0; } /*calculate bits per pixel out of colortype and bitdepth*/ unsigned lodepng_get_bpp(const LodePNGColorMode* info) { return lodepng_get_bpp_lct(info->colortype, info->bitdepth); } unsigned lodepng_get_channels(const LodePNGColorMode* info) { return getNumColorChannels(info->colortype); } unsigned lodepng_is_greyscale_type(const LodePNGColorMode* info) { return info->colortype == LCT_GREY || info->colortype == LCT_GREY_ALPHA; } unsigned lodepng_is_alpha_type(const LodePNGColorMode* info) { return (info->colortype & 4) != 0; /*4 or 6*/ } unsigned lodepng_is_palette_type(const LodePNGColorMode* info) { return info->colortype == LCT_PALETTE; } unsigned lodepng_has_palette_alpha(const LodePNGColorMode* info) { size_t i; for(i = 0; i != info->palettesize; ++i) { if(info->palette[i * 4 + 3] < 255) return 1; } return 0; } unsigned lodepng_can_have_alpha(const LodePNGColorMode* info) { return info->key_defined || lodepng_is_alpha_type(info) || lodepng_has_palette_alpha(info); } static size_t lodepng_get_raw_size_lct(unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth) { size_t bpp = lodepng_get_bpp_lct(colortype, bitdepth); size_t n = (size_t)w * (size_t)h; return ((n / 8u) * bpp) + ((n & 7u) * bpp + 7u) / 8u; } size_t lodepng_get_raw_size(unsigned w, unsigned h, const LodePNGColorMode* color) { return lodepng_get_raw_size_lct(w, h, color->colortype, color->bitdepth); } #ifdef LODEPNG_COMPILE_PNG /*in an idat chunk, each scanline is a multiple of 8 bits, unlike the lodepng output buffer, and in addition has one extra byte per line: the filter byte. So this gives a larger result than lodepng_get_raw_size. Set h to 1 to get the size of 1 row including filter byte. */ static size_t lodepng_get_raw_size_idat(unsigned w, unsigned h, unsigned bpp) { /* + 1 for the filter byte, and possibly plus padding bits per line. */ /* Ignoring casts, the expression is equal to (w * bpp + 7) / 8 + 1, but avoids overflow of w * bpp */ size_t line = ((size_t)(w / 8u) * bpp) + 1u + ((w & 7u) * bpp + 7u) / 8u; return (size_t)h * line; } #ifdef LODEPNG_COMPILE_DECODER /*Safely checks whether size_t overflow can be caused due to amount of pixels. This check is overcautious rather than precise. If this check indicates no overflow, you can safely compute in a size_t (but not an unsigned): -(size_t)w * (size_t)h * 8 -amount of bytes in IDAT (including filter, padding and Adam7 bytes) -amount of bytes in raw color model Returns 1 if overflow possible, 0 if not. */ static int lodepng_pixel_overflow(unsigned w, unsigned h, const LodePNGColorMode* pngcolor, const LodePNGColorMode* rawcolor) { size_t bpp = LODEPNG_MAX(lodepng_get_bpp(pngcolor), lodepng_get_bpp(rawcolor)); size_t numpixels, total; size_t line; /* bytes per line in worst case */ if(lodepng_mulofl((size_t)w, (size_t)h, &numpixels)) return 1; if(lodepng_mulofl(numpixels, 8, &total)) return 1; /* bit pointer with 8-bit color, or 8 bytes per channel color */ /* Bytes per scanline with the expression "(w / 8u) * bpp) + ((w & 7u) * bpp + 7u) / 8u" */ if(lodepng_mulofl((size_t)(w / 8u), bpp, &line)) return 1; if(lodepng_addofl(line, ((w & 7u) * bpp + 7u) / 8u, &line)) return 1; if(lodepng_addofl(line, 5, &line)) return 1; /* 5 bytes overhead per line: 1 filterbyte, 4 for Adam7 worst case */ if(lodepng_mulofl(line, h, &total)) return 1; /* Total bytes in worst case */ return 0; /* no overflow */ } #endif /*LODEPNG_COMPILE_DECODER*/ #endif /*LODEPNG_COMPILE_PNG*/ #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS static void LodePNGUnknownChunks_init(LodePNGInfo* info) { unsigned i; for(i = 0; i != 3; ++i) info->unknown_chunks_data[i] = 0; for(i = 0; i != 3; ++i) info->unknown_chunks_size[i] = 0; } static void LodePNGUnknownChunks_cleanup(LodePNGInfo* info) { unsigned i; for(i = 0; i != 3; ++i) lodepng_free(info->unknown_chunks_data[i]); } static unsigned LodePNGUnknownChunks_copy(LodePNGInfo* dest, const LodePNGInfo* src) { unsigned i; LodePNGUnknownChunks_cleanup(dest); for(i = 0; i != 3; ++i) { size_t j; dest->unknown_chunks_size[i] = src->unknown_chunks_size[i]; dest->unknown_chunks_data[i] = (unsigned char*)lodepng_malloc(src->unknown_chunks_size[i]); if(!dest->unknown_chunks_data[i] && dest->unknown_chunks_size[i]) return 83; /*alloc fail*/ for(j = 0; j < src->unknown_chunks_size[i]; ++j) { dest->unknown_chunks_data[i][j] = src->unknown_chunks_data[i][j]; } } return 0; } /******************************************************************************/ static void LodePNGText_init(LodePNGInfo* info) { info->text_num = 0; info->text_keys = NULL; info->text_strings = NULL; } static void LodePNGText_cleanup(LodePNGInfo* info) { size_t i; for(i = 0; i != info->text_num; ++i) { string_cleanup(&info->text_keys[i]); string_cleanup(&info->text_strings[i]); } lodepng_free(info->text_keys); lodepng_free(info->text_strings); } static unsigned LodePNGText_copy(LodePNGInfo* dest, const LodePNGInfo* source) { size_t i = 0; dest->text_keys = NULL; dest->text_strings = NULL; dest->text_num = 0; for(i = 0; i != source->text_num; ++i) { CERROR_TRY_RETURN(lodepng_add_text(dest, source->text_keys[i], source->text_strings[i])); } return 0; } static unsigned lodepng_add_text_sized(LodePNGInfo* info, const char* key, const char* str, size_t size) { char** new_keys = (char**)(lodepng_realloc(info->text_keys, sizeof(char*) * (info->text_num + 1))); char** new_strings = (char**)(lodepng_realloc(info->text_strings, sizeof(char*) * (info->text_num + 1))); if(new_keys) info->text_keys = new_keys; if(new_strings) info->text_strings = new_strings; if(!new_keys || !new_strings) return 83; /*alloc fail*/ ++info->text_num; info->text_keys[info->text_num - 1] = alloc_string(key); info->text_strings[info->text_num - 1] = alloc_string_sized(str, size); if(!info->text_keys[info->text_num - 1] || !info->text_strings[info->text_num - 1]) return 83; /*alloc fail*/ return 0; } unsigned lodepng_add_text(LodePNGInfo* info, const char* key, const char* str) { return lodepng_add_text_sized(info, key, str, lodepng_strlen(str)); } void lodepng_clear_text(LodePNGInfo* info) { LodePNGText_cleanup(info); } /******************************************************************************/ static void LodePNGIText_init(LodePNGInfo* info) { info->itext_num = 0; info->itext_keys = NULL; info->itext_langtags = NULL; info->itext_transkeys = NULL; info->itext_strings = NULL; } static void LodePNGIText_cleanup(LodePNGInfo* info) { size_t i; for(i = 0; i != info->itext_num; ++i) { string_cleanup(&info->itext_keys[i]); string_cleanup(&info->itext_langtags[i]); string_cleanup(&info->itext_transkeys[i]); string_cleanup(&info->itext_strings[i]); } lodepng_free(info->itext_keys); lodepng_free(info->itext_langtags); lodepng_free(info->itext_transkeys); lodepng_free(info->itext_strings); } static unsigned LodePNGIText_copy(LodePNGInfo* dest, const LodePNGInfo* source) { size_t i = 0; dest->itext_keys = NULL; dest->itext_langtags = NULL; dest->itext_transkeys = NULL; dest->itext_strings = NULL; dest->itext_num = 0; for(i = 0; i != source->itext_num; ++i) { CERROR_TRY_RETURN(lodepng_add_itext(dest, source->itext_keys[i], source->itext_langtags[i], source->itext_transkeys[i], source->itext_strings[i])); } return 0; } void lodepng_clear_itext(LodePNGInfo* info) { LodePNGIText_cleanup(info); } static unsigned lodepng_add_itext_sized(LodePNGInfo* info, const char* key, const char* langtag, const char* transkey, const char* str, size_t size) { char** new_keys = (char**)(lodepng_realloc(info->itext_keys, sizeof(char*) * (info->itext_num + 1))); char** new_langtags = (char**)(lodepng_realloc(info->itext_langtags, sizeof(char*) * (info->itext_num + 1))); char** new_transkeys = (char**)(lodepng_realloc(info->itext_transkeys, sizeof(char*) * (info->itext_num + 1))); char** new_strings = (char**)(lodepng_realloc(info->itext_strings, sizeof(char*) * (info->itext_num + 1))); if(new_keys) info->itext_keys = new_keys; if(new_langtags) info->itext_langtags = new_langtags; if(new_transkeys) info->itext_transkeys = new_transkeys; if(new_strings) info->itext_strings = new_strings; if(!new_keys || !new_langtags || !new_transkeys || !new_strings) return 83; /*alloc fail*/ ++info->itext_num; info->itext_keys[info->itext_num - 1] = alloc_string(key); info->itext_langtags[info->itext_num - 1] = alloc_string(langtag); info->itext_transkeys[info->itext_num - 1] = alloc_string(transkey); info->itext_strings[info->itext_num - 1] = alloc_string_sized(str, size); return 0; } unsigned lodepng_add_itext(LodePNGInfo* info, const char* key, const char* langtag, const char* transkey, const char* str) { return lodepng_add_itext_sized(info, key, langtag, transkey, str, lodepng_strlen(str)); } /* same as set but does not delete */ static unsigned lodepng_assign_icc(LodePNGInfo* info, const char* name, const unsigned char* profile, unsigned profile_size) { if(profile_size == 0) return 100; /*invalid ICC profile size*/ info->iccp_name = alloc_string(name); info->iccp_profile = (unsigned char*)lodepng_malloc(profile_size); if(!info->iccp_name || !info->iccp_profile) return 83; /*alloc fail*/ lodepng_memcpy(info->iccp_profile, profile, profile_size); info->iccp_profile_size = profile_size; return 0; /*ok*/ } unsigned lodepng_set_icc(LodePNGInfo* info, const char* name, const unsigned char* profile, unsigned profile_size) { if(info->iccp_name) lodepng_clear_icc(info); info->iccp_defined = 1; return lodepng_assign_icc(info, name, profile, profile_size); } void lodepng_clear_icc(LodePNGInfo* info) { string_cleanup(&info->iccp_name); lodepng_free(info->iccp_profile); info->iccp_profile = NULL; info->iccp_profile_size = 0; info->iccp_defined = 0; } #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ void lodepng_info_init(LodePNGInfo* info) { lodepng_color_mode_init(&info->color); info->interlace_method = 0; info->compression_method = 0; info->filter_method = 0; #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS info->background_defined = 0; info->background_r = info->background_g = info->background_b = 0; LodePNGText_init(info); LodePNGIText_init(info); info->time_defined = 0; info->phys_defined = 0; info->gama_defined = 0; info->chrm_defined = 0; info->srgb_defined = 0; info->iccp_defined = 0; info->iccp_name = NULL; info->iccp_profile = NULL; info->sbit_defined = 0; info->sbit_r = info->sbit_g = info->sbit_b = info->sbit_a = 0; LodePNGUnknownChunks_init(info); #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ } void lodepng_info_cleanup(LodePNGInfo* info) { lodepng_color_mode_cleanup(&info->color); #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS LodePNGText_cleanup(info); LodePNGIText_cleanup(info); lodepng_clear_icc(info); LodePNGUnknownChunks_cleanup(info); #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ } unsigned lodepng_info_copy(LodePNGInfo* dest, const LodePNGInfo* source) { lodepng_info_cleanup(dest); lodepng_memcpy(dest, source, sizeof(LodePNGInfo)); lodepng_color_mode_init(&dest->color); CERROR_TRY_RETURN(lodepng_color_mode_copy(&dest->color, &source->color)); #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS CERROR_TRY_RETURN(LodePNGText_copy(dest, source)); CERROR_TRY_RETURN(LodePNGIText_copy(dest, source)); if(source->iccp_defined) { CERROR_TRY_RETURN(lodepng_assign_icc(dest, source->iccp_name, source->iccp_profile, source->iccp_profile_size)); } LodePNGUnknownChunks_init(dest); CERROR_TRY_RETURN(LodePNGUnknownChunks_copy(dest, source)); #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ return 0; } /* ////////////////////////////////////////////////////////////////////////// */ /*index: bitgroup index, bits: bitgroup size(1, 2 or 4), in: bitgroup value, out: octet array to add bits to*/ static void addColorBits(unsigned char* out, size_t index, unsigned bits, unsigned in) { unsigned m = bits == 1 ? 7 : bits == 2 ? 3 : 1; /*8 / bits - 1*/ /*p = the partial index in the byte, e.g. with 4 palettebits it is 0 for first half or 1 for second half*/ unsigned p = index & m; in &= (1u << bits) - 1u; /*filter out any other bits of the input value*/ in = in << (bits * (m - p)); if(p == 0) out[index * bits / 8u] = in; else out[index * bits / 8u] |= in; } typedef struct ColorTree ColorTree; /* One node of a color tree This is the data structure used to count the number of unique colors and to get a palette index for a color. It's like an octree, but because the alpha channel is used too, each node has 16 instead of 8 children. */ struct ColorTree { ColorTree* children[16]; /*up to 16 pointers to ColorTree of next level*/ int index; /*the payload. Only has a meaningful value if this is in the last level*/ }; static void color_tree_init(ColorTree* tree) { lodepng_memset(tree->children, 0, 16 * sizeof(*tree->children)); tree->index = -1; } static void color_tree_cleanup(ColorTree* tree) { int i; for(i = 0; i != 16; ++i) { if(tree->children[i]) { color_tree_cleanup(tree->children[i]); lodepng_free(tree->children[i]); } } } /*returns -1 if color not present, its index otherwise*/ static int color_tree_get(ColorTree* tree, unsigned char r, unsigned char g, unsigned char b, unsigned char a) { int bit = 0; for(bit = 0; bit < 8; ++bit) { int i = 8 * ((r >> bit) & 1) + 4 * ((g >> bit) & 1) + 2 * ((b >> bit) & 1) + 1 * ((a >> bit) & 1); if(!tree->children[i]) return -1; else tree = tree->children[i]; } return tree ? tree->index : -1; } #ifdef LODEPNG_COMPILE_ENCODER static int color_tree_has(ColorTree* tree, unsigned char r, unsigned char g, unsigned char b, unsigned char a) { return color_tree_get(tree, r, g, b, a) >= 0; } #endif /*LODEPNG_COMPILE_ENCODER*/ /*color is not allowed to already exist. Index should be >= 0 (it's signed to be compatible with using -1 for "doesn't exist") Returns error code, or 0 if ok*/ static unsigned color_tree_add(ColorTree* tree, unsigned char r, unsigned char g, unsigned char b, unsigned char a, unsigned index) { int bit; for(bit = 0; bit < 8; ++bit) { int i = 8 * ((r >> bit) & 1) + 4 * ((g >> bit) & 1) + 2 * ((b >> bit) & 1) + 1 * ((a >> bit) & 1); if(!tree->children[i]) { tree->children[i] = (ColorTree*)lodepng_malloc(sizeof(ColorTree)); if(!tree->children[i]) return 83; /*alloc fail*/ color_tree_init(tree->children[i]); } tree = tree->children[i]; } tree->index = (int)index; return 0; } /*put a pixel, given its RGBA color, into image of any color type*/ static unsigned rgba8ToPixel(unsigned char* out, size_t i, const LodePNGColorMode* mode, ColorTree* tree /*for palette*/, unsigned char r, unsigned char g, unsigned char b, unsigned char a) { if(mode->colortype == LCT_GREY) { unsigned char gray = r; /*((unsigned short)r + g + b) / 3u;*/ if(mode->bitdepth == 8) out[i] = gray; else if(mode->bitdepth == 16) out[i * 2 + 0] = out[i * 2 + 1] = gray; else { /*take the most significant bits of gray*/ gray = ((unsigned)gray >> (8u - mode->bitdepth)) & ((1u << mode->bitdepth) - 1u); addColorBits(out, i, mode->bitdepth, gray); } } else if(mode->colortype == LCT_RGB) { if(mode->bitdepth == 8) { out[i * 3 + 0] = r; out[i * 3 + 1] = g; out[i * 3 + 2] = b; } else { out[i * 6 + 0] = out[i * 6 + 1] = r; out[i * 6 + 2] = out[i * 6 + 3] = g; out[i * 6 + 4] = out[i * 6 + 5] = b; } } else if(mode->colortype == LCT_PALETTE) { int index = color_tree_get(tree, r, g, b, a); if(index < 0) return 82; /*color not in palette*/ if(mode->bitdepth == 8) out[i] = index; else addColorBits(out, i, mode->bitdepth, (unsigned)index); } else if(mode->colortype == LCT_GREY_ALPHA) { unsigned char gray = r; /*((unsigned short)r + g + b) / 3u;*/ if(mode->bitdepth == 8) { out[i * 2 + 0] = gray; out[i * 2 + 1] = a; } else if(mode->bitdepth == 16) { out[i * 4 + 0] = out[i * 4 + 1] = gray; out[i * 4 + 2] = out[i * 4 + 3] = a; } } else if(mode->colortype == LCT_RGBA) { if(mode->bitdepth == 8) { out[i * 4 + 0] = r; out[i * 4 + 1] = g; out[i * 4 + 2] = b; out[i * 4 + 3] = a; } else { out[i * 8 + 0] = out[i * 8 + 1] = r; out[i * 8 + 2] = out[i * 8 + 3] = g; out[i * 8 + 4] = out[i * 8 + 5] = b; out[i * 8 + 6] = out[i * 8 + 7] = a; } } return 0; /*no error*/ } /*put a pixel, given its RGBA16 color, into image of any color 16-bitdepth type*/ static void rgba16ToPixel(unsigned char* out, size_t i, const LodePNGColorMode* mode, unsigned short r, unsigned short g, unsigned short b, unsigned short a) { if(mode->colortype == LCT_GREY) { unsigned short gray = r; /*((unsigned)r + g + b) / 3u;*/ out[i * 2 + 0] = (gray >> 8) & 255; out[i * 2 + 1] = gray & 255; } else if(mode->colortype == LCT_RGB) { out[i * 6 + 0] = (r >> 8) & 255; out[i * 6 + 1] = r & 255; out[i * 6 + 2] = (g >> 8) & 255; out[i * 6 + 3] = g & 255; out[i * 6 + 4] = (b >> 8) & 255; out[i * 6 + 5] = b & 255; } else if(mode->colortype == LCT_GREY_ALPHA) { unsigned short gray = r; /*((unsigned)r + g + b) / 3u;*/ out[i * 4 + 0] = (gray >> 8) & 255; out[i * 4 + 1] = gray & 255; out[i * 4 + 2] = (a >> 8) & 255; out[i * 4 + 3] = a & 255; } else if(mode->colortype == LCT_RGBA) { out[i * 8 + 0] = (r >> 8) & 255; out[i * 8 + 1] = r & 255; out[i * 8 + 2] = (g >> 8) & 255; out[i * 8 + 3] = g & 255; out[i * 8 + 4] = (b >> 8) & 255; out[i * 8 + 5] = b & 255; out[i * 8 + 6] = (a >> 8) & 255; out[i * 8 + 7] = a & 255; } } /*Get RGBA8 color of pixel with index i (y * width + x) from the raw image with given color type.*/ static void getPixelColorRGBA8(unsigned char* r, unsigned char* g, unsigned char* b, unsigned char* a, const unsigned char* in, size_t i, const LodePNGColorMode* mode) { if(mode->colortype == LCT_GREY) { if(mode->bitdepth == 8) { *r = *g = *b = in[i]; if(mode->key_defined && *r == mode->key_r) *a = 0; else *a = 255; } else if(mode->bitdepth == 16) { *r = *g = *b = in[i * 2 + 0]; if(mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r) *a = 0; else *a = 255; } else { unsigned highest = ((1U << mode->bitdepth) - 1U); /*highest possible value for this bit depth*/ size_t j = i * mode->bitdepth; unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth); *r = *g = *b = (value * 255) / highest; if(mode->key_defined && value == mode->key_r) *a = 0; else *a = 255; } } else if(mode->colortype == LCT_RGB) { if(mode->bitdepth == 8) { *r = in[i * 3 + 0]; *g = in[i * 3 + 1]; *b = in[i * 3 + 2]; if(mode->key_defined && *r == mode->key_r && *g == mode->key_g && *b == mode->key_b) *a = 0; else *a = 255; } else { *r = in[i * 6 + 0]; *g = in[i * 6 + 2]; *b = in[i * 6 + 4]; if(mode->key_defined && 256U * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r && 256U * in[i * 6 + 2] + in[i * 6 + 3] == mode->key_g && 256U * in[i * 6 + 4] + in[i * 6 + 5] == mode->key_b) *a = 0; else *a = 255; } } else if(mode->colortype == LCT_PALETTE) { unsigned index; if(mode->bitdepth == 8) index = in[i]; else { size_t j = i * mode->bitdepth; index = readBitsFromReversedStream(&j, in, mode->bitdepth); } /*out of bounds of palette not checked: see lodepng_color_mode_alloc_palette.*/ *r = mode->palette[index * 4 + 0]; *g = mode->palette[index * 4 + 1]; *b = mode->palette[index * 4 + 2]; *a = mode->palette[index * 4 + 3]; } else if(mode->colortype == LCT_GREY_ALPHA) { if(mode->bitdepth == 8) { *r = *g = *b = in[i * 2 + 0]; *a = in[i * 2 + 1]; } else { *r = *g = *b = in[i * 4 + 0]; *a = in[i * 4 + 2]; } } else if(mode->colortype == LCT_RGBA) { if(mode->bitdepth == 8) { *r = in[i * 4 + 0]; *g = in[i * 4 + 1]; *b = in[i * 4 + 2]; *a = in[i * 4 + 3]; } else { *r = in[i * 8 + 0]; *g = in[i * 8 + 2]; *b = in[i * 8 + 4]; *a = in[i * 8 + 6]; } } } /*Similar to getPixelColorRGBA8, but with all the for loops inside of the color mode test cases, optimized to convert the colors much faster, when converting to the common case of RGBA with 8 bit per channel. buffer must be RGBA with enough memory.*/ static void getPixelColorsRGBA8(unsigned char* LODEPNG_RESTRICT buffer, size_t numpixels, const unsigned char* LODEPNG_RESTRICT in, const LodePNGColorMode* mode) { unsigned num_channels = 4; size_t i; if(mode->colortype == LCT_GREY) { if(mode->bitdepth == 8) { for(i = 0; i != numpixels; ++i, buffer += num_channels) { buffer[0] = buffer[1] = buffer[2] = in[i]; buffer[3] = 255; } if(mode->key_defined) { buffer -= numpixels * num_channels; for(i = 0; i != numpixels; ++i, buffer += num_channels) { if(buffer[0] == mode->key_r) buffer[3] = 0; } } } else if(mode->bitdepth == 16) { for(i = 0; i != numpixels; ++i, buffer += num_channels) { buffer[0] = buffer[1] = buffer[2] = in[i * 2]; buffer[3] = mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r ? 0 : 255; } } else { unsigned highest = ((1U << mode->bitdepth) - 1U); /*highest possible value for this bit depth*/ size_t j = 0; for(i = 0; i != numpixels; ++i, buffer += num_channels) { unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth); buffer[0] = buffer[1] = buffer[2] = (value * 255) / highest; buffer[3] = mode->key_defined && value == mode->key_r ? 0 : 255; } } } else if(mode->colortype == LCT_RGB) { if(mode->bitdepth == 8) { for(i = 0; i != numpixels; ++i, buffer += num_channels) { lodepng_memcpy(buffer, &in[i * 3], 3); buffer[3] = 255; } if(mode->key_defined) { buffer -= numpixels * num_channels; for(i = 0; i != numpixels; ++i, buffer += num_channels) { if(buffer[0] == mode->key_r && buffer[1]== mode->key_g && buffer[2] == mode->key_b) buffer[3] = 0; } } } else { for(i = 0; i != numpixels; ++i, buffer += num_channels) { buffer[0] = in[i * 6 + 0]; buffer[1] = in[i * 6 + 2]; buffer[2] = in[i * 6 + 4]; buffer[3] = mode->key_defined && 256U * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r && 256U * in[i * 6 + 2] + in[i * 6 + 3] == mode->key_g && 256U * in[i * 6 + 4] + in[i * 6 + 5] == mode->key_b ? 0 : 255; } } } else if(mode->colortype == LCT_PALETTE) { if(mode->bitdepth == 8) { for(i = 0; i != numpixels; ++i, buffer += num_channels) { unsigned index = in[i]; /*out of bounds of palette not checked: see lodepng_color_mode_alloc_palette.*/ lodepng_memcpy(buffer, &mode->palette[index * 4], 4); } } else { size_t j = 0; for(i = 0; i != numpixels; ++i, buffer += num_channels) { unsigned index = readBitsFromReversedStream(&j, in, mode->bitdepth); /*out of bounds of palette not checked: see lodepng_color_mode_alloc_palette.*/ lodepng_memcpy(buffer, &mode->palette[index * 4], 4); } } } else if(mode->colortype == LCT_GREY_ALPHA) { if(mode->bitdepth == 8) { for(i = 0; i != numpixels; ++i, buffer += num_channels) { buffer[0] = buffer[1] = buffer[2] = in[i * 2 + 0]; buffer[3] = in[i * 2 + 1]; } } else { for(i = 0; i != numpixels; ++i, buffer += num_channels) { buffer[0] = buffer[1] = buffer[2] = in[i * 4 + 0]; buffer[3] = in[i * 4 + 2]; } } } else if(mode->colortype == LCT_RGBA) { if(mode->bitdepth == 8) { lodepng_memcpy(buffer, in, numpixels * 4); } else { for(i = 0; i != numpixels; ++i, buffer += num_channels) { buffer[0] = in[i * 8 + 0]; buffer[1] = in[i * 8 + 2]; buffer[2] = in[i * 8 + 4]; buffer[3] = in[i * 8 + 6]; } } } } /*Similar to getPixelColorsRGBA8, but with 3-channel RGB output.*/ static void getPixelColorsRGB8(unsigned char* LODEPNG_RESTRICT buffer, size_t numpixels, const unsigned char* LODEPNG_RESTRICT in, const LodePNGColorMode* mode) { const unsigned num_channels = 3; size_t i; if(mode->colortype == LCT_GREY) { if(mode->bitdepth == 8) { for(i = 0; i != numpixels; ++i, buffer += num_channels) { buffer[0] = buffer[1] = buffer[2] = in[i]; } } else if(mode->bitdepth == 16) { for(i = 0; i != numpixels; ++i, buffer += num_channels) { buffer[0] = buffer[1] = buffer[2] = in[i * 2]; } } else { unsigned highest = ((1U << mode->bitdepth) - 1U); /*highest possible value for this bit depth*/ size_t j = 0; for(i = 0; i != numpixels; ++i, buffer += num_channels) { unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth); buffer[0] = buffer[1] = buffer[2] = (value * 255) / highest; } } } else if(mode->colortype == LCT_RGB) { if(mode->bitdepth == 8) { lodepng_memcpy(buffer, in, numpixels * 3); } else { for(i = 0; i != numpixels; ++i, buffer += num_channels) { buffer[0] = in[i * 6 + 0]; buffer[1] = in[i * 6 + 2]; buffer[2] = in[i * 6 + 4]; } } } else if(mode->colortype == LCT_PALETTE) { if(mode->bitdepth == 8) { for(i = 0; i != numpixels; ++i, buffer += num_channels) { unsigned index = in[i]; /*out of bounds of palette not checked: see lodepng_color_mode_alloc_palette.*/ lodepng_memcpy(buffer, &mode->palette[index * 4], 3); } } else { size_t j = 0; for(i = 0; i != numpixels; ++i, buffer += num_channels) { unsigned index = readBitsFromReversedStream(&j, in, mode->bitdepth); /*out of bounds of palette not checked: see lodepng_color_mode_alloc_palette.*/ lodepng_memcpy(buffer, &mode->palette[index * 4], 3); } } } else if(mode->colortype == LCT_GREY_ALPHA) { if(mode->bitdepth == 8) { for(i = 0; i != numpixels; ++i, buffer += num_channels) { buffer[0] = buffer[1] = buffer[2] = in[i * 2 + 0]; } } else { for(i = 0; i != numpixels; ++i, buffer += num_channels) { buffer[0] = buffer[1] = buffer[2] = in[i * 4 + 0]; } } } else if(mode->colortype == LCT_RGBA) { if(mode->bitdepth == 8) { for(i = 0; i != numpixels; ++i, buffer += num_channels) { lodepng_memcpy(buffer, &in[i * 4], 3); } } else { for(i = 0; i != numpixels; ++i, buffer += num_channels) { buffer[0] = in[i * 8 + 0]; buffer[1] = in[i * 8 + 2]; buffer[2] = in[i * 8 + 4]; } } } } /*Get RGBA16 color of pixel with index i (y * width + x) from the raw image with given color type, but the given color type must be 16-bit itself.*/ static void getPixelColorRGBA16(unsigned short* r, unsigned short* g, unsigned short* b, unsigned short* a, const unsigned char* in, size_t i, const LodePNGColorMode* mode) { if(mode->colortype == LCT_GREY) { *r = *g = *b = 256 * in[i * 2 + 0] + in[i * 2 + 1]; if(mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r) *a = 0; else *a = 65535; } else if(mode->colortype == LCT_RGB) { *r = 256u * in[i * 6 + 0] + in[i * 6 + 1]; *g = 256u * in[i * 6 + 2] + in[i * 6 + 3]; *b = 256u * in[i * 6 + 4] + in[i * 6 + 5]; if(mode->key_defined && 256u * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r && 256u * in[i * 6 + 2] + in[i * 6 + 3] == mode->key_g && 256u * in[i * 6 + 4] + in[i * 6 + 5] == mode->key_b) *a = 0; else *a = 65535; } else if(mode->colortype == LCT_GREY_ALPHA) { *r = *g = *b = 256u * in[i * 4 + 0] + in[i * 4 + 1]; *a = 256u * in[i * 4 + 2] + in[i * 4 + 3]; } else if(mode->colortype == LCT_RGBA) { *r = 256u * in[i * 8 + 0] + in[i * 8 + 1]; *g = 256u * in[i * 8 + 2] + in[i * 8 + 3]; *b = 256u * in[i * 8 + 4] + in[i * 8 + 5]; *a = 256u * in[i * 8 + 6] + in[i * 8 + 7]; } } unsigned lodepng_convert(unsigned char* out, const unsigned char* in, const LodePNGColorMode* mode_out, const LodePNGColorMode* mode_in, unsigned w, unsigned h) { size_t i; ColorTree tree; size_t numpixels = (size_t)w * (size_t)h; unsigned error = 0; if(mode_in->colortype == LCT_PALETTE && !mode_in->palette) { return 107; /* error: must provide palette if input mode is palette */ } if(lodepng_color_mode_equal(mode_out, mode_in)) { size_t numbytes = lodepng_get_raw_size(w, h, mode_in); lodepng_memcpy(out, in, numbytes); return 0; } if(mode_out->colortype == LCT_PALETTE) { size_t palettesize = mode_out->palettesize; const unsigned char* palette = mode_out->palette; size_t palsize = (size_t)1u << mode_out->bitdepth; /*if the user specified output palette but did not give the values, assume they want the values of the input color type (assuming that one is palette). Note that we never create a new palette ourselves.*/ if(palettesize == 0) { palettesize = mode_in->palettesize; palette = mode_in->palette; /*if the input was also palette with same bitdepth, then the color types are also equal, so copy literally. This to preserve the exact indices that were in the PNG even in case there are duplicate colors in the palette.*/ if(mode_in->colortype == LCT_PALETTE && mode_in->bitdepth == mode_out->bitdepth) { size_t numbytes = lodepng_get_raw_size(w, h, mode_in); lodepng_memcpy(out, in, numbytes); return 0; } } if(palettesize < palsize) palsize = palettesize; color_tree_init(&tree); for(i = 0; i != palsize; ++i) { const unsigned char* p = &palette[i * 4]; error = color_tree_add(&tree, p[0], p[1], p[2], p[3], (unsigned)i); if(error) break; } } if(!error) { if(mode_in->bitdepth == 16 && mode_out->bitdepth == 16) { for(i = 0; i != numpixels; ++i) { unsigned short r = 0, g = 0, b = 0, a = 0; getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode_in); rgba16ToPixel(out, i, mode_out, r, g, b, a); } } else if(mode_out->bitdepth == 8 && mode_out->colortype == LCT_RGBA) { getPixelColorsRGBA8(out, numpixels, in, mode_in); } else if(mode_out->bitdepth == 8 && mode_out->colortype == LCT_RGB) { getPixelColorsRGB8(out, numpixels, in, mode_in); } else { unsigned char r = 0, g = 0, b = 0, a = 0; for(i = 0; i != numpixels; ++i) { getPixelColorRGBA8(&r, &g, &b, &a, in, i, mode_in); error = rgba8ToPixel(out, i, mode_out, &tree, r, g, b, a); if(error) break; } } } if(mode_out->colortype == LCT_PALETTE) { color_tree_cleanup(&tree); } return error; } /* Converts a single rgb color without alpha from one type to another, color bits truncated to their bitdepth. In case of single channel (gray or palette), only the r channel is used. Slow function, do not use to process all pixels of an image. Alpha channel not supported on purpose: this is for bKGD, supporting alpha may prevent it from finding a color in the palette, from the specification it looks like bKGD should ignore the alpha values of the palette since it can use any palette index but doesn't have an alpha channel. Idem with ignoring color key. */ unsigned lodepng_convert_rgb( unsigned* r_out, unsigned* g_out, unsigned* b_out, unsigned r_in, unsigned g_in, unsigned b_in, const LodePNGColorMode* mode_out, const LodePNGColorMode* mode_in) { unsigned r = 0, g = 0, b = 0; unsigned mul = 65535 / ((1u << mode_in->bitdepth) - 1u); /*65535, 21845, 4369, 257, 1*/ unsigned shift = 16 - mode_out->bitdepth; if(mode_in->colortype == LCT_GREY || mode_in->colortype == LCT_GREY_ALPHA) { r = g = b = r_in * mul; } else if(mode_in->colortype == LCT_RGB || mode_in->colortype == LCT_RGBA) { r = r_in * mul; g = g_in * mul; b = b_in * mul; } else if(mode_in->colortype == LCT_PALETTE) { if(r_in >= mode_in->palettesize) return 82; r = mode_in->palette[r_in * 4 + 0] * 257u; g = mode_in->palette[r_in * 4 + 1] * 257u; b = mode_in->palette[r_in * 4 + 2] * 257u; } else { return 31; } /* now convert to output format */ if(mode_out->colortype == LCT_GREY || mode_out->colortype == LCT_GREY_ALPHA) { *r_out = r >> shift ; } else if(mode_out->colortype == LCT_RGB || mode_out->colortype == LCT_RGBA) { *r_out = r >> shift ; *g_out = g >> shift ; *b_out = b >> shift ; } else if(mode_out->colortype == LCT_PALETTE) { unsigned i; /* a 16-bit color cannot be in the palette */ if((r >> 8) != (r & 255) || (g >> 8) != (g & 255) || (b >> 8) != (b & 255)) return 82; for(i = 0; i < mode_out->palettesize; i++) { unsigned j = i * 4; if((r >> 8) == mode_out->palette[j + 0] && (g >> 8) == mode_out->palette[j + 1] && (b >> 8) == mode_out->palette[j + 2]) { *r_out = i; return 0; } } return 82; } else { return 31; } return 0; } #ifdef LODEPNG_COMPILE_ENCODER void lodepng_color_stats_init(LodePNGColorStats* stats) { /*stats*/ stats->colored = 0; stats->key = 0; stats->key_r = stats->key_g = stats->key_b = 0; stats->alpha = 0; stats->numcolors = 0; stats->bits = 1; stats->numpixels = 0; /*settings*/ stats->allow_palette = 1; stats->allow_greyscale = 1; } /*function used for debug purposes with C++*/ /*void printColorStats(LodePNGColorStats* p) { std::cout << "colored: " << (int)p->colored << ", "; std::cout << "key: " << (int)p->key << ", "; std::cout << "key_r: " << (int)p->key_r << ", "; std::cout << "key_g: " << (int)p->key_g << ", "; std::cout << "key_b: " << (int)p->key_b << ", "; std::cout << "alpha: " << (int)p->alpha << ", "; std::cout << "numcolors: " << (int)p->numcolors << ", "; std::cout << "bits: " << (int)p->bits << std::endl; }*/ /*Returns how many bits needed to represent given value (max 8 bit)*/ static unsigned getValueRequiredBits(unsigned char value) { if(value == 0 || value == 255) return 1; /*The scaling of 2-bit and 4-bit values uses multiples of 85 and 17*/ if(value % 17 == 0) return value % 85 == 0 ? 2 : 4; return 8; } /*stats must already have been inited. */ unsigned lodepng_compute_color_stats(LodePNGColorStats* stats, const unsigned char* in, unsigned w, unsigned h, const LodePNGColorMode* mode_in) { size_t i; ColorTree tree; size_t numpixels = (size_t)w * (size_t)h; unsigned error = 0; /* mark things as done already if it would be impossible to have a more expensive case */ unsigned colored_done = lodepng_is_greyscale_type(mode_in) ? 1 : 0; unsigned alpha_done = lodepng_can_have_alpha(mode_in) ? 0 : 1; unsigned numcolors_done = 0; unsigned bpp = lodepng_get_bpp(mode_in); unsigned bits_done = (stats->bits == 1 && bpp == 1) ? 1 : 0; unsigned sixteen = 0; /* whether the input image is 16 bit */ unsigned maxnumcolors = 257; if(bpp <= 8) maxnumcolors = LODEPNG_MIN(257, stats->numcolors + (1u << bpp)); stats->numpixels += numpixels; /*if palette not allowed, no need to compute numcolors*/ if(!stats->allow_palette) numcolors_done = 1; color_tree_init(&tree); /*If the stats was already filled in from previous data, fill its palette in tree and mark things as done already if we know they are the most expensive case already*/ if(stats->alpha) alpha_done = 1; if(stats->colored) colored_done = 1; if(stats->bits == 16) numcolors_done = 1; if(stats->bits >= bpp) bits_done = 1; if(stats->numcolors >= maxnumcolors) numcolors_done = 1; if(!numcolors_done) { for(i = 0; i < stats->numcolors; i++) { const unsigned char* color = &stats->palette[i * 4]; error = color_tree_add(&tree, color[0], color[1], color[2], color[3], i); if(error) goto cleanup; } } /*Check if the 16-bit input is truly 16-bit*/ if(mode_in->bitdepth == 16 && !sixteen) { unsigned short r = 0, g = 0, b = 0, a = 0; for(i = 0; i != numpixels; ++i) { getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode_in); if((r & 255) != ((r >> 8) & 255) || (g & 255) != ((g >> 8) & 255) || (b & 255) != ((b >> 8) & 255) || (a & 255) != ((a >> 8) & 255)) /*first and second byte differ*/ { stats->bits = 16; sixteen = 1; bits_done = 1; numcolors_done = 1; /*counting colors no longer useful, palette doesn't support 16-bit*/ break; } } } if(sixteen) { unsigned short r = 0, g = 0, b = 0, a = 0; for(i = 0; i != numpixels; ++i) { getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode_in); if(!colored_done && (r != g || r != b)) { stats->colored = 1; colored_done = 1; } if(!alpha_done) { unsigned matchkey = (r == stats->key_r && g == stats->key_g && b == stats->key_b); if(a != 65535 && (a != 0 || (stats->key && !matchkey))) { stats->alpha = 1; stats->key = 0; alpha_done = 1; } else if(a == 0 && !stats->alpha && !stats->key) { stats->key = 1; stats->key_r = r; stats->key_g = g; stats->key_b = b; } else if(a == 65535 && stats->key && matchkey) { /* Color key cannot be used if an opaque pixel also has that RGB color. */ stats->alpha = 1; stats->key = 0; alpha_done = 1; } } if(alpha_done && numcolors_done && colored_done && bits_done) break; } if(stats->key && !stats->alpha) { for(i = 0; i != numpixels; ++i) { getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode_in); if(a != 0 && r == stats->key_r && g == stats->key_g && b == stats->key_b) { /* Color key cannot be used if an opaque pixel also has that RGB color. */ stats->alpha = 1; stats->key = 0; alpha_done = 1; } } } } else /* < 16-bit */ { unsigned char r = 0, g = 0, b = 0, a = 0; for(i = 0; i != numpixels; ++i) { getPixelColorRGBA8(&r, &g, &b, &a, in, i, mode_in); if(!bits_done && stats->bits < 8) { /*only r is checked, < 8 bits is only relevant for grayscale*/ unsigned bits = getValueRequiredBits(r); if(bits > stats->bits) stats->bits = bits; } bits_done = (stats->bits >= bpp); if(!colored_done && (r != g || r != b)) { stats->colored = 1; colored_done = 1; if(stats->bits < 8) stats->bits = 8; /*PNG has no colored modes with less than 8-bit per channel*/ } if(!alpha_done) { unsigned matchkey = (r == stats->key_r && g == stats->key_g && b == stats->key_b); if(a != 255 && (a != 0 || (stats->key && !matchkey))) { stats->alpha = 1; stats->key = 0; alpha_done = 1; if(stats->bits < 8) stats->bits = 8; /*PNG has no alphachannel modes with less than 8-bit per channel*/ } else if(a == 0 && !stats->alpha && !stats->key) { stats->key = 1; stats->key_r = r; stats->key_g = g; stats->key_b = b; } else if(a == 255 && stats->key && matchkey) { /* Color key cannot be used if an opaque pixel also has that RGB color. */ stats->alpha = 1; stats->key = 0; alpha_done = 1; if(stats->bits < 8) stats->bits = 8; /*PNG has no alphachannel modes with less than 8-bit per channel*/ } } if(!numcolors_done) { if(!color_tree_has(&tree, r, g, b, a)) { error = color_tree_add(&tree, r, g, b, a, stats->numcolors); if(error) goto cleanup; if(stats->numcolors < 256) { unsigned char* p = stats->palette; unsigned n = stats->numcolors; p[n * 4 + 0] = r; p[n * 4 + 1] = g; p[n * 4 + 2] = b; p[n * 4 + 3] = a; } ++stats->numcolors; numcolors_done = stats->numcolors >= maxnumcolors; } } if(alpha_done && numcolors_done && colored_done && bits_done) break; } if(stats->key && !stats->alpha) { for(i = 0; i != numpixels; ++i) { getPixelColorRGBA8(&r, &g, &b, &a, in, i, mode_in); if(a != 0 && r == stats->key_r && g == stats->key_g && b == stats->key_b) { /* Color key cannot be used if an opaque pixel also has that RGB color. */ stats->alpha = 1; stats->key = 0; alpha_done = 1; if(stats->bits < 8) stats->bits = 8; /*PNG has no alphachannel modes with less than 8-bit per channel*/ } } } /*make the stats's key always 16-bit for consistency - repeat each byte twice*/ stats->key_r += (stats->key_r << 8); stats->key_g += (stats->key_g << 8); stats->key_b += (stats->key_b << 8); } cleanup: color_tree_cleanup(&tree); return error; } #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS /*Adds a single color to the color stats. The stats must already have been inited. The color must be given as 16-bit (with 2 bytes repeating for 8-bit and 65535 for opaque alpha channel). This function is expensive, do not call it for all pixels of an image but only for a few additional values. */ static unsigned lodepng_color_stats_add(LodePNGColorStats* stats, unsigned r, unsigned g, unsigned b, unsigned a) { unsigned error = 0; unsigned char image[8]; LodePNGColorMode mode; lodepng_color_mode_init(&mode); image[0] = r >> 8; image[1] = r; image[2] = g >> 8; image[3] = g; image[4] = b >> 8; image[5] = b; image[6] = a >> 8; image[7] = a; mode.bitdepth = 16; mode.colortype = LCT_RGBA; error = lodepng_compute_color_stats(stats, image, 1, 1, &mode); lodepng_color_mode_cleanup(&mode); return error; } #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ /*Computes a minimal PNG color model that can contain all colors as indicated by the stats. The stats should be computed with lodepng_compute_color_stats. mode_in is raw color profile of the image the stats were computed on, to copy palette order from when relevant. Minimal PNG color model means the color type and bit depth that gives smallest amount of bits in the output image, e.g. gray if only grayscale pixels, palette if less than 256 colors, color key if only single transparent color, ... This is used if auto_convert is enabled (it is by default). */ static unsigned auto_choose_color(LodePNGColorMode* mode_out, const LodePNGColorMode* mode_in, const LodePNGColorStats* stats) { unsigned error = 0; unsigned palettebits; size_t i, n; size_t numpixels = stats->numpixels; unsigned palette_ok, gray_ok; unsigned alpha = stats->alpha; unsigned key = stats->key; unsigned bits = stats->bits; mode_out->key_defined = 0; if(key && numpixels <= 16) { alpha = 1; /*too few pixels to justify tRNS chunk overhead*/ key = 0; if(bits < 8) bits = 8; /*PNG has no alphachannel modes with less than 8-bit per channel*/ } gray_ok = !stats->colored; if(!stats->allow_greyscale) gray_ok = 0; if(!gray_ok && bits < 8) bits = 8; n = stats->numcolors; palettebits = n <= 2 ? 1 : (n <= 4 ? 2 : (n <= 16 ? 4 : 8)); palette_ok = n <= 256 && bits <= 8 && n != 0; /*n==0 means likely numcolors wasn't computed*/ if(numpixels < n * 2) palette_ok = 0; /*don't add palette overhead if image has only a few pixels*/ if(gray_ok && !alpha && bits <= palettebits) palette_ok = 0; /*gray is less overhead*/ if(!stats->allow_palette) palette_ok = 0; if(palette_ok) { const unsigned char* p = stats->palette; lodepng_palette_clear(mode_out); /*remove potential earlier palette*/ for(i = 0; i != stats->numcolors; ++i) { error = lodepng_palette_add(mode_out, p[i * 4 + 0], p[i * 4 + 1], p[i * 4 + 2], p[i * 4 + 3]); if(error) break; } mode_out->colortype = LCT_PALETTE; mode_out->bitdepth = palettebits; if(mode_in->colortype == LCT_PALETTE && mode_in->palettesize >= mode_out->palettesize && mode_in->bitdepth == mode_out->bitdepth) { /*If input should have same palette colors, keep original to preserve its order and prevent conversion*/ lodepng_color_mode_cleanup(mode_out); /*clears palette, keeps the above set colortype and bitdepth fields as-is*/ lodepng_color_mode_copy(mode_out, mode_in); } } else /*8-bit or 16-bit per channel*/ { mode_out->bitdepth = bits; mode_out->colortype = alpha ? (gray_ok ? LCT_GREY_ALPHA : LCT_RGBA) : (gray_ok ? LCT_GREY : LCT_RGB); if(key) { unsigned mask = (1u << mode_out->bitdepth) - 1u; /*stats always uses 16-bit, mask converts it*/ mode_out->key_r = stats->key_r & mask; mode_out->key_g = stats->key_g & mask; mode_out->key_b = stats->key_b & mask; mode_out->key_defined = 1; } } return error; } #endif /* #ifdef LODEPNG_COMPILE_ENCODER */ /* Paeth predictor, used by PNG filter type 4 The parameters are of type short, but should come from unsigned chars, the shorts are only needed to make the paeth calculation correct. */ static unsigned char paethPredictor(short a, short b, short c) { short pa = LODEPNG_ABS(b - c); short pb = LODEPNG_ABS(a - c); short pc = LODEPNG_ABS(a + b - c - c); /* return input value associated with smallest of pa, pb, pc (with certain priority if equal) */ if(pb < pa) { a = b; pa = pb; } return (pc < pa) ? c : a; } /*shared values used by multiple Adam7 related functions*/ static const unsigned ADAM7_IX[7] = { 0, 4, 0, 2, 0, 1, 0 }; /*x start values*/ static const unsigned ADAM7_IY[7] = { 0, 0, 4, 0, 2, 0, 1 }; /*y start values*/ static const unsigned ADAM7_DX[7] = { 8, 8, 4, 4, 2, 2, 1 }; /*x delta values*/ static const unsigned ADAM7_DY[7] = { 8, 8, 8, 4, 4, 2, 2 }; /*y delta values*/ /* Outputs various dimensions and positions in the image related to the Adam7 reduced images. passw: output containing the width of the 7 passes passh: output containing the height of the 7 passes filter_passstart: output containing the index of the start and end of each reduced image with filter bytes padded_passstart output containing the index of the start and end of each reduced image when without filter bytes but with padded scanlines passstart: output containing the index of the start and end of each reduced image without padding between scanlines, but still padding between the images w, h: width and height of non-interlaced image bpp: bits per pixel "padded" is only relevant if bpp is less than 8 and a scanline or image does not end at a full byte */ static void Adam7_getpassvalues(unsigned passw[7], unsigned passh[7], size_t filter_passstart[8], size_t padded_passstart[8], size_t passstart[8], unsigned w, unsigned h, unsigned bpp) { /*the passstart values have 8 values: the 8th one indicates the byte after the end of the 7th (= last) pass*/ unsigned i; /*calculate width and height in pixels of each pass*/ for(i = 0; i != 7; ++i) { passw[i] = (w + ADAM7_DX[i] - ADAM7_IX[i] - 1) / ADAM7_DX[i]; passh[i] = (h + ADAM7_DY[i] - ADAM7_IY[i] - 1) / ADAM7_DY[i]; if(passw[i] == 0) passh[i] = 0; if(passh[i] == 0) passw[i] = 0; } filter_passstart[0] = padded_passstart[0] = passstart[0] = 0; for(i = 0; i != 7; ++i) { /*if passw[i] is 0, it's 0 bytes, not 1 (no filtertype-byte)*/ filter_passstart[i + 1] = filter_passstart[i] + ((passw[i] && passh[i]) ? passh[i] * (1u + (passw[i] * bpp + 7u) / 8u) : 0); /*bits padded if needed to fill full byte at end of each scanline*/ padded_passstart[i + 1] = padded_passstart[i] + passh[i] * ((passw[i] * bpp + 7u) / 8u); /*only padded at end of reduced image*/ passstart[i + 1] = passstart[i] + (passh[i] * passw[i] * bpp + 7u) / 8u; } } #ifdef LODEPNG_COMPILE_DECODER /* ////////////////////////////////////////////////////////////////////////// */ /* / PNG Decoder / */ /* ////////////////////////////////////////////////////////////////////////// */ /*read the information from the header and store it in the LodePNGInfo. return value is error*/ unsigned lodepng_inspect(unsigned* w, unsigned* h, LodePNGState* state, const unsigned char* in, size_t insize) { unsigned width, height; LodePNGInfo* info = &state->info_png; if(insize == 0 || in == 0) { CERROR_RETURN_ERROR(state->error, 48); /*error: the given data is empty*/ } if(insize < 33) { CERROR_RETURN_ERROR(state->error, 27); /*error: the data length is smaller than the length of a PNG header*/ } /*when decoding a new PNG image, make sure all parameters created after previous decoding are reset*/ /* TODO: remove this. One should use a new LodePNGState for new sessions */ lodepng_info_cleanup(info); lodepng_info_init(info); if(in[0] != 137 || in[1] != 80 || in[2] != 78 || in[3] != 71 || in[4] != 13 || in[5] != 10 || in[6] != 26 || in[7] != 10) { CERROR_RETURN_ERROR(state->error, 28); /*error: the first 8 bytes are not the correct PNG signature*/ } if(lodepng_chunk_length(in + 8) != 13) { CERROR_RETURN_ERROR(state->error, 94); /*error: header size must be 13 bytes*/ } if(!lodepng_chunk_type_equals(in + 8, "IHDR")) { CERROR_RETURN_ERROR(state->error, 29); /*error: it doesn't start with a IHDR chunk!*/ } /*read the values given in the header*/ width = lodepng_read32bitInt(&in[16]); height = lodepng_read32bitInt(&in[20]); /*TODO: remove the undocumented feature that allows to give null pointers to width or height*/ if(w) *w = width; if(h) *h = height; info->color.bitdepth = in[24]; info->color.colortype = (LodePNGColorType)in[25]; info->compression_method = in[26]; info->filter_method = in[27]; info->interlace_method = in[28]; /*errors returned only after the parsing so other values are still output*/ /*error: invalid image size*/ if(width == 0 || height == 0) CERROR_RETURN_ERROR(state->error, 93); /*error: invalid colortype or bitdepth combination*/ state->error = checkColorValidity(info->color.colortype, info->color.bitdepth); if(state->error) return state->error; /*error: only compression method 0 is allowed in the specification*/ if(info->compression_method != 0) CERROR_RETURN_ERROR(state->error, 32); /*error: only filter method 0 is allowed in the specification*/ if(info->filter_method != 0) CERROR_RETURN_ERROR(state->error, 33); /*error: only interlace methods 0 and 1 exist in the specification*/ if(info->interlace_method > 1) CERROR_RETURN_ERROR(state->error, 34); if(!state->decoder.ignore_crc) { unsigned CRC = lodepng_read32bitInt(&in[29]); unsigned checksum = lodepng_crc32(&in[12], 17); if(CRC != checksum) { CERROR_RETURN_ERROR(state->error, 57); /*invalid CRC*/ } } return state->error; } static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scanline, const unsigned char* precon, size_t bytewidth, unsigned char filterType, size_t length) { /* For PNG filter method 0 unfilter a PNG image scanline by scanline. when the pixels are smaller than 1 byte, the filter works byte per byte (bytewidth = 1) precon is the previous unfiltered scanline, recon the result, scanline the current one the incoming scanlines do NOT include the filtertype byte, that one is given in the parameter filterType instead recon and scanline MAY be the same memory address! precon must be disjoint. */ size_t i; switch(filterType) { case 0: for(i = 0; i != length; ++i) recon[i] = scanline[i]; break; case 1: { size_t j = 0; for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i]; for(i = bytewidth; i != length; ++i, ++j) recon[i] = scanline[i] + recon[j]; break; } case 2: if(precon) { for(i = 0; i != length; ++i) recon[i] = scanline[i] + precon[i]; } else { for(i = 0; i != length; ++i) recon[i] = scanline[i]; } break; case 3: if(precon) { size_t j = 0; for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i] + (precon[i] >> 1u); /* Unroll independent paths of this predictor. A 6x and 8x version is also possible but that adds too much code. Whether this speeds up anything depends on compiler and settings. */ if(bytewidth >= 4) { for(; i + 3 < length; i += 4, j += 4) { unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2], s3 = scanline[i + 3]; unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2], r3 = recon[j + 3]; unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2], p3 = precon[i + 3]; recon[i + 0] = s0 + ((r0 + p0) >> 1u); recon[i + 1] = s1 + ((r1 + p1) >> 1u); recon[i + 2] = s2 + ((r2 + p2) >> 1u); recon[i + 3] = s3 + ((r3 + p3) >> 1u); } } else if(bytewidth >= 3) { for(; i + 2 < length; i += 3, j += 3) { unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2]; unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2]; unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2]; recon[i + 0] = s0 + ((r0 + p0) >> 1u); recon[i + 1] = s1 + ((r1 + p1) >> 1u); recon[i + 2] = s2 + ((r2 + p2) >> 1u); } } else if(bytewidth >= 2) { for(; i + 1 < length; i += 2, j += 2) { unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1]; unsigned char r0 = recon[j + 0], r1 = recon[j + 1]; unsigned char p0 = precon[i + 0], p1 = precon[i + 1]; recon[i + 0] = s0 + ((r0 + p0) >> 1u); recon[i + 1] = s1 + ((r1 + p1) >> 1u); } } for(; i != length; ++i, ++j) recon[i] = scanline[i] + ((recon[j] + precon[i]) >> 1u); } else { size_t j = 0; for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i]; for(i = bytewidth; i != length; ++i, ++j) recon[i] = scanline[i] + (recon[j] >> 1u); } break; case 4: if(precon) { size_t j = 0; for(i = 0; i != bytewidth; ++i) { recon[i] = (scanline[i] + precon[i]); /*paethPredictor(0, precon[i], 0) is always precon[i]*/ } /* Unroll independent paths of the paeth predictor. A 6x and 8x version is also possible but that adds too much code. Whether this speeds up anything depends on compiler and settings. */ if(bytewidth >= 4) { for(; i + 3 < length; i += 4, j += 4) { unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2], s3 = scanline[i + 3]; unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2], r3 = recon[j + 3]; unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2], p3 = precon[i + 3]; unsigned char q0 = precon[j + 0], q1 = precon[j + 1], q2 = precon[j + 2], q3 = precon[j + 3]; recon[i + 0] = s0 + paethPredictor(r0, p0, q0); recon[i + 1] = s1 + paethPredictor(r1, p1, q1); recon[i + 2] = s2 + paethPredictor(r2, p2, q2); recon[i + 3] = s3 + paethPredictor(r3, p3, q3); } } else if(bytewidth >= 3) { for(; i + 2 < length; i += 3, j += 3) { unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2]; unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2]; unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2]; unsigned char q0 = precon[j + 0], q1 = precon[j + 1], q2 = precon[j + 2]; recon[i + 0] = s0 + paethPredictor(r0, p0, q0); recon[i + 1] = s1 + paethPredictor(r1, p1, q1); recon[i + 2] = s2 + paethPredictor(r2, p2, q2); } } else if(bytewidth >= 2) { for(; i + 1 < length; i += 2, j += 2) { unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1]; unsigned char r0 = recon[j + 0], r1 = recon[j + 1]; unsigned char p0 = precon[i + 0], p1 = precon[i + 1]; unsigned char q0 = precon[j + 0], q1 = precon[j + 1]; recon[i + 0] = s0 + paethPredictor(r0, p0, q0); recon[i + 1] = s1 + paethPredictor(r1, p1, q1); } } for(; i != length; ++i, ++j) { recon[i] = (scanline[i] + paethPredictor(recon[i - bytewidth], precon[i], precon[j])); } } else { size_t j = 0; for(i = 0; i != bytewidth; ++i) { recon[i] = scanline[i]; } for(i = bytewidth; i != length; ++i, ++j) { /*paethPredictor(recon[i - bytewidth], 0, 0) is always recon[i - bytewidth]*/ recon[i] = (scanline[i] + recon[j]); } } break; default: return 36; /*error: invalid filter type given*/ } return 0; } static unsigned unfilter(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, unsigned bpp) { /* For PNG filter method 0 this function unfilters a single image (e.g. without interlacing this is called once, with Adam7 seven times) out must have enough bytes allocated already, in must have the scanlines + 1 filtertype byte per scanline w and h are image dimensions or dimensions of reduced image, bpp is bits per pixel in and out are allowed to be the same memory address (but aren't the same size since in has the extra filter bytes) */ unsigned y; unsigned char* prevline = 0; /*bytewidth is used for filtering, is 1 when bpp < 8, number of bytes per pixel otherwise*/ size_t bytewidth = (bpp + 7u) / 8u; /*the width of a scanline in bytes, not including the filter type*/ size_t linebytes = lodepng_get_raw_size_idat(w, 1, bpp) - 1u; for(y = 0; y < h; ++y) { size_t outindex = linebytes * y; size_t inindex = (1 + linebytes) * y; /*the extra filterbyte added to each row*/ unsigned char filterType = in[inindex]; CERROR_TRY_RETURN(unfilterScanline(&out[outindex], &in[inindex + 1], prevline, bytewidth, filterType, linebytes)); prevline = &out[outindex]; } return 0; } /* in: Adam7 interlaced image, with no padding bits between scanlines, but between reduced images so that each reduced image starts at a byte. out: the same pixels, but re-ordered so that they're now a non-interlaced image with size w*h bpp: bits per pixel out has the following size in bits: w * h * bpp. in is possibly bigger due to padding bits between reduced images. out must be big enough AND must be 0 everywhere if bpp < 8 in the current implementation (because that's likely a little bit faster) NOTE: comments about padding bits are only relevant if bpp < 8 */ static void Adam7_deinterlace(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, unsigned bpp) { unsigned passw[7], passh[7]; size_t filter_passstart[8], padded_passstart[8], passstart[8]; unsigned i; Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp); if(bpp >= 8) { for(i = 0; i != 7; ++i) { unsigned x, y, b; size_t bytewidth = bpp / 8u; for(y = 0; y < passh[i]; ++y) for(x = 0; x < passw[i]; ++x) { size_t pixelinstart = passstart[i] + (y * passw[i] + x) * bytewidth; size_t pixeloutstart = ((ADAM7_IY[i] + (size_t)y * ADAM7_DY[i]) * (size_t)w + ADAM7_IX[i] + (size_t)x * ADAM7_DX[i]) * bytewidth; for(b = 0; b < bytewidth; ++b) { out[pixeloutstart + b] = in[pixelinstart + b]; } } } } else /*bpp < 8: Adam7 with pixels < 8 bit is a bit trickier: with bit pointers*/ { for(i = 0; i != 7; ++i) { unsigned x, y, b; unsigned ilinebits = bpp * passw[i]; unsigned olinebits = bpp * w; size_t obp, ibp; /*bit pointers (for out and in buffer)*/ for(y = 0; y < passh[i]; ++y) for(x = 0; x < passw[i]; ++x) { ibp = (8 * passstart[i]) + (y * ilinebits + x * bpp); obp = (ADAM7_IY[i] + (size_t)y * ADAM7_DY[i]) * olinebits + (ADAM7_IX[i] + (size_t)x * ADAM7_DX[i]) * bpp; for(b = 0; b < bpp; ++b) { unsigned char bit = readBitFromReversedStream(&ibp, in); setBitOfReversedStream(&obp, out, bit); } } } } } static void removePaddingBits(unsigned char* out, const unsigned char* in, size_t olinebits, size_t ilinebits, unsigned h) { /* After filtering there are still padding bits if scanlines have non multiple of 8 bit amounts. They need to be removed (except at last scanline of (Adam7-reduced) image) before working with pure image buffers for the Adam7 code, the color convert code and the output to the user. in and out are allowed to be the same buffer, in may also be higher but still overlapping; in must have >= ilinebits*h bits, out must have >= olinebits*h bits, olinebits must be <= ilinebits also used to move bits after earlier such operations happened, e.g. in a sequence of reduced images from Adam7 only useful if (ilinebits - olinebits) is a value in the range 1..7 */ unsigned y; size_t diff = ilinebits - olinebits; size_t ibp = 0, obp = 0; /*input and output bit pointers*/ for(y = 0; y < h; ++y) { size_t x; for(x = 0; x < olinebits; ++x) { unsigned char bit = readBitFromReversedStream(&ibp, in); setBitOfReversedStream(&obp, out, bit); } ibp += diff; } } /*out must be buffer big enough to contain full image, and in must contain the full decompressed data from the IDAT chunks (with filter index bytes and possible padding bits) return value is error*/ static unsigned postProcessScanlines(unsigned char* out, unsigned char* in, unsigned w, unsigned h, const LodePNGInfo* info_png) { /* This function converts the filtered-padded-interlaced data into pure 2D image buffer with the PNG's colortype. Steps: *) if no Adam7: 1) unfilter 2) remove padding bits (= possible extra bits per scanline if bpp < 8) *) if adam7: 1) 7x unfilter 2) 7x remove padding bits 3) Adam7_deinterlace NOTE: the in buffer will be overwritten with intermediate data! */ unsigned bpp = lodepng_get_bpp(&info_png->color); if(bpp == 0) return 31; /*error: invalid colortype*/ if(info_png->interlace_method == 0) { if(bpp < 8 && w * bpp != ((w * bpp + 7u) / 8u) * 8u) { CERROR_TRY_RETURN(unfilter(in, in, w, h, bpp)); removePaddingBits(out, in, w * bpp, ((w * bpp + 7u) / 8u) * 8u, h); } /*we can immediately filter into the out buffer, no other steps needed*/ else CERROR_TRY_RETURN(unfilter(out, in, w, h, bpp)); } else /*interlace_method is 1 (Adam7)*/ { unsigned passw[7], passh[7]; size_t filter_passstart[8], padded_passstart[8], passstart[8]; unsigned i; Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp); for(i = 0; i != 7; ++i) { CERROR_TRY_RETURN(unfilter(&in[padded_passstart[i]], &in[filter_passstart[i]], passw[i], passh[i], bpp)); /*TODO: possible efficiency improvement: if in this reduced image the bits fit nicely in 1 scanline, move bytes instead of bits or move not at all*/ if(bpp < 8) { /*remove padding bits in scanlines; after this there still may be padding bits between the different reduced images: each reduced image still starts nicely at a byte*/ removePaddingBits(&in[passstart[i]], &in[padded_passstart[i]], passw[i] * bpp, ((passw[i] * bpp + 7u) / 8u) * 8u, passh[i]); } } Adam7_deinterlace(out, in, w, h, bpp); } return 0; } static unsigned readChunk_PLTE(LodePNGColorMode* color, const unsigned char* data, size_t chunkLength) { unsigned pos = 0, i; color->palettesize = chunkLength / 3u; if(color->palettesize == 0 || color->palettesize > 256) return 38; /*error: palette too small or big*/ lodepng_color_mode_alloc_palette(color); if(!color->palette && color->palettesize) { color->palettesize = 0; return 83; /*alloc fail*/ } for(i = 0; i != color->palettesize; ++i) { color->palette[4 * i + 0] = data[pos++]; /*R*/ color->palette[4 * i + 1] = data[pos++]; /*G*/ color->palette[4 * i + 2] = data[pos++]; /*B*/ color->palette[4 * i + 3] = 255; /*alpha*/ } return 0; /* OK */ } static unsigned readChunk_tRNS(LodePNGColorMode* color, const unsigned char* data, size_t chunkLength) { unsigned i; if(color->colortype == LCT_PALETTE) { /*error: more alpha values given than there are palette entries*/ if(chunkLength > color->palettesize) return 39; for(i = 0; i != chunkLength; ++i) color->palette[4 * i + 3] = data[i]; } else if(color->colortype == LCT_GREY) { /*error: this chunk must be 2 bytes for grayscale image*/ if(chunkLength != 2) return 30; color->key_defined = 1; color->key_r = color->key_g = color->key_b = 256u * data[0] + data[1]; } else if(color->colortype == LCT_RGB) { /*error: this chunk must be 6 bytes for RGB image*/ if(chunkLength != 6) return 41; color->key_defined = 1; color->key_r = 256u * data[0] + data[1]; color->key_g = 256u * data[2] + data[3]; color->key_b = 256u * data[4] + data[5]; } else return 42; /*error: tRNS chunk not allowed for other color models*/ return 0; /* OK */ } #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS /*background color chunk (bKGD)*/ static unsigned readChunk_bKGD(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) { if(info->color.colortype == LCT_PALETTE) { /*error: this chunk must be 1 byte for indexed color image*/ if(chunkLength != 1) return 43; /*error: invalid palette index, or maybe this chunk appeared before PLTE*/ if(data[0] >= info->color.palettesize) return 103; info->background_defined = 1; info->background_r = info->background_g = info->background_b = data[0]; } else if(info->color.colortype == LCT_GREY || info->color.colortype == LCT_GREY_ALPHA) { /*error: this chunk must be 2 bytes for grayscale image*/ if(chunkLength != 2) return 44; /*the values are truncated to bitdepth in the PNG file*/ info->background_defined = 1; info->background_r = info->background_g = info->background_b = 256u * data[0] + data[1]; } else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_RGBA) { /*error: this chunk must be 6 bytes for grayscale image*/ if(chunkLength != 6) return 45; /*the values are truncated to bitdepth in the PNG file*/ info->background_defined = 1; info->background_r = 256u * data[0] + data[1]; info->background_g = 256u * data[2] + data[3]; info->background_b = 256u * data[4] + data[5]; } return 0; /* OK */ } /*text chunk (tEXt)*/ static unsigned readChunk_tEXt(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) { unsigned error = 0; char *key = 0, *str = 0; while(!error) /*not really a while loop, only used to break on error*/ { unsigned length, string2_begin; length = 0; while(length < chunkLength && data[length] != 0) ++length; /*even though it's not allowed by the standard, no error is thrown if there's no null termination char, if the text is empty*/ if(length < 1 || length > 79) CERROR_BREAK(error, 89); /*keyword too short or long*/ key = (char*)lodepng_malloc(length + 1); if(!key) CERROR_BREAK(error, 83); /*alloc fail*/ lodepng_memcpy(key, data, length); key[length] = 0; string2_begin = length + 1; /*skip keyword null terminator*/ length = (unsigned)(chunkLength < string2_begin ? 0 : chunkLength - string2_begin); str = (char*)lodepng_malloc(length + 1); if(!str) CERROR_BREAK(error, 83); /*alloc fail*/ lodepng_memcpy(str, data + string2_begin, length); str[length] = 0; error = lodepng_add_text(info, key, str); break; } lodepng_free(key); lodepng_free(str); return error; } /*compressed text chunk (zTXt)*/ static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecoderSettings* decoder, const unsigned char* data, size_t chunkLength) { unsigned error = 0; /*copy the object to change parameters in it*/ LodePNGDecompressSettings zlibsettings = decoder->zlibsettings; unsigned length, string2_begin; char *key = 0; unsigned char* str = 0; size_t size = 0; while(!error) /*not really a while loop, only used to break on error*/ { for(length = 0; length < chunkLength && data[length] != 0; ++length) ; if(length + 2 >= chunkLength) CERROR_BREAK(error, 75); /*no null termination, corrupt?*/ if(length < 1 || length > 79) CERROR_BREAK(error, 89); /*keyword too short or long*/ key = (char*)lodepng_malloc(length + 1); if(!key) CERROR_BREAK(error, 83); /*alloc fail*/ lodepng_memcpy(key, data, length); key[length] = 0; if(data[length + 1] != 0) CERROR_BREAK(error, 72); /*the 0 byte indicating compression must be 0*/ string2_begin = length + 2; if(string2_begin > chunkLength) CERROR_BREAK(error, 75); /*no null termination, corrupt?*/ length = (unsigned)chunkLength - string2_begin; zlibsettings.max_output_size = decoder->max_text_size; /*will fail if zlib error, e.g. if length is too small*/ error = zlib_decompress(&str, &size, 0, &data[string2_begin], length, &zlibsettings); /*error: compressed text larger than decoder->max_text_size*/ if(error && size > zlibsettings.max_output_size) error = 112; if(error) break; error = lodepng_add_text_sized(info, key, (char*)str, size); break; } lodepng_free(key); lodepng_free(str); return error; } /*international text chunk (iTXt)*/ static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecoderSettings* decoder, const unsigned char* data, size_t chunkLength) { unsigned error = 0; unsigned i; /*copy the object to change parameters in it*/ LodePNGDecompressSettings zlibsettings = decoder->zlibsettings; unsigned length, begin, compressed; char *key = 0, *langtag = 0, *transkey = 0; while(!error) /*not really a while loop, only used to break on error*/ { /*Quick check if the chunk length isn't too small. Even without check it'd still fail with other error checks below if it's too short. This just gives a different error code.*/ if(chunkLength < 5) CERROR_BREAK(error, 30); /*iTXt chunk too short*/ /*read the key*/ for(length = 0; length < chunkLength && data[length] != 0; ++length) ; if(length + 3 >= chunkLength) CERROR_BREAK(error, 75); /*no null termination char, corrupt?*/ if(length < 1 || length > 79) CERROR_BREAK(error, 89); /*keyword too short or long*/ key = (char*)lodepng_malloc(length + 1); if(!key) CERROR_BREAK(error, 83); /*alloc fail*/ lodepng_memcpy(key, data, length); key[length] = 0; /*read the compression method*/ compressed = data[length + 1]; if(data[length + 2] != 0) CERROR_BREAK(error, 72); /*the 0 byte indicating compression must be 0*/ /*even though it's not allowed by the standard, no error is thrown if there's no null termination char, if the text is empty for the next 3 texts*/ /*read the langtag*/ begin = length + 3; length = 0; for(i = begin; i < chunkLength && data[i] != 0; ++i) ++length; langtag = (char*)lodepng_malloc(length + 1); if(!langtag) CERROR_BREAK(error, 83); /*alloc fail*/ lodepng_memcpy(langtag, data + begin, length); langtag[length] = 0; /*read the transkey*/ begin += length + 1; length = 0; for(i = begin; i < chunkLength && data[i] != 0; ++i) ++length; transkey = (char*)lodepng_malloc(length + 1); if(!transkey) CERROR_BREAK(error, 83); /*alloc fail*/ lodepng_memcpy(transkey, data + begin, length); transkey[length] = 0; /*read the actual text*/ begin += length + 1; length = (unsigned)chunkLength < begin ? 0 : (unsigned)chunkLength - begin; if(compressed) { unsigned char* str = 0; size_t size = 0; zlibsettings.max_output_size = decoder->max_text_size; /*will fail if zlib error, e.g. if length is too small*/ error = zlib_decompress(&str, &size, 0, &data[begin], length, &zlibsettings); /*error: compressed text larger than decoder->max_text_size*/ if(error && size > zlibsettings.max_output_size) error = 112; if(!error) error = lodepng_add_itext_sized(info, key, langtag, transkey, (char*)str, size); lodepng_free(str); } else { error = lodepng_add_itext_sized(info, key, langtag, transkey, (char*)(data + begin), length); } break; } lodepng_free(key); lodepng_free(langtag); lodepng_free(transkey); return error; } static unsigned readChunk_tIME(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) { if(chunkLength != 7) return 73; /*invalid tIME chunk size*/ info->time_defined = 1; info->time.year = 256u * data[0] + data[1]; info->time.month = data[2]; info->time.day = data[3]; info->time.hour = data[4]; info->time.minute = data[5]; info->time.second = data[6]; return 0; /* OK */ } static unsigned readChunk_pHYs(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) { if(chunkLength != 9) return 74; /*invalid pHYs chunk size*/ info->phys_defined = 1; info->phys_x = 16777216u * data[0] + 65536u * data[1] + 256u * data[2] + data[3]; info->phys_y = 16777216u * data[4] + 65536u * data[5] + 256u * data[6] + data[7]; info->phys_unit = data[8]; return 0; /* OK */ } static unsigned readChunk_gAMA(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) { if(chunkLength != 4) return 96; /*invalid gAMA chunk size*/ info->gama_defined = 1; info->gama_gamma = 16777216u * data[0] + 65536u * data[1] + 256u * data[2] + data[3]; return 0; /* OK */ } static unsigned readChunk_cHRM(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) { if(chunkLength != 32) return 97; /*invalid cHRM chunk size*/ info->chrm_defined = 1; info->chrm_white_x = 16777216u * data[ 0] + 65536u * data[ 1] + 256u * data[ 2] + data[ 3]; info->chrm_white_y = 16777216u * data[ 4] + 65536u * data[ 5] + 256u * data[ 6] + data[ 7]; info->chrm_red_x = 16777216u * data[ 8] + 65536u * data[ 9] + 256u * data[10] + data[11]; info->chrm_red_y = 16777216u * data[12] + 65536u * data[13] + 256u * data[14] + data[15]; info->chrm_green_x = 16777216u * data[16] + 65536u * data[17] + 256u * data[18] + data[19]; info->chrm_green_y = 16777216u * data[20] + 65536u * data[21] + 256u * data[22] + data[23]; info->chrm_blue_x = 16777216u * data[24] + 65536u * data[25] + 256u * data[26] + data[27]; info->chrm_blue_y = 16777216u * data[28] + 65536u * data[29] + 256u * data[30] + data[31]; return 0; /* OK */ } static unsigned readChunk_sRGB(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) { if(chunkLength != 1) return 98; /*invalid sRGB chunk size (this one is never ignored)*/ info->srgb_defined = 1; info->srgb_intent = data[0]; return 0; /* OK */ } static unsigned readChunk_iCCP(LodePNGInfo* info, const LodePNGDecoderSettings* decoder, const unsigned char* data, size_t chunkLength) { unsigned error = 0; unsigned i; size_t size = 0; /*copy the object to change parameters in it*/ LodePNGDecompressSettings zlibsettings = decoder->zlibsettings; unsigned length, string2_begin; info->iccp_defined = 1; if(info->iccp_name) lodepng_clear_icc(info); for(length = 0; length < chunkLength && data[length] != 0; ++length) ; if(length + 2 >= chunkLength) return 75; /*no null termination, corrupt?*/ if(length < 1 || length > 79) return 89; /*keyword too short or long*/ info->iccp_name = (char*)lodepng_malloc(length + 1); if(!info->iccp_name) return 83; /*alloc fail*/ info->iccp_name[length] = 0; for(i = 0; i != length; ++i) info->iccp_name[i] = (char)data[i]; if(data[length + 1] != 0) return 72; /*the 0 byte indicating compression must be 0*/ string2_begin = length + 2; if(string2_begin > chunkLength) return 75; /*no null termination, corrupt?*/ length = (unsigned)chunkLength - string2_begin; zlibsettings.max_output_size = decoder->max_icc_size; error = zlib_decompress(&info->iccp_profile, &size, 0, &data[string2_begin], length, &zlibsettings); /*error: ICC profile larger than decoder->max_icc_size*/ if(error && size > zlibsettings.max_output_size) error = 113; info->iccp_profile_size = size; if(!error && !info->iccp_profile_size) error = 100; /*invalid ICC profile size*/ return error; } /*significant bits chunk (sBIT)*/ static unsigned readChunk_sBIT(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) { unsigned bitdepth = (info->color.colortype == LCT_PALETTE) ? 8 : info->color.bitdepth; if(info->color.colortype == LCT_GREY) { /*error: this chunk must be 1 bytes for grayscale image*/ if(chunkLength != 1) return 114; if(data[0] == 0 || data[0] > bitdepth) return 115; info->sbit_defined = 1; info->sbit_r = info->sbit_g = info->sbit_b = data[0]; /*setting g and b is not required, but sensible*/ } else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_PALETTE) { /*error: this chunk must be 3 bytes for RGB and palette image*/ if(chunkLength != 3) return 114; if(data[0] == 0 || data[1] == 0 || data[2] == 0) return 115; if(data[0] > bitdepth || data[1] > bitdepth || data[2] > bitdepth) return 115; info->sbit_defined = 1; info->sbit_r = data[0]; info->sbit_g = data[1]; info->sbit_b = data[2]; } else if(info->color.colortype == LCT_GREY_ALPHA) { /*error: this chunk must be 2 byte for grayscale with alpha image*/ if(chunkLength != 2) return 114; if(data[0] == 0 || data[1] == 0) return 115; if(data[0] > bitdepth || data[1] > bitdepth) return 115; info->sbit_defined = 1; info->sbit_r = info->sbit_g = info->sbit_b = data[0]; /*setting g and b is not required, but sensible*/ info->sbit_a = data[1]; } else if(info->color.colortype == LCT_RGBA) { /*error: this chunk must be 4 bytes for grayscale image*/ if(chunkLength != 4) return 114; if(data[0] == 0 || data[1] == 0 || data[2] == 0 || data[3] == 0) return 115; if(data[0] > bitdepth || data[1] > bitdepth || data[2] > bitdepth || data[3] > bitdepth) return 115; info->sbit_defined = 1; info->sbit_r = data[0]; info->sbit_g = data[1]; info->sbit_b = data[2]; info->sbit_a = data[3]; } return 0; /* OK */ } #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos, const unsigned char* in, size_t insize) { const unsigned char* chunk = in + pos; unsigned chunkLength; const unsigned char* data; unsigned unhandled = 0; unsigned error = 0; if(pos + 4 > insize) return 30; chunkLength = lodepng_chunk_length(chunk); if(chunkLength > 2147483647) return 63; data = lodepng_chunk_data_const(chunk); if(chunkLength + 12 > insize - pos) return 30; if(lodepng_chunk_type_equals(chunk, "PLTE")) { error = readChunk_PLTE(&state->info_png.color, data, chunkLength); } else if(lodepng_chunk_type_equals(chunk, "tRNS")) { error = readChunk_tRNS(&state->info_png.color, data, chunkLength); #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS } else if(lodepng_chunk_type_equals(chunk, "bKGD")) { error = readChunk_bKGD(&state->info_png, data, chunkLength); } else if(lodepng_chunk_type_equals(chunk, "tEXt")) { error = readChunk_tEXt(&state->info_png, data, chunkLength); } else if(lodepng_chunk_type_equals(chunk, "zTXt")) { error = readChunk_zTXt(&state->info_png, &state->decoder, data, chunkLength); } else if(lodepng_chunk_type_equals(chunk, "iTXt")) { error = readChunk_iTXt(&state->info_png, &state->decoder, data, chunkLength); } else if(lodepng_chunk_type_equals(chunk, "tIME")) { error = readChunk_tIME(&state->info_png, data, chunkLength); } else if(lodepng_chunk_type_equals(chunk, "pHYs")) { error = readChunk_pHYs(&state->info_png, data, chunkLength); } else if(lodepng_chunk_type_equals(chunk, "gAMA")) { error = readChunk_gAMA(&state->info_png, data, chunkLength); } else if(lodepng_chunk_type_equals(chunk, "cHRM")) { error = readChunk_cHRM(&state->info_png, data, chunkLength); } else if(lodepng_chunk_type_equals(chunk, "sRGB")) { error = readChunk_sRGB(&state->info_png, data, chunkLength); } else if(lodepng_chunk_type_equals(chunk, "iCCP")) { error = readChunk_iCCP(&state->info_png, &state->decoder, data, chunkLength); } else if(lodepng_chunk_type_equals(chunk, "sBIT")) { error = readChunk_sBIT(&state->info_png, data, chunkLength); #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ } else { /* unhandled chunk is ok (is not an error) */ unhandled = 1; } if(!error && !unhandled && !state->decoder.ignore_crc) { if(lodepng_chunk_check_crc(chunk)) return 57; /*invalid CRC*/ } return error; } /*read a PNG, the result will be in the same color type as the PNG (hence "generic")*/ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h, LodePNGState* state, const unsigned char* in, size_t insize) { unsigned char IEND = 0; const unsigned char* chunk; /*points to beginning of next chunk*/ unsigned char* idat; /*the data from idat chunks, zlib compressed*/ size_t idatsize = 0; unsigned char* scanlines = 0; size_t scanlines_size = 0, expected_size = 0; size_t outsize = 0; /*for unknown chunk order*/ unsigned unknown = 0; #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS unsigned critical_pos = 1; /*1 = after IHDR, 2 = after PLTE, 3 = after IDAT*/ #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ /* safe output values in case error happens */ *out = 0; *w = *h = 0; state->error = lodepng_inspect(w, h, state, in, insize); /*reads header and resets other parameters in state->info_png*/ if(state->error) return; if(lodepng_pixel_overflow(*w, *h, &state->info_png.color, &state->info_raw)) { CERROR_RETURN(state->error, 92); /*overflow possible due to amount of pixels*/ } /*the input filesize is a safe upper bound for the sum of idat chunks size*/ idat = (unsigned char*)lodepng_malloc(insize); if(!idat) CERROR_RETURN(state->error, 83); /*alloc fail*/ chunk = &in[33]; /*first byte of the first chunk after the header*/ /*loop through the chunks, ignoring unknown chunks and stopping at IEND chunk. IDAT data is put at the start of the in buffer*/ while(!IEND && !state->error) { unsigned chunkLength; const unsigned char* data; /*the data in the chunk*/ size_t pos = (size_t)(chunk - in); /*error: next chunk out of bounds of the in buffer*/ if(chunk < in || pos + 12 > insize) { if(state->decoder.ignore_end) break; /*other errors may still happen though*/ CERROR_BREAK(state->error, 30); } /*length of the data of the chunk, excluding the 12 bytes for length, chunk type and CRC*/ chunkLength = lodepng_chunk_length(chunk); /*error: chunk length larger than the max PNG chunk size*/ if(chunkLength > 2147483647) { if(state->decoder.ignore_end) break; /*other errors may still happen though*/ CERROR_BREAK(state->error, 63); } if(pos + (size_t)chunkLength + 12 > insize || pos + (size_t)chunkLength + 12 < pos) { CERROR_BREAK(state->error, 64); /*error: size of the in buffer too small to contain next chunk (or int overflow)*/ } data = lodepng_chunk_data_const(chunk); unknown = 0; /*IDAT chunk, containing compressed image data*/ if(lodepng_chunk_type_equals(chunk, "IDAT")) { size_t newsize; if(lodepng_addofl(idatsize, chunkLength, &newsize)) CERROR_BREAK(state->error, 95); if(newsize > insize) CERROR_BREAK(state->error, 95); lodepng_memcpy(idat + idatsize, data, chunkLength); idatsize += chunkLength; #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS critical_pos = 3; #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ } else if(lodepng_chunk_type_equals(chunk, "IEND")) { /*IEND chunk*/ IEND = 1; } else if(lodepng_chunk_type_equals(chunk, "PLTE")) { /*palette chunk (PLTE)*/ state->error = readChunk_PLTE(&state->info_png.color, data, chunkLength); if(state->error) break; #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS critical_pos = 2; #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ } else if(lodepng_chunk_type_equals(chunk, "tRNS")) { /*palette transparency chunk (tRNS). Even though this one is an ancillary chunk , it is still compiled in without 'LODEPNG_COMPILE_ANCILLARY_CHUNKS' because it contains essential color information that affects the alpha channel of pixels. */ state->error = readChunk_tRNS(&state->info_png.color, data, chunkLength); if(state->error) break; #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS /*background color chunk (bKGD)*/ } else if(lodepng_chunk_type_equals(chunk, "bKGD")) { state->error = readChunk_bKGD(&state->info_png, data, chunkLength); if(state->error) break; } else if(lodepng_chunk_type_equals(chunk, "tEXt")) { /*text chunk (tEXt)*/ if(state->decoder.read_text_chunks) { state->error = readChunk_tEXt(&state->info_png, data, chunkLength); if(state->error) break; } } else if(lodepng_chunk_type_equals(chunk, "zTXt")) { /*compressed text chunk (zTXt)*/ if(state->decoder.read_text_chunks) { state->error = readChunk_zTXt(&state->info_png, &state->decoder, data, chunkLength); if(state->error) break; } } else if(lodepng_chunk_type_equals(chunk, "iTXt")) { /*international text chunk (iTXt)*/ if(state->decoder.read_text_chunks) { state->error = readChunk_iTXt(&state->info_png, &state->decoder, data, chunkLength); if(state->error) break; } } else if(lodepng_chunk_type_equals(chunk, "tIME")) { state->error = readChunk_tIME(&state->info_png, data, chunkLength); if(state->error) break; } else if(lodepng_chunk_type_equals(chunk, "pHYs")) { state->error = readChunk_pHYs(&state->info_png, data, chunkLength); if(state->error) break; } else if(lodepng_chunk_type_equals(chunk, "gAMA")) { state->error = readChunk_gAMA(&state->info_png, data, chunkLength); if(state->error) break; } else if(lodepng_chunk_type_equals(chunk, "cHRM")) { state->error = readChunk_cHRM(&state->info_png, data, chunkLength); if(state->error) break; } else if(lodepng_chunk_type_equals(chunk, "sRGB")) { state->error = readChunk_sRGB(&state->info_png, data, chunkLength); if(state->error) break; } else if(lodepng_chunk_type_equals(chunk, "iCCP")) { state->error = readChunk_iCCP(&state->info_png, &state->decoder, data, chunkLength); if(state->error) break; } else if(lodepng_chunk_type_equals(chunk, "sBIT")) { state->error = readChunk_sBIT(&state->info_png, data, chunkLength); if(state->error) break; #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ } else /*it's not an implemented chunk type, so ignore it: skip over the data*/ { /*error: unknown critical chunk (5th bit of first byte of chunk type is 0)*/ if(!state->decoder.ignore_critical && !lodepng_chunk_ancillary(chunk)) { CERROR_BREAK(state->error, 69); } unknown = 1; #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS if(state->decoder.remember_unknown_chunks) { state->error = lodepng_chunk_append(&state->info_png.unknown_chunks_data[critical_pos - 1], &state->info_png.unknown_chunks_size[critical_pos - 1], chunk); if(state->error) break; } #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ } if(!state->decoder.ignore_crc && !unknown) /*check CRC if wanted, only on known chunk types*/ { if(lodepng_chunk_check_crc(chunk)) CERROR_BREAK(state->error, 57); /*invalid CRC*/ } if(!IEND) chunk = lodepng_chunk_next_const(chunk, in + insize); } if(!state->error && state->info_png.color.colortype == LCT_PALETTE && !state->info_png.color.palette) { state->error = 106; /* error: PNG file must have PLTE chunk if color type is palette */ } if(!state->error) { /*predict output size, to allocate exact size for output buffer to avoid more dynamic allocation. If the decompressed size does not match the prediction, the image must be corrupt.*/ if(state->info_png.interlace_method == 0) { size_t bpp = lodepng_get_bpp(&state->info_png.color); expected_size = lodepng_get_raw_size_idat(*w, *h, bpp); } else { size_t bpp = lodepng_get_bpp(&state->info_png.color); /*Adam-7 interlaced: expected size is the sum of the 7 sub-images sizes*/ expected_size = 0; expected_size += lodepng_get_raw_size_idat((*w + 7) >> 3, (*h + 7) >> 3, bpp); if(*w > 4) expected_size += lodepng_get_raw_size_idat((*w + 3) >> 3, (*h + 7) >> 3, bpp); expected_size += lodepng_get_raw_size_idat((*w + 3) >> 2, (*h + 3) >> 3, bpp); if(*w > 2) expected_size += lodepng_get_raw_size_idat((*w + 1) >> 2, (*h + 3) >> 2, bpp); expected_size += lodepng_get_raw_size_idat((*w + 1) >> 1, (*h + 1) >> 2, bpp); if(*w > 1) expected_size += lodepng_get_raw_size_idat((*w + 0) >> 1, (*h + 1) >> 1, bpp); expected_size += lodepng_get_raw_size_idat((*w + 0), (*h + 0) >> 1, bpp); } state->error = zlib_decompress(&scanlines, &scanlines_size, expected_size, idat, idatsize, &state->decoder.zlibsettings); } if(!state->error && scanlines_size != expected_size) state->error = 91; /*decompressed size doesn't match prediction*/ lodepng_free(idat); if(!state->error) { outsize = lodepng_get_raw_size(*w, *h, &state->info_png.color); *out = (unsigned char*)lodepng_malloc(outsize); if(!*out) state->error = 83; /*alloc fail*/ } if(!state->error) { lodepng_memset(*out, 0, outsize); state->error = postProcessScanlines(*out, scanlines, *w, *h, &state->info_png); } lodepng_free(scanlines); } unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h, LodePNGState* state, const unsigned char* in, size_t insize) { *out = 0; decodeGeneric(out, w, h, state, in, insize); if(state->error) return state->error; if(!state->decoder.color_convert || lodepng_color_mode_equal(&state->info_raw, &state->info_png.color)) { /*same color type, no copying or converting of data needed*/ /*store the info_png color settings on the info_raw so that the info_raw still reflects what colortype the raw image has to the end user*/ if(!state->decoder.color_convert) { state->error = lodepng_color_mode_copy(&state->info_raw, &state->info_png.color); if(state->error) return state->error; } } else { /*color conversion needed*/ unsigned char* data = *out; size_t outsize; /*TODO: check if this works according to the statement in the documentation: "The converter can convert from grayscale input color type, to 8-bit grayscale or grayscale with alpha"*/ if(!(state->info_raw.colortype == LCT_RGB || state->info_raw.colortype == LCT_RGBA) && !(state->info_raw.bitdepth == 8)) { return 56; /*unsupported color mode conversion*/ } outsize = lodepng_get_raw_size(*w, *h, &state->info_raw); *out = (unsigned char*)lodepng_malloc(outsize); if(!(*out)) { state->error = 83; /*alloc fail*/ } else state->error = lodepng_convert(*out, data, &state->info_raw, &state->info_png.color, *w, *h); lodepng_free(data); } return state->error; } unsigned lodepng_decode_memory(unsigned char** out, unsigned* w, unsigned* h, const unsigned char* in, size_t insize, LodePNGColorType colortype, unsigned bitdepth) { unsigned error; LodePNGState state; lodepng_state_init(&state); state.info_raw.colortype = colortype; state.info_raw.bitdepth = bitdepth; #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS /*disable reading things that this function doesn't output*/ state.decoder.read_text_chunks = 0; state.decoder.remember_unknown_chunks = 0; #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ error = lodepng_decode(out, w, h, &state, in, insize); lodepng_state_cleanup(&state); return error; } unsigned lodepng_decode32(unsigned char** out, unsigned* w, unsigned* h, const unsigned char* in, size_t insize) { return lodepng_decode_memory(out, w, h, in, insize, LCT_RGBA, 8); } unsigned lodepng_decode24(unsigned char** out, unsigned* w, unsigned* h, const unsigned char* in, size_t insize) { return lodepng_decode_memory(out, w, h, in, insize, LCT_RGB, 8); } #ifdef LODEPNG_COMPILE_DISK unsigned lodepng_decode_file(unsigned char** out, unsigned* w, unsigned* h, const char* filename, LodePNGColorType colortype, unsigned bitdepth) { unsigned char* buffer = 0; size_t buffersize; unsigned error; /* safe output values in case error happens */ *out = 0; *w = *h = 0; error = lodepng_load_file(&buffer, &buffersize, filename); if(!error) error = lodepng_decode_memory(out, w, h, buffer, buffersize, colortype, bitdepth); lodepng_free(buffer); return error; } unsigned lodepng_decode32_file(unsigned char** out, unsigned* w, unsigned* h, const char* filename) { return lodepng_decode_file(out, w, h, filename, LCT_RGBA, 8); } unsigned lodepng_decode24_file(unsigned char** out, unsigned* w, unsigned* h, const char* filename) { return lodepng_decode_file(out, w, h, filename, LCT_RGB, 8); } #endif /*LODEPNG_COMPILE_DISK*/ void lodepng_decoder_settings_init(LodePNGDecoderSettings* settings) { settings->color_convert = 1; #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS settings->read_text_chunks = 1; settings->remember_unknown_chunks = 0; settings->max_text_size = 16777216; settings->max_icc_size = 16777216; /* 16MB is much more than enough for any reasonable ICC profile */ #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ settings->ignore_crc = 0; settings->ignore_critical = 0; settings->ignore_end = 0; lodepng_decompress_settings_init(&settings->zlibsettings); } #endif /*LODEPNG_COMPILE_DECODER*/ #if defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ENCODER) void lodepng_state_init(LodePNGState* state) { #ifdef LODEPNG_COMPILE_DECODER lodepng_decoder_settings_init(&state->decoder); #endif /*LODEPNG_COMPILE_DECODER*/ #ifdef LODEPNG_COMPILE_ENCODER lodepng_encoder_settings_init(&state->encoder); #endif /*LODEPNG_COMPILE_ENCODER*/ lodepng_color_mode_init(&state->info_raw); lodepng_info_init(&state->info_png); state->error = 1; } void lodepng_state_cleanup(LodePNGState* state) { lodepng_color_mode_cleanup(&state->info_raw); lodepng_info_cleanup(&state->info_png); } void lodepng_state_copy(LodePNGState* dest, const LodePNGState* source) { lodepng_state_cleanup(dest); *dest = *source; lodepng_color_mode_init(&dest->info_raw); lodepng_info_init(&dest->info_png); dest->error = lodepng_color_mode_copy(&dest->info_raw, &source->info_raw); if(dest->error) return; dest->error = lodepng_info_copy(&dest->info_png, &source->info_png); if(dest->error) return; } #endif /* defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ENCODER) */ #ifdef LODEPNG_COMPILE_ENCODER /* ////////////////////////////////////////////////////////////////////////// */ /* / PNG Encoder / */ /* ////////////////////////////////////////////////////////////////////////// */ static unsigned writeSignature(ucvector* out) { size_t pos = out->size; const unsigned char signature[] = {137, 80, 78, 71, 13, 10, 26, 10}; /*8 bytes PNG signature, aka the magic bytes*/ if(!ucvector_resize(out, out->size + 8)) return 83; /*alloc fail*/ lodepng_memcpy(out->data + pos, signature, 8); return 0; } static unsigned addChunk_IHDR(ucvector* out, unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth, unsigned interlace_method) { unsigned char *chunk, *data; CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 13, "IHDR")); data = chunk + 8; lodepng_set32bitInt(data + 0, w); /*width*/ lodepng_set32bitInt(data + 4, h); /*height*/ data[8] = (unsigned char)bitdepth; /*bit depth*/ data[9] = (unsigned char)colortype; /*color type*/ data[10] = 0; /*compression method*/ data[11] = 0; /*filter method*/ data[12] = interlace_method; /*interlace method*/ lodepng_chunk_generate_crc(chunk); return 0; } /* only adds the chunk if needed (there is a key or palette with alpha) */ static unsigned addChunk_PLTE(ucvector* out, const LodePNGColorMode* info) { unsigned char* chunk; size_t i, j = 8; if(info->palettesize == 0 || info->palettesize > 256) { return 68; /*invalid palette size, it is only allowed to be 1-256*/ } CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, info->palettesize * 3, "PLTE")); for(i = 0; i != info->palettesize; ++i) { /*add all channels except alpha channel*/ chunk[j++] = info->palette[i * 4 + 0]; chunk[j++] = info->palette[i * 4 + 1]; chunk[j++] = info->palette[i * 4 + 2]; } lodepng_chunk_generate_crc(chunk); return 0; } static unsigned addChunk_tRNS(ucvector* out, const LodePNGColorMode* info) { unsigned char* chunk = 0; if(info->colortype == LCT_PALETTE) { size_t i, amount = info->palettesize; /*the tail of palette values that all have 255 as alpha, does not have to be encoded*/ for(i = info->palettesize; i != 0; --i) { if(info->palette[4 * (i - 1) + 3] != 255) break; --amount; } if(amount) { CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, amount, "tRNS")); /*add the alpha channel values from the palette*/ for(i = 0; i != amount; ++i) chunk[8 + i] = info->palette[4 * i + 3]; } } else if(info->colortype == LCT_GREY) { if(info->key_defined) { CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 2, "tRNS")); chunk[8] = (unsigned char)(info->key_r >> 8); chunk[9] = (unsigned char)(info->key_r & 255); } } else if(info->colortype == LCT_RGB) { if(info->key_defined) { CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 6, "tRNS")); chunk[8] = (unsigned char)(info->key_r >> 8); chunk[9] = (unsigned char)(info->key_r & 255); chunk[10] = (unsigned char)(info->key_g >> 8); chunk[11] = (unsigned char)(info->key_g & 255); chunk[12] = (unsigned char)(info->key_b >> 8); chunk[13] = (unsigned char)(info->key_b & 255); } } if(chunk) lodepng_chunk_generate_crc(chunk); return 0; } static unsigned addChunk_IDAT(ucvector* out, const unsigned char* data, size_t datasize, LodePNGCompressSettings* zlibsettings) { unsigned error = 0; unsigned char* zlib = 0; size_t zlibsize = 0; error = zlib_compress(&zlib, &zlibsize, data, datasize, zlibsettings); if(!error) { error = lodepng_chunk_createv(out, zlibsize, "IDAT", zlib); } lodepng_free(zlib); return error; } static unsigned addChunk_IEND(ucvector* out) { return lodepng_chunk_createv(out, 0, "IEND", 0); } #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS static unsigned addChunk_tEXt(ucvector* out, const char* keyword, const char* textstring) { unsigned char* chunk = 0; size_t keysize = lodepng_strlen(keyword), textsize = lodepng_strlen(textstring); size_t size = keysize + 1 + textsize; if(keysize < 1 || keysize > 79) return 89; /*error: invalid keyword size*/ CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, size, "tEXt")); lodepng_memcpy(chunk + 8, keyword, keysize); chunk[8 + keysize] = 0; /*null termination char*/ lodepng_memcpy(chunk + 9 + keysize, textstring, textsize); lodepng_chunk_generate_crc(chunk); return 0; } static unsigned addChunk_zTXt(ucvector* out, const char* keyword, const char* textstring, LodePNGCompressSettings* zlibsettings) { unsigned error = 0; unsigned char* chunk = 0; unsigned char* compressed = 0; size_t compressedsize = 0; size_t textsize = lodepng_strlen(textstring); size_t keysize = lodepng_strlen(keyword); if(keysize < 1 || keysize > 79) return 89; /*error: invalid keyword size*/ error = zlib_compress(&compressed, &compressedsize, (const unsigned char*)textstring, textsize, zlibsettings); if(!error) { size_t size = keysize + 2 + compressedsize; error = lodepng_chunk_init(&chunk, out, size, "zTXt"); } if(!error) { lodepng_memcpy(chunk + 8, keyword, keysize); chunk[8 + keysize] = 0; /*null termination char*/ chunk[9 + keysize] = 0; /*compression method: 0*/ lodepng_memcpy(chunk + 10 + keysize, compressed, compressedsize); lodepng_chunk_generate_crc(chunk); } lodepng_free(compressed); return error; } static unsigned addChunk_iTXt(ucvector* out, unsigned compress, const char* keyword, const char* langtag, const char* transkey, const char* textstring, LodePNGCompressSettings* zlibsettings) { unsigned error = 0; unsigned char* chunk = 0; unsigned char* compressed = 0; size_t compressedsize = 0; size_t textsize = lodepng_strlen(textstring); size_t keysize = lodepng_strlen(keyword), langsize = lodepng_strlen(langtag), transsize = lodepng_strlen(transkey); if(keysize < 1 || keysize > 79) return 89; /*error: invalid keyword size*/ if(compress) { error = zlib_compress(&compressed, &compressedsize, (const unsigned char*)textstring, textsize, zlibsettings); } if(!error) { size_t size = keysize + 3 + langsize + 1 + transsize + 1 + (compress ? compressedsize : textsize); error = lodepng_chunk_init(&chunk, out, size, "iTXt"); } if(!error) { size_t pos = 8; lodepng_memcpy(chunk + pos, keyword, keysize); pos += keysize; chunk[pos++] = 0; /*null termination char*/ chunk[pos++] = (compress ? 1 : 0); /*compression flag*/ chunk[pos++] = 0; /*compression method: 0*/ lodepng_memcpy(chunk + pos, langtag, langsize); pos += langsize; chunk[pos++] = 0; /*null termination char*/ lodepng_memcpy(chunk + pos, transkey, transsize); pos += transsize; chunk[pos++] = 0; /*null termination char*/ if(compress) { lodepng_memcpy(chunk + pos, compressed, compressedsize); } else { lodepng_memcpy(chunk + pos, textstring, textsize); } lodepng_chunk_generate_crc(chunk); } lodepng_free(compressed); return error; } static unsigned addChunk_bKGD(ucvector* out, const LodePNGInfo* info) { unsigned char* chunk = 0; if(info->color.colortype == LCT_GREY || info->color.colortype == LCT_GREY_ALPHA) { CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 2, "bKGD")); chunk[8] = (unsigned char)(info->background_r >> 8); chunk[9] = (unsigned char)(info->background_r & 255); } else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_RGBA) { CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 6, "bKGD")); chunk[8] = (unsigned char)(info->background_r >> 8); chunk[9] = (unsigned char)(info->background_r & 255); chunk[10] = (unsigned char)(info->background_g >> 8); chunk[11] = (unsigned char)(info->background_g & 255); chunk[12] = (unsigned char)(info->background_b >> 8); chunk[13] = (unsigned char)(info->background_b & 255); } else if(info->color.colortype == LCT_PALETTE) { CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 1, "bKGD")); chunk[8] = (unsigned char)(info->background_r & 255); /*palette index*/ } if(chunk) lodepng_chunk_generate_crc(chunk); return 0; } static unsigned addChunk_tIME(ucvector* out, const LodePNGTime* time) { unsigned char* chunk; CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 7, "tIME")); chunk[8] = (unsigned char)(time->year >> 8); chunk[9] = (unsigned char)(time->year & 255); chunk[10] = (unsigned char)time->month; chunk[11] = (unsigned char)time->day; chunk[12] = (unsigned char)time->hour; chunk[13] = (unsigned char)time->minute; chunk[14] = (unsigned char)time->second; lodepng_chunk_generate_crc(chunk); return 0; } static unsigned addChunk_pHYs(ucvector* out, const LodePNGInfo* info) { unsigned char* chunk; CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 9, "pHYs")); lodepng_set32bitInt(chunk + 8, info->phys_x); lodepng_set32bitInt(chunk + 12, info->phys_y); chunk[16] = info->phys_unit; lodepng_chunk_generate_crc(chunk); return 0; } static unsigned addChunk_gAMA(ucvector* out, const LodePNGInfo* info) { unsigned char* chunk; CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 4, "gAMA")); lodepng_set32bitInt(chunk + 8, info->gama_gamma); lodepng_chunk_generate_crc(chunk); return 0; } static unsigned addChunk_cHRM(ucvector* out, const LodePNGInfo* info) { unsigned char* chunk; CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 32, "cHRM")); lodepng_set32bitInt(chunk + 8, info->chrm_white_x); lodepng_set32bitInt(chunk + 12, info->chrm_white_y); lodepng_set32bitInt(chunk + 16, info->chrm_red_x); lodepng_set32bitInt(chunk + 20, info->chrm_red_y); lodepng_set32bitInt(chunk + 24, info->chrm_green_x); lodepng_set32bitInt(chunk + 28, info->chrm_green_y); lodepng_set32bitInt(chunk + 32, info->chrm_blue_x); lodepng_set32bitInt(chunk + 36, info->chrm_blue_y); lodepng_chunk_generate_crc(chunk); return 0; } static unsigned addChunk_sRGB(ucvector* out, const LodePNGInfo* info) { unsigned char data = info->srgb_intent; return lodepng_chunk_createv(out, 1, "sRGB", &data); } static unsigned addChunk_iCCP(ucvector* out, const LodePNGInfo* info, LodePNGCompressSettings* zlibsettings) { unsigned error = 0; unsigned char* chunk = 0; unsigned char* compressed = 0; size_t compressedsize = 0; size_t keysize = lodepng_strlen(info->iccp_name); if(keysize < 1 || keysize > 79) return 89; /*error: invalid keyword size*/ error = zlib_compress(&compressed, &compressedsize, info->iccp_profile, info->iccp_profile_size, zlibsettings); if(!error) { size_t size = keysize + 2 + compressedsize; error = lodepng_chunk_init(&chunk, out, size, "iCCP"); } if(!error) { lodepng_memcpy(chunk + 8, info->iccp_name, keysize); chunk[8 + keysize] = 0; /*null termination char*/ chunk[9 + keysize] = 0; /*compression method: 0*/ lodepng_memcpy(chunk + 10 + keysize, compressed, compressedsize); lodepng_chunk_generate_crc(chunk); } lodepng_free(compressed); return error; } static unsigned addChunk_sBIT(ucvector* out, const LodePNGInfo* info) { unsigned bitdepth = (info->color.colortype == LCT_PALETTE) ? 8 : info->color.bitdepth; unsigned char* chunk = 0; if(info->color.colortype == LCT_GREY) { if(info->sbit_r == 0 || info->sbit_r > bitdepth) return 115; CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 1, "sBIT")); chunk[8] = info->sbit_r; } else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_PALETTE) { if(info->sbit_r == 0 || info->sbit_g == 0 || info->sbit_b == 0) return 115; if(info->sbit_r > bitdepth || info->sbit_g > bitdepth || info->sbit_b > bitdepth) return 115; CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 3, "sBIT")); chunk[8] = info->sbit_r; chunk[9] = info->sbit_g; chunk[10] = info->sbit_b; } else if(info->color.colortype == LCT_GREY_ALPHA) { if(info->sbit_r == 0 || info->sbit_a == 0) return 115; if(info->sbit_r > bitdepth || info->sbit_a > bitdepth) return 115; CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 2, "sBIT")); chunk[8] = info->sbit_r; chunk[9] = info->sbit_a; } else if(info->color.colortype == LCT_RGBA) { if(info->sbit_r == 0 || info->sbit_g == 0 || info->sbit_b == 0 || info->sbit_a == 0 || info->sbit_r > bitdepth || info->sbit_g > bitdepth || info->sbit_b > bitdepth || info->sbit_a > bitdepth) { return 115; } CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 4, "sBIT")); chunk[8] = info->sbit_r; chunk[9] = info->sbit_g; chunk[10] = info->sbit_b; chunk[11] = info->sbit_a; } if(chunk) lodepng_chunk_generate_crc(chunk); return 0; } #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ static void filterScanline(unsigned char* out, const unsigned char* scanline, const unsigned char* prevline, size_t length, size_t bytewidth, unsigned char filterType) { size_t i; switch(filterType) { case 0: /*None*/ for(i = 0; i != length; ++i) out[i] = scanline[i]; break; case 1: /*Sub*/ for(i = 0; i != bytewidth; ++i) out[i] = scanline[i]; for(i = bytewidth; i < length; ++i) out[i] = scanline[i] - scanline[i - bytewidth]; break; case 2: /*Up*/ if(prevline) { for(i = 0; i != length; ++i) out[i] = scanline[i] - prevline[i]; } else { for(i = 0; i != length; ++i) out[i] = scanline[i]; } break; case 3: /*Average*/ if(prevline) { for(i = 0; i != bytewidth; ++i) out[i] = scanline[i] - (prevline[i] >> 1); for(i = bytewidth; i < length; ++i) out[i] = scanline[i] - ((scanline[i - bytewidth] + prevline[i]) >> 1); } else { for(i = 0; i != bytewidth; ++i) out[i] = scanline[i]; for(i = bytewidth; i < length; ++i) out[i] = scanline[i] - (scanline[i - bytewidth] >> 1); } break; case 4: /*Paeth*/ if(prevline) { /*paethPredictor(0, prevline[i], 0) is always prevline[i]*/ for(i = 0; i != bytewidth; ++i) out[i] = (scanline[i] - prevline[i]); for(i = bytewidth; i < length; ++i) { out[i] = (scanline[i] - paethPredictor(scanline[i - bytewidth], prevline[i], prevline[i - bytewidth])); } } else { for(i = 0; i != bytewidth; ++i) out[i] = scanline[i]; /*paethPredictor(scanline[i - bytewidth], 0, 0) is always scanline[i - bytewidth]*/ for(i = bytewidth; i < length; ++i) out[i] = (scanline[i] - scanline[i - bytewidth]); } break; default: return; /*invalid filter type given*/ } } /* integer binary logarithm, max return value is 31 */ static size_t ilog2(size_t i) { size_t result = 0; if(i >= 65536) { result += 16; i >>= 16; } if(i >= 256) { result += 8; i >>= 8; } if(i >= 16) { result += 4; i >>= 4; } if(i >= 4) { result += 2; i >>= 2; } if(i >= 2) { result += 1; /*i >>= 1;*/ } return result; } /* integer approximation for i * log2(i), helper function for LFS_ENTROPY */ static size_t ilog2i(size_t i) { size_t l; if(i == 0) return 0; l = ilog2(i); /* approximate i*log2(i): l is integer logarithm, ((i - (1u << l)) << 1u) linearly approximates the missing fractional part multiplied by i */ return i * l + ((i - (1u << l)) << 1u); } static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, const LodePNGColorMode* color, const LodePNGEncoderSettings* settings) { /* For PNG filter method 0 out must be a buffer with as size: h + (w * h * bpp + 7u) / 8u, because there are the scanlines with 1 extra byte per scanline */ unsigned bpp = lodepng_get_bpp(color); /*the width of a scanline in bytes, not including the filter type*/ size_t linebytes = lodepng_get_raw_size_idat(w, 1, bpp) - 1u; /*bytewidth is used for filtering, is 1 when bpp < 8, number of bytes per pixel otherwise*/ size_t bytewidth = (bpp + 7u) / 8u; const unsigned char* prevline = 0; unsigned x, y; unsigned error = 0; LodePNGFilterStrategy strategy = settings->filter_strategy; /* There is a heuristic called the minimum sum of absolute differences heuristic, suggested by the PNG standard: * If the image type is Palette, or the bit depth is smaller than 8, then do not filter the image (i.e. use fixed filtering, with the filter None). * (The other case) If the image type is Grayscale or RGB (with or without Alpha), and the bit depth is not smaller than 8, then use adaptive filtering heuristic as follows: independently for each row, apply all five filters and select the filter that produces the smallest sum of absolute values per row. This heuristic is used if filter strategy is LFS_MINSUM and filter_palette_zero is true. If filter_palette_zero is true and filter_strategy is not LFS_MINSUM, the above heuristic is followed, but for "the other case", whatever strategy filter_strategy is set to instead of the minimum sum heuristic is used. */ if(settings->filter_palette_zero && (color->colortype == LCT_PALETTE || color->bitdepth < 8)) strategy = LFS_ZERO; if(bpp == 0) return 31; /*error: invalid color type*/ if(strategy >= LFS_ZERO && strategy <= LFS_FOUR) { unsigned char type = (unsigned char)strategy; for(y = 0; y != h; ++y) { size_t outindex = (1 + linebytes) * y; /*the extra filterbyte added to each row*/ size_t inindex = linebytes * y; out[outindex] = type; /*filter type byte*/ filterScanline(&out[outindex + 1], &in[inindex], prevline, linebytes, bytewidth, type); prevline = &in[inindex]; } } else if(strategy == LFS_MINSUM) { /*adaptive filtering*/ unsigned char* attempt[5]; /*five filtering attempts, one for each filter type*/ size_t smallest = 0; unsigned char type, bestType = 0; for(type = 0; type != 5; ++type) { attempt[type] = (unsigned char*)lodepng_malloc(linebytes); if(!attempt[type]) error = 83; /*alloc fail*/ } if(!error) { for(y = 0; y != h; ++y) { /*try the 5 filter types*/ for(type = 0; type != 5; ++type) { size_t sum = 0; filterScanline(attempt[type], &in[y * linebytes], prevline, linebytes, bytewidth, type); /*calculate the sum of the result*/ if(type == 0) { for(x = 0; x != linebytes; ++x) sum += (unsigned char)(attempt[type][x]); } else { for(x = 0; x != linebytes; ++x) { /*For differences, each byte should be treated as signed, values above 127 are negative (converted to signed char). Filtertype 0 isn't a difference though, so use unsigned there. This means filtertype 0 is almost never chosen, but that is justified.*/ unsigned char s = attempt[type][x]; sum += s < 128 ? s : (255U - s); } } /*check if this is smallest sum (or if type == 0 it's the first case so always store the values)*/ if(type == 0 || sum < smallest) { bestType = type; smallest = sum; } } prevline = &in[y * linebytes]; /*now fill the out values*/ out[y * (linebytes + 1)] = bestType; /*the first byte of a scanline will be the filter type*/ for(x = 0; x != linebytes; ++x) out[y * (linebytes + 1) + 1 + x] = attempt[bestType][x]; } } for(type = 0; type != 5; ++type) lodepng_free(attempt[type]); } else if(strategy == LFS_ENTROPY) { unsigned char* attempt[5]; /*five filtering attempts, one for each filter type*/ size_t bestSum = 0; unsigned type, bestType = 0; unsigned count[256]; for(type = 0; type != 5; ++type) { attempt[type] = (unsigned char*)lodepng_malloc(linebytes); if(!attempt[type]) error = 83; /*alloc fail*/ } if(!error) { for(y = 0; y != h; ++y) { /*try the 5 filter types*/ for(type = 0; type != 5; ++type) { size_t sum = 0; filterScanline(attempt[type], &in[y * linebytes], prevline, linebytes, bytewidth, type); lodepng_memset(count, 0, 256 * sizeof(*count)); for(x = 0; x != linebytes; ++x) ++count[attempt[type][x]]; ++count[type]; /*the filter type itself is part of the scanline*/ for(x = 0; x != 256; ++x) { sum += ilog2i(count[x]); } /*check if this is smallest sum (or if type == 0 it's the first case so always store the values)*/ if(type == 0 || sum > bestSum) { bestType = type; bestSum = sum; } } prevline = &in[y * linebytes]; /*now fill the out values*/ out[y * (linebytes + 1)] = bestType; /*the first byte of a scanline will be the filter type*/ for(x = 0; x != linebytes; ++x) out[y * (linebytes + 1) + 1 + x] = attempt[bestType][x]; } } for(type = 0; type != 5; ++type) lodepng_free(attempt[type]); } else if(strategy == LFS_PREDEFINED) { for(y = 0; y != h; ++y) { size_t outindex = (1 + linebytes) * y; /*the extra filterbyte added to each row*/ size_t inindex = linebytes * y; unsigned char type = settings->predefined_filters[y]; out[outindex] = type; /*filter type byte*/ filterScanline(&out[outindex + 1], &in[inindex], prevline, linebytes, bytewidth, type); prevline = &in[inindex]; } } else if(strategy == LFS_BRUTE_FORCE) { /*brute force filter chooser. deflate the scanline after every filter attempt to see which one deflates best. This is very slow and gives only slightly smaller, sometimes even larger, result*/ size_t size[5]; unsigned char* attempt[5]; /*five filtering attempts, one for each filter type*/ size_t smallest = 0; unsigned type = 0, bestType = 0; unsigned char* dummy; LodePNGCompressSettings zlibsettings; lodepng_memcpy(&zlibsettings, &settings->zlibsettings, sizeof(LodePNGCompressSettings)); /*use fixed tree on the attempts so that the tree is not adapted to the filtertype on purpose, to simulate the true case where the tree is the same for the whole image. Sometimes it gives better result with dynamic tree anyway. Using the fixed tree sometimes gives worse, but in rare cases better compression. It does make this a bit less slow, so it's worth doing this.*/ zlibsettings.btype = 1; /*a custom encoder likely doesn't read the btype setting and is optimized for complete PNG images only, so disable it*/ zlibsettings.custom_zlib = 0; zlibsettings.custom_deflate = 0; for(type = 0; type != 5; ++type) { attempt[type] = (unsigned char*)lodepng_malloc(linebytes); if(!attempt[type]) error = 83; /*alloc fail*/ } if(!error) { for(y = 0; y != h; ++y) /*try the 5 filter types*/ { for(type = 0; type != 5; ++type) { unsigned testsize = (unsigned)linebytes; /*if(testsize > 8) testsize /= 8;*/ /*it already works good enough by testing a part of the row*/ filterScanline(attempt[type], &in[y * linebytes], prevline, linebytes, bytewidth, type); size[type] = 0; dummy = 0; zlib_compress(&dummy, &size[type], attempt[type], testsize, &zlibsettings); lodepng_free(dummy); /*check if this is smallest size (or if type == 0 it's the first case so always store the values)*/ if(type == 0 || size[type] < smallest) { bestType = type; smallest = size[type]; } } prevline = &in[y * linebytes]; out[y * (linebytes + 1)] = bestType; /*the first byte of a scanline will be the filter type*/ for(x = 0; x != linebytes; ++x) out[y * (linebytes + 1) + 1 + x] = attempt[bestType][x]; } } for(type = 0; type != 5; ++type) lodepng_free(attempt[type]); } else return 88; /* unknown filter strategy */ return error; } static void addPaddingBits(unsigned char* out, const unsigned char* in, size_t olinebits, size_t ilinebits, unsigned h) { /*The opposite of the removePaddingBits function olinebits must be >= ilinebits*/ unsigned y; size_t diff = olinebits - ilinebits; size_t obp = 0, ibp = 0; /*bit pointers*/ for(y = 0; y != h; ++y) { size_t x; for(x = 0; x < ilinebits; ++x) { unsigned char bit = readBitFromReversedStream(&ibp, in); setBitOfReversedStream(&obp, out, bit); } /*obp += diff; --> no, fill in some value in the padding bits too, to avoid "Use of uninitialised value of size ###" warning from valgrind*/ for(x = 0; x != diff; ++x) setBitOfReversedStream(&obp, out, 0); } } /* in: non-interlaced image with size w*h out: the same pixels, but re-ordered according to PNG's Adam7 interlacing, with no padding bits between scanlines, but between reduced images so that each reduced image starts at a byte. bpp: bits per pixel there are no padding bits, not between scanlines, not between reduced images in has the following size in bits: w * h * bpp. out is possibly bigger due to padding bits between reduced images NOTE: comments about padding bits are only relevant if bpp < 8 */ static void Adam7_interlace(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, unsigned bpp) { unsigned passw[7], passh[7]; size_t filter_passstart[8], padded_passstart[8], passstart[8]; unsigned i; Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp); if(bpp >= 8) { for(i = 0; i != 7; ++i) { unsigned x, y, b; size_t bytewidth = bpp / 8u; for(y = 0; y < passh[i]; ++y) for(x = 0; x < passw[i]; ++x) { size_t pixelinstart = ((ADAM7_IY[i] + y * ADAM7_DY[i]) * w + ADAM7_IX[i] + x * ADAM7_DX[i]) * bytewidth; size_t pixeloutstart = passstart[i] + (y * passw[i] + x) * bytewidth; for(b = 0; b < bytewidth; ++b) { out[pixeloutstart + b] = in[pixelinstart + b]; } } } } else /*bpp < 8: Adam7 with pixels < 8 bit is a bit trickier: with bit pointers*/ { for(i = 0; i != 7; ++i) { unsigned x, y, b; unsigned ilinebits = bpp * passw[i]; unsigned olinebits = bpp * w; size_t obp, ibp; /*bit pointers (for out and in buffer)*/ for(y = 0; y < passh[i]; ++y) for(x = 0; x < passw[i]; ++x) { ibp = (ADAM7_IY[i] + y * ADAM7_DY[i]) * olinebits + (ADAM7_IX[i] + x * ADAM7_DX[i]) * bpp; obp = (8 * passstart[i]) + (y * ilinebits + x * bpp); for(b = 0; b < bpp; ++b) { unsigned char bit = readBitFromReversedStream(&ibp, in); setBitOfReversedStream(&obp, out, bit); } } } } } /*out must be buffer big enough to contain uncompressed IDAT chunk data, and in must contain the full image. return value is error**/ static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const unsigned char* in, unsigned w, unsigned h, const LodePNGInfo* info_png, const LodePNGEncoderSettings* settings) { /* This function converts the pure 2D image with the PNG's colortype, into filtered-padded-interlaced data. Steps: *) if no Adam7: 1) add padding bits (= possible extra bits per scanline if bpp < 8) 2) filter *) if adam7: 1) Adam7_interlace 2) 7x add padding bits 3) 7x filter */ unsigned bpp = lodepng_get_bpp(&info_png->color); unsigned error = 0; if(info_png->interlace_method == 0) { *outsize = h + (h * ((w * bpp + 7u) / 8u)); /*image size plus an extra byte per scanline + possible padding bits*/ *out = (unsigned char*)lodepng_malloc(*outsize); if(!(*out) && (*outsize)) error = 83; /*alloc fail*/ if(!error) { /*non multiple of 8 bits per scanline, padding bits needed per scanline*/ if(bpp < 8 && w * bpp != ((w * bpp + 7u) / 8u) * 8u) { unsigned char* padded = (unsigned char*)lodepng_malloc(h * ((w * bpp + 7u) / 8u)); if(!padded) error = 83; /*alloc fail*/ if(!error) { addPaddingBits(padded, in, ((w * bpp + 7u) / 8u) * 8u, w * bpp, h); error = filter(*out, padded, w, h, &info_png->color, settings); } lodepng_free(padded); } else { /*we can immediately filter into the out buffer, no other steps needed*/ error = filter(*out, in, w, h, &info_png->color, settings); } } } else /*interlace_method is 1 (Adam7)*/ { unsigned passw[7], passh[7]; size_t filter_passstart[8], padded_passstart[8], passstart[8]; unsigned char* adam7; Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp); *outsize = filter_passstart[7]; /*image size plus an extra byte per scanline + possible padding bits*/ *out = (unsigned char*)lodepng_malloc(*outsize); if(!(*out)) error = 83; /*alloc fail*/ adam7 = (unsigned char*)lodepng_malloc(passstart[7]); if(!adam7 && passstart[7]) error = 83; /*alloc fail*/ if(!error) { unsigned i; Adam7_interlace(adam7, in, w, h, bpp); for(i = 0; i != 7; ++i) { if(bpp < 8) { unsigned char* padded = (unsigned char*)lodepng_malloc(padded_passstart[i + 1] - padded_passstart[i]); if(!padded) ERROR_BREAK(83); /*alloc fail*/ addPaddingBits(padded, &adam7[passstart[i]], ((passw[i] * bpp + 7u) / 8u) * 8u, passw[i] * bpp, passh[i]); error = filter(&(*out)[filter_passstart[i]], padded, passw[i], passh[i], &info_png->color, settings); lodepng_free(padded); } else { error = filter(&(*out)[filter_passstart[i]], &adam7[padded_passstart[i]], passw[i], passh[i], &info_png->color, settings); } if(error) break; } } lodepng_free(adam7); } return error; } #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS static unsigned addUnknownChunks(ucvector* out, unsigned char* data, size_t datasize) { unsigned char* inchunk = data; while((size_t)(inchunk - data) < datasize) { CERROR_TRY_RETURN(lodepng_chunk_append(&out->data, &out->size, inchunk)); out->allocsize = out->size; /*fix the allocsize again*/ inchunk = lodepng_chunk_next(inchunk, data + datasize); } return 0; } static unsigned isGrayICCProfile(const unsigned char* profile, unsigned size) { /* It is a gray profile if bytes 16-19 are "GRAY", rgb profile if bytes 16-19 are "RGB ". We do not perform any full parsing of the ICC profile here, other than check those 4 bytes to grayscale profile. Other than that, validity of the profile is not checked. This is needed only because the PNG specification requires using a non-gray color model if there is an ICC profile with "RGB " (sadly limiting compression opportunities if the input data is grayscale RGB data), and requires using a gray color model if it is "GRAY". */ if(size < 20) return 0; return profile[16] == 'G' && profile[17] == 'R' && profile[18] == 'A' && profile[19] == 'Y'; } static unsigned isRGBICCProfile(const unsigned char* profile, unsigned size) { /* See comment in isGrayICCProfile*/ if(size < 20) return 0; return profile[16] == 'R' && profile[17] == 'G' && profile[18] == 'B' && profile[19] == ' '; } #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ unsigned lodepng_encode(unsigned char** out, size_t* outsize, const unsigned char* image, unsigned w, unsigned h, LodePNGState* state) { unsigned char* data = 0; /*uncompressed version of the IDAT chunk data*/ size_t datasize = 0; ucvector outv = ucvector_init(NULL, 0); LodePNGInfo info; const LodePNGInfo* info_png = &state->info_png; LodePNGColorMode auto_color; lodepng_info_init(&info); lodepng_color_mode_init(&auto_color); /*provide some proper output values if error will happen*/ *out = 0; *outsize = 0; state->error = 0; /*check input values validity*/ if((info_png->color.colortype == LCT_PALETTE || state->encoder.force_palette) && (info_png->color.palettesize == 0 || info_png->color.palettesize > 256)) { /*this error is returned even if auto_convert is enabled and thus encoder could generate the palette by itself: while allowing this could be possible in theory, it may complicate the code or edge cases, and always requiring to give a palette when setting this color type is a simpler contract*/ state->error = 68; /*invalid palette size, it is only allowed to be 1-256*/ goto cleanup; } if(state->encoder.zlibsettings.btype > 2) { state->error = 61; /*error: invalid btype*/ goto cleanup; } if(info_png->interlace_method > 1) { state->error = 71; /*error: invalid interlace mode*/ goto cleanup; } state->error = checkColorValidity(info_png->color.colortype, info_png->color.bitdepth); if(state->error) goto cleanup; /*error: invalid color type given*/ state->error = checkColorValidity(state->info_raw.colortype, state->info_raw.bitdepth); if(state->error) goto cleanup; /*error: invalid color type given*/ /* color convert and compute scanline filter types */ lodepng_info_copy(&info, &state->info_png); if(state->encoder.auto_convert) { LodePNGColorStats stats; unsigned allow_convert = 1; lodepng_color_stats_init(&stats); #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS if(info_png->iccp_defined && isGrayICCProfile(info_png->iccp_profile, info_png->iccp_profile_size)) { /*the PNG specification does not allow to use palette with a GRAY ICC profile, even if the palette has only gray colors, so disallow it.*/ stats.allow_palette = 0; } if(info_png->iccp_defined && isRGBICCProfile(info_png->iccp_profile, info_png->iccp_profile_size)) { /*the PNG specification does not allow to use grayscale color with RGB ICC profile, so disallow gray.*/ stats.allow_greyscale = 0; } #endif /* LODEPNG_COMPILE_ANCILLARY_CHUNKS */ state->error = lodepng_compute_color_stats(&stats, image, w, h, &state->info_raw); if(state->error) goto cleanup; #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS if(info_png->background_defined) { /*the background chunk's color must be taken into account as well*/ unsigned r = 0, g = 0, b = 0; LodePNGColorMode mode16 = lodepng_color_mode_make(LCT_RGB, 16); lodepng_convert_rgb(&r, &g, &b, info_png->background_r, info_png->background_g, info_png->background_b, &mode16, &info_png->color); state->error = lodepng_color_stats_add(&stats, r, g, b, 65535); if(state->error) goto cleanup; } #endif /* LODEPNG_COMPILE_ANCILLARY_CHUNKS */ state->error = auto_choose_color(&auto_color, &state->info_raw, &stats); if(state->error) goto cleanup; #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS if(info_png->sbit_defined) { /*if sbit is defined, due to strict requirements of which sbit values can be present for which color modes, auto_convert can't be done in many cases. However, do support a few cases here. TODO: more conversions may be possible, and it may also be possible to get a more appropriate color type out of auto_choose_color if knowledge about sbit is used beforehand */ unsigned sbit_max = LODEPNG_MAX(LODEPNG_MAX(LODEPNG_MAX(info_png->sbit_r, info_png->sbit_g), info_png->sbit_b), info_png->sbit_a); unsigned equal = (!info_png->sbit_g || info_png->sbit_g == info_png->sbit_r) && (!info_png->sbit_b || info_png->sbit_b == info_png->sbit_r) && (!info_png->sbit_a || info_png->sbit_a == info_png->sbit_r); allow_convert = 0; if(info.color.colortype == LCT_PALETTE && auto_color.colortype == LCT_PALETTE) { /* input and output are palette, and in this case it may happen that palette data is expected to be copied from info_raw into the info_png */ allow_convert = 1; } /*going from 8-bit RGB to palette (or 16-bit as long as sbit_max <= 8) is possible since both are 8-bit RGB for sBIT's purposes*/ if(info.color.colortype == LCT_RGB && auto_color.colortype == LCT_PALETTE && sbit_max <= 8) { allow_convert = 1; } /*going from 8-bit RGBA to palette is also ok but only if sbit_a is exactly 8*/ if(info.color.colortype == LCT_RGBA && auto_color.colortype == LCT_PALETTE && info_png->sbit_a == 8 && sbit_max <= 8) { allow_convert = 1; } /*going from 16-bit RGB(A) to 8-bit RGB(A) is ok if all sbit values are <= 8*/ if((info.color.colortype == LCT_RGB || info.color.colortype == LCT_RGBA) && info.color.bitdepth == 16 && auto_color.colortype == info.color.colortype && auto_color.bitdepth == 8 && sbit_max <= 8) { allow_convert = 1; } /*going to less channels is ok if all bit values are equal (all possible values in sbit, as well as the chosen bitdepth of the result). Due to how auto_convert works, we already know that auto_color.colortype has less than or equal amount of channels than info.colortype. Palette is not used here. This conversion is not allowed if info_png->sbit_r < auto_color.bitdepth, because specifically for alpha, non-presence of an sbit value heavily implies that alpha's bit depth is equal to the PNG bit depth (rather than the bit depths set in the r, g and b sbit values, by how the PNG specification describes handling tRNS chunk case with sBIT), so be conservative here about ignoring user input.*/ if(info.color.colortype != LCT_PALETTE && auto_color.colortype != LCT_PALETTE && equal && info_png->sbit_r == auto_color.bitdepth) { allow_convert = 1; } } #endif if(state->encoder.force_palette) { if(info.color.colortype != LCT_GREY && info.color.colortype != LCT_GREY_ALPHA && (auto_color.colortype == LCT_GREY || auto_color.colortype == LCT_GREY_ALPHA)) { /*user speficially forced a PLTE palette, so cannot convert to grayscale types because the PNG specification only allows writing a suggested palette in PLTE for truecolor types*/ allow_convert = 0; } } if(allow_convert) { lodepng_color_mode_copy(&info.color, &auto_color); #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS /*also convert the background chunk*/ if(info_png->background_defined) { if(lodepng_convert_rgb(&info.background_r, &info.background_g, &info.background_b, info_png->background_r, info_png->background_g, info_png->background_b, &info.color, &info_png->color)) { state->error = 104; goto cleanup; } } #endif /* LODEPNG_COMPILE_ANCILLARY_CHUNKS */ } } #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS if(info_png->iccp_defined) { unsigned gray_icc = isGrayICCProfile(info_png->iccp_profile, info_png->iccp_profile_size); unsigned rgb_icc = isRGBICCProfile(info_png->iccp_profile, info_png->iccp_profile_size); unsigned gray_png = info.color.colortype == LCT_GREY || info.color.colortype == LCT_GREY_ALPHA; if(!gray_icc && !rgb_icc) { state->error = 100; /* Disallowed profile color type for PNG */ goto cleanup; } if(gray_icc != gray_png) { /*Not allowed to use RGB/RGBA/palette with GRAY ICC profile or vice versa, or in case of auto_convert, it wasn't possible to find appropriate model*/ state->error = state->encoder.auto_convert ? 102 : 101; goto cleanup; } } #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ if(!lodepng_color_mode_equal(&state->info_raw, &info.color)) { unsigned char* converted; size_t size = ((size_t)w * (size_t)h * (size_t)lodepng_get_bpp(&info.color) + 7u) / 8u; converted = (unsigned char*)lodepng_malloc(size); if(!converted && size) state->error = 83; /*alloc fail*/ if(!state->error) { state->error = lodepng_convert(converted, image, &info.color, &state->info_raw, w, h); } if(!state->error) { state->error = preProcessScanlines(&data, &datasize, converted, w, h, &info, &state->encoder); } lodepng_free(converted); if(state->error) goto cleanup; } else { state->error = preProcessScanlines(&data, &datasize, image, w, h, &info, &state->encoder); if(state->error) goto cleanup; } /* output all PNG chunks */ { #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS size_t i; #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ /*write signature and chunks*/ state->error = writeSignature(&outv); if(state->error) goto cleanup; /*IHDR*/ state->error = addChunk_IHDR(&outv, w, h, info.color.colortype, info.color.bitdepth, info.interlace_method); if(state->error) goto cleanup; #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS /*unknown chunks between IHDR and PLTE*/ if(info.unknown_chunks_data[0]) { state->error = addUnknownChunks(&outv, info.unknown_chunks_data[0], info.unknown_chunks_size[0]); if(state->error) goto cleanup; } /*color profile chunks must come before PLTE */ if(info.iccp_defined) { state->error = addChunk_iCCP(&outv, &info, &state->encoder.zlibsettings); if(state->error) goto cleanup; } if(info.srgb_defined) { state->error = addChunk_sRGB(&outv, &info); if(state->error) goto cleanup; } if(info.gama_defined) { state->error = addChunk_gAMA(&outv, &info); if(state->error) goto cleanup; } if(info.chrm_defined) { state->error = addChunk_cHRM(&outv, &info); if(state->error) goto cleanup; } if(info_png->sbit_defined) { state->error = addChunk_sBIT(&outv, &info); if(state->error) goto cleanup; } #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ /*PLTE*/ if(info.color.colortype == LCT_PALETTE) { state->error = addChunk_PLTE(&outv, &info.color); if(state->error) goto cleanup; } if(state->encoder.force_palette && (info.color.colortype == LCT_RGB || info.color.colortype == LCT_RGBA)) { /*force_palette means: write suggested palette for truecolor in PLTE chunk*/ state->error = addChunk_PLTE(&outv, &info.color); if(state->error) goto cleanup; } /*tRNS (this will only add if when necessary) */ state->error = addChunk_tRNS(&outv, &info.color); if(state->error) goto cleanup; #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS /*bKGD (must come between PLTE and the IDAt chunks*/ if(info.background_defined) { state->error = addChunk_bKGD(&outv, &info); if(state->error) goto cleanup; } /*pHYs (must come before the IDAT chunks)*/ if(info.phys_defined) { state->error = addChunk_pHYs(&outv, &info); if(state->error) goto cleanup; } /*unknown chunks between PLTE and IDAT*/ if(info.unknown_chunks_data[1]) { state->error = addUnknownChunks(&outv, info.unknown_chunks_data[1], info.unknown_chunks_size[1]); if(state->error) goto cleanup; } #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ /*IDAT (multiple IDAT chunks must be consecutive)*/ state->error = addChunk_IDAT(&outv, data, datasize, &state->encoder.zlibsettings); if(state->error) goto cleanup; #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS /*tIME*/ if(info.time_defined) { state->error = addChunk_tIME(&outv, &info.time); if(state->error) goto cleanup; } /*tEXt and/or zTXt*/ for(i = 0; i != info.text_num; ++i) { if(lodepng_strlen(info.text_keys[i]) > 79) { state->error = 66; /*text chunk too large*/ goto cleanup; } if(lodepng_strlen(info.text_keys[i]) < 1) { state->error = 67; /*text chunk too small*/ goto cleanup; } if(state->encoder.text_compression) { state->error = addChunk_zTXt(&outv, info.text_keys[i], info.text_strings[i], &state->encoder.zlibsettings); if(state->error) goto cleanup; } else { state->error = addChunk_tEXt(&outv, info.text_keys[i], info.text_strings[i]); if(state->error) goto cleanup; } } /*LodePNG version id in text chunk*/ if(state->encoder.add_id) { unsigned already_added_id_text = 0; for(i = 0; i != info.text_num; ++i) { const char* k = info.text_keys[i]; /* Could use strcmp, but we're not calling or reimplementing this C library function for this use only */ if(k[0] == 'L' && k[1] == 'o' && k[2] == 'd' && k[3] == 'e' && k[4] == 'P' && k[5] == 'N' && k[6] == 'G' && k[7] == '\0') { already_added_id_text = 1; break; } } if(already_added_id_text == 0) { state->error = addChunk_tEXt(&outv, "LodePNG", LODEPNG_VERSION_STRING); /*it's shorter as tEXt than as zTXt chunk*/ if(state->error) goto cleanup; } } /*iTXt*/ for(i = 0; i != info.itext_num; ++i) { if(lodepng_strlen(info.itext_keys[i]) > 79) { state->error = 66; /*text chunk too large*/ goto cleanup; } if(lodepng_strlen(info.itext_keys[i]) < 1) { state->error = 67; /*text chunk too small*/ goto cleanup; } state->error = addChunk_iTXt( &outv, state->encoder.text_compression, info.itext_keys[i], info.itext_langtags[i], info.itext_transkeys[i], info.itext_strings[i], &state->encoder.zlibsettings); if(state->error) goto cleanup; } /*unknown chunks between IDAT and IEND*/ if(info.unknown_chunks_data[2]) { state->error = addUnknownChunks(&outv, info.unknown_chunks_data[2], info.unknown_chunks_size[2]); if(state->error) goto cleanup; } #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ state->error = addChunk_IEND(&outv); if(state->error) goto cleanup; } cleanup: lodepng_info_cleanup(&info); lodepng_free(data); lodepng_color_mode_cleanup(&auto_color); /*instead of cleaning the vector up, give it to the output*/ *out = outv.data; *outsize = outv.size; return state->error; } unsigned lodepng_encode_memory(unsigned char** out, size_t* outsize, const unsigned char* image, unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth) { unsigned error; LodePNGState state; lodepng_state_init(&state); state.info_raw.colortype = colortype; state.info_raw.bitdepth = bitdepth; state.info_png.color.colortype = colortype; state.info_png.color.bitdepth = bitdepth; lodepng_encode(out, outsize, image, w, h, &state); error = state.error; lodepng_state_cleanup(&state); return error; } unsigned lodepng_encode32(unsigned char** out, size_t* outsize, const unsigned char* image, unsigned w, unsigned h) { return lodepng_encode_memory(out, outsize, image, w, h, LCT_RGBA, 8); } unsigned lodepng_encode24(unsigned char** out, size_t* outsize, const unsigned char* image, unsigned w, unsigned h) { return lodepng_encode_memory(out, outsize, image, w, h, LCT_RGB, 8); } #ifdef LODEPNG_COMPILE_DISK unsigned lodepng_encode_file(const char* filename, const unsigned char* image, unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth) { unsigned char* buffer; size_t buffersize; unsigned error = lodepng_encode_memory(&buffer, &buffersize, image, w, h, colortype, bitdepth); if(!error) error = lodepng_save_file(buffer, buffersize, filename); lodepng_free(buffer); return error; } unsigned lodepng_encode32_file(const char* filename, const unsigned char* image, unsigned w, unsigned h) { return lodepng_encode_file(filename, image, w, h, LCT_RGBA, 8); } unsigned lodepng_encode24_file(const char* filename, const unsigned char* image, unsigned w, unsigned h) { return lodepng_encode_file(filename, image, w, h, LCT_RGB, 8); } #endif /*LODEPNG_COMPILE_DISK*/ void lodepng_encoder_settings_init(LodePNGEncoderSettings* settings) { lodepng_compress_settings_init(&settings->zlibsettings); settings->filter_palette_zero = 1; settings->filter_strategy = LFS_MINSUM; settings->auto_convert = 1; settings->force_palette = 0; settings->predefined_filters = 0; #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS settings->add_id = 0; settings->text_compression = 1; #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ } #endif /*LODEPNG_COMPILE_ENCODER*/ #endif /*LODEPNG_COMPILE_PNG*/ #ifdef LODEPNG_COMPILE_ERROR_TEXT /* This returns the description of a numerical error code in English. This is also the documentation of all the error codes. */ const char* lodepng_error_text(unsigned code) { switch(code) { case 0: return "no error, everything went ok"; case 1: return "nothing done yet"; /*the Encoder/Decoder has done nothing yet, error checking makes no sense yet*/ case 10: return "end of input memory reached without huffman end code"; /*while huffman decoding*/ case 11: return "error in code tree made it jump outside of huffman tree"; /*while huffman decoding*/ case 13: return "problem while processing dynamic deflate block"; case 14: return "problem while processing dynamic deflate block"; case 15: return "problem while processing dynamic deflate block"; /*this error could happen if there are only 0 or 1 symbols present in the huffman code:*/ case 16: return "invalid code while processing dynamic deflate block"; case 17: return "end of out buffer memory reached while inflating"; case 18: return "invalid distance code while inflating"; case 19: return "end of out buffer memory reached while inflating"; case 20: return "invalid deflate block BTYPE encountered while decoding"; case 21: return "NLEN is not ones complement of LEN in a deflate block"; /*end of out buffer memory reached while inflating: This can happen if the inflated deflate data is longer than the amount of bytes required to fill up all the pixels of the image, given the color depth and image dimensions. Something that doesn't happen in a normal, well encoded, PNG image.*/ case 22: return "end of out buffer memory reached while inflating"; case 23: return "end of in buffer memory reached while inflating"; case 24: return "invalid FCHECK in zlib header"; case 25: return "invalid compression method in zlib header"; case 26: return "FDICT encountered in zlib header while it's not used for PNG"; case 27: return "PNG file is smaller than a PNG header"; /*Checks the magic file header, the first 8 bytes of the PNG file*/ case 28: return "incorrect PNG signature, it's no PNG or corrupted"; case 29: return "first chunk is not the header chunk"; case 30: return "chunk length too large, chunk broken off at end of file"; case 31: return "illegal PNG color type or bpp"; case 32: return "illegal PNG compression method"; case 33: return "illegal PNG filter method"; case 34: return "illegal PNG interlace method"; case 35: return "chunk length of a chunk is too large or the chunk too small"; case 36: return "illegal PNG filter type encountered"; case 37: return "illegal bit depth for this color type given"; case 38: return "the palette is too small or too big"; /*0, or more than 256 colors*/ case 39: return "tRNS chunk before PLTE or has more entries than palette size"; case 40: return "tRNS chunk has wrong size for grayscale image"; case 41: return "tRNS chunk has wrong size for RGB image"; case 42: return "tRNS chunk appeared while it was not allowed for this color type"; case 43: return "bKGD chunk has wrong size for palette image"; case 44: return "bKGD chunk has wrong size for grayscale image"; case 45: return "bKGD chunk has wrong size for RGB image"; case 48: return "empty input buffer given to decoder. Maybe caused by non-existing file?"; case 49: return "jumped past memory while generating dynamic huffman tree"; case 50: return "jumped past memory while generating dynamic huffman tree"; case 51: return "jumped past memory while inflating huffman block"; case 52: return "jumped past memory while inflating"; case 53: return "size of zlib data too small"; case 54: return "repeat symbol in tree while there was no value symbol yet"; /*jumped past tree while generating huffman tree, this could be when the tree will have more leaves than symbols after generating it out of the given lengths. They call this an oversubscribed dynamic bit lengths tree in zlib.*/ case 55: return "jumped past tree while generating huffman tree"; case 56: return "given output image colortype or bitdepth not supported for color conversion"; case 57: return "invalid CRC encountered (checking CRC can be disabled)"; case 58: return "invalid ADLER32 encountered (checking ADLER32 can be disabled)"; case 59: return "requested color conversion not supported"; case 60: return "invalid window size given in the settings of the encoder (must be 0-32768)"; case 61: return "invalid BTYPE given in the settings of the encoder (only 0, 1 and 2 are allowed)"; /*LodePNG leaves the choice of RGB to grayscale conversion formula to the user.*/ case 62: return "conversion from color to grayscale not supported"; /*(2^31-1)*/ case 63: return "length of a chunk too long, max allowed for PNG is 2147483647 bytes per chunk"; /*this would result in the inability of a deflated block to ever contain an end code. It must be at least 1.*/ case 64: return "the length of the END symbol 256 in the Huffman tree is 0"; case 66: return "the length of a text chunk keyword given to the encoder is longer than the maximum of 79 bytes"; case 67: return "the length of a text chunk keyword given to the encoder is smaller than the minimum of 1 byte"; case 68: return "tried to encode a PLTE chunk with a palette that has less than 1 or more than 256 colors"; case 69: return "unknown chunk type with 'critical' flag encountered by the decoder"; case 71: return "invalid interlace mode given to encoder (must be 0 or 1)"; case 72: return "while decoding, invalid compression method encountering in zTXt or iTXt chunk (it must be 0)"; case 73: return "invalid tIME chunk size"; case 74: return "invalid pHYs chunk size"; /*length could be wrong, or data chopped off*/ case 75: return "no null termination char found while decoding text chunk"; case 76: return "iTXt chunk too short to contain required bytes"; case 77: return "integer overflow in buffer size"; case 78: return "failed to open file for reading"; /*file doesn't exist or couldn't be opened for reading*/ case 79: return "failed to open file for writing"; case 80: return "tried creating a tree of 0 symbols"; case 81: return "lazy matching at pos 0 is impossible"; case 82: return "color conversion to palette requested while a color isn't in palette, or index out of bounds"; case 83: return "memory allocation failed"; case 84: return "given image too small to contain all pixels to be encoded"; case 86: return "impossible offset in lz77 encoding (internal bug)"; case 87: return "must provide custom zlib function pointer if LODEPNG_COMPILE_ZLIB is not defined"; case 88: return "invalid filter strategy given for LodePNGEncoderSettings.filter_strategy"; case 89: return "text chunk keyword too short or long: must have size 1-79"; /*the windowsize in the LodePNGCompressSettings. Requiring POT(==> & instead of %) makes encoding 12% faster.*/ case 90: return "windowsize must be a power of two"; case 91: return "invalid decompressed idat size"; case 92: return "integer overflow due to too many pixels"; case 93: return "zero width or height is invalid"; case 94: return "header chunk must have a size of 13 bytes"; case 95: return "integer overflow with combined idat chunk size"; case 96: return "invalid gAMA chunk size"; case 97: return "invalid cHRM chunk size"; case 98: return "invalid sRGB chunk size"; case 99: return "invalid sRGB rendering intent"; case 100: return "invalid ICC profile color type, the PNG specification only allows RGB or GRAY"; case 101: return "PNG specification does not allow RGB ICC profile on gray color types and vice versa"; case 102: return "not allowed to set grayscale ICC profile with colored pixels by PNG specification"; case 103: return "invalid palette index in bKGD chunk. Maybe it came before PLTE chunk?"; case 104: return "invalid bKGD color while encoding (e.g. palette index out of range)"; case 105: return "integer overflow of bitsize"; case 106: return "PNG file must have PLTE chunk if color type is palette"; case 107: return "color convert from palette mode requested without setting the palette data in it"; case 108: return "tried to add more than 256 values to a palette"; /*this limit can be configured in LodePNGDecompressSettings*/ case 109: return "tried to decompress zlib or deflate data larger than desired max_output_size"; case 110: return "custom zlib or inflate decompression failed"; case 111: return "custom zlib or deflate compression failed"; /*max text size limit can be configured in LodePNGDecoderSettings. This error prevents unreasonable memory consumption when decoding due to impossibly large text sizes.*/ case 112: return "compressed text unreasonably large"; /*max ICC size limit can be configured in LodePNGDecoderSettings. This error prevents unreasonable memory consumption when decoding due to impossibly large ICC profile*/ case 113: return "ICC profile unreasonably large"; case 114: return "sBIT chunk has wrong size for the color type of the image"; case 115: return "sBIT value out of range"; } return "unknown error code"; } #endif /*LODEPNG_COMPILE_ERROR_TEXT*/ /* ////////////////////////////////////////////////////////////////////////// */ /* ////////////////////////////////////////////////////////////////////////// */ /* // C++ Wrapper // */ /* ////////////////////////////////////////////////////////////////////////// */ /* ////////////////////////////////////////////////////////////////////////// */ #ifdef LODEPNG_COMPILE_CPP namespace lodepng { #ifdef LODEPNG_COMPILE_DISK unsigned load_file(std::vector& buffer, const std::string& filename) { long size = lodepng_filesize(filename.c_str()); if(size < 0) return 78; buffer.resize((size_t)size); return size == 0 ? 0 : lodepng_buffer_file(&buffer[0], (size_t)size, filename.c_str()); } /*write given buffer to the file, overwriting the file, it doesn't append to it.*/ unsigned save_file(const std::vector& buffer, const std::string& filename) { return lodepng_save_file(buffer.empty() ? 0 : &buffer[0], buffer.size(), filename.c_str()); } #endif /* LODEPNG_COMPILE_DISK */ #ifdef LODEPNG_COMPILE_ZLIB #ifdef LODEPNG_COMPILE_DECODER unsigned decompress(std::vector& out, const unsigned char* in, size_t insize, const LodePNGDecompressSettings& settings) { unsigned char* buffer = 0; size_t buffersize = 0; unsigned error = zlib_decompress(&buffer, &buffersize, 0, in, insize, &settings); if(buffer) { out.insert(out.end(), &buffer[0], &buffer[buffersize]); lodepng_free(buffer); } return error; } unsigned decompress(std::vector& out, const std::vector& in, const LodePNGDecompressSettings& settings) { return decompress(out, in.empty() ? 0 : &in[0], in.size(), settings); } #endif /* LODEPNG_COMPILE_DECODER */ #ifdef LODEPNG_COMPILE_ENCODER unsigned compress(std::vector& out, const unsigned char* in, size_t insize, const LodePNGCompressSettings& settings) { unsigned char* buffer = 0; size_t buffersize = 0; unsigned error = zlib_compress(&buffer, &buffersize, in, insize, &settings); if(buffer) { out.insert(out.end(), &buffer[0], &buffer[buffersize]); lodepng_free(buffer); } return error; } unsigned compress(std::vector& out, const std::vector& in, const LodePNGCompressSettings& settings) { return compress(out, in.empty() ? 0 : &in[0], in.size(), settings); } #endif /* LODEPNG_COMPILE_ENCODER */ #endif /* LODEPNG_COMPILE_ZLIB */ #ifdef LODEPNG_COMPILE_PNG State::State() { lodepng_state_init(this); } State::State(const State& other) { lodepng_state_init(this); lodepng_state_copy(this, &other); } State::~State() { lodepng_state_cleanup(this); } State& State::operator=(const State& other) { lodepng_state_copy(this, &other); return *this; } #ifdef LODEPNG_COMPILE_DECODER unsigned decode(std::vector& out, unsigned& w, unsigned& h, const unsigned char* in, size_t insize, LodePNGColorType colortype, unsigned bitdepth) { unsigned char* buffer = 0; unsigned error = lodepng_decode_memory(&buffer, &w, &h, in, insize, colortype, bitdepth); if(buffer && !error) { State state; state.info_raw.colortype = colortype; state.info_raw.bitdepth = bitdepth; size_t buffersize = lodepng_get_raw_size(w, h, &state.info_raw); out.insert(out.end(), &buffer[0], &buffer[buffersize]); } lodepng_free(buffer); return error; } unsigned decode(std::vector& out, unsigned& w, unsigned& h, const std::vector& in, LodePNGColorType colortype, unsigned bitdepth) { return decode(out, w, h, in.empty() ? 0 : &in[0], (unsigned)in.size(), colortype, bitdepth); } unsigned decode(std::vector& out, unsigned& w, unsigned& h, State& state, const unsigned char* in, size_t insize) { unsigned char* buffer = NULL; unsigned error = lodepng_decode(&buffer, &w, &h, &state, in, insize); if(buffer && !error) { size_t buffersize = lodepng_get_raw_size(w, h, &state.info_raw); out.insert(out.end(), &buffer[0], &buffer[buffersize]); } lodepng_free(buffer); return error; } unsigned decode(std::vector& out, unsigned& w, unsigned& h, State& state, const std::vector& in) { return decode(out, w, h, state, in.empty() ? 0 : &in[0], in.size()); } #ifdef LODEPNG_COMPILE_DISK unsigned decode(std::vector& out, unsigned& w, unsigned& h, const std::string& filename, LodePNGColorType colortype, unsigned bitdepth) { std::vector buffer; /* safe output values in case error happens */ w = h = 0; unsigned error = load_file(buffer, filename); if(error) return error; return decode(out, w, h, buffer, colortype, bitdepth); } #endif /* LODEPNG_COMPILE_DECODER */ #endif /* LODEPNG_COMPILE_DISK */ #ifdef LODEPNG_COMPILE_ENCODER unsigned encode(std::vector& out, const unsigned char* in, unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth) { unsigned char* buffer; size_t buffersize; unsigned error = lodepng_encode_memory(&buffer, &buffersize, in, w, h, colortype, bitdepth); if(buffer) { out.insert(out.end(), &buffer[0], &buffer[buffersize]); lodepng_free(buffer); } return error; } unsigned encode(std::vector& out, const std::vector& in, unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth) { if(lodepng_get_raw_size_lct(w, h, colortype, bitdepth) > in.size()) return 84; return encode(out, in.empty() ? 0 : &in[0], w, h, colortype, bitdepth); } unsigned encode(std::vector& out, const unsigned char* in, unsigned w, unsigned h, State& state) { unsigned char* buffer; size_t buffersize; unsigned error = lodepng_encode(&buffer, &buffersize, in, w, h, &state); if(buffer) { out.insert(out.end(), &buffer[0], &buffer[buffersize]); lodepng_free(buffer); } return error; } unsigned encode(std::vector& out, const std::vector& in, unsigned w, unsigned h, State& state) { if(lodepng_get_raw_size(w, h, &state.info_raw) > in.size()) return 84; return encode(out, in.empty() ? 0 : &in[0], w, h, state); } #ifdef LODEPNG_COMPILE_DISK unsigned encode(const std::string& filename, const unsigned char* in, unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth) { std::vector buffer; unsigned error = encode(buffer, in, w, h, colortype, bitdepth); if(!error) error = save_file(buffer, filename); return error; } unsigned encode(const std::string& filename, const std::vector& in, unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth) { if(lodepng_get_raw_size_lct(w, h, colortype, bitdepth) > in.size()) return 84; return encode(filename, in.empty() ? 0 : &in[0], w, h, colortype, bitdepth); } #endif /* LODEPNG_COMPILE_DISK */ #endif /* LODEPNG_COMPILE_ENCODER */ #endif /* LODEPNG_COMPILE_PNG */ } /* namespace lodepng */ #endif /*LODEPNG_COMPILE_CPP*/ lodepng-0.0~git20220618.b4ed2cd/lodepng.h000066400000000000000000003073271425344217700175640ustar00rootroot00000000000000/* LodePNG version 20220618 Copyright (c) 2005-2022 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef LODEPNG_H #define LODEPNG_H #include /*for size_t*/ extern const char* LODEPNG_VERSION_STRING; /* The following #defines are used to create code sections. They can be disabled to disable code sections, which can give faster compile time and smaller binary. The "NO_COMPILE" defines are designed to be used to pass as defines to the compiler command to disable them without modifying this header, e.g. -DLODEPNG_NO_COMPILE_ZLIB for gcc or clang. */ /*deflate & zlib. If disabled, you must specify alternative zlib functions in the custom_zlib field of the compress and decompress settings*/ #ifndef LODEPNG_NO_COMPILE_ZLIB /*pass -DLODEPNG_NO_COMPILE_ZLIB to the compiler to disable this, or comment out LODEPNG_COMPILE_ZLIB below*/ #define LODEPNG_COMPILE_ZLIB #endif /*png encoder and png decoder*/ #ifndef LODEPNG_NO_COMPILE_PNG /*pass -DLODEPNG_NO_COMPILE_PNG to the compiler to disable this, or comment out LODEPNG_COMPILE_PNG below*/ #define LODEPNG_COMPILE_PNG #endif /*deflate&zlib decoder and png decoder*/ #ifndef LODEPNG_NO_COMPILE_DECODER /*pass -DLODEPNG_NO_COMPILE_DECODER to the compiler to disable this, or comment out LODEPNG_COMPILE_DECODER below*/ #define LODEPNG_COMPILE_DECODER #endif /*deflate&zlib encoder and png encoder*/ #ifndef LODEPNG_NO_COMPILE_ENCODER /*pass -DLODEPNG_NO_COMPILE_ENCODER to the compiler to disable this, or comment out LODEPNG_COMPILE_ENCODER below*/ #define LODEPNG_COMPILE_ENCODER #endif /*the optional built in harddisk file loading and saving functions*/ #ifndef LODEPNG_NO_COMPILE_DISK /*pass -DLODEPNG_NO_COMPILE_DISK to the compiler to disable this, or comment out LODEPNG_COMPILE_DISK below*/ #define LODEPNG_COMPILE_DISK #endif /*support for chunks other than IHDR, IDAT, PLTE, tRNS, IEND: ancillary and unknown chunks*/ #ifndef LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS /*pass -DLODEPNG_NO_COMPILE_ANCILLARY_CHUNKS to the compiler to disable this, or comment out LODEPNG_COMPILE_ANCILLARY_CHUNKS below*/ #define LODEPNG_COMPILE_ANCILLARY_CHUNKS #endif /*ability to convert error numerical codes to English text string*/ #ifndef LODEPNG_NO_COMPILE_ERROR_TEXT /*pass -DLODEPNG_NO_COMPILE_ERROR_TEXT to the compiler to disable this, or comment out LODEPNG_COMPILE_ERROR_TEXT below*/ #define LODEPNG_COMPILE_ERROR_TEXT #endif /*Compile the default allocators (C's free, malloc and realloc). If you disable this, you can define the functions lodepng_free, lodepng_malloc and lodepng_realloc in your source files with custom allocators.*/ #ifndef LODEPNG_NO_COMPILE_ALLOCATORS /*pass -DLODEPNG_NO_COMPILE_ALLOCATORS to the compiler to disable the built-in ones, or comment out LODEPNG_COMPILE_ALLOCATORS below*/ #define LODEPNG_COMPILE_ALLOCATORS #endif /*Disable built-in CRC function, in that case a custom implementation of lodepng_crc32 must be defined externally so that it can be linked in.*/ #ifndef LODEPNG_NO_COMPILE_CRC /*pass -DLODEPNG_NO_COMPILE_CRC to the compiler to disable the built-in one, or comment out LODEPNG_COMPILE_CRC below*/ #define LODEPNG_COMPILE_CRC #endif /*compile the C++ version (you can disable the C++ wrapper here even when compiling for C++)*/ #ifdef __cplusplus #ifndef LODEPNG_NO_COMPILE_CPP /*pass -DLODEPNG_NO_COMPILE_CPP to the compiler to disable C++ (not needed if a C-only compiler), or comment out LODEPNG_COMPILE_CPP below*/ #define LODEPNG_COMPILE_CPP #endif #endif #ifdef LODEPNG_COMPILE_CPP #include #include #endif /*LODEPNG_COMPILE_CPP*/ #ifdef LODEPNG_COMPILE_PNG /*The PNG color types (also used for raw image).*/ typedef enum LodePNGColorType { LCT_GREY = 0, /*grayscale: 1,2,4,8,16 bit*/ LCT_RGB = 2, /*RGB: 8,16 bit*/ LCT_PALETTE = 3, /*palette: 1,2,4,8 bit*/ LCT_GREY_ALPHA = 4, /*grayscale with alpha: 8,16 bit*/ LCT_RGBA = 6, /*RGB with alpha: 8,16 bit*/ /*LCT_MAX_OCTET_VALUE lets the compiler allow this enum to represent any invalid byte value from 0 to 255 that could be present in an invalid PNG file header. Do not use, compare with or set the name LCT_MAX_OCTET_VALUE, instead either use the valid color type names above, or numeric values like 1 or 7 when checking for particular disallowed color type byte values, or cast to integer to print it.*/ LCT_MAX_OCTET_VALUE = 255 } LodePNGColorType; #ifdef LODEPNG_COMPILE_DECODER /* Converts PNG data in memory to raw pixel data. out: Output parameter. Pointer to buffer that will contain the raw pixel data. After decoding, its size is w * h * (bytes per pixel) bytes larger than initially. Bytes per pixel depends on colortype and bitdepth. Must be freed after usage with free(*out). Note: for 16-bit per channel colors, uses big endian format like PNG does. w: Output parameter. Pointer to width of pixel data. h: Output parameter. Pointer to height of pixel data. in: Memory buffer with the PNG file. insize: size of the in buffer. colortype: the desired color type for the raw output image. See explanation on PNG color types. bitdepth: the desired bit depth for the raw output image. See explanation on PNG color types. Return value: LodePNG error code (0 means no error). */ unsigned lodepng_decode_memory(unsigned char** out, unsigned* w, unsigned* h, const unsigned char* in, size_t insize, LodePNGColorType colortype, unsigned bitdepth); /*Same as lodepng_decode_memory, but always decodes to 32-bit RGBA raw image*/ unsigned lodepng_decode32(unsigned char** out, unsigned* w, unsigned* h, const unsigned char* in, size_t insize); /*Same as lodepng_decode_memory, but always decodes to 24-bit RGB raw image*/ unsigned lodepng_decode24(unsigned char** out, unsigned* w, unsigned* h, const unsigned char* in, size_t insize); #ifdef LODEPNG_COMPILE_DISK /* Load PNG from disk, from file with given name. Same as the other decode functions, but instead takes a filename as input. NOTE: Wide-character filenames are not supported, you can use an external method to handle such files and decode in-memory.*/ unsigned lodepng_decode_file(unsigned char** out, unsigned* w, unsigned* h, const char* filename, LodePNGColorType colortype, unsigned bitdepth); /*Same as lodepng_decode_file, but always decodes to 32-bit RGBA raw image. NOTE: Wide-character filenames are not supported, you can use an external method to handle such files and decode in-memory.*/ unsigned lodepng_decode32_file(unsigned char** out, unsigned* w, unsigned* h, const char* filename); /*Same as lodepng_decode_file, but always decodes to 24-bit RGB raw image. NOTE: Wide-character filenames are not supported, you can use an external method to handle such files and decode in-memory.*/ unsigned lodepng_decode24_file(unsigned char** out, unsigned* w, unsigned* h, const char* filename); #endif /*LODEPNG_COMPILE_DISK*/ #endif /*LODEPNG_COMPILE_DECODER*/ #ifdef LODEPNG_COMPILE_ENCODER /* Converts raw pixel data into a PNG image in memory. The colortype and bitdepth of the output PNG image cannot be chosen, they are automatically determined by the colortype, bitdepth and content of the input pixel data. Note: for 16-bit per channel colors, needs big endian format like PNG does. out: Output parameter. Pointer to buffer that will contain the PNG image data. Must be freed after usage with free(*out). outsize: Output parameter. Pointer to the size in bytes of the out buffer. image: The raw pixel data to encode. The size of this buffer should be w * h * (bytes per pixel), bytes per pixel depends on colortype and bitdepth. w: width of the raw pixel data in pixels. h: height of the raw pixel data in pixels. colortype: the color type of the raw input image. See explanation on PNG color types. bitdepth: the bit depth of the raw input image. See explanation on PNG color types. Return value: LodePNG error code (0 means no error). */ unsigned lodepng_encode_memory(unsigned char** out, size_t* outsize, const unsigned char* image, unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth); /*Same as lodepng_encode_memory, but always encodes from 32-bit RGBA raw image.*/ unsigned lodepng_encode32(unsigned char** out, size_t* outsize, const unsigned char* image, unsigned w, unsigned h); /*Same as lodepng_encode_memory, but always encodes from 24-bit RGB raw image.*/ unsigned lodepng_encode24(unsigned char** out, size_t* outsize, const unsigned char* image, unsigned w, unsigned h); #ifdef LODEPNG_COMPILE_DISK /* Converts raw pixel data into a PNG file on disk. Same as the other encode functions, but instead takes a filename as output. NOTE: This overwrites existing files without warning! NOTE: Wide-character filenames are not supported, you can use an external method to handle such files and encode in-memory.*/ unsigned lodepng_encode_file(const char* filename, const unsigned char* image, unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth); /*Same as lodepng_encode_file, but always encodes from 32-bit RGBA raw image. NOTE: Wide-character filenames are not supported, you can use an external method to handle such files and encode in-memory.*/ unsigned lodepng_encode32_file(const char* filename, const unsigned char* image, unsigned w, unsigned h); /*Same as lodepng_encode_file, but always encodes from 24-bit RGB raw image. NOTE: Wide-character filenames are not supported, you can use an external method to handle such files and encode in-memory.*/ unsigned lodepng_encode24_file(const char* filename, const unsigned char* image, unsigned w, unsigned h); #endif /*LODEPNG_COMPILE_DISK*/ #endif /*LODEPNG_COMPILE_ENCODER*/ #ifdef LODEPNG_COMPILE_CPP namespace lodepng { #ifdef LODEPNG_COMPILE_DECODER /*Same as lodepng_decode_memory, but decodes to an std::vector. The colortype is the format to output the pixels to. Default is RGBA 8-bit per channel.*/ unsigned decode(std::vector& out, unsigned& w, unsigned& h, const unsigned char* in, size_t insize, LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); unsigned decode(std::vector& out, unsigned& w, unsigned& h, const std::vector& in, LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); #ifdef LODEPNG_COMPILE_DISK /* Converts PNG file from disk to raw pixel data in memory. Same as the other decode functions, but instead takes a filename as input. NOTE: Wide-character filenames are not supported, you can use an external method to handle such files and decode in-memory. */ unsigned decode(std::vector& out, unsigned& w, unsigned& h, const std::string& filename, LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); #endif /* LODEPNG_COMPILE_DISK */ #endif /* LODEPNG_COMPILE_DECODER */ #ifdef LODEPNG_COMPILE_ENCODER /*Same as lodepng_encode_memory, but encodes to an std::vector. colortype is that of the raw input data. The output PNG color type will be auto chosen.*/ unsigned encode(std::vector& out, const unsigned char* in, unsigned w, unsigned h, LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); unsigned encode(std::vector& out, const std::vector& in, unsigned w, unsigned h, LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); #ifdef LODEPNG_COMPILE_DISK /* Converts 32-bit RGBA raw pixel data into a PNG file on disk. Same as the other encode functions, but instead takes a filename as output. NOTE: This overwrites existing files without warning! NOTE: Wide-character filenames are not supported, you can use an external method to handle such files and decode in-memory. */ unsigned encode(const std::string& filename, const unsigned char* in, unsigned w, unsigned h, LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); unsigned encode(const std::string& filename, const std::vector& in, unsigned w, unsigned h, LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); #endif /* LODEPNG_COMPILE_DISK */ #endif /* LODEPNG_COMPILE_ENCODER */ } /* namespace lodepng */ #endif /*LODEPNG_COMPILE_CPP*/ #endif /*LODEPNG_COMPILE_PNG*/ #ifdef LODEPNG_COMPILE_ERROR_TEXT /*Returns an English description of the numerical error code.*/ const char* lodepng_error_text(unsigned code); #endif /*LODEPNG_COMPILE_ERROR_TEXT*/ #ifdef LODEPNG_COMPILE_DECODER /*Settings for zlib decompression*/ typedef struct LodePNGDecompressSettings LodePNGDecompressSettings; struct LodePNGDecompressSettings { /* Check LodePNGDecoderSettings for more ignorable errors such as ignore_crc */ unsigned ignore_adler32; /*if 1, continue and don't give an error message if the Adler32 checksum is corrupted*/ unsigned ignore_nlen; /*ignore complement of len checksum in uncompressed blocks*/ /*Maximum decompressed size, beyond this the decoder may (and is encouraged to) stop decoding, return an error, output a data size > max_output_size and all the data up to that point. This is not hard limit nor a guarantee, but can prevent excessive memory usage. This setting is ignored by the PNG decoder, but is used by the deflate/zlib decoder and can be used by custom ones. Set to 0 to impose no limit (the default).*/ size_t max_output_size; /*use custom zlib decoder instead of built in one (default: null). Should return 0 if success, any non-0 if error (numeric value not exposed).*/ unsigned (*custom_zlib)(unsigned char**, size_t*, const unsigned char*, size_t, const LodePNGDecompressSettings*); /*use custom deflate decoder instead of built in one (default: null) if custom_zlib is not null, custom_inflate is ignored (the zlib format uses deflate). Should return 0 if success, any non-0 if error (numeric value not exposed).*/ unsigned (*custom_inflate)(unsigned char**, size_t*, const unsigned char*, size_t, const LodePNGDecompressSettings*); const void* custom_context; /*optional custom settings for custom functions*/ }; extern const LodePNGDecompressSettings lodepng_default_decompress_settings; void lodepng_decompress_settings_init(LodePNGDecompressSettings* settings); #endif /*LODEPNG_COMPILE_DECODER*/ #ifdef LODEPNG_COMPILE_ENCODER /* Settings for zlib compression. Tweaking these settings tweaks the balance between speed and compression ratio. */ typedef struct LodePNGCompressSettings LodePNGCompressSettings; struct LodePNGCompressSettings /*deflate = compress*/ { /*LZ77 related settings*/ unsigned btype; /*the block type for LZ (0, 1, 2 or 3, see zlib standard). Should be 2 for proper compression.*/ unsigned use_lz77; /*whether or not to use LZ77. Should be 1 for proper compression.*/ unsigned windowsize; /*must be a power of two <= 32768. higher compresses more but is slower. Default value: 2048.*/ unsigned minmatch; /*minimum lz77 length. 3 is normally best, 6 can be better for some PNGs. Default: 0*/ unsigned nicematch; /*stop searching if >= this length found. Set to 258 for best compression. Default: 128*/ unsigned lazymatching; /*use lazy matching: better compression but a bit slower. Default: true*/ /*use custom zlib encoder instead of built in one (default: null)*/ unsigned (*custom_zlib)(unsigned char**, size_t*, const unsigned char*, size_t, const LodePNGCompressSettings*); /*use custom deflate encoder instead of built in one (default: null) if custom_zlib is used, custom_deflate is ignored since only the built in zlib function will call custom_deflate*/ unsigned (*custom_deflate)(unsigned char**, size_t*, const unsigned char*, size_t, const LodePNGCompressSettings*); const void* custom_context; /*optional custom settings for custom functions*/ }; extern const LodePNGCompressSettings lodepng_default_compress_settings; void lodepng_compress_settings_init(LodePNGCompressSettings* settings); #endif /*LODEPNG_COMPILE_ENCODER*/ #ifdef LODEPNG_COMPILE_PNG /* Color mode of an image. Contains all information required to decode the pixel bits to RGBA colors. This information is the same as used in the PNG file format, and is used both for PNG and raw image data in LodePNG. */ typedef struct LodePNGColorMode { /*header (IHDR)*/ LodePNGColorType colortype; /*color type, see PNG standard or documentation further in this header file*/ unsigned bitdepth; /*bits per sample, see PNG standard or documentation further in this header file*/ /* palette (PLTE and tRNS) Dynamically allocated with the colors of the palette, including alpha. This field may not be allocated directly, use lodepng_color_mode_init first, then lodepng_palette_add per color to correctly initialize it (to ensure size of exactly 1024 bytes). The alpha channels must be set as well, set them to 255 for opaque images. When decoding, with the default settings you can ignore this palette, since LodePNG already fills the palette colors in the pixels of the raw RGBA output, but when decoding to the original PNG color mode it is needed to reconstruct the colors. The palette is only supported for color type 3. */ unsigned char* palette; /*palette in RGBARGBA... order. Must be either 0, or when allocated must have 1024 bytes*/ size_t palettesize; /*palette size in number of colors (amount of used bytes is 4 * palettesize)*/ /* transparent color key (tRNS) This color uses the same bit depth as the bitdepth value in this struct, which can be 1-bit to 16-bit. For grayscale PNGs, r, g and b will all 3 be set to the same. When decoding, by default you can ignore this information, since LodePNG sets pixels with this key to transparent already in the raw RGBA output. The color key is only supported for color types 0 and 2. */ unsigned key_defined; /*is a transparent color key given? 0 = false, 1 = true*/ unsigned key_r; /*red/grayscale component of color key*/ unsigned key_g; /*green component of color key*/ unsigned key_b; /*blue component of color key*/ } LodePNGColorMode; /*init, cleanup and copy functions to use with this struct*/ void lodepng_color_mode_init(LodePNGColorMode* info); void lodepng_color_mode_cleanup(LodePNGColorMode* info); /*return value is error code (0 means no error)*/ unsigned lodepng_color_mode_copy(LodePNGColorMode* dest, const LodePNGColorMode* source); /* Makes a temporary LodePNGColorMode that does not need cleanup (no palette) */ LodePNGColorMode lodepng_color_mode_make(LodePNGColorType colortype, unsigned bitdepth); void lodepng_palette_clear(LodePNGColorMode* info); /*add 1 color to the palette*/ unsigned lodepng_palette_add(LodePNGColorMode* info, unsigned char r, unsigned char g, unsigned char b, unsigned char a); /*get the total amount of bits per pixel, based on colortype and bitdepth in the struct*/ unsigned lodepng_get_bpp(const LodePNGColorMode* info); /*get the amount of color channels used, based on colortype in the struct. If a palette is used, it counts as 1 channel.*/ unsigned lodepng_get_channels(const LodePNGColorMode* info); /*is it a grayscale type? (only colortype 0 or 4)*/ unsigned lodepng_is_greyscale_type(const LodePNGColorMode* info); /*has it got an alpha channel? (only colortype 2 or 6)*/ unsigned lodepng_is_alpha_type(const LodePNGColorMode* info); /*has it got a palette? (only colortype 3)*/ unsigned lodepng_is_palette_type(const LodePNGColorMode* info); /*only returns true if there is a palette and there is a value in the palette with alpha < 255. Loops through the palette to check this.*/ unsigned lodepng_has_palette_alpha(const LodePNGColorMode* info); /* Check if the given color info indicates the possibility of having non-opaque pixels in the PNG image. Returns true if the image can have translucent or invisible pixels (it still be opaque if it doesn't use such pixels). Returns false if the image can only have opaque pixels. In detail, it returns true only if it's a color type with alpha, or has a palette with non-opaque values, or if "key_defined" is true. */ unsigned lodepng_can_have_alpha(const LodePNGColorMode* info); /*Returns the byte size of a raw image buffer with given width, height and color mode*/ size_t lodepng_get_raw_size(unsigned w, unsigned h, const LodePNGColorMode* color); #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS /*The information of a Time chunk in PNG.*/ typedef struct LodePNGTime { unsigned year; /*2 bytes used (0-65535)*/ unsigned month; /*1-12*/ unsigned day; /*1-31*/ unsigned hour; /*0-23*/ unsigned minute; /*0-59*/ unsigned second; /*0-60 (to allow for leap seconds)*/ } LodePNGTime; #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ /*Information about the PNG image, except pixels, width and height.*/ typedef struct LodePNGInfo { /*header (IHDR), palette (PLTE) and transparency (tRNS) chunks*/ unsigned compression_method;/*compression method of the original file. Always 0.*/ unsigned filter_method; /*filter method of the original file*/ unsigned interlace_method; /*interlace method of the original file: 0=none, 1=Adam7*/ LodePNGColorMode color; /*color type and bits, palette and transparency of the PNG file*/ #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS /* Suggested background color chunk (bKGD) This uses the same color mode and bit depth as the PNG (except no alpha channel), with values truncated to the bit depth in the unsigned integer. For grayscale and palette PNGs, the value is stored in background_r. The values in background_g and background_b are then unused. The decoder will set them equal to background_r, the encoder ignores them in this case. When decoding, you may get these in a different color mode than the one you requested for the raw pixels: the colortype and bitdepth defined by info_png.color, that is the ones defined in the header of the PNG image, are used. When encoding with auto_convert, you must use the color model defined in info_png.color for these values. The encoder normally ignores info_png.color when auto_convert is on, but will use it to interpret these values (and convert copies of them to its chosen color model). When encoding, avoid setting this to an expensive color, such as a non-gray value when the image is gray, or the compression will be worse since it will be forced to write the PNG with a more expensive color mode (when auto_convert is on). The decoder does not use this background color to edit the color of pixels. This is a completely optional metadata feature. */ unsigned background_defined; /*is a suggested background color given?*/ unsigned background_r; /*red/gray/palette component of suggested background color*/ unsigned background_g; /*green component of suggested background color*/ unsigned background_b; /*blue component of suggested background color*/ /* Non-international text chunks (tEXt and zTXt) The char** arrays each contain num strings. The actual messages are in text_strings, while text_keys are keywords that give a short description what the actual text represents, e.g. Title, Author, Description, or anything else. All the string fields below including strings, keys, names and language tags are null terminated. The PNG specification uses null characters for the keys, names and tags, and forbids null characters to appear in the main text which is why we can use null termination everywhere here. A keyword is minimum 1 character and maximum 79 characters long (plus the additional null terminator). It's discouraged to use a single line length longer than 79 characters for texts. Don't allocate these text buffers yourself. Use the init/cleanup functions correctly and use lodepng_add_text and lodepng_clear_text. Standard text chunk keywords and strings are encoded using Latin-1. */ size_t text_num; /*the amount of texts in these char** buffers (there may be more texts in itext)*/ char** text_keys; /*the keyword of a text chunk (e.g. "Comment")*/ char** text_strings; /*the actual text*/ /* International text chunks (iTXt) Similar to the non-international text chunks, but with additional strings "langtags" and "transkeys", and the following text encodings are used: keys: Latin-1, langtags: ASCII, transkeys and strings: UTF-8. keys must be 1-79 characters (plus the additional null terminator), the other strings are any length. */ size_t itext_num; /*the amount of international texts in this PNG*/ char** itext_keys; /*the English keyword of the text chunk (e.g. "Comment")*/ char** itext_langtags; /*language tag for this text's language, ISO/IEC 646 string, e.g. ISO 639 language tag*/ char** itext_transkeys; /*keyword translated to the international language - UTF-8 string*/ char** itext_strings; /*the actual international text - UTF-8 string*/ /*time chunk (tIME)*/ unsigned time_defined; /*set to 1 to make the encoder generate a tIME chunk*/ LodePNGTime time; /*phys chunk (pHYs)*/ unsigned phys_defined; /*if 0, there is no pHYs chunk and the values below are undefined, if 1 else there is one*/ unsigned phys_x; /*pixels per unit in x direction*/ unsigned phys_y; /*pixels per unit in y direction*/ unsigned phys_unit; /*may be 0 (unknown unit) or 1 (metre)*/ /* Color profile related chunks: gAMA, cHRM, sRGB, iCPP, sBIT LodePNG does not apply any color conversions on pixels in the encoder or decoder and does not interpret these color profile values. It merely passes on the information. If you wish to use color profiles and convert colors, please use these values with a color management library. See the PNG, ICC and sRGB specifications for more information about the meaning of these values. */ /* gAMA chunk: optional, overridden by sRGB or iCCP if those are present. */ unsigned gama_defined; /* Whether a gAMA chunk is present (0 = not present, 1 = present). */ unsigned gama_gamma; /* Gamma exponent times 100000 */ /* cHRM chunk: optional, overridden by sRGB or iCCP if those are present. */ unsigned chrm_defined; /* Whether a cHRM chunk is present (0 = not present, 1 = present). */ unsigned chrm_white_x; /* White Point x times 100000 */ unsigned chrm_white_y; /* White Point y times 100000 */ unsigned chrm_red_x; /* Red x times 100000 */ unsigned chrm_red_y; /* Red y times 100000 */ unsigned chrm_green_x; /* Green x times 100000 */ unsigned chrm_green_y; /* Green y times 100000 */ unsigned chrm_blue_x; /* Blue x times 100000 */ unsigned chrm_blue_y; /* Blue y times 100000 */ /* sRGB chunk: optional. May not appear at the same time as iCCP. If gAMA is also present gAMA must contain value 45455. If cHRM is also present cHRM must contain respectively 31270,32900,64000,33000,30000,60000,15000,6000. */ unsigned srgb_defined; /* Whether an sRGB chunk is present (0 = not present, 1 = present). */ unsigned srgb_intent; /* Rendering intent: 0=perceptual, 1=rel. colorimetric, 2=saturation, 3=abs. colorimetric */ /* iCCP chunk: optional. May not appear at the same time as sRGB. LodePNG does not parse or use the ICC profile (except its color space header field for an edge case), a separate library to handle the ICC data (not included in LodePNG) format is needed to use it for color management and conversions. For encoding, if iCCP is present, gAMA and cHRM are recommended to be added as well with values that match the ICC profile as closely as possible, if you wish to do this you should provide the correct values for gAMA and cHRM and enable their '_defined' flags since LodePNG will not automatically compute them from the ICC profile. For encoding, the ICC profile is required by the PNG specification to be an "RGB" profile for non-gray PNG color types and a "GRAY" profile for gray PNG color types. If you disable auto_convert, you must ensure the ICC profile type matches your requested color type, else the encoder gives an error. If auto_convert is enabled (the default), and the ICC profile is not a good match for the pixel data, this will result in an encoder error if the pixel data has non-gray pixels for a GRAY profile, or a silent less-optimal compression of the pixel data if the pixels could be encoded as grayscale but the ICC profile is RGB. To avoid this do not set an ICC profile in the image unless there is a good reason for it, and when doing so make sure you compute it carefully to avoid the above problems. */ unsigned iccp_defined; /* Whether an iCCP chunk is present (0 = not present, 1 = present). */ char* iccp_name; /* Null terminated string with profile name, 1-79 bytes */ /* The ICC profile in iccp_profile_size bytes. Don't allocate this buffer yourself. Use the init/cleanup functions correctly and use lodepng_set_icc and lodepng_clear_icc. */ unsigned char* iccp_profile; unsigned iccp_profile_size; /* The size of iccp_profile in bytes */ /* sBIT chunk: significant bits. Optional metadata, only set this if needed. If defined, these values give the bit depth of the original data. Since PNG only stores 1, 2, 4, 8 or 16-bit per channel data, the significant bits value can be used to indicate the original encoded data has another sample depth, such as 10 or 12. Encoders using this value, when storing the pixel data, should use the most significant bits of the data to store the original bits, and use a good sample depth scaling method such as "left bit replication" to fill in the least significant bits, rather than fill zeroes. Decoders using this value, if able to work with data that's e.g. 10-bit or 12-bit, should right shift the data to go back to the original bit depth, but decoders are also allowed to ignore sbit and work e.g. with the 8-bit or 16-bit data from the PNG directly, since thanks to the encoder contract, the values encoded in PNG are in valid range for the PNG bit depth. For grayscale images, sbit_g and sbit_b are not used, and for images that don't use color type RGBA or grayscale+alpha, sbit_a is not used (it's not used even for palette images with translucent palette values, or images with color key). The values that are used must be greater than zero and smaller than or equal to the PNG bit depth. The color type from the header in the PNG image defines these used and unused fields: if decoding with a color mode conversion, such as always decoding to RGBA, this metadata still only uses the color type of the original PNG, and may e.g. lack the alpha channel info if the PNG was RGB. When encoding with auto_convert (as well as without), also always the color model defined in info_png.color determines this. NOTE: enabling sbit can hurt compression, because the encoder can then not always use auto_convert to choose a more optimal color mode for the data, because the PNG format has strict requirements for the allowed sbit values in combination with color modes. For example, setting these fields to 10-bit will force the encoder to keep using a 16-bit per channel color mode, even if the pixel data would in fact fit in a more efficient 8-bit mode. */ unsigned sbit_defined; /*is significant bits given? if not, the values below are unused*/ unsigned sbit_r; /*red or gray component of significant bits*/ unsigned sbit_g; /*green component of significant bits*/ unsigned sbit_b; /*blue component of significant bits*/ unsigned sbit_a; /*alpha component of significant bits*/ /* End of color profile related chunks */ /* unknown chunks: chunks not known by LodePNG, passed on byte for byte. There are 3 buffers, one for each position in the PNG where unknown chunks can appear. Each buffer contains all unknown chunks for that position consecutively. The 3 positions are: 0: between IHDR and PLTE, 1: between PLTE and IDAT, 2: between IDAT and IEND. For encoding, do not store critical chunks or known chunks that are enabled with a "_defined" flag above in here, since the encoder will blindly follow this and could then encode an invalid PNG file (such as one with two IHDR chunks or the disallowed combination of sRGB with iCCP). But do use this if you wish to store an ancillary chunk that is not supported by LodePNG (such as sPLT or hIST), or any non-standard PNG chunk. Do not allocate or traverse this data yourself. Use the chunk traversing functions declared later, such as lodepng_chunk_next and lodepng_chunk_append, to read/write this struct. */ unsigned char* unknown_chunks_data[3]; size_t unknown_chunks_size[3]; /*size in bytes of the unknown chunks, given for protection*/ #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ } LodePNGInfo; /*init, cleanup and copy functions to use with this struct*/ void lodepng_info_init(LodePNGInfo* info); void lodepng_info_cleanup(LodePNGInfo* info); /*return value is error code (0 means no error)*/ unsigned lodepng_info_copy(LodePNGInfo* dest, const LodePNGInfo* source); #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS unsigned lodepng_add_text(LodePNGInfo* info, const char* key, const char* str); /*push back both texts at once*/ void lodepng_clear_text(LodePNGInfo* info); /*use this to clear the texts again after you filled them in*/ unsigned lodepng_add_itext(LodePNGInfo* info, const char* key, const char* langtag, const char* transkey, const char* str); /*push back the 4 texts of 1 chunk at once*/ void lodepng_clear_itext(LodePNGInfo* info); /*use this to clear the itexts again after you filled them in*/ /*replaces if exists*/ unsigned lodepng_set_icc(LodePNGInfo* info, const char* name, const unsigned char* profile, unsigned profile_size); void lodepng_clear_icc(LodePNGInfo* info); /*use this to clear the texts again after you filled them in*/ #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ /* Converts raw buffer from one color type to another color type, based on LodePNGColorMode structs to describe the input and output color type. See the reference manual at the end of this header file to see which color conversions are supported. return value = LodePNG error code (0 if all went ok, an error if the conversion isn't supported) The out buffer must have size (w * h * bpp + 7) / 8, where bpp is the bits per pixel of the output color type (lodepng_get_bpp). For < 8 bpp images, there should not be padding bits at the end of scanlines. For 16-bit per channel colors, uses big endian format like PNG does. Return value is LodePNG error code */ unsigned lodepng_convert(unsigned char* out, const unsigned char* in, const LodePNGColorMode* mode_out, const LodePNGColorMode* mode_in, unsigned w, unsigned h); #ifdef LODEPNG_COMPILE_DECODER /* Settings for the decoder. This contains settings for the PNG and the Zlib decoder, but not the Info settings from the Info structs. */ typedef struct LodePNGDecoderSettings { LodePNGDecompressSettings zlibsettings; /*in here is the setting to ignore Adler32 checksums*/ /* Check LodePNGDecompressSettings for more ignorable errors such as ignore_adler32 */ unsigned ignore_crc; /*ignore CRC checksums*/ unsigned ignore_critical; /*ignore unknown critical chunks*/ unsigned ignore_end; /*ignore issues at end of file if possible (missing IEND chunk, too large chunk, ...)*/ /* TODO: make a system involving warnings with levels and a strict mode instead. Other potentially recoverable errors: srgb rendering intent value, size of content of ancillary chunks, more than 79 characters for some strings, placement/combination rules for ancillary chunks, crc of unknown chunks, allowed characters in string keys, etc... */ unsigned color_convert; /*whether to convert the PNG to the color type you want. Default: yes*/ #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS unsigned read_text_chunks; /*if false but remember_unknown_chunks is true, they're stored in the unknown chunks*/ /*store all bytes from unknown chunks in the LodePNGInfo (off by default, useful for a png editor)*/ unsigned remember_unknown_chunks; /* maximum size for decompressed text chunks. If a text chunk's text is larger than this, an error is returned, unless reading text chunks is disabled or this limit is set higher or disabled. Set to 0 to allow any size. By default it is a value that prevents unreasonably large strings from hogging memory. */ size_t max_text_size; /* maximum size for compressed ICC chunks. If the ICC profile is larger than this, an error will be returned. Set to 0 to allow any size. By default this is a value that prevents ICC profiles that would be much larger than any legitimate profile could be to hog memory. */ size_t max_icc_size; #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ } LodePNGDecoderSettings; void lodepng_decoder_settings_init(LodePNGDecoderSettings* settings); #endif /*LODEPNG_COMPILE_DECODER*/ #ifdef LODEPNG_COMPILE_ENCODER /*automatically use color type with less bits per pixel if losslessly possible. Default: AUTO*/ typedef enum LodePNGFilterStrategy { /*every filter at zero*/ LFS_ZERO = 0, /*every filter at 1, 2, 3 or 4 (paeth), unlike LFS_ZERO not a good choice, but for testing*/ LFS_ONE = 1, LFS_TWO = 2, LFS_THREE = 3, LFS_FOUR = 4, /*Use filter that gives minimum sum, as described in the official PNG filter heuristic.*/ LFS_MINSUM, /*Use the filter type that gives smallest Shannon entropy for this scanline. Depending on the image, this is better or worse than minsum.*/ LFS_ENTROPY, /* Brute-force-search PNG filters by compressing each filter for each scanline. Experimental, very slow, and only rarely gives better compression than MINSUM. */ LFS_BRUTE_FORCE, /*use predefined_filters buffer: you specify the filter type for each scanline*/ LFS_PREDEFINED } LodePNGFilterStrategy; /*Gives characteristics about the integer RGBA colors of the image (count, alpha channel usage, bit depth, ...), which helps decide which color model to use for encoding. Used internally by default if "auto_convert" is enabled. Public because it's useful for custom algorithms.*/ typedef struct LodePNGColorStats { unsigned colored; /*not grayscale*/ unsigned key; /*image is not opaque and color key is possible instead of full alpha*/ unsigned short key_r; /*key values, always as 16-bit, in 8-bit case the byte is duplicated, e.g. 65535 means 255*/ unsigned short key_g; unsigned short key_b; unsigned alpha; /*image is not opaque and alpha channel or alpha palette required*/ unsigned numcolors; /*amount of colors, up to 257. Not valid if bits == 16 or allow_palette is disabled.*/ unsigned char palette[1024]; /*Remembers up to the first 256 RGBA colors, in no particular order, only valid when numcolors is valid*/ unsigned bits; /*bits per channel (not for palette). 1,2 or 4 for grayscale only. 16 if 16-bit per channel required.*/ size_t numpixels; /*user settings for computing/using the stats*/ unsigned allow_palette; /*default 1. if 0, disallow choosing palette colortype in auto_choose_color, and don't count numcolors*/ unsigned allow_greyscale; /*default 1. if 0, choose RGB or RGBA even if the image only has gray colors*/ } LodePNGColorStats; void lodepng_color_stats_init(LodePNGColorStats* stats); /*Get a LodePNGColorStats of the image. The stats must already have been inited. Returns error code (e.g. alloc fail) or 0 if ok.*/ unsigned lodepng_compute_color_stats(LodePNGColorStats* stats, const unsigned char* image, unsigned w, unsigned h, const LodePNGColorMode* mode_in); /*Settings for the encoder.*/ typedef struct LodePNGEncoderSettings { LodePNGCompressSettings zlibsettings; /*settings for the zlib encoder, such as window size, ...*/ unsigned auto_convert; /*automatically choose output PNG color type. Default: true*/ /*If true, follows the official PNG heuristic: if the PNG uses a palette or lower than 8 bit depth, set all filters to zero. Otherwise use the filter_strategy. Note that to completely follow the official PNG heuristic, filter_palette_zero must be true and filter_strategy must be LFS_MINSUM*/ unsigned filter_palette_zero; /*Which filter strategy to use when not using zeroes due to filter_palette_zero. Set filter_palette_zero to 0 to ensure always using your chosen strategy. Default: LFS_MINSUM*/ LodePNGFilterStrategy filter_strategy; /*used if filter_strategy is LFS_PREDEFINED. In that case, this must point to a buffer with the same length as the amount of scanlines in the image, and each value must <= 5. You have to cleanup this buffer, LodePNG will never free it. Don't forget that filter_palette_zero must be set to 0 to ensure this is also used on palette or low bitdepth images.*/ const unsigned char* predefined_filters; /*force creating a PLTE chunk if colortype is 2 or 6 (= a suggested palette). If colortype is 3, PLTE is always created. If color type is explicitely set to a grayscale type (1 or 4), this is not done and is ignored. If enabling this, a palette must be present in the info_png. NOTE: enabling this may worsen compression if auto_convert is used to choose optimal color mode, because it cannot use grayscale color modes in this case*/ unsigned force_palette; #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS /*add LodePNG identifier and version as a text chunk, for debugging*/ unsigned add_id; /*encode text chunks as zTXt chunks instead of tEXt chunks, and use compression in iTXt chunks*/ unsigned text_compression; #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ } LodePNGEncoderSettings; void lodepng_encoder_settings_init(LodePNGEncoderSettings* settings); #endif /*LODEPNG_COMPILE_ENCODER*/ #if defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ENCODER) /*The settings, state and information for extended encoding and decoding.*/ typedef struct LodePNGState { #ifdef LODEPNG_COMPILE_DECODER LodePNGDecoderSettings decoder; /*the decoding settings*/ #endif /*LODEPNG_COMPILE_DECODER*/ #ifdef LODEPNG_COMPILE_ENCODER LodePNGEncoderSettings encoder; /*the encoding settings*/ #endif /*LODEPNG_COMPILE_ENCODER*/ LodePNGColorMode info_raw; /*specifies the format in which you would like to get the raw pixel buffer*/ LodePNGInfo info_png; /*info of the PNG image obtained after decoding*/ unsigned error; } LodePNGState; /*init, cleanup and copy functions to use with this struct*/ void lodepng_state_init(LodePNGState* state); void lodepng_state_cleanup(LodePNGState* state); void lodepng_state_copy(LodePNGState* dest, const LodePNGState* source); #endif /* defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ENCODER) */ #ifdef LODEPNG_COMPILE_DECODER /* Same as lodepng_decode_memory, but uses a LodePNGState to allow custom settings and getting much more information about the PNG image and color mode. */ unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h, LodePNGState* state, const unsigned char* in, size_t insize); /* Read the PNG header, but not the actual data. This returns only the information that is in the IHDR chunk of the PNG, such as width, height and color type. The information is placed in the info_png field of the LodePNGState. */ unsigned lodepng_inspect(unsigned* w, unsigned* h, LodePNGState* state, const unsigned char* in, size_t insize); #endif /*LODEPNG_COMPILE_DECODER*/ /* Reads one metadata chunk (other than IHDR, which is handled by lodepng_inspect) of the PNG file and outputs what it read in the state. Returns error code on failure. Use lodepng_inspect first with a new state, then e.g. lodepng_chunk_find_const to find the desired chunk type, and if non null use lodepng_inspect_chunk (with chunk_pointer - start_of_file as pos). Supports most metadata chunks from the PNG standard (gAMA, bKGD, tEXt, ...). Ignores unsupported, unknown, non-metadata or IHDR chunks (without error). Requirements: &in[pos] must point to start of a chunk, must use regular lodepng_inspect first since format of most other chunks depends on IHDR, and if there is a PLTE chunk, that one must be inspected before tRNS or bKGD. */ unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos, const unsigned char* in, size_t insize); #ifdef LODEPNG_COMPILE_ENCODER /*This function allocates the out buffer with standard malloc and stores the size in *outsize.*/ unsigned lodepng_encode(unsigned char** out, size_t* outsize, const unsigned char* image, unsigned w, unsigned h, LodePNGState* state); #endif /*LODEPNG_COMPILE_ENCODER*/ /* The lodepng_chunk functions are normally not needed, except to traverse the unknown chunks stored in the LodePNGInfo struct, or add new ones to it. It also allows traversing the chunks of an encoded PNG file yourself. The chunk pointer always points to the beginning of the chunk itself, that is the first byte of the 4 length bytes. In the PNG file format, chunks have the following format: -4 bytes length: length of the data of the chunk in bytes (chunk itself is 12 bytes longer) -4 bytes chunk type (ASCII a-z,A-Z only, see below) -length bytes of data (may be 0 bytes if length was 0) -4 bytes of CRC, computed on chunk name + data The first chunk starts at the 8th byte of the PNG file, the entire rest of the file exists out of concatenated chunks with the above format. PNG standard chunk ASCII naming conventions: -First byte: uppercase = critical, lowercase = ancillary -Second byte: uppercase = public, lowercase = private -Third byte: must be uppercase -Fourth byte: uppercase = unsafe to copy, lowercase = safe to copy */ /* Gets the length of the data of the chunk. Total chunk length has 12 bytes more. There must be at least 4 bytes to read from. If the result value is too large, it may be corrupt data. */ unsigned lodepng_chunk_length(const unsigned char* chunk); /*puts the 4-byte type in null terminated string*/ void lodepng_chunk_type(char type[5], const unsigned char* chunk); /*check if the type is the given type*/ unsigned char lodepng_chunk_type_equals(const unsigned char* chunk, const char* type); /*0: it's one of the critical chunk types, 1: it's an ancillary chunk (see PNG standard)*/ unsigned char lodepng_chunk_ancillary(const unsigned char* chunk); /*0: public, 1: private (see PNG standard)*/ unsigned char lodepng_chunk_private(const unsigned char* chunk); /*0: the chunk is unsafe to copy, 1: the chunk is safe to copy (see PNG standard)*/ unsigned char lodepng_chunk_safetocopy(const unsigned char* chunk); /*get pointer to the data of the chunk, where the input points to the header of the chunk*/ unsigned char* lodepng_chunk_data(unsigned char* chunk); const unsigned char* lodepng_chunk_data_const(const unsigned char* chunk); /*returns 0 if the crc is correct, 1 if it's incorrect (0 for OK as usual!)*/ unsigned lodepng_chunk_check_crc(const unsigned char* chunk); /*generates the correct CRC from the data and puts it in the last 4 bytes of the chunk*/ void lodepng_chunk_generate_crc(unsigned char* chunk); /* Iterate to next chunks, allows iterating through all chunks of the PNG file. Input must be at the beginning of a chunk (result of a previous lodepng_chunk_next call, or the 8th byte of a PNG file which always has the first chunk), or alternatively may point to the first byte of the PNG file (which is not a chunk but the magic header, the function will then skip over it and return the first real chunk). Will output pointer to the start of the next chunk, or at or beyond end of the file if there is no more chunk after this or possibly if the chunk is corrupt. Start this process at the 8th byte of the PNG file. In a non-corrupt PNG file, the last chunk should have name "IEND". */ unsigned char* lodepng_chunk_next(unsigned char* chunk, unsigned char* end); const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk, const unsigned char* end); /*Finds the first chunk with the given type in the range [chunk, end), or returns NULL if not found.*/ unsigned char* lodepng_chunk_find(unsigned char* chunk, unsigned char* end, const char type[5]); const unsigned char* lodepng_chunk_find_const(const unsigned char* chunk, const unsigned char* end, const char type[5]); /* Appends chunk to the data in out. The given chunk should already have its chunk header. The out variable and outsize are updated to reflect the new reallocated buffer. Returns error code (0 if it went ok) */ unsigned lodepng_chunk_append(unsigned char** out, size_t* outsize, const unsigned char* chunk); /* Appends new chunk to out. The chunk to append is given by giving its length, type and data separately. The type is a 4-letter string. The out variable and outsize are updated to reflect the new reallocated buffer. Returne error code (0 if it went ok) */ unsigned lodepng_chunk_create(unsigned char** out, size_t* outsize, unsigned length, const char* type, const unsigned char* data); /*Calculate CRC32 of buffer*/ unsigned lodepng_crc32(const unsigned char* buf, size_t len); #endif /*LODEPNG_COMPILE_PNG*/ #ifdef LODEPNG_COMPILE_ZLIB /* This zlib part can be used independently to zlib compress and decompress a buffer. It cannot be used to create gzip files however, and it only supports the part of zlib that is required for PNG, it does not support dictionaries. */ #ifdef LODEPNG_COMPILE_DECODER /*Inflate a buffer. Inflate is the decompression step of deflate. Out buffer must be freed after use.*/ unsigned lodepng_inflate(unsigned char** out, size_t* outsize, const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings); /* Decompresses Zlib data. Reallocates the out buffer and appends the data. The data must be according to the zlib specification. Either, *out must be NULL and *outsize must be 0, or, *out must be a valid buffer and *outsize its size in bytes. out must be freed by user after usage. */ unsigned lodepng_zlib_decompress(unsigned char** out, size_t* outsize, const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings); #endif /*LODEPNG_COMPILE_DECODER*/ #ifdef LODEPNG_COMPILE_ENCODER /* Compresses data with Zlib. Reallocates the out buffer and appends the data. Zlib adds a small header and trailer around the deflate data. The data is output in the format of the zlib specification. Either, *out must be NULL and *outsize must be 0, or, *out must be a valid buffer and *outsize its size in bytes. out must be freed by user after usage. */ unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, const unsigned char* in, size_t insize, const LodePNGCompressSettings* settings); /* Find length-limited Huffman code for given frequencies. This function is in the public interface only for tests, it's used internally by lodepng_deflate. */ unsigned lodepng_huffman_code_lengths(unsigned* lengths, const unsigned* frequencies, size_t numcodes, unsigned maxbitlen); /*Compress a buffer with deflate. See RFC 1951. Out buffer must be freed after use.*/ unsigned lodepng_deflate(unsigned char** out, size_t* outsize, const unsigned char* in, size_t insize, const LodePNGCompressSettings* settings); #endif /*LODEPNG_COMPILE_ENCODER*/ #endif /*LODEPNG_COMPILE_ZLIB*/ #ifdef LODEPNG_COMPILE_DISK /* Load a file from disk into buffer. The function allocates the out buffer, and after usage you should free it. out: output parameter, contains pointer to loaded buffer. outsize: output parameter, size of the allocated out buffer filename: the path to the file to load return value: error code (0 means ok) NOTE: Wide-character filenames are not supported, you can use an external method to handle such files and decode in-memory. */ unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename); /* Save a file from buffer to disk. Warning, if it exists, this function overwrites the file without warning! buffer: the buffer to write buffersize: size of the buffer to write filename: the path to the file to save to return value: error code (0 means ok) NOTE: Wide-character filenames are not supported, you can use an external method to handle such files and encode in-memory */ unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename); #endif /*LODEPNG_COMPILE_DISK*/ #ifdef LODEPNG_COMPILE_CPP /* The LodePNG C++ wrapper uses std::vectors instead of manually allocated memory buffers. */ namespace lodepng { #ifdef LODEPNG_COMPILE_PNG class State : public LodePNGState { public: State(); State(const State& other); ~State(); State& operator=(const State& other); }; #ifdef LODEPNG_COMPILE_DECODER /* Same as other lodepng::decode, but using a State for more settings and information. */ unsigned decode(std::vector& out, unsigned& w, unsigned& h, State& state, const unsigned char* in, size_t insize); unsigned decode(std::vector& out, unsigned& w, unsigned& h, State& state, const std::vector& in); #endif /*LODEPNG_COMPILE_DECODER*/ #ifdef LODEPNG_COMPILE_ENCODER /* Same as other lodepng::encode, but using a State for more settings and information. */ unsigned encode(std::vector& out, const unsigned char* in, unsigned w, unsigned h, State& state); unsigned encode(std::vector& out, const std::vector& in, unsigned w, unsigned h, State& state); #endif /*LODEPNG_COMPILE_ENCODER*/ #ifdef LODEPNG_COMPILE_DISK /* Load a file from disk into an std::vector. return value: error code (0 means ok) NOTE: Wide-character filenames are not supported, you can use an external method to handle such files and decode in-memory */ unsigned load_file(std::vector& buffer, const std::string& filename); /* Save the binary data in an std::vector to a file on disk. The file is overwritten without warning. NOTE: Wide-character filenames are not supported, you can use an external method to handle such files and encode in-memory */ unsigned save_file(const std::vector& buffer, const std::string& filename); #endif /* LODEPNG_COMPILE_DISK */ #endif /* LODEPNG_COMPILE_PNG */ #ifdef LODEPNG_COMPILE_ZLIB #ifdef LODEPNG_COMPILE_DECODER /* Zlib-decompress an unsigned char buffer */ unsigned decompress(std::vector& out, const unsigned char* in, size_t insize, const LodePNGDecompressSettings& settings = lodepng_default_decompress_settings); /* Zlib-decompress an std::vector */ unsigned decompress(std::vector& out, const std::vector& in, const LodePNGDecompressSettings& settings = lodepng_default_decompress_settings); #endif /* LODEPNG_COMPILE_DECODER */ #ifdef LODEPNG_COMPILE_ENCODER /* Zlib-compress an unsigned char buffer */ unsigned compress(std::vector& out, const unsigned char* in, size_t insize, const LodePNGCompressSettings& settings = lodepng_default_compress_settings); /* Zlib-compress an std::vector */ unsigned compress(std::vector& out, const std::vector& in, const LodePNGCompressSettings& settings = lodepng_default_compress_settings); #endif /* LODEPNG_COMPILE_ENCODER */ #endif /* LODEPNG_COMPILE_ZLIB */ } /* namespace lodepng */ #endif /*LODEPNG_COMPILE_CPP*/ /* TODO: [.] test if there are no memory leaks or security exploits - done a lot but needs to be checked often [.] check compatibility with various compilers - done but needs to be redone for every newer version [X] converting color to 16-bit per channel types [X] support color profile chunk types (but never let them touch RGB values by default) [ ] support all public PNG chunk types (almost done except sPLT and hIST) [ ] make sure encoder generates no chunks with size > (2^31)-1 [ ] partial decoding (stream processing) [X] let the "isFullyOpaque" function check color keys and transparent palettes too [X] better name for the variables "codes", "codesD", "codelengthcodes", "clcl" and "lldl" [ ] allow treating some errors like warnings, when image is recoverable (e.g. 69, 57, 58) [ ] make warnings like: oob palette, checksum fail, data after iend, wrong/unknown crit chunk, no null terminator in text, ... [ ] error messages with line numbers (and version) [ ] errors in state instead of as return code? [ ] new errors/warnings like suspiciously big decompressed ztxt or iccp chunk [ ] let the C++ wrapper catch exceptions coming from the standard library and return LodePNG error codes [ ] allow user to provide custom color conversion functions, e.g. for premultiplied alpha, padding bits or not, ... [ ] allow user to give data (void*) to custom allocator [X] provide alternatives for C library functions not present on some platforms (memcpy, ...) */ #endif /*LODEPNG_H inclusion guard*/ /* LodePNG Documentation --------------------- 0. table of contents -------------------- 1. about 1.1. supported features 1.2. features not supported 2. C and C++ version 3. security 4. decoding 5. encoding 6. color conversions 6.1. PNG color types 6.2. color conversions 6.3. padding bits 6.4. A note about 16-bits per channel and endianness 7. error values 8. chunks and PNG editing 9. compiler support 10. examples 10.1. decoder C++ example 10.2. decoder C example 11. state settings reference 12. changes 13. contact information 1. about -------- PNG is a file format to store raster images losslessly with good compression, supporting different color types and alpha channel. LodePNG is a PNG codec according to the Portable Network Graphics (PNG) Specification (Second Edition) - W3C Recommendation 10 November 2003. The specifications used are: *) Portable Network Graphics (PNG) Specification (Second Edition): http://www.w3.org/TR/2003/REC-PNG-20031110 *) RFC 1950 ZLIB Compressed Data Format version 3.3: http://www.gzip.org/zlib/rfc-zlib.html *) RFC 1951 DEFLATE Compressed Data Format Specification ver 1.3: http://www.gzip.org/zlib/rfc-deflate.html The most recent version of LodePNG can currently be found at http://lodev.org/lodepng/ LodePNG works both in C (ISO C90) and C++, with a C++ wrapper that adds extra functionality. LodePNG exists out of two files: -lodepng.h: the header file for both C and C++ -lodepng.c(pp): give it the name lodepng.c or lodepng.cpp (or .cc) depending on your usage If you want to start using LodePNG right away without reading this doc, get the examples from the LodePNG website to see how to use it in code, or check the smaller examples in chapter 13 here. LodePNG is simple but only supports the basic requirements. To achieve simplicity, the following design choices were made: There are no dependencies on any external library. There are functions to decode and encode a PNG with a single function call, and extended versions of these functions taking a LodePNGState struct allowing to specify or get more information. By default the colors of the raw image are always RGB or RGBA, no matter what color type the PNG file uses. To read and write files, there are simple functions to convert the files to/from buffers in memory. This all makes LodePNG suitable for loading textures in games, demos and small programs, ... It's less suitable for full fledged image editors, loading PNGs over network (it requires all the image data to be available before decoding can begin), life-critical systems, ... 1.1. supported features ----------------------- The following features are supported by the decoder: *) decoding of PNGs with any color type, bit depth and interlace mode, to a 24- or 32-bit color raw image, or the same color type as the PNG *) encoding of PNGs, from any raw image to 24- or 32-bit color, or the same color type as the raw image *) Adam7 interlace and deinterlace for any color type *) loading the image from harddisk or decoding it from a buffer from other sources than harddisk *) support for alpha channels, including RGBA color model, translucent palettes and color keying *) zlib decompression (inflate) *) zlib compression (deflate) *) CRC32 and ADLER32 checksums *) colorimetric color profile conversions: currently experimentally available in lodepng_util.cpp only, plus alternatively ability to pass on chroma/gamma/ICC profile information to other color management system. *) handling of unknown chunks, allowing making a PNG editor that stores custom and unknown chunks. *) the following chunks are supported by both encoder and decoder: IHDR: header information PLTE: color palette IDAT: pixel data IEND: the final chunk tRNS: transparency for palettized images tEXt: textual information zTXt: compressed textual information iTXt: international textual information bKGD: suggested background color pHYs: physical dimensions tIME: modification time cHRM: RGB chromaticities gAMA: RGB gamma correction iCCP: ICC color profile sRGB: rendering intent sBIT: significant bits 1.2. features not supported --------------------------- The following features are not (yet) supported: *) some features needed to make a conformant PNG-Editor might be still missing. *) partial loading/stream processing. All data must be available and is processed in one call. *) The hIST and sPLT public chunks are not (yet) supported but treated as unknown chunks 2. C and C++ version -------------------- The C version uses buffers allocated with alloc that you need to free() yourself. You need to use init and cleanup functions for each struct whenever using a struct from the C version to avoid exploits and memory leaks. The C++ version has extra functions with std::vectors in the interface and the lodepng::State class which is a LodePNGState with constructor and destructor. These files work without modification for both C and C++ compilers because all the additional C++ code is in "#ifdef __cplusplus" blocks that make C-compilers ignore it, and the C code is made to compile both with strict ISO C90 and C++. To use the C++ version, you need to rename the source file to lodepng.cpp (instead of lodepng.c), and compile it with a C++ compiler. To use the C version, you need to rename the source file to lodepng.c (instead of lodepng.cpp), and compile it with a C compiler. 3. Security ----------- Even if carefully designed, it's always possible that LodePNG contains possible exploits. If you discover one, please let me know, and it will be fixed. When using LodePNG, care has to be taken with the C version of LodePNG, as well as the C-style structs when working with C++. The following conventions are used for all C-style structs: -if a struct has a corresponding init function, always call the init function when making a new one -if a struct has a corresponding cleanup function, call it before the struct disappears to avoid memory leaks -if a struct has a corresponding copy function, use the copy function instead of "=". The destination must also be inited already. 4. Decoding ----------- Decoding converts a PNG compressed image to a raw pixel buffer. Most documentation on using the decoder is at its declarations in the header above. For C, simple decoding can be done with functions such as lodepng_decode32, and more advanced decoding can be done with the struct LodePNGState and lodepng_decode. For C++, all decoding can be done with the various lodepng::decode functions, and lodepng::State can be used for advanced features. When using the LodePNGState, it uses the following fields for decoding: *) LodePNGInfo info_png: it stores extra information about the PNG (the input) in here *) LodePNGColorMode info_raw: here you can say what color mode of the raw image (the output) you want to get *) LodePNGDecoderSettings decoder: you can specify a few extra settings for the decoder to use LodePNGInfo info_png -------------------- After decoding, this contains extra information of the PNG image, except the actual pixels, width and height because these are already gotten directly from the decoder functions. It contains for example the original color type of the PNG image, text comments, suggested background color, etc... More details about the LodePNGInfo struct are at its declaration documentation. LodePNGColorMode info_raw ------------------------- When decoding, here you can specify which color type you want the resulting raw image to be. If this is different from the colortype of the PNG, then the decoder will automatically convert the result. This conversion always works, except if you want it to convert a color PNG to grayscale or to a palette with missing colors. By default, 32-bit color is used for the result. LodePNGDecoderSettings decoder ------------------------------ The settings can be used to ignore the errors created by invalid CRC and Adler32 chunks, and to disable the decoding of tEXt chunks. There's also a setting color_convert, true by default. If false, no conversion is done, the resulting data will be as it was in the PNG (after decompression) and you'll have to puzzle the colors of the pixels together yourself using the color type information in the LodePNGInfo. 5. Encoding ----------- Encoding converts a raw pixel buffer to a PNG compressed image. Most documentation on using the encoder is at its declarations in the header above. For C, simple encoding can be done with functions such as lodepng_encode32, and more advanced decoding can be done with the struct LodePNGState and lodepng_encode. For C++, all encoding can be done with the various lodepng::encode functions, and lodepng::State can be used for advanced features. Like the decoder, the encoder can also give errors. However it gives less errors since the encoder input is trusted, the decoder input (a PNG image that could be forged by anyone) is not trusted. When using the LodePNGState, it uses the following fields for encoding: *) LodePNGInfo info_png: here you specify how you want the PNG (the output) to be. *) LodePNGColorMode info_raw: here you say what color type of the raw image (the input) has *) LodePNGEncoderSettings encoder: you can specify a few settings for the encoder to use LodePNGInfo info_png -------------------- When encoding, you use this the opposite way as when decoding: for encoding, you fill in the values you want the PNG to have before encoding. By default it's not needed to specify a color type for the PNG since it's automatically chosen, but it's possible to choose it yourself given the right settings. The encoder will not always exactly match the LodePNGInfo struct you give, it tries as close as possible. Some things are ignored by the encoder. The encoder uses, for example, the following settings from it when applicable: colortype and bitdepth, text chunks, time chunk, the color key, the palette, the background color, the interlace method, unknown chunks, ... When encoding to a PNG with colortype 3, the encoder will generate a PLTE chunk. If the palette contains any colors for which the alpha channel is not 255 (so there are translucent colors in the palette), it'll add a tRNS chunk. LodePNGColorMode info_raw ------------------------- You specify the color type of the raw image that you give to the input here, including a possible transparent color key and palette you happen to be using in your raw image data. By default, 32-bit color is assumed, meaning your input has to be in RGBA format with 4 bytes (unsigned chars) per pixel. LodePNGEncoderSettings encoder ------------------------------ The following settings are supported (some are in sub-structs): *) auto_convert: when this option is enabled, the encoder will automatically choose the smallest possible color mode (including color key) that can encode the colors of all pixels without information loss. *) btype: the block type for LZ77. 0 = uncompressed, 1 = fixed huffman tree, 2 = dynamic huffman tree (best compression). Should be 2 for proper compression. *) use_lz77: whether or not to use LZ77 for compressed block types. Should be true for proper compression. *) windowsize: the window size used by the LZ77 encoder (1 - 32768). Has value 2048 by default, but can be set to 32768 for better, but slow, compression. *) force_palette: if colortype is 2 or 6, you can make the encoder write a PLTE chunk if force_palette is true. This can used as suggested palette to convert to by viewers that don't support more than 256 colors (if those still exist) *) add_id: add text chunk "Encoder: LodePNG " to the image. *) text_compression: default 1. If 1, it'll store texts as zTXt instead of tEXt chunks. zTXt chunks use zlib compression on the text. This gives a smaller result on large texts but a larger result on small texts (such as a single program name). It's all tEXt or all zTXt though, there's no separate setting per text yet. 6. color conversions -------------------- An important thing to note about LodePNG, is that the color type of the PNG, and the color type of the raw image, are completely independent. By default, when you decode a PNG, you get the result as a raw image in the color type you want, no matter whether the PNG was encoded with a palette, grayscale or RGBA color. And if you encode an image, by default LodePNG will automatically choose the PNG color type that gives good compression based on the values of colors and amount of colors in the image. It can be configured to let you control it instead as well, though. To be able to do this, LodePNG does conversions from one color mode to another. It can convert from almost any color type to any other color type, except the following conversions: RGB to grayscale is not supported, and converting to a palette when the palette doesn't have a required color is not supported. This is not supported on purpose: this is information loss which requires a color reduction algorithm that is beyond the scope of a PNG encoder (yes, RGB to gray is easy, but there are multiple ways if you want to give some channels more weight). By default, when decoding, you get the raw image in 32-bit RGBA or 24-bit RGB color, no matter what color type the PNG has. And by default when encoding, LodePNG automatically picks the best color model for the output PNG, and expects the input image to be 32-bit RGBA or 24-bit RGB. So, unless you want to control the color format of the images yourself, you can skip this chapter. 6.1. PNG color types -------------------- A PNG image can have many color types, ranging from 1-bit color to 64-bit color, as well as palettized color modes. After the zlib decompression and unfiltering in the PNG image is done, the raw pixel data will have that color type and thus a certain amount of bits per pixel. If you want the output raw image after decoding to have another color type, a conversion is done by LodePNG. The PNG specification gives the following color types: 0: grayscale, bit depths 1, 2, 4, 8, 16 2: RGB, bit depths 8 and 16 3: palette, bit depths 1, 2, 4 and 8 4: grayscale with alpha, bit depths 8 and 16 6: RGBA, bit depths 8 and 16 Bit depth is the amount of bits per pixel per color channel. So the total amount of bits per pixel is: amount of channels * bitdepth. 6.2. color conversions ---------------------- As explained in the sections about the encoder and decoder, you can specify color types and bit depths in info_png and info_raw to change the default behaviour. If, when decoding, you want the raw image to be something else than the default, you need to set the color type and bit depth you want in the LodePNGColorMode, or the parameters colortype and bitdepth of the simple decoding function. If, when encoding, you use another color type than the default in the raw input image, you need to specify its color type and bit depth in the LodePNGColorMode of the raw image, or use the parameters colortype and bitdepth of the simple encoding function. If, when encoding, you don't want LodePNG to choose the output PNG color type but control it yourself, you need to set auto_convert in the encoder settings to false, and specify the color type you want in the LodePNGInfo of the encoder (including palette: it can generate a palette if auto_convert is true, otherwise not). If the input and output color type differ (whether user chosen or auto chosen), LodePNG will do a color conversion, which follows the rules below, and may sometimes result in an error. To avoid some confusion: -the decoder converts from PNG to raw image -the encoder converts from raw image to PNG -the colortype and bitdepth in LodePNGColorMode info_raw, are those of the raw image -the colortype and bitdepth in the color field of LodePNGInfo info_png, are those of the PNG -when encoding, the color type in LodePNGInfo is ignored if auto_convert is enabled, it is automatically generated instead -when decoding, the color type in LodePNGInfo is set by the decoder to that of the original PNG image, but it can be ignored since the raw image has the color type you requested instead -if the color type of the LodePNGColorMode and PNG image aren't the same, a conversion between the color types is done if the color types are supported. If it is not supported, an error is returned. If the types are the same, no conversion is done. -even though some conversions aren't supported, LodePNG supports loading PNGs from any colortype and saving PNGs to any colortype, sometimes it just requires preparing the raw image correctly before encoding. -both encoder and decoder use the same color converter. The function lodepng_convert does the color conversion. It is available in the interface but normally isn't needed since the encoder and decoder already call it. Non supported color conversions: -color to grayscale when non-gray pixels are present: no error is thrown, but the result will look ugly because only the red channel is taken (it assumes all three channels are the same in this case so ignores green and blue). The reason no error is given is to allow converting from three-channel grayscale images to one-channel even if there are numerical imprecisions. -anything to palette when the palette does not have an exact match for a from-color in it: in this case an error is thrown Supported color conversions: -anything to 8-bit RGB, 8-bit RGBA, 16-bit RGB, 16-bit RGBA -any gray or gray+alpha, to gray or gray+alpha -anything to a palette, as long as the palette has the requested colors in it -removing alpha channel -higher to smaller bitdepth, and vice versa If you want no color conversion to be done (e.g. for speed or control): -In the encoder, you can make it save a PNG with any color type by giving the raw color mode and LodePNGInfo the same color mode, and setting auto_convert to false. -In the decoder, you can make it store the pixel data in the same color type as the PNG has, by setting the color_convert setting to false. Settings in info_raw are then ignored. 6.3. padding bits ----------------- In the PNG file format, if a less than 8-bit per pixel color type is used and the scanlines have a bit amount that isn't a multiple of 8, then padding bits are used so that each scanline starts at a fresh byte. But that is NOT true for the LodePNG raw input and output. The raw input image you give to the encoder, and the raw output image you get from the decoder will NOT have these padding bits, e.g. in the case of a 1-bit image with a width of 7 pixels, the first pixel of the second scanline will the 8th bit of the first byte, not the first bit of a new byte. 6.4. A note about 16-bits per channel and endianness ---------------------------------------------------- LodePNG uses unsigned char arrays for 16-bit per channel colors too, just like for any other color format. The 16-bit values are stored in big endian (most significant byte first) in these arrays. This is the opposite order of the little endian used by x86 CPU's. LodePNG always uses big endian because the PNG file format does so internally. Conversions to other formats than PNG uses internally are not supported by LodePNG on purpose, there are myriads of formats, including endianness of 16-bit colors, the order in which you store R, G, B and A, and so on. Supporting and converting to/from all that is outside the scope of LodePNG. This may mean that, depending on your use case, you may want to convert the big endian output of LodePNG to little endian with a for loop. This is certainly not always needed, many applications and libraries support big endian 16-bit colors anyway, but it means you cannot simply cast the unsigned char* buffer to an unsigned short* buffer on x86 CPUs. 7. error values --------------- All functions in LodePNG that return an error code, return 0 if everything went OK, or a non-zero code if there was an error. The meaning of the LodePNG error values can be retrieved with the function lodepng_error_text: given the numerical error code, it returns a description of the error in English as a string. Check the implementation of lodepng_error_text to see the meaning of each code. It is not recommended to use the numerical values to programmatically make different decisions based on error types as the numbers are not guaranteed to stay backwards compatible. They are for human consumption only. Programmatically only 0 or non-0 matter. 8. chunks and PNG editing ------------------------- If you want to add extra chunks to a PNG you encode, or use LodePNG for a PNG editor that should follow the rules about handling of unknown chunks, or if your program is able to read other types of chunks than the ones handled by LodePNG, then that's possible with the chunk functions of LodePNG. A PNG chunk has the following layout: 4 bytes length 4 bytes type name length bytes data 4 bytes CRC 8.1. iterating through chunks ----------------------------- If you have a buffer containing the PNG image data, then the first chunk (the IHDR chunk) starts at byte number 8 of that buffer. The first 8 bytes are the signature of the PNG and are not part of a chunk. But if you start at byte 8 then you have a chunk, and can check the following things of it. NOTE: none of these functions check for memory buffer boundaries. To avoid exploits, always make sure the buffer contains all the data of the chunks. When using lodepng_chunk_next, make sure the returned value is within the allocated memory. unsigned lodepng_chunk_length(const unsigned char* chunk): Get the length of the chunk's data. The total chunk length is this length + 12. void lodepng_chunk_type(char type[5], const unsigned char* chunk): unsigned char lodepng_chunk_type_equals(const unsigned char* chunk, const char* type): Get the type of the chunk or compare if it's a certain type unsigned char lodepng_chunk_critical(const unsigned char* chunk): unsigned char lodepng_chunk_private(const unsigned char* chunk): unsigned char lodepng_chunk_safetocopy(const unsigned char* chunk): Check if the chunk is critical in the PNG standard (only IHDR, PLTE, IDAT and IEND are). Check if the chunk is private (public chunks are part of the standard, private ones not). Check if the chunk is safe to copy. If it's not, then, when modifying data in a critical chunk, unsafe to copy chunks of the old image may NOT be saved in the new one if your program doesn't handle that type of unknown chunk. unsigned char* lodepng_chunk_data(unsigned char* chunk): const unsigned char* lodepng_chunk_data_const(const unsigned char* chunk): Get a pointer to the start of the data of the chunk. unsigned lodepng_chunk_check_crc(const unsigned char* chunk): void lodepng_chunk_generate_crc(unsigned char* chunk): Check if the crc is correct or generate a correct one. unsigned char* lodepng_chunk_next(unsigned char* chunk): const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk): Iterate to the next chunk. This works if you have a buffer with consecutive chunks. Note that these functions do no boundary checking of the allocated data whatsoever, so make sure there is enough data available in the buffer to be able to go to the next chunk. unsigned lodepng_chunk_append(unsigned char** out, size_t* outsize, const unsigned char* chunk): unsigned lodepng_chunk_create(unsigned char** out, size_t* outsize, unsigned length, const char* type, const unsigned char* data): These functions are used to create new chunks that are appended to the data in *out that has length *outsize. The append function appends an existing chunk to the new data. The create function creates a new chunk with the given parameters and appends it. Type is the 4-letter name of the chunk. 8.2. chunks in info_png ----------------------- The LodePNGInfo struct contains fields with the unknown chunk in it. It has 3 buffers (each with size) to contain 3 types of unknown chunks: the ones that come before the PLTE chunk, the ones that come between the PLTE and the IDAT chunks, and the ones that come after the IDAT chunks. It's necessary to make the distinction between these 3 cases because the PNG standard forces to keep the ordering of unknown chunks compared to the critical chunks, but does not force any other ordering rules. info_png.unknown_chunks_data[0] is the chunks before PLTE info_png.unknown_chunks_data[1] is the chunks after PLTE, before IDAT info_png.unknown_chunks_data[2] is the chunks after IDAT The chunks in these 3 buffers can be iterated through and read by using the same way described in the previous subchapter. When using the decoder to decode a PNG, you can make it store all unknown chunks if you set the option settings.remember_unknown_chunks to 1. By default, this option is off (0). The encoder will always encode unknown chunks that are stored in the info_png. If you need it to add a particular chunk that isn't known by LodePNG, you can use lodepng_chunk_append or lodepng_chunk_create to the chunk data in info_png.unknown_chunks_data[x]. Chunks that are known by LodePNG should not be added in that way. E.g. to make LodePNG add a bKGD chunk, set background_defined to true and add the correct parameters there instead. 9. compiler support ------------------- No libraries other than the current standard C library are needed to compile LodePNG. For the C++ version, only the standard C++ library is needed on top. Add the files lodepng.c(pp) and lodepng.h to your project, include lodepng.h where needed, and your program can read/write PNG files. It is compatible with C90 and up, and C++03 and up. If performance is important, use optimization when compiling! For both the encoder and decoder, this makes a large difference. Make sure that LodePNG is compiled with the same compiler of the same version and with the same settings as the rest of the program, or the interfaces with std::vectors and std::strings in C++ can be incompatible. CHAR_BITS must be 8 or higher, because LodePNG uses unsigned chars for octets. *) gcc and g++ LodePNG is developed in gcc so this compiler is natively supported. It gives no warnings with compiler options "-Wall -Wextra -pedantic -ansi", with gcc and g++ version 4.7.1 on Linux, 32-bit and 64-bit. *) Clang Fully supported and warning-free. *) Mingw The Mingw compiler (a port of gcc for Windows) should be fully supported by LodePNG. *) Visual Studio and Visual C++ Express Edition LodePNG should be warning-free with warning level W4. Two warnings were disabled with pragmas though: warning 4244 about implicit conversions, and warning 4996 where it wants to use a non-standard function fopen_s instead of the standard C fopen. Visual Studio may want "stdafx.h" files to be included in each source file and give an error "unexpected end of file while looking for precompiled header". This is not standard C++ and will not be added to the stock LodePNG. You can disable it for lodepng.cpp only by right clicking it, Properties, C/C++, Precompiled Headers, and set it to Not Using Precompiled Headers there. NOTE: Modern versions of VS should be fully supported, but old versions, e.g. VS6, are not guaranteed to work. *) Compilers on Macintosh LodePNG has been reported to work both with gcc and LLVM for Macintosh, both for C and C++. *) Other Compilers If you encounter problems on any compilers, feel free to let me know and I may try to fix it if the compiler is modern and standards compliant. 10. examples ------------ This decoder example shows the most basic usage of LodePNG. More complex examples can be found on the LodePNG website. NOTE: these examples do not support wide-character filenames, you can use an external method to handle such files and encode or decode in-memory 10.1. decoder C++ example ------------------------- #include "lodepng.h" #include int main(int argc, char *argv[]) { const char* filename = argc > 1 ? argv[1] : "test.png"; //load and decode std::vector image; unsigned width, height; unsigned error = lodepng::decode(image, width, height, filename); //if there's an error, display it if(error) std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl; //the pixels are now in the vector "image", 4 bytes per pixel, ordered RGBARGBA..., use it as texture, draw it, ... } 10.2. decoder C example ----------------------- #include "lodepng.h" int main(int argc, char *argv[]) { unsigned error; unsigned char* image; size_t width, height; const char* filename = argc > 1 ? argv[1] : "test.png"; error = lodepng_decode32_file(&image, &width, &height, filename); if(error) printf("decoder error %u: %s\n", error, lodepng_error_text(error)); / * use image here * / free(image); return 0; } 11. state settings reference ---------------------------- A quick reference of some settings to set on the LodePNGState For decoding: state.decoder.zlibsettings.ignore_adler32: ignore ADLER32 checksums state.decoder.zlibsettings.custom_...: use custom inflate function state.decoder.ignore_crc: ignore CRC checksums state.decoder.ignore_critical: ignore unknown critical chunks state.decoder.ignore_end: ignore missing IEND chunk. May fail if this corruption causes other errors state.decoder.color_convert: convert internal PNG color to chosen one state.decoder.read_text_chunks: whether to read in text metadata chunks state.decoder.remember_unknown_chunks: whether to read in unknown chunks state.info_raw.colortype: desired color type for decoded image state.info_raw.bitdepth: desired bit depth for decoded image state.info_raw....: more color settings, see struct LodePNGColorMode state.info_png....: no settings for decoder but ouput, see struct LodePNGInfo For encoding: state.encoder.zlibsettings.btype: disable compression by setting it to 0 state.encoder.zlibsettings.use_lz77: use LZ77 in compression state.encoder.zlibsettings.windowsize: tweak LZ77 windowsize state.encoder.zlibsettings.minmatch: tweak min LZ77 length to match state.encoder.zlibsettings.nicematch: tweak LZ77 match where to stop searching state.encoder.zlibsettings.lazymatching: try one more LZ77 matching state.encoder.zlibsettings.custom_...: use custom deflate function state.encoder.auto_convert: choose optimal PNG color type, if 0 uses info_png state.encoder.filter_palette_zero: PNG filter strategy for palette state.encoder.filter_strategy: PNG filter strategy to encode with state.encoder.force_palette: add palette even if not encoding to one state.encoder.add_id: add LodePNG identifier and version as a text chunk state.encoder.text_compression: use compressed text chunks for metadata state.info_raw.colortype: color type of raw input image you provide state.info_raw.bitdepth: bit depth of raw input image you provide state.info_raw: more color settings, see struct LodePNGColorMode state.info_png.color.colortype: desired color type if auto_convert is false state.info_png.color.bitdepth: desired bit depth if auto_convert is false state.info_png.color....: more color settings, see struct LodePNGColorMode state.info_png....: more PNG related settings, see struct LodePNGInfo 12. changes ----------- The version number of LodePNG is the date of the change given in the format yyyymmdd. Some changes aren't backwards compatible. Those are indicated with a (!) symbol. Not all changes are listed here, the commit history in github lists more: https://github.com/lvandeve/lodepng *) 13 jun 2022: added support for the sBIT chunk. *) 09 jan 2022: minor decoder speed improvements. *) 27 jun 2021: added warnings that file reading/writing functions don't support wide-character filenames (support for this is not planned, opening files is not the core part of PNG decoding/decoding and is platform dependent). *) 17 okt 2020: prevent decoding too large text/icc chunks by default. *) 06 mar 2020: simplified some of the dynamic memory allocations. *) 12 jan 2020: (!) added 'end' argument to lodepng_chunk_next to allow correct overflow checks. *) 14 aug 2019: around 25% faster decoding thanks to huffman lookup tables. *) 15 jun 2019: (!) auto_choose_color API changed (for bugfix: don't use palette if gray ICC profile) and non-ICC LodePNGColorProfile renamed to LodePNGColorStats. *) 30 dec 2018: code style changes only: removed newlines before opening braces. *) 10 sep 2018: added way to inspect metadata chunks without full decoding. *) 19 aug 2018: (!) fixed color mode bKGD is encoded with and made it use palette index in case of palette. *) 10 aug 2018: (!) added support for gAMA, cHRM, sRGB and iCCP chunks. This change is backwards compatible unless you relied on unknown_chunks for those. *) 11 jun 2018: less restrictive check for pixel size integer overflow *) 14 jan 2018: allow optionally ignoring a few more recoverable errors *) 17 sep 2017: fix memory leak for some encoder input error cases *) 27 nov 2016: grey+alpha auto color model detection bugfix *) 18 apr 2016: Changed qsort to custom stable sort (for platforms w/o qsort). *) 09 apr 2016: Fixed colorkey usage detection, and better file loading (within the limits of pure C90). *) 08 dec 2015: Made load_file function return error if file can't be opened. *) 24 okt 2015: Bugfix with decoding to palette output. *) 18 apr 2015: Boundary PM instead of just package-merge for faster encoding. *) 24 aug 2014: Moved to github *) 23 aug 2014: Reduced needless memory usage of decoder. *) 28 jun 2014: Removed fix_png setting, always support palette OOB for simplicity. Made ColorProfile public. *) 09 jun 2014: Faster encoder by fixing hash bug and more zeros optimization. *) 22 dec 2013: Power of two windowsize required for optimization. *) 15 apr 2013: Fixed bug with LAC_ALPHA and color key. *) 25 mar 2013: Added an optional feature to ignore some PNG errors (fix_png). *) 11 mar 2013: (!) Bugfix with custom free. Changed from "my" to "lodepng_" prefix for the custom allocators and made it possible with a new #define to use custom ones in your project without needing to change lodepng's code. *) 28 jan 2013: Bugfix with color key. *) 27 okt 2012: Tweaks in text chunk keyword length error handling. *) 8 okt 2012: (!) Added new filter strategy (entropy) and new auto color mode. (no palette). Better deflate tree encoding. New compression tweak settings. Faster color conversions while decoding. Some internal cleanups. *) 23 sep 2012: Reduced warnings in Visual Studio a little bit. *) 1 sep 2012: (!) Removed #define's for giving custom (de)compression functions and made it work with function pointers instead. *) 23 jun 2012: Added more filter strategies. Made it easier to use custom alloc and free functions and toggle #defines from compiler flags. Small fixes. *) 6 may 2012: (!) Made plugging in custom zlib/deflate functions more flexible. *) 22 apr 2012: (!) Made interface more consistent, renaming a lot. Removed redundant C++ codec classes. Reduced amount of structs. Everything changed, but it is cleaner now imho and functionality remains the same. Also fixed several bugs and shrunk the implementation code. Made new samples. *) 6 nov 2011: (!) By default, the encoder now automatically chooses the best PNG color model and bit depth, based on the amount and type of colors of the raw image. For this, autoLeaveOutAlphaChannel replaced by auto_choose_color. *) 9 okt 2011: simpler hash chain implementation for the encoder. *) 8 sep 2011: lz77 encoder lazy matching instead of greedy matching. *) 23 aug 2011: tweaked the zlib compression parameters after benchmarking. A bug with the PNG filtertype heuristic was fixed, so that it chooses much better ones (it's quite significant). A setting to do an experimental, slow, brute force search for PNG filter types is added. *) 17 aug 2011: (!) changed some C zlib related function names. *) 16 aug 2011: made the code less wide (max 120 characters per line). *) 17 apr 2011: code cleanup. Bugfixes. Convert low to 16-bit per sample colors. *) 21 feb 2011: fixed compiling for C90. Fixed compiling with sections disabled. *) 11 dec 2010: encoding is made faster, based on suggestion by Peter Eastman to optimize long sequences of zeros. *) 13 nov 2010: added LodePNG_InfoColor_hasPaletteAlpha and LodePNG_InfoColor_canHaveAlpha functions for convenience. *) 7 nov 2010: added LodePNG_error_text function to get error code description. *) 30 okt 2010: made decoding slightly faster *) 26 okt 2010: (!) changed some C function and struct names (more consistent). Reorganized the documentation and the declaration order in the header. *) 08 aug 2010: only changed some comments and external samples. *) 05 jul 2010: fixed bug thanks to warnings in the new gcc version. *) 14 mar 2010: fixed bug where too much memory was allocated for char buffers. *) 02 sep 2008: fixed bug where it could create empty tree that linux apps could read by ignoring the problem but windows apps couldn't. *) 06 jun 2008: added more error checks for out of memory cases. *) 26 apr 2008: added a few more checks here and there to ensure more safety. *) 06 mar 2008: crash with encoding of strings fixed *) 02 feb 2008: support for international text chunks added (iTXt) *) 23 jan 2008: small cleanups, and #defines to divide code in sections *) 20 jan 2008: support for unknown chunks allowing using LodePNG for an editor. *) 18 jan 2008: support for tIME and pHYs chunks added to encoder and decoder. *) 17 jan 2008: ability to encode and decode compressed zTXt chunks added Also various fixes, such as in the deflate and the padding bits code. *) 13 jan 2008: Added ability to encode Adam7-interlaced images. Improved filtering code of encoder. *) 07 jan 2008: (!) changed LodePNG to use ISO C90 instead of C++. A C++ wrapper around this provides an interface almost identical to before. Having LodePNG be pure ISO C90 makes it more portable. The C and C++ code are together in these files but it works both for C and C++ compilers. *) 29 dec 2007: (!) changed most integer types to unsigned int + other tweaks *) 30 aug 2007: bug fixed which makes this Borland C++ compatible *) 09 aug 2007: some VS2005 warnings removed again *) 21 jul 2007: deflate code placed in new namespace separate from zlib code *) 08 jun 2007: fixed bug with 2- and 4-bit color, and small interlaced images *) 04 jun 2007: improved support for Visual Studio 2005: crash with accessing invalid std::vector element [0] fixed, and level 3 and 4 warnings removed *) 02 jun 2007: made the encoder add a tag with version by default *) 27 may 2007: zlib and png code separated (but still in the same file), simple encoder/decoder functions added for more simple usage cases *) 19 may 2007: minor fixes, some code cleaning, new error added (error 69), moved some examples from here to lodepng_examples.cpp *) 12 may 2007: palette decoding bug fixed *) 24 apr 2007: changed the license from BSD to the zlib license *) 11 mar 2007: very simple addition: ability to encode bKGD chunks. *) 04 mar 2007: (!) tEXt chunk related fixes, and support for encoding palettized PNG images. Plus little interface change with palette and texts. *) 03 mar 2007: Made it encode dynamic Huffman shorter with repeat codes. Fixed a bug where the end code of a block had length 0 in the Huffman tree. *) 26 feb 2007: Huffman compression with dynamic trees (BTYPE 2) now implemented and supported by the encoder, resulting in smaller PNGs at the output. *) 27 jan 2007: Made the Adler-32 test faster so that a timewaste is gone. *) 24 jan 2007: gave encoder an error interface. Added color conversion from any greyscale type to 8-bit greyscale with or without alpha. *) 21 jan 2007: (!) Totally changed the interface. It allows more color types to convert to and is more uniform. See the manual for how it works now. *) 07 jan 2007: Some cleanup & fixes, and a few changes over the last days: encode/decode custom tEXt chunks, separate classes for zlib & deflate, and at last made the decoder give errors for incorrect Adler32 or Crc. *) 01 jan 2007: Fixed bug with encoding PNGs with less than 8 bits per channel. *) 29 dec 2006: Added support for encoding images without alpha channel, and cleaned out code as well as making certain parts faster. *) 28 dec 2006: Added "Settings" to the encoder. *) 26 dec 2006: The encoder now does LZ77 encoding and produces much smaller files now. Removed some code duplication in the decoder. Fixed little bug in an example. *) 09 dec 2006: (!) Placed output parameters of public functions as first parameter. Fixed a bug of the decoder with 16-bit per color. *) 15 okt 2006: Changed documentation structure *) 09 okt 2006: Encoder class added. It encodes a valid PNG image from the given image buffer, however for now it's not compressed. *) 08 sep 2006: (!) Changed to interface with a Decoder class *) 30 jul 2006: (!) LodePNG_InfoPng , width and height are now retrieved in different way. Renamed decodePNG to decodePNGGeneric. *) 29 jul 2006: (!) Changed the interface: image info is now returned as a struct of type LodePNG::LodePNG_Info, instead of a vector, which was a bit clumsy. *) 28 jul 2006: Cleaned the code and added new error checks. Corrected terminology "deflate" into "inflate". *) 23 jun 2006: Added SDL example in the documentation in the header, this example allows easy debugging by displaying the PNG and its transparency. *) 22 jun 2006: (!) Changed way to obtain error value. Added loadFile function for convenience. Made decodePNG32 faster. *) 21 jun 2006: (!) Changed type of info vector to unsigned. Changed position of palette in info vector. Fixed an important bug that happened on PNGs with an uncompressed block. *) 16 jun 2006: Internally changed unsigned into unsigned where needed, and performed some optimizations. *) 07 jun 2006: (!) Renamed functions to decodePNG and placed them in LodePNG namespace. Changed the order of the parameters. Rewrote the documentation in the header. Renamed files to lodepng.cpp and lodepng.h *) 22 apr 2006: Optimized and improved some code *) 07 sep 2005: (!) Changed to std::vector interface *) 12 aug 2005: Initial release (C++, decoder only) 13. contact information ----------------------- Feel free to contact me with suggestions, problems, comments, ... concerning LodePNG. If you encounter a PNG image that doesn't work properly with this decoder, feel free to send it and I'll use it to find and fix the problem. My email address is (puzzle the account and domain together with an @ symbol): Domain: gmail dot com. Account: lode dot vandevenne. Copyright (c) 2005-2022 Lode Vandevenne */ lodepng-0.0~git20220618.b4ed2cd/lodepng_benchmark.cpp000066400000000000000000000332441425344217700221230ustar00rootroot00000000000000/* LodePNG Benchmark Copyright (c) 2005-2019 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ //g++ lodepng.cpp lodepng_benchmark.cpp -Wall -Wextra -pedantic -ansi -lSDL -O3 //g++ lodepng.cpp lodepng_benchmark.cpp -Wall -Wextra -pedantic -ansi -lSDL -O3 && ./a.out #include "lodepng.h" #include #include #include #include #include #include #include #include //SDL is used for timing. bool apply_mods = false; #define NUM_DECODE 5 //decode multiple times to measure better. Must be at least 1. size_t total_pixels = 0; size_t total_png_orig_size = 0; size_t total_raw_orig_size = 0; // This is the uncompressed data in the raw color format in the original input PNGs double total_dec_time = 0; size_t total_png_in_size = 0; size_t total_raw_in_size = 0; // This is the uncompressed data in the raw color format in the input PNGs given to the decoder (not same as orig when using the encoded ones) size_t total_raw_dec_size = 0; // This is the uncompressed data in the raw color format of raw image buffers output by the decoder double total_enc_time = 0; size_t total_raw_enc_size = 0; // This is the uncompressed data in the raw color format of the raw images given to the encoder size_t total_png_out_size = 0; size_t total_raw_out_size = 0; // This is the uncompressed data in the raw color format of the encoded PNGs bool verbose = false; bool do_decode = false; bool do_encode = false; bool decode_encoded = false; // do the decoding benchmark on the encoded images rather than the original inputs std::string dumpdir; //////////////////////////////////////////////////////////////////////////////// double getTime() { return SDL_GetTicks() / 1000.0; } template void assertEquals(const T& expected, const U& actual, const std::string& message = "") { if(expected != (T)actual) { std::cout << "Error: Not equal! Expected " << expected << " got " << actual << "." << std::endl; std::cout << "Message: " << message << std::endl; std::exit(1); } } void assertTrue(bool value, const std::string& message = "") { if(!value) { std::cout << "Error: expected true." << std::endl; std::cout << "Message: " << message << std::endl; std::exit(1); } } //Test image data struct Image { std::vector data; unsigned width; unsigned height; LodePNGColorType colorType; unsigned bitDepth; std::string name; }; //Utility for debug messages template std::string valtostr(const T& val) { std::ostringstream sstream; sstream << val; return sstream.str(); } template void printValue(const std::string& name, const T& value, const std::string& unit = "") { std::cout << name << ": " << value << unit << std::endl; } template void printValue(const std::string& name, const T& value, const std::string& s2, const U& value2, const std::string& unit = "") { std::cout << name << ": " << value << s2 << value2 << unit << std::endl; } //Test LodePNG encoding and decoding the encoded result, using the C interface std::vector testEncode(Image& image) { unsigned char* encoded = 0; size_t encoded_size = 0; lodepng::State state; state.info_raw.colortype = image.colorType; state.info_raw.bitdepth = image.bitDepth; // Try custom compression settings if(apply_mods) { //state.encoder.filter_strategy = LFS_ZERO; //state.encoder.filter_strategy = LFS_ENTROPY; //state.encoder.filter_strategy = LFS_FOUR; //state.encoder.zlibsettings.btype = 0; //state.encoder.zlibsettings.btype = 1; //state.encoder.auto_convert = 0; //state.encoder.zlibsettings.use_lz77 = 0; state.encoder.zlibsettings.windowsize = 1; //state.encoder.zlibsettings.windowsize = 32768; } double t_enc0 = getTime(); unsigned error_enc = lodepng_encode(&encoded, &encoded_size, &image.data[0], image.width, image.height, &state); double t_enc1 = getTime(); assertEquals(0, error_enc, "encoder error"); total_raw_enc_size += lodepng_get_raw_size(image.width, image.height, &state.info_raw); total_png_out_size += encoded_size; total_enc_time += (t_enc1 - t_enc0); if(verbose) { printValue("encoding time", t_enc1 - t_enc0, "s"); std::cout << "compression: " << ((double)(encoded_size) / (double)(image.data.size())) * 100 << "%" << ", ratio: " << ((double)(image.data.size()) / (double)(encoded_size)) << ", size: " << encoded_size << ", bpp: " << (8.0 * encoded_size / image.width / image.height) << std::endl; } if(!dumpdir.empty()) { std::string dumpname = dumpdir; if(dumpname[dumpname.size() - 1] != '/') dumpname += "/"; dumpname += image.name; if(lodepng_save_file(encoded, encoded_size, dumpname.c_str())) { std::cout << "WARNING: failed to dump " << dumpname << ". The dir must already exist." << std::endl; } else if(verbose) { std::cout << "saved to: " << dumpname << std::endl; } } // output image stats { lodepng::State inspect; unsigned w, h; lodepng_inspect(&w, &h, &inspect, encoded, encoded_size); total_raw_out_size += lodepng_get_raw_size(w, h, &inspect.info_png.color); } std::vector result(encoded, encoded + encoded_size); free(encoded); return result; } void testDecode(const std::vector& png) { lodepng::State state; unsigned char* decoded = 0; unsigned w, h; // Try custom decompression settings if(apply_mods) { state.decoder.color_convert = 0; //state.decoder.ignore_crc = 1; } double t_dec0 = getTime(); for(int i = 0; i < NUM_DECODE; i++) { unsigned error_dec = lodepng_decode(&decoded, &w, &h, &state, png.data(), png.size()); assertEquals(0, error_dec, "decoder error"); } double t_dec1 = getTime(); total_dec_time += (t_dec1 - t_dec0); total_raw_dec_size += lodepng_get_raw_size(w, h, &state.info_raw); if(verbose) { printValue("decoding time", t_dec1 - t_dec0, "/", NUM_DECODE, " s"); } free(decoded); // input image stats { lodepng::State inspect; unsigned w, h; lodepng_inspect(&w, &h, &inspect, png.data(), png.size()); total_raw_in_size += lodepng_get_raw_size(w, h, &inspect.info_png.color); total_png_in_size += png.size(); } } std::string getFilePart(const std::string& path) { if(path.empty()) return ""; int slash = path.size() - 1; while(slash >= 0 && path[slash] != '/') slash--; return path.substr(slash + 1); } void testFile(const std::string& filename) { if(verbose) std::cout << "file " << filename << std::endl; std::vector png; if(lodepng::load_file(png, filename)) { std::cout << "\nfailed to load file " << filename << std::endl << std::endl; return; } // input image stats { lodepng::State inspect; unsigned w, h; lodepng_inspect(&w, &h, &inspect, png.data(), png.size()); total_pixels += (w * h); total_png_orig_size += png.size(); size_t raw_size = lodepng_get_raw_size(w, h, &inspect.info_png.color); total_raw_orig_size += raw_size; if(verbose) std::cout << "orig compressed size: " << png.size() << ", pixels: " << (w * h) << ", raw size: " << raw_size << std::endl; } if(do_encode) { Image image; image.name = getFilePart(filename); image.colorType = LCT_RGBA; image.bitDepth = 8; assertEquals(0, lodepng::decode(image.data, image.width, image.height, filename, image.colorType, image.bitDepth)); std::vector temp = testEncode(image); if(decode_encoded) png = temp; } if(do_decode) { testDecode(png); } if(verbose) std::cout << std::endl; } void showHelp(int argc, char *argv[]) { (void)argc; std::cout << "Usage: " << argv[0] << " png_filenames... [OPTIONS...] [--dumpdir directory]" << std::endl; std::cout << "Options:" << std::endl; std::cout << " -h: show this help" << std::endl; std::cout << " -v: verbose" << std::endl; std::cout << " -d: decode only" << std::endl; std::cout << " -e: encode only" << std::endl; std::cout << " -o: decode on original images rather than encoded ones (always true if -d without -e)" << std::endl; std::cout << " -m: apply modifications to encoder and decoder settings, the modification itself must be implemented or changed in the benchmark source code (search for apply_mods in the code, for encode and for decode)" << std::endl; } int main(int argc, char *argv[]) { verbose = false; do_decode = true; do_encode = true; decode_encoded = true; std::vector files; for(int i = 1; i < argc; i++) { std::string arg = argv[i]; if(arg == "-v") verbose = true; else if(arg == "-h" || arg == "--help") { showHelp(argc, argv); return 0; } else if(arg == "-d") do_decode ? (do_encode = false) : (do_decode = true); else if(arg == "-e") do_encode ? (do_decode = false) : (do_encode = true); else if(arg == "-o") decode_encoded = false; else if(arg == "-m") apply_mods = true; else if(arg == "--dumpdir" && i + 1 < argc) { dumpdir = argv[++i]; } else files.push_back(arg); } if(!do_encode) decode_encoded = false; if(files.empty()) { std::cout << "must give .png filenames to benchamrk" << std::endl; showHelp(argc, argv); return 1; } for(size_t i = 0; i < files.size(); i++) { testFile(files[i]); } // test images stats if(verbose) { std::cout << "Final Summary: " << std::endl; std::cout << "input images: " << files.size() << std::endl; std::cout << "total_pixels: " << total_pixels << std::endl; // file size of original PNGs that were given as command line arguments to the tool std::cout << "total_png_orig_size: " << total_png_orig_size << " (" << (8.0 * total_png_orig_size / total_pixels) << " bpp)" << std::endl; // size of the data inside the original PNGs, dependent on color encoding (bit depth used in the PNG) std::cout << "total_raw_orig_size: " << total_raw_orig_size << " (" << (8.0 * total_raw_orig_size / total_pixels) << " bpp)" << std::endl; // size of the pixel data given to the benchmark encoder, dependent on color encoding (bit depth used in the image representation in the benchmark tool, probably 32 bits) if(do_encode) std::cout << "total_raw_enc_size: " << total_raw_enc_size << " (" << (8.0 * total_raw_enc_size / total_pixels) << " bpp)" << std::endl; // file size of PNGs created by the benchmark encoder if(do_encode) std::cout << "total_png_out_size: " << total_png_out_size << " (" << (8.0 * total_png_out_size / total_pixels) << " bpp)" << std::endl; // size of the data inside the PNGs created by the benchmark encoder, dependent on color encoding (bit depth used in the PNG), may differ from total_raw_orig_size since the encoder may choose to use a different color encoding if(do_encode) std::cout << "total_raw_out_size: " << total_raw_out_size << " (" << (8.0 * total_raw_out_size / total_pixels) << " bpp)" << std::endl; // size of file size of the PNGs given to the benchmark decoder, this could either be the original ones or the ones encoded by the benchmark encoder depending on user options if(do_decode) std::cout << "total_png_in_size: " << total_png_in_size << " (" << (8.0 * total_png_in_size / total_pixels) << " bpp)" << std::endl; // size of the data inside the PNGs mentioned at total_png_in_size, dependent on color encoding (bit depth used in the image representation in the benchmark tool, probably 32 bits) if(do_decode) std::cout << "total_raw_in_size: " << total_raw_in_size << " (" << (8.0 * total_raw_in_size / total_pixels) << " bpp)" << std::endl; // size of the pixel data requested from the benchmark decoder, dependent on color encoding requested (bit depth used in the image representation in the benchmark tool, probably 32 bits) if(do_decode) std::cout << "total_raw_dec_size: " << total_raw_dec_size << " (" << (8.0 * total_raw_dec_size / total_pixels) << " bpp)" << std::endl; } // final encoding stats if(do_encode) { std::cout << "encoding time: " << total_enc_time << "s on " << total_pixels << " pixels and " << total_raw_out_size << " raw bytes (" << ((total_raw_enc_size/1024.0/1024.0)/(total_enc_time)) << " MB/s, " << ((total_pixels/1024.0/1024.0)/(total_enc_time)) << " MP/s)" << std::endl; std::cout << "encoded size: " << total_png_out_size << " (" << (100.0 * total_png_out_size / total_raw_out_size) << "%), bpp: " << (8.0 * total_png_out_size / total_pixels) << std::endl; } // final decoding stats if(do_decode) { if(verbose) std::cout << "decoding iterations: " << NUM_DECODE << std::endl; std::cout << "decoding time: " << total_dec_time/NUM_DECODE << "s on " << total_pixels << " pixels and " << total_png_in_size << " compressed bytes (" << ((total_raw_in_size/1024.0/1024.0)/(total_dec_time/NUM_DECODE)) << " MB/s, " << ((total_pixels/1024.0/1024.0)/(total_dec_time/NUM_DECODE)) << " MP/s)" << std::endl; } } lodepng-0.0~git20220618.b4ed2cd/lodepng_fuzzer.cpp000066400000000000000000000064051425344217700215150ustar00rootroot00000000000000/* LodePNG Fuzzer Copyright (c) 2005-2019 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ // clang++ -fsanitize=fuzzer lodepng.cpp lodepng_fuzzer.cpp -O3 && ./a.out #include "lodepng.h" #include namespace { // Amount of valid colortype/bidthdepth combinations in the PNG file format. const size_t num_combinations = 15; LodePNGColorType colortypes[num_combinations] = { LCT_GREY, LCT_GREY, LCT_GREY, LCT_GREY, LCT_GREY, // 1, 2, 4, 8 or 16 bits LCT_RGB, LCT_RGB, // 8 or 16 bits LCT_PALETTE, LCT_PALETTE, LCT_PALETTE, LCT_PALETTE, // 1, 2, 4 or 8 bits LCT_GREY_ALPHA, LCT_GREY_ALPHA, // 8 or 16 bits LCT_RGBA, LCT_RGBA, // 8 or 16 bits }; unsigned bitdepths[num_combinations] = { 1, 2, 4, 8, 16, // gray 8, 16, // rgb 1, 2, 4, 8, // palette 8, 16, // gray+alpha 8, 16, // rgb+alpha }; unsigned testDecode(lodepng::State& state, const uint8_t* data, size_t size) { unsigned w, h; std::vector image; return lodepng::decode(image, w, h, state, (const unsigned char*)data, size); } } // end anonymous namespace extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if(size == 0) return 0; // Setting last byte of input as random_color_type // Fuzzer will still be able to mutate the data accordingly as // last byte of png file can be changed and file will still remain valid. size_t random_color_type = data[size-1] % num_combinations; lodepng::State state; // Make the decoder ignore three types of checksums the PNG/zlib format have // built-in, because they are less likely to be correct in the random input // data, and if invalid make the decoder return an error before much gets ran. state.decoder.zlibsettings.ignore_adler32 = 1; state.decoder.zlibsettings.ignore_nlen = 1; state.decoder.ignore_crc = 1; // Also make decoder attempt to support partial files with missing ending to // go further with parsing. state.decoder.ignore_end = 1; // First test without color conversion (keep color type of the PNG) state.decoder.color_convert = 0; unsigned error = testDecode(state, data, size); // If valid PNG found, try decoding with color conversion to the most common // default color type, and to the randomly chosen type. if(error == 0) { state.decoder.color_convert = 1; testDecode(state, data, size); state.info_raw.colortype = colortypes[random_color_type]; state.info_raw.bitdepth = bitdepths[random_color_type]; testDecode(state, data, size); } return 0; } lodepng-0.0~git20220618.b4ed2cd/lodepng_unittest.cpp000066400000000000000000011461601425344217700220530ustar00rootroot00000000000000/* LodePNG Unit Test Copyright (c) 2005-2022 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ //g++ lodepng.cpp lodepng_util.cpp lodepng_unittest.cpp -Wall -Wextra -Wsign-conversion -pedantic -ansi -O3 /* Testing instructions: *) Ensure no tests commented out below or early return in doMain *) Compile with g++ with all warnings and run the unit test g++ lodepng.cpp lodepng_util.cpp lodepng_unittest.cpp -Werror -Wall -Wextra -Wsign-conversion -Wshadow -pedantic -ansi -O3 && ./a.out *) Compile with clang, which may sometimes give different warnings clang++ lodepng.cpp lodepng_util.cpp lodepng_unittest.cpp -Werror -Wall -Wextra -Wsign-conversion -Wshadow -pedantic -ansi -O3 *) Compile with pure ISO C90 and all warnings: mv lodepng.cpp lodepng.c ; gcc -I ./ lodepng.c examples/example_decode.c -ansi -pedantic -Werror -Wall -Wextra -O3 ; mv lodepng.c lodepng.cpp mv lodepng.cpp lodepng.c ; clang -I ./ lodepng.c examples/example_decode.c -ansi -pedantic -Werror -Wall -Wextra -O3 ; mv lodepng.c lodepng.cpp *) Compile with C with -pedantic but not -ansi flag so it warns about // style comments in C++-only ifdefs mv lodepng.cpp lodepng.c ; gcc -I ./ lodepng.c examples/example_decode.c -pedantic -Werror -Wall -Wextra -O3 ; mv lodepng.c lodepng.cpp *) test other compilers *) try lodepng_benchmark.cpp g++ lodepng.cpp lodepng_benchmark.cpp -Werror -Wall -Wextra -pedantic -ansi -lSDL2 -O3 && ./a.out testdata/corpus/''* *) try the fuzzer clang++ -fsanitize=fuzzer -DLODEPNG_MAX_ALLOC=100000000 lodepng.cpp lodepng_fuzzer.cpp -O3 -o fuzzer && ./fuzzer clang++ -fsanitize=fuzzer,address,undefined -DLODEPNG_MAX_ALLOC=100000000 lodepng.cpp lodepng_fuzzer.cpp -O3 -o fuzzer && ./fuzzer *) Check if all C++ examples compile without warnings: g++ -I ./ lodepng.cpp examples/''*.cpp -Werror -W -Wall -ansi -pedantic -O3 -c *) Check if all C examples compile without warnings: mv lodepng.cpp lodepng.c ; gcc -I ./ lodepng.c examples/''*.c -Werror -W -Wall -ansi -pedantic -O3 -c ; mv lodepng.c lodepng.cpp *) Check pngdetail.cpp: g++ lodepng.cpp lodepng_util.cpp pngdetail.cpp -Werror -W -Wall -ansi -pedantic -O3 -o pngdetail ./pngdetail testdata/PngSuite/basi0g01.png *) Test compiling with some code sections with #defines disabled, for unused static function warnings etc... g++ lodepng.cpp -W -Wall -ansi -pedantic -O3 -c -DLODEPNG_NO_COMPILE_CRC g++ lodepng.cpp -W -Wall -ansi -pedantic -O3 -c -DLODEPNG_NO_COMPILE_ZLIB g++ lodepng.cpp -W -Wall -ansi -pedantic -O3 -c -DLODEPNG_NO_COMPILE_PNG g++ lodepng.cpp -W -Wall -ansi -pedantic -O3 -c -DLODEPNG_NO_COMPILE_DECODER g++ lodepng.cpp -W -Wall -ansi -pedantic -O3 -c -DLODEPNG_NO_COMPILE_ENCODER g++ lodepng.cpp -W -Wall -ansi -pedantic -O3 -c -DLODEPNG_NO_COMPILE_DISK g++ lodepng.cpp -W -Wall -ansi -pedantic -O3 -c -DLODEPNG_NO_COMPILE_ANCILLARY_CHUNKS g++ lodepng.cpp -W -Wall -ansi -pedantic -O3 -c -DLODEPNG_NO_COMPILE_ERROR_TEXT g++ lodepng.cpp -W -Wall -ansi -pedantic -O3 -c -DLODEPNG_NO_COMPILE_CPP g++ lodepng.cpp -W -Wall -ansi -pedantic -O3 -c -DLODEPNG_NO_COMPILE_ZLIB -DLODEPNG_NO_COMPILE_DECODER g++ lodepng.cpp -W -Wall -ansi -pedantic -O3 -c -DLODEPNG_NO_COMPILE_ZLIB -DLODEPNG_NO_COMPILE_ENCODER g++ lodepng.cpp -W -Wall -ansi -pedantic -O3 -c -DLODEPNG_NO_COMPILE_PNG -DLODEPNG_NO_COMPILE_DECODER g++ lodepng.cpp -W -Wall -ansi -pedantic -O3 -c -DLODEPNG_NO_COMPILE_PNG -DLODEPNG_NO_COMPILE_ENCODER g++ lodepng.cpp -W -Wall -ansi -pedantic -O3 -c -DLODEPNG_NO_COMPILE_DECODER -DLODEPNG_NO_COMPILE_ANCILLARY_CHUNKS -DLODEPNG_NO_COMPILE_ERROR_TEXT -DLODEPNG_NO_COMPILE_DISK g++ lodepng.cpp -W -Wall -ansi -pedantic -O3 -c -DLODEPNG_NO_COMPILE_ENCODER -DLODEPNG_NO_COMPILE_ANCILLARY_CHUNKS -DLODEPNG_NO_COMPILE_ERROR_TEXT -DLODEPNG_NO_COMPILE_DISK rm *.o *) analyze with clang: clang++ lodepng.cpp --analyze More verbose: clang++ --analyze -Xanalyzer -analyzer-output=text lodepng.cpp Or html, look under lodepng.plist dir afterwards and find the numbered locations in the pages: clang++ --analyze -Xanalyzer -analyzer-output=html lodepng.cpp *) check for memory leaks and vulnerabilities with valgrind (DISABLE_SLOW disables a few tests that are very slow with valgrind) g++ -DDISABLE_SLOW lodepng.cpp lodepng_util.cpp lodepng_unittest.cpp -Wall -Wextra -pedantic -ansi -O3 -DLODEPNG_MAX_ALLOC=100000000 && valgrind --leak-check=full --track-origins=yes ./a.out *) Try with clang++ and address sanitizer (to get line numbers, make sure 'llvm' is also installed to get 'llvm-symbolizer' clang++ -O3 -fsanitize=address,undefined lodepng.cpp lodepng_util.cpp lodepng_unittest.cpp -Werror -Wall -Wextra -Wshadow -pedantic -ansi && ASAN_OPTIONS=allocator_may_return_null=1 ./a.out clang++ -g3 -fsanitize=address,undefined lodepng.cpp lodepng_util.cpp lodepng_unittest.cpp -Werror -Wall -Wextra -Wshadow -pedantic -ansi && ASAN_OPTIONS=allocator_may_return_null=1 ./a.out *) remove "#include " from lodepng.cpp if it's still in there (some are legit) cat lodepng.cpp lodepng_util.cpp | grep iostream cat lodepng.cpp lodepng_util.cpp | grep stdio cat lodepng.cpp lodepng_util.cpp | grep "#include" *) try the Makefile make clean && make -j rm *.o *.obj *) check that no plain free, malloc, realloc, strlen, memcpy, memset, ... used, but the lodepng_* versions instead *) check version dates in copyright message and LODEPNG_VERSION_STRING *) check year in copyright message at top of all files as well as at bottom of lodepng.h *) check examples/sdl.cpp with the png test suite images (the "x" ones are expected to show error) g++ -I ./ lodepng.cpp examples/example_sdl.cpp -Werror -Wall -Wextra -pedantic -ansi -O3 -lSDL2 -o showpng && ./showpng testdata/PngSuite/''*.png *) strip trailing spaces and ensure consistent newlines *) test warnings in other compilers *) check diff of lodepng.cpp and lodepng.h before submitting git difftool -y */ #include "lodepng.h" #include "lodepng_util.h" #include #include #include #include #include #include #include #include #include //////////////////////////////////////////////////////////////////////////////// void fail() { throw 1; //that's how to let a unittest fail } //Utility for debug messages template std::string valtostr(const T& val) { std::ostringstream sstream; sstream << val; return sstream.str(); } //Print char as a numeric value rather than a character template<> std::string valtostr(const unsigned char& val) { std::ostringstream sstream; sstream << (int)val; return sstream.str(); } //Print char pointer as pointer, not as string template std::string valtostr(const T* val) { std::ostringstream sstream; sstream << (const void*)val; return sstream.str(); } template std::string valtostr(const std::vector& val) { std::ostringstream sstream; sstream << "[vector with size " << val.size() << "]"; return sstream.str(); } // TODO: remove, use only ASSERT_EQUALS (it prints line number). Requires adding extra message ability to ASSERT_EQUALS template void assertEquals(const T& expected, const U& actual, const std::string& message = "") { if(expected != (T)actual) { std::cout << "Error: Not equal! Expected " << valtostr(expected) << " got " << valtostr((T)actual) << ". " << "Message: " << message << std::endl; fail(); } } // TODO: remove, use only ASSERT_TRUE (it prints line number). Requires adding extra message ability to ASSERT_TRUE void assertTrue(bool value, const std::string& message = "") { if(!value) { std::cout << "Error: expected true. " << "Message: " << message << std::endl; fail(); } } //assert that no error void assertNoPNGError(unsigned error, const std::string& message = "") { if(error) { std::string msg = (message == "") ? lodepng_error_text(error) : message + std::string(": ") + lodepng_error_text(error); assertEquals(0, error, msg); } } void assertNoError(unsigned error) { if(error) { assertEquals(0, error, "Expected no error"); } } #define STR_EXPAND(s) #s #define STR(s) STR_EXPAND(s) #define ASSERT_TRUE(v) {\ if(!(v)) {\ std::cout << std::string("line ") + STR(__LINE__) + ": " + STR(v) + " ASSERT_TRUE failed: ";\ std::cout << "Expected true but got " << valtostr(v) << ". " << std::endl;\ fail();\ }\ } #define ASSERT_EQUALS(e, v) {\ if((e) != (v)) {\ std::cout << std::string("line ") + STR(__LINE__) + ": " + STR(v) + " ASSERT_EQUALS failed: ";\ std::cout << "Expected " << valtostr(e) << " but got " << valtostr(v) << ". " << std::endl;\ fail();\ }\ } #define ASSERT_NOT_EQUALS(e, v) {\ if((e) == (v)) {\ std::cout << std::string("line ") + STR(__LINE__) + ": " + STR(v) + " ASSERT_NOT_EQUALS failed: ";\ std::cout << "Expected not " << valtostr(e) << " but got " << valtostr(v) << ". " << std::endl;\ fail();\ }\ } template bool isNear(T e, U v, V maxdist) { T dist = e > (T)v ? e - (T)v : (T)v - e; return dist <= (T)maxdist; } template T diff(T e, U v) { return v > e ? v - e : e - v; } #define ASSERT_NEAR(e, v, maxdist) {\ if(!isNear(e, v, maxdist)) {\ std::cout << std::string("line ") + STR(__LINE__) + ": " + STR(v) + " ASSERT_NEAR failed: ";\ std::cout << "dist too great! Expected near " << valtostr(e) << " but got " << valtostr(v) << ", with max dist " << valtostr(maxdist)\ << " but got dist " << valtostr(diff(e, v)) << ". " << std::endl;\ fail();\ }\ } #define ASSERT_STRING_EQUALS(e, v) ASSERT_EQUALS(std::string(e), std::string(v)) #define ASSERT_NO_PNG_ERROR_MSG(error, message) assertNoPNGError(error, std::string("line ") + STR(__LINE__) + (std::string(message).empty() ? std::string("") : (": " + std::string(message)))) #define ASSERT_NO_PNG_ERROR(error) ASSERT_NO_PNG_ERROR_MSG(error, std::string("")) static const std::string BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; //T and U can be std::string or std::vector template void toBase64(T& out, const U& in) { for(size_t i = 0; i < in.size(); i += 3) { int v = 65536 * in[i]; if(i + 1 < in.size()) v += 256 * in[i + 1]; if(i + 2 < in.size()) v += in[i + 2]; out.push_back(BASE64[(v >> 18) & 0x3f]); out.push_back(BASE64[(v >> 12) & 0x3f]); if(i + 1 < in.size()) out.push_back(BASE64[(v >> 6) & 0x3f]); else out.push_back('='); if(i + 2 < in.size()) out.push_back(BASE64[(v >> 0) & 0x3f]); else out.push_back('='); } } int fromBase64(int v) { if(v >= 'A' && v <= 'Z') return (v - 'A'); if(v >= 'a' && v <= 'z') return (v - 'a' + 26); if(v >= '0' && v <= '9') return (v - '0' + 52); if(v == '+') return 62; if(v == '/') return 63; return 0; //v == '=' } //T and U can be std::string or std::vector template void fromBase64(T& out, const U& in) { for(size_t i = 0; i + 3 < in.size(); i += 4) { int v = 262144 * fromBase64(in[i]) + 4096 * fromBase64(in[i + 1]) + 64 * fromBase64(in[i + 2]) + fromBase64(in[i + 3]); out.push_back((v >> 16) & 0xff); if(in[i + 2] != '=') out.push_back((v >> 8) & 0xff); if(in[i + 3] != '=') out.push_back((v >> 0) & 0xff); } } unsigned getRandom() { static unsigned s = 1000000000; // xorshift32, good enough for testing s ^= (s << 13); s ^= (s >> 17); s ^= (s << 5); return s; } //////////////////////////////////////////////////////////////////////////////// unsigned leftrotate(unsigned x, unsigned c) { return (x << c) | (x >> (32u - c)); } // the 128-bit result is output in 4 32-bit integers a0..d0 (to make 16-byte digest: append a0|b0|c0|d0 in little endian) void md5sum(const unsigned char* in, size_t size, unsigned* a0, unsigned* b0, unsigned* c0, unsigned* d0) { ASSERT_EQUALS(4, sizeof(unsigned)); // per-round shift amounts static const unsigned s[64] = { 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, }; // precomputed table from sines static const unsigned k[64] = { 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391, }; *a0 = 0x67452301; *b0 = 0xefcdab89; *c0 = 0x98badcfe; *d0 = 0x10325476; // append bit, padding and size to input std::vector data(in, in + size); data.resize(((size + 1 + 8 + 63) / 64) * 64, 0); data[size] = 128; // append 1 bit (msb) size_t bitsize = size * 8; // append the size (shifts > 31 are avoided) data[data.size() - 1] = ((bitsize >> 28u) >> 28u) & 255u; data[data.size() - 2] = ((bitsize >> 24u) >> 24u) & 255u; data[data.size() - 3] = ((bitsize >> 20u) >> 20u) & 255u; data[data.size() - 4] = ((bitsize >> 16u) >> 16u) & 255u; data[data.size() - 5] = (bitsize >> 24u) & 255u; data[data.size() - 6] = (bitsize >> 16u) & 255u; data[data.size() - 7] = (bitsize >> 8u) & 255u; data[data.size() - 8] = bitsize & 255u; // per chunk for(size_t i = 0; i < data.size(); i += 64) { unsigned a = *a0; unsigned b = *b0; unsigned c = *c0; unsigned d = *d0; for(size_t j = 0; j < 64; j++) { unsigned f, g; if(j <= 15u) { f = (b & c) | (~b & d); g = j; } else if(j <= 31u) { f = (d & b) | (~d & c); g = (5u * j + 1u) & 15u; } else if(j <= 47u) { f = b ^ c ^ d; g = (3u * j + 5u) & 15u; } else { f = c ^ (b | ~d); g = (7u * j) & 15u; } unsigned m = (unsigned)(data[i + g * 4 + 3] << 24u) | (unsigned)(data[i + g * 4 + 2] << 16u) | (unsigned)(data[i + g * 4 + 1] << 8u) | (unsigned)data[i + g * 4]; f += a + k[j] + m; a = d; d = c; c = b; b += leftrotate(f, s[j]); } *a0 += a; *b0 += b; *c0 += c; *d0 += d; } } std::string md5sum(const std::vector& in) { unsigned a0, b0, c0, d0; md5sum(in.data(), in.size(), &a0, &b0, &c0, &d0); char result[33]; //sprintf(result, "%8.8x%8.8x%8.8x%8.8x", a0, b0, c0, d0); sprintf(result, "%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x", a0 & 255, (a0 >> 8) & 255, (a0 >> 16) & 255, (a0 >> 24) & 255, b0 & 255, (b0 >> 8) & 255, (b0 >> 16) & 255, (b0 >> 24) & 255, c0 & 255, (c0 >> 8) & 255, (c0 >> 16) & 255, (c0 >> 24) & 255, d0 & 255, (d0 >> 8) & 255, (d0 >> 16) & 255, (d0 >> 24) & 255); return std::string(result); } //////////////////////////////////////////////////////////////////////////////// //Test image data struct Image { std::vector data; unsigned width; unsigned height; LodePNGColorType colorType; unsigned bitDepth; }; //Get number of color channels for a given PNG color type unsigned getNumColorChannels(unsigned colorType) { switch(colorType) { case 0: return 1; /*gray*/ case 2: return 3; /*RGB*/ case 3: return 1; /*palette*/ case 4: return 2; /*gray + alpha*/ case 6: return 4; /*RGBA*/ } return 0; /*unexisting color type*/ } //Generate a test image with some data in it, the contents of the data is unspecified, //except the content is not just one plain color, and not true random either to be compressible. void generateTestImage(Image& image, unsigned width, unsigned height, LodePNGColorType colorType = LCT_RGBA, unsigned bitDepth = 8) { image.width = width; image.height = height; image.colorType = colorType; image.bitDepth = bitDepth; size_t bits = bitDepth * getNumColorChannels(colorType); //bits per pixel size_t size = (width * height * bits + 7) / 8; //total image size in bytes image.data.resize(size); unsigned char value = 128; for(size_t i = 0; i < size; i++) { image.data[i] = value++; } } //Generate a 16-bit test image with minimal size that requires at minimum the given color type (bit depth, grayscaleness, ...) //If key is true, makes it such that exactly one color is transparent, so it can use a key. If false, adds a translucent color depending on //whether it's an alpha color type or not. void generateTestImageRequiringColorType16(Image& image, LodePNGColorType colorType, unsigned bitDepth, bool key) { image.colorType = colorType; image.bitDepth = bitDepth; unsigned w = 1; unsigned h = 1; bool gray = colorType == LCT_GREY || colorType == LCT_GREY_ALPHA; bool alpha = colorType == LCT_RGBA || colorType == LCT_GREY_ALPHA; if(colorType == LCT_PALETTE) { w = 1u << bitDepth; h = 256; // ensure it'll really choose palette, not omit it due to small image size image.data.resize(w * h * 8); for(size_t y = 0; y < h; y++) { for(size_t x = 0; x < w; x++) { size_t i = y * w * 8 + x * 8; image.data[i + 0] = image.data[i + 1] = y; image.data[i + 2] = image.data[i + 3] = 255; image.data[i + 4] = image.data[i + 5] = 0; image.data[i + 6] = image.data[i + 7] = (key && y == 0) ? 0 : 255; } } } else if(bitDepth == 16) { // one color suffices for this model. But add one more to support key. w = 2; image.data.resize(w * h * 8); image.data[0] = 10; image.data[1] = 20; image.data[2] = 10; image.data[3] = 20; image.data[4] = gray ? 10 : 110; image.data[5] = gray ? 20 : 120; image.data[6] = alpha ? 128 : 255; image.data[7] = alpha ? 20 : 255; image.data[8] = 40; image.data[9] = 50; image.data[10] = 40; image.data[11] = 50; image.data[12] = gray ? 40 : 140; image.data[13] = gray ? 50 : 150; image.data[14] = key ? 0 : 255; image.data[15] = key ? 0 : 255; } else if(gray) { w = 2; unsigned v = 255u / ((1u << bitDepth) - 1u); // value that forces at least this bitdepth image.data.resize(w * h * 8); image.data[0] = v; image.data[1] = v; image.data[2] = v; image.data[3] = v; image.data[4] = v; image.data[5] = v; image.data[6] = alpha ? v : 255; image.data[7] = alpha ? v : 255; image.data[8] = image.data[9] = 0; image.data[10] = image.data[11] = 0; image.data[12] = image.data[13] = 0; image.data[14] = image.data[15] = key ? 0 : 255; } else { // now it's RGB or RGBA with bitdepth 8 w = 257; // must have at least more than 256 colors so it won't use palette image.data.resize(w * h * 8); for(size_t y = 0; y < h; y++) { for(size_t x = 0; x < w; x++) { size_t i = y * w * 8 + x * 8; image.data[i + 0] = image.data[i + 1] = i / 2; image.data[i + 2] = image.data[i + 3] = i / 3; image.data[i + 4] = image.data[i + 5] = i / 5; image.data[i + 6] = image.data[i + 7] = (key && y == 0) ? 0 : (alpha ? i : 255); } } } image.width = w; image.height = h; } //Generate a 8-bit test image with minimal size that requires at minimum the given color type (bit depth, grayscaleness, ...). bitDepth max 8 here. //If key is true, makes it such that exactly one color is transparent, so it can use a key. If false, adds a translucent color depending on //whether it's an alpha color type or not. void generateTestImageRequiringColorType8(Image& image, LodePNGColorType colorType, unsigned bitDepth, bool key) { image.colorType = colorType; image.bitDepth = bitDepth; unsigned w = 1; unsigned h = 1; bool gray = colorType == LCT_GREY || colorType == LCT_GREY_ALPHA; bool alpha = colorType == LCT_RGBA || colorType == LCT_GREY_ALPHA; if(colorType == LCT_PALETTE) { w = 1u << bitDepth; h = 256; // ensure it'll really choose palette, not omit it due to small image size image.data.resize(w * h * 4); for(size_t y = 0; y < h; y++) { for(size_t x = 0; x < w; x++) { size_t i = y * w * 4 + x * 4; image.data[i + 0] = x; image.data[i + 1] = 255; image.data[i + 2] = 0; image.data[i + 3] = (key && x == 0) ? 0 : 255; } } } else if(gray) { w = 2; unsigned v = 255u / ((1u << bitDepth) - 1u); // value that forces at least this bitdepth image.data.resize(w * h * 4); image.data[0] = v; image.data[1] = v; image.data[2] = v; image.data[3] = alpha ? v : 255; image.data[4] = 0; image.data[5] = 0; image.data[6] = 0; image.data[7] = key ? 0 : 255; } else { // now it's RGB or RGBA with bitdepth 8 w = 257; // must have at least more than 256 colors so it won't use palette image.data.resize(w * h * 4); for(size_t y = 0; y < h; y++) { for(size_t x = 0; x < w; x++) { size_t i = y * w * 4 + x * 4; image.data[i + 0] = i / 2; image.data[i + 1] = i / 3; image.data[i + 2] = i / 5; image.data[i + 3] = (key && x == 0) ? 0 : (alpha ? i : 255); } } } image.width = w; image.height = h; } //Check that the decoded PNG pixels are the same as the pixels in the image void assertPixels(Image& image, const unsigned char* decoded, const std::string& message) { for(size_t i = 0; i < image.data.size(); i++) { int byte_expected = image.data[i]; int byte_actual = decoded[i]; //last byte is special due to possible random padding bits which need not to be equal if(i == image.data.size() - 1) { size_t numbits = getNumColorChannels(image.colorType) * image.bitDepth * image.width * image.height; size_t padding = 8u - (numbits - 8u * (numbits / 8u)); if(padding != 8u) { //set all padding bits of both to 0 for(size_t j = 0; j < padding; j++) { byte_expected = (byte_expected & (~(1 << j))) % 256; byte_actual = (byte_actual & (~(1 << j))) % 256; } } } assertEquals(byte_expected, byte_actual, message + " " + valtostr(i)); } } //Test LodePNG encoding and decoding the encoded result, using the C interface void doCodecTestC(Image& image) { unsigned char* encoded = 0; size_t encoded_size = 0; unsigned char* decoded = 0; unsigned decoded_w; unsigned decoded_h; struct OnExitScope { unsigned char** a; unsigned char** b; OnExitScope(unsigned char** ca, unsigned char** cb) : a(ca), b(cb) {} ~OnExitScope() { free(*a); free(*b); } } onExitScope(&encoded, &decoded); unsigned error_enc = lodepng_encode_memory(&encoded, &encoded_size, &image.data[0], image.width, image.height, image.colorType, image.bitDepth); if(error_enc != 0) std::cout << "Error: " << lodepng_error_text(error_enc) << std::endl; ASSERT_NO_PNG_ERROR_MSG(error_enc, "encoder error C"); //if the image is large enough, compressing it should result in smaller size if(image.data.size() > 512) assertTrue(encoded_size < image.data.size(), "compressed size"); unsigned error_dec = lodepng_decode_memory(&decoded, &decoded_w, &decoded_h, encoded, encoded_size, image.colorType, image.bitDepth); if(error_dec != 0) std::cout << "Error: " << lodepng_error_text(error_dec) << std::endl; ASSERT_NO_PNG_ERROR_MSG(error_dec, "decoder error C"); ASSERT_EQUALS(image.width, decoded_w); ASSERT_EQUALS(image.height, decoded_h); assertPixels(image, decoded, "Pixels C"); } //Test LodePNG encoding and decoding the encoded result, using the C++ interface void doCodecTestCPP(Image& image) { std::vector encoded; std::vector decoded; unsigned decoded_w; unsigned decoded_h; unsigned error_enc = lodepng::encode(encoded, image.data, image.width, image.height, image.colorType, image.bitDepth); ASSERT_NO_PNG_ERROR_MSG(error_enc, "encoder error C++"); //if the image is large enough, compressing it should result in smaller size if(image.data.size() > 512) assertTrue(encoded.size() < image.data.size(), "compressed size"); unsigned error_dec = lodepng::decode(decoded, decoded_w, decoded_h, encoded, image.colorType, image.bitDepth); ASSERT_NO_PNG_ERROR_MSG(error_dec, "decoder error C++"); ASSERT_EQUALS(image.width, decoded_w); ASSERT_EQUALS(image.height, decoded_h); ASSERT_EQUALS(image.data.size(), decoded.size()); assertPixels(image, &decoded[0], "Pixels C++"); } void doCodecTestWithEncState(Image& image, lodepng::State& state) { std::vector encoded; std::vector decoded; unsigned decoded_w; unsigned decoded_h; state.info_raw.colortype = image.colorType; state.info_raw.bitdepth = image.bitDepth; unsigned error_enc = lodepng::encode(encoded, image.data, image.width, image.height, state); ASSERT_NO_PNG_ERROR_MSG(error_enc, "encoder error uncompressed"); unsigned error_dec = lodepng::decode(decoded, decoded_w, decoded_h, encoded, image.colorType, image.bitDepth); ASSERT_NO_PNG_ERROR_MSG(error_dec, "decoder error uncompressed"); ASSERT_EQUALS(image.width, decoded_w); ASSERT_EQUALS(image.height, decoded_h); ASSERT_EQUALS(image.data.size(), decoded.size()); assertPixels(image, &decoded[0], "Pixels uncompressed"); } //Test LodePNG encoding and decoding the encoded result, using the C++ interface void doCodecTestUncompressed(Image& image) { lodepng::State state; state.encoder.zlibsettings.btype = 0; doCodecTestWithEncState(image, state); } void doCodecTestNoLZ77(Image& image) { lodepng::State state; state.encoder.zlibsettings.use_lz77 = 0; doCodecTestWithEncState(image, state); } void testGetFilterTypes() { std::cout << "testGetFilterTypes" << std::endl; // Test that getFilterTypes works on the special case of 1-pixel wide interlaced image std::string png64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAAHCAIAAAExKYBVAAAAHUlEQVR4ASXHAQoAAAjCwPX/R9tK4ZBN4EHKcPcLXCgGAQa0TV8AAAAASUVORK5CYII="; std::vector png; fromBase64(png, png64); std::vector types; lodepng::getFilterTypes(types, png); ASSERT_EQUALS(7, types.size()); ASSERT_EQUALS(1, types[0]); ASSERT_EQUALS(1, types[1]); ASSERT_EQUALS(1, types[2]); ASSERT_EQUALS(0, types[3]); ASSERT_EQUALS(1, types[4]); ASSERT_EQUALS(1, types[5]); ASSERT_EQUALS(1, types[6]); } //Test LodePNG encoding and decoding the encoded result, using the C++ interface, with interlace void doCodecTestInterlaced(Image& image) { std::vector encoded; std::vector decoded; unsigned decoded_w; unsigned decoded_h; lodepng::State state; state.info_png.interlace_method = 1; state.info_raw.colortype = image.colorType; state.info_raw.bitdepth = image.bitDepth; unsigned error_enc = lodepng::encode(encoded, image.data, image.width, image.height, state); ASSERT_NO_PNG_ERROR_MSG(error_enc, "encoder error interlaced"); //if the image is large enough, compressing it should result in smaller size if(image.data.size() > 512) assertTrue(encoded.size() < image.data.size(), "compressed size"); state.info_raw.colortype = image.colorType; state.info_raw.bitdepth = image.bitDepth; unsigned error_dec = lodepng::decode(decoded, decoded_w, decoded_h, state, encoded); ASSERT_NO_PNG_ERROR_MSG(error_dec, "decoder error interlaced"); ASSERT_EQUALS(image.width, decoded_w); ASSERT_EQUALS(image.height, decoded_h); ASSERT_EQUALS(image.data.size(), decoded.size()); assertPixels(image, &decoded[0], "Pixels interlaced"); } //Test LodePNG encoding and decoding the encoded result void doCodecTest(Image& image) { doCodecTestC(image); doCodecTestCPP(image); doCodecTestInterlaced(image); doCodecTestUncompressed(image); doCodecTestNoLZ77(image); } //Test LodePNG encoding and decoding using some image generated with the given parameters void codecTest(unsigned width, unsigned height, LodePNGColorType colorType = LCT_RGBA, unsigned bitDepth = 8) { std::cout << "codec test " << width << " " << height << std::endl; Image image; generateTestImage(image, width, height, colorType, bitDepth); doCodecTest(image); } std::string removeSpaces(const std::string& s) { std::string result; for(size_t i = 0; i < s.size(); i++) if(s[i] != ' ') result += s[i]; return result; } void bitStringToBytes(std::vector& bytes, const std::string& bits_) { std::string bits = removeSpaces(bits_); bytes.resize((bits.size()) + 7 / 8); for(size_t i = 0; i < bits.size(); i++) { size_t j = i / 8; size_t k = i % 8; char c = bits[i]; if(k == 0) bytes[j] = 0; if(c == '1') bytes[j] |= (1 << (7 - k)); } } /* test color convert on a single pixel. Testing palette and testing color keys is not supported by this function. Pixel values given using bits in an std::string of 0's and 1's. */ void colorConvertTest(const std::string& bits_in, LodePNGColorType colorType_in, unsigned bitDepth_in, const std::string& bits_out, LodePNGColorType colorType_out, unsigned bitDepth_out) { std::cout << "color convert test " << bits_in << " - " << bits_out << std::endl; std::vector expected, actual, image; bitStringToBytes(expected, bits_out); actual.resize(expected.size()); bitStringToBytes(image, bits_in); LodePNGColorMode mode_in, mode_out; lodepng_color_mode_init(&mode_in); lodepng_color_mode_init(&mode_out); mode_in.colortype = colorType_in; mode_in.bitdepth = bitDepth_in; mode_out.colortype = colorType_out; mode_out.bitdepth = bitDepth_out; unsigned error = lodepng_convert(&actual[0], &image[0], &mode_out, &mode_in, 1, 1); ASSERT_NO_PNG_ERROR_MSG(error, "convert error"); for(size_t i = 0; i < expected.size(); i++) { assertEquals((int)expected[i], (int)actual[i], "byte " + valtostr(i)); } lodepng_color_mode_cleanup(&mode_in); lodepng_color_mode_cleanup(&mode_out); } void testOtherPattern1() { std::cout << "codec other pattern 1" << std::endl; Image image1; size_t w = 192; size_t h = 192; image1.width = w; image1.height = h; image1.colorType = LCT_RGBA; image1.bitDepth = 8; image1.data.resize(w * h * 4u); for(size_t y = 0; y < h; y++) for(size_t x = 0; x < w; x++) { //pattern 1 image1.data[4u * w * y + 4u * x + 0u] = (unsigned char)(127 * (1 + std::sin(( x * x + y * y) / (w * h / 8.0)))); image1.data[4u * w * y + 4u * x + 1u] = (unsigned char)(127 * (1 + std::sin(((w - x - 1) * (w - x - 1) + y * y) / (w * h / 8.0)))); image1.data[4u * w * y + 4u * x + 2u] = (unsigned char)(127 * (1 + std::sin(( x * x + (h - y - 1) * (h - y - 1)) / (w * h / 8.0)))); image1.data[4u * w * y + 4u * x + 3u] = (unsigned char)(127 * (1 + std::sin(((w - x - 1) * (w - x - 1) + (h - y - 1) * (h - y - 1)) / (w * h / 8.0)))); } doCodecTest(image1); } void testOtherPattern2() { std::cout << "codec other pattern 2" << std::endl; Image image1; size_t w = 192; size_t h = 192; image1.width = w; image1.height = h; image1.colorType = LCT_RGBA; image1.bitDepth = 8; image1.data.resize(w * h * 4u); for(size_t y = 0; y < h; y++) for(size_t x = 0; x < w; x++) { image1.data[4u * w * y + 4u * x + 0u] = 255 * !(x & y); image1.data[4u * w * y + 4u * x + 1u] = x ^ y; image1.data[4u * w * y + 4u * x + 2u] = x | y; image1.data[4u * w * y + 4u * x + 3u] = 255; } doCodecTest(image1); } void testSinglePixel(int r, int g, int b, int a) { std::cout << "codec single pixel " << r << " " << g << " " << b << " " << a << std::endl; Image pixel; pixel.width = 1; pixel.height = 1; pixel.colorType = LCT_RGBA; pixel.bitDepth = 8; pixel.data.resize(4); pixel.data[0] = r; pixel.data[1] = g; pixel.data[2] = b; pixel.data[3] = a; doCodecTest(pixel); } void testColor(int r, int g, int b, int a) { std::cout << "codec test color " << r << " " << g << " " << b << " " << a << std::endl; Image image; image.width = 20; image.height = 20; image.colorType = LCT_RGBA; image.bitDepth = 8; image.data.resize(20 * 20 * 4); for(size_t y = 0; y < 20; y++) for(size_t x = 0; x < 20; x++) { image.data[20 * 4 * y + 4 * x + 0] = r; image.data[20 * 4 * y + 4 * x + 0] = g; image.data[20 * 4 * y + 4 * x + 0] = b; image.data[20 * 4 * y + 4 * x + 0] = a; } doCodecTest(image); Image image2 = image; image2.data[3] = 0; //one fully transparent pixel doCodecTest(image2); image2.data[3] = 128; //one semi transparent pixel doCodecTest(image2); Image image3 = image; // add 255 different colors for(size_t i = 0; i < 255; i++) { image.data[i * 4 + 0] = i; image.data[i * 4 + 1] = i; image.data[i * 4 + 2] = i; image.data[i * 4 + 3] = 255; } doCodecTest(image3); // a 256th color image.data[255 * 4 + 0] = 255; image.data[255 * 4 + 1] = 255; image.data[255 * 4 + 2] = 255; image.data[255 * 4 + 3] = 255; doCodecTest(image3); testSinglePixel(r, g, b, a); } // Tests combinations of various colors in different orders void testFewColors() { std::cout << "codec test few colors " << std::endl; Image image; image.width = 4; image.height = 4; image.colorType = LCT_RGBA; image.bitDepth = 8; image.data.resize(image.width * image.height * 4); std::vector colors; colors.push_back(0); colors.push_back(0); colors.push_back(0); colors.push_back(255); // black colors.push_back(255); colors.push_back(255); colors.push_back(255); colors.push_back(255); // white colors.push_back(128); colors.push_back(128); colors.push_back(128); colors.push_back(255); // gray colors.push_back(0); colors.push_back(0); colors.push_back(255); colors.push_back(255); // blue colors.push_back(255); colors.push_back(255); colors.push_back(255); colors.push_back(0); // transparent white colors.push_back(255); colors.push_back(255); colors.push_back(255); colors.push_back(1); // translucent white for(size_t i = 0; i < colors.size(); i += 4) for(size_t j = 0; j < colors.size(); j += 4) for(size_t k = 0; k < colors.size(); k += 4) for(size_t l = 0; l < colors.size(); l += 4) { for(unsigned y = 0; y < image.height; y++) for(unsigned x = 0; x < image.width; x++) { size_t a = (y * image.width + x) & 3; size_t b = (a == 0) ? i : ((a == 1) ? j : ((a == 2) ? k : l)); for(size_t c = 0; c < 4; c++) { image.data[y * image.width * 4 + x * 4 + c] = colors[b + c]; } } doCodecTest(image); } image.width = 20; image.height = 20; image.data.resize(image.width * image.height * 4); for(size_t i = 0; i < colors.size(); i += 4) for(size_t j = 0; j < colors.size(); j += 4) for(size_t k = 0; k < colors.size(); k += 4) { for(unsigned y = 0; y < image.height; y++) for(unsigned x = 0; x < image.width; x++) { size_t a = (y * image.width + x) % 3; size_t b = (a == 0) ? i : ((a == 1) ? j : k); for(size_t c = 0; c < 4; c++) { image.data[y * image.width * 4 + x * 4 + c] = colors[b + c]; } } doCodecTest(image); } } void testSize(unsigned w, unsigned h) { std::cout << "codec test size " << w << " " << h << std::endl; Image image; image.width = w; image.height = h; image.colorType = LCT_RGBA; image.bitDepth = 8; image.data.resize(w * h * 4); for(size_t y = 0; y < h; y++) for(size_t x = 0; x < w; x++) { image.data[w * 4 * y + 4 * x + 0] = x % 256; image.data[w * 4 * y + 4 * x + 0] = y % 256; image.data[w * 4 * y + 4 * x + 0] = 255; image.data[w * 4 * y + 4 * x + 0] = 255; } doCodecTest(image); } void testPNGCodec() { codecTest(1, 1); codecTest(2, 2); codecTest(1, 1, LCT_GREY, 1); codecTest(7, 7, LCT_GREY, 1); #ifndef DISABLE_SLOW codecTest(127, 127); codecTest(127, 127, LCT_GREY, 1); codecTest(320, 320); codecTest(1, 10000); codecTest(10000, 1); testOtherPattern1(); testOtherPattern2(); #endif // DISABLE_SLOW testColor(255, 255, 255, 255); testColor(0, 0, 0, 255); testColor(1, 2, 3, 255); testColor(255, 0, 0, 255); testColor(0, 255, 0, 255); testColor(0, 0, 255, 255); testColor(0, 0, 0, 255); testColor(1, 1, 1, 255); testColor(1, 1, 1, 1); testColor(0, 0, 0, 128); testColor(255, 0, 0, 128); testColor(127, 127, 127, 255); testColor(128, 128, 128, 255); testColor(127, 127, 127, 128); testColor(128, 128, 128, 128); //transparent single pixels testColor(0, 0, 0, 0); testColor(255, 0, 0, 0); testColor(1, 2, 3, 0); testColor(255, 255, 255, 0); testColor(254, 254, 254, 0); // This is mainly to test the Adam7 interlacing for(unsigned h = 1; h < 12; h++) for(unsigned w = 1; w < 12; w++) { testSize(w, h); } } //Tests some specific color conversions with specific color bit combinations void testColorConvert() { //test color conversions to RGBA8 colorConvertTest("1", LCT_GREY, 1, "11111111 11111111 11111111 11111111", LCT_RGBA, 8); colorConvertTest("10", LCT_GREY, 2, "10101010 10101010 10101010 11111111", LCT_RGBA, 8); colorConvertTest("1001", LCT_GREY, 4, "10011001 10011001 10011001 11111111", LCT_RGBA, 8); colorConvertTest("10010101", LCT_GREY, 8, "10010101 10010101 10010101 11111111", LCT_RGBA, 8); colorConvertTest("10010101 11111110", LCT_GREY_ALPHA, 8, "10010101 10010101 10010101 11111110", LCT_RGBA, 8); colorConvertTest("10010101 00000001 11111110 00000001", LCT_GREY_ALPHA, 16, "10010101 10010101 10010101 11111110", LCT_RGBA, 8); colorConvertTest("01010101 00000000 00110011", LCT_RGB, 8, "01010101 00000000 00110011 11111111", LCT_RGBA, 8); colorConvertTest("01010101 00000000 00110011 10101010", LCT_RGBA, 8, "01010101 00000000 00110011 10101010", LCT_RGBA, 8); colorConvertTest("10101010 01010101 11111111 00000000 11001100 00110011", LCT_RGB, 16, "10101010 11111111 11001100 11111111", LCT_RGBA, 8); colorConvertTest("10101010 01010101 11111111 00000000 11001100 00110011 11100111 00011000", LCT_RGBA, 16, "10101010 11111111 11001100 11100111", LCT_RGBA, 8); //test color conversions to RGB8 colorConvertTest("1", LCT_GREY, 1, "11111111 11111111 11111111", LCT_RGB, 8); colorConvertTest("10", LCT_GREY, 2, "10101010 10101010 10101010", LCT_RGB, 8); colorConvertTest("1001", LCT_GREY, 4, "10011001 10011001 10011001", LCT_RGB, 8); colorConvertTest("10010101", LCT_GREY, 8, "10010101 10010101 10010101", LCT_RGB, 8); colorConvertTest("10010101 11111110", LCT_GREY_ALPHA, 8, "10010101 10010101 10010101", LCT_RGB, 8); colorConvertTest("10010101 00000001 11111110 00000001", LCT_GREY_ALPHA, 16, "10010101 10010101 10010101", LCT_RGB, 8); colorConvertTest("01010101 00000000 00110011", LCT_RGB, 8, "01010101 00000000 00110011", LCT_RGB, 8); colorConvertTest("01010101 00000000 00110011 10101010", LCT_RGBA, 8, "01010101 00000000 00110011", LCT_RGB, 8); colorConvertTest("10101010 01010101 11111111 00000000 11001100 00110011", LCT_RGB, 16, "10101010 11111111 11001100", LCT_RGB, 8); colorConvertTest("10101010 01010101 11111111 00000000 11001100 00110011 11100111 00011000", LCT_RGBA, 16, "10101010 11111111 11001100", LCT_RGB, 8); //test color conversions to RGBA16 colorConvertTest("1", LCT_GREY, 1, "11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111", LCT_RGBA, 16); colorConvertTest("10", LCT_GREY, 2, "10101010 10101010 10101010 10101010 10101010 10101010 11111111 11111111", LCT_RGBA, 16); //test grayscale color conversions colorConvertTest("1", LCT_GREY, 1, "11111111", LCT_GREY, 8); colorConvertTest("1", LCT_GREY, 1, "1111111111111111", LCT_GREY, 16); colorConvertTest("0", LCT_GREY, 1, "00000000", LCT_GREY, 8); colorConvertTest("0", LCT_GREY, 1, "0000000000000000", LCT_GREY, 16); colorConvertTest("11", LCT_GREY, 2, "11111111", LCT_GREY, 8); colorConvertTest("11", LCT_GREY, 2, "1111111111111111", LCT_GREY, 16); colorConvertTest("10", LCT_GREY, 2, "10101010", LCT_GREY, 8); colorConvertTest("10", LCT_GREY, 2, "1010101010101010", LCT_GREY, 16); colorConvertTest("1000", LCT_GREY, 4, "10001000", LCT_GREY, 8); colorConvertTest("1000", LCT_GREY, 4, "1000100010001000", LCT_GREY, 16); colorConvertTest("10110101", LCT_GREY, 8, "1011010110110101", LCT_GREY, 16); colorConvertTest("1011010110110101", LCT_GREY, 16, "10110101", LCT_GREY, 8); //others colorConvertTest("11111111 11111111 11111111 00000000 00000000 00000000", LCT_RGB, 8, "10", LCT_GREY, 1); colorConvertTest("11111111 11111111 11111111 11111111 11111111 11111111 00000000 00000000 00000000 00000000 00000000 00000000", LCT_RGB, 16, "10", LCT_GREY, 1); } //This tests color conversions from any color model to any color model, with any bit depth //But it tests only with colors black and white, because that are the only colors every single model supports void testColorConvert2() { std::cout << "testColorConvert2" << std::endl; struct Combo { LodePNGColorType colortype; unsigned bitdepth; }; Combo combos[15] = { { LCT_GREY, 1}, { LCT_GREY, 2}, { LCT_GREY, 4}, { LCT_GREY, 8}, { LCT_GREY, 16}, { LCT_RGB, 8}, { LCT_RGB, 16}, { LCT_PALETTE, 1}, { LCT_PALETTE, 2}, { LCT_PALETTE, 4}, { LCT_PALETTE, 8}, { LCT_GREY_ALPHA, 8}, { LCT_GREY_ALPHA, 16}, { LCT_RGBA, 8}, { LCT_RGBA, 16}, }; lodepng::State state; LodePNGColorMode& mode_in = state.info_png.color; LodePNGColorMode& mode_out = state.info_raw; LodePNGColorMode mode_8; lodepng_color_mode_init(&mode_8); for(size_t i = 0; i < 256; i++) { size_t j = i == 1 ? 255 : i; lodepng_palette_add(&mode_in, j, j, j, 255); lodepng_palette_add(&mode_out, j, j, j, 255); } for(size_t i = 0; i < 15; i++) { mode_in.colortype = combos[i].colortype; mode_in.bitdepth = combos[i].bitdepth; for(size_t j = 0; j < 15; j++) { mode_out.colortype = combos[i].colortype; mode_out.bitdepth = combos[i].bitdepth; unsigned char eight[36] = { 0,0,0,255, 255,255,255,255, 0,0,0,255, 255,255,255,255, 255,255,255,255, 0,0,0,255, 255,255,255,255, 255,255,255,255, 0,0,0,255 }; //input in RGBA8 unsigned char in[72]; //custom input color type unsigned char out[72]; //custom output color type unsigned char eight2[36]; //back in RGBA8 after all conversions to check correctness unsigned error = 0; error |= lodepng_convert(in, eight, &mode_in, &mode_8, 3, 3); if(!error) error |= lodepng_convert(out, in, &mode_out, &mode_in, 3, 3); //Test input to output type if(!error) error |= lodepng_convert(eight2, out, &mode_8, &mode_out, 3, 3); if(!error) { for(size_t k = 0; k < 36; k++) { if(eight[k] != eight2[k]) { error = 99999; break; } } } if(error) { std::cout << "Error " << error << " i: " << i << " j: " << j << " colortype i: " << combos[i].colortype << " bitdepth i: " << combos[i].bitdepth << " colortype j: " << combos[j].colortype << " bitdepth j: " << combos[j].bitdepth << std::endl; if(error != 99999) ASSERT_NO_PNG_ERROR(error); else fail(); } } } } //if compressible is true, the test will also assert that the compressed string is smaller void testCompressStringZlib(const std::string& text, bool compressible) { if(text.size() < 500) std::cout << "compress test with text: " << text << std::endl; else std::cout << "compress test with text length: " << text.size() << std::endl; std::vector in(text.size()); for(size_t i = 0; i < text.size(); i++) in[i] = (unsigned char)text[i]; unsigned char* out = 0; size_t outsize = 0; unsigned error = 0; error = lodepng_zlib_compress(&out, &outsize, in.empty() ? 0 : &in[0], in.size(), &lodepng_default_compress_settings); ASSERT_NO_PNG_ERROR(error); if(compressible) assertTrue(outsize < in.size()); unsigned char* out2 = 0; size_t outsize2 = 0; error = lodepng_zlib_decompress(&out2, &outsize2, out, outsize, &lodepng_default_decompress_settings); ASSERT_NO_PNG_ERROR(error); ASSERT_EQUALS(outsize2, in.size()); for(size_t i = 0; i < in.size(); i++) ASSERT_EQUALS(in[i], out2[i]); free(out); free(out2); } void testCompressZlib() { testCompressStringZlib("", false); testCompressStringZlib("a", false); testCompressStringZlib("aa", false); testCompressStringZlib("ababababababababababababababababababababababababababababababababababababababababababab", true); testCompressStringZlib("abaaaabaabbbaabbabbababbbbabababbbaabbbaaaabbbbabbbabbbaababbbbbaaabaabbabaaaabbbbbbab", true); testCompressStringZlib("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab", true); testCompressStringZlib("omnomnomnomnomnomnomnomnomnomnom", true); testCompressStringZlib("the quick brown fox jumps over the lazy dog. the quick brown fox jumps over the lazy dog.", true); testCompressStringZlib("abracadabra", false); testCompressStringZlib("hello hello hello hello hello hello hello hello hello hello hello?", true); testCompressStringZlib("WPgZX2D*um0H::,4/KU\"kt\"Ne\"#Qa.&# buffer; lodepng::load_file(buffer, filename); std::string f; for(size_t i = 0; i < buffer.size(); i++) f += (char)buffer[i]; testCompressStringZlib(f, false); } void testDiskPNG(const std::string& filename) { std::cout << "testDiskPNG: File " << filename << std::endl; Image image; image.colorType = LCT_RGB; image.bitDepth = 8; unsigned error = lodepng::decode(image.data, image.width, image.height, filename, image.colorType, image.bitDepth); ASSERT_NO_PNG_ERROR(error); doCodecTest(image); } std::vector strtovector(const std::string& numbers) { std::vector result; std::stringstream ss(numbers); unsigned i; while(ss >> i) result.push_back(i); return result; } void doTestHuffmanCodeLengths(const std::string& expectedstr, const std::string& counts, size_t bitlength) { std::vector expected = strtovector(expectedstr); std::vector count = strtovector(counts); std::cout << "doTestHuffmanCodeLengths: " << counts << std::endl; std::vector result(count.size()); unsigned error = lodepng_huffman_code_lengths(&result[0], &count[0], count.size(), bitlength); ASSERT_NO_PNG_ERROR_MSG(error, "errorcode"); std::stringstream ss1, ss2; for(size_t i = 0; i < count.size(); i++) { ss1 << expected[i] << " "; ss2 << result[i] << " "; } assertEquals(ss1.str(), ss2.str(), "value"); } void testHuffmanCodeLengths() { bool atleasttwo = true; //LodePNG generates at least two, instead of at least one, symbol if(atleasttwo) { doTestHuffmanCodeLengths("1 1", "0 0", 16); doTestHuffmanCodeLengths("1 1 0", "0 0 0", 16); doTestHuffmanCodeLengths("1 1", "1 0", 16); doTestHuffmanCodeLengths("1 1 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0", 16); doTestHuffmanCodeLengths("1 1 0 0 0 0 0 0 0", "1 0 0 0 0 0 0 0 0", 16); doTestHuffmanCodeLengths("1 1 0 0 0 0 0 0 0", "0 1 0 0 0 0 0 0 0", 16); doTestHuffmanCodeLengths("1 0 0 0 0 0 0 0 1", "0 0 0 0 0 0 0 0 1", 16); doTestHuffmanCodeLengths("0 0 0 0 0 0 0 1 1", "0 0 0 0 0 0 0 1 1", 16); } else { doTestHuffmanCodeLengths("1 0", "0 0", 16); doTestHuffmanCodeLengths("1 0 0", "0 0 0", 16); doTestHuffmanCodeLengths("1 0", "1 0", 16); doTestHuffmanCodeLengths("1", "1", 16); doTestHuffmanCodeLengths("1", "0", 16); } doTestHuffmanCodeLengths("1 1", "1 1", 16); doTestHuffmanCodeLengths("1 1", "1 100", 16); doTestHuffmanCodeLengths("2 2 1", "1 2 3", 16); doTestHuffmanCodeLengths("2 1 2", "2 3 1", 16); doTestHuffmanCodeLengths("1 2 2", "3 1 2", 16); doTestHuffmanCodeLengths("3 3 2 1", "1 30 31 32", 16); doTestHuffmanCodeLengths("2 2 2 2", "1 30 31 32", 2); doTestHuffmanCodeLengths("5 5 4 4 4 3 3 1", "1 2 3 4 5 6 7 500", 16); } /* Create a PNG image with all known chunks (except only one of tEXt or zTXt) plus unknown chunks, and a palette. */ void createComplexPNG(std::vector& png) { unsigned w = 16, h = 17; std::vector image(w * h); for(size_t i = 0; i < w * h; i++) { image[i] = i % 256; } lodepng::State state; LodePNGInfo& info = state.info_png; info.color.colortype = LCT_PALETTE; info.color.bitdepth = 8; state.info_raw.colortype = LCT_PALETTE; state.info_raw.bitdepth = 8; state.encoder.auto_convert = false; state.encoder.text_compression = 1; state.encoder.add_id = 1; for(size_t i = 0; i < 256; i++) { lodepng_palette_add(&info.color, i, i, i, i); lodepng_palette_add(&state.info_raw, i, i, i, i); } info.background_defined = 1; info.background_r = 127; lodepng_add_text(&info, "key0", "string0"); lodepng_add_text(&info, "key1", "string1"); lodepng_add_itext(&info, "ikey0", "ilangtag0", "itranskey0", "istring0"); lodepng_add_itext(&info, "ikey1", "ilangtag1", "itranskey1", "istring1"); info.time_defined = 1; info.time.year = 2012; info.time.month = 1; info.time.day = 2; info.time.hour = 3; info.time.minute = 4; info.time.second = 5; info.phys_defined = 1; info.phys_x = 1; info.phys_y = 2; info.phys_unit = 1; lodepng_chunk_create(&info.unknown_chunks_data[0], &info.unknown_chunks_size[0], 3, "uNKa", (unsigned char*)"a00"); lodepng_chunk_create(&info.unknown_chunks_data[0], &info.unknown_chunks_size[0], 3, "uNKa", (unsigned char*)"a01"); lodepng_chunk_create(&info.unknown_chunks_data[1], &info.unknown_chunks_size[1], 3, "uNKb", (unsigned char*)"b00"); lodepng_chunk_create(&info.unknown_chunks_data[2], &info.unknown_chunks_size[2], 3, "uNKc", (unsigned char*)"c00"); unsigned error = lodepng::encode(png, &image[0], w, h, state); ASSERT_NO_PNG_ERROR(error); } std::string extractChunkNames(const std::vector& png) { const unsigned char* chunk = &png[8]; const unsigned char* end = &png.back() + 1; char name[5]; std::string result = ""; for(;;) { lodepng_chunk_type(name, chunk); result += (std::string(" ") + name); if(std::string(name) == "IEND") break; chunk = lodepng_chunk_next_const(chunk, end); assertTrue(chunk < &png.back(), "jumped out of chunks"); } return result; } void testComplexPNG() { std::cout << "testComplexPNG" << std::endl; std::vector png; createComplexPNG(png); { lodepng::State state; LodePNGInfo& info = state.info_png; unsigned w, h; std::vector image; unsigned error = lodepng::decode(image, w, h, state, &png[0], png.size()); ASSERT_NO_PNG_ERROR(error); ASSERT_EQUALS(16, w); ASSERT_EQUALS(17, h); ASSERT_EQUALS(1, info.background_defined); ASSERT_EQUALS(127, info.background_r); ASSERT_EQUALS(1, info.time_defined); ASSERT_EQUALS(2012, info.time.year); ASSERT_EQUALS(1, info.time.month); ASSERT_EQUALS(2, info.time.day); ASSERT_EQUALS(3, info.time.hour); ASSERT_EQUALS(4, info.time.minute); ASSERT_EQUALS(5, info.time.second); ASSERT_EQUALS(1, info.phys_defined); ASSERT_EQUALS(1, info.phys_x); ASSERT_EQUALS(2, info.phys_y); ASSERT_EQUALS(1, info.phys_unit); std::string chunknames = extractChunkNames(png); //std::string expectednames = " IHDR uNKa uNKa PLTE tRNS bKGD pHYs uNKb IDAT tIME tEXt tEXt tEXt iTXt iTXt uNKc IEND"; std::string expectednames = " IHDR uNKa uNKa PLTE tRNS bKGD pHYs uNKb IDAT tIME zTXt zTXt tEXt iTXt iTXt uNKc IEND"; ASSERT_EQUALS(expectednames, chunknames); ASSERT_EQUALS(3, info.text_num); ASSERT_STRING_EQUALS("key0", info.text_keys[0]); ASSERT_STRING_EQUALS("string0", info.text_strings[0]); ASSERT_STRING_EQUALS("key1", info.text_keys[1]); ASSERT_STRING_EQUALS("string1", info.text_strings[1]); ASSERT_STRING_EQUALS("LodePNG", info.text_keys[2]); ASSERT_STRING_EQUALS(LODEPNG_VERSION_STRING, info.text_strings[2]); ASSERT_EQUALS(2, info.itext_num); ASSERT_STRING_EQUALS("ikey0", info.itext_keys[0]); ASSERT_STRING_EQUALS("ilangtag0", info.itext_langtags[0]); ASSERT_STRING_EQUALS("itranskey0", info.itext_transkeys[0]); ASSERT_STRING_EQUALS("istring0", info.itext_strings[0]); ASSERT_STRING_EQUALS("ikey1", info.itext_keys[1]); ASSERT_STRING_EQUALS("ilangtag1", info.itext_langtags[1]); ASSERT_STRING_EQUALS("itranskey1", info.itext_transkeys[1]); ASSERT_STRING_EQUALS("istring1", info.itext_strings[1]); // TODO: test if unknown chunks listed too } // Test that if read_text_chunks is disabled, we do not get the texts { lodepng::State state; state.decoder.read_text_chunks = 0; unsigned w, h; std::vector image; unsigned error = lodepng::decode(image, w, h, state, &png[0], png.size()); ASSERT_NO_PNG_ERROR(error); ASSERT_EQUALS(0, state.info_png.text_num); ASSERT_EQUALS(0, state.info_png.itext_num); // But we should still get other values. ASSERT_EQUALS(2012, state.info_png.time.year); } } // Tests lodepng_inspect_chunk, and also lodepng_chunk_find to find the chunk to inspect void testInspectChunk() { std::cout << "testInspectChunk" << std::endl; std::vector png; createComplexPNG(png); const unsigned char* chunk; lodepng::State state; LodePNGInfo& info = state.info_png; state.decoder.read_text_chunks = 0; lodepng_inspect(0, 0, &state, png.data(), png.size()); chunk = lodepng_chunk_find(png.data(), png.data() + png.size(), "tIME"); ASSERT_NOT_EQUALS((const unsigned char*)0, chunk); // should be non-null, since it should find it ASSERT_EQUALS(0, info.time_defined); lodepng_inspect_chunk(&state, (size_t)(chunk - png.data()), png.data(), png.size()); ASSERT_EQUALS(1, info.time_defined); ASSERT_EQUALS(2012, state.info_png.time.year); ASSERT_EQUALS(1, info.time.month); ASSERT_EQUALS(2, info.time.day); ASSERT_EQUALS(3, info.time.hour); ASSERT_EQUALS(4, info.time.minute); ASSERT_EQUALS(5, info.time.second); ASSERT_EQUALS(0, info.text_num); chunk = lodepng_chunk_find_const(png.data(), png.data() + png.size(), "zTXt"); lodepng_inspect_chunk(&state, (size_t)(chunk - png.data()), png.data(), png.size()); ASSERT_EQUALS(1, info.text_num); chunk = lodepng_chunk_find_const(chunk, png.data() + png.size(), "zTXt"); lodepng_inspect_chunk(&state, (size_t)(chunk - png.data()), png.data(), png.size()); ASSERT_EQUALS(2, info.text_num); } //test that, by default, it chooses filter type zero for all scanlines if the image has a palette void testPaletteFilterTypesZero() { std::cout << "testPaletteFilterTypesZero" << std::endl; std::vector png; createComplexPNG(png); std::vector filterTypes; lodepng::getFilterTypes(filterTypes, png); ASSERT_EQUALS(17, filterTypes.size()); for(size_t i = 0; i < 17; i++) ASSERT_EQUALS(0, filterTypes[i]); } //tests that there are no crashes with auto color chooser in case of palettes with translucency etc... void testPaletteToPaletteConvert() { std::cout << "testPaletteToPaletteConvert" << std::endl; unsigned error; unsigned w = 16, h = 16; std::vector image(w * h); for(size_t i = 0; i < w * h; i++) image[i] = i % 256; lodepng::State state; LodePNGInfo& info = state.info_png; info.color.colortype = state.info_raw.colortype = LCT_PALETTE; info.color.bitdepth = state.info_raw.bitdepth = 8; ASSERT_EQUALS(true, state.encoder.auto_convert); for(size_t i = 0; i < 256; i++) { lodepng_palette_add(&info.color, i, i, i, i); } std::vector png; for(size_t i = 0; i < 256; i++) { lodepng_palette_add(&state.info_raw, i, i, i, i); } error = lodepng::encode(png, &image[0], w, h, state); ASSERT_NO_PNG_ERROR(error); } //for this test, you have to choose palette colors that cause LodePNG to actually use a palette, //so don't use all grayscale colors for example void doRGBAToPaletteTest(unsigned char* palette, size_t size, LodePNGColorType expectedType = LCT_PALETTE) { std::cout << "testRGBToPaletteConvert " << size << std::endl; unsigned error; unsigned w = size, h = 257 /*LodePNG encodes no palette if image is too small*/; std::vector image(w * h * 4); for(size_t i = 0; i < image.size(); i++) image[i] = palette[i % (size * 4)]; std::vector png; error = lodepng::encode(png, &image[0], w, h); ASSERT_NO_PNG_ERROR(error); lodepng::State state; std::vector image2; error = lodepng::decode(image2, w, h, state, png); ASSERT_NO_PNG_ERROR(error); ASSERT_EQUALS(image.size(), image2.size()); for(size_t i = 0; i < image.size(); i++) ASSERT_EQUALS(image[i], image2[i]); ASSERT_EQUALS(expectedType, state.info_png.color.colortype); if(expectedType == LCT_PALETTE) { ASSERT_EQUALS(size, state.info_png.color.palettesize); for(size_t i = 0; i < size * 4; i++) ASSERT_EQUALS(state.info_png.color.palette[i], image[i]); } } void testRGBToPaletteConvert() { unsigned char palette1[4] = {1,2,3,4}; doRGBAToPaletteTest(palette1, 1); unsigned char palette2[8] = {1,2,3,4, 5,6,7,8}; doRGBAToPaletteTest(palette2, 2); unsigned char palette3[12] = {1,1,1,255, 20,20,20,255, 20,20,21,255}; doRGBAToPaletteTest(palette3, 3); std::vector palette; for(int i = 0; i < 256; i++) { palette.push_back(i); palette.push_back(5); palette.push_back(6); palette.push_back(128); } doRGBAToPaletteTest(&palette[0], 256); palette.push_back(5); palette.push_back(6); palette.push_back(7); palette.push_back(8); doRGBAToPaletteTest(&palette[0], 257, LCT_RGBA); } void testColorKeyConvert() { std::cout << "testColorKeyConvert" << std::endl; unsigned error; unsigned w = 32, h = 32; std::vector image(w * h * 4); for(size_t i = 0; i < w * h; i++) { image[i * 4 + 0] = i % 256; image[i * 4 + 1] = i / 256; image[i * 4 + 2] = 0; image[i * 4 + 3] = i == 23 ? 0 : 255; } std::vector png; error = lodepng::encode(png, &image[0], w, h); ASSERT_NO_PNG_ERROR(error); lodepng::State state; std::vector image2; error = lodepng::decode(image2, w, h, state, png); ASSERT_NO_PNG_ERROR(error); ASSERT_EQUALS(32, w); ASSERT_EQUALS(32, h); ASSERT_EQUALS(1, state.info_png.color.key_defined); ASSERT_EQUALS(23, state.info_png.color.key_r); ASSERT_EQUALS(0, state.info_png.color.key_g); ASSERT_EQUALS(0, state.info_png.color.key_b); ASSERT_EQUALS(image.size(), image2.size()); for(size_t i = 0; i < image.size(); i++) { ASSERT_EQUALS(image[i], image2[i]); } } void testNoAutoConvert() { std::cout << "testNoAutoConvert" << std::endl; unsigned error; unsigned w = 32, h = 32; std::vector image(w * h * 4); for(size_t i = 0; i < w * h; i++) { image[i * 4 + 0] = (i % 2) ? 255 : 0; image[i * 4 + 1] = (i % 2) ? 255 : 0; image[i * 4 + 2] = (i % 2) ? 255 : 0; image[i * 4 + 3] = 0; } std::vector png; lodepng::State state; state.info_png.color.colortype = LCT_RGBA; state.info_png.color.bitdepth = 8; state.encoder.auto_convert = false; error = lodepng::encode(png, &image[0], w, h, state); ASSERT_NO_PNG_ERROR(error); lodepng::State state2; std::vector image2; error = lodepng::decode(image2, w, h, state2, png); ASSERT_NO_PNG_ERROR(error); ASSERT_EQUALS(32, w); ASSERT_EQUALS(32, h); ASSERT_EQUALS(LCT_RGBA, state2.info_png.color.colortype); ASSERT_EQUALS(8, state2.info_png.color.bitdepth); ASSERT_EQUALS(image.size(), image2.size()); for(size_t i = 0; i < image.size(); i++) { ASSERT_EQUALS(image[i], image2[i]); } } unsigned char flipBit(unsigned char c, int bitpos) { return c ^ (1 << bitpos); } //Test various broken inputs. Returned errors are not checked, what is tested is //that is doesn't crash, and, when run with valgrind, no memory warnings are //given. void testFuzzing() { std::cout << "testFuzzing" << std::endl; std::vector png; createComplexPNG(png); std::vector broken = png; std::vector result; std::map errors; unsigned w, h; lodepng::State state; state.decoder.ignore_crc = 1; state.decoder.zlibsettings.ignore_adler32 = 1; for(size_t i = 0; i < png.size(); i++) { result.clear(); broken[i] = ~png[i]; errors[lodepng::decode(result, w, h, state, broken)]++; broken[i] = 0; errors[lodepng::decode(result, w, h, state, broken)]++; for(int j = 0; j < 8; j++) { broken[i] = flipBit(png[i], j); errors[lodepng::decode(result, w, h, state, broken)]++; } broken[i] = 255; errors[lodepng::decode(result, w, h, state, broken)]++; broken[i] = png[i]; //fix it again for the next test } std::cout << "testFuzzing shrinking" << std::endl; broken = png; while(broken.size() > 0) { broken.resize(broken.size() - 1); errors[lodepng::decode(result, w, h, state, broken)]++; } //For fun, print the number of each error std::cout << "Fuzzing error code counts: "; for(std::map::iterator it = errors.begin(); it != errors.end(); ++it) { std::cout << it->first << ":" << it->second << ", "; } std::cout << std::endl; } int custom_proof = 0; // global variable for nested function to call. Of course when this test is switched to modern C++ we can use a lamba instead. void testCustomZlibCompress() { std::cout << "testCustomZlibCompress" << std::endl; Image image; generateTestImage(image, 5, 5, LCT_RGBA, 8); std::vector encoded; int customcontext = 5; struct TestFun { static unsigned custom_zlib(unsigned char**, size_t*, const unsigned char*, size_t, const LodePNGCompressSettings* settings) { ASSERT_EQUALS(5, *(int*)(settings->custom_context)); custom_proof = 1; return 5555; // return a custom error code, which will be converted to an error known to lodepng. } }; lodepng::State state; state.encoder.zlibsettings.custom_zlib = TestFun::custom_zlib; state.encoder.zlibsettings.custom_context = &customcontext; custom_proof = 0; unsigned error = lodepng::encode(encoded, image.data, image.width, image.height, state); ASSERT_EQUALS(1, custom_proof); // check that the custom zlib was called ASSERT_EQUALS(111, error); // expect a known lodepng error, not the custom 5555 } void testCustomZlibCompress2() { std::cout << "testCustomZlibCompress2" << std::endl; Image image; generateTestImage(image, 5, 5, LCT_RGBA, 8); std::vector encoded; lodepng::State state; state.encoder.zlibsettings.custom_zlib = lodepng_zlib_compress; unsigned error = lodepng::encode(encoded, image.data, image.width, image.height, state); ASSERT_NO_PNG_ERROR(error); std::vector decoded; unsigned w, h; state.decoder.zlibsettings.ignore_adler32 = 0; state.decoder.ignore_crc = 0; error = lodepng::decode(decoded, w, h, state, encoded); ASSERT_NO_PNG_ERROR(error); ASSERT_EQUALS(5, w); ASSERT_EQUALS(5, h); } void testCustomDeflate() { std::cout << "testCustomDeflate" << std::endl; Image image; generateTestImage(image, 5, 5, LCT_RGBA, 8); std::vector encoded; int customcontext = 5; struct TestFun { static unsigned custom_deflate(unsigned char**, size_t*, const unsigned char*, size_t, const LodePNGCompressSettings* settings) { ASSERT_EQUALS(5, *(int*)(settings->custom_context)); custom_proof = 1; return 5555; // return a custom error code, which will be converted to an error known to lodepng. } }; lodepng::State state; state.encoder.zlibsettings.custom_deflate = TestFun::custom_deflate; state.encoder.zlibsettings.custom_context = &customcontext; custom_proof = 0; unsigned error = lodepng::encode(encoded, image.data, image.width, image.height, state); ASSERT_EQUALS(1, custom_proof); // check that the custom deflate was called ASSERT_EQUALS(111, error); // expect a known lodepng error, not the custom 5555 } void testCustomZlibDecompress() { std::cout << "testCustomZlibDecompress" << std::endl; Image image; generateTestImage(image, 5, 5, LCT_RGBA, 8); std::vector encoded; unsigned error_enc = lodepng::encode(encoded, image.data, image.width, image.height, image.colorType, image.bitDepth); ASSERT_NO_PNG_ERROR_MSG(error_enc, "encoder error not expected"); std::vector decoded; unsigned w, h; int customcontext = 5; struct TestFun { static unsigned custom_zlib(unsigned char**, size_t*, const unsigned char*, size_t, const LodePNGDecompressSettings* settings) { ASSERT_EQUALS(5, *(int*)(settings->custom_context)); custom_proof = 1; return 5555; // return a custom error code, which will be converted to an error known to lodepng. } }; lodepng::State state; state.decoder.zlibsettings.custom_zlib = TestFun::custom_zlib; state.decoder.zlibsettings.custom_context = &customcontext; state.decoder.zlibsettings.ignore_adler32 = 0; state.decoder.ignore_crc = 0; custom_proof = 0; unsigned error = lodepng::decode(decoded, w, h, state, encoded); ASSERT_EQUALS(1, custom_proof); // check that the custom zlib was called ASSERT_EQUALS(110, error); } void testCustomInflate() { std::cout << "testCustomInflate" << std::endl; Image image; generateTestImage(image, 5, 5, LCT_RGBA, 8); std::vector encoded; unsigned error_enc = lodepng::encode(encoded, image.data, image.width, image.height, image.colorType, image.bitDepth); ASSERT_NO_PNG_ERROR_MSG(error_enc, "encoder error not expected"); std::vector decoded; unsigned w, h; int customcontext = 5; struct TestFun { static unsigned custom_inflate(unsigned char**, size_t*, const unsigned char*, size_t, const LodePNGDecompressSettings* settings) { ASSERT_EQUALS(5, *(int*)(settings->custom_context)); custom_proof = 1; return 5555; // return a custom error code, which will be converted to an error known to lodepng. } }; lodepng::State state; state.decoder.zlibsettings.custom_inflate = TestFun::custom_inflate; state.decoder.zlibsettings.custom_context = &customcontext; state.decoder.zlibsettings.ignore_adler32 = 0; state.decoder.ignore_crc = 0; custom_proof = 0; unsigned error = lodepng::decode(decoded, w, h, state, encoded); ASSERT_EQUALS(1, custom_proof); // check that the custom zlib was called ASSERT_EQUALS(110, error); } void testChunkUtil() { std::cout << "testChunkUtil" << std::endl; std::vector png; createComplexPNG(png); std::vector names[3]; std::vector > chunks[3]; assertNoError(lodepng::getChunks(names, chunks, png)); std::vector > chunks2[3]; chunks2[0].push_back(chunks[2][2]); //zTXt chunks2[1].push_back(chunks[2][3]); //tEXt chunks2[2].push_back(chunks[2][4]); //iTXt assertNoError(lodepng::insertChunks(png, chunks2)); std::string chunknames = extractChunkNames(png); // chunks2[0] chunks2[1] chunks2[2] // v v v std::string expectednames = " IHDR uNKa uNKa zTXt PLTE tRNS bKGD pHYs uNKb tEXt IDAT tIME zTXt zTXt tEXt iTXt iTXt uNKc iTXt IEND"; ASSERT_EQUALS(expectednames, chunknames); std::vector image; unsigned w, h; ASSERT_NO_PNG_ERROR(lodepng::decode(image, w, h, png)); } //Test that when decoding to 16-bit per channel, it always uses big endian consistently. //It should always output big endian, the convention used inside of PNG, even though x86 CPU's are little endian. void test16bitColorEndianness() { std::cout << "test16bitColorEndianness" << std::endl; //basn0g16.png from the PNG test suite std::string base64 = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAAAAAAGgflrAAAABGdBTUEAAYagMeiWXwAAAF5JREFU" "eJzV0jEKwDAMQ1E5W+9/xtygk8AoezLVKgSj2Y8/OICnuFcTE2OgOoJgHQiZAN2C9kDKBOgW3AZC" "JkC3oD2QMgG6BbeBkAnQLWgPpExgP28H7E/0GTjPfwAW2EvYX64rn9cAAAAASUVORK5CYII="; std::vector png; fromBase64(png, base64); unsigned w, h; std::vector image; lodepng::State state; // Decode from 16-bit gray image to 16-bit per channel RGBA state.info_raw.bitdepth = 16; ASSERT_NO_PNG_ERROR(lodepng::decode(image, w, h, state, png)); ASSERT_EQUALS(0x09, image[8]); ASSERT_EQUALS(0x00, image[9]); // Decode from 16-bit gray image to 16-bit gray raw image (no conversion) image.clear(); state = lodepng::State(); state.decoder.color_convert = false; ASSERT_NO_PNG_ERROR(lodepng::decode(image, w, h, state, png)); ASSERT_EQUALS(0x09, image[2]); ASSERT_EQUALS(0x00, image[3]); // Decode from 16-bit per channel RGB image to 16-bit per channel RGBA base64 = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAIAAACsiDHgAAAABGdBTUEAAYagMeiWXwAAAANzQklU" "DQ0N0DeNwQAAAH5JREFUeJztl8ENxEAIAwcJ6cpI+q8qKeNepAgelq2dCjz4AdQM1jRcf3WIDQ13" "qUNsiBBQZ1gR0cARUFIz3pug3586wo5+rOcfIaBOsCSggSOgpcB8D4D3R9DgfUyECIhDbAhp4Ajo" "KPD+CBq8P4IG72MiQkCdYUVEA0dAyQcwUyZpXH92ZwAAAABJRU5ErkJggg=="; //cs3n2c16.png png.clear(); fromBase64(png, base64); image.clear(); state = lodepng::State(); state.info_raw.bitdepth = 16; ASSERT_NO_PNG_ERROR(lodepng::decode(image, w, h, state, png)); ASSERT_EQUALS(0x1f, image[258]); ASSERT_EQUALS(0xf9, image[259]); // Decode from 16-bit per channel RGB image to 16-bit per channel RGBA raw image (no conversion) image.clear(); state = lodepng::State(); state.decoder.color_convert = false; ASSERT_NO_PNG_ERROR(lodepng::decode(image, w, h, state, png)); ASSERT_EQUALS(0x1f, image[194]); ASSERT_EQUALS(0xf9, image[195]); image.clear(); state = lodepng::State(); // Decode from palette image to 16-bit per channel RGBA base64 = "iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHAgMAAAC5PL9AAAAABGdBTUEAAYagMeiWXwAAAANzQklU" "BAQEd/i1owAAAAxQTFRF/wB3AP93//8AAAD/G0OznAAAABpJREFUeJxj+P+H4WoMw605DDfmgEgg" "+/8fAHF5CrkeXW0HAAAAAElFTkSuQmCC"; //s07n3p02.png png.clear(); fromBase64(png, base64); image.clear(); state = lodepng::State(); state.info_raw.bitdepth = 16; ASSERT_NO_PNG_ERROR(lodepng::decode(image, w, h, state, png)); ASSERT_EQUALS(0x77, image[84]); ASSERT_EQUALS(0x77, image[85]); } void testPredefinedFilters() { size_t w = 32, h = 32; std::cout << "testPredefinedFilters" << std::endl; Image image; generateTestImage(image, w, h, LCT_RGBA, 8); // everything to filter type '3' std::vector predefined(h, 3); lodepng::State state; state.encoder.filter_strategy = LFS_PREDEFINED; state.encoder.filter_palette_zero = 0; state.encoder.predefined_filters = &predefined[0]; std::vector png; unsigned error = lodepng::encode(png, &image.data[0], w, h, state); assertNoError(error); std::vector outfilters; error = lodepng::getFilterTypes(outfilters, png); assertNoError(error); ASSERT_EQUALS(outfilters.size(), h); for(size_t i = 0; i < h; i++) ASSERT_EQUALS(3, outfilters[i]); } void testEncoderErrors() { std::cout << "testEncoderErrors" << std::endl; std::vector png; unsigned w = 32, h = 32; Image image; generateTestImage(image, w, h); lodepng::State def; lodepng::State state; ASSERT_EQUALS(0, lodepng::encode(png, &image.data[0], w, h, state)); // test window sizes state.encoder.zlibsettings.windowsize = 0; ASSERT_EQUALS(60, lodepng::encode(png, &image.data[0], w, h, state)); state.encoder.zlibsettings.windowsize = 65536; ASSERT_EQUALS(60, lodepng::encode(png, &image.data[0], w, h, state)); state.encoder.zlibsettings.windowsize = 1000; // not power of two ASSERT_EQUALS(90, lodepng::encode(png, &image.data[0], w, h, state)); state.encoder.zlibsettings.windowsize = 256; ASSERT_EQUALS(0, lodepng::encode(png, &image.data[0], w, h, state)); state = def; state.info_png.color.bitdepth = 3; ASSERT_EQUALS(37, lodepng::encode(png, &image.data[0], w, h, state)); state = def; state.info_png.color.colortype = (LodePNGColorType)5; ASSERT_EQUALS(31, lodepng::encode(png, &image.data[0], w, h, state)); state = def; state.info_png.color.colortype = LCT_PALETTE; ASSERT_EQUALS(68, lodepng::encode(png, &image.data[0], w, h, state)); state = def; state.info_png.interlace_method = 0; ASSERT_EQUALS(0, lodepng::encode(png, &image.data[0], w, h, state)); state.info_png.interlace_method = 1; ASSERT_EQUALS(0, lodepng::encode(png, &image.data[0], w, h, state)); state.info_png.interlace_method = 2; ASSERT_EQUALS(71, lodepng::encode(png, &image.data[0], w, h, state)); state = def; state.encoder.zlibsettings.btype = 0; ASSERT_EQUALS(0, lodepng::encode(png, &image.data[0], w, h, state)); state.encoder.zlibsettings.btype = 1; ASSERT_EQUALS(0, lodepng::encode(png, &image.data[0], w, h, state)); state.encoder.zlibsettings.btype = 2; ASSERT_EQUALS(0, lodepng::encode(png, &image.data[0], w, h, state)); state.encoder.zlibsettings.btype = 3; ASSERT_EQUALS(61, lodepng::encode(png, &image.data[0], w, h, state)); } void addColor(std::vector& colors, unsigned char r, unsigned char g, unsigned char b, unsigned char a) { colors.push_back(r); colors.push_back(g); colors.push_back(b); colors.push_back(a); } void addColor16(std::vector& colors, unsigned short r, unsigned short g, unsigned short b, unsigned short a) { colors.push_back(r & 255); colors.push_back((r >> 8) & 255); colors.push_back(g & 255); colors.push_back((g >> 8) & 255); colors.push_back(b & 255); colors.push_back((b >> 8) & 255); colors.push_back(a & 255); colors.push_back((a >> 8) & 255); } // Tests auto_convert // colors is in RGBA, inbitdepth must be 8 or 16, the amount of bits per channel. // colortype and bitdepth are the expected values. insize is amount of pixels. So the amount of bytes is insize * 4 * (inbitdepth / 8) void testAutoColorModel(const std::vector& colors, unsigned inbitdepth, LodePNGColorType colortype, unsigned bitdepth, bool key) { std::cout << "testAutoColorModel " << inbitdepth << " " << colortype << " " << bitdepth << " " << key << std::endl; size_t innum = colors.size() / 4 * inbitdepth / 8; size_t num = innum < 65536 ? 65536 : innum; // Make image bigger so the convert doesn't avoid palette due to small image. std::vector colors2(num * 4 * (inbitdepth / 8)); for(size_t i = 0; i < colors2.size(); i++) colors2[i] = colors[i % colors.size()]; std::vector png; lodepng::encode(png, colors2, num, 1, LCT_RGBA, inbitdepth); // now extract the color type it chose unsigned w, h; lodepng::State state; std::vector decoded; lodepng::decode(decoded, w, h, state, png); ASSERT_EQUALS(num, w); ASSERT_EQUALS(1, h); ASSERT_EQUALS(colortype, state.info_png.color.colortype); ASSERT_EQUALS(bitdepth, state.info_png.color.bitdepth); ASSERT_EQUALS(key, state.info_png.color.key_defined); // also check that the PNG decoded correctly and has same colors as input if(inbitdepth == 8) { for(size_t i = 0; i < colors.size(); i++) ASSERT_EQUALS(colors[i], decoded[i]); } else { for(size_t i = 0; i < colors.size() / 2; i++) ASSERT_EQUALS(colors[i * 2], decoded[i]); } } void testAutoColorModels() { // 1-bit gray std::vector gray1; for(size_t i = 0; i < 2; i++) addColor(gray1, i * 255, i * 255, i * 255, 255); testAutoColorModel(gray1, 8, LCT_GREY, 1, false); // 2-bit gray std::vector gray2; for(size_t i = 0; i < 4; i++) addColor(gray2, i * 85, i * 85, i * 85, 255); testAutoColorModel(gray2, 8, LCT_GREY, 2, false); // 4-bit gray std::vector gray4; for(size_t i = 0; i < 16; i++) addColor(gray4, i * 17, i * 17, i * 17, 255); testAutoColorModel(gray4, 8, LCT_GREY, 4, false); // 8-bit gray std::vector gray8; for(size_t i = 0; i < 256; i++) addColor(gray8, i, i, i, 255); testAutoColorModel(gray8, 8, LCT_GREY, 8, false); // 16-bit gray std::vector gray16; for(size_t i = 0; i < 257; i++) addColor16(gray16, i, i, i, 65535); testAutoColorModel(gray16, 16, LCT_GREY, 16, false); // 8-bit gray+alpha std::vector gray8a; for(size_t i = 0; i < 17; i++) addColor(gray8a, i, i, i, i); testAutoColorModel(gray8a, 8, LCT_PALETTE, 8, false); // palette not possible, becomes gray alpha for(size_t i = 0; i < 256; i++) addColor(gray8a, i, i, i, i ^ 1); testAutoColorModel(gray8a, 8, LCT_GREY_ALPHA, 8, false); // 16-bit gray+alpha std::vector gray16a; for(size_t i = 0; i < 257; i++) addColor16(gray16a, i, i, i, i); testAutoColorModel(gray16a, 16, LCT_GREY_ALPHA, 16, false); // various palette tests std::vector palette; addColor(palette, 0, 0, 1, 255); testAutoColorModel(palette, 8, LCT_PALETTE, 1, false); addColor(palette, 0, 0, 2, 255); testAutoColorModel(palette, 8, LCT_PALETTE, 1, false); for(int i = 3; i <= 4; i++) addColor(palette, 0, 0, i, 255); testAutoColorModel(palette, 8, LCT_PALETTE, 2, false); for(int i = 5; i <= 7; i++) addColor(palette, 0, 0, i, 255); testAutoColorModel(palette, 8, LCT_PALETTE, 4, false); for(int i = 8; i <= 17; i++) addColor(palette, 0, 0, i, 255); testAutoColorModel(palette, 8, LCT_PALETTE, 8, false); addColor(palette, 0, 0, 18, 0); // transparent testAutoColorModel(palette, 8, LCT_PALETTE, 8, false); addColor(palette, 0, 0, 18, 1); // translucent testAutoColorModel(palette, 8, LCT_PALETTE, 8, false); // 1-bit gray + alpha not possible, becomes palette std::vector gray1a; for(size_t i = 0; i < 2; i++) addColor(gray1a, i, i, i, 128); testAutoColorModel(gray1a, 8, LCT_PALETTE, 1, false); // 2-bit gray + alpha not possible, becomes palette std::vector gray2a; for(size_t i = 0; i < 4; i++) addColor(gray2a, i, i, i, 128); testAutoColorModel(gray2a, 8, LCT_PALETTE, 2, false); // 4-bit gray + alpha not possible, becomes palette std::vector gray4a; for(size_t i = 0; i < 16; i++) addColor(gray4a, i, i, i, 128); testAutoColorModel(gray4a, 8, LCT_PALETTE, 4, false); // 8-bit rgb std::vector rgb = gray8; addColor(rgb, 255, 0, 0, 255); testAutoColorModel(rgb, 8, LCT_RGB, 8, false); // 8-bit rgb + key std::vector rgb_key = rgb; addColor(rgb_key, 128, 0, 0, 0); testAutoColorModel(rgb_key, 8, LCT_RGB, 8, true); // 8-bit rgb, not key due to edge case: single key color, but opaque color has same RGB value std::vector rgb_key2 = rgb_key; addColor(rgb_key2, 128, 0, 0, 255); // same color but opaque ==> no more key testAutoColorModel(rgb_key2, 8, LCT_RGBA, 8, false); // 8-bit rgb, not key due to semi translucent std::vector rgb_key3 = rgb_key; addColor(rgb_key3, 128, 0, 0, 255); // semi-translucent ==> no more key testAutoColorModel(rgb_key3, 8, LCT_RGBA, 8, false); // 8-bit rgb, not key due to multiple transparent colors std::vector rgb_key4 = rgb_key; addColor(rgb_key4, 128, 0, 0, 255); addColor(rgb_key4, 129, 0, 0, 255); // two different transparent colors ==> no more key testAutoColorModel(rgb_key4, 8, LCT_RGBA, 8, false); // 1-bit gray with key std::vector gray1_key = gray1; gray1_key[7] = 0; testAutoColorModel(gray1_key, 8, LCT_GREY, 1, true); // 2-bit gray with key std::vector gray2_key = gray2; gray2_key[7] = 0; testAutoColorModel(gray2_key, 8, LCT_GREY, 2, true); // 4-bit gray with key std::vector gray4_key = gray4; gray4_key[7] = 0; testAutoColorModel(gray4_key, 8, LCT_GREY, 4, true); // 8-bit gray with key std::vector gray8_key = gray8; gray8_key[7] = 0; testAutoColorModel(gray8_key, 8, LCT_GREY, 8, true); // 16-bit gray with key std::vector gray16_key = gray16; gray16_key[14] = gray16_key[15] = 0; testAutoColorModel(gray16_key, 16, LCT_GREY, 16, true); // a single 16-bit color, can't become palette due to being 16-bit std::vector small16; addColor16(small16, 1, 0, 0, 65535); testAutoColorModel(small16, 16, LCT_RGB, 16, false); std::vector small16a; addColor16(small16a, 1, 0, 0, 1); testAutoColorModel(small16a, 16, LCT_RGBA, 16, false); // what we provide as 16-bit is actually representable as 8-bit, so 8-bit palette expected for single color std::vector not16; addColor16(not16, 257, 257, 257, 0); testAutoColorModel(not16, 16, LCT_PALETTE, 1, false); // the rgb color is representable as 8-bit, but the alpha channel only as 16-bit, so ensure it uses 16-bit and not palette for this single color std::vector alpha16; addColor16(alpha16, 257, 0, 0, 10000); testAutoColorModel(alpha16, 16, LCT_RGBA, 16, false); // 1-bit gray, with attempt to get color key but can't do it due to opaque color with same value std::vector gray1k; addColor(gray1k, 0, 0, 0, 255); addColor(gray1k, 255, 255, 255, 255); addColor(gray1k, 255, 255, 255, 0); testAutoColorModel(gray1k, 8, LCT_PALETTE, 2, false); } void testPaletteToPaletteDecode() { std::cout << "testPaletteToPaletteDecode" << std::endl; // It's a bit big for a 2x2 image... but this tests needs one with 256 palette entries in it. std::string base64 = "iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAMAAABFaP0WAAAAA3NCSVQICAjb4U/gAAADAFBMVEUA" "AAAAADMAAGYAAJkAAMwAAP8AMwAAMzMAM2YAM5kAM8wAM/8AZgAAZjMAZmYAZpkAZswAZv8AmQAA" "mTMAmWYAmZkAmcwAmf8AzAAAzDMAzGYAzJkAzMwAzP8A/wAA/zMA/2YA/5kA/8wA//8zAAAzADMz" "AGYzAJkzAMwzAP8zMwAzMzMzM2YzM5kzM8wzM/8zZgAzZjMzZmYzZpkzZswzZv8zmQAzmTMzmWYz" "mZkzmcwzmf8zzAAzzDMzzGYzzJkzzMwzzP8z/wAz/zMz/2Yz/5kz/8wz//9mAABmADNmAGZmAJlm" "AMxmAP9mMwBmMzNmM2ZmM5lmM8xmM/9mZgBmZjNmZmZmZplmZsxmZv9mmQBmmTNmmWZmmZlmmcxm" "mf9mzABmzDNmzGZmzJlmzMxmzP9m/wBm/zNm/2Zm/5lm/8xm//+ZAACZADOZAGaZAJmZAMyZAP+Z" "MwCZMzOZM2aZM5mZM8yZM/+ZZgCZZjOZZmaZZpmZZsyZZv+ZmQCZmTOZmWaZmZmZmcyZmf+ZzACZ" "zDOZzGaZzJmZzMyZzP+Z/wCZ/zOZ/2aZ/5mZ/8yZ///MAADMADPMAGbMAJnMAMzMAP/MMwDMMzPM" "M2bMM5nMM8zMM//MZgDMZjPMZmbMZpnMZszMZv/MmQDMmTPMmWbMmZnMmczMmf/MzADMzDPMzGbM" "zJnMzMzMzP/M/wDM/zPM/2bM/5nM/8zM////AAD/ADP/AGb/AJn/AMz/AP//MwD/MzP/M2b/M5n/" "M8z/M///ZgD/ZjP/Zmb/Zpn/Zsz/Zv//mQD/mTP/mWb/mZn/mcz/mf//zAD/zDP/zGb/zJn/zMz/" "zP///wD//zP//2b//5n//8z///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABlenwdAAABAHRSTlP/////////////////////////" "////////////////////////////////////////////////////////////////////////////" "////////////////////////////////////////////////////////////////////////////" "////////////////////////////////////////////////////////////////////////////" "//////////////////////////////////8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAG8mZagAAAAlwSFlzAAAOTQAADpwB3vacVwAAAA5JREFUCJlj2CLHwHodAATjAa+k" "lTE5AAAAAElFTkSuQmCC"; std::vector png; fromBase64(png, base64); std::vector image; unsigned width, height; unsigned error = lodepng::decode(image, width, height, png, LCT_PALETTE, 8); ASSERT_EQUALS(0, error); ASSERT_EQUALS(2, width); ASSERT_EQUALS(2, height); ASSERT_EQUALS(180, image[0]); ASSERT_EQUALS(30, image[1]); ASSERT_EQUALS(5, image[2]); ASSERT_EQUALS(215, image[3]); } //2-bit palette void testPaletteToPaletteDecode2() { std::cout << "testPaletteToPaletteDecode2" << std::endl; std::string base64 = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAgMAAAAOFJJnAAAADFBMVEX/AAAA/wAAAP/////7AGD2AAAAE0lEQVR4AWMQhAKG3VCALDIqAgDl2WYBCQHY9gAAAABJRU5ErkJggg=="; std::vector png; fromBase64(png, base64); std::vector image; unsigned width, height; unsigned error = lodepng::decode(image, width, height, png, LCT_PALETTE, 8); ASSERT_EQUALS(0, error); ASSERT_EQUALS(32, width); ASSERT_EQUALS(32, height); ASSERT_EQUALS(0, image[0]); ASSERT_EQUALS(1, image[1]); //Now add a user-specified output palette, that differs from the input palette. That should give error 82. LodePNGState state; lodepng_state_init(&state); state.info_raw.colortype = LCT_PALETTE; state.info_raw.bitdepth = 8; lodepng_palette_add(&state.info_raw, 0, 0, 0, 255); lodepng_palette_add(&state.info_raw, 1, 1, 1, 255); lodepng_palette_add(&state.info_raw, 2, 2, 2, 255); lodepng_palette_add(&state.info_raw, 3, 3, 3, 255); unsigned char* image2 = 0; unsigned error2 = lodepng_decode(&image2, &width, &height, &state, &png[0], png.size()); lodepng_state_cleanup(&state); ASSERT_EQUALS(82, error2); free(image2); } void assertColorProfileDataEqual(const lodepng::State& a, const lodepng::State& b) { ASSERT_EQUALS(a.info_png.gama_defined, b.info_png.gama_defined); if(a.info_png.gama_defined) { ASSERT_EQUALS(a.info_png.gama_gamma, b.info_png.gama_gamma); } ASSERT_EQUALS(a.info_png.chrm_defined, b.info_png.chrm_defined); if(a.info_png.chrm_defined) { ASSERT_EQUALS(a.info_png.chrm_white_x, b.info_png.chrm_white_x); ASSERT_EQUALS(a.info_png.chrm_white_y, b.info_png.chrm_white_y); ASSERT_EQUALS(a.info_png.chrm_red_x, b.info_png.chrm_red_x); ASSERT_EQUALS(a.info_png.chrm_red_y, b.info_png.chrm_red_y); ASSERT_EQUALS(a.info_png.chrm_green_x, b.info_png.chrm_green_x); ASSERT_EQUALS(a.info_png.chrm_green_y, b.info_png.chrm_green_y); ASSERT_EQUALS(a.info_png.chrm_blue_x, b.info_png.chrm_blue_x); ASSERT_EQUALS(a.info_png.chrm_blue_y, b.info_png.chrm_blue_y); } ASSERT_EQUALS(a.info_png.srgb_defined, b.info_png.srgb_defined); if(a.info_png.srgb_defined) { ASSERT_EQUALS(a.info_png.srgb_intent, b.info_png.srgb_intent); } ASSERT_EQUALS(a.info_png.iccp_defined, b.info_png.iccp_defined); if(a.info_png.iccp_defined) { //ASSERT_EQUALS(std::string(a.info_png.iccp_name), std::string(b.info_png.iccp_name)); ASSERT_EQUALS(a.info_png.iccp_profile_size, b.info_png.iccp_profile_size); for(size_t i = 0; i < a.info_png.iccp_profile_size; ++i) { ASSERT_EQUALS(a.info_png.iccp_profile[i], b.info_png.iccp_profile[i]); } } } // Tests the gAMA, cHRM, sRGB, iCCP chunks void testColorProfile() { std::cout << "testColorProfile" << std::endl; { unsigned error; unsigned w = 32, h = 32; std::vector image(w * h * 4); for(size_t i = 0; i < image.size(); i++) image[i] = i & 255; std::vector png; lodepng::State state; state.info_png.gama_defined = 1; state.info_png.gama_gamma = 12345; state.info_png.chrm_defined = 1; state.info_png.chrm_white_x = 10; state.info_png.chrm_white_y = 20; state.info_png.chrm_red_x = 30; state.info_png.chrm_red_y = 40; state.info_png.chrm_green_x = 100000; state.info_png.chrm_green_y = 200000; state.info_png.chrm_blue_x = 300000; state.info_png.chrm_blue_y = 400000; error = lodepng::encode(png, &image[0], w, h, state); ASSERT_NO_PNG_ERROR(error); lodepng::State state2; std::vector image2; error = lodepng::decode(image2, w, h, state2, png); ASSERT_NO_PNG_ERROR(error); assertColorProfileDataEqual(state, state2); ASSERT_EQUALS(32, w); ASSERT_EQUALS(32, h); ASSERT_EQUALS(image.size(), image2.size()); for(size_t i = 0; i < image.size(); i++) ASSERT_EQUALS(image[i], image2[i]); } { unsigned error; unsigned w = 32, h = 32; std::vector image(w * h * 4); for(size_t i = 0; i < image.size(); i++) image[i] = i & 255; std::vector png; lodepng::State state; state.info_png.srgb_defined = 1; state.info_png.srgb_intent = 2; error = lodepng::encode(png, &image[0], w, h, state); ASSERT_NO_PNG_ERROR(error); lodepng::State state2; std::vector image2; error = lodepng::decode(image2, w, h, state2, png); ASSERT_NO_PNG_ERROR(error); assertColorProfileDataEqual(state, state2); ASSERT_EQUALS(32, w); ASSERT_EQUALS(32, h); ASSERT_EQUALS(image.size(), image2.size()); for(size_t i = 0; i < image.size(); i++) ASSERT_EQUALS(image[i], image2[i]); } { unsigned error; unsigned w = 32, h = 32; std::vector image(w * h * 4); for(size_t i = 0; i < image.size(); i++) image[i] = i & 255; std::vector png; lodepng::State state; state.info_png.iccp_defined = 1; std::string testprofile = "0123456789abcdefRGB fake iccp profile for testing"; testprofile[0] = testprofile[1] = 0; lodepng_set_icc(&state.info_png, "test", (const unsigned char*)testprofile.c_str(), testprofile.size()); error = lodepng::encode(png, &image[0], w, h, state); ASSERT_NO_PNG_ERROR(error); lodepng::State state2; std::vector image2; error = lodepng::decode(image2, w, h, state2, png); ASSERT_NO_PNG_ERROR(error); assertColorProfileDataEqual(state, state2); ASSERT_EQUALS(32, w); ASSERT_EQUALS(32, h); ASSERT_EQUALS(image.size(), image2.size()); for(size_t i = 0; i < image.size(); i++) ASSERT_EQUALS(image[i], image2[i]); } // grayscale ICC profile { unsigned error; unsigned w = 32, h = 32; std::vector image(w * h * 4); for(size_t i = 0; i + 4 <= image.size(); i += 4) { image[i] = image[i + 1] = image[i + 2] = image[i + 3] = i; } std::vector png; lodepng::State state; state.info_png.iccp_defined = 1; std::string testprofile = "0123456789abcdefGRAYfake iccp profile for testing"; testprofile[0] = testprofile[1] = 0; lodepng_set_icc(&state.info_png, "test", (const unsigned char*)testprofile.c_str(), testprofile.size()); error = lodepng::encode(png, &image[0], w, h, state); ASSERT_NO_PNG_ERROR(error); lodepng::State state2; std::vector image2; error = lodepng::decode(image2, w, h, state2, png); ASSERT_NO_PNG_ERROR(error); assertColorProfileDataEqual(state, state2); ASSERT_EQUALS(32, w); ASSERT_EQUALS(32, h); ASSERT_EQUALS(image.size(), image2.size()); for(size_t i = 0; i < image.size(); i++) ASSERT_EQUALS(image[i], image2[i]); } // grayscale ICC profile, using an input image with grayscale colors but that // would normally benefit from a palette (which auto_convert would normally // choose). But the PNG spec does not allow combining palette with GRAY ICC // profile, so the encoder should not choose to use palette after all. { unsigned error; unsigned w = 32, h = 32; std::vector image(w * h * 4); int colors[3] = {0, 3, 133}; for(size_t i = 0; i + 4 <= image.size(); i += 4) { image[i] = image[i + 1] = image[i + 2] = image[i + 3] = colors[(i / 4) % 3]; } std::vector png; lodepng::State state; state.info_png.iccp_defined = 1; std::string testprofile = "0123456789abcdefGRAYfake iccp profile for testing"; testprofile[0] = testprofile[1] = 0; lodepng_set_icc(&state.info_png, "test", (const unsigned char*)testprofile.c_str(), testprofile.size()); error = lodepng::encode(png, &image[0], w, h, state); ASSERT_NO_PNG_ERROR(error); lodepng::State state2; std::vector image2; error = lodepng::decode(image2, w, h, state2, png); ASSERT_NO_PNG_ERROR(error); assertColorProfileDataEqual(state, state2); ASSERT_NOT_EQUALS(LCT_PALETTE, state2.info_png.color.colortype); } // RGB ICC profile, using an input image with grayscale colors: the encoder // is forced to choose an RGB color type anyway with auto_convert { unsigned error; unsigned w = 32, h = 32; std::vector image(w * h * 4); for(size_t i = 0; i + 4 <= image.size(); i += 4) { image[i] = image[i + 1] = image[i + 2] = (i / 4) & 255; image[i + 3] = 255; } std::vector png; lodepng::State state; state.info_png.iccp_defined = 1; std::string testprofile = "0123456789abcdefRGB fake iccp profile for testing"; testprofile[0] = testprofile[1] = 0; lodepng_set_icc(&state.info_png, "test", (const unsigned char*)testprofile.c_str(), testprofile.size()); error = lodepng::encode(png, &image[0], w, h, state); ASSERT_NO_PNG_ERROR(error); lodepng::State state2; std::vector image2; error = lodepng::decode(image2, w, h, state2, png); ASSERT_NO_PNG_ERROR(error); assertColorProfileDataEqual(state, state2); // LCT_RGB or LCT_PALETTE are both ok, gray is not (it likely chooses palette in practice) ASSERT_NOT_EQUALS(LCT_GREY, state2.info_png.color.colortype); ASSERT_NOT_EQUALS(LCT_GREY_ALPHA, state2.info_png.color.colortype); } // Encoder must give error when forcing invalid combination of color/gray // PNG with gray/color ICC Profile { unsigned error; unsigned w = 32, h = 32; std::vector image(w * h * 4); int colors[3] = {0, 5, 33}; for(size_t i = 0; i + 4 <= image.size(); i += 4) { image[i] = 255; image[i + 1] = image[i + 2] = image[i + 3] = colors[(i / 4) % 3]; } std::vector png; lodepng::State state; state.info_png.iccp_defined = 1; std::string testprofile = "0123456789abcdefGRAYfake iccp profile for testing"; testprofile[0] = testprofile[1] = 0; lodepng_set_icc(&state.info_png, "test", (const unsigned char*)testprofile.c_str(), testprofile.size()); error = lodepng::encode(png, &image[0], w, h, state); ASSERT_NOT_EQUALS(0, error); // must give error due to color image input with gray profile } } // r, g, b is input background color to encoder, given in png color model // r2, g2, b2 is expected decoded background color, in color model it auto chose if auto_convert is on // pixels must be given in mode_raw color format void testBkgdChunk(unsigned r, unsigned g, unsigned b, unsigned r2, unsigned g2, unsigned b2, const std::vector& pixels, unsigned w, unsigned h, const LodePNGColorMode& mode_raw, const LodePNGColorMode& mode_png, bool auto_convert, bool expect_encoder_error = false) { unsigned error; lodepng::State state; LodePNGInfo& info = state.info_png; lodepng_color_mode_copy(&info.color, &mode_png); lodepng_color_mode_copy(&state.info_raw, &mode_raw); state.encoder.auto_convert = auto_convert; info.background_defined = 1; info.background_r = r; info.background_g = g; info.background_b = b; std::vector png; error = lodepng::encode(png, pixels, w, h, state); if(expect_encoder_error) { ASSERT_NOT_EQUALS(0, error); return; } ASSERT_NO_PNG_ERROR(error); lodepng::State state2; LodePNGInfo& info2 = state2.info_png; state2.info_raw.colortype = LCT_RGBA; state2.info_raw.bitdepth = 16; unsigned w2, h2; std::vector image2; error = lodepng::decode(image2, w2, h2, state2, &png[0], png.size()); ASSERT_NO_PNG_ERROR(error); ASSERT_EQUALS(w, w2); ASSERT_EQUALS(h, h2); ASSERT_EQUALS(1, info2.background_defined); ASSERT_EQUALS(r2, info2.background_r); ASSERT_EQUALS(g2, info2.background_g); ASSERT_EQUALS(b2, info2.background_b); // compare pixels in the "raw" color model LodePNGColorMode mode_decoded; lodepng_color_mode_init(&mode_decoded); mode_decoded.bitdepth = 16; mode_decoded.colortype = LCT_RGBA; std::vector image3((w * h * lodepng_get_bpp(&mode_raw) + 7) / 8); error = lodepng_convert(image3.data(), image2.data(), &mode_raw, &mode_decoded, w, h); ASSERT_NO_PNG_ERROR(error); ASSERT_EQUALS(pixels.size(), image3.size()); for(size_t i = 0; i < image3.size(); i++) { ASSERT_EQUALS((int)image3[i], (int)pixels[i]); } } // r, g, b is input background color to encoder, given in png color model // r2, g2, b2 is expected decoded background color, in color model it auto chose if auto_convert is on void testBkgdChunk(unsigned r, unsigned g, unsigned b, unsigned r2, unsigned g2, unsigned b2, LodePNGColorType type_pixels, unsigned bitdepth_pixels, LodePNGColorType type_raw, unsigned bitdepth_raw, LodePNGColorType type_png, unsigned bitdepth_png, bool auto_convert, bool expect_encoder_error = false) { unsigned error; Image image; generateTestImageRequiringColorType16(image, type_pixels, bitdepth_pixels, false); LodePNGColorMode mode_raw; lodepng_color_mode_init(&mode_raw); mode_raw.bitdepth = bitdepth_raw; mode_raw.colortype = type_raw; LodePNGColorMode mode_test; lodepng_color_mode_init(&mode_test); mode_test.bitdepth = 16; mode_test.colortype = LCT_RGBA; LodePNGColorMode mode_png; lodepng_color_mode_init(&mode_png); mode_png.bitdepth = bitdepth_png; mode_png.colortype = type_png; std::vector temp((image.width * image.height * lodepng_get_bpp(&mode_raw) + 7) / 8); error = lodepng_convert(temp.data(), image.data.data(), &mode_raw, &mode_test, image.width, image.height); ASSERT_NO_PNG_ERROR(error); image.data = temp; testBkgdChunk(r, g, b, r2, g2, b2, image.data, image.width, image.height, mode_raw, mode_png, auto_convert, expect_encoder_error); } void testBkgdChunk() { std::cout << "testBkgdChunk" << std::endl; // color param order is: generated, raw, png ( == bKGD) // here generated means: what color values the pixels will get, so what auto_convert will make it choose testBkgdChunk(255, 0, 0, 255, 0, 0, LCT_RGBA, 8, LCT_RGBA, 8, LCT_RGBA, 8, true); testBkgdChunk(255, 0, 0, 255, 0, 0, LCT_RGBA, 8, LCT_RGB, 8, LCT_RGB, 8, true); testBkgdChunk(255, 0, 0, 255, 0, 0, LCT_RGB, 8, LCT_RGB, 8, LCT_RGB, 8, true); testBkgdChunk(255, 255, 255, 1, 1, 1, LCT_GREY, 1, LCT_RGB, 8, LCT_RGB, 8, true); testBkgdChunk(255, 255, 255, 3, 3, 3, LCT_GREY, 2, LCT_RGB, 8, LCT_RGB, 8, true); testBkgdChunk(255, 255, 255, 15, 15, 15, LCT_GREY, 4, LCT_RGB, 8, LCT_RGB, 8, true); testBkgdChunk(255, 255, 255, 255, 255, 255, LCT_GREY, 8, LCT_RGB, 8, LCT_RGB, 8, true); testBkgdChunk(255, 255, 255, 65535, 65535, 65535, LCT_GREY, 16, LCT_RGB, 16, LCT_RGB, 8, true); testBkgdChunk(123, 0, 0, 123, 0, 0, LCT_GREY, 1, LCT_RGB, 8, LCT_RGB, 8, true); testBkgdChunk(170, 170, 170, 2, 2, 2, LCT_GREY, 1, LCT_RGB, 8, LCT_RGB, 8, true); // 170 = value 2 in 2-bit // without auto_convert. Note that it will still convert if different colortype is given for raw and png, it's just // not automatic in that case. testBkgdChunk(255, 0, 0, 255, 0, 0, LCT_RGBA, 8, LCT_RGBA, 8, LCT_RGBA, 8, false); testBkgdChunk(60000, 0, 0, 60000, 0, 0, LCT_RGBA, 8, LCT_RGBA, 8, LCT_RGBA, 16, false); testBkgdChunk(128, 128, 128, 128, 128, 128, LCT_GREY, 8, LCT_RGBA, 8, LCT_GREY, 8, false); { LodePNGColorMode pal; lodepng_color_mode_init(&pal); for(int i = 0; i < 200; i++) lodepng_palette_add(&pal, i, i / 2, 0, 255); pal.colortype = LCT_PALETTE; pal.bitdepth = 8; unsigned w = 200; unsigned h = 200; std::vector img(w * h); for(unsigned y = 0; y < h; y++) for(unsigned x = 0; x < w; x++) { img[y * w + x] = x; } testBkgdChunk(100, 0, 0, 100, 100, 100, img, w, h, pal, pal, true, false); testBkgdChunk(100, 0, 0, 100, 100, 100, img, w, h, pal, pal, false, false); testBkgdChunk(250, 0, 0, 250, 250, 250, img, w, h, pal, pal, true, true); std::vector fourcolor(w * h); for(unsigned y = 0; y < h; y++) for(unsigned x = 0; x < w; x++) { fourcolor[y * w + x] = x & 3; } // palette index 4 expected for output bKGD: auto_convert should turn the 200-sized // palette in one of size 5, 4 values for the fourcolor image above, and then a 5th for // the bkgd index. The other two 4's actually shouldn't matter, it's not defined what // they should be though currently lodepng sets them also to the palette index... testBkgdChunk(100, 0, 0, 4, 4, 4, fourcolor, w, h, pal, pal, true, false); std::vector mini(4); mini[0] = 1; mini[1] = 2; mini[2] = 3; mini[3] = 4; // here we expect RGB color from the output image, since the image is tiny so it chooses to not add PLTE testBkgdChunk(100, 0, 0, 100, 50, 0, mini, 2, 2, pal, pal, true, false); lodepng_color_mode_cleanup(&pal); } } void testBkgdChunk2() { std::cout << "testBkgdChunk2" << std::endl; Image image; generateTestImageRequiringColorType8(image, LCT_GREY, 2, false); // without background, it should choose 2-bit gray for this PNG std::vector png0; ASSERT_NO_PNG_ERROR(lodepng::encode(png0, image.data, image.width, image.height)); lodepng::State state0; unsigned w0, h0; lodepng_inspect(&w0, &h0, &state0, png0.data(), png0.size()); ASSERT_EQUALS(2, state0.info_png.color.bitdepth); ASSERT_EQUALS(LCT_GREY, state0.info_png.color.colortype); // red background, with auto_convert, it is forced to choose RGB lodepng::State state; LodePNGInfo& info = state.info_png; info.background_defined = 1; info.background_r = 255; info.background_g = 0; info.background_b = 0; std::vector png1; ASSERT_NO_PNG_ERROR(lodepng::encode(png1, image.data, image.width, image.height, state)); lodepng::State state1; unsigned w1, h1; lodepng_inspect(&w1, &h1, &state1, png1.data(), png1.size()); ASSERT_EQUALS(8, state1.info_png.color.bitdepth); ASSERT_EQUALS(LCT_RGB, state1.info_png.color.colortype); // gray output required, background color also interpreted as gray state.info_raw.colortype = LCT_RGB; state.info_png.color.colortype = LCT_GREY; state.info_png.color.bitdepth = 1; state.encoder.auto_convert = 0; info.background_defined = 1; info.background_r = 1; info.background_g = 1; info.background_b = 1; std::vector png2; ASSERT_NO_PNG_ERROR(lodepng::encode(png2, image.data, image.width, image.height, state)); lodepng::State state2; unsigned w2, h2; lodepng_inspect(&w2, &h2, &state2, png2.data(), png2.size()); ASSERT_EQUALS(1, state2.info_png.color.bitdepth); ASSERT_EQUALS(LCT_GREY, state2.info_png.color.colortype); } // r, g, b, a are the bit depths to store void testSbitChunk(unsigned r, unsigned g, unsigned b, unsigned a, const std::vector& pixels, unsigned w, unsigned h, const LodePNGColorMode& mode_raw, const LodePNGColorMode& mode_png, bool auto_convert, bool expect_encoder_error = false) { unsigned error; lodepng::State state; LodePNGInfo& info = state.info_png; lodepng_color_mode_copy(&info.color, &mode_png); lodepng_color_mode_copy(&state.info_raw, &mode_raw); state.encoder.auto_convert = auto_convert; if(mode_raw.colortype == LCT_PALETTE) { for(size_t i = 0; i < 256; i++) { // TODO: consider allowing to set only 1 of these palettes in lodepng in the case // where both info_raw and info_png have the palette color type lodepng_palette_add(&state.info_raw, i, i, i, 255); lodepng_palette_add(&info.color, i, i, i, 255); } } info.sbit_defined = 1; info.sbit_r = r; info.sbit_g = g; info.sbit_b = b; info.sbit_a = a; std::vector png; error = lodepng::encode(png, pixels, w, h, state); if(expect_encoder_error) { ASSERT_NOT_EQUALS(0, error); return; } ASSERT_NO_PNG_ERROR(error); lodepng::State state2; LodePNGInfo& info2 = state2.info_png; unsigned w2, h2; std::vector image2; error = lodepng::decode(image2, w2, h2, state2, &png[0], png.size()); ASSERT_NO_PNG_ERROR(error); LodePNGColorType type = mode_png.colortype; ASSERT_EQUALS(w, w2); ASSERT_EQUALS(h, h2); ASSERT_EQUALS(1, info2.sbit_defined); ASSERT_EQUALS(r, info2.sbit_r); if(type == LCT_RGB || type == LCT_RGBA || type == LCT_PALETTE) { ASSERT_EQUALS(g, info2.sbit_g); ASSERT_EQUALS(b, info2.sbit_b); } if(type == LCT_GREY_ALPHA || type == LCT_RGBA) { ASSERT_EQUALS(a, info2.sbit_a); } // compare pixels in a 16-bit color model LodePNGColorMode mode_compare; lodepng_color_mode_init(&mode_compare); mode_compare.bitdepth = 16; mode_compare.colortype = LCT_RGBA; LodePNGColorMode mode_decoded; lodepng_color_mode_init(&mode_decoded); mode_decoded.bitdepth = 8; mode_decoded.colortype = LCT_RGBA; std::vector image3(w * h * 8); error = lodepng_convert(image3.data(), image2.data(), &mode_compare, &mode_decoded, w, h); std::vector image4(w * h * 8); error = lodepng_convert(image4.data(), pixels.data(), &mode_compare, &state.info_raw, w, h); ASSERT_NO_PNG_ERROR(error); ASSERT_EQUALS(image4.size(), image3.size()); for(size_t i = 0; i < image3.size(); i++) { ASSERT_EQUALS((int)image4[i], (int)image3[i]); } } void testSbitChunk(unsigned r, unsigned g, unsigned b, unsigned a, LodePNGColorType type, unsigned bitdepth, bool expect_encoder_error = false) { LodePNGColorMode mode_raw; lodepng_color_mode_init(&mode_raw); mode_raw.bitdepth = bitdepth; mode_raw.colortype = type; LodePNGColorMode mode_png; lodepng_color_mode_init(&mode_png); mode_png.bitdepth = bitdepth; mode_png.colortype = type; std::vector pixels(8, 255); // force all pixels to be white, so encoder tries to use auto_convert as much as possible testSbitChunk(r, g, b, a, pixels, 1, 1, mode_raw, mode_png, false, expect_encoder_error); testSbitChunk(r, g, b, a, pixels, 1, 1, mode_raw, mode_png, true, expect_encoder_error); } // type_pixels = what the pixels should require at least for auto_convert // type_raw = actual raw pixel type to give to the encoder // type_png = PNG type to request from the encoder (if not auto_convert) // auto_convert: 0 = no, 1 = yes, 2 = try both void testSbitChunk2(unsigned r, unsigned g, unsigned b, unsigned a, LodePNGColorType type_pixels, unsigned bitdepth_pixels, LodePNGColorType type_raw, unsigned bitdepth_raw, LodePNGColorType type_png, unsigned bitdepth_png, int auto_convert, bool expect_encoder_error = false) { unsigned error; Image image; generateTestImageRequiringColorType16(image, type_pixels, bitdepth_pixels, false); LodePNGColorMode mode_raw; lodepng_color_mode_init(&mode_raw); mode_raw.bitdepth = bitdepth_raw; mode_raw.colortype = type_raw; LodePNGColorMode mode_test; lodepng_color_mode_init(&mode_test); mode_test.bitdepth = 16; mode_test.colortype = LCT_RGBA; LodePNGColorMode mode_png; lodepng_color_mode_init(&mode_png); mode_png.bitdepth = bitdepth_png; mode_png.colortype = type_png; std::vector temp((image.width * image.height * lodepng_get_bpp(&mode_raw) + 7) / 8); error = lodepng_convert(temp.data(), image.data.data(), &mode_raw, &mode_test, image.width, image.height); ASSERT_NO_PNG_ERROR(error); image.data = temp; if(auto_convert == 0 || auto_convert == 2) testSbitChunk(r, g, b, a, image.data, image.width, image.height, mode_raw, mode_png, false, expect_encoder_error); if(auto_convert == 1 || auto_convert == 2) testSbitChunk(r, g, b, a, image.data, image.width, image.height, mode_raw, mode_png, true, expect_encoder_error); } // Test the sBIT chunk for all color types, and for possible combinations of pixel colors where auto_convert conversions occur (only conversions that // still allow storing all the sBIT information within the PNG specification limitations may occur) void testSbitChunk() { std::cout << "testSbitChunk" << std::endl; testSbitChunk(8, 8, 8, 0, LCT_RGB, 8, false); testSbitChunk(1, 2, 3, 0, LCT_RGB, 8, false); testSbitChunk(0, 2, 3, 0, LCT_RGB, 8, true); testSbitChunk(9, 2, 3, 0, LCT_RGB, 8, true); testSbitChunk(8, 8, 8, 8, LCT_RGBA, 8, false); testSbitChunk(1, 2, 3, 4, LCT_RGBA, 8, false); testSbitChunk(0, 2, 3, 4, LCT_RGBA, 8, true); testSbitChunk(9, 2, 3, 4, LCT_RGBA, 8, true); testSbitChunk(1, 2, 3, 0, LCT_RGB, 16, false); testSbitChunk(0, 2, 3, 0, LCT_RGB, 16, true); testSbitChunk(9, 2, 3, 0, LCT_RGB, 16, false); testSbitChunk(17, 2, 3, 0, LCT_RGB, 16, true); testSbitChunk(1, 2, 3, 4, LCT_RGBA, 16, false); testSbitChunk(0, 2, 3, 4, LCT_RGBA, 16, true); testSbitChunk(9, 2, 3, 4, LCT_RGBA, 16, false); testSbitChunk(17, 2, 3, 4, LCT_RGBA, 16, true); testSbitChunk(8, 2, 3, 0, LCT_PALETTE, 8, false); testSbitChunk(8, 2, 3, 0, LCT_PALETTE, 4, false); // 4-bit palette still treats the RGB as 8-bit testSbitChunk(9, 2, 3, 0, LCT_PALETTE, 8, true); testSbitChunk(8, 0, 0, 0, LCT_GREY, 8, false); testSbitChunk(8, 0, 0, 0, LCT_GREY, 4, true); testSbitChunk(5, 0, 0, 0, LCT_GREY, 8, false); testSbitChunk(1, 0, 0, 0, LCT_GREY, 1, false); testSbitChunk(3, 0, 0, 0, LCT_GREY, 1, true); testSbitChunk(0, 0, 0, 0, LCT_GREY, 1, true); testSbitChunk(16, 0, 0, 0, LCT_GREY, 16, false); testSbitChunk(17, 0, 0, 0, LCT_GREY, 16, true); testSbitChunk(8, 0, 0, 0, LCT_GREY, 16, false); testSbitChunk(5, 0, 0, 0, LCT_GREY, 16, false); testSbitChunk(8, 0, 0, 8, LCT_GREY_ALPHA, 8, false); testSbitChunk(8, 0, 0, 0, LCT_GREY_ALPHA, 8, true); testSbitChunk(8, 0, 0, 9, LCT_GREY_ALPHA, 8, true); testSbitChunk(5, 0, 0, 5, LCT_GREY_ALPHA, 8, false); testSbitChunk(5, 0, 0, 8, LCT_GREY_ALPHA, 8, false); testSbitChunk(16, 0, 0, 16, LCT_GREY_ALPHA, 16, false); testSbitChunk(16, 0, 0, 8, LCT_GREY_ALPHA, 16, false); testSbitChunk(8, 0, 0, 8, LCT_GREY_ALPHA, 16, false); testSbitChunk(16, 0, 0, 0, LCT_GREY_ALPHA, 16, true); testSbitChunk(16, 0, 0, 17, LCT_GREY_ALPHA, 16, true); testSbitChunk(5, 0, 0, 5, LCT_GREY_ALPHA, 16, false); testSbitChunk(5, 0, 0, 8, LCT_GREY_ALPHA, 16, false); testSbitChunk2(8, 8, 8, 0, LCT_RGB, 8, LCT_RGB, 8, LCT_RGB, 8, 2, false); testSbitChunk2(8, 8, 8, 0, LCT_GREY, 8, LCT_RGB, 8, LCT_RGB, 8, 2, false); testSbitChunk2(12, 12, 12, 0, LCT_GREY, 8, LCT_RGB, 16, LCT_RGB, 16, 2, false); testSbitChunk2(12, 12, 12, 8, LCT_GREY, 8, LCT_RGBA, 16, LCT_RGBA, 16, 2, false); testSbitChunk2(8, 8, 8, 0, LCT_GREY, 8, LCT_RGB, 16, LCT_RGB, 16, 2, false); testSbitChunk2(8, 7, 8, 0, LCT_GREY, 8, LCT_RGB, 16, LCT_RGB, 16, 2, false); testSbitChunk2(8, 8, 7, 0, LCT_GREY, 8, LCT_RGB, 16, LCT_RGB, 16, 2, false); testSbitChunk2(8, 7, 8, 0, LCT_GREY, 8, LCT_RGB, 8, LCT_RGB, 8, 2, false); testSbitChunk2(8, 8, 7, 0, LCT_GREY, 8, LCT_RGB, 8, LCT_RGB, 8, 2, false); testSbitChunk2(8, 8, 8, 0, LCT_GREY, 8, LCT_RGB, 8, LCT_GREY_ALPHA, 8, 1, false); testSbitChunk2(8, 8, 8, 8, LCT_GREY, 8, LCT_RGB, 8, LCT_GREY_ALPHA, 8, 0, false); // test png-suite image cs3n3p08.png, which has an sBIT chunk with RGB values set to 3 bits { std::vector png, decoded; fromBase64(png, std::string("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAABGdBTUEAAYagMeiWXwAAAANzQklUAwMDo5KgQgAAAFRQTFRFkv8AAP+SAP//AP8AANv/AP9t/7YAAG3/tv8A/5IA2/8AAEn//yQA/wAAJP8ASf8AAP/bAP9JAP+2//8AAP8kALb//9sAAJL//20AACT//0kAbf8A33ArFwAAAEtJREFUeJyFyscBggAAALGzYldUsO2/pyMk73SGGE7QF3pDe2gLzdADHA7QDqIfdIUu0AocntAIbaAFdIdu0BIc1tAEvaABOkIf+AMiQDPhd/SuJgAAAABJRU5ErkJggg==")); lodepng::State state; unsigned w, h; unsigned error = lodepng::decode(decoded, w, h, state, png); assertNoError(error); ASSERT_EQUALS(1, state.info_png.sbit_defined); ASSERT_EQUALS(3, state.info_png.sbit_r); ASSERT_EQUALS(3, state.info_png.sbit_g); ASSERT_EQUALS(3, state.info_png.sbit_b); } // test png-suite image basn0g02.png, which is known to not have an sBIT chunk { std::vector png, decoded; fromBase64(png, std::string("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAgAAAAAcoT2JAAAABGdBTUEAAYagMeiWXwAAAB9JREFUeJxjYAhd9R+M8TCIUMIAU4aPATMJH2OQuQcAvUl/gYsJiakAAAAASUVORK5CYII=")); lodepng::State state; unsigned w, h; unsigned error = lodepng::decode(decoded, w, h, state, png); assertNoError(error); ASSERT_EQUALS(0, state.info_png.sbit_defined); } } // Test particular cHRM+gAMA conversion to srgb // gamma = gamma given 100000x multiplied form of PNG, or 0 to set none at all // wx..by = whitepoint and chromaticities, given in the 100000x multiplied form of PNG // r, g, b: r, g, b values to encode in the PNG's data // er, eg, eb: expected r, g, b values after decoding and converting to sRGB void testChrmToSrgb(unsigned gamma, unsigned wx, unsigned wy, unsigned rx, unsigned ry, unsigned gx, unsigned gy, unsigned bx, unsigned by, unsigned char r, unsigned char g, unsigned char b, unsigned char er, unsigned char eg, unsigned char eb, int max_dist = 0) { std::vector image(4); image[0] = r; image[1] = g; image[2] = b; image[3] = 255; lodepng::State state; if(gamma) { state.info_png.gama_defined = 1; state.info_png.gama_gamma = gamma; } state.info_png.chrm_defined = 1; state.info_png.chrm_white_x = wx; state.info_png.chrm_white_y = wy; state.info_png.chrm_red_x = rx; state.info_png.chrm_red_y = ry; state.info_png.chrm_green_x = gx; state.info_png.chrm_green_y = gy; state.info_png.chrm_blue_x = bx; state.info_png.chrm_blue_y = by; std::vector image2(4); convertToSrgb(image2.data(), image.data(), 1, 1, &state); if(max_dist == 0) { ASSERT_EQUALS(er, image2[0]); ASSERT_EQUALS(eg, image2[1]); ASSERT_EQUALS(eb, image2[2]); } else { ASSERT_NEAR(er, image2[0], max_dist); ASSERT_NEAR(eg, image2[1], max_dist); ASSERT_NEAR(eb, image2[2], max_dist); } // Also test the opposite direction std::vector image3(4); convertFromSrgb(image3.data(), image2.data(), 1, 1, &state); if(max_dist == 0) { ASSERT_EQUALS(r, image3[0]); ASSERT_EQUALS(g, image3[1]); ASSERT_EQUALS(b, image3[2]); } else { ASSERT_NEAR(r, image3[0], max_dist); ASSERT_NEAR(g, image3[1], max_dist); ASSERT_NEAR(b, image3[2], max_dist); } } void testChrmToSrgb() { std::cout << "testChrmToSrgb" << std::endl; // srgb gamma approximation and chromaticities defined as standard by png (multiplied by 100000) unsigned sg = 45455; // srgb gamma approximation unsigned swx = 31270; unsigned swy = 32900; unsigned srx = 64000; unsigned sry = 33000; unsigned sgx = 30000; unsigned sgy = 60000; unsigned sbx = 15000; unsigned sby = 6000; testChrmToSrgb(sg, swx, swy, srx, sry, sgx, sgy, sbx, sby, 0, 0, 0, 0, 0, 0); testChrmToSrgb(sg, swx, swy, srx, sry, sgx, sgy, sbx, sby, 255, 255, 255, 255, 255, 255); testChrmToSrgb(0, swx, swy, srx, sry, sgx, sgy, sbx, sby, 50, 50, 50, 50, 50, 50); testChrmToSrgb(0, swx, swy, srx, sry, sgx, sgy, sbx, sby, 128, 128, 128, 128, 128, 128); testChrmToSrgb(0, swx, swy, srx, sry, sgx, sgy, sbx, sby, 200, 200, 200, 200, 200, 200); testChrmToSrgb(0, swx, swy, srx, sry, sgx, sgy, sbx, sby, 255, 0, 0, 255, 0, 0); testChrmToSrgb(0, swx, swy, srx, sry, sgx, sgy, sbx, sby, 0, 255, 0, 0, 255, 0); testChrmToSrgb(0, swx, swy, srx, sry, sgx, sgy, sbx, sby, 0, 0, 255, 0, 0, 255); // swap red and green chromaticities testChrmToSrgb(0, swx, swy, sgx, sgy, srx, sry, sbx, sby, 255, 0, 0, 0, 255, 0); testChrmToSrgb(0, swx, swy, sgx, sgy, srx, sry, sbx, sby, 0, 255, 0, 255, 0, 0); testChrmToSrgb(0, swx, swy, sgx, sgy, srx, sry, sbx, sby, 0, 0, 255, 0, 0, 255); // swap red/green/blue chromaticities testChrmToSrgb(0, swx, swy, sgx, sgy, sbx, sby, srx, sry, 255, 0, 0, 0, 255, 0); testChrmToSrgb(0, swx, swy, sgx, sgy, sbx, sby, srx, sry, 0, 255, 0, 0, 0, 255); testChrmToSrgb(0, swx, swy, sgx, sgy, sbx, sby, srx, sry, 0, 0, 255, 255, 0, 0); // different whitepoint does not affect white or gray, due to the relative rendering intent (adaptation) testChrmToSrgb(0, 35000, 25000, srx, sry, sgx, sgy, sbx, sby, 0, 0, 0, 0, 0, 0); testChrmToSrgb(0, 35000, 25000, srx, sry, sgx, sgy, sbx, sby, 50, 50, 50, 50, 50, 50); testChrmToSrgb(0, 35000, 25000, srx, sry, sgx, sgy, sbx, sby, 128, 128, 128, 128, 128, 128); testChrmToSrgb(0, 35000, 25000, srx, sry, sgx, sgy, sbx, sby, 200, 200, 200, 200, 200, 200); testChrmToSrgb(0, 35000, 25000, srx, sry, sgx, sgy, sbx, sby, 255, 255, 255, 255, 255, 255); } void testXYZ() { std::cout << "testXYZ" << std::endl; unsigned w = 512, h = 512; std::vector v(w * h * 4 * 2); for(size_t i = 0; i < v.size(); i++) { v[i] = getRandom() & 255; } // Test sRGB -> XYZ -> sRGB roundtrip unsigned rendering_intent = 3; // test with absolute for now // 8-bit { // Default state, the conversions use 8-bit sRGB lodepng::State state; std::vector f(w * h * 4); float whitepoint[3]; assertNoError(lodepng::convertToXYZ(f.data(), whitepoint, v.data(), w, h, &state)); std::vector v2(w * h * 4); assertNoError(lodepng::convertFromXYZ(v2.data(), f.data(), w, h, &state, whitepoint, rendering_intent)); for(size_t i = 0; i < v2.size(); i++) { ASSERT_EQUALS(v[i], v2[i]); } } // 16-bit { // Default state but with 16-bit, the conversions use 16-bit sRGB lodepng::State state; state.info_raw.bitdepth = 16; std::vector f(w * h * 4); float whitepoint[3]; assertNoError(lodepng::convertToXYZ(f.data(), whitepoint, v.data(), w, h, &state)); std::vector v2(w * h * 8); assertNoError(lodepng::convertFromXYZ(v2.data(), f.data(), w, h, &state, whitepoint, rendering_intent)); for(size_t i = 0; i < v2.size(); i++) { ASSERT_EQUALS(v[i], v2[i]); } } // Test custom RGB+gamma -> XYZ -> custom RGB+gamma roundtrip LodePNGInfo info_custom; lodepng_info_init(&info_custom); info_custom.gama_defined = 1; info_custom.gama_gamma = 30000; // default 45455 info_custom.chrm_defined = 1; info_custom.chrm_white_x = 10000; // default 31270 info_custom.chrm_white_y = 20000; // default 32900 info_custom.chrm_red_x = 30000; // default 64000 info_custom.chrm_red_y = 50000; // default 33000 info_custom.chrm_green_x = 70000; // default 30000 info_custom.chrm_green_y = 11000; // default 60000 info_custom.chrm_blue_x = 13000; // default 15000 info_custom.chrm_blue_y = 17000; // default 6000 // 8-bit { lodepng::State state; lodepng_info_copy(&state.info_png, &info_custom); std::vector f(w * h * 4); float whitepoint[3]; assertNoError(lodepng::convertToXYZ(f.data(), whitepoint, v.data(), w, h, &state)); std::vector v2(w * h * 4); assertNoError(lodepng::convertFromXYZ(v2.data(), f.data(), w, h, &state, whitepoint, rendering_intent)); for(size_t i = 0; i < v2.size(); i++) { // Allow near instead of exact due to numerical issues with low values, // see description at the 16-bit test below. unsigned maxdist = 0; if(v[i] <= 2) maxdist = 3; else if(v[i] <= 4) maxdist = 2; else maxdist = 0; ASSERT_NEAR(v[i], v2[i], maxdist); } } // 16-bit { lodepng::State state; lodepng_info_copy(&state.info_png, &info_custom); state.info_raw.bitdepth = 16; std::vector f(w * h * 4); float whitepoint[3]; assertNoError(lodepng::convertToXYZ(f.data(), whitepoint, v.data(), w, h, &state)); std::vector v2(w * h * 8); assertNoError(lodepng::convertFromXYZ(v2.data(), f.data(), w, h, &state, whitepoint, rendering_intent)); for(size_t i = 0; i < v2.size(); i += 2) { unsigned a = v[i + 0] * 256u + v[i + 1]; unsigned a2 = v2[i + 0] * 256u + v2[i + 1]; // There are numerical issues with low values due to the precision of float, // so allow some distance for low values (low compared to 65535). // The issue seems to be: the combination of how the gamma correction affects // low values and the color conversion matrix operating on single precision // floating point. With the sRGB's gamma the problem seems not to happen, maybe // because that linear part near 0 behaves better than power. // TODO: check if it can be fixed without using double for the image and without slow double precision pow. unsigned maxdist = 0; if(a < 2048) maxdist = 768; else if(a < 4096) maxdist = 24; else if(a < 16384) maxdist = 4; else maxdist = 2; ASSERT_NEAR(a, a2, maxdist); } } lodepng_info_cleanup(&info_custom); } void testICC() { std::cout << "testICC" << std::endl; // approximate srgb (gamma function not exact) std::string icc_near_srgb_base64 = "AAABwHRlc3QCQAAAbW50clJHQiBYWVogB+MAAQABAAAAAAAAYWNzcFNHSSAAAAABAAAAAAAAAAAA" "AAAAAAAAAAAAAAEAAPbWAAEAAAAA0y10ZXN0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAJY3BydAAAAPAAAAANZGVzYwAAAQAAAABfd3RwdAAAAWAAAAAUclhZ" "WgAAAXQAAAAUZ1hZWgAAAYgAAAAUYlhZWgAAAZwAAAAUclRSQwAAAbAAAAAOZ1RSQwAAAbAAAAAO" "YlRSQwAAAbAAAAAOdGV4dAAAAABDQzAgAAAAAGRlc2MAAAAAAAAABXRlc3QAZW5VUwAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAFhZWiAAAAAAAADzUQABAAAAARbMWFlaIAAAAAAAAG+gAAA49AAAA5BYWVogAAAA" "AAAAYpYAALeHAAAY2VhZWiAAAAAAAAAkngAAD4QAALbCY3VydgAAAAAAAAABAjMAAA=="; std::vector icc_near_srgb; fromBase64(icc_near_srgb, icc_near_srgb_base64); lodepng::State state_near_srgb; lodepng_set_icc(&state_near_srgb.info_png, "near_srgb", icc_near_srgb.data(), icc_near_srgb.size()); // a made up RGB model. // it causes (when converting from this to srgb) green to become softer green, blue to become softer blue, red to become orange. // this model intersects sRGB, but some parts are outside of sRGB, some parts of sRGB are outside of this one. // so when converting between this and sRGB and clipping the values to 8-bit, and then converting back, the values will not be the same due to this clipping std::string icc_orange_base64 = "AAABwHRlc3QCQAAAbW50clJHQiBYWVogB+MAAQABAAAAAAAAYWNzcFNHSSAAAAABAAAAAAAAAAAA" "AAAAAAAAAAAAAAMAAPbWAAEAAAAA0y10ZXN0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAJY3BydAAAAPAAAAANZGVzYwAAAQAAAABfd3RwdAAAAWAAAAAUclhZ" "WgAAAXQAAAAUZ1hZWgAAAYgAAAAUYlhZWgAAAZwAAAAUclRSQwAAAbAAAAAOZ1RSQwAAAbAAAAAO" "YlRSQwAAAbAAAAAOdGV4dAAAAABDQzAgAAAAAGRlc2MAAAAAAAAABXRlc3QAZW5VUwAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAFhZWiAAAAAAAAE7uwABAAAAARmZWFlaIAAAAAAAANAHAACTTAAACrRYWVogAAAA" "AAAABOMAAFd4AAAFzVhZWiAAAAAAAAAh6gAAFTsAAMKqY3VydgAAAAAAAAABAoAAAA=="; std::vector icc_orange; fromBase64(icc_orange, icc_orange_base64); lodepng::State state_orange; lodepng_set_icc(&state_orange.info_png, "orange", icc_orange.data(), icc_orange.size()); // A made up RGB model which is a superset of sRGB, and has R/G/B shifted around (so it greatly alters colors) // Since this is a superset of sRGB, converting from sRGB to this model, and then back, should be lossless, but the opposite not necessarily. std::string icc_super_base64 = "AAABwHRlc3QCQAAAbW50clJHQiBYWVogB+MAAQABAAAAAAAAYWNzcFNHSSAAAAABAAAAAAAAAAAA" "AAAAAAAAAAAAAAEAAPbWAAEAAAAA0y10ZXN0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAJY3BydAAAAPAAAAANZGVzYwAAAQAAAABfd3RwdAAAAWAAAAAUclhZ" "WgAAAXQAAAAUZ1hZWgAAAYgAAAAUYlhZWgAAAZwAAAAUclRSQwAAAbAAAAAOZ1RSQwAAAbAAAAAO" "YlRSQwAAAbAAAAAOdGV4dAAAAABDQzAgAAAAAGRlc2MAAAAAAAAABXRlc3QAZW5VUwAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAFhZWiAAAAAAAADzUQABAAAAARbMWFlaIAAAAAAAAFW+AADL3f//70ZYWVogAAAA" "AAAAJqD////UAADsUFhZWiAAAAAAAAB6dgAANE////eXY3VydgAAAAAAAAABAjMAAA=="; std::vector icc_super; fromBase64(icc_super, icc_super_base64); lodepng::State state_super; lodepng_set_icc(&state_super.info_png, "super", icc_super.data(), icc_super.size()); // A made up RGB model which is a subset of sRGB, and has R/G/B shifted around (so it greatly alters colors) // Since this is a subset of sRGB, converting to sRGB from this model, and then back, should be lossless, but the opposite not necessarily. std::string icc_sub_base64 = "AAABwHRlc3QCQAAAbW50clJHQiBYWVogB+MAAQABAAAAAAAAYWNzcFNHSSAAAAABAAAAAAAAAAAA" "AAAAAAAAAAAAAAEAAPbWAAEAAAAA0y10ZXN0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAJY3BydAAAAPAAAAANZGVzYwAAAQAAAABfd3RwdAAAAWAAAAAUclhZ" "WgAAAXQAAAAUZ1hZWgAAAYgAAAAUYlhZWgAAAZwAAAAUclRSQwAAAbAAAAAOZ1RSQwAAAbAAAAAO" "YlRSQwAAAbAAAAAOdGV4dAAAAABDQzAgAAAAAGRlc2MAAAAAAAAABXRlc3QAZW5VUwAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAFhZWiAAAAAAAADzUQABAAAAARbMWFlaIAAAAAAAAHEEAABy1AAAr8ZYWVogAAAA" "AAAAV5kAAEPkAAAMs1hZWiAAAAAAAAAuNwAASUcAABazY3VydgAAAAAAAAABAjMAAA=="; std::vector icc_sub; fromBase64(icc_sub, icc_sub_base64); lodepng::State state_sub; lodepng_set_icc(&state_sub.info_png, "sub", icc_sub.data(), icc_sub.size()); // make 8-pixel image with following colors: white, gray, red, darkred, green, darkgreen, blue, darkblue unsigned w = 4, h = 2; std::vector im(w * h * 4, 255); im[0 * 4 + 0] = 255; im[0 * 4 + 1] = 255; im[0 * 4 + 2] = 255; im[1 * 4 + 0] = 128; im[1 * 4 + 1] = 128; im[1 * 4 + 2] = 128; im[2 * 4 + 0] = 255; im[2 * 4 + 1] = 0; im[2 * 4 + 2] = 0; im[3 * 4 + 0] = 128; im[3 * 4 + 1] = 0; im[3 * 4 + 2] = 0; im[4 * 4 + 0] = 0; im[4 * 4 + 1] = 255; im[4 * 4 + 2] = 0; im[5 * 4 + 0] = 0; im[5 * 4 + 1] = 128; im[5 * 4 + 2] = 0; im[6 * 4 + 0] = 0; im[6 * 4 + 1] = 0; im[6 * 4 + 2] = 255; im[7 * 4 + 0] = 0; im[7 * 4 + 1] = 0; im[7 * 4 + 2] = 128; { std::vector im2(w * h * 4, 255); assertNoError(convertToSrgb(im2.data(), im.data(), w, h, &state_orange)); ASSERT_NEAR(255, im2[0 * 4 + 0], 1); ASSERT_NEAR(255, im2[0 * 4 + 1], 1); ASSERT_NEAR(255, im2[0 * 4 + 2], 1); ASSERT_NEAR(117, im2[1 * 4 + 0], 1); ASSERT_NEAR(117, im2[1 * 4 + 1], 1); ASSERT_NEAR(117, im2[1 * 4 + 2], 1); ASSERT_NEAR(255, im2[2 * 4 + 0], 1); ASSERT_NEAR(151, im2[2 * 4 + 1], 1); ASSERT_NEAR( 0, im2[2 * 4 + 2], 1); ASSERT_NEAR(145, im2[3 * 4 + 0], 1); ASSERT_NEAR( 66, im2[3 * 4 + 1], 1); ASSERT_NEAR( 0, im2[3 * 4 + 2], 1); ASSERT_NEAR( 0, im2[4 * 4 + 0], 1); ASSERT_NEAR(209, im2[4 * 4 + 1], 1); ASSERT_NEAR( 0, im2[4 * 4 + 2], 1); ASSERT_NEAR( 0, im2[5 * 4 + 0], 1); ASSERT_NEAR( 95, im2[5 * 4 + 1], 1); ASSERT_NEAR( 0, im2[5 * 4 + 2], 1); ASSERT_NEAR( 0, im2[6 * 4 + 0], 1); ASSERT_NEAR( 66, im2[6 * 4 + 1], 1); ASSERT_NEAR(255, im2[6 * 4 + 2], 1); ASSERT_NEAR( 0, im2[7 * 4 + 0], 1); ASSERT_NEAR( 25, im2[7 * 4 + 1], 1); ASSERT_NEAR(120, im2[7 * 4 + 2], 1); // Cannot test the inverse direction to see if same as original, because the color model here has values // outside of sRGB so several values were clipped. } { std::vector im2(w * h * 4, 255); // convert between the two in one and then the other direction assertNoError(convertRGBModel(im2.data(), im.data(), w, h, &state_near_srgb, &state_sub, 3)); std::vector im3(w * h * 4, 255); assertNoError(convertRGBModel(im3.data(), im2.data(), w, h, &state_sub, &state_near_srgb, 3)); // im3 should be same as im (allow some numerical errors), because we converted from a subset of sRGB to sRGB // and then back. // If state_super was used here instead (with a superset RGB color model), the test below would faill due to // the clipping of the values in the 8-bit chars (due to the superset being out of range for sRGB) for(size_t i = 0; i < im.size(); i++) { // due to the gamma (trc), small values are very imprecise (due to the 8-bit char step in between), so allow more distance there int tolerance = im[i] < 32 ? 16 : 1; ASSERT_NEAR(im[i], im3[i], tolerance); } } { std::vector im2(w * h * 4, 255); assertNoError(convertFromSrgb(im2.data(), im.data(), w, h, &state_super)); std::vector im3(w * h * 4, 255); assertNoError(convertToSrgb(im3.data(), im2.data(), w, h, &state_super)); for(size_t i = 0; i < im.size(); i++) { int tolerance = im[i] < 32 ? 16 : 1; ASSERT_NEAR(im[i], im3[i], tolerance); } } } void testICCGray() { std::cout << "testICCGray" << std::endl; // Grayscale, Gamma 2.2, sRGB whitepoint std::string icc22_base64 = "AAABSHRlc3QCQAAAbW50ckdSQVlYWVogB+MAAQABAAAAAAAAYWNzcFNHSSAAAAABAAAAAAAAAAAA" "AAAAAAAAAAAAAAMAAPbWAAEAAAAA0y10ZXN0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAEY3BydAAAALQAAAANZGVzYwAAAMQAAABfd3RwdAAAASQAAAAUa1RS" "QwAAATgAAAAOdGV4dAAAAABDQzAgAAAAAGRlc2MAAAAAAAAABXRlc3QAZW5VUwAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAFhZWiAAAAAAAADzUQABAAAAARbMY3VydgAAAAAAAAABAjMAAA=="; std::vector icc22; fromBase64(icc22, icc22_base64); lodepng::State state22; state22.info_raw.colortype = LCT_GREY; lodepng_set_icc(&state22.info_png, "gray22", icc22.data(), icc22.size()); // Grayscale, Gamma 2.9, custom whitepoint std::string icc29_base64 = "AAABSHRlc3QCQAAAbW50ckdSQVlYWVogB+MAAQABAAAAAAAAYWNzcFNHSSAAAAABAAAAAAAAAAAA" "AAAAAAAAAAAAAAMAAPbWAAEAAAAA0y10ZXN0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAEY3BydAAAALQAAAANZGVzYwAAAMQAAABfd3RwdAAAASQAAAAUa1RS" "QwAAATgAAAAOdGV4dAAAAABDQzAgAAAAAGRlc2MAAAAAAAAABXRlc3QAZW5VUwAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAFhZWiAAAAAAAAE7uwABAAAAARmZY3VydgAAAAAAAAABAuYAAA=="; std::vector icc29; fromBase64(icc29, icc29_base64); lodepng::State state29; state29.info_raw.colortype = LCT_GREY; lodepng_set_icc(&state29.info_png, "gray29", icc29.data(), icc29.size()); // Grayscale, Gamma 1.5, custom whitepoint std::string icc15_base64 = "AAABSHRlc3QCQAAAbW50ckdSQVlYWVogB+MAAQABAAAAAAAAYWNzcFNHSSAAAAABAAAAAAAAAAAA" "AAAAAAAAAAAAAAMAAPbWAAEAAAAA0y10ZXN0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAEY3BydAAAALQAAAANZGVzYwAAAMQAAABfd3RwdAAAASQAAAAUa1RS" "QwAAATgAAAAOdGV4dAAAAABDQzAgAAAAAGRlc2MAAAAAAAAABXRlc3QAZW5VUwAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAFhZWiAAAAAAAAE7uwABAAAAARmZY3VydgAAAAAAAAABAYAAAA=="; std::vector icc15; fromBase64(icc15, icc15_base64); lodepng::State state15; state15.info_raw.colortype = LCT_GREY; lodepng_set_icc(&state15.info_png, "gray15", icc15.data(), icc15.size()); // make 8-pixel grayscale image with different shades of gray unsigned w = 4, h = 2; std::vector im(w * h, 255); im[0] = 0; im[1] = 40; im[2] = 80; im[3] = 120; im[4] = 160; im[5] = 200; im[6] = 240; im[7] = 255; { std::vector im2(w * h, 255); assertNoError(convertToSrgb(im2.data(), im.data(), w, h, &state29)); ASSERT_NEAR(0, im2[0], 1); ASSERT_NEAR(15, im2[1], 1); ASSERT_NEAR(52, im2[2], 1); ASSERT_NEAR(94, im2[3], 1); ASSERT_NEAR(139, im2[4], 1); ASSERT_NEAR(187, im2[5], 1); ASSERT_NEAR(236, im2[6], 1); ASSERT_NEAR(255, im2[7], 1); std::vector im3(w * h, 255); assertNoError(convertFromSrgb(im3.data(), im2.data(), w, h, &state29)); for(size_t i = 0; i < 8; i++) { ASSERT_NEAR(im[i], im3[i], 1); } } { std::vector im2(w * h , 255); assertNoError(convertRGBModel(im2.data(), im.data(), w, h, &state22, &state15, 3)); std::vector im3(w * h, 255); assertNoError(convertRGBModel(im3.data(), im2.data(), w, h, &state15, &state22, 3)); for(size_t i = 0; i < im.size(); i++) { int tolerance = im[i] < 16 ? 8 : 1; ASSERT_NEAR(im[i], im3[i], tolerance); } } } // input is base64-encoded png image and base64-encoded RGBA pixels (8 bit per channel) void testBase64Image(const std::string& png64, bool expect_error, unsigned expect_w, unsigned expect_h, const std::string& expect_md5) { std::vector png, pixels; fromBase64(png, png64); std::vector decoded; unsigned w, h; unsigned error = lodepng::decode(decoded, w, h, png); if(expect_error) { ASSERT_EQUALS(true, error != 0); return; } assertNoError(error); ASSERT_EQUALS(expect_w, w); ASSERT_EQUALS(expect_h, h); ASSERT_EQUALS(expect_md5, md5sum(decoded)); // test decoding without alpha channel { size_t numpixels = w * h; std::vector expected_rgb(numpixels * 3); for(size_t i = 0; i < numpixels; i++) { expected_rgb[i * 3 + 0] = decoded[i * 4 + 0]; expected_rgb[i * 3 + 1] = decoded[i * 4 + 1]; expected_rgb[i * 3 + 2] = decoded[i * 4 + 2]; } std::vector rgb; ASSERT_NO_PNG_ERROR(lodepng::decode(rgb, w, h, png, LCT_RGB)); ASSERT_EQUALS(expect_w, w); ASSERT_EQUALS(expect_h, h); ASSERT_EQUALS(expected_rgb, rgb); } // test decoding 16-bit RGBA // TODO: get an additional md5sum for 16-bit pixels instead to compare with { size_t numpixels = w * h; std::vector rgba16; ASSERT_NO_PNG_ERROR(lodepng::decode(rgba16, w, h, png, LCT_RGBA, 16)); ASSERT_EQUALS(expect_w, w); ASSERT_EQUALS(expect_h, h); std::vector rgba8(numpixels * 4); for(size_t i = 0; i < numpixels; i++) { rgba8[i * 4 + 0] = rgba16[i * 8 + 0]; rgba8[i * 4 + 1] = rgba16[i * 8 + 2]; rgba8[i * 4 + 2] = rgba16[i * 8 + 4]; rgba8[i * 4 + 3] = rgba16[i * 8 + 6]; } ASSERT_EQUALS(decoded, rgba8); } // test decoding 16-bit RGB { size_t numpixels = w * h; std::vector expected_rgb(numpixels * 3); for(size_t i = 0; i < numpixels; i++) { expected_rgb[i * 3 + 0] = decoded[i * 4 + 0]; expected_rgb[i * 3 + 1] = decoded[i * 4 + 1]; expected_rgb[i * 3 + 2] = decoded[i * 4 + 2]; } std::vector rgb16; ASSERT_NO_PNG_ERROR(lodepng::decode(rgb16, w, h, png, LCT_RGB, 16)); ASSERT_EQUALS(expect_w, w); ASSERT_EQUALS(expect_h, h); std::vector rgb8(numpixels * 3); for(size_t i = 0; i < numpixels; i++) { rgb8[i * 3 + 0] = rgb16[i * 6 + 0]; rgb8[i * 3 + 1] = rgb16[i * 6 + 2]; rgb8[i * 3 + 2] = rgb16[i * 6 + 4]; } ASSERT_EQUALS(expected_rgb, rgb8); } // test encode/decode // TODO: also test state, for text chunks, ... { std::vector rgba16; ASSERT_NO_PNG_ERROR(lodepng::decode(rgba16, w, h, png, LCT_RGBA, 16)); std::vector png_b; ASSERT_NO_PNG_ERROR(lodepng::encode(png_b, rgba16, w, h, LCT_RGBA, 16)); std::vector rgba16_b; ASSERT_NO_PNG_ERROR(lodepng::decode(rgba16_b, w, h, png_b, LCT_RGBA, 16)); ASSERT_EQUALS(rgba16, rgba16_b); } } // input is base64-encoded png image and base64-encoded RGBA pixels (8 bit per channel) void testPngSuiteImage(const std::string& png64, const std::string& name, bool expect_error, unsigned expect_w, unsigned expect_h, const std::string& expect_md5) { std::cout << "testPngSuiteImage: " << name << std::endl; testBase64Image(png64, expect_error, expect_w, expect_h, expect_md5); } // Tests base64-encoded PngSuite images' pixels against expected md5 sum of their pixels void testPngSuite() { std::cout << "testPngSuite" << std::endl; /* LICENSE of the PngSuite images: PngSuite -------- Permission to use, copy, modify and distribute these images for any purpose and without fee is hereby granted. (c) Willem van Schaik, 1996, 2011 */ testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQAAAAEsBnfPAAAABGdBTUEAAYagMeiWXwAAAJBJREFUeJwtjTEOwjAMRd/GgsQVGHoApC4Zergeg7En4AxWOQATY6WA2FgsZckQNXxLeLC/v99PcBaMGeesuXCj8tHe2Wlc5b9ZY9/ZKq9Mn9kn6kSeZIffW5w255m5G98IK01L1AFP5AFLAat6F67mlNKNMootY4N6cEUeFkhwLZqf9KEdL3pRqiHloYx//QCU41EdZhgi8gAAAABJRU5ErkJggg==", "basi0g01.png", false, 32, 32, "4336909be7bff35103266c9b215ab516"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAgAAAAFrpg0fAAAABGdBTUEAAYagMeiWXwAAAFFJREFUeJxjUGLoYADhcoa7YJyTw3DsGJSUlgYxNm5EZ7OuZ13PEPUh6gMDkMHKAGRE4RZDSCBkEUpIUscQuuo/GMMZGAIMMEEEA6YKwaCSOQCcUoBNhbbZfQAAAABJRU5ErkJggg==", "basi0g02.png", false, 32, 32, "b16bee35e71dce6c08c2447a62ccedea"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAAAAAHk5vi/AAAABGdBTUEAAYagMeiWXwAAAK5JREFUeJxljlERwjAQRBccFBwUHAQchDoodRDqINRBwEHBQcFBwEGRECRUA5lJmM7Nftzs7bub28OywrZFdUX7xLrBvkNzR/fGanc8I9YNsV6I9cViczilQWwuaRqbR1qJzSftoSiVro39q0PWHlkHZPXIOiJrQNZpvsMH+TJHcBaHcjq/Mf+DoihLpbSua2OsZSCtcwyk7XsG0g4DA2m9ZyDtODKQNgQG0k4TgR8ngeup000HFgAAAABJRU5ErkJggg==", "basi0g04.png", false, 32, 32, "0b40ec7e4231183b51e1c23f818a955f"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAAAAAEhFhW+AAAABGdBTUEAAYagMeiWXwAAALVJREFUeJy1kF0KwjAQhJ26yBxCxHv4Q88lPoh4sKoXEQ8hS9ymviQPXSGllM7T5JvNMiwWJBFVFRVJmKpCSCKoKlYkoaqKiyTFj5mZmQgTCYmgSgDXbCwJ52zyGtyyCTk6ZVNXfaFxQKLFnnDsv6OI3/HwO4L7gr0H8F98sT+AuwetL9YMARw8WI7v8fTgO77HzoMtypJ66gBeQxtiV5Y0UwewGchF5r/Du5h2nYT577AupsAPm7n/RegfnygAAAAASUVORK5CYII=", "basi0g08.png", false, 32, 32, "f6470f9f6296c5109e2bd730fe203773"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAAAAAFxhsn9AAAABGdBTUEAAYagMeiWXwAAAOJJREFUeJy1kTsOwjAQRMdJCqj4XYHD5DAcj1Okyg2okCyBRLOSC0BDERKCI7xJVmgaa/X8PFo7oESJEtkaTeLDjdjjgCMe7eTE96FGd3AL7HvZsdNEaJMVo0GNGm775bgwW6Afj/SAjAY+JsYNXIHtz2xYxTXiUoOek4AbFcCnDYEK4NMGsgXcMrGHJytkBX5HIP8FAhVANIMVIBVANMPfgUAFEM3wAVyG5cxcecY5/dup3LVFa1HXmA61LY59f6Ygp1Eg1gZGQaBRILYGdxoFYmtAGgXx9YmCfPD+RMHwuuAFVpjuiRT///4AAAAASUVORK5CYII=", "basi0g16.png", false, 32, 32, "a14e204bbf905586d3763f3cc5dcb2f3"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAGLH901AAAABGdBTUEAAYagMeiWXwAAAPJJREFUeJzVk0GqBCEMRKvAe3gTPVnTczO9iddoaLVm0Qz0Z1r4WWQxoRZifFaIkZKA4xIlfdagpM8aAQCO4xKl88acN+b8w/R+Z3agf4va9bQP7tLTPgJeL/T+LUpj4aFtkRgLc22LxFhUxW2VGGP0p+C2bc8JqQDz/6KUjUCR5TyobASKZDkPZitQSpmWYM7ZBhgrmgGovgClZASm7eGCsSI7QCXjLE3jQwRjRXaAyTqtpsmbc4Zaqy/AlJINkBogP13f4ZcNKEVngybP+6/v/NMGVPRtEZvkeT+Cc4f8DRidW8TWmjwj1Fp/24AxRleDN99NCjEh/D0zAAAAAElFTkSuQmCC", "basi2c08.png", false, 32, 32, "512c3874e30061e623739e2f9adc4eba"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAIAAAHbjwF2AAAABGdBTUEAAYagMeiWXwAAAgpJREFUeJzVliFz4zAQhT/PGDjMYaGBgYWlPlZ4f6E/oTCFLjtYeLSwsDCBuX9wMAcLU+awV6CokSu7kWO58Qns7LxZvX3PK0VJJAnWbwDrHdg8tUl9ZUVq644QQJE7OywEUEyTbdWpx+LG67G48XpY6NBD2lbwbw+fYuUhe2ujobdvbJ6Z6GlqKnLixPseTUUukuyWUrgHSG0Stmab4A2zjZEUsMGWHjdUYaVfdmgqhcNnrW9oL/U6nCo1MZF2S3i7B9jdw8l8GVDzkWdFx7mFLHPC8hJgWkZqUCcFyDOAaci56E76uUHrOTqX1Mn9YxSDFCCfHB00NOhH6tY4DeKR1vJqJcHrtQR/XyTYXEnw8izB00KCxycJyrkEd78luJ1J8PNRgiKX4OqXBPNMgryUACRI7eUYZuVlau9dfGo4XLTYDmpTjOugTm3ySA6aqE3e20E7tcl7ODhFbfLU/sLHpwaYPnR00IX66CCoQXdqgwc4OJc6wEE/6i8dxKBucRCP2nMQm9rkiVStYL+Geqw85Ex8FYmnEc+Kgd+bIZZ52W0c7D2Lu+qiASYm34x4Au2iAbLS4CObQJhoFx/BBLqLdvELTaCfaBf/xgnEE+3iZ/0furRogMkPgOzPABMYXrSLR7oD3yvare8xgcuJdvGOExiHaBcPmMD4RLt4ywTGLdrFnQn8P6Jd/B2kFN6z3xNE9wAAAABJRU5ErkJggg==", "basi2c16.png", false, 32, 32, "a3774d09367dd147a3539d2d2f6ca133"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQMAAAE+s9ghAAAABGdBTUEAAYagMeiWXwAAAAZQTFRF7v8iImb/bBrSJgAAAClJREFUeJxjYICCD1C4CgpD0bCxMcOZM9hJCININj8QQIgPQAAhKBADAAm6Qi12qcOeAAAAAElFTkSuQmCC", "basi3p01.png", false, 32, 32, "1ba59f527ff2cfdc68bb0c3487862e91"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAgMAAAF5E6LxAAAABGdBTUEAAYagMeiWXwAAAANzQklUAQEBfC53ggAAAAxQTFRFAP8A/wAA//8AAAD/ZT8rugAAAFFJREFUeJxjeMewmwGEXRgEwdjMjCE5GUreuAFi9Pais78u+LqAgT+KP4oByPjKAGTw4xZDSCBkEUpIUvc/dBUYIxiYQqugLAQDKvEfwaCSOQC0Wn3pH3XhAwAAAABJRU5ErkJggg==", "basi3p02.png", false, 32, 32, "0528e9ac365252a8c0e2d9ced8a2cc6b"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAMAAAH2U1dRAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAC1QTFRFIgD/AP//iAD/Iv8AAJn//2YA3QD/d/8A/wAAAP+Z3f8A/wC7/7sAAET/AP9E0rBJvQAAALZJREFUeJxj6KljOP6QoU6W4eElhihLhsVTGCwdGKawMcQst5vIAMS+DEDMxADE2Qytp4pfQiSADBGILJBxAaIEyFCDqOsIPbOq3PjdTAYoLcgApV0YoPRdBhjNAKWVGKB0GgOU3o0wB9NATJMxrcC0C9NSTNsxnYFwT0do6Jkzq1aVlxsbv3s3cyamACpXUBBTAJXr4oIpgMq9exdTAI3LgCmAylVSwhRA5aalYQqgcnfvxhAAALN26mgMdNBfAAAAAElFTkSuQmCC", "basi3p04.png", false, 32, 32, "a339593b0d82103e30ed7b00afd68816"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAAEzo7pQAAAABGdBTUEAAYagMeiWXwAAAwBQTFRFIkQA9f/td/93y///EQoAOncAIiL//xH/EQAAIiIA/6xVZv9m/2Zm/wH/IhIA3P//zP+ZRET/AFVVIgAAy8v/REQAVf9Vy8sAMxoA/+zc7f//5P/L/9zcRP9EZmb/MwAARCIA7e3/ZmYA/6RE//+q7e0AAMvL/v///f/+//8BM/8zVSoAAQH/iIj/AKqqAQEARAAAiIgA/+TLulsAIv8iZjIA//+Zqqr/VQAAqqoAy2MAEf8R1P+qdzoA/0RE3GsAZgAAAf8BiEIA7P/ca9wA/9y6ADMzAO0A7XMA//+ImUoAEf//dwAA/4MB/7q6/nsA//7/AMsA/5mZIv//iAAA//93AIiI/9z/GjMAAACqM///AJkAmQAAAAABMmYA/7r/RP///6r/AHcAAP7+qgAASpkA//9m/yIiAACZi/8RVf///wEB/4j/AFUAABER///+//3+pP9EZv///2b/ADMA//9V/3d3AACI/0T/ABEAd///AGZm///tAAEA//XtERH///9E/yL//+3tEREAiP//AAB3k/8iANzcMzP//gD+urr/mf//MzMAY8sAuroArP9V///c//8ze/4A7QDtVVX/qv//3Nz/VVUAAABm3NwA3ADcg/8Bd3f//v7////L/1VVd3cA/v4AywDLAAD+AQIAAQAAEiIA//8iAEREm/8z/9SqAABVmZn/mZkAugC6KlUA/8vLtP9m/5sz//+6qgCqQogAU6oA/6qqAADtALq6//8RAP4AAABEAJmZmQCZ/8yZugAAiACIANwA/5MiAADc/v/+qlMAdwB3AgEAywAAAAAz/+3/ALoA/zMz7f/t/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oKm2AjjINHMBbOwAL4D3P+/hByr8HlAAAAAElFTkSuQmCC", "basi3p08.png", false, 32, 32, "d36bdbefc126ef50bd57d51eb38f2ac4"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAQAAAGudILpAAAABGdBTUEAAYagMeiWXwAAAI1JREFUeJztj80KgzAMx3+BHvTWvUH7KPbB9yhzT7Dt5LUeHBWiEkFWhpgQGtL/RyIZOhLJ3Zli2UgOJAvzgECcs/ygoZsDyb7wA5Hoek2pMpAXeDw3VaVbMHTUADx/biG5Wbt+Lve2LD4W4FKoZnFYQQZovtmqd8+kNR2sMG8wBU6wwQlOuDb4hw2OCozsTz0JHVlVXQAAAABJRU5ErkJggg==", "basi4a08.png", false, 32, 32, "e2212ec5fa026a41826136e983bf92b2"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAQAAAH+5F6qAAAABGdBTUEAAYagMeiWXwAACt5JREFUeJyNl39wVNd1xz9aPUlvd9Hq7a4QQjIST4jfhKAYHByEBhY10NRmCeMacAYT0ZpmpjQOjmIS9JzpOE/UNXZIXOKp8SDGQxOwYzeW49SuIy0OKzA2DlCCDQjQggSykLR6Vyvt6q10teofT0wybTyTP75zztw/7nzPued8z7nZAOZM+M3rYNdAljkTjBumPhCHJUssg5EWGIibOoy0Cuu7h7LtGvj2lqrnb96MCM0P2SENfj4PNh6AS/eBMm005D+xKaR1/Dcs442dyst/gM/2hzR1nmUElr5xQ1nfBw/Nf2NnZyfiygLICmkQESH/Fg9s8ULoNBxNwtEUXHjLMhRzJvTfhk+fCGnrfxDSru6HQ7st49FoRDx5KSJclgF3WqGjA5Z3WYaqW8bpGdDZCX2NkFX1HHQNVD2/sQ829sPK78B/TnXwq6mQpasQ0v4Iy4CI+CMU5Zbu/vAlXa3wwogHEv8BV5PQloTKt8/WKw+0Q9s2XT2+TVfXPgOdBfDr78O92Wfrv3QYoTzQDkt6oOUPunrqKV195xo8lHO2fumPEMX7QLm/C6QL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0ba"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAAEEfUpiAAAABGdBTUEAAYagMeiWXwAAASBJREFUeJzFlUFOwzAQRZ+lQbi7smZBuAabhh6LTRLBwRLBRSpxCipl2EDVlJBB/EgeyYrifH8/jSfj5GSAR2AP7A0fOQ+74mM6MeKTieTk6nv9vz2aa4AKuJ8b1rVTz8uwZ56WBWPXLgqSk7cze5+YjMZ/Xw4YbSDoCAQvHJcFThMJ2kDQLX4n+S4DbL/GTfD8MRemIQobatGgDfIcGrzyoBlExxAbDLVooAGQnJz545nPPY2dRmCodUBdmmDQALBeLeVeJXgLelJo4GIhGOI5mqsGOoFYCEYvGrhokPwuA+SLsQne19Js5L9ZDbkbrABQdH/sUBXOgNoOVwAoG+Uz8M5tWQC1m8sA6m0gAxTPgB+qsgDqdSgDqNepDFA6A5+CSlP0aU5zQgAAAABJRU5ErkJggg==", "basi6a08.png", false, 32, 32, "e80a60aecf13ebd863b61167ba95960b"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAYAAAFU7ZYhAAAABGdBTUEAAYagMeiWXwAAEAtJREFUeJzdmWt0VdWdwH/3xX3lJvckQGgI4o2guBookKUDItCGEh8dAa1g0FmO0I6tIowKtELOWtMub9BZKFpBR60Eyhokg6hQ7eiAyQwgyHQMOEJbqZgjEEMCSc5J7mtf7uPMh72vJMy4nFmdD7Pmw12/tR9n7/9j7/9/730dtm3bAK0mALRaQ4ltt/RJ2jZEIz/9iSRYVknxys2un/1szI9k171PQq02t25unW2vfAWwodXCtqcfBbAsKCleufmxn8IT61ZulqOu3OxoTyoZrK+U4fgaqNX27ZVz10wtyPDhhzVTpzzthh0JgO/Ojb0DteG2Ond4wzRTB39FqvP1z92wIwnwm7eNW7936+sP3TgDrluD9f6hCYnhdeCw7faknCzih1rtxFpZOt4g+Z/KisYryQOBmabuviRuIA9QvW7EYagNV/PduVAbXnGzbH2rvGND5SOmDv9+9bdOtlpgXqW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+tSA8+ezHwAT32mGcBTl9krr2PKAIVrWeEx7YIKgufV21aX8rB8aoqt6x8IrbH0zhBUDBiiezuU32OI3plQdtAQ1gkIVxsivhyKNhki5QF/1hCZzeD5oSHy14HzQ0M4P4T8dYbw/BAymw3hz0LKY4iiTRBfbohwNVgnDFF2EHpnGqL8HujeboiKAegMGSK0pn/A+bylQ2dxRUzKOWqplFte/y6sG7FW6qVeYxZrO2DQbaywAtIrlafVChBqBcjTdKIdghFLTxgQjFgkRkDwAiSWQ3AjJA5BcAYkKiHYAcnVchmnDPBH4GI7DKuCrC7f/u0T4KiWP/uErMvqMMyAixHw10CqDXIGuCJgG+CIgHMG5A+BeyNkl4P3AqRHgL8WUi2QMOIfBSPoCSPOyCkAgYz8/8T3T+ImAF+9aAbw6unokBVQuBfL59NUNHnQ32DpfX4oTRrC3A3aAkP0L4KSnYYYyEKx2xDxbVB0ryESN0PwXUOkTPBrhhCbwLfMEJkbwHPYENnT4B5riPwT4FxjCHsiOI4bwnEc7ImGcK6B/BOGcI+F7GlDeA5D5gZD+JaB2GQIvwYp0xDBdyFxsyGK7oX4NkMUu2Ega4iSndC/yBDaAjB3G6I0CX1+Q/gbkgcdBywd+gKlKalnafOlFeAoPFaLFvDVgmgdylSrtO7l9f8v2ufAfwAZC+9JQJpSCQAAAABJRU5ErkJggg==", "basi6a16.png", false, 32, 32, "4d9d6473bb7403d7f85e3e7537c34e9d"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQAAAABbAUdZAAAABGdBTUEAAYagMeiWXwAAAFtJREFUeJwtzLEJAzAMBdHr0gSySiALejRvkBU8gsGNCmFFB1Hx4IovqurSpIRszqklUwbnUzRXEuIRsiG/SyY9G0JzJSVei9qynm9qyjBpLp0pYW7pbzBl8L8fEIdJL9AvFMkAAAAASUVORK5CYII=", "basn0g01.png", false, 32, 32, "4336909be7bff35103266c9b215ab516"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAgAAAAAcoT2JAAAABGdBTUEAAYagMeiWXwAAAB9JREFUeJxjYAhd9R+M8TCIUMIAU4aPATMJH2OQuQcAvUl/gYsJiakAAAAASUVORK5CYII=", "basn0g02.png", false, 32, 32, "b16bee35e71dce6c08c2447a62ccedea"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAAAAACT4cgpAAAABGdBTUEAAYagMeiWXwAAAEhJREFUeJxjYGAQFFRSMjZ2cQkNTUsrL2cgQwCV29FBjgAqd+ZMcgRQuatWkSOAyt29mxwBVO6ZM+QIoHLv3iVHAJX77h0ZAgAfFO4B6v9B+gAAAABJRU5ErkJggg==", "basn0g04.png", false, 32, 32, "0b40ec7e4231183b51e1c23f818a955f"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAAAAABWESUoAAAABGdBTUEAAYagMeiWXwAAAEFJREFUeJxjZGAkABQIyLMMBQWMDwgp+PcfP2B5MBwUMMoRkGdkonlcDAYFjI/wyv7/z/iH5nExGBQwyuCVZWQEAFDl/nE14thZAAAAAElFTkSuQmCC", "basn0g08.png", false, 32, 32, "f6470f9f6296c5109e2bd730fe203773"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAAAAAAGgflrAAAABGdBTUEAAYagMeiWXwAAAF5JREFUeJzV0jEKwDAMQ1E5W+9/xtygk8AoezLVKgSj2Y8/OICnuFcTE2OgOoJgHQiZAN2C9kDKBOgW3AZCJkC3oD2QMgG6BbeBkAnQLWgPpExgP28H7E/0GTjPfwAW2EvYX64rn9cAAAAASUVORK5CYII=", "basn0g16.png", false, 32, 32, "a14e204bbf905586d3763f3cc5dcb2f3"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAABGdBTUEAAYagMeiWXwAAAEhJREFUeJzt1cEJADAMAkCF7JH9t3ITO0Qr9KH4zuErtA0EO4AKFPgcoO3kfUx4QIECD0qHH8KEBxQo8KB0OCOpQIG7cHejwAGCsfleD0DPSwAAAABJRU5ErkJggg==", "basn2c08.png", false, 32, 32, "512c3874e30061e623739e2f9adc4eba"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAIAAACsiDHgAAAABGdBTUEAAYagMeiWXwAAAOVJREFUeJzVlsEKgzAQRKfgQX/Lfrf9rfaWHgYDkoYmZpPMehiGReQ91qCPEEIAPi/gmu9kcnN+GD0nM1/O4vNad7cC6850KHCiM5fz7fJwXdEBYPOygV/o7PICeXSmsMA/dKbkGShD51xsAzXo7DIC9ehMAYG76MypZ6ANnfNJG7BAZx8uYIfOHChgjR4F+MfuDx0AtmfnDfREZ+8m0B+9m8Ao9Chg9x0Yi877jTYwA529WWAeerPAbPQoUH8GNNA5r9yAEjp7sYAeerGAKnoUyJ8BbXTOMxvwgM6eCPhBTwS8oTO/5kL+Xge7xOwAAAAASUVORK5CYII=", "basn2c16.png", false, 32, 32, "a3774d09367dd147a3539d2d2f6ca133"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQMAAABJtOi3AAAABGdBTUEAAYagMeiWXwAAAAZQTFRF7v8iImb/bBrSJgAAABVJREFUeJxj4AcCBjTiAxCgEwOkDgC7Hz/Bk4JmWQAAAABJRU5ErkJggg==", "basn3p01.png", false, 32, 32, "1ba59f527ff2cfdc68bb0c3487862e91"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAgMAAAAOFJJnAAAABGdBTUEAAYagMeiWXwAAAANzQklUAQEBfC53ggAAAAxQTFRFAP8A/wAA//8AAAD/ZT8rugAAACJJREFUeJxj+B+6igGEGfAw8MnBGKugLHwMqNL/+BiDzD0AvUl/geqJjhsAAAAASUVORK5CYII=", "basn3p02.png", false, 32, 32, "0528e9ac365252a8c0e2d9ced8a2cc6b"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAMAAACBVGfHAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAC1QTFRFIgD/AP//iAD/Iv8AAJn//2YA3QD/d/8A/wAAAP+Z3f8A/wC7/7sAAET/AP9E0rBJvQAAAEdJREFUeJxj6OgIDT1zZtWq8nJj43fvZs5kIEMAlSsoSI4AKtfFhRwBVO7du+QIoHEZyBFA5SopkSOAyk1LI0cAlbt7NxkCAODE6tEPggV9AAAAAElFTkSuQmCC", "basn3p04.png", false, 32, 32, "a339593b0d82103e30ed7b00afd68816"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAABGdBTUEAAYagMeiWXwAAAwBQTFRFIkQA9f/td/93y///EQoAOncAIiL//xH/EQAAIiIA/6xVZv9m/2Zm/wH/IhIA3P//zP+ZRET/AFVVIgAAy8v/REQAVf9Vy8sAMxoA/+zc7f//5P/L/9zcRP9EZmb/MwAARCIA7e3/ZmYA/6RE//+q7e0AAMvL/v///f/+//8BM/8zVSoAAQH/iIj/AKqqAQEARAAAiIgA/+TLulsAIv8iZjIA//+Zqqr/VQAAqqoAy2MAEf8R1P+qdzoA/0RE3GsAZgAAAf8BiEIA7P/ca9wA/9y6ADMzAO0A7XMA//+ImUoAEf//dwAA/4MB/7q6/nsA//7/AMsA/5mZIv//iAAA//93AIiI/9z/GjMAAACqM///AJkAmQAAAAABMmYA/7r/RP///6r/AHcAAP7+qgAASpkA//9m/yIiAACZi/8RVf///wEB/4j/AFUAABER///+//3+pP9EZv///2b/ADMA//9V/3d3AACI/0T/ABEAd///AGZm///tAAEA//XtERH///9E/yL//+3tEREAiP//AAB3k/8iANzcMzP//gD+urr/mf//MzMAY8sAuroArP9V///c//8ze/4A7QDtVVX/qv//3Nz/VVUAAABm3NwA3ADcg/8Bd3f//v7////L/1VVd3cA/v4AywDLAAD+AQIAAQAAEiIA//8iAEREm/8z/9SqAABVmZn/mZkAugC6KlUA/8vLtP9m/5sz//+6qgCqQogAU6oA/6qqAADtALq6//8RAP4AAABEAJmZmQCZ/8yZugAAiACIANwA/5MiAADc/v/+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iTzlPLzkrja0pJo+628KNzOJ2XPrWlhO8jMY5PSuTsN85PQnAD3a1hdhUgYzAL0vgPGTSXFSSXFjq0C5O9VjHpdwoTzglhqpSLGMjLh2ENPK2jvCsm0CSnAmJWZb7Ok8+aEFNwehkYDXBPcvDKjN5UZpSBoKwTWJ8ENqQx3Q5LM8lHx81JZXC3+tYI0LeTSF2TPQdgeHpL3Bi5I5+1huPMVeB40w9AsQKMC4Zyy4ySE7m+BewjWyhIg7x2TGLVkSpgYjDt2LCauFo0KqQxD1sunVCQQkDPTlGdWV6Vzz5MGPBPaeWgGoLEDGt9CIwlGUCGwdglW3pT06myRDLdYkCTzcF35eV1cracu2u5fEIUD2XM9LGw3R2TmrimdeyZUTOikwUso530FWilozSsEVg2oGxKdqwclQA6kHXvrZ5JkImnl52lxteCrou1digNaXvY8lBe2mwWZebMgnXfS0lBnFLwr0K5COwmt5xQC9QrccyW3L6v02p+QDGdVhDy9PcrPx0RQuneLtoP87T8oex66IWw352TmzYB03hmVxjo52PgteEnwYgqBegqcGbk09J907GhG0mvfDpXhMirJPCN+rh0XV+saUQVcFoULNGXPjZvC9nBOZt4uSuedHCxPQceGTgo2bPjxr2aOLRfFyIxjR1LqxvKuyu0zKr0WJcMFipJkutVFtqsoBfiSou3+lChcMCl7biSF7a2UzNxLSuebM+CkYDOrOGBlaxkrLXc1MyY3lp55ye2haUmvwXGV4TxJMr73gDOqAFsZiyfyGhwXkQnZsmqteSGcFxPYO2n58poN/wUgAscPw+GsdQAAAABJRU5ErkJggg==", "basn4a16.png", false, 32, 32, "f1423ebc08979252299ca238656ab0ba"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAAYagMeiWXwAAAG9JREFUeJzt1jEKgDAMRuEnZGhPofc/VQSPIcTdxUV4HVLoUCj8H00o2YoBMF57fpz/ujODHXUFRwPKBqj5DVigB041HiJ9gFyCVOMbsEIPXNwuAHkgiJL/4qABNqB7QAeUPBAE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wBBWASGAZrCtKCJOFJAZwIYlfKMVEC3icSkDvel7gUTYI7LGrFLUA8BU4Bkkmwh/U9BViZWpnqlGxwzJJ0WLPB/1UPMAUN+YjUKEN2tFZqjkFmVMySGYXgN+DfD8Ex8A9LrPDGIRwDbxSiOXA3QXQK3H2iJ+3X5WuDPQrpJUm001cl37Se0v9jkI5q3yfW0N2nY41BVNJ3jayhf1jmEpfBKUHyM7AfXcN0DKxRaIw1xrIlgPSCJP7puDUCVppmtinxCfNxNHNBPiZm5/5vbG7+/fr9ofVvbgb5NJbZ1ny3NmqZZLb5LmS2iRluxsYEZG/T/kdx/xvwP2XY7MOt27XzAAAAAElFTkSuQmCC", "basn6a16.png", false, 32, 32, "4d9d6473bb7403d7f85e3e7537c34e9d"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAQAAAGudILpAAAABGdBTUEAAYagMeiWXwAAAI1JREFUeJztj80KgzAMx3+BHvTWvUH7KPbB9yhzT7Dt5LUeHBWiEkFWhpgQGtL/RyIZOhLJ3Zli2UgOJAvzgECcs/ygoZsDyb7wA5Hoek2pMpAXeDw3VaVbMHTUADx/biG5Wbt+Lve2LD4W4FKoZnFYQQZovtmqd8+kNR2sMG8wBU6wwQlOuDb4hw2OCozsTz0JHVlVXQAAAABJRU5ErkJggg==", "bgai4a08.png", false, 32, 32, "e2212ec5fa026a41826136e983bf92b2"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAQAAAH+5F6qAAAABGdBTUEAAYagMeiWXwAACt5JREFUeJyNl39wVNd1xz9aPUlvd9Hq7a4QQjIST4jfhKAYHByEBhY10NRmCeMacAYT0ZpmpjQOjmIS9JzpOE/UNXZIXOKp8SDGQxOwYzeW49SuIy0OKzA2DlCCDQjQggSykLR6Vyvt6q10teofT0wybTyTP75zztw/7nzPued8z7nZAOZM+M3rYNdAljkTjBumPhCHJUssg5EWGIibOoy0Cuu7h7LtGvj2lqrnb96MCM0P2SENfj4PNh6AS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WcQgLIa4Up74K/FUZbYSICSiu4Wx29CDRCbyvGxcNQuAf8QSh4E3wlk79FcVhrtLb4zUDK+RUFRz7H/pkzgLgH4u7/Y//c2aQd8ID/qGVodaIhW0hQq+zI9FNCFucLOe0hIaeWCjl1u5DBeUIGHhdSu09I7SkhfbVC5j8rpPfrQnr/XUj3NiGzZgg5ekDIsQeFHN8r5PgqISd+ICRfEtL1j0K6KoVUHhUyZ5qQeRuEzHML6T4h5MgX7EjPe/C/SQETOWwWx8sAAAAASUVORK5CYII=", "bgai4a16.png", false, 32, 32, "f1423ebc08979252299ca238656ab0ba"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAAYagMeiWXwAAAG9JREFUeJzt1jEKgDAMRuEnZGhPofc/VQSPIcTdxUV4HVLoUCj8H00o2YoBMF57fpz/ujODHXUFRwPKBqj5DVigB041HiJ9gFyCVOMbsEIPXNwuAHkgiJL/4qABNqB7QAeUPBAE2QAZUDZAfwEb8ABSIBqcFg+4TAAAAABJRU5ErkJggg==", "bgan6a08.png", false, 32, 32, "e80a60aecf13ebd863b61167ba95960b"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAYAAAAj6qa3AAAABGdBTUEAAYagMeiWXwAADSJJREFUeJzdmV9sHNd1xn/zj7NLck0u5VqOSwSgrIcEkQDKtNvYxlKJAstNEIgWIFkuUtQyWsCQW8mKlAJecf1iLLUGWsmKDCgwUMByigC25UKh0SaIXNMpiSiJHZoERAN+kEQ0lR1LkLhLL8nd4fzrwzl3qVVVNI9BHhbfzp07d+537r3nfOeMlaZpCtB8FwCaE+3YmLh9+x/LfStNG/8hfzPfgN6x5iZ98P/B5ubfr98fWn/TD5rvZrbVRt01W/AsQGYuMwf5clqWxnRMMDH4N4LxccFI28O/F3T12tHnnW8JWj9U1PvsUjTv2aL41zr+TxT1fvT0Le97RPGQYPBrRb3fHFU013/ZIr4pc6FaguZIZhxuMkCqNhL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vAJvvRtoxdixZJr7x7NyiIkzMxkXMrSMGLF9eACu6sXWpTUrdva1bWqWUrrU+fFhY+4efXe2LfEYaSzs5r9Sfv3Jm8dOncPrmshi9fTi1bJiQEVCKu4tcrvI9hKVBey9//TYJliCODzpdTkY0+Qg/PnDkzb56Kyvve03IMk1N9fbX891RUPL50SefmzUaf/v7zUVHHeXnfv1exBrqS4U1qam3tnj0Vzx127nRy2rSJbUl4OFDaPf/0lzywN9/s2FFbO+f5c3uo/JMnYmLu+QIgzZCASpg5s2iOkpK9hwc3N3d5+fz57wRit6fnIWLTsoiHR+mZqqqHh7n58nKgbKz1W5QkZ8ljZvZMGyzPrxwby56uhpaq68zMYrS1Ve/fv286YQL72yPogOHI45iY2bP1JwBlP6phSIPTQ52jY8jHjx8xNcMTLV4AAPEBazSls8MzAAAAAElFTkSuQmCC", "ccwn3p08.png", false, 32, 32, "1a63f18f17006d850d1c041e49a7721f"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAAAgAAAAgCAIAAACgkq6HAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAAlwSFlzAAAAAQAAAAQAMlIwkwAAASdJREFUeJxV0mFx7DAMBOCvmRAQBVMIhVAIhaNwFPogvFI4CA2FQGggVBDcH3acNpMZja1daVfWWwWClWRvZ3OPGwGSA6YOjw5QepxgcX+lg2ZYKc7BXNip1G9f1bP6X9WqvqtMregBTk691NTCcbUYCXX19d0qbuqyVvVTDZNwdjWFJS+/c/PEw/5QZNnTGa1HIsNHeAUlEc0gztheyguRLlWN8XRs2Vv0Hm12xRGt5j2rS/qY753w6+oPI+OefuPNA/KyHuISZZYCJf+VyKVrlINR8nyw3I95MRy2XeCMwSiwK0FGSwxGODk4yyV8lgpP0o612UlTU3EtjXL5nNozrQTLr8RbxZMix9Z9cDQfxz1B2kK0WY0dabc5EtlRf0B1/Ku63McfFzN1pnMg8LcAAAAASUVORK5CYII=", "cdfn2c08.png", false, 8, 32, "dbfdad37268883ddeeecc745da77130c"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAICAIAAAAX52r4AAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAAlwSFlzAAAABAAAAAEAH+hVZQAAAOtJREFUeJx9kmuxwyAUhL/M1MBawEIsxEIsxEIs3FiohVjAAhaOhSMh9wePQtt0hwEG5rx2d7r4QADVxbg3eN3zxbr7iEc5BTOssJaHFtIHeleo9RDao8EBCawvIFgglN5dRIjwLLNsuHBh3RRy5AQgwSn8D2aYA+TlEEuZB+sr0EpeHJE/zl1PtshGrMPICAdz3GFNzIJoJANr8+foE6xRdAeBMJGQqhSGnE6kOzjAdPUULfjyRtECAQfXIEJmCYMY8D1T5HDU1JWi6WqdhkFkH63xZhCNIr8oPsAGkacvNu2d8YOH3ql+a9N/CM1cqmi++6QAAAAASUVORK5CYII=", "cdhn2c08.png", false, 32, 8, "650268c7196860898cbe701005cf2407"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAAlwSFlzAAAAAQAAAAEATyXE1gAAAHtJREFUeJxFzlENwkAURNFTgoFnYS3UQisBC1gACSCBSsDCVgIroSuhlbB8NIX5mUwyubldQzCQ2KjMcBZ8zKFiP0zcaRd53Stb3n2LNWvJSVIwX/PoNvbbNlQkJ0dqRI0Qxz5Qg+VlffxQXQuyEsphFxNP3V93hxQKfAEqsC/QF17WrgAAAABJRU5ErkJggg==", "cdsn2c08.png", false, 8, 8, "9e580d6237f77bfa8e49cfef19236bcb"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAAlwSFlzAAAD6AAAA+gBtXtSawAAAmdJREFUeJyVluGR3CAMhb/bcQNqgRZowVeCr4RLCZsSsiXcteASQglxC7RACckPEEbYeDeandkZDHpP0hPi7S/P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soSI4AKtfFhRwBVO7du+QIoHEZyBFA5SopkSOAyk1LI0cAlbt7NxkCAODE6tEPggV9AAAAAElFTkSuQmCC", "ch1n3p04.png", false, 32, 32, "a339593b0d82103e30ed7b00afd68816"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAABGdBTUEAAYagMeiWXwAAAwBQTFRFIkQA9f/td/93y///EQoAOncAIiL//xH/EQAAIiIA/6xVZv9m/2Zm/wH/IhIA3P//zP+ZRET/AFVVIgAAy8v/REQAVf9Vy8sAMxoA/+zc7f//5P/L/9zcRP9EZmb/MwAARCIA7e3/ZmYA/6RE//+q7e0AAMvL/v///f/+//8BM/8zVSoAAQH/iIj/AKqqAQEARAAAiIgA/+TLulsAIv8iZjIA//+Zqqr/VQAAqqoAy2MAEf8R1P+qdzoA/0RE3GsAZgAAAf8BiEIA7P/ca9wA/9y6ADMzAO0A7XMA//+ImUoAEf//dwAA/4MB/7q6/nsA//7/AMsA/5mZIv//iAAA//93AIiI/9z/GjMAAACqM///AJkAmQAAAAABMmYA/7r/RP///6r/AHcAAP7+qgAASpkA//9m/yIiAACZi/8RVf///wEB/4j/AFUAABER///+//3+pP9EZv///2b/ADMA//9V/3d3AACI/0T/ABEAd///AGZm///tAAEA//XtERH///9E/yL//+3tEREAiP//AAB3k/8iANzcMzP//gD+urr/mf//MzMAY8sAuroArP9V///c//8ze/4A7QDtVVX/qv//3Nz/VVUAAABm3NwA3ADcg/8Bd3f//v7////L/1VVd3cA/v4AywDLAAD+AQIAAQAAEiIA//8iAEREm/8z/9SqAABVmZn/mZkAugC6KlUA/8vLtP9m/5sz//+6qgCqQogAU6oA/6qqAADtALq6//8RAP4AAABEAJmZmQCZ/8yZugAAiACIANwA/5MiAADc/v/+qlMAdwB3AgEAywAAAAAz/+3/ALoA/zMz7f/t/8SIvP93AKoAZgBmACIi3AAA/8v/3P/c/4sRAADLAAEBVQBVAIgAAAAiAf//y//L7QAA/4iIRABEW7oA/7x3/5n/AGYAuv+6AHd3c+0A/gAAMwAzAAC6/3f/AEQAqv+q//7+AAARIgAixP+IAO3tmf+Z/1X/ACIA/7RmEQARChEA/xER3P+6uv//iP+IAQAB/zP/uY7TYgAAAgBoSVNUAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAARNzPXjAAABsUlEQVR4nA3BBwAIBBAAwEeojEhkKzszCWVrWGVn7xWK0LD3Kio0aJgNq2zK3qOMhp2VWTKy9767mML3FOZX+rKXptwlHuQBBnODnrzFea4TaUjJQ0zlKjs4wAUiG+n5iAa8S0U2c4p4midIS/A/01nOEeI58vMFc+jEo/zIPqI8xchOM/6hN1+ynXiVMkwmMa04wVB+IV7jBYrwE/upR3fWEE2oyiza0pgVtGcl0YaNPM/PbKMQDVlIrKYoIznKVpZwmtnEJkryOB9Ti9z8xbfETsrxFS+xlvdZz9fEISqTi/+oxCUW8xlxkhp8w6csozXfMZx4k2o8xTgqcJACpCBusoeldKAUr9CfpEQ71jGNYTxLHZIwkPiN+XzCDPLRiA+4R5QlBwPoShZakJoexCQe5j1GkY43+JwrRHKu8TrzSMbbZOUdohvHqMufJKQX4zlDHOYPqnCROwyhIB2J2qyiOKm4zIfM5DixiB/ISWnOMoYStCSq8zILuMW/3GYEzYm5PMNEMvE3iXiMXURmMjCaF9nNI4ylPjGIfvQhAb+TkSfZQpyjC53JywbyMIGa3AeBG/4Qh5bI4AAAAABJRU5ErkJggg==", "ch2n3p08.png", false, 32, 32, "d36bdbefc126ef50bd57d51eb38f2ac4"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAAAAACT4cgpAAAABGdBTUEAAYagMeiWXwAAAAd0SU1FB9ABAQwiON2c/4AAAADISURBVHicXdHBDcIwDAVQHypACPAIHaEjsAojVOLIBTEBGzACbFBGYAPYoEY9lQKfxElR4hwq58V17ZRgFiVxa4ENSJ7xmoip8bSAbQL3f80I/LXg358J0Y09LBS4ZuxPSwrnB6DQdI7AKMjvBeSS1x6m7UYLO+hQuoCvvnt4cOddAzmHLwdwjyokKOwq6Xns1YOg1/4e2unn6ED3Q7wgEglj1HEWnotO21UjhCkxMbcujYEVchDk8GYDF+QwsIHkZ2gopYF0/QAe2cJF+P+JawAAAABJRU5ErkJggg==", "cm0n0g04.png", false, 32, 32, "cf2f1ab4f34d0c70f15f636ef584d53a"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAAAAACT4cgpAAAABGdBTUEAAYagMeiWXwAAAAd0SU1FB7IBAQAAAB4KVgsAAADISURBVHicXdHBDcIwDAVQHypACPAIHaEjsAojVOLIBTEBGzACbFBGYAPYoEY9lQKfxElR4hwq58V17ZRgFiVxa4ENSJ7xmoip8bSAbQL3f80I/LXg358J0Y09LBS4ZuxPSwrnB6DQdI7AKMjvBeSS1x6m7UYLO+hQuoCvvnt4cOddAzmHLwdwjyokKOwq6Xns1YOg1/4e2unn6ED3Q7wgEglj1HEWnotO21UjhCkxMbcujYEVchDk8GYDF+QwsIHkZ2gopYF0/QAe2cJF+P+JawAAAABJRU5ErkJggg==", "cm7n0g04.png", false, 32, 32, "cf2f1ab4f34d0c70f15f636ef584d53a"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAAAAACT4cgpAAAABGdBTUEAAYagMeiWXwAAAAd0SU1FB88MHxc7O3UwH+AAAADISURBVHicXdHBDcIwDAVQHypACPAIHaEjsAojVOLIBTEBGzACbFBGYAPYoEY9lQKfxElR4hwq58V17ZRgFiVxa4ENSJ7xmoip8bSAbQL3f80I/LXg358J0Y09LBS4ZuxPSwrnB6DQdI7AKMjvBeSS1x6m7UYLO+hQuoCvvnt4cOddAzmHLwdwjyokKOwq6Xns1YOg1/4e2unn6ED3Q7wgEglj1HEWnotO21UjhCkxMbcujYEVchDk8GYDF+QwsIHkZ2gopYF0/QAe2cJF+P+JawAAAABJRU5ErkJggg==", "cm9n0g04.png", false, 32, 32, "cf2f1ab4f34d0c70f15f636ef584d53a"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAIAAACsiDHgAAAABGdBTUEAAYagMeiWXwAAAANzQklUDQ0N0DeNwQAAAH5JREFUeJztl8ENxEAIAwcJ6cpI+q8qKeNepAgelq2dCjz4AdQM1jRcf3WIDQ13qUNsiBBQZ1gR0cARUFIz3pug3586wo5+rOcfIaBOsCSggSOgpcB8D4D3R9DgfUyECIhDbAhp4AjoKPD+CBq8P4IG72MiQkCdYUVEA0dAyQcwUyZpXH92ZwAAAABJRU5ErkJggg==", "cs3n2c16.png", false, 32, 32, "023541189afc3aa4ae617158b59fe635"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAABGdBTUEAAYagMeiWXwAAAANzQklUAwMDo5KgQgAAAFRQTFRFkv8AAP+SAP//AP8AANv/AP9t/7YAAG3/tv8A/5IA2/8AAEn//yQA/wAAJP8ASf8AAP/bAP9JAP+2//8AAP8kALb//9sAAJL//20AACT//0kAbf8A33ArFwAAAEtJREFUeJyFyscBggAAALGzYldUsO2/pyMk73SGGE7QF3pDe2gLzdADHA7QDqIfdIUu0AocntAIbaAFdIdu0BIc1tAEvaABOkIf+AMiQDPhd/SuJgAAAABJRU5ErkJggg==", "cs3n3p08.png", false, 32, 32, "6b15613bf70a37c37de24edfb8f6d1df"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAABGdBTUEAAYagMeiWXwAAAANzQklUBQUFGCbeQwAAAGJJREFUeJztlbERgEAMw5Q7L0EH+w/Fd4zxbEAqUUUDROfCcW1cwmELLltw2gI9wQgaastFyOPeJ7ctWLZATzCCjsLuAfIgBPlXBHkQ/kgwgm8KeRCCPAhB/hVh2QI9wQgaXuXOFG8QELloAAAAAElFTkSuQmCC", "cs5n2c08.png", false, 32, 32, "3211fb3ede03caf163fe33b4cf6d78f6"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAABGdBTUEAAYagMeiWXwAAAANzQklUBQUFGCbeQwAAAGBQTFRF/xkAQv8Axf8AAP97AP+9AP//AP8AAMX/AKX//94Apf8AAGP//5wAACH//1oAAP86/zoAY/8A5v8A/wAAAP9aIf8AAP+cAP/eAOb///8AAIT//70AAEL//3sAhP8AAP8ZRy+F9QAAAEtJREFUeJyFwQUBwAAAgDDu7u79Wz4CG5NA9YJW8AhqwSUoBIdgFISCUvAKBkEgWASp4BN0glkQCVZBLNgEiWAXZIJccAoqwS1oxA/GcT4B7dbxuwAAAABJRU5ErkJggg==", "cs5n3p08.png", false, 32, 32, "3211fb3ede03caf163fe33b4cf6d78f6"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAABGdBTUEAAYagMeiWXwAAAExJREFUeJzt1UENADAMQlGa4GPzr2pT0olo/mkgoO9EqRYba9HADhBgmGq4CL7sffkECDBNie6B4EGw4F8R4AOgBA+CBQ+CdQIEGOYB69wUb0ah5KoAAAAASUVORK5CYII=", "cs8n2c08.png", false, 32, 32, "023541189afc3aa4ae617158b59fe635"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAABGdBTUEAAYagMeiWXwAAAGBQTFRFIP8A/x8AAP8fAP/foP8AAP8/AP//AP8AgP8AAP9fAP9/YP8A/wAA4P8AAP+fAOD/QP8A//8AAMD//98AAKD//78AAID/wP8AAP+//58AAGD//38AAED//18AACD//z8As4GzYwAAAEtJREFUeJyFwQUBwAAAgDDu7u79Wz4CG7UgEHyCR3AJDsEimASDoBFsgliQCypBL1CZIBQkgkJQClrBLogEqaATjIJZsApOwS14xQ8p4j4B+PNT2QAAAABJRU5ErkJggg==", "cs8n3p08.png", false, 32, 32, "023541189afc3aa4ae617158b59fe635"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAAAAACT4cgpAAAABGdBTUEAAYagMeiWXwAAAMhJREFUeJxd0cENwjAMBVAfKkAI8AgdoSOwCiNU4sgFMQEbMAJsUEZgA9igRj2VAp/ESVHiHCrnxXXtlGAWJXFrgQ1InvGaiKnxtIBtAvd/zQj8teDfnwnRjT0sFLhm7E9LCucHoNB0jsAoyO8F5JLXHqbtRgs76FC6gK++e3hw510DOYcvB3CPKiQo7CrpeezVg6DX/h7a6efoQPdDvCASCWPUcRaei07bVSOEKTExty6NgRVyEOTwZgMX5DCwgeRnaCilgXT9AB7ZwkX4/4lrAAAAAElFTkSuQmCC", "ct0n0g04.png", false, 32, 32, "cf2f1ab4f34d0c70f15f636ef584d53a"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAAAAACT4cgpAAAABGdBTUEAAYagMeiWXwAAAA50RVh0VGl0bGUAUG5nU3VpdGVPVc9MAAAAMXRFWHRBdXRob3IAV2lsbGVtIEEuSi4gdmFuIFNjaGFpawood2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Duhw+dJAuNzrEKz8bNlzoizBx9XHHl09SFP5mRoj4WzEAsGOxmS9T6NKyrkNPjI8FEFsiUCyJi2X3Lk0dXXFH2Chl4z1ys9Uv7MlA9MGg/n3P8jAPPoJ4XkFAvpMo96Auom3E1DME27QUCGhfRXZ54AdNqHwrVDBQKyzOKLnCgpyhrjHYFeWw2Q4GRTFCg8j3oWXvaiiNcQmI3lIXOLGKV5NcW7XBgMliWWP4Bfj5Xj5+d0mLKOcpUa/Le1ALghLGRkJegqljYAQJnKGU10eR7lLwD/kXl0LQA6BMtT2eUFK0/sMo9uvbr+CztK5Y3mPSskAAAAAElFTkSuQmCC", "exif2c08.png", false, 32, 32, "7acea6df2b0e2a7613981decc569b2fb"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAAAAABWESUoAAABBklEQVR4nIXSL0xCURTH8a/gGHNjBjc3AoFioFhIr7z0molmsxFpVCONSLPRbCYSiWKxWAwWN4ObG5ubcwzk6f3jds71hXPr/eye3/3dy/VkOruZ394tlqv7h8en55fXt/f1x+fXZrv73pflD2NDMDIEQ0NwZQguDcHAEFwYgkILwkoEuRJQFWQi3Jafkgr6IiDmAJWDcxEQkroTVFJ6IsAn9SHUXTgTgX+5kFLdlq4I8DlwZ6g+6IgANwV/W9UYbRHh9DBFdcqpCL8f+1CtcyLC7Sd9BMGxCEj6iIKWCKIg9vEnOEpFWPr1aVZF8j9oJCLLi38/iENDUDcENUNwYAgsgSWwxC/EfcpYUKbOtgAAAABJRU5ErkJggg==", "f00n0g08.png", false, 32, 32, "f34b8a71205dc26cd37d58fb19179172"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAJcklEQVR4nHWWb3BU5RXGn/fe3U02sMmGsAksSbMB2Qyw/BGWprho0EWCsIBAdoIM8UaHENiWhA6zBAditoIJDGsiomQ7ILGUTcJIQ2GBtFaMt/yJoIFlKFKoekPAoEgvFK18fLpMKDjank/vnA+/55z3n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BVsRIqoREbcVbsxE4aevf658CNU4zYH/Up8KvTUxFbSVu4i0RZgx76oVzBT7gqX/EV3/ANPyt0fCcMhYEfxEXv6TPgx6fHE7aSt3DVpCRM9rxUUMFNqKKKq1LDNTTjOq7LDdxAg3987TbwrdPDGcvbv3zeYZTj0cQzyKBAgQkqVFShQYMZOuowYHD7SYB2epAKyvEovp3IkokiiphEFdWpiuZoYnZ0qTuGu339n0A4ff3BKii7o/hmxUR2mKM4Fc/kqJ7qqJ7maZ7Zqwe6/+LZjwD3yTNawtEAZwmUe5wgvtFJDvNkj3mKVwlMnhrOtEgLzFE9fvHC3wF36yeMqCXf44FopHKciCcGKZA85snrEkeVwBSpkZqokZZomTmdXnobcDd/xjBG1lLsKBA7eyBesnj02rkgBSySIxYpUSUxJWqmJqrRMs1OP38LcO+/yiiMiVG0VDsKZOXiCvHINaInRVIgRSyS1yXOlMyUqcbv3+GqR7f+zKhaZjsKxHbSENc6MRAjaSVhiZyxTDGKMRlv/eXqgpt/Y3TGrGXYUSAXIYh5xntiJEZSOmNGXr+bQilME7VSq2qlNTaBsAmEMbQs99qggLCCD3hPiMRITMS1xs6XJStYoUyUSqlMlZ1A2ATCPDQW2wsEikOEhPe4rcNHYiKsNUbM5/3OBZvIlVKxyk4gbAKhDs3LXUIQLuAc8viA8/iIj4SET8R0voOc97uQJ1LlKBA2gTANylBd9n4QchseF3AeF/ERn84Ew2fiut+FOBErR4GwCQQb5KGyXMwgVi4d2joU8QmXcGl/zyEUwoSvHAXCJhDSIA7ysppB676dO9g65FFEEZfQWmMo49cVPwuEo0DYBMImEEvngq2DrYOAPEQUUYKE0vHOcxAIR4FwEYhf/gtC7nstgnuX5wAAAABJRU5ErkJggg==", "f01n2c08.png", false, 32, 32, "a9081889af0c30f206d793919792a0b6"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAAAAABWESUoAAABKklEQVR4nIXRL0uDURgF8MP5OBaLIIggCIJBDAODTdgHGCxYh0kwDFYEw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2yzDRBRFCe0MWKvogVPggTAxAiPgHY2dcQrz+CzkAAAAASUVORK5CYII=", "f03n0g08.png", false, 32, 32, "bab714eea8df8ab97f4095442247c9e1"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAE0klEQVR4nH2WXYhUZRjHf8+8Z2fnzNcZv1r7kCyyD7Gy1CiN2kK3kAXDQjJCKk2FCr0QDAp6D3hjflB30lV30k1Xe9FtIMEiXlh2YRBi5UWCre7sfO6cfbo45505M7O7w2GY4Rze3/v/P8/7/I9RcjZXsMWKray2q9fa+x+y69bbRx6zG560GzfZpzfb57babS/al162r4zb13faiTft7km75y279x2771373vv2wAf24CF75Kj95FN77Lg9ccKe/Nx+8aX9ytpTp8yxdcYvRQRQhjKUoARFKEIBCpCHPPiQc9+jkHXfIzACHnhgwEAGMiAgAOboU55W8IOIgARTSmG6jEIKk0thYka2n2F6DPPh84ZANMBfkWKUHaCL6erIp3R0pSytw+zfnqGsVNBA/ZUDDKUozi6lIMnqvpITp0PJClkYUUbAEzzwFAMZIYN5+9UMJaEMFdEAf3WaIZSUklCEglBQ8kIB8oKv+EIORsUxJPFqRPDE6RAzuStDkT7GmiUYRcfIgy8pHcKoMuoYiY6EYSbeyCQmlIWSY4wty4i9WkZHimHGd0vSJHFJy0qABuqv7cQMCf4Kz/8bnr8VnrsZnvszPHs9PPt7eOZqeOZK+PW0Pb2l11qj/a01Ah5m4/ZMA+pQgzmkCrMwi9xVmn40C9+ELZb+fGafbUArdc3DPLRhHiIw67dJA6lDHeaglmLMKHU/+sgWDtrgkF31sR07bB88Yh/+LrwVr35N99WhAQ1oQtMx2g4zD+a+zdJ0D9USHTgGM6o1v3PP/a3CTvktXv0n3VWDeGdpRhtppxgm2EiLAYY4hszCjFL1o5hxWP6OV7+g2+bchgYATWghsY42mNzj0oYm0oKG29EwY9aPzko1Xv2EbqjCHMy555fRYcyjya8mEt9zNZdaijG1otMt7C/hf5fC2w/bVV0Raa8Gd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RpkkqS0+gqnSrnynmCMwBI5NDybz2JHDZCdRKKUkkTTpwcUMpjBTuuDnpxqCYxfbc4QeGjp56oa8VfLqFV3HTWogMFfmwftHD8mx2aaX74ZvjQ1sYA1rCLCCD7CEBo0eOzQQpgPFDO1Yzb0KewAGx3ZHvofxs+ke7iFAGCzmyNAnENvtJJFpS+j8cU+m72FITw8WduCGfThYZ/quBrITDUQbQutzHTm0pwcBBZPlysI2+xIp2MtqrJAy4xvtrSI0fiwJhyrapzOPmzBDrmympoNazCgfY9WCVeW1QAtc0oz2jPUQaQR2g92ZIcgpzYOqcgcrCIWnTFbzgIPsNw+OyjEP8qUMCwrW/wPZ2mq+jvKj/AAAAABJRU5ErkJggg==", "f04n2c08.png", false, 32, 32, "82a6745345706f5c5a662a94fdd0ea29"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAAAAACT4cgpAAABcUlEQVR4nHVRsU4CQRDd5Y5kj2oXtDi7u1IbNFRWiom1iYk/IMYfMIpfQPwCPf0CobAzAQmxMkaOxMLCgl3srNzdCtaCrLNgMEGdu8zt7cy8eW/GQ3PmT7xXpsj2n2e3C3snYAeb7oxdfDdmkKFEF3IycLEVRwwsH5dcFGDKS2EYBAFCJvvmQMt5xjCUIBvJe5dzmDTaaa+fdlvJcRFAF/fjmDKIKCvE000GrTIG/wxezFgBQEvLYY5ARmCIRurB9xiUOTaIKipZEfnVqzaX0lopebdZ28DZo7Vo2lYrJXkzM+VPvx2w8NbDfECAJjLQWXF/fh4oe9pIBWAC6kfaOt/5DWqt1giUIefh7OGVkGFMjEF2ZN5lzx8rJ9yhaXgUzGz7rJFy4Mp52rqo/CVfKqu00nbyGYB8W8gR+kkMtB2KWzfTTkQpU473oD8lu11NLuv166RW+W9R446QQgzEZLmeqxm+kpGSL48/2x/fzdR/AW8Fs1uE53SkAAAAAElFTkSuQmCC", "f99n0g04.png", false, 32, 32, "207c771481d8e0786644d1d3ccdc1253"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAAAAAAGgflrAAAABGdBTUEAAIi4vcVJsAAAARBJREFUeJy11U0KwjAQBeBXrFpFUCjFXcFTNJfwtF4itxBcCCKCpeJfbXUhQTMTE0N0FoEZ6Os3pbTR/Q6tokjvpdT7otD7uGn0wXwOa9EbsIAsswdQMQsYjwMFo1GgYDgMFAwGnoLbTR/0+4GCJAkU9HqBAtcKTkG36ynwXeH/AlcAE9T1jwVxrPdt6ymgr/Ll4hDQACqgAU4BDaDFBNerX8DXgtkMWC7VVAj1eWUCumOnAwB5vlqpExBCSnUygXmF9fq9k9IiOJ9NAgCYTjcbtYBFQFdQzyBNdzsYiglOJ5NgMgHSFNjvhZDyfQUmOB5NAVWl+udlrx8cExwOpoDPxQRl6RfABNttoGCxCBM8AHUVjIYrRN23AAAAAElFTkSuQmCC", "g03n0g16.png", false, 32, 32, "33bca103ab06d5288fc5a40d52b46648"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAABGdBTUEAAIi4vcVJsAAAASlJREFUeJzllk2KwkAQRqsx/kQEERR3LrzEeAiP6yH6FC4EFzKCGGRGZ0bjwojJJI/kw7iyVpVKpV+/LgLtYisOZ/DGu+L6R3E5OANgPi+uL6DfgIuA0YhWggBhBPT7IoAM/qC/1xMBqkG3KwLUGYShCFANOh0RoM6g3RYBqoEMUA1aLRFABrUBVINmUwS8n0EQiAAy+IV+NLhAXTUIyeAH6qoBHhEByID6Xz4DGfCMwXTqzGy5zK4xMzMzf38kg1LAZOJWqzidJKv7bEIGJwA0GkmyXsf5ovnKBgT4N4Px2G02qU1WNzgC4LFZs+HQbbd0Q7sHGXyXAQYDd2OY2W4XJ1vOHxEZfJUBoij7qc8ltyCDAwBq+w/20J+eQaUgg8+6AGRAt+W6DK5anlkjB1vfagAAAABJRU5ErkJggg==", "g03n2c08.png", false, 32, 32, "5ab30d7747a459c1051650a1351a4519"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAMAAACBVGfHAAAABGdBTUEAAIi4vcVJsAAAAB5QTFRFAAAAAP///wD/AMjIra0A3d0A//////8A/93//63/MbogiAAAAGNJREFUeJxjKAcCJSAwBgJBIGBAFmAAAfqoCAWCmUAAV4EsQEcVLkDQAQRwFcgClKlg6DA2YEZS0dDBYcxsgGIGB1wFCKSlJaTBVUAE2MACCBUJDGzMQC1IKtLS4O5AFiBTBQBS03C95h21qwAAAABJRU5ErkJggg==", "g03n3p04.png", false, 32, 32, "cab490ee86d478d165f2a516345d0ff0"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAAAAAAGgflrAAAABGdBTUEAAK/INwWK6QAAASJJREFUeJytlDkOwjAQRSciLAEkmjQpUtJwAE6AT+0bcAAaCgoKmhQgZWEJCUVkhZkxGVnGhaX5Up6fvxQHbQtoBQGetcbzbofnsK5xsN3C4KIHMEAcDwOocfh+42C18jRYLh0NKGCxcDR4vXAwn3saRJGjAQXMZp4G06mjAe1AAjADV4DYwWTiaSABxA6cDZ7PPxuMx3huGkcD+i/c74IBBVADChANKIAu0SAMhwHM4PGwG2w2AIeDSZUyzyszsAPW6+PR7ABKaW120aC7wun0PX0/7cyAttx3kKbnc59351sMqsoOSJLLhX9uMShLHHQdxDFAkgBkmVJaK9XXyAyKwmZwvZpZa6GDPLdf4ddiBrcbDkajYQAzyDJPg/3eDUANPik0iSilDmOAAAAAAElFTkSuQmCC", "g04n0g16.png", false, 32, 32, "e38a1551172886575b1d91af694ecfde"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAABGdBTUEAAK/INwWK6QAAATBJREFUeJzVlj1uwkAQRr+VzJ+MRAMFBS0FB+AG8aF9hByAgoKGgoJIKFIifpLIFBiwg1+cT3GTKaz1eHfevJ3GIVN1BMGXNFTnn6rT0ScA5vPq/DPsF3ARMBxSJQgQRsBgYAJcg37fBLgGcWwCXINezwS4BjaADD5gf7drAlwDG+DOoNMxAWRAV9RumwB3Bv/fwAa4Bq2WCSCDE+xHgy/IuwYxGRDANcArOkCeDGwABRkcmwL8xWA2C5IWi3KNRJKUXl9dgyjKF9NpWC6z4iKvnpYXZEAzuwFWq+wxeW/8FmRAgG8zmEzCev3QZFIgkcEeAPdmpfE4bDY/Vhcb1AJGo3BhSNpus7xucmWobgbvdYDdrnw0LTyLQQZvdYDfBhm8NgUgg5emAGRAf8tNGZwBkU1XhkiDotcAAAAASUVORK5CYII=", "g04n2c08.png", false, 32, 32, "daa8561d65a6598e69d6ddb060d802b7"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAMAAACBVGfHAAAABGdBTUEAAK/INwWK6QAAAB5QTFRFAAAAAP///9T/1NQA/wD/ALq6//////8A/5v/m5sAIugsggAAAGhJREFUeJy9zsEJgDAQRNEhsLnbgaQFW7CAXOae07ZgC7Zgt04IhPWq4D8Oj2VxqF1RLQpxQO8fsalTTRGHH8WlipoiDt8ECqsFsZZEq48biaxD9NybkzbEGLILBNGQDYjCff4Rh5fiBou1fg11pxGVAAAAAElFTkSuQmCC", "g04n3p04.png", false, 32, 32, "0f81d4307736954402890d7203244bd0"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAAAAAAGgflrAAAABGdBTUEAANbY1E9YMgAAAQpJREFUeJyt1b0KgzAQB/AI0X4gSMcOzu3SxTdpHvQexdk+QRdBCqK2VewgQXOnCUeaQS8B//nlQA3GURgjCMw5gDm/3825/H7NhctFWAfeQPa9uXA62QOwmAiShCnAAXHsKTgemQLcA1eAU3A4MAWfDy/AKdjvmQJuABHgI+x2ngJXwP8F3ACnIIo8BThgGJgC/DK1rUPwftsFOIAIXAF4OAVhaA9gCLIsz3WtlP68EkHXrQtut7lWCkBfiWAroCiuV10DWAS4y8sm6toqwAHLJq41lAiaBi3I6X4+C5Gmz6dSAMsjEAEO0LuW5XSfHpt/cERQ19tHWBtE8HrxAoigqtCCZAoeDz/BD+1fhGYCQbPgAAAAAElFTkSuQmCC", "g05n0g16.png", false, 32, 32, "5f67c34aadb2f3a602fea6d4ad14fa6d"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAABGdBTUEAANbY1E9YMgAAARVJREFUeJzlljkOwjAQRcdS2EJEQUdDiWiochI4aG5Cj7gADaJA7ItCwSJC8iR/cMdUzvjHL8+xorjcqssZzGSuuj+ubkdnAAwG1f055A24COh2aSUoEI4ukO90RIBqkCQigAwI0G6LANUgjkWAatBqiQDVQAaoBs2mCCCDE+QbDRHwfwYyQDWo10UAGQTbomAGV+iTwRHyCQH20A9mQADVoFaDCSoyIECwU3SA/IdBmrrptLjGxMzMsuflLwajkfvo2OS59Gvwi8Fslg+HruCUeRvQoSi/5ELH3+BLQLnIYOcB6PWcmfX7brHIH49c3iIy2HoAlsu3u7PS4F5ksPEAeBUZrCEfRSKADFaQD2ZAf8uhvkU3ajlNmZwVLFcAAAAASUVORK5CYII=", "g05n2c08.png", false, 32, 32, "30cda048c618598b39f96c40141851fa"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAMAAACBVGfHAAAABGdBTUEAANbY1E9YMgAAAB5QTFRFAAAAAP//zMwA/8z/AK6u/wD/i4sA//////8A/4v/c+IkkgAAAFtJREFUeJxj6ACCUCBwAQJBIGBAFmAAAfqoUAKCmUAAV4EsQEcVaUBgDARwFcgClKkwMHZxYEFWwWDswuKAQwUIlJcXlMNVIAsgqWBgZwFqQVJRXg53B7IAmSoA1Ah4O0rtoFUAAAAASUVORK5CYII=", "g05n3p04.png", false, 32, 32, "2be19a2ad1bdba9734899e453a27625b"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAAAAAAGgflrAAAABGdBTUEAARFwiTtYVgAAAPhJREFUeJzNlbsNhDAMhg1C4SVomYABqFiASchcmYkxEC2Ip4S4AuVEbCAXpbm/SUzx+cMC2TkOUOI4ai2EWte1Wnvbpj7IMngNbkAAafoOwMYEkCSWBnFsaRBFlgY6gNYgDC0NdACtQRAYGqyrGeAPDUwBWgPftzTQAYwN9t3QAP/O02RpgAHEYFneATjEwBSADdwFhX1TVYwxBgDA+dVAzaNBWd7baGdw9gRomqKQ92vIDOb5HoDvnJ8bghj8BuBcIrCBO6HIEeY5QJ4zxjmAEELIHXWgePhDkV3b9jzlapMnmcE4Pr/CXcgMhsEMQAz63tKg6+wMPgLFodTQLHMsAAAAAElFTkSuQmCC", "g07n0g16.png", false, 32, 32, "cdd82be241cbfadbceffc98d967dfe30"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAABGdBTUEAARFwiTtYVgAAAQtJREFUeJzVlkEKgzAQRSciiaK49QS5gCsv4EnqsXImryHdlhZtKdhFK1U6HzM0YDvMIowhz+dXUE3ElyJwxSl+fuDH8Q0AypKfH8F+AlwIKAohAAhDQJ6jk0BJDbJMCJAaiAFSgzQVAqQGYgAyuIYC7GaAAEkiBCAD9IjEgJ8zMEYIkL5F/28AAXcwlxoUUgAyGMF+aHAB890yQAZaCwHAIBqJ2DZm1U2jnotXtZwB114Gda22nVAGgweg66aqUhsAlAECfIbMxN4SuXn9jQE/adcMYBANRGxr/W5rFRFZq7Sez3XzuUsDrmP03Szvt+8X/o74NcrAB+BVKINzKAAyOIUCIAP0MxvK4AEWgFoVP+GhCgAAAABJRU5ErkJggg==", "g07n2c08.png", false, 32, 32, "0dcc8b7a828dd05df802b636673ed0ab"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAMAAACBVGfHAAAABGdBTUEAARFwiTtYVgAAAB5QTFRFAAAAAP//AJycv78A/3b/dnYA/wD///////8A/7//TpdUbAAAAFxJREFUeJxj6ACCNCBQAgJBIGBAFmAAAfqoMAYCFyCAq0AWoKOKUCCYCQRwFcgClKmYMFOJCUUFA1gAuwoQKC8vKFdiYoKogAswMCCrYGBnUkJRUV4OdweyAJkqACOga73pcj3PAAAAAElFTkSuQmCC", "g07n3p04.png", false, 32, 32, "8f1a3f91ca328ca507273e80324087e9"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAAAAAAGgflrAAAABGdBTUEAAYagMeiWXwAAAL1JREFUeJztlTEOhCAQRT8bCyw9hlzD0tIDIQfyCF7D0ktYSGLBFoTFmUQC2WRjsv4CZqaYefwQEM6BSAiaa03zcaR5ZS0tSImk+IDiBpy42ndaqOtfEzwe3MGDrwlKTfxHD46jkKBp0g2KPdi2QoI73YNhmKYQGxOe12wP+j7Gxmgd1myCee66sx/G+J0TvCyT/Ajwa2QAAMeUNDHG8XvhBKJtaSEYpxQALItS/vyhSfbPtK7n2dcEz6sMvAHqCJi/5fyWiAAAAABJRU5ErkJggg==", "g10n0g16.png", false, 32, 32, "75b64641f0a3c0899ae3b466fcb97c06"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAABGdBTUEAAYagMeiWXwAAANRJREFUeJztljEKhDAURP8HC+32HpYewdbS+/zNfbyCx7D1FAu7xUK2cA0aM0j4ARWcKhlNJsNTkS2FxQSuCIf9Z9jO3iAgz8P+B9xPIDdDC6IDQOHoAKhUDaBQA8SgKCIDDmtwM3C6GezqsAbJIF+HwRf4sQ0eKOAF/GQMUMB1GCApG7Qtd916D0NERDJPNQ2ahv1IM2/tBpqvad/buuYAdrMY6xn4znR2l6F/inxH1lNNg7JkIqoqHgb7P7hsIGsYjONitWwGk87+HuzrdA1S/VX8ANStTVTe34+eAAAAAElFTkSuQmCC", "g10n2c08.png", false, 32, 32, "69926b0e52c1371c81ca49d7cd0cf2b1"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAMAAACBVGfHAAAABGdBTUEAAYagMeiWXwAAAB5QTFRFAAAAqakAAP///6r/VFQA/wD/AH9///////8A/1X/7g7bWgAAAGNJREFUeJxj6ACCUCBIAwIlIGBAFmAAAfqoEASCmUAAV4EsQEcVLkBgDARwFcgClKkwME5LYENWwWCcxpaApoKNAaICBMrLC8rTGKAq4AJALUgqGNjZgIYiqSgvh7sDWYBMFQBG4oXJmToRDgAAAABJRU5ErkJggg==", "g10n3p04.png", false, 32, 32, "832e5401524ab7238a6eccd5d852b8ef"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAAAAAAGgflrAAAABGdBTUEAA9CQ+FSITwAAATZJREFUeJyllMsNwjAMQN0SQHwixGeNbsSBAToHXQDuHLoCi5A1CgjxhxY4RFGxLRJZ+FDXVvLy6laN3m9AEUW4ThJcbza4VkUBoqAHqO1WBqDGarfznxA02O9lAGYgBTCDw+FPAwqIY6HB8YgbjYbQQApgBqfTnwbnM2koocHlghvNptDgepUBmAEFtFpCg9sNN9ptocH97geUZcCAAgYDXNPXzAweD9zodPwAZvB8+gE0mAEFdLt+ADOgQ+r1bF6tAGYze29M/WtlBlWFG/0+AMBikabuGjCgAK1dzrK6qoMaxBUJrbXWGiDL5vNvgDHOAId6vTDRfQfL5XdljJsEmwF9Jrslz6dTgDy325KkHiSbAW0Mhzav1za7+bscNHCAXxE0GI38AGZAF4zHQgO6YDKRGXwAuz+aGCA4FKQAAAAASUVORK5CYII=", "g25n0g16.png", false, 32, 32, "698f892bb4453fdd325ae414dc82b34f"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAABGdBTUEAA9CQ+FSITwAAAUxJREFUeJytlcttAjEQQMeLgSAQ4SPK2I44UAB1oC1gC+BACVQSykB8hIgSSIJzwFq8xE/KSB75MIxn5+lpLGGcxMMI3OQmXn+Ll+0WAOoArt2lAoCw3acCkMGB+uED2hkaHFMByIAAWRav3whABiclAIMMkgHI4Az9jYYSQAYEsFYJIIP3VAAySAYggw/ob7WUADIgQLOpBJDBJ/S320oAGVy0gB+okwEBXl/ggl4FGXxBf6ejBJDBVQugIINv6O92lQAy+A9guTQiMpsFMzYief0DrUGv55OyNPO5C5N4kAG9ugpwz4vCPBWfAwyym0j09Pv+iEhRmMXCififj9jUDWLH0l9gOKss3d+in14tg3ZAgMHAJ6uVm07NPXlMzOvThXdAW6sAIrJeB13h4wlzMiDAcAgXFGRA/aOREkAG1D8eKwFag8lECQCDX4gtYR8yuXeNAAAAAElFTkSuQmCC", "g25n2c08.png", false, 32, 32, "a64f63bacd6a0edec500179d538ede01"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAMAAACBVGfHAAAABGdBTUEAA9CQ+FSITwAAAB5QTFRFAAAAAC0tAP//EBAA/1z//xD//wD/XFwA//////8AUlHX5QAAAGRJREFUeJy9zrENgDAMRFFbSpHWK7ACC7jICqzACrSUXoFtc1EkczVI+eX5FZYHncjQhoQHGa0RFzpQCh4Wih01lIKHf0KaKQtvZQyvcC8pRnHXaqpTzCEqziRCQo0Fyj94+Cg6NXRmxzu0UNgAAAAASUVORK5CYII=", "g25n3p04.png", false, 32, 32, "c2b4d9eb0587bc254212b05beb972578"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAAAAAAGgflrAAAABGdBTUEAAYagMeiWXwAAAF5JREFUeJzV0jEKwDAMQ1E5W+9/xtygk8AoezLVKgSj2Y8/OICnuFcTE2OgOoJgHQiZAN2C9kDKBOgW3AZCJkC3oD2QMgG6BbeBkAnQLWgPpExgP28H7E/0GTjPfwAW2EvYX64rn9cAAAAASUVORK5CYII=", "oi1n0g16.png", false, 32, 32, "a14e204bbf905586d3763f3cc5dcb2f3"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAIAAACsiDHgAAAABGdBTUEAAYagMeiWXwAAAOVJREFUeJzVlsEKgzAQRKfgQX/Lfrf9rfaWHgYDkoYmZpPMehiGReQ91qCPEEIAPi/gmu9kcnN+GD0nM1/O4vNad7cC6850KHCiM5fz7fJwXdEBYPOygV/o7PICeXSmsMA/dKbkGShD51xsAzXo7DIC9ehMAYG76MypZ6ANnfNJG7BAZx8uYIfOHChgjR4F+MfuDx0AtmfnDfREZ+8m0B+9m8Ao9Chg9x0Yi877jTYwA529WWAeerPAbPQoUH8GNNA5r9yAEjp7sYAeerGAKnoUyJ8BbXTOMxvwgM6eCPhBTwS8oTO/5kL+Xge7xOwAAAAASUVORK5CYII=", "oi1n2c16.png", false, 32, 32, "a3774d09367dd147a3539d2d2f6ca133"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAAAAAAGgflrAAAABGdBTUEAAYagMeiWXwAAAEBJREFUeJzV0jEKwDAMQ1E5W+9/xtygk8AoezLVKgSj2Y8/OICnuFcTE2OgOoJgHQiZAN2C9kDKBOgW3AZCJkC3oD2QMjqwwDMAAAAeSURBVAG6BbeBkAnQLWgPpExgP28H7E/0GTjPfwAW2EvYX7J6X30AAAAASUVORK5CYII=", "oi2n0g16.png", false, 32, 32, "a14e204bbf905586d3763f3cc5dcb2f3"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAIAAACsiDHgAAAABGdBTUEAAYagMeiWXwAAAIBJREFUeJzVlsEKgzAQRKfgQX/Lfrf9rfaWHgYDkoYmZpPMehiGReQ91qCPEEIAPi/gmu9kcnN+GD0nM1/O4vNad7cC6850KHCiM5fz7fJwXdEBYPOygV/o7PICeXSmsMA/dKbkGShD51xsAzXo7DIC9ehMAYG76MypZ6ANnfNJG7BAZx+ZiKBzAAAAZUlEQVQuYIfOHChgjR4F+MfuDx0AtmfnDfREZ+8m0B+9m8Ao9Chg9x0Yi877jTYwA529WWAeerPAbPQoUH8GNNA5r9yAEjp7sYAeerGAKnoUyJ8BbXTOMxvwgM6eCPhBTwS8oTO/5kL+Xk13nmIAAAAASUVORK5CYII=", "oi2n2c16.png", false, 32, 32, "a3774d09367dd147a3539d2d2f6ca133"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAAAAAAGgflrAAAABGdBTUEAAYagMeiWXwAAAB9JREFUeJzV0jEKwDAMQ1E5W+9/xtygk8AoezLVKgSj2Y8/OIdtk98AAAAfSURBVICnuFcTE2OgOoJgHQiZAN2C9kDKBOgW3AZCJkC3oD3Oo8vsAAAAAklEQVSQMsVtZiAAAAAeSURBVAG6BbeBkAnQLWgPpExgP28H7E/0GTjPfwAW2EvYX7J6X30AAAAASUVORK5CYII=", "oi4n0g16.png", false, 32, 32, "a14e204bbf905586d3763f3cc5dcb2f3"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAIAAACsiDHgAAAABGdBTUEAAYagMeiWXwAAAGNJREFUeJzVlsEKgzAQRKfgQX/Lfrf9rfaWHgYDkoYmZpPMehiGReQ91qCPEEIAPi/gmu9kcnN+GD0nM1/O4vNad7cC6850KHCiM5fz7fJwXdEBYPOygV/o7PICeXSmsMA/dKbkGShDblRaWAAAAB1JREFU51xsAzXo7DIC9ehMAYG76MypZ6ANnfNJG7BAZx9l6MXmAAAAY0lEQVQuYIfOHChgjR4F+MfuDx0AtmfnDfREZ+8m0B+9m8Ao9Chg9x0Yi877jTYwA529WWAeerPAbPQoUH8GNNA5r9yAEjp7sYAeerGAKnoUyJ8BbXTOMxvwgM6eCPhBTwS8oTO/5kIg4uIpAAAAAklEQVT+XnoXDXoAAAAASUVORK5CYII=", "oi4n2c16.png", false, 32, 32, "a3774d09367dd147a3539d2d2f6ca133"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAAAAAAGgflrAAAABGdBTUEAAYagMeiWXwAAAAFJREFUeHbmhOYAAAABSURBVJzRgaKHAAAAAUlEQVTV3oFbswAAAAFJREFU0kDlzhAAAAABSURBVDF55n3SAAAAAUlEQVQKyO2U9gAAAAFJREFUwLNcv1gAAAABSURBVDAO4U1EAAAAAUlEQVQMIY4xwwAAAAFJREFUQ8ftbcIAAAABSURBVFE0VByKAAAAAUlEQVQ5dz314AAAAAFJREFUW9SB9ZQAAAABSURBVO8YjYIBAAAAAUlEQVR/6IIRRQAAAAFJREFUxlo/Gm0A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NQEhAAAAAUlEQVQHtlzoSwAAAAFJREFU7IGE07sAAAABSURBVE/OWyHpAAAAAUlEQVT0kuhL7QAAAAFJREFUGUxT1SgAAAABSURBVDgAOsV2AAAAAUlEQVTPI+OiyQAAAAFJREFUf+iCEUUAAAABSURBVAAoOH3oAAAAAUlEQVQW3OzIuQAAAAFJREFU2KAwJw4AAAABSURBVEvJNuXwAAAAAUlEQVTYoDAnDgAAAAFJREFUX9PsMY0AAAAASUVORK5CYII=", "oi9n0g16.png", false, 32, 32, "a14e204bbf905586d3763f3cc5dcb2f3"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAIAAACsiDHgAAAABGdBTUEAAYagMeiWXwAAAAFJREFUeHbmhOYAAAABSURBVJzRgaKHAAAAAUlEQVTV3oFbswAAAAFJREFUljFUS5kAAAABSURBVMHEW4/OAAAAAUlEQVQKyO2U9gAAAAFJREFUg1yJr3IAAAABSURBVDAO4U1EAAAAAUlEQVQQNY9tjAAAAAFJREFURFmJ+GEAAAABSURBVKdgikujAAAAAUlEQVTgiDKfkAAAAAFJREFUQSnjDO4AAAABSURBVH/oghFFAAAAAUlEQVTLJI5m0AAAAAFJREFUfp+FIdMAAAABSURBVLd9PVvHAAAAAUlEQVT96zTzSQAAAAFJREFUrYBfor0AAAABSURBVPZ85irBAAAAAUlEQVSWMVRLmQAAAAFJREFUHtI3QIsAAAABSURBVAbBW9jdAAAAAUlEQVQDsTEsUgAAAAFJREFUkjY5j4AAAAABSURBVIYs41v9AAAAAUlEQVQm+jX4FQAAAAFJREFUZozpuYUAAAABSURBVJNBPr8WAAAAAUlEQVTMuurzcwAAAAFJREFUepjo5coAAAABSURBVBg7VOW+AAAAAUlEQVSGLONb/QAAAAFJREFURS6OyPcAAAABSURBVOSPX1uJAAAAAUlEQVQ9cFAx+QAAAAFJREFU1keICgkAAAABSURBVKD+7t4AAAAAAUlEQVSPVT/jWQAAAAFJREFUEDWPbYwAAAABSURBVEKw6l1UAAAAAUlEQ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gnUAAAABSURBVDbnguhxAAAAAUlEQVQwDuFNRAAAAAFJREFUA7ExLFIAAAABSURBVJ2mhpIRAAAAAUlEQVS9neiy2QAAAAFJREFUWTqPlLgAAAABSURBVGBlihywAAAAAUlEQVQe0jdAiwAAAAFJREFUepjo5coAAAABSURBVLN6UJ/eAAAAAUlEQVTAs1y/WAAAAAFJREFUbGw8UJsAAAABSURBVPSS6EvtAAAAAUlEQVQoHY3VEgAAAAFJREFUUENTLBwAAAABSURBVH/oghFFAAAAAUlEQVQGwVvY3QAAAAFJREFUNAmMiV0AAAABSURBVNCu6688AAAAAUlEQVQ5dz314AAAAAFJREFUr25Rw5EAAAABSURBVNynXeMXAAAAAUlEQVSAxYD+yAAAAAFJREFUEtuBDKAAAAABSURBVDruNKRaAAAAAUlEQVR77+/VXAAAAAFJREFUsZRe/vIAAAABSURBVIDFgP7IAAAAAUlEQVQe0jdAiwAAAAFJREFUepjo5coAAAABSURBVLGUXv7yAAAAAUlEQVSAxYD+yAAAAAFJREFUKvODtD4AAAABSURBVHqY6OXKAAAAAUlEQVQUMuKplQAAAAFJREFUyL2HN2oAAAABSURBVJ9IiPM9AAAAAUlEQVQBXz9NfgAAAAFJREFUbRs7YA0AAAABSURBVHR/UMjNAAAAAUlEQVTOVOSSXwAAAAFJREFUM5foHP4AAAABSURBVBuiXbQEAAAAAUlEQVTwlYWP9AAAAAFJREFUgMWA/sgAAAABSURBVM5U5JJfAAAAAUlEQVSeP4/DqwAAAAFJREFUCCbj9doAAAABSURBVPibXgfGAAAAAUlEQVRBKeMM7gAAAAFJREFUT85bIekAAAABSURBVAQvVbnxAAAAAUlEQVS86u+CTwAAAAFJREFUoYnp7pYAAAABSURBVDOX6Bz+AAAAAUlEQVS/c+bT9QAAAAFJREFU5mFROqUAAAABSURBVEKw6l1UAAAAAUlEQVT+cj2i8wAAAAFJREFUXqTrARsAAAAASUVORK5CYII=", "oi9n2c16.png", false, 32, 32, "a3774d09367dd147a3539d2d2f6ca133"); testPngSu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wgAEgAUPoAAIAFA4QMIABIAFD6AACABQOEDCAASABQ+gAAgAUDhAwgAEgAUPoAAIAFA4QMIABIAFD6AACABQOEDCAASABQ+gAAgAUDhAwgAEgAUPoAAIAFA4QMIABIAFD6AACABQOEDCAASABQ+gAAgAUDhAwgAEgAUPoAAIAFA4QMIABIAFD6AACABQOEDCAASABQ+gAAgAUDhAwgAEgAUPoAAIAFA4QMIABIAFD6AACABQOEDCAASABQ+gAAgAUDhAwgAEgAUPoAAIAFA4QMIABIAFD6AACABQOEDCAASABQ+gAAgAUDhAwgAEgAUPoAAIAFA4QMIABIAFD6AACABQOEDCAASABQ+gAAgAUDhAwgAEgAUPoAAIAFA4QMIABIAFD6AACABQOEDCAASABQ+gAAgAUDhAwgAEgAUPoAAIAFA4QMIABIAFD6AACABQOEDCAASABQ+gAAgAUDhAwgAEgAUPoAAIAFA4QMIABIAFD6AACABQOEDCAASABQ+gAAgAUDhAwgAEgAUPoAAIAFA4QMIABIAFD6AACABQOEDCAASABQ+gAAgAUDhAwgAEgAUPoAAIAFA4QMIABIAFD6AACABQOEDCAASABQ+gAAgAUDhAwgAEgAUPoAAIAFA4QMIABIAFD6AACABQOEDCAASABQ+gAAgAUDhAwgAEgAUPoAAIAFA4QMIABIAFD6AACABQOEDCAASABQ+gAAgAUDhAwgAEgAUPoAAIAFA4QMIABIAFD6AACABQOEDrNu2zb4Gs2n9C98FlZObRxMyAAAAAElFTkSuQmCC", "PngSuite.png", false, 256, 256, "183c2504778cb2b6384dbbad46fa2a2a"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAIAAACsiDHgAAAABGdBTUEAAYagMeiWXwAAAohQTFRFAAAAAAAzAABmAACZAADMAAD/ADMAADMzADNmADOZADPMADP/AGYAAGYzAGZmAGaZAGbMAGb/AJkAAJkzAJlmAJmZAJnMAJn/AMwAAMwzAMxmAMyZAMzMAMz/AP8AAP8zAP9mAP+ZAP/MAP//MwAAMwAzMwBmMwCZMwDMMwD/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f1x//WzS2pJjgUAAAADyPWrwgMAAABgAMF+VXgAAAAAXIAdS3U3AAAAooADG8P2VRMVDwMAAAAASUVORK5CYII=", "pp0n6a08.png", false, 32, 32, "de9a6b2025046b20b3a408990a2b7e71"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAAAAABWESUoAAAABGdBTUEAAYagMeiWXwAABRpzUExUc2l4LWN1YmUACAAAAP8AAAAAM/8AAAAAZv8AAAAAmf8AAAAAzP8AAAAA//8AAAAzAP8AAAAzM/8AAAAzZv8AAAAzmf8AAAAzzP8AAAAz//8AAABmAP8AAABmM/8AAABmZv8AAABmmf8AAABmzP8AAABm//8AAACZAP8AAACZM/8AAACZZv8AAACZmf8AAACZzP8AAACZ//8AAADMAP8AAADMM/8AAADMZv8AAADMmf8AAADMzP8AAADM//8AAAD/AP8AAAD/M/8AAAD/Zv8AAAD/mf8AAAD/zP8AAAD///8AADMAAP8AADMAM/8AADMAZv8AADMAmf8AADMAzP8AADMA//8AADMzAP8AADMzM/8AADMzZv8AADMzmf8AADMzzP8AADMz//8AADNmAP8AADNmM/8AADNmZv8AADNmmf8AADNmzP8AADNm//8AADOZAP8AADOZM/8AADOZZv8AADOZmf8AADOZzP8AADOZ//8AADPMAP8AADPMM/8AADPMZv8AADPMmf8AADPMzP8AADPM//8AADP/AP8AADP/M/8AADP/Zv8AADP/mf8AADP/zP8AADP///8AAGYAAP8AAGYAM/8AAGYAZv8AAGYAmf8AAGYAzP8AAGYA//8AAGYzAP8AAGYzM/8AAGYzZv8AAGYzmf8AAGYzzP8AAGYz//8AAGZmAP8AAGZmM/8AAGZmZv8AAGZmmf8AAGZmzP8AAGZm//8AAGaZAP8AAGaZM/8AAGaZZv8AAGaZmf8AAGaZzP8AAGaZ//8AAGbMAP8AAGbMM/8AAGbMZv8AAGbMmf8AAGbMzP8AAGbM//8AAGb/AP8AAGb/M/8AAGb/Zv8AAGb/mf8AAGb/zP8AAGb///8AAJkAAP8AAJkAM/8AAJ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VlgHnqzwGz0KFB/BjTQOa/cgBI6e7GAHnqxgCp6FMifAW10zjMb8IDOngj4QU8EvKEzv+ZC/l4Hu8TsAAAAAElFTkSuQmCC", "ps2n2c16.png", false, 32, 32, "a3774d09367dd147a3539d2d2f6ca133"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAFS3GZcAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAANQTFRFAAD/injSVwAAAApJREFUeJxjYAAAAAIAAUivpHEAAAAASUVORK5CYII=", "s01i3p01.png", false, 1, 1, "c987217b78dd44056a9da58cf06b8c7a"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAANQTFRFAAD/injSVwAAAApJREFUeJxjYAAAAAIAAUivpHEAAAAASUVORK5CYII=", "s01n3p01.png", false, 1, 1, "c987217b78dd44056a9da58cf06b8c7a"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAAAIAAAACAQMAAAE/f6/xAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAANQTFRFAP//GVwvJQAAAAtJREFUeJxjYAABAAAGAAH+jGfIAAAAAElFTkSuQmCC", "s02i3p01.png", false, 2, 2, "e1b1f768e50f5269db92782b4ad62247"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAAAIAAAACAQMAAABIeJ9nAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAANQTFRFAP//GVwvJQAAAAxJREFUeJxjYGBgAAAABAAB9hc4VQAAAABJRU5ErkJggg==", "s02n3p01.png", false, 2, 2, "e1b1f768e50f5269db92782b4ad62247"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAAAMAAAADAQMAAAEb4RdqAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAAZQTFRFAP8A/3cAseWlnwAAAAxJREFUeJxjYIADBwAATABB2snmHAAAAABJRU5ErkJggg==", "s03i3p01.png", false, 3, 3, "b05c579eb095ddac5d3b30e0329c33f4"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAAAMAAAADAQMAAABs5if8AAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAAZQTFRFAP8A/3cAseWlnwAAAA5JREFUeJxjYGBwYGAAAADGAEE5MQxLAAAAAElFTkSuQmCC", "s03n3p01.png", false, 3, 3, "b05c579eb095ddac5d3b30e0329c33f4"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAAAQAAAAEAQMAAAHkODyrAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAAZQTFRF/wB3//8AmvdDuQAAABRJREFUeJxjaGAAwQMMDgwTGD4AABmuBAG53zf2AAAAAElFTkSuQmCC", "s04i3p01.png", false, 4, 4, "c268bd54d984c22857d450e233766115"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAAAQAAAAEAQMAAACTPww9AAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAAZQTFRF/wB3//8AmvdDuQAAAA9JREFUeJxj+MAwAQg/AAAMCAMBgre2CgAAAABJRU5ErkJggg==", "s04n3p01.png", false, 4, 4, "c268bd54d984c22857d450e233766115"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFAgMAAAGHBv7gAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAAlQTFRFAP//dwD//wAAQaSqcwAAABlJREFUeJxjaGBoYFjAACI7gHQAEE9tACIATYMG43AkRkUAAAAASUVORK5CYII=", "s05i3p02.png", false, 5, 5, "fceb20e261cb29ebb6349bc6c2265beb"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFAgMAAADwAc52AAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAAlQTFRFAP//dwD//wAAQaSqcwAAABRJREFUeJxjWNXAMLWBYSKYXNUAACoHBZCujPRKAAAAAElFTkSuQmCC", "s05n3p02.png", false, 5, 5, "fceb20e261cb29ebb6349bc6c2265beb"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAAAYAAAAGAgMAAAHqpTdNAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAAlQTFRFAP8AAHf//wD/o0UOaAAAACJJREFUeJxjaGBoYJgAxA4MLQwrGDwYIhimJjBMSGBYtQAAWccHTMhl7SQAAAAASUVORK5CYII=", "s06i3p02.png", false, 6, 6, "b5c9900082b8119515e3b00634a379c5"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAAAYAAAAGAgMAAACdogfbAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAAlQTFRFAP8AAHf//wD/o0UOaAAAABZJREFUeJxjWLWAYWoCwwQwAjJWLQAAOc8GXylw/coAAAAASUVORK5CYII=", "s06n3p02.png", false, 6, 6, "b5c9900082b8119515e3b00634a379c5"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHAgMAAAHOO4/WAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAAxQTFRF/wB3AP93//8AAAD/G0OznAAAACVJREFUeJxjOMBwgOEBwweGDQyvGf4z/GFIAcI/DFdjGG7MAZIAweMMgVWC+YkAAAAASUVORK5CYII=", "s07i3p02.png", false, 7, 7, "cefe38d2a35e41b73b6270a398c283e8"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHAgMAAAC5PL9AAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAAxQTFRF/wB3AP93//8AAAD/G0OznAAAABpJREFUeJxj+P+H4WoMw605DDfmgEgg+/8fAHF5CrkeXW0HAAAAAElFTkSuQmCC", "s07n3p02.png", false, 7, 7, "cefe38d2a35e41b73b6270a398c283e8"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIAgMAAAHOZmaOAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAAxQTFRFAP//dwD/d/8A/wAAqrpZHAAAACVJREFUeJxjYAACASB+wGDHoAWk9zDMYVjBoLWCQbeCQf8HUAAAUNcF93DTSq8AAAAASUVORK5CYII=", "s08i3p02.png", false, 8, 8, "3f0fc2c825d2fad899359508e7f645e1"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIAgMAAAC5YVYYAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAAxQTFRFAP//dwD/d/8A/wAAqrpZHAAAABtJREFUeJxjYGBg0FrBoP+DQbcChIAMIJeBAQA9VgU9+UwQEwAAAABJRU5ErkJggg==", "s08n3p02.png", false, 8, 8, "3f0fc2c825d2fad899359508e7f645e1"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJAgMAAAHq+N4VAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAAxQTFRFAP8AAHf//wD//3cA/1YAZAAAACNJREFUeJxjYEACC4BYC4wYGF4zXAdiBgb7/wwMltEQDGQDAHX/B0YWjJcDAAAAAElFTkSuQmCC", "s09i3p02.png", false, 9, 9, "5c55b2480d623eae3a3aaac444eb9542"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJAgMAAACd/+6DAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAAAxQTFRFAP8AAHf//wD//3cA/1YAZAAAAB9JREFUeJxjYAAC+/8MDFarGRgso4FYGkKD+CBxIAAAaWUFw2pDfyMAAAAASUVORK5CYII=", "s09n3p02.png", false, 9, 9, "5c55b2480d623eae3a3aaac444eb9542"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAMAAAH2U1dRAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAACdQTFRFAAAA/wB3AP//AP8AdwD/AHf/d/8A/wD//wAAAP93//8A/3cAAAD/9b8GOwAAANhJREFUeJx9kL0OgjAURj9FfuJTuBjXhqkkDvBGujo1casOLOyEgZmpM4kk8Fi29FYpMTbNl8O59+Y2AByC48nw5Ehe4Pr25orpfEeQ6LhPNgLgdmpQm2iWsdVxqA3V9lOyWKajTCEwWpDpx8TO6Oz3zMIoHYgtlWDORlWFqqDKgiAk6OBM6XoqgsgBPj0mC4QWcgUHJZW+QD1F56Yighx0ro82Ow5z4tEyDJ6ocfQFMuz8ER1/BaLs4HforcN6hMRF18KlMIyluP4QbCX0qz0hsN6yWjv/iTeEUtKElO3EIwAAAABJRU5ErkJggg==", "s32i3p04.png", false, 32, 32, "bbe63d9433641df3fcd2c745fed89a93"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAMAAACBVGfHAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAACdQTFRFAAAA/wB3AP//AP8AdwD/AHf/d/8A/wD//wAAAP93//8A/3cAAAD/9b8GOwAAAHxJREFUeJyV0b0NgCAQBeBXAIlxCRt6WrbyNqB3CSsnYTAPTYzvSIhSXMhHcn8A7ch25FiviA40wDEkVAZ4hh2RQXMa6JLmxZaNPwEdBJO0aB9u3NhzraJvBKuCfwNmXQVBW9YQ5AskC1xW2n4ZMDEU2FlCNrOYae+Pt3ACA2HDSOt6Ji4AAAAASUVORK5CYII=", "s32n3p04.png", false, 32, 32, "bbe63d9433641df3fcd2c745fed89a93"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACEAAAAhBAMAAAHSze/KAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAACdQTFRFAAAA/wB3AP//AP8AdwD/AHf/d/8A/wD//wAAAP93//8A/3cAAAD/9b8GOwAAAPZJREFUeJxdjzFywjAQRT/JMCjEBdzAkxN4RhdIwQHcuKeiplNLqZKWzrUr+jQ+gA6Vv6sVlnkey5K+Vm8NxBvmNMP7DpHzxLmL/HCHG+Cy8xI6l+M0y2GGYBw1lN0kq5gTOaThawlM434SRrT4UVqEsAvCFSNKmjNejpCz3RWTAUs/WsldVOM0Wug/vfISsPcmaWtFxBqrAkqVAesJ+jOkKQ0E/bMYXalhl1bUWRUbykVooPwtPHG5nPkunPG441Fzx8BnOyz0OBEdjF8ciQ7GAfjm9WsX5W+uWqMMK3r0tUZE5qo8m0OtEd48qlq5vtRXm8Td/wMULdZI1p9klQAAAABJRU5ErkJggg==", "s33i3p04.png", false, 33, 33, "20708bc9a6ffa8d8ca6e004e1e9aa3ae"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACEAAAAhBAMAAAClyt9cAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAACdQTFRFAAAA/wB3AP//AP8AdwD/AHf/d/8A/wD//wAAAP93//8A/3cAAAD/9b8GOwAAAL5JREFUeJxdzy0SwyAQhuGv0+n0V6Q36HCCzHCBih4gBh8VXVeLjIyNi0bV13CAHKrLDi27vAwrEMADpMaS5wN8Sm+EEHAKpQXD0NMu9bAWWytqMU+YZRMMXWxENzhaO1fqsK5rTONXxIPikbvjRfHIPXGleOQaNlWuM1GUa6H/VC46qV26ForEKRLnVB06SaJwiZKUUNn1D/vsEqZNI0mjP3h4SUrR60G3aBOzalcL5TqyTbmMqVzJqV0R5PoCM2LWk+YxJesAAAAASUVORK5CYII=", "s33n3p04.png", false, 33, 33, "20708bc9a6ffa8d8ca6e004e1e9aa3ae"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACIAAAAiBAMAAAG/biZnAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAACdQTFRFAAAA/wB3AP//AP8AdwD/AHf/d/8A/wD//wAAAP93//8A/3cAAAD/9b8GOwAAANJJREFUeJx9jr0KgzAURr9q/elbdJGu4mTAQR+pa6eAW+yQxV06ODs5CxX0sWrURHstDcnH4eTe3ABxBz6d5+74b8S7zcck72D7KvMx4XPaHfC4vVCpeP0OS0W1hAg9EQ0imqZhWElEm/OMm28tTdwQQkPzOrVl1pYpWplpcjQ1ME6aulKTawhbXUnI0dRsZG5hyJVHUr9bX5Hp8tl7UbOgXxJFHaL/NhUCYsBwJl0soO9QA5ddSc00vD90/TOgprpQA9rFXWpQMxAzLzIdh/+g/wDxGv/uWt+IKQAAAABJRU5ErkJggg==", "s34i3p04.png", false, 34, 34, "0912e0f97224057b298f163739d1365f"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACIAAAAiBAMAAADIaRbxAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAACdQTFRFAAAA/wB3AP//AP8AdwD/AHf/d/8A/wD//wAAAP93//8A/3cAAAD/9b8GOwAAAG1JREFUeJyVz7ENgCAQBdBfIIlb2NDbMpYb0LMEFZMwGKcWJv9HwSsu5CX8uwPOOnKNod0dKtbhSHY0EiwkBYHEglk0OW4yPfwXqHhOTraPG234vCcFYykqKwtUeFZS8Sx2NUjqhFz1LVl+vUgHrMXtiDoroU4AAAAASUVORK5CYII=", "s34n3p04.png", false, 34, 34, "0912e0f97224057b298f163739d1365f"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACMAAAAjBAMAAAGb8J78AAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAACdQTFRFAAAA/wB3AP//AP8AdwD/AHf/d/8A/wD//wAAAP93//8A/3cAAAD/9b8GOwAAAQRJREFUeJxlkD2uglAUhMf4A1GL93ZAWIHJ2YCFC7Cxt7Kmo7WktLWjprJ/DQu4i3pzzuUAF4fwk5k7+SYAzRN96CFyQsPvEIC80ZcIDf04iYZ5HmOeZaQOYzoxDRY05og7MCePDtQ5Al2770woUEahrrPahBaeluWUqiqmMWqBMS2GtEYGHR4XdK2flLVI3OO0AqE/hrjXuRWb3sVIEfHuRLMifxEGbsauFdl/Dk1NvTsthXeDdytUMP3N9MHjcec90x3vF96JXrjx2t5muuJC2cN1xi9lD9cPcCBjQeSGJXEpEhMYdU1hm5E4wlZGTGAHFj9IYTsd8A1MiVujzokXHXH+B9CK7qGbaRQOAAAAAElFTkSuQmCC", "s35i3p04.png", false, 35, 35, "b46d9ba87963f526624a6d485ff6465e"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACMAAAAjBAMAAADs965qAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAACdQTFRFAAAA/wB3AP//AP8AdwD/AHf/d/8A/wD//wAAAP93//8A/3cAAAD/9b8GOwAAAMdJREFUeJxl0SEOg0AQheHXtJSmmPYGhBOQcIEKDoDBo9C42spKLA6Nqq/hAHuoPqZhM7P7E0asmOyXBbbeqpec4Kv6YFkWXBfVjL7v+Ks6VBWOla7ENGIyjSi4vdDlaPklraqBc27dhm9FzWTsPfBkMvYG3JmMvZv4QmNGlTXOvFdo5FFkDCoD4N8YRqPhsSbgsdXyTt7oeak3et5BjIZ3EaPhZVwv76h4kuWdN3JMjIwjImMOa0zEaY3Ocb021tsVrJE+pMMPA+LuR86i5UgAAAAASUVORK5CYII=", "s35n3p04.png", false, 35, 35, "b46d9ba87963f526624a6d485ff6465e"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACQAAAAkBAMAAAFkKbU9AAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAACdQTFRFAAAA/wB3AP//AP8AdwD/AHf/d/8A/wD//wAAAP93//8A/3cAAAD/9b8GOwAAANlJREFUeJyNkb0KgzAURj/b+tO36CJdxUnBob5Ru3YKuGkHF3dxcHZyDlTQx2piTaJJC4bk43juvUEUiCgIO6/V8d6IVptMSUZx9HhmU0IwJwWe1+aOes7mV9ZzHr6JJfPAzcORbRCMC+Whcq5044bIgQoKXEGhcDn4svoqZRt9mQqyBXWQrpR9lSBHElRf9ZdgLdRVkCSqnaraqnozifXN61G0sT8siaINMGiqhq8rxDjpg7Fv3GUoOPFF72LvoF+/etipav4DtgosYSptELsHdXX2qaZa/jk/GoQXLvsYf8IAAAAASUVORK5CYII=", "s36i3p04.png", false, 36, 36, "65e57e33b4763a3b0c3f0fa92295406d"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACQAAAAkBAMAAAATLoWrAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAACdQTFRFAAAA/wB3AP//AP8AdwD/AHf/d/8A/wD//wAAAP93//8A/3cAAAD/9b8GOwAAAHdJREFUeJxjYACBwu5llqpHoCQDFiEgxcCCLmTAcARdiIEVXWgBgyq6ENB0DCEsxlsqYDpClSwhBixCbBjGNwDdhe4ILE5F4lBXCBToqEILgEKMqEIMnKoHGNCEgCQWoULCQgYYNjJgsZGBWBvJE8L0EBZvgwMHAABJBMjTkay+AAAAAElFTkSuQmCC", "s36n3p04.png", false, 36, 36, "65e57e33b4763a3b0c3f0fa92295406d"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACUAAAAlBAMAAAFAtw2mAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAACdQTFRFAAAA/wB3AP//AP8AdwD/AHf/d/8A/wD//wAAAP93//8A/3cAAAD/9b8GOwAAAP5JREFUeJxlkDsSgjAQhv8RHfFR6A0cTsBMLmDhAWjsrajpaFNS0tqlprK3yQFyKDcb8jD5GJLMssu3G2CS0EZDiBYTnY0Bat59DHxuBYG6nihgLBAcmSywm+Sclr9qjkvOKSOIESmxqOPCKNzQOG4Yx/3IDFAICU2TJDAglhUVEzYhYaA/2JFco4tacyEq4YhWGH02brigp0pfG0QQntiQu5S11vUNdzk8dmgx1FaxV1+rTWza19bWS3xTPuj7F70pL7xnvP+Z8aRn90zp8CB4CdxxJXgJXIATiXIvtVJ4C8hb0OVK5ppzyUa1FE5rLb04FN4OuZdG367zplJ6fx0nFJojsT+zAAAAAElFTkSuQmCC", "s37i3p04.png", false, 37, 37, "f21eff5c07a755577fea69c01459c65f"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACUAAAAlBAMAAAA3sD0wAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAACdQTFRFAAAA/wB3AP//AP8AdwD/AHf/d/8A/wD//wAAAP93//8A/3cAAAD/9b8GOwAAAMVJREFUeJxl0S0Og0AQhuEvoU36J+AGDSfYhAsgegAMHoWuq62sxOJWr6rHcAAO1dkppbMzD9kRmxB4M0D0kp58hUl6I4SAU5A8+r6jI3WoKmRVwmEcMKYGlPSJMnFFS8++lRosyzLH8TfjRnhsajwIj80dBeGxybnV9J4pUPV6+j/TS3e2V3M69ttrUK/RpKmiV6QylcoKLVerXXMnjd4NGrxqjbW212W2F0fbC9vbwPbOF91Lq96t+xXw26+MjUfFHuh8APqFElFWDb0cAAAAAElFTkSuQmCC", "s37n3p04.png", false, 37, 37, "f21eff5c07a755577fea69c01459c65f"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACYAAAAmBAMAAAEtFMQLAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAACdQTFRFAAAA/wB3AP//AP8AdwD/AHf/d/8A/wD//wAAAP93//8A/3cAAAD/9b8GOwAAANpJREFUeJylkT8LgkAchp/+WEFfokVapamDhvxGtTYduGmDi7s0NDc1Cwn6sTpF7w7PQEju9/L48N6pCMcCqeZuzeYjOfZT0I6sT1HNYtNkVHcpi5aB2/5xIW/z8TtzKzsDcbCOD5VaEknVY3yw7NrYaoABGucVxmJbmL2zUK0X7zTU6Gl8YWxqupnGlUGsbjYNUzR6ZzSGjFisbjjWbQrtdU2ewi/7JHkGlEOX4zsOwdLZK3z3PNexEjunp17FeYZ995dr/uR24JpvYoIb3euVlyl7x3pCnZd8AfUFRB95/EUWAAAAAElFTkSuQmCC", "s38i3p04.png", false, 38, 38, "f6237240a70b5844def0406dc8f63bbd"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACYAAAAmBAMAAABaE/SdAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAACdQTFRFAAAA/wB3AP//AP8AdwD/AHf/d/8A/wD//wAAAP93//8A/3cAAAD/9b8GOwAAAGpJREFUeJxjYACBwu5llqpHYCQDNjEgzcCCIWbAcARDjIEVQ2wBgyqGGNAKTDFsdlgqYHGLKrliDNjE2DDtaAC6D8Mt2NyMzBs4MaDL0MUMgGLcaGLAuClgQBcDkmSLYTEPm72DyS3gsAIA8mkrg86sROEAAAAASUVORK5CYII=", "s38n3p04.png", false, 38, 38, "f6237240a70b5844def0406dc8f63bbd"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACcAAAAnBAMAAAEJinyQAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAACdQTFRFAAAA/wB3AP//AP8AdwD/AHf/d/8A/wD//wAAAP93//8A/3cAAAD/9b8GOwAAARlJREFUeJxtkDFygzAQRZ/HkwSTFM4NGE7AjC6QIgdw457KtTtaSpVu3VFTuafhADpUVhISCOUxwPC1u/8voHtmM6NUg9ZgDBSimUSbaZRAUWgRjAXlFPmWavdaavypdopKlb6wStM4xTX1PeNQjh4q6gW67qPzMBAL6npTEGA5HcYhFFQ1a8E9FIyU2O20Dy0NSyPqqDzNmqHCzF8uuqwf49ylP06AdYKKE2LGym8eJsQ4OusvR8KEoyJMkCzE/s1ChAnoTYIBx5Tw4nZr5U5oeT547nhwlevtmnDhV3CPlR++BfdYOcOnuGXukih3zxH3nMvOeOOeOh/OmfE0Zc7tuzXfuT9O1nzv7n/lf+b7tQ8uQOpurXn9AQyWNfYM/uLgAAAAAElFTkSuQmCC", "s39i3p04.png", false, 39, 39, "ceb3b33633c181e13ecee80b153fb602"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACcAAAAnBAMAAAB+jUwGAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAACdQTFRFAAAA/wB3AP//AP8AdwD/AHf/d/8A/wD//wAAAP93//8A/3cAAAD/9b8GOwAAANVJREFUeJxt0iEOg0AQheFHSJuUGnqDhhOQcIEKDoDBo9A4LBKJxaFX4TEcgEN1ZklDZ2Z/YMQa+DIA3Cga/Bk20QrnHBInWtC2DT2iBkWBuJDlmCfMqgkZvSeTvVHTdatFFY7j2Hn8taOk/Lj6oKf8uOrwovy4Sr3b2p9k1faFvtPa6TBgN+UGftptZLdViv1nL0P2PmSX7ihV7JEXPhj2ttGxYidMV+7mznRlz2OmK/v0YDo0m25o+/kXGjfoDtED9g565dFv7WLlni/tDMeq7AxPli8bpjUVK/+f5gAAAABJRU5ErkJggg==", "s39n3p04.png", false, 39, 39, "ceb3b33633c181e13ecee80b153fb602"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACgAAAAoBAMAAAEJ15XIAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAACdQTFRFAAAA/wB3AP//AP8AdwD/AHf/d/8A/wD//wAAAP93//8A/3cAAAD/9b8GOwAAANpJREFUeJytjrEKgzAURa/FWmv7EV2kq2RS6FD/qK5OATd1cHEXB2cn50IL+lnVUBMxr4VCQ97N4ZC8POT+HcexclEQp/3g8GVBnHy4JANgT5kM66zjcx1jIxKLrFfpTFndROLN6aZPmdjgTKLjSUwXyL6gt+MSexCWAei2YVeKjXaBpUQotAoKAWPGTtmu/B1hzViEoPCqEK1EQ2GocGyWNXCfUdYEi0RW7QmJQJfcIiSaALqcltaTuvlJEiP9VZ7GAa21nCYBIUFIHHQJg3huUj3NiGvSHb9pXgoWak5w83t4AAAAAElFTkSuQmCC", "s40i3p04.png", false, 40, 40, "140f0d2eb778dad4a1871c17767e2d48"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACgAAAAoBAMAAAB+0KVeAAAABGdBTUEAAYagMeiWXwAAAANzQklUBAQEd/i1owAAACdQTFRFAAAA/wB3AP//AP8AdwD/AHf/d/8A/wD//wAAAP93//8A/3cAAAD/9b8GOwAAAHVJREFUeJzN0LENgDAMRNFDiiwhlqBhiGxFNkifJagyBwWDEagQ/kXoSOHiyVZOp1K1HKnU+Jhi3BBHQCFGjxnRAGVRHms3Xq8LC51/Qurz99iacDg3tDcqpCyHbRLipgBXQk0ed8FHGggpUuCcuOnDYyF3dSfnZ1dwSF0UKQAAAABJRU5ErkJggg==", "s40n3p04.png", false, 40, 40, "140f0d2eb778dad4a1871c17767e2d48"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAAAAACT4cgpAAAABGdBTUEAAYagMeiWXwAAAAJ0Uk5TAA/mLNCpAAAAAmJLR0QAAKqNIzIAAAFISURBVCiRddExT8JAFMBxPoJHWUxcriQuJiaFqpNLWxkdLOVCHJjunSau9GByohwTk8Il+hkcHd0kLrIymLCaOLBq0epdbRRIeNv9pnfvn/temdw6eJktQXJPK7cL8BbRklmsjzNInsJquWRjc/8mhc9B6JZt13aLe6z9rGDEm2W7VvU8d5vzcwUTEXqMcxocMd48VfAqBM8mDI4VvENr2M3eXkMDE1Km4iO7r+BDgxaKkXGnAURv0JZd6uON/FRBDK1eBHIQOAgX9GJzOBO8psA0nIN0UyBdTuS1j228qeELKh0NJ9hCWxoSCCKmwMljtJv+FgJOiLwqGRg1foEyDVbBQv0UIspqRHawgnEKMQBoMNBOdsJHBb0ORvlxBkkERDQtdPh35FiDU5j9ZxgRQf3LxS5DQetL5eaCPiynnFystE2m6+r/AOOSVs9bKk33AAAAAElFTkSuQmCC", "tbbn0g04.png", false, 32, 32, "d9b53613bd731e66dcfd5be93186c100"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAIAAACsiDHgAAAABGdBTUEAAYagMeiWXwAAAAZ0Uk5T////////nr1LMgAAAAZiS0dEAAAAAP//R2WpgAAAB4xJREFUWIXV2AtMG2UcAPDvlEcw+IhuTI0aFiRREdHYxGJTmGLAFpahtaNlI6F2PFwdIiBMoFSUwrrSUloKHR1lEBgON7c5B6JONDpxZDpmDDFmzETjcw+2uanx/X+gNllQukGMv4TL5Y7e9/9/7zvx+/+c+K8DuFgLksDn5AA5TRaiFDYPCXxN9pI6UkBKSh4GdXV3gK1b08DYmAscOzYFLr5cFnICJ8kosZEiYjLlgerqZLBx49XA4RCSEFarAFVVeGxowGNnpwR6exPB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zeb6erOZ3+Y4De54/D61gtxDeE/KI+1iYpiH70LThDdt/IrD3YzT4DX4IcKvKfyfv5KLL33evsz9Rt4k/FbNafAazC0wTOarRLYgnxaPEhfhWYu/dyxEWQv4cfcc4e+kC1fK//7r9B+bDPke+qJhGgAAAABJRU5ErkJggg==", "tbbn2c16.png", false, 32, 32, "75954a76132c3971509841e973f029cd"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAABGdBTUEAAYagMeiWXwAAAuJQTFRF////gFZWtbW4qEJCn5+fsSAgixUVnZ2dGxtZm5ubAACEmZmZj6ePl5eXlZWVk5OTKSlWkZGRAACbj4+Pi5WLLi6njY2NgAAAi4uLuQAAiYmJDAzVeHV1h4eHAACyhYWFpQAA3gAAgYGBf39/AACefX19AADJe3t7eXl5NzdWd3d3dXV1c3NzSKlIjgAAAgJkAABiVolWKCh8U4tTiYmPZ2dnZWVlXW1dE+UThiYmby0tRJFEYWFhO507RIlEPZM9AACkAPMAAPEAWVlZV1dXVVVVU1NTNIU0UVFRJJckT09POjpBEBC6sg8PAMcAAMUA/Pz8AMMABASXAMEALXct+vr6AL8AAABoAL0A2tTUEBB7Ca0J+Pj4ALkAALcAnJyh9vb2DKEMALMAALEAEJEQAKsA8vLyAKkAAKcA7u7u7OzsAJcA6urqAABrAI0AAIsAAIkAAIcAMTExGRkqBwdAEhKuCQnu09bTzMzMkwAAoyoqxsbGxMTEzAAA0woKgWtreD4+AwNtAACfCgpWRkZIQUFNc11dUQcHqKio7e3voKCgnp6enJycAAC5mpqasgAAmJiY6wAAlpaWngAAlJSUExMckpKSkJCQjo6OAACRioqKiIiIdqJ2hYiFhoaGhISEeA8PgoKCfoJ+fn5+fHx8enp6SsBKdnZ2dHR0cnJycHBwmAAAbm5uanBqemZmampqhAAARKJES5ZLYWRhYmJiAPQAOJg4XFxcWlpaAOYAAgJdQnhCVlZWAADwLpQuR2hHMTFgANgAUlJSUFBQAM4AIZghFBRtAMgATEx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Gj4Aa6AIK4KP1mZu78vJyGlo+vw0YBQ65u+8RCARcbgxwiTLIyipeDJCfn29cb0zq7BzpvF21HX266uvaNB/eBd40FsQg/QgMDFy5soPqY2QU6eXl5eR0ELrmqzMxCeru7l4M8OTJE+0FrbPKOexgWHh0+LLzy/CJfgmoIdFIaLaJQToolUqXL/+IPHI44c7OIWx2DXCRz9/b1vbl7EtmYGUODg7GxMTQBnYodMCn+p2QC6laSrETgxSXAGvWUFNmMkwEw9D2LLK0jL1+ffBlV4YBZGNjY1lZWUFxQTivr20OJLkSjUZDDBpj0uRNm7xZLGobKk74xo2Jt279bNDPgoBZfVO1tLToxIMWZhZk2TISO2LQGEskEpFIxOfbmJp6eHnFP3w4sZCTxQBzdmPohkuNC3WtMkNJ+44YVD1aWH5+flu3biVBpWtb3MOr30UTExMkcLR5qGjEoDHet28f7Rb64/Pnz195fEkvuxcvXly5coWWNjFojCmDjo6OpRxcKmDORkdHtVotdRc9QZZ+6vUevzMzM/RCfa0jb/x1/Sd+IPxqXp1JowAAAABJRU5ErkJggg==", "tbrn2c08.png", false, 32, 32, "75954a76132c3971509841e973f029cd"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAAAAAAGgflrAAAABGdBTUEAAYagMeiWXwAAAAJ0Uk5T///Itd/HAAAAAmJLR0T//xSrMc0AAAS8SURBVEiJY/hPIWCgqQGPH588+fEjWQa8eLF1a11damrUTjf9hB8LBR8JEG3Au3f793d2pqcnTvDZZSaiFaD+Unmr+hy9VwGeE72vbP/zB48Bnz4dOTJ1alFRzrzgSbYLdLP0t2s3q2VqLbc5rnRIglFqq/pLA46ctAULzp//8QPNgO/fT52aNausrLg4bZXHY0NO/SyjbSYXbALsZM1bDAOtZ7tWGFerbdNl1noZ1Z6XV1xcVjZ79pEj797BDThzpr6+rKwUCPzEzc3NmM3m2sSE2qTIBag5zne+6L7dNdAxy07O/IKaWc68UijIypo1C27AnTutrR0dLS3V1ckcLp7u8omvyqLLwaCINe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d3d/f2lpQEB9vaSisLO/lYvNNAV42jWL9yuKg14mD9jY6O7u7c3KAgf39z8/LyX7+wqcVRL7x/v2BBc3NbW0dHenpgYEDAggV//2JXibNm+vfvwIHW1ra2xMSgoO3bcakiULXduzdhQmrqmTP41BCoXL9+ffwYvwqKa2cA4MyW1TM3HhMAAAAASUVORK5CYII=", "tbwn0g16.png", false, 32, 32, "56ea136a6e299452015ac02a7837e365"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAABGdBTUEAAYagMeiWXwAAAt9QTFRF////gFZWtbW4qEJCn5+fsSAgixUVnZ2dGxtZm5ubAACEmZmZj6ePl5eXlZWVk5OTKSlWkZGRAACbj4+Pi5WLLi6njY2NgAAAi4uLuQAAiYmJDAzVeHV1h4eHAACyhYWFpQAA3gAAgYGBf39/AACefX19AADJe3t7eXl5NzdWd3d3dXV1c3NzSKlIjgAAAgJkAABiVolWKCh8U4tTiYmPZ2dnZWVlXW1dE+UThiYmby0tRJFEYWFhO507RIlEPZM9AACkAPMAAPEAWVlZV1dXVVVVU1NTNIU0UVFRJJckT09POjpBEBC6sg8PAMcAAMUA/Pz8AMMABASXAMEALXct+vr6AL8AAABoAL0A2tTUEBB7Ca0J+Pj4ALkAALcAnJyh9vb2DKEMALMAALEAEJEQAKsA8vLyAKkAAKcA7u7u7OzsAJcA6urqAABrAI0AAIsAAIkAAIcAMTExGRkqBwdAEhKuCQnu09bTzMzMkwAAoyoqxsbGxMTEzAAA0woKgWtreD4+AwNtAACfCgpWRkZIQUFNc11dUQcHqKio7e3voKCgnp6enJycAAC5mpqasgAAmJiY6wAAlpaWngAAlJSUExMckpKSkJCQjo6OAACRioqKiIiIdqJ2hYiFhoaGhISEeA8PgoKCfoJ+fn5+fHx8enp6SsBKdnZ2dHR0cnJycHBwmAAAbm5uanBqemZmampqhAAARKJES5ZLYWRhYmJiAPQAOJg4XFxcWlpaAOYAAgJdQnhCVlZWAADwLpQuR2hHMTFgAN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8F7+Xk2h5hwSgPBi+lmFfjkGRgSHuCXxwQADa7/kZ2V28AAAAAASUVORK5CYII=", "tbwn3p08.png", false, 32, 32, "d1f6636d81c74f163bfff1405bf406cf"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAABGdBTUEAAYagMeiWXwAAAuJQTFRF////gFZWtbW4qEJCn5+fsSAgixUVnZ2dGxtZm5ubAACEmZmZj6ePl5eXlZWVk5OTKSlWkZGRAACbj4+Pi5WLLi6njY2NgAAAi4uLuQAAiYmJDAzVeHV1h4eHAACyhYWFpQAA3gAAgYGBf39/AACefX19AADJe3t7eXl5NzdWd3d3dXV1c3NzSKlIjgAAAgJkAABiVolWKCh8U4tTiYmPZ2dnZWVlXW1dE+UThiYmby0tRJFEYWFhO507RIlEPZM9AACkAPMAAPEAWVlZV1dXVVVVU1NTNIU0UVFRJJckT09POjpBEBC6sg8PAMcAAMUA/Pz8AMMABASXAMEALXct+vr6AL8AAABoAL0A2tTUEBB7Ca0J+Pj4ALkAALcAnJyh9vb2DKEMALMAALEAEJEQAKsA8vLyAKkAAKcA7u7u7OzsAJcA6urqAABrAI0AAIsAAIkAAIcAMTExGRkqBwdAEhKuCQnu09bTzMzMkwAAoyoqxsbGxMTEzAAA0woKgWtreD4+AwNtAACfCgpWRkZIQUFNc11dUQcHqKio7e3voKCgnp6enJycAAC5mpqasgAAmJiY6wAAlpaWngAAlJSUExMckpKSkJCQjo6OAACRioqKiIiIdqJ2hYiFhoaGhISEeA8PgoKCfoJ+fn5+fHx8enp6SsBKdnZ2dHR0cnJycHBwmAAAbm5uanBqemZmampqhAAARKJES5ZLYWRhYmJiAPQAOJg4XFxcWlpaAOYAAgJdQnhCVlZWAADwLpQuR2hHMTFgANgAUlJSUFBQAM4AIZghFBRtAMgATExM/f39AMYAAACdb2tr6g4OSEhIALwANGY0AgL1U1NgALAAAK4AtwAAAKQA7+/vAKIAj09PlTQ0AJgAAJYAAJIA5+fnAIwA4+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AAF0Uk5TAEDm2GYAAAKKSURBVDiNY2CgMnjwKg2P7D2mxWZPLJm/fMAqm/leyrStgU1vg/iG1VVfIgNQZdNq+FaeabCsnFwpvsCqvb19w6N1Xc9jYLIxr/qW67RZPpqs0F9bK6nAZrlAfLXekzU6yzlrMsEKKpSXa2vfkuy/6nvrJqui4sSJirWS4me0gWB9H1jBC/nZ89UZfVlvymhpadUz1509W1fFCGSu2n7oPVhBznyluTOklDVQwfItrodP3IO4YZHnNVsRfuH56jCwdKnGepfDJ845Q105K+mU47JpfLxTZJdAwcrtRkFRAi0LoQqmRUdstRCcwsvNyS2hvHixqtaWSz5qM8PDBTqgCqYkJu3cOodfZKMuT3fPjMXrd7yV3tu0q8SAoxyqoONo6vGty6bpnk/fx87StXSHs+hntV3FU5s1YcHJtO/GlZ1OIhuP397W082ywvnZxb2N3udeC6yEBWW1e3LeEcdNtn637TnZu9cADXB40xrVNDMepiByd/LDWKcU21PZ9n2c7KZvy/Y2HghSefmpGqYgZ/eVwsSDGZ6Bd+wn9PXYvPvcy/H6ZW4uRwJMQcD+9Dshwf53g+9u4uXu2yF6ketjsf5joWeI2F577dr+xIP5YXmb+HgnuZTuDW8tOiaXa4JQIHbj8gW749nn71vz8wnv8enVbzngcLq5GqEglMd9s1n0ldh8Y0F+KdfS058OBMlxMKEkqedrzPYlxRUYCgsquUZx6XPNPPYcLUlmzTO/nFRgLCa81PVj41MDoxcM6CCg4+jlQkMJsRVu3sUl7zox5IGgfFvIotkSaw55FWmFYpNnYLjeNX/ebFOPw10nscsDwXv5eTaHmHBKA8GL6WYV+OQZGBIe4JfHBAANrv+RnZXbwAAAAABJRU5ErkJggg==", "tp1n3p08.png", false, 32, 32, "d1f6636d81c74f163bfff1405bf406cf"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAEAAADurUJNAAAABGdBTUEAAYagMeiWXwAAAEFJREFUeJxjZGAkABQIyLMMBQWMDwgp+PcfP2B5MBwUMMoRkGdkonlcDAYFjI/wyv7/z/iH5nExGBQwyuCVZWQEAFDl/nE14thZAAAAAElFTkSuQmCC", "xc1n0g08.png", true, 32, 32, "d41d8cd98f00b204e9800998ecf8427e"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAkAAAArGWqiAAAABGdBTUEAAYagMeiWXwAAAEhJREFUeJzt1cEJADAMAkCF7JH9t3ITO0Qr9KH4zuErtA0EO4AKFPgcoO3kfUx4QIECD0qHH8KEBxQo8KB0OCOpQIG7cHejwAGCsfleD0DPSwAAAABJRU5ErkJggg==", "xc9n2c08.png", true, 32, 32, "d41d8cd98f00b204e9800998ecf8427e"); testPngSuiteImage("iVBORw0NGg0AAAANSUhEUgAAACAAAAAgBAAAAACT4cgpAAAABGdBTUEAAYagMeiWXwAAAEhJREFUeJxjYGAQFFRSMjZ2cQkNTUsrL2cgQwCV29FBjgAqd+ZMcgRQuatWkSOAyt29mxwBVO6ZM+QIoHLv3iVHAJX77h0ZAgAfFO4B6v9B+gAAAABJRU5ErkJggg==", "xcrn0g04.png", true, 32, 32, "d41d8cd98f00b204e9800998ecf8427e"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQAAAABbAUdZAAAABGdBTUEAAYagMeiWXwAAAFtJREFUeJwtzLEJAzAMBdHr0gSySiALejRvkBU8gsGNCmFFB1Hx4IovqurSpIRszqklUwbnUzRXEuIRsiG/SyY9G0JzJSVei9qynm9qyjBpLp0pYW7pbzBl8L8fEIdJL0NTVU0AAAAASUVORK5CYII=", "xcsn0g01.png", true, 32, 32, "d41d8cd98f00b204e9800998ecf8427e"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAAIAAADMaKZiAAAABGdBTUEAAYagMeiWXwAAAEhJREFUeJzt1cEJADAMAkCF7JH9t3ITO0Qr9KH4zuErtA0EO4AKFPgcoO3kfUx4QIECD0qHH8KEBxQo8KB0OCOpQIG7cHejwAGCsfleD0DPSwAAAABJRU5ErkJggg==", "xd0n2c08.png", true, 32, 32, "d41d8cd98f00b204e9800998ecf8427e"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAwIAAACLyNyyAAAABGdBTUEAAYagMeiWXwAAAEhJREFUeJzt1cEJADAMAkCF7JH9t3ITO0Qr9KH4zuErtA0EO4AKFPgcoO3kfUx4QIECD0qHH8KEBxQo8KB0OCOpQIG7cHejwAGCsfleD0DPSwAAAABJRU5ErkJggg==", "xd3n2c08.png", true, 32, 32, "d41d8cd98f00b204e9800998ecf8427e"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgYwIAAAAS+qv/AAAABGdBTUEAAYagMeiWXwAAAEhJREFUeJzt1cEJADAMAkCF7JH9t3ITO0Qr9KH4zuErtA0EO4AKFPgcoO3kfUx4QIECD0qHH8KEBxQo8KB0OCOpQIG7cHejwAGCsfleD0DPSwAAAABJRU5ErkJggg==", "xd9n2c08.png", true, 32, 32, "d41d8cd98f00b204e9800998ecf8427e"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQAAAABbAUdZAAAABGdBTUEAAYagMeiWXwAAAABJRU5ErkJggg==", "xdtn0g01.png", true, 32, 32, "d41d8cd98f00b204e9800998ecf8427e"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAAAAABDU1VNAAAABGdBTUEAAYagMeiWXwAAAEFJREFUeJxjZGAkABQIyLMMBQWMDwgp+PcfP2B5MBwUMMoRkGdkonlcDAYFjI/wyv7/z/iH5nExGBQwyuCVZWQEAFDl/nE14thZAAAAAElFTkSuQmCC", "xhdn0g08.png", true, 32, 32, "d41d8cd98f00b204e9800998ecf8427e"); testPngSuiteImage("iVBORwoKGgoAAAAKSUhEUgAAACAAAAAgBAAAAACT4cgpAAAABGdBTUEAAYagMeiWXwAAAEhJREFUeJxjYGAQFFRSMjZ2cQkKTUsrL2cgQwCV29FBjgAqd+ZMcgRQuatWkSOAyt29mxwBVO6ZM+QIoHLv3iVHAJX77h0ZAgAfFO4B6v9B+gAAAABJRU5ErkJggg==", "xlfn0g04.png", true, 32, 32, "d41d8cd98f00b204e9800998ecf8427e"); testPngSuiteImage("CVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQAAAABbAUdZAAAABGdBTUEAAYagMeiWXwAAAFtJREFUeJwtzLEJAzAMBdHr0gSySiALejRvkBU8gsGNCmFFB1Hx4IovqurSpIRszqklUwbnUzRXEuIRsiG/SyY9G0JzJSVei9qynm9qyjBpLp0pYW7pbzBl8L8fEIdJL9AvFMkAAAAASUVORK5CYII=", "xs1n0g01.png", true, 32, 32, "d41d8cd98f00b204e9800998ecf8427e"); testPngSuiteImage("iVFORw0KGgoAAAANSUhEUgAAACAAAAAgAQAAAABbAUdZAAAABGdBTUEAAYagMeiWXwAAAFtJREFUeJwtzLEJAzAMBdHr0gSySiALejRvkBU8gsGNCmFFB1Hx4IovqurSpIRszqklUwbnUzRXEuIRsiG/SyY9G0JzJSVei9qynm9qyjBpLp0pYW7pbzBl8L8fEIdJL9AvFMkAAAAASUVORK5CYII=", "xs2n0g01.png", true, 32, 32, "d41d8cd98f00b204e9800998ecf8427e"); testPngSuiteImage("iVBOZw0KGgoAAAANSUhEUgAAACAAAAAgAQAAAABbAUdZAAAABGdBTUEAAYagMeiWXwAAAFtJREFUeJwtzLEJAzAMBdHr0gSySiALejRvkBU8gsGNCmFFB1Hx4IovqurSpIRszqklUwbnUzRXEuIRsiG/SyY9G0JzJSVei9qynm9qyjBpLp0pYW7pbzBl8L8fEIdJL9AvFMkAAAAASUVORK5CYII=", "xs4n0g01.png", true, 32, 32, "d41d8cd98f00b204e9800998ecf8427e"); testPngSuiteImage("iVBORw0KIAoAAAANSUhEUgAAACAAAAAgAQAAAABbAUdZAAAABGdBTUEAAYagMeiWXwAAAFtJREFUeJwtzLEJAzAMBdHr0gSySiALejRvkBU8gsGNCmFFB1Hx4IovqurSpIRszqklUwbnUzRXEuIRsiG/SyY9G0JzJSVei9qynm9qyj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gAAAgAAAkAAAgAAAgAAAgAAAkAAAgAAAhVk05uHxPwlQAAAABJRU5ErkJggg==", "z00n2c08.png", false, 32, 32, "6284c288d49534c897da4e50a9d05002"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAr0lEQVR4XrXR3Q5AMAwF4Epc8P4Py91sIgxb15/TRUSC76Q9U0q0U7m28/5/Zl7Vv/Q+mwsZeJbQgIUoB+Q5Q07RidagCS79nADfwaNHBLx0eAdfHdtBQweuqK2jAro6JIDT/SUPdGfJY92zIpFuDpDqtg4UuqEDna5dkVpXBVh0eQdGXdiBXZesyKUPA7w6HwDQmZIxeq9kmN5cEVL/B4D1Twd4ve4gRL9XFKXngANVk05u39tDGQAAAABJRU5ErkJggg==", "z03n2c08.png", false, 32, 32, "6284c288d49534c897da4e50a9d05002"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAp0lEQVR4nLXRSw6AIBAD0JqwwPsfFna4MX4QYT4dVySS19BuraECFSg4D9158ktyLaEi8suhARnICSVQB/agF5x6UEW3HhHw0ukb9Dp3g4FOrGisswJ+dUrATPePvNCdI691T0Ui3Rwg1W0bKHTDBjpdW5FaVwVYdPkGRl24gV2XVOTSlwFefR5A0Ccjc/S/kWn6sCKm/g0g690GfP25QYh+VRSlA/kAVZNObjFSwSwAAAAASUVORK5CYII=", "z06n2c08.png", false, 32, 32, "6284c288d49534c897da4e50a9d05002"); testPngSuiteImage("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAp0lEQVR42rXRSw6AIBAD0JqwwPsfFna4MX4QYT4dVySS19BuraECFSg4D9158ktyLaEi8suhARnICSVQB/agF5x6UEW3HhHw0ukb9Dp3g4FOrGisswJ+dUrATPePvNCdI691T0Ui3Rwg1W0bKHTDBjpdW5FaVwVYdPkGRl24gV2XVOTSlwFefR5A0Ccjc/S/kWn6sCKm/g0g690GfP25QYh+VRSlA/kAVZNObtYRvvUAAAAASUVORK5CYII=", "z09n2c08.png", false, 32, 32, "6284c288d49534c897da4e50a9d05002"); } void testErrorImages() { std::cout << "testErrorImages" << std::endl; // Image with color type palette but missing PLTE chunk testBase64Image("iVBORw0KGgoAAAANSUhEUgAAAQAAAAEAAgMAAAAhHED1AAAAU0lEQVR4Ae3MwQAAAAxFoXnM3/NDvGsBdB8JBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEEQDHGPAW1eyhK0AAAAASUVORK5CYII=", true, 256, 256, ""); } void doMain() { //PNG testPngSuite(); testErrorImages(); testPNGCodec(); testPaletteFilterTypesZero(); testComplexPNG(); testInspectChunk(); testPredefinedFilters(); testFuzzing(); testEncoderErrors(); testPaletteToPaletteDecode(); testPaletteToPaletteDecode2(); testColorProfile(); testBkgdChunk(); testBkgdChunk2(); testSbitChunk(); //Colors #ifndef DISABLE_SLOW testFewColors(); #endif // DISABLE_SLOW testColorKeyConvert(); testColorConvert(); testColorConvert2(); testPaletteToPaletteConvert(); testRGBToPaletteConvert(); test16bitColorEndianness(); testAutoColorModels(); testNoAutoConvert(); testChrmToSrgb(); testXYZ(); testICC(); testICCGray(); //Zlib testCompressZlib(); testHuffmanCodeLengths(); testCustomZlibCompress(); testCustomZlibCompress2(); testCustomDeflate(); testCustomZlibDecompress(); testCustomInflate(); // TODO: add test for huffman code with exactly 0 and 1 symbols present //lodepng_util testChunkUtil(); testGetFilterTypes(); std::cout << "\ntest successful" << std::endl; } int main() { try { doMain(); } catch(...) { std::cout << std::endl; std::cout << "caught error!" << std::endl; std::cout << "*** TEST FAILED ***" << std::endl; } return 0; } lodepng-0.0~git20220618.b4ed2cd/lodepng_util.cpp000066400000000000000000002163231425344217700211470ustar00rootroot00000000000000/* LodePNG Utils Copyright (c) 2005-2022 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "lodepng_util.h" #include /* allocations */ namespace lodepng { LodePNGInfo getPNGHeaderInfo(const std::vector& png) { unsigned w, h; lodepng::State state; lodepng_inspect(&w, &h, &state, &png[0], png.size()); return state.info_png; } unsigned getChunkInfo(std::vector& names, std::vector& sizes, const std::vector& png) { // Listing chunks is based on the original file, not the decoded png info. const unsigned char *chunk, *end; end = &png.back() + 1; chunk = &png.front() + 8; while(chunk < end && end - chunk >= 8) { char type[5]; lodepng_chunk_type(type, chunk); if(std::string(type).size() != 4) return 1; unsigned length = lodepng_chunk_length(chunk); names.push_back(type); sizes.push_back(length); chunk = lodepng_chunk_next_const(chunk, end); } return 0; } unsigned getChunks(std::vector names[3], std::vector > chunks[3], const std::vector& png) { const unsigned char *chunk, *next, *end; end = &png.back() + 1; chunk = &png.front() + 8; int location = 0; while(chunk < end && end - chunk >= 8) { char type[5]; lodepng_chunk_type(type, chunk); std::string name(type); if(name.size() != 4) return 1; next = lodepng_chunk_next_const(chunk, end); if(name == "IHDR") { location = 0; } else if(name == "PLTE") { location = 1; } else if(name == "IDAT") { location = 2; } else if(name == "IEND") { break; // anything after IEND is not part of the PNG or the 3 groups here. } else { if(next >= end) return 1; // invalid chunk, content too far names[location].push_back(name); chunks[location].push_back(std::vector(chunk, next)); } chunk = next; } return 0; } unsigned insertChunks(std::vector& png, const std::vector > chunks[3]) { const unsigned char *chunk, *begin, *end; end = &png.back() + 1; begin = chunk = &png.front() + 8; long l0 = 0; //location 0: IHDR-l0-PLTE (or IHDR-l0-l1-IDAT) long l1 = 0; //location 1: PLTE-l1-IDAT (or IHDR-l0-l1-IDAT) long l2 = 0; //location 2: IDAT-l2-IEND while(chunk < end && end - chunk >= 8) { char type[5]; lodepng_chunk_type(type, chunk); std::string name(type); if(name.size() != 4) return 1; if(name == "PLTE") { if(l0 == 0) l0 = chunk - begin + 8; } else if(name == "IDAT") { if(l0 == 0) l0 = chunk - begin + 8; if(l1 == 0) l1 = chunk - begin + 8; } else if(name == "IEND") { if(l2 == 0) l2 = chunk - begin + 8; } chunk = lodepng_chunk_next_const(chunk, end); } std::vector result; result.insert(result.end(), png.begin(), png.begin() + l0); for(size_t i = 0; i < chunks[0].size(); i++) result.insert(result.end(), chunks[0][i].begin(), chunks[0][i].end()); result.insert(result.end(), png.begin() + l0, png.begin() + l1); for(size_t i = 0; i < chunks[1].size(); i++) result.insert(result.end(), chunks[1][i].begin(), chunks[1][i].end()); result.insert(result.end(), png.begin() + l1, png.begin() + l2); for(size_t i = 0; i < chunks[2].size(); i++) result.insert(result.end(), chunks[2][i].begin(), chunks[2][i].end()); result.insert(result.end(), png.begin() + l2, png.end()); png = result; return 0; } unsigned getFilterTypesInterlaced(std::vector >& filterTypes, const std::vector& png) { //Get color type and interlace type lodepng::State state; unsigned w, h; unsigned error; error = lodepng_inspect(&w, &h, &state, &png[0], png.size()); if(error) return 1; //Read literal data from all IDAT chunks const unsigned char *chunk, *begin, *end; end = &png.back() + 1; begin = chunk = &png.front() + 8; std::vector zdata; while(chunk < end && end - chunk >= 8) { char type[5]; lodepng_chunk_type(type, chunk); if(std::string(type).size() != 4) break; //Probably not a PNG file if(std::string(type) == "IDAT") { const unsigned char* cdata = lodepng_chunk_data_const(chunk); unsigned clength = lodepng_chunk_length(chunk); if(chunk + clength + 12 > end || clength > png.size() || chunk + clength + 12 < begin) { // corrupt chunk length return 1; } for(unsigned i = 0; i < clength; i++) { zdata.push_back(cdata[i]); } } chunk = lodepng_chunk_next_const(chunk, end); } //Decompress all IDAT data (if the while loop ended early, this might fail) std::vector data; error = lodepng::decompress(data, &zdata[0], zdata.size()); if(error) return 1; if(state.info_png.interlace_method == 0) { filterTypes.resize(1); //A line is 1 filter byte + all pixels size_t linebytes = 1 + lodepng_get_raw_size(w, 1, &state.info_png.color); for(size_t i = 0; i < data.size(); i += linebytes) { filterTypes[0].push_back(data[i]); } } else { //Interlaced filterTypes.resize(7); static const unsigned ADAM7_IX[7] = { 0, 4, 0, 2, 0, 1, 0 }; /*x start values*/ static const unsigned ADAM7_IY[7] = { 0, 0, 4, 0, 2, 0, 1 }; /*y start values*/ static const unsigned ADAM7_DX[7] = { 8, 8, 4, 4, 2, 2, 1 }; /*x delta values*/ static const unsigned ADAM7_DY[7] = { 8, 8, 8, 4, 4, 2, 2 }; /*y delta values*/ size_t pos = 0; for(size_t j = 0; j < 7; j++) { unsigned w2 = (w - ADAM7_IX[j] + ADAM7_DX[j] - 1) / ADAM7_DX[j]; unsigned h2 = (h - ADAM7_IY[j] + ADAM7_DY[j] - 1) / ADAM7_DY[j]; if(ADAM7_IX[j] >= w || ADAM7_IY[j] >= h) continue; size_t linebytes = 1 + lodepng_get_raw_size(w2, 1, &state.info_png.color); for(size_t i = 0; i < h2; i++) { filterTypes[j].push_back(data[pos]); pos += linebytes; } } } return 0; /* OK */ } unsigned getFilterTypes(std::vector& filterTypes, const std::vector& png) { std::vector > passes; unsigned error = getFilterTypesInterlaced(passes, png); if(error) return error; if(passes.size() == 1) { filterTypes.swap(passes[0]); } else { // Simplify interlaced filter types to get a single filter value per scanline: // put pass 6 and 7 alternating in the one vector, these filters // correspond to the closest to what it would be for non-interlaced // image. If the image is only 1 pixel wide, pass 6 doesn't exist so the // alternative values column0 are used. The shift values are to match // the y position in the interlaced sub-images. // NOTE: the values 0-6 match Adam7's passes 1-7. const unsigned column0[8] = {0, 6, 4, 6, 2, 6, 4, 6}; const unsigned column1[8] = {5, 6, 5, 6, 5, 6, 5, 6}; const unsigned shift0[8] = {3, 1, 2, 1, 3, 1, 2, 1}; const unsigned shift1[8] = {1, 1, 1, 1, 1, 1, 1, 1}; lodepng::State state; unsigned w, h; lodepng_inspect(&w, &h, &state, &png[0], png.size()); const unsigned* column = w > 1 ? column1 : column0; const unsigned* shift = w > 1 ? shift1 : shift0; for(size_t i = 0; i < h; i++) { filterTypes.push_back(passes[column[i & 7u]][i >> shift[i & 7u]]); } } return 0; /* OK */ } int getPaletteValue(const unsigned char* data, size_t i, int bits) { if(bits == 8) return data[i]; else if(bits == 4) return (data[i / 2] >> ((i % 2) * 4)) & 15; else if(bits == 2) return (data[i / 4] >> ((i % 4) * 2)) & 3; else if(bits == 1) return (data[i / 8] >> (i % 8)) & 1; else return 0; } //////////////////////////////////////////////////////////////////////////////// #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS // Only temporarily here until this is integrated into lodepng.c(pp) #define LODEPNG_MAX(a, b) (((a) > (b)) ? (a) : (b)) #define LODEPNG_MIN(a, b) (((a) < (b)) ? (a) : (b)) // Only temporarily here until this is integrated into lodepng.c(pp) #ifdef LODEPNG_COMPILE_ALLOCATORS static void* lodepng_malloc(size_t size) { return malloc(size); } static void lodepng_free(void* ptr) { free(ptr); } #else /*LODEPNG_COMPILE_ALLOCATORS*/ void* lodepng_malloc(size_t size); void lodepng_free(void* ptr); #endif /*LODEPNG_COMPILE_ALLOCATORS*/ /* define infinity and NaN in a way compatible with ANSI C90 (no INFINITY or NAN macros) yet also with visual studio */ /* visual studio doesn't allow division through a zero literal, but allows it through public non-const variable set to zero */ float lodepng_flt_zero_ = 0.0f; static const float lodepng_flt_inf = 1.0f / lodepng_flt_zero_; /* infinity */ static const float lodepng_flt_nan = 0.0f / lodepng_flt_zero_; /* not a number */ static const float lodepng_flt_max = 3.40282346638528859811704183484516925e38f; /* avoid needing for FLT_MAX. This assumes IEEE 32-bit float. */ /* powf polyfill, 5-6 digits accurate, 33-80% slower than powf, assumes IEEE 32-bit float, but other than that multiplatform and no math lib needed (note: powf also isn't in ISO C90, and pow is slower). */ static float lodepng_powf(float x, float y) { float j, t0, t1, l; int i = 0; /* handle all the special floating point rules */ if(x == 1 || y == 0) return 1; /*these cases return 1 even if the other value is NaN, as specified*/ if(y == 1) return x; /* preserves negative-0 */ if(!(x > 0 && x <= lodepng_flt_max && y >= -lodepng_flt_max && y <= lodepng_flt_max)) { /*all special cases*/ if(x != x || y != y) return x + y; /* nan */ if(x > 0) { if(x > lodepng_flt_max) return y <= 0 ? (y == 0 ? 1 : 0) : x; /* x = +infinity */ } else { if(!(y < -1073741824.0f || y > 1073741824.0f)) { /* large y always even integer, but cast would overflow */ i = (int)y; /* not using floor: not using math lib */ if(i != y) { return (x < -lodepng_flt_max) ? (y < 0 ? 0 : lodepng_flt_inf) : (x == 0 ? (y < 0 ? lodepng_flt_inf : 0) : lodepng_flt_nan); } if(i & 1) return x == 0 ? (y < 0 ? (1 / x) : x) : -lodepng_powf(-x, y); } if(x == 0) return y <= 0 ? lodepng_flt_inf : 0; if(x < -lodepng_flt_max) { /* x == -infinity */ return y <= 0 ? (y == 0 ? 1 : 0) : ((i & 1) ? -lodepng_flt_inf : lodepng_flt_inf); } x = -x; if(x == 1) return 1; /* under the C++ rules, pow(-1, +/- infinity) also returns 1 */ } if(y < -lodepng_flt_max || y > lodepng_flt_max) return ((x < 1) != (y > 0)) ? (y < 0 ? -y : y) : 0; } l = x; j = 0; while(l < (1.0f / 65536)) { j -= 16; l *= 65536.0f; } while(l > 65536) { j += 16; l *= (1.0f / 65536); } while(l < 1) { j--; l *= 2.0f; } while(l > 2) { j++; l *= 0.5f; } /* polynomial to approximate log2(x) with x in range 1..2 */ t0 = -0.393118410458557f + l * (-0.0883639468229365f + l * (0.466142650227994f + l * 0.0153397331014276f)); t1 = 0.0907447971403586f + l * (0.388892024755479f + l * 0.137228280305862f); l = t0 / t1 + j; l *= y; /* using the formula exp2(y * log2(x)) */ /* prevent int shift overflow, 0 or inf result are ok to return since exp will be taken, 127 is max float exponent */ if(l <= -128.0f || l >= 128.0f) return ((x > 1) == (y > 0)) ? lodepng_flt_inf : 0; i = (int)l; l -= i; /* polynomial to approximate exp2(x) with x in range -1..1 */ t0 = 1.0f + l * (0.41777833582744256f + l * (0.0728482595347711f + l * 0.005635023478609625f)); t1 = 1.0f + l * (-0.27537016151408167f + l * 0.023501446055084033f); while(i <= -31) { t0 *= (1.0f / 2147483648.0f); i += 31; } while(i >= 31) { t0 *= 2147483648.0f; i -= 31; } return (i < 0) ? (t0 / (t1 * (1 << -i))) : ((t0 * (1 << i)) / t1); } /* Parameters of a tone reproduction curve, either with a power law formula or with a lookup table. */ typedef struct { unsigned type; /* 0=linear, 1=lut, 2 = simple gamma, 3-6 = parametric (matches ICC parametric types 1-4) */ float* lut; /* for type 1 */ size_t lut_size; float gamma; /* for type 2 and more */ float a, b, c, d, e, f; /* parameters for type 3-7 */ } LodePNGICCCurve; void lodepng_icc_curve_init(LodePNGICCCurve* curve) { curve->lut = 0; curve->lut_size = 0; } void lodepng_icc_curve_cleanup(LodePNGICCCurve* curve) { lodepng_free(curve->lut); } /* Values parsed from ICC profile, see parseICC for more information about this subset.*/ typedef struct { /* 0 = color model not supported by PNG (CMYK, Lab, ...), 1 = gray, 2 = RGB */ int inputspace; int version_major; int version_minor; int version_bugfix; /* The whitepoint of the profile connection space (PCS). Should always be D50, but parsed and used anyway. (to be clear, whitepoint and illuminant are synonyms in practice, but here field "illuminant" is ICC's "global" whitepoint that is always D50, and the field "white" below allows deriving the whitepoint of the particular RGB space represented here) */ float illuminant[3]; /* if true, has chromatic adaptation matrix that must be used. If false, you must compute a chromatic adaptation matrix yourself from "illuminant" and "white". */ unsigned has_chad; float chad[9]; /* chromatic adaptation matrix, if given */ /* The whitepoint of the RGB color space as stored in the ICC file. If has_chad, must be adapted with the chad matrix to become the one we need to go to absolute XYZ (in fact ICC implies it should then be exactly D50 in the file, redundantly, before this transformation with chad), else use as-is (then its values can actually be something else than D50, and are the ones we need). */ unsigned has_whitepoint; float white[3]; /* Chromaticities of the RGB space in XYZ color space, but given such that you must still whitepoint adapt them from D50 to the RGB space whitepoint to go to absolute XYZ (if has_chad, with chad, else with bradford adaptation matrix from illuminant to white). */ unsigned has_chromaticity; float red[3]; float green[3]; float blue[3]; unsigned has_trc; /* TRC = tone reproduction curve (aka "gamma correction") */ /* TRC's for the three channels (only first one used if grayscale) */ LodePNGICCCurve trc[3]; } LodePNGICC; void lodepng_icc_init(LodePNGICC* icc) { lodepng_icc_curve_init(&icc->trc[0]); lodepng_icc_curve_init(&icc->trc[1]); lodepng_icc_curve_init(&icc->trc[2]); } void lodepng_icc_cleanup(LodePNGICC* icc) { lodepng_icc_curve_cleanup(&icc->trc[0]); lodepng_icc_curve_cleanup(&icc->trc[1]); lodepng_icc_curve_cleanup(&icc->trc[2]); } /* ICC tone response curve, nonlinear (encoded) to linear. Input and output in range 0-1. If color was integer 0-255, multiply with (1.0f/255) to get the correct floating point behavior. Outside of range 0-1, will not clip but either return x itself, or in cases where it makes sense, a value defined by the same function. NOTE: ICC requires clipping, but we do that only later when converting float to integer.*/ static float iccForwardTRC(const LodePNGICCCurve* curve, float x) { if(curve->type == 0) { return x; } if(curve->type == 1) { /* Lookup table */ float v0, v1, fraction; size_t index; if(!curve->lut) return 0; /* error */ if(x < 0) return x; index = (size_t)(x * (curve->lut_size - 1)); if(index >= curve->lut_size) return x; /* LERP */ v0 = curve->lut[index]; v1 = (index + 1 < curve->lut_size) ? curve->lut[index + 1] : 1.0f; fraction = (x * (curve->lut_size - 1)) - index; return v0 * (1 - fraction) + v1 * fraction; } if(curve->type == 2) { /* Gamma expansion */ return (x > 0) ? lodepng_powf(x, curve->gamma) : x; } /* TODO: all the ones below are untested */ if(curve->type == 3) { if(x < 0) return x; return x >= (-curve->b / curve->a) ? (lodepng_powf(curve->a * x + curve->b, curve->gamma) + curve->c) : 0; } if(curve->type == 4) { if(x < 0) return x; return x >= (-curve->b / curve->a) ? (lodepng_powf(curve->a * x + curve->b, curve->gamma) + curve->c) : curve->c; } if(curve->type == 5) { return x >= curve->d ? (lodepng_powf(curve->a * x + curve->b, curve->gamma)) : (curve->c * x); } if(curve->type == 6) { return x >= curve->d ? (lodepng_powf(curve->a * x + curve->b, curve->gamma) + curve->c) : (curve->c * x + curve->f); } return 0; } /* ICC tone response curve, linear to nonlinear (encoded). Input and output in range 0-1. Outside of that range, will not clip but either return x itself, or in cases where it makes sense, a value defined by the same function. NOTE: ICC requires clipping, but we do that only later when converting float to integer.*/ static float iccBackwardTRC(const LodePNGICCCurve* curve, float x) { if(curve->type == 0) { return x; } if(curve->type == 1) { size_t a, b, m; float v; if(x <= 0) return x; if(x >= 1) return x; /* binary search in the table */ /* TODO: use faster way of inverting the lookup table */ a = 0; b = curve->lut_size; for(;;) { if(a == b) return curve->lut[a]; if(a + 1 == b) { /* LERP */ float v0 = curve->lut[a]; float v1 = curve->lut[b]; float fraction; if(v0 == v1) return v0; fraction = (x - v0) / (v1 - v0); return v0 * (1 - fraction) + v1 * fraction; } m = (a + b) / 2u; v = curve->lut[m]; if(v > x) { b = m; } else { a = m; } } } if(curve->type == 2) { /* Gamma compression */ return (x > 0) ? lodepng_powf(x, 1.0f / curve->gamma) : x; } /* TODO: all the ones below are untested */ if(curve->type == 3) { if(x < 0) return x; return x > 0 ? ((lodepng_powf(x, 1.0f / curve->gamma) - curve->b) / curve->a) : (-curve->b / curve->a); } if(curve->type == 4) { if(x < 0) return x; return x > curve->c ? ((lodepng_powf(x - curve->c, 1.0f / curve->gamma) - curve->b) / curve->a) : (-curve->b / curve->a); } if(curve->type == 5) { return x > (curve->c * curve->d) ? ((lodepng_powf(x, 1.0f / curve->gamma) - curve->b) / curve->a) : (x / curve->c); } if(curve->type == 6) { return x > (curve->c * curve->d + curve->f) ? ((lodepng_powf(x - curve->c, 1.0f / curve->gamma) - curve->b) / curve->a) : ((x - curve->f) / curve->c); } return 0; } static unsigned decodeICCUint16(const unsigned char* data, size_t size, size_t* pos) { *pos += 2; if (*pos > size) return 0; return (unsigned)((data[*pos - 2] << 8) | (data[*pos - 1])); } static unsigned decodeICCUint32(const unsigned char* data, size_t size, size_t* pos) { *pos += 4; if (*pos > size) return 0; return (unsigned)((data[*pos - 4] << 24) | (data[*pos - 3] << 16) | (data[*pos - 2] << 8) | (data[*pos - 1] << 0)); } static int decodeICCInt32(const unsigned char* data, size_t size, size_t* pos) { *pos += 4; if (*pos > size) return 0; /*TODO: this is incorrect if sizeof(int) != 4*/ return (data[*pos - 4] << 24) | (data[*pos - 3] << 16) | (data[*pos - 2] << 8) | (data[*pos - 1] << 0); } static float decodeICC15Fixed16(const unsigned char* data, size_t size, size_t* pos) { return decodeICCInt32(data, size, pos) / 65536.0f; } static unsigned isICCword(const unsigned char* data, size_t size, size_t pos, const char* word) { if(pos + 4 > size) return 0; return data[pos + 0] == (unsigned char)word[0] && data[pos + 1] == (unsigned char)word[1] && data[pos + 2] == (unsigned char)word[2] && data[pos + 3] == (unsigned char)word[3]; } /* Parses a subset of the ICC profile, supporting the necessary mix of ICC v2 and ICC v4 required to correctly convert the RGB color space to XYZ. Does not parse values not related to this specific PNG-related purpose, and does not support non-RGB profiles or lookup-table based chroma (but it supports lookup tables for TRC aka "gamma"). */ static unsigned parseICC(LodePNGICC* icc, const unsigned char* data, size_t size) { size_t i, j; size_t pos = 0; unsigned version; unsigned inputspace; size_t numtags; if(size < 132) return 1; /* Too small to be a valid icc profile. */ icc->has_chromaticity = 0; icc->has_whitepoint = 0; icc->has_trc = 0; icc->has_chad = 0; icc->trc[0].type = icc->trc[1].type = icc->trc[2].type = 0; icc->white[0] = icc->white[1] = icc->white[2] = 0; icc->red[0] = icc->red[1] = icc->red[2] = 0; icc->green[0] = icc->green[1] = icc->green[2] = 0; icc->blue[0] = icc->blue[1] = icc->blue[2] = 0; pos = 8; version = decodeICCUint32(data, size, &pos); if(pos >= size) return 1; icc->version_major = (int)((version >> 24) & 255); icc->version_minor = (int)((version >> 20) & 15); icc->version_bugfix = (int)((version >> 16) & 15); pos = 16; inputspace = decodeICCUint32(data, size, &pos); if(pos >= size) return 1; if(inputspace == 0x47524159) { /* The string "GRAY" as unsigned 32-bit int. */ icc->inputspace = 1; } else if(inputspace == 0x52474220) { /* The string "RGB " as unsigned 32-bit int. */ icc->inputspace = 2; } else { /* unsupported by PNG (CMYK, YCbCr, Lab, HSV, ...) */ icc->inputspace = 0; } /* Should always be 0.9642, 1.0, 0.8249 */ pos = 68; icc->illuminant[0] = decodeICC15Fixed16(data, size, &pos); icc->illuminant[1] = decodeICC15Fixed16(data, size, &pos); icc->illuminant[2] = decodeICC15Fixed16(data, size, &pos); pos = 128; numtags = decodeICCUint32(data, size, &pos); if(pos >= size) return 1; /* scan for tags we want to handle */ for(i = 0; i < numtags; i++) { size_t offset; unsigned tagsize; size_t namepos = pos; pos += 4; offset = decodeICCUint32(data, size, &pos); tagsize = decodeICCUint32(data, size, &pos); if(pos >= size || offset >= size) return 1; if(offset + tagsize > size) return 1; if(tagsize < 8) return 1; if(isICCword(data, size, namepos, "wtpt")) { offset += 8; /* skip tag and reserved */ icc->white[0] = decodeICC15Fixed16(data, size, &offset); icc->white[1] = decodeICC15Fixed16(data, size, &offset); icc->white[2] = decodeICC15Fixed16(data, size, &offset); icc->has_whitepoint = 1; } else if(isICCword(data, size, namepos, "rXYZ")) { offset += 8; /* skip tag and reserved */ icc->red[0] = decodeICC15Fixed16(data, size, &offset); icc->red[1] = decodeICC15Fixed16(data, size, &offset); icc->red[2] = decodeICC15Fixed16(data, size, &offset); icc->has_chromaticity = 1; } else if(isICCword(data, size, namepos, "gXYZ")) { offset += 8; /* skip tag and reserved */ icc->green[0] = decodeICC15Fixed16(data, size, &offset); icc->green[1] = decodeICC15Fixed16(data, size, &offset); icc->green[2] = decodeICC15Fixed16(data, size, &offset); icc->has_chromaticity = 1; } else if(isICCword(data, size, namepos, "bXYZ")) { offset += 8; /* skip tag and reserved */ icc->blue[0] = decodeICC15Fixed16(data, size, &offset); icc->blue[1] = decodeICC15Fixed16(data, size, &offset); icc->blue[2] = decodeICC15Fixed16(data, size, &offset); icc->has_chromaticity = 1; } else if(isICCword(data, size, namepos, "chad")) { offset += 8; /* skip datatype keyword "sf32" and reserved */ for(j = 0; j < 9; j++) { icc->chad[j] = decodeICC15Fixed16(data, size, &offset); } icc->has_chad = 1; } else if(isICCword(data, size, namepos, "rTRC") || isICCword(data, size, namepos, "gTRC") || isICCword(data, size, namepos, "bTRC") || isICCword(data, size, namepos, "kTRC")) { char c = (char)data[namepos]; /* both 'k' and 'r' are stored in channel 0 */ int channel = (c == 'b') ? 2 : (c == 'g' ? 1 : 0); /* "curv": linear, gamma power or LUT */ if(isICCword(data, size, offset, "curv")) { size_t count; LodePNGICCCurve* trc = &icc->trc[channel]; icc->has_trc = 1; offset += 8; /* skip tag "curv" and reserved */ count = decodeICCUint32(data, size, &offset); if(count == 0) { trc->type = 0; /* linear */ } else if(count == 1) { trc->type = 2; /* gamma */ trc->gamma = decodeICCUint16(data, size, &offset) / 256.0f; } else { trc->type = 1; /* LUT */ if(offset + count * 2 > size || count > 16777216) return 1; /* also avoid crazy count */ trc->lut_size = count; trc->lut = (float*)lodepng_malloc(count * sizeof(float)); for(j = 0; j < count; j++) { trc->lut[j] = decodeICCUint16(data, size, &offset) * (1.0f / 65535.0f); } } } /* "para": parametric formula with gamma power, multipliers, biases and comparison point */ /* TODO: test this on a realistic sample */ if(isICCword(data, size, offset, "para")) { unsigned type; LodePNGICCCurve* trc = &icc->trc[channel]; icc->has_trc = 1; offset += 8; /* skip tag "para" and reserved */ type = decodeICCUint16(data, size, &offset); offset += 2; if(type > 4) return 1; /* unknown parametric curve type */ trc->type = type + 2; trc->gamma = decodeICC15Fixed16(data, size, &offset); if(type >= 1) { trc->a = decodeICC15Fixed16(data, size, &offset); trc->b = decodeICC15Fixed16(data, size, &offset); } if(type >= 2) { trc->c = decodeICC15Fixed16(data, size, &offset); } if(type >= 3) { trc->d = decodeICC15Fixed16(data, size, &offset); } if(type == 4) { trc->e = decodeICC15Fixed16(data, size, &offset); trc->f = decodeICC15Fixed16(data, size, &offset); } } /* TODO: verify: does the "chrm" tag participate in computation so should be parsed? */ } /* Return error if any parse went beyond the filesize. Note that the parsing itself was always safe since it bound-checks inside. */ if(offset > size) return 1; } return 0; } /* Multiplies 3 vector values with 3x3 matrix */ static void mulMatrix(float* x2, float* y2, float* z2, const float* m, double x, double y, double z) { /* double used as inputs even though in general the images are float, so the sums happen in double precision, because float can give numerical problems for nearby values */ *x2 = (float)(x * m[0] + y * m[1] + z * m[2]); *y2 = (float)(x * m[3] + y * m[4] + z * m[5]); *z2 = (float)(x * m[6] + y * m[7] + z * m[8]); } static void mulMatrixMatrix(float* result, const float* a, const float* b) { int i; float temp[9]; /* temp is to allow result and a or b to be the same */ mulMatrix(&temp[0], &temp[3], &temp[6], a, b[0], b[3], b[6]); mulMatrix(&temp[1], &temp[4], &temp[7], a, b[1], b[4], b[7]); mulMatrix(&temp[2], &temp[5], &temp[8], a, b[2], b[5], b[8]); for(i = 0; i < 9; i++) result[i] = temp[i]; } /* Inverts 3x3 matrix in place */ static unsigned invMatrix(float* m) { int i; /* double used instead of float for intermediate computations to avoid intermediate numerical precision issues */ double e0 = (double)m[4] * m[8] - (double)m[5] * m[7]; double e3 = (double)m[5] * m[6] - (double)m[3] * m[8]; double e6 = (double)m[3] * m[7] - (double)m[4] * m[6]; /* inverse determinant */ double d = 1.0 / (m[0] * e0 + m[1] * e3 + m[2] * e6); double result[9]; if((d > 0 ? d : -d) > 1e15) return 1; /* error, likely not invertible */ result[0] = e0 * d; result[1] = ((double)m[2] * m[7] - (double)m[1] * m[8]) * d; result[2] = ((double)m[1] * m[5] - (double)m[2] * m[4]) * d; result[3] = e3 * d; result[4] = ((double)m[0] * m[8] - (double)m[2] * m[6]) * d; result[5] = ((double)m[3] * m[2] - (double)m[0] * m[5]) * d; result[6] = e6 * d; result[7] = ((double)m[6] * m[1] - (double)m[0] * m[7]) * d; result[8] = ((double)m[0] * m[4] - (double)m[3] * m[1]) * d; for(i = 0; i < 9; i++) m[i] = (float)result[i]; return 0; /* ok */ } /* Get the matrix to go from linear RGB to XYZ given the RGB whitepoint and chromaticities in XYZ colorspace */ static unsigned getChrmMatrixXYZ(float* m, float wX, float wY, float wZ, float rX, float rY, float rZ, float gX, float gY, float gZ, float bX, float bY, float bZ) { float t[9]; float rs, gs, bs; t[0] = rX; t[1] = gX; t[2] = bX; t[3] = rY; t[4] = gY; t[5] = bY; t[6] = rZ; t[7] = gZ; t[8] = bZ; if(invMatrix(t)) return 1; /* error, not invertible */ mulMatrix(&rs, &gs, &bs, t, wX, wY, wZ); m[0] = rs * rX; m[1] = gs * gX; m[2] = bs * bX; m[3] = rs * rY; m[4] = gs * gY; m[5] = bs * bY; m[6] = rs * rZ; m[7] = gs * gZ; m[8] = bs * bZ; return 0; } /* Get the matrix to go from linear RGB to XYZ given the RGB whitepoint and chromaticities in xy colorspace */ static unsigned getChrmMatrixXY(float* m, float wx, float wy, float rx, float ry, float gx, float gy, float bx, float by) { if(wy == 0 || ry == 0 || gy == 0 || by == 0) { return 1; /* error, division through zero */ } else { float wX = wx / wy, wY = 1, wZ = (1 - wx - wy) / wy; float rX = rx / ry, rY = 1, rZ = (1 - rx - ry) / ry; float gX = gx / gy, gY = 1, gZ = (1 - gx - gy) / gy; float bX = bx / by, bY = 1, bZ = (1 - bx - by) / by; return getChrmMatrixXYZ(m, wX, wY, wZ, rX, rY, rZ, gX, gY, gZ, bX, bY, bZ); } } /* Returns matrix that adapts from source whitepoint 0 to destination whitepoint 1. Types: 0=XYZ scaling, 1=Bradford, 2=Vonkries */ static unsigned getAdaptationMatrix(float* m, int type, float wx0, float wy0, float wz0, float wx1, float wy1, float wz1) { int i; static const float bradford[9] = { 0.8951f, 0.2664f, -0.1614f, -0.7502f, 1.7135f, 0.0367f, 0.0389f, -0.0685f, 1.0296f }; static const float bradfordinv[9] = { 0.9869929f, -0.1470543f, 0.1599627f, 0.4323053f, 0.5183603f, 0.0492912f, -0.0085287f, 0.0400428f, 0.9684867f }; static const float vonkries[9] = { 0.40024f, 0.70760f, -0.08081f, -0.22630f, 1.16532f, 0.04570f, 0.00000f, 0.00000f, 0.91822f, }; static const float vonkriesinv[9] = { 1.8599364f, -1.1293816f, 0.2198974f, 0.3611914f, 0.6388125f, -0.0000064f, 0.0000000f, 0.0000000f, 1.0890636f }; if(type == 0) { for(i = 0; i < 9; i++) m[i] = 0; m[0] = wx1 / wx0; m[4] = wy1 / wy0; m[8] = wz1 / wz0; } else { const float* cat = (type == 1) ? bradford : vonkries; const float* inv = (type == 1) ? bradfordinv : vonkriesinv; float rho0, gam0, bet0, rho1, gam1, bet1, rho2, gam2, bet2; mulMatrix(&rho0, &gam0, &bet0, cat, wx0, wy0, wz0); mulMatrix(&rho1, &gam1, &bet1, cat, wx1, wy1, wz1); rho2 = rho1 / rho0; gam2 = gam1 / gam0; bet2 = bet1 / bet0; /* Multiply diagonal matrix with cat */ for(i = 0; i < 3; i++) { m[i + 0] = rho2 * cat[i + 0]; m[i + 3] = gam2 * cat[i + 3]; m[i + 6] = bet2 * cat[i + 6]; } mulMatrixMatrix(m, inv, m); } return 0; /* ok */ } /* validate whether the ICC profile is supported here for PNG */ static unsigned validateICC(const LodePNGICC* icc) { /* disable for unsupported things in the icc profile */ if(icc->inputspace == 0) return 0; /* if we didn't recognize both chrm and trc, then maybe the ICC uses data types not supported here yet, so fall back to not using it. */ if(icc->inputspace == 2) { /* RGB profile should have chromaticities */ if(!icc->has_chromaticity) return 0; } /* An ICC profile without whitepoint is invalid for the kind of profiles used here. */ if(!icc->has_whitepoint) return 0; if(!icc->has_trc) return 0; return 1; /* ok */ } /* Returns chromaticity matrix for given ICC profile, adapted from ICC's global illuminant as necessary. Also returns the profile's whitepoint. In case of a gray profile (icc->inputspace == 1), the identity matrix will be returned so in that case you could skip the transform. */ static unsigned getICCChrm(float m[9], float whitepoint[3], const LodePNGICC* icc) { size_t i; if(icc->inputspace == 2) { /* RGB profile */ float red[3], green[3], blue[3]; float white[3]; /* the whitepoint of the RGB color space (absolute) */ /* Adaptation matrix a. This is an adaptation needed for ICC's file format (due to it using an internal global illuminant unrelated to the actual images) */ float a[9] = {1,0,0, 0,1,0, 0,0,1}; /* If the profile has chromatic adaptation matrix "chad", use that one, else compute it from the illuminant and whitepoint. */ if(icc->has_chad) { for(i = 0; i < 9; i++) a[i] = icc->chad[i]; invMatrix(a); } else { if(getAdaptationMatrix(a, 1, icc->illuminant[0], icc->illuminant[1], icc->illuminant[2], icc->white[0], icc->white[1], icc->white[2])) { return 1; /* error computing matrix */ } } /* If the profile has a chad, then also the RGB's whitepoint must also be adapted from it (and the one given is normally D50). If it did not have a chad, then the whitepoint given is already the adapted one. */ if(icc->has_chad) { mulMatrix(&white[0], &white[1], &white[2], a, icc->white[0], icc->white[1], icc->white[2]); } else { for(i = 0; i < 3; i++) white[i] = icc->white[i]; } mulMatrix(&red[0], &red[1], &red[2], a, icc->red[0], icc->red[1], icc->red[2]); mulMatrix(&green[0], &green[1], &green[2], a, icc->green[0], icc->green[1], icc->green[2]); mulMatrix(&blue[0], &blue[1], &blue[2], a, icc->blue[0], icc->blue[1], icc->blue[2]); if(getChrmMatrixXYZ(m, white[0], white[1], white[2], red[0], red[1], red[2], green[0], green[1], green[2], blue[0], blue[1], blue[2])) { return 1; /* error computing matrix */ } /* output absolute whitepoint of the original RGB model */ whitepoint[0] = white[0]; whitepoint[1] = white[1]; whitepoint[2] = white[2]; } else { /* output the unity matrix, for doing no transform */ m[0] = m[4] = m[8] = 1; m[1] = m[2] = m[3] = m[5] = m[6] = m[7] = 0; /* grayscale, don't do anything. That means we are implicitely using equal energy whitepoint "E", indicate this to the output. */ whitepoint[0] = whitepoint[1] = whitepoint[2] = 1; } return 0; /* success */ } /* Outputs whitepoint and matrix to go from the icc or info profile (depending on what was in the PNG) to XYZ, without applying any (rendering intent related) whitepoint adaptation */ static unsigned getChrm(float m[9], float whitepoint[3], unsigned use_icc, const LodePNGICC* icc, const LodePNGInfo* info) { size_t i; if(use_icc) { if(getICCChrm(m, whitepoint, icc)) return 1; /* error in the matrix computations */ } else if(info->chrm_defined && !info->srgb_defined) { float wx = info->chrm_white_x / 100000.0f, wy = info->chrm_white_y / 100000.0f; float rx = info->chrm_red_x / 100000.0f, ry = info->chrm_red_y / 100000.0f; float gx = info->chrm_green_x / 100000.0f, gy = info->chrm_green_y / 100000.0f; float bx = info->chrm_blue_x / 100000.0f, by = info->chrm_blue_y / 100000.0f; if(getChrmMatrixXY(m, wx, wy, rx, ry, gx, gy, bx, by)) return 1; /* returns if error */ /* Output whitepoint, xyY to XYZ: */ whitepoint[0] = wx / wy; whitepoint[1] = 1; whitepoint[2] = (1 - wx - wy) / wy; } else { /* the standard linear sRGB to XYZ matrix */ static const float srgb[9] = { 0.4124564f, 0.3575761f, 0.1804375f, 0.2126729f, 0.7151522f, 0.0721750f, 0.0193339f, 0.1191920f, 0.9503041f }; for(i = 0; i < 9; i++) m[i] = srgb[i]; /* sRGB's whitepoint xyY "0.3127,0.3290,1" in XYZ: */ whitepoint[0] = 0.9504559270516716f; whitepoint[1] = 1; whitepoint[2] = 1.0890577507598784f; } return 0; } /* Returns whether the color chunks in info represent the default PNG sRGB, which is when either no colorometry fields are present at all, or an srgb field or chrm/gama field with default values are present. ICC chunks representing sRGB are currently considered not the same. */ static unsigned isSRGB(const LodePNGInfo* info) { if(!info) return 1; /* the default is considered sRGB. */ /* TODO: support some ICC profiles that represent sRGB too. Tricky due to possible slight deviations and many ways of representing its gamma function. */ if(info->iccp_defined) return 0; if(info->srgb_defined) return 1; /* The gamma chunk is unable to represent sRGB's two-part gamma, so cannot be sRGB, even if it's the default 45455. */ if(info->gama_defined) return 0; if(info->chrm_defined) { if(info->chrm_white_x != 31270 || info->chrm_white_y != 32900) return 0; if(info->chrm_red_x != 64000 || info->chrm_red_y != 33000) return 0; if(info->chrm_green_x != 30000 || info->chrm_green_y != 60000) return 0; if(info->chrm_blue_x != 15000 || info->chrm_blue_y != 6000) return 0; } return 1; } /* Checks whether the RGB models are equal (chromaticities, ...). The raw byte format is allowed to be different. Input pointers are allowed to be null, they then represent the default PNG sRGB (same as having no color model chunks at all or an srgb chunk in the PNG) */ static unsigned modelsEqual(const LodePNGState* state_a, const LodePNGState* state_b) { size_t i; const LodePNGInfo* a = state_a ? &state_a->info_png : 0; const LodePNGInfo* b = state_b ? &state_b->info_png : 0; if(isSRGB(a) != isSRGB(b)) return 0; /* now a and b are guaranteed to be non-NULL */ if(a->iccp_defined != b->iccp_defined) return 0; if(a->iccp_defined) { if(a->iccp_profile_size != b->iccp_profile_size) return 0; /* TODO: return equal in more cases, such as when two ICC profiles that are not byte-for-byte equal, but represent the same color model. */ for(i = 0; i < a->iccp_profile_size; i++) { if(a->iccp_profile[i] != b->iccp_profile[i]) return 0; } /* since the ICC model overrides gamma and chrm, those can be ignored. */ /* TODO: this doesn't cover the case where the ICC profile is invalid */ return 1; } if(a->srgb_defined != b->srgb_defined) return 0; if(a->srgb_defined) { /* since the sRGB model overrides gamma and chrm, those can be ignored. srgb_intent not checked since the conversion ignores it */ return 1; } if(a->gama_defined != b->gama_defined) return 0; if(a->gama_defined) { if(a->gama_gamma != b->gama_gamma) return 0; } if(a->chrm_defined != b->chrm_defined) return 0; if(a->chrm_defined) { if(a->chrm_white_x != b->chrm_white_x) return 0; if(a->chrm_white_y != b->chrm_white_y) return 0; if(a->chrm_red_x != b->chrm_red_x) return 0; if(a->chrm_red_y != b->chrm_red_y) return 0; if(a->chrm_green_x != b->chrm_green_x) return 0; if(a->chrm_green_y != b->chrm_green_y) return 0; if(a->chrm_blue_x != b->chrm_blue_x) return 0; if(a->chrm_blue_y != b->chrm_blue_y) return 0; } return 1; } /* Converts in-place. Does not clamp. Do not use for integer input, make table instead there. */ static void convertToXYZ_gamma(float* out, const float* in, unsigned w, unsigned h, const LodePNGInfo* info, unsigned use_icc, const LodePNGICC* icc) { size_t i, c; size_t n = w * h; for(i = 0; i < n * 4; i++) { out[i] = in[i]; } if(use_icc) { for(i = 0; i < n; i++) { for(c = 0; c < 3; c++) { /* TODO: this is likely very slow */ out[i * 4 + c] = iccForwardTRC(&icc->trc[c], in[i * 4 + c]); } } } else if(info->gama_defined && !info->srgb_defined) { /* nothing to do if gamma is 1 */ if(info->gama_gamma != 100000) { float gamma = 100000.0f / info->gama_gamma; for(i = 0; i < n; i++) { for(c = 0; c < 3; c++) { float v = in[i * 4 + c]; out[i * 4 + c] = (v <= 0) ? v : lodepng_powf(v, gamma); } } } } else { for(i = 0; i < n; i++) { for(c = 0; c < 3; c++) { /* sRGB gamma expand */ float v = in[i * 4 + c]; out[i * 4 + c] = (v < 0.04045f) ? (v / 12.92f) : lodepng_powf((v + 0.055f) / 1.055f, 2.4f); } } } } /* Same as convertToXYZ_gamma, but creates a lookup table rather than operating on an image */ static void convertToXYZ_gamma_table(float* out, size_t n, size_t c, const LodePNGInfo* info, unsigned use_icc, const LodePNGICC* icc) { size_t i; float mul = 1.0f / (n - 1); if(use_icc) { for(i = 0; i < n; i++) { float v = i * mul; out[i] = iccForwardTRC(&icc->trc[c], v); } } else if(info->gama_defined && !info->srgb_defined) { /* no power needed if gamma is 1 */ if(info->gama_gamma == 100000) { for(i = 0; i < n; i++) { out[i] = i * mul; } } else { float gamma = 100000.0f / info->gama_gamma; for(i = 0; i < n; i++) { float v = i * mul; out[i] = lodepng_powf(v, gamma); } } } else { for(i = 0; i < n; i++) { /* sRGB gamma expand */ float v = i * mul; out[i] = (v < 0.04045f) ? (v / 12.92f) : lodepng_powf((v + 0.055f) / 1.055f, 2.4f); } } } /* In-place */ static unsigned convertToXYZ_chrm(float* im, unsigned w, unsigned h, const LodePNGInfo* info, unsigned use_icc, const LodePNGICC* icc, float whitepoint[3]) { unsigned error = 0; size_t i; size_t n = w * h; float m[9]; /* XYZ to linear RGB matrix */ /* Must be called even for grayscale, to get the correct whitepoint to output */ error = getChrm(m, whitepoint, use_icc, icc, info); if(error) return error; /* Note: no whitepoint adaptation done to m here, because we only do the adaptation in convertFromXYZ (we only whitepoint adapt when going to the target RGB space, but here we're going from the source RGB space to XYZ) */ /* Apply the above computed linear-RGB-to-XYZ matrix to the pixels. Skip the transform if it's the unit matrix (which is the case if grayscale profile) */ if(!use_icc || icc->inputspace == 2) { for(i = 0; i < n; i++) { size_t j = i * 4; mulMatrix(&im[j + 0], &im[j + 1], &im[j + 2], m, im[j + 0], im[j + 1], im[j + 2]); } } return 0; } unsigned convertToXYZ(float* out, float whitepoint[3], const unsigned char* in, unsigned w, unsigned h, const LodePNGState* state) { unsigned error = 0; size_t i; size_t n = w * h; const LodePNGColorMode* mode_in = &state->info_raw; const LodePNGInfo* info = &state->info_png; unsigned char* data = 0; float* gammatable = 0; int bit16 = mode_in->bitdepth > 8; size_t num = bit16 ? 65536 : 256; LodePNGColorMode tempmode = lodepng_color_mode_make(LCT_RGBA, bit16 ? 16 : 8); unsigned use_icc = 0; LodePNGICC icc; lodepng_icc_init(&icc); if(info->iccp_defined) { error = parseICC(&icc, info->iccp_profile, info->iccp_profile_size); if(error) goto cleanup; /* corrupted ICC profile */ use_icc = validateICC(&icc); } data = (unsigned char*)lodepng_malloc(w * h * (bit16 ? 8 : 4)); error = lodepng_convert(data, in, &tempmode, mode_in, w, h); if(error) goto cleanup; /* Handle transfer function */ { float* gammatable_r; float* gammatable_g; float* gammatable_b; /* RGB ICC, can have three different transfer functions */ if(use_icc && icc.inputspace == 2) { gammatable = (float*)lodepng_malloc(num * 3 * sizeof(float)); gammatable_r = &gammatable[num * 0]; gammatable_g = &gammatable[num * 1]; gammatable_b = &gammatable[num * 2]; convertToXYZ_gamma_table(gammatable_r, num, 0, info, use_icc, &icc); convertToXYZ_gamma_table(gammatable_g, num, 1, info, use_icc, &icc); convertToXYZ_gamma_table(gammatable_b, num, 2, info, use_icc, &icc); } else { gammatable = (float*)lodepng_malloc(num * sizeof(float)); gammatable_r = gammatable_g = gammatable_b = gammatable; convertToXYZ_gamma_table(gammatable, num, 0, info, use_icc, &icc); } if(bit16) { for(i = 0; i < n; i++) { out[i * 4 + 0] = gammatable_r[data[i * 8 + 0] * 256u + data[i * 8 + 1]]; out[i * 4 + 1] = gammatable_g[data[i * 8 + 2] * 256u + data[i * 8 + 3]]; out[i * 4 + 2] = gammatable_b[data[i * 8 + 4] * 256u + data[i * 8 + 5]]; out[i * 4 + 3] = (data[i * 8 + 6] * 256 + data[i * 8 + 7]) * (1 / 65535.0f); } } else { for(i = 0; i < n; i++) { out[i * 4 + 0] = gammatable_r[data[i * 4 + 0]]; out[i * 4 + 1] = gammatable_g[data[i * 4 + 1]]; out[i * 4 + 2] = gammatable_b[data[i * 4 + 2]]; out[i * 4 + 3] = data[i * 4 + 3] * (1 / 255.0f); } } } convertToXYZ_chrm(out, w, h, info, use_icc, &icc, whitepoint); cleanup: lodepng_icc_cleanup(&icc); lodepng_free(data); lodepng_free(gammatable); return error; } unsigned convertToXYZFloat(float* out, float whitepoint[3], const float* in, unsigned w, unsigned h, const LodePNGState* state) { unsigned error = 0; const LodePNGInfo* info = &state->info_png; unsigned use_icc = 0; LodePNGICC icc; lodepng_icc_init(&icc); if(info->iccp_defined) { error = parseICC(&icc, info->iccp_profile, info->iccp_profile_size); if(error) goto cleanup; /* corrupted ICC profile */ use_icc = validateICC(&icc); } /* Input is floating point, so lookup table cannot be used, but it's ensured to use float pow, not the slower double pow. */ convertToXYZ_gamma(out, in, w, h, info, use_icc, &icc); convertToXYZ_chrm(out, w, h, info, use_icc, &icc, whitepoint); cleanup: lodepng_icc_cleanup(&icc); return error; } static unsigned convertFromXYZ_chrm(float* out, const float* in, unsigned w, unsigned h, const LodePNGInfo* info, unsigned use_icc, const LodePNGICC* icc, const float whitepoint[3], unsigned rendering_intent) { size_t i; size_t n = w * h; float m[9]; /* XYZ to linear RGB matrix */ float white[3]; /* The whitepoint (absolute) of the target RGB space */ if(getChrm(m, white, use_icc, icc, info)) return 1; if(invMatrix(m)) return 1; /* error, not invertible */ /* for relative rendering intent (any except absolute "3"), must whitepoint adapt to the original whitepoint. this also ensures grayscale stays grayscale (with absolute, grayscale could become e.g. blue or sepia) */ if(rendering_intent != 3) { float a[9] = {1,0,0, 0,1,0, 0,0,1}; /* "white" = absolute whitepoint of the new target RGB space, read from the target color profile. "whitepoint" is original absolute whitepoint (input as parameter of this function) of an RGB space the XYZ data once had before it was converted to XYZ, in other words the whitepoint that we want to adapt our current data to to make sure values that had equal R==G==B in the old space have the same property now (white stays white and gray stays gray). Note: "absolute" whitepoint above means, can be used as-is, not needing further adaptation itself like icc.white does.*/ if(getAdaptationMatrix(a, 1, whitepoint[0], whitepoint[1], whitepoint[2], white[0], white[1], white[2])) { return 1; } /* multiply the from xyz matrix with the adaptation matrix: in total, the resulting matrix first adapts in XYZ space, then converts to RGB*/ mulMatrixMatrix(m, m, a); } /* Apply the above computed XYZ-to-linear-RGB matrix to the pixels. This transformation also includes the whitepoint adaptation. The transform can be skipped only if it's the unit matrix (only if grayscale profile and no whitepoint adaptation, such as with rendering intent 3)*/ if(!use_icc || icc->inputspace == 2 || rendering_intent != 3) { for(i = 0; i < n; i++) { size_t j = i * 4; mulMatrix(&out[j + 0], &out[j + 1], &out[j + 2], m, in[j + 0], in[j + 1], in[j + 2]); out[j + 3] = in[j + 3]; } } else { for(i = 0; i < n * 4; i++) { out[i] = in[i]; } } return 0; } /* Converts in-place. Does not clamp. */ static void convertFromXYZ_gamma(float* im, unsigned w, unsigned h, const LodePNGInfo* info, unsigned use_icc, const LodePNGICC* icc) { size_t i, c; size_t n = w * h; if(use_icc) { for(i = 0; i < n; i++) { for(c = 0; c < 3; c++) { /* TODO: this is likely very slow */ im[i * 4 + c] = iccBackwardTRC(&icc->trc[c], im[i * 4 + c]); } } } else if(info->gama_defined && !info->srgb_defined) { /* nothing to do if gamma is 1 */ if(info->gama_gamma != 100000) { float gamma = info->gama_gamma / 100000.0f; for(i = 0; i < n; i++) { for(c = 0; c < 3; c++) { if(im[i * 4 + c] > 0) im[i * 4 + c] = lodepng_powf(im[i * 4 + c], gamma); } } } } else { for(i = 0; i < n; i++) { for(c = 0; c < 3; c++) { /* sRGB gamma compress */ float* v = &im[i * 4 + c]; *v = (*v < 0.0031308f) ? (*v * 12.92f) : (1.055f * lodepng_powf(*v, 1 / 2.4f) - 0.055f); } } } } unsigned convertFromXYZ(unsigned char* out, const float* in, unsigned w, unsigned h, const LodePNGState* state, const float whitepoint[3], unsigned rendering_intent) { unsigned error = 0; size_t i, c; size_t n = w * h; const LodePNGColorMode* mode_out = &state->info_raw; const LodePNGInfo* info = &state->info_png; int bit16 = mode_out->bitdepth > 8; float* im = 0; unsigned char* data = 0; /* parse ICC if present */ unsigned use_icc = 0; LodePNGICC icc; lodepng_icc_init(&icc); if(info->iccp_defined) { error = parseICC(&icc, info->iccp_profile, info->iccp_profile_size); if(error) goto cleanup; /* corrupted ICC profile */ use_icc = validateICC(&icc); } /* Handle gamut */ im = (float*)lodepng_malloc(w * h * 4 * sizeof(float)); error = convertFromXYZ_chrm(im, in, w, h, info, use_icc, &icc, whitepoint, rendering_intent); if(error) goto cleanup; /* Handle transfer function */ /* Input is floating point, so lookup table cannot be used, but it's ensured to use float pow, not the slower double pow. */ convertFromXYZ_gamma(im, w, h, info, use_icc, &icc); /* Convert to integer output */ data = (unsigned char*)lodepng_malloc(w * h * 8); /* TODO: check if also 1/2/4 bit case needed: rounding is at different fine-grainedness for 8 and 16 bits below. */ if(bit16) { LodePNGColorMode mode16 = lodepng_color_mode_make(LCT_RGBA, 16); for(i = 0; i < n; i++) { for(c = 0; c < 4; c++) { size_t j = i * 8 + c * 2; int i16 = (int)(0.5f + 65535.0f * LODEPNG_MIN(LODEPNG_MAX(0.0f, im[i * 4 + c]), 1.0f)); data[j + 0] = (unsigned char)(i16 >> 8); data[j + 1] = (unsigned char)(i16 & 255); } } error = lodepng_convert(out, data, mode_out, &mode16, w, h); if(error) goto cleanup; } else { LodePNGColorMode mode8 = lodepng_color_mode_make(LCT_RGBA, 8); for(i = 0; i < n; i++) { for(c = 0; c < 4; c++) { data[i * 4 + c] = (unsigned char)(0.5f + 255.0f * LODEPNG_MIN(LODEPNG_MAX(0.0f, im[i * 4 + c]), 1.0f)); } } error = lodepng_convert(out, data, mode_out, &mode8, w, h); if(error) goto cleanup; } cleanup: lodepng_icc_cleanup(&icc); lodepng_free(im); lodepng_free(data); return error; } unsigned convertFromXYZFloat(float* out, const float* in, unsigned w, unsigned h, const LodePNGState* state, const float whitepoint[3], unsigned rendering_intent) { unsigned error = 0; const LodePNGInfo* info = &state->info_png; /* parse ICC if present */ unsigned use_icc = 0; LodePNGICC icc; lodepng_icc_init(&icc); if(info->iccp_defined) { error = parseICC(&icc, info->iccp_profile, info->iccp_profile_size); if(error) goto cleanup; /* corrupted ICC profile */ use_icc = validateICC(&icc); } /* Handle gamut */ error = convertFromXYZ_chrm(out, in, w, h, info, use_icc, &icc, whitepoint, rendering_intent); if(error) goto cleanup; /* Handle transfer function */ convertFromXYZ_gamma(out, w, h, info, use_icc, &icc); cleanup: lodepng_icc_cleanup(&icc); return error; } unsigned convertRGBModel(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, const LodePNGState* state_out, const LodePNGState* state_in, unsigned rendering_intent) { if(modelsEqual(state_in, state_out)) { return lodepng_convert(out, in, &state_out->info_raw, &state_in->info_raw, w, h); } else { unsigned error = 0; float* xyz = (float*)lodepng_malloc(w * h * 4 * sizeof(float)); float whitepoint[3]; error = convertToXYZ(&xyz[0], whitepoint, in, w, h, state_in); if (!error) error = convertFromXYZ(out, &xyz[0], w, h, state_out, whitepoint, rendering_intent); lodepng_free(xyz); return error; } } unsigned convertToSrgb(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, const LodePNGState* state_in) { LodePNGState srgb; lodepng_state_init(&srgb); lodepng_color_mode_copy(&srgb.info_raw, &state_in->info_raw); return convertRGBModel(out, in, w, h, &srgb, state_in, 1); } unsigned convertFromSrgb(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, const LodePNGState* state_out) { LodePNGState srgb; lodepng_state_init(&srgb); lodepng_color_mode_copy(&srgb.info_raw, &state_out->info_raw); return convertRGBModel(out, in, w, h, state_out, &srgb, 1); } #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ //////////////////////////////////////////////////////////////////////////////// //This uses a stripped down version of picoPNG to extract detailed zlib information while decompressing. static const unsigned long LENBASE[29] = {3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258}; static const unsigned long LENEXTRA[29] = {0,0,0,0,0,0,0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0}; static const unsigned long DISTBASE[30] = {1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577}; static const unsigned long DISTEXTRA[30] = {0,0,0,0,1,1,2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13}; static const unsigned long CLCL[19] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; //code length code lengths struct ExtractZlib { // Zlib decompression and information extraction std::vector* zlibinfo; ExtractZlib(std::vector* info) : zlibinfo(info) {}; int error; unsigned long readBitFromStream(size_t& bitp, const unsigned char* bits) { unsigned long result = (bits[bitp >> 3] >> (bitp & 0x7)) & 1; bitp++; return result; } unsigned long readBitsFromStream(size_t& bitp, const unsigned char* bits, size_t nbits) { unsigned long result = 0; for(size_t i = 0; i < nbits; i++) result += (readBitFromStream(bitp, bits)) << i; return result; } struct HuffmanTree { int makeFromLengths(const std::vector& bitlen, unsigned long maxbitlen) { //make tree given the lengths unsigned long numcodes = (unsigned long)(bitlen.size()), treepos = 0, nodefilled = 0; std::vector tree1d(numcodes), blcount(maxbitlen + 1, 0), nextcode(maxbitlen + 1, 0); //count number of instances of each code length for(unsigned long bits = 0; bits < numcodes; bits++) blcount[bitlen[bits]]++; for(unsigned long bits = 1; bits <= maxbitlen; bits++) { nextcode[bits] = (nextcode[bits - 1] + blcount[bits - 1]) << 1; } //generate all the codes for(unsigned long n = 0; n < numcodes; n++) if(bitlen[n] != 0) tree1d[n] = nextcode[bitlen[n]]++; tree2d.clear(); tree2d.resize(numcodes * 2, 32767); //32767 here means the tree2d isn't filled there yet for(unsigned long n = 0; n < numcodes; n++) //the codes for(unsigned long i = 0; i < bitlen[n]; i++) { //the bits for this code unsigned long bit = (tree1d[n] >> (bitlen[n] - i - 1)) & 1; if(treepos > numcodes - 2) return 55; if(tree2d[2 * treepos + bit] == 32767) { //not yet filled in if(i + 1 == bitlen[n]) { //last bit tree2d[2 * treepos + bit] = n; treepos = 0; } else { //addresses are encoded as values > numcodes tree2d[2 * treepos + bit] = ++nodefilled + numcodes; treepos = nodefilled; } } else treepos = tree2d[2 * treepos + bit] - numcodes; //subtract numcodes from address to get address value } return 0; } int decode(bool& decoded, unsigned long& result, size_t& treepos, unsigned long bit) const { //Decodes a symbol from the tree unsigned long numcodes = (unsigned long)tree2d.size() / 2; if(treepos >= numcodes) return 11; //error: you appeared outside the codetree result = tree2d[2 * treepos + bit]; decoded = (result < numcodes); treepos = decoded ? 0 : result - numcodes; return 0; } //2D representation of a huffman tree: one dimension is "0" or "1", the other contains all nodes and leaves. std::vector tree2d; }; void inflate(std::vector& out, const std::vector& in, size_t inpos = 0) { size_t bp = 0, pos = 0; //bit pointer and byte pointer error = 0; unsigned long BFINAL = 0; while(!BFINAL && !error) { size_t uncomprblockstart = pos; size_t bpstart = bp; if(bp >> 3 >= in.size()) { error = 52; return; } //error, bit pointer will jump past memory BFINAL = readBitFromStream(bp, &in[inpos]); unsigned long BTYPE = readBitFromStream(bp, &in[inpos]); BTYPE += 2 * readBitFromStream(bp, &in[inpos]); zlibinfo->resize(zlibinfo->size() + 1); zlibinfo->back().btype = BTYPE; if(BTYPE == 3) { error = 20; return; } //error: invalid BTYPE else if(BTYPE == 0) inflateNoCompression(out, &in[inpos], bp, pos, in.size()); else inflateHuffmanBlock(out, &in[inpos], bp, pos, in.size(), BTYPE); size_t uncomprblocksize = pos - uncomprblockstart; zlibinfo->back().compressedbits = bp - bpstart; zlibinfo->back().uncompressedbytes = uncomprblocksize; } } void generateFixedTrees(HuffmanTree& tree, HuffmanTree& treeD) { //get the tree of a deflated block with fixed tree std::vector bitlen(288, 8), bitlenD(32, 5);; for(size_t i = 144; i <= 255; i++) bitlen[i] = 9; for(size_t i = 256; i <= 279; i++) bitlen[i] = 7; tree.makeFromLengths(bitlen, 15); treeD.makeFromLengths(bitlenD, 15); } //the code tree for Huffman codes, dist codes, and code length codes HuffmanTree codetree, codetreeD, codelengthcodetree; unsigned long huffmanDecodeSymbol(const unsigned char* in, size_t& bp, const HuffmanTree& tree, size_t inlength) { //decode a single symbol from given list of bits with given code tree. return value is the symbol bool decoded; unsigned long ct; for(size_t treepos = 0;;) { if((bp & 0x07) == 0 && (bp >> 3) > inlength) { error = 10; return 0; } //error: end reached without endcode error = tree.decode(decoded, ct, treepos, readBitFromStream(bp, in)); if(error) return 0; //stop, an error happened if(decoded) return ct; } } void getTreeInflateDynamic(HuffmanTree& tree, HuffmanTree& treeD, const unsigned char* in, size_t& bp, size_t inlength) { size_t bpstart = bp; //get the tree of a deflated block with dynamic tree, the tree itself is also Huffman compressed with a known tree std::vector bitlen(288, 0), bitlenD(32, 0); if(bp >> 3 >= inlength - 2) { error = 49; return; } //the bit pointer is or will go past the memory size_t HLIT = readBitsFromStream(bp, in, 5) + 257; //number of literal/length codes + 257 size_t HDIST = readBitsFromStream(bp, in, 5) + 1; //number of dist codes + 1 size_t HCLEN = readBitsFromStream(bp, in, 4) + 4; //number of code length codes + 4 zlibinfo->back().hlit = HLIT - 257; zlibinfo->back().hdist = HDIST - 1; zlibinfo->back().hclen = HCLEN - 4; std::vector codelengthcode(19); //lengths of tree to decode the lengths of the dynamic tree for(size_t i = 0; i < 19; i++) codelengthcode[CLCL[i]] = (i < HCLEN) ? readBitsFromStream(bp, in, 3) : 0; //code length code lengths for(size_t i = 0; i < codelengthcode.size(); i++) zlibinfo->back().clcl.push_back(codelengthcode[i]); error = codelengthcodetree.makeFromLengths(codelengthcode, 7); if(error) return; size_t i = 0, replength; while(i < HLIT + HDIST) { unsigned long code = huffmanDecodeSymbol(in, bp, codelengthcodetree, inlength); if(error) return; zlibinfo->back().treecodes.push_back(code); //tree symbol code if(code <= 15) { if(i < HLIT) bitlen[i++] = code; else bitlenD[i++ - HLIT] = code; } //a length code else if(code == 16) { //repeat previous if(bp >> 3 >= inlength) { error = 50; return; } //error, bit pointer jumps past memory replength = 3 + readBitsFromStream(bp, in, 2); unsigned long value; //set value to the previous code if((i - 1) < HLIT) value = bitlen[i - 1]; else value = bitlenD[i - HLIT - 1]; for(size_t n = 0; n < replength; n++) { //repeat this value in the next lengths if(i >= HLIT + HDIST) { error = 13; return; } //error: i is larger than the amount of codes if(i < HLIT) bitlen[i++] = value; else bitlenD[i++ - HLIT] = value; } } else if(code == 17) { //repeat "0" 3-10 times if(bp >> 3 >= inlength) { error = 50; return; } //error, bit pointer jumps past memory replength = 3 + readBitsFromStream(bp, in, 3); zlibinfo->back().treecodes.push_back(replength); //tree symbol code repetitions for(size_t n = 0; n < replength; n++) { //repeat this value in the next lengths if(i >= HLIT + HDIST) { error = 14; return; } //error: i is larger than the amount of codes if(i < HLIT) bitlen[i++] = 0; else bitlenD[i++ - HLIT] = 0; } } else if(code == 18) { //repeat "0" 11-138 times if(bp >> 3 >= inlength) { error = 50; return; } //error, bit pointer jumps past memory replength = 11 + readBitsFromStream(bp, in, 7); zlibinfo->back().treecodes.push_back(replength); //tree symbol code repetitions for(size_t n = 0; n < replength; n++) { //repeat this value in the next lengths if(i >= HLIT + HDIST) { error = 15; return; } //error: i is larger than the amount of codes if(i < HLIT) bitlen[i++] = 0; else bitlenD[i++ - HLIT] = 0; } } else { error = 16; return; } //error: somehow an unexisting code appeared. This can never happen. } if(bitlen[256] == 0) { error = 64; return; } //the length of the end code 256 must be larger than 0 error = tree.makeFromLengths(bitlen, 15); if(error) return; //now we've finally got HLIT and HDIST, so generate the code trees, and the function is done error = treeD.makeFromLengths(bitlenD, 15); if(error) return; zlibinfo->back().treebits = bp - bpstart; //lit/len/end symbol lengths for(size_t j = 0; j < bitlen.size(); j++) zlibinfo->back().litlenlengths.push_back(bitlen[j]); //dist lengths for(size_t j = 0; j < bitlenD.size(); j++) zlibinfo->back().distlengths.push_back(bitlenD[j]); } void inflateHuffmanBlock(std::vector& out, const unsigned char* in, size_t& bp, size_t& pos, size_t inlength, unsigned long btype) { size_t numcodes = 0, numlit = 0, numlen = 0; //for logging if(btype == 1) { generateFixedTrees(codetree, codetreeD); } else if(btype == 2) { getTreeInflateDynamic(codetree, codetreeD, in, bp, inlength); if(error) return; } for(;;) { unsigned long code = huffmanDecodeSymbol(in, bp, codetree, inlength); if(error) return; numcodes++; zlibinfo->back().lz77_lcode.push_back(code); //output code zlibinfo->back().lz77_dcode.push_back(0); zlibinfo->back().lz77_lbits.push_back(0); zlibinfo->back().lz77_dbits.push_back(0); zlibinfo->back().lz77_lvalue.push_back(0); zlibinfo->back().lz77_dvalue.push_back(0); if(code == 256) { break; //end code } else if(code <= 255) { //literal symbol out.push_back((unsigned char)(code)); pos++; numlit++; } else if(code >= 257 && code <= 285) { //length code size_t length = LENBASE[code - 257], numextrabits = LENEXTRA[code - 257]; if((bp >> 3) >= inlength) { error = 51; return; } //error, bit pointer will jump past memory length += readBitsFromStream(bp, in, numextrabits); unsigned long codeD = huffmanDecodeSymbol(in, bp, codetreeD, inlength); if(error) return; if(codeD > 29) { error = 18; return; } //error: invalid dist code (30-31 are never used) unsigned long dist = DISTBASE[codeD], numextrabitsD = DISTEXTRA[codeD]; if((bp >> 3) >= inlength) { error = 51; return; } //error, bit pointer will jump past memory dist += readBitsFromStream(bp, in, numextrabitsD); size_t start = pos, back = start - dist; //backwards for(size_t i = 0; i < length; i++) { out.push_back(out[back++]); pos++; if(back >= start) back = start - dist; } numlen++; zlibinfo->back().lz77_dcode.back() = codeD; //output distance code zlibinfo->back().lz77_lbits.back() = numextrabits; //output length extra bits zlibinfo->back().lz77_dbits.back() = numextrabitsD; //output dist extra bits zlibinfo->back().lz77_lvalue.back() = length; //output length zlibinfo->back().lz77_dvalue.back() = dist; //output dist } } zlibinfo->back().numlit = numlit; //output number of literal symbols zlibinfo->back().numlen = numlen; //output number of length symbols } void inflateNoCompression(std::vector& out, const unsigned char* in, size_t& bp, size_t& pos, size_t inlength) { while((bp & 0x7) != 0) bp++; //go to first boundary of byte size_t p = bp / 8; if(p >= inlength - 4) { error = 52; return; } //error, bit pointer will jump past memory unsigned long LEN = in[p] + 256u * in[p + 1], NLEN = in[p + 2] + 256u * in[p + 3]; p += 4; if(LEN + NLEN != 65535) { error = 21; return; } //error: NLEN is not one's complement of LEN if(p + LEN > inlength) { error = 23; return; } //error: reading outside of in buffer for(unsigned long n = 0; n < LEN; n++) { out.push_back(in[p++]); //read LEN bytes of literal data pos++; } bp = p * 8; } int decompress(std::vector& out, const std::vector& in) { //returns error value if(in.size() < 2) { return 53; } //error, size of zlib data too small //error: 256 * in[0] + in[1] must be a multiple of 31, the FCHECK value is supposed to be made that way if((in[0] * 256 + in[1]) % 31 != 0) { return 24; } unsigned long CM = in[0] & 15, CINFO = (in[0] >> 4) & 15, FDICT = (in[1] >> 5) & 1; //error: only compression method 8: inflate with sliding window of 32k is supported by the PNG spec if(CM != 8 || CINFO > 7) { return 25; } //error: the PNG spec says about the zlib stream: "The additional flags shall not specify a preset dictionary." if(FDICT != 0) { return 26; } inflate(out, in, 2); return error; //note: adler32 checksum was skipped and ignored } }; struct ExtractPNG { //PNG decoding and information extraction std::vector* zlibinfo; ExtractPNG(std::vector* info) : zlibinfo(info) {}; int error; void decode(const unsigned char* in, size_t size) { error = 0; if(size == 0 || in == 0) { error = 48; return; } //the given data is empty readPngHeader(&in[0], size); if(error) return; size_t pos = 33; //first byte of the first chunk after the header std::vector idat; //the data from idat chunks bool IEND = false; //loop through the chunks, ignoring unknown chunks and stopping at IEND chunk. //IDAT data is put at the start of the in buffer while(!IEND) { //error: size of the in buffer too small to contain next chunk if(pos + 8 >= size) { error = 30; return; } size_t chunkLength = read32bitInt(&in[pos]); pos += 4; if(chunkLength > 2147483647) { error = 63; return; } //error: size of the in buffer too small to contain next chunk if(pos + chunkLength >= size) { error = 35; return; } //IDAT chunk, containing compressed image data if(in[pos + 0] == 'I' && in[pos + 1] == 'D' && in[pos + 2] == 'A' && in[pos + 3] == 'T') { idat.insert(idat.end(), &in[pos + 4], &in[pos + 4 + chunkLength]); pos += (4 + chunkLength); } else if(in[pos + 0] == 'I' && in[pos + 1] == 'E' && in[pos + 2] == 'N' && in[pos + 3] == 'D') { pos += 4; IEND = true; } else { //it's not an implemented chunk type, so ignore it: skip over the data pos += (chunkLength + 4); //skip 4 letters and uninterpreted data of unimplemented chunk } pos += 4; //step over CRC (which is ignored) } std::vector out; //now the out buffer will be filled ExtractZlib zlib(zlibinfo); //decompress with the Zlib decompressor error = zlib.decompress(out, idat); if(error) return; //stop if the zlib decompressor returned an error } //read the information from the header and store it in the Info void readPngHeader(const unsigned char* in, size_t inlength) { if(inlength < 29) { error = 27; return; } //error: the data length is smaller than the length of the header if(in[0] != 137 || in[1] != 80 || in[2] != 78 || in[3] != 71 || in[4] != 13 || in[5] != 10 || in[6] != 26 || in[7] != 10) { error = 28; return; } //no PNG signature //error: it doesn't start with a IHDR chunk! if(in[12] != 'I' || in[13] != 'H' || in[14] != 'D' || in[15] != 'R') { error = 29; return; } } unsigned long readBitFromReversedStream(size_t& bitp, const unsigned char* bits) { unsigned long result = (bits[bitp >> 3] >> (7 - (bitp & 0x7))) & 1; bitp++; return result; } unsigned long readBitsFromReversedStream(size_t& bitp, const unsigned char* bits, unsigned long nbits) { unsigned long result = 0; for(size_t i = nbits - 1; i < nbits; i--) result += ((readBitFromReversedStream(bitp, bits)) << i); return result; } void setBitOfReversedStream(size_t& bitp, unsigned char* bits, unsigned long bit) { bits[bitp >> 3] |= (bit << (7 - (bitp & 0x7))); bitp++; } unsigned long read32bitInt(const unsigned char* buffer) { return (unsigned int)((buffer[0] << 24u) | (buffer[1] << 16u) | (buffer[2] << 8u) | buffer[3]); } }; unsigned extractZlibInfo(std::vector& zlibinfo, const std::vector& in) { ExtractPNG decoder(&zlibinfo); decoder.decode(&in[0], in.size()); return decoder.error ? 1 : 0; } } // namespace lodepng lodepng-0.0~git20220618.b4ed2cd/lodepng_util.h000066400000000000000000000327371425344217700206210ustar00rootroot00000000000000/* LodePNG Utils Copyright (c) 2005-2022 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ /* Extra C++ utilities for LodePNG, for convenience. Not part of the stable API of lodepng, more loose separate utils. */ #ifndef LODEPNG_UTIL_H #define LODEPNG_UTIL_H #include #include #include "lodepng.h" namespace lodepng { /* Returns info from the header of the PNG by value, purely for convenience. Does NOT check for errors. Returns bogus info if the PNG has an error. Does not require cleanup of allocated memory because no palette or text chunk info is in the LodePNGInfo object after checking only the header of the PNG. */ LodePNGInfo getPNGHeaderInfo(const std::vector& png); /* Get the names and sizes of all chunks in the PNG file. Returns 0 if ok, non-0 if error happened. */ unsigned getChunkInfo(std::vector& names, std::vector& sizes, const std::vector& png); /* Returns the names and full chunks (including the name and everything else that makes up the chunk) for all chunks except IHDR, PLTE, IDAT and IEND. It separates the chunks into 3 separate lists, representing the chunks between certain critical chunks: 0: IHDR-PLTE, 1: PLTE-IDAT, 2: IDAT-IEND Returns 0 if ok, non-0 if error happened. */ unsigned getChunks(std::vector names[3], std::vector > chunks[3], const std::vector& png); /* Inserts chunks into the given png file. The chunks must be fully encoded, including length, type, content and CRC. The array index determines where it goes: 0: between IHDR and PLTE, 1: between PLTE and IDAT, 2: between IDAT and IEND. They're appended at the end of those locations within the PNG. Returns 0 if ok, non-0 if error happened. */ unsigned insertChunks(std::vector& png, const std::vector > chunks[3]); /* Get the filtertypes of each scanline in this PNG file. Returns 0 if ok, 1 if PNG decoding error happened. For a non-interlaced PNG, it returns one filtertype per scanline, in order. For interlaced PNGs, it returns a result as if it's not interlaced. It returns one filtertype per scanline, in order. The values match pass 6 and 7 of the Adam7 interlacing, alternating between the two, so that the values correspond the most to their scanlines. */ unsigned getFilterTypes(std::vector& filterTypes, const std::vector& png); /* Get the filtertypes of each scanline in every interlace pass this PNG file. Returns 0 if ok, 1 if PNG decoding error happened. For a non-interlaced PNG, it returns one filtertype per scanline, in order, in a single std::vector in filterTypes. For an interlaced PNG, it returns 7 std::vectors in filterTypes, one for each Adam7 pass. The amount of values per pass can be calculated as follows, where w and h are the size of the image and all divisions are integer divisions: pass 1: (h + 7) / 8 pass 2: w <= 4 ? 0 : (h + 7) / 8 pass 3: h <= 4 ? 0 : (h + 7) / 8 pass 4: w <= 2 ? 0 : (h + 3) / 4 pass 5: h <= 2 ? 0 : (h + 3) / 4 pass 6: w <= 1 ? 0 : (h + 1) / 2 pass 7: h <= 1 ? 0 : (h + 1) / 2 */ unsigned getFilterTypesInterlaced(std::vector >& filterTypes, const std::vector& png); /* Returns the value of the i-th pixel in an image with 1, 2, 4 or 8-bit color. E.g. if bits is 4 and i is 5, it returns the 5th nibble (4-bit group), which is the second half of the 3th byte, in big endian (PNG's endian order). */ int getPaletteValue(const unsigned char* data, size_t i, int bits); #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS /* Similar to convertRGBModel, but the 'to' model is sRGB. The pixel format of in and out must be the same and is given by state_in->info_raw. An error may occur if the pixel format cannot contain the new colors (e.g. palette) */ unsigned convertToSrgb(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, const LodePNGState* state_in); /* Similar to convertRGBModel, but the 'from' model is sRGB. The pixel format of in and out must be the same and is given by state_out->info_raw. An error may occur if the pixel format cannot contain the new colors (e.g. palette) */ unsigned convertFromSrgb(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, const LodePNGState* state_out); /* Converts from one RGB model to another RGB model. Similar to calling convertToXYZ followed by convertFromXYZ, but may be more efficient and more precise (e.g. no computation needed when both models are the same). See their documentation for more info. Parameters: *) out: output pixel data *) in: input pixel data *) w, h: image size *) state_out: output RGB color model in state_out->info_png and byte format in state_out->info_raw. *) state_in: output RGB color model in state_in->info_png and byte format in state_in->info_raw *) return value: 0 if ok, positive value if error *) rendering_intent: 1 for relative, 3 for absolute, should be relative for standard behavior. See description at convertFromXYZ. */ unsigned convertRGBModel(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, const LodePNGState* state_out, const LodePNGState* state_in, unsigned rendering_intent); /* Converts the RGB color to the absolute XYZ color space given the RGB color profile chunks in the PNG info. Color space here refers to the different possible RGB spaces with different possible chromaticities or whitepoint and XYZ color from colorimetry, not the LodePNGColorType that describes the byte based encoding. You need this function only if the PNG could contain data in an arbitrary RGB color space and you wish to output to a display or format that does not provide color management for you (so you need to convert rather than pass on the profile to it) but expects a certain RGB format (e.g. sRGB). See the background info below. Supports the gAMA, cHRM, sRGB and iCCP colorimetry chunks. If no colometry chunks are present (that is, in state->info_png, the fields gama_defined, chrm_defined, srgb_defined and iccp_defined are all 0), it assumes the format is sRGB. For more information, see the chunk specifications in the PNG specification. Some background: A PNG image contains RGB data inside, but this data may use a specific RGB model (by default sRGB but different if colorimetry chunks are given). The computer display and/or operating system can have another RGB model (typically sRGB, or wider gamut or HDR formats). The PNG chunks describe what format the data inside has, not the format of the display. To correctly display a PNG image on a display, a conversion is needed from the PNG model to the display model if their models differ. Some options to achieve that are: *) If your use case already supports color management on its own, you can give it the RGB values straight from the PNG image and give it the information from the cHRM, gAMA, sRGB and iCCP chunks (which you can find in the LodePNGInfo), and the color management should then handle it correctly for you. You don't need this function here in that case. *) If your use case does not support color management, you may instead want to give it the RGB values in a consistent color model, such as sRGB, but the PNG does not necessarily have it in this desired model. In that case, use the function below (or a similar one from a CMS library if you prefer) to convert it to the absolute color space XYZ, and then you can convert it to the target RGB with the counterpart convertFromXYZ further below. Parameters: *) out: 4 floats per pixel, X,Y,Z,alpha color format, in range 0-1 (normally, not clipped if beyond), must be allocated to have 4 * w * h floats available. *) whitepoint: output argument, the whitepoint the original RGB data used, given in absolute XYZ. Needed for relative rendering intents: give these values to counterpart function convertFromXYZ. *) in: input RGB color, in byte format given by state->info_raw and RGB color profile given by info->info_png *) w, h: image size *) state (when using a LodePNG decode function that takes a LodePNGState parameter, can directly use that one): state->info_png: PNG info with possibly an RGB color model in cHRM,gAMA and/or sRGB chunks state->info_raw: byte format of in (amount of channels, bit depth) *) return value: 0 if ok, positive value if error */ unsigned convertToXYZ(float* out, float whitepoint[3], const unsigned char* in, unsigned w, unsigned h, const LodePNGState* state); /* Same as convertToXYZ but takes floating point input. Slower. The main black..white range in 0..1. Does not clip values that are outside that range. */ unsigned convertToXYZFloat(float* out, float whitepoint[3], const float* in, unsigned w, unsigned h, const LodePNGState* state); /* Converts XYZ to RGB in the RGB color model given by info and byte format by mode_out. If info has no coloremtry chunks, converts to sRGB. Parameters: *) out: output color in byte format given by state->info_raw and RGB color profile given by info->info_png. Must have enough bytes allocated to contain pixels in the given byte format. *) in: 4 floats per pixel, X,Y,Z,alpha color format, in range 0-1 (normally). *) whitepoint: input argument, the original whitepoint in absolute XYZ that the pixel data in "in" had back when it was in a previous RGB space. Needed to preserve the whitepoint in the new target RGB space for relative rendering intent. *) rendering_intent: the desired rendering intent, with numeric meaning matching the values used by ICC: 0=perceptual, 1=relative, 2=saturation, 3=absolute. Should be 1 for normal use cases, it adapts white to match that of different RGB models which is the best practice. Using 3 may change the color of white and may turn grayscale into colors of a certain tone. Using 0 and 2 will have the same effect as 1 because using those requires more data than the matrix-based RGB profiles supporetd here have. *) w, h: image size *) state: state->info_png: PNG info with possibly an RGB color profile in cHRM,gAMA and/or sRGB chunks state->info_raw: byte format of out (amount of channels, bit depth) *) return value: 0 if ok, positive value if error */ unsigned convertFromXYZ(unsigned char* out, const float* in, unsigned w, unsigned h, const LodePNGState* state, const float whitepoint[3], unsigned rendering_intent); /* Same as convertFromXYZ but outputs the RGB colors in floating point. The main black..white range in 0..1. Does not clip values that are outside that range. */ unsigned convertFromXYZFloat(float* out, const float* in, unsigned w, unsigned h, const LodePNGState* state, const float whitepoint[3], unsigned rendering_intent); #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ /* The information for extractZlibInfo. */ struct ZlibBlockInfo { int btype; //block type (0-2) size_t compressedbits; //size of compressed block in bits size_t uncompressedbytes; //size of uncompressed block in bytes // only filled in for block type 2 size_t treebits; //encoded tree size in bits int hlit; //the HLIT value that was filled in for this tree int hdist; //the HDIST value that was filled in for this tree int hclen; //the HCLEN value that was filled in for this tree std::vector clcl; //19 code length code lengths (compressed tree's tree) std::vector treecodes; //N tree codes, with values 0-18. Values 17 or 18 are followed by the repetition value. std::vector litlenlengths; //288 code lengths for lit/len symbols std::vector distlengths; //32 code lengths for dist symbols // only filled in for block types 1 or 2 std::vector lz77_lcode; //LZ77 codes. 0-255: literals. 256: end symbol. 257-285: length code of length/dist pairs // the next vectors have the same size as lz77_lcode, but an element only has meaningful value if lz77_lcode contains a length code. std::vector lz77_dcode; std::vector lz77_lbits; std::vector lz77_dbits; std::vector lz77_lvalue; std::vector lz77_dvalue; size_t numlit; //number of lit codes in this block size_t numlen; //number of len codes in this block }; //Extracts all info needed from a PNG file to reconstruct the zlib compression exactly. // Returns 0 if no error, non-zero value if error unsigned extractZlibInfo(std::vector& zlibinfo, const std::vector& in); } // namespace lodepng #endif /*LODEPNG_UTIL_H inclusion guard*/ lodepng-0.0~git20220618.b4ed2cd/pngdetail.cpp000066400000000000000000001573721425344217700204410ustar00rootroot00000000000000/* LodePNG pngdetail Copyright (c) 2005-2020 Lode Vandevenne This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ //g++ pngdetail.cpp lodepng_util.cpp lodepng.cpp -ansi -pedantic -Wall -Wextra -o pngdetail -O3 /* Utility program that shows a lot of information in the console about a PNG file, including color type, text chunks, the names and sizes of all chunks in the image, all the zlib compression blocks and symbols, etc... compression info: ./pngdetail -sfczB image.png everything, 8-bit: ./pngdetail -sPlLA#cfzB7 image.png everything, 16-bit: ./pngdetail -sPlLA@cfzB7 image.png everything except huge output: ./pngdetail -sPlAcfzB image.png */ #include "lodepng.h" #include "lodepng_util.h" #include #include #include #include #include #include #include #include void showHelp() { std::cout << "pngdetail by Lode Vandevenne" << std::endl; std::cout << "version: " << LODEPNG_VERSION_STRING << std::endl; std::cout << "Shows detailed information about a PNG image, its compression and possible corruptions.\n" "Usage: pngdetail [filename] [options]...\n" "Without options shows a default set of stats. With options, shows only selected options.\n" "E.g. 'pngdetail image.png -plc' to show png info, palette info and chunks\n" "Options:\n" "-o: show header summary on one line\n" "-H: show header info\n" "-p: show PNG file info\n" "-e: analyze errors or warnings\n" "-i: show ICC profile details (if any)\n" "-I: show ICC profile bytes\n" "--format=: display mode for -I:\n" " hex: print bytes in hex\n" " mix: print printable bytes as ASCII characters, hex for others\n" " bin: dump as binary in terminal\n" "-l: show palette (if any)\n" "-s: show color statistics\n" "-r: render the PNG image in terminal (with --mode and --size)\n" "--size=: render width for -r\n" "--mode=: render mode for -r:\n" " ascii: Letters ROYLGTCABVMF indicate hue (L=lime, T=turquoise, A=azure, F=fuchsia, ...).\n" " hex: CSS hex notation for every pixel.\n" " hex16: Like hex but shows 16 bits values per channel.\n" " palette: Shows palette index of each pixel, only for palette images.\n" "--size=: render width (not used by hex, hex16 or palette):\n" "-c: show PNG chunks\n" "-C: show PNG chunks (alternate format)\n" "-f: show PNG filters\n" "-z: show Zlib info\n" "-b: show Zlib blocks\n" "-B: show Zlib block symbol counts\n" "-7: show all lz77 values (huge output)\n" "-v: be more verbose\n" "-t: expand long texts\n" "-x: print most integer numbers in hexadecimal (includes e.g. year, num unique colors, ...)\n" "-?, --help, -h: show this help" << std::endl; } enum RenderMode { RM_ASCII, RM_HEX, // CSS RM_HEX16, RM_PAL // palette indices (only rendered if image is palette based) }; // for displaying ICC profile enum HexFormat { HF_HEX, HF_MIX, // hex and ascii HF_BIN // bytes as binary data dump }; struct Options { bool verbose; bool expand_long_texts; bool show_one_line_summary; //show filesize, pixels and color type on single line bool show_header; // show only info from the IHDR chunk bool show_errors; bool show_icc_details; // show ICC color profile details bool show_icc_hex; // show ICC color profile in full bool show_color_stats; bool show_png_info; //show things like filesize, width, height, palette size, ... bool show_palette; //show all palette values bool show_palette_pixels; //show palette indices of pixels HexFormat hexformat; bool show_render; RenderMode rendermode; int rendersize; bool show_chunks; //show the PNG chunk names and their lengths bool show_chunks2; //alternate form to print chunks bool show_filters; //show the PNG filter of each scanline (not supported for interlaced PNGs currently) bool zlib_info; //show basic zlib info bool zlib_blocks; //show type, tree info, code length summaries and sizes for each zlib block bool zlib_counts; //in addition to the zlib_blocks info, show counts of occurrences all symbols bool zlib_full; //in addition to the zlib_blocks info, show all symbols, one per line (huge output) bool use_hex; //show some sizes or positions in hexadecimal Options() : verbose(false), expand_long_texts(false), show_one_line_summary(false), show_header(false), show_errors(false), show_icc_details(false), show_icc_hex(false), show_color_stats(false), show_png_info(false), show_palette(false), show_palette_pixels(false), hexformat(HF_MIX), show_render(false), rendermode(RM_ASCII), rendersize(80), show_chunks(false), show_chunks2(false), show_filters(false), zlib_info(false), zlib_blocks(false), zlib_counts(false), zlib_full(false), use_hex(false) { } }; unsigned inspect_chunk_by_name(const unsigned char* data, const unsigned char* end, lodepng::State& state, const char type[5]) { const unsigned char* p = lodepng_chunk_find_const(data, end, type); return lodepng_inspect_chunk(&state, p - data, data, end - data); } // Lazy loads the raw file, inspected header or entire image as needed struct Data { std::string filename; std::vector buffer; std::vector pixels; // 16-bit unsigned w; unsigned h; lodepng::State state; unsigned error; bool inspected; bool is_icc; // the file is a raw icc file, not a PNG, only -i and -I are useful Data(const std::string& filename) : filename(filename), error(0), inspected(false), is_icc(false) {} // Load the file if not already loaded void loadFile() { if(buffer.empty()) { error = lodepng::load_file(buffer, filename); //load the image file with given filename } else { error = 0; // for reloadpixels, reset error if file was already successfully loaded } } // is PNG according to the file signature bool isPng() { if(buffer.size() < 8) return false; return buffer[0] == 137 && buffer[1] == 80 && buffer[2] == 78 && buffer[3] == 71 && buffer[4] == 13 && buffer[5] == 10 && buffer[6] == 26 && buffer[7] == 10; } // is probably an ICC profile bool isIcc() { if(isPng()) return false; if(buffer.size() < 128) return false; size_t size = (buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3]; if(size != buffer.size()) return false; if(buffer[36] != 'a') return false; if(buffer[37] != 'c') return false; if(buffer[38] != 's') return false; if(buffer[39] != 'p') return false; return true; } // Load header info (plus a few more nearby light chunks) if not already loaded, and the file if needed void loadInspect() { if(inspected) return; inspected = true; loadFile(); if(error) return; if(isIcc()) { lodepng_set_icc(&state.info_png, "", &buffer[0], buffer.size()); is_icc = true; } else { is_icc = false; const unsigned char* data = &buffer[0]; error = lodepng_inspect(&w, &h, &state, data, buffer.size()); if(error) return; // end before first IDAT chunk: do not parse more than first part of file for all this. const unsigned char* end = lodepng_chunk_find_const(data, data + buffer.size(), "IDAT"); if(!end) end = data + buffer.size(); // no IDAT, invalid PNG but extract info anyway inspect_chunk_by_name(data, end, state, "PLTE"); if(error) return; inspect_chunk_by_name(data, end, state, "tRNS"); if(error) return; inspect_chunk_by_name(data, end, state, "cHRM"); if(error) return; inspect_chunk_by_name(data, end, state, "gAMA"); if(error) return; inspect_chunk_by_name(data, end, state, "sBIT"); if(error) return; inspect_chunk_by_name(data, end, state, "bKGD"); if(error) return; inspect_chunk_by_name(data, end, state, "hIST"); if(error) return; inspect_chunk_by_name(data, end, state, "pHYs"); if(error) return; inspect_chunk_by_name(data, end, state, "iCCP"); if(error) return; } } // Load the pixels if not already loaded, and the file if needed void loadPixels() { if(pixels.empty()) reloadPixels(); } void reloadPixels() { loadFile(); if(error) return; inspected = true; state.info_raw.colortype = LCT_RGBA; state.info_raw.bitdepth = 16; pixels.clear(); error = lodepng::decode(pixels, w, h, state, buffer); } }; std::string colorTypeString(LodePNGColorType type) { std::string name; switch(type) { case LCT_GREY: name = "grey"; break; case LCT_RGB: name = "RGB"; break; case LCT_PALETTE: name = "palette"; break; case LCT_GREY_ALPHA: name = "grey+alpha"; break; case LCT_RGBA: name = "RGBA"; break; default: name = "invalid"; break; } std::stringstream ss; ss << type << " (" << name << ")"; return ss.str(); } template T strtoval(const std::string& s) { std::istringstream sstream(s); T val; sstream >> val; return val; } /* Display the names and sizes of all chunks in the PNG file. */ void displayChunkNames(Data& data, const Options& options) { if(data.is_icc) return; data.loadFile(); if(data.error) return; std::cout << (options.use_hex ? std::hex: std::dec); const std::vector& buffer = data.buffer; std::vector names; std::vector sizes; unsigned error = lodepng::getChunkInfo(names, sizes, buffer); if(error) { if(!names.empty() && names.back() == "IEND" && sizes.back() == 0) { std::cout << "Corruption or superfluous data detected after the IEND chunk" << std::endl; } else { std::cout << "Error while identifying chunks. Listing identified chunks anyway." << std::endl; } } if(options.show_chunks2) { std::cout << "Chunk types: "; for(size_t i = 0; i < names.size(); i++) std::cout << names[i] << " "; std::cout << std::endl; std::cout << "Chunk sizes: "; for(size_t i = 0; i < sizes.size(); i++) std::cout << sizes[i] << " "; std::cout << std::endl; } else { std::cout << "Chunks (type: lengths):"; std::string last_type; for(size_t i = 0; i < names.size(); i++) { if(last_type != names[i]) { std::cout << std::endl; std::cout << " " << names[i] << ": "; } last_type = names[i]; std::cout << sizes[i] << " "; } std::cout << std::endl; } std::map typedict; for(size_t i = 0; i < names.size(); i++) { typedict[names[i]] = true; } if(!error) { if(!typedict["IHDR"]) std::cout << "Error: no IHDR chunk" << std::endl; if(!typedict["IDAT"]) std::cout << "Error: no IDAT chunk" << std::endl; if(!typedict["IEND"]) std::cout << "Error: no IEND chunk" << std::endl; } } void RGBtoHSL(unsigned char r, unsigned char g, unsigned char b, unsigned char* h, unsigned char* s, unsigned char* l) { int cmax = std::max(r, std::max(g, b)); int cmin = std::min(r, std::min(g, b)); if(cmin == cmax) { *h = *s = 0; *l = r; } else { int sum = cmin + cmax; int diff = cmax - cmin; *l = sum / 2; *s = 255 * diff / ((*l < 128) ? sum : (512 - sum)); int hi = (r == cmax) ? (255 * (g - b) / diff) : ((g == cmax) ? (512 + 255 * (b - r) / diff) : (1024 + 255 * (r - g) / diff)); *h = ((hi / 6) & 255); } } /* HCT: Hue, Chroma, Tone: returns a linear combination between a pure hue and a greyscale value. *) Chroma: The linear combination factor: 255 for pure hue, 0 for pure greyscale *) Tone: greyscale to mix with: 0 = black (shade), 255 = white (tint), in between = grey (tone) */ void RGBtoHCT(unsigned char r, unsigned char g, unsigned char b, unsigned char* h, unsigned char* c, unsigned char* t) { int cmax = std::max(r, std::max(g, b)); int cmin = std::min(r, std::min(g, b)); RGBtoHSL(r, g, b, h, c, t); *c = cmax - cmin; *t = *c == 255 ? 0 : 255 * cmin / (255 + cmin - cmax); } // add 32 to get small letter instead of capital char HueToLetter(int h) { char hl = 'R'; // 12 unique hue letters for 30 degree increment hues. if(h < 11 || h >= 244) hl = 'R'; // red else if(h >= 11 && h < 32) hl = 'O'; // orange else if(h >= 32 && h < 53) hl = 'Y'; // yellow else if(h >= 53 && h < 74) hl = 'L'; // lime (officialy "chartreuse" but c is for cyan) else if(h >= 74 && h < 96) hl = 'G'; // green else if(h >= 96 && h < 117) hl = 'T'; // turquoise (officially "spring green" but that name overlaps green) else if(h >= 117 && h < 138) hl = 'C'; // cyan else if(h >= 138 && h < 159) hl = 'A'; // azure else if(h >= 159 && h < 181) hl = 'B'; // blue else if(h >= 181 && h < 202) hl = 'V'; // violet else if(h >= 202 && h < 223) hl = 'M'; // magenta else if(h >= 223 && h < 244) hl = 'F'; // fuchsia (officially "rose" but r is for red) return hl; } char lightnessToLetter(int l) { int c = ' '; if(l < 16) c = ' '; else if(l < 48) c = '.'; else if(l < 80) c = ':'; else if(l < 112) c = '-'; else if(l < 144) c = '!'; else if(l < 176) c = '*'; else if(l < 208) c = '+'; // The + looks denser than the * in a terminal... else if(l < 240) c = '='; else c = '#'; return c; } // Both v and result are assumed in range 0-255 // range is the size of an individual bucket. A value in roughly range [-range/2, range/2) can get added to v. // E.g. if there are 12 hue letters, give 255/12 = 21 as range static inline int applyDither(int v, int range, int x, int y, bool wrap) { // ordered dithering pattern; ranges from 0-15, so multiply with 17 to have 0-255 static const int pattern[16] = {0,8,2,10, 12,4,14,6, 3,11,1,9, 15,7,13,5}; int d = pattern[(x & 3) + 4 * (y & 3)] * 17 - 128; // range: -128 to 127 if(wrap) return (v + d * range / 256) & 255; else return std::max(0, std::min(255, v + d * range / 256)); } // x and y are to use for dithering // inverted inverts black and white, for in case black text on white background is used (by default it assumes white text on black background) char RGBtoLetter(unsigned char r, unsigned char g, unsigned char b, unsigned char a, unsigned x, unsigned y, bool dither = true, bool inverted = false) { if(a < 255) { r = a * r / 255; g = a * g / 255; b = a * b / 255; } if(dither) { unsigned char h, c, t; RGBtoHCT(r, g, b, &h, &c, &t); int l = (std::max(std::max(r, g), b) + std::min(std::min(r, g), b)) / 2; if(inverted) { l = 255 - l; t = 255 - t; } if(applyDither(c, 254, x, y, false) >= 128) { char letter = HueToLetter(applyDither(h, 21, x, y, true)); bool smallcaps = applyDither(l, 64, x+2, y+2, false) < 80; return letter + (smallcaps ? 32 : 0); } else return lightnessToLetter(applyDither(l, 31, x, y, false)); } else { unsigned char h, s, l; RGBtoHSL(r, g, b, &h, &s, &l); if(inverted) l = 255 - l; char hl = HueToLetter(h); char c = ' '; if(l < 24 || l > 232 || s < 64) { c = lightnessToLetter(l); } else { if(l < 128) c = hl + 32; else c = hl; } return c; } } std::vector rescale(const std::vector& in, int w0, int h0, int w1, int h1, bool smooth) { int numchannels = in.size() / (w0 * h0); std::vector out(w1 * h1 * numchannels); if(smooth) { // box filter. std::vector temp(w1 * h0 * numchannels); for (int c = 0; c < numchannels; c++) { for (int x = 0; x < w1; x++) { float xaf = x * 1.0 * w0 / w1; float xbf = (x + 1.0) * w0 / w1; int xa = (int)xaf; int xb = (int)xbf; double norm = 1.0 / (xbf - xaf); xaf -= std::floor(xaf); xbf -= std::floor(xbf); for (int y = 0; y < h0; y++) { int index1 = x * numchannels + y * w1 * numchannels; double val = 0; for(int x0 = xa; x0 <= xb; x0++) { int index0 = x0 * numchannels + y * w0 * numchannels; double v = 1; if(x0 == xa) v -= xaf; if(x0 == xb) v -= (1 - xbf); val += v * in[index0 + c]; } temp[index1 + c] = val * norm; } } for (int y = 0; y < h1; y++) { float yaf = y * 1.0 * h0 / h1; float ybf = (y + 1.0) * h0 / h1; int ya = (int)yaf; int yb = (int)ybf; double norm = 1.0 / (ybf - yaf); yaf -= std::floor(yaf); ybf -= std::floor(ybf); for (int x = 0; x < w1; x++) { int index1 = x * numchannels + y * w1 * numchannels; double val = 0; for(int y0 = ya; y0 <= yb; y0++) { int index0 = x * numchannels + y0 * w1 * numchannels; double v = 1; if(y0 == ya) v -= yaf; if(y0 == yb) v -= (1 - ybf); val += v * temp[index0 + c]; } out[index1 + c] = val * norm; } } } } else { for(int y = 0; y < h1; y++) { int y0 = (int)((y + 0.5) * h0 / h1 - 0.5); for (int x = 0; x < w1; x++) { int x0 = (int)((x + 0.5) * w0 / w1 - 0.5); int index0 = x0 * numchannels + y0 * w0 * numchannels; int index1 = x * numchannels + y * w1 * numchannels; for (int c = 0; c < numchannels; c++) { out[index1 + c] = in[index0 + c]; } } } } return out; } /* Show ASCII art preview of the image image is given in 16-bit big endian */ void displayAsciiArt(const std::vector& image, unsigned w, unsigned h, unsigned asciiw) { const std::vector* imagep = ℑ std::vector image2; if(asciiw < w) { unsigned w2 = asciiw; unsigned h2 = h * w2 / w; image2 = rescale(image, w, h, w2, h2, true); imagep = &image2; w = w2; h = h2; } if(w > 0 && h > 0) { std::cout << "ASCII Art Preview: " << std::endl; unsigned h2 = 1 + ((h - 1) * 4) / 7; //compensate for non-square characters in terminal std::cout << '+'; for(unsigned x = 0; x < w; x++) std::cout << '-'; std::cout << '+' << std::endl; for(unsigned y = 0; y < h2; y++) { std::cout << "|"; unsigned y2 = y * h / h2; for(unsigned x = 0; x < w; x++) { int r = (*imagep)[y2 * w * 8 + x * 8 + 0]; int g = (*imagep)[y2 * w * 8 + x * 8 + 2]; int b = (*imagep)[y2 * w * 8 + x * 8 + 4]; int a = (*imagep)[y2 * w * 8 + x * 8 + 6]; char symbol = RGBtoLetter(r, g, b, a, x, y, true, false); std::cout << (char)symbol; } std::cout << "|"; std::cout << std::endl; } std::cout << '+'; for(unsigned x = 0; x < w; x++) std::cout << '-'; std::cout << '+' << std::endl; } } //sixteen: print 16 bits per pixel //alpha: print alpha channel //input image ALWAYS given in 16-bit per channel RGBA void displayColorsHex(const std::vector& image, unsigned w, unsigned h, bool sixteen) { std::ios_base::fmtflags flags = std::cout.flags(); if(w > 0 && h > 0) { std::cout << "Colors (CSS RGBA hex format):" << std::endl; for(unsigned y = 0; y < h; y++) { std::cout.flags(flags); //print line numbers in hex or dec whatever it originally was std::cout << y << ":"; for(unsigned x = 0; x < w; x++) { size_t index = y * w * 8 + x * 8; if (sixteen) { int r = image[index + 0] * 256 + image[index + 1]; int g = image[index + 2] * 256 + image[index + 3]; int b = image[index + 4] * 256 + image[index + 5]; int a = image[index + 6] * 256 + image[index + 7]; std::cout << std::hex << std::setfill('0') << " #" << std::setw(4) << r << std::setw(4) << g << std::setw(4) << b << std::setw(4) << a; } else { int r = image[index + 0]; int g = image[index + 2]; int b = image[index + 4]; int a = image[index + 6]; std::cout << std::hex << std::setfill('0') << " #" << std::setw(2) << r << std::setw(2) << g << std::setw(2) << b << std::setw(2) << a; } } std::cout << std::endl; } } std::cout.flags(flags); } /* Show the filtertypes of each scanline in this PNG image. */ void displayFilterTypes(Data& data, const Options& options) { std::cout << (options.use_hex ? std::hex: std::dec); data.loadFile(); if(data.error) return; const std::vector& buffer = data.buffer; std::vector > types; unsigned error = lodepng::getFilterTypesInterlaced(types, buffer); if(error) { std::cout << "Error getting filter types" << std::endl; return; } if(types.size() == 7) { std::cout << "Filter types (Adam7 interlaced):" << std::endl; for(int j = 0; j < 7; j++) { std::cout << " Pass " << (j + 1) << ": "; for(size_t i = 0; i < types[j].size(); i++) { std::cout << (int)(types[j][i]); } std::cout << std::endl; } } else { std::cout << "Filter types: "; for(size_t i = 0; i < types[0].size(); i++) { std::cout << (int)(types[0][i]); } std::cout << std::endl; } } //image type MUST be palette void displayPalette(Data& data, const Options& options) { data.loadInspect(); if(data.error) return; std::cout << (options.use_hex ? std::hex: std::dec); const LodePNGInfo& info = data.state.info_png; const LodePNGColorMode& color = info.color; std::cout << "Palette size: " << color.palettesize << std::endl; std::cout << "Palette colors: "; std::ios_base::fmtflags flags = std::cout.flags(); std::cout << std::hex << std::setfill('0'); for(size_t i = 0; i < color.palettesize; i++) { unsigned char* p = &color.palette[i * 4]; std::cout << "#" << std::setw(2) << (int)p[0] << std::setw(2) << (int)p[1] << std::setw(2) << (int)p[2] << std::setw(2) << (int)p[3] << " "; } std::cout.flags(flags); std::cout << std::endl; } //image type MUST be palette void displayPalettePixels(const std::vector& buffer, const Options& options) { unsigned w, h; lodepng::State state; std::vector out; std::cout << (options.use_hex ? std::hex: std::dec); state.decoder.color_convert = 0; lodepng::decode(out, w, h, state, buffer); if(state.info_png.color.colortype == LCT_PALETTE) { if (options.show_color_stats) { std::vector count(256, 0); size_t outofbounds = 0; for(size_t i = 0; i < w * h; i++) { int value = lodepng::getPaletteValue(&out[0], i, state.info_raw.bitdepth); count[value]++; if(value >= (int)state.info_raw.palettesize) outofbounds++; } std::cout << "Palette count: "; for(size_t i = 0; i < state.info_raw.palettesize; i++) { std::cout << count[i] << " "; } std::cout << std::endl; if(outofbounds > 0) std::cout << "Out of bounds palette values: " << outofbounds << std::endl; } std::cout << "Pixel palette indices:" << std::endl; for(size_t i = 0; i < w * h; i++) { int value = lodepng::getPaletteValue(&out[0], i, state.info_raw.bitdepth); std::cout << value << ", "; if(i % w == w - 1) std::cout << std::endl; } } else { std::cout << "Pixel palette indices: not shown, not a palette image\n" << std::endl; } } void printZlibInfo(Data& data, const Options& options) { data.loadFile(); if(data.error) return; const std::vector& in = data.buffer; std::cout << (options.use_hex ? std::hex: std::dec); std::vector zlibinfo; lodepng::extractZlibInfo(zlibinfo, in); if(options.zlib_info) { //std::cout << "Zlib info: " << std::endl; size_t compressed = 0; size_t uncompressed = 0; std::vector boundaries_compressed; std::vector boundaries_uncompressed; for(size_t i = 0; i < zlibinfo.size(); i++) { compressed += zlibinfo[i].compressedbits / 8; uncompressed += zlibinfo[i].uncompressedbytes; boundaries_compressed.push_back(compressed); boundaries_uncompressed.push_back(uncompressed); } std::cout << "IDAT zlib info: " << compressed << std::endl; std::cout << "Compressed size: " << compressed << std::endl; std::cout << "Uncompressed size: " << uncompressed << std::endl; std::cout << "Amount of zlib blocks: " << zlibinfo.size() << std::endl; if(zlibinfo.size() > 1) { std::cout << "Block sizes (uncompressed): "; for(size_t i = 0; i < zlibinfo.size(); i++) std::cout << zlibinfo[i].uncompressedbytes << " "; std::cout << std::endl; std::cout << "Block sizes (compressed): "; for(size_t i = 0; i < zlibinfo.size(); i++) std::cout << (zlibinfo[i].compressedbits / 8) << " "; std::cout << std::endl; std::cout << "Block boundaries (uncompressed): "; for(size_t i = 0; i + 1 < boundaries_uncompressed.size(); i++) std::cout << boundaries_uncompressed[i] << " "; std::cout << std::endl; std::cout << "Block boundaries (compressed): "; for(size_t i = 0; i + 1 < boundaries_compressed.size(); i++) std::cout << boundaries_compressed[i] << " "; std::cout << std::endl; } } if(options.zlib_blocks) { for(size_t i = 0; i < zlibinfo.size(); i++) { const lodepng::ZlibBlockInfo& info = zlibinfo[i]; std::cout << "Zlib block " << i << ":" << std::endl; std::cout << " block type: " << info.btype << std::endl; size_t compressedsize = info.compressedbits / 8; size_t uncompressedsize = info.uncompressedbytes; std::cout << " block compressed: " << compressedsize << " (" << compressedsize / 1024 << "K) (" << info.compressedbits << " bits)" << std::endl; std::cout << " block uncompressed: " << uncompressedsize << " (" << uncompressedsize / 1024 << "K)" << std::endl; if(info.btype > 2) { std::cout << "Error: Invalid Block Type" << std::endl; return; } if(info.btype == 2) { std::cout << " encoded trees size: " << info.treebits / 8 << " (" << info.treebits << " bits)" << std::endl; std::cout << " HLIT: " << info.hlit << std::endl; std::cout << " HDIST: " << info.hdist << std::endl; std::cout << " HCLEN: " << info.hclen << std::endl; std::cout << std::hex; std::cout << " code length code lengths: "; for(size_t j = 0; j < 19; j++) std::cout << info.clcl[j]; std::cout << std::endl; if(!options.use_hex) std::cout << std::dec; if(options.zlib_full) { for(size_t j = 0; j < info.treecodes.size(); j++) { int code = info.treecodes[j]; if(code < 17) { std::cout << " tree: " << code << std::endl; } else { j++; std::cout << " tree: " << code << " rep: " << info.treecodes[j] << std::endl; } } } std::cout << std::hex; std::cout << " lit code lengths 0-127 : "; for(size_t j = 0; j < 128; j++) std::cout << info.litlenlengths[j]; std::cout << std::endl; std::cout << " lit code lengths 128-255: "; for(size_t j = 128; j < 256; j++) std::cout << info.litlenlengths[j]; std::cout << std::endl; std::cout << " end code length : "; std::cout << info.litlenlengths[256]; std::cout << std::endl; std::cout << " len code lengths : "; for(size_t j = 257; j < 288; j++) std::cout << info.litlenlengths[j]; std::cout << std::endl; std::cout << " dist code lengths : "; for(size_t j = 0; j < 32; j++) std::cout << info.distlengths[j]; std::cout << std::endl; if(!options.use_hex) std::cout << std::dec; } if(info.btype != 0) { std::cout << " code counts: lit: " << info.numlit << ", len/dist: " << info.numlen << ", total: " << (info.numlit + info.numlen + 1) << ", with dists: " << (info.numlit + 2 * info.numlen + 1) << std::endl; if(options.zlib_full) { for(size_t j = 0; j < info.lz77_lcode.size(); j++) { int symbol = info.lz77_lcode[j]; if(symbol == 256) { std::cout << " end" << std::endl; } else if(symbol < 256) { std::cout << " lit: " << symbol << std::endl; } else { std::cout << " len: " << info.lz77_lvalue[j] << ", dist: " << info.lz77_dvalue[j] << std::endl; } } } if(options.zlib_counts) { std::vector ll_count(288, 0); std::vector d_count(32, 0); for(size_t j = 0; j < info.lz77_lcode.size(); j++) { int symbol = info.lz77_lcode[j]; if(symbol <= 256) { ll_count[symbol]++; } else { ll_count[symbol]++; d_count[info.lz77_dcode[j]]++; } } std::cout << " lit code 0-63 counts : "; for(size_t j = 0; j < 64; j++) std::cout << ll_count[j] << " "; std::cout << std::endl; std::cout << " lit code 64-127 counts : "; for(size_t j = 64; j < 128; j++) std::cout << ll_count[j] << " "; std::cout << std::endl; std::cout << " lit code 128-191 counts: "; for(size_t j = 128; j < 192; j++) std::cout << ll_count[j] << " "; std::cout << std::endl; std::cout << " lit code 192-255 counts: "; for(size_t j = 192; j < 256; j++) std::cout << ll_count[j] << " "; std::cout << std::endl; std::cout << " end code count : "; std::cout << ll_count[256] << " "; std::cout << std::endl; std::cout << " len code counts : "; for(size_t j = 257; j < 288; j++) std::cout << ll_count[j] << " "; std::cout << std::endl; std::cout << " dist code counts : "; for(size_t j = 0; j < 32; j++) std::cout << d_count[j] << " "; std::cout << std::endl; } } } } } // returns number of unique RGBA colors in the image // also fills unique r, g, b, a counts in the output parameters // the input image is in 16-bit per channel color, so 8 chars per pixel size_t countColors(std::vector image, unsigned w, unsigned h, size_t* ro, size_t* go, size_t* bo, size_t* ao) { typedef std::pair, std::pair > RGBA; std::map rgbam; //std::map rgbam; std::vector rm(65536, 0); std::vector gm(65536, 0); std::vector bm(65536, 0); std::vector am(65536, 0); for(unsigned y = 0; y < h; y++) { for(unsigned x = 0; x < w; x++) { unsigned short r = 256 * image[y * 8 * w + x * 8 + 0] + image[y * 8 * w + x * 8 + 1]; unsigned short g = 256 * image[y * 8 * w + x * 8 + 2] + image[y * 8 * w + x * 8 + 3]; unsigned short b = 256 * image[y * 8 * w + x * 8 + 4] + image[y * 8 * w + x * 8 + 5]; unsigned short a = 256 * image[y * 8 * w + x * 8 + 6] + image[y * 8 * w + x * 8 + 7]; RGBA rgba(std::make_pair(r, g), std::make_pair(b, a)); //uint64_t rgba = (uint64_t)r + ((uint64_t)g << 16) + ((uint64_t)b << 32) + ((uint64_t)a << 48); rgbam[rgba]++; rm[r] = 1; gm[g] = 1; bm[b] = 1; am[a] = 1; } } *ro = *go = *bo = *ao = 0; for(size_t i = 0; i < rm.size(); i++) { *ro += rm[i]; *go += gm[i]; *bo += bm[i]; *ao += am[i]; } return rgbam.size(); } void showError(Data& data, const Options& options) { std::cout << (options.use_hex ? std::hex: std::dec); std::string prefix = (options.use_hex ? "0x": ""); if(!data.error) { std::cout << "No error" << std::endl; } std::cout << "Decoding error " << prefix << data.error << ": " << lodepng_error_text(data.error) << std::endl; } void loadWithErrorRecovery(Data& data, const Options& options, bool show_errors_mode) { (void)options; unsigned& error = data.error; lodepng::State& state = data.state; data.loadPixels(); if(show_errors_mode) { if(!error) std::cout << "No errors or warnings" << std::endl; return; } // In case of checksum errors and some other ignorable errors, report it but ignore it and retry while(error) { // Not showing regular error here, is shown at end of program. unsigned error2 = error; if(error == 57) { showError(data, options); if(!show_errors_mode) std::cerr << "Ignoring the error: enabling ignore_crc" << std::endl; state.decoder.ignore_crc = 1; data.reloadPixels(); } else if(error == 58) { showError(data, options); if(!show_errors_mode) std::cerr << "Ignoring the error: enabling ignore_adler32" << std::endl; state.decoder.zlibsettings.ignore_adler32 = 1; data.reloadPixels(); } else if(error == 69) { showError(data, options); if(!show_errors_mode) std::cerr << "Ignoring the error: enabling ignore_critical" << std::endl; state.decoder.ignore_critical = 1; data.reloadPixels(); } else if(error == 30 || error == 63) { showError(data, options); if(!show_errors_mode) std::cerr << "Ignoring the error: enabling ignore_end" << std::endl; state.decoder.ignore_end = 1; data.reloadPixels(); } else { showError(data, options); if(!show_errors_mode) std::cerr << "This error is unrecoverable" << std::endl; break; // other error that we cannot ignore } if(!show_errors_mode) if(error == 0) std::cerr << "Successfully ignored the error" << std::endl; if(error == error2) { if(!show_errors_mode) std::cerr << "Failed to ignore the error" << std::endl; break; // avoid infinite loop if ignoring did not fix the error code } } if(show_errors_mode) { if(!error) std::cout << "The error is recoverable" << std::endl; else std::cout << "The error is not recoverable" << std::endl; } } void showSingleLineSummary(Data& data, const Options& options) { data.loadInspect(); if(data.error && data.error != 57) return; // CRC error (57) ignored here for parsing of header only std::cout << (options.use_hex ? std::hex: std::dec); std::cout << "Filesize: " << data.buffer.size() << " (" << data.buffer.size() / 1024 << "K)"; if(data.is_icc) { std::cout << ", not a PNG but an ICC profile, use -i to expand ICC profile info." << std::endl; return; } std::cout << ", " << data.w << "x" << data.h << ", "; std::cout << "Color: " << colorTypeString(data.state.info_png.color.colortype) << ", " << data.state.info_png.color.bitdepth << " bit" << std::endl; } static unsigned getICCUint16(const unsigned char* icc, size_t size, size_t pos) { if (pos + 2 > size) return 0; return (unsigned)((icc[pos] << 8) | (icc[pos + 1])); } static unsigned getICCUint32(const unsigned char* icc, size_t size, size_t pos) { if (pos + 4 > size) return 0; return (unsigned)((icc[pos] << 24) | (icc[pos + 1] << 16) | (icc[pos + 2] << 8) | (icc[pos + 3] << 0)); } static int getICCInt32(const unsigned char* icc, size_t size, size_t pos) { if (pos + 4 > size) return 0; return (int)((icc[pos] << 24) | (icc[pos + 1] << 16) | (icc[pos + 2] << 8) | (icc[pos + 3] << 0)); } // Signed static float getICC15Fixed16(const unsigned char* icc, size_t size, size_t pos) { return getICCInt32(icc, size, pos) / 65536.0; } // Unsigned static float getICC16Fixed16(const unsigned char* icc, size_t size, size_t pos) { return getICCUint32(icc, size, pos) / 65536.0; } static std::string printableICCWord(const unsigned char* icc, size_t size, size_t pos) { if (pos + 4 > size) { return "out of range"; } std::string result; for (int i = 0; i < 4; i++) { char c = icc[pos + i]; result += ((c >= 32 && c < 127) ? c : '?'); } return result; } void printICCDetails(const unsigned char* icc, size_t size, const std::string& indent) { // 128 for header, 4 for num tags if(size < 132) { std::cout << indent << "Invalid ICC: too small to contain header" << std::endl; return; } if(printableICCWord(icc, size, 36) != "acsp") { std::cout << indent << "Invalid ICC: does not contain signature \"acsp\"" << std::endl; return; } std::cout << indent << "profile size: " << getICCUint32(icc, size, 0) << std::endl; std::cout << indent << "CMM type: " << printableICCWord(icc, size, 4) << std::endl; uint32_t version = getICCUint32(icc, size, 8); uint16_t version_major = (version >> 24) & 255; uint16_t version_minor = (version >> 20) & 15; uint16_t version_bugfix = (version >> 16) & 15; std::cout << indent << "version: " << version_major << "." << version_minor << "." << version_bugfix << std::endl; std::cout << indent << "device class: " << printableICCWord(icc, size, 12) << std::endl; std::cout << indent << "input space: \"" << printableICCWord(icc, size, 16) << "\", "; std::cout << "output space: \"" << printableICCWord(icc, size, 20) << "\"" << std::endl; std::cout << indent; printf("date: %02d-%02d-%02dT%02d:%02d:%02d\n", getICCUint16(icc, size, 24), getICCUint16(icc, size, 26), getICCUint16(icc, size, 28), getICCUint16(icc, size, 30), getICCUint16(icc, size, 32), getICCUint16(icc, size, 34)); std::cout << indent << "signature: " << printableICCWord(icc, size, 36) << std::endl; std::cout << indent << "platform: " << printableICCWord(icc, size, 40) << std::endl; std::cout << indent << "flags: " << getICCUint32(icc, size, 44) << std::endl; std::cout << indent << "device manufacturer: " << printableICCWord(icc, size, 48) << ", "; std::cout << "device model: " << printableICCWord(icc, size, 52) << ", "; std::cout << "device attributes: " << getICCUint32(icc, size, 56) << " " << getICCUint32(icc, size, 60) << std::endl; std::cout << indent << "rendering intent: " << getICCUint32(icc, size, 64) << std::endl; float pcsx = getICC15Fixed16(icc, size, 68); float pcsy = getICC15Fixed16(icc, size, 72); float pcsz = getICC15Fixed16(icc, size, 76); float pcsxyz = pcsx + pcsy + pcsz; std::cout << indent << "xyz illuminant: X:" << pcsx << ", Y:" << pcsy << ", Z:" << pcsz << ", xy:" << (pcsx / pcsxyz) << "," << (pcsy / pcsxyz) << std::endl; std::cout << indent << "creator: " << printableICCWord(icc, size, 80) << std::endl; // The md5 is present in v2.4 and above profiles, but it's always shown anyway. Those // bytes are normally all zero for older versions. std::cout << indent; printf("md5: %08x%08x%08x%08x\n", getICCUint32(icc, size, 84), getICCUint32(icc, size, 88), getICCUint32(icc, size, 92), getICCUint32(icc, size, 96)); size_t numtags = getICCUint32(icc, size, 128); std::cout << indent << "num icc tags: " << numtags << std::endl; if(size < 128 + 4 + numtags * 12) { std::cout << indent << "Invalid ICC: too small to contain tag descriptions" << std::endl; return; } for(size_t i = 0; i < numtags; i++) { size_t pos = 132 + i * 12; std::cout << indent << "icc tag: \"" << printableICCWord(icc, size, pos) << "\""; size_t offset = getICCUint32(icc, size, pos + 4); size_t tagsize = getICCUint32(icc, size, pos + 8); std::cout << ", offset: " << offset << ", size: " << tagsize; if(offset + tagsize > size || tagsize < 4) { std::cout << std::endl << indent << "Invalid ICC: tag out of range" << std::endl; return; } std::string datatype = printableICCWord(icc, size, offset); std::cout << ", datatype: \"" << datatype << "\""; if(datatype == "XYZ ") { float x = getICC15Fixed16(icc, size, offset + 8); float y = getICC15Fixed16(icc, size, offset + 12); float z = getICC15Fixed16(icc, size, offset + 16); float xyz = x + y + z; std::cout << ", X:" << x << ", Y:" << y << ", Z:" << z; if(xyz) std::cout << ", xy:" << (x / xyz) << "," << (y / xyz); } if(datatype == "curv") { size_t lutsize = getICCUint32(icc, size, offset + 8); std::cout << ", lookup table size: " << lutsize; if(lutsize == 1 && offset + 14 <= size) { std::cout << " (gamma: " << (getICCUint16(icc, size, offset + 12) / 256.0) << ")"; } if(lutsize == 0) std::cout << " (linear)"; } if(datatype == "para") { unsigned type = getICCUint16(icc, size, offset + 8); float gamma = getICC15Fixed16(icc, size, offset + 12); int numparams = (type == 4) ? 7 : ((type >= 1 && type <= 3) ? (type + 1) : 0); std::cout << " type: " << type << ", gamma: " << gamma; if(numparams > 0) { std::cout << ", params: "; for(int j = 0; j < numparams; j++) { if(j > 0) std::cout << ", "; std::cout << getICC15Fixed16(icc, size, offset + 16 + j * 4); } } } if(datatype == "sf32") { std::cout << ":"; for(size_t j = 8; j < tagsize; j += 4) { float v = getICC15Fixed16(icc, size, offset + j); std::cout << " " << v; } } if(datatype == "chrm") { size_t numchannels = getICCUint16(icc, size, offset + 8); std::cout << ": n:" << numchannels << " phosphor:" << getICCUint16(icc, size, offset + 10); for(size_t j = 0; j < numchannels; j++) { std::cout << " xy:" << getICC16Fixed16(icc, size, offset + 12 + j * 8) << "," << getICC16Fixed16(icc, size, offset + 12 + j * 8 + 4); } } if(datatype == "text" || datatype == "mluc" || datatype == "desc") { // TODO: this is a bit of a simplification of the parse for now, e.g. // ignoring UTF-16, instead implicitely skipping non-ASCII bytes, and // potentially printing things multiple times in a row if multiple // variants are in desc or mluc. std::cout << ": "; for(size_t j = (datatype == "mluc" ? 28 : 8); j < tagsize; j++) { char c = icc[offset + j]; if(c >= 32 && c < 127) std::cout << c; } } std::cout << std::endl; } } void showHeaderInfo(Data& data, const Options& options) { data.loadInspect(); if(data.error) return; std::cout << (options.use_hex ? std::hex: std::dec); const LodePNGInfo& info = data.state.info_png; const LodePNGColorMode& color = info.color; if(options.show_header) { std::cout << "Filesize: " << data.buffer.size() << " (" << data.buffer.size() / 1024 << "K)" << std::endl; if(data.is_icc) { std::cout << "Not a PNG but an ICC profile, use -i for more info." << std::endl; } else { std::cout << "Width: " << data.w << std::endl; std::cout << "Height: " << data.h << std::endl; if(options.verbose) { double bpp = data.buffer.size() / (double)(data.w * data.h); std::cout << "Compressed bpp: " << bpp << std::endl; } std::cout << "Interlace method: " << info.interlace_method << std::endl; if(options.verbose) { std::cout << "Compression method: " << info.compression_method << std::endl; std::cout << "Filter method: " << info.filter_method << std::endl; } std::cout << "Color type: " << colorTypeString(color.colortype) << std::endl; std::cout << "Bit depth: " << color.bitdepth << std::endl; if(options.verbose) { std::cout << "Bits per pixel: " << lodepng_get_bpp(&color) << std::endl; std::cout << "Channels per pixel: " << lodepng_get_channels(&color) << std::endl; std::cout << "Is greyscale type: " << lodepng_is_greyscale_type(&color) << std::endl; std::cout << "Can have alpha: " << lodepng_can_have_alpha(&color) << std::endl; std::cout << "Has color key: " << color.key_defined << std::endl; } } } if(options.show_png_info && !data.is_icc) { if (color.colortype == LCT_PALETTE) { std::cout << "Palette size: " << color.palettesize << std::endl; } if(color.key_defined) { std::cout << "Color key rgb: " << color.key_r << ", " << color.key_g << ", " << color.key_b << std::endl; } if(info.background_defined) { if(color.colortype == LCT_PALETTE) { std::cout << "Background index: " << info.background_r << std::endl; } else { std::cout << "Background rgb: " << info.background_r << ", " << info.background_g << ", " << info.background_b << std::endl; } } if(info.gama_defined) { std::cout << "gAMA defined: " << info.gama_gamma << " (" << (info.gama_gamma / 100000.0) << ", " << (100000.0 / info.gama_gamma) << ")" << std::endl; } if(info.chrm_defined) { std::cout << "cHRM defined: w: " << (info.chrm_white_x / 100000.0) << " " << (info.chrm_white_y / 100000.0) << ", r: " << (info.chrm_red_x / 100000.0) << " " << (info.chrm_red_y / 100000.0) << ", g: " << (info.chrm_green_x / 100000.0) << " " << (info.chrm_green_y / 100000.0) << ", b: " << (info.chrm_blue_x / 100000.0) << " " << (info.chrm_blue_y / 100000.0) << std::endl; } if(info.srgb_defined) { std::cout << "sRGB defined: rendering intent: " << info.srgb_intent << std::endl; } if(info.iccp_defined) { std::cout << "iCCP defined (" << info.iccp_profile_size << " bytes): name: " << info.iccp_name << std::endl; if(options.verbose && !options.show_icc_details && !options.show_icc_hex) { std::cout << "Use -i or -I to show ICC profile details or hex" << std::endl; } } } if(info.iccp_defined && options.show_icc_details) { if(!options.show_header) { std::cout << "ICC profile details (" << info.iccp_profile_size << " bytes), PNG name: " << info.iccp_name << std::endl; } printICCDetails(info.iccp_profile, info.iccp_profile_size, " "); std::cout << "end of ICC profile" << std::endl; } if(info.iccp_defined && options.show_icc_hex) { for(size_t i = 0; i < info.iccp_profile_size; i++) { unsigned char c = info.iccp_profile[i]; if(options.hexformat == HF_BIN) { printf("%c", c); } else { if(c > 32 && c < 127 && options.hexformat == HF_MIX) printf(" %c ", c); else printf("%02x ", c); if(i % 32 == 31 && i + 1 != info.iccp_profile_size) std::cout << std::endl; } } if(options.hexformat != HF_BIN) std::cout << std::endl; } if(options.show_png_info && !data.is_icc) { if(options.verbose) std::cout << "Physics defined: " << info.phys_defined << std::endl; if(info.phys_defined) { std::cout << "Physics: X: " << info.phys_x << ", Y: " << info.phys_y << ", unit: " << info.phys_unit << std::endl; } } } // shortens the text unless options.expand_long_texts is true std::string shortenText(const std::string& text, const Options& options) { if(options.expand_long_texts) return text; size_t maxlen = 512; size_t maxnl = options.verbose ? 5 : 1; size_t numnl = 0; // amount of newlines for(size_t i = 0; i < text.size(); i++) { if(text[i] == 10) numnl++; if(numnl >= maxnl) { maxlen = i; break; } } if(text.size() < maxlen) return text; return text.substr(0, maxlen) + (numnl > 1 ? "\n" : "") + "... [TEXT SNIPPED! use -t to expand long text]"; } // A bit more PNG info, which is from chunks that can come after IDAT. showHeaderInfo shows most other stuff. void showPNGInfo(Data& data, const Options& options) { if(data.is_icc) return; loadWithErrorRecovery(data, options, false); if(data.error) return; std::cout << (options.use_hex ? std::hex: std::dec); const LodePNGInfo& info = data.state.info_png; if(options.verbose) std::cout << "Texts: " << info.text_num << std::endl; for(size_t i = 0; i < info.text_num; i++) { std::cout << "Text (" << (strlen(info.text_strings[i])) << " bytes): " << info.text_keys[i] << ": " << shortenText(info.text_strings[i], options) << std::endl; } if(options.verbose) std::cout << "International texts: " << info.itext_num << std::endl; for(size_t i = 0; i < info.itext_num; i++) { std::cout << "Text (" << (strlen(info.itext_strings[i])) << " bytes): " << info.itext_keys[i] << ", " << info.itext_langtags[i] << ", " << info.itext_transkeys[i] << ": " << shortenText(info.itext_strings[i], options) << std::endl; } if(options.verbose) std::cout << "Time defined: " << info.time_defined << std::endl; if(info.time_defined) { const LodePNGTime& time = info.time; printf("time: %02d-%02d-%02dT%02d:%02d:%02d\n", time.year, time.month, time.day, time.hour, time.minute, time.second); } } void showColorStats(Data& data, const Options& options) { if(data.is_icc) return; std::cout << (options.use_hex ? std::hex: std::dec); std::vector& image = data.pixels; unsigned& w = data.w; unsigned& h = data.h; data.loadPixels(); if(data.error) return; // TODO: move to show color stats function if(options.verbose) std::cout << "Num pixels: " << w * h << std::endl; size_t rc, gc, bc, ac; std::cout << "Num unique colors: " << countColors(image, w, h, &rc, &gc, &bc, &ac); std::cout << " (r: " << rc << ", g: " << gc << ", b: " << bc << ", a: " << ac << ")"; std::cout << std::endl; if(w > 0 && h > 0) { double avg[4] = {0, 0, 0, 0}; double min[4] = {999999, 999999, 999999, 999999}; double max[4] = {0, 0, 0, 0}; for(unsigned y = 0; y < h; y++) { for(unsigned x = 0; x < w; x++) { for(int c = 0; c < 4; c++) { double v = 256 * image[y * 8 * w + x * 8 + c * 2] + image[y * 8 * w + x * 8 + c * 2 + 1]; avg[c] += v; min[c] = std::min(min[c], v); max[c] = std::max(max[c], v); } } } for(int c = 0; c < 4; c++) { avg[c] /= (w * h * 257.0); min[c] /= 257.0; max[c] /= 257.0; } if(options.verbose) std::cout << "Ranges shown as 0.0-255.0, even for 16-bit data:" << std::endl; std::cout << "Average color: " << avg[0] << ", " << avg[1] << ", " << avg[2] << ", " << avg[3] << std::endl; std::cout << "Color ranges: " << min[0] << "-" << max[0] << ", " << min[1] << "-" << max[1] << ", " << min[2] << "-" << max[2] << ", " << min[3] << "-" << max[3] << std::endl; } } void showErrors(Data& data, const Options& options) { std::cout << "Error report: " << std::endl; Data data2(data.filename); loadWithErrorRecovery(data2, options, true); } void showRender(Data& data, const Options& options) { data.loadPixels(); if(data.error) return; if(options.rendermode == RM_ASCII) { displayAsciiArt(data.pixels, data.w, data.h, options.rendersize); } if(options.rendermode == RM_HEX) { displayColorsHex(data.pixels, data.w, data.h, false); } if(options.rendermode == RM_HEX16) { displayColorsHex(data.pixels, data.w, data.h, true); } if(options.rendermode == RM_PAL) { displayPalettePixels(data.buffer, options); } } void showInfos(Data& data, const Options& options) { if(options.show_one_line_summary) showSingleLineSummary(data, options); if(options.show_errors) showErrors(data, options); if(options.show_header || options.show_icc_details || options.show_icc_hex) showHeaderInfo(data, options); if(options.show_color_stats) showColorStats(data, options); if(options.show_png_info) showPNGInfo(data, options); if(options.show_palette) displayPalette(data, options); if(options.show_chunks || options.show_chunks2) displayChunkNames(data, options); if(options.show_filters) displayFilterTypes(data, options); if(options.show_render) showRender(data, options); if(options.zlib_info || options.zlib_blocks || options.zlib_counts || options.zlib_full) { printZlibInfo(data, options); } if(data.error) showError(data, options); } int main(int argc, char *argv[]) { Options options; bool options_chosen = false; std::vector filenames; for (int i = 1; i < argc; i++) { std::string s = argv[i]; if(s.size() > 1 && s[0] == '-' && s[1] != '-') { // anything that chooses actual set disables the defaults if(s != "-x" && s != "-v" && s != "-t") options_chosen = true; for(size_t j = 1; j < s.size(); j++) { char c = s[j]; if(c == 'o') options.show_one_line_summary = true; else if(c == 'H') options.show_header = true; else if(c == 'i') options.show_icc_details = true; else if(c == 'I') options.show_icc_hex = true; else if(c == 'v') options.verbose = true; else if(c == 't') options.expand_long_texts = true; else if(c == 's') options.show_color_stats = true; else if(c == 'e') options.show_errors = true; else if(c == 'p') options.show_header = options.show_png_info = true; else if(c == 'r') options.show_render = true; else if(c == 'l') options.show_palette = true; else if(c == 'L') options.show_palette_pixels = true; else if(c == 'c') options.show_chunks = true; else if(c == 'C') options.show_chunks2 = true; else if(c == 'f') options.show_filters = true; else if(c == 'z') options.zlib_info = true; else if(c == 'b') options.zlib_blocks = true; else if(c == 'B') { options.zlib_blocks = true; options.zlib_counts = true; } else if(c == '7') { options.zlib_blocks = true; options.zlib_full = true; } else if(c == 'x') { options.use_hex = true; std::cout << std::hex; } else { if(s != "--help" && c != 'h' && c != '?') std::cout << "Unknown flag: " << c << ". Use -h for help" << std::endl; showHelp(); return 0; } } } else if(s.size() > 1 && s[0] == '-' && s[1] == '-') { size_t eqpos = 2; while(eqpos < s.size() && s[eqpos] != '=') eqpos++; std::string key = s.substr(2, eqpos - 2); std::string value = (eqpos + 1) < s.size() ? s.substr(eqpos + 1) : ""; if(key == "help") { showHelp(); return 0; } if(key == "mode") { if(value == "ascii") options.rendermode = RM_ASCII; else if(value == "hex") options.rendermode = RM_HEX; else if(value == "hex16") options.rendermode = RM_HEX16; else if(value == "palette") options.rendermode = RM_PAL; } if(key == "size") { int size = strtoval(value); if(options.rendersize >= 1 && options.rendersize <= 4096) options.rendersize = size; } if(key == "format") { if(value == "mix") options.hexformat = HF_MIX; else if(value == "hex") options.hexformat = HF_HEX; else if(value == "bin") options.hexformat = HF_BIN; } } else filenames.push_back(s); } if(filenames.empty()) { std::cout << "Please provide a filename to preview" << std::endl; showHelp(); return 0; } if(!options_chosen) { //fill in defaults options.show_header = true; options.show_png_info = true; options.show_chunks2 = true; // verbose lets individual sections show more, and in addition adds more default unlocked sections if no specific one chosen if(options.verbose) { options.show_chunks2 = false; options.show_chunks = true; } } for(size_t i = 0; i < filenames.size(); i++) { if(filenames.size() > 1) { if(i > 0 && !options.show_one_line_summary) std::cout << std::endl; std::cout << filenames[i] << ":"; if(!options.show_one_line_summary) std::cout << std::endl; else std::cout << " "; } Data data(filenames[i]); showInfos(data, options); } }