examples: slight cleanup

spelling/indent/condense a few lines
removal/restriction of extern "C" usage
add const where applicable

Change-Id: Idd49b3498b1d7fc391724b4cde63706022217cb0
This commit is contained in:
James Zern 2011-11-04 15:20:08 -07:00
parent abd030b573
commit 04e84cf1f1
3 changed files with 71 additions and 88 deletions

View File

@ -54,9 +54,17 @@ DEFINE_GUID(GUID_WICPixelFormat32bppRGBA,
#include "webp/encode.h" #include "webp/encode.h"
#include "stopwatch.h" #include "stopwatch.h"
#ifndef WEBP_DLL #ifndef WEBP_DLL
extern void* VP8GetCPUInfo; // opaque forward declaration. #if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif #endif
extern void* VP8GetCPUInfo; // opaque forward declaration.
#if defined(__cplusplus) || defined(c_plusplus)
} // extern "C"
#endif
#endif // WEBP_DLL
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
static int verbose = 0; static int verbose = 0;

View File

@ -40,14 +40,18 @@
#include "webp/decode.h" #include "webp/decode.h"
#include "stopwatch.h" #include "stopwatch.h"
static int verbose = 0;
#ifndef WEBP_DLL
#if defined(__cplusplus) || defined(c_plusplus) #if defined(__cplusplus) || defined(c_plusplus)
extern "C" { extern "C" {
#endif #endif
static int verbose = 0;
#ifndef WEBP_DLL
extern void* VP8GetCPUInfo; // opaque forward declaration. extern void* VP8GetCPUInfo; // opaque forward declaration.
#if defined(__cplusplus) || defined(c_plusplus)
} // extern "C"
#endif #endif
#endif // WEBP_DLL
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -493,7 +497,3 @@ int main(int argc, const char *argv[]) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#if defined(__cplusplus) || defined(c_plusplus)
} // extern "C"
#endif

View File

