blob: 4ef703da0f5b463d034b4534f0896db7316b3eab [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 Zern4aaf4632014-08-29 19:07:17 -070016#include <stdio.h>
James Zern8955da22014-04-28 14:56:19 -070017#include "webp/decode.h"
James Zern061263a2012-05-11 16:00:57 -070018
James Zern605a7122013-11-25 14:43:12 -080019#ifdef __cplusplus
James Zern061263a2012-05-11 16:00:57 -070020extern "C" {
21#endif
22
James Zern4aaf4632014-08-29 19:07:17 -070023// Reopen file in binary (O_BINARY) mode.
24// Returns 'file' on success, NULL otherwise.
25FILE* ExUtilSetBinaryMode(FILE* file);
26
James Zern061263a2012-05-11 16:00:57 -070027// Allocates storage for entire file 'file_name' and returns contents and size
28// in 'data' and 'data_size'. Returns 1 on success, 0 otherwise. '*data' should
29// be deleted using free().
skal2bcad892014-03-12 19:32:16 +010030// If 'file_name' is NULL or equal to "-", input is read from stdin by calling
31// the function ExUtilReadFromStdin().
James Zern061263a2012-05-11 16:00:57 -070032int ExUtilReadFile(const char* const file_name,
33 const uint8_t** data, size_t* data_size);
34
skal2bcad892014-03-12 19:32:16 +010035// Same as ExUtilReadFile(), but reads until EOF from stdin instead.
36int ExUtilReadFromStdin(const uint8_t** data, size_t* data_size);
37
Urvang Joshie9a15a32012-11-07 14:41:15 -080038// Write a data segment into a file named 'file_name'. Returns true if ok.
skal2bcad892014-03-12 19:32:16 +010039// If 'file_name' is NULL or equal to "-", output is written to stdout.
Urvang Joshie9a15a32012-11-07 14:41:15 -080040int ExUtilWriteFile(const char* const file_name,
41 const uint8_t* data, size_t data_size);
42
James Zern4a0e7392014-04-22 19:33:22 -070043//------------------------------------------------------------------------------
44// WebP decoding
45
46// Prints an informative error message regarding decode failure of 'in_file'.
47// 'status' is treated as a VP8StatusCode and if valid will be printed as a
48// text string.
49void ExUtilPrintWebPError(const char* const in_file, int status);
50
51// Reads a WebP from 'in_file', returning the contents and size in 'data' and
Pascal Massiminof0b65c92014-04-26 01:10:52 -070052// 'data_size'. If not NULL, 'bitstream' is populated using WebPGetFeatures().
James Zern4a0e7392014-04-22 19:33:22 -070053// Returns true on success.
54int ExUtilLoadWebP(const char* const in_file,
55 const uint8_t** data, size_t* data_size,
James Zern8955da22014-04-28 14:56:19 -070056 WebPBitstreamFeatures* bitstream);
James Zern4a0e7392014-04-22 19:33:22 -070057
James Zern1b2fe142014-04-26 14:26:13 -070058// Decodes the WebP contained in 'data'.
59// 'config' is a structure previously initialized by WebPInitDecoderConfig().
60// 'config->output' should have the desired colorspace selected. 'verbose' will
61// cause decode timing to be reported.
James Zern4a0e7392014-04-22 19:33:22 -070062// Returns the decoder status. On success 'config->output' will contain the
63// decoded picture.
James Zern8955da22014-04-28 14:56:19 -070064VP8StatusCode ExUtilDecodeWebP(const uint8_t* const data, size_t data_size,
65 int verbose, WebPDecoderConfig* const config);
James Zern4a0e7392014-04-22 19:33:22 -070066
James Zern1b2fe142014-04-26 14:26:13 -070067// Same as ExUtilDecodeWebP(), but using the incremental decoder.
James Zern8955da22014-04-28 14:56:19 -070068VP8StatusCode ExUtilDecodeWebPIncremental(
James Zern1b2fe142014-04-26 14:26:13 -070069 const uint8_t* const data, size_t data_size,
James Zern8955da22014-04-28 14:56:19 -070070 int verbose, WebPDecoderConfig* const config);
James Zern1b2fe142014-04-26 14:26:13 -070071
James Zern605a7122013-11-25 14:43:12 -080072#ifdef __cplusplus
James Zern061263a2012-05-11 16:00:57 -070073} // extern "C"
74#endif
75
76#endif // WEBP_EXAMPLES_EXAMPLE_UTIL_H_