Merge "allow 'cwebp -o -' to emit output to stdout"

This commit is contained in:
James Zern 2014-03-12 14:01:15 -07:00 committed by Gerrit Code Review
commit 24ca3678f9
2 changed files with 18 additions and 12 deletions

View File

@ -310,18 +310,18 @@ static void PrintMapInfo(const WebPPicture* const pic) {
for (x = 0; x < mb_w; ++x) { for (x = 0; x < mb_w; ++x) {
const int c = pic->extra_info[x + y * mb_w]; const int c = pic->extra_info[x + y * mb_w];
if (type == 1) { // intra4/intra16 if (type == 1) { // intra4/intra16
printf("%c", "+."[c]); fprintf(stderr, "%c", "+."[c]);
} else if (type == 2) { // segments } else if (type == 2) { // segments
printf("%c", ".-*X"[c]); fprintf(stderr, "%c", ".-*X"[c]);
} else if (type == 3) { // quantizers } else if (type == 3) { // quantizers
printf("%.2d ", c); fprintf(stderr, "%.2d ", c);
} else if (type == 6 || type == 7) { } else if (type == 6 || type == 7) {
printf("%3d ", c); fprintf(stderr, "%3d ", c);
} else { } else {
printf("0x%.2x ", c); fprintf(stderr, "0x%.2x ", c);
} }
} }
printf("\n"); fprintf(stderr, "\n");
} }
} }
} }
@ -534,9 +534,8 @@ static int WriteWebPWithMetadata(FILE* const out,
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
static int ProgressReport(int percent, const WebPPicture* const picture) { static int ProgressReport(int percent, const WebPPicture* const picture) {
printf("[%s]: %3d %% \r", fprintf(stderr, "[%s]: %3d %% \r",
(char*)picture->user_data, percent); (char*)picture->user_data, percent);
fflush(stdout);
return 1; // all ok return 1; // all ok
} }
@ -975,8 +974,9 @@ int main(int argc, const char *argv[]) {
} }
// Open the output // Open the output
if (out_file) { if (out_file != NULL) {
out = fopen(out_file, "wb"); const int use_stdout = !strcmp(out_file, "-");
out = use_stdout ? stdout : fopen(out_file, "wb");
if (out == NULL) { if (out == NULL) {
fprintf(stderr, "Error! Cannot open output file '%s'\n", out_file); fprintf(stderr, "Error! Cannot open output file '%s'\n", out_file);
goto Error; goto Error;
@ -1126,7 +1126,7 @@ int main(int argc, const char *argv[]) {
MetadataFree(&metadata); MetadataFree(&metadata);
WebPPictureFree(&picture); WebPPictureFree(&picture);
WebPPictureFree(&original_picture); WebPPictureFree(&original_picture);
if (out != NULL) { if (out != NULL && out != stdout) {
fclose(out); fclose(out);
} }

View File

@ -19,6 +19,12 @@ The basic options are:
.BI \-o " string .BI \-o " string
Specify the name of the output WebP file. If omitted, \fBcwebp\fP will Specify the name of the output WebP file. If omitted, \fBcwebp\fP will
perform compression but only report statistics. perform compression but only report statistics.
Using "\-" as output name will direct output to 'stdout'.
.TP
.BI \-\- " string
Explicitly specify the input file. This option is useful if the input
file starts with an '\-' for instance. This option must appear \fBlast\fP.
Any other options afterward will be ignored.
.TP .TP
.B \-h, \-help .B \-h, \-help
A short usage summary. A short usage summary.