Graphical demo for the LPC4088 Experiment Base Board with one of the Display Expansion Kits. This demo shows a rotating 3D cube with and without textures.

Dependencies:   EALib mbed

Committer:
embeddedartists
Date:
Fri Oct 03 12:48:37 2014 +0000
Revision:
0:c828045bbe69
First version.

Who changed what in which revision?

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