Path: blob/master/thirdparty/libwebp/src/dec/vp8_dec.h
9912 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"17#include "src/webp/types.h"1819#ifdef __cplusplus20extern "C" {21#endif2223//------------------------------------------------------------------------------24// Lower-level API25//26// These functions provide fine-grained control of the decoding process.27// The call flow should resemble:28//29// VP8Io io;30// VP8InitIo(&io);31// io.data = data;32// io.data_size = size;33// /* customize io's functions (setup()/put()/teardown()) if needed. */34//35// VP8Decoder* dec = VP8New();36// int ok = VP8Decode(dec, &io);37// if (!ok) printf("Error: %s\n", VP8StatusMessage(dec));38// VP8Delete(dec);39// return ok;4041// Input / Output42typedef struct VP8Io VP8Io;43typedef int (*VP8IoPutHook)(const VP8Io* io);44typedef int (*VP8IoSetupHook)(VP8Io* io);45typedef void (*VP8IoTeardownHook)(const VP8Io* io);4647struct VP8Io {48// set by VP8GetHeaders()49int width, height; // picture dimensions, in pixels (invariable).50// These are the original, uncropped dimensions.51// The actual area passed to put() is stored52// in mb_w / mb_h fields.5354// set before calling put()55int mb_y; // position of the current rows (in pixels)56int mb_w; // number of columns in the sample57int mb_h; // number of rows in the sample58const uint8_t* y, *u, *v; // rows to copy (in yuv420 format)59int y_stride; // row stride for luma60int uv_stride; // row stride for chroma6162void* opaque; // user data6364// called when fresh samples are available. Currently, samples are in65// YUV420 format, and can be up to width x 24 in size (depending on the66// in-loop filtering level, e.g.). Should return false in case of error67// or abort request. The actual size of the area to update is mb_w x mb_h68// in size, taking cropping into account.69VP8IoPutHook put;7071// called just before starting to decode the blocks.72// Must return false in case of setup error, true otherwise. If false is73// returned, teardown() will NOT be called. But if the setup succeeded74// and true is returned, then teardown() will always be called afterward.75VP8IoSetupHook setup;7677// Called just after block decoding is finished (or when an error occurred78// during put()). Is NOT called if setup() failed.79VP8IoTeardownHook teardown;8081// this is a recommendation for the user-side yuv->rgb converter. This flag82// is set when calling setup() hook and can be overwritten by it. It then83// can be taken into consideration during the put() method.84int fancy_upsampling;8586// Input buffer.87size_t data_size;88const uint8_t* data;8990// If true, in-loop filtering will not be performed even if present in the91// bitstream. Switching off filtering may speed up decoding at the expense92// of more visible blocking. Note that output will also be non-compliant93// with the VP8 specifications.94int bypass_filtering;9596// Cropping parameters.97int use_cropping;98int crop_left, crop_right, crop_top, crop_bottom;99100// Scaling parameters.101int use_scaling;102int scaled_width, scaled_height;103104// If non NULL, pointer to the alpha data (if present) corresponding to the105// start of the current row (That is: it is pre-offset by mb_y and takes106// cropping into account).107const uint8_t* a;108};109110// Internal, version-checked, entry point111WEBP_NODISCARD int VP8InitIoInternal(VP8Io* const, int);112113// Set the custom IO function pointers and user-data. The setter for IO hooks114// should be called before initiating incremental decoding. Returns true if115// WebPIDecoder object is successfully modified, false otherwise.116WEBP_NODISCARD int WebPISetIOHooks(WebPIDecoder* const idec, VP8IoPutHook put,117VP8IoSetupHook setup,118VP8IoTeardownHook teardown, void* user_data);119120// Main decoding object. This is an opaque structure.121typedef struct VP8Decoder VP8Decoder;122123// Create a new decoder object.124VP8Decoder* VP8New(void);125126// Must be called to make sure 'io' is initialized properly.127// Returns false in case of version mismatch. Upon such failure, no other128// decoding function should be called (VP8Decode, VP8GetHeaders, ...)129WEBP_NODISCARD static WEBP_INLINE int VP8InitIo(VP8Io* const io) {130return VP8InitIoInternal(io, WEBP_DECODER_ABI_VERSION);131}132133// Decode the VP8 frame header. Returns true if ok.134// Note: 'io->data' must be pointing to the start of the VP8 frame header.135WEBP_NODISCARD int VP8GetHeaders(VP8Decoder* const dec, VP8Io* const io);136137// Decode a picture. Will call VP8GetHeaders() if it wasn't done already.138// Returns false in case of error.139WEBP_NODISCARD int VP8Decode(VP8Decoder* const dec, VP8Io* const io);140141// Return current status of the decoder:142VP8StatusCode VP8Status(VP8Decoder* const dec);143144// return readable string corresponding to the last status.145const char* VP8StatusMessage(VP8Decoder* const dec);146147// Resets the decoder in its initial state, reclaiming memory.148// Not a mandatory call between calls to VP8Decode().149void VP8Clear(VP8Decoder* const dec);150151// Destroy the decoder object.152void VP8Delete(VP8Decoder* const dec);153154//------------------------------------------------------------------------------155// Miscellaneous VP8/VP8L bitstream probing functions.156157// Returns true if the next 3 bytes in data contain the VP8 signature.158WEBP_EXTERN int VP8CheckSignature(const uint8_t* const data, size_t data_size);159160// Validates the VP8 data-header and retrieves basic header information viz161// width and height. Returns 0 in case of formatting error. *width/*height162// can be passed NULL.163WEBP_EXTERN int VP8GetInfo(164const uint8_t* data,165size_t data_size, // data available so far166size_t chunk_size, // total data size expected in the chunk167int* const width, int* const height);168169// Returns true if the next byte(s) in data is a VP8L signature.170WEBP_EXTERN int VP8LCheckSignature(const uint8_t* const data, size_t size);171172// Validates the VP8L data-header and retrieves basic header information viz173// width, height and alpha. Returns 0 in case of formatting error.174// width/height/has_alpha can be passed NULL.175WEBP_EXTERN int VP8LGetInfo(176const uint8_t* data, size_t data_size, // data available so far177int* const width, int* const height, int* const has_alpha);178179#ifdef __cplusplus180} // extern "C"181#endif182183#endif // WEBP_DEC_VP8_DEC_H_184185186