NTrace
GPU ray tracing framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
lodepng.h
Go to the documentation of this file.
1 /*
2 LodePNG version 20110823
3 
4 Copyright (c) 2005-2011 Lode Vandevenne
5 
6 This software is provided 'as-is', without any express or implied
7 warranty. In no event will the authors be held liable for any damages
8 arising from the use of this software.
9 
10 Permission is granted to anyone to use this software for any purpose,
11 including commercial applications, and to alter it and redistribute it
12 freely, subject to the following restrictions:
13 
14  1. The origin of this software must not be misrepresented; you must not
15  claim that you wrote the original software. If you use this software
16  in a product, an acknowledgment in the product documentation would be
17  appreciated but is not required.
18 
19  2. Altered source versions must be plainly marked as such, and must not be
20  misrepresented as being the original software.
21 
22  3. This notice may not be removed or altered from any source
23  distribution.
24 */
25 
26 #ifndef LODEPNG_H
27 #define LODEPNG_H
28 
29 #include <string.h> /*for size_t*/
30 
31 #ifdef __cplusplus
32 #include <vector>
33 #include <string>
34 #endif /*__cplusplus*/
35 
36 /* ////////////////////////////////////////////////////////////////////////// */
37 /* Code Sections */
38 /* ////////////////////////////////////////////////////////////////////////// */
39 
40 /*
41 The following #defines are used to create code sections. They can be disabled
42 to disable code sections, which can give faster compile time and smaller binary.
43 */
44 
45 /*deflate&zlib encoder and deflate&zlib decoder.
46 If this is disabled, you need to implement the dummy LodePNG_zlib_compress and
47 LodePNG_zlib_decompress functions in the #else belonging to this #define in the
48 source file.*/
49 #define LODEPNG_COMPILE_ZLIB
50 /*png encoder and png decoder*/
51 #define LODEPNG_COMPILE_PNG
52 /*deflate&zlib decoder and png decoder*/
53 #define LODEPNG_COMPILE_DECODER
54 /*deflate&zlib encoder and png encoder*/
55 #define LODEPNG_COMPILE_ENCODER
56 /*the optional built in harddisk file loading and saving functions*/
57 #define LODEPNG_COMPILE_DISK
58 /*any code or struct datamember related to chunks other than IHDR, IDAT, PLTE, tRNS, IEND*/
59 #define LODEPNG_COMPILE_ANCILLARY_CHUNKS
60 /*handling of unknown chunks*/
61 #define LODEPNG_COMPILE_UNKNOWN_CHUNKS
62 /*ability to convert error numerical codes to English text string*/
63 #define LODEPNG_COMPILE_ERROR_TEXT
64 
65 /* ////////////////////////////////////////////////////////////////////////// */
66 /* Simple Functions */
67 /* ////////////////////////////////////////////////////////////////////////// */
68 
69 /*
70 This are the simple C and C++ functions, which cover basic usage.
71 Further on in the header file are the more advanced functions allowing custom behaviour.
72 */
73 
74 #ifdef LODEPNG_COMPILE_PNG
75 
76 /*constants for the PNG color types. "LCT" = "LodePNG Color Type"*/
77 #define LCT_GREY 0 /*PNG color type greyscale*/
78 #define LCT_RGB 2 /*PNG color type RGB*/
79 #define LCT_PALETTE 3 /*PNG color type palette*/
80 #define LCT_GREY_ALPHA 4 /*PNG color type greyscale with alpha*/
81 #define LCT_RGBA 6 /*PNG color type RGB with alpha*/
82 
83 #ifdef LODEPNG_COMPILE_DECODER
84 /*
85 Converts PNG data in memory to raw pixel data.
86 out: Output parameter. Pointer to buffer that will contain the raw pixel data.
87  Its size is w * h * (bytes per pixel), bytes per pixel depends on colorType and bitDepth.
88  Must be freed after usage with free(*out).
89 w: Output parameter. Pointer to width of pixel data.
90 h: Output parameter. Pointer to height of pixel data.
91 in: Memory buffer with the PNG file.
92 insize: size of the in buffer.
93 colorType: the desired color type for the raw output image. See explanation on PNG color types.
94 bitDepth: the desired bit depth for the raw output image. See explanation on PNG color types.
95 Return value: LodePNG error code (0 means no error).
96 */
97 unsigned LodePNG_decode(unsigned char** out, unsigned* w, unsigned* h,
98  const unsigned char* in, size_t insize, unsigned colorType, unsigned bitDepth);
99 
100 /*Same as LodePNG_decode, but uses colorType = 6 and bitDepth = 8 by default (32-bit RGBA)*/
101 unsigned LodePNG_decode32(unsigned char** out, unsigned* w, unsigned* h,
102  const unsigned char* in, size_t insize);
103 
104 /*Same as LodePNG_decode, but uses colorType = 2 and bitDepth = 8 by default (24-bit RGB)*/
105 unsigned LodePNG_decode24(unsigned char** out, unsigned* w, unsigned* h,
106  const unsigned char* in, size_t insize);
107 
108 #ifdef LODEPNG_COMPILE_DISK
109 /*
110 Load PNG from disk, from file with given name.
111 out: Output parameter. Pointer to buffer that will contain the raw pixel data.
112  Its size is w * h * (bytes per pixel), bytes per pixel depends on colorType and bitDepth.
113  Must be freed after usage with free(*out).
114 w: Output parameter. Pointer to width of pixel data.
115 h: Output parameter. Pointer to height of pixel data.
116 filename: Path on disk of the PNG file.
117 colorType: the desired color type for the raw output image. See explanation on PNG color types.
118 bitDepth: the desired bit depth for the raw output image. See explanation on PNG color types.
119 Return value: LodePNG error code (0 means no error).
120 */
121 unsigned LodePNG_decode_file(unsigned char** out, unsigned* w, unsigned* h,
122  const char* filename, unsigned colorType, unsigned bitDepth);
123 
124 /*Same as LodePNG_decode_file, but uses colorType = 6 and bitDepth = 8 by default (32-bit RGBA)*/
125 unsigned LodePNG_decode32_file(unsigned char** out, unsigned* w, unsigned* h, const char* filename);
126 
127 /*Same as LodePNG_decode_file, but uses colorType = 2 and bitDepth = 8 by default (24-bit RGB)*/
128 unsigned LodePNG_decode24_file(unsigned char** out, unsigned* w, unsigned* h, const char* filename);
129 
130 
131 #endif /*LODEPNG_COMPILE_DISK*/
132 #endif /*LODEPNG_COMPILE_DECODER*/
133 
134 #ifdef LODEPNG_COMPILE_ENCODER
135 /*
136 Converts raw pixel data into a PNG image in memory. The colorType and bitDepth
137  of the output PNG image cannot be chosen, they are automatically determined
138  by the colorType, bitDepth and content of the input pixel data.
139 out: Output parameter. Pointer to buffer that will contain the raw pixel data.
140  Must be freed after usage with free(*out).
141 outsize: Output parameter. Pointer to the size in bytes of the out buffer.
142 image: The raw pixel data to encode. The size of this buffer should be
143  w * h * (bytes per pixel), bytes per pixel depends on colorType and bitDepth.
144 w: width of the raw pixel data in pixels.
145 h: height of the raw pixel data in pixels.
146 colorType: the color type of the raw input image. See explanation on PNG color types.
147 bitDepth: the bit depth of the raw input image. See explanation on PNG color types.
148 Return value: LodePNG error code (0 means no error).
149 */
150 unsigned LodePNG_encode(unsigned char** out, size_t* outsize,
151  const unsigned char* image, unsigned w, unsigned h, unsigned colorType, unsigned bitDepth);
152 
153 /*Same as LodePNG_encode, but uses colorType = 6 and bitDepth = 8 by default (32-bit RGBA).*/
154 unsigned LodePNG_encode32(unsigned char** out, size_t* outsize, const unsigned char* image, unsigned w, unsigned h);
155 
156 /*Same as LodePNG_encode, but uses colorType = 2 and bitDepth = 8 by default (24-bit RGB).*/
157 unsigned LodePNG_encode24(unsigned char** out, size_t* outsize, const unsigned char* image, unsigned w, unsigned h);
158 
159 #ifdef LODEPNG_COMPILE_DISK
160 
161 /*
162 Converts raw pixel data into a PNG file on disk. Same as LodePNG_encode, but
163 outputs to disk instead of memory buffer.
164 filename: path to file on disk to write the PNG image to.
165 image: The raw pixel data to encode. The size of this buffer should be
166  w * h * (bytes per pixel), bytes per pixel depends on colorType and bitDepth.
167 w: width of the raw pixel data in pixels.
168 h: height of the raw pixel data in pixels.
169 colorType: the color type of the raw input image. See explanation on PNG color types.
170 bitDepth: the bit depth of the raw input image. See explanation on PNG color types.
171 Return value: LodePNG error code (0 means no error).
172 */
173 unsigned LodePNG_encode_file(const char* filename, const unsigned char* image,
174  unsigned w, unsigned h, unsigned colorType, unsigned bitDepth);
175 
176 /*Same as LodePNG_encode_file, but uses colorType = 6 and bitDepth = 8 by default (32-bit RGBS).*/
177 unsigned LodePNG_encode32_file(const char* filename, const unsigned char* image, unsigned w, unsigned h);
178 
179 /*Same as LodePNG_encode_file, but uses colorType = 2 and bitDepth = 8 by default (24-bit RGB).*/
180 unsigned LodePNG_encode24_file(const char* filename, const unsigned char* image, unsigned w, unsigned h);
181 #endif /*LODEPNG_COMPILE_DISK*/
182 #endif /*LODEPNG_COMPILE_ENCODER*/
183 
184 #ifdef __cplusplus
185 namespace LodePNG
186 {
187 
188 #ifdef LODEPNG_COMPILE_DECODER
189  /*
190  Converts PNG data in memory to raw pixel data.
191  out: Output parameter, std::vector containing the raw pixel data. Its size
192  will be w * h * (bytes per pixel), where bytes per pixel is 4 if the default
193  colorType=6 and bitDepth=8 is used. The pixels are 32-bit RGBA bit in that case.
194  w: Output parameter, width of the image in pixels.
195  h: Output parameter, height of the image in pixels.
196  in: Memory buffer with the PNG file.
197  insize: size of the in buffer.
198  colorType: the desired color type for the raw output image. See explanation on PNG color types.
199  bitDepth: the desired bit depth for the raw output image. See explanation on PNG color types.
200  Return value: LodePNG error code (0 means no error).
201  */
202  unsigned decode(std::vector<unsigned char>& out, unsigned& w, unsigned& h,
203  const unsigned char* in, size_t insize, unsigned colorType = LCT_RGBA, unsigned bitDepth = 8);
204 
205  /*
206  Same as the decode function that takes a unsigned char buffer, but instead of giving
207  a pointer and a size, this takes the input buffer as an std::vector.
208  */
209  unsigned decode(std::vector<unsigned char>& out, unsigned& w, unsigned& h,
210  const std::vector<unsigned char>& in, unsigned colorType = LCT_RGBA, unsigned bitDepth = 8);
211 #ifdef LODEPNG_COMPILE_DISK
212  /*
213  Converts PNG file from disk to raw pixel data in memory.
214  out: Output parameter, std::vector containing the raw pixel data. Its size
215  will be w * h * (bytes per pixel), where bytes per pixel is 4 if the default
216  colorType=6 and bitDepth=8 is used. The pixels are 32-bit RGBA bit in that case.
217  w: Output parameter, width of the image in pixels.
218  h: Output parameter, height of the image in pixels.
219  filename: Path to PNG file on disk.
220  colorType: the desired color type for the raw output image. See explanation on PNG color types.
221  bitDepth: the desired bit depth for the raw output image. See explanation on PNG color types.
222  Return value: LodePNG error code (0 means no error).
223  */
224  unsigned decode(std::vector<unsigned char>& out, unsigned& w, unsigned& h,
225  const std::string& filename, unsigned colorType = LCT_RGBA, unsigned bitDepth = 8);
226 #endif //LODEPNG_COMPILE_DISK
227 #endif //LODEPNG_COMPILE_DECODER
228 
229 #ifdef LODEPNG_COMPILE_ENCODER
230  /*
231  Converts 32-bit RGBA raw pixel data into a PNG image in memory.
232  out: Output parameter, std::vector containing the PNG image data.
233  in: Memory buffer with raw pixel data. The size of this buffer should be
234  w * h * (bytes per pixel), With the default colorType=6 and bitDepth=8, bytes
235  per pixel should be 4 and the data is a 32-bit RGBA pixel buffer.
236  w: Width of the image in pixels.
237  h: Height of the image in pixels.
238  colorType: the color type of the raw input image. See explanation on PNG color types.
239  bitDepth: the bit depth of the raw input image. See explanation on PNG color types.
240  Return value: LodePNG error code (0 means no error).
241  */
242  unsigned encode(std::vector<unsigned char>& out, const unsigned char* in,
243  unsigned w, unsigned h, unsigned colorType = LCT_RGBA, unsigned bitDepth = 8);
244 
245  /*
246  Same as the encode function that takes a unsigned char buffer, but instead of giving
247  a pointer and a size, this takes the input buffer as an std::vector.
248  */
249  unsigned encode(std::vector<unsigned char>& out, const std::vector<unsigned char>& in,
250  unsigned w, unsigned h, unsigned colorType = LCT_RGBA, unsigned bitDepth = 8);
251 #ifdef LODEPNG_COMPILE_DISK
252  /*
253  Converts 32-bit RGBA raw pixel data into a PNG file on disk.
254  filename: Path to the file to write the PNG image to.
255  in: Memory buffer with raw pixel data. The size of this buffer should be
256  w * h * (bytes per pixel), With the default colorType=6 and bitDepth=8, bytes
257  per pixel should be 4 and the data is a 32-bit RGBA pixel buffer.
258  w: Width of the image in pixels.
259  h: Height of the image in pixels.
260  colorType: the color type of the raw input image. See explanation on PNG color types.
261  bitDepth: the bit depth of the raw input image. See explanation on PNG color types.
262  Return value: LodePNG error code (0 means no error).
263  */
264  unsigned encode(const std::string& filename, const unsigned char* in,
265  unsigned w, unsigned h, unsigned colorType = LCT_RGBA, unsigned bitDepth = 8);
266 
267  /*
268  Same as the encode function that takes a unsigned char buffer, but instead of giving
269  a pointer and a size, this takes the input buffer as an std::vector.
270  */
271  unsigned encode(const std::string& filename, const std::vector<unsigned char>& in,
272  unsigned w, unsigned h, unsigned colorType = LCT_RGBA, unsigned bitDepth = 8);
273 #endif //LODEPNG_COMPILE_DISK
274 #endif //LODEPNG_COMPILE_ENCODER
275 } //namespace LodePNG
276 #endif /*__cplusplus*/
277 #endif /*LODEPNG_COMPILE_PNG*/
278 
279 #ifdef LODEPNG_COMPILE_ERROR_TEXT
280 /*
281 Returns a textual description of the error code, in English. The
282 numerical value of the code itself is not included in this description.
283 */
284 const char* LodePNG_error_text(unsigned code);
285 #endif /*LODEPNG_COMPILE_ERROR_TEXT*/
286 
287 /* ////////////////////////////////////////////////////////////////////////// */
288 /* Inflate & Deflate Setting Structs */
289 /* ////////////////////////////////////////////////////////////////////////// */
290 
291 /*
292 These structs contain settings for the decompression and compression of the
293 PNG files. Typically you won't need these directly.
294 */
295 
296 #ifdef LODEPNG_COMPILE_DECODER
298 {
299  unsigned ignoreAdler32; /*if 1, continue and don't give an error message if the Adler32 checksum is corrupted*/
301 
304 #endif /*LODEPNG_COMPILE_DECODER*/
305 
306 #ifdef LODEPNG_COMPILE_ENCODER
307 /*
308 Compression settings. Tweaking these settings tweaks the balance between
309 speed and compression ratio.
310 */
311 typedef struct LodePNG_CompressSettings /*deflate = compress*/
312 {
313  /*LZ77 related settings*/
314  unsigned btype; /*the block type for LZ (0, 1, 2 or 3, see zlib standard). Should be 2 for proper compression.*/
315  unsigned useLZ77; /*whether or not to use LZ77. Should be 1 for proper compression.*/
316  unsigned windowSize; /*the maximum is 32768, higher gives more compression but is slower. Typical value: 2048.*/
318 
321 #endif /*LODEPNG_COMPILE_ENCODER*/
322 
323 #ifdef LODEPNG_COMPILE_PNG
324 /* ////////////////////////////////////////////////////////////////////////// */
325 /* PNG and Raw Image Information Structs */
326 /* ////////////////////////////////////////////////////////////////////////// */
327 
328 /*
329 Info about the color type of an image.
330 The same LodePNG_InfoColor struct is used for both the PNG and raw image type,
331 even though they are two totally different things.
332 */
333 typedef struct LodePNG_InfoColor
334 {
335  /*header (IHDR)*/
336  unsigned colorType; /*color type, see PNG standard or documentation further in this header file*/
337  unsigned bitDepth; /*bits per sample, see PNG standard or documentation further in this header file*/
338 
339  /*
340  palette (PLTE and tRNS)
341 
342  This is a dynamically allocated unsigned char array with the colors of the palette, including alpha.
343  The value palettesize indicates the amount of colors in the palette.
344  The allocated size of the buffer is 4 * palettesize bytes, in order RGBARGBARGBA...
345 
346  When encoding a PNG, to store your colors in the palette of the LodePNG_InfoRaw, first use
347  LodePNG_InfoColor_clearPalette, then for each color use LodePNG_InfoColor_addPalette.
348 
349  If you encode an image without alpha with palette, don't forget to put value 255 in each A byte of the palette.
350 
351  When decoding, by default you can ignore this palette, since LodePNG already
352  fills the palette colors in the pixels of the raw RGBA output.
353  */
354  unsigned char* palette; /*palette in RGBARGBA... order*/
355  size_t palettesize; /*palette size in number of colors (amount of bytes is 4 * palettesize)*/
356 
357  /*
358  transparent color key (tRNS)
359  This color uses the same bit depth as the bitDepth value in this struct, which can be 1-bit to 16-bit.
360  For greyscale PNGs, r, g and b will all 3 be set to the same.
361 
362  When decoding, by default you can ignore this information, since LodePNG sets
363  pixels with this key to transparent already in the raw RGBA output.
364  */
365  unsigned key_defined; /*is a transparent color key given? 0 = false, 1 = true*/
366  unsigned key_r; /*red/greyscale component of color key*/
367  unsigned key_g; /*green component of color key*/
368  unsigned key_b; /*blue component of color key*/
370 
371 /*init, cleanup and copy functions to use with this struct*/
374 /*return value is error code (0 means no error)*/
375 unsigned LodePNG_InfoColor_copy(LodePNG_InfoColor* dest, const LodePNG_InfoColor* source);
376 
378 /*add 1 color to the palette*/
379 unsigned LodePNG_InfoColor_addPalette(LodePNG_InfoColor* info, unsigned char r,
380  unsigned char g, unsigned char b, unsigned char a);
381 
382 /*additional color info*/
383 
384 /*get the total amount of bits per pixel, based on colorType and bitDepth in the struct*/
385 unsigned LodePNG_InfoColor_getBpp(const LodePNG_InfoColor* info);
386 /*get the amount of color channels used, based on colorType in the struct.
387 If a palette is used, it counts as 1 channel.*/
389 /*is it a greyscale type? (only colorType 0 or 4)*/
391 /*has it got an alpha channel? (only colorType 2 or 6)*/
393 /*has it got a palette? (only colorType 3)*/
395 /*only returns true if there is a palette and there is a value in the palette with alpha < 255.
396 Loops through the palette to check this.*/
398 
399 /*
400 Check if the given color info indicates the possibility of having non-opaque pixels in the PNG image.
401 Returns true if the image can have translucent or invisible pixels (it still be opaque if it doesn't use such pixels).
402 Returns false if the image can only have opaque pixels.
403 In detail, it returns true only if it's a color type with alpha, or has a palette with non-opaque values,
404 or if "key_defined" is true.
405 */
407 
408 #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
409 /*
410 The information of a Time chunk in PNG.
411 To make the encoder add a time chunk, set time_defined to 1 and fill in
412 the correct values in all the time parameters. LodePNG will not fill the current
413 time in these values itself, all it does is copy them over into the chunk bytes.
414 */
415 typedef struct LodePNG_Time
416 {
417  unsigned year; /*2 bytes used (0-65535)*/
418  unsigned char month; /*1-12*/
419  unsigned char day; /*1-31*/
420  unsigned char hour; /*0-23*/
421  unsigned char minute; /*0-59*/
422  unsigned char second; /*0-60 (to allow for leap seconds)*/
423 } LodePNG_Time;
424 
425 /*
426 Info about text chunks in a PNG file. The arrays can contain multiple keys
427 and strings. The amount of keys and strings is the same. The amount of strings
428 ends when the pointer to the string is a null pointer.
429 
430 They keyword of text chunks gives a short description what the actual text
431 represents. There are a few standard standard keywords recognised
432 by many programs: Title, Author, Description, Copyright, Creation Time,
433 Software, Disclaimer, Warning, Source, Comment. It's allowed to use other keys.
434 
435 A keyword is minimum 1 character and maximum 79 characters long. It's
436 discouraged to use a single line length longer than 79 characters for texts.
437 */
438 typedef struct LodePNG_Text /*non-international text*/
439 {
440  /*Don't allocate these text buffers yourself. Use the init/cleanup functions
441  correctly and use LodePNG_Text_add and LodePNG_Text_clear.*/
442  size_t num; /*the amount of texts in these char** buffers (there may be more texts in itext)*/
443  char** keys; /*the keyword of a text chunk (e.g. "Comment")*/
444  char** strings; /*the actual text*/
445 } LodePNG_Text;
446 
447 /*init, cleanup and copy functions to use with this struct*/
448 void LodePNG_Text_init(LodePNG_Text* text);
450 /*return value is error code (0 means no error)*/
451 unsigned LodePNG_Text_copy(LodePNG_Text* dest, const LodePNG_Text* source);
452 
453 /*Use these functions instead of allocating the char**s manually*/
454 void LodePNG_Text_clear(LodePNG_Text* text); /*use this to clear the texts again after you filled them in*/
455 unsigned LodePNG_Text_add(LodePNG_Text* text, const char* key, const char* str); /*push back both texts at once*/
456 
457 /*
458 Info about international text chunks in a PNG file. The arrays can contain multiple keys
459 and strings. The amount of keys, lengtags, transkeys and strings is the same.
460 The amount of strings ends when the pointer to the string is a null pointer.
461 
462 A keyword is minimum 1 character and maximum 79 characters long. It's
463 discouraged to use a single line length longer than 79 characters for texts.
464 */
465 typedef struct LodePNG_IText /*international text*/
466 {
467  /*Don't allocate these text buffers yourself. Use the init/cleanup functions
468  correctly and use LodePNG_IText_add and LodePNG_IText_clear.*/
469 
470  /*the amount of international texts in this PNG*/
471  size_t num;
472  /*the English keyword of the text chunk (e.g. "Comment")*/
473  char** keys;
474  /*the language tag for this text's international language, ISO/IEC 646 string, e.g. ISO 639 language tag*/
475  char** langtags;
476  /*keyword translated to the international language - UTF-8 string*/
477  char** transkeys;
478  /*the actual international text - UTF-8 string*/
479  char** strings;
480 } LodePNG_IText;
481 
482 /*init, cleanup and copy functions to use with this struct*/
485 /*return value is error code (0 means no error)*/
486 unsigned LodePNG_IText_copy(LodePNG_IText* dest, const LodePNG_IText* source);
487 
488 /*Use these functions instead of allocating the char**s manually*/
489 void LodePNG_IText_clear(LodePNG_IText* text); /*use this to clear the itexts again after you filled them in*/
490 unsigned LodePNG_IText_add(LodePNG_IText* text, const char* key, const char* langtag,
491  const char* transkey, const char* str); /*push back the 4 texts of 1 chunk at once*/
492 #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
493 
494 #ifdef LODEPNG_COMPILE_UNKNOWN_CHUNKS
495 /*
496 Unknown chunks read from the PNG, or extra chunks the user wants to have added
497 in the encoded PNG.
498 */
499 typedef struct LodePNG_UnknownChunks
500 {
501  /*There are 3 buffers, one for each position in the PNG where unknown chunks can appear
502  each buffer contains all unknown chunks for that position consecutively
503  The 3 buffers are the unknown chunks between certain critical chunks:
504  0: IHDR-PLTE, 1: PLTE-IDAT, 2: IDAT-IEND
505 
506  Do not allocate or traverse this data yourself. Use the chunk traversing functions declared
507  later, such as LodePNG_chunk_next and LodePNG_append_chunk, to read/write this struct.
508  */
509  unsigned char* data[3];
510  size_t datasize[3]; /*size in bytes of the unknown chunks, given for protection*/
511 
513 
514 /*init, cleanup and copy functions to use with this struct*/
517 /*return value is error code (0 means no error)*/
519 #endif /*LODEPNG_COMPILE_UNKNOWN_CHUNKS*/
520 
521 /*
522 Information about the PNG image, except pixels and sometimes except width and height.
523 */
524 typedef struct LodePNG_InfoPng
525 {
526  /*header (IHDR), palette (PLTE) and transparency (tRNS)*/
527 
528  /*
529  Note: width and height are only used as information of a decoded PNG image. When encoding one, you don't have
530  to specify width and height in an LodePNG_Info struct, but you give them as parameters of the encode function.
531  The rest of the LodePNG_Info struct IS used by the encoder though!
532  */
533  unsigned width; /*width of the image in pixels (ignored by encoder, but filled in by decoder)*/
534  unsigned height; /*height of the image in pixels (ignored by encoder, but filled in by decoder)*/
535  unsigned compressionMethod; /*compression method of the original file. Always 0.*/
536  unsigned filterMethod; /*filter method of the original file*/
537  unsigned interlaceMethod; /*interlace method of the original file*/
538  LodePNG_InfoColor color; /*color type and bits, palette and transparency of the PNG file*/
539 
540 #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
541  /*
542  suggested background color (bKGD)
543  This color uses the same bit depth as the bitDepth value in this struct, which can be 1-bit to 16-bit.
544 
545  For greyscale PNGs, r, g and b will all 3 be set to the same. When encoding
546  the encoder writes the red one. For palette PNGs: When decoding, the RGB value
547  will be stored, not a palette index. But when encoding, specify the index of
548  the palette in background_r, the other two are then ignored.
549 
550  The decoder does not use this background color to edit the color of pixels.
551  */
552  unsigned background_defined; /*is a suggested background color given?*/
553  unsigned background_r; /*red component of suggested background color*/
554  unsigned background_g; /*green component of suggested background color*/
555  unsigned background_b; /*blue component of suggested background color*/
556 
557  /*non-international text chunks (tEXt and zTXt)*/
559 
560  /*international text chunks (iTXt)*/
562 
563  /*time chunk (tIME)*/
564  unsigned char time_defined; /*if 0, no tIME chunk was or will be generated in the PNG image*/
566 
567  /*phys chunk (pHYs)*/
568  unsigned phys_defined; /*if 0, there is no pHYs chunk and the values below are undefined, if 1 else there is one*/
569  unsigned phys_x; /*pixels per unit in x direction*/
570  unsigned phys_y; /*pixels per unit in y direction*/
571  unsigned char phys_unit; /*may be 0 (unknown unit) or 1 (metre)*/
572 #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
573 
574 #ifdef LODEPNG_COMPILE_UNKNOWN_CHUNKS
575  /*unknown chunks*/
577 #endif /*LODEPNG_COMPILE_UNKNOWN_CHUNKS*/
579 
580 /*init, cleanup and copy functions to use with this struct*/
583 /*return value is error code (0 means no error)*/
584 unsigned LodePNG_InfoPng_copy(LodePNG_InfoPng* dest, const LodePNG_InfoPng* source);
585 
586 /*
587 Contains user-chosen information about the raw image data, which is independent of the PNG image
588 With raw images, I mean the image data in the form of the simple raw buffer to which the
589 compressed PNG data is decoded, or from which a PNG image can be encoded.
590 */
591 typedef struct LodePNG_InfoRaw
592 {
593  LodePNG_InfoColor color; /*color info of the raw image, note that the same struct as for PNG data is used.*/
595 
596 /*init, cleanup and copy functions to use with this struct*/
599 /*return value is error code (0 means no error)*/
600 unsigned LodePNG_InfoRaw_copy(LodePNG_InfoRaw* dest, const LodePNG_InfoRaw* source);
601 
602 /*
603 Converts raw buffer from one color type to another color type, based on
604 LodePNG_InfoColor structs to describe the input and output color type.
605 See the reference manual at the end of this header file to see which color conversions are supported.
606 return value = LodePNG error code (0 if all went ok, an error if the conversion isn't supported)
607 The out buffer must have size (w * h * bpp + 7) / 8, where bpp is the bits per pixel
608 of the output color type (LodePNG_InfoColor_getBpp)
609 */
610 unsigned LodePNG_convert(unsigned char* out, const unsigned char* in, LodePNG_InfoColor* infoOut,
611  LodePNG_InfoColor* infoIn, unsigned w, unsigned h);
612 
613 #ifdef LODEPNG_COMPILE_DECODER
614 
615 /* ////////////////////////////////////////////////////////////////////////// */
616 /* LodePNG Decoder */
617 /* ////////////////////////////////////////////////////////////////////////// */
618 
619 /*
620 Settings for the decoder. This contains settings for the PNG and the Zlib
621 decoder, but not the Info settings from the Info structs.
622 */
624 {
625  LodePNG_DecompressSettings zlibsettings; /*in here is the setting to ignore Adler32 checksums*/
626 
627  unsigned ignoreCrc; /*ignore CRC checksums*/
628  unsigned color_convert; /*whether to convert the PNG to the color type you want. Default: yes*/
629 
630 #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
631  unsigned readTextChunks; /*if false but rememberUnknownChunks is true, they're stored in the unknown chunks*/
632 #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
633 
634 #ifdef LODEPNG_COMPILE_UNKNOWN_CHUNKS
635  /*store all bytes from unknown chunks in the InfoPng (off by default, useful for a png editor)*/
637 #endif /*LODEPNG_COMPILE_UNKNOWN_CHUNKS*/
639 
641 
642 /*
643 The LodePNG_Decoder struct has most input and output parameters the decoder uses,
644 such as the settings, the info of the PNG and the raw data, and the error. Only
645 the pixel buffer is not contained in this struct.
646 */
647 typedef struct LodePNG_Decoder
648 {
649  LodePNG_DecodeSettings settings; /*the decoding settings*/
650  LodePNG_InfoRaw infoRaw; /*specifies the format in which you would like to get the raw pixel buffer*/
651  LodePNG_InfoPng infoPng; /*info of the PNG image obtained after decoding*/
652  unsigned error;
654 
655 /*init, cleanup and copy functions to use with this struct*/
658 void LodePNG_Decoder_copy(LodePNG_Decoder* dest, const LodePNG_Decoder* source);
659 
660 /*
661 Decode based on a LodePNG_Decoder.
662 This function allocates the out buffer and stores the size in *outsize. This buffer
663 needs to be freed after usage.
664 Other information about the PNG file, such as the size, colorType and extra chunks
665 are stored in the infoPng field of the LodePNG_Decoder.
666 */
667 void LodePNG_Decoder_decode(LodePNG_Decoder* decoder, unsigned char** out, size_t* outsize,
668  const unsigned char* in, size_t insize);
669 
670 /*
671 Read the PNG header, but not the actual data. This returns only the information
672 that is in the header chunk of the PNG, such as width, height and color type. The
673 information is placed in the infoPng field of the LodePNG_Decoder.
674 */
675 void LodePNG_Decoder_inspect(LodePNG_Decoder* decoder, const unsigned char* in, size_t insize);
676 #endif /*LODEPNG_COMPILE_DECODER*/
677 
678 #ifdef LODEPNG_COMPILE_ENCODER
679 /* ////////////////////////////////////////////////////////////////////////// */
680 /* LodePNG Encoder */
681 /* ////////////////////////////////////////////////////////////////////////// */
682 
683 /*Settings for the encoder.*/
685 {
686  LodePNG_CompressSettings zlibsettings; /*settings for the zlib encoder, such as window size, ...*/
687 
688  /*Brute-force-search PNG filters by compressing each filter for each scanline.
689  This gives better compression, at the cost of being super slow.
690  Don't enable this for normal image saving, compression can take minutes
691  instead of seconds. This is experimental. If enabled, compression still isn't
692  as good as some other PNG encoders and optimizers, except for some images.
693  If you enable this, also consider setting zlibsettings.windowSize to 32768, and consider
694  using a less than 24-bit per pixel colorType if the image has <= 256 colors, for optimal compression.
695  Default: 0 (false)*/
697 
698  /*automatically use color type without alpha instead of given one, if given image is opaque*/
700  /*force creating a PLTE chunk if colortype is 2 or 6 (= a suggested palette).
701  If colortype is 3, PLTE is _always_ created.*/
702  unsigned force_palette;
703 #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
704  /*add LodePNG version as text chunk*/
705  unsigned add_id;
706  /*encode text chunks as zTXt chunks instead of tEXt chunks, and use compression in iTXt chunks*/
708 #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
710 
712 
713 /*
714 This struct has most input and output parameters the encoder uses,
715 such as the settings, the info of the PNG and the raw data, and the error. Only
716 the pixel buffer is not contained in this struct.
717 */
718 typedef struct LodePNG_Encoder
719 {
720  /*compression settings of the encoder*/
722  /*the info specified by the user is not changed by the encoder. The encoder
723  will try to generate a PNG close to the given info.*/
725  /*put the properties of the input raw image in here*/
727  /*error value filled in if error happened, or 0 if all went ok*/
728  unsigned error;
730 
731 /*init, cleanup and copy functions to use with this struct*/
734 void LodePNG_Encoder_copy(LodePNG_Encoder* dest, const LodePNG_Encoder* source);
735 
736 /*This function allocates the out buffer with standard malloc and stores the size in *outsize.*/
737 void LodePNG_Encoder_encode(LodePNG_Encoder* encoder, unsigned char** out, size_t* outsize,
738  const unsigned char* image, unsigned w, unsigned h);
739 #endif /*LODEPNG_COMPILE_ENCODER*/
740 
741 /* ////////////////////////////////////////////////////////////////////////// */
742 /* Chunk Traversing Utilities */
743 /* ////////////////////////////////////////////////////////////////////////// */
744 
745 /*
746 LodePNG_chunk functions:
747 These functions need as input a large enough amount of allocated memory.
748 These functions can be used on raw PNG data, but they are exposed in the API
749 because they are needed if you want to traverse the unknown chunks stored
750 in the LodePNG_UnknownChunks struct, or add new ones to it.
751 */
752 
753 /*get the length of the data of the chunk. Total chunk length has 12 bytes more.*/
754 unsigned LodePNG_chunk_length(const unsigned char* chunk);
755 
756 /*puts the 4-byte type in null terminated string*/
757 void LodePNG_chunk_type(char type[5], const unsigned char* chunk);
758 
759 /*check if the type is the given type*/
760 unsigned char LodePNG_chunk_type_equals(const unsigned char* chunk, const char* type);
761 
762 /*
763 These functions get properties of PNG chunks gotten from capitalization of chunk
764 type name, as defined by the PNG standard.
765 */
766 
767 /*
768 properties of PNG chunks gotten from capitalization of chunk type name, as defined by the standard
769 0: ancillary chunk, 1: it's one of the critical chunk types
770 */
771 unsigned char LodePNG_chunk_critical(const unsigned char* chunk);
772 
773 /*0: public, 1: private*/
774 unsigned char LodePNG_chunk_private(const unsigned char* chunk);
775 
776 /*0: the chunk is unsafe to copy, 1: the chunk is safe to copy*/
777 unsigned char LodePNG_chunk_safetocopy(const unsigned char* chunk);
778 
779 /*get pointer to the data of the chunk*/
780 unsigned char* LodePNG_chunk_data(unsigned char* chunk);
781 
782 /*get pointer to the data of the chunk*/
783 const unsigned char* LodePNG_chunk_data_const(const unsigned char* chunk);
784 
785 /*returns 0 if the crc is correct, 1 if it's incorrect*/
786 unsigned LodePNG_chunk_check_crc(const unsigned char* chunk);
787 
788 /*generates the correct CRC from the data and puts it in the last 4 bytes of the chunk*/
789 void LodePNG_chunk_generate_crc(unsigned char* chunk);
790 
791 /*iterate to next chunks. don't use on IEND chunk, as there is no next chunk then*/
792 unsigned char* LodePNG_chunk_next(unsigned char* chunk);
793 const unsigned char* LodePNG_chunk_next_const(const unsigned char* chunk);
794 
795 /*
796 Appends chunk to the data in out. The given chunk should already have its chunk header.
797 The out variable and outlength are updated to reflect the new reallocated buffer.
798 Returns error code (0 if it went ok)
799 */
800 unsigned LodePNG_append_chunk(unsigned char** out, size_t* outlength, const unsigned char* chunk);
801 
802 /*
803 Appends new chunk to out. The chunk to append is given by giving its length, type
804 and data separately. The type is a 4-letter string.
805 The out variable and outlength are updated to reflect the new reallocated buffer.
806 Returne error code (0 if it went ok)
807 */
808 unsigned LodePNG_create_chunk(unsigned char** out, size_t* outlength, unsigned length,
809  const char* type, const unsigned char* data);
810 #endif /*LODEPNG_COMPILE_PNG*/
811 
812 #ifdef LODEPNG_COMPILE_ZLIB
813 /* ////////////////////////////////////////////////////////////////////////// */
814 /* Zlib encoder and decoder */
815 /* ////////////////////////////////////////////////////////////////////////// */
816 
817 /*
818 This zlib part can be used independently to zlib compress and decompress a
819 buffer. It cannot be used to create gzip files however, and it only supports the
820 part of zlib that is required for PNG, it does not support dictionaries.
821 */
822 
823 #ifdef LODEPNG_COMPILE_DECODER
824 /*Decompresses Zlib data. Reallocates the out buffer and appends the data. The
825 data must be according to the zlib specification.
826 Either, *out must be NULL and *outsize must be 0, or, *out must be a valid
827 buffer and *outsize its size in bytes. out must be freed by user after usage.*/
828 unsigned LodePNG_zlib_decompress(unsigned char** out, size_t* outsize,
829  const unsigned char* in, size_t insize, const LodePNG_DecompressSettings* settings);
830 #endif /*LODEPNG_COMPILE_DECODER*/
831 
832 #ifdef LODEPNG_COMPILE_ENCODER
833 /*Compresses data with Zlib. Reallocates the out buffer and appends the data.
834 The data is output in the format of the zlib specification.
835 Either, *out must be NULL and *outsize must be 0, or, *out must be a valid
836 buffer and *outsize its size in bytes. out must be freed by user after usage.*/
837 unsigned LodePNG_zlib_compress(unsigned char** out, size_t* outsize,
838  const unsigned char* in, size_t insize, const LodePNG_CompressSettings* settings);
839 #endif /*LODEPNG_COMPILE_ENCODER*/
840 #endif /*LODEPNG_COMPILE_ZLIB*/
841 
842 #ifdef LODEPNG_COMPILE_DISK
843 /*
844 Load a file from disk into buffer. The function allocates the out buffer, and
845 after usage you are responsible for freeing it.
846 out: output parameter, contains pointer to loaded buffer.
847 outsize: output parameter, size of the allocated out buffer
848 filename: the path to the file to load
849 return value: error code (0 means ok)
850 */
851 unsigned LodePNG_loadFile(unsigned char** out, size_t* outsize, const char* filename);
852 
853 /*
854 Save a file from buffer to disk. Warning, if it exists, this function overwrites
855 the file without warning!
856 buffer: the buffer to write
857 buffersize: size of the buffer to write
858 filename: the path to the file to save to
859 return value: error code (0 means ok)
860 */
861 unsigned LodePNG_saveFile(const unsigned char* buffer, size_t buffersize, const char* filename);
862 #endif /*LODEPNG_COMPILE_DISK*/
863 
864 #ifdef __cplusplus
865 /* ////////////////////////////////////////////////////////////////////////// */
866 /* LodePNG C++ wrapper */
867 /* ////////////////////////////////////////////////////////////////////////// */
868 
869 //The LodePNG C++ wrapper uses classes with handy constructors and destructors
870 //instead of manual init and cleanup functions, and uses std::vectors instead of
871 //manually allocated memory buffers.
872 
873 namespace LodePNG
874 {
875 #ifdef LODEPNG_COMPILE_ZLIB
876 //The C++ wrapper for the zlib part
877 #ifdef LODEPNG_COMPILE_DECODER
878  //Zlib-decompress an unsigned char buffer
879  unsigned decompress(std::vector<unsigned char>& out, const unsigned char* in, size_t insize,
880  const LodePNG_DecompressSettings& settings = LodePNG_defaultDecompressSettings);
881 
882  //Zlib-decompress an std::vector
883  unsigned decompress(std::vector<unsigned char>& out, const std::vector<unsigned char>& in,
884  const LodePNG_DecompressSettings& settings = LodePNG_defaultDecompressSettings);
885 #endif //LODEPNG_COMPILE_DECODER
886 
887 #ifdef LODEPNG_COMPILE_ENCODER
888  //Zlib-compress an unsigned char buffer
889  unsigned compress(std::vector<unsigned char>& out, const unsigned char* in, size_t insize,
890  const LodePNG_CompressSettings& settings = LodePNG_defaultCompressSettings);
891 
892  //Zlib-compress an std::vector
893  unsigned compress(std::vector<unsigned char>& out, const std::vector<unsigned char>& in,
894  const LodePNG_CompressSettings& settings = LodePNG_defaultCompressSettings);
895 #endif //LODEPNG_COMPILE_ENCODER
896 #endif //LODEPNG_COMPILE_ZLIB
897 
898 #ifdef LODEPNG_COMPILE_PNG
899 #ifdef LODEPNG_COMPILE_DECODER
900  /*
901  Class to decode a PNG image. Before decoding, settings can be set and
902  after decoding, extra information about the PNG can be retrieved.
903  Extends from the C-struct LodePNG_Decoder to add constructors and destructors
904  to initialize/cleanup it automatically. Beware, no virtual destructor is used.
905  */
906  class Decoder : public LodePNG_Decoder
907  {
908  public:
909 
910  Decoder();
911  ~Decoder();
912  void operator=(const LodePNG_Decoder& other);
913 
914  //decode PNG buffer to raw out buffer. Width and height can be retrieved with getWidth() and
915  //getHeight() and error should be checked with hasError() and getError()
916  void decode(std::vector<unsigned char>& out, const unsigned char* in, size_t insize);
917 
918  //decode PNG buffer to raw out buffer. Width and height can be retrieved with getWidth() and
919  //getHeight() and error should be checked with hasError() and getError()
920  void decode(std::vector<unsigned char>& out, const std::vector<unsigned char>& in);
921 
922  //inspect functions: get only the info from the PNG header. The info can then be retrieved with
923  //the functions of this class.
924  void inspect(const unsigned char* in, size_t insize);
925 
926  //inspect functions: get only the info from the PNG header. The info can then be retrieved with
927  //the functions of this class.
928  void inspect(const std::vector<unsigned char>& in);
929 
930  //error checking after decoding
931  bool hasError() const;
932  unsigned getError() const;
933 
934  //convenient access to some InfoPng parameters after decoding
935  unsigned getWidth() const; //width of image in pixels
936  unsigned getHeight() const; //height of image in pixels
937  unsigned getBpp(); //bits per pixel
938  unsigned getChannels(); //amount of channels
939  unsigned isGreyscaleType(); //is it a greyscale type? (colorType 0 or 4)
940  unsigned isAlphaType(); //has it an alpha channel? (colorType 2 or 6)
941 
942  //getters and setters for the decoding settings
943  const LodePNG_DecodeSettings& getSettings() const;
944  LodePNG_DecodeSettings& getSettings();
945  void setSettings(const LodePNG_DecodeSettings& info);
946 
947  //getters and setters for the PNG image info, after decoding this describes information of the PNG image
948  const LodePNG_InfoPng& getInfoPng() const;
949  LodePNG_InfoPng& getInfoPng();
950  void setInfoPng(const LodePNG_InfoPng& info);
951  void swapInfoPng(LodePNG_InfoPng& info); //faster than copying with setInfoPng
952 
953  //getters and setters for the raw image info, this determines in what format
954  //you get the pixel buffer from the decoder
955  const LodePNG_InfoRaw& getInfoRaw() const;
956  LodePNG_InfoRaw& getInfoRaw();
957  void setInfoRaw(const LodePNG_InfoRaw& info);
958  };
959 #endif //LODEPNG_COMPILE_DECODER
960 
961 #ifdef LODEPNG_COMPILE_ENCODER
962  /*
963  Class to encode a PNG image. Before encoding, settings can be set.
964  Extends from the C-struct LodePNG_Enoder to add constructors and destructors
965  to initialize/cleanup it automatically. Beware, no virtual destructor is used.
966  */
967  class Encoder : public LodePNG_Encoder
968  {
969  public:
970 
971  Encoder();
972  ~Encoder();
973  void operator=(const LodePNG_Encoder& other);
974 
975  //encoding image to PNG buffer
976  void encode(std::vector<unsigned char>& out, const unsigned char* image, unsigned w, unsigned h);
977 
978  //encoding image to PNG buffer
979  void encode(std::vector<unsigned char>& out, const std::vector<unsigned char>& image, unsigned w, unsigned h);
980 
981  //error checking after decoding
982  bool hasError() const;
983  unsigned getError() const;
984 
985  //convenient direct access to some parameters of the InfoPng
986  void clearPalette();
987  void addPalette(unsigned char r, unsigned char g, unsigned char b, unsigned char a); //add 1 color to the palette
988 #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
989  void clearText();
990  void addText(const std::string& key, const std::string& str); //push back both texts at once
991  void clearIText();
992  void addIText(const std::string& key, const std::string& langtag,
993  const std::string& transkey, const std::string& str);
994 #endif //LODEPNG_COMPILE_ANCILLARY_CHUNKS
995 
996  //getters and setters for the encoding settings
997  const LodePNG_EncodeSettings& getSettings() const;
998  LodePNG_EncodeSettings& getSettings();
999  void setSettings(const LodePNG_EncodeSettings& info);
1000 
1001  //getters and setters for the PNG image info, this describes what color type
1002  //and other settings the resulting PNG should have
1003  const LodePNG_InfoPng& getInfoPng() const;
1004  LodePNG_InfoPng& getInfoPng();
1005  void setInfoPng(const LodePNG_InfoPng& info);
1006  void swapInfoPng(LodePNG_InfoPng& info); //faster than copying with setInfoPng
1007 
1008  //getters and setters for the raw image info, this describes how the encoder
1009  //should interpret the input pixel buffer
1010  const LodePNG_InfoRaw& getInfoRaw() const;
1011  LodePNG_InfoRaw& getInfoRaw();
1012  void setInfoRaw(const LodePNG_InfoRaw& info);
1013  };
1014 #endif //LODEPNG_COMPILE_ENCODER
1015 
1016 #ifdef LODEPNG_COMPILE_DISK
1017  /*
1018  Load a file from disk into an std::vector. If the vector is empty, then either
1019  the file doesn't exist or is an empty file.
1020  */
1021  void loadFile(std::vector<unsigned char>& buffer, const std::string& filename);
1022 
1023  /*
1024  Save the binary data in an std::vector to a file on disk. The file is overwritten
1025  without warning.
1026  */
1027  void saveFile(const std::vector<unsigned char>& buffer, const std::string& filename);
1028 #endif //LODEPNG_COMPILE_DISK
1029 #endif //LODEPNG_COMPILE_PNG
1030 } //namespace LodePNG
1031 #endif /*end of __cplusplus wrapper*/
1032 
1033 /*
1034 TODO:
1035 [.] test if there are no memory leaks or security exploits - done a lot but needs to be checked often
1036 [.] check compatibility with vareous compilers - done but needs to be redone for every newer version
1037 [ ] LZ77 encoder more like the one described in zlib - to make sure it's patentfree
1038 [X] converting color to 16-bit per channel types
1039 [ ] read all public PNG chunk types (but never let the color profile and gamma ones touch RGB values)
1040 [ ] make sure encoder generates no chunks with size > (2^31)-1
1041 [ ] partial decoding (stream processing)
1042 [ ] let the "isFullyOpaque" function check color keys and transparent palettes too
1043 [X] better name for the variables "codes", "codesD", "codelengthcodes", "clcl" and "lldl"
1044 [ ] don't stop decoding on errors like 69, 57, 58 (make warnings)
1045 [ ] make option to choose if the raw image with non multiple of 8 bits per scanline should have padding bits or not
1046 [ ] let the C++ wrapper catch exceptions coming from the standard library and return LodePNG error codes
1047 */
1048 
1049 #endif /*LODEPNG_H inclusion guard*/
1050 
1051 /*
1052 LodePNG Documentation
1053 ---------------------
1054 
1055 This documentations contains background information and examples. For the function
1056 and class documentation, see the comments in the declarations above.
1057 
1058 0. table of contents
1059 --------------------
1060 
1061  1. about
1062  1.1. supported features
1063  1.2. features not supported
1064  2. C and C++ version
1065  3. security
1066  4. decoding
1067  5. encoding
1068  6. color conversions
1069  6.1. PNG color types
1070  6.2. Default Behaviour of LodePNG
1071  6.3. Color Conversions
1072  6.4. More Notes
1073  7. error values
1074  8. chunks and PNG editing
1075  9. compiler support
1076  10. examples
1077  10.1. decoder C++ example
1078  10.2. encoder C++ example
1079  10.3. decoder C example
1080  11. changes
1081  12. contact information
1082 
1083 
1084 1. about
1085 --------
1086 
1087 PNG is a file format to store raster images losslessly with good compression,
1088 supporting different color types. It can be implemented in a patent-free way.
1089 
1090 LodePNG is a PNG codec according to the Portable Network Graphics (PNG)
1091 Specification (Second Edition) - W3C Recommendation 10 November 2003.
1092 
1093 The specifications used are:
1094 
1095 *) Portable Network Graphics (PNG) Specification (Second Edition):
1096  http://www.w3.org/TR/2003/REC-PNG-20031110
1097 *) RFC 1950 ZLIB Compressed Data Format version 3.3:
1098  http://www.gzip.org/zlib/rfc-zlib.html
1099 *) RFC 1951 DEFLATE Compressed Data Format Specification ver 1.3:
1100  http://www.gzip.org/zlib/rfc-deflate.html
1101 
1102 The most recent version of LodePNG can currently be found at
1103 http://members.gamedev.net/lode/projects/LodePNG/
1104 
1105 LodePNG works both in C (ISO C90) and C++, with a C++ wrapper that adds
1106 extra functionality.
1107 
1108 LodePNG exists out of two files:
1109 -lodepng.h: the header file for both C and C++
1110 -lodepng.c(pp): give it the name lodepng.c or lodepng.cpp (or .cc) depending on your usage
1111 
1112 If you want to start using LodePNG right away without reading this doc, get the
1113 files lodepng_examples.c or lodepng_examples.cpp to see how to use it in code,
1114 or check the (smaller) examples in chapter 13 here.
1115 
1116 LodePNG is simple but only supports the basic requirements. To achieve
1117 simplicity, the following design choices were made: There are no dependencies
1118 on any external library. To decode PNGs, there's a Decoder struct or class that
1119 can convert any PNG file data into an RGBA image buffer with a single function
1120 call. To encode PNGs, there's an Encoder struct or class that can convert image
1121 data into PNG file data with a single function call. To read and write files,
1122 there are simple functions to convert the files to/from buffers in memory.
1123 
1124 This all makes LodePNG suitable for loading textures in games, demoscene
1125 productions, saving a screenshot, images in programs that require them for simple
1126 usage, ... It's less suitable for full fledged image editors, loading PNGs
1127 over network (it requires all the image data to be available before decoding can
1128 begin), life-critical systems, ...
1129 LodePNG has a standards conformant decoder and encoder, and supports the ability
1130 to make a somewhat conformant editor.
1131 
1132 1.1. supported features
1133 -----------------------
1134 
1135 The following features are supported by the decoder:
1136 
1137 *) decoding of PNGs with any color type, bit depth and interlace mode, to a 24- or 32-bit color raw image,
1138  or the same color type as the PNG
1139 *) encoding of PNGs, from any raw image to 24- or 32-bit color, or the same color type as the raw image
1140 *) Adam7 interlace and deinterlace for any color type
1141 *) loading the image from harddisk or decoding it from a buffer from other sources than harddisk
1142 *) support for alpha channels, including RGBA color model, translucent palettes and color keying
1143 *) zlib decompression (inflate)
1144 *) zlib compression (deflate)
1145 *) CRC32 and ADLER32 checksums
1146 *) handling of unknown chunks, allowing making a PNG editor that stores custom and unknown chunks.
1147 *) the following chunks are supported (generated/interpreted) by both encoder and decoder:
1148  IHDR: header information
1149  PLTE: color palette
1150  IDAT: pixel data
1151  IEND: the final chunk
1152  tRNS: transparency for palettized images
1153  tEXt: textual information
1154  zTXt: compressed textual information
1155  iTXt: international textual information
1156  bKGD: suggested background color
1157  pHYs: physical dimensions
1158  tIME: modification time
1159 
1160 1.2. features not supported
1161 ---------------------------
1162 
1163 The following features are _not_ supported:
1164 
1165 *) some features needed to make a conformant PNG-Editor might be still missing.
1166 *) partial loading/stream processing. All data must be available and is processed in one call.
1167 *) The following public chunks are not supported but treated as unknown chunks by LodePNG
1168  cHRM, gAMA, iCCP, sRGB, sBIT, hIST, sPLT
1169 
1170 
1171 2. C and C++ version
1172 --------------------
1173 
1174 The C version uses buffers allocated with alloc that you need to free()
1175 yourself. On top of that, you need to use init and cleanup functions for each
1176 struct whenever using a struct from the C version to avoid exploits and memory leaks.
1177 
1178 The C++ version has constructors and destructors that take care of these things,
1179 and uses std::vectors in the interface for storing data.
1180 
1181 Both the C and the C++ version are contained in this file! The C++ code depends on
1182 the C code, the C code works on its own.
1183 
1184 These files work without modification for both C and C++ compilers because all the
1185 additional C++ code is in "#ifdef __cplusplus" blocks that make C-compilers ignore
1186 it, and the C code is made to compile both with strict ISO C90 and C++.
1187 
1188 To use the C++ version, you need to rename the source file to lodepng.cpp (instead
1189 of lodepng.c), and compile it with a C++ compiler.
1190 
1191 To use the C version, you need to rename the source file to lodepng.c (instead
1192 of lodepng.cpp), and compile it with a C compiler.
1193 
1194 
1195 3. Security
1196 -----------
1197 
1198 As with most software, even if carefully designed, it's always possible that
1199 LodePNG may contain possible exploits.
1200 
1201 If you discover a possible exploit, please let me know, and it will be fixed.
1202 
1203 When using LodePNG, care has to be taken with the C version of LodePNG, as well as the C-style
1204 structs when working with C++. The following conventions are used for all C-style structs:
1205 
1206 -if a struct has a corresponding init function, always call the init function when making a new one, to avoid exploits
1207 -if a struct has a corresponding cleanup function, call it before the struct disappears to avoid memory leaks
1208 -if a struct has a corresponding copy function, use the copy function instead of "=".
1209  The destination must also be inited already!
1210 
1211 4. Decoding
1212 -----------
1213 
1214 Decoding converts a PNG compressed image to a raw pixel buffer.
1215 
1216 Most documentation on using the decoder is at its declarations in the header
1217 above. For C, simple decoding can be done with functions such as LodePNG_decode32,
1218 and more advanced decoding can be done with the struct LodePNG_Decoder and its
1219 functions. For C++, simple decoding can be done with the LodePNG::decode functions
1220 and advanced decoding with the LodePNG::Decoder class.
1221 
1222 The Decoder contains 3 components:
1223 *) LodePNG_InfoPng: it stores information about the PNG (the input) in an LodePNG_InfoPng struct,
1224  don't modify this one yourself
1225 *) Settings: you can specify a few other settings for the decoder to use
1226 *) LodePNG_InfoRaw: here you can say what type of raw image (the output) you want to get
1227 
1228 Some of the parameters described below may be inside the sub-struct "LodePNG_InfoColor color".
1229 In the C and C++ version, when using Info structs outside of the decoder or encoder, you need to use their
1230 init and cleanup functions, but normally you use the ones in the decoder that are already handled
1231 in the init and cleanup functions of the decoder itself.
1232 
1233 =LodePNG_InfoPng=
1234 
1235 This contains information such as the original color type of the PNG image, text
1236 comments, suggested background color, etc... More details about the LodePNG_InfoPng struct
1237 are at its declaration documentation.
1238 
1239 Because the dimensions of the image are important, there are shortcuts to get them in the
1240 C++ version: use decoder.getWidth() and decoder.getHeight().
1241 In the C version, use decoder.infoPng.width and decoder.infoPng.height.
1242 
1243 =LodePNG_InfoRaw=
1244 
1245 In the LodePNG_InfoRaw struct of the Decoder, you can specify which color type you want
1246 the resulting raw image to be. If this is different from the colorType of the
1247 PNG, then the decoder will automatically convert the result to your LodePNG_InfoRaw
1248 settings. Not all combinations of color conversions are supported though, see
1249 a different section for information about the color modes and supported conversions.
1250 
1251 Palette of LodePNG_InfoRaw isn't used by the Decoder, when converting from palette color
1252 to palette color, the values of the pixels are left untouched so that the colors
1253 will change if the palette is different. Color key of LodePNG_InfoRaw is not used by the
1254 Decoder. If setting color_convert is false then LodePNG_InfoRaw is completely ignored,
1255 but it will be modified to match the color type of the PNG so will be overwritten.
1256 
1257 By default, 32-bit color is used for the result.
1258 
1259 =Settings=
1260 
1261 The Settings can be used to ignore the errors created by invalid CRC and Adler32
1262 chunks, and to disable the decoding of tEXt chunks.
1263 
1264 There's also a setting color_convert, true by default. If false, no conversion
1265 is done, the resulting data will be as it was in the PNG (after decompression)
1266 and you'll have to puzzle the colors of the pixels together yourself using the
1267 color type information in the LodePNG_InfoPng.
1268 
1269 
1270 5. Encoding
1271 -----------
1272 
1273 Encoding converts a raw pixel buffer to a PNG compressed image.
1274 
1275 Most documentation on using the encoder is at its declarations in the header
1276 above. For C, simple encoding can be done with functions such as LodePNG_encode32,
1277 and more advanced decoding can be done with the struct LodePNG_Encoder and its
1278 functions. For C++, simple encoding can be done with the LodePNG::encode functions
1279 and advanced decoding with the LodePNG::Encoder class.
1280 
1281 Like the decoder, the encoder can also give errors. However it gives less errors
1282 since the encoder input is trusted, the decoder input (a PNG image that could
1283 be forged by anyone) is not trusted.
1284 
1285 Like the Decoder, the Encoder has 3 components:
1286 *) LodePNG_InfoRaw: here you say what color type of the raw image (the input) has
1287 *) Settings: you can specify a few settings for the encoder to use
1288 *) LodePNG_InfoPng: the same LodePNG_InfoPng struct as created by the Decoder. For the encoder,
1289 with this you specify how you want the PNG (the output) to be.
1290 
1291 Some of the parameters described below may be inside the sub-struct "LodePNG_InfoColor color".
1292 In the C and C++ version, when using Info structs outside of the decoder or encoder, you need to use their
1293 init and cleanup functions, but normally you use the ones in the encoder that are already handled
1294 in the init and cleanup functions of the decoder itself.
1295 
1296 =LodePNG_InfoPng=
1297 
1298 The Decoder class stores information about the PNG image in an LodePNG_InfoPng object. With
1299 the Encoder you can do the opposite: you give it an LodePNG_InfoPng object, and it'll try
1300 to match the LodePNG_InfoPng you give as close as possible in the PNG it encodes. For
1301 example in the LodePNG_InfoPng you can specify the color type you want to use, possible
1302 tEXt chunks you want the PNG to contain, etc... For an explanation of all the
1303 values in LodePNG_InfoPng see a further section. Not all PNG color types are supported
1304 by the Encoder.
1305 
1306 The encoder will not always exactly match the LodePNG_InfoPng struct you give,
1307 it tries as close as possible. Some things are ignored by the encoder. The width
1308 and height of LodePNG_InfoPng are ignored as well, because instead the width and
1309 height of the raw image you give in the input are used. In fact the encoder
1310 currently uses only the following settings from it:
1311 -colorType and bitDepth: the ones it supports
1312 -text chunks, that you can add to the LodePNG_InfoPng with "addText"
1313 -the color key, if applicable for the given color type
1314 -the palette, if you encode to a PNG with colorType 3
1315 -the background color: it'll add a bKGD chunk to the PNG if one is given
1316 -the interlaceMethod: None (0) or Adam7 (1)
1317 
1318 When encoding to a PNG with colorType 3, the encoder will generate a PLTE chunk.
1319 If the palette contains any colors for which the alpha channel is not 255 (so
1320 there are translucent colors in the palette), it'll add a tRNS chunk.
1321 
1322 =LodePNG_InfoRaw=
1323 
1324 You specify the color type of the raw image that you give to the input here,
1325 including a possible transparent color key and palette you happen to be using in
1326 your raw image data.
1327 
1328 By default, 32-bit color is assumed, meaning your input has to be in RGBA
1329 format with 4 bytes (unsigned chars) per pixel.
1330 
1331 =Settings=
1332 
1333 The following settings are supported (some are in sub-structs):
1334 *) autoLeaveOutAlphaChannel: when this option is enabled, when you specify a PNG
1335 color type with alpha channel (not to be confused with the color type of the raw
1336 image you specify!!), but the encoder detects that all pixels of the given image
1337 are opaque, then it'll automatically use the corresponding type without alpha
1338 channel, resulting in a smaller PNG image.
1339 *) btype: the block type for LZ77.
1340  0 = uncompressed, 1 = fixed huffman tree, 2 = dynamic huffman tree (best compression)
1341 *) useLZ77: whether or not to use LZ77 for compressed block types
1342 *) windowSize: the window size used by the LZ77 encoder (1 - 32768)
1343 *) force_palette: if colorType is 2 or 6, you can make the encoder write a PLTE
1344  chunk if force_palette is true. This can used as suggested palette to convert
1345  to by viewers that don't support more than 256 colors (if those still exist)
1346 *) add_id: add text chunk "Encoder: LodePNG <version>" to the image.
1347 *) text_compression: default 0. If 1, it'll store texts as zTXt instead of tEXt chunks.
1348  zTXt chunks use zlib compression on the text. This gives a smaller result on
1349  large texts but a larger result on small texts (such as a single program name).
1350  It's all tEXt or all zTXt though, there's no separate setting per text yet.
1351 
1352 
1353 6. color conversions
1354 --------------------
1355 
1356 In LodePNG, the color mode (bits, channels and palette) used in the PNG image,
1357 and the color mode used in the raw data, are separate and independently
1358 configurable. Therefore, LodePNG needs to do conversions from one color mode to
1359 another. Not all possible conversions are supported (e.g. converting to a palette
1360 or a lower bit depth isn't supported). This section will explain which conversions
1361 are supported and how to configure this. This explains for example when LodePNG
1362 uses the settings in LodePNG_InfoPng, LodePNG_InfoRaw and Settings.
1363 
1364 6.1. PNG color types
1365 --------------------
1366 
1367 A PNG image can have many color types, ranging from 1-bit color to 64-bit color,
1368 as well as palettized color modes. After the zlib decompression and unfiltering
1369 in the PNG image is done, the raw pixel data will have that color type and thus
1370 a certain amount of bits per pixel. If you want the output raw image after
1371 decoding to have another color type, a conversion is done by LodePNG.
1372 
1373 The PNG specification mentions the following color types:
1374 
1375 0: greyscale, bit depths 1, 2, 4, 8, 16
1376 2: RGB, bit depths 8 and 16
1377 3: palette, bit depths 1, 2, 4 and 8
1378 4: greyscale with alpha, bit depths 8 and 16
1379 6: RGBA, bit depths 8 and 16
1380 
1381 Bit depth is the amount of bits per pixel per color channel. So the total amount
1382 of bits per pixel = amount of channels * bitDepth.
1383 
1384 6.2. Default Behaviour of LodePNG
1385 ---------------------------------
1386 
1387 By default, the Decoder will convert the data from the PNG to 32-bit RGBA color,
1388 no matter what color type the PNG has, so that the result can be used directly
1389 as a texture in OpenGL etc... without worries about what color type the original
1390 image has.
1391 
1392 The Encoder assumes by default that the raw input you give it is a 32-bit RGBA
1393 buffer and will store the PNG as either 32 bit or 24 bit depending on whether
1394 or not any translucent pixels were detected in it.
1395 
1396 To get the default behaviour, don't change the values of LodePNG_InfoRaw and
1397 LodePNG_InfoPng of the encoder, and don't change the values of LodePNG_InfoRaw
1398 of the decoder.
1399 
1400 6.3. Color Conversions
1401 ----------------------
1402 
1403 As explained in the sections about the Encoder and Decoder, you can specify
1404 color types and bit depths in LodePNG_InfoPng and LodePNG_InfoRaw, to change the default behaviour
1405 explained above. (for the Decoder you can only specify the LodePNG_InfoRaw, because the
1406 LodePNG_InfoPng contains what the PNG file has).
1407 
1408 To avoid some confusion:
1409 -the Decoder converts from PNG to raw image
1410 -the Encoder converts from raw image to PNG
1411 -the color type and bit depth in LodePNG_InfoRaw, are those of the raw image
1412 -the color type and bit depth in LodePNG_InfoPng, are those of the PNG
1413 -if the color type of the LodePNG_InfoRaw and PNG image aren't the same, a conversion
1414 between the color types is done if the color types are supported. If it is not
1415 supported, an error is returned. If the types are the same, no conversion is done
1416 and this is supported for any color type.
1417 
1418 Supported color conversions:
1419 -It's possible to load PNGs from any colortype and to save PNGs of any colorType.
1420 -Both encoder and decoder use the same converter. So both encoder and decoder
1421 suport the same color types at the input and the output. So the decoder supports
1422 any type of PNG image and can convert it to certain types of raw image, while the
1423 encoder supports any type of raw data but only certain color types for the output PNG.
1424 -The converter can convert from _any_ input color type, to 24-bit RGB or 32-bit RGBA (8 bits per channel)
1425 -The converter can convert from _any_ input color type, to 48-bit RGB or 64-bit RGBA (16 bits per channel)
1426 -The converter can convert from greyscale input color type, to 8-bit greyscale or greyscale with alpha
1427 -The converter can convert from greyscale input color type, to 16-bit greyscale or greyscale with alpha
1428 -If both color types are the same, conversion from anything to anything is possible
1429 -Color types that are invalid according to the PNG specification are not allowed
1430 -When converting from a type with alpha channel to one without, the alpha channel information is discarded
1431 -When converting from a type without alpha channel to one with, the result will be opaque except
1432  pixels that have the same color as the color key of the input if one was given
1433 -When converting from 16-bit bitDepth to 8-bit bitDepth, the 16-bit precision information is lost,
1434  only the most significant byte is kept
1435 -When converting from 8-bit bitDepth to 16-bit bitDepth, the 8-bit byte is duplicated, so that 0 stays 0, and
1436  the 8-bit maximum 255 is converted to the 16-bit maximum 65535. Something similar happens at bit level for
1437  converting very low bit depths to 8 or 16 bit.
1438 -Converting from color to greyscale or to palette is not supported on purpose: there are multiple possible
1439  algorithms to do this color reduction, LodePNG does not want to pick one and leaves this choice to the
1440  user instead, because it's beyond the scope of PNG encoding.
1441 -Converting from a palette to a palette, only keeps the indices, it ignores the colors defined in the
1442  palette without giving an error
1443 
1444 No conversion needed...:
1445 -If the color type of the PNG image and raw image are the same, then no
1446 conversion is done, and all color types are supported.
1447 -In the encoder, you can make it save a PNG with any color by giving the
1448 LodePNG_InfoRaw and LodePNG_InfoPng the same color type.
1449 -In the decoder, you can make it store the pixel data in the same color type
1450 as the PNG has, by setting the color_convert setting to false. Settings in
1451 infoRaw are then ignored.
1452 
1453 The function LodePNG_convert does this, which is available in the interface but
1454 normally isn't needed since the encoder and decoder already call it.
1455 
1456 6.4. More Notes
1457 ---------------
1458 
1459 In the PNG file format, if a less than 8-bit per pixel color type is used and the scanlines
1460 have a bit amount that isn't a multiple of 8, then padding bits are used so that each
1461 scanline starts at a fresh byte. But that is NOT true for the LodePNG input and output!
1462 The raw input image you give to the encoder, and the raw output image you get from the decoder
1463 will NOT have these padding bits, e.g. in the case of a 1-bit image with a width
1464 of 7 pixels, the first pixel of the second scanline will the the 8th bit of the first byte,
1465 not the first bit of a new byte.
1466 
1467 7. error values
1468 ---------------
1469 
1470 All functions in LodePNG that return an error code, return 0 if everything went
1471 OK, or one of the code defined by LodePNG if there was an error.
1472 
1473 The meaning of the LodePNG error values can be retrieved with the function
1474 LodePNG_error_text: given the numerical error code, it returns a description
1475 of the error in English as a string.
1476 
1477 Check the implementation of LodePNG_error_text to see the meaning of each error code.
1478 
1479 
1480 8. chunks and PNG editing
1481 -------------------------
1482 
1483 If you want to add extra chunks to a PNG you encode, or use LodePNG for a PNG
1484 editor that should follow the rules about handling of unknown chunks, or if you
1485 program is able to read other types of chunks than the ones handled by LodePNG,
1486 then that's possible with the chunk functions of LodePNG.
1487 
1488 A PNG chunk has the following layout:
1489 
1490 4 bytes length
1491 4 bytes type name
1492 length bytes data
1493 4 bytes CRC
1494 
1495 
1496 8.1. iterating through chunks
1497 -----------------------------
1498 
1499 If you have a buffer containing the PNG image data, then the first chunk (the
1500 IHDR chunk) starts at byte number 8 of that buffer. The first 8 bytes are the
1501 signature of the PNG and are not part of a chunk. But if you start at byte 8
1502 then you have a chunk, and can check the following things of it.
1503 
1504 NOTE: none of these functions check for memory buffer boundaries. To avoid
1505 exploits, always make sure the buffer contains all the data of the chunks.
1506 When using LodePNG_chunk_next, make sure the returned value is within the
1507 allocated memory.
1508 
1509 unsigned LodePNG_chunk_length(const unsigned char* chunk):
1510 
1511 Get the length of the chunk's data. The total chunk length is this length + 12.
1512 
1513 void LodePNG_chunk_type(char type[5], const unsigned char* chunk):
1514 unsigned char LodePNG_chunk_type_equals(const unsigned char* chunk, const char* type):
1515 
1516 Get the type of the chunk or compare if it's a certain type
1517 
1518 unsigned char LodePNG_chunk_critical(const unsigned char* chunk):
1519 unsigned char LodePNG_chunk_private(const unsigned char* chunk):
1520 unsigned char LodePNG_chunk_safetocopy(const unsigned char* chunk):
1521 
1522 Check if the chunk is critical in the PNG standard (only IHDR, PLTE, IDAT and IEND are).
1523 Check if the chunk is private (public chunks are part of the standard, private ones not).
1524 Check if the chunk is safe to copy. If it's not, then, when modifying data in a critical
1525 chunk, unsafe to copy chunks of the old image may NOT be saved in the new one if your
1526 program doesn't handle that type of unknown chunk.
1527 
1528 unsigned char* LodePNG_chunk_data(unsigned char* chunk):
1529 const unsigned char* LodePNG_chunk_data_const(const unsigned char* chunk):
1530 
1531 Get a pointer to the start of the data of the chunk.
1532 
1533 unsigned LodePNG_chunk_check_crc(const unsigned char* chunk):
1534 void LodePNG_chunk_generate_crc(unsigned char* chunk):
1535 
1536 Check if the crc is correct or generate a correct one.
1537 
1538 unsigned char* LodePNG_chunk_next(unsigned char* chunk):
1539 const unsigned char* LodePNG_chunk_next_const(const unsigned char* chunk):
1540 
1541 Iterate to the next chunk. This works if you have a buffer with consecutive chunks. Note that these
1542 functions do no boundary checking of the allocated data whatsoever, so make sure there is enough
1543 data available in the buffer to be able to go to the next chunk.
1544 
1545 unsigned LodePNG_append_chunk(unsigned char** out, size_t* outlength, const unsigned char* chunk):
1546 unsigned LodePNG_create_chunk(unsigned char** out, size_t* outlength, unsigned length,
1547  const char* type, const unsigned char* data):
1548 
1549 These functions are used to create new chunks that are appended to the data in *out that has
1550 length *outlength. The append function appends an existing chunk to the new data. The create
1551 function creates a new chunk with the given parameters and appends it. Type is the 4-letter
1552 name of the chunk.
1553 
1554 
1555 8.2. chunks in infoPng
1556 ----------------------
1557 
1558 The LodePNG_InfoPng struct contains a struct LodePNG_UnknownChunks in it. This
1559 struct has 3 buffers (each with size) to contain 3 types of unknown chunks:
1560 the ones that come before the PLTE chunk, the ones that come between the PLTE
1561 and the IDAT chunks, and the ones that come after the IDAT chunks.
1562 It's necessary to make the distionction between these 3 cases because the PNG
1563 standard forces to keep the ordering of unknown chunks compared to the critical
1564 chunks, but does not force any other ordering rules.
1565 
1566 infoPng.unknown_chunks.data[0] is the chunks before PLTE
1567 infoPng.unknown_chunks.data[1] is the chunks after PLTE, before IDAT
1568 infoPng.unknown_chunks.data[2] is the chunks after IDAT
1569 
1570 The chunks in these 3 buffers can be iterated through and read by using the same
1571 way described in the previous subchapter.
1572 
1573 When using the decoder to decode a PNG, you can make it store all unknown chunks
1574 if you set the option settings.rememberUnknownChunks to 1. By default, this option
1575 is off and is 0.
1576 
1577 The encoder will always encode unknown chunks that are stored in the infoPng. If
1578 you need it to add a particular chunk that isn't known by LodePNG, you can use
1579 LodePNG_append_chunk or LodePNG_create_chunk to the chunk data in
1580 infoPng.unknown_chunks.data[x].
1581 
1582 Chunks that are known by LodePNG should not be added in that way. E.g. to make
1583 LodePNG add a bKGD chunk, set background_defined to true and add the correct
1584 parameters there and LodePNG will generate the chunk.
1585 
1586 
1587 9. compiler support
1588 -------------------
1589 
1590 No libraries other than the current standard C library are needed to compile
1591 LodePNG. For the C++ version, only the standard C++ library is needed on top.
1592 Add the files lodepng.c(pp) and lodepng.h to your project, include
1593 lodepng.h where needed, and your program can read/write PNG files.
1594 
1595 Use optimization! For both the encoder and decoder, compiling with the best
1596 optimizations makes a large difference.
1597 
1598 Make sure that LodePNG is compiled with the same compiler of the same version
1599 and with the same settings as the rest of the program, or the interfaces with
1600 std::vectors and std::strings in C++ can be incompatible resulting in bad things.
1601 
1602 CHAR_BITS must be 8 or higher, because LodePNG uses unsigned chars for octets.
1603 
1604 *) gcc and g++
1605 
1606 LodePNG is developed in gcc so this compiler is natively supported. It gives no
1607 warnings with compiler options "-Wall -Wextra -pedantic -ansi", with gcc and g++
1608 version 4.5.1 on Linux.
1609 
1610 *) Mingw and Bloodshed DevC++
1611 
1612 The Mingw compiler (a port of gcc) used by Bloodshed DevC++ for Windows is fully
1613 supported by LodePNG.
1614 
1615 *) Visual Studio 2005 and Visual C++ 2005 Express Edition
1616 
1617 Versions 20070604 up to 20080107 have been tested on VS2005 and work. Visual
1618 studio may give warnings about 'fopen' being deprecated. A multiplatform library
1619 can't support the proposed Visual Studio alternative however.
1620 
1621 If you're using LodePNG in VS2005 and don't want to see the deprecated warnings,
1622 put this on top of lodepng.h before the inclusions: #define _CRT_SECURE_NO_DEPRECATE
1623 
1624 *) Visual Studio 6.0
1625 
1626 The C++ version of LodePNG was not supported by Visual Studio 6.0 because Visual
1627 Studio 6.0 doesn't follow the C++ standard and implements it incorrectly.
1628 The current C version of LodePNG has not been tested in VS6 but may work now.
1629 
1630 *) Comeau C/C++
1631 
1632 Vesion 20070107 compiles without problems on the Comeau C/C++ Online Test Drive
1633 at http://www.comeaucomputing.com/tryitout in both C90 and C++ mode.
1634 
1635 *) Compilers on Macintosh
1636 
1637 LodePNG has been reported to work both with the gcc and LLVM for Macintosh, both
1638 for C and C++.
1639 
1640 *) Other Compilers
1641 
1642 If you encounter problems on other compilers, I'm happy to help out make LodePNG
1643 support the compiler if it supports the ISO C90 and C++ standard well enough and
1644 the required modification doesn't require using non standard or less good C/C++
1645 code or headers.
1646 
1647 
1648 10. examples
1649 ------------
1650 
1651 This decoder and encoder example show the most basic usage of LodePNG (using the
1652 classes, not the simple functions, which would be trivial)
1653 
1654 More complex examples can be found in:
1655 -lodepng_examples.c: 9 different examples in C, such as showing the image with SDL, ...
1656 -lodepng_examples.cpp: the same examples in C++ using the C++ wrapper of LodePNG
1657 
1658 These files can be found on the LodePNG website or searched for on the internet.
1659 
1660 10.1. decoder C++ example
1661 -------------------------
1662 
1664 #include "lodepng.h"
1665 #include <iostream>
1666 
1667 int main(int argc, char *argv[])
1668 {
1669  const char* filename = argc > 1 ? argv[1] : "test.png";
1670 
1671  //load and decode
1672  std::vector<unsigned char> buffer, image; //buffer will contain the PNG file, image will contain the raw pixels
1673  LodePNG::loadFile(buffer, filename); //load the image file with given filename
1674  LodePNG::Decoder decoder;
1675  decoder.decode(image, buffer.size() ? &buffer[0] : 0, (unsigned)buffer.size()); //decode the png
1676 
1677  //if there's an error, display it
1678  if(decoder.hasError())
1679  std::cout << "error " << decoder.getError() << ": "<< LodePNG_error_text(decoder.getError()) << std::endl;
1680 
1681  int width = decoder.getWidth(); //get the width in pixels
1682  int height = decoder.getHeight(); //get the height in pixels
1683  //the pixels are now in the vector "image", 4 bytes per pixel, ordered RGBARGBA..., use it as texture, draw it, ...
1684 }
1685 
1686 //alternative version using the "simple" function
1687 int main(int argc, char *argv[])
1688 {
1689  const char* filename = argc > 1 ? argv[1] : "test.png";
1690 
1691  //load and decode
1692  std::vector<unsigned char> image;
1693  unsigned width, height;
1694  unsigned error = LodePNG::decode(image, width, height, filename);
1695 
1696  //if there's an error, display it
1697  if(error != 0) std::cout << "error " << error << ": " << LodePNG_error_text(error) << std::endl;
1698 
1699  //the pixels are now in the vector "image", 4 bytes per pixel, ordered RGBARGBA..., use it as texture, draw it, ...
1700 }
1702 
1703 
1704 10.2. encoder C++ example
1705 -------------------------
1706 
1708 #include "lodepng.h"
1709 #include <iostream>
1710 
1711 //saves image to filename given as argument. Warning, this overwrites the file without warning!
1712 int main(int argc, char *argv[])
1713 {
1714  //check if user gave a filename
1715  if(argc <= 1)
1716  {
1717  std::cout << "please provide a filename to save to\n";
1718  return 0;
1719  }
1720 
1721  //generate some image
1722  std::vector<unsigned char> image;
1723  image.resize(512 * 512 * 4);
1724  for(unsigned y = 0; y < 512; y++)
1725  for(unsigned x = 0; x < 512; x++)
1726  {
1727  image[4 * 512 * y + 4 * x + 0] = 255 * !(x & y);
1728  image[4 * 512 * y + 4 * x + 1] = x ^ y;
1729  image[4 * 512 * y + 4 * x + 2] = x | y;
1730  image[4 * 512 * y + 4 * x + 3] = 255;
1731  }
1732 
1733  //encode and save, using the Encoder class
1734  std::vector<unsigned char> buffer;
1735  LodePNG::Encoder encoder;
1736  encoder.encode(buffer, image, 512, 512);
1737  LodePNG::saveFile(buffer, argv[1]);
1738 
1739  //the same as the 4 lines of code above, but in 1 call without the class:
1740  //LodePNG::encode(argv[1], image, 512, 512);
1741 }
1743 
1744 
1745 10.3. Decoder C example
1746 -----------------------
1747 
1748 This example loads the PNG from a file into a pixel buffer in 1 function call
1749 
1750 #include "lodepng.h"
1751 
1752 int main(int argc, char *argv[])
1753 {
1754  unsigned error;
1755  unsigned char* image;
1756  size_t width, height;
1757 
1758  if(argc <= 1) return 0;
1759 
1760  error = LodePNG_decode32_file(&image, &width, &height, filename);
1761 
1762  if(error != 0) printf("error %u: %s\n", error, LodePNG_error_text(error));
1763 
1764  //use image here
1765 
1766  free(image);
1767 }
1768 
1769 
1770 11. changes
1771 -----------
1772 
1773 The version number of LodePNG is the date of the change given in the format
1774 yyyymmdd.
1775 
1776 Some changes aren't backwards compatible. Those are indicated with a (!)
1777 symbol.
1778 
1779 *) 23 aug 2011: tweaked the zlib compression parameters after benchmarking.
1780  A bug with the PNG filtertype heuristic was fixed, so that it chooses much
1781  better ones (it's quite significant). A setting to do an experimental, slow,
1782  brute force search for PNG filter types is added.
1783 *) 17 aug 2011 (!): changed some C zlib related function names.
1784 *) 16 aug 2011: made the code less wide (max 120 characters per line).
1785 *) 17 apr 2011: code cleanup. Bugfixes. Convert low to 16-bit per sample colors.
1786 *) 21 feb 2011: fixed compiling for C90. Fixed compiling with sections disabled.
1787 *) 11 dec 2010: encoding is made faster, based on suggestion by Peter Eastman
1788  to optimize long sequences of zeros.
1789 *) 13 nov 2010: added LodePNG_InfoColor_hasPaletteAlpha and
1790  LodePNG_InfoColor_canHaveAlpha functions for convenience.
1791 *) 7 nov 2010: added LodePNG_error_text function to get error code description.
1792 *) 30 okt 2010: made decoding slightly faster
1793 *) 26 okt 2010: (!) changed some C function and struct names (more consistent).
1794  Reorganized the documentation and the declaration order in the header.
1795 *) 08 aug 2010: only changed some comments and external samples.
1796 *) 05 jul 2010: fixed bug thanks to warnings in the new gcc version.
1797 *) 14 mar 2010: fixed bug where too much memory was allocated for char buffers.
1798 *) 02 sep 2008: fixed bug where it could create empty tree that linux apps could
1799  read by ignoring the problem but windows apps couldn't.
1800 *) 06 jun 2008: added more error checks for out of memory cases.
1801 *) 26 apr 2008: added a few more checks here and there to ensure more safety.
1802 *) 06 mar 2008: crash with encoding of strings fixed
1803 *) 02 feb 2008: support for international text chunks added (iTXt)
1804 *) 23 jan 2008: small cleanups, and #defines to divide code in sections
1805 *) 20 jan 2008: support for unknown chunks allowing using LodePNG for an editor.
1806 *) 18 jan 2008: support for tIME and pHYs chunks added to encoder and decoder.
1807 *) 17 jan 2008: ability to encode and decode compressed zTXt chunks added
1808  Also vareous fixes, such as in the deflate and the padding bits code.
1809 *) 13 jan 2008: Added ability to encode Adam7-interlaced images. Improved
1810  filtering code of encoder.
1811 *) 07 jan 2008: (!) changed LodePNG to use ISO C90 instead of C++. A
1812  C++ wrapper around this provides an interface almost identical to before.
1813  Having LodePNG be pure ISO C90 makes it more portable. The C and C++ code
1814  are together in these files but it works both for C and C++ compilers.
1815 *) 29 dec 2007: (!) changed most integer types to unsigned int + other tweaks
1816 *) 30 aug 2007: bug fixed which makes this Borland C++ compatible
1817 *) 09 aug 2007: some VS2005 warnings removed again
1818 *) 21 jul 2007: deflate code placed in new namespace separate from zlib code
1819 *) 08 jun 2007: fixed bug with 2- and 4-bit color, and small interlaced images
1820 *) 04 jun 2007: improved support for Visual Studio 2005: crash with accessing
1821  invalid std::vector element [0] fixed, and level 3 and 4 warnings removed
1822 *) 02 jun 2007: made the encoder add a tag with version by default
1823 *) 27 may 2007: zlib and png code separated (but still in the same file),
1824  simple encoder/decoder functions added for more simple usage cases
1825 *) 19 may 2007: minor fixes, some code cleaning, new error added (error 69),
1826  moved some examples from here to lodepng_examples.cpp
1827 *) 12 may 2007: palette decoding bug fixed
1828 *) 24 apr 2007: changed the license from BSD to the zlib license
1829 *) 11 mar 2007: very simple addition: ability to encode bKGD chunks.
1830 *) 04 mar 2007: (!) tEXt chunk related fixes, and support for encoding
1831  palettized PNG images. Plus little interface change with palette and texts.
1832 *) 03 mar 2007: Made it encode dynamic Huffman shorter with repeat codes.
1833  Fixed a bug where the end code of a block had length 0 in the Huffman tree.
1834 *) 26 feb 2007: Huffman compression with dynamic trees (BTYPE 2) now implemented
1835  and supported by the encoder, resulting in smaller PNGs at the output.
1836 *) 27 jan 2007: Made the Adler-32 test faster so that a timewaste is gone.
1837 *) 24 jan 2007: gave encoder an error interface. Added color conversion from any
1838  greyscale type to 8-bit greyscale with or without alpha.
1839 *) 21 jan 2007: (!) Totally changed the interface. It allows more color types
1840  to convert to and is more uniform. See the manual for how it works now.
1841 *) 07 jan 2007: Some cleanup & fixes, and a few changes over the last days:
1842  encode/decode custom tEXt chunks, separate classes for zlib & deflate, and
1843  at last made the decoder give errors for incorrect Adler32 or Crc.
1844 *) 01 jan 2007: Fixed bug with encoding PNGs with less than 8 bits per channel.
1845 *) 29 dec 2006: Added support for encoding images without alpha channel, and
1846  cleaned out code as well as making certain parts faster.
1847 *) 28 dec 2006: Added "Settings" to the encoder.
1848 *) 26 dec 2006: The encoder now does LZ77 encoding and produces much smaller files now.
1849  Removed some code duplication in the decoder. Fixed little bug in an example.
1850 *) 09 dec 2006: (!) Placed output parameters of public functions as first parameter.
1851  Fixed a bug of the decoder with 16-bit per color.
1852 *) 15 okt 2006: Changed documentation structure
1853 *) 09 okt 2006: Encoder class added. It encodes a valid PNG image from the
1854  given image buffer, however for now it's not compressed.
1855 *) 08 sep 2006: (!) Changed to interface with a Decoder class
1856 *) 30 jul 2006: (!) LodePNG_InfoPng , width and height are now retrieved in different
1857  way. Renamed decodePNG to decodePNGGeneric.
1858 *) 29 jul 2006: (!) Changed the interface: image info is now returned as a
1859  struct of type LodePNG::LodePNG_Info, instead of a vector, which was a bit clumsy.
1860 *) 28 jul 2006: Cleaned the code and added new error checks.
1861  Corrected terminology "deflate" into "inflate".
1862 *) 23 jun 2006: Added SDL example in the documentation in the header, this
1863  example allows easy debugging by displaying the PNG and its transparency.
1864 *) 22 jun 2006: (!) Changed way to obtain error value. Added
1865  loadFile function for convenience. Made decodePNG32 faster.
1866 *) 21 jun 2006: (!) Changed type of info vector to unsigned.
1867  Changed position of palette in info vector. Fixed an important bug that
1868  happened on PNGs with an uncompressed block.
1869 *) 16 jun 2006: Internally changed unsigned into unsigned where
1870  needed, and performed some optimizations.
1871 *) 07 jun 2006: (!) Renamed functions to decodePNG and placed them
1872  in LodePNG namespace. Changed the order of the parameters. Rewrote the
1873  documentation in the header. Renamed files to lodepng.cpp and lodepng.h
1874 *) 22 apr 2006: Optimized and improved some code
1875 *) 07 sep 2005: (!) Changed to std::vector interface
1876 *) 12 aug 2005: Initial release (C++, decoder only)
1877 
1878 
1879 12. contact information
1880 -----------------------
1881 
1882 Feel free to contact me with suggestions, problems, comments, ... concerning
1883 LodePNG. If you encounter a PNG image that doesn't work properly with this
1884 decoder, feel free to send it and I'll use it to find and fix the problem.
1885 
1886 My email address is (puzzle the account and domain together with an @ symbol):
1887 Domain: gmail dot com.
1888 Account: lode dot vandevenne.
1889 
1890 
1891 Copyright (c) 2005-2011 Lode Vandevenne
1892 */
unsigned autoLeaveOutAlphaChannel
Definition: lodepng.h:699
LodePNG_InfoRaw infoRaw
Definition: lodepng.h:650
void LodePNG_chunk_generate_crc(unsigned char *chunk)
Definition: lodepng.cpp:2342
const unsigned char * LodePNG_chunk_data_const(const unsigned char *chunk)
Definition: lodepng.cpp:2327
unsigned LodePNG_InfoColor_isAlphaType(const LodePNG_InfoColor *info)
Definition: lodepng.cpp:2510
char ** transkeys
Definition: lodepng.h:477
struct LodePNG_Decoder LodePNG_Decoder
unsigned LodePNG_chunk_length(const unsigned char *chunk)
Definition: lodepng.cpp:2289
LodePNG_Text text
Definition: lodepng.h:558
void LodePNG_UnknownChunks_cleanup(LodePNG_UnknownChunks *chunks)
Definition: lodepng.cpp:2551
void LodePNG_chunk_type(char type[5], const unsigned char *chunk)
Definition: lodepng.cpp:2294
struct LodePNG_InfoPng LodePNG_InfoPng
char ** langtags
Definition: lodepng.h:475
unsigned bruteForceFilters
Definition: lodepng.h:696
struct LodePNG_DecodeSettings LodePNG_DecodeSettings
void LodePNG_IText_clear(LodePNG_IText *text)
Definition: lodepng.cpp:2672
void LodePNG_Decoder_cleanup(LodePNG_Decoder *decoder)
Definition: lodepng.cpp:4186
unsigned LodePNG_encode32(unsigned char **out, size_t *outsize, const unsigned char *image, unsigned w, unsigned h)
Definition: lodepng.cpp:5158
unsigned char LodePNG_chunk_private(const unsigned char *chunk)
Definition: lodepng.cpp:2312
void LodePNG_Decoder_copy(LodePNG_Decoder *dest, const LodePNG_Decoder *source)
Definition: lodepng.cpp:4192
unsigned phys_defined
Definition: lodepng.h:568
unsigned height
Definition: lodepng.h:534
char ** strings
Definition: lodepng.h:479
unsigned LodePNG_chunk_check_crc(const unsigned char *chunk)
Definition: lodepng.cpp:2332
unsigned filterMethod
Definition: lodepng.h:536
void LodePNG_DecodeSettings_init(LodePNG_DecodeSettings *settings)
Definition: lodepng.cpp:4165
unsigned char LodePNG_chunk_safetocopy(const unsigned char *chunk)
Definition: lodepng.cpp:2317
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer
Definition: DLLImports.inl:315
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid * data
Definition: DLLImports.inl:319
void LodePNG_Encoder_cleanup(LodePNG_Encoder *encoder)
Definition: lodepng.cpp:5211
unsigned LodePNG_InfoColor_getBpp(const LodePNG_InfoColor *info)
Definition: lodepng.cpp:2494
unsigned char hour
Definition: lodepng.h:420
unsigned LodePNG_decode24_file(unsigned char **out, unsigned *w, unsigned *h, const char *filename)
Definition: lodepng.cpp:4159
char ** keys
Definition: lodepng.h:473
unsigned char * data[3]
Definition: lodepng.h:509
unsigned char month
Definition: lodepng.h:418
LodePNG_DecompressSettings zlibsettings
Definition: lodepng.h:625
LodePNG_IText itext
Definition: lodepng.h:561
size_t num
Definition: lodepng.h:471
unsigned LodePNG_encode(unsigned char **out, size_t *outsize, const unsigned char *image, unsigned w, unsigned h, unsigned colorType, unsigned bitDepth)
Definition: lodepng.cpp:5142
LodePNG_DecodeSettings settings
Definition: lodepng.h:649
unsigned LodePNG_encode24(unsigned char **out, size_t *outsize, const unsigned char *image, unsigned w, unsigned h)
Definition: lodepng.cpp:5163
unsigned LodePNG_InfoColor_copy(LodePNG_InfoColor *dest, const LodePNG_InfoColor *source)
Definition: lodepng.cpp:2787
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type GLsizei const GLuint framebuffers GLsizei const GLuint renderbuffers GLuint v GLuint v GLenum GLenum GLenum GLuint GLint level GLsizei GLuint framebuffers GLuint const GLchar name GLenum GLintptr GLsizeiptr GLvoid data GLuint GLenum GLint param GLuint GLenum GLint param GLhandleARB programObj GLenum GLenum GLsizei GLsizei height GLenum GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid pixels GLint GLsizei const GLfloat value GLint GLfloat GLfloat v1 GLint GLfloat GLfloat GLfloat v2 GLint GLsizei const GLfloat value GLint GLsizei GLboolean const GLfloat value GLuint program GLuint GLfloat GLfloat GLfloat z GLuint GLint GLenum GLboolean GLsizei const GLvoid pointer GLuint GLuint const GLchar name GLenum GLsizei GLenum GLsizei GLsizei height GLenum GLuint renderbuffer GLenum GLenum GLint params GLuint GLsizei range GLuint GLsizei const GLubyte GLsizei GLenum const GLvoid coords GLuint GLsizei GLsizei GLsizei const GLubyte GLsizei GLenum const GLvoid coords GLuint GLenum GLsizei length
Definition: DLLImports.inl:388
unsigned char time_defined
Definition: lodepng.h:564
unsigned LodePNG_UnknownChunks_copy(LodePNG_UnknownChunks *dest, const LodePNG_UnknownChunks *src)
Definition: lodepng.cpp:2557
void LodePNG_EncodeSettings_init(LodePNG_EncodeSettings *settings)
Definition: lodepng.cpp:5191
unsigned char day
Definition: lodepng.h:419
void LodePNG_IText_cleanup(LodePNG_IText *text)
Definition: lodepng.cpp:2650
unsigned LodePNG_loadFile(unsigned char **out, size_t *outsize, const char *filename)
Definition: lodepng.cpp:393
unsigned char * LodePNG_chunk_data(unsigned char *chunk)
Definition: lodepng.cpp:2322
unsigned LodePNG_encode32_file(const char *filename, const unsigned char *image, unsigned w, unsigned h)
Definition: lodepng.cpp:5180
void LodePNG_InfoPng_cleanup(LodePNG_InfoPng *info)
Definition: lodepng.cpp:2748
const LodePNG_CompressSettings LodePNG_defaultCompressSettings
Definition: lodepng.cpp:2173
unsigned char * LodePNG_chunk_next(unsigned char *chunk)
Definition: lodepng.cpp:2349
unsigned LodePNG_zlib_decompress(unsigned char **out, size_t *outsize, const unsigned char *in, size_t insize, const LodePNG_DecompressSettings *settings)
Definition: lodepng.cpp:2032
unsigned text_compression
Definition: lodepng.h:707
void LodePNG_CompressSettings_init(LodePNG_CompressSettings *settings)
Definition: lodepng.cpp:2165
LodePNG_CompressSettings zlibsettings
Definition: lodepng.h:686
void LodePNG_IText_init(LodePNG_IText *text)
Definition: lodepng.cpp:2641
LodePNG_InfoPng infoPng
Definition: lodepng.h:651
unsigned char LodePNG_chunk_critical(const unsigned char *chunk)
Definition: lodepng.cpp:2307
void LodePNG_InfoRaw_init(LodePNG_InfoRaw *info)
Definition: lodepng.cpp:2798
unsigned interlaceMethod
Definition: lodepng.h:537
struct LodePNG_Text LodePNG_Text
void LodePNG_Decoder_init(LodePNG_Decoder *decoder)
Definition: lodepng.cpp:4178
unsigned LodePNG_encode24_file(const char *filename, const unsigned char *image, unsigned w, unsigned h)
Definition: lodepng.cpp:5185
unsigned LodePNG_InfoColor_addPalette(LodePNG_InfoColor *info, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
Definition: lodepng.cpp:2472
unsigned LodePNG_decode24(unsigned char **out, unsigned *w, unsigned *h, const unsigned char *in, size_t insize)
Definition: lodepng.cpp:4136
void LodePNG_InfoPng_init(LodePNG_InfoPng *info)
Definition: lodepng.cpp:2726
unsigned LodePNG_encode_file(const char *filename, const unsigned char *image, unsigned w, unsigned h, unsigned colorType, unsigned bitDepth)
Definition: lodepng.cpp:5169
void LodePNG_Encoder_copy(LodePNG_Encoder *dest, const LodePNG_Encoder *source)
Definition: lodepng.cpp:5217
unsigned bitDepth
Definition: lodepng.h:337
unsigned LodePNG_InfoColor_getChannels(const LodePNG_InfoColor *info)
Definition: lodepng.cpp:2500
struct LodePNG_Time LodePNG_Time
LodePNG_Time time
Definition: lodepng.h:565
void LodePNG_DecompressSettings_init(LodePNG_DecompressSettings *settings)
Definition: lodepng.cpp:2179
unsigned LodePNG_InfoPng_copy(LodePNG_InfoPng *dest, const LodePNG_InfoPng *source)
Definition: lodepng.cpp:2760
unsigned LodePNG_decode32(unsigned char **out, unsigned *w, unsigned *h, const unsigned char *in, size_t insize)
Definition: lodepng.cpp:4131
void LodePNG_Text_init(LodePNG_Text *text)
Definition: lodepng.cpp:2577
unsigned LodePNG_InfoColor_canHaveAlpha(const LodePNG_InfoColor *info)
Definition: lodepng.cpp:2530
void LodePNG_Text_cleanup(LodePNG_Text *text)
Definition: lodepng.cpp:2584
void LodePNG_Encoder_encode(LodePNG_Encoder *encoder, unsigned char **out, size_t *outsize, const unsigned char *image, unsigned w, unsigned h)
Definition: lodepng.cpp:4938
#define LCT_RGBA
Definition: lodepng.h:81
unsigned key_r
Definition: lodepng.h:366
unsigned LodePNG_convert(unsigned char *out, const unsigned char *in, LodePNG_InfoColor *infoOut, LodePNG_InfoColor *infoIn, unsigned w, unsigned h)
Definition: lodepng.cpp:3257
unsigned LodePNG_create_chunk(unsigned char **out, size_t *outlength, unsigned length, const char *type, const unsigned char *data)
Definition: lodepng.cpp:2380
void LodePNG_InfoColor_clearPalette(LodePNG_InfoColor *info)
Definition: lodepng.cpp:2466
const String & getError(void)
Definition: Defs.cpp:296
unsigned readTextChunks
Definition: lodepng.h:631
unsigned LodePNG_InfoColor_isGreyscaleType(const LodePNG_InfoColor *info)
Definition: lodepng.cpp:2505
void LodePNG_InfoColor_cleanup(LodePNG_InfoColor *info)
Definition: lodepng.cpp:2461
const unsigned char * LodePNG_chunk_next_const(const unsigned char *chunk)
Definition: lodepng.cpp:2355
size_t palettesize
Definition: lodepng.h:355
unsigned background_g
Definition: lodepng.h:554
struct LodePNG_EncodeSettings LodePNG_EncodeSettings
unsigned LodePNG_IText_copy(LodePNG_IText *dest, const LodePNG_IText *source)
Definition: lodepng.cpp:2655
unsigned char minute
Definition: lodepng.h:421
unsigned LodePNG_IText_add(LodePNG_IText *text, const char *key, const char *langtag, const char *transkey, const char *str)
Definition: lodepng.cpp:2688
unsigned LodePNG_append_chunk(unsigned char **out, size_t *outlength, const unsigned char *chunk)
Definition: lodepng.cpp:2361
void LodePNG_Decoder_decode(LodePNG_Decoder *decoder, unsigned char **out, size_t *outsize, const unsigned char *in, size_t insize)
Definition: lodepng.cpp:4068
unsigned colorType
Definition: lodepng.h:336
char ** strings
Definition: lodepng.h:444
unsigned background_r
Definition: lodepng.h:553
unsigned background_b
Definition: lodepng.h:555
unsigned error
Definition: lodepng.h:728
unsigned LodePNG_decode(unsigned char **out, unsigned *w, unsigned *h, const unsigned char *in, size_t insize, unsigned colorType, unsigned bitDepth)
Definition: lodepng.cpp:4114
size_t num
Definition: lodepng.h:442
size_t datasize[3]
Definition: lodepng.h:510
void LodePNG_UnknownChunks_init(LodePNG_UnknownChunks *chunks)
Definition: lodepng.cpp:2544
unsigned LodePNG_decode_file(unsigned char **out, unsigned *w, unsigned *h, const char *filename, unsigned colorType, unsigned bitDepth)
Definition: lodepng.cpp:4142
unsigned phys_x
Definition: lodepng.h:569
bool hasError(void)
Definition: Defs.cpp:289
struct LodePNG_DecompressSettings LodePNG_DecompressSettings
struct LodePNG_UnknownChunks LodePNG_UnknownChunks
struct LodePNG_CompressSettings LodePNG_CompressSettings
unsigned year
Definition: lodepng.h:417
unsigned LodePNG_InfoColor_hasPaletteAlpha(const LodePNG_InfoColor *info)
Definition: lodepng.cpp:2520
unsigned rememberUnknownChunks
Definition: lodepng.h:636
unsigned LodePNG_saveFile(const unsigned char *buffer, size_t buffersize, const char *filename)
Definition: lodepng.cpp:421
unsigned key_g
Definition: lodepng.h:367
unsigned LodePNG_InfoRaw_copy(LodePNG_InfoRaw *dest, const LodePNG_InfoRaw *source)
Definition: lodepng.cpp:2808
unsigned LodePNG_zlib_compress(unsigned char **out, size_t *outsize, const unsigned char *in, size_t insize, const LodePNG_CompressSettings *settings)
Definition: lodepng.cpp:2086
unsigned background_defined
Definition: lodepng.h:552
unsigned LodePNG_Text_add(LodePNG_Text *text, const char *key, const char *str)
Definition: lodepng.cpp:2615
unsigned color_convert
Definition: lodepng.h:628
LodePNG_EncodeSettings settings
Definition: lodepng.h:721
void LodePNG_Text_clear(LodePNG_Text *text)
Definition: lodepng.cpp:2603
const LodePNG_DecompressSettings LodePNG_defaultDecompressSettings
Definition: lodepng.cpp:2184
LodePNG_InfoColor color
Definition: lodepng.h:538
unsigned force_palette
Definition: lodepng.h:702
unsigned LodePNG_Text_copy(LodePNG_Text *dest, const LodePNG_Text *source)
Definition: lodepng.cpp:2589
unsigned char * palette
Definition: lodepng.h:354
struct LodePNG_IText LodePNG_IText
unsigned compressionMethod
Definition: lodepng.h:535
LodePNG_InfoPng infoPng
Definition: lodepng.h:724
unsigned width
Definition: lodepng.h:533
unsigned LodePNG_decode32_file(unsigned char **out, unsigned *w, unsigned *h, const char *filename)
Definition: lodepng.cpp:4154
unsigned LodePNG_InfoColor_isPaletteType(const LodePNG_InfoColor *info)
Definition: lodepng.cpp:2515
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type
Definition: DLLImports.inl:323
void LodePNG_Encoder_init(LodePNG_Encoder *encoder)
Definition: lodepng.cpp:5203
unsigned key_b
Definition: lodepng.h:368
unsigned phys_y
Definition: lodepng.h:570
unsigned char second
Definition: lodepng.h:422
unsigned char phys_unit
Definition: lodepng.h:571
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void * image
Definition: DLLImports.inl:60
unsigned char LodePNG_chunk_type_equals(const unsigned char *chunk, const char *type)
Definition: lodepng.cpp:2301
LodePNG_InfoRaw infoRaw
Definition: lodepng.h:726
struct LodePNG_Encoder LodePNG_Encoder
struct LodePNG_InfoColor LodePNG_InfoColor
void LodePNG_Decoder_inspect(LodePNG_Decoder *decoder, const unsigned char *in, size_t insize)
Definition: lodepng.cpp:3359
unsigned error
Definition: lodepng.h:652
void LodePNG_InfoRaw_cleanup(LodePNG_InfoRaw *info)
Definition: lodepng.cpp:2803
void LodePNG_InfoColor_init(LodePNG_InfoColor *info)
Definition: lodepng.cpp:2451
LodePNG_UnknownChunks unknown_chunks
Definition: lodepng.h:576
unsigned key_defined
Definition: lodepng.h:365
LodePNG_InfoColor color
Definition: lodepng.h:593
char ** keys
Definition: lodepng.h:443
const char * LodePNG_error_text(unsigned code)
Definition: lodepng.cpp:5239
struct LodePNG_InfoRaw LodePNG_InfoRaw