blob: 8e8e8014f70f7c4d69cea21f83ea6f821064b728 [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 Zern5927e152014-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 Zern96d43a82014-09-10 23:35:48 -070023//------------------------------------------------------------------------------
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.
29uint32_t ExUtilGetUInt(const char* const v, int base, int* const error);
30int ExUtilGetInt(const char* const v, int base, int* const error);
31float ExUtilGetFloat(const char* const v, int* const error);
32
33//------------------------------------------------------------------------------
34// File I/O
35
James Zern5927e152014-08-29 19:07:17 -070036// Reopen file in binary (O_BINARY) mode.
37// Returns 'file' on success, NULL otherwise.
38FILE* ExUtilSetBinaryMode(FILE* file);
39
James Zern061263a2012-05-11 16:00:57 -070040// Allocates storage for entire file 'file_name' and returns contents and size
41// in 'data' and 'data_size'. Returns 1 on success, 0 otherwise. '*data' should
42// be deleted using free().
skal2bcad892014-03-12 19:32:16 +010043// If 'file_name' is NULL or equal to "-", input is read from stdin by calling
44// the function ExUtilReadFromStdin().
James Zern061263a2012-05-11 16:00:57 -070045int ExUtilReadFile(const char* const file_name,
46 const uint8_t** data, size_t* data_size);
47
skal2bcad892014-03-12 19:32:16 +010048// Same as ExUtilReadFile(), but reads until EOF from stdin instead.
49int ExUtilReadFromStdin(const uint8_t** data, size_t* data_size);
50
Urvang Joshie9a15a32012-11-07 14:41:15 -080051// Write a data segment into a file named 'file_name'. Returns true if ok.
skal2bcad892014-03-12 19:32:16 +010052// If 'file_name' is NULL or equal to "-", output is written to stdout.
Urvang Joshie9a15a32012-11-07 14:41:15 -080053int ExUtilWriteFile(const char* const file_name,
54 const uint8_t* data, size_t data_size);
55
James Zern4a0e7392014-04-22 19:33:22 -070056//------------------------------------------------------------------------------
57// WebP decoding
58
59// Prints an informative error message regarding decode failure of 'in_file'.
60// 'status' is treated as a VP8StatusCode and if valid will be printed as a
61// text string.
62void ExUtilPrintWebPError(const char* const in_file, int status);
63
64// Reads a WebP from 'in_file', returning the contents and size in 'data' and
Pascal Massiminof0b65c92014-04-26 01:10:52 -070065// 'data_size'. If not NULL, 'bitstream' is populated using WebPGetFeatures().
James Zern4a0e7392014-04-22 19:33:22 -070066// Returns true on success.
67int ExUtilLoadWebP(const char* const in_file,
68 const uint8_t** data, size_t* data_size,
James Zern8955da22014-04-28 14:56:19 -070069 WebPBitstreamFeatures* bitstream);
James Zern4a0e7392014-04-22 19:33:22 -070070
James Zern1b2fe142014-04-26 14:26:13 -070071// Decodes the WebP contained in 'data'.
72// 'config' is a structure previously initialized by WebPInitDecoderConfig().
73// 'config->output' should have the desired colorspace selected. 'verbose' will
74// cause decode timing to be reported.
James Zern4a0e7392014-04-22 19:33:22 -070075// Returns the decoder status. On success 'config->output' will contain the
76// decoded picture.
James Zern8955da22014-04-28 14:56:19 -070077VP8StatusCode ExUtilDecodeWebP(const uint8_t* const data, size_t data_size,
78 int verbose, WebPDecoderConfig* const config);
James Zern4a0e7392014-04-22 19:33:22 -070079
James Zern1b2fe142014-04-26 14:26:13 -070080// Same as ExUtilDecodeWebP(), but using the incremental decoder.
James Zern8955da22014-04-28 14:56:19 -070081VP8StatusCode ExUtilDecodeWebPIncremental(
James Zern1b2fe142014-04-26 14:26:13 -070082 const uint8_t* const data, size_t data_size,
James Zern8955da22014-04-28 14:56:19 -070083 int verbose, WebPDecoderConfig* const config);
James Zern1b2fe142014-04-26 14:26:13 -070084
James Zern605a7122013-11-25 14:43:12 -080085#ifdef __cplusplus
James Zern061263a2012-05-11 16:00:57 -070086} // extern "C"
87#endif
88
89#endif // WEBP_EXAMPLES_EXAMPLE_UTIL_H_