James Zern | 061263a | 2012-05-11 16:00:57 -0700 | [diff] [blame] | 1 | // Copyright 2012 Google Inc. All Rights Reserved. |
| 2 | // |
James Zern | d640614 | 2013-06-06 23:05:58 -0700 | [diff] [blame] | 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. |
James Zern | 061263a | 2012-05-11 16:00:57 -0700 | [diff] [blame] | 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 | |
James Zern | 605a712 | 2013-11-25 14:43:12 -0800 | [diff] [blame] | 18 | #ifdef __cplusplus |
James Zern | 061263a | 2012-05-11 16:00:57 -0700 | [diff] [blame] | 19 | extern "C" { |
| 20 | #endif |
| 21 | |
James Zern | 4a0e739 | 2014-04-22 19:33:22 -0700 | [diff] [blame] | 22 | struct WebPDecoderConfig; |
| 23 | struct WebPBitstreamFeatures; |
| 24 | |
James Zern | 061263a | 2012-05-11 16:00:57 -0700 | [diff] [blame] | 25 | // Allocates storage for entire file 'file_name' and returns contents and size |
| 26 | // in 'data' and 'data_size'. Returns 1 on success, 0 otherwise. '*data' should |
| 27 | // be deleted using free(). |
skal | 2bcad89 | 2014-03-12 19:32:16 +0100 | [diff] [blame] | 28 | // If 'file_name' is NULL or equal to "-", input is read from stdin by calling |
| 29 | // the function ExUtilReadFromStdin(). |
James Zern | 061263a | 2012-05-11 16:00:57 -0700 | [diff] [blame] | 30 | int ExUtilReadFile(const char* const file_name, |
| 31 | const uint8_t** data, size_t* data_size); |
| 32 | |
skal | 2bcad89 | 2014-03-12 19:32:16 +0100 | [diff] [blame] | 33 | // Same as ExUtilReadFile(), but reads until EOF from stdin instead. |
| 34 | int ExUtilReadFromStdin(const uint8_t** data, size_t* data_size); |
| 35 | |
Urvang Joshi | e9a15a3 | 2012-11-07 14:41:15 -0800 | [diff] [blame] | 36 | // Write a data segment into a file named 'file_name'. Returns true if ok. |
skal | 2bcad89 | 2014-03-12 19:32:16 +0100 | [diff] [blame] | 37 | // If 'file_name' is NULL or equal to "-", output is written to stdout. |
Urvang Joshi | e9a15a3 | 2012-11-07 14:41:15 -0800 | [diff] [blame] | 38 | int ExUtilWriteFile(const char* const file_name, |
| 39 | const uint8_t* data, size_t data_size); |
| 40 | |
James Zern | 4a0e739 | 2014-04-22 19:33:22 -0700 | [diff] [blame] | 41 | //------------------------------------------------------------------------------ |
| 42 | // WebP decoding |
| 43 | |
| 44 | // Prints an informative error message regarding decode failure of 'in_file'. |
| 45 | // 'status' is treated as a VP8StatusCode and if valid will be printed as a |
| 46 | // text string. |
| 47 | void ExUtilPrintWebPError(const char* const in_file, int status); |
| 48 | |
| 49 | // Reads a WebP from 'in_file', returning the contents and size in 'data' and |
| 50 | // 'data_size'. 'bitstream' is populated using WebPGetFeatures(). |
| 51 | // Returns true on success. |
| 52 | int ExUtilLoadWebP(const char* const in_file, |
| 53 | const uint8_t** data, size_t* data_size, |
| 54 | struct WebPBitstreamFeatures* bitstream); |
| 55 | |
| 56 | // Decodes the WebP contained in 'data'. 'config' is a structure previously |
| 57 | // initialized by WebPInitDecoderConfig(). 'config->output' should have the |
| 58 | // desired colorspace selected. If 'incremental' is set to true the WebP |
| 59 | // incremental decoder will be used. 'verbose' will cause decode timing to be |
| 60 | // reported. |
| 61 | // Returns the decoder status. On success 'config->output' will contain the |
| 62 | // decoded picture. |
| 63 | enum VP8StatusCode ExUtilDecodeWebP(const uint8_t* const data, size_t data_size, |
| 64 | int incremental, int verbose, |
| 65 | struct WebPDecoderConfig* const config); |
| 66 | |
James Zern | 605a712 | 2013-11-25 14:43:12 -0800 | [diff] [blame] | 67 | #ifdef __cplusplus |
James Zern | 061263a | 2012-05-11 16:00:57 -0700 | [diff] [blame] | 68 | } // extern "C" |
| 69 | #endif |
| 70 | |
| 71 | #endif // WEBP_EXAMPLES_EXAMPLE_UTIL_H_ |