go-libwebp

Experimental translation from libwebp to Go source.
Log | Files | Refs | README | LICENSE

example_util.h (2753B)


      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 
     13 #ifndef WEBP_EXAMPLES_EXAMPLE_UTIL_H_
     14 #define WEBP_EXAMPLES_EXAMPLE_UTIL_H_
     15 
     16 #include "webp/types.h"
     17 #include "webp/mux_types.h"
     18 
     19 #ifdef __cplusplus
     20 extern "C" {
     21 #endif
     22 
     23 //------------------------------------------------------------------------------
     24 // String parsing
     25 
     26 // Parses 'v' using strto(ul|l|d)(). If error is non-NULL, '*error' is set to
     27 // true on failure while on success it is left unmodified to allow chaining of
     28 // calls. An error is only printed on the first occurrence.
     29 uint32_t ExUtilGetUInt(const char* const v, int base, int* const error);
     30 int ExUtilGetInt(const char* const v, int base, int* const error);
     31 float ExUtilGetFloat(const char* const v, int* const error);
     32 
     33 // This variant of ExUtilGetInt() will parse multiple integers from a
     34 // comma-separated list. Up to 'max_output' integers are parsed.
     35 // The result is placed in the output[] array, and the number of integers
     36 // actually parsed is returned, or -1 if an error occurred.
     37 int ExUtilGetInts(const char* v, int base, int max_output, int output[]);
     38 
     39 // Reads a file named 'filename' into a WebPData structure. The content of
     40 // webp_data is overwritten. Returns false in case of error.
     41 int ExUtilReadFileToWebPData(const char* const filename,
     42                              WebPData* const webp_data);
     43 
     44 //------------------------------------------------------------------------------
     45 // Command-line arguments
     46 
     47 typedef struct {
     48   int argc;
     49   const char** argv;
     50   WebPData argv_data;
     51   int own_argv;
     52 } CommandLineArguments;
     53 
     54 // Initializes the structure from the command-line parameters. If there is
     55 // only one parameter and it does not start with a '-', then it is assumed to
     56 // be a file name. This file will be read and tokenized into command-line
     57 // arguments. The content of 'args' is overwritten.
     58 // Returns false in case of error (memory allocation failure, non
     59 // existing file, too many arguments, ...).
     60 int ExUtilInitCommandLineArguments(int argc, const char* argv[],
     61                                    CommandLineArguments* const args);
     62 
     63 // Deallocate all memory and reset 'args'.
     64 void ExUtilDeleteCommandLineArguments(CommandLineArguments* const args);
     65 
     66 #ifdef __cplusplus
     67 }    // extern "C"
     68 #endif
     69 
     70 #endif  // WEBP_EXAMPLES_EXAMPLE_UTIL_H_