cwebp: add -metadata option

currently has no effect except to disable metadata extraction from the
input when the value is 'none'.

Change-Id: Ic50d4c9d634cc1f6b72ae4e130e99736c85a6477
This commit is contained in:
James Zern 2013-01-11 12:25:36 -08:00
parent 36c52c2cf1
commit 7eaee9f1ac
3 changed files with 77 additions and 2 deletions

4
README
View File

@ -171,6 +171,10 @@ options:
-hint <string> ......... Specify image characteristics hint. -hint <string> ......... Specify image characteristics hint.
One of: photo, picture or graph One of: photo, picture or graph
-metadata <string> ..... comma separated list of metadata to
copy from the input to the output if present.
Valid values: all, none (default), exif, iccp, xmp
-short ................. condense printed message -short ................. condense printed message
-quiet ................. don't print anything. -quiet ................. don't print anything.
-version ............... print version number and exit. -version ............... print version number and exit.

View File

@ -545,6 +545,16 @@ static int DumpPicture(const WebPPicture* const picture, const char* PGM_name) {
return 1; return 1;
} }
// -----------------------------------------------------------------------------
// Metadata writing.
enum {
METADATA_EXIF = (1 << 0),
METADATA_ICCP = (1 << 1),
METADATA_XMP = (1 << 2),
METADATA_ALL = METADATA_EXIF | METADATA_ICCP | METADATA_XMP
};
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
static int ProgressReport(int percent, const WebPPicture* const picture) { static int ProgressReport(int percent, const WebPPicture* const picture) {
@ -617,6 +627,13 @@ static void HelpLong(void) {
printf(" -hint <string> ......... Specify image characteristics hint.\n"); printf(" -hint <string> ......... Specify image characteristics hint.\n");
printf(" One of: photo, picture or graph\n"); printf(" One of: photo, picture or graph\n");
printf("\n");
printf(" -metadata <string> ..... comma separated list of metadata to\n");
printf(" ");
printf("copy from the input to the output if present.\n");
printf(" "
"Valid values: all, none (default), exif, iccp, xmp\n");
printf("\n"); printf("\n");
printf(" -short ................. condense printed message\n"); printf(" -short ................. condense printed message\n");
printf(" -quiet ................. don't print anything.\n"); printf(" -quiet ................. don't print anything.\n");
@ -669,6 +686,7 @@ int main(int argc, const char *argv[]) {
int crop = 0, crop_x = 0, crop_y = 0, crop_w = 0, crop_h = 0; int crop = 0, crop_x = 0, crop_y = 0, crop_w = 0, crop_h = 0;
int resize_w = 0, resize_h = 0; int resize_w = 0, resize_h = 0;
int show_progress = 0; int show_progress = 0;
int keep_metadata = 0;
WebPPicture picture; WebPPicture picture;
int print_distortion = -1; // -1=off, 0=PSNR, 1=SSIM, 2=LSIM int print_distortion = -1; // -1=off, 0=PSNR, 1=SSIM, 2=LSIM
WebPPicture original_picture; // when PSNR or SSIM is requested WebPPicture original_picture; // when PSNR or SSIM is requested
@ -832,6 +850,50 @@ int main(int argc, const char *argv[]) {
fprintf(stderr, "Error! Could initialize configuration with preset.\n"); fprintf(stderr, "Error! Could initialize configuration with preset.\n");
goto Error; goto Error;
} }
} else if (!strcmp(argv[c], "-metadata") && c < argc - 1) {
static const struct {
const char* option;
int flag;
} kTokens[] = {
{ "all", METADATA_ALL },
{ "none", 0 },
{ "exif", METADATA_EXIF },
{ "iccp", METADATA_ICCP },
{ "xmp", METADATA_XMP },
};
const size_t kNumTokens = sizeof(kTokens) / sizeof(kTokens[0]);
const char* start = argv[++c];
const char* const end = start + strlen(start);
while (start < end) {
size_t i;
const char* token = strchr(start, ',');
if (token == NULL) token = end;
for (i = 0; i < kNumTokens; ++i) {
if ((size_t)(token - start) == strlen(kTokens[i].option) &&
!strncmp(start, kTokens[i].option, strlen(kTokens[i].option))) {
if (kTokens[i].flag != 0) {
keep_metadata |= kTokens[i].flag;
} else {
keep_metadata = 0;
}
break;
}
}
if (i == kNumTokens) {
fprintf(stderr, "Error! Unknown metadata type '%.*s'\n",
(int)(token - start), start);
HelpLong();
return -1;
}
start = token + 1;
}
if (keep_metadata != 0) {
// TODO(jzern): remove when -metadata is supported on all platforms.
fprintf(stderr, "Warning: -metadata is currently unsupported on this"
" platform. Ignoring this option!\n");
}
} else if (!strcmp(argv[c], "-v")) { } else if (!strcmp(argv[c], "-v")) {
verbose = 1; verbose = 1;
} else if (argv[c][0] == '-') { } else if (argv[c][0] == '-') {
@ -870,7 +932,8 @@ int main(int argc, const char *argv[]) {
if (verbose) { if (verbose) {
StopwatchReadAndReset(&stop_watch); StopwatchReadAndReset(&stop_watch);
} }
if (!ReadPicture(in_file, &picture, keep_alpha, &metadata)) { if (!ReadPicture(in_file, &picture, keep_alpha,
(keep_metadata == 0) ? NULL : &metadata)) {
fprintf(stderr, "Error! Cannot read input picture file '%s'\n", in_file); fprintf(stderr, "Error! Cannot read input picture file '%s'\n", in_file);
goto Error; goto Error;
} }

View File

@ -1,5 +1,5 @@
.\" Hey, EMACS: -*- nroff -*- .\" Hey, EMACS: -*- nroff -*-
.TH CWEBP 1 "November 15, 2012" .TH CWEBP 1 "January 11, 2013"
.SH NAME .SH NAME
cwebp \- compress an image file to a WebP file cwebp \- compress an image file to a WebP file
.SH SYNOPSIS .SH SYNOPSIS
@ -172,6 +172,14 @@ Encode the image without any loss.
Specify the hint about input image type. Possible values are: Specify the hint about input image type. Possible values are:
\fBphoto\fP, \fBpicture\fP or \fBgraph\fP. \fBphoto\fP, \fBpicture\fP or \fBgraph\fP.
.TP .TP
.B \-metadata string
A comma separated list of metadata to copy from the input to the output if
present.
Valid values: \fBall\fP, \fBnone\fP, \fBexif\fP, \fBiccp\fP, \fBxmp\fP.
The default is \fBnone\fP.
Note: each input format may not support all combinations.
.TP
.B \-noasm .B \-noasm
Disable all assembly optimizations. Disable all assembly optimizations.
.TP .TP