lodepng sync with mainstream: merged commits d4d8f1aa and d03d7df9

(excluded 64 bit warning fix commits 9ab58e3 and 116f5b2e for now)

git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@1573 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
Ozkan Sezer 2018-03-26 21:04:10 +00:00
parent 2beab62809
commit 84c2c3c4ea
2 changed files with 42 additions and 18 deletions

View File

@ -1,7 +1,7 @@
/*
LodePNG version 20170917
LodePNG version 20180326
Copyright (c) 2005-2017 Lode Vandevenne
Copyright (c) 2005-2018 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
@ -39,7 +39,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 = "20170917";
const char* LODEPNG_VERSION_STRING = "20180326";
/*
This source file is built up in the following large parts. The code sections
@ -2621,15 +2621,10 @@ static int lodepng_color_mode_equal(const LodePNGColorMode* a, const LodePNGColo
if(a->key_g != b->key_g) return 0;
if(a->key_b != b->key_b) return 0;
}
/*if one of the palette sizes is 0, then we consider it to be the same as the
other: it means that e.g. the palette was not given by the user and should be
considered the same as the palette inside the PNG.*/
if(1/*a->palettesize != 0 && b->palettesize != 0*/) {
if(a->palettesize != b->palettesize) return 0;
for(i = 0; i != a->palettesize * 4; ++i)
{
if(a->palette[i] != b->palette[i]) return 0;
}
if(a->palettesize != b->palettesize) return 0;
for(i = 0; i != a->palettesize * 4; ++i)
{
if(a->palette[i] != b->palette[i]) return 0;
}
return 1;
}
@ -3461,7 +3456,7 @@ unsigned lodepng_convert(unsigned char* out, const unsigned char* in,
{
size_t palettesize = mode_out->palettesize;
const unsigned char* palette = mode_out->palette;
size_t palsize = 1u << mode_out->bitdepth;
size_t palsize = (size_t)1u << mode_out->bitdepth;
/*if the user specified output palette but did not give the values, assume
they want the values of the input color type (assuming that one is palette).
Note that we never create a new palette ourselves.*/
@ -3469,6 +3464,15 @@ unsigned lodepng_convert(unsigned char* out, const unsigned char* in,
{
palettesize = mode_in->palettesize;
palette = mode_in->palette;
/*if the input was also palette with same bitdepth, then the color types are also
equal, so copy literally. This to preserve the exact indices that were in the PNG
even in case there are duplicate colors in the palette.*/
if (mode_in->colortype == LCT_PALETTE && mode_in->bitdepth == mode_out->bitdepth)
{
size_t numbytes = lodepng_get_raw_size(w, h, mode_in);
for(i = 0; i != numbytes; ++i) out[i] = in[i];
return 0;
}
}
if(palettesize < palsize) palsize = palettesize;
color_tree_init(&tree);
@ -4550,12 +4554,20 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
const unsigned char* data; /*the data in the chunk*/
/*error: size of the in buffer too small to contain next chunk*/
if((size_t)((chunk - in) + 12) > insize || chunk < in) CERROR_BREAK(state->error, 30);
if((size_t)((chunk - in) + 12) > insize || chunk < in)
{
if(state->decoder.ignore_end) break; /*other errors may still happen though*/
CERROR_BREAK(state->error, 30);
}
/*length of the data of the chunk, excluding the length bytes, chunk type and CRC bytes*/
chunkLength = lodepng_chunk_length(chunk);
/*error: chunk length larger than the max PNG chunk size*/
if(chunkLength > 2147483647) CERROR_BREAK(state->error, 63);
if(chunkLength > 2147483647)
{
if(state->decoder.ignore_end) break; /*other errors may still happen though*/
CERROR_BREAK(state->error, 63);
}
if((size_t)((chunk - in) + chunkLength + 12) > insize || (chunk + chunkLength + 12) < in)
{
@ -4642,7 +4654,10 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
else /*it's not an implemented chunk type, so ignore it: skip over the data*/
{
/*error: unknown critical chunk (5th bit of first byte of chunk type is 0)*/
if(!lodepng_chunk_ancillary(chunk)) CERROR_BREAK(state->error, 69);
if(!state->decoder.ignore_critical && !lodepng_chunk_ancillary(chunk))
{
CERROR_BREAK(state->error, 69);
}
unknown = 1;
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
@ -4807,6 +4822,8 @@ void lodepng_decoder_settings_init(LodePNGDecoderSettings* settings)
settings->remember_unknown_chunks = 0;
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
settings->ignore_crc = 0;
settings->ignore_critical = 0;
settings->ignore_end = 0;
lodepng_decompress_settings_init(&settings->zlibsettings);
}

View File

@ -1,7 +1,7 @@
/*
LodePNG version 20170917
LodePNG version 20180326
Copyright (c) 2005-2017 Lode Vandevenne
Copyright (c) 2005-2018 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
@ -255,6 +255,7 @@ const char* lodepng_error_text(unsigned code);
typedef struct LodePNGDecompressSettings LodePNGDecompressSettings;
struct LodePNGDecompressSettings
{
/* Check LodePNGDecoderSettings for more ignorable errors */
unsigned ignore_adler32; /*if 1, continue and don't give an error message if the Adler32 checksum is corrupted*/
/*use custom zlib decoder instead of built in one (default: null)*/
@ -520,7 +521,10 @@ typedef struct LodePNGDecoderSettings
{
LodePNGDecompressSettings zlibsettings; /*in here is the setting to ignore Adler32 checksums*/
/* Check LodePNGDecompressSettings for more ignorable errors */
unsigned ignore_crc; /*ignore CRC checksums*/
unsigned ignore_critical; /*ignore unknown critical chunks*/
unsigned ignore_end; /*ignore issues at end of file if possible (missing IEND chunk, too large chunk, ...)*/
unsigned color_convert; /*whether to convert the PNG to the color type you want. Default: yes*/
@ -1567,6 +1571,8 @@ For decoding:
state.decoder.zlibsettings.ignore_adler32: ignore ADLER32 checksums
state.decoder.zlibsettings.custom_...: use custom inflate function
state.decoder.ignore_crc: ignore CRC checksums
state.decoder.ignore_critical: ignore unknown critical chunks
state.decoder.ignore_end: ignore missing IEND chunk. May fail if this corruption causes other errors
state.decoder.color_convert: convert internal PNG color to chosen one
state.decoder.read_text_chunks: whether to read in text metadata chunks
state.decoder.remember_unknown_chunks: whether to read in unknown chunks
@ -1608,6 +1614,7 @@ yyyymmdd.
Some changes aren't backwards compatible. Those are indicated with a (!)
symbol.
*) 14 jan 2018: allow optionally ignoring a few more recoverable errors
*) 17 sep 2017: fix memory leak for some encoder input error cases
*) 27 nov 2016: grey+alpha auto color model detection bugfix
*) 18 apr 2016: Changed qsort to custom stable sort (for platforms w/o qsort).