blob: bf90c35deb0e014a3f0b23772c96e8b257c97cd8 [file] [log] [blame]
James Zern061263a2012-05-11 16:00:57 -07001// Copyright 2012 Google Inc. All Rights Reserved.
2//
James Zernd6406142013-06-06 23:05:58 -07003// 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 Zern061263a2012-05-11 16:00:57 -07008// -----------------------------------------------------------------------------
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
James Zern8955da22014-04-28 14:56:19 -070016#include "webp/decode.h"
James Zern061263a2012-05-11 16:00:57 -070017
James Zern605a7122013-11-25 14:43:12 -080018#ifdef __cplusplus
James Zern061263a2012-05-11 16:00:57 -070019extern "C" {
20#endif
21
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().
skal2bcad892014-03-12 19:32:16 +010025// If 'file_name' is NULL or equal to "-", input is read from stdin by calling
26// the function ExUtilReadFromStdin().
James Zern061263a2012-05-11 16:00:57 -070027int ExUtilReadFile(const char* const file_name,
28 const uint8_t** data, size_t* data_size);
29
skal2bcad892014-03-12 19:32:16 +010030// Same as ExUtilReadFile(), but reads until EOF from stdin instead.
31int ExUtilReadFromStdin(const uint8_t** data, size_t* data_size);
32
Urvang Joshie9a15a32012-11-07 14:41:15 -080033// Write a data segment into a file named 'file_name'. Returns true if ok.
skal2bcad892014-03-12 19:32:16 +010034// If 'file_name' is NULL or equal to "-", output is written to stdout.
Urvang Joshie9a15a32012-11-07 14:41:15 -080035int ExUtilWriteFile(const char* const file_name,
36 const uint8_t* data, size_t data_size);
37
James Zern4a0e7392014-04-22 19:33:22 -070038//------------------------------------------------------------------------------
39// WebP decoding
40
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
43// text string.
44void ExUtilPrintWebPError(const char* const in_file, int status);
45
46// Reads a WebP from 'in_file', returning the contents and size in 'data' and
Pascal Massiminof0b65c92014-04-26 01:10:52 -070047// 'data_size'. If not NULL, 'bitstream' is populated using WebPGetFeatures().
James Zern4a0e7392014-04-22 19:33:22 -070048// Returns true on success.
49int ExUtilLoadWebP(const char* const in_file,
50 const uint8_t** data, size_t* data_size,
James Zern8955da22014-04-28 14:56:19 -070051 WebPBitstreamFeatures* bitstream);
James Zern4a0e7392014-04-22 19:33:22 -070052
James Zern1b2fe142014-04-26 14:26:13 -070053// 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.
James Zern4a0e7392014-04-22 19:33:22 -070057// Returns the decoder status. On success 'config->output' will contain the
58// decoded picture.
James Zern8955da22014-04-28 14:56:19 -070059VP8StatusCode ExUtilDecodeWebP(const uint8_t* const data, size_t data_size,
60 int verbose, WebPDecoderConfig* const config);
James Zern4a0e7392014-04-22 19:33:22 -070061
James Zern1b2fe142014-04-26 14:26:13 -070062// Same as ExUtilDecodeWebP(), but using the incremental decoder.
James Zern8955da22014-04-28 14:56:19 -070063VP8StatusCode ExUtilDecodeWebPIncremental(
James Zern1b2fe142014-04-26 14:26:13 -070064 const uint8_t* const data, size_t data_size,
James Zern8955da22014-04-28 14:56:19 -070065 int verbose, WebPDecoderConfig* const config);
James Zern1b2fe142014-04-26 14:26:13 -070066
James Zern605a7122013-11-25 14:43:12 -080067#ifdef __cplusplus
James Zern061263a2012-05-11 16:00:57 -070068} // extern "C"
69#endif
70
71#endif // WEBP_EXAMPLES_EXAMPLE_UTIL_H_