From c35514be86eaf472906620eeafaa007027d8a67b Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Thu, 6 Apr 2017 19:44:41 +0200 Subject: [PATCH] add version flag --- guetzli/guetzli.cc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/guetzli/guetzli.cc b/guetzli/guetzli.cc index 5f78b30b..ec00f5c5 100644 --- a/guetzli/guetzli.cc +++ b/guetzli/guetzli.cc @@ -30,6 +30,9 @@ namespace { +// The current guetzli version +static const char* const kVersion = "1.0.1"; + constexpr int kDefaultJPEGQuality = 95; // An upper estimate of memory usage of Guetzli. The bound is @@ -66,7 +69,7 @@ bool ReadPNG(const std::string& data, int* xsize, int* ysize, std::istringstream memstream(data, std::ios::in | std::ios::binary); png_set_read_fn(png_ptr, static_cast(&memstream), [](png_structp png_ptr, png_bytep outBytes, png_size_t byteCountToRead) { std::istringstream& memstream = *static_cast(png_get_io_ptr(png_ptr)); - + memstream.read(reinterpret_cast(outBytes), byteCountToRead); if (memstream.eof()) png_error(png_ptr, "unexpected end of data"); @@ -217,6 +220,7 @@ void Usage() { "guetzli [flags] input_filename output_filename\n" "\n" "Flags:\n" + " --version - Print version.\n" " --verbose - Print a verbose trace of all attempts to standard output.\n" " --quality Q - Visual quality to aim for, expressed as a JPEG quality value.\n" " Default value is %d.\n" @@ -226,6 +230,12 @@ void Usage() { exit(1); } +void Version() { + fprintf(stdout, + "Guetzli %s\n", kVersion); + exit(0); +} + } // namespace int main(int argc, char** argv) { @@ -239,6 +249,9 @@ int main(int argc, char** argv) { for(;opt_idx < argc;opt_idx++) { if (strnlen(argv[opt_idx], 2) < 2 || argv[opt_idx][0] != '-' || argv[opt_idx][1] != '-') break; + if (!strcmp(argv[opt_idx], "--version")) { + Version(); + } if (!strcmp(argv[opt_idx], "--verbose")) { verbose = 1; } else if (!strcmp(argv[opt_idx], "--quality")) {