@ -8,7 +8,7 @@
// Simple command-line to create a WebP container file and to extract or strip // Simple command-line to create a WebP container file and to extract or strip
// relevant data from the container file. // relevant data from the container file.
// //
// Compile with: gcc -o webpmux webpmux.c -lwebpmux // Compile with: gcc -o webpmux webpmux.c -lwebpmux -lwebp
// //
// //
// Authors: Vikas (vikaas.arora@gmail.com), // Authors: Vikas (vikaas.arora@gmail.com),
@ -17,7 +17,6 @@
/* Usage examples: /* Usage examples:
Create container WebP file: Create container WebP file:
webpmux -tile tile_1.webp +0+0 \ webpmux -tile tile_1.webp +0+0 \
-tile tile_2.webp +960+0 \ -tile tile_2.webp +960+0 \
-tile tile_3.webp +0+576 \ -tile tile_3.webp +0+576 \
@ -32,35 +31,21 @@
-o out_animation_container.webp -o out_animation_container.webp
webpmux -set icc image_profile.icc in.webp -o out_icc_container.webp webpmux -set icc image_profile.icc in.webp -o out_icc_container.webp
webpmux -set xmp image_metadata.xmp in.webp -o out_xmp_container.webp webpmux -set xmp image_metadata.xmp in.webp -o out_xmp_container.webp
Extract relevant data from WebP container file: Extract relevant data from WebP container file:
webpmux -get tile n in.webp -o out_tile.webp webpmux -get tile n in.webp -o out_tile.webp
webpmux -get frame n in.webp -o out_frame.webp webpmux -get frame n in.webp -o out_frame.webp
webpmux -get icc in.webp -o image_profile.icc webpmux -get icc in.webp -o image_profile.icc
webpmux -get xmp in.webp -o image_metadata.xmp webpmux -get xmp in.webp -o image_metadata.xmp
Strip data from WebP Container file: Strip data from WebP Container file:
webpmux -strip icc in.webp -o out.webp
webmux -strip icc in.webp -o out.webp webpmux -strip xmp in.webp -o out.webp
webmux -strip xmp in.webp -o out.webp
Misc: Misc:
webpmux -info in.webp webpmux -info in.webp
webpmux [ -h | -help ]
webpmux -help
webpmux -h
*/ */
#include <assert.h> #include <assert.h>
@ -69,10 +54,6 @@
#include <string.h> #include <string.h>
#include "webp/mux.h" #include "webp/mux.h"
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Config object to parse command-line arguments. // Config object to parse command-line arguments.
@ -121,7 +102,7 @@ typedef struct {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Helper functions. // Helper functions.
static int CountOccurences(const char* arglist[], int list_length, static int CountOccurrences(const char* arglist[], int list_length,
const char* arg) { const char* arg) {
int i; int i;
int num_occurences = 0; int num_occurences = 0;
@ -151,19 +132,25 @@ static int IsNotCompatible(int count1, int count2) {
} }
#define ERROR_GOTO1(ERR_MSG, LABEL) \ #define ERROR_GOTO1(ERR_MSG, LABEL) \
do { \
fprintf(stderr, ERR_MSG); \ fprintf(stderr, ERR_MSG); \
ok = 0; \ ok = 0; \
goto LABEL; goto LABEL; \
} while (0)
#define ERROR_GOTO2(ERR_MSG, FORMAT_STR, LABEL) \ #define ERROR_GOTO2(ERR_MSG, FORMAT_STR, LABEL) \
do { \
fprintf(stderr, ERR_MSG, FORMAT_STR); \ fprintf(stderr, ERR_MSG, FORMAT_STR); \
ok = 0; \ ok = 0; \
goto LABEL; goto LABEL; \
} while (0)
#define ERROR_GOTO3(ERR_MSG, FORMAT_STR1, FORMAT_STR2, LABEL) \ #define ERROR_GOTO3(ERR_MSG, FORMAT_STR1, FORMAT_STR2, LABEL) \
do { \
fprintf(stderr, ERR_MSG, FORMAT_STR1, FORMAT_STR2); \ fprintf(stderr, ERR_MSG, FORMAT_STR1, FORMAT_STR2); \
ok = 0; \ ok = 0; \
goto LABEL; goto LABEL; \
} while (0)
static WebPMuxError DisplayInfo(const WebPMux* mux) { static WebPMuxError DisplayInfo(const WebPMux* mux) {
int nFrames; int nFrames;
@ -202,7 +189,7 @@ static WebPMuxError DisplayInfo(const WebPMux* mux) {
int i; int i;
uint32_t x_offset, y_offset, duration; uint32_t x_offset, y_offset, duration;
fprintf(stderr, "No : x_offset y_offset duration\n"); fprintf(stderr, "No.: x_offset y_offset duration\n");
for (i = 1; i <= nFrames; i++) { for (i = 1; i <= nFrames; i++) {
err = WebPMuxGetFrame(mux, i, &data, &size, &x_offset, &y_offset, err = WebPMuxGetFrame(mux, i, &data, &size, &x_offset, &y_offset,
&duration); &duration);
@ -220,7 +207,7 @@ static WebPMuxError DisplayInfo(const WebPMux* mux) {
if (nTiles > 0) { if (nTiles > 0) {
int i; int i;
uint32_t x_offset, y_offset; uint32_t x_offset, y_offset;
fprintf(stderr, "No : x_offset y_offset\n"); fprintf(stderr, "No.: x_offset y_offset\n");
for (i = 1; i <= nTiles; i++) { for (i = 1; i <= nTiles; i++) {
err = WebPMuxGetTile(mux, i, &data, &size, &x_offset, &y_offset); err = WebPMuxGetTile(mux, i, &data, &size, &x_offset, &y_offset);
assert(err == WEBP_MUX_OK); assert(err == WEBP_MUX_OK);
@ -404,7 +391,7 @@ static int ReadImageData(const char* filename, int image_index,
static int WriteData(const char* filename, void* data, uint32_t size) { static int WriteData(const char* filename, void* data, uint32_t size) {
int ok = 0; int ok = 0;
FILE* fout = strcmp(filename, "--") ? fopen(filename, "wb") : stdout; FILE* fout = strcmp(filename, "-") ? fopen(filename, "wb") : stdout;
if (!fout) { if (!fout) {
fprintf(stderr, "Error opening output WebP file %s!\n", filename); fprintf(stderr, "Error opening output WebP file %s!\n", filename);
return 0; return 0;
@ -472,29 +459,26 @@ static int ValidateCommandLine(int argc, const char* argv[],
*num_feature_args = 0; *num_feature_args = 0;
// Simple checks. // Simple checks.
if (CountOccurences(argv, argc, "-get") > 1) { if (CountOccurrences(argv, argc, "-get") > 1) {
ERROR_GOTO1("ERROR: Multiple '-get' arguments specified.\n", ErrValidate); ERROR_GOTO1("ERROR: Multiple '-get' arguments specified.\n", ErrValidate);
} }
if (CountOccurences(argv, argc, "-set") > 1) { if (CountOccurrences(argv, argc, "-set") > 1) {
ERROR_GOTO1("ERROR: Multiple '-set' arguments specified.\n", ErrValidate); ERROR_GOTO1("ERROR: Multiple '-set' arguments specified.\n", ErrValidate);
} }
if (CountOccurences(argv, argc, "-strip") > 1) { if (CountOccurrences(argv, argc, "-strip") > 1) {
ERROR_GOTO1("ERROR: Multiple '-strip' arguments specified.\n", ErrValidate); ERROR_GOTO1("ERROR: Multiple '-strip' arguments specified.\n", ErrValidate);
} }
if (CountOccurences(argv, argc, "-info") > 1) { if (CountOccurrences(argv, argc, "-info") > 1) {
ERROR_GOTO1("ERROR: Multiple '-info' arguments specified.\n", ErrValidate); ERROR_GOTO1("ERROR: Multiple '-info' arguments specified.\n", ErrValidate);
} }
if (CountOccurences(argv, argc, "-help") > 1) { if (CountOccurrences(argv, argc, "-o") > 1) {
ERROR_GOTO1("ERROR: Multiple '-help' arguments specified.\n", ErrValidate);
}
if (CountOccurences(argv, argc, "-o") > 1) {
ERROR_GOTO1("ERROR: Multiple output files specified.\n", ErrValidate); ERROR_GOTO1("ERROR: Multiple output files specified.\n", ErrValidate);
} }
// Compound checks. // Compound checks.
num_frame_args = CountOccurences(argv, argc, "-frame"); num_frame_args = CountOccurrences(argv, argc, "-frame");
num_tile_args = CountOccurences(argv, argc, "-tile"); num_tile_args = CountOccurrences(argv, argc, "-tile");
num_loop_args = CountOccurences(argv, argc, "-loop"); num_loop_args = CountOccurrences(argv, argc, "-loop");
if (num_loop_args > 1) { if (num_loop_args > 1) {
ERROR_GOTO1("ERROR: Multiple loop counts specified.\n", ErrValidate); ERROR_GOTO1("ERROR: Multiple loop counts specified.\n", ErrValidate);
@ -552,7 +536,7 @@ static int ParseCommandLine(int argc, const char* argv[],
while (i < argc) { while (i < argc) {
Feature* const feature = &config->feature_; Feature* const feature = &config->feature_;
FeatureArg* arg = &feature->args_[feature_arg_index]; FeatureArg* const arg = &feature->args_[feature_arg_index];
if (argv[i][0] == '-') { // One of the action types or output. if (argv[i][0] == '-') { // One of the action types or output.
if (!strcmp(argv[i], "-set")) { if (!strcmp(argv[i], "-set")) {
if (ACTION_IS_NIL) { if (ACTION_IS_NIL) {
@ -690,7 +674,7 @@ static int ParseCommandLine(int argc, const char* argv[],
return ok; return ok;
} }
// Additional Checks after config is filled. // Additional checks after config is filled.
static int ValidateConfig(WebPMuxConfig* config) { static int ValidateConfig(WebPMuxConfig* config) {
int ok = 1; int ok = 1;
Feature* const feature = &config->feature_; Feature* const feature = &config->feature_;
@ -751,12 +735,8 @@ static int InitializeConfig(int argc, const char* argv[],
} }
// Parse command-line. // Parse command-line.
if (!ParseCommandLine(argc, argv, *config)) { if (!ParseCommandLine(argc, argv, *config) ||
ERROR_GOTO1("Exiting due to command-line parsing error.\n", Err1); !ValidateConfig(*config)) {
}
// Additional Checks.
if (!ValidateConfig(*config)) {
ERROR_GOTO1("Exiting due to command-line parsing error.\n", Err1); ERROR_GOTO1("Exiting due to command-line parsing error.\n", Err1);
} }
@ -772,7 +752,8 @@ static int InitializeConfig(int argc, const char* argv[],
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Processing. // Processing.
static int GetFrameTile(WebPMux* mux, WebPMuxConfig* config, int isFrame) { static int GetFrameTile(const WebPMux* mux,
const WebPMuxConfig* config, int isFrame) {
const uint8_t* data = NULL; const uint8_t* data = NULL;
uint32_t size = 0; uint32_t size = 0;
uint32_t x_offset = 0; uint32_t x_offset = 0;
@ -819,7 +800,7 @@ static int GetFrameTile(WebPMux* mux, WebPMuxConfig* config, int isFrame) {
} }
// Read and process config. // Read and process config.
static int Process(WebPMuxConfig* config) { static int Process(const WebPMuxConfig* config) {
WebPMux* mux = NULL; WebPMux* mux = NULL;
const uint8_t* data = NULL; const uint8_t* data = NULL;
uint32_t size = 0; uint32_t size = 0;
@ -831,7 +812,7 @@ static int Process(WebPMuxConfig* config) {
long num; long num;
int index = 0; int index = 0;
int ok = 1; int ok = 1;
Feature* const feature = &config->feature_; const Feature* const feature = &config->feature_;
switch (config->action_type_) { switch (config->action_type_) {
case ACTION_GET: case ACTION_GET:
@ -939,8 +920,7 @@ static int Process(WebPMuxConfig* config) {
case FEATURE_ICCP: case FEATURE_ICCP:
ok = ReadFile(config->input_, &mux); ok = ReadFile(config->input_, &mux);
if (!ok) goto Err2; if (!ok) goto Err2;
ok = ReadData(feature->args_[0].filename_, (void**)&data, ok = ReadData(feature->args_[0].filename_, (void**)&data, &size);
&size);
if (!ok) goto Err2; if (!ok) goto Err2;
err = WebPMuxSetColorProfile(mux, data, size, 1); err = WebPMuxSetColorProfile(mux, data, size, 1);
free((void*)data); free((void*)data);
@ -952,8 +932,7 @@ static int Process(WebPMuxConfig* config) {
case FEATURE_XMP: case FEATURE_XMP:
ok = ReadFile(config->input_, &mux); ok = ReadFile(config->input_, &mux);
if (!ok) goto Err2; if (!ok) goto Err2;
ok = ReadData(feature->args_[0].filename_, (void**)&data, ok = ReadData(feature->args_[0].filename_, (void**)&data, &size);
&size);
if (!ok) goto Err2; if (!ok) goto Err2;
err = WebPMuxSetMetadata(mux, data, size, 1); err = WebPMuxSetMetadata(mux, data, size, 1);
free((void*)data); free((void*)data);
@ -1027,7 +1006,3 @@ int main(int argc, const char* argv[]) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#if defined(__cplusplus) || defined(c_plusplus)
} // extern "C"
#endif