| OLD | NEW |
| 1 // Copyright 2010 Google Inc. | 1 // Copyright 2010 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // This code is licensed under the same terms as WebM: | 3 // This code is licensed under the same terms as WebM: |
| 4 // Software License Agreement: http://www.webmproject.org/license/software/ | 4 // Software License Agreement: http://www.webmproject.org/license/software/ |
| 5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/ | 5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/ |
| 6 // ----------------------------------------------------------------------------- | 6 // ----------------------------------------------------------------------------- |
| 7 // | 7 // |
| 8 // VP8 decoder: internal header. | 8 // VP8 decoder: internal header. |
| 9 // | 9 // |
| 10 // Author: Skal (pascal.massimino@gmail.com) | 10 // Author: Skal (pascal.massimino@gmail.com) |
| 11 | 11 |
| 12 #ifndef WEBP_DEC_VP8I_H_ | 12 #ifndef WEBP_DEC_VP8I_H_ |
| 13 #define WEBP_DEC_VP8I_H_ | 13 #define WEBP_DEC_VP8I_H_ |
| 14 | 14 |
| 15 #include <string.h> // for memcpy() | 15 #include <string.h> // for memcpy() |
| 16 #include "./vp8li.h" |
| 16 #include "../utils/bit_reader.h" | 17 #include "../utils/bit_reader.h" |
| 17 #include "../utils/thread.h" | 18 #include "../utils/thread.h" |
| 18 #include "../dsp/dsp.h" | 19 #include "../dsp/dsp.h" |
| 19 | 20 |
| 20 #if defined(__cplusplus) || defined(c_plusplus) | 21 #if defined(__cplusplus) || defined(c_plusplus) |
| 21 extern "C" { | 22 extern "C" { |
| 22 #endif | 23 #endif |
| 23 | 24 |
| 24 //------------------------------------------------------------------------------ | 25 //------------------------------------------------------------------------------ |
| 25 // Various defines and enums | 26 // Various defines and enums |
| 26 | 27 |
| 27 // version numbers | 28 // version numbers |
| 28 #define DEC_MAJ_VERSION 0 | 29 #define DEC_MAJ_VERSION 0 |
| 29 #define DEC_MIN_VERSION 1 | 30 #define DEC_MIN_VERSION 2 |
| 30 #define DEC_REV_VERSION 3 | 31 #define DEC_REV_VERSION 0 |
| 31 | 32 |
| 32 #define ONLY_KEYFRAME_CODE // to remove any code related to P-Frames | 33 #define ONLY_KEYFRAME_CODE // to remove any code related to P-Frames |
| 33 | 34 |
| 34 // intra prediction modes | 35 // intra prediction modes |
| 35 enum { B_DC_PRED = 0, // 4x4 modes | 36 enum { B_DC_PRED = 0, // 4x4 modes |
| 36 B_TM_PRED, | 37 B_TM_PRED, |
| 37 B_VE_PRED, | 38 B_VE_PRED, |
| 38 B_HE_PRED, | 39 B_HE_PRED, |
| 39 B_RD_PRED, | 40 B_RD_PRED, |
| 40 B_VR_PRED, | 41 B_VR_PRED, |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 unsigned int f_inner_:1; // do inner filtering? | 156 unsigned int f_inner_:1; // do inner filtering? |
| 156 } VP8FInfo; | 157 } VP8FInfo; |
| 157 | 158 |
| 158 typedef struct { // used for syntax-parsing | 159 typedef struct { // used for syntax-parsing |
| 159 unsigned int nz_; // non-zero AC/DC coeffs | 160 unsigned int nz_; // non-zero AC/DC coeffs |
| 160 unsigned int dc_nz_:1; // non-zero DC coeffs | 161 unsigned int dc_nz_:1; // non-zero DC coeffs |
| 161 unsigned int skip_:1; // block type | 162 unsigned int skip_:1; // block type |
| 162 } VP8MB; | 163 } VP8MB; |
| 163 | 164 |
| 164 // Dequantization matrices | 165 // Dequantization matrices |
| 166 typedef int quant_t[2]; // [DC / AC]. Can be 'uint16_t[2]' too (~slower). |
| 165 typedef struct { | 167 typedef struct { |
| 166 uint16_t y1_mat_[2], y2_mat_[2], uv_mat_[2]; // [DC / AC] | 168 quant_t y1_mat_, y2_mat_, uv_mat_; |
| 167 } VP8QuantMatrix; | 169 } VP8QuantMatrix; |
| 168 | 170 |
| 169 // Persistent information needed by the parallel processing | 171 // Persistent information needed by the parallel processing |
| 170 typedef struct { | 172 typedef struct { |
| 171 int id_; // cache row to process (in [0..2]) | 173 int id_; // cache row to process (in [0..2]) |
| 172 int mb_y_; // macroblock position of the row | 174 int mb_y_; // macroblock position of the row |
| 173 int filter_row_; // true if row-filtering is needed | 175 int filter_row_; // true if row-filtering is needed |
| 174 VP8FInfo* f_info_; // filter strengths | 176 VP8FInfo* f_info_; // filter strengths |
| 175 VP8Io io_; // copy of the VP8Io to pass to put() | 177 VP8Io io_; // copy of the VP8Io to pass to put() |
| 176 } VP8ThreadContext; | 178 } VP8ThreadContext; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 int16_t* coeffs_; // 384 coeffs = (16+8+8) * 4*4 | 245 int16_t* coeffs_; // 384 coeffs = (16+8+8) * 4*4 |
| 244 | 246 |
| 245 uint8_t* cache_y_; // macroblock row for storing unfiltered samples | 247 uint8_t* cache_y_; // macroblock row for storing unfiltered samples |
| 246 uint8_t* cache_u_; | 248 uint8_t* cache_u_; |
| 247 uint8_t* cache_v_; | 249 uint8_t* cache_v_; |
| 248 int cache_y_stride_; | 250 int cache_y_stride_; |
| 249 int cache_uv_stride_; | 251 int cache_uv_stride_; |
| 250 | 252 |
| 251 // main memory chunk for the above data. Persistent. | 253 // main memory chunk for the above data. Persistent. |
| 252 void* mem_; | 254 void* mem_; |
| 253 int mem_size_; | 255 size_t mem_size_; |
| 254 | 256 |
| 255 // Per macroblock non-persistent infos. | 257 // Per macroblock non-persistent infos. |
| 256 int mb_x_, mb_y_; // current position, in macroblock units | 258 int mb_x_, mb_y_; // current position, in macroblock units |
| 257 uint8_t is_i4x4_; // true if intra4x4 | 259 uint8_t is_i4x4_; // true if intra4x4 |
| 258 uint8_t imodes_[16]; // one 16x16 mode (#0) or sixteen 4x4 modes | 260 uint8_t imodes_[16]; // one 16x16 mode (#0) or sixteen 4x4 modes |
| 259 uint8_t uvmode_; // chroma prediction mode | 261 uint8_t uvmode_; // chroma prediction mode |
| 260 uint8_t segment_; // block's segment | 262 uint8_t segment_; // block's segment |
| 261 | 263 |
| 262 // bit-wise info about the content of each sub-4x4 blocks: there are 16 bits | 264 // bit-wise info about the content of each sub-4x4 blocks: there are 16 bits |
| 263 // for luma (bits #0->#15), then 4 bits for chroma-u (#16->#19) and 4 bits for | 265 // for luma (bits #0->#15), then 4 bits for chroma-u (#16->#19) and 4 bits for |
| 264 // chroma-v (#20->#23), each corresponding to one 4x4 block in decoding order. | 266 // chroma-v (#20->#23), each corresponding to one 4x4 block in decoding order. |
| 265 // If the bit is set, the 4x4 block contains some non-zero coefficients. | 267 // If the bit is set, the 4x4 block contains some non-zero coefficients. |
| 266 uint32_t non_zero_; | 268 uint32_t non_zero_; |
| 267 uint32_t non_zero_ac_; | 269 uint32_t non_zero_ac_; |
| 268 | 270 |
| 269 // Filtering side-info | 271 // Filtering side-info |
| 270 int filter_type_; // 0=off, 1=simple, 2=complex | 272 int filter_type_; // 0=off, 1=simple, 2=complex |
| 271 int filter_row_; // per-row flag | 273 int filter_row_; // per-row flag |
| 272 uint8_t filter_levels_[NUM_MB_SEGMENTS]; // precalculated per-segment | 274 uint8_t filter_levels_[NUM_MB_SEGMENTS]; // precalculated per-segment |
| 273 | 275 |
| 274 // extensions | 276 // extensions |
| 275 const uint8_t* alpha_data_; // compressed alpha data (if present) | 277 const uint8_t* alpha_data_; // compressed alpha data (if present) |
| 276 size_t alpha_data_size_; | 278 size_t alpha_data_size_; |
| 277 uint8_t* alpha_plane_; // output | 279 uint8_t* alpha_plane_; // output. Persistent, contains the whole data. |
| 278 | 280 |
| 279 int layer_colorspace_; | 281 int layer_colorspace_; |
| 280 const uint8_t* layer_data_; // compressed layer data (if present) | 282 const uint8_t* layer_data_; // compressed layer data (if present) |
| 281 size_t layer_data_size_; | 283 size_t layer_data_size_; |
| 282 }; | 284 }; |
| 283 | 285 |
| 284 //------------------------------------------------------------------------------ | 286 //------------------------------------------------------------------------------ |
| 285 // internal functions. Not public. | 287 // internal functions. Not public. |
| 286 | 288 |
| 287 // in vp8.c | 289 // in vp8.c |
| 288 int VP8SetError(VP8Decoder* const dec, | 290 int VP8SetError(VP8Decoder* const dec, |
| 289 VP8StatusCode error, const char * const msg); | 291 VP8StatusCode error, const char* const msg); |
| 290 | |
| 291 // Validates the VP8 data-header and retrieve basic header information viz width | |
| 292 // and height. Returns 0 in case of formatting error. *width/*height/*has_alpha | |
| 293 // can be passed NULL. | |
| 294 int VP8GetInfo(const uint8_t* data, | |
| 295 uint32_t data_size, // data available so far | |
| 296 uint32_t chunk_size, // total data size expect in the chunk | |
| 297 int *width, int *height, int *has_alpha); | |
| 298 | 292 |
| 299 // in tree.c | 293 // in tree.c |
| 300 void VP8ResetProba(VP8Proba* const proba); | 294 void VP8ResetProba(VP8Proba* const proba); |
| 301 void VP8ParseProba(VP8BitReader* const br, VP8Decoder* const dec); | 295 void VP8ParseProba(VP8BitReader* const br, VP8Decoder* const dec); |
| 302 void VP8ParseIntraMode(VP8BitReader* const br, VP8Decoder* const dec); | 296 void VP8ParseIntraMode(VP8BitReader* const br, VP8Decoder* const dec); |
| 303 | 297 |
| 304 // in quant.c | 298 // in quant.c |
| 305 void VP8ParseQuant(VP8Decoder* const dec); | 299 void VP8ParseQuant(VP8Decoder* const dec); |
| 306 | 300 |
| 307 // in frame.c | 301 // in frame.c |
| 308 int VP8InitFrame(VP8Decoder* const dec, VP8Io* io); | 302 int VP8InitFrame(VP8Decoder* const dec, VP8Io* io); |
| 309 // Predict a block and add residual | 303 // Predict a block and add residual |
| 310 void VP8ReconstructBlock(VP8Decoder* const dec); | 304 void VP8ReconstructBlock(VP8Decoder* const dec); |
| 311 // Call io->setup() and finish setting up scan parameters. | 305 // Call io->setup() and finish setting up scan parameters. |
| 312 // After this call returns, one must always call VP8ExitCritical() with the | 306 // After this call returns, one must always call VP8ExitCritical() with the |
| 313 // same parameters. Both functions should be used in pair. Returns VP8_STATUS_OK | 307 // same parameters. Both functions should be used in pair. Returns VP8_STATUS_OK |
| 314 // if ok, otherwise sets and returns the error status on *dec. | 308 // if ok, otherwise sets and returns the error status on *dec. |
| 315 VP8StatusCode VP8EnterCritical(VP8Decoder* const dec, VP8Io* const io); | 309 VP8StatusCode VP8EnterCritical(VP8Decoder* const dec, VP8Io* const io); |
| 316 // Must always be called in pair with VP8EnterCritical(). | 310 // Must always be called in pair with VP8EnterCritical(). |
| 317 // Returns false in case of error. | 311 // Returns false in case of error. |
| 318 int VP8ExitCritical(VP8Decoder* const dec, VP8Io* const io); | 312 int VP8ExitCritical(VP8Decoder* const dec, VP8Io* const io); |
| 319 // Filter the decoded macroblock row (if needed) | |
| 320 int VP8FinishRow(VP8Decoder* const dec, VP8Io* io); // multi threaded call | |
| 321 // Process the last decoded row (filtering + output) | 313 // Process the last decoded row (filtering + output) |
| 322 int VP8ProcessRow(VP8Decoder* const dec, VP8Io* const io); | 314 int VP8ProcessRow(VP8Decoder* const dec, VP8Io* const io); |
| 323 // Store a block, along with filtering params | 315 // Store a block, along with filtering params |
| 324 void VP8StoreBlock(VP8Decoder* const dec); | 316 void VP8StoreBlock(VP8Decoder* const dec); |
| 325 // Finalize and transmit a complete row. Return false in case of user-abort. | |
| 326 int VP8FinishRow(VP8Decoder* const dec, VP8Io* const io); | |
| 327 // To be called at the start of a new scanline, to initialize predictors. | 317 // To be called at the start of a new scanline, to initialize predictors. |
| 328 void VP8InitScanline(VP8Decoder* const dec); | 318 void VP8InitScanline(VP8Decoder* const dec); |
| 329 // Decode one macroblock. Returns false if there is not enough data. | 319 // Decode one macroblock. Returns false if there is not enough data. |
| 330 int VP8DecodeMB(VP8Decoder* const dec, VP8BitReader* const token_br); | 320 int VP8DecodeMB(VP8Decoder* const dec, VP8BitReader* const token_br); |
| 331 | 321 |
| 332 // in alpha.c | 322 // in alpha.c |
| 333 const uint8_t* VP8DecompressAlphaRows(VP8Decoder* const dec, | 323 const uint8_t* VP8DecompressAlphaRows(VP8Decoder* const dec, |
| 334 int row, int num_rows); | 324 int row, int num_rows); |
| 335 | 325 |
| 336 // in layer.c | 326 // in layer.c |
| 337 int VP8DecodeLayer(VP8Decoder* const dec); | 327 int VP8DecodeLayer(VP8Decoder* const dec); |
| 338 | 328 |
| 339 //------------------------------------------------------------------------------ | 329 //------------------------------------------------------------------------------ |
| 340 | 330 |
| 341 #if defined(__cplusplus) || defined(c_plusplus) | 331 #if defined(__cplusplus) || defined(c_plusplus) |
| 342 } // extern "C" | 332 } // extern "C" |
| 343 #endif | 333 #endif |
| 344 | 334 |
| 345 #endif /* WEBP_DEC_VP8I_H_ */ | 335 #endif /* WEBP_DEC_VP8I_H_ */ |
| OLD | NEW |