example_util.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2012 Google Inc. All Rights Reserved.
  2. //
  3. // Use of this source code is governed by a BSD-style license
  4. // that can be found in the COPYING file in the root of the source
  5. // tree. An additional intellectual property rights grant can be found
  6. // in the file PATENTS. All contributing project authors may
  7. // be found in the AUTHORS file in the root of the source tree.
  8. // -----------------------------------------------------------------------------
  9. //
  10. // Utility functions used by the example programs.
  11. //
  12. #ifndef WEBP_EXAMPLES_EXAMPLE_UTIL_H_
  13. #define WEBP_EXAMPLES_EXAMPLE_UTIL_H_
  14. #include "webp/types.h"
  15. #include "webp/mux_types.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. //------------------------------------------------------------------------------
  20. // String parsing
  21. // Parses 'v' using strto(ul|l|d)(). If error is non-NULL, '*error' is set to
  22. // true on failure while on success it is left unmodified to allow chaining of
  23. // calls. An error is only printed on the first occurrence.
  24. uint32_t ExUtilGetUInt(const char* const v, int base, int* const error);
  25. int ExUtilGetInt(const char* const v, int base, int* const error);
  26. float ExUtilGetFloat(const char* const v, int* const error);
  27. // This variant of ExUtilGetInt() will parse multiple integers from a
  28. // comma-separated list. Up to 'max_output' integers are parsed.
  29. // The result is placed in the output[] array, and the number of integers
  30. // actually parsed is returned, or -1 if an error occurred.
  31. int ExUtilGetInts(const char* v, int base, int max_output, int output[]);
  32. // Reads a file named 'filename' into a WebPData structure. The content of
  33. // webp_data is overwritten. Returns false in case of error.
  34. int ExUtilReadFileToWebPData(const char* const filename,
  35. WebPData* const webp_data);
  36. //------------------------------------------------------------------------------
  37. // Command-line arguments
  38. typedef struct {
  39. int argc_;
  40. const char** argv_;
  41. WebPData argv_data_;
  42. int own_argv_;
  43. } CommandLineArguments;
  44. // Initializes the structure from the command-line parameters. If there is
  45. // only one parameter and it does not start with a '-', then it is assumed to
  46. // be a file name. This file will be read and tokenized into command-line
  47. // arguments. The content of 'args' is overwritten.
  48. // Returns false in case of error (memory allocation failure, non
  49. // existing file, too many arguments, ...).
  50. int ExUtilInitCommandLineArguments(int argc, const char* argv[],
  51. CommandLineArguments* const args);
  52. // Deallocate all memory and reset 'args'.
  53. void ExUtilDeleteCommandLineArguments(CommandLineArguments* const args);
  54. #ifdef __cplusplus
  55. } // extern "C"
  56. #endif
  57. #endif // WEBP_EXAMPLES_EXAMPLE_UTIL_H_