Path: blob/master/thirdparty/libwebp/src/dec/vp8_dec.h
21539 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 <stddef.h>1718#include "src/webp/decode.h"19#include "src/webp/types.h"2021#ifdef __cplusplus22extern "C" {23#endif2425//------------------------------------------------------------------------------26// Lower-level API27//28// These functions provide fine-grained control of the decoding process.29// The call flow should resemble:30//31// VP8Io io;32// VP8InitIo(&io);33// io.data = data;34// io.data_size = size;35// /* customize io's functions (setup()/put()/teardown()) if needed. */36//37// VP8Decoder* dec = VP8New();38// int ok = VP8Decode(dec, &io);39// if (!ok) printf("Error: %s\n", VP8StatusMessage(dec));40// VP8Delete(dec);41// return ok;4243// Input / Output44typedef struct VP8Io VP8Io;45typedef int (*VP8IoPutHook)(const VP8Io* io);46typedef int (*VP8IoSetupHook)(VP8Io* io);47typedef void (*VP8IoTeardownHook)(const VP8Io* io);4849struct VP8Io {50// set by VP8GetHeaders()51int width, height; // picture dimensions, in pixels (invariable).52// These are the original, uncropped dimensions.53// The actual area passed to put() is stored54// in mb_w / mb_h fields.5556// set before calling put()57int mb_y; // position of the current rows (in pixels)58int mb_w; // number of columns in the sample59int mb_h; // number of rows in the sample60const uint8_t* y, *u, *v; // rows to copy (in yuv420 format)61int y_stride; // row stride for luma62int uv_stride; // row stride for chroma6364void* opaque; // user data6566// called when fresh samples are available. Currently, samples are in67// YUV420 format, and can be up to width x 24 in size (depending on the68// in-loop filtering level, e.g.). Should return false in case of error69// or abort request. The actual size of the area to update is mb_w x mb_h70// in size, taking cropping into account.71VP8IoPutHook put;7273// called just before starting to decode the blocks.74// Must return false in case of setup error, true otherwise. If false is75// returned, teardown() will NOT be called. But if the setup succeeded76// and true is returned, then teardown() will always be called afterward.77VP8IoSetupHook setup;7879// Called just after block decoding is finished (or when an error occurred80// during put()). Is NOT called if setup() failed.81VP8IoTeardownHook teardown;8283// this is a recommendation for the user-side yuv->rgb converter. This flag84// is set when calling setup() hook and can be overwritten by it. It then85// can be taken into consideration during the put() method.86int fancy_upsampling;8788// Input buffer.89size_t data_size;90const uint8_t* data;9192// If true, in-loop filtering will not be performed even if present in the93// bitstream. Switching off filtering may speed up decoding at the expense94// of more visible blocking. Note that output will also be non-compliant95// with the VP8 specifications.96int bypass_filtering;9798// Cropping parameters.99int use_cropping;100int crop_left, crop_right, crop_top, crop_bottom;101102// Scaling parameters.103int use_scaling;104int scaled_width, scaled_height;105106// If non NULL, pointer to the alpha data (if present) corresponding to the107// start of the current row (That is: it is pre-offset by mb_y and takes108// cropping into account).109const uint8_t* a;110};111112// Internal, version-checked, entry point113WEBP_NODISCARD int VP8InitIoInternal(VP8Io* const, int);114115// Set the custom IO function pointers and user-data. The setter for IO hooks116// should be called before initiating incremental decoding. Returns true if117// WebPIDecoder object is successfully modified, false otherwise.118WEBP_NODISCARD int WebPISetIOHooks(WebPIDecoder* const idec, VP8IoPutHook put,119VP8IoSetupHook setup,120VP8IoTeardownHook teardown, void* user_data);121122// Main decoding object. This is an opaque structure.123typedef struct VP8Decoder VP8Decoder;124125// Create a new decoder object.126VP8Decoder* VP8New(void);127128// Must be called to make sure 'io' is initialized properly.129// Returns false in case of version mismatch. Upon such failure, no other130// decoding function should be called (VP8Decode, VP8GetHeaders, ...)131WEBP_NODISCARD static WEBP_INLINE int VP8InitIo(VP8Io* const io) {132return VP8InitIoInternal(io, WEBP_DECODER_ABI_VERSION);133}134135// Decode the VP8 frame header. Returns true if ok.136// Note: 'io->data' must be pointing to the start of the VP8 frame header.137WEBP_NODISCARD int VP8GetHeaders(VP8Decoder* const dec, VP8Io* const io);138139// Decode a picture. Will call VP8GetHeaders() if it wasn't done already.140// Returns false in case of error.141WEBP_NODISCARD int VP8Decode(VP8Decoder* const dec, VP8Io* const io);142143// Return current status of the decoder:144VP8StatusCode VP8Status(VP8Decoder* const dec);145146// return readable string corresponding to the last status.147const char* VP8StatusMessage(VP8Decoder* const dec);148149// Resets the decoder in its initial state, reclaiming memory.150// Not a mandatory call between calls to VP8Decode().151void VP8Clear(VP8Decoder* const dec);152153// Destroy the decoder object.154void VP8Delete(VP8Decoder* const dec);155156//------------------------------------------------------------------------------157// Miscellaneous VP8/VP8L bitstream probing functions.158159// Returns true if the next 3 bytes in data contain the VP8 signature.160WEBP_EXTERN int VP8CheckSignature(const uint8_t* const data, size_t data_size);161162// Validates the VP8 data-header and retrieves basic header information viz163// width and height. Returns 0 in case of formatting error. *width/*height164// can be passed NULL.165WEBP_EXTERN int VP8GetInfo(166const uint8_t* data,167size_t data_size, // data available so far168size_t chunk_size, // total data size expected in the chunk169int* const width, int* const height);170171// Returns true if the next byte(s) in data is a VP8L signature.172WEBP_EXTERN int VP8LCheckSignature(const uint8_t* const data, size_t size);173174// Validates the VP8L data-header and retrieves basic header information viz175// width, height and alpha. Returns 0 in case of formatting error.176// width/height/has_alpha can be passed NULL.177WEBP_EXTERN int VP8LGetInfo(178const uint8_t* data, size_t data_size, // data available so far179int* const width, int* const height, int* const has_alpha);180181#ifdef __cplusplus182} // extern "C"183#endif184185#endif // WEBP_DEC_VP8_DEC_H_186187188