1
// Copyright 2012 Google Inc. All Rights Reserved.
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
// -----------------------------------------------------------------------------
10
// Utility functions used by the example programs.
13
#ifndef WEBP_EXAMPLES_EXAMPLE_UTIL_H_
14
#define WEBP_EXAMPLES_EXAMPLE_UTIL_H_
16
#include "webp/decode.h"
22
// Allocates storage for entire file 'file_name' and returns contents and size
23
// in 'data' and 'data_size'. Returns 1 on success, 0 otherwise. '*data' should
24
// be deleted using free().
25
// If 'file_name' is NULL or equal to "-", input is read from stdin by calling
26
// the function ExUtilReadFromStdin().
27
int ExUtilReadFile(const char* const file_name,
28
const uint8_t** data, size_t* data_size);
30
// Same as ExUtilReadFile(), but reads until EOF from stdin instead.
31
int ExUtilReadFromStdin(const uint8_t** data, size_t* data_size);
33
// Write a data segment into a file named 'file_name'. Returns true if ok.
34
// If 'file_name' is NULL or equal to "-", output is written to stdout.
35
int ExUtilWriteFile(const char* const file_name,
36
const uint8_t* data, size_t data_size);
38
//------------------------------------------------------------------------------
41
// Prints an informative error message regarding decode failure of 'in_file'.
42
// 'status' is treated as a VP8StatusCode and if valid will be printed as a
44
void ExUtilPrintWebPError(const char* const in_file, int status);
46
// Reads a WebP from 'in_file', returning the contents and size in 'data' and
47
// 'data_size'. If not NULL, 'bitstream' is populated using WebPGetFeatures().
48
// Returns true on success.
49
int ExUtilLoadWebP(const char* const in_file,
50
const uint8_t** data, size_t* data_size,
51
WebPBitstreamFeatures* bitstream);
53
// Decodes the WebP contained in 'data'.
54
// 'config' is a structure previously initialized by WebPInitDecoderConfig().
55
// 'config->output' should have the desired colorspace selected. 'verbose' will
56
// cause decode timing to be reported.
57
// Returns the decoder status. On success 'config->output' will contain the
59
VP8StatusCode ExUtilDecodeWebP(const uint8_t* const data, size_t data_size,
60
int verbose, WebPDecoderConfig* const config);
62
// Same as ExUtilDecodeWebP(), but using the incremental decoder.
63
VP8StatusCode ExUtilDecodeWebPIncremental(
64
const uint8_t* const data, size_t data_size,
65
int verbose, WebPDecoderConfig* const config);
71
#endif // WEBP_EXAMPLES_EXAMPLE_UTIL_H_