19aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Copyright 2010 Google Inc. 29aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// 39aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// This code is licensed under the same terms as WebM: 49aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Software License Agreement: http://www.webmproject.org/license/software/ 59aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ 69aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// ----------------------------------------------------------------------------- 79aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// 89aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Low-level API for VP8 decoder 99aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// 109aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Author: Skal (pascal.massimino@gmail.com) 119aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1203d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora#ifndef WEBP_WEBP_DECODE_VP8_H_ 1303d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora#define WEBP_WEBP_DECODE_VP8_H_ 149aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 15466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora#include "./decode.h" 169aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 179aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#if defined(__cplusplus) || defined(c_plusplus) 189aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldextern "C" { 199aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#endif 209aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 219aea642eefa7a641ab8b89d953251939221d2719Eric Hassold//----------------------------------------------------------------------------- 229aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Lower-level API 239aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// 2488fe2b83c4b9232cd08729556fd0485d6a6a92cdVikas Arora// These functions provide fine-grained control of the decoding process. 259aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// The call flow should resemble: 269aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// 279aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// VP8Io io; 289aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// VP8InitIo(&io); 299aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// io.data = data; 309aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// io.data_size = size; 319aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// /* customize io's functions (setup()/put()/teardown()) if needed. */ 329aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// 339aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// VP8Decoder* dec = VP8New(); 349aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// bool ok = VP8Decode(dec); 359aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// if (!ok) printf("Error: %s\n", VP8StatusMessage(dec)); 369aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// VP8Delete(dec); 379aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// return ok; 389aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 399aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Input / Output 409aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldtypedef struct VP8Io VP8Io; 413417a639b7b2a482a76019e987c9cfb5045e1ceeVikas Aroratypedef int (*VP8IoPutHook)(const VP8Io* io); 423417a639b7b2a482a76019e987c9cfb5045e1ceeVikas Aroratypedef int (*VP8IoSetupHook)(VP8Io* io); 433417a639b7b2a482a76019e987c9cfb5045e1ceeVikas Aroratypedef void (*VP8IoTeardownHook)(const VP8Io* io); 443417a639b7b2a482a76019e987c9cfb5045e1ceeVikas Arora 459aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstruct VP8Io { 469aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // set by VP8GetHeaders() 47466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora int width, height; // picture dimensions, in pixels (invariable). 48466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora // These are the original, uncropped dimensions. 49466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora // The actual area passed to put() is stored 50466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora // in mb_w / mb_h fields. 519aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 529aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // set before calling put() 539aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int mb_y; // position of the current rows (in pixels) 54466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora int mb_w; // number of columns in the sample 559aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int mb_h; // number of rows in the sample 56466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora const uint8_t* y, *u, *v; // rows to copy (in yuv420 format) 579aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int y_stride; // row stride for luma 589aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int uv_stride; // row stride for chroma 599aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 609aea642eefa7a641ab8b89d953251939221d2719Eric Hassold void* opaque; // user data 619aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 629aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // called when fresh samples are available. Currently, samples are in 639aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // YUV420 format, and can be up to width x 24 in size (depending on the 6403d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora // in-loop filtering level, e.g.). Should return false in case of error 65466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora // or abort request. The actual size of the area to update is mb_w x mb_h 66466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora // in size, taking cropping into account. 673417a639b7b2a482a76019e987c9cfb5045e1ceeVikas Arora VP8IoPutHook put; 689aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 699aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // called just before starting to decode the blocks. 709aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // Should returns 0 in case of error. 713417a639b7b2a482a76019e987c9cfb5045e1ceeVikas Arora VP8IoSetupHook setup; 729aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 739aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // called just after block decoding is finished (or when an error occurred). 743417a639b7b2a482a76019e987c9cfb5045e1ceeVikas Arora VP8IoTeardownHook teardown; 759aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 769aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // this is a recommendation for the user-side yuv->rgb converter. This flag 779aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // is set when calling setup() hook and can be overwritten by it. It then 789aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // can be taken into consideration during the put() method. 79466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora int fancy_upsampling; 809aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 819aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // Input buffer. 829aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint32_t data_size; 839aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const uint8_t* data; 8403d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora 8503d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora // If true, in-loop filtering will not be performed even if present in the 8603d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora // bitstream. Switching off filtering may speed up decoding at the expense 8703d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora // of more visible blocking. Note that output will also be non-compliant 8803d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora // with the VP8 specifications. 8903d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora int bypass_filtering; 90466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora 91466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora // Cropping parameters. 92466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora int use_cropping; 93466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora int crop_left, crop_right, crop_top, crop_bottom; 94466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora 95466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora // Scaling parameters. 96466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora int use_scaling; 97466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora int scaled_width, scaled_height; 98466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora 99466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora // pointer to the alpha data (if present) corresponding to the rows 100466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora const uint8_t* a; 1019aea642eefa7a641ab8b89d953251939221d2719Eric Hassold}; 1029aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 10303d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora// Internal, version-checked, entry point 104466727975bcc57c0c5597bcd0747a2fe4777b303Vikas AroraWEBP_EXTERN(int) VP8InitIoInternal(VP8Io* const, int); 10503d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora 1063417a639b7b2a482a76019e987c9cfb5045e1ceeVikas Arora// Set the custom IO function pointers and user-data. The setter for IO hooks 1073417a639b7b2a482a76019e987c9cfb5045e1ceeVikas Arora// should be called before initiating incremental decoding. Returns true if 10888fe2b83c4b9232cd08729556fd0485d6a6a92cdVikas Arora// WebPIDecoder object is successfully modified, false otherwise. 109466727975bcc57c0c5597bcd0747a2fe4777b303Vikas AroraWEBP_EXTERN(int) WebPISetIOHooks(WebPIDecoder* const idec, 110466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora VP8IoPutHook put, 111466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora VP8IoSetupHook setup, 112466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora VP8IoTeardownHook teardown, 113466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora void* user_data); 1143417a639b7b2a482a76019e987c9cfb5045e1ceeVikas Arora 1159aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Main decoding object. This is an opaque structure. 1169aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldtypedef struct VP8Decoder VP8Decoder; 1179aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1189aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Create a new decoder object. 119466727975bcc57c0c5597bcd0747a2fe4777b303Vikas AroraWEBP_EXTERN(VP8Decoder*) VP8New(void); 1209aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 12103d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora// Must be called to make sure 'io' is initialized properly. 12203d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora// Returns false in case of version mismatch. Upon such failure, no other 12303d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora// decoding function should be called (VP8Decode, VP8GetHeaders, ...) 12403d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arorastatic inline int VP8InitIo(VP8Io* const io) { 12503d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora return VP8InitIoInternal(io, WEBP_DECODER_ABI_VERSION); 12603d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora} 1279aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1289aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Start decoding a new picture. Returns true if ok. 129466727975bcc57c0c5597bcd0747a2fe4777b303Vikas AroraWEBP_EXTERN(int) VP8GetHeaders(VP8Decoder* const dec, VP8Io* const io); 1309aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1319aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Decode a picture. Will call VP8GetHeaders() if it wasn't done already. 13203d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora// Returns false in case of error. 133466727975bcc57c0c5597bcd0747a2fe4777b303Vikas AroraWEBP_EXTERN(int) VP8Decode(VP8Decoder* const dec, VP8Io* const io); 1349aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1359aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Return current status of the decoder: 136466727975bcc57c0c5597bcd0747a2fe4777b303Vikas AroraWEBP_EXTERN(VP8StatusCode) VP8Status(VP8Decoder* const dec); 1379aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1389aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// return readable string corresponding to the last status. 139466727975bcc57c0c5597bcd0747a2fe4777b303Vikas AroraWEBP_EXTERN(const char*) VP8StatusMessage(VP8Decoder* const dec); 1409aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1419aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Resets the decoder in its initial state, reclaiming memory. 1429aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Not a mandatory call between calls to VP8Decode(). 143466727975bcc57c0c5597bcd0747a2fe4777b303Vikas AroraWEBP_EXTERN(void) VP8Clear(VP8Decoder* const dec); 1449aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1459aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Destroy the decoder object. 146466727975bcc57c0c5597bcd0747a2fe4777b303Vikas AroraWEBP_EXTERN(void) VP8Delete(VP8Decoder* const dec); 1479aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1489aea642eefa7a641ab8b89d953251939221d2719Eric Hassold//----------------------------------------------------------------------------- 1499aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1509aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#if defined(__cplusplus) || defined(c_plusplus) 1519aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} // extern "C" 1529aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#endif 1539aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 15403d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora#endif /* WEBP_WEBP_DECODE_VP8_H_ */ 155