public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/rEFInd] rawhide: Update LodePNG to version 20261006
@ 2026-11-24 19:00 Jan200101
0 siblings, 0 replies; only message in thread
From: Jan200101 @ 2026-11-24 19:00 UTC (permalink / raw)
To: git-commits
A new commit has been pushed.
Repo : rpms/rEFInd
Branch : rawhide
Commit : dab64a1a9f9c7abb5b7749011bdb47bedef2f11f
Author : Jan200101 <sentrycraft123@gmail.com>
Date : 2026-10-21T12:51:45+02:00
Stats : +1861/-1 in 2 file(s)
URL : https://src.fedoraproject.org/rpms/rEFInd/c/dab64a1a9f9c7abb5b7749011bdb47bedef2f11f?branch=rawhide
Log:
Update LodePNG to version 20261006
the prior version was vulnerable to CVE-2026-112020
Resolves rhbz#2558151
---
diff --git a/rEFInd.spec b/rEFInd.spec
index 9c21281..aa9ca16 100644
--- a/rEFInd.spec
+++ b/rEFInd.spec
@@ -27,7 +27,7 @@ Linux kernels that provide EFI stub support.
Name: rEFInd
Version: 0.14.2
-Release: 6%{?dist}
+Release: 7%{?dist}
Summary: User friendly EFI boot manager
License: GPL-3.0-or-later
@@ -43,6 +43,8 @@ Patch1: detect-efi-size.patch
Patch2: fix-aarch64-efi-build.patch
# Replaces outdated objcopy target option
Patch3: fix-target-option.patch
+# Update LodePNG to a version not vulnerable to CVE-2026-112020
+Patch4: update-lodepng.patch
ExclusiveArch: %{efi}
# rEFInd doesn't work on 32-bit arm
@@ -173,6 +175,9 @@ echo "no need to install this update in the ESP." >> READM
%changelog
+* Wed Oct 21 2026 Jan200101 <sentrycraft123@gmail.com> - 0.14.2-7
+- Update LodePNG to version 20261006
+
* Thu Jul 16 2026 Fedora Release Engineering <releng@fedoraproject.org> - 0.14.2-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_45_Mass_Rebuild
diff --git a/update-lodepng.patch b/update-lodepng.patch
new file mode 100644
index 0000000..5fc7ac9
--- /dev/null
+++ b/update-lodepng.patch
@@ -0,0 +1,1855 @@
+From 02c0d35b95033d47301c760b6954aa0b0205cf2a Mon Sep 17 00:00:00 2001
+From: Jan200101 <sentrycraft123@gmail.com>
+Date: Wed, 21 Oct 2026 11:42:12 +0200
+Subject: [PATCH] Update LodePNG to version 20261006
+
+---
+ libeg/lodepng.c | 720 +++++++++++++++++++++++++++++++++---------------
+ libeg/lodepng.h | 225 ++++++++++-----
+ 2 files changed, 655 insertions(+), 290 deletions(-)
+
+diff --git a/libeg/lodepng.c b/libeg/lodepng.c
+index 4afbb54..4915ed7 100644
+--- a/libeg/lodepng.c
++++ b/libeg/lodepng.c
+@@ -1,7 +1,7 @@
+ /*
+-LodePNG version 20230410
++LodePNG version 20261006
+
+-Copyright (c) 2005-2023 Lode Vandevenne
++Copyright (c) 2005-2026 Lode Vandevenne
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+@@ -44,7 +44,7 @@ Rename this file to lodepng.cpp to use it for C++, or to lodepng.c to use it for
+ #pragma warning( disable : 4996 ) /*VS does not like fopen, but fopen_s is not standard C so unusable here*/
+ #endif /*_MSC_VER */
+
+-const char* LODEPNG_VERSION_STRING = "20230410";
++const char* LODEPNG_VERSION_STRING = "20261006";
+
+ /*
+ This source file is divided into the following large parts. The code sections
+@@ -141,32 +141,40 @@ static size_t lodepng_strlen(const char* a) {
+ #define LODEPNG_MAX(a, b) (((a) > (b)) ? (a) : (b))
+ #define LODEPNG_MIN(a, b) (((a) < (b)) ? (a) : (b))
+
+-#if defined(LODEPNG_COMPILE_PNG) || defined(LODEPNG_COMPILE_DECODER)
+ /* Safely check if adding two integers will overflow (no undefined
+-behavior, compiler removing the code, etc...) and output result. */
++behavior, compiler removing the code, etc...) and output result.
++Returns 1 if it overflows, 0 if ok */
+ static int lodepng_addofl(size_t a, size_t b, size_t* result) {
+ *result = a + b; /* Unsigned addition is well defined and safe in C90 */
+ return *result < a;
+ }
+-#endif /*defined(LODEPNG_COMPILE_PNG) || defined(LODEPNG_COMPILE_DECODER)*/
+
+-#ifdef LODEPNG_COMPILE_DECODER
++#if defined(LODEPNG_COMPILE_ENCODER) || defined(LODEPNG_COMPILE_ZLIB)
++/* Safely check if adding two integers overflows (without returning result).
++Returns 1 if it overflows, 0 if ok */
++static int lodepng_addofls(size_t a, size_t b) {
++ size_t result = a + b;
++ return result < a;
++}
++#endif /*defined(LODEPNG_COMPILE_ENCODER) || defined(LODEPNG_COMPILE_ZLIB)*/
++
++#if defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ZLIB)
+ /* Safely check if multiplying two integers will overflow (no undefined
+ behavior, compiler removing the code, etc...) and output result. */
+ static int lodepng_mulofl(size_t a, size_t b, size_t* result) {
+ *result = a * b; /* Unsigned multiplication is well defined and safe in C90 */
+ return (a != 0 && *result / a != b);
+ }
++#endif /*defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ZLIB)*/
+
+-#ifdef LODEPNG_COMPILE_ZLIB
++#if defined(LODEPNG_COMPILE_DECODER) && defined(LODEPNG_COMPILE_ZLIB)
+ /* Safely check if a + b > c, even if overflow could happen. */
+ static int lodepng_gtofl(size_t a, size_t b, size_t c) {
+ size_t d;
+ if(lodepng_addofl(a, b, &d)) return 1;
+ return d > c;
+ }
+-#endif /*LODEPNG_COMPILE_ZLIB*/
+-#endif /*LODEPNG_COMPILE_DECODER*/
++#endif /*defined(LODEPNG_COMPILE_DECODER) && defined(LODEPNG_COMPILE_ZLIB)*/
+
+
+ /*
+@@ -192,8 +200,8 @@ Example: if(!uivector_resize(&lz77_encoded, datasize)) ERROR_BREAK(83);
+
+ /*Try the code, if it returns error, also return the error.*/
+ #define CERROR_TRY_RETURN(call){\
+- unsigned error = call;\
+- if(error) return error;\
++ unsigned error_ = call;\
++ if(error_) return error_;\
+ }
+
+ /*Set error var to the error code, and return from the void function.*/
+@@ -228,10 +236,13 @@ static void uivector_cleanup(void* p) {
+
+ /*returns 1 if success, 0 if failure ==> nothing done*/
+ static unsigned uivector_resize(uivector* p, size_t size) {
+- size_t allocsize = size * sizeof(unsigned);
++ size_t allocsize;
++ if(lodepng_mulofl(size, sizeof(unsigned), &allocsize)) return 0;
+ if(allocsize > p->allocsize) {
+- size_t newsize = allocsize + (p->allocsize >> 1u);
+- void* data = lodepng_realloc(p->data, newsize);
++ size_t newsize;
++ void* data;
++ if(lodepng_addofl(allocsize, p->allocsize >> 1u, &newsize)) return 0;
++ data = lodepng_realloc(p->data, newsize);
+ if(data) {
+ p->allocsize = newsize;
+ p->data = (unsigned*)data;
+@@ -249,7 +260,7 @@ static void uivector_init(uivector* p) {
+
+ /*returns 1 if success, 0 if failure ==> nothing done*/
+ static unsigned uivector_push_back(uivector* p, unsigned c) {
+- if(!uivector_resize(p, p->size + 1)) return 0;
++ if(lodepng_addofls(p->size, 1u) || !uivector_resize(p, p->size + 1u)) return 0;
+ p->data[p->size - 1] = c;
+ return 1;
+ }
+@@ -268,8 +279,10 @@ typedef struct ucvector {
+ /*returns 1 if success, 0 if failure ==> nothing done*/
+ static unsigned ucvector_reserve(ucvector* p, size_t size) {
+ if(size > p->allocsize) {
+- size_t newsize = size + (p->allocsize >> 1u);
+- void* data = lodepng_realloc(p->data, newsize);
++ size_t newsize;
++ void* data;
++ if(lodepng_addofl(size, p->allocsize >> 1u, &newsize)) return 0;
++ data = lodepng_realloc(p->data, newsize);
+ if(data) {
+ p->allocsize = newsize;
+ p->data = (unsigned char*)data;
+@@ -297,12 +310,6 @@ static ucvector ucvector_init(unsigned char* buffer, size_t size) {
+ #ifdef LODEPNG_COMPILE_PNG
+ #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
+
+-/*free string pointer and set it to NULL*/
+-static void string_cleanup(char** out) {
+- lodepng_free(*out);
+- *out = NULL;
+-}
+-
+ /*also appends null termination character*/
+ static char* alloc_string_sized(const char* in, size_t insize) {
+ char* out = (char*)lodepng_malloc(insize + 1);
+@@ -346,54 +353,39 @@ static void lodepng_set32bitInt(unsigned char* buffer, unsigned value) {
+ #ifdef LODEPNG_COMPILE_DISK
+
+ /* returns negative value on error. This should be pure C compatible, so no fstat. */
+-static long lodepng_filesize(const char* filename) {
+- FILE* file;
++static long lodepng_filesize(FILE* file) {
+ long size;
+- file = fopen(filename, "rb");
+- if(!file) return -1;
+-
+- if(fseek(file, 0, SEEK_END) != 0) {
+- fclose(file);
+- return -1;
+- }
+-
++ if(fseek(file, 0, SEEK_END) != 0) return -1;
+ size = ftell(file);
+ /* It may give LONG_MAX as directory size, this is invalid for us. */
+- if(size == LONG_MAX) size = -1;
+-
+- fclose(file);
++ if(size == LONG_MAX) return -1;
++ if(fseek(file, 0, SEEK_SET) != 0) return -1;
+ return size;
+ }
+
+-/* load file into buffer that already has the correct allocated size. Returns error code.*/
+-static unsigned lodepng_buffer_file(unsigned char* out, size_t size, const char* filename) {
+- FILE* file;
+- size_t readsize;
+- file = fopen(filename, "rb");
+- if(!file) return 78;
+-
+- readsize = fread(out, 1, size, file);
+- fclose(file);
+-
+- if(readsize != size) return 78;
+- return 0;
+-}
+-
+-unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename) {
+- long size = lodepng_filesize(filename);
++/* Allocates the output buffer to the file size and reads the file into it. Returns error code.*/
++static unsigned lodepng_load_file_(unsigned char** out, size_t* outsize, FILE* file) {
++ long size = lodepng_filesize(file);
+ if(size < 0) return 78;
+ *outsize = (size_t)size;
+-
+ *out = (unsigned char*)lodepng_malloc((size_t)size);
+ if(!(*out) && size > 0) return 83; /*the above malloc failed*/
++ if(fread(*out, 1, *outsize, file) != *outsize) return 78;
++ return 0; /*ok*/
++}
+
+- return lodepng_buffer_file(*out, (size_t)size, filename);
++unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename) {
++ unsigned error;
++ FILE* file = fopen(filename, "rb");
++ if(!file) return 78;
++ error = lodepng_load_file_(out, outsize, file);
++ fclose(file);
++ return error;
+ }
+
+ /*write given buffer to the file, overwriting the file, it doesn't append to it.*/
+ unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename) {
+- FILE* file;
+- file = fopen(filename, "wb" );
++ FILE* file = fopen(filename, "wb" );
+ if(!file) return 79;
+ fwrite(buffer, 1, buffersize, file);
+ fclose(file);
+@@ -425,7 +417,7 @@ static void LodePNGBitWriter_init(LodePNGBitWriter* writer, ucvector* data) {
+ #define WRITEBIT(writer, bit){\
+ /* append new byte */\
+ if(((writer->bp) & 7u) == 0) {\
+- if(!ucvector_resize(writer->data, writer->data->size + 1)) return;\
++ if(lodepng_addofls(writer->data->size, 1) || !ucvector_resize(writer->data, writer->data->size + 1)) return;\
+ writer->data->data[writer->data->size - 1] = 0;\
+ }\
+ (writer->data->data[writer->data->size - 1]) |= (bit << ((writer->bp) & 7u));\
+@@ -1243,7 +1235,7 @@ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
+ const size_t reserved_size = 260; /* must be at least 258 for max length, and a few extra for adding a few extra literals */
+ int done = 0;
+
+- if(!ucvector_reserve(out, out->size + reserved_size)) return 83; /*alloc fail*/
++ if(lodepng_addofls(out->size, reserved_size) || !ucvector_reserve(out, out->size + reserved_size)) return 83; /*alloc fail*/
+
+ HuffmanTree_init(&tree_ll);
+ HuffmanTree_init(&tree_d);
+@@ -1323,7 +1315,7 @@ static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
+ ERROR_BREAK(16); /*error: tried to read disallowed huffman symbol*/
+ }
+ if(out->allocsize - out->size < reserved_size) {
+- if(!ucvector_reserve(out, out->size + reserved_size)) ERROR_BREAK(83); /*alloc fail*/
++ if(lodepng_addofls(out->size, reserved_size) || !ucvector_reserve(out, out->size + reserved_size)) ERROR_BREAK(83); /*alloc fail*/
+ }
+ /*check if any of the ensureBits above went out of bounds*/
+ if(reader->bp > reader->bitsize) {
+@@ -1362,12 +1354,12 @@ static unsigned inflateNoCompression(ucvector* out, LodePNGBitReader* reader,
+ return 21; /*error: NLEN is not one's complement of LEN*/
+ }
+
+- if(!ucvector_resize(out, out->size + LEN)) return 83; /*alloc fail*/
++ if(lodepng_addofls(out->size, LEN) || !ucvector_resize(out, out->size + LEN)) return 83; /*alloc fail*/
+
+ /*read the literal data: LEN bytes are now stored in the out buffer*/
+ if(bytepos + LEN > size) return 23; /*error: reading outside of in buffer*/
+
+- /*out->data can be NULL (when LEN is zero), and arithmetics on NULL ptr is undefined*/
++ /*out->data can be NULL (when LEN is zero), and arithmetic on NULL ptr is undefined*/
+ if (LEN) {
+ lodepng_memcpy(out->data + out->size - LEN, reader->data + bytepos, LEN);
+ bytepos += LEN;
+@@ -1471,7 +1463,7 @@ static void addLengthDistance(uivector* values, size_t length, size_t distance)
+
+ size_t pos = values->size;
+ /*TODO: return error when this fails (out of memory)*/
+- unsigned ok = uivector_resize(values, values->size + 4);
++ unsigned ok = !lodepng_addofls(values->size, 4) && uivector_resize(values, values->size + 4);
+ if(ok) {
+ values->data[pos + 0] = length_code + FIRST_LENGTH_CODE_INDEX;
+ values->data[pos + 1] = extra_length;
+@@ -1740,7 +1732,7 @@ static unsigned deflateNoCompression(ucvector* out, const unsigned char* data, s
+ 2 bytes LEN, 2 bytes NLEN, LEN bytes literal DATA*/
+
+ size_t i, numdeflateblocks = (datasize + 65534u) / 65535u;
+- unsigned datapos = 0;
++ size_t datapos = 0;
+ for(i = 0; i != numdeflateblocks; ++i) {
+ unsigned BFINAL, BTYPE, LEN, NLEN;
+ unsigned char firstbyte;
+@@ -1750,10 +1742,10 @@ static unsigned deflateNoCompression(ucvector* out, const unsigned char* data, s
+ BTYPE = 0;
+
+ LEN = 65535;
+- if(datasize - datapos < 65535u) LEN = (unsigned)datasize - datapos;
++ if(datasize - datapos < 65535u) LEN = (unsigned)datasize - (unsigned)datapos;
+ NLEN = 65535 - LEN;
+
+- if(!ucvector_resize(out, out->size + LEN + 5)) return 83; /*alloc fail*/
++ if(lodepng_addofls(out->size, LEN + 5) || !ucvector_resize(out, out->size + LEN + 5)) return 83; /*alloc fail*/
+
+ firstbyte = (unsigned char)(BFINAL + ((BTYPE & 1u) << 1u) + ((BTYPE & 2u) << 1u));
+ out->data[pos + 0] = firstbyte;
+@@ -2134,14 +2126,14 @@ static unsigned deflate(unsigned char** out, size_t* outsize,
+ /* / Adler32 / */
+ /* ////////////////////////////////////////////////////////////////////////// */
+
+-static unsigned update_adler32(unsigned adler, const unsigned char* data, unsigned len) {
++static unsigned update_adler32(unsigned adler, const unsigned char* data, size_t len) {
+ unsigned s1 = adler & 0xffffu;
+ unsigned s2 = (adler >> 16u) & 0xffffu;
+
+ while(len != 0u) {
+- unsigned i;
++ size_t i;
+ /*at least 5552 sums can be done before the sums overflow, saving a lot of module divisions*/
+- unsigned amount = len > 5552u ? 5552u : len;
++ size_t amount = len > 5552u ? 5552u : len;
+ len -= amount;
+ for(i = 0; i != amount; ++i) {
+ s1 += (*data++);
+@@ -2155,7 +2147,7 @@ static unsigned update_adler32(unsigned adler, const unsigned char* data, unsign
+ }
+
+ /*Return the adler32 of the bytes data[0..len-1]*/
+-static unsigned adler32(const unsigned char* data, unsigned len) {
++static unsigned adler32(const unsigned char* data, size_t len) {
+ return update_adler32(1u, data, len);
+ }
+
+@@ -2199,7 +2191,7 @@ static unsigned lodepng_zlib_decompressv(ucvector* out,
+
+ if(!settings->ignore_adler32) {
+ unsigned ADLER32 = lodepng_read32bitInt(&in[insize - 4]);
+- unsigned checksum = adler32(out->data, (unsigned)(out->size));
++ unsigned checksum = adler32(out->data, out->size);
+ if(checksum != ADLER32) return 58; /*error, adler checksum not correct, data must be corrupted*/
+ }
+
+@@ -2232,7 +2224,7 @@ static unsigned zlib_decompress(unsigned char** out, size_t* outsize, size_t exp
+ ucvector v = ucvector_init(*out, *outsize);
+ if(expected_size) {
+ /*reserve the memory to avoid intermediate reallocations*/
+- ucvector_resize(&v, *outsize + expected_size);
++ if(lodepng_addofls(*outsize, expected_size) || !ucvector_resize(&v, *outsize + expected_size)) return 83; /*alloc faile*/
+ v.size = *outsize;
+ }
+ error = lodepng_zlib_decompressv(&v, in, insize, settings);
+@@ -2264,7 +2256,7 @@ unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, const unsig
+ }
+
+ if(!error) {
+- unsigned ADLER32 = adler32(in, (unsigned)insize);
++ unsigned ADLER32 = adler32(in, insize);
+ /*zlib data: 1 byte CMF (CM+CINFO), 1 byte FLG, deflate data, 4 byte ADLER32 checksum of the Decompressed data*/
+ unsigned CMF = 120; /*0b01111000: CM 8, CINFO 7. With CINFO 7, any window size up to 32768 can be used.*/
+ unsigned FLEVEL = 0;
+@@ -2748,11 +2740,29 @@ unsigned char lodepng_chunk_type_equals(const unsigned char* chunk, const char*
+ return (chunk[4] == type[0] && chunk[5] == type[1] && chunk[6] == type[2] && chunk[7] == type[3]);
+ }
+
++/* chunk type name must exist only out of alphabetic characters a-z or A-Z */
++static unsigned char lodepng_chunk_type_name_valid(const unsigned char* chunk) {
++ unsigned i;
++ for(i = 0; i != 4; ++i) {
++ char c = (char)chunk[4 + i];
++ if(!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))) {
++ return 0; /* not valid */
++ }
++ }
++ return 1; /* valid */
++}
++
+ unsigned char lodepng_chunk_ancillary(const unsigned char* chunk) {
+ return((chunk[4] & 32) != 0);
+ }
+
+ unsigned char lodepng_chunk_private(const unsigned char* chunk) {
++ return((chunk[5] & 32) != 0);
++}
++
++/* this is an error if it is reserved: the third character must be uppercase in the PNG standard,
++lowercasing this character is reserved for possible future extension by the spec*/
++static unsigned char lodepng_chunk_reserved(const unsigned char* chunk) {
+ return((chunk[6] & 32) != 0);
+ }
+
+@@ -2770,17 +2780,17 @@ const unsigned char* lodepng_chunk_data_const(const unsigned char* chunk) {
+
+ unsigned lodepng_chunk_check_crc(const unsigned char* chunk) {
+ unsigned length = lodepng_chunk_length(chunk);
+- unsigned CRC = lodepng_read32bitInt(&chunk[length + 8]);
++ unsigned crc = lodepng_read32bitInt(&chunk[length + 8]);
+ /*the CRC is taken of the data and the 4 chunk type letters, not the length*/
+ unsigned checksum = lodepng_crc32(&chunk[4], length + 4);
+- if(CRC != checksum) return 1;
++ if(crc != checksum) return 1;
+ else return 0;
+ }
+
+ void lodepng_chunk_generate_crc(unsigned char* chunk) {
+ unsigned length = lodepng_chunk_length(chunk);
+- unsigned CRC = lodepng_crc32(&chunk[4], length + 4);
+- lodepng_set32bitInt(chunk + 8 + length, CRC);
++ unsigned crc = lodepng_crc32(&chunk[4], length + 4);
++ lodepng_set32bitInt(chunk + 8 + length, crc);
+ }
+
+ unsigned char* lodepng_chunk_next(unsigned char* chunk, unsigned char* end) {
+@@ -2834,6 +2844,13 @@ unsigned lodepng_chunk_append(unsigned char** out, size_t* outsize, const unsign
+ size_t total_chunk_length, new_length;
+ unsigned char *chunk_start, *new_buffer;
+
++ if(!lodepng_chunk_type_name_valid(chunk)) {
++ return 121; /* invalid chunk type name */
++ }
++ if(lodepng_chunk_reserved(chunk)) {
++ return 122; /* invalid third lowercase character */
++ }
++
+ if(lodepng_addofl(lodepng_chunk_length(chunk), 12, &total_chunk_length)) return 77;
+ if(lodepng_addofl(*outsize, total_chunk_length, &new_length)) return 77;
+
+@@ -3152,8 +3169,8 @@ static void LodePNGText_init(LodePNGInfo* info) {
+ static void LodePNGText_cleanup(LodePNGInfo* info) {
+ size_t i;
+ for(i = 0; i != info->text_num; ++i) {
+- string_cleanup(&info->text_keys[i]);
+- string_cleanup(&info->text_strings[i]);
++ lodepng_free(info->text_keys[i]);
++ lodepng_free(info->text_strings[i]);
+ }
+ lodepng_free(info->text_keys);
+ lodepng_free(info->text_strings);
+@@ -3193,6 +3210,8 @@ unsigned lodepng_add_text(LodePNGInfo* info, const char* key, const char* str) {
+
+ void lodepng_clear_text(LodePNGInfo* info) {
+ LodePNGText_cleanup(info);
++ /*cleanup only deconstructs, need to init again to set appropriate pointers to NULL*/
++ LodePNGText_init(info);
+ }
+
+ /******************************************************************************/
+@@ -3208,10 +3227,10 @@ static void LodePNGIText_init(LodePNGInfo* info) {
+ static void LodePNGIText_cleanup(LodePNGInfo* info) {
+ size_t i;
+ for(i = 0; i != info->itext_num; ++i) {
+- string_cleanup(&info->itext_keys[i]);
+- string_cleanup(&info->itext_langtags[i]);
+- string_cleanup(&info->itext_transkeys[i]);
+- string_cleanup(&info->itext_strings[i]);
++ lodepng_free(info->itext_keys[i]);
++ lodepng_free(info->itext_langtags[i]);
++ lodepng_free(info->itext_transkeys[i]);
++ lodepng_free(info->itext_strings[i]);
+ }
+ lodepng_free(info->itext_keys);
+ lodepng_free(info->itext_langtags);
+@@ -3235,6 +3254,8 @@ static unsigned LodePNGIText_copy(LodePNGInfo* dest, const LodePNGInfo* source)
+
+ void lodepng_clear_itext(LodePNGInfo* info) {
+ LodePNGIText_cleanup(info);
++ /*cleanup only deconstructs, need to init again to set appropriate pointers to NULL*/
++ LodePNGIText_init(info);
+ }
+
+ static unsigned lodepng_add_itext_sized(LodePNGInfo* info, const char* key, const char* langtag,
+@@ -3266,34 +3287,62 @@ unsigned lodepng_add_itext(LodePNGInfo* info, const char* key, const char* langt
+ return lodepng_add_itext_sized(info, key, langtag, transkey, str, lodepng_strlen(str));
+ }
+
+-/* same as set but does not delete */
+-static unsigned lodepng_assign_icc(LodePNGInfo* info, const char* name, const unsigned char* profile, unsigned profile_size) {
+- if(profile_size == 0) return 100; /*invalid ICC profile size*/
++unsigned lodepng_set_icc(LodePNGInfo* info, const char* name, const unsigned char* profile, unsigned profile_size) {
++ if(info->iccp_defined) lodepng_clear_icc(info);
++
++ if(profile_size == 0) return 123; /*invalid ICC profile size*/
+
+ info->iccp_name = alloc_string(name);
+- info->iccp_profile = (unsigned char*)lodepng_malloc(profile_size);
++ if(!info->iccp_name) return 83; /*alloc fail*/
+
+- if(!info->iccp_name || !info->iccp_profile) return 83; /*alloc fail*/
++ info->iccp_profile = (unsigned char*)lodepng_malloc(profile_size);
++ if(!info->iccp_profile) {
++ lodepng_free(info->iccp_name);
++ return 83; /*alloc fail*/
++ }
+
+ lodepng_memcpy(info->iccp_profile, profile, profile_size);
+ info->iccp_profile_size = profile_size;
++ info->iccp_defined = 1;
+
+ return 0; /*ok*/
+ }
+
+-unsigned lodepng_set_icc(LodePNGInfo* info, const char* name, const unsigned char* profile, unsigned profile_size) {
+- if(info->iccp_name) lodepng_clear_icc(info);
+- info->iccp_defined = 1;
+-
+- return lodepng_assign_icc(info, name, profile, profile_size);
++static void lodepng_init_icc(LodePNGInfo* info) {
++ info->iccp_defined = 0;
++ info->iccp_name = NULL;
++ info->iccp_profile = NULL;
++ info->iccp_profile_size = 0;
+ }
+
+ void lodepng_clear_icc(LodePNGInfo* info) {
+- string_cleanup(&info->iccp_name);
++ lodepng_free(info->iccp_name);
+ lodepng_free(info->iccp_profile);
+- info->iccp_profile = NULL;
+- info->iccp_profile_size = 0;
+- info->iccp_defined = 0;
++ lodepng_init_icc(info);
++}
++
++unsigned lodepng_set_exif(LodePNGInfo* info, const unsigned char* exif, unsigned exif_size) {
++ if(info->exif_defined) lodepng_clear_exif(info);
++ info->exif = (unsigned char*)lodepng_malloc(exif_size);
++
++ if(!info->exif) return 83; /*alloc fail*/
++
++ lodepng_memcpy(info->exif, exif, exif_size);
++ info->exif_size = exif_size;
++ info->exif_defined = 1;
++
++ return 0; /*ok*/
++}
++
++static void lodepng_init_exif(LodePNGInfo* info) {
++ info->exif_defined = 0;
++ info->exif = NULL;
++ info->exif_size = 0;
++}
++
++void lodepng_clear_exif(LodePNGInfo* info) {
++ lodepng_free(info->exif);
++ lodepng_init_exif(info);
+ }
+ #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
+
+@@ -3308,6 +3357,8 @@ void lodepng_info_init(LodePNGInfo* info) {
+
+ LodePNGText_init(info);
+ LodePNGIText_init(info);
++ lodepng_init_icc(info);
++ lodepng_init_exif(info);
+
+ info->time_defined = 0;
+ info->phys_defined = 0;
+@@ -3315,9 +3366,25 @@ void lodepng_info_init(LodePNGInfo* info) {
+ info->gama_defined = 0;
+ info->chrm_defined = 0;
+ info->srgb_defined = 0;
+- info->iccp_defined = 0;
+- info->iccp_name = NULL;
+- info->iccp_profile = NULL;
++ info->cicp_defined = 0;
++ info->cicp_color_primaries = 0;
++ info->cicp_transfer_function = 0;
++ info->cicp_matrix_coefficients = 0;
++ info->cicp_video_full_range_flag = 0;
++ info->mdcv_defined = 0;
++ info->mdcv_red_x = 0;
++ info->mdcv_red_y = 0;
++ info->mdcv_green_x = 0;
++ info->mdcv_green_y = 0;
++ info->mdcv_blue_x = 0;
++ info->mdcv_blue_y = 0;
++ info->mdcv_white_x = 0;
++ info->mdcv_white_y = 0;
++ info->mdcv_max_luminance = 0;
++ info->mdcv_min_luminance = 0;
++ info->clli_defined = 0;
++ info->clli_max_cll = 0;
++ info->clli_max_fall = 0;
+
+ info->sbit_defined = 0;
+ info->sbit_r = info->sbit_g = info->sbit_b = info->sbit_a = 0;
+@@ -3333,6 +3400,7 @@ void lodepng_info_cleanup(LodePNGInfo* info) {
+ LodePNGIText_cleanup(info);
+
+ lodepng_clear_icc(info);
++ lodepng_clear_exif(info);
+
+ LodePNGUnknownChunks_cleanup(info);
+ #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
+@@ -3341,19 +3409,30 @@ void lodepng_info_cleanup(LodePNGInfo* info) {
+ unsigned lodepng_info_copy(LodePNGInfo* dest, const LodePNGInfo* source) {
+ lodepng_info_cleanup(dest);
+ lodepng_memcpy(dest, source, sizeof(LodePNGInfo));
++
++ /*ensure to initialize all fields pointing to allocated data to NULL first*/
+ lodepng_color_mode_init(&dest->color);
+- CERROR_TRY_RETURN(lodepng_color_mode_copy(&dest->color, &source->color));
++#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
++ LodePNGText_init(dest);
++ LodePNGIText_init(dest);
++ lodepng_init_icc(dest);
++ lodepng_init_exif(dest);
++ LodePNGUnknownChunks_init(dest);
++#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
+
++ CERROR_TRY_RETURN(lodepng_color_mode_copy(&dest->color, &source->color));
+ #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
+ CERROR_TRY_RETURN(LodePNGText_copy(dest, source));
+ CERROR_TRY_RETURN(LodePNGIText_copy(dest, source));
+ if(source->iccp_defined) {
+- CERROR_TRY_RETURN(lodepng_assign_icc(dest, source->iccp_name, source->iccp_profile, source->iccp_profile_size));
++ CERROR_TRY_RETURN(lodepng_set_icc(dest, source->iccp_name, source->iccp_profile, source->iccp_profile_size));
++ }
++ if(source->exif_defined) {
++ CERROR_TRY_RETURN(lodepng_set_exif(dest, source->exif, source->exif_size));
+ }
+-
+- LodePNGUnknownChunks_init(dest);
+ CERROR_TRY_RETURN(LodePNGUnknownChunks_copy(dest, source));
+ #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
++
+ return 0;
+ }
+
+@@ -4062,9 +4141,18 @@ unsigned lodepng_compute_color_stats(LodePNGColorStats* stats,
+ }
+ } else /* < 16-bit */ {
+ unsigned char r = 0, g = 0, b = 0, a = 0;
++ unsigned char pr = 0, pg = 0, pb = 0, pa = 0;
+ for(i = 0; i != numpixels; ++i) {
+ getPixelColorRGBA8(&r, &g, &b, &a, in, i, mode_in);
+
++ /*skip if color same as before, this speeds up large non-photographic
++ images with many same colors by avoiding 'color_tree_has' below */
++ if(i != 0 && r == pr && g == pg && b == pb && a == pa) continue;
++ pr = r;
++ pg = g;
++ pb = b;
++ pa = a;
++
+ if(!bits_done && stats->bits < 8) {
+ /*only r is checked, < 8 bits is only relevant for grayscale*/
+ unsigned bits = getValueRequiredBits(r);
+@@ -4358,9 +4446,9 @@ unsigned lodepng_inspect(unsigned* w, unsigned* h, LodePNGState* state,
+ if(info->interlace_method > 1) CERROR_RETURN_ERROR(state->error, 34);
+
+ if(!state->decoder.ignore_crc) {
+- unsigned CRC = lodepng_read32bitInt(&in[29]);
++ unsigned crc = lodepng_read32bitInt(&in[29]);
+ unsigned checksum = lodepng_crc32(&in[12], 17);
+- if(CRC != checksum) {
++ if(crc != checksum) {
+ CERROR_RETURN_ERROR(state->error, 57); /*invalid CRC*/
+ }
+ }
+@@ -4952,7 +5040,7 @@ static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecoderSettings*
+ if(!error) error = lodepng_add_itext_sized(info, key, langtag, transkey, (char*)str, size);
+ lodepng_free(str);
+ } else {
+- error = lodepng_add_itext_sized(info, key, langtag, transkey, (char*)(data + begin), length);
++ error = lodepng_add_itext_sized(info, key, langtag, transkey, (const char*)(data + begin), length);
+ }
+
+ break;
+@@ -5034,8 +5122,7 @@ static unsigned readChunk_iCCP(LodePNGInfo* info, const LodePNGDecoderSettings*
+
+ unsigned length, string2_begin;
+
+- info->iccp_defined = 1;
+- if(info->iccp_name) lodepng_clear_icc(info);
++ if(info->iccp_defined) lodepng_clear_icc(info);
+
+ for(length = 0; length < chunkLength && data[length] != 0; ++length) ;
+ if(length + 2 >= chunkLength) return 75; /*no null termination, corrupt?*/
+@@ -5057,13 +5144,61 @@ static unsigned readChunk_iCCP(LodePNGInfo* info, const LodePNGDecoderSettings*
+ error = zlib_decompress(&info->iccp_profile, &size, 0,
+ &data[string2_begin],
+ length, &zlibsettings);
+- /*error: ICC profile larger than decoder->max_icc_size*/
++ /*error: ICC profile larger than decoder->max_icc_size*/
+ if(error && size > zlibsettings.max_output_size) error = 113;
+ info->iccp_profile_size = (unsigned)size;
+- if(!error && !info->iccp_profile_size) error = 100; /*invalid ICC profile size*/
++ if(!error && !info->iccp_profile_size) error = 123; /*invalid ICC profile size*/
++
++ if(!error) info->iccp_defined = 1;
+ return error;
+ }
+
++static unsigned readChunk_cICP(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) {
++ if(chunkLength != 4) return 117; /*invalid cICP chunk size*/
++
++ info->cicp_defined = 1;
++ /* No error checking for value ranges is done here, that is up to a CICP
++ handling library, not the PNG decoding. Just pass on the metadata. */
++ info->cicp_color_primaries = data[0];
++ info->cicp_transfer_function = data[1];
++ info->cicp_matrix_coefficients = data[2];
++ info->cicp_video_full_range_flag = data[3];
++
++ return 0; /* OK */
++}
++
++static unsigned readChunk_mDCV(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) {
++ if(chunkLength != 24) return 119; /*invalid mDCV chunk size*/
++
++ info->mdcv_defined = 1;
++ info->mdcv_red_x = 256u * data[0] + data[1];
++ info->mdcv_red_y = 256u * data[2] + data[3];
++ info->mdcv_green_x = 256u * data[4] + data[5];
++ info->mdcv_green_y = 256u * data[6] + data[7];
++ info->mdcv_blue_x = 256u * data[8] + data[9];
++ info->mdcv_blue_y = 256u * data[10] + data[11];
++ info->mdcv_white_x = 256u * data[12] + data[13];
++ info->mdcv_white_y = 256u * data[14] + data[15];
++ info->mdcv_max_luminance = 16777216u * data[16] + 65536u * data[17] + 256u * data[18] + data[19];
++ info->mdcv_min_luminance = 16777216u * data[20] + 65536u * data[21] + 256u * data[22] + data[23];
++
++ return 0; /* OK */
++}
++
++static unsigned readChunk_cLLI(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) {
++ if(chunkLength != 8) return 120; /*invalid cLLI chunk size*/
++
++ info->clli_defined = 1;
++ info->clli_max_cll = 16777216u * data[0] + 65536u * data[1] + 256u * data[2] + data[3];
++ info->clli_max_fall = 16777216u * data[4] + 65536u * data[5] + 256u * data[6] + data[7];
++
++ return 0; /* OK */
++}
++
++static unsigned readChunk_eXIf(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) {
++ return lodepng_set_exif(info, data, (unsigned)chunkLength);
++}
++
+ /*significant bits chunk (sBIT)*/
+ static unsigned readChunk_sBIT(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) {
+ unsigned bitdepth = (info->color.colortype == LCT_PALETTE) ? 8 : info->color.bitdepth;
+@@ -5145,6 +5280,14 @@ unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos,
+ error = readChunk_sRGB(&state->info_png, data, chunkLength);
+ } else if(lodepng_chunk_type_equals(chunk, "iCCP")) {
+ error = readChunk_iCCP(&state->info_png, &state->decoder, data, chunkLength);
++ } else if(lodepng_chunk_type_equals(chunk, "cICP")) {
++ error = readChunk_cICP(&state->info_png, data, chunkLength);
++ } else if(lodepng_chunk_type_equals(chunk, "mDCV")) {
++ error = readChunk_mDCV(&state->info_png, data, chunkLength);
++ } else if(lodepng_chunk_type_equals(chunk, "cLLI")) {
++ error = readChunk_cLLI(&state->info_png, data, chunkLength);
++ } else if(lodepng_chunk_type_equals(chunk, "eXIf")) {
++ error = readChunk_eXIf(&state->info_png, data, chunkLength);
+ } else if(lodepng_chunk_type_equals(chunk, "sBIT")) {
+ error = readChunk_sBIT(&state->info_png, data, chunkLength);
+ #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
+@@ -5292,11 +5435,30 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
+ } else if(lodepng_chunk_type_equals(chunk, "iCCP")) {
+ state->error = readChunk_iCCP(&state->info_png, &state->decoder, data, chunkLength);
+ if(state->error) break;
++ } else if(lodepng_chunk_type_equals(chunk, "cICP")) {
++ state->error = readChunk_cICP(&state->info_png, data, chunkLength);
++ if(state->error) break;
++ } else if(lodepng_chunk_type_equals(chunk, "mDCV")) {
++ state->error = readChunk_mDCV(&state->info_png, data, chunkLength);
++ if(state->error) break;
++ } else if(lodepng_chunk_type_equals(chunk, "cLLI")) {
++ state->error = readChunk_cLLI(&state->info_png, data, chunkLength);
++ if(state->error) break;
++ } else if(lodepng_chunk_type_equals(chunk, "eXIf")) {
++ state->error = readChunk_eXIf(&state->info_png, data, chunkLength);
++ if(state->error) break;
+ } else if(lodepng_chunk_type_equals(chunk, "sBIT")) {
+ state->error = readChunk_sBIT(&state->info_png, data, chunkLength);
+ if(state->error) break;
+ #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
+ } else /*it's not an implemented chunk type, so ignore it: skip over the data*/ {
++ if(!lodepng_chunk_type_name_valid(chunk)) {
++ CERROR_BREAK(state->error, 121); /* invalid chunk type name */
++ }
++ if(lodepng_chunk_reserved(chunk)) {
++ CERROR_BREAK(state->error, 122); /* invalid third lowercase character */
++ }
++
+ /*error: unknown critical chunk (5th bit of first byte of chunk type is 0)*/
+ if(!state->decoder.ignore_critical && !lodepng_chunk_ancillary(chunk)) {
+ CERROR_BREAK(state->error, 69);
+@@ -5480,13 +5642,15 @@ void lodepng_state_cleanup(LodePNGState* state) {
+ lodepng_info_cleanup(&state->info_png);
+ }
+
+-void lodepng_state_copy(LodePNGState* dest, const LodePNGState* source) {
++unsigned lodepng_state_copy(LodePNGState* dest, const LodePNGState* source) {
+ lodepng_state_cleanup(dest);
+ *dest = *source;
+ lodepng_color_mode_init(&dest->info_raw);
+ lodepng_info_init(&dest->info_png);
+- dest->error = lodepng_color_mode_copy(&dest->info_raw, &source->info_raw); if(dest->error) return;
+- dest->error = lodepng_info_copy(&dest->info_png, &source->info_png); if(dest->error) return;
++ dest->error = lodepng_color_mode_copy(&dest->info_raw, &source->info_raw);
++ if(dest->error) return dest->error;
++ dest->error = lodepng_info_copy(&dest->info_png, &source->info_png);
++ return dest->error;
+ }
+
+ #endif /* defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ENCODER) */
+@@ -5502,7 +5666,7 @@ static unsigned writeSignature(ucvector* out) {
+ size_t pos = out->size;
+ const unsigned char signature[] = {137, 80, 78, 71, 13, 10, 26, 10};
+ /*8 bytes PNG signature, aka the magic bytes*/
+- if(!ucvector_resize(out, out->size + 8)) return 83; /*alloc fail*/
++ if(lodepng_addofls(out->size, 8) || !ucvector_resize(out, out->size + 8)) return 83; /*alloc fail*/
+ lodepng_memcpy(out->data + pos, signature, 8);
+ return 0;
+ }
+@@ -5585,14 +5749,23 @@ static unsigned addChunk_tRNS(ucvector* out, const LodePNGColorMode* info) {
+ }
+
+ static unsigned addChunk_IDAT(ucvector* out, const unsigned char* data, size_t datasize,
+- LodePNGCompressSettings* zlibsettings) {
++ const LodePNGCompressSettings* zlibsettings) {
+ unsigned error = 0;
+ unsigned char* zlib = 0;
++ size_t pos = 0;
+ size_t zlibsize = 0;
++ /* max chunk length allowed by the specification is 2147483647 bytes */
++ const size_t max_chunk_length = 2147483647u;
+
+ error = zlib_compress(&zlib, &zlibsize, data, datasize, zlibsettings);
+- if(!error) {
+- error = lodepng_chunk_createv(out, zlibsize, "IDAT", zlib);
++ while(!error) {
++ if(zlibsize - pos > max_chunk_length) {
++ error = lodepng_chunk_createv(out, max_chunk_length, "IDAT", zlib + pos);
++ pos += max_chunk_length;
++ } else {
++ error = lodepng_chunk_createv(out, zlibsize - pos, "IDAT", zlib + pos);
++ break;
++ }
+ }
+ lodepng_free(zlib);
+ return error;
+@@ -5618,7 +5791,7 @@ static unsigned addChunk_tEXt(ucvector* out, const char* keyword, const char* te
+ }
+
+ static unsigned addChunk_zTXt(ucvector* out, const char* keyword, const char* textstring,
+- LodePNGCompressSettings* zlibsettings) {
++ const LodePNGCompressSettings* zlibsettings) {
+ unsigned error = 0;
+ unsigned char* chunk = 0;
+ unsigned char* compressed = 0;
+@@ -5646,7 +5819,7 @@ static unsigned addChunk_zTXt(ucvector* out, const char* keyword, const char* te
+ }
+
+ static unsigned addChunk_iTXt(ucvector* out, unsigned compress, const char* keyword, const char* langtag,
+- const char* transkey, const char* textstring, LodePNGCompressSettings* zlibsettings) {
++ const char* transkey, const char* textstring, const LodePNGCompressSettings* zlibsettings) {
+ unsigned error = 0;
+ unsigned char* chunk = 0;
+ unsigned char* compressed = 0;
+@@ -5763,7 +5936,7 @@ static unsigned addChunk_sRGB(ucvector* out, const LodePNGInfo* info) {
+ return lodepng_chunk_createv(out, 1, "sRGB", &data);
+ }
+
+-static unsigned addChunk_iCCP(ucvector* out, const LodePNGInfo* info, LodePNGCompressSettings* zlibsettings) {
++static unsigned addChunk_iCCP(ucvector* out, const LodePNGInfo* info, const LodePNGCompressSettings* zlibsettings) {
+ unsigned error = 0;
+ unsigned char* chunk = 0;
+ unsigned char* compressed = 0;
+@@ -5789,6 +5962,71 @@ static unsigned addChunk_iCCP(ucvector* out, const LodePNGInfo* info, LodePNGCom
+ return error;
+ }
+
++static unsigned addChunk_cICP(ucvector* out, const LodePNGInfo* info) {
++ unsigned char* chunk;
++ /* Allow up to 255 since they are bytes. The ITU-R-BT.709 spec has a more
++ restricted set of valid values for each field, but that's up to the error
++ handling of a CICP library, not the PNG encoding/decoding, to manage. */
++ if(info->cicp_color_primaries > 255) return 116;
++ if(info->cicp_transfer_function > 255) return 116;
++ if(info->cicp_matrix_coefficients > 255) return 116;
++ if(info->cicp_video_full_range_flag > 255) return 116;
++ CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 4, "cICP"));
++ chunk[8 + 0] = (unsigned char)info->cicp_color_primaries;
++ chunk[8 + 1] = (unsigned char)info->cicp_transfer_function;
++ chunk[8 + 2] = (unsigned char)info->cicp_matrix_coefficients;
++ chunk[8 + 3] = (unsigned char)info->cicp_video_full_range_flag;
++ lodepng_chunk_generate_crc(chunk);
++ return 0;
++}
++
++static unsigned addChunk_mDCV(ucvector* out, const LodePNGInfo* info) {
++ unsigned char* chunk;
++ /* Allow up to 65535 since they are 16-bit ints. */
++ if(info->mdcv_red_x > 65535) return 118;
++ if(info->mdcv_red_y > 65535) return 118;
++ if(info->mdcv_green_x > 65535) return 118;
++ if(info->mdcv_green_y > 65535) return 118;
++ if(info->mdcv_blue_x > 65535) return 118;
++ if(info->mdcv_blue_y > 65535) return 118;
++ if(info->mdcv_white_x > 65535) return 118;
++ if(info->mdcv_white_y > 65535) return 118;
++ CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 24, "mDCV"));
++ chunk[8 + 0] = (unsigned char)((info->mdcv_red_x) >> 8u);
++ chunk[8 + 1] = (unsigned char)(info->mdcv_red_x);
++ chunk[8 + 2] = (unsigned char)((info->mdcv_red_y) >> 8u);
++ chunk[8 + 3] = (unsigned char)(info->mdcv_red_y);
++ chunk[8 + 4] = (unsigned char)((info->mdcv_green_x) >> 8u);
++ chunk[8 + 5] = (unsigned char)(info->mdcv_green_x);
++ chunk[8 + 6] = (unsigned char)((info->mdcv_green_y) >> 8u);
++ chunk[8 + 7] = (unsigned char)(info->mdcv_green_y);
++ chunk[8 + 8] = (unsigned char)((info->mdcv_blue_x) >> 8u);
++ chunk[8 + 9] = (unsigned char)(info->mdcv_blue_x);
++ chunk[8 + 10] = (unsigned char)((info->mdcv_blue_y) >> 8u);
++ chunk[8 + 11] = (unsigned char)(info->mdcv_blue_y);
++ chunk[8 + 12] = (unsigned char)((info->mdcv_white_x) >> 8u);
++ chunk[8 + 13] = (unsigned char)(info->mdcv_white_x);
++ chunk[8 + 14] = (unsigned char)((info->mdcv_white_y) >> 8u);
++ chunk[8 + 15] = (unsigned char)(info->mdcv_white_y);
++ lodepng_set32bitInt(chunk + 8 + 16, info->mdcv_max_luminance);
++ lodepng_set32bitInt(chunk + 8 + 20, info->mdcv_min_luminance);
++ lodepng_chunk_generate_crc(chunk);
++ return 0;
++}
++
++static unsigned addChunk_cLLI(ucvector* out, const LodePNGInfo* info) {
++ unsigned char* chunk;
++ CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 8, "cLLI"));
++ lodepng_set32bitInt(chunk + 8 + 0, info->clli_max_cll);
++ lodepng_set32bitInt(chunk + 8 + 4, info->clli_max_fall);
++ lodepng_chunk_generate_crc(chunk);
++ return 0;
++}
++
++static unsigned addChunk_eXIf(ucvector* out, const LodePNGInfo* info) {
++ return lodepng_chunk_createv(out, info->exif_size, "eXIf", info->exif);
++}
++
+ static unsigned addChunk_sBIT(ucvector* out, const LodePNGInfo* info) {
+ unsigned bitdepth = (info->color.colortype == LCT_PALETTE) ? 8 : info->color.bitdepth;
+ unsigned char* chunk = 0;
+@@ -5911,21 +6149,11 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w,
+ unsigned error = 0;
+ LodePNGFilterStrategy strategy = settings->filter_strategy;
+
+- /*
+- There is a heuristic called the minimum sum of absolute differences heuristic, suggested by the PNG standard:
+- * If the image type is Palette, or the bit depth is smaller than 8, then do not filter the image (i.e.
+- use fixed filtering, with the filter None).
+- * (The other case) If the image type is Grayscale or RGB (with or without Alpha), and the bit depth is
+- not smaller than 8, then use adaptive filtering heuristic as follows: independently for each row, apply
+- all five filters and select the filter that produces the smallest sum of absolute values per row.
+- This heuristic is used if filter strategy is LFS_MINSUM and filter_palette_zero is true.
+-
+- If filter_palette_zero is true and filter_strategy is not LFS_MINSUM, the above heuristic is followed,
+- but for "the other case", whatever strategy filter_strategy is set to instead of the minimum sum
+- heuristic is used.
+- */
+- if(settings->filter_palette_zero &&
+- (color->colortype == LCT_PALETTE || color->bitdepth < 8)) strategy = LFS_ZERO;
++ if(settings->filter_palette_zero && (color->colortype == LCT_PALETTE || color->bitdepth < 8)) {
++ /*if the filter_palette_zero setting is enabled, override the filter strategy with
++ zero for all scanlines for palette and less-than-8-bitdepth images*/
++ strategy = LFS_ZERO;
++ }
+
+ if(bpp == 0) return 31; /*error: invalid color type*/
+
+@@ -5939,7 +6167,8 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w,
+ prevline = &in[inindex];
+ }
+ } else if(strategy == LFS_MINSUM) {
+- /*adaptive filtering*/
++ /*adaptive filtering: independently for each row, try all five filter types and select the one that produces the
++ smallest sum of absolute values per row.*/
+ unsigned char* attempt[5]; /*five filtering attempts, one for each filter type*/
+ size_t smallest = 0;
+ unsigned char type, bestType = 0;
+@@ -6165,21 +6394,21 @@ static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const
+ *) if no Adam7: 1) add padding bits (= possible extra bits per scanline if bpp < 8) 2) filter
+ *) if adam7: 1) Adam7_interlace 2) 7x add padding bits 3) 7x filter
+ */
+- unsigned bpp = lodepng_get_bpp(&info_png->color);
++ size_t bpp = lodepng_get_bpp(&info_png->color);
+ unsigned error = 0;
+-
+ if(info_png->interlace_method == 0) {
+- *outsize = h + (h * ((w * bpp + 7u) / 8u)); /*image size plus an extra byte per scanline + possible padding bits*/
++ /*image size plus an extra byte per scanline + possible padding bits*/
++ *outsize = (size_t)h + ((size_t)h * (((size_t)w * bpp + 7u) / 8u));
+ *out = (unsigned char*)lodepng_malloc(*outsize);
+ if(!(*out) && (*outsize)) error = 83; /*alloc fail*/
+
+ if(!error) {
+ /*non multiple of 8 bits per scanline, padding bits needed per scanline*/
+- if(bpp < 8 && w * bpp != ((w * bpp + 7u) / 8u) * 8u) {
++ if(bpp < 8 && (size_t)w * bpp != (((size_t)w * bpp + 7u) / 8u) * 8u) {
+ unsigned char* padded = (unsigned char*)lodepng_malloc(h * ((w * bpp + 7u) / 8u));
+ if(!padded) error = 83; /*alloc fail*/
+ if(!error) {
+- addPaddingBits(padded, in, ((w * bpp + 7u) / 8u) * 8u, w * bpp, h);
++ addPaddingBits(padded, in, (((size_t)w * bpp + 7u) / 8u) * 8u, (size_t)w * bpp, h);
+ error = filter(*out, padded, w, h, &info_png->color, settings);
+ }
+ lodepng_free(padded);
+@@ -6193,7 +6422,7 @@ static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const
+ size_t filter_passstart[8], padded_passstart[8], passstart[8];
+ unsigned char* adam7;
+
+- Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp);
++ Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, (unsigned)bpp);
+
+ *outsize = filter_passstart[7]; /*image size plus an extra byte per scanline + possible padding bits*/
+ *out = (unsigned char*)lodepng_malloc(*outsize);
+@@ -6205,13 +6434,13 @@ static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const
+ if(!error) {
+ unsigned i;
+
+- Adam7_interlace(adam7, in, w, h, bpp);
++ Adam7_interlace(adam7, in, w, h, (unsigned)bpp);
+ for(i = 0; i != 7; ++i) {
+ if(bpp < 8) {
+ unsigned char* padded = (unsigned char*)lodepng_malloc(padded_passstart[i + 1] - padded_passstart[i]);
+ if(!padded) ERROR_BREAK(83); /*alloc fail*/
+ addPaddingBits(padded, &adam7[passstart[i]],
+- ((passw[i] * bpp + 7u) / 8u) * 8u, passw[i] * bpp, passh[i]);
++ (((size_t)passw[i] * bpp + 7u) / 8u) * 8u, (size_t)passw[i] * bpp, passh[i]);
+ error = filter(&(*out)[filter_passstart[i]], padded,
+ passw[i], passh[i], &info_png->color, settings);
+ lodepng_free(padded);
+@@ -6271,6 +6500,7 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
+ LodePNGInfo info;
+ const LodePNGInfo* info_png = &state->info_png;
+ LodePNGColorMode auto_color;
++ unsigned error = 0;
+
+ lodepng_info_init(&info);
+ lodepng_color_mode_init(&auto_color);
+@@ -6278,7 +6508,6 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
+ /*provide some proper output values if error will happen*/
+ *out = 0;
+ *outsize = 0;
+- state->error = 0;
+
+ /*check input values validity*/
+ if((info_png->color.colortype == LCT_PALETTE || state->encoder.force_palette)
+@@ -6287,24 +6516,24 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
+ generate the palette by itself: while allowing this could be possible in theory,
+ it may complicate the code or edge cases, and always requiring to give a palette
+ when setting this color type is a simpler contract*/
+- state->error = 68; /*invalid palette size, it is only allowed to be 1-256*/
++ error = 68; /*invalid palette size, it is only allowed to be 1-256*/
+ goto cleanup;
+ }
+ if(state->encoder.zlibsettings.btype > 2) {
+- state->error = 61; /*error: invalid btype*/
++ error = 61; /*error: invalid btype*/
+ goto cleanup;
+ }
+ if(info_png->interlace_method > 1) {
+- state->error = 71; /*error: invalid interlace mode*/
++ error = 71; /*error: invalid interlace mode*/
+ goto cleanup;
+ }
+- state->error = checkColorValidity(info_png->color.colortype, info_png->color.bitdepth);
+- if(state->error) goto cleanup; /*error: invalid color type given*/
+- state->error = checkColorValidity(state->info_raw.colortype, state->info_raw.bitdepth);
+- if(state->error) goto cleanup; /*error: invalid color type given*/
++ error = checkColorValidity(info_png->color.colortype, info_png->color.bitdepth);
++ if(error) goto cleanup; /*error: invalid color type given*/
++ error = checkColorValidity(state->info_raw.colortype, state->info_raw.bitdepth);
++ if(error) goto cleanup; /*error: invalid color type given*/
+
+ /* color convert and compute scanline filter types */
+- lodepng_info_copy(&info, &state->info_png);
++ CERROR_TRY_RETURN(lodepng_info_copy(&info, &state->info_png));
+ if(state->encoder.auto_convert) {
+ LodePNGColorStats stats;
+ unsigned allow_convert = 1;
+@@ -6322,8 +6551,8 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
+ stats.allow_greyscale = 0;
+ }
+ #endif /* LODEPNG_COMPILE_ANCILLARY_CHUNKS */
+- state->error = lodepng_compute_color_stats(&stats, image, w, h, &state->info_raw);
+- if(state->error) goto cleanup;
++ error = lodepng_compute_color_stats(&stats, image, w, h, &state->info_raw);
++ if(error) goto cleanup;
+ #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
+ if(info_png->background_defined) {
+ /*the background chunk's color must be taken into account as well*/
+@@ -6331,12 +6560,12 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
+ LodePNGColorMode mode16 = lodepng_color_mode_make(LCT_RGB, 16);
+ lodepng_convert_rgb(&r, &g, &b,
+ info_png->background_r, info_png->background_g, info_png->background_b, &mode16, &info_png->color);
+- state->error = lodepng_color_stats_add(&stats, r, g, b, 65535);
+- if(state->error) goto cleanup;
++ error = lodepng_color_stats_add(&stats, r, g, b, 65535);
++ if(error) goto cleanup;
+ }
+ #endif /* LODEPNG_COMPILE_ANCILLARY_CHUNKS */
+- state->error = auto_choose_color(&auto_color, &state->info_raw, &stats);
+- if(state->error) goto cleanup;
++ error = auto_choose_color(&auto_color, &state->info_raw, &stats);
++ if(error) goto cleanup;
+ #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
+ if(info_png->sbit_defined) {
+ /*if sbit is defined, due to strict requirements of which sbit values can be present for which color modes,
+@@ -6390,7 +6619,7 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
+ if(state->encoder.force_palette) {
+ if(info.color.colortype != LCT_GREY && info.color.colortype != LCT_GREY_ALPHA &&
+ (auto_color.colortype == LCT_GREY || auto_color.colortype == LCT_GREY_ALPHA)) {
+- /*user speficially forced a PLTE palette, so cannot convert to grayscale types because
++ /*user specifically forced a PLTE palette, so cannot convert to grayscale types because
+ the PNG specification only allows writing a suggested palette in PLTE for truecolor types*/
+ allow_convert = 0;
+ }
+@@ -6402,7 +6631,7 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
+ if(info_png->background_defined) {
+ if(lodepng_convert_rgb(&info.background_r, &info.background_g, &info.background_b,
+ info_png->background_r, info_png->background_g, info_png->background_b, &info.color, &info_png->color)) {
+- state->error = 104;
++ error = 104;
+ goto cleanup;
+ }
+ }
+@@ -6415,13 +6644,13 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
+ unsigned rgb_icc = isRGBICCProfile(info_png->iccp_profile, info_png->iccp_profile_size);
+ unsigned gray_png = info.color.colortype == LCT_GREY || info.color.colortype == LCT_GREY_ALPHA;
+ if(!gray_icc && !rgb_icc) {
+- state->error = 100; /* Disallowed profile color type for PNG */
++ error = 100; /* Disallowed profile color type for PNG */
+ goto cleanup;
+ }
+ if(gray_icc != gray_png) {
+ /*Not allowed to use RGB/RGBA/palette with GRAY ICC profile or vice versa,
+ or in case of auto_convert, it wasn't possible to find appropriate model*/
+- state->error = state->encoder.auto_convert ? 102 : 101;
++ error = state->encoder.auto_convert ? 102 : 101;
+ goto cleanup;
+ }
+ }
+@@ -6431,18 +6660,18 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
+ size_t size = ((size_t)w * (size_t)h * (size_t)lodepng_get_bpp(&info.color) + 7u) / 8u;
+
+ converted = (unsigned char*)lodepng_malloc(size);
+- if(!converted && size) state->error = 83; /*alloc fail*/
+- if(!state->error) {
+- state->error = lodepng_convert(converted, image, &info.color, &state->info_raw, w, h);
++ if(!converted && size) error = 83; /*alloc fail*/
++ if(!error) {
++ error = lodepng_convert(converted, image, &info.color, &state->info_raw, w, h);
+ }
+- if(!state->error) {
+- state->error = preProcessScanlines(&data, &datasize, converted, w, h, &info, &state->encoder);
++ if(!error) {
++ error = preProcessScanlines(&data, &datasize, converted, w, h, &info, &state->encoder);
+ }
+ lodepng_free(converted);
+- if(state->error) goto cleanup;
++ if(error) goto cleanup;
+ } else {
+- state->error = preProcessScanlines(&data, &datasize, image, w, h, &info, &state->encoder);
+- if(state->error) goto cleanup;
++ error = preProcessScanlines(&data, &datasize, image, w, h, &info, &state->encoder);
++ if(error) goto cleanup;
+ }
+
+ /* output all PNG chunks */ {
+@@ -6450,95 +6679,111 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
+ size_t i;
+ #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
+ /*write signature and chunks*/
+- state->error = writeSignature(&outv);
+- if(state->error) goto cleanup;
++ error = writeSignature(&outv);
++ if(error) goto cleanup;
+ /*IHDR*/
+- state->error = addChunk_IHDR(&outv, w, h, info.color.colortype, info.color.bitdepth, info.interlace_method);
+- if(state->error) goto cleanup;
++ error = addChunk_IHDR(&outv, w, h, info.color.colortype, info.color.bitdepth, info.interlace_method);
++ if(error) goto cleanup;
+ #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
+ /*unknown chunks between IHDR and PLTE*/
+ if(info.unknown_chunks_data[0]) {
+- state->error = addUnknownChunks(&outv, info.unknown_chunks_data[0], info.unknown_chunks_size[0]);
+- if(state->error) goto cleanup;
++ error = addUnknownChunks(&outv, info.unknown_chunks_data[0], info.unknown_chunks_size[0]);
++ if(error) goto cleanup;
+ }
+ /*color profile chunks must come before PLTE */
++ if(info.cicp_defined) {
++ error = addChunk_cICP(&outv, &info);
++ if(error) goto cleanup;
++ }
++ if(info.mdcv_defined) {
++ error = addChunk_mDCV(&outv, &info);
++ if(error) goto cleanup;
++ }
++ if(info.clli_defined) {
++ error = addChunk_cLLI(&outv, &info);
++ if(error) goto cleanup;
++ }
+ if(info.iccp_defined) {
+- state->error = addChunk_iCCP(&outv, &info, &state->encoder.zlibsettings);
+- if(state->error) goto cleanup;
++ error = addChunk_iCCP(&outv, &info, &state->encoder.zlibsettings);
++ if(error) goto cleanup;
+ }
+ if(info.srgb_defined) {
+- state->error = addChunk_sRGB(&outv, &info);
+- if(state->error) goto cleanup;
++ error = addChunk_sRGB(&outv, &info);
++ if(error) goto cleanup;
+ }
+ if(info.gama_defined) {
+- state->error = addChunk_gAMA(&outv, &info);
+- if(state->error) goto cleanup;
++ error = addChunk_gAMA(&outv, &info);
++ if(error) goto cleanup;
+ }
+ if(info.chrm_defined) {
+- state->error = addChunk_cHRM(&outv, &info);
+- if(state->error) goto cleanup;
++ error = addChunk_cHRM(&outv, &info);
++ if(error) goto cleanup;
+ }
+ if(info_png->sbit_defined) {
+- state->error = addChunk_sBIT(&outv, &info);
+- if(state->error) goto cleanup;
++ error = addChunk_sBIT(&outv, &info);
++ if(error) goto cleanup;
++ }
++ if(info.exif_defined) {
++ error = addChunk_eXIf(&outv, &info);
++ if(error) goto cleanup;
+ }
+ #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
+ /*PLTE*/
+ if(info.color.colortype == LCT_PALETTE) {
+- state->error = addChunk_PLTE(&outv, &info.color);
+- if(state->error) goto cleanup;
++ error = addChunk_PLTE(&outv, &info.color);
++ if(error) goto cleanup;
+ }
+ if(state->encoder.force_palette && (info.color.colortype == LCT_RGB || info.color.colortype == LCT_RGBA)) {
+ /*force_palette means: write suggested palette for truecolor in PLTE chunk*/
+- state->error = addChunk_PLTE(&outv, &info.color);
+- if(state->error) goto cleanup;
++ error = addChunk_PLTE(&outv, &info.color);
++ if(error) goto cleanup;
+ }
+ /*tRNS (this will only add if when necessary) */
+- state->error = addChunk_tRNS(&outv, &info.color);
+- if(state->error) goto cleanup;
++ error = addChunk_tRNS(&outv, &info.color);
++ if(error) goto cleanup;
+ #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
+ /*bKGD (must come between PLTE and the IDAt chunks*/
+ if(info.background_defined) {
+- state->error = addChunk_bKGD(&outv, &info);
+- if(state->error) goto cleanup;
++ error = addChunk_bKGD(&outv, &info);
++ if(error) goto cleanup;
+ }
+ /*pHYs (must come before the IDAT chunks)*/
+ if(info.phys_defined) {
+- state->error = addChunk_pHYs(&outv, &info);
+- if(state->error) goto cleanup;
++ error = addChunk_pHYs(&outv, &info);
++ if(error) goto cleanup;
+ }
+
+ /*unknown chunks between PLTE and IDAT*/
+ if(info.unknown_chunks_data[1]) {
+- state->error = addUnknownChunks(&outv, info.unknown_chunks_data[1], info.unknown_chunks_size[1]);
+- if(state->error) goto cleanup;
++ error = addUnknownChunks(&outv, info.unknown_chunks_data[1], info.unknown_chunks_size[1]);
++ if(error) goto cleanup;
+ }
+ #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
+ /*IDAT (multiple IDAT chunks must be consecutive)*/
+- state->error = addChunk_IDAT(&outv, data, datasize, &state->encoder.zlibsettings);
+- if(state->error) goto cleanup;
++ error = addChunk_IDAT(&outv, data, datasize, &state->encoder.zlibsettings);
++ if(error) goto cleanup;
+ #ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
+ /*tIME*/
+ if(info.time_defined) {
+- state->error = addChunk_tIME(&outv, &info.time);
+- if(state->error) goto cleanup;
++ error = addChunk_tIME(&outv, &info.time);
++ if(error) goto cleanup;
+ }
+ /*tEXt and/or zTXt*/
+ for(i = 0; i != info.text_num; ++i) {
+ if(lodepng_strlen(info.text_keys[i]) > 79) {
+- state->error = 66; /*text chunk too large*/
++ error = 66; /*text chunk too large*/
+ goto cleanup;
+ }
+ if(lodepng_strlen(info.text_keys[i]) < 1) {
+- state->error = 67; /*text chunk too small*/
++ error = 67; /*text chunk too small*/
+ goto cleanup;
+ }
+ if(state->encoder.text_compression) {
+- state->error = addChunk_zTXt(&outv, info.text_keys[i], info.text_strings[i], &state->encoder.zlibsettings);
+- if(state->error) goto cleanup;
++ error = addChunk_zTXt(&outv, info.text_keys[i], info.text_strings[i], &state->encoder.zlibsettings);
++ if(error) goto cleanup;
+ } else {
+- state->error = addChunk_tEXt(&outv, info.text_keys[i], info.text_strings[i]);
+- if(state->error) goto cleanup;
++ error = addChunk_tEXt(&outv, info.text_keys[i], info.text_strings[i]);
++ if(error) goto cleanup;
+ }
+ }
+ /*LodePNG version id in text chunk*/
+@@ -6554,35 +6799,35 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
+ }
+ }
+ if(already_added_id_text == 0) {
+- state->error = addChunk_tEXt(&outv, "LodePNG", LODEPNG_VERSION_STRING); /*it's shorter as tEXt than as zTXt chunk*/
+- if(state->error) goto cleanup;
++ error = addChunk_tEXt(&outv, "LodePNG", LODEPNG_VERSION_STRING); /*it's shorter as tEXt than as zTXt chunk*/
++ if(error) goto cleanup;
+ }
+ }
+ /*iTXt*/
+ for(i = 0; i != info.itext_num; ++i) {
+ if(lodepng_strlen(info.itext_keys[i]) > 79) {
+- state->error = 66; /*text chunk too large*/
++ error = 66; /*text chunk too large*/
+ goto cleanup;
+ }
+ if(lodepng_strlen(info.itext_keys[i]) < 1) {
+- state->error = 67; /*text chunk too small*/
++ error = 67; /*text chunk too small*/
+ goto cleanup;
+ }
+- state->error = addChunk_iTXt(
++ error = addChunk_iTXt(
+ &outv, state->encoder.text_compression,
+ info.itext_keys[i], info.itext_langtags[i], info.itext_transkeys[i], info.itext_strings[i],
+ &state->encoder.zlibsettings);
+- if(state->error) goto cleanup;
++ if(error) goto cleanup;
+ }
+
+ /*unknown chunks between IDAT and IEND*/
+ if(info.unknown_chunks_data[2]) {
+- state->error = addUnknownChunks(&outv, info.unknown_chunks_data[2], info.unknown_chunks_size[2]);
+- if(state->error) goto cleanup;
++ error = addUnknownChunks(&outv, info.unknown_chunks_data[2], info.unknown_chunks_size[2]);
++ if(error) goto cleanup;
+ }
+ #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
+- state->error = addChunk_IEND(&outv);
+- if(state->error) goto cleanup;
++ error = addChunk_IEND(&outv);
++ if(error) goto cleanup;
+ }
+
+ cleanup:
+@@ -6594,7 +6839,9 @@ cleanup:
+ *out = outv.data;
+ *outsize = outv.size;
+
+- return state->error;
++ state->error = error; /*TODO: remove this and make input state const*/
++
++ return error;
+ }
+
+ unsigned lodepng_encode_memory(unsigned char** out, size_t* outsize, const unsigned char* image,
+@@ -6606,8 +6853,7 @@ unsigned lodepng_encode_memory(unsigned char** out, size_t* outsize, const unsig
+ state.info_raw.bitdepth = bitdepth;
+ state.info_png.color.colortype = colortype;
+ state.info_png.color.bitdepth = bitdepth;
+- lodepng_encode(out, outsize, image, w, h, &state);
+- error = state.error;
++ error = lodepng_encode(out, outsize, image, w, h, &state);
+ lodepng_state_cleanup(&state);
+ return error;
+ }
+@@ -6735,7 +6981,7 @@ const char* lodepng_error_text(unsigned code) {
+ case 68: return "tried to encode a PLTE chunk with a palette that has less than 1 or more than 256 colors";
+ case 69: return "unknown chunk type with 'critical' flag encountered by the decoder";
+ case 71: return "invalid interlace mode given to encoder (must be 0 or 1)";
+- case 72: return "while decoding, invalid compression method encountering in zTXt or iTXt chunk (it must be 0)";
++ case 72: return "while decoding, invalid compression method encountered in zTXt, iTXt or iCCP chunk (it must be 0)";
+ case 73: return "invalid tIME chunk size";
+ case 74: return "invalid pHYs chunk size";
+ /*length could be wrong, or data chopped off*/
+@@ -6785,6 +7031,14 @@ const char* lodepng_error_text(unsigned code) {
+ case 113: return "ICC profile unreasonably large";
+ case 114: return "sBIT chunk has wrong size for the color type of the image";
+ case 115: return "sBIT value out of range";
++ case 116: return "cICP value out of range";
++ case 117: return "invalid cICP chunk size";
++ case 118: return "mDCV value out of range";
++ case 119: return "invalid mDCV chunk size";
++ case 120: return "invalid cLLI chunk size";
++ case 121: return "invalid chunk type name: may only contain [a-zA-Z]";
++ case 122: return "invalid chunk type name: third character must be uppercase";
++ case 123: return "invalid ICC profile size";
+ }
+ return "unknown error code";
+ }
+@@ -6800,11 +7054,23 @@ const char* lodepng_error_text(unsigned code) {
+ namespace lodepng {
+
+ #ifdef LODEPNG_COMPILE_DISK
+-unsigned load_file(std::vector<unsigned char>& buffer, const std::string& filename) {
+- long size = lodepng_filesize(filename.c_str());
++/* Resizes the vector to the file size and reads the file into it. Returns error code.*/
++static unsigned load_file_(std::vector<unsigned char>& buffer, FILE* file) {
++ long size = lodepng_filesize(file);
+ if(size < 0) return 78;
+ buffer.resize((size_t)size);
+- return size == 0 ? 0 : lodepng_buffer_file(&buffer[0], (size_t)size, filename.c_str());
++ if(size == 0) return 0; /*ok*/
++ if(fread(&buffer[0], 1, buffer.size(), file) != buffer.size()) return 78;
++ return 0; /*ok*/
++}
++
++unsigned load_file(std::vector<unsigned char>& buffer, const std::string& filename) {
++ unsigned error;
++ FILE* file = fopen(filename.c_str(), "rb");
++ if(!file) return 78;
++ error = load_file_(buffer, file);
++ fclose(file);
++ return error;
+ }
+
+ /*write given buffer to the file, overwriting the file, it doesn't append to it.*/
+diff --git a/libeg/lodepng.h b/libeg/lodepng.h
+index 3bceefa..93c0c17 100644
+--- a/libeg/lodepng.h
++++ b/libeg/lodepng.h
+@@ -1,7 +1,7 @@
+ /*
+-LodePNG version 20230410
++LodePNG version 20261006
+
+-Copyright (c) 2005-2023 Lode Vandevenne
++Copyright (c) 2005-2026 Lode Vandevenne
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+@@ -574,6 +574,18 @@ typedef struct LodePNGInfo {
+ char** itext_transkeys; /*keyword translated to the international language - UTF-8 string*/
+ char** itext_strings; /*the actual international text - UTF-8 string*/
+
++ /*
++ Optional exif metadata in exif_size bytes.
++ Don't allocate this buffer yourself. Use the init/cleanup functions
++ correctly and use lodepng_set_exif and lodepng_clear_exif.
++ The exif data is in exif-encoded form but without JPEG markers, starting with the 'II' or 'MM' marker that indicates
++ endianness. It's up to an exif handling library to encode/decode its information.
++ */
++ unsigned exif_defined; /* Whether exif metadata is present, that is, the PNG image has an eXIf chunk */
++ unsigned char* exif; /* The bytes of the exif metadata, if present */
++ unsigned exif_size; /* The size of the exif data in bytes */
++
++
+ /*time chunk (tIME)*/
+ unsigned time_defined; /*set to 1 to make the encoder generate a tIME chunk*/
+ LodePNGTime time;
+@@ -585,20 +597,34 @@ typedef struct LodePNGInfo {
+ unsigned phys_unit; /*may be 0 (unknown unit) or 1 (metre)*/
+
+ /*
+- Color profile related chunks: gAMA, cHRM, sRGB, iCPP, sBIT
++ Color profile related chunk types: cICP, iCPP, sRGB, gAMA, cHRM, sBIT
+
+ LodePNG does not apply any color conversions on pixels in the encoder or decoder and does not interpret these color
+- profile values. It merely passes on the information. If you wish to use color profiles and convert colors, please
+- use these values with a color management library.
+-
+- See the PNG, ICC and sRGB specifications for more information about the meaning of these values.
++ profile values. It merely passes on the information. If you wish to use color profiles and convert colors, a separate
++ color management library should be used. There is also a limited library for this in lodepng_util.h.
++
++ There are 4 types of (sets of) chunks providing color information. If multiple are present, each will be decoded by
++ LodePNG, but only one should be handled by the user, with the following order of priority depending on what the user
++ supports:
++ 1: cICP: Coding-independent code points (CICP)
++ 2: iCCP: ICC profile
++ 3: sRGB: indicates the image is in the sRGB color profile
++ 4: gAMA and cHRM: indicates a gamma and chromaticity value to define the color profile
+ */
+
+- /* gAMA chunk: optional, overridden by sRGB or iCCP if those are present. */
++ /*
++ gAMA chunk: Image gamma
++ Optional, overridden by cICP, iCCP or sRGB if those are present.
++ Together with cHRM, this is a primitive way of specifying the image color profile.
++ */
+ unsigned gama_defined; /* Whether a gAMA chunk is present (0 = not present, 1 = present). */
+ unsigned gama_gamma; /* Gamma exponent times 100000 */
+
+- /* cHRM chunk: optional, overridden by sRGB or iCCP if those are present. */
++ /*
++ cHRM chunk: Primary chromaticities and white point
++ Optional, overridden by cICP, iCCP or sRGB if those are present.
++ Together with gAMA, this is a primitive way of specifying the image color profile.
++ */
+ unsigned chrm_defined; /* Whether a cHRM chunk is present (0 = not present, 1 = present). */
+ unsigned chrm_white_x; /* White Point x times 100000 */
+ unsigned chrm_white_y; /* White Point y times 100000 */
+@@ -610,7 +636,8 @@ typedef struct LodePNGInfo {
+ unsigned chrm_blue_y; /* Blue y times 100000 */
+
+ /*
+- sRGB chunk: optional. May not appear at the same time as iCCP.
++ sRGB chunk: Indicates the image is in the sRGB color space.
++ Optional. Should not appear at the same time as iCCP.
+ If gAMA is also present gAMA must contain value 45455.
+ If cHRM is also present cHRM must contain respectively 31270,32900,64000,33000,30000,60000,15000,6000.
+ */
+@@ -618,22 +645,25 @@ typedef struct LodePNGInfo {
+ unsigned srgb_intent; /* Rendering intent: 0=perceptual, 1=rel. colorimetric, 2=saturation, 3=abs. colorimetric */
+
+ /*
+- iCCP chunk: optional. May not appear at the same time as sRGB.
++ iCCP chunk: Embedded ICC profile.
++ Optional. Should not appear at the same time as sRGB.
+
+- LodePNG does not parse or use the ICC profile (except its color space header field for an edge case), a
+- separate library to handle the ICC data (not included in LodePNG) format is needed to use it for color
++ Contains ICC profile, which can use any version of the ICC.1 specification by the International Color Consortium. See
++ its specification for more details. LodePNG does not parse or use the ICC profile (except its color space header
++ field for "RGB" or "GRAY", see below), a separate library to handle the ICC data format is needed to use it for color
+ management and conversions.
+
+- For encoding, if iCCP is present, gAMA and cHRM are recommended to be added as well with values that match the ICC
+- profile as closely as possible, if you wish to do this you should provide the correct values for gAMA and cHRM and
+- enable their '_defined' flags since LodePNG will not automatically compute them from the ICC profile.
++ For encoding, if iCCP is present, the PNG specification recommends to also add gAMA and cHRM chunks that approximate
++ the ICC profile, for compatibility with applications that don't use the ICC chunk. This is not required, and it's up
++ to the user to compute approximate values and set then in the appropriate gama_ and chrm_ fields, LodePNG does not do
++ this automatically since it does not interpret the ICC profile.
+
+- For encoding, the ICC profile is required by the PNG specification to be an "RGB" profile for non-gray
+- PNG color types and a "GRAY" profile for gray PNG color types. If you disable auto_convert, you must ensure
+- the ICC profile type matches your requested color type, else the encoder gives an error. If auto_convert is
+- enabled (the default), and the ICC profile is not a good match for the pixel data, this will result in an encoder
+- error if the pixel data has non-gray pixels for a GRAY profile, or a silent less-optimal compression of the pixel
+- data if the pixels could be encoded as grayscale but the ICC profile is RGB.
++ For encoding, the ICC profile is required by the PNG specification to be an "RGB" profile for non-gray PNG color
++ types (types 2, 3 and 6) and a "GRAY" profile for gray PNG color types (types 1 and 4). If you disable auto_convert,
++ you must ensure the ICC profile type matches your requested color type, else the encoder gives an error. If
++ auto_convert is enabled (the default), and the ICC profile is not a correct match for the pixel data, this will result
++ in an encoder error if the pixel data has non-gray pixels for a GRAY profile, or a silent less-optimal compression of
++ the pixel data if the pixels could be encoded as grayscale but the ICC profile is RGB.
+
+ To avoid this do not set an ICC profile in the image unless there is a good reason for it, and when doing so
+ make sure you compute it carefully to avoid the above problems.
+@@ -649,7 +679,58 @@ typedef struct LodePNGInfo {
+ unsigned iccp_profile_size; /* The size of iccp_profile in bytes */
+
+ /*
+- sBIT chunk: significant bits. Optional metadata, only set this if needed.
++ cICP chunk: Coding-independent code points for video signal type identification.
++ Optional. If present, and supported, overrides iCCP, sRGB, gAMA and cHRM.
++ The meaning of the values are as defined in the specification ITU-T-H.273. LodePNG does not
++ use these values, only passes on the metadata. The meaning of the values is they are enum
++ values representing certain color spaces, including HDR color spaces, such as Display P3,
++ PQ and HLG. The video full range flag value should typically be 1 for the use cases of PNG
++ images, but can be 0 for narrow-range images in certain video editing workflows.
++ */
++ unsigned cicp_defined; /* Whether an cICP chunk is present (0 = not present, 1 = present). */
++ unsigned cicp_color_primaries; /* Colour primaries value */
++ unsigned cicp_transfer_function; /* Transfer characteristics value */
++ unsigned cicp_matrix_coefficients; /* Matrix coefficients value */
++ unsigned cicp_video_full_range_flag; /* Video full range flag value */
++
++ /*
++ mDCV chunk: Mastering Display Color Volume.
++ Optional, typically used in conjunction with certain HDR color spaces that can
++ be represented by the cICP chunk.
++ See the PNG specification, third edition, for more information on this chunk.
++ All the red, green, blue and white x and y values are encoded as 16-bit
++ integers and therefore must be in range 0-65536. The min and max luminance
++ values are 32-bit integers.
++ */
++ unsigned mdcv_defined; /* Whether an mDCV chunk is present (0 = not present, 1 = present). */
++ /* Mastering display color primary chromaticities (CIE 1931 x,y of R,G,B) */
++ unsigned mdcv_red_x; /* Red x times 50000 */
++ unsigned mdcv_red_y; /* Red y times 50000 */
++ unsigned mdcv_green_x; /* Green x times 50000 */
++ unsigned mdcv_green_y; /* Green y times 50000 */
++ unsigned mdcv_blue_x; /* Blue x times 50000 */
++ unsigned mdcv_blue_y; /* Blue y times 50000 */
++ /* Mastering display white point chromaticity (CIE 1931 x,y) */
++ unsigned mdcv_white_x; /* White Point x times 50000 */
++ unsigned mdcv_white_y; /* White Point y times 50000 */
++ /* Mastering display luminance */
++ unsigned mdcv_max_luminance; /* Max luminance in cd/m^2 times 10000 */
++ unsigned mdcv_min_luminance; /* Min luminance in cd/m^2 times 10000 */
++
++ /*
++ cLLI chunk: Content Light Level Information.
++ Optional, typically used in conjunction with certain HDR color spaces that can
++ be represented by the cICP chunk.
++ See the PNG specification, third edition, for more information on this chunk.
++ The clli_max_cll and clli_max_fall values are 32-bit integers.
++ */
++ unsigned clli_defined; /* Whether a cLLI chunk is present (0 = not present, 1 = present). */
++ unsigned clli_max_cll; /* Maximum Content Light Level (MaxCLL) in cd/m^2 times 10000 */
++ unsigned clli_max_fall; /* Maximum Frame-Average Light Level (MaxFALL) in cd/m^2 times 10000 */
++
++ /*
++ sBIT chunk: significant bits.
++ Optional metadata, only set this if needed.
+
+ If defined, these values give the bit depth of the original data. Since PNG only stores 1, 2, 4, 8 or 16-bit
+ per channel data, the significant bits value can be used to indicate the original encoded data has another
+@@ -714,6 +795,7 @@ typedef struct LodePNGInfo {
+
+ /*init, cleanup and copy functions to use with this struct*/
+ void lodepng_info_init(LodePNGInfo* info);
++/*destructs the LodePNGInfo and brings it to invalid state, requiring lodepng_info_init again before reusing it*/
+ void lodepng_info_cleanup(LodePNGInfo* info);
+ /*return value is error code (0 means no error)*/
+ unsigned lodepng_info_copy(LodePNGInfo* dest, const LodePNGInfo* source);
+@@ -728,7 +810,11 @@ void lodepng_clear_itext(LodePNGInfo* info); /*use this to clear the itexts agai
+
+ /*replaces if exists*/
+ unsigned lodepng_set_icc(LodePNGInfo* info, const char* name, const unsigned char* profile, unsigned profile_size);
+-void lodepng_clear_icc(LodePNGInfo* info); /*use this to clear the texts again after you filled them in*/
++void lodepng_clear_icc(LodePNGInfo* info); /*use this to clear the profile again after you filled it in*/
++
++/*replaces if exists*/
++unsigned lodepng_set_exif(LodePNGInfo* info, const unsigned char* exif, unsigned exif_size);
++void lodepng_clear_exif(LodePNGInfo* info); /*use this to clear the exif metadata again after you filled it in*/
+ #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
+
+ /*
+@@ -761,7 +847,7 @@ typedef struct LodePNGDecoderSettings {
+ /* TODO: make a system involving warnings with levels and a strict mode instead. Other potentially recoverable
+ errors: srgb rendering intent value, size of content of ancillary chunks, more than 79 characters for some
+ strings, placement/combination rules for ancillary chunks, crc of unknown chunks, allowed characters
+- in string keys, etc... */
++ in string keys, invalid characters in chunk types names, etc... */
+
+ unsigned color_convert; /*whether to convert the PNG to the color type you want. Default: yes*/
+
+@@ -787,7 +873,8 @@ void lodepng_decoder_settings_init(LodePNGDecoderSettings* settings);
+ #endif /*LODEPNG_COMPILE_DECODER*/
+
+ #ifdef LODEPNG_COMPILE_ENCODER
+-/*automatically use color type with less bits per pixel if losslessly possible. Default: AUTO*/
++/*strategy to use to choose the PNG filter per scanline. Strategies 0-4 correspond
++to each of the 5 filter types PNG supports, the next values are adaptive strategies*/
+ typedef enum LodePNGFilterStrategy {
+ /*every filter at zero*/
+ LFS_ZERO = 0,
+@@ -796,7 +883,8 @@ typedef enum LodePNGFilterStrategy {
+ LFS_TWO = 2,
+ LFS_THREE = 3,
+ LFS_FOUR = 4,
+- /*Use filter that gives minimum sum, as described in the official PNG filter heuristic.*/
++ /*Use the filter out of the 5 above types that gives minimum sum, by trying each one. This is the adaptive filtering
++ suggested heuristic in the PNG standard chapter 'Filter selection'.*/
+ LFS_MINSUM,
+ /*Use the filter type that gives smallest Shannon entropy for this scanline. Depending
+ on the image, this is better or worse than minsum.*/
+@@ -842,12 +930,15 @@ unsigned lodepng_compute_color_stats(LodePNGColorStats* stats,
+ typedef struct LodePNGEncoderSettings {
+ LodePNGCompressSettings zlibsettings; /*settings for the zlib encoder, such as window size, ...*/
+
+- unsigned auto_convert; /*automatically choose output PNG color type. Default: true*/
++ /*automatically choose output PNG color type. If false, must explicitly choose the output color
++ type in state.info_png.color.colortype, info_png.color.bitdepth and optionally its palette.
++ Default: true*/
++ unsigned auto_convert;
+
+- /*If true, follows the official PNG heuristic: if the PNG uses a palette or lower than
+- 8 bit depth, set all filters to zero. Otherwise use the filter_strategy. Note that to
+- completely follow the official PNG heuristic, filter_palette_zero must be true and
+- filter_strategy must be LFS_MINSUM*/
++ /*If true, follows the suggestion in the PNG standard in chapter 'Filter selection': if the PNG uses
++ a palette or lower than 8 bit depth, set all filters to zero.
++ In other cases this will use the heuristic from the chosen filter_strategy. The PNG standard
++ suggests LFS_MINSUM for those cases.*/
+ unsigned filter_palette_zero;
+ /*Which filter strategy to use when not using zeroes due to filter_palette_zero.
+ Set filter_palette_zero to 0 to ensure always using your chosen strategy. Default: LFS_MINSUM*/
+@@ -859,7 +950,7 @@ typedef struct LodePNGEncoderSettings {
+ const unsigned char* predefined_filters;
+
+ /*force creating a PLTE chunk if colortype is 2 or 6 (= a suggested palette).
+- If colortype is 3, PLTE is always created. If color type is explicitely set
++ If colortype is 3, PLTE is always created. If color type is explicitly set
+ to a grayscale type (1 or 4), this is not done and is ignored. If enabling this,
+ a palette must be present in the info_png.
+ NOTE: enabling this may worsen compression if auto_convert is used to choose
+@@ -878,7 +969,17 @@ void lodepng_encoder_settings_init(LodePNGEncoderSettings* settings);
+
+
+ #if defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ENCODER)
+-/*The settings, state and information for extended encoding and decoding.*/
++/*The settings, state and information for extended encoding and decoding.
++
++Using this struct requires using lodepng_state_init to initialize it
++and using lodepng_state_cleanup to deconstruct it. If using C++, you can
++use lodepng::State instead which does those things automatically with RAII.
++
++While a LodePNGState can be reused once in a chain of lodepng_decode followed by
++lodepng_encode, it's not recommended to reuse it for multiple encode, decode
++or inspect calls, and if any such function returns an error code, the
++LodePNGState should not be reused at all as it can be in an unexpected state..
++*/
+ typedef struct LodePNGState {
+ #ifdef LODEPNG_COMPILE_DECODER
+ LodePNGDecoderSettings decoder; /*the decoding settings*/
+@@ -888,13 +989,15 @@ typedef struct LodePNGState {
+ #endif /*LODEPNG_COMPILE_ENCODER*/
+ LodePNGColorMode info_raw; /*specifies the format in which you would like to get the raw pixel buffer*/
+ LodePNGInfo info_png; /*info of the PNG image obtained after decoding*/
+- unsigned error;
++ unsigned error; /*deprecated, use the return value of the encode/decode functions to check errors instead*/
+ } LodePNGState;
+
+ /*init, cleanup and copy functions to use with this struct*/
+ void lodepng_state_init(LodePNGState* state);
++/*destructs the LodePNGState and brings it to invalid state, requiring lodepng_info_init again before reusing it*/
+ void lodepng_state_cleanup(LodePNGState* state);
+-void lodepng_state_copy(LodePNGState* dest, const LodePNGState* source);
++/*return value is error code (0 means no error)*/
++unsigned lodepng_state_copy(LodePNGState* dest, const LodePNGState* source);
+ #endif /* defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ENCODER) */
+
+ #ifdef LODEPNG_COMPILE_DECODER
+@@ -1023,7 +1126,7 @@ unsigned lodepng_chunk_append(unsigned char** out, size_t* outsize, const unsign
+ Appends new chunk to out. The chunk to append is given by giving its length, type
+ and data separately. The type is a 4-letter string.
+ The out variable and outsize are updated to reflect the new reallocated buffer.
+-Returne error code (0 if it went ok)
++Returns error code (0 if it went ok)
+ */
+ unsigned lodepng_chunk_create(unsigned char** out, size_t* outsize, size_t length,
+ const char* type, const unsigned char* data);
+@@ -1117,6 +1220,8 @@ unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const
+ /* The LodePNG C++ wrapper uses std::vectors instead of manually allocated memory buffers. */
+ namespace lodepng {
+ #ifdef LODEPNG_COMPILE_PNG
++/* Wrapper around LodePNGState, which automatically calls lodepng_state_init in the constructor
++and lodepng_state_cleanup in the desctructor.*/
+ class State : public LodePNGState {
+ public:
+ State();
+@@ -1196,7 +1301,8 @@ TODO:
+ [.] check compatibility with various compilers - done but needs to be redone for every newer version
+ [X] converting color to 16-bit per channel types
+ [X] support color profile chunk types (but never let them touch RGB values by default)
+-[ ] support all public PNG chunk types (almost done except sPLT and hIST)
++[ ] support all second edition public PNG chunk types (almost done except sPLT and hIST)
++[X] support non-animation third edition public PNG chunk types: eXIf, cICP, mDCV, cLLI
+ [ ] make sure encoder generates no chunks with size > (2^31)-1
+ [ ] partial decoding (stream processing)
+ [X] let the "isFullyOpaque" function check color keys and transparent palettes too
+@@ -1898,7 +2004,7 @@ state.decoder.remember_unknown_chunks: whether to read in unknown chunks
+ state.info_raw.colortype: desired color type for decoded image
+ state.info_raw.bitdepth: desired bit depth for decoded image
+ state.info_raw....: more color settings, see struct LodePNGColorMode
+-state.info_png....: no settings for decoder but ouput, see struct LodePNGInfo
++state.info_png....: no settings for decoder but output, see struct LodePNGInfo
+
+ For encoding:
+
+@@ -1936,13 +2042,21 @@ symbol.
+ Not all changes are listed here, the commit history in github lists more:
+ https://github.com/lvandeve/lodepng
+
++*) 6 may 2025 (!): renamed mDCv to mDCV and cLLi to cLLI as per the recent
++ rename in the draft png third edition spec. Please note that as long as the
++ third edition is not finalized, backwards-incompatible changes to its
++ features are possible.
++*) 23 dec 2024: added support for the mDCv and cLLi chunks (for png third
++ edition spec)
++*) 22 dec 2024: added support for the cICP chunk (for png third edition spec)
++*) 15 dec 2024: added support for the eXIf chunk (for png third edition spec)
+ *) 10 apr 2023: faster CRC32 implementation, but with larger lookup table.
+ *) 13 jun 2022: added support for the sBIT chunk.
+ *) 09 jan 2022: minor decoder speed improvements.
+ *) 27 jun 2021: added warnings that file reading/writing functions don't support
+ wide-character filenames (support for this is not planned, opening files is
+ not the core part of PNG decoding/decoding and is platform dependent).
+-*) 17 okt 2020: prevent decoding too large text/icc chunks by default.
++*) 17 oct 2020: prevent decoding too large text/icc chunks by default.
+ *) 06 mar 2020: simplified some of the dynamic memory allocations.
+ *) 12 jan 2020: (!) added 'end' argument to lodepng_chunk_next to allow correct
+ overflow checks.
+@@ -1964,7 +2078,7 @@ https://github.com/lvandeve/lodepng
+ *) 09 apr 2016: Fixed colorkey usage detection, and better file loading (within
+ the limits of pure C90).
+ *) 08 dec 2015: Made load_file function return error if file can't be opened.
+-*) 24 okt 2015: Bugfix with decoding to palette output.
++*) 24 oct 2015: Bugfix with decoding to palette output.
+ *) 18 apr 2015: Boundary PM instead of just package-merge for faster encoding.
+ *) 24 aug 2014: Moved to github
+ *) 23 aug 2014: Reduced needless memory usage of decoder.
+@@ -1978,8 +2092,8 @@ https://github.com/lvandeve/lodepng
+ prefix for the custom allocators and made it possible with a new #define to
+ use custom ones in your project without needing to change lodepng's code.
+ *) 28 jan 2013: Bugfix with color key.
+-*) 27 okt 2012: Tweaks in text chunk keyword length error handling.
+-*) 8 okt 2012: (!) Added new filter strategy (entropy) and new auto color mode.
++*) 27 oct 2012: Tweaks in text chunk keyword length error handling.
++*) 8 oct 2012: (!) Added new filter strategy (entropy) and new auto color mode.
+ (no palette). Better deflate tree encoding. New compression tweak settings.
+ Faster color conversions while decoding. Some internal cleanups.
+ *) 23 sep 2012: Reduced warnings in Visual Studio a little bit.
+@@ -1995,7 +2109,7 @@ https://github.com/lvandeve/lodepng
+ *) 6 nov 2011: (!) By default, the encoder now automatically chooses the best
+ PNG color model and bit depth, based on the amount and type of colors of the
+ raw image. For this, autoLeaveOutAlphaChannel replaced by auto_choose_color.
+-*) 9 okt 2011: simpler hash chain implementation for the encoder.
++*) 9 oct 2011: simpler hash chain implementation for the encoder.
+ *) 8 sep 2011: lz77 encoder lazy matching instead of greedy matching.
+ *) 23 aug 2011: tweaked the zlib compression parameters after benchmarking.
+ A bug with the PNG filtertype heuristic was fixed, so that it chooses much
+@@ -2010,8 +2124,8 @@ https://github.com/lvandeve/lodepng
+ *) 13 nov 2010: added LodePNG_InfoColor_hasPaletteAlpha and
+ LodePNG_InfoColor_canHaveAlpha functions for convenience.
+ *) 7 nov 2010: added LodePNG_error_text function to get error code description.
+-*) 30 okt 2010: made decoding slightly faster
+-*) 26 okt 2010: (!) changed some C function and struct names (more consistent).
++*) 30 oct 2010: made decoding slightly faster
++*) 26 oct 2010: (!) changed some C function and struct names (more consistent).
+ Reorganized the documentation and the declaration order in the header.
+ *) 08 aug 2010: only changed some comments and external samples.
+ *) 05 jul 2010: fixed bug thanks to warnings in the new gcc version.
+@@ -2070,8 +2184,8 @@ https://github.com/lvandeve/lodepng
+ Removed some code duplication in the decoder. Fixed little bug in an example.
+ *) 09 dec 2006: (!) Placed output parameters of public functions as first parameter.
+ Fixed a bug of the decoder with 16-bit per color.
+-*) 15 okt 2006: Changed documentation structure
+-*) 09 okt 2006: Encoder class added. It encodes a valid PNG image from the
++*) 15 oct 2006: Changed documentation structure
++*) 09 oct 2006: Encoder class added. It encodes a valid PNG image from the
+ given image buffer, however for now it's not compressed.
+ *) 08 sep 2006: (!) Changed to interface with a Decoder class
+ *) 30 jul 2006: (!) LodePNG_InfoPng , width and height are now retrieved in different
+@@ -2095,19 +2209,4 @@ https://github.com/lvandeve/lodepng
+ *) 22 apr 2006: Optimized and improved some code
+ *) 07 sep 2005: (!) Changed to std::vector interface
+ *) 12 aug 2005: Initial release (C++, decoder only)
+-
+-
+-13. contact information
+------------------------
+-
+-Feel free to contact me with suggestions, problems, comments, ... concerning
+-LodePNG. If you encounter a PNG image that doesn't work properly with this
+-decoder, feel free to send it and I'll use it to find and fix the problem.
+-
+-My email address is (puzzle the account and domain together with an @ symbol):
+-Domain: gmail dot com.
+-Account: lode dot vandevenne.
+-
+-
+-Copyright (c) 2005-2022 Lode Vandevenne
+ */
+--
+2.56.0
+
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-24 19:00 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 19:00 [rpms/rEFInd] rawhide: Update LodePNG to version 20261006 Jan200101
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox