From 704904377590487c1a51fb35357a2a84ae0f03b1 Mon Sep 17 00:00:00 2001 From: James Zern Date: Mon, 9 Dec 2013 20:15:54 -0800 Subject: [PATCH] cwebp: print metadata stats when no output file is given this is more consistent with the encode stats Change-Id: I5793062b3b29f5cb891461d6faaa53b43c0a4482 --- examples/cwebp.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/examples/cwebp.c b/examples/cwebp.c index 0e4f4e5d..0fa83d1e 100644 --- a/examples/cwebp.c +++ b/examples/cwebp.c @@ -1024,11 +1024,32 @@ int main(int argc, const char *argv[]) { } } - if (keep_metadata != 0 && out != NULL) { - if (!WriteWebPWithMetadata(out, &picture, &memory_writer, - &metadata, keep_metadata, &metadata_written)) { - fprintf(stderr, "Error writing WebP file with metadata!\n"); - goto Error; + if (keep_metadata != 0) { + if (out != NULL) { + if (!WriteWebPWithMetadata(out, &picture, &memory_writer, + &metadata, keep_metadata, &metadata_written)) { + fprintf(stderr, "Error writing WebP file with metadata!\n"); + goto Error; + } + } else { // output is disabled, just display the metadata stats. + const struct { + const MetadataPayload* const payload; + int flag; + } *iter, info[] = { + { &metadata.exif, METADATA_EXIF }, + { &metadata.iccp, METADATA_ICC }, + { &metadata.xmp, METADATA_XMP }, + { NULL, 0 } + }; + uint32_t unused1 = 0; + uint64_t unused2 = 0; + + for (iter = info; iter->payload != NULL; ++iter) { + if (UpdateFlagsAndSize(iter->payload, !!(keep_metadata & iter->flag), + 0, &unused1, &unused2)) { + metadata_written |= iter->flag; + } + } } }