mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-17 22:39:52 +02:00
Initial commit
Change-Id: I4712afb3912625e7aaccfa5160dcf78ee252f159
This commit is contained in:
111
src/webp/decode.h
Normal file
111
src/webp/decode.h
Normal file
@ -0,0 +1,111 @@
|
||||
// Copyright 2010 Google Inc.
|
||||
//
|
||||
// This code is licensed under the same terms as WebM:
|
||||
// Software License Agreement: http://www.webmproject.org/license/software/
|
||||
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// Main decoding functions for WEBP images.
|
||||
//
|
||||
// Author: Skal (pascal.massimino@gmail.com)
|
||||
|
||||
#ifndef WEBP_DECODE_WEBP_DECODE_H_
|
||||
#define WEBP_DECODE_WEBP_DECODE_H_
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <inttypes.h>
|
||||
#else
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef signed int int32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned long long int uint64_t;
|
||||
#define inline __forceinline
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Retrieve basic header information: width, height.
|
||||
// This function will also validate the header and return 0 in
|
||||
// case of formatting error.
|
||||
// Pointers *width/*height can be passed NULL if deemed irrelevant.
|
||||
int WebPGetInfo(const uint8_t* data, uint32_t data_size,
|
||||
int *width, int *height);
|
||||
|
||||
// Decodes WEBP images pointed to by *data and returns RGB samples, along
|
||||
// with the dimensions in *width and *height.
|
||||
// The returned pointer should be deleted calling free().
|
||||
// Returns NULL in case of error.
|
||||
uint8_t* WebPDecodeRGB(const uint8_t* data, uint32_t data_size,
|
||||
int *width, int *height);
|
||||
|
||||
// Same as WebPDecodeRGB, but returning RGBA data.
|
||||
uint8_t* WebPDecodeRGBA(const uint8_t* data, uint32_t data_size,
|
||||
int *width, int *height);
|
||||
|
||||
// This variant decode to BGR instead of RGB.
|
||||
uint8_t* WebPDecodeBGR(const uint8_t* data, uint32_t data_size,
|
||||
int *width, int *height);
|
||||
// This variant decodes to BGRA instead of RGBA.
|
||||
uint8_t* WebPDecodeBGRA(const uint8_t* data, uint32_t data_size,
|
||||
int *width, int *height);
|
||||
|
||||
// Decode WEBP images stored in *data in Y'UV format(*). The pointer returned is
|
||||
// the Y samples buffer. Upon return, *u and *v will point to the U and V
|
||||
// chroma data. These U and V buffers need NOT be free()'d, unlike the returned
|
||||
// Y luma one. The dimension of the U and V planes are both (*width + 1) / 2
|
||||
// and (*height + 1)/ 2.
|
||||
// Upon return, the Y buffer has a stride returned as '*stride', while U and V
|
||||
// have a common stride returned as '*uv_stride'.
|
||||
// Return NULL in case of error.
|
||||
// (*) Also named Y'CbCr. See: http://en.wikipedia.org/wiki/YCbCr
|
||||
uint8_t* WebPDecodeYUV(const uint8_t* data, uint32_t data_size,
|
||||
int *width, int *height, uint8_t** u, uint8_t** v,
|
||||
int *stride, int* uv_stride);
|
||||
|
||||
// These three functions are variants of the above ones, that decode the image
|
||||
// directly into a pre-allocated buffer 'output_buffer'. The maximum storage
|
||||
// available in this buffer is indicated by 'output_buffer_size'. If this
|
||||
// storage is not sufficient (or an error occurred), NULL is returned.
|
||||
// Otherwise, output_buffer is returned, for convenience.
|
||||
// The parameter 'output_stride' specifies the distance (in bytes)
|
||||
// between scanlines. Hence, output_buffer_size is expected to be at least
|
||||
// output_stride x picture-height.
|
||||
uint8_t* WebPDecodeRGBInto(const uint8_t* data, uint32_t data_size,
|
||||
uint8_t* output_buffer, int output_buffer_size,
|
||||
int output_stride);
|
||||
uint8_t* WebPDecodeRGBAInto(const uint8_t* data, uint32_t data_size,
|
||||
uint8_t* output_buffer, int output_buffer_size,
|
||||
int output_stride);
|
||||
// BGR variants
|
||||
uint8_t* WebPDecodeBGRInto(const uint8_t* data, uint32_t data_size,
|
||||
uint8_t* output_buffer, int output_buffer_size,
|
||||
int output_stride);
|
||||
uint8_t* WebPDecodeBGRAInto(const uint8_t* data, uint32_t data_size,
|
||||
uint8_t* output_buffer, int output_buffer_size,
|
||||
int output_stride);
|
||||
|
||||
// WebPDecodeYUVInto() is a variant of WebPDecodeYUV() that operates directly
|
||||
// into pre-allocated luma/chroma plane buffers. This function requires the
|
||||
// strides to be passed: one for the luma plane and one for each of the
|
||||
// chroma ones. The size of each plane buffer is passed as 'luma_size',
|
||||
// 'u_size' and 'v_size' respectively.
|
||||
// Pointer to the luma plane ('*luma') is returned or NULL if an error occurred
|
||||
// during decoding (or because some buffers were found to be too small).
|
||||
uint8_t* WebPDecodeYUVInto(const uint8_t* data, uint32_t data_size,
|
||||
uint8_t* luma, int luma_size, int luma_stride,
|
||||
uint8_t* u, int u_size, int u_stride,
|
||||
uint8_t* v, int v_size, int v_stride);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // WEBP_DECODE_WEBP_DECODE_H_
|
107
src/webp/decode_vp8.h
Normal file
107
src/webp/decode_vp8.h
Normal file
@ -0,0 +1,107 @@
|
||||
// Copyright 2010 Google Inc.
|
||||
//
|
||||
// This code is licensed under the same terms as WebM:
|
||||
// Software License Agreement: http://www.webmproject.org/license/software/
|
||||
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// Low-level API for VP8 decoder
|
||||
//
|
||||
// Author: Skal (pascal.massimino@gmail.com)
|
||||
|
||||
#ifndef WEBP_DECODE_WEBP_DECODE_VP8_H_
|
||||
#define WEBP_DECODE_WEBP_DECODE_VP8_H_
|
||||
|
||||
#include "decode.h"
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Lower-level API
|
||||
//
|
||||
// Thes functions provide fine-grained control of the decoding process.
|
||||
// The call flow should resemble:
|
||||
//
|
||||
// VP8Io io;
|
||||
// VP8InitIo(&io);
|
||||
// io.data = data;
|
||||
// io.data_size = size;
|
||||
// /* customize io's functions (setup()/put()/teardown()) if needed. */
|
||||
//
|
||||
// VP8Decoder* dec = VP8New();
|
||||
// bool ok = VP8Decode(dec);
|
||||
// if (!ok) printf("Error: %s\n", VP8StatusMessage(dec));
|
||||
// VP8Delete(dec);
|
||||
// return ok;
|
||||
|
||||
// Input / Output
|
||||
typedef struct VP8Io VP8Io;
|
||||
struct VP8Io {
|
||||
// set by VP8GetHeaders()
|
||||
int width, height; // picture dimensions, in pixels
|
||||
|
||||
// set before calling put()
|
||||
int mb_x, mb_y; // position of the current sample (in pixels)
|
||||
int mb_w, mb_h; // size of the current sample (usually 16x16)
|
||||
const uint8_t *y, *u, *v; // samples to copy
|
||||
int y_stride; // stride for luma
|
||||
int uv_stride; // stride for chroma
|
||||
|
||||
void* opaque; // user data
|
||||
|
||||
// called when fresh samples are available (1 block of 16x16 pixels)
|
||||
void (*put)(const VP8Io* io);
|
||||
|
||||
// called just before starting to decode the blocks
|
||||
void (*setup)(const VP8Io* io);
|
||||
|
||||
// called just after block decoding is finished
|
||||
void (*teardown)(const VP8Io* io);
|
||||
|
||||
// Input buffer.
|
||||
uint32_t data_size;
|
||||
const uint8_t* data;
|
||||
};
|
||||
|
||||
// Main decoding object. This is an opaque structure.
|
||||
typedef struct VP8Decoder VP8Decoder;
|
||||
|
||||
// Create a new decoder object.
|
||||
VP8Decoder* VP8New();
|
||||
|
||||
// Can be called to make sure 'io' is initialized properly.
|
||||
void VP8InitIo(VP8Io* const io);
|
||||
|
||||
// Start decoding a new picture. Returns true if ok.
|
||||
int VP8GetHeaders(VP8Decoder* const dec, VP8Io* const io);
|
||||
|
||||
// Decode a picture. Will call VP8GetHeaders() if it wasn't done already.
|
||||
int VP8Decode(VP8Decoder* const dec, VP8Io* const io);
|
||||
|
||||
// Return current status of the decoder:
|
||||
// 0 = OK
|
||||
// 1 = OUT_OF_MEMORY
|
||||
// 2 = INVALID_PARAM
|
||||
// 3 = BITSTREAM_ERROR
|
||||
// 4 = UNSUPPORTED_FEATURE
|
||||
int VP8Status(VP8Decoder* const dec);
|
||||
|
||||
// return readable string corresponding to the last status.
|
||||
const char* VP8StatusMessage(VP8Decoder* const dec);
|
||||
|
||||
// Resets the decoder in its initial state, reclaiming memory.
|
||||
// Not a mandatory call between calls to VP8Decode().
|
||||
void VP8Clear(VP8Decoder* const dec);
|
||||
|
||||
// Destroy the decoder object.
|
||||
void VP8Delete(VP8Decoder* const dec);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // WEBP_DECODE_WEBP_DECODE_VP8_H_
|
Reference in New Issue
Block a user