Skip to content

Commit c70fa8b

Browse files
committed
Update zopfli
1 parent b881aa3 commit c70fa8b

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

lib/zopfli/cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void ZopfliInitCache(size_t blocksize, ZopfliLongestMatchCache* lmc) {
3434
if(lmc->sublen == NULL) {
3535
fprintf(stderr,
3636
"Error: Out of memory. Tried allocating %lu bytes of memory.\n",
37-
ZOPFLI_CACHE_LENGTH * 3 * blocksize);
37+
(unsigned long)ZOPFLI_CACHE_LENGTH * 3 * blocksize);
3838
exit (EXIT_FAILURE);
3939
}
4040

lib/zopfli/squeeze.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ static double GetBestLengths(ZopfliBlockState *s,
205205
double* literals; /*Cost of a literal*/
206206
double litlentable[259]; /*Cost of the length bits of a match*/
207207
double disttable[30]; /*Cost of the distance bits of a match*/
208+
double litstack[256];
208209
if(costcontext){
209210
literals = costcontext->ll_symbols;
210211
for (i = 3; i < 259; i++){
@@ -215,7 +216,6 @@ static double GetBestLengths(ZopfliBlockState *s,
215216
}
216217
}
217218
else{
218-
double litstack[256];
219219
literals = litstack;
220220
for (i = 0; i < 256; i++){
221221
literals[i] = 8 + (i > 143);

lib/zopflipng/lodepng/lodepng_util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ unsigned convertToXYZ(float* out, float whitepoint[3], const unsigned char* in,
11511151
use_icc = validateICC(&icc);
11521152
}
11531153

1154-
data = (unsigned char*)lodepng_malloc(w * h * (bit16 ? 8 : 4));
1154+
data = (unsigned char*)lodepng_malloc((size_t)w * (size_t)h * (bit16 ? 8 : 4));
11551155
error = lodepng_convert(data, in, &tempmode, mode_in, w, h);
11561156
if(error) goto cleanup;
11571157

lib/zopflipng/zopflipng_lib.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ ZopfliPNGOptions::ZopfliPNGOptions()
3535
, lossy_transparent(false)
3636
, lossy_8bit(false)
3737
, auto_filter_strategy(true)
38+
, keep_colortype(false)
3839
, use_zopfli(true)
3940
, num_iterations(15)
4041
, num_iterations_large(5)
@@ -379,7 +380,7 @@ int ZopfliPNGOptimize(const std::vector<unsigned char>& origpng,
379380
lodepng::State inputstate;
380381
error = lodepng::decode(image, w, h, inputstate, origpng);
381382

382-
bool keep_colortype = false;
383+
bool keep_colortype = png_options.keep_colortype;
383384

384385
if (!png_options.keepchunks.empty()) {
385386
// If the user wants to keep the non-essential chunks bKGD or sBIT, the
@@ -391,10 +392,12 @@ int ZopfliPNGOptimize(const std::vector<unsigned char>& origpng,
391392
// possible.
392393
std::set<std::string> keepchunks;
393394
ChunksToKeep(origpng, png_options.keepchunks, &keepchunks);
394-
keep_colortype = keepchunks.count("bKGD") || keepchunks.count("sBIT");
395-
if (keep_colortype && verbose) {
396-
printf("Forced to keep original color type due to keeping bKGD or sBIT"
397-
" chunk.\n");
395+
if (keepchunks.count("bKGD") || keepchunks.count("sBIT")) {
396+
if (!keep_colortype && verbose) {
397+
printf("Forced to keep original color type due to keeping bKGD or sBIT"
398+
" chunk.\n");
399+
}
400+
keep_colortype = true;
398401
}
399402
}
400403

lib/zopflipng/zopflipng_lib.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ struct ZopfliPNGOptions {
105105
// Automatically choose filter strategy using less good compression
106106
bool auto_filter_strategy;
107107

108+
// Keep original color type (RGB, RGBA, gray, gray+alpha or palette) and bit
109+
// depth of the PNG.
110+
// This results in a loss of compression opportunities, e.g. it will no
111+
// longer convert a 4-channel RGBA image to 2-channel gray+alpha if the image
112+
// only had translucent gray pixels.
113+
// May be useful if a device does not support decoding PNGs of a particular
114+
// color type.
115+
// Default value: false.
116+
bool keep_colortype;
117+
108118
// PNG chunks to keep
109119
// chunks to literally copy over from the original PNG to the resulting one
110120
std::vector<std::string> keepchunks;

0 commit comments

Comments
 (0)