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