Path: blob/master/3rdparty/libwebp/src/dec/quant_dec.c
16358 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// Quantizer initialization10//11// Author: Skal ([email protected])1213#include "src/dec/vp8i_dec.h"1415static WEBP_INLINE int clip(int v, int M) {16return v < 0 ? 0 : v > M ? M : v;17}1819// Paragraph 14.120static const uint8_t kDcTable[128] = {214, 5, 6, 7, 8, 9, 10, 10,2211, 12, 13, 14, 15, 16, 17, 17,2318, 19, 20, 20, 21, 21, 22, 22,2423, 23, 24, 25, 25, 26, 27, 28,2529, 30, 31, 32, 33, 34, 35, 36,2637, 37, 38, 39, 40, 41, 42, 43,2744, 45, 46, 46, 47, 48, 49, 50,2851, 52, 53, 54, 55, 56, 57, 58,2959, 60, 61, 62, 63, 64, 65, 66,3067, 68, 69, 70, 71, 72, 73, 74,3175, 76, 76, 77, 78, 79, 80, 81,3282, 83, 84, 85, 86, 87, 88, 89,3391, 93, 95, 96, 98, 100, 101, 102,34104, 106, 108, 110, 112, 114, 116, 118,35122, 124, 126, 128, 130, 132, 134, 136,36138, 140, 143, 145, 148, 151, 154, 15737};3839static const uint16_t kAcTable[128] = {404, 5, 6, 7, 8, 9, 10, 11,4112, 13, 14, 15, 16, 17, 18, 19,4220, 21, 22, 23, 24, 25, 26, 27,4328, 29, 30, 31, 32, 33, 34, 35,4436, 37, 38, 39, 40, 41, 42, 43,4544, 45, 46, 47, 48, 49, 50, 51,4652, 53, 54, 55, 56, 57, 58, 60,4762, 64, 66, 68, 70, 72, 74, 76,4878, 80, 82, 84, 86, 88, 90, 92,4994, 96, 98, 100, 102, 104, 106, 108,50110, 112, 114, 116, 119, 122, 125, 128,51131, 134, 137, 140, 143, 146, 149, 152,52155, 158, 161, 164, 167, 170, 173, 177,53181, 185, 189, 193, 197, 201, 205, 209,54213, 217, 221, 225, 229, 234, 239, 245,55249, 254, 259, 264, 269, 274, 279, 28456};5758//------------------------------------------------------------------------------59// Paragraph 9.66061void VP8ParseQuant(VP8Decoder* const dec) {62VP8BitReader* const br = &dec->br_;63const int base_q0 = VP8GetValue(br, 7);64const int dqy1_dc = VP8Get(br) ? VP8GetSignedValue(br, 4) : 0;65const int dqy2_dc = VP8Get(br) ? VP8GetSignedValue(br, 4) : 0;66const int dqy2_ac = VP8Get(br) ? VP8GetSignedValue(br, 4) : 0;67const int dquv_dc = VP8Get(br) ? VP8GetSignedValue(br, 4) : 0;68const int dquv_ac = VP8Get(br) ? VP8GetSignedValue(br, 4) : 0;6970const VP8SegmentHeader* const hdr = &dec->segment_hdr_;71int i;7273for (i = 0; i < NUM_MB_SEGMENTS; ++i) {74int q;75if (hdr->use_segment_) {76q = hdr->quantizer_[i];77if (!hdr->absolute_delta_) {78q += base_q0;79}80} else {81if (i > 0) {82dec->dqm_[i] = dec->dqm_[0];83continue;84} else {85q = base_q0;86}87}88{89VP8QuantMatrix* const m = &dec->dqm_[i];90m->y1_mat_[0] = kDcTable[clip(q + dqy1_dc, 127)];91m->y1_mat_[1] = kAcTable[clip(q + 0, 127)];9293m->y2_mat_[0] = kDcTable[clip(q + dqy2_dc, 127)] * 2;94// For all x in [0..284], x*155/100 is bitwise equal to (x*101581) >> 16.95// The smallest precision for that is '(x*6349) >> 12' but 16 is a good96// word size.97m->y2_mat_[1] = (kAcTable[clip(q + dqy2_ac, 127)] * 101581) >> 16;98if (m->y2_mat_[1] < 8) m->y2_mat_[1] = 8;99100m->uv_mat_[0] = kDcTable[clip(q + dquv_dc, 117)];101m->uv_mat_[1] = kAcTable[clip(q + dquv_ac, 127)];102103m->uv_quant_ = q + dquv_ac; // for dithering strength evaluation104}105}106}107108//------------------------------------------------------------------------------109110111112