From 9e9b36c1ed44612f0ca49e04cbb3d774dd87e2c7 Mon Sep 17 00:00:00 2001 From: Lode Date: Sun, 24 Jan 2016 20:27:52 +0100 Subject: various updates --- lodepng.cpp | 2 +- lodepng.h | 41 ++++++++++++++++++++++++++++---- lodepng_unittest.cpp | 67 ++++++++++++++++++++++++++++++++++++++++------------ 3 files changed, 90 insertions(+), 20 deletions(-) diff --git a/lodepng.cpp b/lodepng.cpp index 8e6e368..057e750 100644 --- a/lodepng.cpp +++ b/lodepng.cpp @@ -1768,7 +1768,7 @@ static unsigned deflateDynamic(ucvector* out, size_t* bp, Hash* hash, else { if(!uivector_resize(&lz77_encoded, datasize)) ERROR_BREAK(83 /*alloc fail*/); - for(i = datapos; i < dataend; ++i) lz77_encoded.data[i-datapos] = data[i]; /*no LZ77, but still will be Huffman compressed*/ + for(i = datapos; i < dataend; ++i) lz77_encoded.data[i - datapos] = data[i]; /*no LZ77, but still will be Huffman compressed*/ } if(!uivector_resizev(&frequencies_ll, 286, 0)) ERROR_BREAK(83 /*alloc fail*/); diff --git a/lodepng.h b/lodepng.h index 2cda86f..24097db 100644 --- a/lodepng.h +++ b/lodepng.h @@ -927,8 +927,9 @@ LodePNG Documentation 10. examples 10.1. decoder C++ example 10.2. decoder C example - 11. changes - 12. contact information + 11. state settings reference + 12. changes + 13. contact information 1. about @@ -1554,8 +1555,40 @@ int main(int argc, char *argv[]) return 0; } +11. state settings reference +---------------------------- -11. changes +A quick reference of some settings to set on the LodePNGState + +For decoding: + +state.decoder.zlibsettings.ignore_adler32: ignore ADLER32 checksups +state.decoder.ignore_crc: ignore CRC checksums +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 +state.info_raw.colortype: desired color type for decoded image +state.info_raw.bitdepth: desired bit depth for decoded image + +For encoding: + +state.encoder.zlibsettings.btype: disable compression by setting it to 0 +state.encoder.zlibsettings.use_lz77: use LZ77 in compression +state.encoder.zlibsettings.windowsize: tweak LZ77 windowsize +state.encoder.zlibsettings.minmatch: tweak min LZ77 length to match +state.encoder.zlibsettings.nicematch: tweak LZ77 match where to stop searching +state.encoder.zlibsettings.lazymatching: try one more LZ77 matching +state.encoder.auto_convert: choose optimal PNG color type, if 0 uses raw format +state.encoder.filter_palette_zero: PNG filter strategy for palette +state.encoder.filter_strategy: PNG filter strategy to encode with +state.encoder.force_palette: add palette even if not encoding to one +state.encoder.add_id: add LodePNG identifier and version as a text chunk +state.encoder.text_compression: use compressed text chunks for metadata +state.info_raw.colortype: color type of raw input image you provide +state.info_raw.bitdepth: bit depth of raw input image you provide + + +12. changes ----------- The version number of LodePNG is the date of the change given in the format @@ -1697,7 +1730,7 @@ symbol. *) 12 aug 2005: Initial release (C++, decoder only) -12. contact information +13. contact information ----------------------- Feel free to contact me with suggestions, problems, comments, ... concerning diff --git a/lodepng_unittest.cpp b/lodepng_unittest.cpp index 6d9cbab..8259db5 100644 --- a/lodepng_unittest.cpp +++ b/lodepng_unittest.cpp @@ -299,15 +299,11 @@ void doCodecTestC(Image& image) struct OnExitScope { - unsigned char* a; - unsigned char* b; - OnExitScope(unsigned char* ca, unsigned char* cb) : a(ca), b(cb) {} - ~OnExitScope() - { - free(a); - free(b); - } - } onExitScope(encoded, decoded); + unsigned char** a; + unsigned char** b; + OnExitScope(unsigned char** ca, unsigned char** cb) : a(ca), b(cb) {} + ~OnExitScope() { free(*a); free(*b); } + } onExitScope(&encoded, &decoded); unsigned error_enc = lodepng_encode_memory(&encoded, &encoded_size, &image.data[0], image.width, image.height, image.colorType, image.bitDepth); @@ -327,9 +323,6 @@ void doCodecTestC(Image& image) ASSERT_EQUALS(image.width, decoded_w); ASSERT_EQUALS(image.height, decoded_h); assertPixels(image, decoded, "Pixels C"); - - free(decoded); - free(encoded); } //Test LodePNG encoding and decoding the encoded result, using the C++ interface @@ -358,6 +351,45 @@ void doCodecTestCPP(Image& image) assertPixels(image, &decoded[0], "Pixels C++"); } + +void doCodecTestWithEncState(Image& image, lodepng::State& state) { + std::vector encoded; + std::vector decoded; + unsigned decoded_w; + unsigned decoded_h; + state.info_raw.colortype = image.colorType; + state.info_raw.bitdepth = image.bitDepth; + + + unsigned error_enc = lodepng::encode(encoded, image.data, image.width, image.height, state); + assertNoPNGError(error_enc, "encoder error uncompressed"); + + unsigned error_dec = lodepng::decode(decoded, decoded_w, decoded_h, encoded, image.colorType, image.bitDepth); + + assertNoPNGError(error_dec, "decoder error uncompressed"); + + ASSERT_EQUALS(image.width, decoded_w); + ASSERT_EQUALS(image.height, decoded_h); + ASSERT_EQUALS(image.data.size(), decoded.size()); + assertPixels(image, &decoded[0], "Pixels uncompressed"); +} + + +//Test LodePNG encoding and decoding the encoded result, using the C++ interface +void doCodecTestUncompressed(Image& image) +{ + lodepng::State state; + state.encoder.zlibsettings.btype = 0; + doCodecTestWithEncState(image, state); +} + +void doCodecTestNoLZ77(Image& image) +{ + lodepng::State state; + state.encoder.zlibsettings.use_lz77 = 0; + doCodecTestWithEncState(image, state); +} + //Test LodePNG encoding and decoding the encoded result, using the C++ interface, with interlace void doCodecTestInterlaced(Image& image) { @@ -373,7 +405,7 @@ void doCodecTestInterlaced(Image& image) unsigned error_enc = lodepng::encode(encoded, image.data, image.width, image.height, state); - assertNoPNGError(error_enc, "encoder error C++"); + assertNoPNGError(error_enc, "encoder error interlaced"); //if the image is large enough, compressing it should result in smaller size if(image.data.size() > 512) assertTrue(encoded.size() < image.data.size(), "compressed size"); @@ -382,12 +414,12 @@ void doCodecTestInterlaced(Image& image) state.info_raw.bitdepth = image.bitDepth; unsigned error_dec = lodepng::decode(decoded, decoded_w, decoded_h, state, encoded); - assertNoPNGError(error_dec, "decoder error C++"); + assertNoPNGError(error_dec, "decoder error interlaced"); ASSERT_EQUALS(image.width, decoded_w); ASSERT_EQUALS(image.height, decoded_h); ASSERT_EQUALS(image.data.size(), decoded.size()); - assertPixels(image, &decoded[0], "Pixels C++"); + assertPixels(image, &decoded[0], "Pixels interlaced"); } //Test LodePNG encoding and decoding the encoded result @@ -396,6 +428,8 @@ void doCodecTest(Image& image) doCodecTestC(image); doCodecTestCPP(image); doCodecTestInterlaced(image); + doCodecTestUncompressed(image); + doCodecTestNoLZ77(image); } @@ -603,6 +637,9 @@ void testPNGCodec() codecTest(7, 7, LCT_GREY, 1); codecTest(127, 127); codecTest(127, 127, LCT_GREY, 1); + codecTest(500, 500); + codecTest(1, 10000); + codecTest(10000, 1); testOtherPattern1(); testOtherPattern2(); -- cgit v1.2.3