Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/lvandeve/lodepng.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLode <lvandeve@gmail.com>2022-06-19 00:32:47 +0300
committerLode <lvandeve@gmail.com>2022-06-19 00:32:47 +0300
commitb4ed2cd7ecf61d29076169b49199371456d4f90b (patch)
treee849ad69963d6e017410364db47e186dfcf0c3a4
parent08a7cd132311f5b98c30657af1dc6d72ec8f0a50 (diff)
document NO_COMPILE macros better, and cleanups
-rw-r--r--examples/example_sdl.c1
-rw-r--r--lodepng.cpp12
-rw-r--r--lodepng.h27
-rw-r--r--lodepng_util.cpp27
-rw-r--r--lodepng_util.h5
5 files changed, 46 insertions, 26 deletions
diff --git a/examples/example_sdl.c b/examples/example_sdl.c
index e2c58c1..72686c2 100644
--- a/examples/example_sdl.c
+++ b/examples/example_sdl.c
@@ -115,6 +115,7 @@ int show(const char* filename) {
SDL_RenderPresent(sdl_renderer);
/* pause until you press escape and meanwhile redraw screen */
+ done = 0;
while(done == 0) {
while(SDL_PollEvent(&sdl_event)) {
if(sdl_event.type == SDL_QUIT) done = 2;
diff --git a/lodepng.cpp b/lodepng.cpp
index c2305a0..33f3ea5 100644
--- a/lodepng.cpp
+++ b/lodepng.cpp
@@ -1,5 +1,5 @@
/*
-LodePNG version 20220613
+LodePNG version 20220618
Copyright (c) 2005-2022 Lode Vandevenne
@@ -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 = "20220613";
+const char* LODEPNG_VERSION_STRING = "20220618";
/*
This source file is divided into the following large parts. The code sections
@@ -2373,7 +2373,7 @@ const LodePNGDecompressSettings lodepng_default_decompress_settings = {0, 0, 0,
/* ////////////////////////////////////////////////////////////////////////// */
-#ifndef LODEPNG_NO_COMPILE_CRC
+#ifdef LODEPNG_COMPILE_CRC
/* CRC polynomial: 0xedb88320 */
static unsigned lodepng_crc32_table[256] = {
0u, 1996959894u, 3993919788u, 2567524794u, 124634137u, 1886057615u, 3915621685u, 2657392035u,
@@ -2419,9 +2419,11 @@ unsigned lodepng_crc32(const unsigned char* data, size_t length) {
}
return r ^ 0xffffffffu;
}
-#else /* !LODEPNG_NO_COMPILE_CRC */
+#else /* LODEPNG_COMPILE_CRC */
+/*in this case, the function is only declared here, and must be defined externally
+so that it will be linked in*/
unsigned lodepng_crc32(const unsigned char* data, size_t length);
-#endif /* !LODEPNG_NO_COMPILE_CRC */
+#endif /* LODEPNG_COMPILE_CRC */
/* ////////////////////////////////////////////////////////////////////////// */
/* / Reading and writing PNG color channel bits / */
diff --git a/lodepng.h b/lodepng.h
index e83a508..e5e3ab4 100644
--- a/lodepng.h
+++ b/lodepng.h
@@ -1,5 +1,5 @@
/*
-LodePNG version 20220613
+LodePNG version 20220618
Copyright (c) 2005-2022 Lode Vandevenne
@@ -35,43 +35,50 @@ The following #defines are used to create code sections. They can be disabled
to disable code sections, which can give faster compile time and smaller binary.
The "NO_COMPILE" defines are designed to be used to pass as defines to the
compiler command to disable them without modifying this header, e.g.
--DLODEPNG_NO_COMPILE_ZLIB for gcc.
-In addition to those below, you can also define LODEPNG_NO_COMPILE_CRC to
-allow implementing a custom lodepng_crc32.
+-DLODEPNG_NO_COMPILE_ZLIB for gcc or clang.
*/
/*deflate & zlib. If disabled, you must specify alternative zlib functions in
the custom_zlib field of the compress and decompress settings*/
#ifndef LODEPNG_NO_COMPILE_ZLIB
+/*pass -DLODEPNG_NO_COMPILE_ZLIB to the compiler to disable this, or comment out LODEPNG_COMPILE_ZLIB below*/
#define LODEPNG_COMPILE_ZLIB
#endif
/*png encoder and png decoder*/
#ifndef LODEPNG_NO_COMPILE_PNG
+/*pass -DLODEPNG_NO_COMPILE_PNG to the compiler to disable this, or comment out LODEPNG_COMPILE_PNG below*/
#define LODEPNG_COMPILE_PNG
#endif
/*deflate&zlib decoder and png decoder*/
#ifndef LODEPNG_NO_COMPILE_DECODER
+/*pass -DLODEPNG_NO_COMPILE_DECODER to the compiler to disable this, or comment out LODEPNG_COMPILE_DECODER below*/
#define LODEPNG_COMPILE_DECODER
#endif
/*deflate&zlib encoder and png encoder*/
#ifndef LODEPNG_NO_COMPILE_ENCODER
+/*pass -DLODEPNG_NO_COMPILE_ENCODER to the compiler to disable this, or comment out LODEPNG_COMPILE_ENCODER below*/
#define LODEPNG_COMPILE_ENCODER
#endif
/*the optional built in harddisk file loading and saving functions*/
#ifndef LODEPNG_NO_COMPILE_DISK
+/*pass -DLODEPNG_NO_COMPILE_DISK to the compiler to disable this, or comment out LODEPNG_COMPILE_DISK below*/
#define LODEPNG_COMPILE_DISK
#endif
/*support for chunks other than IHDR, IDAT, PLTE, tRNS, IEND: ancillary and unknown chunks*/
#ifndef LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS
+/*pass -DLODEPNG_NO_COMPILE_ANCILLARY_CHUNKS to the compiler to disable this,
+or comment out LODEPNG_COMPILE_ANCILLARY_CHUNKS below*/
#define LODEPNG_COMPILE_ANCILLARY_CHUNKS
#endif
/*ability to convert error numerical codes to English text string*/
#ifndef LODEPNG_NO_COMPILE_ERROR_TEXT
+/*pass -DLODEPNG_NO_COMPILE_ERROR_TEXT to the compiler to disable this,
+or comment out LODEPNG_COMPILE_ERROR_TEXT below*/
#define LODEPNG_COMPILE_ERROR_TEXT
#endif
@@ -79,12 +86,24 @@ the custom_zlib field of the compress and decompress settings*/
you can define the functions lodepng_free, lodepng_malloc and lodepng_realloc in your
source files with custom allocators.*/
#ifndef LODEPNG_NO_COMPILE_ALLOCATORS
+/*pass -DLODEPNG_NO_COMPILE_ALLOCATORS to the compiler to disable the built-in ones,
+or comment out LODEPNG_COMPILE_ALLOCATORS below*/
#define LODEPNG_COMPILE_ALLOCATORS
#endif
+/*Disable built-in CRC function, in that case a custom implementation of
+lodepng_crc32 must be defined externally so that it can be linked in.*/
+#ifndef LODEPNG_NO_COMPILE_CRC
+/*pass -DLODEPNG_NO_COMPILE_CRC to the compiler to disable the built-in one,
+or comment out LODEPNG_COMPILE_CRC below*/
+#define LODEPNG_COMPILE_CRC
+#endif
+
/*compile the C++ version (you can disable the C++ wrapper here even when compiling for C++)*/
#ifdef __cplusplus
#ifndef LODEPNG_NO_COMPILE_CPP
+/*pass -DLODEPNG_NO_COMPILE_CPP to the compiler to disable C++ (not needed if a C-only compiler),
+or comment out LODEPNG_COMPILE_CPP below*/
#define LODEPNG_COMPILE_CPP
#endif
#endif
diff --git a/lodepng_util.cpp b/lodepng_util.cpp
index 1d76b35..95aaeb1 100644
--- a/lodepng_util.cpp
+++ b/lodepng_util.cpp
@@ -1,7 +1,7 @@
/*
LodePNG Utils
-Copyright (c) 2005-2020 Lode Vandevenne
+Copyright (c) 2005-2022 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
@@ -24,7 +24,6 @@ freely, subject to the following restrictions:
*/
#include "lodepng_util.h"
-#include <iostream> // TODO: remove, don't print stuff from here, return errors instead
#include <stdlib.h> /* allocations */
namespace lodepng {
@@ -489,7 +488,6 @@ static float iccBackwardTRC(const LodePNGICCCurve* curve, float x) {
a = m;
}
}
- return 0;
}
if(curve->type == 2) {
/* Gamma compression */
@@ -539,7 +537,7 @@ static int decodeICCInt32(const unsigned char* data, size_t size, size_t* pos) {
}
static float decodeICC15Fixed16(const unsigned char* data, size_t size, size_t* pos) {
- return decodeICCInt32(data, size, pos) / 65536.0;
+ return decodeICCInt32(data, size, pos) / 65536.0f;
}
static unsigned isICCword(const unsigned char* data, size_t size, size_t pos, const char* word) {
@@ -717,9 +715,9 @@ static unsigned parseICC(LodePNGICC* icc, const unsigned char* data, size_t size
static void mulMatrix(float* x2, float* y2, float* z2, const float* m, double x, double y, double z) {
/* double used as inputs even though in general the images are float, so the sums happen in
double precision, because float can give numerical problems for nearby values */
- *x2 = x * m[0] + y * m[1] + z * m[2];
- *y2 = x * m[3] + y * m[4] + z * m[5];
- *z2 = x * m[6] + y * m[7] + z * m[8];
+ *x2 = (float)(x * m[0] + y * m[1] + z * m[2]);
+ *y2 = (float)(x * m[3] + y * m[4] + z * m[5]);
+ *z2 = (float)(x * m[6] + y * m[7] + z * m[8]);
}
static void mulMatrixMatrix(float* result, const float* a, const float* b) {
@@ -741,7 +739,7 @@ static unsigned invMatrix(float* m) {
double e6 = (double)m[3] * m[7] - (double)m[4] * m[6];
/* inverse determinant */
double d = 1.0 / (m[0] * e0 + m[1] * e3 + m[2] * e6);
- float result[9];
+ double result[9];
if((d > 0 ? d : -d) > 1e15) return 1; /* error, likely not invertible */
result[0] = e0 * d;
result[1] = ((double)m[2] * m[7] - (double)m[1] * m[8]) * d;
@@ -752,7 +750,7 @@ static unsigned invMatrix(float* m) {
result[6] = e6 * d;
result[7] = ((double)m[6] * m[1] - (double)m[0] * m[7]) * d;
result[8] = ((double)m[0] * m[4] - (double)m[3] * m[1]) * d;
- for(i = 0; i < 9; i++) m[i] = result[i];
+ for(i = 0; i < 9; i++) m[i] = (float)result[i];
return 0; /* ok */
}
@@ -1343,8 +1341,8 @@ unsigned convertFromXYZ(unsigned char* out, const float* in, unsigned w, unsigne
for(c = 0; c < 4; c++) {
size_t j = i * 8 + c * 2;
int i16 = (int)(0.5f + 65535.0f * LODEPNG_MIN(LODEPNG_MAX(0.0f, im[i * 4 + c]), 1.0f));
- data[j + 0] = i16 >> 8;
- data[j + 1] = i16 & 255;
+ data[j + 0] = (unsigned char)(i16 >> 8);
+ data[j + 1] = (unsigned char)(i16 & 255);
}
}
error = lodepng_convert(out, data, mode_out, &mode16, w, h);
@@ -1353,8 +1351,7 @@ unsigned convertFromXYZ(unsigned char* out, const float* in, unsigned w, unsigne
LodePNGColorMode mode8 = lodepng_color_mode_make(LCT_RGBA, 8);
for(i = 0; i < n; i++) {
for(c = 0; c < 4; c++) {
- int i8 = (int)(0.5f + 255.0f * LODEPNG_MIN(LODEPNG_MAX(0.0f, im[i * 4 + c]), 1.0f));
- data[i * 4 + c] = i8;
+ data[i * 4 + c] = (unsigned char)(0.5f + 255.0f * LODEPNG_MIN(LODEPNG_MAX(0.0f, im[i * 4 + c]), 1.0f));
}
}
error = lodepng_convert(out, data, mode_out, &mode8, w, h);
@@ -1755,11 +1752,11 @@ struct ExtractPNG { //PNG decoding and information extraction
}
};
-void extractZlibInfo(std::vector<ZlibBlockInfo>& zlibinfo, const std::vector<unsigned char>& in) {
+unsigned extractZlibInfo(std::vector<ZlibBlockInfo>& zlibinfo, const std::vector<unsigned char>& in) {
ExtractPNG decoder(&zlibinfo);
decoder.decode(&in[0], in.size());
- if(decoder.error) std::cout << "extract error: " << decoder.error << std::endl;
+ return decoder.error ? 1 : 0;
}
} // namespace lodepng
diff --git a/lodepng_util.h b/lodepng_util.h
index 97fd804..13b9e9d 100644
--- a/lodepng_util.h
+++ b/lodepng_util.h
@@ -1,7 +1,7 @@
/*
LodePNG Utils
-Copyright (c) 2005-2020 Lode Vandevenne
+Copyright (c) 2005-2022 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
@@ -283,7 +283,8 @@ struct ZlibBlockInfo {
};
//Extracts all info needed from a PNG file to reconstruct the zlib compression exactly.
-void extractZlibInfo(std::vector<ZlibBlockInfo>& zlibinfo, const std::vector<unsigned char>& in);
+// Returns 0 if no error, non-zero value if error
+unsigned extractZlibInfo(std::vector<ZlibBlockInfo>& zlibinfo, const std::vector<unsigned char>& in);
} // namespace lodepng