Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add version flag #179

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion guetzli/guetzli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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
Expand Down Expand Up @@ -67,7 +70,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<void*>(&memstream), [](png_structp png_ptr, png_bytep outBytes, png_size_t byteCountToRead) {
std::istringstream& memstream = *static_cast<std::istringstream*>(png_get_io_ptr(png_ptr));

memstream.read(reinterpret_cast<char*>(outBytes), byteCountToRead);

if (memstream.eof()) png_error(png_ptr, "unexpected end of data");
Expand Down Expand Up @@ -218,6 +221,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"
Expand All @@ -227,6 +231,12 @@ void Usage() {
exit(1);
}

void Version() {
fprintf(stdout,
"Guetzli %s\n", kVersion);
exit(0);
}

} // namespace

int main(int argc, char** argv) {
Expand All @@ -240,6 +250,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")) {
Expand Down