Path: blob/a-new-beginning/SharedDependencies/Sources/lodepng/include/lodepng.h
2 views
/*1LodePNG version 2025050623Copyright (c) 2005-2025 Lode Vandevenne45This software is provided 'as-is', without any express or implied6warranty. In no event will the authors be held liable for any damages7arising from the use of this software.89Permission is granted to anyone to use this software for any purpose,10including commercial applications, and to alter it and redistribute it11freely, subject to the following restrictions:12131. The origin of this software must not be misrepresented; you must not14claim that you wrote the original software. If you use this software15in a product, an acknowledgment in the product documentation would be16appreciated but is not required.17182. Altered source versions must be plainly marked as such, and must not be19misrepresented as being the original software.20213. This notice may not be removed or altered from any source22distribution.23*/2425#ifndef LODEPNG_H26#define LODEPNG_H2728#include <string.h> /*for size_t*/2930extern const char* LODEPNG_VERSION_STRING;3132/*33The following #defines are used to create code sections. They can be disabled34to disable code sections, which can give faster compile time and smaller binary.35The "NO_COMPILE" defines are designed to be used to pass as defines to the36compiler command to disable them without modifying this header, e.g.37-DLODEPNG_NO_COMPILE_ZLIB for gcc or clang.38*/39/*deflate & zlib. If disabled, you must specify alternative zlib functions in40the custom_zlib field of the compress and decompress settings*/41#ifndef LODEPNG_NO_COMPILE_ZLIB42/*pass -DLODEPNG_NO_COMPILE_ZLIB to the compiler to disable this, or comment out LODEPNG_COMPILE_ZLIB below*/43#define LODEPNG_COMPILE_ZLIB44#endif4546/*png encoder and png decoder*/47#ifndef LODEPNG_NO_COMPILE_PNG48/*pass -DLODEPNG_NO_COMPILE_PNG to the compiler to disable this, or comment out LODEPNG_COMPILE_PNG below*/49#define LODEPNG_COMPILE_PNG50#endif5152/*deflate&zlib decoder and png decoder*/53#ifndef LODEPNG_NO_COMPILE_DECODER54/*pass -DLODEPNG_NO_COMPILE_DECODER to the compiler to disable this, or comment out LODEPNG_COMPILE_DECODER below*/55#define LODEPNG_COMPILE_DECODER56#endif5758/*deflate&zlib encoder and png encoder*/59#ifndef LODEPNG_NO_COMPILE_ENCODER60/*pass -DLODEPNG_NO_COMPILE_ENCODER to the compiler to disable this, or comment out LODEPNG_COMPILE_ENCODER below*/61#define LODEPNG_COMPILE_ENCODER62#endif6364/*the optional built in harddisk file loading and saving functions*/65#ifndef LODEPNG_NO_COMPILE_DISK66/*pass -DLODEPNG_NO_COMPILE_DISK to the compiler to disable this, or comment out LODEPNG_COMPILE_DISK below*/67#define LODEPNG_COMPILE_DISK68#endif6970/*support for chunks other than IHDR, IDAT, PLTE, tRNS, IEND: ancillary and unknown chunks*/71#ifndef LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS72/*pass -DLODEPNG_NO_COMPILE_ANCILLARY_CHUNKS to the compiler to disable this,73or comment out LODEPNG_COMPILE_ANCILLARY_CHUNKS below*/74#define LODEPNG_COMPILE_ANCILLARY_CHUNKS75#endif7677/*ability to convert error numerical codes to English text string*/78#ifndef LODEPNG_NO_COMPILE_ERROR_TEXT79/*pass -DLODEPNG_NO_COMPILE_ERROR_TEXT to the compiler to disable this,80or comment out LODEPNG_COMPILE_ERROR_TEXT below*/81#define LODEPNG_COMPILE_ERROR_TEXT82#endif8384/*Compile the default allocators (C's free, malloc and realloc). If you disable this,85you can define the functions lodepng_free, lodepng_malloc and lodepng_realloc in your86source files with custom allocators.*/87#ifndef LODEPNG_NO_COMPILE_ALLOCATORS88/*pass -DLODEPNG_NO_COMPILE_ALLOCATORS to the compiler to disable the built-in ones,89or comment out LODEPNG_COMPILE_ALLOCATORS below*/90#define LODEPNG_COMPILE_ALLOCATORS91#endif9293/*Disable built-in CRC function, in that case a custom implementation of94lodepng_crc32 must be defined externally so that it can be linked in.95The default built-in CRC code comes with 8KB of lookup tables, so for memory constrained environment you may want it96disabled and provide a much smaller implementation externally as said above. You can find such an example implementation97in a comment in the lodepng.c(pp) file in the 'else' case of the searchable LODEPNG_COMPILE_CRC section.*/98#ifndef LODEPNG_NO_COMPILE_CRC99/*pass -DLODEPNG_NO_COMPILE_CRC to the compiler to disable the built-in one,100or comment out LODEPNG_COMPILE_CRC below*/101#define LODEPNG_COMPILE_CRC102#endif103104/*compile the C++ version (you can disable the C++ wrapper here even when compiling for C++)*/105#ifdef __cplusplus106#ifndef LODEPNG_NO_COMPILE_CPP107/*pass -DLODEPNG_NO_COMPILE_CPP to the compiler to disable C++ (not needed if a C-only compiler),108or comment out LODEPNG_COMPILE_CPP below*/109#define LODEPNG_COMPILE_CPP110#endif111#endif112113#ifdef LODEPNG_COMPILE_CPP114#include <vector>115#include <string>116#endif /*LODEPNG_COMPILE_CPP*/117118#ifdef LODEPNG_COMPILE_PNG119/*The PNG color types (also used for raw image).*/120typedef enum LodePNGColorType {121LCT_GREY = 0, /*grayscale: 1,2,4,8,16 bit*/122LCT_RGB = 2, /*RGB: 8,16 bit*/123LCT_PALETTE = 3, /*palette: 1,2,4,8 bit*/124LCT_GREY_ALPHA = 4, /*grayscale with alpha: 8,16 bit*/125LCT_RGBA = 6, /*RGB with alpha: 8,16 bit*/126/*LCT_MAX_OCTET_VALUE lets the compiler allow this enum to represent any invalid127byte value from 0 to 255 that could be present in an invalid PNG file header. Do128not use, compare with or set the name LCT_MAX_OCTET_VALUE, instead either use129the valid color type names above, or numeric values like 1 or 7 when checking for130particular disallowed color type byte values, or cast to integer to print it.*/131LCT_MAX_OCTET_VALUE = 255132} LodePNGColorType;133134#ifdef LODEPNG_COMPILE_DECODER135/*136Converts PNG data in memory to raw pixel data.137out: Output parameter. Pointer to buffer that will contain the raw pixel data.138After decoding, its size is w * h * (bytes per pixel) bytes larger than139initially. Bytes per pixel depends on colortype and bitdepth.140Must be freed after usage with free(*out).141Note: for 16-bit per channel colors, uses big endian format like PNG does.142w: Output parameter. Pointer to width of pixel data.143h: Output parameter. Pointer to height of pixel data.144in: Memory buffer with the PNG file.145insize: size of the in buffer.146colortype: the desired color type for the raw output image. See explanation on PNG color types.147bitdepth: the desired bit depth for the raw output image. See explanation on PNG color types.148Return value: LodePNG error code (0 means no error).149*/150unsigned lodepng_decode_memory(unsigned char** out, unsigned* w, unsigned* h,151const unsigned char* in, size_t insize,152LodePNGColorType colortype, unsigned bitdepth);153154/*Same as lodepng_decode_memory, but always decodes to 32-bit RGBA raw image*/155unsigned lodepng_decode32(unsigned char** out, unsigned* w, unsigned* h,156const unsigned char* in, size_t insize);157158/*Same as lodepng_decode_memory, but always decodes to 24-bit RGB raw image*/159unsigned lodepng_decode24(unsigned char** out, unsigned* w, unsigned* h,160const unsigned char* in, size_t insize);161162#ifdef LODEPNG_COMPILE_DISK163/*164Load PNG from disk, from file with given name.165Same as the other decode functions, but instead takes a filename as input.166167NOTE: Wide-character filenames are not supported, you can use an external method168to handle such files and decode in-memory.*/169unsigned lodepng_decode_file(unsigned char** out, unsigned* w, unsigned* h,170const char* filename,171LodePNGColorType colortype, unsigned bitdepth);172173/*Same as lodepng_decode_file, but always decodes to 32-bit RGBA raw image.174175NOTE: Wide-character filenames are not supported, you can use an external method176to handle such files and decode in-memory.*/177unsigned lodepng_decode32_file(unsigned char** out, unsigned* w, unsigned* h,178const char* filename);179180/*Same as lodepng_decode_file, but always decodes to 24-bit RGB raw image.181182NOTE: Wide-character filenames are not supported, you can use an external method183to handle such files and decode in-memory.*/184unsigned lodepng_decode24_file(unsigned char** out, unsigned* w, unsigned* h,185const char* filename);186#endif /*LODEPNG_COMPILE_DISK*/187#endif /*LODEPNG_COMPILE_DECODER*/188189190#ifdef LODEPNG_COMPILE_ENCODER191/*192Converts raw pixel data into a PNG image in memory. The colortype and bitdepth193of the output PNG image cannot be chosen, they are automatically determined194by the colortype, bitdepth and content of the input pixel data.195Note: for 16-bit per channel colors, needs big endian format like PNG does.196out: Output parameter. Pointer to buffer that will contain the PNG image data.197Must be freed after usage with free(*out).198outsize: Output parameter. Pointer to the size in bytes of the out buffer.199image: The raw pixel data to encode. The size of this buffer should be200w * h * (bytes per pixel), bytes per pixel depends on colortype and bitdepth.201w: width of the raw pixel data in pixels.202h: height of the raw pixel data in pixels.203colortype: the color type of the raw input image. See explanation on PNG color types.204bitdepth: the bit depth of the raw input image. See explanation on PNG color types.205Return value: LodePNG error code (0 means no error).206*/207unsigned lodepng_encode_memory(unsigned char** out, size_t* outsize,208const unsigned char* image, unsigned w, unsigned h,209LodePNGColorType colortype, unsigned bitdepth);210211/*Same as lodepng_encode_memory, but always encodes from 32-bit RGBA raw image.*/212unsigned lodepng_encode32(unsigned char** out, size_t* outsize,213const unsigned char* image, unsigned w, unsigned h);214215/*Same as lodepng_encode_memory, but always encodes from 24-bit RGB raw image.*/216unsigned lodepng_encode24(unsigned char** out, size_t* outsize,217const unsigned char* image, unsigned w, unsigned h);218219#ifdef LODEPNG_COMPILE_DISK220/*221Converts raw pixel data into a PNG file on disk.222Same as the other encode functions, but instead takes a filename as output.223224NOTE: This overwrites existing files without warning!225226NOTE: Wide-character filenames are not supported, you can use an external method227to handle such files and encode in-memory.*/228unsigned lodepng_encode_file(const char* filename,229const unsigned char* image, unsigned w, unsigned h,230LodePNGColorType colortype, unsigned bitdepth);231232/*Same as lodepng_encode_file, but always encodes from 32-bit RGBA raw image.233234NOTE: Wide-character filenames are not supported, you can use an external method235to handle such files and encode in-memory.*/236unsigned lodepng_encode32_file(const char* filename,237const unsigned char* image, unsigned w, unsigned h);238239/*Same as lodepng_encode_file, but always encodes from 24-bit RGB raw image.240241NOTE: Wide-character filenames are not supported, you can use an external method242to handle such files and encode in-memory.*/243unsigned lodepng_encode24_file(const char* filename,244const unsigned char* image, unsigned w, unsigned h);245#endif /*LODEPNG_COMPILE_DISK*/246#endif /*LODEPNG_COMPILE_ENCODER*/247248249#ifdef LODEPNG_COMPILE_CPP250namespace lodepng {251#ifdef LODEPNG_COMPILE_DECODER252/*Same as lodepng_decode_memory, but decodes to an std::vector. The colortype253is the format to output the pixels to. Default is RGBA 8-bit per channel.*/254unsigned decode(std::vector<unsigned char>& out, unsigned& w, unsigned& h,255const unsigned char* in, size_t insize,256LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8);257unsigned decode(std::vector<unsigned char>& out, unsigned& w, unsigned& h,258const std::vector<unsigned char>& in,259LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8);260#ifdef LODEPNG_COMPILE_DISK261/*262Converts PNG file from disk to raw pixel data in memory.263Same as the other decode functions, but instead takes a filename as input.264265NOTE: Wide-character filenames are not supported, you can use an external method266to handle such files and decode in-memory.267*/268unsigned decode(std::vector<unsigned char>& out, unsigned& w, unsigned& h,269const std::string& filename,270LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8);271#endif /* LODEPNG_COMPILE_DISK */272#endif /* LODEPNG_COMPILE_DECODER */273274#ifdef LODEPNG_COMPILE_ENCODER275/*Same as lodepng_encode_memory, but encodes to an std::vector. colortype276is that of the raw input data. The output PNG color type will be auto chosen.*/277unsigned encode(std::vector<unsigned char>& out,278const unsigned char* in, unsigned w, unsigned h,279LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8);280unsigned encode(std::vector<unsigned char>& out,281const std::vector<unsigned char>& in, unsigned w, unsigned h,282LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8);283#ifdef LODEPNG_COMPILE_DISK284/*285Converts 32-bit RGBA raw pixel data into a PNG file on disk.286Same as the other encode functions, but instead takes a filename as output.287288NOTE: This overwrites existing files without warning!289290NOTE: Wide-character filenames are not supported, you can use an external method291to handle such files and decode in-memory.292*/293unsigned encode(const std::string& filename,294const unsigned char* in, unsigned w, unsigned h,295LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8);296unsigned encode(const std::string& filename,297const std::vector<unsigned char>& in, unsigned w, unsigned h,298LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8);299#endif /* LODEPNG_COMPILE_DISK */300#endif /* LODEPNG_COMPILE_ENCODER */301} /* namespace lodepng */302#endif /*LODEPNG_COMPILE_CPP*/303#endif /*LODEPNG_COMPILE_PNG*/304305#ifdef LODEPNG_COMPILE_ERROR_TEXT306/*Returns an English description of the numerical error code.*/307const char* lodepng_error_text(unsigned code);308#endif /*LODEPNG_COMPILE_ERROR_TEXT*/309310#ifdef LODEPNG_COMPILE_DECODER311/*Settings for zlib decompression*/312typedef struct LodePNGDecompressSettings LodePNGDecompressSettings;313struct LodePNGDecompressSettings {314/* Check LodePNGDecoderSettings for more ignorable errors such as ignore_crc */315unsigned ignore_adler32; /*if 1, continue and don't give an error message if the Adler32 checksum is corrupted*/316unsigned ignore_nlen; /*ignore complement of len checksum in uncompressed blocks*/317318/*Maximum decompressed size, beyond this the decoder may (and is encouraged to) stop decoding,319return an error, output a data size > max_output_size and all the data up to that point. This is320not hard limit nor a guarantee, but can prevent excessive memory usage. This setting is321ignored by the PNG decoder, but is used by the deflate/zlib decoder and can be used by custom ones.322Set to 0 to impose no limit (the default).*/323size_t max_output_size;324325/*use custom zlib decoder instead of built in one (default: null).326Should return 0 if success, any non-0 if error (numeric value not exposed).*/327unsigned (*custom_zlib)(unsigned char**, size_t*,328const unsigned char*, size_t,329const LodePNGDecompressSettings*);330/*use custom deflate decoder instead of built in one (default: null)331if custom_zlib is not null, custom_inflate is ignored (the zlib format uses deflate).332Should return 0 if success, any non-0 if error (numeric value not exposed).*/333unsigned (*custom_inflate)(unsigned char**, size_t*,334const unsigned char*, size_t,335const LodePNGDecompressSettings*);336337const void* custom_context; /*optional custom settings for custom functions*/338};339340extern const LodePNGDecompressSettings lodepng_default_decompress_settings;341void lodepng_decompress_settings_init(LodePNGDecompressSettings* settings);342#endif /*LODEPNG_COMPILE_DECODER*/343344#ifdef LODEPNG_COMPILE_ENCODER345/*346Settings for zlib compression. Tweaking these settings tweaks the balance347between speed and compression ratio.348*/349typedef struct LodePNGCompressSettings LodePNGCompressSettings;350struct LodePNGCompressSettings /*deflate = compress*/ {351/*LZ77 related settings*/352unsigned btype; /*the block type for LZ (0, 1, 2 or 3, see zlib standard). Should be 2 for proper compression.*/353unsigned use_lz77; /*whether or not to use LZ77. Should be 1 for proper compression.*/354unsigned windowsize; /*must be a power of two <= 32768. higher compresses more but is slower. Default value: 2048.*/355unsigned minmatch; /*minimum lz77 length. 3 is normally best, 6 can be better for some PNGs. Default: 0*/356unsigned nicematch; /*stop searching if >= this length found. Set to 258 for best compression. Default: 128*/357unsigned lazymatching; /*use lazy matching: better compression but a bit slower. Default: true*/358359/*use custom zlib encoder instead of built in one (default: null)*/360unsigned (*custom_zlib)(unsigned char**, size_t*,361const unsigned char*, size_t,362const LodePNGCompressSettings*);363/*use custom deflate encoder instead of built in one (default: null)364if custom_zlib is used, custom_deflate is ignored since only the built in365zlib function will call custom_deflate*/366unsigned (*custom_deflate)(unsigned char**, size_t*,367const unsigned char*, size_t,368const LodePNGCompressSettings*);369370const void* custom_context; /*optional custom settings for custom functions*/371};372373extern const LodePNGCompressSettings lodepng_default_compress_settings;374void lodepng_compress_settings_init(LodePNGCompressSettings* settings);375#endif /*LODEPNG_COMPILE_ENCODER*/376377#ifdef LODEPNG_COMPILE_PNG378/*379Color mode of an image. Contains all information required to decode the pixel380bits to RGBA colors. This information is the same as used in the PNG file381format, and is used both for PNG and raw image data in LodePNG.382*/383typedef struct LodePNGColorMode {384/*header (IHDR)*/385LodePNGColorType colortype; /*color type, see PNG standard or documentation further in this header file*/386unsigned bitdepth; /*bits per sample, see PNG standard or documentation further in this header file*/387388/*389palette (PLTE and tRNS)390391Dynamically allocated with the colors of the palette, including alpha.392This field may not be allocated directly, use lodepng_color_mode_init first,393then lodepng_palette_add per color to correctly initialize it (to ensure size394of exactly 1024 bytes).395396The alpha channels must be set as well, set them to 255 for opaque images.397398When decoding, with the default settings you can ignore this palette, since399LodePNG already fills the palette colors in the pixels of the raw RGBA output,400but when decoding to the original PNG color mode it is needed to reconstruct401the colors.402403The palette is only supported for color type 3.404*/405unsigned char* palette; /*palette in RGBARGBA... order. Must be either 0, or when allocated must have 1024 bytes*/406size_t palettesize; /*palette size in number of colors (amount of used bytes is 4 * palettesize)*/407408/*409transparent color key (tRNS)410411This color uses the same bit depth as the bitdepth value in this struct, which can be 1-bit to 16-bit.412For grayscale PNGs, r, g and b will all 3 be set to the same.413414When decoding, by default you can ignore this information, since LodePNG sets415pixels with this key to transparent already in the raw RGBA output.416417The color key is only supported for color types 0 and 2.418*/419unsigned key_defined; /*is a transparent color key given? 0 = false, 1 = true*/420unsigned key_r; /*red/grayscale component of color key*/421unsigned key_g; /*green component of color key*/422unsigned key_b; /*blue component of color key*/423} LodePNGColorMode;424425/*init, cleanup and copy functions to use with this struct*/426void lodepng_color_mode_init(LodePNGColorMode* info);427void lodepng_color_mode_cleanup(LodePNGColorMode* info);428/*return value is error code (0 means no error)*/429unsigned lodepng_color_mode_copy(LodePNGColorMode* dest, const LodePNGColorMode* source);430/* Makes a temporary LodePNGColorMode that does not need cleanup (no palette) */431LodePNGColorMode lodepng_color_mode_make(LodePNGColorType colortype, unsigned bitdepth);432433void lodepng_palette_clear(LodePNGColorMode* info);434/*add 1 color to the palette*/435unsigned lodepng_palette_add(LodePNGColorMode* info,436unsigned char r, unsigned char g, unsigned char b, unsigned char a);437438/*get the total amount of bits per pixel, based on colortype and bitdepth in the struct*/439unsigned lodepng_get_bpp(const LodePNGColorMode* info);440/*get the amount of color channels used, based on colortype in the struct.441If a palette is used, it counts as 1 channel.*/442unsigned lodepng_get_channels(const LodePNGColorMode* info);443/*is it a grayscale type? (only colortype 0 or 4)*/444unsigned lodepng_is_greyscale_type(const LodePNGColorMode* info);445/*has it got an alpha channel? (only colortype 2 or 6)*/446unsigned lodepng_is_alpha_type(const LodePNGColorMode* info);447/*has it got a palette? (only colortype 3)*/448unsigned lodepng_is_palette_type(const LodePNGColorMode* info);449/*only returns true if there is a palette and there is a value in the palette with alpha < 255.450Loops through the palette to check this.*/451unsigned lodepng_has_palette_alpha(const LodePNGColorMode* info);452/*453Check if the given color info indicates the possibility of having non-opaque pixels in the PNG image.454Returns true if the image can have translucent or invisible pixels (it still be opaque if it doesn't use such pixels).455Returns false if the image can only have opaque pixels.456In detail, it returns true only if it's a color type with alpha, or has a palette with non-opaque values,457or if "key_defined" is true.458*/459unsigned lodepng_can_have_alpha(const LodePNGColorMode* info);460/*Returns the byte size of a raw image buffer with given width, height and color mode*/461size_t lodepng_get_raw_size(unsigned w, unsigned h, const LodePNGColorMode* color);462463#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS464/*The information of a Time chunk in PNG.*/465typedef struct LodePNGTime {466unsigned year; /*2 bytes used (0-65535)*/467unsigned month; /*1-12*/468unsigned day; /*1-31*/469unsigned hour; /*0-23*/470unsigned minute; /*0-59*/471unsigned second; /*0-60 (to allow for leap seconds)*/472} LodePNGTime;473#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/474475/*Information about the PNG image, except pixels, width and height.*/476typedef struct LodePNGInfo {477/*header (IHDR), palette (PLTE) and transparency (tRNS) chunks*/478unsigned compression_method;/*compression method of the original file. Always 0.*/479unsigned filter_method; /*filter method of the original file*/480unsigned interlace_method; /*interlace method of the original file: 0=none, 1=Adam7*/481LodePNGColorMode color; /*color type and bits, palette and transparency of the PNG file*/482483#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS484/*485Suggested background color chunk (bKGD)486487This uses the same color mode and bit depth as the PNG (except no alpha channel),488with values truncated to the bit depth in the unsigned integer.489490For grayscale and palette PNGs, the value is stored in background_r. The values491in background_g and background_b are then unused. The decoder will set them492equal to background_r, the encoder ignores them in this case.493494When decoding, you may get these in a different color mode than the one you requested495for the raw pixels: the colortype and bitdepth defined by info_png.color, that is the496ones defined in the header of the PNG image, are used.497498When encoding with auto_convert, you must use the color model defined in info_png.color for499these values. The encoder normally ignores info_png.color when auto_convert is on, but will500use it to interpret these values (and convert copies of them to its chosen color model).501502When encoding, avoid setting this to an expensive color, such as a non-gray value503when the image is gray, or the compression will be worse since it will be forced to504write the PNG with a more expensive color mode (when auto_convert is on).505506The decoder does not use this background color to edit the color of pixels. This is a507completely optional metadata feature.508*/509unsigned background_defined; /*is a suggested background color given?*/510unsigned background_r; /*red/gray/palette component of suggested background color*/511unsigned background_g; /*green component of suggested background color*/512unsigned background_b; /*blue component of suggested background color*/513514/*515Non-international text chunks (tEXt and zTXt)516517The char** arrays each contain num strings. The actual messages are in518text_strings, while text_keys are keywords that give a short description what519the actual text represents, e.g. Title, Author, Description, or anything else.520521All the string fields below including strings, keys, names and language tags are null terminated.522The PNG specification uses null characters for the keys, names and tags, and forbids null523characters to appear in the main text which is why we can use null termination everywhere here.524525A keyword is minimum 1 character and maximum 79 characters long (plus the526additional null terminator). It's discouraged to use a single line length527longer than 79 characters for texts.528529Don't allocate these text buffers yourself. Use the init/cleanup functions530correctly and use lodepng_add_text and lodepng_clear_text.531532Standard text chunk keywords and strings are encoded using Latin-1.533*/534size_t text_num; /*the amount of texts in these char** buffers (there may be more texts in itext)*/535char** text_keys; /*the keyword of a text chunk (e.g. "Comment")*/536char** text_strings; /*the actual text*/537538/*539International text chunks (iTXt)540Similar to the non-international text chunks, but with additional strings541"langtags" and "transkeys", and the following text encodings are used:542keys: Latin-1, langtags: ASCII, transkeys and strings: UTF-8.543keys must be 1-79 characters (plus the additional null terminator), the other544strings are any length.545*/546size_t itext_num; /*the amount of international texts in this PNG*/547char** itext_keys; /*the English keyword of the text chunk (e.g. "Comment")*/548char** itext_langtags; /*language tag for this text's language, ISO/IEC 646 string, e.g. ISO 639 language tag*/549char** itext_transkeys; /*keyword translated to the international language - UTF-8 string*/550char** itext_strings; /*the actual international text - UTF-8 string*/551552/*553Optional exif metadata in exif_size bytes.554Don't allocate this buffer yourself. Use the init/cleanup functions555correctly and use lodepng_set_exif and lodepng_clear_exif.556The exif data is in exif-encoded form but without JPEG markers, starting with the 'II' or 'MM' marker that indicates557endianness. It's up to an exif handling library to encode/decode its information.558*/559unsigned exif_defined; /* Whether exif metadata is present, that is, the PNG image has an eXIf chunk */560unsigned char* exif; /* The bytes of the exif metadata, if present */561unsigned exif_size; /* The size of the exif data in bytes */562563564/*time chunk (tIME)*/565unsigned time_defined; /*set to 1 to make the encoder generate a tIME chunk*/566LodePNGTime time;567568/*phys chunk (pHYs)*/569unsigned phys_defined; /*if 0, there is no pHYs chunk and the values below are undefined, if 1 else there is one*/570unsigned phys_x; /*pixels per unit in x direction*/571unsigned phys_y; /*pixels per unit in y direction*/572unsigned phys_unit; /*may be 0 (unknown unit) or 1 (metre)*/573574/*575Color profile related chunk types: cICP, iCPP, sRGB, gAMA, cHRM, sBIT576577LodePNG does not apply any color conversions on pixels in the encoder or decoder and does not interpret these color578profile values. It merely passes on the information. If you wish to use color profiles and convert colors, a separate579color management library should be used. There is also a limited library for this in lodepng_util.h.580581There are 4 types of (sets of) chunks providing color information. If multiple are present, each will be decoded by582LodePNG, but only one should be handled by the user, with the following order of priority depending on what the user583supports:5841: cICP: Coding-independent code points (CICP)5852: iCCP: ICC profile5863: sRGB: indicates the image is in the sRGB color profile5874: gAMA and cHRM: indicates a gamma and chromaticity value to define the color profile588*/589590/*591gAMA chunk: Image gamma592Optional, overridden by cICP, iCCP or sRGB if those are present.593Together with cHRM, this is a primitive way of specifying the image color profile.594*/595unsigned gama_defined; /* Whether a gAMA chunk is present (0 = not present, 1 = present). */596unsigned gama_gamma; /* Gamma exponent times 100000 */597598/*599cHRM chunk: Primary chromaticities and white point600Optional, overridden by cICP, iCCP or sRGB if those are present.601Together with gAMA, this is a primitive way of specifying the image color profile.602*/603unsigned chrm_defined; /* Whether a cHRM chunk is present (0 = not present, 1 = present). */604unsigned chrm_white_x; /* White Point x times 100000 */605unsigned chrm_white_y; /* White Point y times 100000 */606unsigned chrm_red_x; /* Red x times 100000 */607unsigned chrm_red_y; /* Red y times 100000 */608unsigned chrm_green_x; /* Green x times 100000 */609unsigned chrm_green_y; /* Green y times 100000 */610unsigned chrm_blue_x; /* Blue x times 100000 */611unsigned chrm_blue_y; /* Blue y times 100000 */612613/*614sRGB chunk: Indicates the image is in the sRGB color space.615Optional. Should not appear at the same time as iCCP.616If gAMA is also present gAMA must contain value 45455.617If cHRM is also present cHRM must contain respectively 31270,32900,64000,33000,30000,60000,15000,6000.618*/619unsigned srgb_defined; /* Whether an sRGB chunk is present (0 = not present, 1 = present). */620unsigned srgb_intent; /* Rendering intent: 0=perceptual, 1=rel. colorimetric, 2=saturation, 3=abs. colorimetric */621622/*623iCCP chunk: Embedded ICC profile.624Optional. Should not appear at the same time as sRGB.625626Contains ICC profile, which can use any version of the ICC.1 specification by the International Color Consortium. See627its specification for more details. LodePNG does not parse or use the ICC profile (except its color space header628field for "RGB" or "GRAY", see below), a separate library to handle the ICC data format is needed to use it for color629management and conversions.630631For encoding, if iCCP is present, the PNG specification recommends to also add gAMA and cHRM chunks that approximate632the ICC profile, for compatibility with applications that don't use the ICC chunk. This is not required, and it's up633to the user to compute approximate values and set then in the appropriate gama_ and chrm_ fields, LodePNG does not do634this automatically since it does not interpret the ICC profile.635636For encoding, the ICC profile is required by the PNG specification to be an "RGB" profile for non-gray PNG color637types (types 2, 3 and 6) and a "GRAY" profile for gray PNG color types (types 1 and 4). If you disable auto_convert,638you must ensure the ICC profile type matches your requested color type, else the encoder gives an error. If639auto_convert is enabled (the default), and the ICC profile is not a correct match for the pixel data, this will result640in an encoder error if the pixel data has non-gray pixels for a GRAY profile, or a silent less-optimal compression of641the pixel data if the pixels could be encoded as grayscale but the ICC profile is RGB.642643To avoid this do not set an ICC profile in the image unless there is a good reason for it, and when doing so644make sure you compute it carefully to avoid the above problems.645*/646unsigned iccp_defined; /* Whether an iCCP chunk is present (0 = not present, 1 = present). */647char* iccp_name; /* Null terminated string with profile name, 1-79 bytes */648/*649The ICC profile in iccp_profile_size bytes.650Don't allocate this buffer yourself. Use the init/cleanup functions651correctly and use lodepng_set_icc and lodepng_clear_icc.652*/653unsigned char* iccp_profile;654unsigned iccp_profile_size; /* The size of iccp_profile in bytes */655656/*657cICP chunk: Coding-independent code points for video signal type identification.658Optional. If present, and supported, overrides iCCP, sRGB, gAMA and cHRM.659The meaning of the values are as defined in the specification ITU-T-H.273. LodePNG does not660use these values, only passes on the metadata. The meaning of the values is they are enum661values representing certain color spaces, including HDR color spaces, such as Display P3,662PQ and HLG. The video full range flag value should typically be 1 for the use cases of PNG663images, but can be 0 for narrow-range images in certain video editing workflows.664*/665unsigned cicp_defined; /* Whether an cICP chunk is present (0 = not present, 1 = present). */666unsigned cicp_color_primaries; /* Colour primaries value */667unsigned cicp_transfer_function; /* Transfer characteristics value */668unsigned cicp_matrix_coefficients; /* Matrix coefficients value */669unsigned cicp_video_full_range_flag; /* Video full range flag value */670671/*672mDCV chunk: Mastering Display Color Volume.673Optional, typically used in conjunction with certain HDR color spaces that can674be represented by the cICP chunk.675See the PNG specification, third edition, for more information on this chunk.676All the red, green, blue and white x and y values are encoded as 16-bit677integers and therefore must be in range 0-65536. The min and max luminance678values are 32-bit integers.679*/680unsigned mdcv_defined; /* Whether an mDCV chunk is present (0 = not present, 1 = present). */681/* Mastering display color primary chromaticities (CIE 1931 x,y of R,G,B) */682unsigned mdcv_red_x; /* Red x times 50000 */683unsigned mdcv_red_y; /* Red y times 50000 */684unsigned mdcv_green_x; /* Green x times 50000 */685unsigned mdcv_green_y; /* Green y times 50000 */686unsigned mdcv_blue_x; /* Blue x times 50000 */687unsigned mdcv_blue_y; /* Blue y times 50000 */688/* Mastering display white point chromaticity (CIE 1931 x,y) */689unsigned mdcv_white_x; /* White Point x times 50000 */690unsigned mdcv_white_y; /* White Point y times 50000 */691/* Mastering display luminance */692unsigned mdcv_max_luminance; /* Max luminance in cd/m^2 times 10000 */693unsigned mdcv_min_luminance; /* Min luminance in cd/m^2 times 10000 */694695/*696cLLI chunk: Content Light Level Information.697Optional, typically used in conjunction with certain HDR color spaces that can698be represented by the cICP chunk.699See the PNG specification, third edition, for more information on this chunk.700The clli_max_cll and clli_max_fall values are 32-bit integers.701*/702unsigned clli_defined; /* Whether a cLLI chunk is present (0 = not present, 1 = present). */703unsigned clli_max_cll; /* Maximum Content Light Level (MaxCLL) in cd/m^2 times 10000 */704unsigned clli_max_fall; /* Maximum Frame-Average Light Level (MaxFALL) in cd/m^2 times 10000 */705706/*707sBIT chunk: significant bits.708Optional metadata, only set this if needed.709710If defined, these values give the bit depth of the original data. Since PNG only stores 1, 2, 4, 8 or 16-bit711per channel data, the significant bits value can be used to indicate the original encoded data has another712sample depth, such as 10 or 12.713714Encoders using this value, when storing the pixel data, should use the most significant bits715of the data to store the original bits, and use a good sample depth scaling method such as716"left bit replication" to fill in the least significant bits, rather than fill zeroes.717718Decoders using this value, if able to work with data that's e.g. 10-bit or 12-bit, should right719shift the data to go back to the original bit depth, but decoders are also allowed to ignore720sbit and work e.g. with the 8-bit or 16-bit data from the PNG directly, since thanks721to the encoder contract, the values encoded in PNG are in valid range for the PNG bit depth.722723For grayscale images, sbit_g and sbit_b are not used, and for images that don't use color724type RGBA or grayscale+alpha, sbit_a is not used (it's not used even for palette images with725translucent palette values, or images with color key). The values that are used must be726greater than zero and smaller than or equal to the PNG bit depth.727728The color type from the header in the PNG image defines these used and unused fields: if729decoding with a color mode conversion, such as always decoding to RGBA, this metadata still730only uses the color type of the original PNG, and may e.g. lack the alpha channel info731if the PNG was RGB. When encoding with auto_convert (as well as without), also always the732color model defined in info_png.color determines this.733734NOTE: enabling sbit can hurt compression, because the encoder can then not always use735auto_convert to choose a more optimal color mode for the data, because the PNG format has736strict requirements for the allowed sbit values in combination with color modes.737For example, setting these fields to 10-bit will force the encoder to keep using a 16-bit per channel738color mode, even if the pixel data would in fact fit in a more efficient 8-bit mode.739*/740unsigned sbit_defined; /*is significant bits given? if not, the values below are unused*/741unsigned sbit_r; /*red or gray component of significant bits*/742unsigned sbit_g; /*green component of significant bits*/743unsigned sbit_b; /*blue component of significant bits*/744unsigned sbit_a; /*alpha component of significant bits*/745746/* End of color profile related chunks */747748749/*750unknown chunks: chunks not known by LodePNG, passed on byte for byte.751752There are 3 buffers, one for each position in the PNG where unknown chunks can appear.753Each buffer contains all unknown chunks for that position consecutively.754The 3 positions are:7550: between IHDR and PLTE, 1: between PLTE and IDAT, 2: between IDAT and IEND.756757For encoding, do not store critical chunks or known chunks that are enabled with a "_defined" flag758above in here, since the encoder will blindly follow this and could then encode an invalid PNG file759(such as one with two IHDR chunks or the disallowed combination of sRGB with iCCP). But do use760this if you wish to store an ancillary chunk that is not supported by LodePNG (such as sPLT or hIST),761or any non-standard PNG chunk.762763Do not allocate or traverse this data yourself. Use the chunk traversing functions declared764later, such as lodepng_chunk_next and lodepng_chunk_append, to read/write this struct.765*/766unsigned char* unknown_chunks_data[3];767size_t unknown_chunks_size[3]; /*size in bytes of the unknown chunks, given for protection*/768#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/769} LodePNGInfo;770771/*init, cleanup and copy functions to use with this struct*/772void lodepng_info_init(LodePNGInfo* info);773void lodepng_info_cleanup(LodePNGInfo* info);774/*return value is error code (0 means no error)*/775unsigned lodepng_info_copy(LodePNGInfo* dest, const LodePNGInfo* source);776777#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS778unsigned lodepng_add_text(LodePNGInfo* info, const char* key, const char* str); /*push back both texts at once*/779void lodepng_clear_text(LodePNGInfo* info); /*use this to clear the texts again after you filled them in*/780781unsigned lodepng_add_itext(LodePNGInfo* info, const char* key, const char* langtag,782const char* transkey, const char* str); /*push back the 4 texts of 1 chunk at once*/783void lodepng_clear_itext(LodePNGInfo* info); /*use this to clear the itexts again after you filled them in*/784785/*replaces if exists*/786unsigned lodepng_set_icc(LodePNGInfo* info, const char* name, const unsigned char* profile, unsigned profile_size);787void lodepng_clear_icc(LodePNGInfo* info); /*use this to clear the profile again after you filled it in*/788789/*replaces if exists*/790unsigned lodepng_set_exif(LodePNGInfo* info, const unsigned char* exif, unsigned exif_size);791void lodepng_clear_exif(LodePNGInfo* info); /*use this to clear the exif metadata again after you filled it in*/792#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/793794/*795Converts raw buffer from one color type to another color type, based on796LodePNGColorMode structs to describe the input and output color type.797See the reference manual at the end of this header file to see which color conversions are supported.798return value = LodePNG error code (0 if all went ok, an error if the conversion isn't supported)799The out buffer must have size (w * h * bpp + 7) / 8, where bpp is the bits per pixel800of the output color type (lodepng_get_bpp).801For < 8 bpp images, there should not be padding bits at the end of scanlines.802For 16-bit per channel colors, uses big endian format like PNG does.803Return value is LodePNG error code804*/805unsigned lodepng_convert(unsigned char* out, const unsigned char* in,806const LodePNGColorMode* mode_out, const LodePNGColorMode* mode_in,807unsigned w, unsigned h);808809#ifdef LODEPNG_COMPILE_DECODER810/*811Settings for the decoder. This contains settings for the PNG and the Zlib812decoder, but not the Info settings from the Info structs.813*/814typedef struct LodePNGDecoderSettings {815LodePNGDecompressSettings zlibsettings; /*in here is the setting to ignore Adler32 checksums*/816817/* Check LodePNGDecompressSettings for more ignorable errors such as ignore_adler32 */818unsigned ignore_crc; /*ignore CRC checksums*/819unsigned ignore_critical; /*ignore unknown critical chunks*/820unsigned ignore_end; /*ignore issues at end of file if possible (missing IEND chunk, too large chunk, ...)*/821/* TODO: make a system involving warnings with levels and a strict mode instead. Other potentially recoverable822errors: srgb rendering intent value, size of content of ancillary chunks, more than 79 characters for some823strings, placement/combination rules for ancillary chunks, crc of unknown chunks, allowed characters824in string keys, invalid characters in chunk types names, etc... */825826unsigned color_convert; /*whether to convert the PNG to the color type you want. Default: yes*/827828#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS829unsigned read_text_chunks; /*if false but remember_unknown_chunks is true, they're stored in the unknown chunks*/830831/*store all bytes from unknown chunks in the LodePNGInfo (off by default, useful for a png editor)*/832unsigned remember_unknown_chunks;833834/* maximum size for decompressed text chunks. If a text chunk's text is larger than this, an error is returned,835unless reading text chunks is disabled or this limit is set higher or disabled. Set to 0 to allow any size.836By default it is a value that prevents unreasonably large strings from hogging memory. */837size_t max_text_size;838839/* maximum size for compressed ICC chunks. If the ICC profile is larger than this, an error will be returned. Set to8400 to allow any size. By default this is a value that prevents ICC profiles that would be much larger than any841legitimate profile could be to hog memory. */842size_t max_icc_size;843#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/844} LodePNGDecoderSettings;845846void lodepng_decoder_settings_init(LodePNGDecoderSettings* settings);847#endif /*LODEPNG_COMPILE_DECODER*/848849#ifdef LODEPNG_COMPILE_ENCODER850/*strategy to use to choose the PNG filter per scanline. Strategies 0-4 correspond851to each of the 5 filter types PNG supports, the next values are adaptive strategies*/852typedef enum LodePNGFilterStrategy {853/*every filter at zero*/854LFS_ZERO = 0,855/*every filter at 1, 2, 3 or 4 (paeth), unlike LFS_ZERO not a good choice, but for testing*/856LFS_ONE = 1,857LFS_TWO = 2,858LFS_THREE = 3,859LFS_FOUR = 4,860/*Use the filter out of the 5 above types that gives minimum sum, by trying each one. This is the adaptive filtering861suggested heuristic in the PNG standard chapter 'Filter selection'.*/862LFS_MINSUM,863/*Use the filter type that gives smallest Shannon entropy for this scanline. Depending864on the image, this is better or worse than minsum.*/865LFS_ENTROPY,866/*867Brute-force-search PNG filters by compressing each filter for each scanline.868Experimental, very slow, and only rarely gives better compression than MINSUM.869*/870LFS_BRUTE_FORCE,871/*use predefined_filters buffer: you specify the filter type for each scanline*/872LFS_PREDEFINED873} LodePNGFilterStrategy;874875/*Gives characteristics about the integer RGBA colors of the image (count, alpha channel usage, bit depth, ...),876which helps decide which color model to use for encoding.877Used internally by default if "auto_convert" is enabled. Public because it's useful for custom algorithms.*/878typedef struct LodePNGColorStats {879unsigned colored; /*not grayscale*/880unsigned key; /*image is not opaque and color key is possible instead of full alpha*/881unsigned short key_r; /*key values, always as 16-bit, in 8-bit case the byte is duplicated, e.g. 65535 means 255*/882unsigned short key_g;883unsigned short key_b;884unsigned alpha; /*image is not opaque and alpha channel or alpha palette required*/885unsigned numcolors; /*amount of colors, up to 257. Not valid if bits == 16 or allow_palette is disabled.*/886unsigned char palette[1024]; /*Remembers up to the first 256 RGBA colors, in no particular order, only valid when numcolors is valid*/887unsigned bits; /*bits per channel (not for palette). 1,2 or 4 for grayscale only. 16 if 16-bit per channel required.*/888size_t numpixels;889890/*user settings for computing/using the stats*/891unsigned allow_palette; /*default 1. if 0, disallow choosing palette colortype in auto_choose_color, and don't count numcolors*/892unsigned allow_greyscale; /*default 1. if 0, choose RGB or RGBA even if the image only has gray colors*/893} LodePNGColorStats;894895void lodepng_color_stats_init(LodePNGColorStats* stats);896897/*Get a LodePNGColorStats of the image. The stats must already have been inited.898Returns error code (e.g. alloc fail) or 0 if ok.*/899unsigned lodepng_compute_color_stats(LodePNGColorStats* stats,900const unsigned char* image, unsigned w, unsigned h,901const LodePNGColorMode* mode_in);902903/*Settings for the encoder.*/904typedef struct LodePNGEncoderSettings {905LodePNGCompressSettings zlibsettings; /*settings for the zlib encoder, such as window size, ...*/906907/*automatically choose output PNG color type. If false, must explicitely choose the output color908type in state.info_png.color.colortype, info_png.color.bitdepth and optionally its palette.909Default: true*/910unsigned auto_convert;911912/*If true, follows the suggestion in the PNG standard in chapter 'Filter selection': if the PNG uses913a palette or lower than 8 bit depth, set all filters to zero.914In other cases this will use the heuristic from the chosen filter_strategy. The PNG standard915suggests LFS_MINSUM for those cases.*/916unsigned filter_palette_zero;917/*Which filter strategy to use when not using zeroes due to filter_palette_zero.918Set filter_palette_zero to 0 to ensure always using your chosen strategy. Default: LFS_MINSUM*/919LodePNGFilterStrategy filter_strategy;920/*used if filter_strategy is LFS_PREDEFINED. In that case, this must point to a buffer with921the same length as the amount of scanlines in the image, and each value must <= 5. You922have to cleanup this buffer, LodePNG will never free it. Don't forget that filter_palette_zero923must be set to 0 to ensure this is also used on palette or low bitdepth images.*/924const unsigned char* predefined_filters;925926/*force creating a PLTE chunk if colortype is 2 or 6 (= a suggested palette).927If colortype is 3, PLTE is always created. If color type is explicitely set928to a grayscale type (1 or 4), this is not done and is ignored. If enabling this,929a palette must be present in the info_png.930NOTE: enabling this may worsen compression if auto_convert is used to choose931optimal color mode, because it cannot use grayscale color modes in this case*/932unsigned force_palette;933#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS934/*add LodePNG identifier and version as a text chunk, for debugging*/935unsigned add_id;936/*encode text chunks as zTXt chunks instead of tEXt chunks, and use compression in iTXt chunks*/937unsigned text_compression;938#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/939} LodePNGEncoderSettings;940941void lodepng_encoder_settings_init(LodePNGEncoderSettings* settings);942#endif /*LODEPNG_COMPILE_ENCODER*/943944945#if defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ENCODER)946/*The settings, state and information for extended encoding and decoding.*/947typedef struct LodePNGState {948#ifdef LODEPNG_COMPILE_DECODER949LodePNGDecoderSettings decoder; /*the decoding settings*/950#endif /*LODEPNG_COMPILE_DECODER*/951#ifdef LODEPNG_COMPILE_ENCODER952LodePNGEncoderSettings encoder; /*the encoding settings*/953#endif /*LODEPNG_COMPILE_ENCODER*/954LodePNGColorMode info_raw; /*specifies the format in which you would like to get the raw pixel buffer*/955LodePNGInfo info_png; /*info of the PNG image obtained after decoding*/956unsigned error;957} LodePNGState;958959/*init, cleanup and copy functions to use with this struct*/960void lodepng_state_init(LodePNGState* state);961void lodepng_state_cleanup(LodePNGState* state);962void lodepng_state_copy(LodePNGState* dest, const LodePNGState* source);963#endif /* defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ENCODER) */964965#ifdef LODEPNG_COMPILE_DECODER966/*967Same as lodepng_decode_memory, but uses a LodePNGState to allow custom settings and968getting much more information about the PNG image and color mode.969*/970unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h,971LodePNGState* state,972const unsigned char* in, size_t insize);973974/*975Read the PNG header, but not the actual data. This returns only the information976that is in the IHDR chunk of the PNG, such as width, height and color type. The977information is placed in the info_png field of the LodePNGState.978*/979unsigned lodepng_inspect(unsigned* w, unsigned* h,980LodePNGState* state,981const unsigned char* in, size_t insize);982#endif /*LODEPNG_COMPILE_DECODER*/983984/*985Reads one metadata chunk (other than IHDR, which is handled by lodepng_inspect)986of the PNG file and outputs what it read in the state. Returns error code on failure.987Use lodepng_inspect first with a new state, then e.g. lodepng_chunk_find_const988to find the desired chunk type, and if non null use lodepng_inspect_chunk (with989chunk_pointer - start_of_file as pos).990Supports most metadata chunks from the PNG standard (gAMA, bKGD, tEXt, ...).991Ignores unsupported, unknown, non-metadata or IHDR chunks (without error).992Requirements: &in[pos] must point to start of a chunk, must use regular993lodepng_inspect first since format of most other chunks depends on IHDR, and if994there is a PLTE chunk, that one must be inspected before tRNS or bKGD.995*/996unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos,997const unsigned char* in, size_t insize);998999#ifdef LODEPNG_COMPILE_ENCODER1000/*This function allocates the out buffer with standard malloc and stores the size in *outsize.*/1001unsigned lodepng_encode(unsigned char** out, size_t* outsize,1002const unsigned char* image, unsigned w, unsigned h,1003LodePNGState* state);1004#endif /*LODEPNG_COMPILE_ENCODER*/10051006/*1007The lodepng_chunk functions are normally not needed, except to traverse the1008unknown chunks stored in the LodePNGInfo struct, or add new ones to it.1009It also allows traversing the chunks of an encoded PNG file yourself.10101011The chunk pointer always points to the beginning of the chunk itself, that is1012the first byte of the 4 length bytes.10131014In the PNG file format, chunks have the following format:1015-4 bytes length: length of the data of the chunk in bytes (chunk itself is 12 bytes longer)1016-4 bytes chunk type (ASCII a-z,A-Z only, see below)1017-length bytes of data (may be 0 bytes if length was 0)1018-4 bytes of CRC, computed on chunk name + data10191020The first chunk starts at the 8th byte of the PNG file, the entire rest of the file1021exists out of concatenated chunks with the above format.10221023PNG standard chunk ASCII naming conventions:1024-First byte: uppercase = critical, lowercase = ancillary1025-Second byte: uppercase = public, lowercase = private1026-Third byte: must be uppercase1027-Fourth byte: uppercase = unsafe to copy, lowercase = safe to copy1028*/10291030/*1031Gets the length of the data of the chunk. Total chunk length has 12 bytes more.1032There must be at least 4 bytes to read from. If the result value is too large,1033it may be corrupt data.1034*/1035unsigned lodepng_chunk_length(const unsigned char* chunk);10361037/*puts the 4-byte type in null terminated string*/1038void lodepng_chunk_type(char type[5], const unsigned char* chunk);10391040/*check if the type is the given type*/1041unsigned char lodepng_chunk_type_equals(const unsigned char* chunk, const char* type);10421043/*0: it's one of the critical chunk types, 1: it's an ancillary chunk (see PNG standard)*/1044unsigned char lodepng_chunk_ancillary(const unsigned char* chunk);10451046/*0: public, 1: private (see PNG standard)*/1047unsigned char lodepng_chunk_private(const unsigned char* chunk);10481049/*0: the chunk is unsafe to copy, 1: the chunk is safe to copy (see PNG standard)*/1050unsigned char lodepng_chunk_safetocopy(const unsigned char* chunk);10511052/*get pointer to the data of the chunk, where the input points to the header of the chunk*/1053unsigned char* lodepng_chunk_data(unsigned char* chunk);1054const unsigned char* lodepng_chunk_data_const(const unsigned char* chunk);10551056/*returns 0 if the crc is correct, 1 if it's incorrect (0 for OK as usual!)*/1057unsigned lodepng_chunk_check_crc(const unsigned char* chunk);10581059/*generates the correct CRC from the data and puts it in the last 4 bytes of the chunk*/1060void lodepng_chunk_generate_crc(unsigned char* chunk);10611062/*1063Iterate to next chunks, allows iterating through all chunks of the PNG file.1064Input must be at the beginning of a chunk (result of a previous lodepng_chunk_next call,1065or the 8th byte of a PNG file which always has the first chunk), or alternatively may1066point to the first byte of the PNG file (which is not a chunk but the magic header, the1067function will then skip over it and return the first real chunk).1068Will output pointer to the start of the next chunk, or at or beyond end of the file if there1069is no more chunk after this or possibly if the chunk is corrupt.1070Start this process at the 8th byte of the PNG file.1071In a non-corrupt PNG file, the last chunk should have name "IEND".1072*/1073unsigned char* lodepng_chunk_next(unsigned char* chunk, unsigned char* end);1074const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk, const unsigned char* end);10751076/*Finds the first chunk with the given type in the range [chunk, end), or returns NULL if not found.*/1077unsigned char* lodepng_chunk_find(unsigned char* chunk, unsigned char* end, const char type[5]);1078const unsigned char* lodepng_chunk_find_const(const unsigned char* chunk, const unsigned char* end, const char type[5]);10791080/*1081Appends chunk to the data in out. The given chunk should already have its chunk header.1082The out variable and outsize are updated to reflect the new reallocated buffer.1083Returns error code (0 if it went ok)1084*/1085unsigned lodepng_chunk_append(unsigned char** out, size_t* outsize, const unsigned char* chunk);10861087/*1088Appends new chunk to out. The chunk to append is given by giving its length, type1089and data separately. The type is a 4-letter string.1090The out variable and outsize are updated to reflect the new reallocated buffer.1091Returne error code (0 if it went ok)1092*/1093unsigned lodepng_chunk_create(unsigned char** out, size_t* outsize, size_t length,1094const char* type, const unsigned char* data);109510961097/*Calculate CRC32 of buffer*/1098unsigned lodepng_crc32(const unsigned char* buf, size_t len);1099#endif /*LODEPNG_COMPILE_PNG*/110011011102#ifdef LODEPNG_COMPILE_ZLIB1103/*1104This zlib part can be used independently to zlib compress and decompress a1105buffer. It cannot be used to create gzip files however, and it only supports the1106part of zlib that is required for PNG, it does not support dictionaries.1107*/11081109#ifdef LODEPNG_COMPILE_DECODER1110/*Inflate a buffer. Inflate is the decompression step of deflate. Out buffer must be freed after use.*/1111unsigned lodepng_inflate(unsigned char** out, size_t* outsize,1112const unsigned char* in, size_t insize,1113const LodePNGDecompressSettings* settings);11141115/*1116Decompresses Zlib data. Reallocates the out buffer and appends the data. The1117data must be according to the zlib specification.1118Either, *out must be NULL and *outsize must be 0, or, *out must be a valid1119buffer and *outsize its size in bytes. out must be freed by user after usage.1120*/1121unsigned lodepng_zlib_decompress(unsigned char** out, size_t* outsize,1122const unsigned char* in, size_t insize,1123const LodePNGDecompressSettings* settings);1124#endif /*LODEPNG_COMPILE_DECODER*/11251126#ifdef LODEPNG_COMPILE_ENCODER1127/*1128Compresses data with Zlib. Reallocates the out buffer and appends the data.1129Zlib adds a small header and trailer around the deflate data.1130The data is output in the format of the zlib specification.1131Either, *out must be NULL and *outsize must be 0, or, *out must be a valid1132buffer and *outsize its size in bytes. out must be freed by user after usage.1133*/1134unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize,1135const unsigned char* in, size_t insize,1136const LodePNGCompressSettings* settings);11371138/*1139Find length-limited Huffman code for given frequencies. This function is in the1140public interface only for tests, it's used internally by lodepng_deflate.1141*/1142unsigned lodepng_huffman_code_lengths(unsigned* lengths, const unsigned* frequencies,1143size_t numcodes, unsigned maxbitlen);11441145/*Compress a buffer with deflate. See RFC 1951. Out buffer must be freed after use.*/1146unsigned lodepng_deflate(unsigned char** out, size_t* outsize,1147const unsigned char* in, size_t insize,1148const LodePNGCompressSettings* settings);11491150#endif /*LODEPNG_COMPILE_ENCODER*/1151#endif /*LODEPNG_COMPILE_ZLIB*/11521153#ifdef LODEPNG_COMPILE_DISK1154/*1155Load a file from disk into buffer. The function allocates the out buffer, and1156after usage you should free it.1157out: output parameter, contains pointer to loaded buffer.1158outsize: output parameter, size of the allocated out buffer1159filename: the path to the file to load1160return value: error code (0 means ok)11611162NOTE: Wide-character filenames are not supported, you can use an external method1163to handle such files and decode in-memory.1164*/1165unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename);11661167/*1168Save a file from buffer to disk. Warning, if it exists, this function overwrites1169the file without warning!1170buffer: the buffer to write1171buffersize: size of the buffer to write1172filename: the path to the file to save to1173return value: error code (0 means ok)11741175NOTE: Wide-character filenames are not supported, you can use an external method1176to handle such files and encode in-memory1177*/1178unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename);1179#endif /*LODEPNG_COMPILE_DISK*/11801181#ifdef LODEPNG_COMPILE_CPP1182/* The LodePNG C++ wrapper uses std::vectors instead of manually allocated memory buffers. */1183namespace lodepng {1184#ifdef LODEPNG_COMPILE_PNG1185class State : public LodePNGState {1186public:1187State();1188State(const State& other);1189~State();1190State& operator=(const State& other);1191};11921193#ifdef LODEPNG_COMPILE_DECODER1194/* Same as other lodepng::decode, but using a State for more settings and information. */1195unsigned decode(std::vector<unsigned char>& out, unsigned& w, unsigned& h,1196State& state,1197const unsigned char* in, size_t insize);1198unsigned decode(std::vector<unsigned char>& out, unsigned& w, unsigned& h,1199State& state,1200const std::vector<unsigned char>& in);1201#endif /*LODEPNG_COMPILE_DECODER*/12021203#ifdef LODEPNG_COMPILE_ENCODER1204/* Same as other lodepng::encode, but using a State for more settings and information. */1205unsigned encode(std::vector<unsigned char>& out,1206const unsigned char* in, unsigned w, unsigned h,1207State& state);1208unsigned encode(std::vector<unsigned char>& out,1209const std::vector<unsigned char>& in, unsigned w, unsigned h,1210State& state);1211#endif /*LODEPNG_COMPILE_ENCODER*/12121213#ifdef LODEPNG_COMPILE_DISK1214/*1215Load a file from disk into an std::vector.1216return value: error code (0 means ok)12171218NOTE: Wide-character filenames are not supported, you can use an external method1219to handle such files and decode in-memory1220*/1221unsigned load_file(std::vector<unsigned char>& buffer, const std::string& filename);12221223/*1224Save the binary data in an std::vector to a file on disk. The file is overwritten1225without warning.12261227NOTE: Wide-character filenames are not supported, you can use an external method1228to handle such files and encode in-memory1229*/1230unsigned save_file(const std::vector<unsigned char>& buffer, const std::string& filename);1231#endif /* LODEPNG_COMPILE_DISK */1232#endif /* LODEPNG_COMPILE_PNG */12331234#ifdef LODEPNG_COMPILE_ZLIB1235#ifdef LODEPNG_COMPILE_DECODER1236/* Zlib-decompress an unsigned char buffer */1237unsigned decompress(std::vector<unsigned char>& out, const unsigned char* in, size_t insize,1238const LodePNGDecompressSettings& settings = lodepng_default_decompress_settings);12391240/* Zlib-decompress an std::vector */1241unsigned decompress(std::vector<unsigned char>& out, const std::vector<unsigned char>& in,1242const LodePNGDecompressSettings& settings = lodepng_default_decompress_settings);1243#endif /* LODEPNG_COMPILE_DECODER */12441245#ifdef LODEPNG_COMPILE_ENCODER1246/* Zlib-compress an unsigned char buffer */1247unsigned compress(std::vector<unsigned char>& out, const unsigned char* in, size_t insize,1248const LodePNGCompressSettings& settings = lodepng_default_compress_settings);12491250/* Zlib-compress an std::vector */1251unsigned compress(std::vector<unsigned char>& out, const std::vector<unsigned char>& in,1252const LodePNGCompressSettings& settings = lodepng_default_compress_settings);1253#endif /* LODEPNG_COMPILE_ENCODER */1254#endif /* LODEPNG_COMPILE_ZLIB */1255} /* namespace lodepng */1256#endif /*LODEPNG_COMPILE_CPP*/12571258/*1259TODO:1260[.] test if there are no memory leaks or security exploits - done a lot but needs to be checked often1261[.] check compatibility with various compilers - done but needs to be redone for every newer version1262[X] converting color to 16-bit per channel types1263[X] support color profile chunk types (but never let them touch RGB values by default)1264[ ] support all second edition public PNG chunk types (almost done except sPLT and hIST)1265[X] support non-animation third edition public PNG chunk types: eXIf, cICP, mDCV, cLLI1266[ ] make sure encoder generates no chunks with size > (2^31)-11267[ ] partial decoding (stream processing)1268[X] let the "isFullyOpaque" function check color keys and transparent palettes too1269[X] better name for the variables "codes", "codesD", "codelengthcodes", "clcl" and "lldl"1270[ ] allow treating some errors like warnings, when image is recoverable (e.g. 69, 57, 58)1271[ ] make warnings like: oob palette, checksum fail, data after iend, wrong/unknown crit chunk, no null terminator in text, ...1272[ ] error messages with line numbers (and version)1273[ ] errors in state instead of as return code?1274[ ] new errors/warnings like suspiciously big decompressed ztxt or iccp chunk1275[ ] let the C++ wrapper catch exceptions coming from the standard library and return LodePNG error codes1276[ ] allow user to provide custom color conversion functions, e.g. for premultiplied alpha, padding bits or not, ...1277[ ] allow user to give data (void*) to custom allocator1278[X] provide alternatives for C library functions not present on some platforms (memcpy, ...)1279*/12801281#endif /*LODEPNG_H inclusion guard*/12821283/*1284LodePNG Documentation1285---------------------128612870. table of contents1288--------------------128912901. about12911.1. supported features12921.2. features not supported12932. C and C++ version12943. security12954. decoding12965. encoding12976. color conversions12986.1. PNG color types12996.2. color conversions13006.3. padding bits13016.4. A note about 16-bits per channel and endianness13027. error values13038. chunks and PNG editing13049. compiler support130510. examples130610.1. decoder C++ example130710.2. decoder C example130811. state settings reference130912. changes131013. contact information1311131213131. about1314--------13151316PNG is a file format to store raster images losslessly with good compression,1317supporting different color types and alpha channel.13181319LodePNG is a PNG codec according to the Portable Network Graphics (PNG)1320Specification (Second Edition) - W3C Recommendation 10 November 2003.13211322The specifications used are:13231324*) Portable Network Graphics (PNG) Specification (Second Edition):1325http://www.w3.org/TR/2003/REC-PNG-200311101326*) RFC 1950 ZLIB Compressed Data Format version 3.3:1327http://www.gzip.org/zlib/rfc-zlib.html1328*) RFC 1951 DEFLATE Compressed Data Format Specification ver 1.3:1329http://www.gzip.org/zlib/rfc-deflate.html13301331The most recent version of LodePNG can currently be found at1332http://lodev.org/lodepng/13331334LodePNG works both in C (ISO C90) and C++, with a C++ wrapper that adds1335extra functionality.13361337LodePNG exists out of two files:1338-lodepng.h: the header file for both C and C++1339-lodepng.c(pp): give it the name lodepng.c or lodepng.cpp (or .cc) depending on your usage13401341If you want to start using LodePNG right away without reading this doc, get the1342examples from the LodePNG website to see how to use it in code, or check the1343smaller examples in chapter 13 here.13441345LodePNG is simple but only supports the basic requirements. To achieve1346simplicity, the following design choices were made: There are no dependencies1347on any external library. There are functions to decode and encode a PNG with1348a single function call, and extended versions of these functions taking a1349LodePNGState struct allowing to specify or get more information. By default1350the colors of the raw image are always RGB or RGBA, no matter what color type1351the PNG file uses. To read and write files, there are simple functions to1352convert the files to/from buffers in memory.13531354This all makes LodePNG suitable for loading textures in games, demos and small1355programs, ... It's less suitable for full fledged image editors, loading PNGs1356over network (it requires all the image data to be available before decoding can1357begin), life-critical systems, ...135813591.1. supported features1360-----------------------13611362The following features are supported by the decoder:13631364*) decoding of PNGs with any color type, bit depth and interlace mode, to a 24- or 32-bit color raw image,1365or the same color type as the PNG1366*) encoding of PNGs, from any raw image to 24- or 32-bit color, or the same color type as the raw image1367*) Adam7 interlace and deinterlace for any color type1368*) loading the image from harddisk or decoding it from a buffer from other sources than harddisk1369*) support for alpha channels, including RGBA color model, translucent palettes and color keying1370*) zlib decompression (inflate)1371*) zlib compression (deflate)1372*) CRC32 and ADLER32 checksums1373*) colorimetric color profile conversions: currently experimentally available in lodepng_util.cpp only,1374plus alternatively ability to pass on chroma/gamma/ICC profile information to other color management system.1375*) handling of unknown chunks, allowing making a PNG editor that stores custom and unknown chunks.1376*) the following chunks are supported by both encoder and decoder:1377IHDR: header information1378PLTE: color palette1379IDAT: pixel data1380IEND: the final chunk1381tRNS: transparency for palettized images1382tEXt: textual information1383zTXt: compressed textual information1384iTXt: international textual information1385bKGD: suggested background color1386pHYs: physical dimensions1387tIME: modification time1388cHRM: RGB chromaticities1389gAMA: RGB gamma correction1390iCCP: ICC color profile1391sRGB: rendering intent1392sBIT: significant bits139313941.2. features not supported1395---------------------------13961397The following features are not (yet) supported:13981399*) some features needed to make a conformant PNG-Editor might be still missing.1400*) partial loading/stream processing. All data must be available and is processed in one call.1401*) The hIST and sPLT public chunks are not (yet) supported but treated as unknown chunks1402140314042. C and C++ version1405--------------------14061407The C version uses buffers allocated with alloc that you need to free()1408yourself. You need to use init and cleanup functions for each struct whenever1409using a struct from the C version to avoid exploits and memory leaks.14101411The C++ version has extra functions with std::vectors in the interface and the1412lodepng::State class which is a LodePNGState with constructor and destructor.14131414These files work without modification for both C and C++ compilers because all1415the additional C++ code is in "#ifdef __cplusplus" blocks that make C-compilers1416ignore it, and the C code is made to compile both with strict ISO C90 and C++.14171418To use the C++ version, you need to rename the source file to lodepng.cpp1419(instead of lodepng.c), and compile it with a C++ compiler.14201421To use the C version, you need to rename the source file to lodepng.c (instead1422of lodepng.cpp), and compile it with a C compiler.1423142414253. Security1426-----------14271428Even if carefully designed, it's always possible that LodePNG contains possible1429exploits. If you discover one, please let me know, and it will be fixed.14301431When using LodePNG, care has to be taken with the C version of LodePNG, as well1432as the C-style structs when working with C++. The following conventions are used1433for all C-style structs:14341435-if a struct has a corresponding init function, always call the init function when making a new one1436-if a struct has a corresponding cleanup function, call it before the struct disappears to avoid memory leaks1437-if a struct has a corresponding copy function, use the copy function instead of "=".1438The destination must also be inited already.1439144014414. Decoding1442-----------14431444Decoding converts a PNG compressed image to a raw pixel buffer.14451446Most documentation on using the decoder is at its declarations in the header1447above. For C, simple decoding can be done with functions such as1448lodepng_decode32, and more advanced decoding can be done with the struct1449LodePNGState and lodepng_decode. For C++, all decoding can be done with the1450various lodepng::decode functions, and lodepng::State can be used for advanced1451features.14521453When using the LodePNGState, it uses the following fields for decoding:1454*) LodePNGInfo info_png: it stores extra information about the PNG (the input) in here1455*) LodePNGColorMode info_raw: here you can say what color mode of the raw image (the output) you want to get1456*) LodePNGDecoderSettings decoder: you can specify a few extra settings for the decoder to use14571458LodePNGInfo info_png1459--------------------14601461After decoding, this contains extra information of the PNG image, except the actual1462pixels, width and height because these are already gotten directly from the decoder1463functions.14641465It contains for example the original color type of the PNG image, text comments,1466suggested background color, etc... More details about the LodePNGInfo struct are1467at its declaration documentation.14681469LodePNGColorMode info_raw1470-------------------------14711472When decoding, here you can specify which color type you want1473the resulting raw image to be. If this is different from the colortype of the1474PNG, then the decoder will automatically convert the result. This conversion1475always works, except if you want it to convert a color PNG to grayscale or to1476a palette with missing colors.14771478By default, 32-bit color is used for the result.14791480LodePNGDecoderSettings decoder1481------------------------------14821483The settings can be used to ignore the errors created by invalid CRC and Adler321484chunks, and to disable the decoding of tEXt chunks.14851486There's also a setting color_convert, true by default. If false, no conversion1487is done, the resulting data will be as it was in the PNG (after decompression)1488and you'll have to puzzle the colors of the pixels together yourself using the1489color type information in the LodePNGInfo.1490149114925. Encoding1493-----------14941495Encoding converts a raw pixel buffer to a PNG compressed image.14961497Most documentation on using the encoder is at its declarations in the header1498above. For C, simple encoding can be done with functions such as1499lodepng_encode32, and more advanced decoding can be done with the struct1500LodePNGState and lodepng_encode. For C++, all encoding can be done with the1501various lodepng::encode functions, and lodepng::State can be used for advanced1502features.15031504Like the decoder, the encoder can also give errors. However it gives less errors1505since the encoder input is trusted, the decoder input (a PNG image that could1506be forged by anyone) is not trusted.15071508When using the LodePNGState, it uses the following fields for encoding:1509*) LodePNGInfo info_png: here you specify how you want the PNG (the output) to be.1510*) LodePNGColorMode info_raw: here you say what color type of the raw image (the input) has1511*) LodePNGEncoderSettings encoder: you can specify a few settings for the encoder to use15121513LodePNGInfo info_png1514--------------------15151516When encoding, you use this the opposite way as when decoding: for encoding,1517you fill in the values you want the PNG to have before encoding. By default it's1518not needed to specify a color type for the PNG since it's automatically chosen,1519but it's possible to choose it yourself given the right settings.15201521The encoder will not always exactly match the LodePNGInfo struct you give,1522it tries as close as possible. Some things are ignored by the encoder. The1523encoder uses, for example, the following settings from it when applicable:1524colortype and bitdepth, text chunks, time chunk, the color key, the palette, the1525background color, the interlace method, unknown chunks, ...15261527When encoding to a PNG with colortype 3, the encoder will generate a PLTE chunk.1528If the palette contains any colors for which the alpha channel is not 255 (so1529there are translucent colors in the palette), it'll add a tRNS chunk.15301531LodePNGColorMode info_raw1532-------------------------15331534You specify the color type of the raw image that you give to the input here,1535including a possible transparent color key and palette you happen to be using in1536your raw image data.15371538By default, 32-bit color is assumed, meaning your input has to be in RGBA1539format with 4 bytes (unsigned chars) per pixel.15401541LodePNGEncoderSettings encoder1542------------------------------15431544The following settings are supported (some are in sub-structs):1545*) auto_convert: when this option is enabled, the encoder will1546automatically choose the smallest possible color mode (including color key) that1547can encode the colors of all pixels without information loss.1548*) btype: the block type for LZ77. 0 = uncompressed, 1 = fixed huffman tree,15492 = dynamic huffman tree (best compression). Should be 2 for proper1550compression.1551*) use_lz77: whether or not to use LZ77 for compressed block types. Should be1552true for proper compression.1553*) windowsize: the window size used by the LZ77 encoder (1 - 32768). Has value15542048 by default, but can be set to 32768 for better, but slow, compression.1555*) force_palette: if colortype is 2 or 6, you can make the encoder write a PLTE1556chunk if force_palette is true. This can used as suggested palette to convert1557to by viewers that don't support more than 256 colors (if those still exist)1558*) add_id: add text chunk "Encoder: LodePNG <version>" to the image.1559*) text_compression: default 1. If 1, it'll store texts as zTXt instead of tEXt chunks.1560zTXt chunks use zlib compression on the text. This gives a smaller result on1561large texts but a larger result on small texts (such as a single program name).1562It's all tEXt or all zTXt though, there's no separate setting per text yet.1563156415656. color conversions1566--------------------15671568An important thing to note about LodePNG, is that the color type of the PNG, and1569the color type of the raw image, are completely independent. By default, when1570you decode a PNG, you get the result as a raw image in the color type you want,1571no matter whether the PNG was encoded with a palette, grayscale or RGBA color.1572And if you encode an image, by default LodePNG will automatically choose the PNG1573color type that gives good compression based on the values of colors and amount1574of colors in the image. It can be configured to let you control it instead as1575well, though.15761577To be able to do this, LodePNG does conversions from one color mode to another.1578It can convert from almost any color type to any other color type, except the1579following conversions: RGB to grayscale is not supported, and converting to a1580palette when the palette doesn't have a required color is not supported. This is1581not supported on purpose: this is information loss which requires a color1582reduction algorithm that is beyond the scope of a PNG encoder (yes, RGB to gray1583is easy, but there are multiple ways if you want to give some channels more1584weight).15851586By default, when decoding, you get the raw image in 32-bit RGBA or 24-bit RGB1587color, no matter what color type the PNG has. And by default when encoding,1588LodePNG automatically picks the best color model for the output PNG, and expects1589the input image to be 32-bit RGBA or 24-bit RGB. So, unless you want to control1590the color format of the images yourself, you can skip this chapter.159115926.1. PNG color types1593--------------------15941595A PNG image can have many color types, ranging from 1-bit color to 64-bit color,1596as well as palettized color modes. After the zlib decompression and unfiltering1597in the PNG image is done, the raw pixel data will have that color type and thus1598a certain amount of bits per pixel. If you want the output raw image after1599decoding to have another color type, a conversion is done by LodePNG.16001601The PNG specification gives the following color types:160216030: grayscale, bit depths 1, 2, 4, 8, 1616042: RGB, bit depths 8 and 1616053: palette, bit depths 1, 2, 4 and 816064: grayscale with alpha, bit depths 8 and 1616076: RGBA, bit depths 8 and 1616081609Bit depth is the amount of bits per pixel per color channel. So the total amount1610of bits per pixel is: amount of channels * bitdepth.161116126.2. color conversions1613----------------------16141615As explained in the sections about the encoder and decoder, you can specify1616color types and bit depths in info_png and info_raw to change the default1617behaviour.16181619If, when decoding, you want the raw image to be something else than the default,1620you need to set the color type and bit depth you want in the LodePNGColorMode,1621or the parameters colortype and bitdepth of the simple decoding function.16221623If, when encoding, you use another color type than the default in the raw input1624image, you need to specify its color type and bit depth in the LodePNGColorMode1625of the raw image, or use the parameters colortype and bitdepth of the simple1626encoding function.16271628If, when encoding, you don't want LodePNG to choose the output PNG color type1629but control it yourself, you need to set auto_convert in the encoder settings1630to false, and specify the color type you want in the LodePNGInfo of the1631encoder (including palette: it can generate a palette if auto_convert is true,1632otherwise not).16331634If the input and output color type differ (whether user chosen or auto chosen),1635LodePNG will do a color conversion, which follows the rules below, and may1636sometimes result in an error.16371638To avoid some confusion:1639-the decoder converts from PNG to raw image1640-the encoder converts from raw image to PNG1641-the colortype and bitdepth in LodePNGColorMode info_raw, are those of the raw image1642-the colortype and bitdepth in the color field of LodePNGInfo info_png, are those of the PNG1643-when encoding, the color type in LodePNGInfo is ignored if auto_convert1644is enabled, it is automatically generated instead1645-when decoding, the color type in LodePNGInfo is set by the decoder to that of the original1646PNG image, but it can be ignored since the raw image has the color type you requested instead1647-if the color type of the LodePNGColorMode and PNG image aren't the same, a conversion1648between the color types is done if the color types are supported. If it is not1649supported, an error is returned. If the types are the same, no conversion is done.1650-even though some conversions aren't supported, LodePNG supports loading PNGs from any1651colortype and saving PNGs to any colortype, sometimes it just requires preparing1652the raw image correctly before encoding.1653-both encoder and decoder use the same color converter.16541655The function lodepng_convert does the color conversion. It is available in the1656interface but normally isn't needed since the encoder and decoder already call1657it.16581659Non supported color conversions:1660-color to grayscale when non-gray pixels are present: no error is thrown, but1661the result will look ugly because only the red channel is taken (it assumes all1662three channels are the same in this case so ignores green and blue). The reason1663no error is given is to allow converting from three-channel grayscale images to1664one-channel even if there are numerical imprecisions.1665-anything to palette when the palette does not have an exact match for a from-color1666in it: in this case an error is thrown16671668Supported color conversions:1669-anything to 8-bit RGB, 8-bit RGBA, 16-bit RGB, 16-bit RGBA1670-any gray or gray+alpha, to gray or gray+alpha1671-anything to a palette, as long as the palette has the requested colors in it1672-removing alpha channel1673-higher to smaller bitdepth, and vice versa16741675If you want no color conversion to be done (e.g. for speed or control):1676-In the encoder, you can make it save a PNG with any color type by giving the1677raw color mode and LodePNGInfo the same color mode, and setting auto_convert to1678false.1679-In the decoder, you can make it store the pixel data in the same color type1680as the PNG has, by setting the color_convert setting to false. Settings in1681info_raw are then ignored.168216836.3. padding bits1684-----------------16851686In the PNG file format, if a less than 8-bit per pixel color type is used and the scanlines1687have a bit amount that isn't a multiple of 8, then padding bits are used so that each1688scanline starts at a fresh byte. But that is NOT true for the LodePNG raw input and output.1689The raw input image you give to the encoder, and the raw output image you get from the decoder1690will NOT have these padding bits, e.g. in the case of a 1-bit image with a width1691of 7 pixels, the first pixel of the second scanline will the 8th bit of the first byte,1692not the first bit of a new byte.169316946.4. A note about 16-bits per channel and endianness1695----------------------------------------------------16961697LodePNG uses unsigned char arrays for 16-bit per channel colors too, just like1698for any other color format. The 16-bit values are stored in big endian (most1699significant byte first) in these arrays. This is the opposite order of the1700little endian used by x86 CPU's.17011702LodePNG always uses big endian because the PNG file format does so internally.1703Conversions to other formats than PNG uses internally are not supported by1704LodePNG on purpose, there are myriads of formats, including endianness of 16-bit1705colors, the order in which you store R, G, B and A, and so on. Supporting and1706converting to/from all that is outside the scope of LodePNG.17071708This may mean that, depending on your use case, you may want to convert the big1709endian output of LodePNG to little endian with a for loop. This is certainly not1710always needed, many applications and libraries support big endian 16-bit colors1711anyway, but it means you cannot simply cast the unsigned char* buffer to an1712unsigned short* buffer on x86 CPUs.1713171417157. error values1716---------------17171718All functions in LodePNG that return an error code, return 0 if everything went1719OK, or a non-zero code if there was an error.17201721The meaning of the LodePNG error values can be retrieved with the function1722lodepng_error_text: given the numerical error code, it returns a description1723of the error in English as a string.17241725Check the implementation of lodepng_error_text to see the meaning of each code.17261727It is not recommended to use the numerical values to programmatically make1728different decisions based on error types as the numbers are not guaranteed to1729stay backwards compatible. They are for human consumption only. Programmatically1730only 0 or non-0 matter.1731173217338. chunks and PNG editing1734-------------------------17351736If you want to add extra chunks to a PNG you encode, or use LodePNG for a PNG1737editor that should follow the rules about handling of unknown chunks, or if your1738program is able to read other types of chunks than the ones handled by LodePNG,1739then that's possible with the chunk functions of LodePNG.17401741A PNG chunk has the following layout:174217434 bytes length17444 bytes type name1745length bytes data17464 bytes CRC174717488.1. iterating through chunks1749-----------------------------17501751If you have a buffer containing the PNG image data, then the first chunk (the1752IHDR chunk) starts at byte number 8 of that buffer. The first 8 bytes are the1753signature of the PNG and are not part of a chunk. But if you start at byte 81754then you have a chunk, and can check the following things of it.17551756NOTE: none of these functions check for memory buffer boundaries. To avoid1757exploits, always make sure the buffer contains all the data of the chunks.1758When using lodepng_chunk_next, make sure the returned value is within the1759allocated memory.17601761unsigned lodepng_chunk_length(const unsigned char* chunk):17621763Get the length of the chunk's data. The total chunk length is this length + 12.17641765void lodepng_chunk_type(char type[5], const unsigned char* chunk):1766unsigned char lodepng_chunk_type_equals(const unsigned char* chunk, const char* type):17671768Get the type of the chunk or compare if it's a certain type17691770unsigned char lodepng_chunk_critical(const unsigned char* chunk):1771unsigned char lodepng_chunk_private(const unsigned char* chunk):1772unsigned char lodepng_chunk_safetocopy(const unsigned char* chunk):17731774Check if the chunk is critical in the PNG standard (only IHDR, PLTE, IDAT and IEND are).1775Check if the chunk is private (public chunks are part of the standard, private ones not).1776Check if the chunk is safe to copy. If it's not, then, when modifying data in a critical1777chunk, unsafe to copy chunks of the old image may NOT be saved in the new one if your1778program doesn't handle that type of unknown chunk.17791780unsigned char* lodepng_chunk_data(unsigned char* chunk):1781const unsigned char* lodepng_chunk_data_const(const unsigned char* chunk):17821783Get a pointer to the start of the data of the chunk.17841785unsigned lodepng_chunk_check_crc(const unsigned char* chunk):1786void lodepng_chunk_generate_crc(unsigned char* chunk):17871788Check if the crc is correct or generate a correct one.17891790unsigned char* lodepng_chunk_next(unsigned char* chunk):1791const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk):17921793Iterate to the next chunk. This works if you have a buffer with consecutive chunks. Note that these1794functions do no boundary checking of the allocated data whatsoever, so make sure there is enough1795data available in the buffer to be able to go to the next chunk.17961797unsigned lodepng_chunk_append(unsigned char** out, size_t* outsize, const unsigned char* chunk):1798unsigned lodepng_chunk_create(unsigned char** out, size_t* outsize, unsigned length,1799const char* type, const unsigned char* data):18001801These functions are used to create new chunks that are appended to the data in *out that has1802length *outsize. The append function appends an existing chunk to the new data. The create1803function creates a new chunk with the given parameters and appends it. Type is the 4-letter1804name of the chunk.180518068.2. chunks in info_png1807-----------------------18081809The LodePNGInfo struct contains fields with the unknown chunk in it. It has 31810buffers (each with size) to contain 3 types of unknown chunks:1811the ones that come before the PLTE chunk, the ones that come between the PLTE1812and the IDAT chunks, and the ones that come after the IDAT chunks.1813It's necessary to make the distinction between these 3 cases because the PNG1814standard forces to keep the ordering of unknown chunks compared to the critical1815chunks, but does not force any other ordering rules.18161817info_png.unknown_chunks_data[0] is the chunks before PLTE1818info_png.unknown_chunks_data[1] is the chunks after PLTE, before IDAT1819info_png.unknown_chunks_data[2] is the chunks after IDAT18201821The chunks in these 3 buffers can be iterated through and read by using the same1822way described in the previous subchapter.18231824When using the decoder to decode a PNG, you can make it store all unknown chunks1825if you set the option settings.remember_unknown_chunks to 1. By default, this1826option is off (0).18271828The encoder will always encode unknown chunks that are stored in the info_png.1829If you need it to add a particular chunk that isn't known by LodePNG, you can1830use lodepng_chunk_append or lodepng_chunk_create to the chunk data in1831info_png.unknown_chunks_data[x].18321833Chunks that are known by LodePNG should not be added in that way. E.g. to make1834LodePNG add a bKGD chunk, set background_defined to true and add the correct1835parameters there instead.1836183718389. compiler support1839-------------------18401841No libraries other than the current standard C library are needed to compile1842LodePNG. For the C++ version, only the standard C++ library is needed on top.1843Add the files lodepng.c(pp) and lodepng.h to your project, include1844lodepng.h where needed, and your program can read/write PNG files.18451846It is compatible with C90 and up, and C++03 and up.18471848If performance is important, use optimization when compiling! For both the1849encoder and decoder, this makes a large difference.18501851Make sure that LodePNG is compiled with the same compiler of the same version1852and with the same settings as the rest of the program, or the interfaces with1853std::vectors and std::strings in C++ can be incompatible.18541855CHAR_BITS must be 8 or higher, because LodePNG uses unsigned chars for octets.18561857*) gcc and g++18581859LodePNG is developed in gcc so this compiler is natively supported. It gives no1860warnings with compiler options "-Wall -Wextra -pedantic -ansi", with gcc and g++1861version 4.7.1 on Linux, 32-bit and 64-bit.18621863*) Clang18641865Fully supported and warning-free.18661867*) Mingw18681869The Mingw compiler (a port of gcc for Windows) should be fully supported by1870LodePNG.18711872*) Visual Studio and Visual C++ Express Edition18731874LodePNG should be warning-free with warning level W4. Two warnings were disabled1875with pragmas though: warning 4244 about implicit conversions, and warning 49961876where it wants to use a non-standard function fopen_s instead of the standard C1877fopen.18781879Visual Studio may want "stdafx.h" files to be included in each source file and1880give an error "unexpected end of file while looking for precompiled header".1881This is not standard C++ and will not be added to the stock LodePNG. You can1882disable it for lodepng.cpp only by right clicking it, Properties, C/C++,1883Precompiled Headers, and set it to Not Using Precompiled Headers there.18841885NOTE: Modern versions of VS should be fully supported, but old versions, e.g.1886VS6, are not guaranteed to work.18871888*) Compilers on Macintosh18891890LodePNG has been reported to work both with gcc and LLVM for Macintosh, both for1891C and C++.18921893*) Other Compilers18941895If you encounter problems on any compilers, feel free to let me know and I may1896try to fix it if the compiler is modern and standards compliant.18971898189910. examples1900------------19011902This decoder example shows the most basic usage of LodePNG. More complex1903examples can be found on the LodePNG website.19041905NOTE: these examples do not support wide-character filenames, you can use an1906external method to handle such files and encode or decode in-memory1907190810.1. decoder C++ example1909-------------------------19101911#include "lodepng.h"1912#include <iostream>19131914int main(int argc, char *argv[]) {1915const char* filename = argc > 1 ? argv[1] : "test.png";19161917//load and decode1918std::vector<unsigned char> image;1919unsigned width, height;1920unsigned error = lodepng::decode(image, width, height, filename);19211922//if there's an error, display it1923if(error) std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl;19241925//the pixels are now in the vector "image", 4 bytes per pixel, ordered RGBARGBA..., use it as texture, draw it, ...1926}1927192810.2. decoder C example1929-----------------------19301931#include "lodepng.h"19321933int main(int argc, char *argv[]) {1934unsigned error;1935unsigned char* image;1936size_t width, height;1937const char* filename = argc > 1 ? argv[1] : "test.png";19381939error = lodepng_decode32_file(&image, &width, &height, filename);19401941if(error) printf("decoder error %u: %s\n", error, lodepng_error_text(error));19421943/ * use image here * /19441945free(image);1946return 0;1947}1948194911. state settings reference1950----------------------------19511952A quick reference of some settings to set on the LodePNGState19531954For decoding:19551956state.decoder.zlibsettings.ignore_adler32: ignore ADLER32 checksums1957state.decoder.zlibsettings.custom_...: use custom inflate function1958state.decoder.ignore_crc: ignore CRC checksums1959state.decoder.ignore_critical: ignore unknown critical chunks1960state.decoder.ignore_end: ignore missing IEND chunk. May fail if this corruption causes other errors1961state.decoder.color_convert: convert internal PNG color to chosen one1962state.decoder.read_text_chunks: whether to read in text metadata chunks1963state.decoder.remember_unknown_chunks: whether to read in unknown chunks1964state.info_raw.colortype: desired color type for decoded image1965state.info_raw.bitdepth: desired bit depth for decoded image1966state.info_raw....: more color settings, see struct LodePNGColorMode1967state.info_png....: no settings for decoder but ouput, see struct LodePNGInfo19681969For encoding:19701971state.encoder.zlibsettings.btype: disable compression by setting it to 01972state.encoder.zlibsettings.use_lz77: use LZ77 in compression1973state.encoder.zlibsettings.windowsize: tweak LZ77 windowsize1974state.encoder.zlibsettings.minmatch: tweak min LZ77 length to match1975state.encoder.zlibsettings.nicematch: tweak LZ77 match where to stop searching1976state.encoder.zlibsettings.lazymatching: try one more LZ77 matching1977state.encoder.zlibsettings.custom_...: use custom deflate function1978state.encoder.auto_convert: choose optimal PNG color type, if 0 uses info_png1979state.encoder.filter_palette_zero: PNG filter strategy for palette1980state.encoder.filter_strategy: PNG filter strategy to encode with1981state.encoder.force_palette: add palette even if not encoding to one1982state.encoder.add_id: add LodePNG identifier and version as a text chunk1983state.encoder.text_compression: use compressed text chunks for metadata1984state.info_raw.colortype: color type of raw input image you provide1985state.info_raw.bitdepth: bit depth of raw input image you provide1986state.info_raw: more color settings, see struct LodePNGColorMode1987state.info_png.color.colortype: desired color type if auto_convert is false1988state.info_png.color.bitdepth: desired bit depth if auto_convert is false1989state.info_png.color....: more color settings, see struct LodePNGColorMode1990state.info_png....: more PNG related settings, see struct LodePNGInfo19911992199312. changes1994-----------19951996The version number of LodePNG is the date of the change given in the format1997yyyymmdd.19981999Some changes aren't backwards compatible. Those are indicated with a (!)2000symbol.20012002Not all changes are listed here, the commit history in github lists more:2003https://github.com/lvandeve/lodepng20042005*) 6 may 2025: renamed mDCv to mDCV and cLLi to cLLI as per the recent rename2006in the draft png third edition spec. Please note that while the third2007edition is not finalized, backwards-incompatible changes to its features are2008possible.2009*) 23 dec 2024: added support for the mDCv and cLLi chunks (for png third2010edition spec)2011*) 22 dec 2024: added support for the cICP chunk (for png third edition spec)2012*) 15 dec 2024: added support for the eXIf chunk (for png third edition spec)2013*) 10 apr 2023: faster CRC32 implementation, but with larger lookup table.2014*) 13 jun 2022: added support for the sBIT chunk.2015*) 09 jan 2022: minor decoder speed improvements.2016*) 27 jun 2021: added warnings that file reading/writing functions don't support2017wide-character filenames (support for this is not planned, opening files is2018not the core part of PNG decoding/decoding and is platform dependent).2019*) 17 oct 2020: prevent decoding too large text/icc chunks by default.2020*) 06 mar 2020: simplified some of the dynamic memory allocations.2021*) 12 jan 2020: (!) added 'end' argument to lodepng_chunk_next to allow correct2022overflow checks.2023*) 14 aug 2019: around 25% faster decoding thanks to huffman lookup tables.2024*) 15 jun 2019: (!) auto_choose_color API changed (for bugfix: don't use palette2025if gray ICC profile) and non-ICC LodePNGColorProfile renamed to2026LodePNGColorStats.2027*) 30 dec 2018: code style changes only: removed newlines before opening braces.2028*) 10 sep 2018: added way to inspect metadata chunks without full decoding.2029*) 19 aug 2018: (!) fixed color mode bKGD is encoded with and made it use2030palette index in case of palette.2031*) 10 aug 2018: (!) added support for gAMA, cHRM, sRGB and iCCP chunks. This2032change is backwards compatible unless you relied on unknown_chunks for those.2033*) 11 jun 2018: less restrictive check for pixel size integer overflow2034*) 14 jan 2018: allow optionally ignoring a few more recoverable errors2035*) 17 sep 2017: fix memory leak for some encoder input error cases2036*) 27 nov 2016: grey+alpha auto color model detection bugfix2037*) 18 apr 2016: Changed qsort to custom stable sort (for platforms w/o qsort).2038*) 09 apr 2016: Fixed colorkey usage detection, and better file loading (within2039the limits of pure C90).2040*) 08 dec 2015: Made load_file function return error if file can't be opened.2041*) 24 oct 2015: Bugfix with decoding to palette output.2042*) 18 apr 2015: Boundary PM instead of just package-merge for faster encoding.2043*) 24 aug 2014: Moved to github2044*) 23 aug 2014: Reduced needless memory usage of decoder.2045*) 28 jun 2014: Removed fix_png setting, always support palette OOB for2046simplicity. Made ColorProfile public.2047*) 09 jun 2014: Faster encoder by fixing hash bug and more zeros optimization.2048*) 22 dec 2013: Power of two windowsize required for optimization.2049*) 15 apr 2013: Fixed bug with LAC_ALPHA and color key.2050*) 25 mar 2013: Added an optional feature to ignore some PNG errors (fix_png).2051*) 11 mar 2013: (!) Bugfix with custom free. Changed from "my" to "lodepng_"2052prefix for the custom allocators and made it possible with a new #define to2053use custom ones in your project without needing to change lodepng's code.2054*) 28 jan 2013: Bugfix with color key.2055*) 27 oct 2012: Tweaks in text chunk keyword length error handling.2056*) 8 oct 2012: (!) Added new filter strategy (entropy) and new auto color mode.2057(no palette). Better deflate tree encoding. New compression tweak settings.2058Faster color conversions while decoding. Some internal cleanups.2059*) 23 sep 2012: Reduced warnings in Visual Studio a little bit.2060*) 1 sep 2012: (!) Removed #define's for giving custom (de)compression functions2061and made it work with function pointers instead.2062*) 23 jun 2012: Added more filter strategies. Made it easier to use custom alloc2063and free functions and toggle #defines from compiler flags. Small fixes.2064*) 6 may 2012: (!) Made plugging in custom zlib/deflate functions more flexible.2065*) 22 apr 2012: (!) Made interface more consistent, renaming a lot. Removed2066redundant C++ codec classes. Reduced amount of structs. Everything changed,2067but it is cleaner now imho and functionality remains the same. Also fixed2068several bugs and shrunk the implementation code. Made new samples.2069*) 6 nov 2011: (!) By default, the encoder now automatically chooses the best2070PNG color model and bit depth, based on the amount and type of colors of the2071raw image. For this, autoLeaveOutAlphaChannel replaced by auto_choose_color.2072*) 9 oct 2011: simpler hash chain implementation for the encoder.2073*) 8 sep 2011: lz77 encoder lazy matching instead of greedy matching.2074*) 23 aug 2011: tweaked the zlib compression parameters after benchmarking.2075A bug with the PNG filtertype heuristic was fixed, so that it chooses much2076better ones (it's quite significant). A setting to do an experimental, slow,2077brute force search for PNG filter types is added.2078*) 17 aug 2011: (!) changed some C zlib related function names.2079*) 16 aug 2011: made the code less wide (max 120 characters per line).2080*) 17 apr 2011: code cleanup. Bugfixes. Convert low to 16-bit per sample colors.2081*) 21 feb 2011: fixed compiling for C90. Fixed compiling with sections disabled.2082*) 11 dec 2010: encoding is made faster, based on suggestion by Peter Eastman2083to optimize long sequences of zeros.2084*) 13 nov 2010: added LodePNG_InfoColor_hasPaletteAlpha and2085LodePNG_InfoColor_canHaveAlpha functions for convenience.2086*) 7 nov 2010: added LodePNG_error_text function to get error code description.2087*) 30 oct 2010: made decoding slightly faster2088*) 26 oct 2010: (!) changed some C function and struct names (more consistent).2089Reorganized the documentation and the declaration order in the header.2090*) 08 aug 2010: only changed some comments and external samples.2091*) 05 jul 2010: fixed bug thanks to warnings in the new gcc version.2092*) 14 mar 2010: fixed bug where too much memory was allocated for char buffers.2093*) 02 sep 2008: fixed bug where it could create empty tree that linux apps could2094read by ignoring the problem but windows apps couldn't.2095*) 06 jun 2008: added more error checks for out of memory cases.2096*) 26 apr 2008: added a few more checks here and there to ensure more safety.2097*) 06 mar 2008: crash with encoding of strings fixed2098*) 02 feb 2008: support for international text chunks added (iTXt)2099*) 23 jan 2008: small cleanups, and #defines to divide code in sections2100*) 20 jan 2008: support for unknown chunks allowing using LodePNG for an editor.2101*) 18 jan 2008: support for tIME and pHYs chunks added to encoder and decoder.2102*) 17 jan 2008: ability to encode and decode compressed zTXt chunks added2103Also various fixes, such as in the deflate and the padding bits code.2104*) 13 jan 2008: Added ability to encode Adam7-interlaced images. Improved2105filtering code of encoder.2106*) 07 jan 2008: (!) changed LodePNG to use ISO C90 instead of C++. A2107C++ wrapper around this provides an interface almost identical to before.2108Having LodePNG be pure ISO C90 makes it more portable. The C and C++ code2109are together in these files but it works both for C and C++ compilers.2110*) 29 dec 2007: (!) changed most integer types to unsigned int + other tweaks2111*) 30 aug 2007: bug fixed which makes this Borland C++ compatible2112*) 09 aug 2007: some VS2005 warnings removed again2113*) 21 jul 2007: deflate code placed in new namespace separate from zlib code2114*) 08 jun 2007: fixed bug with 2- and 4-bit color, and small interlaced images2115*) 04 jun 2007: improved support for Visual Studio 2005: crash with accessing2116invalid std::vector element [0] fixed, and level 3 and 4 warnings removed2117*) 02 jun 2007: made the encoder add a tag with version by default2118*) 27 may 2007: zlib and png code separated (but still in the same file),2119simple encoder/decoder functions added for more simple usage cases2120*) 19 may 2007: minor fixes, some code cleaning, new error added (error 69),2121moved some examples from here to lodepng_examples.cpp2122*) 12 may 2007: palette decoding bug fixed2123*) 24 apr 2007: changed the license from BSD to the zlib license2124*) 11 mar 2007: very simple addition: ability to encode bKGD chunks.2125*) 04 mar 2007: (!) tEXt chunk related fixes, and support for encoding2126palettized PNG images. Plus little interface change with palette and texts.2127*) 03 mar 2007: Made it encode dynamic Huffman shorter with repeat codes.2128Fixed a bug where the end code of a block had length 0 in the Huffman tree.2129*) 26 feb 2007: Huffman compression with dynamic trees (BTYPE 2) now implemented2130and supported by the encoder, resulting in smaller PNGs at the output.2131*) 27 jan 2007: Made the Adler-32 test faster so that a timewaste is gone.2132*) 24 jan 2007: gave encoder an error interface. Added color conversion from any2133greyscale type to 8-bit greyscale with or without alpha.2134*) 21 jan 2007: (!) Totally changed the interface. It allows more color types2135to convert to and is more uniform. See the manual for how it works now.2136*) 07 jan 2007: Some cleanup & fixes, and a few changes over the last days:2137encode/decode custom tEXt chunks, separate classes for zlib & deflate, and2138at last made the decoder give errors for incorrect Adler32 or Crc.2139*) 01 jan 2007: Fixed bug with encoding PNGs with less than 8 bits per channel.2140*) 29 dec 2006: Added support for encoding images without alpha channel, and2141cleaned out code as well as making certain parts faster.2142*) 28 dec 2006: Added "Settings" to the encoder.2143*) 26 dec 2006: The encoder now does LZ77 encoding and produces much smaller files now.2144Removed some code duplication in the decoder. Fixed little bug in an example.2145*) 09 dec 2006: (!) Placed output parameters of public functions as first parameter.2146Fixed a bug of the decoder with 16-bit per color.2147*) 15 oct 2006: Changed documentation structure2148*) 09 oct 2006: Encoder class added. It encodes a valid PNG image from the2149given image buffer, however for now it's not compressed.2150*) 08 sep 2006: (!) Changed to interface with a Decoder class2151*) 30 jul 2006: (!) LodePNG_InfoPng , width and height are now retrieved in different2152way. Renamed decodePNG to decodePNGGeneric.2153*) 29 jul 2006: (!) Changed the interface: image info is now returned as a2154struct of type LodePNG::LodePNG_Info, instead of a vector, which was a bit clumsy.2155*) 28 jul 2006: Cleaned the code and added new error checks.2156Corrected terminology "deflate" into "inflate".2157*) 23 jun 2006: Added SDL example in the documentation in the header, this2158example allows easy debugging by displaying the PNG and its transparency.2159*) 22 jun 2006: (!) Changed way to obtain error value. Added2160loadFile function for convenience. Made decodePNG32 faster.2161*) 21 jun 2006: (!) Changed type of info vector to unsigned.2162Changed position of palette in info vector. Fixed an important bug that2163happened on PNGs with an uncompressed block.2164*) 16 jun 2006: Internally changed unsigned into unsigned where2165needed, and performed some optimizations.2166*) 07 jun 2006: (!) Renamed functions to decodePNG and placed them2167in LodePNG namespace. Changed the order of the parameters. Rewrote the2168documentation in the header. Renamed files to lodepng.cpp and lodepng.h2169*) 22 apr 2006: Optimized and improved some code2170*) 07 sep 2005: (!) Changed to std::vector interface2171*) 12 aug 2005: Initial release (C++, decoder only)2172*/217321742175