Graphical demo for the LPC4088 Experiment Base Board with one of the Display Expansion Kits. This program decodes decodes and shows two png images.
lodepng.h@0:b567d56a59d7, 2014-10-03 (annotated)
- Committer:
- embeddedartists
- Date:
- Fri Oct 03 13:30:09 2014 +0000
- Revision:
- 0:b567d56a59d7
First version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 0:b567d56a59d7 | 1 | /* |
embeddedartists | 0:b567d56a59d7 | 2 | LodePNG version 20131222 |
embeddedartists | 0:b567d56a59d7 | 3 | |
embeddedartists | 0:b567d56a59d7 | 4 | Copyright (c) 2005-2013 Lode Vandevenne |
embeddedartists | 0:b567d56a59d7 | 5 | |
embeddedartists | 0:b567d56a59d7 | 6 | This software is provided 'as-is', without any express or implied |
embeddedartists | 0:b567d56a59d7 | 7 | warranty. In no event will the authors be held liable for any damages |
embeddedartists | 0:b567d56a59d7 | 8 | arising from the use of this software. |
embeddedartists | 0:b567d56a59d7 | 9 | |
embeddedartists | 0:b567d56a59d7 | 10 | Permission is granted to anyone to use this software for any purpose, |
embeddedartists | 0:b567d56a59d7 | 11 | including commercial applications, and to alter it and redistribute it |
embeddedartists | 0:b567d56a59d7 | 12 | freely, subject to the following restrictions: |
embeddedartists | 0:b567d56a59d7 | 13 | |
embeddedartists | 0:b567d56a59d7 | 14 | 1. The origin of this software must not be misrepresented; you must not |
embeddedartists | 0:b567d56a59d7 | 15 | claim that you wrote the original software. If you use this software |
embeddedartists | 0:b567d56a59d7 | 16 | in a product, an acknowledgment in the product documentation would be |
embeddedartists | 0:b567d56a59d7 | 17 | appreciated but is not required. |
embeddedartists | 0:b567d56a59d7 | 18 | |
embeddedartists | 0:b567d56a59d7 | 19 | 2. Altered source versions must be plainly marked as such, and must not be |
embeddedartists | 0:b567d56a59d7 | 20 | misrepresented as being the original software. |
embeddedartists | 0:b567d56a59d7 | 21 | |
embeddedartists | 0:b567d56a59d7 | 22 | 3. This notice may not be removed or altered from any source |
embeddedartists | 0:b567d56a59d7 | 23 | distribution. |
embeddedartists | 0:b567d56a59d7 | 24 | */ |
embeddedartists | 0:b567d56a59d7 | 25 | |
embeddedartists | 0:b567d56a59d7 | 26 | #ifndef LODEPNG_H |
embeddedartists | 0:b567d56a59d7 | 27 | #define LODEPNG_H |
embeddedartists | 0:b567d56a59d7 | 28 | |
embeddedartists | 0:b567d56a59d7 | 29 | #include <string.h> /*for size_t*/ |
embeddedartists | 0:b567d56a59d7 | 30 | |
embeddedartists | 0:b567d56a59d7 | 31 | #ifdef __cplusplus |
embeddedartists | 0:b567d56a59d7 | 32 | #include <vector> |
embeddedartists | 0:b567d56a59d7 | 33 | #include <string> |
embeddedartists | 0:b567d56a59d7 | 34 | #endif /*__cplusplus*/ |
embeddedartists | 0:b567d56a59d7 | 35 | |
embeddedartists | 0:b567d56a59d7 | 36 | |
embeddedartists | 0:b567d56a59d7 | 37 | // Settings modified by Embedded Artists |
embeddedartists | 0:b567d56a59d7 | 38 | #define LODEPNG_NO_COMPILE_ENCODER |
embeddedartists | 0:b567d56a59d7 | 39 | #define LODEPNG_NO_COMPILE_DISK |
embeddedartists | 0:b567d56a59d7 | 40 | #define LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS |
embeddedartists | 0:b567d56a59d7 | 41 | #define LODEPNG_NO_COMPILE_ERROR_TEXT |
embeddedartists | 0:b567d56a59d7 | 42 | #define LODEPNG_NO_COMPILE_CPP |
embeddedartists | 0:b567d56a59d7 | 43 | |
embeddedartists | 0:b567d56a59d7 | 44 | |
embeddedartists | 0:b567d56a59d7 | 45 | /* |
embeddedartists | 0:b567d56a59d7 | 46 | The following #defines are used to create code sections. They can be disabled |
embeddedartists | 0:b567d56a59d7 | 47 | to disable code sections, which can give faster compile time and smaller binary. |
embeddedartists | 0:b567d56a59d7 | 48 | The "NO_COMPILE" defines are designed to be used to pass as defines to the |
embeddedartists | 0:b567d56a59d7 | 49 | compiler command to disable them without modifying this header, e.g. |
embeddedartists | 0:b567d56a59d7 | 50 | -DLODEPNG_NO_COMPILE_ZLIB for gcc. |
embeddedartists | 0:b567d56a59d7 | 51 | */ |
embeddedartists | 0:b567d56a59d7 | 52 | /*deflate & zlib. If disabled, you must specify alternative zlib functions in |
embeddedartists | 0:b567d56a59d7 | 53 | the custom_zlib field of the compress and decompress settings*/ |
embeddedartists | 0:b567d56a59d7 | 54 | #ifndef LODEPNG_NO_COMPILE_ZLIB |
embeddedartists | 0:b567d56a59d7 | 55 | #define LODEPNG_COMPILE_ZLIB |
embeddedartists | 0:b567d56a59d7 | 56 | #endif |
embeddedartists | 0:b567d56a59d7 | 57 | /*png encoder and png decoder*/ |
embeddedartists | 0:b567d56a59d7 | 58 | #ifndef LODEPNG_NO_COMPILE_PNG |
embeddedartists | 0:b567d56a59d7 | 59 | #define LODEPNG_COMPILE_PNG |
embeddedartists | 0:b567d56a59d7 | 60 | #endif |
embeddedartists | 0:b567d56a59d7 | 61 | /*deflate&zlib decoder and png decoder*/ |
embeddedartists | 0:b567d56a59d7 | 62 | #ifndef LODEPNG_NO_COMPILE_DECODER |
embeddedartists | 0:b567d56a59d7 | 63 | #define LODEPNG_COMPILE_DECODER |
embeddedartists | 0:b567d56a59d7 | 64 | #endif |
embeddedartists | 0:b567d56a59d7 | 65 | /*deflate&zlib encoder and png encoder*/ |
embeddedartists | 0:b567d56a59d7 | 66 | #ifndef LODEPNG_NO_COMPILE_ENCODER |
embeddedartists | 0:b567d56a59d7 | 67 | #define LODEPNG_COMPILE_ENCODER |
embeddedartists | 0:b567d56a59d7 | 68 | #endif |
embeddedartists | 0:b567d56a59d7 | 69 | /*the optional built in harddisk file loading and saving functions*/ |
embeddedartists | 0:b567d56a59d7 | 70 | #ifndef LODEPNG_NO_COMPILE_DISK |
embeddedartists | 0:b567d56a59d7 | 71 | #define LODEPNG_COMPILE_DISK |
embeddedartists | 0:b567d56a59d7 | 72 | #endif |
embeddedartists | 0:b567d56a59d7 | 73 | /*support for chunks other than IHDR, IDAT, PLTE, tRNS, IEND: ancillary and unknown chunks*/ |
embeddedartists | 0:b567d56a59d7 | 74 | #ifndef LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS |
embeddedartists | 0:b567d56a59d7 | 75 | #define LODEPNG_COMPILE_ANCILLARY_CHUNKS |
embeddedartists | 0:b567d56a59d7 | 76 | #endif |
embeddedartists | 0:b567d56a59d7 | 77 | /*ability to convert error numerical codes to English text string*/ |
embeddedartists | 0:b567d56a59d7 | 78 | #ifndef LODEPNG_NO_COMPILE_ERROR_TEXT |
embeddedartists | 0:b567d56a59d7 | 79 | #define LODEPNG_COMPILE_ERROR_TEXT |
embeddedartists | 0:b567d56a59d7 | 80 | #endif |
embeddedartists | 0:b567d56a59d7 | 81 | /*Compile the default allocators (C's free, malloc and realloc). If you disable this, |
embeddedartists | 0:b567d56a59d7 | 82 | you can define the functions lodepng_free, lodepng_malloc and lodepng_realloc in your |
embeddedartists | 0:b567d56a59d7 | 83 | source files with custom allocators.*/ |
embeddedartists | 0:b567d56a59d7 | 84 | #ifndef LODEPNG_NO_COMPILE_ALLOCATORS |
embeddedartists | 0:b567d56a59d7 | 85 | #define LODEPNG_COMPILE_ALLOCATORS |
embeddedartists | 0:b567d56a59d7 | 86 | #endif |
embeddedartists | 0:b567d56a59d7 | 87 | /*compile the C++ version (you can disable the C++ wrapper here even when compiling for C++)*/ |
embeddedartists | 0:b567d56a59d7 | 88 | #ifdef __cplusplus |
embeddedartists | 0:b567d56a59d7 | 89 | #ifndef LODEPNG_NO_COMPILE_CPP |
embeddedartists | 0:b567d56a59d7 | 90 | #define LODEPNG_COMPILE_CPP |
embeddedartists | 0:b567d56a59d7 | 91 | #endif |
embeddedartists | 0:b567d56a59d7 | 92 | #endif |
embeddedartists | 0:b567d56a59d7 | 93 | |
embeddedartists | 0:b567d56a59d7 | 94 | #ifdef LODEPNG_COMPILE_PNG |
embeddedartists | 0:b567d56a59d7 | 95 | /*The PNG color types (also used for raw).*/ |
embeddedartists | 0:b567d56a59d7 | 96 | typedef enum LodePNGColorType |
embeddedartists | 0:b567d56a59d7 | 97 | { |
embeddedartists | 0:b567d56a59d7 | 98 | LCT_GREY = 0, /*greyscale: 1,2,4,8,16 bit*/ |
embeddedartists | 0:b567d56a59d7 | 99 | LCT_RGB = 2, /*RGB: 8,16 bit*/ |
embeddedartists | 0:b567d56a59d7 | 100 | LCT_PALETTE = 3, /*palette: 1,2,4,8 bit*/ |
embeddedartists | 0:b567d56a59d7 | 101 | LCT_GREY_ALPHA = 4, /*greyscale with alpha: 8,16 bit*/ |
embeddedartists | 0:b567d56a59d7 | 102 | LCT_RGBA = 6 /*RGB with alpha: 8,16 bit*/ |
embeddedartists | 0:b567d56a59d7 | 103 | } LodePNGColorType; |
embeddedartists | 0:b567d56a59d7 | 104 | |
embeddedartists | 0:b567d56a59d7 | 105 | #ifdef LODEPNG_COMPILE_DECODER |
embeddedartists | 0:b567d56a59d7 | 106 | /* |
embeddedartists | 0:b567d56a59d7 | 107 | Converts PNG data in memory to raw pixel data. |
embeddedartists | 0:b567d56a59d7 | 108 | out: Output parameter. Pointer to buffer that will contain the raw pixel data. |
embeddedartists | 0:b567d56a59d7 | 109 | After decoding, its size is w * h * (bytes per pixel) bytes larger than |
embeddedartists | 0:b567d56a59d7 | 110 | initially. Bytes per pixel depends on colortype and bitdepth. |
embeddedartists | 0:b567d56a59d7 | 111 | Must be freed after usage with free(*out). |
embeddedartists | 0:b567d56a59d7 | 112 | Note: for 16-bit per channel colors, uses big endian format like PNG does. |
embeddedartists | 0:b567d56a59d7 | 113 | w: Output parameter. Pointer to width of pixel data. |
embeddedartists | 0:b567d56a59d7 | 114 | h: Output parameter. Pointer to height of pixel data. |
embeddedartists | 0:b567d56a59d7 | 115 | in: Memory buffer with the PNG file. |
embeddedartists | 0:b567d56a59d7 | 116 | insize: size of the in buffer. |
embeddedartists | 0:b567d56a59d7 | 117 | colortype: the desired color type for the raw output image. See explanation on PNG color types. |
embeddedartists | 0:b567d56a59d7 | 118 | bitdepth: the desired bit depth for the raw output image. See explanation on PNG color types. |
embeddedartists | 0:b567d56a59d7 | 119 | Return value: LodePNG error code (0 means no error). |
embeddedartists | 0:b567d56a59d7 | 120 | */ |
embeddedartists | 0:b567d56a59d7 | 121 | unsigned lodepng_decode_memory(unsigned char** out, unsigned* w, unsigned* h, |
embeddedartists | 0:b567d56a59d7 | 122 | const unsigned char* in, size_t insize, |
embeddedartists | 0:b567d56a59d7 | 123 | LodePNGColorType colortype, unsigned bitdepth); |
embeddedartists | 0:b567d56a59d7 | 124 | |
embeddedartists | 0:b567d56a59d7 | 125 | /*Same as lodepng_decode_memory, but always decodes to 32-bit RGBA raw image*/ |
embeddedartists | 0:b567d56a59d7 | 126 | unsigned lodepng_decode32(unsigned char** out, unsigned* w, unsigned* h, |
embeddedartists | 0:b567d56a59d7 | 127 | const unsigned char* in, size_t insize); |
embeddedartists | 0:b567d56a59d7 | 128 | |
embeddedartists | 0:b567d56a59d7 | 129 | /*Same as lodepng_decode_memory, but always decodes to 24-bit RGB raw image*/ |
embeddedartists | 0:b567d56a59d7 | 130 | unsigned lodepng_decode24(unsigned char** out, unsigned* w, unsigned* h, |
embeddedartists | 0:b567d56a59d7 | 131 | const unsigned char* in, size_t insize); |
embeddedartists | 0:b567d56a59d7 | 132 | |
embeddedartists | 0:b567d56a59d7 | 133 | #ifdef LODEPNG_COMPILE_DISK |
embeddedartists | 0:b567d56a59d7 | 134 | /* |
embeddedartists | 0:b567d56a59d7 | 135 | Load PNG from disk, from file with given name. |
embeddedartists | 0:b567d56a59d7 | 136 | Same as the other decode functions, but instead takes a filename as input. |
embeddedartists | 0:b567d56a59d7 | 137 | */ |
embeddedartists | 0:b567d56a59d7 | 138 | unsigned lodepng_decode_file(unsigned char** out, unsigned* w, unsigned* h, |
embeddedartists | 0:b567d56a59d7 | 139 | const char* filename, |
embeddedartists | 0:b567d56a59d7 | 140 | LodePNGColorType colortype, unsigned bitdepth); |
embeddedartists | 0:b567d56a59d7 | 141 | |
embeddedartists | 0:b567d56a59d7 | 142 | /*Same as lodepng_decode_file, but always decodes to 32-bit RGBA raw image.*/ |
embeddedartists | 0:b567d56a59d7 | 143 | unsigned lodepng_decode32_file(unsigned char** out, unsigned* w, unsigned* h, |
embeddedartists | 0:b567d56a59d7 | 144 | const char* filename); |
embeddedartists | 0:b567d56a59d7 | 145 | |
embeddedartists | 0:b567d56a59d7 | 146 | /*Same as lodepng_decode_file, but always decodes to 24-bit RGB raw image.*/ |
embeddedartists | 0:b567d56a59d7 | 147 | unsigned lodepng_decode24_file(unsigned char** out, unsigned* w, unsigned* h, |
embeddedartists | 0:b567d56a59d7 | 148 | const char* filename); |
embeddedartists | 0:b567d56a59d7 | 149 | #endif /*LODEPNG_COMPILE_DISK*/ |
embeddedartists | 0:b567d56a59d7 | 150 | #endif /*LODEPNG_COMPILE_DECODER*/ |
embeddedartists | 0:b567d56a59d7 | 151 | |
embeddedartists | 0:b567d56a59d7 | 152 | |
embeddedartists | 0:b567d56a59d7 | 153 | #ifdef LODEPNG_COMPILE_ENCODER |
embeddedartists | 0:b567d56a59d7 | 154 | /* |
embeddedartists | 0:b567d56a59d7 | 155 | Converts raw pixel data into a PNG image in memory. The colortype and bitdepth |
embeddedartists | 0:b567d56a59d7 | 156 | of the output PNG image cannot be chosen, they are automatically determined |
embeddedartists | 0:b567d56a59d7 | 157 | by the colortype, bitdepth and content of the input pixel data. |
embeddedartists | 0:b567d56a59d7 | 158 | Note: for 16-bit per channel colors, needs big endian format like PNG does. |
embeddedartists | 0:b567d56a59d7 | 159 | out: Output parameter. Pointer to buffer that will contain the PNG image data. |
embeddedartists | 0:b567d56a59d7 | 160 | Must be freed after usage with free(*out). |
embeddedartists | 0:b567d56a59d7 | 161 | outsize: Output parameter. Pointer to the size in bytes of the out buffer. |
embeddedartists | 0:b567d56a59d7 | 162 | image: The raw pixel data to encode. The size of this buffer should be |
embeddedartists | 0:b567d56a59d7 | 163 | w * h * (bytes per pixel), bytes per pixel depends on colortype and bitdepth. |
embeddedartists | 0:b567d56a59d7 | 164 | w: width of the raw pixel data in pixels. |
embeddedartists | 0:b567d56a59d7 | 165 | h: height of the raw pixel data in pixels. |
embeddedartists | 0:b567d56a59d7 | 166 | colortype: the color type of the raw input image. See explanation on PNG color types. |
embeddedartists | 0:b567d56a59d7 | 167 | bitdepth: the bit depth of the raw input image. See explanation on PNG color types. |
embeddedartists | 0:b567d56a59d7 | 168 | Return value: LodePNG error code (0 means no error). |
embeddedartists | 0:b567d56a59d7 | 169 | */ |
embeddedartists | 0:b567d56a59d7 | 170 | unsigned lodepng_encode_memory(unsigned char** out, size_t* outsize, |
embeddedartists | 0:b567d56a59d7 | 171 | const unsigned char* image, unsigned w, unsigned h, |
embeddedartists | 0:b567d56a59d7 | 172 | LodePNGColorType colortype, unsigned bitdepth); |
embeddedartists | 0:b567d56a59d7 | 173 | |
embeddedartists | 0:b567d56a59d7 | 174 | /*Same as lodepng_encode_memory, but always encodes from 32-bit RGBA raw image.*/ |
embeddedartists | 0:b567d56a59d7 | 175 | unsigned lodepng_encode32(unsigned char** out, size_t* outsize, |
embeddedartists | 0:b567d56a59d7 | 176 | const unsigned char* image, unsigned w, unsigned h); |
embeddedartists | 0:b567d56a59d7 | 177 | |
embeddedartists | 0:b567d56a59d7 | 178 | /*Same as lodepng_encode_memory, but always encodes from 24-bit RGB raw image.*/ |
embeddedartists | 0:b567d56a59d7 | 179 | unsigned lodepng_encode24(unsigned char** out, size_t* outsize, |
embeddedartists | 0:b567d56a59d7 | 180 | const unsigned char* image, unsigned w, unsigned h); |
embeddedartists | 0:b567d56a59d7 | 181 | |
embeddedartists | 0:b567d56a59d7 | 182 | #ifdef LODEPNG_COMPILE_DISK |
embeddedartists | 0:b567d56a59d7 | 183 | /* |
embeddedartists | 0:b567d56a59d7 | 184 | Converts raw pixel data into a PNG file on disk. |
embeddedartists | 0:b567d56a59d7 | 185 | Same as the other encode functions, but instead takes a filename as output. |
embeddedartists | 0:b567d56a59d7 | 186 | NOTE: This overwrites existing files without warning! |
embeddedartists | 0:b567d56a59d7 | 187 | */ |
embeddedartists | 0:b567d56a59d7 | 188 | unsigned lodepng_encode_file(const char* filename, |
embeddedartists | 0:b567d56a59d7 | 189 | const unsigned char* image, unsigned w, unsigned h, |
embeddedartists | 0:b567d56a59d7 | 190 | LodePNGColorType colortype, unsigned bitdepth); |
embeddedartists | 0:b567d56a59d7 | 191 | |
embeddedartists | 0:b567d56a59d7 | 192 | /*Same as lodepng_encode_file, but always encodes from 32-bit RGBA raw image.*/ |
embeddedartists | 0:b567d56a59d7 | 193 | unsigned lodepng_encode32_file(const char* filename, |
embeddedartists | 0:b567d56a59d7 | 194 | const unsigned char* image, unsigned w, unsigned h); |
embeddedartists | 0:b567d56a59d7 | 195 | |
embeddedartists | 0:b567d56a59d7 | 196 | /*Same as lodepng_encode_file, but always encodes from 24-bit RGB raw image.*/ |
embeddedartists | 0:b567d56a59d7 | 197 | unsigned lodepng_encode24_file(const char* filename, |
embeddedartists | 0:b567d56a59d7 | 198 | const unsigned char* image, unsigned w, unsigned h); |
embeddedartists | 0:b567d56a59d7 | 199 | #endif /*LODEPNG_COMPILE_DISK*/ |
embeddedartists | 0:b567d56a59d7 | 200 | #endif /*LODEPNG_COMPILE_ENCODER*/ |
embeddedartists | 0:b567d56a59d7 | 201 | |
embeddedartists | 0:b567d56a59d7 | 202 | |
embeddedartists | 0:b567d56a59d7 | 203 | #ifdef LODEPNG_COMPILE_CPP |
embeddedartists | 0:b567d56a59d7 | 204 | namespace lodepng |
embeddedartists | 0:b567d56a59d7 | 205 | { |
embeddedartists | 0:b567d56a59d7 | 206 | #ifdef LODEPNG_COMPILE_DECODER |
embeddedartists | 0:b567d56a59d7 | 207 | /*Same as lodepng_decode_memory, but decodes to an std::vector.*/ |
embeddedartists | 0:b567d56a59d7 | 208 | unsigned decode(std::vector<unsigned char>& out, unsigned& w, unsigned& h, |
embeddedartists | 0:b567d56a59d7 | 209 | const unsigned char* in, size_t insize, |
embeddedartists | 0:b567d56a59d7 | 210 | LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); |
embeddedartists | 0:b567d56a59d7 | 211 | unsigned decode(std::vector<unsigned char>& out, unsigned& w, unsigned& h, |
embeddedartists | 0:b567d56a59d7 | 212 | const std::vector<unsigned char>& in, |
embeddedartists | 0:b567d56a59d7 | 213 | LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); |
embeddedartists | 0:b567d56a59d7 | 214 | #ifdef LODEPNG_COMPILE_DISK |
embeddedartists | 0:b567d56a59d7 | 215 | /* |
embeddedartists | 0:b567d56a59d7 | 216 | Converts PNG file from disk to raw pixel data in memory. |
embeddedartists | 0:b567d56a59d7 | 217 | Same as the other decode functions, but instead takes a filename as input. |
embeddedartists | 0:b567d56a59d7 | 218 | */ |
embeddedartists | 0:b567d56a59d7 | 219 | unsigned decode(std::vector<unsigned char>& out, unsigned& w, unsigned& h, |
embeddedartists | 0:b567d56a59d7 | 220 | const std::string& filename, |
embeddedartists | 0:b567d56a59d7 | 221 | LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); |
embeddedartists | 0:b567d56a59d7 | 222 | #endif //LODEPNG_COMPILE_DISK |
embeddedartists | 0:b567d56a59d7 | 223 | #endif //LODEPNG_COMPILE_DECODER |
embeddedartists | 0:b567d56a59d7 | 224 | |
embeddedartists | 0:b567d56a59d7 | 225 | #ifdef LODEPNG_COMPILE_ENCODER |
embeddedartists | 0:b567d56a59d7 | 226 | /*Same as lodepng_encode_memory, but encodes to an std::vector.*/ |
embeddedartists | 0:b567d56a59d7 | 227 | unsigned encode(std::vector<unsigned char>& out, |
embeddedartists | 0:b567d56a59d7 | 228 | const unsigned char* in, unsigned w, unsigned h, |
embeddedartists | 0:b567d56a59d7 | 229 | LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); |
embeddedartists | 0:b567d56a59d7 | 230 | unsigned encode(std::vector<unsigned char>& out, |
embeddedartists | 0:b567d56a59d7 | 231 | const std::vector<unsigned char>& in, unsigned w, unsigned h, |
embeddedartists | 0:b567d56a59d7 | 232 | LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); |
embeddedartists | 0:b567d56a59d7 | 233 | #ifdef LODEPNG_COMPILE_DISK |
embeddedartists | 0:b567d56a59d7 | 234 | /* |
embeddedartists | 0:b567d56a59d7 | 235 | Converts 32-bit RGBA raw pixel data into a PNG file on disk. |
embeddedartists | 0:b567d56a59d7 | 236 | Same as the other encode functions, but instead takes a filename as output. |
embeddedartists | 0:b567d56a59d7 | 237 | NOTE: This overwrites existing files without warning! |
embeddedartists | 0:b567d56a59d7 | 238 | */ |
embeddedartists | 0:b567d56a59d7 | 239 | unsigned encode(const std::string& filename, |
embeddedartists | 0:b567d56a59d7 | 240 | const unsigned char* in, unsigned w, unsigned h, |
embeddedartists | 0:b567d56a59d7 | 241 | LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); |
embeddedartists | 0:b567d56a59d7 | 242 | unsigned encode(const std::string& filename, |
embeddedartists | 0:b567d56a59d7 | 243 | const std::vector<unsigned char>& in, unsigned w, unsigned h, |
embeddedartists | 0:b567d56a59d7 | 244 | LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); |
embeddedartists | 0:b567d56a59d7 | 245 | #endif //LODEPNG_COMPILE_DISK |
embeddedartists | 0:b567d56a59d7 | 246 | #endif //LODEPNG_COMPILE_ENCODER |
embeddedartists | 0:b567d56a59d7 | 247 | } //namespace lodepng |
embeddedartists | 0:b567d56a59d7 | 248 | #endif /*LODEPNG_COMPILE_CPP*/ |
embeddedartists | 0:b567d56a59d7 | 249 | #endif /*LODEPNG_COMPILE_PNG*/ |
embeddedartists | 0:b567d56a59d7 | 250 | |
embeddedartists | 0:b567d56a59d7 | 251 | #ifdef LODEPNG_COMPILE_ERROR_TEXT |
embeddedartists | 0:b567d56a59d7 | 252 | /*Returns an English description of the numerical error code.*/ |
embeddedartists | 0:b567d56a59d7 | 253 | const char* lodepng_error_text(unsigned code); |
embeddedartists | 0:b567d56a59d7 | 254 | #endif /*LODEPNG_COMPILE_ERROR_TEXT*/ |
embeddedartists | 0:b567d56a59d7 | 255 | |
embeddedartists | 0:b567d56a59d7 | 256 | #ifdef LODEPNG_COMPILE_DECODER |
embeddedartists | 0:b567d56a59d7 | 257 | /*Settings for zlib decompression*/ |
embeddedartists | 0:b567d56a59d7 | 258 | typedef struct LodePNGDecompressSettings LodePNGDecompressSettings; |
embeddedartists | 0:b567d56a59d7 | 259 | struct LodePNGDecompressSettings |
embeddedartists | 0:b567d56a59d7 | 260 | { |
embeddedartists | 0:b567d56a59d7 | 261 | unsigned ignore_adler32; /*if 1, continue and don't give an error message if the Adler32 checksum is corrupted*/ |
embeddedartists | 0:b567d56a59d7 | 262 | |
embeddedartists | 0:b567d56a59d7 | 263 | /*use custom zlib decoder instead of built in one (default: null)*/ |
embeddedartists | 0:b567d56a59d7 | 264 | unsigned (*custom_zlib)(unsigned char**, size_t*, |
embeddedartists | 0:b567d56a59d7 | 265 | const unsigned char*, size_t, |
embeddedartists | 0:b567d56a59d7 | 266 | const LodePNGDecompressSettings*); |
embeddedartists | 0:b567d56a59d7 | 267 | /*use custom deflate decoder instead of built in one (default: null) |
embeddedartists | 0:b567d56a59d7 | 268 | if custom_zlib is used, custom_deflate is ignored since only the built in |
embeddedartists | 0:b567d56a59d7 | 269 | zlib function will call custom_deflate*/ |
embeddedartists | 0:b567d56a59d7 | 270 | unsigned (*custom_inflate)(unsigned char**, size_t*, |
embeddedartists | 0:b567d56a59d7 | 271 | const unsigned char*, size_t, |
embeddedartists | 0:b567d56a59d7 | 272 | const LodePNGDecompressSettings*); |
embeddedartists | 0:b567d56a59d7 | 273 | |
embeddedartists | 0:b567d56a59d7 | 274 | const void* custom_context; /*optional custom settings for custom functions*/ |
embeddedartists | 0:b567d56a59d7 | 275 | }; |
embeddedartists | 0:b567d56a59d7 | 276 | |
embeddedartists | 0:b567d56a59d7 | 277 | extern const LodePNGDecompressSettings lodepng_default_decompress_settings; |
embeddedartists | 0:b567d56a59d7 | 278 | void lodepng_decompress_settings_init(LodePNGDecompressSettings* settings); |
embeddedartists | 0:b567d56a59d7 | 279 | #endif /*LODEPNG_COMPILE_DECODER*/ |
embeddedartists | 0:b567d56a59d7 | 280 | |
embeddedartists | 0:b567d56a59d7 | 281 | #ifdef LODEPNG_COMPILE_ENCODER |
embeddedartists | 0:b567d56a59d7 | 282 | /* |
embeddedartists | 0:b567d56a59d7 | 283 | Settings for zlib compression. Tweaking these settings tweaks the balance |
embeddedartists | 0:b567d56a59d7 | 284 | between speed and compression ratio. |
embeddedartists | 0:b567d56a59d7 | 285 | */ |
embeddedartists | 0:b567d56a59d7 | 286 | typedef struct LodePNGCompressSettings LodePNGCompressSettings; |
embeddedartists | 0:b567d56a59d7 | 287 | struct LodePNGCompressSettings /*deflate = compress*/ |
embeddedartists | 0:b567d56a59d7 | 288 | { |
embeddedartists | 0:b567d56a59d7 | 289 | /*LZ77 related settings*/ |
embeddedartists | 0:b567d56a59d7 | 290 | unsigned btype; /*the block type for LZ (0, 1, 2 or 3, see zlib standard). Should be 2 for proper compression.*/ |
embeddedartists | 0:b567d56a59d7 | 291 | unsigned use_lz77; /*whether or not to use LZ77. Should be 1 for proper compression.*/ |
embeddedartists | 0:b567d56a59d7 | 292 | unsigned windowsize; /*must be a power of two <= 32768. higher compresses more but is slower. Typical value: 2048.*/ |
embeddedartists | 0:b567d56a59d7 | 293 | unsigned minmatch; /*mininum lz77 length. 3 is normally best, 6 can be better for some PNGs. Default: 0*/ |
embeddedartists | 0:b567d56a59d7 | 294 | unsigned nicematch; /*stop searching if >= this length found. Set to 258 for best compression. Default: 128*/ |
embeddedartists | 0:b567d56a59d7 | 295 | unsigned lazymatching; /*use lazy matching: better compression but a bit slower. Default: true*/ |
embeddedartists | 0:b567d56a59d7 | 296 | |
embeddedartists | 0:b567d56a59d7 | 297 | /*use custom zlib encoder instead of built in one (default: null)*/ |
embeddedartists | 0:b567d56a59d7 | 298 | unsigned (*custom_zlib)(unsigned char**, size_t*, |
embeddedartists | 0:b567d56a59d7 | 299 | const unsigned char*, size_t, |
embeddedartists | 0:b567d56a59d7 | 300 | const LodePNGCompressSettings*); |
embeddedartists | 0:b567d56a59d7 | 301 | /*use custom deflate encoder instead of built in one (default: null) |
embeddedartists | 0:b567d56a59d7 | 302 | if custom_zlib is used, custom_deflate is ignored since only the built in |
embeddedartists | 0:b567d56a59d7 | 303 | zlib function will call custom_deflate*/ |
embeddedartists | 0:b567d56a59d7 | 304 | unsigned (*custom_deflate)(unsigned char**, size_t*, |
embeddedartists | 0:b567d56a59d7 | 305 | const unsigned char*, size_t, |
embeddedartists | 0:b567d56a59d7 | 306 | const LodePNGCompressSettings*); |
embeddedartists | 0:b567d56a59d7 | 307 | |
embeddedartists | 0:b567d56a59d7 | 308 | const void* custom_context; /*optional custom settings for custom functions*/ |
embeddedartists | 0:b567d56a59d7 | 309 | }; |
embeddedartists | 0:b567d56a59d7 | 310 | |
embeddedartists | 0:b567d56a59d7 | 311 | extern const LodePNGCompressSettings lodepng_default_compress_settings; |
embeddedartists | 0:b567d56a59d7 | 312 | void lodepng_compress_settings_init(LodePNGCompressSettings* settings); |
embeddedartists | 0:b567d56a59d7 | 313 | #endif /*LODEPNG_COMPILE_ENCODER*/ |
embeddedartists | 0:b567d56a59d7 | 314 | |
embeddedartists | 0:b567d56a59d7 | 315 | #ifdef LODEPNG_COMPILE_PNG |
embeddedartists | 0:b567d56a59d7 | 316 | /* |
embeddedartists | 0:b567d56a59d7 | 317 | Color mode of an image. Contains all information required to decode the pixel |
embeddedartists | 0:b567d56a59d7 | 318 | bits to RGBA colors. This information is the same as used in the PNG file |
embeddedartists | 0:b567d56a59d7 | 319 | format, and is used both for PNG and raw image data in LodePNG. |
embeddedartists | 0:b567d56a59d7 | 320 | */ |
embeddedartists | 0:b567d56a59d7 | 321 | typedef struct LodePNGColorMode |
embeddedartists | 0:b567d56a59d7 | 322 | { |
embeddedartists | 0:b567d56a59d7 | 323 | /*header (IHDR)*/ |
embeddedartists | 0:b567d56a59d7 | 324 | LodePNGColorType colortype; /*color type, see PNG standard or documentation further in this header file*/ |
embeddedartists | 0:b567d56a59d7 | 325 | unsigned bitdepth; /*bits per sample, see PNG standard or documentation further in this header file*/ |
embeddedartists | 0:b567d56a59d7 | 326 | |
embeddedartists | 0:b567d56a59d7 | 327 | /* |
embeddedartists | 0:b567d56a59d7 | 328 | palette (PLTE and tRNS) |
embeddedartists | 0:b567d56a59d7 | 329 | |
embeddedartists | 0:b567d56a59d7 | 330 | Dynamically allocated with the colors of the palette, including alpha. |
embeddedartists | 0:b567d56a59d7 | 331 | When encoding a PNG, to store your colors in the palette of the LodePNGColorMode, first use |
embeddedartists | 0:b567d56a59d7 | 332 | lodepng_palette_clear, then for each color use lodepng_palette_add. |
embeddedartists | 0:b567d56a59d7 | 333 | If you encode an image without alpha with palette, don't forget to put value 255 in each A byte of the palette. |
embeddedartists | 0:b567d56a59d7 | 334 | |
embeddedartists | 0:b567d56a59d7 | 335 | When decoding, by default you can ignore this palette, since LodePNG already |
embeddedartists | 0:b567d56a59d7 | 336 | fills the palette colors in the pixels of the raw RGBA output. |
embeddedartists | 0:b567d56a59d7 | 337 | |
embeddedartists | 0:b567d56a59d7 | 338 | The palette is only supported for color type 3. |
embeddedartists | 0:b567d56a59d7 | 339 | */ |
embeddedartists | 0:b567d56a59d7 | 340 | unsigned char* palette; /*palette in RGBARGBA... order. When allocated, must be either 0, or have size 1024*/ |
embeddedartists | 0:b567d56a59d7 | 341 | size_t palettesize; /*palette size in number of colors (amount of bytes is 4 * palettesize)*/ |
embeddedartists | 0:b567d56a59d7 | 342 | |
embeddedartists | 0:b567d56a59d7 | 343 | /* |
embeddedartists | 0:b567d56a59d7 | 344 | transparent color key (tRNS) |
embeddedartists | 0:b567d56a59d7 | 345 | |
embeddedartists | 0:b567d56a59d7 | 346 | This color uses the same bit depth as the bitdepth value in this struct, which can be 1-bit to 16-bit. |
embeddedartists | 0:b567d56a59d7 | 347 | For greyscale PNGs, r, g and b will all 3 be set to the same. |
embeddedartists | 0:b567d56a59d7 | 348 | |
embeddedartists | 0:b567d56a59d7 | 349 | When decoding, by default you can ignore this information, since LodePNG sets |
embeddedartists | 0:b567d56a59d7 | 350 | pixels with this key to transparent already in the raw RGBA output. |
embeddedartists | 0:b567d56a59d7 | 351 | |
embeddedartists | 0:b567d56a59d7 | 352 | The color key is only supported for color types 0 and 2. |
embeddedartists | 0:b567d56a59d7 | 353 | */ |
embeddedartists | 0:b567d56a59d7 | 354 | unsigned key_defined; /*is a transparent color key given? 0 = false, 1 = true*/ |
embeddedartists | 0:b567d56a59d7 | 355 | unsigned key_r; /*red/greyscale component of color key*/ |
embeddedartists | 0:b567d56a59d7 | 356 | unsigned key_g; /*green component of color key*/ |
embeddedartists | 0:b567d56a59d7 | 357 | unsigned key_b; /*blue component of color key*/ |
embeddedartists | 0:b567d56a59d7 | 358 | } LodePNGColorMode; |
embeddedartists | 0:b567d56a59d7 | 359 | |
embeddedartists | 0:b567d56a59d7 | 360 | /*init, cleanup and copy functions to use with this struct*/ |
embeddedartists | 0:b567d56a59d7 | 361 | void lodepng_color_mode_init(LodePNGColorMode* info); |
embeddedartists | 0:b567d56a59d7 | 362 | void lodepng_color_mode_cleanup(LodePNGColorMode* info); |
embeddedartists | 0:b567d56a59d7 | 363 | /*return value is error code (0 means no error)*/ |
embeddedartists | 0:b567d56a59d7 | 364 | unsigned lodepng_color_mode_copy(LodePNGColorMode* dest, const LodePNGColorMode* source); |
embeddedartists | 0:b567d56a59d7 | 365 | |
embeddedartists | 0:b567d56a59d7 | 366 | void lodepng_palette_clear(LodePNGColorMode* info); |
embeddedartists | 0:b567d56a59d7 | 367 | /*add 1 color to the palette*/ |
embeddedartists | 0:b567d56a59d7 | 368 | unsigned lodepng_palette_add(LodePNGColorMode* info, |
embeddedartists | 0:b567d56a59d7 | 369 | unsigned char r, unsigned char g, unsigned char b, unsigned char a); |
embeddedartists | 0:b567d56a59d7 | 370 | |
embeddedartists | 0:b567d56a59d7 | 371 | /*get the total amount of bits per pixel, based on colortype and bitdepth in the struct*/ |
embeddedartists | 0:b567d56a59d7 | 372 | unsigned lodepng_get_bpp(const LodePNGColorMode* info); |
embeddedartists | 0:b567d56a59d7 | 373 | /*get the amount of color channels used, based on colortype in the struct. |
embeddedartists | 0:b567d56a59d7 | 374 | If a palette is used, it counts as 1 channel.*/ |
embeddedartists | 0:b567d56a59d7 | 375 | unsigned lodepng_get_channels(const LodePNGColorMode* info); |
embeddedartists | 0:b567d56a59d7 | 376 | /*is it a greyscale type? (only colortype 0 or 4)*/ |
embeddedartists | 0:b567d56a59d7 | 377 | unsigned lodepng_is_greyscale_type(const LodePNGColorMode* info); |
embeddedartists | 0:b567d56a59d7 | 378 | /*has it got an alpha channel? (only colortype 2 or 6)*/ |
embeddedartists | 0:b567d56a59d7 | 379 | unsigned lodepng_is_alpha_type(const LodePNGColorMode* info); |
embeddedartists | 0:b567d56a59d7 | 380 | /*has it got a palette? (only colortype 3)*/ |
embeddedartists | 0:b567d56a59d7 | 381 | unsigned lodepng_is_palette_type(const LodePNGColorMode* info); |
embeddedartists | 0:b567d56a59d7 | 382 | /*only returns true if there is a palette and there is a value in the palette with alpha < 255. |
embeddedartists | 0:b567d56a59d7 | 383 | Loops through the palette to check this.*/ |
embeddedartists | 0:b567d56a59d7 | 384 | unsigned lodepng_has_palette_alpha(const LodePNGColorMode* info); |
embeddedartists | 0:b567d56a59d7 | 385 | /* |
embeddedartists | 0:b567d56a59d7 | 386 | Check if the given color info indicates the possibility of having non-opaque pixels in the PNG image. |
embeddedartists | 0:b567d56a59d7 | 387 | Returns true if the image can have translucent or invisible pixels (it still be opaque if it doesn't use such pixels). |
embeddedartists | 0:b567d56a59d7 | 388 | Returns false if the image can only have opaque pixels. |
embeddedartists | 0:b567d56a59d7 | 389 | In detail, it returns true only if it's a color type with alpha, or has a palette with non-opaque values, |
embeddedartists | 0:b567d56a59d7 | 390 | or if "key_defined" is true. |
embeddedartists | 0:b567d56a59d7 | 391 | */ |
embeddedartists | 0:b567d56a59d7 | 392 | unsigned lodepng_can_have_alpha(const LodePNGColorMode* info); |
embeddedartists | 0:b567d56a59d7 | 393 | /*Returns the byte size of a raw image buffer with given width, height and color mode*/ |
embeddedartists | 0:b567d56a59d7 | 394 | size_t lodepng_get_raw_size(unsigned w, unsigned h, const LodePNGColorMode* color); |
embeddedartists | 0:b567d56a59d7 | 395 | |
embeddedartists | 0:b567d56a59d7 | 396 | #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS |
embeddedartists | 0:b567d56a59d7 | 397 | /*The information of a Time chunk in PNG.*/ |
embeddedartists | 0:b567d56a59d7 | 398 | typedef struct LodePNGTime |
embeddedartists | 0:b567d56a59d7 | 399 | { |
embeddedartists | 0:b567d56a59d7 | 400 | unsigned year; /*2 bytes used (0-65535)*/ |
embeddedartists | 0:b567d56a59d7 | 401 | unsigned month; /*1-12*/ |
embeddedartists | 0:b567d56a59d7 | 402 | unsigned day; /*1-31*/ |
embeddedartists | 0:b567d56a59d7 | 403 | unsigned hour; /*0-23*/ |
embeddedartists | 0:b567d56a59d7 | 404 | unsigned minute; /*0-59*/ |
embeddedartists | 0:b567d56a59d7 | 405 | unsigned second; /*0-60 (to allow for leap seconds)*/ |
embeddedartists | 0:b567d56a59d7 | 406 | } LodePNGTime; |
embeddedartists | 0:b567d56a59d7 | 407 | #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ |
embeddedartists | 0:b567d56a59d7 | 408 | |
embeddedartists | 0:b567d56a59d7 | 409 | /*Information about the PNG image, except pixels, width and height.*/ |
embeddedartists | 0:b567d56a59d7 | 410 | typedef struct LodePNGInfo |
embeddedartists | 0:b567d56a59d7 | 411 | { |
embeddedartists | 0:b567d56a59d7 | 412 | /*header (IHDR), palette (PLTE) and transparency (tRNS) chunks*/ |
embeddedartists | 0:b567d56a59d7 | 413 | unsigned compression_method;/*compression method of the original file. Always 0.*/ |
embeddedartists | 0:b567d56a59d7 | 414 | unsigned filter_method; /*filter method of the original file*/ |
embeddedartists | 0:b567d56a59d7 | 415 | unsigned interlace_method; /*interlace method of the original file*/ |
embeddedartists | 0:b567d56a59d7 | 416 | LodePNGColorMode color; /*color type and bits, palette and transparency of the PNG file*/ |
embeddedartists | 0:b567d56a59d7 | 417 | |
embeddedartists | 0:b567d56a59d7 | 418 | #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS |
embeddedartists | 0:b567d56a59d7 | 419 | /* |
embeddedartists | 0:b567d56a59d7 | 420 | suggested background color chunk (bKGD) |
embeddedartists | 0:b567d56a59d7 | 421 | This color uses the same color mode as the PNG (except alpha channel), which can be 1-bit to 16-bit. |
embeddedartists | 0:b567d56a59d7 | 422 | |
embeddedartists | 0:b567d56a59d7 | 423 | For greyscale PNGs, r, g and b will all 3 be set to the same. When encoding |
embeddedartists | 0:b567d56a59d7 | 424 | the encoder writes the red one. For palette PNGs: When decoding, the RGB value |
embeddedartists | 0:b567d56a59d7 | 425 | will be stored, not a palette index. But when encoding, specify the index of |
embeddedartists | 0:b567d56a59d7 | 426 | the palette in background_r, the other two are then ignored. |
embeddedartists | 0:b567d56a59d7 | 427 | |
embeddedartists | 0:b567d56a59d7 | 428 | The decoder does not use this background color to edit the color of pixels. |
embeddedartists | 0:b567d56a59d7 | 429 | */ |
embeddedartists | 0:b567d56a59d7 | 430 | unsigned background_defined; /*is a suggested background color given?*/ |
embeddedartists | 0:b567d56a59d7 | 431 | unsigned background_r; /*red component of suggested background color*/ |
embeddedartists | 0:b567d56a59d7 | 432 | unsigned background_g; /*green component of suggested background color*/ |
embeddedartists | 0:b567d56a59d7 | 433 | unsigned background_b; /*blue component of suggested background color*/ |
embeddedartists | 0:b567d56a59d7 | 434 | |
embeddedartists | 0:b567d56a59d7 | 435 | /* |
embeddedartists | 0:b567d56a59d7 | 436 | non-international text chunks (tEXt and zTXt) |
embeddedartists | 0:b567d56a59d7 | 437 | |
embeddedartists | 0:b567d56a59d7 | 438 | The char** arrays each contain num strings. The actual messages are in |
embeddedartists | 0:b567d56a59d7 | 439 | text_strings, while text_keys are keywords that give a short description what |
embeddedartists | 0:b567d56a59d7 | 440 | the actual text represents, e.g. Title, Author, Description, or anything else. |
embeddedartists | 0:b567d56a59d7 | 441 | |
embeddedartists | 0:b567d56a59d7 | 442 | A keyword is minimum 1 character and maximum 79 characters long. It's |
embeddedartists | 0:b567d56a59d7 | 443 | discouraged to use a single line length longer than 79 characters for texts. |
embeddedartists | 0:b567d56a59d7 | 444 | |
embeddedartists | 0:b567d56a59d7 | 445 | Don't allocate these text buffers yourself. Use the init/cleanup functions |
embeddedartists | 0:b567d56a59d7 | 446 | correctly and use lodepng_add_text and lodepng_clear_text. |
embeddedartists | 0:b567d56a59d7 | 447 | */ |
embeddedartists | 0:b567d56a59d7 | 448 | size_t text_num; /*the amount of texts in these char** buffers (there may be more texts in itext)*/ |
embeddedartists | 0:b567d56a59d7 | 449 | char** text_keys; /*the keyword of a text chunk (e.g. "Comment")*/ |
embeddedartists | 0:b567d56a59d7 | 450 | char** text_strings; /*the actual text*/ |
embeddedartists | 0:b567d56a59d7 | 451 | |
embeddedartists | 0:b567d56a59d7 | 452 | /* |
embeddedartists | 0:b567d56a59d7 | 453 | international text chunks (iTXt) |
embeddedartists | 0:b567d56a59d7 | 454 | Similar to the non-international text chunks, but with additional strings |
embeddedartists | 0:b567d56a59d7 | 455 | "langtags" and "transkeys". |
embeddedartists | 0:b567d56a59d7 | 456 | */ |
embeddedartists | 0:b567d56a59d7 | 457 | size_t itext_num; /*the amount of international texts in this PNG*/ |
embeddedartists | 0:b567d56a59d7 | 458 | char** itext_keys; /*the English keyword of the text chunk (e.g. "Comment")*/ |
embeddedartists | 0:b567d56a59d7 | 459 | char** itext_langtags; /*language tag for this text's language, ISO/IEC 646 string, e.g. ISO 639 language tag*/ |
embeddedartists | 0:b567d56a59d7 | 460 | char** itext_transkeys; /*keyword translated to the international language - UTF-8 string*/ |
embeddedartists | 0:b567d56a59d7 | 461 | char** itext_strings; /*the actual international text - UTF-8 string*/ |
embeddedartists | 0:b567d56a59d7 | 462 | |
embeddedartists | 0:b567d56a59d7 | 463 | /*time chunk (tIME)*/ |
embeddedartists | 0:b567d56a59d7 | 464 | unsigned time_defined; /*set to 1 to make the encoder generate a tIME chunk*/ |
embeddedartists | 0:b567d56a59d7 | 465 | LodePNGTime time; |
embeddedartists | 0:b567d56a59d7 | 466 | |
embeddedartists | 0:b567d56a59d7 | 467 | /*phys chunk (pHYs)*/ |
embeddedartists | 0:b567d56a59d7 | 468 | unsigned phys_defined; /*if 0, there is no pHYs chunk and the values below are undefined, if 1 else there is one*/ |
embeddedartists | 0:b567d56a59d7 | 469 | unsigned phys_x; /*pixels per unit in x direction*/ |
embeddedartists | 0:b567d56a59d7 | 470 | unsigned phys_y; /*pixels per unit in y direction*/ |
embeddedartists | 0:b567d56a59d7 | 471 | unsigned phys_unit; /*may be 0 (unknown unit) or 1 (metre)*/ |
embeddedartists | 0:b567d56a59d7 | 472 | |
embeddedartists | 0:b567d56a59d7 | 473 | /* |
embeddedartists | 0:b567d56a59d7 | 474 | unknown chunks |
embeddedartists | 0:b567d56a59d7 | 475 | There are 3 buffers, one for each position in the PNG where unknown chunks can appear |
embeddedartists | 0:b567d56a59d7 | 476 | each buffer contains all unknown chunks for that position consecutively |
embeddedartists | 0:b567d56a59d7 | 477 | The 3 buffers are the unknown chunks between certain critical chunks: |
embeddedartists | 0:b567d56a59d7 | 478 | 0: IHDR-PLTE, 1: PLTE-IDAT, 2: IDAT-IEND |
embeddedartists | 0:b567d56a59d7 | 479 | Do not allocate or traverse this data yourself. Use the chunk traversing functions declared |
embeddedartists | 0:b567d56a59d7 | 480 | later, such as lodepng_chunk_next and lodepng_chunk_append, to read/write this struct. |
embeddedartists | 0:b567d56a59d7 | 481 | */ |
embeddedartists | 0:b567d56a59d7 | 482 | unsigned char* unknown_chunks_data[3]; |
embeddedartists | 0:b567d56a59d7 | 483 | size_t unknown_chunks_size[3]; /*size in bytes of the unknown chunks, given for protection*/ |
embeddedartists | 0:b567d56a59d7 | 484 | #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ |
embeddedartists | 0:b567d56a59d7 | 485 | } LodePNGInfo; |
embeddedartists | 0:b567d56a59d7 | 486 | |
embeddedartists | 0:b567d56a59d7 | 487 | /*init, cleanup and copy functions to use with this struct*/ |
embeddedartists | 0:b567d56a59d7 | 488 | void lodepng_info_init(LodePNGInfo* info); |
embeddedartists | 0:b567d56a59d7 | 489 | void lodepng_info_cleanup(LodePNGInfo* info); |
embeddedartists | 0:b567d56a59d7 | 490 | /*return value is error code (0 means no error)*/ |
embeddedartists | 0:b567d56a59d7 | 491 | unsigned lodepng_info_copy(LodePNGInfo* dest, const LodePNGInfo* source); |
embeddedartists | 0:b567d56a59d7 | 492 | |
embeddedartists | 0:b567d56a59d7 | 493 | #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS |
embeddedartists | 0:b567d56a59d7 | 494 | void lodepng_clear_text(LodePNGInfo* info); /*use this to clear the texts again after you filled them in*/ |
embeddedartists | 0:b567d56a59d7 | 495 | unsigned lodepng_add_text(LodePNGInfo* info, const char* key, const char* str); /*push back both texts at once*/ |
embeddedartists | 0:b567d56a59d7 | 496 | |
embeddedartists | 0:b567d56a59d7 | 497 | void lodepng_clear_itext(LodePNGInfo* info); /*use this to clear the itexts again after you filled them in*/ |
embeddedartists | 0:b567d56a59d7 | 498 | unsigned lodepng_add_itext(LodePNGInfo* info, const char* key, const char* langtag, |
embeddedartists | 0:b567d56a59d7 | 499 | const char* transkey, const char* str); /*push back the 4 texts of 1 chunk at once*/ |
embeddedartists | 0:b567d56a59d7 | 500 | #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ |
embeddedartists | 0:b567d56a59d7 | 501 | |
embeddedartists | 0:b567d56a59d7 | 502 | /* |
embeddedartists | 0:b567d56a59d7 | 503 | Converts raw buffer from one color type to another color type, based on |
embeddedartists | 0:b567d56a59d7 | 504 | LodePNGColorMode structs to describe the input and output color type. |
embeddedartists | 0:b567d56a59d7 | 505 | See the reference manual at the end of this header file to see which color conversions are supported. |
embeddedartists | 0:b567d56a59d7 | 506 | return value = LodePNG error code (0 if all went ok, an error if the conversion isn't supported) |
embeddedartists | 0:b567d56a59d7 | 507 | The out buffer must have size (w * h * bpp + 7) / 8, where bpp is the bits per pixel |
embeddedartists | 0:b567d56a59d7 | 508 | of the output color type (lodepng_get_bpp) |
embeddedartists | 0:b567d56a59d7 | 509 | The fix_png value works as described in struct LodePNGDecoderSettings. |
embeddedartists | 0:b567d56a59d7 | 510 | Note: for 16-bit per channel colors, uses big endian format like PNG does. |
embeddedartists | 0:b567d56a59d7 | 511 | */ |
embeddedartists | 0:b567d56a59d7 | 512 | unsigned lodepng_convert(unsigned char* out, const unsigned char* in, |
embeddedartists | 0:b567d56a59d7 | 513 | LodePNGColorMode* mode_out, const LodePNGColorMode* mode_in, |
embeddedartists | 0:b567d56a59d7 | 514 | unsigned w, unsigned h, unsigned fix_png); |
embeddedartists | 0:b567d56a59d7 | 515 | |
embeddedartists | 0:b567d56a59d7 | 516 | #ifdef LODEPNG_COMPILE_DECODER |
embeddedartists | 0:b567d56a59d7 | 517 | /* |
embeddedartists | 0:b567d56a59d7 | 518 | Settings for the decoder. This contains settings for the PNG and the Zlib |
embeddedartists | 0:b567d56a59d7 | 519 | decoder, but not the Info settings from the Info structs. |
embeddedartists | 0:b567d56a59d7 | 520 | */ |
embeddedartists | 0:b567d56a59d7 | 521 | typedef struct LodePNGDecoderSettings |
embeddedartists | 0:b567d56a59d7 | 522 | { |
embeddedartists | 0:b567d56a59d7 | 523 | LodePNGDecompressSettings zlibsettings; /*in here is the setting to ignore Adler32 checksums*/ |
embeddedartists | 0:b567d56a59d7 | 524 | |
embeddedartists | 0:b567d56a59d7 | 525 | unsigned ignore_crc; /*ignore CRC checksums*/ |
embeddedartists | 0:b567d56a59d7 | 526 | /* |
embeddedartists | 0:b567d56a59d7 | 527 | The fix_png setting, if 1, makes the decoder tolerant towards some PNG images |
embeddedartists | 0:b567d56a59d7 | 528 | that do not correctly follow the PNG specification. This only supports errors |
embeddedartists | 0:b567d56a59d7 | 529 | that are fixable, were found in images that are actually used on the web, and |
embeddedartists | 0:b567d56a59d7 | 530 | are silently tolerated by other decoders as well. Currently only one such fix |
embeddedartists | 0:b567d56a59d7 | 531 | is implemented: if a palette index is out of bounds given the palette size, |
embeddedartists | 0:b567d56a59d7 | 532 | interpret it as opaque black. |
embeddedartists | 0:b567d56a59d7 | 533 | By default this value is 0, which makes it stop with an error on such images. |
embeddedartists | 0:b567d56a59d7 | 534 | */ |
embeddedartists | 0:b567d56a59d7 | 535 | unsigned fix_png; |
embeddedartists | 0:b567d56a59d7 | 536 | unsigned color_convert; /*whether to convert the PNG to the color type you want. Default: yes*/ |
embeddedartists | 0:b567d56a59d7 | 537 | |
embeddedartists | 0:b567d56a59d7 | 538 | #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS |
embeddedartists | 0:b567d56a59d7 | 539 | unsigned read_text_chunks; /*if false but remember_unknown_chunks is true, they're stored in the unknown chunks*/ |
embeddedartists | 0:b567d56a59d7 | 540 | /*store all bytes from unknown chunks in the LodePNGInfo (off by default, useful for a png editor)*/ |
embeddedartists | 0:b567d56a59d7 | 541 | unsigned remember_unknown_chunks; |
embeddedartists | 0:b567d56a59d7 | 542 | #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ |
embeddedartists | 0:b567d56a59d7 | 543 | } LodePNGDecoderSettings; |
embeddedartists | 0:b567d56a59d7 | 544 | |
embeddedartists | 0:b567d56a59d7 | 545 | void lodepng_decoder_settings_init(LodePNGDecoderSettings* settings); |
embeddedartists | 0:b567d56a59d7 | 546 | #endif /*LODEPNG_COMPILE_DECODER*/ |
embeddedartists | 0:b567d56a59d7 | 547 | |
embeddedartists | 0:b567d56a59d7 | 548 | #ifdef LODEPNG_COMPILE_ENCODER |
embeddedartists | 0:b567d56a59d7 | 549 | /*automatically use color type with less bits per pixel if losslessly possible. Default: AUTO*/ |
embeddedartists | 0:b567d56a59d7 | 550 | typedef enum LodePNGFilterStrategy |
embeddedartists | 0:b567d56a59d7 | 551 | { |
embeddedartists | 0:b567d56a59d7 | 552 | /*every filter at zero*/ |
embeddedartists | 0:b567d56a59d7 | 553 | LFS_ZERO, |
embeddedartists | 0:b567d56a59d7 | 554 | /*Use filter that gives minumum sum, as described in the official PNG filter heuristic.*/ |
embeddedartists | 0:b567d56a59d7 | 555 | LFS_MINSUM, |
embeddedartists | 0:b567d56a59d7 | 556 | /*Use the filter type that gives smallest Shannon entropy for this scanline. Depending |
embeddedartists | 0:b567d56a59d7 | 557 | on the image, this is better or worse than minsum.*/ |
embeddedartists | 0:b567d56a59d7 | 558 | LFS_ENTROPY, |
embeddedartists | 0:b567d56a59d7 | 559 | /* |
embeddedartists | 0:b567d56a59d7 | 560 | Brute-force-search PNG filters by compressing each filter for each scanline. |
embeddedartists | 0:b567d56a59d7 | 561 | Experimental, very slow, and only rarely gives better compression than MINSUM. |
embeddedartists | 0:b567d56a59d7 | 562 | */ |
embeddedartists | 0:b567d56a59d7 | 563 | LFS_BRUTE_FORCE, |
embeddedartists | 0:b567d56a59d7 | 564 | /*use predefined_filters buffer: you specify the filter type for each scanline*/ |
embeddedartists | 0:b567d56a59d7 | 565 | LFS_PREDEFINED |
embeddedartists | 0:b567d56a59d7 | 566 | } LodePNGFilterStrategy; |
embeddedartists | 0:b567d56a59d7 | 567 | |
embeddedartists | 0:b567d56a59d7 | 568 | /*automatically use color type with less bits per pixel if losslessly possible. Default: LAC_AUTO*/ |
embeddedartists | 0:b567d56a59d7 | 569 | typedef enum LodePNGAutoConvert |
embeddedartists | 0:b567d56a59d7 | 570 | { |
embeddedartists | 0:b567d56a59d7 | 571 | LAC_NO, /*use color type user requested*/ |
embeddedartists | 0:b567d56a59d7 | 572 | LAC_ALPHA, /*use color type user requested, but if only opaque pixels and RGBA or grey+alpha, use RGB or grey*/ |
embeddedartists | 0:b567d56a59d7 | 573 | LAC_AUTO, /*use PNG color type that can losslessly represent the uncompressed image the smallest possible*/ |
embeddedartists | 0:b567d56a59d7 | 574 | /* |
embeddedartists | 0:b567d56a59d7 | 575 | like AUTO, but do not choose 1, 2 or 4 bit per pixel types. |
embeddedartists | 0:b567d56a59d7 | 576 | sometimes a PNG image compresses worse if less than 8 bits per pixels. |
embeddedartists | 0:b567d56a59d7 | 577 | */ |
embeddedartists | 0:b567d56a59d7 | 578 | LAC_AUTO_NO_NIBBLES, |
embeddedartists | 0:b567d56a59d7 | 579 | /* |
embeddedartists | 0:b567d56a59d7 | 580 | like AUTO, but never choose palette color type. For small images, encoding |
embeddedartists | 0:b567d56a59d7 | 581 | the palette may take more bytes than what is gained. Note that AUTO also |
embeddedartists | 0:b567d56a59d7 | 582 | already prevents encoding the palette for extremely small images, but that may |
embeddedartists | 0:b567d56a59d7 | 583 | not be sufficient because due to the compression it cannot predict when to |
embeddedartists | 0:b567d56a59d7 | 584 | switch. |
embeddedartists | 0:b567d56a59d7 | 585 | */ |
embeddedartists | 0:b567d56a59d7 | 586 | LAC_AUTO_NO_PALETTE, |
embeddedartists | 0:b567d56a59d7 | 587 | LAC_AUTO_NO_NIBBLES_NO_PALETTE |
embeddedartists | 0:b567d56a59d7 | 588 | } LodePNGAutoConvert; |
embeddedartists | 0:b567d56a59d7 | 589 | |
embeddedartists | 0:b567d56a59d7 | 590 | |
embeddedartists | 0:b567d56a59d7 | 591 | /* |
embeddedartists | 0:b567d56a59d7 | 592 | Automatically chooses color type that gives smallest amount of bits in the |
embeddedartists | 0:b567d56a59d7 | 593 | output image, e.g. grey if there are only greyscale pixels, palette if there |
embeddedartists | 0:b567d56a59d7 | 594 | are less than 256 colors, ... |
embeddedartists | 0:b567d56a59d7 | 595 | The auto_convert parameter allows limiting it to not use palette, ... |
embeddedartists | 0:b567d56a59d7 | 596 | */ |
embeddedartists | 0:b567d56a59d7 | 597 | unsigned lodepng_auto_choose_color(LodePNGColorMode* mode_out, |
embeddedartists | 0:b567d56a59d7 | 598 | const unsigned char* image, unsigned w, unsigned h, |
embeddedartists | 0:b567d56a59d7 | 599 | const LodePNGColorMode* mode_in, |
embeddedartists | 0:b567d56a59d7 | 600 | LodePNGAutoConvert auto_convert); |
embeddedartists | 0:b567d56a59d7 | 601 | |
embeddedartists | 0:b567d56a59d7 | 602 | /*Settings for the encoder.*/ |
embeddedartists | 0:b567d56a59d7 | 603 | typedef struct LodePNGEncoderSettings |
embeddedartists | 0:b567d56a59d7 | 604 | { |
embeddedartists | 0:b567d56a59d7 | 605 | LodePNGCompressSettings zlibsettings; /*settings for the zlib encoder, such as window size, ...*/ |
embeddedartists | 0:b567d56a59d7 | 606 | |
embeddedartists | 0:b567d56a59d7 | 607 | LodePNGAutoConvert auto_convert; /*how to automatically choose output PNG color type, if at all*/ |
embeddedartists | 0:b567d56a59d7 | 608 | |
embeddedartists | 0:b567d56a59d7 | 609 | /*If true, follows the official PNG heuristic: if the PNG uses a palette or lower than |
embeddedartists | 0:b567d56a59d7 | 610 | 8 bit depth, set all filters to zero. Otherwise use the filter_strategy. Note that to |
embeddedartists | 0:b567d56a59d7 | 611 | completely follow the official PNG heuristic, filter_palette_zero must be true and |
embeddedartists | 0:b567d56a59d7 | 612 | filter_strategy must be LFS_MINSUM*/ |
embeddedartists | 0:b567d56a59d7 | 613 | unsigned filter_palette_zero; |
embeddedartists | 0:b567d56a59d7 | 614 | /*Which filter strategy to use when not using zeroes due to filter_palette_zero. |
embeddedartists | 0:b567d56a59d7 | 615 | Set filter_palette_zero to 0 to ensure always using your chosen strategy. Default: LFS_MINSUM*/ |
embeddedartists | 0:b567d56a59d7 | 616 | LodePNGFilterStrategy filter_strategy; |
embeddedartists | 0:b567d56a59d7 | 617 | /*used if filter_strategy is LFS_PREDEFINED. In that case, this must point to a buffer with |
embeddedartists | 0:b567d56a59d7 | 618 | the same length as the amount of scanlines in the image, and each value must <= 5. You |
embeddedartists | 0:b567d56a59d7 | 619 | have to cleanup this buffer, LodePNG will never free it. Don't forget that filter_palette_zero |
embeddedartists | 0:b567d56a59d7 | 620 | must be set to 0 to ensure this is also used on palette or low bitdepth images.*/ |
embeddedartists | 0:b567d56a59d7 | 621 | const unsigned char* predefined_filters; |
embeddedartists | 0:b567d56a59d7 | 622 | |
embeddedartists | 0:b567d56a59d7 | 623 | /*force creating a PLTE chunk if colortype is 2 or 6 (= a suggested palette). |
embeddedartists | 0:b567d56a59d7 | 624 | If colortype is 3, PLTE is _always_ created.*/ |
embeddedartists | 0:b567d56a59d7 | 625 | unsigned force_palette; |
embeddedartists | 0:b567d56a59d7 | 626 | #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS |
embeddedartists | 0:b567d56a59d7 | 627 | /*add LodePNG identifier and version as a text chunk, for debugging*/ |
embeddedartists | 0:b567d56a59d7 | 628 | unsigned add_id; |
embeddedartists | 0:b567d56a59d7 | 629 | /*encode text chunks as zTXt chunks instead of tEXt chunks, and use compression in iTXt chunks*/ |
embeddedartists | 0:b567d56a59d7 | 630 | unsigned text_compression; |
embeddedartists | 0:b567d56a59d7 | 631 | #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ |
embeddedartists | 0:b567d56a59d7 | 632 | } LodePNGEncoderSettings; |
embeddedartists | 0:b567d56a59d7 | 633 | |
embeddedartists | 0:b567d56a59d7 | 634 | void lodepng_encoder_settings_init(LodePNGEncoderSettings* settings); |
embeddedartists | 0:b567d56a59d7 | 635 | #endif /*LODEPNG_COMPILE_ENCODER*/ |
embeddedartists | 0:b567d56a59d7 | 636 | |
embeddedartists | 0:b567d56a59d7 | 637 | |
embeddedartists | 0:b567d56a59d7 | 638 | #if defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ENCODER) |
embeddedartists | 0:b567d56a59d7 | 639 | /*The settings, state and information for extended encoding and decoding.*/ |
embeddedartists | 0:b567d56a59d7 | 640 | typedef struct LodePNGState |
embeddedartists | 0:b567d56a59d7 | 641 | { |
embeddedartists | 0:b567d56a59d7 | 642 | #ifdef LODEPNG_COMPILE_DECODER |
embeddedartists | 0:b567d56a59d7 | 643 | LodePNGDecoderSettings decoder; /*the decoding settings*/ |
embeddedartists | 0:b567d56a59d7 | 644 | #endif /*LODEPNG_COMPILE_DECODER*/ |
embeddedartists | 0:b567d56a59d7 | 645 | #ifdef LODEPNG_COMPILE_ENCODER |
embeddedartists | 0:b567d56a59d7 | 646 | LodePNGEncoderSettings encoder; /*the encoding settings*/ |
embeddedartists | 0:b567d56a59d7 | 647 | #endif /*LODEPNG_COMPILE_ENCODER*/ |
embeddedartists | 0:b567d56a59d7 | 648 | LodePNGColorMode info_raw; /*specifies the format in which you would like to get the raw pixel buffer*/ |
embeddedartists | 0:b567d56a59d7 | 649 | LodePNGInfo info_png; /*info of the PNG image obtained after decoding*/ |
embeddedartists | 0:b567d56a59d7 | 650 | unsigned error; |
embeddedartists | 0:b567d56a59d7 | 651 | #ifdef LODEPNG_COMPILE_CPP |
embeddedartists | 0:b567d56a59d7 | 652 | //For the lodepng::State subclass. |
embeddedartists | 0:b567d56a59d7 | 653 | virtual ~LodePNGState(){} |
embeddedartists | 0:b567d56a59d7 | 654 | #endif |
embeddedartists | 0:b567d56a59d7 | 655 | } LodePNGState; |
embeddedartists | 0:b567d56a59d7 | 656 | |
embeddedartists | 0:b567d56a59d7 | 657 | /*init, cleanup and copy functions to use with this struct*/ |
embeddedartists | 0:b567d56a59d7 | 658 | void lodepng_state_init(LodePNGState* state); |
embeddedartists | 0:b567d56a59d7 | 659 | void lodepng_state_cleanup(LodePNGState* state); |
embeddedartists | 0:b567d56a59d7 | 660 | void lodepng_state_copy(LodePNGState* dest, const LodePNGState* source); |
embeddedartists | 0:b567d56a59d7 | 661 | #endif /* defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ENCODER) */ |
embeddedartists | 0:b567d56a59d7 | 662 | |
embeddedartists | 0:b567d56a59d7 | 663 | #ifdef LODEPNG_COMPILE_DECODER |
embeddedartists | 0:b567d56a59d7 | 664 | /* |
embeddedartists | 0:b567d56a59d7 | 665 | Same as lodepng_decode_memory, but uses a LodePNGState to allow custom settings and |
embeddedartists | 0:b567d56a59d7 | 666 | getting much more information about the PNG image and color mode. |
embeddedartists | 0:b567d56a59d7 | 667 | */ |
embeddedartists | 0:b567d56a59d7 | 668 | unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h, |
embeddedartists | 0:b567d56a59d7 | 669 | LodePNGState* state, |
embeddedartists | 0:b567d56a59d7 | 670 | const unsigned char* in, size_t insize); |
embeddedartists | 0:b567d56a59d7 | 671 | |
embeddedartists | 0:b567d56a59d7 | 672 | /* |
embeddedartists | 0:b567d56a59d7 | 673 | Read the PNG header, but not the actual data. This returns only the information |
embeddedartists | 0:b567d56a59d7 | 674 | that is in the header chunk of the PNG, such as width, height and color type. The |
embeddedartists | 0:b567d56a59d7 | 675 | information is placed in the info_png field of the LodePNGState. |
embeddedartists | 0:b567d56a59d7 | 676 | */ |
embeddedartists | 0:b567d56a59d7 | 677 | unsigned lodepng_inspect(unsigned* w, unsigned* h, |
embeddedartists | 0:b567d56a59d7 | 678 | LodePNGState* state, |
embeddedartists | 0:b567d56a59d7 | 679 | const unsigned char* in, size_t insize); |
embeddedartists | 0:b567d56a59d7 | 680 | #endif /*LODEPNG_COMPILE_DECODER*/ |
embeddedartists | 0:b567d56a59d7 | 681 | |
embeddedartists | 0:b567d56a59d7 | 682 | |
embeddedartists | 0:b567d56a59d7 | 683 | #ifdef LODEPNG_COMPILE_ENCODER |
embeddedartists | 0:b567d56a59d7 | 684 | /*This function allocates the out buffer with standard malloc and stores the size in *outsize.*/ |
embeddedartists | 0:b567d56a59d7 | 685 | unsigned lodepng_encode(unsigned char** out, size_t* outsize, |
embeddedartists | 0:b567d56a59d7 | 686 | const unsigned char* image, unsigned w, unsigned h, |
embeddedartists | 0:b567d56a59d7 | 687 | LodePNGState* state); |
embeddedartists | 0:b567d56a59d7 | 688 | #endif /*LODEPNG_COMPILE_ENCODER*/ |
embeddedartists | 0:b567d56a59d7 | 689 | |
embeddedartists | 0:b567d56a59d7 | 690 | /* |
embeddedartists | 0:b567d56a59d7 | 691 | The lodepng_chunk functions are normally not needed, except to traverse the |
embeddedartists | 0:b567d56a59d7 | 692 | unknown chunks stored in the LodePNGInfo struct, or add new ones to it. |
embeddedartists | 0:b567d56a59d7 | 693 | It also allows traversing the chunks of an encoded PNG file yourself. |
embeddedartists | 0:b567d56a59d7 | 694 | |
embeddedartists | 0:b567d56a59d7 | 695 | PNG standard chunk naming conventions: |
embeddedartists | 0:b567d56a59d7 | 696 | First byte: uppercase = critical, lowercase = ancillary |
embeddedartists | 0:b567d56a59d7 | 697 | Second byte: uppercase = public, lowercase = private |
embeddedartists | 0:b567d56a59d7 | 698 | Third byte: must be uppercase |
embeddedartists | 0:b567d56a59d7 | 699 | Fourth byte: uppercase = unsafe to copy, lowercase = safe to copy |
embeddedartists | 0:b567d56a59d7 | 700 | */ |
embeddedartists | 0:b567d56a59d7 | 701 | |
embeddedartists | 0:b567d56a59d7 | 702 | /*get the length of the data of the chunk. Total chunk length has 12 bytes more.*/ |
embeddedartists | 0:b567d56a59d7 | 703 | unsigned lodepng_chunk_length(const unsigned char* chunk); |
embeddedartists | 0:b567d56a59d7 | 704 | |
embeddedartists | 0:b567d56a59d7 | 705 | /*puts the 4-byte type in null terminated string*/ |
embeddedartists | 0:b567d56a59d7 | 706 | void lodepng_chunk_type(char type[5], const unsigned char* chunk); |
embeddedartists | 0:b567d56a59d7 | 707 | |
embeddedartists | 0:b567d56a59d7 | 708 | /*check if the type is the given type*/ |
embeddedartists | 0:b567d56a59d7 | 709 | unsigned char lodepng_chunk_type_equals(const unsigned char* chunk, const char* type); |
embeddedartists | 0:b567d56a59d7 | 710 | |
embeddedartists | 0:b567d56a59d7 | 711 | /*0: it's one of the critical chunk types, 1: it's an ancillary chunk (see PNG standard)*/ |
embeddedartists | 0:b567d56a59d7 | 712 | unsigned char lodepng_chunk_ancillary(const unsigned char* chunk); |
embeddedartists | 0:b567d56a59d7 | 713 | |
embeddedartists | 0:b567d56a59d7 | 714 | /*0: public, 1: private (see PNG standard)*/ |
embeddedartists | 0:b567d56a59d7 | 715 | unsigned char lodepng_chunk_private(const unsigned char* chunk); |
embeddedartists | 0:b567d56a59d7 | 716 | |
embeddedartists | 0:b567d56a59d7 | 717 | /*0: the chunk is unsafe to copy, 1: the chunk is safe to copy (see PNG standard)*/ |
embeddedartists | 0:b567d56a59d7 | 718 | unsigned char lodepng_chunk_safetocopy(const unsigned char* chunk); |
embeddedartists | 0:b567d56a59d7 | 719 | |
embeddedartists | 0:b567d56a59d7 | 720 | /*get pointer to the data of the chunk, where the input points to the header of the chunk*/ |
embeddedartists | 0:b567d56a59d7 | 721 | unsigned char* lodepng_chunk_data(unsigned char* chunk); |
embeddedartists | 0:b567d56a59d7 | 722 | const unsigned char* lodepng_chunk_data_const(const unsigned char* chunk); |
embeddedartists | 0:b567d56a59d7 | 723 | |
embeddedartists | 0:b567d56a59d7 | 724 | /*returns 0 if the crc is correct, 1 if it's incorrect (0 for OK as usual!)*/ |
embeddedartists | 0:b567d56a59d7 | 725 | unsigned lodepng_chunk_check_crc(const unsigned char* chunk); |
embeddedartists | 0:b567d56a59d7 | 726 | |
embeddedartists | 0:b567d56a59d7 | 727 | /*generates the correct CRC from the data and puts it in the last 4 bytes of the chunk*/ |
embeddedartists | 0:b567d56a59d7 | 728 | void lodepng_chunk_generate_crc(unsigned char* chunk); |
embeddedartists | 0:b567d56a59d7 | 729 | |
embeddedartists | 0:b567d56a59d7 | 730 | /*iterate to next chunks. don't use on IEND chunk, as there is no next chunk then*/ |
embeddedartists | 0:b567d56a59d7 | 731 | unsigned char* lodepng_chunk_next(unsigned char* chunk); |
embeddedartists | 0:b567d56a59d7 | 732 | const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk); |
embeddedartists | 0:b567d56a59d7 | 733 | |
embeddedartists | 0:b567d56a59d7 | 734 | /* |
embeddedartists | 0:b567d56a59d7 | 735 | Appends chunk to the data in out. The given chunk should already have its chunk header. |
embeddedartists | 0:b567d56a59d7 | 736 | The out variable and outlength are updated to reflect the new reallocated buffer. |
embeddedartists | 0:b567d56a59d7 | 737 | Returns error code (0 if it went ok) |
embeddedartists | 0:b567d56a59d7 | 738 | */ |
embeddedartists | 0:b567d56a59d7 | 739 | unsigned lodepng_chunk_append(unsigned char** out, size_t* outlength, const unsigned char* chunk); |
embeddedartists | 0:b567d56a59d7 | 740 | |
embeddedartists | 0:b567d56a59d7 | 741 | /* |
embeddedartists | 0:b567d56a59d7 | 742 | Appends new chunk to out. The chunk to append is given by giving its length, type |
embeddedartists | 0:b567d56a59d7 | 743 | and data separately. The type is a 4-letter string. |
embeddedartists | 0:b567d56a59d7 | 744 | The out variable and outlength are updated to reflect the new reallocated buffer. |
embeddedartists | 0:b567d56a59d7 | 745 | Returne error code (0 if it went ok) |
embeddedartists | 0:b567d56a59d7 | 746 | */ |
embeddedartists | 0:b567d56a59d7 | 747 | unsigned lodepng_chunk_create(unsigned char** out, size_t* outlength, unsigned length, |
embeddedartists | 0:b567d56a59d7 | 748 | const char* type, const unsigned char* data); |
embeddedartists | 0:b567d56a59d7 | 749 | |
embeddedartists | 0:b567d56a59d7 | 750 | |
embeddedartists | 0:b567d56a59d7 | 751 | /*Calculate CRC32 of buffer*/ |
embeddedartists | 0:b567d56a59d7 | 752 | unsigned lodepng_crc32(const unsigned char* buf, size_t len); |
embeddedartists | 0:b567d56a59d7 | 753 | #endif /*LODEPNG_COMPILE_PNG*/ |
embeddedartists | 0:b567d56a59d7 | 754 | |
embeddedartists | 0:b567d56a59d7 | 755 | |
embeddedartists | 0:b567d56a59d7 | 756 | #ifdef LODEPNG_COMPILE_ZLIB |
embeddedartists | 0:b567d56a59d7 | 757 | /* |
embeddedartists | 0:b567d56a59d7 | 758 | This zlib part can be used independently to zlib compress and decompress a |
embeddedartists | 0:b567d56a59d7 | 759 | buffer. It cannot be used to create gzip files however, and it only supports the |
embeddedartists | 0:b567d56a59d7 | 760 | part of zlib that is required for PNG, it does not support dictionaries. |
embeddedartists | 0:b567d56a59d7 | 761 | */ |
embeddedartists | 0:b567d56a59d7 | 762 | |
embeddedartists | 0:b567d56a59d7 | 763 | #ifdef LODEPNG_COMPILE_DECODER |
embeddedartists | 0:b567d56a59d7 | 764 | /*Inflate a buffer. Inflate is the decompression step of deflate. Out buffer must be freed after use.*/ |
embeddedartists | 0:b567d56a59d7 | 765 | unsigned lodepng_inflate(unsigned char** out, size_t* outsize, |
embeddedartists | 0:b567d56a59d7 | 766 | const unsigned char* in, size_t insize, |
embeddedartists | 0:b567d56a59d7 | 767 | const LodePNGDecompressSettings* settings); |
embeddedartists | 0:b567d56a59d7 | 768 | |
embeddedartists | 0:b567d56a59d7 | 769 | /* |
embeddedartists | 0:b567d56a59d7 | 770 | Decompresses Zlib data. Reallocates the out buffer and appends the data. The |
embeddedartists | 0:b567d56a59d7 | 771 | data must be according to the zlib specification. |
embeddedartists | 0:b567d56a59d7 | 772 | Either, *out must be NULL and *outsize must be 0, or, *out must be a valid |
embeddedartists | 0:b567d56a59d7 | 773 | buffer and *outsize its size in bytes. out must be freed by user after usage. |
embeddedartists | 0:b567d56a59d7 | 774 | */ |
embeddedartists | 0:b567d56a59d7 | 775 | unsigned lodepng_zlib_decompress(unsigned char** out, size_t* outsize, |
embeddedartists | 0:b567d56a59d7 | 776 | const unsigned char* in, size_t insize, |
embeddedartists | 0:b567d56a59d7 | 777 | const LodePNGDecompressSettings* settings); |
embeddedartists | 0:b567d56a59d7 | 778 | #endif /*LODEPNG_COMPILE_DECODER*/ |
embeddedartists | 0:b567d56a59d7 | 779 | |
embeddedartists | 0:b567d56a59d7 | 780 | #ifdef LODEPNG_COMPILE_ENCODER |
embeddedartists | 0:b567d56a59d7 | 781 | /* |
embeddedartists | 0:b567d56a59d7 | 782 | Compresses data with Zlib. Reallocates the out buffer and appends the data. |
embeddedartists | 0:b567d56a59d7 | 783 | Zlib adds a small header and trailer around the deflate data. |
embeddedartists | 0:b567d56a59d7 | 784 | The data is output in the format of the zlib specification. |
embeddedartists | 0:b567d56a59d7 | 785 | Either, *out must be NULL and *outsize must be 0, or, *out must be a valid |
embeddedartists | 0:b567d56a59d7 | 786 | buffer and *outsize its size in bytes. out must be freed by user after usage. |
embeddedartists | 0:b567d56a59d7 | 787 | */ |
embeddedartists | 0:b567d56a59d7 | 788 | unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, |
embeddedartists | 0:b567d56a59d7 | 789 | const unsigned char* in, size_t insize, |
embeddedartists | 0:b567d56a59d7 | 790 | const LodePNGCompressSettings* settings); |
embeddedartists | 0:b567d56a59d7 | 791 | |
embeddedartists | 0:b567d56a59d7 | 792 | /* |
embeddedartists | 0:b567d56a59d7 | 793 | Find length-limited Huffman code for given frequencies. This function is in the |
embeddedartists | 0:b567d56a59d7 | 794 | public interface only for tests, it's used internally by lodepng_deflate. |
embeddedartists | 0:b567d56a59d7 | 795 | */ |
embeddedartists | 0:b567d56a59d7 | 796 | unsigned lodepng_huffman_code_lengths(unsigned* lengths, const unsigned* frequencies, |
embeddedartists | 0:b567d56a59d7 | 797 | size_t numcodes, unsigned maxbitlen); |
embeddedartists | 0:b567d56a59d7 | 798 | |
embeddedartists | 0:b567d56a59d7 | 799 | /*Compress a buffer with deflate. See RFC 1951. Out buffer must be freed after use.*/ |
embeddedartists | 0:b567d56a59d7 | 800 | unsigned lodepng_deflate(unsigned char** out, size_t* outsize, |
embeddedartists | 0:b567d56a59d7 | 801 | const unsigned char* in, size_t insize, |
embeddedartists | 0:b567d56a59d7 | 802 | const LodePNGCompressSettings* settings); |
embeddedartists | 0:b567d56a59d7 | 803 | |
embeddedartists | 0:b567d56a59d7 | 804 | #endif /*LODEPNG_COMPILE_ENCODER*/ |
embeddedartists | 0:b567d56a59d7 | 805 | #endif /*LODEPNG_COMPILE_ZLIB*/ |
embeddedartists | 0:b567d56a59d7 | 806 | |
embeddedartists | 0:b567d56a59d7 | 807 | #ifdef LODEPNG_COMPILE_DISK |
embeddedartists | 0:b567d56a59d7 | 808 | /* |
embeddedartists | 0:b567d56a59d7 | 809 | Load a file from disk into buffer. The function allocates the out buffer, and |
embeddedartists | 0:b567d56a59d7 | 810 | after usage you should free it. |
embeddedartists | 0:b567d56a59d7 | 811 | out: output parameter, contains pointer to loaded buffer. |
embeddedartists | 0:b567d56a59d7 | 812 | outsize: output parameter, size of the allocated out buffer |
embeddedartists | 0:b567d56a59d7 | 813 | filename: the path to the file to load |
embeddedartists | 0:b567d56a59d7 | 814 | return value: error code (0 means ok) |
embeddedartists | 0:b567d56a59d7 | 815 | */ |
embeddedartists | 0:b567d56a59d7 | 816 | unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename); |
embeddedartists | 0:b567d56a59d7 | 817 | |
embeddedartists | 0:b567d56a59d7 | 818 | /* |
embeddedartists | 0:b567d56a59d7 | 819 | Save a file from buffer to disk. Warning, if it exists, this function overwrites |
embeddedartists | 0:b567d56a59d7 | 820 | the file without warning! |
embeddedartists | 0:b567d56a59d7 | 821 | buffer: the buffer to write |
embeddedartists | 0:b567d56a59d7 | 822 | buffersize: size of the buffer to write |
embeddedartists | 0:b567d56a59d7 | 823 | filename: the path to the file to save to |
embeddedartists | 0:b567d56a59d7 | 824 | return value: error code (0 means ok) |
embeddedartists | 0:b567d56a59d7 | 825 | */ |
embeddedartists | 0:b567d56a59d7 | 826 | unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename); |
embeddedartists | 0:b567d56a59d7 | 827 | #endif /*LODEPNG_COMPILE_DISK*/ |
embeddedartists | 0:b567d56a59d7 | 828 | |
embeddedartists | 0:b567d56a59d7 | 829 | #ifdef LODEPNG_COMPILE_CPP |
embeddedartists | 0:b567d56a59d7 | 830 | //The LodePNG C++ wrapper uses std::vectors instead of manually allocated memory buffers. |
embeddedartists | 0:b567d56a59d7 | 831 | namespace lodepng |
embeddedartists | 0:b567d56a59d7 | 832 | { |
embeddedartists | 0:b567d56a59d7 | 833 | #ifdef LODEPNG_COMPILE_PNG |
embeddedartists | 0:b567d56a59d7 | 834 | class State : public LodePNGState |
embeddedartists | 0:b567d56a59d7 | 835 | { |
embeddedartists | 0:b567d56a59d7 | 836 | public: |
embeddedartists | 0:b567d56a59d7 | 837 | State(); |
embeddedartists | 0:b567d56a59d7 | 838 | State(const State& other); |
embeddedartists | 0:b567d56a59d7 | 839 | virtual ~State(); |
embeddedartists | 0:b567d56a59d7 | 840 | State& operator=(const State& other); |
embeddedartists | 0:b567d56a59d7 | 841 | }; |
embeddedartists | 0:b567d56a59d7 | 842 | |
embeddedartists | 0:b567d56a59d7 | 843 | #ifdef LODEPNG_COMPILE_DECODER |
embeddedartists | 0:b567d56a59d7 | 844 | //Same as other lodepng::decode, but using a State for more settings and information. |
embeddedartists | 0:b567d56a59d7 | 845 | unsigned decode(std::vector<unsigned char>& out, unsigned& w, unsigned& h, |
embeddedartists | 0:b567d56a59d7 | 846 | State& state, |
embeddedartists | 0:b567d56a59d7 | 847 | const unsigned char* in, size_t insize); |
embeddedartists | 0:b567d56a59d7 | 848 | unsigned decode(std::vector<unsigned char>& out, unsigned& w, unsigned& h, |
embeddedartists | 0:b567d56a59d7 | 849 | State& state, |
embeddedartists | 0:b567d56a59d7 | 850 | const std::vector<unsigned char>& in); |
embeddedartists | 0:b567d56a59d7 | 851 | #endif /*LODEPNG_COMPILE_DECODER*/ |
embeddedartists | 0:b567d56a59d7 | 852 | |
embeddedartists | 0:b567d56a59d7 | 853 | #ifdef LODEPNG_COMPILE_ENCODER |
embeddedartists | 0:b567d56a59d7 | 854 | //Same as other lodepng::encode, but using a State for more settings and information. |
embeddedartists | 0:b567d56a59d7 | 855 | unsigned encode(std::vector<unsigned char>& out, |
embeddedartists | 0:b567d56a59d7 | 856 | const unsigned char* in, unsigned w, unsigned h, |
embeddedartists | 0:b567d56a59d7 | 857 | State& state); |
embeddedartists | 0:b567d56a59d7 | 858 | unsigned encode(std::vector<unsigned char>& out, |
embeddedartists | 0:b567d56a59d7 | 859 | const std::vector<unsigned char>& in, unsigned w, unsigned h, |
embeddedartists | 0:b567d56a59d7 | 860 | State& state); |
embeddedartists | 0:b567d56a59d7 | 861 | #endif /*LODEPNG_COMPILE_ENCODER*/ |
embeddedartists | 0:b567d56a59d7 | 862 | |
embeddedartists | 0:b567d56a59d7 | 863 | #ifdef LODEPNG_COMPILE_DISK |
embeddedartists | 0:b567d56a59d7 | 864 | /* |
embeddedartists | 0:b567d56a59d7 | 865 | Load a file from disk into an std::vector. If the vector is empty, then either |
embeddedartists | 0:b567d56a59d7 | 866 | the file doesn't exist or is an empty file. |
embeddedartists | 0:b567d56a59d7 | 867 | */ |
embeddedartists | 0:b567d56a59d7 | 868 | void load_file(std::vector<unsigned char>& buffer, const std::string& filename); |
embeddedartists | 0:b567d56a59d7 | 869 | |
embeddedartists | 0:b567d56a59d7 | 870 | /* |
embeddedartists | 0:b567d56a59d7 | 871 | Save the binary data in an std::vector to a file on disk. The file is overwritten |
embeddedartists | 0:b567d56a59d7 | 872 | without warning. |
embeddedartists | 0:b567d56a59d7 | 873 | */ |
embeddedartists | 0:b567d56a59d7 | 874 | void save_file(const std::vector<unsigned char>& buffer, const std::string& filename); |
embeddedartists | 0:b567d56a59d7 | 875 | #endif //LODEPNG_COMPILE_DISK |
embeddedartists | 0:b567d56a59d7 | 876 | #endif //LODEPNG_COMPILE_PNG |
embeddedartists | 0:b567d56a59d7 | 877 | |
embeddedartists | 0:b567d56a59d7 | 878 | #ifdef LODEPNG_COMPILE_ZLIB |
embeddedartists | 0:b567d56a59d7 | 879 | #ifdef LODEPNG_COMPILE_DECODER |
embeddedartists | 0:b567d56a59d7 | 880 | //Zlib-decompress an unsigned char buffer |
embeddedartists | 0:b567d56a59d7 | 881 | unsigned decompress(std::vector<unsigned char>& out, const unsigned char* in, size_t insize, |
embeddedartists | 0:b567d56a59d7 | 882 | const LodePNGDecompressSettings& settings = lodepng_default_decompress_settings); |
embeddedartists | 0:b567d56a59d7 | 883 | |
embeddedartists | 0:b567d56a59d7 | 884 | //Zlib-decompress an std::vector |
embeddedartists | 0:b567d56a59d7 | 885 | unsigned decompress(std::vector<unsigned char>& out, const std::vector<unsigned char>& in, |
embeddedartists | 0:b567d56a59d7 | 886 | const LodePNGDecompressSettings& settings = lodepng_default_decompress_settings); |
embeddedartists | 0:b567d56a59d7 | 887 | #endif //LODEPNG_COMPILE_DECODER |
embeddedartists | 0:b567d56a59d7 | 888 | |
embeddedartists | 0:b567d56a59d7 | 889 | #ifdef LODEPNG_COMPILE_ENCODER |
embeddedartists | 0:b567d56a59d7 | 890 | //Zlib-compress an unsigned char buffer |
embeddedartists | 0:b567d56a59d7 | 891 | unsigned compress(std::vector<unsigned char>& out, const unsigned char* in, size_t insize, |
embeddedartists | 0:b567d56a59d7 | 892 | const LodePNGCompressSettings& settings = lodepng_default_compress_settings); |
embeddedartists | 0:b567d56a59d7 | 893 | |
embeddedartists | 0:b567d56a59d7 | 894 | //Zlib-compress an std::vector |
embeddedartists | 0:b567d56a59d7 | 895 | unsigned compress(std::vector<unsigned char>& out, const std::vector<unsigned char>& in, |
embeddedartists | 0:b567d56a59d7 | 896 | const LodePNGCompressSettings& settings = lodepng_default_compress_settings); |
embeddedartists | 0:b567d56a59d7 | 897 | #endif //LODEPNG_COMPILE_ENCODER |
embeddedartists | 0:b567d56a59d7 | 898 | #endif //LODEPNG_COMPILE_ZLIB |
embeddedartists | 0:b567d56a59d7 | 899 | } //namespace lodepng |
embeddedartists | 0:b567d56a59d7 | 900 | #endif /*LODEPNG_COMPILE_CPP*/ |
embeddedartists | 0:b567d56a59d7 | 901 | |
embeddedartists | 0:b567d56a59d7 | 902 | /* |
embeddedartists | 0:b567d56a59d7 | 903 | TODO: |
embeddedartists | 0:b567d56a59d7 | 904 | [.] test if there are no memory leaks or security exploits - done a lot but needs to be checked often |
embeddedartists | 0:b567d56a59d7 | 905 | [.] check compatibility with vareous compilers - done but needs to be redone for every newer version |
embeddedartists | 0:b567d56a59d7 | 906 | [X] converting color to 16-bit per channel types |
embeddedartists | 0:b567d56a59d7 | 907 | [ ] read all public PNG chunk types (but never let the color profile and gamma ones touch RGB values) |
embeddedartists | 0:b567d56a59d7 | 908 | [ ] make sure encoder generates no chunks with size > (2^31)-1 |
embeddedartists | 0:b567d56a59d7 | 909 | [ ] partial decoding (stream processing) |
embeddedartists | 0:b567d56a59d7 | 910 | [X] let the "isFullyOpaque" function check color keys and transparent palettes too |
embeddedartists | 0:b567d56a59d7 | 911 | [X] better name for the variables "codes", "codesD", "codelengthcodes", "clcl" and "lldl" |
embeddedartists | 0:b567d56a59d7 | 912 | [ ] don't stop decoding on errors like 69, 57, 58 (make warnings) |
embeddedartists | 0:b567d56a59d7 | 913 | [ ] make option to choose if the raw image with non multiple of 8 bits per scanline should have padding bits or not |
embeddedartists | 0:b567d56a59d7 | 914 | [ ] let the C++ wrapper catch exceptions coming from the standard library and return LodePNG error codes |
embeddedartists | 0:b567d56a59d7 | 915 | */ |
embeddedartists | 0:b567d56a59d7 | 916 | |
embeddedartists | 0:b567d56a59d7 | 917 | #endif /*LODEPNG_H inclusion guard*/ |
embeddedartists | 0:b567d56a59d7 | 918 | |
embeddedartists | 0:b567d56a59d7 | 919 | /* |
embeddedartists | 0:b567d56a59d7 | 920 | LodePNG Documentation |
embeddedartists | 0:b567d56a59d7 | 921 | --------------------- |
embeddedartists | 0:b567d56a59d7 | 922 | |
embeddedartists | 0:b567d56a59d7 | 923 | 0. table of contents |
embeddedartists | 0:b567d56a59d7 | 924 | -------------------- |
embeddedartists | 0:b567d56a59d7 | 925 | |
embeddedartists | 0:b567d56a59d7 | 926 | 1. about |
embeddedartists | 0:b567d56a59d7 | 927 | 1.1. supported features |
embeddedartists | 0:b567d56a59d7 | 928 | 1.2. features not supported |
embeddedartists | 0:b567d56a59d7 | 929 | 2. C and C++ version |
embeddedartists | 0:b567d56a59d7 | 930 | 3. security |
embeddedartists | 0:b567d56a59d7 | 931 | 4. decoding |
embeddedartists | 0:b567d56a59d7 | 932 | 5. encoding |
embeddedartists | 0:b567d56a59d7 | 933 | 6. color conversions |
embeddedartists | 0:b567d56a59d7 | 934 | 6.1. PNG color types |
embeddedartists | 0:b567d56a59d7 | 935 | 6.2. color conversions |
embeddedartists | 0:b567d56a59d7 | 936 | 6.3. padding bits |
embeddedartists | 0:b567d56a59d7 | 937 | 6.4. A note about 16-bits per channel and endianness |
embeddedartists | 0:b567d56a59d7 | 938 | 7. error values |
embeddedartists | 0:b567d56a59d7 | 939 | 8. chunks and PNG editing |
embeddedartists | 0:b567d56a59d7 | 940 | 9. compiler support |
embeddedartists | 0:b567d56a59d7 | 941 | 10. examples |
embeddedartists | 0:b567d56a59d7 | 942 | 10.1. decoder C++ example |
embeddedartists | 0:b567d56a59d7 | 943 | 10.2. decoder C example |
embeddedartists | 0:b567d56a59d7 | 944 | 11. changes |
embeddedartists | 0:b567d56a59d7 | 945 | 12. contact information |
embeddedartists | 0:b567d56a59d7 | 946 | |
embeddedartists | 0:b567d56a59d7 | 947 | |
embeddedartists | 0:b567d56a59d7 | 948 | 1. about |
embeddedartists | 0:b567d56a59d7 | 949 | -------- |
embeddedartists | 0:b567d56a59d7 | 950 | |
embeddedartists | 0:b567d56a59d7 | 951 | PNG is a file format to store raster images losslessly with good compression, |
embeddedartists | 0:b567d56a59d7 | 952 | supporting different color types and alpha channel. |
embeddedartists | 0:b567d56a59d7 | 953 | |
embeddedartists | 0:b567d56a59d7 | 954 | LodePNG is a PNG codec according to the Portable Network Graphics (PNG) |
embeddedartists | 0:b567d56a59d7 | 955 | Specification (Second Edition) - W3C Recommendation 10 November 2003. |
embeddedartists | 0:b567d56a59d7 | 956 | |
embeddedartists | 0:b567d56a59d7 | 957 | The specifications used are: |
embeddedartists | 0:b567d56a59d7 | 958 | |
embeddedartists | 0:b567d56a59d7 | 959 | *) Portable Network Graphics (PNG) Specification (Second Edition): |
embeddedartists | 0:b567d56a59d7 | 960 | http://www.w3.org/TR/2003/REC-PNG-20031110 |
embeddedartists | 0:b567d56a59d7 | 961 | *) RFC 1950 ZLIB Compressed Data Format version 3.3: |
embeddedartists | 0:b567d56a59d7 | 962 | http://www.gzip.org/zlib/rfc-zlib.html |
embeddedartists | 0:b567d56a59d7 | 963 | *) RFC 1951 DEFLATE Compressed Data Format Specification ver 1.3: |
embeddedartists | 0:b567d56a59d7 | 964 | http://www.gzip.org/zlib/rfc-deflate.html |
embeddedartists | 0:b567d56a59d7 | 965 | |
embeddedartists | 0:b567d56a59d7 | 966 | The most recent version of LodePNG can currently be found at |
embeddedartists | 0:b567d56a59d7 | 967 | http://lodev.org/lodepng/ |
embeddedartists | 0:b567d56a59d7 | 968 | |
embeddedartists | 0:b567d56a59d7 | 969 | LodePNG works both in C (ISO C90) and C++, with a C++ wrapper that adds |
embeddedartists | 0:b567d56a59d7 | 970 | extra functionality. |
embeddedartists | 0:b567d56a59d7 | 971 | |
embeddedartists | 0:b567d56a59d7 | 972 | LodePNG exists out of two files: |
embeddedartists | 0:b567d56a59d7 | 973 | -lodepng.h: the header file for both C and C++ |
embeddedartists | 0:b567d56a59d7 | 974 | -lodepng.c(pp): give it the name lodepng.c or lodepng.cpp (or .cc) depending on your usage |
embeddedartists | 0:b567d56a59d7 | 975 | |
embeddedartists | 0:b567d56a59d7 | 976 | If you want to start using LodePNG right away without reading this doc, get the |
embeddedartists | 0:b567d56a59d7 | 977 | examples from the LodePNG website to see how to use it in code, or check the |
embeddedartists | 0:b567d56a59d7 | 978 | smaller examples in chapter 13 here. |
embeddedartists | 0:b567d56a59d7 | 979 | |
embeddedartists | 0:b567d56a59d7 | 980 | LodePNG is simple but only supports the basic requirements. To achieve |
embeddedartists | 0:b567d56a59d7 | 981 | simplicity, the following design choices were made: There are no dependencies |
embeddedartists | 0:b567d56a59d7 | 982 | on any external library. There are functions to decode and encode a PNG with |
embeddedartists | 0:b567d56a59d7 | 983 | a single function call, and extended versions of these functions taking a |
embeddedartists | 0:b567d56a59d7 | 984 | LodePNGState struct allowing to specify or get more information. By default |
embeddedartists | 0:b567d56a59d7 | 985 | the colors of the raw image are always RGB or RGBA, no matter what color type |
embeddedartists | 0:b567d56a59d7 | 986 | the PNG file uses. To read and write files, there are simple functions to |
embeddedartists | 0:b567d56a59d7 | 987 | convert the files to/from buffers in memory. |
embeddedartists | 0:b567d56a59d7 | 988 | |
embeddedartists | 0:b567d56a59d7 | 989 | This all makes LodePNG suitable for loading textures in games, demos and small |
embeddedartists | 0:b567d56a59d7 | 990 | programs, ... It's less suitable for full fledged image editors, loading PNGs |
embeddedartists | 0:b567d56a59d7 | 991 | over network (it requires all the image data to be available before decoding can |
embeddedartists | 0:b567d56a59d7 | 992 | begin), life-critical systems, ... |
embeddedartists | 0:b567d56a59d7 | 993 | |
embeddedartists | 0:b567d56a59d7 | 994 | 1.1. supported features |
embeddedartists | 0:b567d56a59d7 | 995 | ----------------------- |
embeddedartists | 0:b567d56a59d7 | 996 | |
embeddedartists | 0:b567d56a59d7 | 997 | The following features are supported by the decoder: |
embeddedartists | 0:b567d56a59d7 | 998 | |
embeddedartists | 0:b567d56a59d7 | 999 | *) decoding of PNGs with any color type, bit depth and interlace mode, to a 24- or 32-bit color raw image, |
embeddedartists | 0:b567d56a59d7 | 1000 | or the same color type as the PNG |
embeddedartists | 0:b567d56a59d7 | 1001 | *) encoding of PNGs, from any raw image to 24- or 32-bit color, or the same color type as the raw image |
embeddedartists | 0:b567d56a59d7 | 1002 | *) Adam7 interlace and deinterlace for any color type |
embeddedartists | 0:b567d56a59d7 | 1003 | *) loading the image from harddisk or decoding it from a buffer from other sources than harddisk |
embeddedartists | 0:b567d56a59d7 | 1004 | *) support for alpha channels, including RGBA color model, translucent palettes and color keying |
embeddedartists | 0:b567d56a59d7 | 1005 | *) zlib decompression (inflate) |
embeddedartists | 0:b567d56a59d7 | 1006 | *) zlib compression (deflate) |
embeddedartists | 0:b567d56a59d7 | 1007 | *) CRC32 and ADLER32 checksums |
embeddedartists | 0:b567d56a59d7 | 1008 | *) handling of unknown chunks, allowing making a PNG editor that stores custom and unknown chunks. |
embeddedartists | 0:b567d56a59d7 | 1009 | *) the following chunks are supported (generated/interpreted) by both encoder and decoder: |
embeddedartists | 0:b567d56a59d7 | 1010 | IHDR: header information |
embeddedartists | 0:b567d56a59d7 | 1011 | PLTE: color palette |
embeddedartists | 0:b567d56a59d7 | 1012 | IDAT: pixel data |
embeddedartists | 0:b567d56a59d7 | 1013 | IEND: the final chunk |
embeddedartists | 0:b567d56a59d7 | 1014 | tRNS: transparency for palettized images |
embeddedartists | 0:b567d56a59d7 | 1015 | tEXt: textual information |
embeddedartists | 0:b567d56a59d7 | 1016 | zTXt: compressed textual information |
embeddedartists | 0:b567d56a59d7 | 1017 | iTXt: international textual information |
embeddedartists | 0:b567d56a59d7 | 1018 | bKGD: suggested background color |
embeddedartists | 0:b567d56a59d7 | 1019 | pHYs: physical dimensions |
embeddedartists | 0:b567d56a59d7 | 1020 | tIME: modification time |
embeddedartists | 0:b567d56a59d7 | 1021 | |
embeddedartists | 0:b567d56a59d7 | 1022 | 1.2. features not supported |
embeddedartists | 0:b567d56a59d7 | 1023 | --------------------------- |
embeddedartists | 0:b567d56a59d7 | 1024 | |
embeddedartists | 0:b567d56a59d7 | 1025 | The following features are _not_ supported: |
embeddedartists | 0:b567d56a59d7 | 1026 | |
embeddedartists | 0:b567d56a59d7 | 1027 | *) some features needed to make a conformant PNG-Editor might be still missing. |
embeddedartists | 0:b567d56a59d7 | 1028 | *) partial loading/stream processing. All data must be available and is processed in one call. |
embeddedartists | 0:b567d56a59d7 | 1029 | *) The following public chunks are not supported but treated as unknown chunks by LodePNG |
embeddedartists | 0:b567d56a59d7 | 1030 | cHRM, gAMA, iCCP, sRGB, sBIT, hIST, sPLT |
embeddedartists | 0:b567d56a59d7 | 1031 | Some of these are not supported on purpose: LodePNG wants to provide the RGB values |
embeddedartists | 0:b567d56a59d7 | 1032 | stored in the pixels, not values modified by system dependent gamma or color models. |
embeddedartists | 0:b567d56a59d7 | 1033 | |
embeddedartists | 0:b567d56a59d7 | 1034 | |
embeddedartists | 0:b567d56a59d7 | 1035 | 2. C and C++ version |
embeddedartists | 0:b567d56a59d7 | 1036 | -------------------- |
embeddedartists | 0:b567d56a59d7 | 1037 | |
embeddedartists | 0:b567d56a59d7 | 1038 | The C version uses buffers allocated with alloc that you need to free() |
embeddedartists | 0:b567d56a59d7 | 1039 | yourself. You need to use init and cleanup functions for each struct whenever |
embeddedartists | 0:b567d56a59d7 | 1040 | using a struct from the C version to avoid exploits and memory leaks. |
embeddedartists | 0:b567d56a59d7 | 1041 | |
embeddedartists | 0:b567d56a59d7 | 1042 | The C++ version has extra functions with std::vectors in the interface and the |
embeddedartists | 0:b567d56a59d7 | 1043 | lodepng::State class which is a LodePNGState with constructor and destructor. |
embeddedartists | 0:b567d56a59d7 | 1044 | |
embeddedartists | 0:b567d56a59d7 | 1045 | These files work without modification for both C and C++ compilers because all |
embeddedartists | 0:b567d56a59d7 | 1046 | the additional C++ code is in "#ifdef __cplusplus" blocks that make C-compilers |
embeddedartists | 0:b567d56a59d7 | 1047 | ignore it, and the C code is made to compile both with strict ISO C90 and C++. |
embeddedartists | 0:b567d56a59d7 | 1048 | |
embeddedartists | 0:b567d56a59d7 | 1049 | To use the C++ version, you need to rename the source file to lodepng.cpp |
embeddedartists | 0:b567d56a59d7 | 1050 | (instead of lodepng.c), and compile it with a C++ compiler. |
embeddedartists | 0:b567d56a59d7 | 1051 | |
embeddedartists | 0:b567d56a59d7 | 1052 | To use the C version, you need to rename the source file to lodepng.c (instead |
embeddedartists | 0:b567d56a59d7 | 1053 | of lodepng.cpp), and compile it with a C compiler. |
embeddedartists | 0:b567d56a59d7 | 1054 | |
embeddedartists | 0:b567d56a59d7 | 1055 | |
embeddedartists | 0:b567d56a59d7 | 1056 | 3. Security |
embeddedartists | 0:b567d56a59d7 | 1057 | ----------- |
embeddedartists | 0:b567d56a59d7 | 1058 | |
embeddedartists | 0:b567d56a59d7 | 1059 | Even if carefully designed, it's always possible that LodePNG contains possible |
embeddedartists | 0:b567d56a59d7 | 1060 | exploits. If you discover one, please let me know, and it will be fixed. |
embeddedartists | 0:b567d56a59d7 | 1061 | |
embeddedartists | 0:b567d56a59d7 | 1062 | When using LodePNG, care has to be taken with the C version of LodePNG, as well |
embeddedartists | 0:b567d56a59d7 | 1063 | as the C-style structs when working with C++. The following conventions are used |
embeddedartists | 0:b567d56a59d7 | 1064 | for all C-style structs: |
embeddedartists | 0:b567d56a59d7 | 1065 | |
embeddedartists | 0:b567d56a59d7 | 1066 | -if a struct has a corresponding init function, always call the init function when making a new one |
embeddedartists | 0:b567d56a59d7 | 1067 | -if a struct has a corresponding cleanup function, call it before the struct disappears to avoid memory leaks |
embeddedartists | 0:b567d56a59d7 | 1068 | -if a struct has a corresponding copy function, use the copy function instead of "=". |
embeddedartists | 0:b567d56a59d7 | 1069 | The destination must also be inited already. |
embeddedartists | 0:b567d56a59d7 | 1070 | |
embeddedartists | 0:b567d56a59d7 | 1071 | |
embeddedartists | 0:b567d56a59d7 | 1072 | 4. Decoding |
embeddedartists | 0:b567d56a59d7 | 1073 | ----------- |
embeddedartists | 0:b567d56a59d7 | 1074 | |
embeddedartists | 0:b567d56a59d7 | 1075 | Decoding converts a PNG compressed image to a raw pixel buffer. |
embeddedartists | 0:b567d56a59d7 | 1076 | |
embeddedartists | 0:b567d56a59d7 | 1077 | Most documentation on using the decoder is at its declarations in the header |
embeddedartists | 0:b567d56a59d7 | 1078 | above. For C, simple decoding can be done with functions such as |
embeddedartists | 0:b567d56a59d7 | 1079 | lodepng_decode32, and more advanced decoding can be done with the struct |
embeddedartists | 0:b567d56a59d7 | 1080 | LodePNGState and lodepng_decode. For C++, all decoding can be done with the |
embeddedartists | 0:b567d56a59d7 | 1081 | various lodepng::decode functions, and lodepng::State can be used for advanced |
embeddedartists | 0:b567d56a59d7 | 1082 | features. |
embeddedartists | 0:b567d56a59d7 | 1083 | |
embeddedartists | 0:b567d56a59d7 | 1084 | When using the LodePNGState, it uses the following fields for decoding: |
embeddedartists | 0:b567d56a59d7 | 1085 | *) LodePNGInfo info_png: it stores extra information about the PNG (the input) in here |
embeddedartists | 0:b567d56a59d7 | 1086 | *) LodePNGColorMode info_raw: here you can say what color mode of the raw image (the output) you want to get |
embeddedartists | 0:b567d56a59d7 | 1087 | *) LodePNGDecoderSettings decoder: you can specify a few extra settings for the decoder to use |
embeddedartists | 0:b567d56a59d7 | 1088 | |
embeddedartists | 0:b567d56a59d7 | 1089 | LodePNGInfo info_png |
embeddedartists | 0:b567d56a59d7 | 1090 | -------------------- |
embeddedartists | 0:b567d56a59d7 | 1091 | |
embeddedartists | 0:b567d56a59d7 | 1092 | After decoding, this contains extra information of the PNG image, except the actual |
embeddedartists | 0:b567d56a59d7 | 1093 | pixels, width and height because these are already gotten directly from the decoder |
embeddedartists | 0:b567d56a59d7 | 1094 | functions. |
embeddedartists | 0:b567d56a59d7 | 1095 | |
embeddedartists | 0:b567d56a59d7 | 1096 | It contains for example the original color type of the PNG image, text comments, |
embeddedartists | 0:b567d56a59d7 | 1097 | suggested background color, etc... More details about the LodePNGInfo struct are |
embeddedartists | 0:b567d56a59d7 | 1098 | at its declaration documentation. |
embeddedartists | 0:b567d56a59d7 | 1099 | |
embeddedartists | 0:b567d56a59d7 | 1100 | LodePNGColorMode info_raw |
embeddedartists | 0:b567d56a59d7 | 1101 | ------------------------- |
embeddedartists | 0:b567d56a59d7 | 1102 | |
embeddedartists | 0:b567d56a59d7 | 1103 | When decoding, here you can specify which color type you want |
embeddedartists | 0:b567d56a59d7 | 1104 | the resulting raw image to be. If this is different from the colortype of the |
embeddedartists | 0:b567d56a59d7 | 1105 | PNG, then the decoder will automatically convert the result. This conversion |
embeddedartists | 0:b567d56a59d7 | 1106 | always works, except if you want it to convert a color PNG to greyscale or to |
embeddedartists | 0:b567d56a59d7 | 1107 | a palette with missing colors. |
embeddedartists | 0:b567d56a59d7 | 1108 | |
embeddedartists | 0:b567d56a59d7 | 1109 | By default, 32-bit color is used for the result. |
embeddedartists | 0:b567d56a59d7 | 1110 | |
embeddedartists | 0:b567d56a59d7 | 1111 | LodePNGDecoderSettings decoder |
embeddedartists | 0:b567d56a59d7 | 1112 | ------------------------------ |
embeddedartists | 0:b567d56a59d7 | 1113 | |
embeddedartists | 0:b567d56a59d7 | 1114 | The settings can be used to ignore the errors created by invalid CRC and Adler32 |
embeddedartists | 0:b567d56a59d7 | 1115 | chunks, and to disable the decoding of tEXt chunks. |
embeddedartists | 0:b567d56a59d7 | 1116 | |
embeddedartists | 0:b567d56a59d7 | 1117 | There's also a setting color_convert, true by default. If false, no conversion |
embeddedartists | 0:b567d56a59d7 | 1118 | is done, the resulting data will be as it was in the PNG (after decompression) |
embeddedartists | 0:b567d56a59d7 | 1119 | and you'll have to puzzle the colors of the pixels together yourself using the |
embeddedartists | 0:b567d56a59d7 | 1120 | color type information in the LodePNGInfo. |
embeddedartists | 0:b567d56a59d7 | 1121 | |
embeddedartists | 0:b567d56a59d7 | 1122 | |
embeddedartists | 0:b567d56a59d7 | 1123 | 5. Encoding |
embeddedartists | 0:b567d56a59d7 | 1124 | ----------- |
embeddedartists | 0:b567d56a59d7 | 1125 | |
embeddedartists | 0:b567d56a59d7 | 1126 | Encoding converts a raw pixel buffer to a PNG compressed image. |
embeddedartists | 0:b567d56a59d7 | 1127 | |
embeddedartists | 0:b567d56a59d7 | 1128 | Most documentation on using the encoder is at its declarations in the header |
embeddedartists | 0:b567d56a59d7 | 1129 | above. For C, simple encoding can be done with functions such as |
embeddedartists | 0:b567d56a59d7 | 1130 | lodepng_encode32, and more advanced decoding can be done with the struct |
embeddedartists | 0:b567d56a59d7 | 1131 | LodePNGState and lodepng_encode. For C++, all encoding can be done with the |
embeddedartists | 0:b567d56a59d7 | 1132 | various lodepng::encode functions, and lodepng::State can be used for advanced |
embeddedartists | 0:b567d56a59d7 | 1133 | features. |
embeddedartists | 0:b567d56a59d7 | 1134 | |
embeddedartists | 0:b567d56a59d7 | 1135 | Like the decoder, the encoder can also give errors. However it gives less errors |
embeddedartists | 0:b567d56a59d7 | 1136 | since the encoder input is trusted, the decoder input (a PNG image that could |
embeddedartists | 0:b567d56a59d7 | 1137 | be forged by anyone) is not trusted. |
embeddedartists | 0:b567d56a59d7 | 1138 | |
embeddedartists | 0:b567d56a59d7 | 1139 | When using the LodePNGState, it uses the following fields for encoding: |
embeddedartists | 0:b567d56a59d7 | 1140 | *) LodePNGInfo info_png: here you specify how you want the PNG (the output) to be. |
embeddedartists | 0:b567d56a59d7 | 1141 | *) LodePNGColorMode info_raw: here you say what color type of the raw image (the input) has |
embeddedartists | 0:b567d56a59d7 | 1142 | *) LodePNGEncoderSettings encoder: you can specify a few settings for the encoder to use |
embeddedartists | 0:b567d56a59d7 | 1143 | |
embeddedartists | 0:b567d56a59d7 | 1144 | LodePNGInfo info_png |
embeddedartists | 0:b567d56a59d7 | 1145 | -------------------- |
embeddedartists | 0:b567d56a59d7 | 1146 | |
embeddedartists | 0:b567d56a59d7 | 1147 | When encoding, you use this the opposite way as when decoding: for encoding, |
embeddedartists | 0:b567d56a59d7 | 1148 | you fill in the values you want the PNG to have before encoding. By default it's |
embeddedartists | 0:b567d56a59d7 | 1149 | not needed to specify a color type for the PNG since it's automatically chosen, |
embeddedartists | 0:b567d56a59d7 | 1150 | but it's possible to choose it yourself given the right settings. |
embeddedartists | 0:b567d56a59d7 | 1151 | |
embeddedartists | 0:b567d56a59d7 | 1152 | The encoder will not always exactly match the LodePNGInfo struct you give, |
embeddedartists | 0:b567d56a59d7 | 1153 | it tries as close as possible. Some things are ignored by the encoder. The |
embeddedartists | 0:b567d56a59d7 | 1154 | encoder uses, for example, the following settings from it when applicable: |
embeddedartists | 0:b567d56a59d7 | 1155 | colortype and bitdepth, text chunks, time chunk, the color key, the palette, the |
embeddedartists | 0:b567d56a59d7 | 1156 | background color, the interlace method, unknown chunks, ... |
embeddedartists | 0:b567d56a59d7 | 1157 | |
embeddedartists | 0:b567d56a59d7 | 1158 | When encoding to a PNG with colortype 3, the encoder will generate a PLTE chunk. |
embeddedartists | 0:b567d56a59d7 | 1159 | If the palette contains any colors for which the alpha channel is not 255 (so |
embeddedartists | 0:b567d56a59d7 | 1160 | there are translucent colors in the palette), it'll add a tRNS chunk. |
embeddedartists | 0:b567d56a59d7 | 1161 | |
embeddedartists | 0:b567d56a59d7 | 1162 | LodePNGColorMode info_raw |
embeddedartists | 0:b567d56a59d7 | 1163 | ------------------------- |
embeddedartists | 0:b567d56a59d7 | 1164 | |
embeddedartists | 0:b567d56a59d7 | 1165 | You specify the color type of the raw image that you give to the input here, |
embeddedartists | 0:b567d56a59d7 | 1166 | including a possible transparent color key and palette you happen to be using in |
embeddedartists | 0:b567d56a59d7 | 1167 | your raw image data. |
embeddedartists | 0:b567d56a59d7 | 1168 | |
embeddedartists | 0:b567d56a59d7 | 1169 | By default, 32-bit color is assumed, meaning your input has to be in RGBA |
embeddedartists | 0:b567d56a59d7 | 1170 | format with 4 bytes (unsigned chars) per pixel. |
embeddedartists | 0:b567d56a59d7 | 1171 | |
embeddedartists | 0:b567d56a59d7 | 1172 | LodePNGEncoderSettings encoder |
embeddedartists | 0:b567d56a59d7 | 1173 | ------------------------------ |
embeddedartists | 0:b567d56a59d7 | 1174 | |
embeddedartists | 0:b567d56a59d7 | 1175 | The following settings are supported (some are in sub-structs): |
embeddedartists | 0:b567d56a59d7 | 1176 | *) auto_convert: when this option is enabled, the encoder will |
embeddedartists | 0:b567d56a59d7 | 1177 | automatically choose the smallest possible color mode (including color key) that |
embeddedartists | 0:b567d56a59d7 | 1178 | can encode the colors of all pixels without information loss. |
embeddedartists | 0:b567d56a59d7 | 1179 | *) btype: the block type for LZ77. 0 = uncompressed, 1 = fixed huffman tree, |
embeddedartists | 0:b567d56a59d7 | 1180 | 2 = dynamic huffman tree (best compression). Should be 2 for proper |
embeddedartists | 0:b567d56a59d7 | 1181 | compression. |
embeddedartists | 0:b567d56a59d7 | 1182 | *) use_lz77: whether or not to use LZ77 for compressed block types. Should be |
embeddedartists | 0:b567d56a59d7 | 1183 | true for proper compression. |
embeddedartists | 0:b567d56a59d7 | 1184 | *) windowsize: the window size used by the LZ77 encoder (1 - 32768). Has value |
embeddedartists | 0:b567d56a59d7 | 1185 | 2048 by default, but can be set to 32768 for better, but slow, compression. |
embeddedartists | 0:b567d56a59d7 | 1186 | *) force_palette: if colortype is 2 or 6, you can make the encoder write a PLTE |
embeddedartists | 0:b567d56a59d7 | 1187 | chunk if force_palette is true. This can used as suggested palette to convert |
embeddedartists | 0:b567d56a59d7 | 1188 | to by viewers that don't support more than 256 colors (if those still exist) |
embeddedartists | 0:b567d56a59d7 | 1189 | *) add_id: add text chunk "Encoder: LodePNG <version>" to the image. |
embeddedartists | 0:b567d56a59d7 | 1190 | *) text_compression: default 1. If 1, it'll store texts as zTXt instead of tEXt chunks. |
embeddedartists | 0:b567d56a59d7 | 1191 | zTXt chunks use zlib compression on the text. This gives a smaller result on |
embeddedartists | 0:b567d56a59d7 | 1192 | large texts but a larger result on small texts (such as a single program name). |
embeddedartists | 0:b567d56a59d7 | 1193 | It's all tEXt or all zTXt though, there's no separate setting per text yet. |
embeddedartists | 0:b567d56a59d7 | 1194 | |
embeddedartists | 0:b567d56a59d7 | 1195 | |
embeddedartists | 0:b567d56a59d7 | 1196 | 6. color conversions |
embeddedartists | 0:b567d56a59d7 | 1197 | -------------------- |
embeddedartists | 0:b567d56a59d7 | 1198 | |
embeddedartists | 0:b567d56a59d7 | 1199 | An important thing to note about LodePNG, is that the color type of the PNG, and |
embeddedartists | 0:b567d56a59d7 | 1200 | the color type of the raw image, are completely independent. By default, when |
embeddedartists | 0:b567d56a59d7 | 1201 | you decode a PNG, you get the result as a raw image in the color type you want, |
embeddedartists | 0:b567d56a59d7 | 1202 | no matter whether the PNG was encoded with a palette, greyscale or RGBA color. |
embeddedartists | 0:b567d56a59d7 | 1203 | And if you encode an image, by default LodePNG will automatically choose the PNG |
embeddedartists | 0:b567d56a59d7 | 1204 | color type that gives good compression based on the values of colors and amount |
embeddedartists | 0:b567d56a59d7 | 1205 | of colors in the image. It can be configured to let you control it instead as |
embeddedartists | 0:b567d56a59d7 | 1206 | well, though. |
embeddedartists | 0:b567d56a59d7 | 1207 | |
embeddedartists | 0:b567d56a59d7 | 1208 | To be able to do this, LodePNG does conversions from one color mode to another. |
embeddedartists | 0:b567d56a59d7 | 1209 | It can convert from almost any color type to any other color type, except the |
embeddedartists | 0:b567d56a59d7 | 1210 | following conversions: RGB to greyscale is not supported, and converting to a |
embeddedartists | 0:b567d56a59d7 | 1211 | palette when the palette doesn't have a required color is not supported. This is |
embeddedartists | 0:b567d56a59d7 | 1212 | not supported on purpose: this is information loss which requires a color |
embeddedartists | 0:b567d56a59d7 | 1213 | reduction algorithm that is beyong the scope of a PNG encoder (yes, RGB to grey |
embeddedartists | 0:b567d56a59d7 | 1214 | is easy, but there are multiple ways if you want to give some channels more |
embeddedartists | 0:b567d56a59d7 | 1215 | weight). |
embeddedartists | 0:b567d56a59d7 | 1216 | |
embeddedartists | 0:b567d56a59d7 | 1217 | By default, when decoding, you get the raw image in 32-bit RGBA or 24-bit RGB |
embeddedartists | 0:b567d56a59d7 | 1218 | color, no matter what color type the PNG has. And by default when encoding, |
embeddedartists | 0:b567d56a59d7 | 1219 | LodePNG automatically picks the best color model for the output PNG, and expects |
embeddedartists | 0:b567d56a59d7 | 1220 | the input image to be 32-bit RGBA or 24-bit RGB. So, unless you want to control |
embeddedartists | 0:b567d56a59d7 | 1221 | the color format of the images yourself, you can skip this chapter. |
embeddedartists | 0:b567d56a59d7 | 1222 | |
embeddedartists | 0:b567d56a59d7 | 1223 | 6.1. PNG color types |
embeddedartists | 0:b567d56a59d7 | 1224 | -------------------- |
embeddedartists | 0:b567d56a59d7 | 1225 | |
embeddedartists | 0:b567d56a59d7 | 1226 | A PNG image can have many color types, ranging from 1-bit color to 64-bit color, |
embeddedartists | 0:b567d56a59d7 | 1227 | as well as palettized color modes. After the zlib decompression and unfiltering |
embeddedartists | 0:b567d56a59d7 | 1228 | in the PNG image is done, the raw pixel data will have that color type and thus |
embeddedartists | 0:b567d56a59d7 | 1229 | a certain amount of bits per pixel. If you want the output raw image after |
embeddedartists | 0:b567d56a59d7 | 1230 | decoding to have another color type, a conversion is done by LodePNG. |
embeddedartists | 0:b567d56a59d7 | 1231 | |
embeddedartists | 0:b567d56a59d7 | 1232 | The PNG specification gives the following color types: |
embeddedartists | 0:b567d56a59d7 | 1233 | |
embeddedartists | 0:b567d56a59d7 | 1234 | 0: greyscale, bit depths 1, 2, 4, 8, 16 |
embeddedartists | 0:b567d56a59d7 | 1235 | 2: RGB, bit depths 8 and 16 |
embeddedartists | 0:b567d56a59d7 | 1236 | 3: palette, bit depths 1, 2, 4 and 8 |
embeddedartists | 0:b567d56a59d7 | 1237 | 4: greyscale with alpha, bit depths 8 and 16 |
embeddedartists | 0:b567d56a59d7 | 1238 | 6: RGBA, bit depths 8 and 16 |
embeddedartists | 0:b567d56a59d7 | 1239 | |
embeddedartists | 0:b567d56a59d7 | 1240 | Bit depth is the amount of bits per pixel per color channel. So the total amount |
embeddedartists | 0:b567d56a59d7 | 1241 | of bits per pixel is: amount of channels * bitdepth. |
embeddedartists | 0:b567d56a59d7 | 1242 | |
embeddedartists | 0:b567d56a59d7 | 1243 | 6.2. color conversions |
embeddedartists | 0:b567d56a59d7 | 1244 | ---------------------- |
embeddedartists | 0:b567d56a59d7 | 1245 | |
embeddedartists | 0:b567d56a59d7 | 1246 | As explained in the sections about the encoder and decoder, you can specify |
embeddedartists | 0:b567d56a59d7 | 1247 | color types and bit depths in info_png and info_raw to change the default |
embeddedartists | 0:b567d56a59d7 | 1248 | behaviour. |
embeddedartists | 0:b567d56a59d7 | 1249 | |
embeddedartists | 0:b567d56a59d7 | 1250 | If, when decoding, you want the raw image to be something else than the default, |
embeddedartists | 0:b567d56a59d7 | 1251 | you need to set the color type and bit depth you want in the LodePNGColorMode, |
embeddedartists | 0:b567d56a59d7 | 1252 | or the parameters of the simple function of LodePNG you're using. |
embeddedartists | 0:b567d56a59d7 | 1253 | |
embeddedartists | 0:b567d56a59d7 | 1254 | If, when encoding, you use another color type than the default in the input |
embeddedartists | 0:b567d56a59d7 | 1255 | image, you need to specify its color type and bit depth in the LodePNGColorMode |
embeddedartists | 0:b567d56a59d7 | 1256 | of the raw image, or use the parameters of the simplefunction of LodePNG you're |
embeddedartists | 0:b567d56a59d7 | 1257 | using. |
embeddedartists | 0:b567d56a59d7 | 1258 | |
embeddedartists | 0:b567d56a59d7 | 1259 | If, when encoding, you don't want LodePNG to choose the output PNG color type |
embeddedartists | 0:b567d56a59d7 | 1260 | but control it yourself, you need to set auto_convert in the encoder settings |
embeddedartists | 0:b567d56a59d7 | 1261 | to LAC_NONE, and specify the color type you want in the LodePNGInfo of the |
embeddedartists | 0:b567d56a59d7 | 1262 | encoder. |
embeddedartists | 0:b567d56a59d7 | 1263 | |
embeddedartists | 0:b567d56a59d7 | 1264 | If you do any of the above, LodePNG may need to do a color conversion, which |
embeddedartists | 0:b567d56a59d7 | 1265 | follows the rules below, and may sometimes not be allowed. |
embeddedartists | 0:b567d56a59d7 | 1266 | |
embeddedartists | 0:b567d56a59d7 | 1267 | To avoid some confusion: |
embeddedartists | 0:b567d56a59d7 | 1268 | -the decoder converts from PNG to raw image |
embeddedartists | 0:b567d56a59d7 | 1269 | -the encoder converts from raw image to PNG |
embeddedartists | 0:b567d56a59d7 | 1270 | -the colortype and bitdepth in LodePNGColorMode info_raw, are those of the raw image |
embeddedartists | 0:b567d56a59d7 | 1271 | -the colortype and bitdepth in the color field of LodePNGInfo info_png, are those of the PNG |
embeddedartists | 0:b567d56a59d7 | 1272 | -when encoding, the color type in LodePNGInfo is ignored if auto_convert |
embeddedartists | 0:b567d56a59d7 | 1273 | is enabled, it is automatically generated instead |
embeddedartists | 0:b567d56a59d7 | 1274 | -when decoding, the color type in LodePNGInfo is set by the decoder to that of the original |
embeddedartists | 0:b567d56a59d7 | 1275 | PNG image, but it can be ignored since the raw image has the color type you requested instead |
embeddedartists | 0:b567d56a59d7 | 1276 | -if the color type of the LodePNGColorMode and PNG image aren't the same, a conversion |
embeddedartists | 0:b567d56a59d7 | 1277 | between the color types is done if the color types are supported. If it is not |
embeddedartists | 0:b567d56a59d7 | 1278 | supported, an error is returned. If the types are the same, no conversion is done. |
embeddedartists | 0:b567d56a59d7 | 1279 | -even though some conversions aren't supported, LodePNG supports loading PNGs from any |
embeddedartists | 0:b567d56a59d7 | 1280 | colortype and saving PNGs to any colortype, sometimes it just requires preparing |
embeddedartists | 0:b567d56a59d7 | 1281 | the raw image correctly before encoding. |
embeddedartists | 0:b567d56a59d7 | 1282 | -both encoder and decoder use the same color converter. |
embeddedartists | 0:b567d56a59d7 | 1283 | |
embeddedartists | 0:b567d56a59d7 | 1284 | Non supported color conversions: |
embeddedartists | 0:b567d56a59d7 | 1285 | -color to greyscale: no error is thrown, but the result will look ugly because |
embeddedartists | 0:b567d56a59d7 | 1286 | only the red channel is taken |
embeddedartists | 0:b567d56a59d7 | 1287 | -anything, to palette when that palette does not have that color in it: in this |
embeddedartists | 0:b567d56a59d7 | 1288 | case an error is thrown |
embeddedartists | 0:b567d56a59d7 | 1289 | |
embeddedartists | 0:b567d56a59d7 | 1290 | Supported color conversions: |
embeddedartists | 0:b567d56a59d7 | 1291 | -anything to 8-bit RGB, 8-bit RGBA, 16-bit RGB, 16-bit RGBA |
embeddedartists | 0:b567d56a59d7 | 1292 | -any grey or grey+alpha, to grey or grey+alpha |
embeddedartists | 0:b567d56a59d7 | 1293 | -anything to a palette, as long as the palette has the requested colors in it |
embeddedartists | 0:b567d56a59d7 | 1294 | -removing alpha channel |
embeddedartists | 0:b567d56a59d7 | 1295 | -higher to smaller bitdepth, and vice versa |
embeddedartists | 0:b567d56a59d7 | 1296 | |
embeddedartists | 0:b567d56a59d7 | 1297 | If you want no color conversion to be done: |
embeddedartists | 0:b567d56a59d7 | 1298 | -In the encoder, you can make it save a PNG with any color type by giving the |
embeddedartists | 0:b567d56a59d7 | 1299 | raw color mode and LodePNGInfo the same color mode, and setting auto_convert to |
embeddedartists | 0:b567d56a59d7 | 1300 | LAC_NO. |
embeddedartists | 0:b567d56a59d7 | 1301 | -In the decoder, you can make it store the pixel data in the same color type |
embeddedartists | 0:b567d56a59d7 | 1302 | as the PNG has, by setting the color_convert setting to false. Settings in |
embeddedartists | 0:b567d56a59d7 | 1303 | info_raw are then ignored. |
embeddedartists | 0:b567d56a59d7 | 1304 | |
embeddedartists | 0:b567d56a59d7 | 1305 | The function lodepng_convert does the color conversion. It is available in the |
embeddedartists | 0:b567d56a59d7 | 1306 | interface but normally isn't needed since the encoder and decoder already call |
embeddedartists | 0:b567d56a59d7 | 1307 | it. |
embeddedartists | 0:b567d56a59d7 | 1308 | |
embeddedartists | 0:b567d56a59d7 | 1309 | 6.3. padding bits |
embeddedartists | 0:b567d56a59d7 | 1310 | ----------------- |
embeddedartists | 0:b567d56a59d7 | 1311 | |
embeddedartists | 0:b567d56a59d7 | 1312 | In the PNG file format, if a less than 8-bit per pixel color type is used and the scanlines |
embeddedartists | 0:b567d56a59d7 | 1313 | have a bit amount that isn't a multiple of 8, then padding bits are used so that each |
embeddedartists | 0:b567d56a59d7 | 1314 | scanline starts at a fresh byte. But that is NOT true for the LodePNG raw input and output. |
embeddedartists | 0:b567d56a59d7 | 1315 | The raw input image you give to the encoder, and the raw output image you get from the decoder |
embeddedartists | 0:b567d56a59d7 | 1316 | will NOT have these padding bits, e.g. in the case of a 1-bit image with a width |
embeddedartists | 0:b567d56a59d7 | 1317 | of 7 pixels, the first pixel of the second scanline will the the 8th bit of the first byte, |
embeddedartists | 0:b567d56a59d7 | 1318 | not the first bit of a new byte. |
embeddedartists | 0:b567d56a59d7 | 1319 | |
embeddedartists | 0:b567d56a59d7 | 1320 | 6.4. A note about 16-bits per channel and endianness |
embeddedartists | 0:b567d56a59d7 | 1321 | ---------------------------------------------------- |
embeddedartists | 0:b567d56a59d7 | 1322 | |
embeddedartists | 0:b567d56a59d7 | 1323 | LodePNG uses unsigned char arrays for 16-bit per channel colors too, just like |
embeddedartists | 0:b567d56a59d7 | 1324 | for any other color format. The 16-bit values are stored in big endian (most |
embeddedartists | 0:b567d56a59d7 | 1325 | significant byte first) in these arrays. This is the opposite order of the |
embeddedartists | 0:b567d56a59d7 | 1326 | little endian used by x86 CPU's. |
embeddedartists | 0:b567d56a59d7 | 1327 | |
embeddedartists | 0:b567d56a59d7 | 1328 | LodePNG always uses big endian because the PNG file format does so internally. |
embeddedartists | 0:b567d56a59d7 | 1329 | Conversions to other formats than PNG uses internally are not supported by |
embeddedartists | 0:b567d56a59d7 | 1330 | LodePNG on purpose, there are myriads of formats, including endianness of 16-bit |
embeddedartists | 0:b567d56a59d7 | 1331 | colors, the order in which you store R, G, B and A, and so on. Supporting and |
embeddedartists | 0:b567d56a59d7 | 1332 | converting to/from all that is outside the scope of LodePNG. |
embeddedartists | 0:b567d56a59d7 | 1333 | |
embeddedartists | 0:b567d56a59d7 | 1334 | This may mean that, depending on your use case, you may want to convert the big |
embeddedartists | 0:b567d56a59d7 | 1335 | endian output of LodePNG to little endian with a for loop. This is certainly not |
embeddedartists | 0:b567d56a59d7 | 1336 | always needed, many applications and libraries support big endian 16-bit colors |
embeddedartists | 0:b567d56a59d7 | 1337 | anyway, but it means you cannot simply cast the unsigned char* buffer to an |
embeddedartists | 0:b567d56a59d7 | 1338 | unsigned short* buffer on x86 CPUs. |
embeddedartists | 0:b567d56a59d7 | 1339 | |
embeddedartists | 0:b567d56a59d7 | 1340 | |
embeddedartists | 0:b567d56a59d7 | 1341 | 7. error values |
embeddedartists | 0:b567d56a59d7 | 1342 | --------------- |
embeddedartists | 0:b567d56a59d7 | 1343 | |
embeddedartists | 0:b567d56a59d7 | 1344 | All functions in LodePNG that return an error code, return 0 if everything went |
embeddedartists | 0:b567d56a59d7 | 1345 | OK, or a non-zero code if there was an error. |
embeddedartists | 0:b567d56a59d7 | 1346 | |
embeddedartists | 0:b567d56a59d7 | 1347 | The meaning of the LodePNG error values can be retrieved with the function |
embeddedartists | 0:b567d56a59d7 | 1348 | lodepng_error_text: given the numerical error code, it returns a description |
embeddedartists | 0:b567d56a59d7 | 1349 | of the error in English as a string. |
embeddedartists | 0:b567d56a59d7 | 1350 | |
embeddedartists | 0:b567d56a59d7 | 1351 | Check the implementation of lodepng_error_text to see the meaning of each code. |
embeddedartists | 0:b567d56a59d7 | 1352 | |
embeddedartists | 0:b567d56a59d7 | 1353 | |
embeddedartists | 0:b567d56a59d7 | 1354 | 8. chunks and PNG editing |
embeddedartists | 0:b567d56a59d7 | 1355 | ------------------------- |
embeddedartists | 0:b567d56a59d7 | 1356 | |
embeddedartists | 0:b567d56a59d7 | 1357 | If you want to add extra chunks to a PNG you encode, or use LodePNG for a PNG |
embeddedartists | 0:b567d56a59d7 | 1358 | editor that should follow the rules about handling of unknown chunks, or if your |
embeddedartists | 0:b567d56a59d7 | 1359 | program is able to read other types of chunks than the ones handled by LodePNG, |
embeddedartists | 0:b567d56a59d7 | 1360 | then that's possible with the chunk functions of LodePNG. |
embeddedartists | 0:b567d56a59d7 | 1361 | |
embeddedartists | 0:b567d56a59d7 | 1362 | A PNG chunk has the following layout: |
embeddedartists | 0:b567d56a59d7 | 1363 | |
embeddedartists | 0:b567d56a59d7 | 1364 | 4 bytes length |
embeddedartists | 0:b567d56a59d7 | 1365 | 4 bytes type name |
embeddedartists | 0:b567d56a59d7 | 1366 | length bytes data |
embeddedartists | 0:b567d56a59d7 | 1367 | 4 bytes CRC |
embeddedartists | 0:b567d56a59d7 | 1368 | |
embeddedartists | 0:b567d56a59d7 | 1369 | 8.1. iterating through chunks |
embeddedartists | 0:b567d56a59d7 | 1370 | ----------------------------- |
embeddedartists | 0:b567d56a59d7 | 1371 | |
embeddedartists | 0:b567d56a59d7 | 1372 | If you have a buffer containing the PNG image data, then the first chunk (the |
embeddedartists | 0:b567d56a59d7 | 1373 | IHDR chunk) starts at byte number 8 of that buffer. The first 8 bytes are the |
embeddedartists | 0:b567d56a59d7 | 1374 | signature of the PNG and are not part of a chunk. But if you start at byte 8 |
embeddedartists | 0:b567d56a59d7 | 1375 | then you have a chunk, and can check the following things of it. |
embeddedartists | 0:b567d56a59d7 | 1376 | |
embeddedartists | 0:b567d56a59d7 | 1377 | NOTE: none of these functions check for memory buffer boundaries. To avoid |
embeddedartists | 0:b567d56a59d7 | 1378 | exploits, always make sure the buffer contains all the data of the chunks. |
embeddedartists | 0:b567d56a59d7 | 1379 | When using lodepng_chunk_next, make sure the returned value is within the |
embeddedartists | 0:b567d56a59d7 | 1380 | allocated memory. |
embeddedartists | 0:b567d56a59d7 | 1381 | |
embeddedartists | 0:b567d56a59d7 | 1382 | unsigned lodepng_chunk_length(const unsigned char* chunk): |
embeddedartists | 0:b567d56a59d7 | 1383 | |
embeddedartists | 0:b567d56a59d7 | 1384 | Get the length of the chunk's data. The total chunk length is this length + 12. |
embeddedartists | 0:b567d56a59d7 | 1385 | |
embeddedartists | 0:b567d56a59d7 | 1386 | void lodepng_chunk_type(char type[5], const unsigned char* chunk): |
embeddedartists | 0:b567d56a59d7 | 1387 | unsigned char lodepng_chunk_type_equals(const unsigned char* chunk, const char* type): |
embeddedartists | 0:b567d56a59d7 | 1388 | |
embeddedartists | 0:b567d56a59d7 | 1389 | Get the type of the chunk or compare if it's a certain type |
embeddedartists | 0:b567d56a59d7 | 1390 | |
embeddedartists | 0:b567d56a59d7 | 1391 | unsigned char lodepng_chunk_critical(const unsigned char* chunk): |
embeddedartists | 0:b567d56a59d7 | 1392 | unsigned char lodepng_chunk_private(const unsigned char* chunk): |
embeddedartists | 0:b567d56a59d7 | 1393 | unsigned char lodepng_chunk_safetocopy(const unsigned char* chunk): |
embeddedartists | 0:b567d56a59d7 | 1394 | |
embeddedartists | 0:b567d56a59d7 | 1395 | Check if the chunk is critical in the PNG standard (only IHDR, PLTE, IDAT and IEND are). |
embeddedartists | 0:b567d56a59d7 | 1396 | Check if the chunk is private (public chunks are part of the standard, private ones not). |
embeddedartists | 0:b567d56a59d7 | 1397 | Check if the chunk is safe to copy. If it's not, then, when modifying data in a critical |
embeddedartists | 0:b567d56a59d7 | 1398 | chunk, unsafe to copy chunks of the old image may NOT be saved in the new one if your |
embeddedartists | 0:b567d56a59d7 | 1399 | program doesn't handle that type of unknown chunk. |
embeddedartists | 0:b567d56a59d7 | 1400 | |
embeddedartists | 0:b567d56a59d7 | 1401 | unsigned char* lodepng_chunk_data(unsigned char* chunk): |
embeddedartists | 0:b567d56a59d7 | 1402 | const unsigned char* lodepng_chunk_data_const(const unsigned char* chunk): |
embeddedartists | 0:b567d56a59d7 | 1403 | |
embeddedartists | 0:b567d56a59d7 | 1404 | Get a pointer to the start of the data of the chunk. |
embeddedartists | 0:b567d56a59d7 | 1405 | |
embeddedartists | 0:b567d56a59d7 | 1406 | unsigned lodepng_chunk_check_crc(const unsigned char* chunk): |
embeddedartists | 0:b567d56a59d7 | 1407 | void lodepng_chunk_generate_crc(unsigned char* chunk): |
embeddedartists | 0:b567d56a59d7 | 1408 | |
embeddedartists | 0:b567d56a59d7 | 1409 | Check if the crc is correct or generate a correct one. |
embeddedartists | 0:b567d56a59d7 | 1410 | |
embeddedartists | 0:b567d56a59d7 | 1411 | unsigned char* lodepng_chunk_next(unsigned char* chunk): |
embeddedartists | 0:b567d56a59d7 | 1412 | const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk): |
embeddedartists | 0:b567d56a59d7 | 1413 | |
embeddedartists | 0:b567d56a59d7 | 1414 | Iterate to the next chunk. This works if you have a buffer with consecutive chunks. Note that these |
embeddedartists | 0:b567d56a59d7 | 1415 | functions do no boundary checking of the allocated data whatsoever, so make sure there is enough |
embeddedartists | 0:b567d56a59d7 | 1416 | data available in the buffer to be able to go to the next chunk. |
embeddedartists | 0:b567d56a59d7 | 1417 | |
embeddedartists | 0:b567d56a59d7 | 1418 | unsigned lodepng_chunk_append(unsigned char** out, size_t* outlength, const unsigned char* chunk): |
embeddedartists | 0:b567d56a59d7 | 1419 | unsigned lodepng_chunk_create(unsigned char** out, size_t* outlength, unsigned length, |
embeddedartists | 0:b567d56a59d7 | 1420 | const char* type, const unsigned char* data): |
embeddedartists | 0:b567d56a59d7 | 1421 | |
embeddedartists | 0:b567d56a59d7 | 1422 | These functions are used to create new chunks that are appended to the data in *out that has |
embeddedartists | 0:b567d56a59d7 | 1423 | length *outlength. The append function appends an existing chunk to the new data. The create |
embeddedartists | 0:b567d56a59d7 | 1424 | function creates a new chunk with the given parameters and appends it. Type is the 4-letter |
embeddedartists | 0:b567d56a59d7 | 1425 | name of the chunk. |
embeddedartists | 0:b567d56a59d7 | 1426 | |
embeddedartists | 0:b567d56a59d7 | 1427 | 8.2. chunks in info_png |
embeddedartists | 0:b567d56a59d7 | 1428 | ----------------------- |
embeddedartists | 0:b567d56a59d7 | 1429 | |
embeddedartists | 0:b567d56a59d7 | 1430 | The LodePNGInfo struct contains fields with the unknown chunk in it. It has 3 |
embeddedartists | 0:b567d56a59d7 | 1431 | buffers (each with size) to contain 3 types of unknown chunks: |
embeddedartists | 0:b567d56a59d7 | 1432 | the ones that come before the PLTE chunk, the ones that come between the PLTE |
embeddedartists | 0:b567d56a59d7 | 1433 | and the IDAT chunks, and the ones that come after the IDAT chunks. |
embeddedartists | 0:b567d56a59d7 | 1434 | It's necessary to make the distionction between these 3 cases because the PNG |
embeddedartists | 0:b567d56a59d7 | 1435 | standard forces to keep the ordering of unknown chunks compared to the critical |
embeddedartists | 0:b567d56a59d7 | 1436 | chunks, but does not force any other ordering rules. |
embeddedartists | 0:b567d56a59d7 | 1437 | |
embeddedartists | 0:b567d56a59d7 | 1438 | info_png.unknown_chunks_data[0] is the chunks before PLTE |
embeddedartists | 0:b567d56a59d7 | 1439 | info_png.unknown_chunks_data[1] is the chunks after PLTE, before IDAT |
embeddedartists | 0:b567d56a59d7 | 1440 | info_png.unknown_chunks_data[2] is the chunks after IDAT |
embeddedartists | 0:b567d56a59d7 | 1441 | |
embeddedartists | 0:b567d56a59d7 | 1442 | The chunks in these 3 buffers can be iterated through and read by using the same |
embeddedartists | 0:b567d56a59d7 | 1443 | way described in the previous subchapter. |
embeddedartists | 0:b567d56a59d7 | 1444 | |
embeddedartists | 0:b567d56a59d7 | 1445 | When using the decoder to decode a PNG, you can make it store all unknown chunks |
embeddedartists | 0:b567d56a59d7 | 1446 | if you set the option settings.remember_unknown_chunks to 1. By default, this |
embeddedartists | 0:b567d56a59d7 | 1447 | option is off (0). |
embeddedartists | 0:b567d56a59d7 | 1448 | |
embeddedartists | 0:b567d56a59d7 | 1449 | The encoder will always encode unknown chunks that are stored in the info_png. |
embeddedartists | 0:b567d56a59d7 | 1450 | If you need it to add a particular chunk that isn't known by LodePNG, you can |
embeddedartists | 0:b567d56a59d7 | 1451 | use lodepng_chunk_append or lodepng_chunk_create to the chunk data in |
embeddedartists | 0:b567d56a59d7 | 1452 | info_png.unknown_chunks_data[x]. |
embeddedartists | 0:b567d56a59d7 | 1453 | |
embeddedartists | 0:b567d56a59d7 | 1454 | Chunks that are known by LodePNG should not be added in that way. E.g. to make |
embeddedartists | 0:b567d56a59d7 | 1455 | LodePNG add a bKGD chunk, set background_defined to true and add the correct |
embeddedartists | 0:b567d56a59d7 | 1456 | parameters there instead. |
embeddedartists | 0:b567d56a59d7 | 1457 | |
embeddedartists | 0:b567d56a59d7 | 1458 | |
embeddedartists | 0:b567d56a59d7 | 1459 | 9. compiler support |
embeddedartists | 0:b567d56a59d7 | 1460 | ------------------- |
embeddedartists | 0:b567d56a59d7 | 1461 | |
embeddedartists | 0:b567d56a59d7 | 1462 | No libraries other than the current standard C library are needed to compile |
embeddedartists | 0:b567d56a59d7 | 1463 | LodePNG. For the C++ version, only the standard C++ library is needed on top. |
embeddedartists | 0:b567d56a59d7 | 1464 | Add the files lodepng.c(pp) and lodepng.h to your project, include |
embeddedartists | 0:b567d56a59d7 | 1465 | lodepng.h where needed, and your program can read/write PNG files. |
embeddedartists | 0:b567d56a59d7 | 1466 | |
embeddedartists | 0:b567d56a59d7 | 1467 | If performance is important, use optimization when compiling! For both the |
embeddedartists | 0:b567d56a59d7 | 1468 | encoder and decoder, this makes a large difference. |
embeddedartists | 0:b567d56a59d7 | 1469 | |
embeddedartists | 0:b567d56a59d7 | 1470 | Make sure that LodePNG is compiled with the same compiler of the same version |
embeddedartists | 0:b567d56a59d7 | 1471 | and with the same settings as the rest of the program, or the interfaces with |
embeddedartists | 0:b567d56a59d7 | 1472 | std::vectors and std::strings in C++ can be incompatible. |
embeddedartists | 0:b567d56a59d7 | 1473 | |
embeddedartists | 0:b567d56a59d7 | 1474 | CHAR_BITS must be 8 or higher, because LodePNG uses unsigned chars for octets. |
embeddedartists | 0:b567d56a59d7 | 1475 | |
embeddedartists | 0:b567d56a59d7 | 1476 | *) gcc and g++ |
embeddedartists | 0:b567d56a59d7 | 1477 | |
embeddedartists | 0:b567d56a59d7 | 1478 | LodePNG is developed in gcc so this compiler is natively supported. It gives no |
embeddedartists | 0:b567d56a59d7 | 1479 | warnings with compiler options "-Wall -Wextra -pedantic -ansi", with gcc and g++ |
embeddedartists | 0:b567d56a59d7 | 1480 | version 4.7.1 on Linux, 32-bit and 64-bit. |
embeddedartists | 0:b567d56a59d7 | 1481 | |
embeddedartists | 0:b567d56a59d7 | 1482 | *) Mingw |
embeddedartists | 0:b567d56a59d7 | 1483 | |
embeddedartists | 0:b567d56a59d7 | 1484 | The Mingw compiler (a port of gcc) for Windows is fully supported by LodePNG. |
embeddedartists | 0:b567d56a59d7 | 1485 | |
embeddedartists | 0:b567d56a59d7 | 1486 | *) Visual Studio 2005 and up, Visual C++ Express Edition 2005 and up |
embeddedartists | 0:b567d56a59d7 | 1487 | |
embeddedartists | 0:b567d56a59d7 | 1488 | Visual Studio may give warnings about 'fopen' being deprecated. A multiplatform library |
embeddedartists | 0:b567d56a59d7 | 1489 | can't support the proposed Visual Studio alternative however, so LodePNG keeps using |
embeddedartists | 0:b567d56a59d7 | 1490 | fopen. If you don't want to see the deprecated warnings, put this on top of lodepng.h |
embeddedartists | 0:b567d56a59d7 | 1491 | before the inclusions: |
embeddedartists | 0:b567d56a59d7 | 1492 | #define _CRT_SECURE_NO_DEPRECATE |
embeddedartists | 0:b567d56a59d7 | 1493 | |
embeddedartists | 0:b567d56a59d7 | 1494 | Other than the above warnings, LodePNG should be warning-free with warning |
embeddedartists | 0:b567d56a59d7 | 1495 | level 3 (W3). Warning level 4 (W4) will give warnings about integer conversions. |
embeddedartists | 0:b567d56a59d7 | 1496 | I'm not planning to resolve these warnings. To get rid of them, let Visual |
embeddedartists | 0:b567d56a59d7 | 1497 | Studio use warning level W3 for lodepng.cpp only: right click lodepng.cpp, |
embeddedartists | 0:b567d56a59d7 | 1498 | Properties, C/C++, General, Warning Level: Level 3 (/W3). |
embeddedartists | 0:b567d56a59d7 | 1499 | |
embeddedartists | 0:b567d56a59d7 | 1500 | Visual Studio may want "stdafx.h" files to be included in each source file and |
embeddedartists | 0:b567d56a59d7 | 1501 | give an error "unexpected end of file while looking for precompiled header". |
embeddedartists | 0:b567d56a59d7 | 1502 | That is not standard C++ and will not be added to the stock LodePNG. You can |
embeddedartists | 0:b567d56a59d7 | 1503 | disable it for lodepng.cpp only by right clicking it, Properties, C/C++, |
embeddedartists | 0:b567d56a59d7 | 1504 | Precompiled Headers, and set it to Not Using Precompiled Headers there. |
embeddedartists | 0:b567d56a59d7 | 1505 | |
embeddedartists | 0:b567d56a59d7 | 1506 | *) Visual Studio 6.0 |
embeddedartists | 0:b567d56a59d7 | 1507 | |
embeddedartists | 0:b567d56a59d7 | 1508 | LodePNG support for Visual Studio 6.0 is not guaranteed because VS6 doesn't |
embeddedartists | 0:b567d56a59d7 | 1509 | follow the C++ standard correctly. |
embeddedartists | 0:b567d56a59d7 | 1510 | |
embeddedartists | 0:b567d56a59d7 | 1511 | *) Comeau C/C++ |
embeddedartists | 0:b567d56a59d7 | 1512 | |
embeddedartists | 0:b567d56a59d7 | 1513 | Vesion 20070107 compiles without problems on the Comeau C/C++ Online Test Drive |
embeddedartists | 0:b567d56a59d7 | 1514 | at http://www.comeaucomputing.com/tryitout in both C90 and C++ mode. |
embeddedartists | 0:b567d56a59d7 | 1515 | |
embeddedartists | 0:b567d56a59d7 | 1516 | *) Compilers on Macintosh |
embeddedartists | 0:b567d56a59d7 | 1517 | |
embeddedartists | 0:b567d56a59d7 | 1518 | LodePNG has been reported to work both with the gcc and LLVM for Macintosh, both |
embeddedartists | 0:b567d56a59d7 | 1519 | for C and C++. |
embeddedartists | 0:b567d56a59d7 | 1520 | |
embeddedartists | 0:b567d56a59d7 | 1521 | *) Other Compilers |
embeddedartists | 0:b567d56a59d7 | 1522 | |
embeddedartists | 0:b567d56a59d7 | 1523 | If you encounter problems on other compilers, feel free to let me know and I may |
embeddedartists | 0:b567d56a59d7 | 1524 | try to fix it if the compiler is modern standards complient. |
embeddedartists | 0:b567d56a59d7 | 1525 | |
embeddedartists | 0:b567d56a59d7 | 1526 | |
embeddedartists | 0:b567d56a59d7 | 1527 | 10. examples |
embeddedartists | 0:b567d56a59d7 | 1528 | ------------ |
embeddedartists | 0:b567d56a59d7 | 1529 | |
embeddedartists | 0:b567d56a59d7 | 1530 | This decoder example shows the most basic usage of LodePNG. More complex |
embeddedartists | 0:b567d56a59d7 | 1531 | examples can be found on the LodePNG website. |
embeddedartists | 0:b567d56a59d7 | 1532 | |
embeddedartists | 0:b567d56a59d7 | 1533 | 10.1. decoder C++ example |
embeddedartists | 0:b567d56a59d7 | 1534 | ------------------------- |
embeddedartists | 0:b567d56a59d7 | 1535 | |
embeddedartists | 0:b567d56a59d7 | 1536 | #include "lodepng.h" |
embeddedartists | 0:b567d56a59d7 | 1537 | #include <iostream> |
embeddedartists | 0:b567d56a59d7 | 1538 | |
embeddedartists | 0:b567d56a59d7 | 1539 | int main(int argc, char *argv[]) |
embeddedartists | 0:b567d56a59d7 | 1540 | { |
embeddedartists | 0:b567d56a59d7 | 1541 | const char* filename = argc > 1 ? argv[1] : "test.png"; |
embeddedartists | 0:b567d56a59d7 | 1542 | |
embeddedartists | 0:b567d56a59d7 | 1543 | //load and decode |
embeddedartists | 0:b567d56a59d7 | 1544 | std::vector<unsigned char> image; |
embeddedartists | 0:b567d56a59d7 | 1545 | unsigned width, height; |
embeddedartists | 0:b567d56a59d7 | 1546 | unsigned error = lodepng::decode(image, width, height, filename); |
embeddedartists | 0:b567d56a59d7 | 1547 | |
embeddedartists | 0:b567d56a59d7 | 1548 | //if there's an error, display it |
embeddedartists | 0:b567d56a59d7 | 1549 | if(error) std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl; |
embeddedartists | 0:b567d56a59d7 | 1550 | |
embeddedartists | 0:b567d56a59d7 | 1551 | //the pixels are now in the vector "image", 4 bytes per pixel, ordered RGBARGBA..., use it as texture, draw it, ... |
embeddedartists | 0:b567d56a59d7 | 1552 | } |
embeddedartists | 0:b567d56a59d7 | 1553 | |
embeddedartists | 0:b567d56a59d7 | 1554 | 10.2. decoder C example |
embeddedartists | 0:b567d56a59d7 | 1555 | ----------------------- |
embeddedartists | 0:b567d56a59d7 | 1556 | |
embeddedartists | 0:b567d56a59d7 | 1557 | #include "lodepng.h" |
embeddedartists | 0:b567d56a59d7 | 1558 | |
embeddedartists | 0:b567d56a59d7 | 1559 | int main(int argc, char *argv[]) |
embeddedartists | 0:b567d56a59d7 | 1560 | { |
embeddedartists | 0:b567d56a59d7 | 1561 | unsigned error; |
embeddedartists | 0:b567d56a59d7 | 1562 | unsigned char* image; |
embeddedartists | 0:b567d56a59d7 | 1563 | size_t width, height; |
embeddedartists | 0:b567d56a59d7 | 1564 | const char* filename = argc > 1 ? argv[1] : "test.png"; |
embeddedartists | 0:b567d56a59d7 | 1565 | |
embeddedartists | 0:b567d56a59d7 | 1566 | error = lodepng_decode32_file(&image, &width, &height, filename); |
embeddedartists | 0:b567d56a59d7 | 1567 | |
embeddedartists | 0:b567d56a59d7 | 1568 | if(error) printf("decoder error %u: %s\n", error, lodepng_error_text(error)); |
embeddedartists | 0:b567d56a59d7 | 1569 | |
embeddedartists | 0:b567d56a59d7 | 1570 | / * use image here * / |
embeddedartists | 0:b567d56a59d7 | 1571 | |
embeddedartists | 0:b567d56a59d7 | 1572 | free(image); |
embeddedartists | 0:b567d56a59d7 | 1573 | return 0; |
embeddedartists | 0:b567d56a59d7 | 1574 | } |
embeddedartists | 0:b567d56a59d7 | 1575 | |
embeddedartists | 0:b567d56a59d7 | 1576 | |
embeddedartists | 0:b567d56a59d7 | 1577 | 11. changes |
embeddedartists | 0:b567d56a59d7 | 1578 | ----------- |
embeddedartists | 0:b567d56a59d7 | 1579 | |
embeddedartists | 0:b567d56a59d7 | 1580 | The version number of LodePNG is the date of the change given in the format |
embeddedartists | 0:b567d56a59d7 | 1581 | yyyymmdd. |
embeddedartists | 0:b567d56a59d7 | 1582 | |
embeddedartists | 0:b567d56a59d7 | 1583 | Some changes aren't backwards compatible. Those are indicated with a (!) |
embeddedartists | 0:b567d56a59d7 | 1584 | symbol. |
embeddedartists | 0:b567d56a59d7 | 1585 | |
embeddedartists | 0:b567d56a59d7 | 1586 | *) 22 dec 2013: Power of two windowsize required for optimization. |
embeddedartists | 0:b567d56a59d7 | 1587 | *) 15 apr 2013: Fixed bug with LAC_ALPHA and color key. |
embeddedartists | 0:b567d56a59d7 | 1588 | *) 25 mar 2013: Added an optional feature to ignore some PNG errors (fix_png). |
embeddedartists | 0:b567d56a59d7 | 1589 | *) 11 mar 2013 (!): Bugfix with custom free. Changed from "my" to "lodepng_" |
embeddedartists | 0:b567d56a59d7 | 1590 | prefix for the custom allocators and made it possible with a new #define to |
embeddedartists | 0:b567d56a59d7 | 1591 | use custom ones in your project without needing to change lodepng's code. |
embeddedartists | 0:b567d56a59d7 | 1592 | *) 28 jan 2013: Bugfix with color key. |
embeddedartists | 0:b567d56a59d7 | 1593 | *) 27 okt 2012: Tweaks in text chunk keyword length error handling. |
embeddedartists | 0:b567d56a59d7 | 1594 | *) 8 okt 2012 (!): Added new filter strategy (entropy) and new auto color mode. |
embeddedartists | 0:b567d56a59d7 | 1595 | (no palette). Better deflate tree encoding. New compression tweak settings. |
embeddedartists | 0:b567d56a59d7 | 1596 | Faster color conversions while decoding. Some internal cleanups. |
embeddedartists | 0:b567d56a59d7 | 1597 | *) 23 sep 2012: Reduced warnings in Visual Studio a little bit. |
embeddedartists | 0:b567d56a59d7 | 1598 | *) 1 sep 2012 (!): Removed #define's for giving custom (de)compression functions |
embeddedartists | 0:b567d56a59d7 | 1599 | and made it work with function pointers instead. |
embeddedartists | 0:b567d56a59d7 | 1600 | *) 23 jun 2012: Added more filter strategies. Made it easier to use custom alloc |
embeddedartists | 0:b567d56a59d7 | 1601 | and free functions and toggle #defines from compiler flags. Small fixes. |
embeddedartists | 0:b567d56a59d7 | 1602 | *) 6 may 2012 (!): Made plugging in custom zlib/deflate functions more flexible. |
embeddedartists | 0:b567d56a59d7 | 1603 | *) 22 apr 2012 (!): Made interface more consistent, renaming a lot. Removed |
embeddedartists | 0:b567d56a59d7 | 1604 | redundant C++ codec classes. Reduced amount of structs. Everything changed, |
embeddedartists | 0:b567d56a59d7 | 1605 | but it is cleaner now imho and functionality remains the same. Also fixed |
embeddedartists | 0:b567d56a59d7 | 1606 | several bugs and shrinked the implementation code. Made new samples. |
embeddedartists | 0:b567d56a59d7 | 1607 | *) 6 nov 2011 (!): By default, the encoder now automatically chooses the best |
embeddedartists | 0:b567d56a59d7 | 1608 | PNG color model and bit depth, based on the amount and type of colors of the |
embeddedartists | 0:b567d56a59d7 | 1609 | raw image. For this, autoLeaveOutAlphaChannel replaced by auto_choose_color. |
embeddedartists | 0:b567d56a59d7 | 1610 | *) 9 okt 2011: simpler hash chain implementation for the encoder. |
embeddedartists | 0:b567d56a59d7 | 1611 | *) 8 sep 2011: lz77 encoder lazy matching instead of greedy matching. |
embeddedartists | 0:b567d56a59d7 | 1612 | *) 23 aug 2011: tweaked the zlib compression parameters after benchmarking. |
embeddedartists | 0:b567d56a59d7 | 1613 | A bug with the PNG filtertype heuristic was fixed, so that it chooses much |
embeddedartists | 0:b567d56a59d7 | 1614 | better ones (it's quite significant). A setting to do an experimental, slow, |
embeddedartists | 0:b567d56a59d7 | 1615 | brute force search for PNG filter types is added. |
embeddedartists | 0:b567d56a59d7 | 1616 | *) 17 aug 2011 (!): changed some C zlib related function names. |
embeddedartists | 0:b567d56a59d7 | 1617 | *) 16 aug 2011: made the code less wide (max 120 characters per line). |
embeddedartists | 0:b567d56a59d7 | 1618 | *) 17 apr 2011: code cleanup. Bugfixes. Convert low to 16-bit per sample colors. |
embeddedartists | 0:b567d56a59d7 | 1619 | *) 21 feb 2011: fixed compiling for C90. Fixed compiling with sections disabled. |
embeddedartists | 0:b567d56a59d7 | 1620 | *) 11 dec 2010: encoding is made faster, based on suggestion by Peter Eastman |
embeddedartists | 0:b567d56a59d7 | 1621 | to optimize long sequences of zeros. |
embeddedartists | 0:b567d56a59d7 | 1622 | *) 13 nov 2010: added LodePNG_InfoColor_hasPaletteAlpha and |
embeddedartists | 0:b567d56a59d7 | 1623 | LodePNG_InfoColor_canHaveAlpha functions for convenience. |
embeddedartists | 0:b567d56a59d7 | 1624 | *) 7 nov 2010: added LodePNG_error_text function to get error code description. |
embeddedartists | 0:b567d56a59d7 | 1625 | *) 30 okt 2010: made decoding slightly faster |
embeddedartists | 0:b567d56a59d7 | 1626 | *) 26 okt 2010: (!) changed some C function and struct names (more consistent). |
embeddedartists | 0:b567d56a59d7 | 1627 | Reorganized the documentation and the declaration order in the header. |
embeddedartists | 0:b567d56a59d7 | 1628 | *) 08 aug 2010: only changed some comments and external samples. |
embeddedartists | 0:b567d56a59d7 | 1629 | *) 05 jul 2010: fixed bug thanks to warnings in the new gcc version. |
embeddedartists | 0:b567d56a59d7 | 1630 | *) 14 mar 2010: fixed bug where too much memory was allocated for char buffers. |
embeddedartists | 0:b567d56a59d7 | 1631 | *) 02 sep 2008: fixed bug where it could create empty tree that linux apps could |
embeddedartists | 0:b567d56a59d7 | 1632 | read by ignoring the problem but windows apps couldn't. |
embeddedartists | 0:b567d56a59d7 | 1633 | *) 06 jun 2008: added more error checks for out of memory cases. |
embeddedartists | 0:b567d56a59d7 | 1634 | *) 26 apr 2008: added a few more checks here and there to ensure more safety. |
embeddedartists | 0:b567d56a59d7 | 1635 | *) 06 mar 2008: crash with encoding of strings fixed |
embeddedartists | 0:b567d56a59d7 | 1636 | *) 02 feb 2008: support for international text chunks added (iTXt) |
embeddedartists | 0:b567d56a59d7 | 1637 | *) 23 jan 2008: small cleanups, and #defines to divide code in sections |
embeddedartists | 0:b567d56a59d7 | 1638 | *) 20 jan 2008: support for unknown chunks allowing using LodePNG for an editor. |
embeddedartists | 0:b567d56a59d7 | 1639 | *) 18 jan 2008: support for tIME and pHYs chunks added to encoder and decoder. |
embeddedartists | 0:b567d56a59d7 | 1640 | *) 17 jan 2008: ability to encode and decode compressed zTXt chunks added |
embeddedartists | 0:b567d56a59d7 | 1641 | Also vareous fixes, such as in the deflate and the padding bits code. |
embeddedartists | 0:b567d56a59d7 | 1642 | *) 13 jan 2008: Added ability to encode Adam7-interlaced images. Improved |
embeddedartists | 0:b567d56a59d7 | 1643 | filtering code of encoder. |
embeddedartists | 0:b567d56a59d7 | 1644 | *) 07 jan 2008: (!) changed LodePNG to use ISO C90 instead of C++. A |
embeddedartists | 0:b567d56a59d7 | 1645 | C++ wrapper around this provides an interface almost identical to before. |
embeddedartists | 0:b567d56a59d7 | 1646 | Having LodePNG be pure ISO C90 makes it more portable. The C and C++ code |
embeddedartists | 0:b567d56a59d7 | 1647 | are together in these files but it works both for C and C++ compilers. |
embeddedartists | 0:b567d56a59d7 | 1648 | *) 29 dec 2007: (!) changed most integer types to unsigned int + other tweaks |
embeddedartists | 0:b567d56a59d7 | 1649 | *) 30 aug 2007: bug fixed which makes this Borland C++ compatible |
embeddedartists | 0:b567d56a59d7 | 1650 | *) 09 aug 2007: some VS2005 warnings removed again |
embeddedartists | 0:b567d56a59d7 | 1651 | *) 21 jul 2007: deflate code placed in new namespace separate from zlib code |
embeddedartists | 0:b567d56a59d7 | 1652 | *) 08 jun 2007: fixed bug with 2- and 4-bit color, and small interlaced images |
embeddedartists | 0:b567d56a59d7 | 1653 | *) 04 jun 2007: improved support for Visual Studio 2005: crash with accessing |
embeddedartists | 0:b567d56a59d7 | 1654 | invalid std::vector element [0] fixed, and level 3 and 4 warnings removed |
embeddedartists | 0:b567d56a59d7 | 1655 | *) 02 jun 2007: made the encoder add a tag with version by default |
embeddedartists | 0:b567d56a59d7 | 1656 | *) 27 may 2007: zlib and png code separated (but still in the same file), |
embeddedartists | 0:b567d56a59d7 | 1657 | simple encoder/decoder functions added for more simple usage cases |
embeddedartists | 0:b567d56a59d7 | 1658 | *) 19 may 2007: minor fixes, some code cleaning, new error added (error 69), |
embeddedartists | 0:b567d56a59d7 | 1659 | moved some examples from here to lodepng_examples.cpp |
embeddedartists | 0:b567d56a59d7 | 1660 | *) 12 may 2007: palette decoding bug fixed |
embeddedartists | 0:b567d56a59d7 | 1661 | *) 24 apr 2007: changed the license from BSD to the zlib license |
embeddedartists | 0:b567d56a59d7 | 1662 | *) 11 mar 2007: very simple addition: ability to encode bKGD chunks. |
embeddedartists | 0:b567d56a59d7 | 1663 | *) 04 mar 2007: (!) tEXt chunk related fixes, and support for encoding |
embeddedartists | 0:b567d56a59d7 | 1664 | palettized PNG images. Plus little interface change with palette and texts. |
embeddedartists | 0:b567d56a59d7 | 1665 | *) 03 mar 2007: Made it encode dynamic Huffman shorter with repeat codes. |
embeddedartists | 0:b567d56a59d7 | 1666 | Fixed a bug where the end code of a block had length 0 in the Huffman tree. |
embeddedartists | 0:b567d56a59d7 | 1667 | *) 26 feb 2007: Huffman compression with dynamic trees (BTYPE 2) now implemented |
embeddedartists | 0:b567d56a59d7 | 1668 | and supported by the encoder, resulting in smaller PNGs at the output. |
embeddedartists | 0:b567d56a59d7 | 1669 | *) 27 jan 2007: Made the Adler-32 test faster so that a timewaste is gone. |
embeddedartists | 0:b567d56a59d7 | 1670 | *) 24 jan 2007: gave encoder an error interface. Added color conversion from any |
embeddedartists | 0:b567d56a59d7 | 1671 | greyscale type to 8-bit greyscale with or without alpha. |
embeddedartists | 0:b567d56a59d7 | 1672 | *) 21 jan 2007: (!) Totally changed the interface. It allows more color types |
embeddedartists | 0:b567d56a59d7 | 1673 | to convert to and is more uniform. See the manual for how it works now. |
embeddedartists | 0:b567d56a59d7 | 1674 | *) 07 jan 2007: Some cleanup & fixes, and a few changes over the last days: |
embeddedartists | 0:b567d56a59d7 | 1675 | encode/decode custom tEXt chunks, separate classes for zlib & deflate, and |
embeddedartists | 0:b567d56a59d7 | 1676 | at last made the decoder give errors for incorrect Adler32 or Crc. |
embeddedartists | 0:b567d56a59d7 | 1677 | *) 01 jan 2007: Fixed bug with encoding PNGs with less than 8 bits per channel. |
embeddedartists | 0:b567d56a59d7 | 1678 | *) 29 dec 2006: Added support for encoding images without alpha channel, and |
embeddedartists | 0:b567d56a59d7 | 1679 | cleaned out code as well as making certain parts faster. |
embeddedartists | 0:b567d56a59d7 | 1680 | *) 28 dec 2006: Added "Settings" to the encoder. |
embeddedartists | 0:b567d56a59d7 | 1681 | *) 26 dec 2006: The encoder now does LZ77 encoding and produces much smaller files now. |
embeddedartists | 0:b567d56a59d7 | 1682 | Removed some code duplication in the decoder. Fixed little bug in an example. |
embeddedartists | 0:b567d56a59d7 | 1683 | *) 09 dec 2006: (!) Placed output parameters of public functions as first parameter. |
embeddedartists | 0:b567d56a59d7 | 1684 | Fixed a bug of the decoder with 16-bit per color. |
embeddedartists | 0:b567d56a59d7 | 1685 | *) 15 okt 2006: Changed documentation structure |
embeddedartists | 0:b567d56a59d7 | 1686 | *) 09 okt 2006: Encoder class added. It encodes a valid PNG image from the |
embeddedartists | 0:b567d56a59d7 | 1687 | given image buffer, however for now it's not compressed. |
embeddedartists | 0:b567d56a59d7 | 1688 | *) 08 sep 2006: (!) Changed to interface with a Decoder class |
embeddedartists | 0:b567d56a59d7 | 1689 | *) 30 jul 2006: (!) LodePNG_InfoPng , width and height are now retrieved in different |
embeddedartists | 0:b567d56a59d7 | 1690 | way. Renamed decodePNG to decodePNGGeneric. |
embeddedartists | 0:b567d56a59d7 | 1691 | *) 29 jul 2006: (!) Changed the interface: image info is now returned as a |
embeddedartists | 0:b567d56a59d7 | 1692 | struct of type LodePNG::LodePNG_Info, instead of a vector, which was a bit clumsy. |
embeddedartists | 0:b567d56a59d7 | 1693 | *) 28 jul 2006: Cleaned the code and added new error checks. |
embeddedartists | 0:b567d56a59d7 | 1694 | Corrected terminology "deflate" into "inflate". |
embeddedartists | 0:b567d56a59d7 | 1695 | *) 23 jun 2006: Added SDL example in the documentation in the header, this |
embeddedartists | 0:b567d56a59d7 | 1696 | example allows easy debugging by displaying the PNG and its transparency. |
embeddedartists | 0:b567d56a59d7 | 1697 | *) 22 jun 2006: (!) Changed way to obtain error value. Added |
embeddedartists | 0:b567d56a59d7 | 1698 | loadFile function for convenience. Made decodePNG32 faster. |
embeddedartists | 0:b567d56a59d7 | 1699 | *) 21 jun 2006: (!) Changed type of info vector to unsigned. |
embeddedartists | 0:b567d56a59d7 | 1700 | Changed position of palette in info vector. Fixed an important bug that |
embeddedartists | 0:b567d56a59d7 | 1701 | happened on PNGs with an uncompressed block. |
embeddedartists | 0:b567d56a59d7 | 1702 | *) 16 jun 2006: Internally changed unsigned into unsigned where |
embeddedartists | 0:b567d56a59d7 | 1703 | needed, and performed some optimizations. |
embeddedartists | 0:b567d56a59d7 | 1704 | *) 07 jun 2006: (!) Renamed functions to decodePNG and placed them |
embeddedartists | 0:b567d56a59d7 | 1705 | in LodePNG namespace. Changed the order of the parameters. Rewrote the |
embeddedartists | 0:b567d56a59d7 | 1706 | documentation in the header. Renamed files to lodepng.cpp and lodepng.h |
embeddedartists | 0:b567d56a59d7 | 1707 | *) 22 apr 2006: Optimized and improved some code |
embeddedartists | 0:b567d56a59d7 | 1708 | *) 07 sep 2005: (!) Changed to std::vector interface |
embeddedartists | 0:b567d56a59d7 | 1709 | *) 12 aug 2005: Initial release (C++, decoder only) |
embeddedartists | 0:b567d56a59d7 | 1710 | |
embeddedartists | 0:b567d56a59d7 | 1711 | |
embeddedartists | 0:b567d56a59d7 | 1712 | 12. contact information |
embeddedartists | 0:b567d56a59d7 | 1713 | ----------------------- |
embeddedartists | 0:b567d56a59d7 | 1714 | |
embeddedartists | 0:b567d56a59d7 | 1715 | Feel free to contact me with suggestions, problems, comments, ... concerning |
embeddedartists | 0:b567d56a59d7 | 1716 | LodePNG. If you encounter a PNG image that doesn't work properly with this |
embeddedartists | 0:b567d56a59d7 | 1717 | decoder, feel free to send it and I'll use it to find and fix the problem. |
embeddedartists | 0:b567d56a59d7 | 1718 | |
embeddedartists | 0:b567d56a59d7 | 1719 | My email address is (puzzle the account and domain together with an @ symbol): |
embeddedartists | 0:b567d56a59d7 | 1720 | Domain: gmail dot com. |
embeddedartists | 0:b567d56a59d7 | 1721 | Account: lode dot vandevenne. |
embeddedartists | 0:b567d56a59d7 | 1722 | |
embeddedartists | 0:b567d56a59d7 | 1723 | |
embeddedartists | 0:b567d56a59d7 | 1724 | Copyright (c) 2005-2013 Lode Vandevenne |
embeddedartists | 0:b567d56a59d7 | 1725 | */ |