15a50414796e9a458925c7a13a15055d02406bf43Vikas Arora// Copyright 2010 Google Inc. All Rights Reserved. 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// VP8 decoder: internal header. 99aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// 109aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Author: Skal (pascal.massimino@gmail.com) 119aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1203d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora#ifndef WEBP_DEC_VP8I_H_ 1303d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora#define WEBP_DEC_VP8I_H_ 149aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 159aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#include <string.h> // for memcpy() 165a50414796e9a458925c7a13a15055d02406bf43Vikas Arora#include "./vp8li.h" 175a50414796e9a458925c7a13a15055d02406bf43Vikas Arora#include "../utils/bit_reader.h" 185a50414796e9a458925c7a13a15055d02406bf43Vikas Arora#include "../utils/thread.h" 195a50414796e9a458925c7a13a15055d02406bf43Vikas Arora#include "../dsp/dsp.h" 209aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 219aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#if defined(__cplusplus) || defined(c_plusplus) 229aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldextern "C" { 239aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#endif 249aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 255a50414796e9a458925c7a13a15055d02406bf43Vikas Arora//------------------------------------------------------------------------------ 269aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Various defines and enums 279aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2803d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora// version numbers 2903d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora#define DEC_MAJ_VERSION 0 305a50414796e9a458925c7a13a15055d02406bf43Vikas Arora#define DEC_MIN_VERSION 2 315a50414796e9a458925c7a13a15055d02406bf43Vikas Arora#define DEC_REV_VERSION 0 3203d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora 339aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#define ONLY_KEYFRAME_CODE // to remove any code related to P-Frames 349aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 359aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// intra prediction modes 369aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldenum { B_DC_PRED = 0, // 4x4 modes 379aea642eefa7a641ab8b89d953251939221d2719Eric Hassold B_TM_PRED, 389aea642eefa7a641ab8b89d953251939221d2719Eric Hassold B_VE_PRED, 399aea642eefa7a641ab8b89d953251939221d2719Eric Hassold B_HE_PRED, 409aea642eefa7a641ab8b89d953251939221d2719Eric Hassold B_RD_PRED, 419aea642eefa7a641ab8b89d953251939221d2719Eric Hassold B_VR_PRED, 429aea642eefa7a641ab8b89d953251939221d2719Eric Hassold B_LD_PRED, 439aea642eefa7a641ab8b89d953251939221d2719Eric Hassold B_VL_PRED, 449aea642eefa7a641ab8b89d953251939221d2719Eric Hassold B_HD_PRED, 459aea642eefa7a641ab8b89d953251939221d2719Eric Hassold B_HU_PRED, 469aea642eefa7a641ab8b89d953251939221d2719Eric Hassold NUM_BMODES = B_HU_PRED + 1 - B_DC_PRED, // = 10 479aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 489aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // Luma16 or UV modes 499aea642eefa7a641ab8b89d953251939221d2719Eric Hassold DC_PRED = B_DC_PRED, V_PRED = B_VE_PRED, 509aea642eefa7a641ab8b89d953251939221d2719Eric Hassold H_PRED = B_HE_PRED, TM_PRED = B_TM_PRED, 519aea642eefa7a641ab8b89d953251939221d2719Eric Hassold B_PRED = NUM_BMODES, // refined I4x4 mode 529aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 539aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // special modes 549aea642eefa7a641ab8b89d953251939221d2719Eric Hassold B_DC_PRED_NOTOP = 4, 559aea642eefa7a641ab8b89d953251939221d2719Eric Hassold B_DC_PRED_NOLEFT = 5, 5603d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora B_DC_PRED_NOTOPLEFT = 6, 5703d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora NUM_B_DC_MODES = 7 }; 589aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 599aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldenum { MB_FEATURE_TREE_PROBS = 3, 609aea642eefa7a641ab8b89d953251939221d2719Eric Hassold NUM_MB_SEGMENTS = 4, 619aea642eefa7a641ab8b89d953251939221d2719Eric Hassold NUM_REF_LF_DELTAS = 4, 629aea642eefa7a641ab8b89d953251939221d2719Eric Hassold NUM_MODE_LF_DELTAS = 4, // I4x4, ZERO, *, SPLIT 639aea642eefa7a641ab8b89d953251939221d2719Eric Hassold MAX_NUM_PARTITIONS = 8, 649aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // Probabilities 659aea642eefa7a641ab8b89d953251939221d2719Eric Hassold NUM_TYPES = 4, 669aea642eefa7a641ab8b89d953251939221d2719Eric Hassold NUM_BANDS = 8, 679aea642eefa7a641ab8b89d953251939221d2719Eric Hassold NUM_CTX = 3, 689aea642eefa7a641ab8b89d953251939221d2719Eric Hassold NUM_PROBAS = 11, 699aea642eefa7a641ab8b89d953251939221d2719Eric Hassold NUM_MV_PROBAS = 19 }; 709aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 719aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// YUV-cache parameters. 729aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Constraints are: We need to store one 16x16 block of luma samples (y), 739aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// and two 8x8 chroma blocks (u/v). These are better be 16-bytes aligned, 749aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// in order to be SIMD-friendly. We also need to store the top, left and 759aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// top-left samples (from previously decoded blocks), along with four 769aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// extra top-right samples for luma (intra4x4 prediction only). 779aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// One possible layout is, using 32 * (17 + 9) bytes: 789aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// 799aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// .+------ <- only 1 pixel high 809aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// .|yyyyt. 819aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// .|yyyyt. 829aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// .|yyyyt. 839aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// .|yyyy.. 849aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// .+--.+-- <- only 1 pixel high 859aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// .|uu.|vv 869aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// .|uu.|vv 879aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// 889aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Every character is a 4x4 block, with legend: 899aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// '.' = unused 909aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// 'y' = y-samples 'u' = u-samples 'v' = u-samples 919aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// '|' = left sample, '-' = top sample, '+' = top-left sample 929aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// 't' = extra top-right sample for 4x4 modes 939aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// With this layout, BPS (=Bytes Per Scan-line) is one cacheline size. 949aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#define BPS 32 // this is the common stride used by yuv[] 959aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#define YUV_SIZE (BPS * 17 + BPS * 9) 969aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#define Y_SIZE (BPS * 17) 979aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#define Y_OFF (BPS * 1 + 8) 989aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#define U_OFF (Y_OFF + BPS * 16 + BPS) 999aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#define V_OFF (U_OFF + 16) 1009aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1015a50414796e9a458925c7a13a15055d02406bf43Vikas Arora//------------------------------------------------------------------------------ 1029aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Headers 1039aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1049aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldtypedef struct { 1059aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t key_frame_; 1069aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t profile_; 1079aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t show_; 1089aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint32_t partition_length_; 1099aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} VP8FrameHeader; 1109aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1119aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldtypedef struct { 1129aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint16_t width_; 1139aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint16_t height_; 1149aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t xscale_; 1159aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t yscale_; 1169aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t colorspace_; // 0 = YCbCr 1179aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t clamp_type_; 1189aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} VP8PictureHeader; 1199aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1209aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// segment features 1219aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldtypedef struct { 1229aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int use_segment_; 1239aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int update_map_; // whether to update the segment map or not 1249aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int absolute_delta_; // absolute or delta values for quantizer and filter 1259aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int8_t quantizer_[NUM_MB_SEGMENTS]; // quantization changes 1269aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int8_t filter_strength_[NUM_MB_SEGMENTS]; // filter strength for segments 1279aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} VP8SegmentHeader; 1289aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1299aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Struct collecting all frame-persistent probabilities. 1309aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldtypedef struct { 1319aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t segments_[MB_FEATURE_TREE_PROBS]; 1329aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // Type: 0:Intra16-AC 1:Intra16-DC 2:Chroma 3:Intra4 1339aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t coeffs_[NUM_TYPES][NUM_BANDS][NUM_CTX][NUM_PROBAS]; 1349aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#ifndef ONLY_KEYFRAME_CODE 1359aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t ymode_[4], uvmode_[3]; 1369aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t mv_[2][NUM_MV_PROBAS]; 1379aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#endif 1389aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} VP8Proba; 1399aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1409aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Filter parameters 1419aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldtypedef struct { 1429aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int simple_; // 0=complex, 1=simple 1439aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int level_; // [0..63] 1449aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int sharpness_; // [0..7] 1459aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int use_lf_delta_; 1469aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int ref_lf_delta_[NUM_REF_LF_DELTAS]; 1479aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int mode_lf_delta_[NUM_MODE_LF_DELTAS]; 1489aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} VP8FilterHeader; 1499aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1505a50414796e9a458925c7a13a15055d02406bf43Vikas Arora//------------------------------------------------------------------------------ 1519aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Informations about the macroblocks. 1529aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1535a50414796e9a458925c7a13a15055d02406bf43Vikas Aroratypedef struct { // filter specs 1545a50414796e9a458925c7a13a15055d02406bf43Vikas Arora unsigned int f_level_:6; // filter strength: 0..63 1555a50414796e9a458925c7a13a15055d02406bf43Vikas Arora unsigned int f_ilevel_:6; // inner limit: 1..63 1565a50414796e9a458925c7a13a15055d02406bf43Vikas Arora unsigned int f_inner_:1; // do inner filtering? 1575a50414796e9a458925c7a13a15055d02406bf43Vikas Arora} VP8FInfo; 1585a50414796e9a458925c7a13a15055d02406bf43Vikas Arora 1595a50414796e9a458925c7a13a15055d02406bf43Vikas Aroratypedef struct { // used for syntax-parsing 1605a50414796e9a458925c7a13a15055d02406bf43Vikas Arora unsigned int nz_; // non-zero AC/DC coeffs 1615a50414796e9a458925c7a13a15055d02406bf43Vikas Arora unsigned int dc_nz_:1; // non-zero DC coeffs 1625a50414796e9a458925c7a13a15055d02406bf43Vikas Arora unsigned int skip_:1; // block type 1639aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} VP8MB; 1649aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1659aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Dequantization matrices 1665a50414796e9a458925c7a13a15055d02406bf43Vikas Aroratypedef int quant_t[2]; // [DC / AC]. Can be 'uint16_t[2]' too (~slower). 1679aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldtypedef struct { 1685a50414796e9a458925c7a13a15055d02406bf43Vikas Arora quant_t y1_mat_, y2_mat_, uv_mat_; 1699aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} VP8QuantMatrix; 1709aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1715a50414796e9a458925c7a13a15055d02406bf43Vikas Arora// Persistent information needed by the parallel processing 1725a50414796e9a458925c7a13a15055d02406bf43Vikas Aroratypedef struct { 1735a50414796e9a458925c7a13a15055d02406bf43Vikas Arora int id_; // cache row to process (in [0..2]) 1745a50414796e9a458925c7a13a15055d02406bf43Vikas Arora int mb_y_; // macroblock position of the row 1755a50414796e9a458925c7a13a15055d02406bf43Vikas Arora int filter_row_; // true if row-filtering is needed 1765a50414796e9a458925c7a13a15055d02406bf43Vikas Arora VP8FInfo* f_info_; // filter strengths 1775a50414796e9a458925c7a13a15055d02406bf43Vikas Arora VP8Io io_; // copy of the VP8Io to pass to put() 1785a50414796e9a458925c7a13a15055d02406bf43Vikas Arora} VP8ThreadContext; 1795a50414796e9a458925c7a13a15055d02406bf43Vikas Arora 1805a50414796e9a458925c7a13a15055d02406bf43Vikas Arora//------------------------------------------------------------------------------ 1819aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// VP8Decoder: the main opaque structure handed over to user 1829aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1839aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstruct VP8Decoder { 18403d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora VP8StatusCode status_; 1859aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int ready_; // true if ready to decode a picture with VP8Decode() 1869aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const char* error_msg_; // set when status_ is not OK. 1879aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1889aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // Main data source 1899aea642eefa7a641ab8b89d953251939221d2719Eric Hassold VP8BitReader br_; 1909aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1919aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // headers 1929aea642eefa7a641ab8b89d953251939221d2719Eric Hassold VP8FrameHeader frm_hdr_; 1939aea642eefa7a641ab8b89d953251939221d2719Eric Hassold VP8PictureHeader pic_hdr_; 1949aea642eefa7a641ab8b89d953251939221d2719Eric Hassold VP8FilterHeader filter_hdr_; 1959aea642eefa7a641ab8b89d953251939221d2719Eric Hassold VP8SegmentHeader segment_hdr_; 1969aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1975a50414796e9a458925c7a13a15055d02406bf43Vikas Arora // Worker 1985a50414796e9a458925c7a13a15055d02406bf43Vikas Arora WebPWorker worker_; 1995a50414796e9a458925c7a13a15055d02406bf43Vikas Arora int use_threads_; // use multi-thread 2005a50414796e9a458925c7a13a15055d02406bf43Vikas Arora int cache_id_; // current cache row 2015a50414796e9a458925c7a13a15055d02406bf43Vikas Arora int num_caches_; // number of cached rows of 16 pixels (1, 2 or 3) 2025a50414796e9a458925c7a13a15055d02406bf43Vikas Arora VP8ThreadContext thread_ctx_; // Thread context 2035a50414796e9a458925c7a13a15055d02406bf43Vikas Arora 2049aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // dimension, in macroblock units. 2059aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int mb_w_, mb_h_; 2069aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 207466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora // Macroblock to process/filter, depending on cropping and filter_type. 208466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora int tl_mb_x_, tl_mb_y_; // top-left MB that must be in-loop filtered 209466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora int br_mb_x_, br_mb_y_; // last bottom-right MB that must be decoded 210466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora 2119aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // number of partitions. 2129aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int num_parts_; 2139aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // per-partition boolean decoders. 2149aea642eefa7a641ab8b89d953251939221d2719Eric Hassold VP8BitReader parts_[MAX_NUM_PARTITIONS]; 2159aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2169aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // buffer refresh flags 2179aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // bit 0: refresh Gold, bit 1: refresh Alt 2189aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // bit 2-3: copy to Gold, bit 4-5: copy to Alt 2199aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // bit 6: Gold sign bias, bit 7: Alt sign bias 2209aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // bit 8: refresh last frame 2219aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint32_t buffer_flags_; 2229aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2239aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // dequantization (one set of DC/AC dequant factor per segment) 2249aea642eefa7a641ab8b89d953251939221d2719Eric Hassold VP8QuantMatrix dqm_[NUM_MB_SEGMENTS]; 2259aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2269aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // probabilities 2279aea642eefa7a641ab8b89d953251939221d2719Eric Hassold VP8Proba proba_; 2289aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int use_skip_proba_; 2299aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t skip_p_; 2309aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#ifndef ONLY_KEYFRAME_CODE 2319aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t intra_p_, last_p_, golden_p_; 2329aea642eefa7a641ab8b89d953251939221d2719Eric Hassold VP8Proba proba_saved_; 2339aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int update_proba_; 2349aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#endif 2359aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2369aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // Boundary data cache and persistent buffers. 2379aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t* intra_t_; // top intra modes values: 4 * mb_w_ 2389aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t intra_l_[4]; // left intra modes values 239466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora uint8_t* y_t_; // top luma samples: 16 * mb_w_ 240466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora uint8_t* u_t_, *v_t_; // top u/v samples: 8 * mb_w_ each 2419aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2425a50414796e9a458925c7a13a15055d02406bf43Vikas Arora VP8MB* mb_info_; // contextual macroblock info (mb_w_ + 1) 2435a50414796e9a458925c7a13a15055d02406bf43Vikas Arora VP8FInfo* f_info_; // filter strength info 2449aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t* yuv_b_; // main block for Y/U/V (size = YUV_SIZE) 2459aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int16_t* coeffs_; // 384 coeffs = (16+8+8) * 4*4 2469aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2479aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t* cache_y_; // macroblock row for storing unfiltered samples 2489aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t* cache_u_; 2499aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t* cache_v_; 2509aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int cache_y_stride_; 2519aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int cache_uv_stride_; 2529aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2539aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // main memory chunk for the above data. Persistent. 2549aea642eefa7a641ab8b89d953251939221d2719Eric Hassold void* mem_; 2555a50414796e9a458925c7a13a15055d02406bf43Vikas Arora size_t mem_size_; 2569aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2579aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // Per macroblock non-persistent infos. 2589aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int mb_x_, mb_y_; // current position, in macroblock units 2599aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t is_i4x4_; // true if intra4x4 2609aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t imodes_[16]; // one 16x16 mode (#0) or sixteen 4x4 modes 2619aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t uvmode_; // chroma prediction mode 2629aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t segment_; // block's segment 2639aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2649aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // bit-wise info about the content of each sub-4x4 blocks: there are 16 bits 2659aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // for luma (bits #0->#15), then 4 bits for chroma-u (#16->#19) and 4 bits for 2669aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // chroma-v (#20->#23), each corresponding to one 4x4 block in decoding order. 2679aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // If the bit is set, the 4x4 block contains some non-zero coefficients. 2689aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint32_t non_zero_; 2699aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint32_t non_zero_ac_; 2709aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2719aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // Filtering side-info 272466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora int filter_type_; // 0=off, 1=simple, 2=complex 2735a50414796e9a458925c7a13a15055d02406bf43Vikas Arora int filter_row_; // per-row flag 2749aea642eefa7a641ab8b89d953251939221d2719Eric Hassold uint8_t filter_levels_[NUM_MB_SEGMENTS]; // precalculated per-segment 275466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora 276466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora // extensions 277466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora const uint8_t* alpha_data_; // compressed alpha data (if present) 278466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora size_t alpha_data_size_; 2795a50414796e9a458925c7a13a15055d02406bf43Vikas Arora uint8_t* alpha_plane_; // output. Persistent, contains the whole data. 280466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora 281466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora int layer_colorspace_; 282466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora const uint8_t* layer_data_; // compressed layer data (if present) 283466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora size_t layer_data_size_; 2849aea642eefa7a641ab8b89d953251939221d2719Eric Hassold}; 2859aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2865a50414796e9a458925c7a13a15055d02406bf43Vikas Arora//------------------------------------------------------------------------------ 2879aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// internal functions. Not public. 2889aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2899aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// in vp8.c 29003d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Aroraint VP8SetError(VP8Decoder* const dec, 2915a50414796e9a458925c7a13a15055d02406bf43Vikas Arora VP8StatusCode error, const char* const msg); 2929aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2939aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// in tree.c 2949aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldvoid VP8ResetProba(VP8Proba* const proba); 2959aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldvoid VP8ParseProba(VP8BitReader* const br, VP8Decoder* const dec); 2969aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldvoid VP8ParseIntraMode(VP8BitReader* const br, VP8Decoder* const dec); 2979aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 2989aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// in quant.c 2999aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldvoid VP8ParseQuant(VP8Decoder* const dec); 3009aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 3019aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// in frame.c 3029aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldint VP8InitFrame(VP8Decoder* const dec, VP8Io* io); 3039aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Predict a block and add residual 3049aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldvoid VP8ReconstructBlock(VP8Decoder* const dec); 305466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora// Call io->setup() and finish setting up scan parameters. 3065a50414796e9a458925c7a13a15055d02406bf43Vikas Arora// After this call returns, one must always call VP8ExitCritical() with the 3075a50414796e9a458925c7a13a15055d02406bf43Vikas Arora// same parameters. Both functions should be used in pair. Returns VP8_STATUS_OK 3085a50414796e9a458925c7a13a15055d02406bf43Vikas Arora// if ok, otherwise sets and returns the error status on *dec. 3095a50414796e9a458925c7a13a15055d02406bf43Vikas AroraVP8StatusCode VP8EnterCritical(VP8Decoder* const dec, VP8Io* const io); 3105a50414796e9a458925c7a13a15055d02406bf43Vikas Arora// Must always be called in pair with VP8EnterCritical(). 3115a50414796e9a458925c7a13a15055d02406bf43Vikas Arora// Returns false in case of error. 3125a50414796e9a458925c7a13a15055d02406bf43Vikas Aroraint VP8ExitCritical(VP8Decoder* const dec, VP8Io* const io); 3135a50414796e9a458925c7a13a15055d02406bf43Vikas Arora// Process the last decoded row (filtering + output) 3145a50414796e9a458925c7a13a15055d02406bf43Vikas Aroraint VP8ProcessRow(VP8Decoder* const dec, VP8Io* const io); 3159aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Store a block, along with filtering params 3169aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldvoid VP8StoreBlock(VP8Decoder* const dec); 3175a50414796e9a458925c7a13a15055d02406bf43Vikas Arora// To be called at the start of a new scanline, to initialize predictors. 3185a50414796e9a458925c7a13a15055d02406bf43Vikas Aroravoid VP8InitScanline(VP8Decoder* const dec); 31903d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora// Decode one macroblock. Returns false if there is not enough data. 32003d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Aroraint VP8DecodeMB(VP8Decoder* const dec, VP8BitReader* const token_br); 3219aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 322466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora// in alpha.c 323466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Aroraconst uint8_t* VP8DecompressAlphaRows(VP8Decoder* const dec, 324466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora int row, int num_rows); 325466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora 326466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora// in layer.c 327466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Aroraint VP8DecodeLayer(VP8Decoder* const dec); 328466727975bcc57c0c5597bcd0747a2fe4777b303Vikas Arora 3295a50414796e9a458925c7a13a15055d02406bf43Vikas Arora//------------------------------------------------------------------------------ 3309aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 3319aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#if defined(__cplusplus) || defined(c_plusplus) 3329aea642eefa7a641ab8b89d953251939221d2719Eric Hassold} // extern "C" 3339aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#endif 3349aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 3355a50414796e9a458925c7a13a15055d02406bf43Vikas Arora#endif /* WEBP_DEC_VP8I_H_ */ 336