Blame examples/example_util.h

Packit 9c6abc
// Copyright 2012 Google Inc. All Rights Reserved.
Packit 9c6abc
//
Packit 9c6abc
// Use of this source code is governed by a BSD-style license
Packit 9c6abc
// that can be found in the COPYING file in the root of the source
Packit 9c6abc
// tree. An additional intellectual property rights grant can be found
Packit 9c6abc
// in the file PATENTS. All contributing project authors may
Packit 9c6abc
// be found in the AUTHORS file in the root of the source tree.
Packit 9c6abc
// -----------------------------------------------------------------------------
Packit 9c6abc
//
Packit 9c6abc
//  Utility functions used by the example programs.
Packit 9c6abc
//
Packit 9c6abc
Packit 9c6abc
#ifndef WEBP_EXAMPLES_EXAMPLE_UTIL_H_
Packit 9c6abc
#define WEBP_EXAMPLES_EXAMPLE_UTIL_H_
Packit 9c6abc
Packit 9c6abc
#include "webp/types.h"
Packit 9c6abc
#include "webp/mux_types.h"
Packit 9c6abc
Packit 9c6abc
#ifdef __cplusplus
Packit 9c6abc
extern "C" {
Packit 9c6abc
#endif
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
// String parsing
Packit 9c6abc
Packit 9c6abc
// Parses 'v' using strto(ul|l|d)(). If error is non-NULL, '*error' is set to
Packit 9c6abc
// true on failure while on success it is left unmodified to allow chaining of
Packit 9c6abc
// calls. An error is only printed on the first occurrence.
Packit 9c6abc
uint32_t ExUtilGetUInt(const char* const v, int base, int* const error);
Packit 9c6abc
int ExUtilGetInt(const char* const v, int base, int* const error);
Packit 9c6abc
float ExUtilGetFloat(const char* const v, int* const error);
Packit 9c6abc
Packit 9c6abc
// This variant of ExUtilGetInt() will parse multiple integers from a
Packit 9c6abc
// comma-separated list. Up to 'max_output' integers are parsed.
Packit 9c6abc
// The result is placed in the output[] array, and the number of integers
Packit 9c6abc
// actually parsed is returned, or -1 if an error occurred.
Packit 9c6abc
int ExUtilGetInts(const char* v, int base, int max_output, int output[]);
Packit 9c6abc
Packit 9c6abc
// Reads a file named 'filename' into a WebPData structure. The content of
Packit 9c6abc
// webp_data is overwritten. Returns false in case of error.
Packit 9c6abc
int ExUtilReadFileToWebPData(const char* const filename,
Packit 9c6abc
                             WebPData* const webp_data);
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
// Command-line arguments
Packit 9c6abc
Packit 9c6abc
typedef struct {
Packit 9c6abc
  int argc_;
Packit 9c6abc
  const char** argv_;
Packit 9c6abc
  WebPData argv_data_;
Packit 9c6abc
  int own_argv_;
Packit 9c6abc
} CommandLineArguments;
Packit 9c6abc
Packit 9c6abc
// Initializes the structure from the command-line parameters. If there is
Packit 9c6abc
// only one parameter and it does not start with a '-', then it is assumed to
Packit 9c6abc
// be a file name. This file will be read and tokenized into command-line
Packit 9c6abc
// arguments. The content of 'args' is overwritten.
Packit 9c6abc
// Returns false in case of error (memory allocation failure, non
Packit 9c6abc
// existing file, too many arguments, ...).
Packit 9c6abc
int ExUtilInitCommandLineArguments(int argc, const char* argv[],
Packit 9c6abc
                                   CommandLineArguments* const args);
Packit 9c6abc
Packit 9c6abc
// Deallocate all memory and reset 'args'.
Packit 9c6abc
void ExUtilDeleteCommandLineArguments(CommandLineArguments* const args);
Packit 9c6abc
Packit 9c6abc
#ifdef __cplusplus
Packit 9c6abc
}    // extern "C"
Packit 9c6abc
#endif
Packit 9c6abc
Packit 9c6abc
#endif  // WEBP_EXAMPLES_EXAMPLE_UTIL_H_