diff options
Diffstat (limited to 'drivers/webp/dec/tree.c')
-rw-r--r-- | drivers/webp/dec/tree.c | 149 |
1 files changed, 122 insertions, 27 deletions
diff --git a/drivers/webp/dec/tree.c b/drivers/webp/dec/tree.c index bf9b7c551a..82484e4c55 100644 --- a/drivers/webp/dec/tree.c +++ b/drivers/webp/dec/tree.c @@ -1,10 +1,8 @@ // Copyright 2010 Google Inc. All Rights Reserved. // -// Use of this source code is governed by a BSD-style license -// that can be found in the COPYING file in the root of the source -// tree. An additional intellectual property rights grant can be found -// in the file PATENTS. All contributing project authors may -// be found in the AUTHORS file in the root of the source tree. +// This code is licensed under the same terms as WebM: +// Software License Agreement: http://www.webmproject.org/license/software/ +// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // ----------------------------------------------------------------------------- // // Coding trees and probas @@ -15,6 +13,10 @@ #define USE_GENERIC_TREE +#if defined(__cplusplus) || defined(c_plusplus) +extern "C" { +#endif + #ifdef USE_GENERIC_TREE static const int8_t kYModesIntra4[18] = { -B_DC_PRED, 1, @@ -29,12 +31,61 @@ static const int8_t kYModesIntra4[18] = { }; #endif +#ifndef ONLY_KEYFRAME_CODE + +// inter prediction modes +enum { + LEFT4 = 0, ABOVE4 = 1, ZERO4 = 2, NEW4 = 3, + NEARESTMV, NEARMV, ZEROMV, NEWMV, SPLITMV }; + +static const int8_t kYModesInter[8] = { + -DC_PRED, 1, + 2, 3, + -V_PRED, -H_PRED, + -TM_PRED, -B_PRED +}; + +static const int8_t kMBSplit[6] = { + -3, 1, + -2, 2, + -0, -1 +}; + +static const int8_t kMVRef[8] = { + -ZEROMV, 1, + -NEARESTMV, 2, + -NEARMV, 3, + -NEWMV, -SPLITMV +}; + +static const int8_t kMVRef4[6] = { + -LEFT4, 1, + -ABOVE4, 2, + -ZERO4, -NEW4 +}; +#endif + //------------------------------------------------------------------------------ // Default probabilities +// Inter +#ifndef ONLY_KEYFRAME_CODE +static const uint8_t kYModeProbaInter0[4] = { 112, 86, 140, 37 }; +static const uint8_t kUVModeProbaInter0[3] = { 162, 101, 204 }; +static const uint8_t kMVProba0[2][NUM_MV_PROBAS] = { + { 162, 128, 225, 146, 172, 147, 214, 39, + 156, 128, 129, 132, 75, 145, 178, 206, + 239, 254, 254 }, + { 164, 128, 204, 170, 119, 235, 140, 230, + 228, 128, 130, 130, 74, 148, 180, 203, + 236, 254, 254 } +}; +#endif + // Paragraph 13.5 static const uint8_t CoeffsProba0[NUM_TYPES][NUM_BANDS][NUM_CTX][NUM_PROBAS] = { + // genereated using vp8_default_coef_probs() in entropy.c:129 { { { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 }, { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 }, { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 } @@ -275,25 +326,28 @@ static const uint8_t kBModesProba[NUM_BMODES][NUM_BMODES][NUM_BMODES - 1] = { void VP8ResetProba(VP8Proba* const proba) { memset(proba->segments_, 255u, sizeof(proba->segments_)); - // proba->bands_[][] is initialized later + memcpy(proba->coeffs_, CoeffsProba0, sizeof(CoeffsProba0)); +#ifndef ONLY_KEYFRAME_CODE + memcpy(proba->mv_, kMVProba0, sizeof(kMVProba0)); + memcpy(proba->ymode_, kYModeProbaInter0, sizeof(kYModeProbaInter0)); + memcpy(proba->uvmode_, kUVModeProbaInter0, sizeof(kUVModeProbaInter0)); +#endif } -void VP8ParseIntraMode(VP8BitReader* const br, VP8Decoder* const dec) { +void VP8ParseIntraMode(VP8BitReader* const br, VP8Decoder* const dec) { uint8_t* const top = dec->intra_t_ + 4 * dec->mb_x_; uint8_t* const left = dec->intra_l_; - VP8MBData* const block = dec->mb_data_ + dec->mb_x_; - - block->is_i4x4_ = !VP8GetBit(br, 145); // decide for B_PRED first - if (!block->is_i4x4_) { - // Hardcoded 16x16 intra-mode decision tree. + // Hardcoded 16x16 intra-mode decision tree. + dec->is_i4x4_ = !VP8GetBit(br, 145); // decide for B_PRED first + if (!dec->is_i4x4_) { const int ymode = VP8GetBit(br, 156) ? (VP8GetBit(br, 128) ? TM_PRED : H_PRED) : (VP8GetBit(br, 163) ? V_PRED : DC_PRED); - block->imodes_[0] = ymode; - memset(top, ymode, 4 * sizeof(*top)); - memset(left, ymode, 4 * sizeof(*left)); + dec->imodes_[0] = ymode; + memset(top, ymode, 4 * sizeof(top[0])); + memset(left, ymode, 4 * sizeof(left[0])); } else { - uint8_t* modes = block->imodes_; + uint8_t* modes = dec->imodes_; int y; for (y = 0; y < 4; ++y) { int ymode = left[y]; @@ -302,10 +356,10 @@ void VP8ParseIntraMode(VP8BitReader* const br, VP8Decoder* const dec) { const uint8_t* const prob = kBModesProba[top[x]][ymode]; #ifdef USE_GENERIC_TREE // Generic tree-parsing - int i = kYModesIntra4[VP8GetBit(br, prob[0])]; - while (i > 0) { + int i = 0; + do { i = kYModesIntra4[2 * i + VP8GetBit(br, prob[i])]; - } + } while (i > 0); ymode = -i; #else // Hardcoded tree parsing @@ -320,16 +374,15 @@ void VP8ParseIntraMode(VP8BitReader* const br, VP8Decoder* const dec) { (!VP8GetBit(br, prob[8]) ? B_HD_PRED : B_HU_PRED))); #endif // USE_GENERIC_TREE top[x] = ymode; + *modes++ = ymode; } - memcpy(modes, top, 4 * sizeof(*top)); - modes += 4; left[y] = ymode; } } // Hardcoded UVMode decision tree - block->uvmode_ = !VP8GetBit(br, 142) ? DC_PRED - : !VP8GetBit(br, 114) ? V_PRED - : VP8GetBit(br, 183) ? TM_PRED : H_PRED; + dec->uvmode_ = !VP8GetBit(br, 142) ? DC_PRED + : !VP8GetBit(br, 114) ? V_PRED + : VP8GetBit(br, 183) ? TM_PRED : H_PRED; } //------------------------------------------------------------------------------ @@ -471,6 +524,17 @@ static const uint8_t } }; +#ifndef ONLY_KEYFRAME_CODE +static const uint8_t MVUpdateProba[2][NUM_MV_PROBAS] = { + { 237, 246, 253, 253, 254, 254, 254, 254, + 254, 254, 254, 254, 254, 254, 250, 250, + 252, 254, 254 }, + { 231, 243, 245, 253, 254, 254, 254, 254, + 254, 254, 254, 254, 254, 254, 251, 251, + 254, 254, 254 } +}; +#endif + // Paragraph 9.9 void VP8ParseProba(VP8BitReader* const br, VP8Decoder* const dec) { VP8Proba* const proba = &dec->proba_; @@ -479,9 +543,9 @@ void VP8ParseProba(VP8BitReader* const br, VP8Decoder* const dec) { for (b = 0; b < NUM_BANDS; ++b) { for (c = 0; c < NUM_CTX; ++c) { for (p = 0; p < NUM_PROBAS; ++p) { - const int v = VP8GetBit(br, CoeffsUpdateProba[t][b][c][p]) ? - VP8GetValue(br, 8) : CoeffsProba0[t][b][c][p]; - proba->bands_[t][b].probas_[c][p] = v; + if (VP8GetBit(br, CoeffsUpdateProba[t][b][c][p])) { + proba->coeffs_[t][b][c][p] = VP8GetValue(br, 8); + } } } } @@ -490,5 +554,36 @@ void VP8ParseProba(VP8BitReader* const br, VP8Decoder* const dec) { if (dec->use_skip_proba_) { dec->skip_p_ = VP8GetValue(br, 8); } +#ifndef ONLY_KEYFRAME_CODE + if (!dec->frm_hdr_.key_frame_) { + int i; + dec->intra_p_ = VP8GetValue(br, 8); + dec->last_p_ = VP8GetValue(br, 8); + dec->golden_p_ = VP8GetValue(br, 8); + if (VP8Get(br)) { // update y-mode + for (i = 0; i < 4; ++i) { + proba->ymode_[i] = VP8GetValue(br, 8); + } + } + if (VP8Get(br)) { // update uv-mode + for (i = 0; i < 3; ++i) { + proba->uvmode_[i] = VP8GetValue(br, 8); + } + } + // update MV + for (i = 0; i < 2; ++i) { + int k; + for (k = 0; k < NUM_MV_PROBAS; ++k) { + if (VP8GetBit(br, MVUpdateProba[i][k])) { + const int v = VP8GetValue(br, 7); + proba->mv_[i][k] = v ? v << 1 : 1; + } + } + } + } +#endif } +#if defined(__cplusplus) || defined(c_plusplus) +} // extern "C" +#endif |