/* Main */ int main(int argc, char *argv[]) /*list the chunks*/ { bool ignore_checksums = false; std::string filename = ""; for (int i = 1; i < argc; i++) { if(std::string(argv[i]) == "--ignore_checksums") ignore_checksums = true; else filename = argv[i]; } if(filename == "") { std::cout << "Please provide a filename to preview" << std::endl; return 0; } std::vector<unsigned char> buffer; std::vector<unsigned char> image; unsigned w, h; lodepng::load_file(buffer, filename); //load the image file with given filename lodepng::State state; if(ignore_checksums) { state.decoder.ignore_crc = 1; state.decoder.zlibsettings.ignore_adler32 = 1; } unsigned error = lodepng::decode(image, w, h, state, buffer); if(error) { std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl; return 0; } std::cout << "Filesize: " << buffer.size() << " (" << buffer.size() / 1024 << "K)" << std::endl; std::cout << "Width: " << w << std::endl; std::cout << "Height: " << h << std::endl; std::cout << "Num pixels: " << w * h << std::endl; if(w > 0 && h > 0) { std::cout << "Top left pixel color:" << " r: " << (int)image[0] << " g: " << (int)image[1] << " b: " << (int)image[2] << " a: " << (int)image[3] << std::endl; } displayPNGInfo(state.info_png); std::cout << std::endl; displayChunkNames(buffer); std::cout << std::endl; displayFilterTypes(buffer, ignore_checksums); std::cout << std::endl; displayAsciiArt(image, w, h); }
/* Main */ int main(int argc, char *argv[]) /*list the chunks*/ { if(argc < 2) { std::cout << "Please provide a filename to preview" << std::endl; return 0; } const char* filename = argv[1]; std::vector<unsigned char> buffer; std::vector<unsigned char> image; unsigned w, h; lodepng::load_file(buffer, filename); //load the image file with given filename lodepng::State state; unsigned error = lodepng::decode(image, w, h, state, buffer); if(error) { std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl; return 0; } std::cout << "Filesize: " << buffer.size() << " (" << buffer.size() / 1024 << "K)" << std::endl; std::cout << "Width: " << w << std::endl; std::cout << "Height: " << h << std::endl; std::cout << "Num pixels: " << w * h << std::endl; if(w > 0 && h > 0) { std::cout << "Top left pixel color:" << " r: " << (int)image[0] << " g: " << (int)image[1] << " b: " << (int)image[2] << " a: " << (int)image[3] << std::endl; } displayPNGInfo(state.info_png); std::cout << std::endl; displayChunkNames(buffer); std::cout << std::endl; displayFilterTypes(buffer); std::cout << std::endl; displayAsciiArt(image, w, h); }
unsigned showFileInfo(const std::string& filename, const Options& options) { std::vector<unsigned char> buffer; std::vector<unsigned char> image; unsigned w, h; lodepng::load_file(buffer, filename); //load the image file with given filename lodepng::State state; state.info_raw.colortype = LCT_RGBA; state.info_raw.bitdepth = 16; unsigned error = lodepng::decode(image, w, h, state, buffer); if(error) { std::cout << "Decoder error " << error << ": " << lodepng_error_text(error) << std::endl; } bool extra_newlines = false; if(!error && options.show_png_summary) { std::cout << "Filesize: " << buffer.size() << " (" << buffer.size() / 1024 << "K)" << ", "; std::cout << w << "x" << h << ", "; std::cout << "Color: " << colorTypeString(state.info_png.color.colortype) << ", " << state.info_png.color.bitdepth << " bit" << std::endl; if(extra_newlines) std::cout << std::endl; } if(!error && options.show_png_info) { std::cout << "Filesize: " << buffer.size() << " (" << buffer.size() / 1024 << "K)" << std::endl; std::cout << "Width: " << w << std::endl; std::cout << "Height: " << h << std::endl; if(options.show_extra_png_info) std::cout << "Num pixels: " << w * h << std::endl; if(options.show_extra_png_info && w > 0 && h > 0) { std::ios_base::fmtflags flags = std::cout.flags(); std::cout << "Top left pixel color: #" << std::hex << std::setfill('0') << std::setw(2) << (int)image[0] << std::setw(2) << (int)image[1] << std::setw(2) << (int)image[2] << std::setw(2) << (int)image[3] << std::endl; std::cout.flags(flags); } displayPNGInfo(state.info_png, options); if(extra_newlines) std::cout << std::endl; } if(options.show_chunks || options.show_chunks2) { displayChunkNames(buffer, options); if(extra_newlines) std::cout << std::endl; } if(options.show_filters) { displayFilterTypes(buffer); if(extra_newlines) std::cout << std::endl; } if(options.show_palette) { displayPalette(buffer); if(extra_newlines) std::cout << std::endl; } if(options.show_palette_pixels) { displayPalettePixels(buffer); if(extra_newlines) std::cout << std::endl; } if (!error && options.show_ascii_art) { displayAsciiArt(image, w, h, options.ascii_art_size); if(extra_newlines) std::cout << std::endl; } if (!error && (options.show_colors_hex || options.show_colors_hex_16)) { displayColorsHex(image, w, h, options.show_colors_hex_16); if(extra_newlines) std::cout << std::endl; } printZlibInfo(buffer, options); return 0; }