Path: blob/master/3rdparty/libwebp/src/dec/vp8_dec.h
16358 views
// Copyright 2010 Google Inc. All Rights Reserved.1//2// Use of this source code is governed by a BSD-style license3// that can be found in the COPYING file in the root of the source4// tree. An additional intellectual property rights grant can be found5// in the file PATENTS. All contributing project authors may6// be found in the AUTHORS file in the root of the source tree.7// -----------------------------------------------------------------------------8//9// Low-level API for VP8 decoder10//11// Author: Skal ([email protected])1213#ifndef WEBP_DEC_VP8_DEC_H_14#define WEBP_DEC_VP8_DEC_H_1516#include "src/webp/decode.h"1718#ifdef __cplusplus19extern "C" {20#endif2122//------------------------------------------------------------------------------23// Lower-level API24//25// These functions provide fine-grained control of the decoding process.26// The call flow should resemble:27//28// VP8Io io;29// VP8InitIo(&io);30// io.data = data;31// io.data_size = size;32// /* customize io's functions (setup()/put()/teardown()) if needed. */33//34// VP8Decoder* dec = VP8New();35// int ok = VP8Decode(dec, &io);36// if (!ok) printf("Error: %s\n", VP8StatusMessage(dec));37// VP8Delete(dec);38// return ok;3940// Input / Output41typedef struct VP8Io VP8Io;42typedef int (*VP8IoPutHook)(const VP8Io* io);43typedef int (*VP8IoSetupHook)(VP8Io* io);44typedef void (*VP8IoTeardownHook)(const VP8Io* io);4546struct VP8Io {47// set by VP8GetHeaders()48int width, height; // picture dimensions, in pixels (invariable).49// These are the original, uncropped dimensions.50// The actual area passed to put() is stored51// in mb_w / mb_h fields.5253// set before calling put()54int mb_y; // position of the current rows (in pixels)55int mb_w; // number of columns in the sample56int mb_h; // number of rows in the sample57const uint8_t* y, *u, *v; // rows to copy (in yuv420 format)58int y_stride; // row stride for luma59int uv_stride; // row stride for chroma6061void* opaque; // user data6263// called when fresh samples are available. Currently, samples are in64// YUV420 format, and can be up to width x 24 in size (depending on the65// in-loop filtering level, e.g.). Should return false in case of error66// or abort request. The actual size of the area to update is mb_w x mb_h67// in size, taking cropping into account.68VP8IoPutHook put;6970// called just before starting to decode the blocks.71// Must return false in case of setup error, true otherwise. If false is72// returned, teardown() will NOT be called. But if the setup succeeded73// and true is returned, then teardown() will always be called afterward.74VP8IoSetupHook setup;7576// Called just after block decoding is finished (or when an error occurred77// during put()). Is NOT called if setup() failed.78VP8IoTeardownHook teardown;7980// this is a recommendation for the user-side yuv->rgb converter. This flag81// is set when calling setup() hook and can be overwritten by it. It then82// can be taken into consideration during the put() method.83int fancy_upsampling;8485// Input buffer.86size_t data_size;87const uint8_t* data;8889// If true, in-loop filtering will not be performed even if present in the90// bitstream. Switching off filtering may speed up decoding at the expense91// of more visible blocking. Note that output will also be non-compliant92// with the VP8 specifications.93int bypass_filtering;9495// Cropping parameters.96int use_cropping;97int crop_left, crop_right, crop_top, crop_bottom;9899// Scaling parameters.100int use_scaling;101int scaled_width, scaled_height;102103// If non NULL, pointer to the alpha data (if present) corresponding to the104// start of the current row (That is: it is pre-offset by mb_y and takes105// cropping into account).106const uint8_t* a;107};108109// Internal, version-checked, entry point110int VP8InitIoInternal(VP8Io* const, int);111112// Set the custom IO function pointers and user-data. The setter for IO hooks113// should be called before initiating incremental decoding. Returns true if114// WebPIDecoder object is successfully modified, false otherwise.115int WebPISetIOHooks(WebPIDecoder* const idec,116VP8IoPutHook put,117VP8IoSetupHook setup,118VP8IoTeardownHook teardown,119void* user_data);120121// Main decoding object. This is an opaque structure.122typedef struct VP8Decoder VP8Decoder;123124// Create a new decoder object.125VP8Decoder* VP8New(void);126127// Must be called to make sure 'io' is initialized properly.128// Returns false in case of version mismatch. Upon such failure, no other129// decoding function should be called (VP8Decode, VP8GetHeaders, ...)130static WEBP_INLINE int VP8InitIo(VP8Io* const io) {131return VP8InitIoInternal(io, WEBP_DECODER_ABI_VERSION);132}133134// Decode the VP8 frame header. Returns true if ok.135// Note: 'io->data' must be pointing to the start of the VP8 frame header.136int VP8GetHeaders(VP8Decoder* const dec, VP8Io* const io);137138// Decode a picture. Will call VP8GetHeaders() if it wasn't done already.139// Returns false in case of error.140int VP8Decode(VP8Decoder* const dec, VP8Io* const io);141142// Return current status of the decoder:143VP8StatusCode VP8Status(VP8Decoder* const dec);144145// return readable string corresponding to the last status.146const char* VP8StatusMessage(VP8Decoder* const dec);147148// Resets the decoder in its initial state, reclaiming memory.149// Not a mandatory call between calls to VP8Decode().150void VP8Clear(VP8Decoder* const dec);151152// Destroy the decoder object.153void VP8Delete(VP8Decoder* const dec);154155//------------------------------------------------------------------------------156// Miscellaneous VP8/VP8L bitstream probing functions.157158// Returns true if the next 3 bytes in data contain the VP8 signature.159WEBP_EXTERN int VP8CheckSignature(const uint8_t* const data, size_t data_size);160161// Validates the VP8 data-header and retrieves basic header information viz162// width and height. Returns 0 in case of formatting error. *width/*height163// can be passed NULL.164WEBP_EXTERN int VP8GetInfo(165const uint8_t* data,166size_t data_size, // data available so far167size_t chunk_size, // total data size expected in the chunk168int* const width, int* const height);169170// Returns true if the next byte(s) in data is a VP8L signature.171WEBP_EXTERN int VP8LCheckSignature(const uint8_t* const data, size_t size);172173// Validates the VP8L data-header and retrieves basic header information viz174// width, height and alpha. Returns 0 in case of formatting error.175// width/height/has_alpha can be passed NULL.176WEBP_EXTERN int VP8LGetInfo(177const uint8_t* data, size_t data_size, // data available so far178int* const width, int* const height, int* const has_alpha);179180#ifdef __cplusplus181} // extern "C"182#endif183184#endif /* WEBP_DEC_VP8_DEC_H_ */185186187