OcPngLib: Merge functional lodepng changes from upstream

This commit is contained in:
vit9696 2019-04-03 04:41:47 +03:00
parent bef05a853f
commit a830c0f938
2 changed files with 44 additions and 22 deletions

View File

@ -1,5 +1,5 @@
/*
LodePNG version 20181230
LodePNG version 20190210
Copyright (c) 2018 savvas
Copyright (c) 2018 vit9696
@ -122,7 +122,7 @@ void* lodepng_realloc(void* ptr, size_t new_size) {
#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 = "20181230";
const char* LODEPNG_VERSION_STRING = "20190210";
/*
This source file is built up in the following large parts. The code sections
@ -2772,6 +2772,7 @@ static unsigned lodepng_assign_icc(LodePNGInfo* info, const char* name, const un
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);
}
@ -2781,6 +2782,7 @@ void lodepng_clear_icc(LodePNGInfo* info) {
lodepng_free(info->iccp_profile);
info->iccp_profile = NULL;
info->iccp_profile_size = 0;
info->iccp_defined = 0;
}
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
@ -4415,8 +4417,10 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
unsigned critical_pos = 1; /*1 = after IHDR, 2 = after PLTE, 3 = after IDAT*/
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
/*provide some proper output values if error will happen*/
/* safe output values in case error happens */
*out = 0;
*w = *h = 0;
state->error = lodepng_inspect(w, h, state, in, insize); /*reads header and resets other parameters in state->info_png*/
if(state->error) return;
@ -4648,6 +4652,9 @@ unsigned lodepng_decode_file(unsigned char** out, unsigned* w, unsigned* h, cons
unsigned char* buffer = 0;
size_t buffersize;
unsigned error;
/* safe output values in case error happens */
*out = 0;
*w = *h = 0;
error = lodepng_load_file(&buffer, &buffersize, filename);
if(!error) error = lodepng_decode_memory(out, w, h, buffer, buffersize, colortype, bitdepth);
lodepng_free(buffer);
@ -5999,6 +6006,8 @@ unsigned decode(std::vector<unsigned char>& out, unsigned& w, unsigned& h,
unsigned decode(std::vector<unsigned char>& out, unsigned& w, unsigned& h, const std::string& filename,
LodePNGColorType colortype, unsigned bitdepth) {
std::vector<unsigned char> buffer;
/* safe output values in case error happens */
w = h = 0;
unsigned error = load_file(buffer, filename);
if(error) return error;
return decode(out, w, h, buffer, colortype, bitdepth);

View File

@ -1,5 +1,5 @@
/*
LodePNG version 20181230
LodePNG version 20190210
Copyright (c) 2018 savvas
Copyright (c) 2018 vit9696
@ -1071,17 +1071,21 @@ 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
[ ] support all public PNG chunk types (almost done except sBIT, sPLT and hIST)
[ ] 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
[X] better name for the variables "codes", "codesD", "codelengthcodes", "clcl" and "lldl"
[ ] don't stop decoding on errors like 69, 57, 58 (make warnings)
[ ] allow treating some errors like warnings, when image is recoverable (e.g. 69, 57, 58)
[ ] make warnings like: oob palette, checksum fail, data after iend, wrong/unknown crit chunk, no null terminator in text, ...
[ ] errors with line numbers (and version)
[ ] error messages with line numbers (and version)
[ ] errors in state instead of as return code?
[ ] new errors/warnings like suspiciously big decompressed ztxt or iccp chunk
[ ] let the C++ wrapper catch exceptions coming from the standard library and return LodePNG error codes
[ ] allow user to provide custom color conversion functions, e.g. for premultiplied alpha, padding bits or not, ...
[ ] allow user to give data (void*) to custom allocator
[ ] provide alternatives for C library functions not present on some platforms (memcpy, ...)
[ ] rename "grey" to "gray" everywhere since "color" also uses US spelling (keep "grey" copies for backwards compatibility)
*/
#endif /*LODEPNG_H inclusion guard*/
@ -1176,8 +1180,10 @@ The following features are supported by the decoder:
*) zlib decompression (inflate)
*) zlib compression (deflate)
*) CRC32 and ADLER32 checksums
*) colorimetric color profile conversions: currently experimentally available in lodepng_util.cpp only,
plus alternatively ability to pass on chroma/gamma/ICC profile information to other color management system.
*) handling of unknown chunks, allowing making a PNG editor that stores custom and unknown chunks.
*) the following chunks are supported (generated/interpreted) by both encoder and decoder:
*) the following chunks are supported by both encoder and decoder:
IHDR: header information
PLTE: color palette
IDAT: pixel data
@ -1189,6 +1195,10 @@ The following features are supported by the decoder:
bKGD: suggested background color
pHYs: physical dimensions
tIME: modification time
cHRM: RGB chromaticities
gAMA: RGB gamma correction
iCCP: ICC color profile
sRGB: rendering intent
1.2. features not supported
---------------------------
@ -1197,10 +1207,10 @@ The following features are _not_ supported:
*) some features needed to make a conformant PNG-Editor might be still missing.
*) partial loading/stream processing. All data must be available and is processed in one call.
*) The following public chunks are not supported but treated as unknown chunks by LodePNG
cHRM, gAMA, iCCP, sRGB, sBIT, hIST, sPLT
Some of these are not supported on purpose: LodePNG wants to provide the RGB values
stored in the pixels, not values modified by system dependent gamma or color models.
*) The following public chunks are not (yet) supported but treated as unknown chunks by LodePNG:
sBIT
hIST
sPLT
2. C and C++ version
@ -1454,15 +1464,22 @@ To avoid some confusion:
the raw image correctly before encoding.
-both encoder and decoder use the same color converter.
The function lodepng_convert does the color conversion. It is available in the
interface but normally isn't needed since the encoder and decoder already call
it.
Non supported color conversions:
-color to grayscale: no error is thrown, but the result will look ugly because
only the red channel is taken
-anything to palette when that palette does not have that color in it: in this
case an error is thrown
-color to grayscale when non-gray pixels are present: no error is thrown, but
the result will look ugly because only the red channel is taken (it assumes all
three channels are the same in this case so ignores green and blue). The reason
no error is given is to allow converting from three-channel grayscale images to
one-channel even if there are numerical imprecisions.
-anything to palette when the palette does not have an exact match for a from-color
in it: in this case an error is thrown
Supported color conversions:
-anything to 8-bit RGB, 8-bit RGBA, 16-bit RGB, 16-bit RGBA
-any grey or grey+alpha, to grey or grey+alpha
-any gray or gray+alpha, to gray or gray+alpha
-anything to a palette, as long as the palette has the requested colors in it
-removing alpha channel
-higher to smaller bitdepth, and vice versa
@ -1475,10 +1492,6 @@ false.
as the PNG has, by setting the color_convert setting to false. Settings in
info_raw are then ignored.
The function lodepng_convert does the color conversion. It is available in the
interface but normally isn't needed since the encoder and decoder already call
it.
6.3. padding bits
-----------------
@ -1948,5 +1961,5 @@ Domain: gmail dot com.
Account: lode dot vandevenne.
Copyright (c) 2005-2018 Lode Vandevenne
Copyright (c) 2005-2019 Lode Vandevenne
*/