examples: logging updates

- send errors to stderr
- send help to stdout
- add image size to webpmux -info output and send to stdout
- correct webpmux exit values

Change-Id: Ifd8e8493aab33a82765f7b7903cef345d96da9ae
This commit is contained in:
James Zern 2012-01-24 12:46:46 -08:00
parent 6c14aaddc4
commit 974aaff360
5 changed files with 117 additions and 123 deletions

View File

@ -8,49 +8,53 @@ Description:
============
WebP Mux: library to create the MUX container object for features like
Color profile, XMP metadata, Animation & Tiling. A reference command line
tool 'webpmux' and Mux container specification 'MuxContainerSpec.pdf' are also
provided in this package.
color profile, XMP metadata, animation & tiling. A reference command line
tool 'webpmux' and Mux container specification 'doc/webp-container-spec.txt'
are also provided in this package.
WebP Mux tool:
==============
The examples/ directory contains tool (webpmux) for manipulating the WebP Mux
file. webpmux tool can be used to create a WebP container file and to extract or
strip relevant data from the container file.
The examples/ directory contains a tool (webpmux) for manipulating the WebP Mux
file. The webpmux tool can be used to create a WebP container file and to
extract or strip relevant data from the container file.
A list of options is available using the -help command line flag:
> webpmux -help
Usage: webpmux -get GET_OPTIONS INPUT -o OUTPUT
or: webpmux -set SET_OPTIONS INPUT -o OUTPUT
or: webpmux -strip STRIP_OPTIONS INPUT -o OUTPUT
or: webpmux [-tile TILE_OPTIONS]... -o OUTPUT
or: webpmux [-frame FRAME_OPTIONS]... -loop LOOP_COUNT -o OUTPUT
or: webpmux -info INPUT
or: webpmux -help OR -h
webpmux -set SET_OPTIONS INPUT -o OUTPUT
webpmux -strip STRIP_OPTIONS INPUT -o OUTPUT
webpmux -tile TILE_OPTIONS [-tile...] -o OUTPUT
webpmux -frame FRAME_OPTIONS [-frame...] -loop LOOP_COUNT -o OUTPUT
webpmux -info INPUT
webpmux [-h|-help]
GET_OPTIONS:
Extract relevant data.
icc Get ICCP Color profile.
xmp Get XMP metadata.
tile n Get nth tile.
frame n Get nth frame.
SET_OPTIONS:
Set color profile/metadata.
icc Set ICC Color profile.
xmp Set XMP metadata.
STRIP_OPTIONS:
Strip color profile/metadata.
icc Strip ICCP color profile.
xmp Strip XMP metadata.
TILE_OPTIONS(i):
Create tiled image.
file_i +xi+yi
where: 'file_i' is the i'th tile (webp format),
'xi','yi' specify the image offset for this tile.
FRAME_OPTIONS(i):
Create animation.
file_i +xi+yi+di
where: 'file_i' is the i'th animation frame (webp format),
'xi','yi' specify the image offset for this frame.
@ -58,8 +62,6 @@ FRAME_OPTIONS(i):
INPUT & OUTPUT are in webp format.
WebP Mux API:
==============
WebP Mux API contains methods for adding data to WebPMux (a MUX container object
@ -101,7 +103,6 @@ Example#2 (pseudo code): Get image & color profile data from a WebP file.
For detailed MUX-API reference, please refer to the header file (src/webp/mux.h)
Bugs:
=====

View File

@ -104,7 +104,7 @@ static int ReadYUV(FILE* in_file, WebPPicture* const pic) {
{ \
hr = (fn); \
if (FAILED(hr) && verbose) \
printf(#fn " failed %08x\n", hr); \
fprintf(stderr, #fn " failed %08x\n", hr); \
} \
} while (0)
@ -118,7 +118,7 @@ static HRESULT OpenInputStream(const char* filename, IStream** ppStream) {
HRESULT hr = S_OK;
IFS(SHCreateStreamOnFileA(filename, STGM_READ, ppStream));
if (FAILED(hr))
printf("Error opening input file %s (%08x)\n", filename, hr);
fprintf(stderr, "Error opening input file %s (%08x)\n", filename, hr);
return hr;
}
@ -148,9 +148,10 @@ static HRESULT ReadPictureWithWIC(const char* filename,
CLSCTX_INPROC_SERVER, MAKE_REFGUID(IID_IWICImagingFactory),
(LPVOID*)&pFactory));
if (hr == REGDB_E_CLASSNOTREG) {
printf("Couldn't access Windows Imaging Component (are you running \n");
printf("Windows XP SP3 or newer?). Most formats not available.\n");
printf("Use -s for the available YUV input.\n");
fprintf(stderr,
"Couldn't access Windows Imaging Component (are you running "
"Windows XP SP3 or newer?). Most formats not available. "
"Use -s for the available YUV input.\n");
}
// Prepare for image decoding.
IFS(OpenInputStream(filename, &pStream));
@ -158,7 +159,7 @@ static HRESULT ReadPictureWithWIC(const char* filename,
WICDecodeMetadataCacheOnDemand, &pDecoder));
IFS(IWICBitmapDecoder_GetFrameCount(pDecoder, &frameCount));
if (SUCCEEDED(hr) && frameCount == 0) {
printf("No frame found in input file.\n");
fprintf(stderr, "No frame found in input file.\n");
hr = E_FAIL;
}
IFS(IWICBitmapDecoder_GetFrame(pDecoder, 0, &pFrame));
@ -333,8 +334,8 @@ static int ReadJPEG(FILE* in_file, WebPPicture* const pic) {
static int ReadJPEG(FILE* in_file, WebPPicture* const pic) {
(void)in_file;
(void)pic;
printf("JPEG support not compiled. Please install the libjpeg development "
"package before building.\n");
fprintf(stderr, "JPEG support not compiled. Please install the libjpeg "
"development package before building.\n");
return 0;
}
#endif
@ -433,8 +434,8 @@ static int ReadPNG(FILE* in_file, WebPPicture* const pic, int keep_alpha) {
(void)in_file;
(void)pic;
(void)keep_alpha;
printf("PNG support not compiled. Please install the libpng development "
"package before building.\n");
fprintf(stderr, "PNG support not compiled. Please install the libpng "
"development package before building.\n");
return 0;
}
#endif

View File

@ -71,7 +71,7 @@ typedef enum {
{ \
hr = (fn); \
if (FAILED(hr) && verbose) \
printf(#fn " failed %08x\n", hr); \
fprintf(stderr, #fn " failed %08x\n", hr); \
} \
} while (0)
@ -86,7 +86,7 @@ static HRESULT CreateOutputStream(const char* out_file_name,
HRESULT hr = S_OK;
IFS(SHCreateStreamOnFileA(out_file_name, STGM_WRITE | STGM_CREATE, ppStream));
if (FAILED(hr))
printf("Error opening output file %s (%08x)\n", out_file_name, hr);
fprintf(stderr, "Error opening output file %s (%08x)\n", out_file_name, hr);
return hr;
}
@ -106,9 +106,10 @@ static HRESULT WriteUsingWIC(const char* out_file_name, REFGUID container_guid,
CLSCTX_INPROC_SERVER, MAKE_REFGUID(IID_IWICImagingFactory),
(LPVOID*)&pFactory));
if (hr == REGDB_E_CLASSNOTREG) {
printf("Couldn't access Windows Imaging Component (are you running \n");
printf("Windows XP SP3 or newer?). PNG support not available.\n");
printf("Use -ppm or -pgm for available PPM and PGM formats.\n");
fprintf(stderr,
"Couldn't access Windows Imaging Component (are you running "
"Windows XP SP3 or newer?). PNG support not available. "
"Use -ppm or -pgm for available PPM and PGM formats.\n");
}
IFS(CreateOutputStream(out_file_name, &pStream));
IFS(IWICImagingFactory_CreateEncoder(pFactory, container_guid, NULL,
@ -189,15 +190,12 @@ static int WritePNG(FILE* out_file, const WebPDecBuffer* const buffer) {
return 1;
}
#else // !HAVE_WINCODEC_H && !WEBP_HAVE_PNG
typedef uint32_t png_uint_32;
static int WritePNG(FILE* out_file, const WebPDecBuffer* const buffer) {
(void)out_file;
(void)buffer;
printf("PNG support not compiled. Please install the libpng development "
"package before building.\n");
printf("You can run with -ppm flag to decode in PPM format.\n");
fprintf(stderr, "PNG support not compiled. Please install the libpng "
"development package before building.\n");
fprintf(stderr, "You can run with -ppm flag to decode in PPM format.\n");
return 0;
}
#endif
@ -396,7 +394,7 @@ int main(int argc, const char *argv[]) {
VP8GetCPUInfo = NULL;
#endif
} else if (argv[c][0] == '-') {
printf("Unknown option '%s'\n", argv[c]);
fprintf(stderr, "Unknown option '%s'\n", argv[c]);
Help();
return -1;
} else {
@ -405,7 +403,7 @@ int main(int argc, const char *argv[]) {
}
if (in_file == NULL) {
printf("missing input file!!\n");
fprintf(stderr, "missing input file!!\n");
Help();
return -1;
}

View File

@ -164,39 +164,40 @@ static WebPMuxError DisplayInfo(const WebPMux* mux) {
}
// Print the features present.
fprintf(stderr, "Features present:");
if (flag & ANIMATION_FLAG) fprintf(stderr, " animation");
if (flag & TILE_FLAG) fprintf(stderr, " tiling");
if (flag & ICCP_FLAG) fprintf(stderr, " icc profile");
if (flag & META_FLAG) fprintf(stderr, " metadata");
if (flag & ALPHA_FLAG) fprintf(stderr, " transparency");
fprintf(stderr, "\n");
printf("Features present:");
if (flag & ANIMATION_FLAG) printf(" animation");
if (flag & TILE_FLAG) printf(" tiling");
if (flag & ICCP_FLAG) printf(" icc profile");
if (flag & META_FLAG) printf(" metadata");
if (flag & ALPHA_FLAG) printf(" transparency");
printf("\n");
if (flag & ANIMATION_FLAG) {
int nFrames;
uint32_t loop_count;
err = WebPMuxGetLoopCount(mux, &loop_count);
RETURN_IF_ERROR("Failed to retrieve loop count\n");
fprintf(stderr, "Loop Count : %d\n", loop_count);
printf("Loop Count : %d\n", loop_count);
err = WebPMuxNumNamedElements(mux, "frame", &nFrames);
RETURN_IF_ERROR("Failed to retrieve number of frames\n");
fprintf(stderr, "Number of frames: %d\n", nFrames);
printf("Number of frames: %d\n", nFrames);
if (nFrames > 0) {
int i;
uint32_t x_offset, y_offset, duration;
fprintf(stderr, "No.: x_offset y_offset duration");
if (flag & ALPHA_FLAG) fprintf(stderr, " alpha_size");
fprintf(stderr, "\n");
printf("No.: x_offset y_offset duration image_size");
if (flag & ALPHA_FLAG) printf(" alpha_size");
printf("\n");
for (i = 1; i <= nFrames; i++) {
uint32_t x_offset, y_offset, duration;
WebPData image, alpha;
err = WebPMuxGetFrame(mux, i, &image, &alpha,
&x_offset, &y_offset, &duration);
RETURN_IF_ERROR2("Failed to retrieve frame#%d\n", i);
fprintf(stderr, "%3d: %8d %8d %8d", i, x_offset, y_offset, duration);
if (flag & ALPHA_FLAG) fprintf(stderr, " %10u", alpha.size_);
fprintf(stderr, "\n");
printf("%3d: %8d %8d %8d %10u",
i, x_offset, y_offset, duration, image.size_);
if (flag & ALPHA_FLAG) printf(" %10u", alpha.size_);
printf("\n");
}
}
}
@ -206,20 +207,21 @@ static WebPMuxError DisplayInfo(const WebPMux* mux) {
err = WebPMuxNumNamedElements(mux, "tile", &nTiles);
RETURN_IF_ERROR("Failed to retrieve number of tiles\n");
fprintf(stderr, "Number of tiles: %d\n", nTiles);
printf("Number of tiles: %d\n", nTiles);
if (nTiles > 0) {
int i;
uint32_t x_offset, y_offset;
fprintf(stderr, "No.: x_offset y_offset");
if (flag & ALPHA_FLAG) fprintf(stderr, " alpha_size");
fprintf(stderr, "\n");
printf("No.: x_offset y_offset image_size");
if (flag & ALPHA_FLAG) printf(" alpha_size");
printf("\n");
for (i = 1; i <= nTiles; i++) {
WebPData image, alpha;
err = WebPMuxGetTile(mux, i, &image, &alpha, &x_offset, &y_offset);
RETURN_IF_ERROR2("Failed to retrieve tile#%d\n", i);
fprintf(stderr, "%3d: %8d %8d", i, x_offset, y_offset);
if (flag & ALPHA_FLAG) fprintf(stderr, " %10u", alpha.size_);
fprintf(stderr, "\n");
printf("%3d: %8d %8d %10u",
i, x_offset, y_offset, image.size_);
if (flag & ALPHA_FLAG) printf(" %10u", alpha.size_);
printf("\n");
}
}
}
@ -228,79 +230,72 @@ static WebPMuxError DisplayInfo(const WebPMux* mux) {
WebPData icc_profile;
err = WebPMuxGetColorProfile(mux, &icc_profile);
RETURN_IF_ERROR("Failed to retrieve the color profile\n");
fprintf(stderr, "Size of the color profile data: %u\n", icc_profile.size_);
printf("Size of the color profile data: %u\n", icc_profile.size_);
}
if (flag & META_FLAG) {
WebPData metadata;
err = WebPMuxGetMetadata(mux, &metadata);
RETURN_IF_ERROR("Failed to retrieve the XMP metadata\n");
fprintf(stderr, "Size of the XMP metadata: %u\n", metadata.size_);
printf("Size of the XMP metadata: %u\n", metadata.size_);
}
if ((flag & ALPHA_FLAG) && !(flag & (ANIMATION_FLAG | TILE_FLAG))) {
WebPData image, alpha;
err = WebPMuxGetImage(mux, &image, &alpha);
RETURN_IF_ERROR("Failed to retrieve the image\n");
fprintf(stderr, "Size of the alpha data: %u\n", alpha.size_);
printf("Size of the alpha data: %u\n", alpha.size_);
}
return WEBP_MUX_OK;
}
static void PrintHelp(void) {
fprintf(stderr, "Usage: webpmux -get GET_OPTIONS INPUT -o OUTPUT "
" Extract relevant data.\n");
fprintf(stderr, " or: webpmux -set SET_OPTIONS INPUT -o OUTPUT "
" Set color profile/metadata.\n");
fprintf(stderr, " or: webpmux -strip STRIP_OPTIONS INPUT -o OUTPUT "
" Strip color profile/metadata.\n");
fprintf(stderr, " or: webpmux [-tile TILE_OPTIONS]... -o OUTPUT "
" Create tiled image.\n");
fprintf(stderr, " or: webpmux [-frame FRAME_OPTIONS]... -loop LOOP_COUNT"
" -o OUTPUT Create animation.\n");
fprintf(stderr, " or: webpmux -info INPUT "
" Print info about given webp file.\n");
fprintf(stderr, " or: webpmux -help OR -h "
" Print this help.\n");
printf("Usage: webpmux -get GET_OPTIONS INPUT -o OUTPUT\n");
printf(" webpmux -set SET_OPTIONS INPUT -o OUTPUT\n");
printf(" webpmux -strip STRIP_OPTIONS INPUT -o OUTPUT\n");
printf(" webpmux -tile TILE_OPTIONS [-tile...] -o OUTPUT\n");
printf(" webpmux -frame FRAME_OPTIONS [-frame...]");
printf(" -loop LOOP_COUNT -o OUTPUT\n");
printf(" webpmux -info INPUT\n");
printf(" webpmux [-h|-help]\n");
fprintf(stderr, "\n");
fprintf(stderr, "GET_OPTIONS:\n");
fprintf(stderr, " icc Get ICCP Color profile.\n");
fprintf(stderr, " xmp Get XMP metadata.\n");
fprintf(stderr, " tile n Get nth tile.\n");
fprintf(stderr, " frame n Get nth frame.\n");
printf("\n");
printf("GET_OPTIONS:\n");
printf(" Extract relevant data.\n");
printf(" icc Get ICCP Color profile.\n");
printf(" xmp Get XMP metadata.\n");
printf(" tile n Get nth tile.\n");
printf(" frame n Get nth frame.\n");
fprintf(stderr, "\n");
fprintf(stderr, "SET_OPTIONS:\n");
fprintf(stderr, " icc Set ICC Color profile.\n");
fprintf(stderr, " xmp Set XMP metadata.\n");
printf("\n");
printf("SET_OPTIONS:\n");
printf(" Set color profile/metadata.\n");
printf(" icc Set ICC Color profile.\n");
printf(" xmp Set XMP metadata.\n");
fprintf(stderr, "\n");
fprintf(stderr, "STRIP_OPTIONS:\n");
fprintf(stderr, " icc Strip ICCP color profile.\n");
fprintf(stderr, " xmp Strip XMP metadata.\n");
printf("\n");
printf("STRIP_OPTIONS:\n");
printf(" Strip color profile/metadata.\n");
printf(" icc Strip ICCP color profile.\n");
printf(" xmp Strip XMP metadata.\n");
fprintf(stderr, "\n");
fprintf(stderr, "TILE_OPTIONS(i):\n");
fprintf(stderr, " file_i +xi+yi\n");
fprintf(stderr, " where: 'file_i' is the i'th tile (webp format),\n");
fprintf(stderr, " 'xi','yi' specify the image offset for this "
"tile.\n");
printf("\n");
printf("TILE_OPTIONS(i):\n");
printf(" Create tiled image.\n");
printf(" file_i +xi+yi\n");
printf(" where: 'file_i' is the i'th tile (webp format),\n");
printf(" 'xi','yi' specify the image offset for this tile.\n");
fprintf(stderr, "\n");
fprintf(stderr, "FRAME_OPTIONS(i):\n");
fprintf(stderr, " file_i +xi+yi+di\n");
fprintf(stderr, " where: 'file_i' is the i'th animation frame (webp "
"format),\n");
fprintf(stderr, " 'xi','yi' specify the image offset for this "
"frame.\n");
fprintf(stderr, " 'di' is the pause duration before next frame."
"\n");
printf("\n");
printf("FRAME_OPTIONS(i):\n");
printf(" Create animation.\n");
printf(" file_i +xi+yi+di\n");
printf(" where: 'file_i' is the i'th animation frame (webp format),\n");
printf(" 'xi','yi' specify the image offset for this frame.\n");
printf(" 'di' is the pause duration before next frame.\n");
fprintf(stderr, "\n");
fprintf(stderr, "INPUT & OUTPUT are in webp format.");
fprintf(stderr, "\n");
printf("\nINPUT & OUTPUT are in webp format.\n");
}
static int ReadData(const char* filename, void** data_ptr, uint32_t* size_ptr) {
@ -654,7 +649,7 @@ static int ParseCommandLine(int argc, const char* argv[],
} else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "-help")) {
PrintHelp();
DeleteConfig(config);
exit(1);
exit(0);
} else {
ERROR_GOTO2("ERROR: Unknown option: '%s'.\n", argv[i], ErrParse);
}
@ -1028,16 +1023,15 @@ static int Process(const WebPMuxConfig* config) {
// Main.
int main(int argc, const char* argv[]) {
int ok = 1;
WebPMuxConfig* config;
ok = InitializeConfig(argc-1, argv+1, &config);
int ok = InitializeConfig(argc - 1, argv + 1, &config);
if (ok) {
Process(config);
ok = Process(config);
} else {
PrintHelp();
}
DeleteConfig(config);
return ok;
return !ok;
}
//------------------------------------------------------------------------------

View File

@ -1,5 +1,5 @@
.\" Hey, EMACS: -*- nroff -*-
.TH WEBPMUX 1 "November 3, 2011"
.TH WEBPMUX 1 "January 24, 2012"
.SH NAME
webpmux \- command line tool to create WebP Mux/container file.
.SH SYNOPSIS
@ -21,14 +21,14 @@ webpmux \- command line tool to create WebP Mux/container file.
.B \-o
.I OUTPUT
.br
.B webpmux [ \-tile
.B webpmux \-tile
.I TILE_OPTIONS
.B ]... \-o
.B [\-tile...] \-o
.I OUTPUT
.br
.B webpmux [ \-frame
.B webpmux \-frame
.I FRAME_OPTIONS
.B ]... \-loop
.B [\-frame...] \-loop
.I LOOP_COUNT
.B \-o
.I OUTPUT
@ -36,7 +36,7 @@ webpmux \- command line tool to create WebP Mux/container file.
.B webpmux \-info
.I INPUT
.br
.B webpmux \-help
.B webpmux [\-h|\-help]
.SH DESCRIPTION
This manual page documents the
.B webpmux