From 2ccff76a584c8e1566779c8daddc757b9bf87a56 Mon Sep 17 00:00:00 2001 From: Lode Date: Mon, 18 Jan 2016 22:33:46 +0100 Subject: various fixes --- pngdetail.cpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'pngdetail.cpp') diff --git a/pngdetail.cpp b/pngdetail.cpp index d62b6dd..0f2b602 100644 --- a/pngdetail.cpp +++ b/pngdetail.cpp @@ -48,6 +48,7 @@ everything except huge output: #include "lodepng_util.h" #include #include +#include #include #include @@ -169,7 +170,8 @@ void displayChunkNames(const std::vector& buffer, const Options& { std::vector names; std::vector sizes; - lodepng::getChunkInfo(names, sizes, buffer); + unsigned error = lodepng::getChunkInfo(names, sizes, buffer); + if(error) std::cout << "Error while identifying chunks. Listing identified chunks anyway." << std::endl; if(options.show_chunks2) { @@ -197,6 +199,17 @@ void displayChunkNames(const std::vector& buffer, const Options& } std::cout << std::endl; } + + std::map typedict; + for(size_t i = 0; i < names.size(); i++) { + typedict[names[i]] = true; + } + + if(!error) { + if(!typedict["IHDR"]) std::cout << "Error: no IHDR chunk" << std::endl; + if(!typedict["IDAT"]) std::cout << "Error: no IDAT chunk" << std::endl; + if(!typedict["IEND"]) std::cout << "Error: no IEND chunk" << std::endl; + } } void RGBtoHSL(unsigned char r, unsigned char g, unsigned char b, unsigned char* h, unsigned char* s, unsigned char* l) { @@ -784,6 +797,23 @@ unsigned showFileInfo(const std::string& filename, const Options& options) state.info_raw.bitdepth = 16; error = lodepng::decode(image, w, h, state, buffer); + // In case of checksum errors, disable checksums + while (error == 57 || error == 58) { + if(error == 57) + { + std::cout << "Error: invalid CRC checksum" << std::endl; + state.decoder.ignore_crc = 1; + error = lodepng::decode(image, w, h, state, buffer); + } + + if(error == 58) + { + std::cout << "Error: invalid Adler32 checksum" << std::endl; + state.decoder.zlibsettings.ignore_adler32 = 1; + error = lodepng::decode(image, w, h, state, buffer); + } + } + if(error) { std::cout << "Decoder error " << error << ": " << lodepng_error_text(error) << std::endl; -- cgit v1.2.3