From 41a5d99d55577c6a214ffb8b1dcef79ccf5fa435 Mon Sep 17 00:00:00 2001 From: skal Date: Mon, 17 Aug 2015 20:07:46 -0700 Subject: [PATCH] add a -quiet option to 'dwebp' (useful for tests) Change-Id: Ia07f407bc1e819a1d3cab64a02317d058733261b --- README | 1 + examples/dwebp.c | 34 ++++++++++++++++++++++------------ man/dwebp.1 | 5 ++++- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/README b/README index fbf4b2f9..2d7fc970 100644 --- a/README +++ b/README @@ -279,6 +279,7 @@ Use following options to convert into alternate image formats: -incremental . use incremental decoding (useful for tests) -h ....... this help message -v ....... verbose (e.g. print encoding/decoding times) + -quiet ....... quiet mode, don't print anything -noasm ....... disable all assembly optimizations Visualization tool: diff --git a/examples/dwebp.c b/examples/dwebp.c index 4d95819f..0233dac7 100644 --- a/examples/dwebp.c +++ b/examples/dwebp.c @@ -555,6 +555,7 @@ static void Help(void) { " -incremental . use incremental decoding (useful for tests)\n" " -h ....... this help message\n" " -v ....... verbose (e.g. print encoding/decoding times)\n" + " -quiet ....... quiet mode, don't print anything\n" #ifndef WEBP_DLL " -noasm ....... disable all assembly optimizations\n" #endif @@ -569,6 +570,7 @@ int main(int argc, const char *argv[]) { int ok = 0; const char *in_file = NULL; const char *out_file = NULL; + int quiet = 0; WebPDecoderConfig config; WebPDecBuffer* const output_buffer = &config.output; @@ -603,6 +605,8 @@ int main(int argc, const char *argv[]) { format = BMP; } else if (!strcmp(argv[c], "-tiff")) { format = TIFF; + } else if (!strcmp(argv[c], "-quiet")) { + quiet = 1; } else if (!strcmp(argv[c], "-version")) { const int version = WebPGetDecoderVersion(); printf("%d.%d.%d\n", @@ -665,6 +669,8 @@ int main(int argc, const char *argv[]) { return -1; } + if (quiet) verbose = 0; + { VP8StatusCode status = VP8_STATUS_OK; size_t data_size = 0; @@ -721,20 +727,24 @@ int main(int argc, const char *argv[]) { } if (out_file != NULL) { - fprintf(stderr, "Decoded %s. Dimensions: %d x %d %s. Format: %s. " - "Now saving...\n", - in_file, output_buffer->width, output_buffer->height, - bitstream->has_alpha ? " (with alpha)" : "", - kFormatType[bitstream->format]); + if (!quiet) { + fprintf(stderr, "Decoded %s. Dimensions: %d x %d %s. Format: %s. " + "Now saving...\n", + in_file, output_buffer->width, output_buffer->height, + bitstream->has_alpha ? " (with alpha)" : "", + kFormatType[bitstream->format]); + } ok = SaveOutput(output_buffer, format, out_file); } else { - fprintf(stderr, "File %s can be decoded " - "(dimensions: %d x %d %s. Format: %s).\n", - in_file, output_buffer->width, output_buffer->height, - bitstream->has_alpha ? " (with alpha)" : "", - kFormatType[bitstream->format]); - fprintf(stderr, "Nothing written; " - "use -o flag to save the result as e.g. PNG.\n"); + if (!quiet) { + fprintf(stderr, "File %s can be decoded " + "(dimensions: %d x %d %s. Format: %s).\n", + in_file, output_buffer->width, output_buffer->height, + bitstream->has_alpha ? " (with alpha)" : "", + kFormatType[bitstream->format]); + fprintf(stderr, "Nothing written; " + "use -o flag to save the result as e.g. PNG.\n"); + } } Exit: WebPFreeDecBuffer(output_buffer); diff --git a/man/dwebp.1 b/man/dwebp.1 index 0e7cd985..1b9a26aa 100644 --- a/man/dwebp.1 +++ b/man/dwebp.1 @@ -1,5 +1,5 @@ .\" Hey, EMACS: -*- nroff -*- -.TH DWEBP 1 "August 13, 2015" +.TH DWEBP 1 "August 17, 2015" .SH NAME dwebp \- decompress a WebP file to an image file .SH SYNOPSIS @@ -98,6 +98,9 @@ is applied \fIafter\fP cropping. If either (but not both) of the \fBwidth\fP or \fBheight\fP parameters is 0, the value will be calculated preserving the aspect-ratio. .TP +.B \-quiet +Do not print anything. +.TP .B \-v Print extra information (decoding time in particular). .TP