/src/libwebp/src/dec/quant_dec.c
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2010 Google Inc. All Rights Reserved. |
2 | | // |
3 | | // Use of this source code is governed by a BSD-style license |
4 | | // that can be found in the COPYING file in the root of the source |
5 | | // tree. An additional intellectual property rights grant can be found |
6 | | // in the file PATENTS. All contributing project authors may |
7 | | // be found in the AUTHORS file in the root of the source tree. |
8 | | // ----------------------------------------------------------------------------- |
9 | | // |
10 | | // Quantizer initialization |
11 | | // |
12 | | // Author: Skal (pascal.massimino@gmail.com) |
13 | | |
14 | | #include "src/dec/common_dec.h" |
15 | | #include "src/dec/vp8_dec.h" |
16 | | #include "src/dec/vp8i_dec.h" |
17 | | #include "src/utils/bit_reader_utils.h" |
18 | | #include "src/webp/types.h" |
19 | | |
20 | 0 | static WEBP_INLINE int clip(int v, int M) { |
21 | 0 | return v < 0 ? 0 : v > M ? M : v; |
22 | 0 | } |
23 | | |
24 | | // Paragraph 14.1 |
25 | | static const uint8_t kDcTable[128] = { |
26 | | 4, 5, 6, 7, 8, 9, 10, 10, |
27 | | 11, 12, 13, 14, 15, 16, 17, 17, |
28 | | 18, 19, 20, 20, 21, 21, 22, 22, |
29 | | 23, 23, 24, 25, 25, 26, 27, 28, |
30 | | 29, 30, 31, 32, 33, 34, 35, 36, |
31 | | 37, 37, 38, 39, 40, 41, 42, 43, |
32 | | 44, 45, 46, 46, 47, 48, 49, 50, |
33 | | 51, 52, 53, 54, 55, 56, 57, 58, |
34 | | 59, 60, 61, 62, 63, 64, 65, 66, |
35 | | 67, 68, 69, 70, 71, 72, 73, 74, |
36 | | 75, 76, 76, 77, 78, 79, 80, 81, |
37 | | 82, 83, 84, 85, 86, 87, 88, 89, |
38 | | 91, 93, 95, 96, 98, 100, 101, 102, |
39 | | 104, 106, 108, 110, 112, 114, 116, 118, |
40 | | 122, 124, 126, 128, 130, 132, 134, 136, |
41 | | 138, 140, 143, 145, 148, 151, 154, 157 |
42 | | }; |
43 | | |
44 | | static const uint16_t kAcTable[128] = { |
45 | | 4, 5, 6, 7, 8, 9, 10, 11, |
46 | | 12, 13, 14, 15, 16, 17, 18, 19, |
47 | | 20, 21, 22, 23, 24, 25, 26, 27, |
48 | | 28, 29, 30, 31, 32, 33, 34, 35, |
49 | | 36, 37, 38, 39, 40, 41, 42, 43, |
50 | | 44, 45, 46, 47, 48, 49, 50, 51, |
51 | | 52, 53, 54, 55, 56, 57, 58, 60, |
52 | | 62, 64, 66, 68, 70, 72, 74, 76, |
53 | | 78, 80, 82, 84, 86, 88, 90, 92, |
54 | | 94, 96, 98, 100, 102, 104, 106, 108, |
55 | | 110, 112, 114, 116, 119, 122, 125, 128, |
56 | | 131, 134, 137, 140, 143, 146, 149, 152, |
57 | | 155, 158, 161, 164, 167, 170, 173, 177, |
58 | | 181, 185, 189, 193, 197, 201, 205, 209, |
59 | | 213, 217, 221, 225, 229, 234, 239, 245, |
60 | | 249, 254, 259, 264, 269, 274, 279, 284 |
61 | | }; |
62 | | |
63 | | //------------------------------------------------------------------------------ |
64 | | // Paragraph 9.6 |
65 | | |
66 | 0 | void VP8ParseQuant(VP8Decoder* const dec) { |
67 | 0 | VP8BitReader* const br = &dec->br; |
68 | 0 | const int base_q0 = VP8GetValue(br, 7, "global-header"); |
69 | 0 | const int dqy1_dc = VP8Get(br, "global-header") ? |
70 | 0 | VP8GetSignedValue(br, 4, "global-header") : 0; |
71 | 0 | const int dqy2_dc = VP8Get(br, "global-header") ? |
72 | 0 | VP8GetSignedValue(br, 4, "global-header") : 0; |
73 | 0 | const int dqy2_ac = VP8Get(br, "global-header") ? |
74 | 0 | VP8GetSignedValue(br, 4, "global-header") : 0; |
75 | 0 | const int dquv_dc = VP8Get(br, "global-header") ? |
76 | 0 | VP8GetSignedValue(br, 4, "global-header") : 0; |
77 | 0 | const int dquv_ac = VP8Get(br, "global-header") ? |
78 | 0 | VP8GetSignedValue(br, 4, "global-header") : 0; |
79 | |
|
80 | 0 | const VP8SegmentHeader* const hdr = &dec->segment_hdr; |
81 | 0 | int i; |
82 | |
|
83 | 0 | for (i = 0; i < NUM_MB_SEGMENTS; ++i) { |
84 | 0 | int q; |
85 | 0 | if (hdr->use_segment) { |
86 | 0 | q = hdr->quantizer[i]; |
87 | 0 | if (!hdr->absolute_delta) { |
88 | 0 | q += base_q0; |
89 | 0 | } |
90 | 0 | } else { |
91 | 0 | if (i > 0) { |
92 | 0 | dec->dqm[i] = dec->dqm[0]; |
93 | 0 | continue; |
94 | 0 | } else { |
95 | 0 | q = base_q0; |
96 | 0 | } |
97 | 0 | } |
98 | 0 | { |
99 | 0 | VP8QuantMatrix* const m = &dec->dqm[i]; |
100 | 0 | m->y1_mat[0] = kDcTable[clip(q + dqy1_dc, 127)]; |
101 | 0 | m->y1_mat[1] = kAcTable[clip(q + 0, 127)]; |
102 | |
|
103 | 0 | m->y2_mat[0] = kDcTable[clip(q + dqy2_dc, 127)] * 2; |
104 | | // For all x in [0..284], x*155/100 is bitwise equal to (x*101581) >> 16. |
105 | | // The smallest precision for that is '(x*6349) >> 12' but 16 is a good |
106 | | // word size. |
107 | 0 | m->y2_mat[1] = (kAcTable[clip(q + dqy2_ac, 127)] * 101581) >> 16; |
108 | 0 | if (m->y2_mat[1] < 8) m->y2_mat[1] = 8; |
109 | |
|
110 | 0 | m->uv_mat[0] = kDcTable[clip(q + dquv_dc, 117)]; |
111 | 0 | m->uv_mat[1] = kAcTable[clip(q + dquv_ac, 127)]; |
112 | |
|
113 | 0 | m->uv_quant = q + dquv_ac; // for dithering strength evaluation |
114 | 0 | } |
115 | 0 | } |
116 | 0 | } |
117 | | |
118 | | //------------------------------------------------------------------------------ |