33extern const char* LODEPNG_VERSION_STRING;
46#ifndef LODEPNG_NO_COMPILE_ZLIB
47#define LODEPNG_COMPILE_ZLIB
51#ifndef LODEPNG_NO_COMPILE_PNG
52#define LODEPNG_COMPILE_PNG
56#ifndef LODEPNG_NO_COMPILE_DECODER
57#define LODEPNG_COMPILE_DECODER
61#ifndef LODEPNG_NO_COMPILE_ENCODER
62#define LODEPNG_COMPILE_ENCODER
66#ifndef LODEPNG_NO_COMPILE_DISK
67#define LODEPNG_COMPILE_DISK
71#ifndef LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS
72#define LODEPNG_COMPILE_ANCILLARY_CHUNKS
76#ifndef LODEPNG_NO_COMPILE_ERROR_TEXT
77#define LODEPNG_COMPILE_ERROR_TEXT
83#ifndef LODEPNG_NO_COMPILE_ALLOCATORS
84#define LODEPNG_COMPILE_ALLOCATORS
89#ifndef LODEPNG_NO_COMPILE_CPP
90#define LODEPNG_COMPILE_CPP
94#ifdef LODEPNG_COMPILE_CPP
99#ifdef LODEPNG_COMPILE_PNG
101typedef enum LodePNGColorType {
112 LCT_MAX_OCTET_VALUE = 255
115#ifdef LODEPNG_COMPILE_DECODER
131unsigned lodepng_decode_memory(
unsigned char** out,
unsigned* w,
unsigned* h,
132 const unsigned char* in,
size_t insize,
133 LodePNGColorType colortype,
unsigned bitdepth);
136unsigned lodepng_decode32(
unsigned char** out,
unsigned* w,
unsigned* h,
137 const unsigned char* in,
size_t insize);
140unsigned lodepng_decode24(
unsigned char** out,
unsigned* w,
unsigned* h,
141 const unsigned char* in,
size_t insize);
143#ifdef LODEPNG_COMPILE_DISK
148unsigned lodepng_decode_file(
unsigned char** out,
unsigned* w,
unsigned* h,
149 const char* filename,
150 LodePNGColorType colortype,
unsigned bitdepth);
153unsigned lodepng_decode32_file(
unsigned char** out,
unsigned* w,
unsigned* h,
154 const char* filename);
157unsigned lodepng_decode24_file(
unsigned char** out,
unsigned* w,
unsigned* h,
158 const char* filename);
163#ifdef LODEPNG_COMPILE_ENCODER
180unsigned lodepng_encode_memory(
unsigned char** out,
size_t* outsize,
181 const unsigned char* image,
unsigned w,
unsigned h,
182 LodePNGColorType colortype,
unsigned bitdepth);
185unsigned lodepng_encode32(
unsigned char** out,
size_t* outsize,
186 const unsigned char* image,
unsigned w,
unsigned h);
189unsigned lodepng_encode24(
unsigned char** out,
size_t* outsize,
190 const unsigned char* image,
unsigned w,
unsigned h);
192#ifdef LODEPNG_COMPILE_DISK
198unsigned lodepng_encode_file(
const char* filename,
199 const unsigned char* image,
unsigned w,
unsigned h,
200 LodePNGColorType colortype,
unsigned bitdepth);
203unsigned lodepng_encode32_file(
const char* filename,
204 const unsigned char* image,
unsigned w,
unsigned h);
207unsigned lodepng_encode24_file(
const char* filename,
208 const unsigned char* image,
unsigned w,
unsigned h);
213#ifdef LODEPNG_COMPILE_CPP
215#ifdef LODEPNG_COMPILE_DECODER
218unsigned decode(std::vector<unsigned char>& out,
unsigned& w,
unsigned& h,
219 const unsigned char* in,
size_t insize,
220 LodePNGColorType colortype = LCT_RGBA,
unsigned bitdepth = 8);
221unsigned decode(std::vector<unsigned char>& out,
unsigned& w,
unsigned& h,
222 const std::vector<unsigned char>& in,
223 LodePNGColorType colortype = LCT_RGBA,
unsigned bitdepth = 8);
224#ifdef LODEPNG_COMPILE_DISK
229unsigned decode(std::vector<unsigned char>& out,
unsigned& w,
unsigned& h,
230 const std::string& filename,
231 LodePNGColorType colortype = LCT_RGBA,
unsigned bitdepth = 8);
235#ifdef LODEPNG_COMPILE_ENCODER
238unsigned encode(std::vector<unsigned char>& out,
239 const unsigned char* in,
unsigned w,
unsigned h,
240 LodePNGColorType colortype = LCT_RGBA,
unsigned bitdepth = 8);
241unsigned encode(std::vector<unsigned char>& out,
242 const std::vector<unsigned char>& in,
unsigned w,
unsigned h,
243 LodePNGColorType colortype = LCT_RGBA,
unsigned bitdepth = 8);
244#ifdef LODEPNG_COMPILE_DISK
250unsigned encode(
const std::string& filename,
251 const unsigned char* in,
unsigned w,
unsigned h,
252 LodePNGColorType colortype = LCT_RGBA,
unsigned bitdepth = 8);
253unsigned encode(
const std::string& filename,
254 const std::vector<unsigned char>& in,
unsigned w,
unsigned h,
255 LodePNGColorType colortype = LCT_RGBA,
unsigned bitdepth = 8);
262#ifdef LODEPNG_COMPILE_ERROR_TEXT
264const char* lodepng_error_text(
unsigned code);
267#ifdef LODEPNG_COMPILE_DECODER
269typedef struct LodePNGDecompressSettings LodePNGDecompressSettings;
270struct LodePNGDecompressSettings {
272 unsigned ignore_adler32;
273 unsigned ignore_nlen;
280 size_t max_output_size;
284 unsigned (*custom_zlib)(
unsigned char**,
size_t*,
285 const unsigned char*, size_t,
286 const LodePNGDecompressSettings*);
290 unsigned (*custom_inflate)(
unsigned char**,
size_t*,
291 const unsigned char*, size_t,
292 const LodePNGDecompressSettings*);
294 const void* custom_context;
297extern const LodePNGDecompressSettings lodepng_default_decompress_settings;
298void lodepng_decompress_settings_init(LodePNGDecompressSettings* settings);
301#ifdef LODEPNG_COMPILE_ENCODER
306typedef struct LodePNGCompressSettings LodePNGCompressSettings;
307struct LodePNGCompressSettings {
314 unsigned lazymatching;
317 unsigned (*custom_zlib)(
unsigned char**,
size_t*,
318 const unsigned char*, size_t,
319 const LodePNGCompressSettings*);
323 unsigned (*custom_deflate)(
unsigned char**,
size_t*,
324 const unsigned char*, size_t,
325 const LodePNGCompressSettings*);
327 const void* custom_context;
330extern const LodePNGCompressSettings lodepng_default_compress_settings;
331void lodepng_compress_settings_init(LodePNGCompressSettings* settings);
334#ifdef LODEPNG_COMPILE_PNG
340typedef struct LodePNGColorMode {
342 LodePNGColorType colortype;
360 unsigned char* palette;
374 unsigned key_defined;
381void lodepng_color_mode_init(LodePNGColorMode* info);
382void lodepng_color_mode_cleanup(LodePNGColorMode* info);
384unsigned lodepng_color_mode_copy(LodePNGColorMode* dest,
const LodePNGColorMode* source);
386LodePNGColorMode lodepng_color_mode_make(LodePNGColorType colortype,
unsigned bitdepth);
388void lodepng_palette_clear(LodePNGColorMode* info);
390unsigned lodepng_palette_add(LodePNGColorMode* info,
391 unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a);
394unsigned lodepng_get_bpp(
const LodePNGColorMode* info);
397unsigned lodepng_get_channels(
const LodePNGColorMode* info);
399unsigned lodepng_is_greyscale_type(
const LodePNGColorMode* info);
401unsigned lodepng_is_alpha_type(
const LodePNGColorMode* info);
403unsigned lodepng_is_palette_type(
const LodePNGColorMode* info);
406unsigned lodepng_has_palette_alpha(
const LodePNGColorMode* info);
414unsigned lodepng_can_have_alpha(
const LodePNGColorMode* info);
416size_t lodepng_get_raw_size(
unsigned w,
unsigned h,
const LodePNGColorMode* color);
418#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
420typedef struct LodePNGTime {
431typedef struct LodePNGInfo {
433 unsigned compression_method;
434 unsigned filter_method;
435 unsigned interlace_method;
436 LodePNGColorMode color;
438#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
462 unsigned background_defined;
463 unsigned background_r;
464 unsigned background_g;
465 unsigned background_b;
501 char** itext_langtags;
502 char** itext_transkeys;
503 char** itext_strings;
506 unsigned time_defined;
510 unsigned phys_defined;
526 unsigned gama_defined;
530 unsigned chrm_defined;
531 unsigned chrm_white_x;
532 unsigned chrm_white_y;
535 unsigned chrm_green_x;
536 unsigned chrm_green_y;
537 unsigned chrm_blue_x;
538 unsigned chrm_blue_y;
545 unsigned srgb_defined;
546 unsigned srgb_intent;
569 unsigned iccp_defined;
576 unsigned char* iccp_profile;
577 unsigned iccp_profile_size;
599 unsigned char* unknown_chunks_data[3];
600 size_t unknown_chunks_size[3];
605void lodepng_info_init(LodePNGInfo* info);
606void lodepng_info_cleanup(LodePNGInfo* info);
608unsigned lodepng_info_copy(LodePNGInfo* dest,
const LodePNGInfo* source);
610#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
611unsigned lodepng_add_text(LodePNGInfo* info,
const char* key,
const char* str);
612void lodepng_clear_text(LodePNGInfo* info);
614unsigned lodepng_add_itext(LodePNGInfo* info,
const char* key,
const char* langtag,
615 const char* transkey,
const char* str);
616void lodepng_clear_itext(LodePNGInfo* info);
619unsigned lodepng_set_icc(LodePNGInfo* info,
const char* name,
const unsigned char* profile,
unsigned profile_size);
620void lodepng_clear_icc(LodePNGInfo* info);
634unsigned lodepng_convert(
unsigned char* out,
const unsigned char* in,
635 const LodePNGColorMode* mode_out,
const LodePNGColorMode* mode_in,
636 unsigned w,
unsigned h);
638#ifdef LODEPNG_COMPILE_DECODER
643typedef struct LodePNGDecoderSettings {
644 LodePNGDecompressSettings zlibsettings;
648 unsigned ignore_critical;
655 unsigned color_convert;
657#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
658 unsigned read_text_chunks;
661 unsigned remember_unknown_chunks;
666 size_t max_text_size;
673} LodePNGDecoderSettings;
675void lodepng_decoder_settings_init(LodePNGDecoderSettings* settings);
678#ifdef LODEPNG_COMPILE_ENCODER
680typedef enum LodePNGFilterStrategy {
700} LodePNGFilterStrategy;
705typedef struct LodePNGColorStats {
708 unsigned short key_r;
709 unsigned short key_g;
710 unsigned short key_b;
713 unsigned char palette[1024];
718 unsigned allow_palette;
719 unsigned allow_greyscale;
722void lodepng_color_stats_init(LodePNGColorStats* stats);
726unsigned lodepng_compute_color_stats(LodePNGColorStats* stats,
727 const unsigned char* image,
unsigned w,
unsigned h,
728 const LodePNGColorMode* mode_in);
731typedef struct LodePNGEncoderSettings {
732 LodePNGCompressSettings zlibsettings;
734 unsigned auto_convert;
740 unsigned filter_palette_zero;
743 LodePNGFilterStrategy filter_strategy;
748 const unsigned char* predefined_filters;
752 unsigned force_palette;
753#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
757 unsigned text_compression;
759} LodePNGEncoderSettings;
761void lodepng_encoder_settings_init(LodePNGEncoderSettings* settings);
765#if defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ENCODER)
767typedef struct LodePNGState {
768#ifdef LODEPNG_COMPILE_DECODER
769 LodePNGDecoderSettings decoder;
771#ifdef LODEPNG_COMPILE_ENCODER
772 LodePNGEncoderSettings encoder;
774 LodePNGColorMode info_raw;
775 LodePNGInfo info_png;
780void lodepng_state_init(LodePNGState* state);
781void lodepng_state_cleanup(LodePNGState* state);
782void lodepng_state_copy(LodePNGState* dest,
const LodePNGState* source);
785#ifdef LODEPNG_COMPILE_DECODER
790unsigned lodepng_decode(
unsigned char** out,
unsigned* w,
unsigned* h,
792 const unsigned char* in,
size_t insize);
799unsigned lodepng_inspect(
unsigned* w,
unsigned* h,
801 const unsigned char* in,
size_t insize);
816unsigned lodepng_inspect_chunk(LodePNGState* state,
size_t pos,
817 const unsigned char* in,
size_t insize);
819#ifdef LODEPNG_COMPILE_ENCODER
821unsigned lodepng_encode(
unsigned char** out,
size_t* outsize,
822 const unsigned char* image,
unsigned w,
unsigned h,
823 LodePNGState* state);
855unsigned lodepng_chunk_length(
const unsigned char* chunk);
858void lodepng_chunk_type(
char type[5],
const unsigned char* chunk);
861unsigned char lodepng_chunk_type_equals(
const unsigned char* chunk,
const char* type);
864unsigned char lodepng_chunk_ancillary(
const unsigned char* chunk);
867unsigned char lodepng_chunk_private(
const unsigned char* chunk);
870unsigned char lodepng_chunk_safetocopy(
const unsigned char* chunk);
873unsigned char* lodepng_chunk_data(
unsigned char* chunk);
874const unsigned char* lodepng_chunk_data_const(
const unsigned char* chunk);
877unsigned lodepng_chunk_check_crc(
const unsigned char* chunk);
880void lodepng_chunk_generate_crc(
unsigned char* chunk);
893unsigned char* lodepng_chunk_next(
unsigned char* chunk,
unsigned char* end);
894const unsigned char* lodepng_chunk_next_const(
const unsigned char* chunk,
const unsigned char* end);
897unsigned char* lodepng_chunk_find(
unsigned char* chunk,
unsigned char* end,
const char type[5]);
898const unsigned char* lodepng_chunk_find_const(
const unsigned char* chunk,
const unsigned char* end,
const char type[5]);
905unsigned lodepng_chunk_append(
unsigned char** out,
size_t* outsize,
const unsigned char* chunk);
913unsigned lodepng_chunk_create(
unsigned char** out,
size_t* outsize,
unsigned length,
914 const char* type,
const unsigned char* data);
918unsigned lodepng_crc32(
const unsigned char* buf,
size_t len);
922#ifdef LODEPNG_COMPILE_ZLIB
929#ifdef LODEPNG_COMPILE_DECODER
931unsigned lodepng_inflate(
unsigned char** out,
size_t* outsize,
932 const unsigned char* in,
size_t insize,
933 const LodePNGDecompressSettings* settings);
941unsigned lodepng_zlib_decompress(
unsigned char** out,
size_t* outsize,
942 const unsigned char* in,
size_t insize,
943 const LodePNGDecompressSettings* settings);
946#ifdef LODEPNG_COMPILE_ENCODER
954unsigned lodepng_zlib_compress(
unsigned char** out,
size_t* outsize,
955 const unsigned char* in,
size_t insize,
956 const LodePNGCompressSettings* settings);
962unsigned lodepng_huffman_code_lengths(
unsigned* lengths,
const unsigned* frequencies,
963 size_t numcodes,
unsigned maxbitlen);
966unsigned lodepng_deflate(
unsigned char** out,
size_t* outsize,
967 const unsigned char* in,
size_t insize,
968 const LodePNGCompressSettings* settings);
973#ifdef LODEPNG_COMPILE_DISK
982unsigned lodepng_load_file(
unsigned char** out,
size_t* outsize,
const char* filename);
992unsigned lodepng_save_file(
const unsigned char* buffer,
size_t buffersize,
const char* filename);
995#ifdef LODEPNG_COMPILE_CPP
998#ifdef LODEPNG_COMPILE_PNG
999class State :
public LodePNGState {
1002 State(
const State& other);
1004 State& operator=(
const State& other);
1007#ifdef LODEPNG_COMPILE_DECODER
1009unsigned decode(std::vector<unsigned char>& out,
unsigned& w,
unsigned& h,
1011 const unsigned char* in,
size_t insize);
1012unsigned decode(std::vector<unsigned char>& out,
unsigned& w,
unsigned& h,
1014 const std::vector<unsigned char>& in);
1017#ifdef LODEPNG_COMPILE_ENCODER
1019unsigned encode(std::vector<unsigned char>& out,
1020 const unsigned char* in,
unsigned w,
unsigned h,
1022unsigned encode(std::vector<unsigned char>& out,
1023 const std::vector<unsigned char>& in,
unsigned w,
unsigned h,
1027#ifdef LODEPNG_COMPILE_DISK
1032unsigned load_file(std::vector<unsigned char>& buffer,
const std::string& filename);
1038unsigned save_file(
const std::vector<unsigned char>& buffer,
const std::string& filename);
1042#ifdef LODEPNG_COMPILE_ZLIB
1043#ifdef LODEPNG_COMPILE_DECODER
1045unsigned decompress(std::vector<unsigned char>& out,
const unsigned char* in,
size_t insize,
1046 const LodePNGDecompressSettings& settings = lodepng_default_decompress_settings);
1049unsigned decompress(std::vector<unsigned char>& out,
const std::vector<unsigned char>& in,
1050 const LodePNGDecompressSettings& settings = lodepng_default_decompress_settings);
1053#ifdef LODEPNG_COMPILE_ENCODER
1055unsigned compress(std::vector<unsigned char>& out,
const unsigned char* in,
size_t insize,
1056 const LodePNGCompressSettings& settings = lodepng_default_compress_settings);
1059unsigned compress(std::vector<unsigned char>& out,
const std::vector<unsigned char>& in,
1060 const LodePNGCompressSettings& settings = lodepng_default_compress_settings);