aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLode Vandevenne <lode@google.com>2019-10-26 11:31:51 +0200
committerLode Vandevenne <lode@google.com>2019-10-26 11:31:51 +0200
commit2f940d2b0b2a2894766d220785a435fd58d11679 (patch)
treea6145c17aa99838c50e027e32747ebe3ac15afaa
parent5d9b71b3c636e9e14a8f7a3f983ff93a1a3793ac (diff)
downloadzopfli-2f940d2b0b2a2894766d220785a435fd58d11679.tar.gz
Update lodepng to latest version
-rw-r--r--src/zopflipng/lodepng/lodepng.cpp22
-rw-r--r--src/zopflipng/lodepng/lodepng.h10
-rw-r--r--src/zopflipng/lodepng/lodepng_util.cpp22
3 files changed, 41 insertions, 13 deletions
diff --git a/src/zopflipng/lodepng/lodepng.cpp b/src/zopflipng/lodepng/lodepng.cpp
index 02bf99b..977bca2 100644
--- a/src/zopflipng/lodepng/lodepng.cpp
+++ b/src/zopflipng/lodepng/lodepng.cpp
@@ -1,5 +1,5 @@
/*
-LodePNG version 20190914
+LodePNG version 20191020
Copyright (c) 2005-2019 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 = "20190914";
+const char* LODEPNG_VERSION_STRING = "20191020";
/*
This source file is built up in the following large parts. The code sections
@@ -2672,6 +2672,9 @@ unsigned lodepng_palette_add(LodePNGColorMode* info,
lodepng_color_mode_alloc_palette(info);
if(!info->palette) return 83; /*alloc fail*/
}
+ if(info->palettesize >= 256) {
+ return 108; /*too many palette values*/
+ }
info->palette[4 * info->palettesize + 0] = r;
info->palette[4 * info->palettesize + 1] = g;
info->palette[4 * info->palettesize + 2] = b;
@@ -3450,6 +3453,10 @@ unsigned lodepng_convert(unsigned char* out, const unsigned char* in,
size_t numpixels = (size_t)w * (size_t)h;
unsigned error = 0;
+ if(mode_in->colortype == LCT_PALETTE && !mode_in->palette) {
+ return 107; /* error: must provide palette if input mode is palette */
+ }
+
if(lodepng_color_mode_equal(mode_out, mode_in)) {
size_t numbytes = lodepng_get_raw_size(w, h, mode_in);
for(i = 0; i != numbytes; ++i) out[i] = in[i];
@@ -4814,6 +4821,11 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
if(!IEND) chunk = lodepng_chunk_next_const(chunk);
}
+ if (state->info_png.color.colortype == LCT_PALETTE
+ && !state->info_png.color.palette) {
+ state->error = 106; /* error: PNG file must have PLTE chunk if color type is palette */
+ }
+
/*predict output size, to allocate exact size for output buffer to avoid more dynamic allocation.
If the decompressed size does not match the prediction, the image must be corrupt.*/
if(state->info_png.interlace_method == 0) {
@@ -4872,8 +4884,7 @@ unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h,
state->error = lodepng_color_mode_copy(&state->info_raw, &state->info_png.color);
if(state->error) return state->error;
}
- } else {
- /*color conversion needed; sort of copy of the data*/
+ } else { /*color conversion needed*/
unsigned char* data = *out;
size_t outsize;
@@ -6110,6 +6121,9 @@ const char* lodepng_error_text(unsigned code) {
case 103: return "invalid palette index in bKGD chunk. Maybe it came before PLTE chunk?";
case 104: return "invalid bKGD color while encoding (e.g. palette index out of range)";
case 105: return "integer overflow of bitsize";
+ case 106: return "PNG file must have PLTE chunk if color type is palette";
+ case 107: return "color convert from palette mode requested without setting the palette data in it";
+ case 108: return "tried to add more than 256 values to a palette";
}
return "unknown error code";
}
diff --git a/src/zopflipng/lodepng/lodepng.h b/src/zopflipng/lodepng/lodepng.h
index 9f21210..26ebe04 100644
--- a/src/zopflipng/lodepng/lodepng.h
+++ b/src/zopflipng/lodepng/lodepng.h
@@ -1,5 +1,5 @@
/*
-LodePNG version 20190914
+LodePNG version 20191020
Copyright (c) 2005-2019 Lode Vandevenne
@@ -335,9 +335,11 @@ typedef struct LodePNGColorMode {
palette (PLTE and tRNS)
Dynamically allocated with the colors of the palette, including alpha.
- When encoding a PNG, to store your colors in the palette of the LodePNGColorMode, first use
- lodepng_palette_clear, then for each color use lodepng_palette_add.
- If you encode an image without alpha with palette, don't forget to put value 255 in each A byte of the palette.
+ This field may not be allocated directly, use lodepng_color_mode_init first,
+ then lodepng_palette_add per color to correctly initialize it (to ensure size
+ of exactly 1024 bytes).
+
+ The alpha channels must be set as well, set them to 255 for opaque images.
When decoding, by default you can ignore this palette, since LodePNG already
fills the palette colors in the pixels of the raw RGBA output.
diff --git a/src/zopflipng/lodepng/lodepng_util.cpp b/src/zopflipng/lodepng/lodepng_util.cpp
index 9ceebe7..bfee116 100644
--- a/src/zopflipng/lodepng/lodepng_util.cpp
+++ b/src/zopflipng/lodepng/lodepng_util.cpp
@@ -277,9 +277,15 @@ void* lodepng_malloc(size_t size);
void lodepng_free(void* ptr);
#endif /*LODEPNG_COMPILE_ALLOCATORS*/
-/* avoid needing <float.h> for FLT_MAX */
+/* avoid needing <float.h> for FLT_MAX. This assumes IEEE 32-bit float. */
static const float lodepng_flt_max = 3.40282346638528859811704183484516925e38f;
+/* define infinity and NaN in a way compatible with ANSI C90 (no INFINITY or NAN macros) yet also with visual studio */
+/* visual studio doesn't allow division through zero literal, but allows it through variable set to zero */
+static const float lodepng_flt_zero_ = 0.0f;
+static const float lodepng_flt_inf = 1.0f / lodepng_flt_zero_; /* infinity */
+static const float lodepng_flt_nan = 0.0f / lodepng_flt_zero_; /* not a number */
+
/* powf polyfill, 5-6 digits accurate, 33% slower than powf, assumes IEEE
32-bit float, but other than that multiplatform and no math lib needed
(note: powf also isn't in ISO C90, and pow is slower). */
@@ -296,11 +302,17 @@ static float lodepng_powf(float x, float y) {
} else {
if(!(y < -1073741824.0f || y > 1073741824.0f)) { /* large y always even integer, but cast would overflow */
i = (int)y;
- if(i != y) return (x < -lodepng_flt_max) ? (y < 0 ? 0 : (1 / 0.0f)) : (x == 0 ? (y < 0 ? 1 / 0.0f : 0) : (0 / 0.0f));
+ if(i != y) {
+ return (x < -lodepng_flt_max) ? (y < 0 ? 0 : lodepng_flt_inf) :
+ (x == 0 ? (y < 0 ? lodepng_flt_inf : 0) : lodepng_flt_nan);
+ }
if(i & 1) return x == 0 ? (y < 0 ? (1 / x) : x) : -lodepng_powf(-x, y);
}
- if(x == 0) return y <= 0 ? (1 / 0.0f) : 0;
- if(x < -lodepng_flt_max) return y <= 0 ? (y == 0 ? 1 : 0) : ((i & 1) ? (-1 / 0.0f) : (1 / 0.0f)); /* x = -infinity */
+ if(x == 0) return y <= 0 ? lodepng_flt_inf : 0;
+ if(x < -lodepng_flt_max) { /* x == -infinity */
+ return y <= 0 ? (y == 0 ? 1 : 0) : ((i & 1) ?
+ -lodepng_flt_inf : lodepng_flt_inf);
+ }
x = -x;
if(x == 1) return 1;
}
@@ -319,7 +331,7 @@ static float lodepng_powf(float x, float y) {
x *= y; /* using the formula exp2(y * log2(x)) */
- if(!(x > -128.0f && x < 128.0f)) return x > 0 ? (1 / 0.0f) : 0; /* prevent int overflow */
+ if(!(x > -128.0f && x < 128.0f)) return x > 0 ? lodepng_flt_inf : 0; /* prevent int overflow */
i = (int)x;
x -= i;
/* polynomial to approximate exp2(x) with x in range -1..1 */