2012-05-12 01:00:57 +02:00
|
|
|
// Copyright 2012 Google Inc. All Rights Reserved.
|
|
|
|
//
|
2013-06-07 08:05:58 +02:00
|
|
|
// Use of this source code is governed by a BSD-style license
|
|
|
|
// that can be found in the COPYING file in the root of the source
|
|
|
|
// tree. An additional intellectual property rights grant can be found
|
|
|
|
// in the file PATENTS. All contributing project authors may
|
|
|
|
// be found in the AUTHORS file in the root of the source tree.
|
2012-05-12 01:00:57 +02:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Utility functions used by the example programs.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef WEBP_EXAMPLES_EXAMPLE_UTIL_H_
|
|
|
|
#define WEBP_EXAMPLES_EXAMPLE_UTIL_H_
|
|
|
|
|
2014-08-30 04:07:17 +02:00
|
|
|
#include <stdio.h>
|
2014-04-28 23:56:19 +02:00
|
|
|
#include "webp/decode.h"
|
2012-05-12 01:00:57 +02:00
|
|
|
|
2013-11-25 23:43:12 +01:00
|
|
|
#ifdef __cplusplus
|
2012-05-12 01:00:57 +02:00
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2014-09-11 08:35:48 +02:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// String parsing
|
|
|
|
|
|
|
|
// Parses 'v' using strto(ul|l|d)(). If error is non-NULL, '*error' is set to
|
|
|
|
// true on failure while on success it is left unmodified to allow chaining of
|
|
|
|
// calls. An error is only printed on the first occurrence.
|
|
|
|
uint32_t ExUtilGetUInt(const char* const v, int base, int* const error);
|
|
|
|
int ExUtilGetInt(const char* const v, int base, int* const error);
|
|
|
|
float ExUtilGetFloat(const char* const v, int* const error);
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// File I/O
|
|
|
|
|
2014-08-30 04:07:17 +02:00
|
|
|
// Reopen file in binary (O_BINARY) mode.
|
|
|
|
// Returns 'file' on success, NULL otherwise.
|
|
|
|
FILE* ExUtilSetBinaryMode(FILE* file);
|
|
|
|
|
2012-05-12 01:00:57 +02:00
|
|
|
// Allocates storage for entire file 'file_name' and returns contents and size
|
|
|
|
// in 'data' and 'data_size'. Returns 1 on success, 0 otherwise. '*data' should
|
|
|
|
// be deleted using free().
|
2014-03-12 19:32:16 +01:00
|
|
|
// If 'file_name' is NULL or equal to "-", input is read from stdin by calling
|
|
|
|
// the function ExUtilReadFromStdin().
|
2012-05-12 01:00:57 +02:00
|
|
|
int ExUtilReadFile(const char* const file_name,
|
|
|
|
const uint8_t** data, size_t* data_size);
|
|
|
|
|
2014-03-12 19:32:16 +01:00
|
|
|
// Same as ExUtilReadFile(), but reads until EOF from stdin instead.
|
|
|
|
int ExUtilReadFromStdin(const uint8_t** data, size_t* data_size);
|
|
|
|
|
2012-11-07 23:41:15 +01:00
|
|
|
// Write a data segment into a file named 'file_name'. Returns true if ok.
|
2014-03-12 19:32:16 +01:00
|
|
|
// If 'file_name' is NULL or equal to "-", output is written to stdout.
|
2012-11-07 23:41:15 +01:00
|
|
|
int ExUtilWriteFile(const char* const file_name,
|
|
|
|
const uint8_t* data, size_t data_size);
|
|
|
|
|
2014-04-23 04:33:22 +02:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// WebP decoding
|
|
|
|
|
|
|
|
// Prints an informative error message regarding decode failure of 'in_file'.
|
|
|
|
// 'status' is treated as a VP8StatusCode and if valid will be printed as a
|
|
|
|
// text string.
|
|
|
|
void ExUtilPrintWebPError(const char* const in_file, int status);
|
|
|
|
|
|
|
|
// Reads a WebP from 'in_file', returning the contents and size in 'data' and
|
2014-04-26 10:10:52 +02:00
|
|
|
// 'data_size'. If not NULL, 'bitstream' is populated using WebPGetFeatures().
|
2014-04-23 04:33:22 +02:00
|
|
|
// Returns true on success.
|
|
|
|
int ExUtilLoadWebP(const char* const in_file,
|
|
|
|
const uint8_t** data, size_t* data_size,
|
2014-04-28 23:56:19 +02:00
|
|
|
WebPBitstreamFeatures* bitstream);
|
2014-04-23 04:33:22 +02:00
|
|
|
|
2014-04-26 23:26:13 +02:00
|
|
|
// Decodes the WebP contained in 'data'.
|
|
|
|
// 'config' is a structure previously initialized by WebPInitDecoderConfig().
|
|
|
|
// 'config->output' should have the desired colorspace selected. 'verbose' will
|
|
|
|
// cause decode timing to be reported.
|
2014-04-23 04:33:22 +02:00
|
|
|
// Returns the decoder status. On success 'config->output' will contain the
|
|
|
|
// decoded picture.
|
2014-04-28 23:56:19 +02:00
|
|
|
VP8StatusCode ExUtilDecodeWebP(const uint8_t* const data, size_t data_size,
|
|
|
|
int verbose, WebPDecoderConfig* const config);
|
2014-04-23 04:33:22 +02:00
|
|
|
|
2014-04-26 23:26:13 +02:00
|
|
|
// Same as ExUtilDecodeWebP(), but using the incremental decoder.
|
2014-04-28 23:56:19 +02:00
|
|
|
VP8StatusCode ExUtilDecodeWebPIncremental(
|
2014-04-26 23:26:13 +02:00
|
|
|
const uint8_t* const data, size_t data_size,
|
2014-04-28 23:56:19 +02:00
|
|
|
int verbose, WebPDecoderConfig* const config);
|
2014-04-26 23:26:13 +02:00
|
|
|
|
2013-11-25 23:43:12 +01:00
|
|
|
#ifdef __cplusplus
|
2012-05-12 01:00:57 +02:00
|
|
|
} // extern "C"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // WEBP_EXAMPLES_EXAMPLE_UTIL_H_
|