1 | /* The copyright in this software is being made available under the BSD |
---|
2 | * License, included below. This software may be subject to other third party |
---|
3 | * and contributor rights, including patent rights, and no such rights are |
---|
4 | * granted under this license. |
---|
5 | * |
---|
6 | * Copyright (c) 2010-2011, ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | |
---|
35 | |
---|
36 | /** \file TComTrQuant.cpp |
---|
37 | \brief transform and quantization class |
---|
38 | */ |
---|
39 | |
---|
40 | #include <stdlib.h> |
---|
41 | #include <math.h> |
---|
42 | #include <memory.h> |
---|
43 | #include "TComTrQuant.h" |
---|
44 | #include "TComPic.h" |
---|
45 | #include "ContextTables.h" |
---|
46 | |
---|
47 | // ==================================================================================================================== |
---|
48 | // Constants |
---|
49 | // ==================================================================================================================== |
---|
50 | |
---|
51 | #define RDOQ_CHROMA 1 ///< use of RDOQ in chroma |
---|
52 | |
---|
53 | #define DQ_BITS 6 |
---|
54 | #define Q_BITS_8 16 |
---|
55 | #define SIGN_BITS 1 |
---|
56 | |
---|
57 | // ==================================================================================================================== |
---|
58 | // Tables |
---|
59 | // ==================================================================================================================== |
---|
60 | |
---|
61 | // RDOQ parameter |
---|
62 | Int entropyBits[128]= |
---|
63 | { |
---|
64 | 895, 943, 994, 1048, 1105, 1165, 1228, 1294, |
---|
65 | 1364, 1439, 1517, 1599, 1686, 1778, 1875, 1978, |
---|
66 | 2086, 2200, 2321, 2448, 2583, 2725, 2876, 3034, |
---|
67 | 3202, 3380, 3568, 3767, 3977, 4199, 4435, 4684, |
---|
68 | 4948, 5228, 5525, 5840, 6173, 6527, 6903, 7303, |
---|
69 | 7727, 8178, 8658, 9169, 9714, 10294, 10914, 11575, |
---|
70 | 12282, 13038, 13849, 14717, 15650, 16653, 17734, 18899, |
---|
71 | 20159, 21523, 23005, 24617, 26378, 28306, 30426, 32768, |
---|
72 | 32768, 35232, 37696, 40159, 42623, 45087, 47551, 50015, |
---|
73 | 52479, 54942, 57406, 59870, 62334, 64798, 67262, 69725, |
---|
74 | 72189, 74653, 77117, 79581, 82044, 84508, 86972, 89436, |
---|
75 | 91900, 94363, 96827, 99291, 101755, 104219, 106683, 109146, |
---|
76 | 111610, 114074, 116538, 119002, 121465, 123929, 126393, 128857, |
---|
77 | 131321, 133785, 136248, 138712, 141176, 143640, 146104, 148568, |
---|
78 | 151031, 153495, 155959, 158423, 160887, 163351, 165814, 168278, |
---|
79 | 170742, 173207, 175669, 178134, 180598, 183061, 185525, 187989 |
---|
80 | }; |
---|
81 | |
---|
82 | static const Int estErr4x4[6][4][4]= |
---|
83 | { |
---|
84 | { |
---|
85 | {25600, 27040, 25600, 27040}, |
---|
86 | {27040, 25600, 27040, 25600}, |
---|
87 | {25600, 27040, 25600, 27040}, |
---|
88 | {27040, 25600, 27040, 25600} |
---|
89 | }, |
---|
90 | { |
---|
91 | {30976, 31360, 30976, 31360}, |
---|
92 | {31360, 32400, 31360, 32400}, |
---|
93 | {30976, 31360, 30976, 31360}, |
---|
94 | {31360, 32400, 31360, 32400} |
---|
95 | }, |
---|
96 | { |
---|
97 | {43264, 40960, 43264, 40960}, |
---|
98 | {40960, 40000, 40960, 40000}, |
---|
99 | {43264, 40960, 43264, 40960}, |
---|
100 | {40960, 40000, 40960, 40000} |
---|
101 | }, |
---|
102 | { |
---|
103 | {50176, 51840, 50176, 51840}, |
---|
104 | {51840, 52900, 51840, 52900}, |
---|
105 | {50176, 51840, 50176, 51840}, |
---|
106 | {51840, 52900, 51840, 52900} |
---|
107 | }, |
---|
108 | { |
---|
109 | {65536, 64000, 65536, 64000}, |
---|
110 | {64000, 62500, 64000, 62500}, |
---|
111 | {65536, 64000, 65536, 64000}, |
---|
112 | {64000, 62500, 64000, 62500} |
---|
113 | }, |
---|
114 | { |
---|
115 | {82944, 84640, 82944, 84640}, |
---|
116 | {84640, 84100, 84640, 84100}, |
---|
117 | {82944, 84640, 82944, 84640}, |
---|
118 | {84640, 84100, 84640, 84100} |
---|
119 | } |
---|
120 | }; |
---|
121 | |
---|
122 | static const Int estErr8x8[6][8][8]={ |
---|
123 | { |
---|
124 | {6553600, 6677056, 6400000, 6677056, 6553600, 6677056, 6400000, 6677056}, |
---|
125 | {6677056, 6765201, 6658560, 6765201, 6677056, 6765201, 6658560, 6765201}, |
---|
126 | {6400000, 6658560, 6553600, 6658560, 6400000, 6658560, 6553600, 6658560}, |
---|
127 | {6677056, 6765201, 6658560, 6765201, 6677056, 6765201, 6658560, 6765201}, |
---|
128 | {6553600, 6677056, 6400000, 6677056, 6553600, 6677056, 6400000, 6677056}, |
---|
129 | {6677056, 6765201, 6658560, 6765201, 6677056, 6765201, 6658560, 6765201}, |
---|
130 | {6400000, 6658560, 6553600, 6658560, 6400000, 6658560, 6553600, 6658560}, |
---|
131 | {6677056, 6765201, 6658560, 6765201, 6677056, 6765201, 6658560, 6765201} |
---|
132 | }, |
---|
133 | { |
---|
134 | {7929856, 8156736, 8028160, 8156736, 7929856, 8156736, 8028160, 8156736}, |
---|
135 | {8156736, 7537770, 7814560, 7537770, 8156736, 7537770, 7814560, 7537770}, |
---|
136 | {8028160, 7814560, 7840000, 7814560, 8028160, 7814560, 7840000, 7814560}, |
---|
137 | {8156736, 7537770, 7814560, 7537770, 8156736, 7537770, 7814560, 7537770}, |
---|
138 | {7929856, 8156736, 8028160, 8156736, 7929856, 8156736, 8028160, 8156736}, |
---|
139 | {8156736, 7537770, 7814560, 7537770, 8156736, 7537770, 7814560, 7537770}, |
---|
140 | {8028160, 7814560, 7840000, 7814560, 8028160, 7814560, 7840000, 7814560}, |
---|
141 | {8156736, 7537770, 7814560, 7537770, 8156736, 7537770, 7814560, 7537770} |
---|
142 | }, |
---|
143 | { |
---|
144 | {11075584, 10653696, 11151360, 10653696, 11075584, 10653696, 11151360, 10653696}, |
---|
145 | {10653696, 11045652, 11109160, 11045652, 10653696, 11045652, 11109160, 11045652}, |
---|
146 | {11151360, 11109160, 11289600, 11109160, 11151360, 11109160, 11289600, 11109160}, |
---|
147 | {10653696, 11045652, 11109160, 11045652, 10653696, 11045652, 11109160, 11045652}, |
---|
148 | {11075584, 10653696, 11151360, 10653696, 11075584, 10653696, 11151360, 10653696}, |
---|
149 | {10653696, 11045652, 11109160, 11045652, 10653696, 11045652, 11109160, 11045652}, |
---|
150 | {11151360, 11109160, 11289600, 11109160, 11151360, 11109160, 11289600, 11109160}, |
---|
151 | {10653696, 11045652, 11109160, 11045652, 10653696, 11045652, 11109160, 11045652} |
---|
152 | }, |
---|
153 | { |
---|
154 | {12845056, 12503296, 12544000, 12503296, 12845056, 12503296, 12544000, 12503296}, |
---|
155 | {12503296, 13050156, 12588840, 13050156, 12503296, 13050156, 12588840, 13050156}, |
---|
156 | {12544000, 12588840, 12960000, 12588840, 12544000, 12588840, 12960000, 12588840}, |
---|
157 | {12503296, 13050156, 12588840, 13050156, 12503296, 13050156, 12588840, 13050156}, |
---|
158 | {12845056, 12503296, 12544000, 12503296, 12845056, 12503296, 12544000, 12503296}, |
---|
159 | {12503296, 13050156, 12588840, 13050156, 12503296, 13050156, 12588840, 13050156}, |
---|
160 | {12544000, 12588840, 12960000, 12588840, 12544000, 12588840, 12960000, 12588840}, |
---|
161 | {12503296, 13050156, 12588840, 13050156, 12503296, 13050156, 12588840, 13050156} |
---|
162 | }, |
---|
163 | { |
---|
164 | {16777216, 16646400, 16384000, 16646400, 16777216, 16646400, 16384000, 16646400}, |
---|
165 | {16646400, 16370116, 16692640, 16370116, 16646400, 16370116, 16692640, 16370116}, |
---|
166 | {16384000, 16692640, 16646400, 16692640, 16384000, 16692640, 16646400, 16692640}, |
---|
167 | {16646400, 16370116, 16692640, 16370116, 16646400, 16370116, 16692640, 16370116}, |
---|
168 | {16777216, 16646400, 16384000, 16646400, 16777216, 16646400, 16384000, 16646400}, |
---|
169 | {16646400, 16370116, 16692640, 16370116, 16646400, 16370116, 16692640, 16370116}, |
---|
170 | {16384000, 16692640, 16646400, 16692640, 16384000, 16692640, 16646400, 16692640}, |
---|
171 | {16646400, 16370116, 16692640, 16370116, 16646400, 16370116, 16692640, 16370116} |
---|
172 | }, |
---|
173 | { |
---|
174 | {21233664, 21381376, 21667840, 21381376, 21233664, 21381376, 21667840, 21381376}, |
---|
175 | {21381376, 21381376, 21374440, 21381376, 21381376, 21381376, 21374440, 21381376}, |
---|
176 | {21667840, 21374440, 21529600, 21374440, 21667840, 21374440, 21529600, 21374440}, |
---|
177 | {21381376, 21381376, 21374440, 21381376, 21381376, 21381376, 21374440, 21381376}, |
---|
178 | {21233664, 21381376, 21667840, 21381376, 21233664, 21381376, 21667840, 21381376}, |
---|
179 | {21381376, 21381376, 21374440, 21381376, 21381376, 21381376, 21374440, 21381376}, |
---|
180 | {21667840, 21374440, 21529600, 21374440, 21667840, 21374440, 21529600, 21374440}, |
---|
181 | {21381376, 21381376, 21374440, 21381376, 21381376, 21381376, 21374440, 21381376} |
---|
182 | } |
---|
183 | }; |
---|
184 | |
---|
185 | #if QC_MOD_LCEC |
---|
186 | #if CAVLC_COEF_LRG_BLK |
---|
187 | static const int VLClength[14][128] = { |
---|
188 | #else |
---|
189 | static const int VLClength[13][128] = { |
---|
190 | #endif |
---|
191 | { 1, 2, 3, 4, 5, 6, 7, 9, 9,11,11,11,11,13,13,13,13,13,13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19}, |
---|
192 | { 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8,10,10,10,10,12,12,12,12,12,12,12,12,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18}, |
---|
193 | { 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,11,11,11,11,11,11,11,11,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17}, |
---|
194 | { 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16}, |
---|
195 | { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13}, |
---|
196 | { 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,30,30,31,31,32,32,33,33,34,34,35,35,36,36,37,37,38,38,39,39,40,40,41,41,42,42,43,43,44,44,45,45,46,46,47,47,48,48,49,49,50,50,51,51,52,52,53,53,54,54,55,55,56,56,57,57,58,58,59,59,60,60,61,61,62,62,63,63,64,64,65,65}, |
---|
197 | { 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,14,15,15,15,15,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,22,22,22,22,23,23,23,23,24,24,24,24,25,25,25,25,26,26,26,26,27,27,27,27,28,28,28,28,29,29,29,29,30,30,30,30,31,31,31,31,32,32,32,32,33,33,33,33,34,34,34,34}, |
---|
198 | { 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19}, |
---|
199 | { 1, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, |
---|
200 | { 3, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13}, |
---|
201 | { 1, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,15}, |
---|
202 | |
---|
203 | { 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8}, |
---|
204 | { 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8} |
---|
205 | #if CAVLC_COEF_LRG_BLK |
---|
206 | ,{ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12} |
---|
207 | #endif |
---|
208 | }; |
---|
209 | #endif |
---|
210 | static const Int estErr16x16[6] = { 25329, 30580, 42563, 49296, 64244, 82293 }; |
---|
211 | static const Int estErr32x32[6] = { 25351, 30674, 42843, 49687, 64898, 82136 }; |
---|
212 | |
---|
213 | // ==================================================================================================================== |
---|
214 | // Qp class member functions |
---|
215 | // ==================================================================================================================== |
---|
216 | |
---|
217 | QpParam::QpParam() |
---|
218 | { |
---|
219 | } |
---|
220 | |
---|
221 | Void QpParam::initOffsetParam( Int iStartQP, Int iEndQP ) |
---|
222 | { |
---|
223 | Int iDefaultOffset; |
---|
224 | Int iDefaultOffset_LTR; |
---|
225 | |
---|
226 | Int iPer; |
---|
227 | |
---|
228 | for (Int iQP = iStartQP; iQP <= iEndQP; iQP++) |
---|
229 | { |
---|
230 | for (UInt uiSliceType = 0; uiSliceType < 3; uiSliceType++) |
---|
231 | { |
---|
232 | Int k = (iQP + 6*g_uiBitIncrement)/6; |
---|
233 | #if FULL_NBIT |
---|
234 | k += g_uiBitDepth - 8; |
---|
235 | #endif |
---|
236 | |
---|
237 | Bool bLowPass = (uiSliceType == 0); |
---|
238 | iDefaultOffset = (bLowPass? 10922 : 5462); |
---|
239 | |
---|
240 | bLowPass = (uiSliceType == 0); |
---|
241 | iDefaultOffset_LTR = (bLowPass? 170 : 86); |
---|
242 | |
---|
243 | iPer = QP_BITS + k - QOFFSET_BITS; |
---|
244 | m_aiAdd2x2[iQP][uiSliceType] = iDefaultOffset << iPer; |
---|
245 | m_aiAdd4x4[iQP][uiSliceType] = iDefaultOffset << iPer; |
---|
246 | |
---|
247 | iPer = QP_BITS + 1 + k - QOFFSET_BITS; |
---|
248 | m_aiAdd8x8[iQP][uiSliceType] = iDefaultOffset << iPer; |
---|
249 | |
---|
250 | iPer = ECore16Shift + k - QOFFSET_BITS_LTR; |
---|
251 | m_aiAdd16x16[iQP][uiSliceType] = iDefaultOffset_LTR << iPer; |
---|
252 | |
---|
253 | iPer = ECore32Shift + k - QOFFSET_BITS_LTR; |
---|
254 | m_aiAdd32x32[iQP][uiSliceType] = iDefaultOffset_LTR << iPer; |
---|
255 | } |
---|
256 | } |
---|
257 | } |
---|
258 | |
---|
259 | // ==================================================================================================================== |
---|
260 | // TComTrQuant class member functions |
---|
261 | // ==================================================================================================================== |
---|
262 | |
---|
263 | TComTrQuant::TComTrQuant() |
---|
264 | { |
---|
265 | m_cQP.clear(); |
---|
266 | |
---|
267 | // allocate temporary buffers |
---|
268 | m_plTempCoeff = new Long[ MAX_CU_SIZE*MAX_CU_SIZE ]; |
---|
269 | |
---|
270 | // allocate bit estimation class (for RDOQ) |
---|
271 | m_pcEstBitsSbac = new estBitsSbacStruct; |
---|
272 | } |
---|
273 | |
---|
274 | TComTrQuant::~TComTrQuant() |
---|
275 | { |
---|
276 | // delete temporary buffers |
---|
277 | if ( m_plTempCoeff ) |
---|
278 | { |
---|
279 | delete [] m_plTempCoeff; |
---|
280 | m_plTempCoeff = NULL; |
---|
281 | } |
---|
282 | |
---|
283 | // delete bit estimation class |
---|
284 | if ( m_pcEstBitsSbac ) delete m_pcEstBitsSbac; |
---|
285 | } |
---|
286 | |
---|
287 | /// Including Chroma QP Parameter setting |
---|
288 | Void TComTrQuant::setQPforQuant( Int iQP, Bool bLowpass, SliceType eSliceType, TextType eTxtType) |
---|
289 | { |
---|
290 | iQP = Max( Min( iQP, 51 ), 0 ); |
---|
291 | |
---|
292 | if(eTxtType != TEXT_LUMA) //Chroma |
---|
293 | { |
---|
294 | iQP = g_aucChromaScale[ iQP ]; |
---|
295 | } |
---|
296 | |
---|
297 | m_cQP.setQpParam( iQP, bLowpass, eSliceType, m_bEnc ); |
---|
298 | } |
---|
299 | |
---|
300 | #if E243_CORE_TRANSFORMS |
---|
301 | |
---|
302 | #if MATRIX_MULT |
---|
303 | /** NxN forward transform (2D) using brute force matrix multiplication (3 nested loops) |
---|
304 | * \param block pointer to input data (residual) |
---|
305 | * \param coeff pointer to output data (transform coefficients) |
---|
306 | * \param uiStride stride of input data |
---|
307 | * \param uiTrSize transform size (uiTrSize x uiTrSize) |
---|
308 | * \param uiMode is Intra Prediction mode used in Mode-Dependent DCT/DST only |
---|
309 | */ |
---|
310 | #if INTRA_DST_TYPE_7 |
---|
311 | void xTr(Pel *block, Long *coeff, UInt uiStride, UInt uiTrSize, UInt uiMode) |
---|
312 | #else |
---|
313 | void xTr(Pel *block, Long *coeff, UInt uiStride, UInt uiTrSize) |
---|
314 | #endif |
---|
315 | { |
---|
316 | Int i,j,k,iSum; |
---|
317 | Int tmp[32*32]; |
---|
318 | const short *iT; |
---|
319 | UInt uiLog2TrSize = g_aucConvertToBit[ uiTrSize ] + 2; |
---|
320 | |
---|
321 | if (uiTrSize==4) |
---|
322 | { |
---|
323 | iT = g_aiT4[0]; |
---|
324 | } |
---|
325 | else if (uiTrSize==8) |
---|
326 | { |
---|
327 | iT = g_aiT8[0]; |
---|
328 | } |
---|
329 | else if (uiTrSize==16) |
---|
330 | { |
---|
331 | iT = g_aiT16[0]; |
---|
332 | } |
---|
333 | else if (uiTrSize==32) |
---|
334 | { |
---|
335 | iT = g_aiT32[0]; |
---|
336 | } |
---|
337 | else{ |
---|
338 | assert(0); |
---|
339 | } |
---|
340 | |
---|
341 | #if FULL_NBIT |
---|
342 | int shift_1st = uiLog2TrSize - 1 + g_uiBitDepth - 8; // log2(N) - 1 + g_uiBitDepth - 8 |
---|
343 | #else |
---|
344 | int shift_1st = uiLog2TrSize - 1 + g_uiBitIncrement; // log2(N) - 1 + g_uiBitIncrement |
---|
345 | #endif |
---|
346 | |
---|
347 | int add_1st = 1<<(shift_1st-1); |
---|
348 | int shift_2nd = uiLog2TrSize + 6; |
---|
349 | int add_2nd = 1<<(shift_2nd-1); |
---|
350 | |
---|
351 | /* Horizontal transform */ |
---|
352 | |
---|
353 | #if INTRA_DST_TYPE_7 |
---|
354 | if (uiTrSize==4) |
---|
355 | { |
---|
356 | if (uiMode != REG_DCT && g_aucDCTDSTMode_Hor[uiMode]) |
---|
357 | { |
---|
358 | iT = g_as_DST_MAT_4[0]; |
---|
359 | } |
---|
360 | } |
---|
361 | #endif |
---|
362 | for (i=0; i<uiTrSize; i++) |
---|
363 | { |
---|
364 | for (j=0; j<uiTrSize; j++) |
---|
365 | { |
---|
366 | iSum = 0; |
---|
367 | for (k=0; k<uiTrSize; k++) |
---|
368 | { |
---|
369 | iSum += iT[i*uiTrSize+k]*block[j*uiStride+k]; |
---|
370 | } |
---|
371 | tmp[i*uiTrSize+j] = (iSum + add_1st)>>shift_1st; |
---|
372 | } |
---|
373 | } |
---|
374 | /* Vertical transform */ |
---|
375 | #if INTRA_DST_TYPE_7 |
---|
376 | if (uiTrSize==4) |
---|
377 | { |
---|
378 | if (uiMode != REG_DCT && g_aucDCTDSTMode_Vert[uiMode]) |
---|
379 | { |
---|
380 | iT = g_as_DST_MAT_4[0]; |
---|
381 | } |
---|
382 | else |
---|
383 | { |
---|
384 | iT = g_aiT4[0]; |
---|
385 | } |
---|
386 | } |
---|
387 | #endif |
---|
388 | for (i=0; i<uiTrSize; i++) |
---|
389 | { |
---|
390 | for (j=0; j<uiTrSize; j++) |
---|
391 | { |
---|
392 | iSum = 0; |
---|
393 | for (k=0; k<uiTrSize; k++) |
---|
394 | { |
---|
395 | iSum += iT[i*uiTrSize+k]*tmp[j*uiTrSize+k]; |
---|
396 | } |
---|
397 | coeff[i*uiTrSize+j] = (iSum + add_2nd)>>shift_2nd; |
---|
398 | } |
---|
399 | } |
---|
400 | } |
---|
401 | |
---|
402 | /** NxN inverse transform (2D) using brute force matrix multiplication (3 nested loops) |
---|
403 | * \param coeff pointer to input data (transform coefficients) |
---|
404 | * \param block pointer to output data (residual) |
---|
405 | * \param uiStride stride of output data |
---|
406 | * \param uiTrSize transform size (uiTrSize x uiTrSize) |
---|
407 | * \param uiMode is Intra Prediction mode used in Mode-Dependent DCT/DST only |
---|
408 | */ |
---|
409 | #if INTRA_DST_TYPE_7 |
---|
410 | void xITr(Long *coeff, Pel *block, UInt uiStride, UInt uiTrSize, UInt uiMode) |
---|
411 | #else |
---|
412 | void xITr(Long *coeff, Pel *block, UInt uiStride, UInt uiTrSize) |
---|
413 | #endif |
---|
414 | { |
---|
415 | int i,j,k,iSum; |
---|
416 | Int tmp[32*32]; |
---|
417 | const short *iT; |
---|
418 | UInt uiLog2TrSize = g_aucConvertToBit[ uiTrSize ] + 2; |
---|
419 | if (uiTrSize==4) |
---|
420 | { |
---|
421 | iT = g_aiT4[0]; |
---|
422 | } |
---|
423 | else if (uiTrSize==8) |
---|
424 | { |
---|
425 | iT = g_aiT8[0]; |
---|
426 | } |
---|
427 | else if (uiTrSize==16) |
---|
428 | { |
---|
429 | iT = g_aiT16[0]; |
---|
430 | } |
---|
431 | else if (uiTrSize==32) |
---|
432 | { |
---|
433 | iT = g_aiT32[0]; |
---|
434 | } |
---|
435 | else{ |
---|
436 | assert(0); |
---|
437 | } |
---|
438 | int shift_1st = SHIFT_INV_1ST; |
---|
439 | int add_1st = 1<<(shift_1st-1); |
---|
440 | #if FULL_NBIT |
---|
441 | int shift_2nd = SHIFT_INV_2ND - ((short)g_uiBitDepth - 8); |
---|
442 | #else |
---|
443 | int shift_2nd = SHIFT_INV_2ND - g_uiBitIncrement; |
---|
444 | #endif |
---|
445 | int add_2nd = 1<<(shift_2nd-1); |
---|
446 | #if INTRA_DST_TYPE_7 |
---|
447 | if (uiTrSize==4) |
---|
448 | { |
---|
449 | if (uiMode != REG_DCT && g_aucDCTDSTMode_Vert[uiMode] ) // Check for DCT or DST |
---|
450 | { |
---|
451 | iT = g_as_DST_MAT_4[0]; |
---|
452 | } |
---|
453 | } |
---|
454 | #endif |
---|
455 | /* Horizontal transform */ |
---|
456 | for (i=0; i<uiTrSize; i++) |
---|
457 | { |
---|
458 | for (j=0; j<uiTrSize; j++) |
---|
459 | { |
---|
460 | iSum = 0; |
---|
461 | for (k=0; k<uiTrSize; k++) |
---|
462 | { |
---|
463 | iSum += iT[k*uiTrSize+i]*coeff[k*uiTrSize+j]; |
---|
464 | } |
---|
465 | tmp[i*uiTrSize+j] = (iSum + add_1st)>>shift_1st; |
---|
466 | } |
---|
467 | } |
---|
468 | #if INTRA_DST_TYPE_7 |
---|
469 | if (uiTrSize==4) |
---|
470 | { |
---|
471 | if (uiMode != REG_DCT && g_aucDCTDSTMode_Hor[uiMode] ) // Check for DCT or DST |
---|
472 | { |
---|
473 | iT = g_as_DST_MAT_4[0]; |
---|
474 | } |
---|
475 | else |
---|
476 | { |
---|
477 | iT = g_aiT4[0]; |
---|
478 | } |
---|
479 | } |
---|
480 | #endif |
---|
481 | /* Vertical transform */ |
---|
482 | for (i=0; i<uiTrSize; i++) |
---|
483 | { |
---|
484 | for (j=0; j<uiTrSize; j++) |
---|
485 | { |
---|
486 | iSum = 0; |
---|
487 | for (k=0; k<uiTrSize; k++) |
---|
488 | { |
---|
489 | iSum += iT[k*uiTrSize+j]*tmp[i*uiTrSize+k]; |
---|
490 | } |
---|
491 | block[i*uiStride+j] = (iSum + add_2nd)>>shift_2nd; |
---|
492 | } |
---|
493 | } |
---|
494 | } |
---|
495 | |
---|
496 | #else //MATRIX_MULT |
---|
497 | |
---|
498 | /** 4x4 forward transform implemented using partial butterfly structure (1D) |
---|
499 | * \param block input data (residual) |
---|
500 | * \param coeff output data (transform coefficients) |
---|
501 | * \param shift specifies right shift after 1D transform |
---|
502 | */ |
---|
503 | void partialButterfly4(short block[4][4],short coeff[4][4],int shift) |
---|
504 | { |
---|
505 | int j; |
---|
506 | int E[2],O[2]; |
---|
507 | int add = 1<<(shift-1); |
---|
508 | |
---|
509 | for (j=0; j<4; j++) |
---|
510 | { |
---|
511 | /* E and O */ |
---|
512 | E[0] = block[j][0] + block[j][3]; |
---|
513 | O[0] = block[j][0] - block[j][3]; |
---|
514 | E[1] = block[j][1] + block[j][2]; |
---|
515 | O[1] = block[j][1] - block[j][2]; |
---|
516 | |
---|
517 | coeff[0][j] = (g_aiT4[0][0]*E[0] + g_aiT4[0][1]*E[1] + add)>>shift; |
---|
518 | coeff[2][j] = (g_aiT4[2][0]*E[0] + g_aiT4[2][1]*E[1] + add)>>shift; |
---|
519 | coeff[1][j] = (g_aiT4[1][0]*O[0] + g_aiT4[1][1]*O[1] + add)>>shift; |
---|
520 | coeff[3][j] = (g_aiT4[3][0]*O[0] + g_aiT4[3][1]*O[1] + add)>>shift; |
---|
521 | } |
---|
522 | } |
---|
523 | |
---|
524 | #if INTRA_DST_TYPE_7 |
---|
525 | // Fast DST Algorithm. Full matrix multiplication for DST and Fast DST algorithm |
---|
526 | // give identical results |
---|
527 | void fastForwardDst(short block[4][4],short coeff[4][4],int shift) // input block, output coeff |
---|
528 | { |
---|
529 | int i, c[4]; |
---|
530 | int rnd_factor = 1<<(shift-1); |
---|
531 | for (i=0; i<4; i++) |
---|
532 | { |
---|
533 | // Intermediate Variables |
---|
534 | c[0] = block[i][0] + block[i][3]; |
---|
535 | c[1] = block[i][1] + block[i][3]; |
---|
536 | c[2] = block[i][0] - block[i][1]; |
---|
537 | c[3] = 74* block[i][2]; |
---|
538 | |
---|
539 | coeff[0][i] = ( 29 * c[0] + 55 * c[1] + c[3] + rnd_factor ) >> shift; |
---|
540 | coeff[1][i] = ( 74 * (block[i][0]+ block[i][1] - block[i][3]) + rnd_factor ) >> shift; |
---|
541 | coeff[2][i] = ( 29 * c[2] + 55 * c[0] - c[3] + rnd_factor ) >> shift; |
---|
542 | coeff[3][i] = ( 55 * c[2] - 29 * c[1] + c[3] + rnd_factor ) >> shift; |
---|
543 | } |
---|
544 | } |
---|
545 | void fastInverseDst(short tmp[4][4],short block[4][4],int shift) // input tmp, output block |
---|
546 | { |
---|
547 | int i, c[4]; |
---|
548 | int rnd_factor = 1<<(shift-1); |
---|
549 | for (i=0; i<4; i++) |
---|
550 | { |
---|
551 | // Intermediate Variables |
---|
552 | c[0] = tmp[0][i] + tmp[2][i]; |
---|
553 | c[1] = tmp[2][i] + tmp[3][i]; |
---|
554 | c[2] = tmp[0][i] - tmp[3][i]; |
---|
555 | c[3] = 74* tmp[1][i]; |
---|
556 | |
---|
557 | block[i][0] = ( 29 * c[0] + 55 * c[1] + c[3] + rnd_factor ) >> shift; |
---|
558 | block[i][1] = ( 55 * c[2] - 29 * c[1] + c[3] + rnd_factor ) >> shift; |
---|
559 | block[i][2] = ( 74 * (tmp[0][i] - tmp[2][i] + tmp[3][i]) + rnd_factor ) >> shift; |
---|
560 | block[i][3] = ( 55 * c[0] + 29 * c[2] - c[3] + rnd_factor ) >> shift; |
---|
561 | } |
---|
562 | } |
---|
563 | #endif |
---|
564 | /** 4x4 forward transform (2D) |
---|
565 | * \param block input data (residual) |
---|
566 | * \param coeff output data (transform coefficients) |
---|
567 | * \param uiMode is Intra Prediction mode used in Mode-Dependent DCT/DST only |
---|
568 | */ |
---|
569 | #if INTRA_DST_TYPE_7 |
---|
570 | void xTr4(short block[4][4],short coeff[4][4],UInt uiMode) |
---|
571 | #else |
---|
572 | void xTr4(short block[4][4],short coeff[4][4]) |
---|
573 | #endif |
---|
574 | { |
---|
575 | #if FULL_NBIT |
---|
576 | int shift_1st = 1 + g_uiBitDepth - 8; // log2(4) - 1 + g_uiBitDepth - 8 |
---|
577 | #else |
---|
578 | int shift_1st = 1 + g_uiBitIncrement; // log2(4) - 1 + g_uiBitIncrement |
---|
579 | #endif |
---|
580 | int shift_2nd = 8; // log2(4) + 6 |
---|
581 | short tmp[4][4]; |
---|
582 | #if INTRA_DST_TYPE_7 |
---|
583 | if (uiMode != REG_DCT && g_aucDCTDSTMode_Hor[uiMode])// Check for DCT or DST |
---|
584 | { |
---|
585 | fastForwardDst(block,tmp,shift_1st); // Forward DST BY FAST ALGORITHM, block input, tmp output |
---|
586 | } |
---|
587 | else |
---|
588 | { |
---|
589 | partialButterfly4(block,tmp,shift_1st); |
---|
590 | } |
---|
591 | #else |
---|
592 | partialButterfly4(block,tmp,shift_1st); |
---|
593 | #endif |
---|
594 | |
---|
595 | #if INTRA_DST_TYPE_7 |
---|
596 | if (uiMode != REG_DCT && g_aucDCTDSTMode_Vert[uiMode] ) // Check for DCT or DST |
---|
597 | { |
---|
598 | fastForwardDst(tmp,coeff,shift_2nd); // Forward DST BY FAST ALGORITHM, tmp input, coeff output |
---|
599 | } |
---|
600 | else |
---|
601 | { |
---|
602 | partialButterfly4(tmp,coeff,shift_2nd); |
---|
603 | } |
---|
604 | #else |
---|
605 | partialButterfly4(tmp,coeff,shift_2nd); |
---|
606 | #endif |
---|
607 | } |
---|
608 | |
---|
609 | /** 4x4 inverse transform implemented using partial butterfly structure (1D) |
---|
610 | * \param coeff input data (transform coefficients) |
---|
611 | * \param block output data (residual) |
---|
612 | * \param shift specifies right shift after 1D transform |
---|
613 | */ |
---|
614 | void partialButterflyInverse4(short tmp[4][4],short block[4][4],int shift) |
---|
615 | { |
---|
616 | int j; |
---|
617 | int E[2],O[2]; |
---|
618 | int add = 1<<(shift-1); |
---|
619 | |
---|
620 | for (j=0; j<4; j++) |
---|
621 | { |
---|
622 | /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */ |
---|
623 | O[0] = g_aiT4[1][0]*tmp[1][j] + g_aiT4[3][0]*tmp[3][j]; |
---|
624 | O[1] = g_aiT4[1][1]*tmp[1][j] + g_aiT4[3][1]*tmp[3][j]; |
---|
625 | E[0] = g_aiT4[0][0]*tmp[0][j] + g_aiT4[2][0]*tmp[2][j]; |
---|
626 | E[1] = g_aiT4[0][1]*tmp[0][j] + g_aiT4[2][1]*tmp[2][j]; |
---|
627 | |
---|
628 | /* Combining even and odd terms at each hierarchy levels to calculate the final spatial domain vector */ |
---|
629 | block[j][0] = (E[0] + O[0] + add)>>shift; |
---|
630 | block[j][1] = (E[1] + O[1] + add)>>shift; |
---|
631 | block[j][2] = (E[1] - O[1] + add)>>shift; |
---|
632 | block[j][3] = (E[0] - O[0] + add)>>shift; |
---|
633 | } |
---|
634 | } |
---|
635 | |
---|
636 | /** 4x4 inverse transform (2D) |
---|
637 | * \param coeff input data (transform coefficients) |
---|
638 | * \param block output data (residual) |
---|
639 | * \param uiMode is Intra Prediction mode used in Mode-Dependent DCT/DST only |
---|
640 | */ |
---|
641 | #if INTRA_DST_TYPE_7 |
---|
642 | void xITr4(short coeff[4][4],short block[4][4], UInt uiMode) |
---|
643 | #else |
---|
644 | void xITr4(short coeff[4][4],short block[4][4]) |
---|
645 | #endif |
---|
646 | { |
---|
647 | int shift_1st = SHIFT_INV_1ST; |
---|
648 | #if FULL_NBIT |
---|
649 | int shift_2nd = SHIFT_INV_2ND - ((short)g_uiBitDepth - 8); |
---|
650 | #else |
---|
651 | int shift_2nd = SHIFT_INV_2ND - g_uiBitIncrement; |
---|
652 | #endif |
---|
653 | short tmp[4][4]; |
---|
654 | |
---|
655 | #if INTRA_DST_TYPE_7 |
---|
656 | if (uiMode != REG_DCT && g_aucDCTDSTMode_Vert[uiMode] ) // Check for DCT or DST |
---|
657 | { |
---|
658 | fastInverseDst(coeff,tmp,shift_1st); // Inverse DST by FAST Algorithm, coeff input, tmp output |
---|
659 | } |
---|
660 | else |
---|
661 | { |
---|
662 | partialButterflyInverse4(coeff,tmp,shift_1st); |
---|
663 | } |
---|
664 | #else |
---|
665 | partialButterflyInverse4(coeff,tmp,shift_1st); |
---|
666 | #endif |
---|
667 | #if INTRA_DST_TYPE_7 |
---|
668 | if (uiMode != REG_DCT && g_aucDCTDSTMode_Hor[uiMode] ) // Check for DCT or DST |
---|
669 | { |
---|
670 | fastInverseDst(tmp,block,shift_2nd); // Inverse DST by FAST Algorithm, tmp input, coeff output |
---|
671 | } |
---|
672 | else |
---|
673 | { |
---|
674 | partialButterflyInverse4(tmp,block,shift_2nd); |
---|
675 | } |
---|
676 | #else |
---|
677 | partialButterflyInverse4(tmp,block,shift_2nd); |
---|
678 | #endif |
---|
679 | } |
---|
680 | |
---|
681 | /** 8x8 forward transform implemented using partial butterfly structure (1D) |
---|
682 | * \param block input data (residual) |
---|
683 | * \param coeff output data (transform coefficients) |
---|
684 | * \param shift specifies right shift after 1D transform |
---|
685 | */ |
---|
686 | void partialButterfly8(short block[8][8],short coeff[8][8],int shift) |
---|
687 | { |
---|
688 | int j,k; |
---|
689 | int E[4],O[4]; |
---|
690 | int EE[2],EO[2]; |
---|
691 | int add = 1<<(shift-1); |
---|
692 | |
---|
693 | for (j=0; j<8; j++) |
---|
694 | { |
---|
695 | /* E and O*/ |
---|
696 | for (k=0;k<4;k++) |
---|
697 | { |
---|
698 | E[k] = block[j][k] + block[j][7-k]; |
---|
699 | O[k] = block[j][k] - block[j][7-k]; |
---|
700 | } |
---|
701 | /* EE and EO */ |
---|
702 | EE[0] = E[0] + E[3]; |
---|
703 | EO[0] = E[0] - E[3]; |
---|
704 | EE[1] = E[1] + E[2]; |
---|
705 | EO[1] = E[1] - E[2]; |
---|
706 | |
---|
707 | coeff[0][j] = (g_aiT8[0][0]*EE[0] + g_aiT8[0][1]*EE[1] + add)>>shift; |
---|
708 | coeff[4][j] = (g_aiT8[4][0]*EE[0] + g_aiT8[4][1]*EE[1] + add)>>shift; |
---|
709 | coeff[2][j] = (g_aiT8[2][0]*EO[0] + g_aiT8[2][1]*EO[1] + add)>>shift; |
---|
710 | coeff[6][j] = (g_aiT8[6][0]*EO[0] + g_aiT8[6][1]*EO[1] + add)>>shift; |
---|
711 | |
---|
712 | coeff[1][j] = (g_aiT8[1][0]*O[0] + g_aiT8[1][1]*O[1] + g_aiT8[1][2]*O[2] + g_aiT8[1][3]*O[3] + add)>>shift; |
---|
713 | coeff[3][j] = (g_aiT8[3][0]*O[0] + g_aiT8[3][1]*O[1] + g_aiT8[3][2]*O[2] + g_aiT8[3][3]*O[3] + add)>>shift; |
---|
714 | coeff[5][j] = (g_aiT8[5][0]*O[0] + g_aiT8[5][1]*O[1] + g_aiT8[5][2]*O[2] + g_aiT8[5][3]*O[3] + add)>>shift; |
---|
715 | coeff[7][j] = (g_aiT8[7][0]*O[0] + g_aiT8[7][1]*O[1] + g_aiT8[7][2]*O[2] + g_aiT8[7][3]*O[3] + add)>>shift; |
---|
716 | } |
---|
717 | } |
---|
718 | |
---|
719 | /** 8x8 forward transform (2D) |
---|
720 | * \param block input data (residual) |
---|
721 | * \param coeff output data (transform coefficients) |
---|
722 | */ |
---|
723 | void xTr8(short block[8][8],short coeff[8][8]) |
---|
724 | { |
---|
725 | #if FULL_NBIT |
---|
726 | int shift_1st = 2 + g_uiBitDepth - 8; // log2(8) - 1 + g_uiBitDepth - 8 |
---|
727 | #else |
---|
728 | int shift_1st = 2 + g_uiBitIncrement; // log2(8) - 1 + g_uiBitIncrement |
---|
729 | #endif |
---|
730 | int shift_2nd = 9; // log2(8) + 6 |
---|
731 | short tmp[8][8]; |
---|
732 | |
---|
733 | partialButterfly8(block,tmp,shift_1st); |
---|
734 | partialButterfly8(tmp,coeff,shift_2nd); |
---|
735 | } |
---|
736 | |
---|
737 | /** 8x8 inverse transform implemented using partial butterfly structure (1D) |
---|
738 | * \param coeff input data (transform coefficients) |
---|
739 | * \param block output data (residual) |
---|
740 | * \param shift specifies right shift after 1D transform |
---|
741 | */ |
---|
742 | void partialButterflyInverse8(short tmp[8][8],short block[8][8],int shift) |
---|
743 | { |
---|
744 | int j,k; |
---|
745 | int E[4],O[4]; |
---|
746 | int EE[2],EO[2]; |
---|
747 | int add = 1<<(shift-1); |
---|
748 | |
---|
749 | for (j=0; j<8; j++) |
---|
750 | { |
---|
751 | /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */ |
---|
752 | for (k=0;k<4;k++) |
---|
753 | { |
---|
754 | O[k] = g_aiT8[ 1][k]*tmp[ 1][j] + g_aiT8[ 3][k]*tmp[ 3][j] + g_aiT8[ 5][k]*tmp[ 5][j] + g_aiT8[ 7][k]*tmp[ 7][j]; |
---|
755 | } |
---|
756 | |
---|
757 | EO[0] = g_aiT8[2][0]*tmp[2][j] + g_aiT8[6][0]*tmp[6][j]; |
---|
758 | EO[1] = g_aiT8[2][1]*tmp[2][j] + g_aiT8[6][1]*tmp[6][j]; |
---|
759 | EE[0] = g_aiT8[0][0]*tmp[0][j] + g_aiT8[4][0]*tmp[4][j]; |
---|
760 | EE[1] = g_aiT8[0][1]*tmp[0][j] + g_aiT8[4][1]*tmp[4][j]; |
---|
761 | |
---|
762 | /* Combining even and odd terms at each hierarchy levels to calculate the final spatial domain vector */ |
---|
763 | E[0] = EE[0] + EO[0]; |
---|
764 | E[3] = EE[0] - EO[0]; |
---|
765 | E[1] = EE[1] + EO[1]; |
---|
766 | E[2] = EE[1] - EO[1]; |
---|
767 | for (k=0;k<4;k++) |
---|
768 | { |
---|
769 | block[j][k] = (E[k] + O[k] + add)>>shift; |
---|
770 | block[j][k+4] = (E[3-k] - O[3-k] + add)>>shift; |
---|
771 | } |
---|
772 | } |
---|
773 | } |
---|
774 | |
---|
775 | /** 8x8 inverse transform (2D) |
---|
776 | * \param coeff input data (transform coefficients) |
---|
777 | * \param block output data (residual) |
---|
778 | */ |
---|
779 | void xITr8(short coeff[8][8],short block[8][8]) |
---|
780 | { |
---|
781 | int shift_1st = SHIFT_INV_1ST; |
---|
782 | #if FULL_NBIT |
---|
783 | int shift_2nd = SHIFT_INV_2ND - ((short)g_uiBitDepth - 8); |
---|
784 | #else |
---|
785 | int shift_2nd = SHIFT_INV_2ND - g_uiBitIncrement; |
---|
786 | #endif |
---|
787 | short tmp[8][8]; |
---|
788 | |
---|
789 | partialButterflyInverse8(coeff,tmp,shift_1st); |
---|
790 | partialButterflyInverse8(tmp,block,shift_2nd); |
---|
791 | } |
---|
792 | |
---|
793 | /** 16x16 forward transform implemented using partial butterfly structure (1D) |
---|
794 | * \param block input data (residual) |
---|
795 | * \param coeff output data (transform coefficients) |
---|
796 | * \param shift specifies right shift after 1D transform |
---|
797 | */ |
---|
798 | void partialButterfly16(short block[16][16],short coeff[16][16],int shift) |
---|
799 | { |
---|
800 | int j,k; |
---|
801 | int E[8],O[8]; |
---|
802 | int EE[4],EO[4]; |
---|
803 | int EEE[2],EEO[2]; |
---|
804 | int add = 1<<(shift-1); |
---|
805 | |
---|
806 | for (j=0; j<16; j++) |
---|
807 | { |
---|
808 | /* E and O*/ |
---|
809 | for (k=0;k<8;k++) |
---|
810 | { |
---|
811 | E[k] = block[j][k] + block[j][15-k]; |
---|
812 | O[k] = block[j][k] - block[j][15-k]; |
---|
813 | } |
---|
814 | /* EE and EO */ |
---|
815 | for (k=0;k<4;k++) |
---|
816 | { |
---|
817 | EE[k] = E[k] + E[7-k]; |
---|
818 | EO[k] = E[k] - E[7-k]; |
---|
819 | } |
---|
820 | /* EEE and EEO */ |
---|
821 | EEE[0] = EE[0] + EE[3]; |
---|
822 | EEO[0] = EE[0] - EE[3]; |
---|
823 | EEE[1] = EE[1] + EE[2]; |
---|
824 | EEO[1] = EE[1] - EE[2]; |
---|
825 | |
---|
826 | coeff[ 0][j] = (g_aiT16[ 0][0]*EEE[0] + g_aiT16[ 0][1]*EEE[1] + add)>>shift; |
---|
827 | coeff[ 8][j] = (g_aiT16[ 8][0]*EEE[0] + g_aiT16[ 8][1]*EEE[1] + add)>>shift; |
---|
828 | coeff[ 4][j] = (g_aiT16[ 4][0]*EEO[0] + g_aiT16[ 4][1]*EEO[1] + add)>>shift; |
---|
829 | coeff[12][j] = (g_aiT16[12][0]*EEO[0] + g_aiT16[12][1]*EEO[1] + add)>>shift; |
---|
830 | |
---|
831 | for (k=2;k<16;k+=4) |
---|
832 | { |
---|
833 | coeff[k][j] = (g_aiT16[k][0]*EO[0] + g_aiT16[k][1]*EO[1] + g_aiT16[k][2]*EO[2] + g_aiT16[k][3]*EO[3] + add)>>shift; |
---|
834 | } |
---|
835 | |
---|
836 | for (k=1;k<16;k+=2) |
---|
837 | { |
---|
838 | coeff[k][j] = (g_aiT16[k][0]*O[0] + g_aiT16[k][1]*O[1] + g_aiT16[k][2]*O[2] + g_aiT16[k][3]*O[3] + |
---|
839 | g_aiT16[k][4]*O[4] + g_aiT16[k][5]*O[5] + g_aiT16[k][6]*O[6] + g_aiT16[k][7]*O[7] + add)>>shift; |
---|
840 | } |
---|
841 | |
---|
842 | } |
---|
843 | } |
---|
844 | |
---|
845 | /** 16x16 forward transform (2D) |
---|
846 | * \param block input data (residual) |
---|
847 | * \param coeff output data (transform coefficients) |
---|
848 | */ |
---|
849 | void xTr16(short block[16][16],short coeff[16][16]) |
---|
850 | { |
---|
851 | #if FULL_NBIT |
---|
852 | int shift_1st = 3 + g_uiBitDepth - 8; // log2(16) - 1 + g_uiBitDepth - 8 |
---|
853 | #else |
---|
854 | int shift_1st = 3 + g_uiBitIncrement; // log2(16) - 1 + g_uiBitIncrement |
---|
855 | #endif |
---|
856 | int shift_2nd = 10; // log2(16) + 6 |
---|
857 | short tmp[16][16]; |
---|
858 | |
---|
859 | partialButterfly16(block,tmp,shift_1st); |
---|
860 | partialButterfly16(tmp,coeff,shift_2nd); |
---|
861 | } |
---|
862 | |
---|
863 | /** 16x16 inverse transform implemented using partial butterfly structure (1D) |
---|
864 | * \param coeff input data (transform coefficients) |
---|
865 | * \param block output data (residual) |
---|
866 | * \param shift specifies right shift after 1D transform |
---|
867 | */ |
---|
868 | void partialButterflyInverse16(short tmp[16][16],short block[16][16],int shift) |
---|
869 | { |
---|
870 | int j,k; |
---|
871 | int E[8],O[8]; |
---|
872 | int EE[4],EO[4]; |
---|
873 | int EEE[2],EEO[2]; |
---|
874 | int add = 1<<(shift-1); |
---|
875 | |
---|
876 | for (j=0; j<16; j++) |
---|
877 | { |
---|
878 | /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */ |
---|
879 | for (k=0;k<8;k++) |
---|
880 | { |
---|
881 | O[k] = g_aiT16[ 1][k]*tmp[ 1][j] + g_aiT16[ 3][k]*tmp[ 3][j] + g_aiT16[ 5][k]*tmp[ 5][j] + g_aiT16[ 7][k]*tmp[ 7][j] + |
---|
882 | g_aiT16[ 9][k]*tmp[ 9][j] + g_aiT16[11][k]*tmp[11][j] + g_aiT16[13][k]*tmp[13][j] + g_aiT16[15][k]*tmp[15][j]; |
---|
883 | } |
---|
884 | for (k=0;k<4;k++) |
---|
885 | { |
---|
886 | EO[k] = g_aiT16[ 2][k]*tmp[ 2][j] + g_aiT16[ 6][k]*tmp[ 6][j] + g_aiT16[10][k]*tmp[10][j] + g_aiT16[14][k]*tmp[14][j]; |
---|
887 | } |
---|
888 | EEO[0] = g_aiT16[4][0]*tmp[4][j] + g_aiT16[12][0]*tmp[12][j]; |
---|
889 | EEE[0] = g_aiT16[0][0]*tmp[0][j] + g_aiT16[ 8][0]*tmp[ 8][j]; |
---|
890 | EEO[1] = g_aiT16[4][1]*tmp[4][j] + g_aiT16[12][1]*tmp[12][j]; |
---|
891 | EEE[1] = g_aiT16[0][1]*tmp[0][j] + g_aiT16[ 8][1]*tmp[ 8][j]; |
---|
892 | |
---|
893 | /* Combining even and odd terms at each hierarchy levels to calculate the final spatial domain vector */ |
---|
894 | for (k=0;k<2;k++) |
---|
895 | { |
---|
896 | EE[k] = EEE[k] + EEO[k]; |
---|
897 | EE[k+2] = EEE[1-k] - EEO[1-k]; |
---|
898 | } |
---|
899 | for (k=0;k<4;k++) |
---|
900 | { |
---|
901 | E[k] = EE[k] + EO[k]; |
---|
902 | E[k+4] = EE[3-k] - EO[3-k]; |
---|
903 | } |
---|
904 | for (k=0;k<8;k++) |
---|
905 | { |
---|
906 | block[j][k] = (E[k] + O[k] + add)>>shift; |
---|
907 | block[j][k+8] = (E[7-k] - O[7-k] + add)>>shift; |
---|
908 | } |
---|
909 | } |
---|
910 | } |
---|
911 | |
---|
912 | /** 16x16 inverse transform (2D) |
---|
913 | * \param coeff input data (transform coefficients) |
---|
914 | * \param block output data (residual) |
---|
915 | */ |
---|
916 | void xITr16(short coeff[16][16],short block[16][16]) |
---|
917 | { |
---|
918 | int shift_1st = SHIFT_INV_1ST; |
---|
919 | #if FULL_NBIT |
---|
920 | int shift_2nd = SHIFT_INV_2ND - ((short)g_uiBitDepth - 8); |
---|
921 | #else |
---|
922 | int shift_2nd = SHIFT_INV_2ND - g_uiBitIncrement; |
---|
923 | #endif |
---|
924 | short tmp[16][16]; |
---|
925 | |
---|
926 | partialButterflyInverse16(coeff,tmp,shift_1st); |
---|
927 | partialButterflyInverse16(tmp,block,shift_2nd); |
---|
928 | } |
---|
929 | |
---|
930 | /** 32x32 forward transform implemented using partial butterfly structure (1D) |
---|
931 | * \param block input data (residual) |
---|
932 | * \param coeff output data (transform coefficients) |
---|
933 | * \param shift specifies right shift after 1D transform |
---|
934 | */ |
---|
935 | void partialButterfly32(short block[32][32],short coeff[32][32],int shift) |
---|
936 | { |
---|
937 | int j,k; |
---|
938 | int E[16],O[16]; |
---|
939 | int EE[8],EO[8]; |
---|
940 | int EEE[4],EEO[4]; |
---|
941 | int EEEE[2],EEEO[2]; |
---|
942 | int add = 1<<(shift-1); |
---|
943 | |
---|
944 | for (j=0; j<32; j++) |
---|
945 | { |
---|
946 | /* E and O*/ |
---|
947 | for (k=0;k<16;k++) |
---|
948 | { |
---|
949 | E[k] = block[j][k] + block[j][31-k]; |
---|
950 | O[k] = block[j][k] - block[j][31-k]; |
---|
951 | } |
---|
952 | /* EE and EO */ |
---|
953 | for (k=0;k<8;k++) |
---|
954 | { |
---|
955 | EE[k] = E[k] + E[15-k]; |
---|
956 | EO[k] = E[k] - E[15-k]; |
---|
957 | } |
---|
958 | /* EEE and EEO */ |
---|
959 | for (k=0;k<4;k++) |
---|
960 | { |
---|
961 | EEE[k] = EE[k] + EE[7-k]; |
---|
962 | EEO[k] = EE[k] - EE[7-k]; |
---|
963 | } |
---|
964 | /* EEEE and EEEO */ |
---|
965 | EEEE[0] = EEE[0] + EEE[3]; |
---|
966 | EEEO[0] = EEE[0] - EEE[3]; |
---|
967 | EEEE[1] = EEE[1] + EEE[2]; |
---|
968 | EEEO[1] = EEE[1] - EEE[2]; |
---|
969 | |
---|
970 | coeff[ 0][j] = (g_aiT32[ 0][0]*EEEE[0] + g_aiT32[ 0][1]*EEEE[1] + add)>>shift; |
---|
971 | coeff[16][j] = (g_aiT32[16][0]*EEEE[0] + g_aiT32[16][1]*EEEE[1] + add)>>shift; |
---|
972 | coeff[ 8][j] = (g_aiT32[ 8][0]*EEEO[0] + g_aiT32[ 8][1]*EEEO[1] + add)>>shift; |
---|
973 | coeff[24][j] = (g_aiT32[24][0]*EEEO[0] + g_aiT32[24][1]*EEEO[1] + add)>>shift; |
---|
974 | for (k=4;k<32;k+=8) |
---|
975 | { |
---|
976 | coeff[k][j] = (g_aiT32[k][0]*EEO[0] + g_aiT32[k][1]*EEO[1] + g_aiT32[k][2]*EEO[2] + g_aiT32[k][3]*EEO[3] + add)>>shift; |
---|
977 | } |
---|
978 | for (k=2;k<32;k+=4) |
---|
979 | { |
---|
980 | coeff[k][j] = (g_aiT32[k][0]*EO[0] + g_aiT32[k][1]*EO[1] + g_aiT32[k][2]*EO[2] + g_aiT32[k][3]*EO[3] + |
---|
981 | g_aiT32[k][4]*EO[4] + g_aiT32[k][5]*EO[5] + g_aiT32[k][6]*EO[6] + g_aiT32[k][7]*EO[7] + add)>>shift; |
---|
982 | } |
---|
983 | for (k=1;k<32;k+=2) |
---|
984 | { |
---|
985 | coeff[k][j] = (g_aiT32[k][ 0]*O[ 0] + g_aiT32[k][ 1]*O[ 1] + g_aiT32[k][ 2]*O[ 2] + g_aiT32[k][ 3]*O[ 3] + |
---|
986 | g_aiT32[k][ 4]*O[ 4] + g_aiT32[k][ 5]*O[ 5] + g_aiT32[k][ 6]*O[ 6] + g_aiT32[k][ 7]*O[ 7] + |
---|
987 | g_aiT32[k][ 8]*O[ 8] + g_aiT32[k][ 9]*O[ 9] + g_aiT32[k][10]*O[10] + g_aiT32[k][11]*O[11] + |
---|
988 | g_aiT32[k][12]*O[12] + g_aiT32[k][13]*O[13] + g_aiT32[k][14]*O[14] + g_aiT32[k][15]*O[15] + add)>>shift; |
---|
989 | } |
---|
990 | } |
---|
991 | } |
---|
992 | |
---|
993 | /** 32x32 forward transform (2D) |
---|
994 | * \param block input data (residual) |
---|
995 | * \param coeff output data (transform coefficients) |
---|
996 | */ |
---|
997 | void xTr32(short block[32][32],short coeff[32][32]) |
---|
998 | { |
---|
999 | #if FULL_NBIT |
---|
1000 | int shift_1st = 4 + g_uiBitDepth - 8; // log2(32) - 1 + g_uiBitDepth - 8 |
---|
1001 | #else |
---|
1002 | int shift_1st = 4 + g_uiBitIncrement; // log2(32) - 1 + g_uiBitIncrement |
---|
1003 | #endif |
---|
1004 | int shift_2nd = 11; // log2(32) + 6 |
---|
1005 | short tmp[32][32]; |
---|
1006 | |
---|
1007 | partialButterfly32(block,tmp,shift_1st); |
---|
1008 | partialButterfly32(tmp,coeff,shift_2nd); |
---|
1009 | } |
---|
1010 | |
---|
1011 | /** 32x32 inverse transform implemented using partial butterfly structure (1D) |
---|
1012 | * \param coeff input data (transform coefficients) |
---|
1013 | * \param block output data (residual) |
---|
1014 | * \param shift specifies right shift after 1D transform |
---|
1015 | */ |
---|
1016 | void partialButterflyInverse32(short tmp[32][32],short block[32][32],int shift) |
---|
1017 | { |
---|
1018 | int j,k; |
---|
1019 | int E[16],O[16]; |
---|
1020 | int EE[8],EO[8]; |
---|
1021 | int EEE[4],EEO[4]; |
---|
1022 | int EEEE[2],EEEO[2]; |
---|
1023 | int add = 1<<(shift-1); |
---|
1024 | |
---|
1025 | for (j=0; j<32; j++) |
---|
1026 | { |
---|
1027 | /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */ |
---|
1028 | for (k=0;k<16;k++) |
---|
1029 | { |
---|
1030 | O[k] = g_aiT32[ 1][k]*tmp[ 1][j] + g_aiT32[ 3][k]*tmp[ 3][j] + g_aiT32[ 5][k]*tmp[ 5][j] + g_aiT32[ 7][k]*tmp[ 7][j] + |
---|
1031 | g_aiT32[ 9][k]*tmp[ 9][j] + g_aiT32[11][k]*tmp[11][j] + g_aiT32[13][k]*tmp[13][j] + g_aiT32[15][k]*tmp[15][j] + |
---|
1032 | g_aiT32[17][k]*tmp[17][j] + g_aiT32[19][k]*tmp[19][j] + g_aiT32[21][k]*tmp[21][j] + g_aiT32[23][k]*tmp[23][j] + |
---|
1033 | g_aiT32[25][k]*tmp[25][j] + g_aiT32[27][k]*tmp[27][j] + g_aiT32[29][k]*tmp[29][j] + g_aiT32[31][k]*tmp[31][j]; |
---|
1034 | } |
---|
1035 | for (k=0;k<8;k++) |
---|
1036 | { |
---|
1037 | EO[k] = g_aiT32[ 2][k]*tmp[ 2][j] + g_aiT32[ 6][k]*tmp[ 6][j] + g_aiT32[10][k]*tmp[10][j] + g_aiT32[14][k]*tmp[14][j] + |
---|
1038 | g_aiT32[18][k]*tmp[18][j] + g_aiT32[22][k]*tmp[22][j] + g_aiT32[26][k]*tmp[26][j] + g_aiT32[30][k]*tmp[30][j]; |
---|
1039 | } |
---|
1040 | for (k=0;k<4;k++) |
---|
1041 | { |
---|
1042 | EEO[k] = g_aiT32[4][k]*tmp[4][j] + g_aiT32[12][k]*tmp[12][j] + g_aiT32[20][k]*tmp[20][j] + g_aiT32[28][k]*tmp[28][j]; |
---|
1043 | } |
---|
1044 | EEEO[0] = g_aiT32[8][0]*tmp[8][j] + g_aiT32[24][0]*tmp[24][j]; |
---|
1045 | EEEO[1] = g_aiT32[8][1]*tmp[8][j] + g_aiT32[24][1]*tmp[24][j]; |
---|
1046 | EEEE[0] = g_aiT32[0][0]*tmp[0][j] + g_aiT32[16][0]*tmp[16][j]; |
---|
1047 | EEEE[1] = g_aiT32[0][1]*tmp[0][j] + g_aiT32[16][1]*tmp[16][j]; |
---|
1048 | |
---|
1049 | /* Combining even and odd terms at each hierarchy levels to calculate the final spatial domain vector */ |
---|
1050 | EEE[0] = EEEE[0] + EEEO[0]; |
---|
1051 | EEE[3] = EEEE[0] - EEEO[0]; |
---|
1052 | EEE[1] = EEEE[1] + EEEO[1]; |
---|
1053 | EEE[2] = EEEE[1] - EEEO[1]; |
---|
1054 | for (k=0;k<4;k++) |
---|
1055 | { |
---|
1056 | EE[k] = EEE[k] + EEO[k]; |
---|
1057 | EE[k+4] = EEE[3-k] - EEO[3-k]; |
---|
1058 | } |
---|
1059 | for (k=0;k<8;k++) |
---|
1060 | { |
---|
1061 | E[k] = EE[k] + EO[k]; |
---|
1062 | E[k+8] = EE[7-k] - EO[7-k]; |
---|
1063 | } |
---|
1064 | for (k=0;k<16;k++) |
---|
1065 | { |
---|
1066 | block[j][k] = (E[k] + O[k] + add)>>shift; |
---|
1067 | block[j][k+16] = (E[15-k] - O[15-k] + add)>>shift; |
---|
1068 | } |
---|
1069 | } |
---|
1070 | } |
---|
1071 | |
---|
1072 | /** 32x32 inverse transform (2D) |
---|
1073 | * \param coeff input data (transform coefficients) |
---|
1074 | * \param block output data (residual) |
---|
1075 | */ |
---|
1076 | void xITr32(short coeff[32][32],short block[32][32]) |
---|
1077 | { |
---|
1078 | int shift_1st = SHIFT_INV_1ST; |
---|
1079 | #if FULL_NBIT |
---|
1080 | int shift_2nd = SHIFT_INV_2ND - ((short)g_uiBitDepth - 8); |
---|
1081 | #else |
---|
1082 | int shift_2nd = SHIFT_INV_2ND - g_uiBitIncrement; |
---|
1083 | #endif |
---|
1084 | short tmp[32][32]; |
---|
1085 | |
---|
1086 | partialButterflyInverse32(coeff,tmp,shift_1st); |
---|
1087 | partialButterflyInverse32(tmp,block,shift_2nd); |
---|
1088 | } |
---|
1089 | #endif //MATRIX_MULT |
---|
1090 | #else //E243_CORE_TRANSFORMS |
---|
1091 | |
---|
1092 | Void TComTrQuant::xT32( Pel* pSrc, UInt uiStride, Long* pDes ) |
---|
1093 | { |
---|
1094 | Int x, y; |
---|
1095 | Long aaiTemp[32][32]; |
---|
1096 | |
---|
1097 | Long A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, A23, A24, A25, A26, A27, A28, A29, A30, A31; |
---|
1098 | Long B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12, B13, B14, B15, B20, B21, B22, B23, B24, B25, B26, B27; |
---|
1099 | Long C0, C1, C2, C3, C4, C5, C6, C7, C10, C11, C12, C13, C16, C17, C18, C19, C20, C21, C22, C23, C24, C25, C26, C27, C28, C29, C30, C31; |
---|
1100 | Long D0, D1, D2, D3, D5, D6, D8, D9, D10, D11, D12, D13, D14, D15, D18, D19, D20, D21, D26, D27, D28, D29; |
---|
1101 | Long E4, E5, E6, E7, E9, E10, E13, E14, E16, E17, E18, E19, E20, E21, E22, E23, E24, E25, E26, E27, E28, E29, E30, E31; |
---|
1102 | Long F8, F9, F10, F11, F12, F13, F14, F15, F17, F18, F21, F22, F25, F26, F29, F30; |
---|
1103 | Long G16, G17, G18, G19, G20, G21, G22, G23, G24, G25, G26, G27, G28, G29, G30, G31; |
---|
1104 | #ifdef TRANS_PRECISION_EXT |
---|
1105 | Int uiBitDepthIncrease=g_iShift32x32-g_uiBitIncrement; |
---|
1106 | Int offset = (uiBitDepthIncrease==0)? 0:(1<<(uiBitDepthIncrease-1)); |
---|
1107 | #endif |
---|
1108 | //--Butterfly |
---|
1109 | for( y=0 ; y<32 ; y++ ) |
---|
1110 | { |
---|
1111 | #ifdef TRANS_PRECISION_EXT |
---|
1112 | A0 = (pSrc[0] + pSrc[31])<<uiBitDepthIncrease; |
---|
1113 | A31 = (pSrc[0] - pSrc[31])<<uiBitDepthIncrease; |
---|
1114 | A1 = (pSrc[1] + pSrc[30])<<uiBitDepthIncrease; |
---|
1115 | A30 = (pSrc[1] - pSrc[30])<<uiBitDepthIncrease; |
---|
1116 | A2 = (pSrc[2] + pSrc[29])<<uiBitDepthIncrease; |
---|
1117 | A29 = (pSrc[2] - pSrc[29])<<uiBitDepthIncrease; |
---|
1118 | A3 = (pSrc[3] + pSrc[28])<<uiBitDepthIncrease; |
---|
1119 | A28 = (pSrc[3] - pSrc[28])<<uiBitDepthIncrease; |
---|
1120 | A4 = (pSrc[4] + pSrc[27])<<uiBitDepthIncrease; |
---|
1121 | A27 = (pSrc[4] - pSrc[27])<<uiBitDepthIncrease; |
---|
1122 | A5 = (pSrc[5] + pSrc[26])<<uiBitDepthIncrease; |
---|
1123 | A26 = (pSrc[5] - pSrc[26])<<uiBitDepthIncrease; |
---|
1124 | A6 = (pSrc[6] + pSrc[25])<<uiBitDepthIncrease; |
---|
1125 | A25 = (pSrc[6] - pSrc[25])<<uiBitDepthIncrease; |
---|
1126 | A7 = (pSrc[7] + pSrc[24])<<uiBitDepthIncrease; |
---|
1127 | A24 = (pSrc[7] - pSrc[24])<<uiBitDepthIncrease; |
---|
1128 | A8 = (pSrc[8] + pSrc[23])<<uiBitDepthIncrease; |
---|
1129 | A23 = (pSrc[8] - pSrc[23])<<uiBitDepthIncrease; |
---|
1130 | A9 = (pSrc[9] + pSrc[22])<<uiBitDepthIncrease; |
---|
1131 | A22 = (pSrc[9] - pSrc[22])<<uiBitDepthIncrease; |
---|
1132 | A10 = (pSrc[10] + pSrc[21])<<uiBitDepthIncrease; |
---|
1133 | A21 = (pSrc[10] - pSrc[21])<<uiBitDepthIncrease; |
---|
1134 | A11 = (pSrc[11] + pSrc[20])<<uiBitDepthIncrease; |
---|
1135 | A20 = (pSrc[11] - pSrc[20])<<uiBitDepthIncrease; |
---|
1136 | A12 = (pSrc[12] + pSrc[19])<<uiBitDepthIncrease; |
---|
1137 | A19 = (pSrc[12] - pSrc[19])<<uiBitDepthIncrease; |
---|
1138 | A13 = (pSrc[13] + pSrc[18])<<uiBitDepthIncrease; |
---|
1139 | A18 = (pSrc[13] - pSrc[18])<<uiBitDepthIncrease; |
---|
1140 | A14 = (pSrc[14] + pSrc[17])<<uiBitDepthIncrease; |
---|
1141 | A17 = (pSrc[14] - pSrc[17])<<uiBitDepthIncrease; |
---|
1142 | A15 = (pSrc[15] + pSrc[16])<<uiBitDepthIncrease; |
---|
1143 | A16 = (pSrc[15] - pSrc[16])<<uiBitDepthIncrease; |
---|
1144 | #else |
---|
1145 | A0 = pSrc[0] + pSrc[31]; |
---|
1146 | A31 = pSrc[0] - pSrc[31]; |
---|
1147 | A1 = pSrc[1] + pSrc[30]; |
---|
1148 | A30 = pSrc[1] - pSrc[30]; |
---|
1149 | A2 = pSrc[2] + pSrc[29]; |
---|
1150 | A29 = pSrc[2] - pSrc[29]; |
---|
1151 | A3 = pSrc[3] + pSrc[28]; |
---|
1152 | A28 = pSrc[3] - pSrc[28]; |
---|
1153 | A4 = pSrc[4] + pSrc[27]; |
---|
1154 | A27 = pSrc[4] - pSrc[27]; |
---|
1155 | A5 = pSrc[5] + pSrc[26]; |
---|
1156 | A26 = pSrc[5] - pSrc[26]; |
---|
1157 | A6 = pSrc[6] + pSrc[25]; |
---|
1158 | A25 = pSrc[6] - pSrc[25]; |
---|
1159 | A7 = pSrc[7] + pSrc[24]; |
---|
1160 | A24 = pSrc[7] - pSrc[24]; |
---|
1161 | A8 = pSrc[8] + pSrc[23]; |
---|
1162 | A23 = pSrc[8] - pSrc[23]; |
---|
1163 | A9 = pSrc[9] + pSrc[22]; |
---|
1164 | A22 = pSrc[9] - pSrc[22]; |
---|
1165 | A10 = pSrc[10] + pSrc[21]; |
---|
1166 | A21 = pSrc[10] - pSrc[21]; |
---|
1167 | A11 = pSrc[11] + pSrc[20]; |
---|
1168 | A20 = pSrc[11] - pSrc[20]; |
---|
1169 | A12 = pSrc[12] + pSrc[19]; |
---|
1170 | A19 = pSrc[12] - pSrc[19]; |
---|
1171 | A13 = pSrc[13] + pSrc[18]; |
---|
1172 | A18 = pSrc[13] - pSrc[18]; |
---|
1173 | A14 = pSrc[14] + pSrc[17]; |
---|
1174 | A17 = pSrc[14] - pSrc[17]; |
---|
1175 | A15 = pSrc[15] + pSrc[16]; |
---|
1176 | A16 = pSrc[15] - pSrc[16]; |
---|
1177 | #endif |
---|
1178 | B0 = A0 + A15; |
---|
1179 | B15 = A0 - A15; |
---|
1180 | B1 = A1 + A14; |
---|
1181 | B14 = A1 - A14; |
---|
1182 | B2 = A2 + A13; |
---|
1183 | B13 = A2 - A13; |
---|
1184 | B3 = A3 + A12; |
---|
1185 | B12 = A3 - A12; |
---|
1186 | B4 = A4 + A11; |
---|
1187 | B11 = A4 - A11; |
---|
1188 | B5 = A5 + A10; |
---|
1189 | B10 = A5 - A10; |
---|
1190 | B6 = A6 + A9; |
---|
1191 | B9 = A6 - A9; |
---|
1192 | B7 = A7 + A8; |
---|
1193 | B8 = A7 - A8; |
---|
1194 | B20 = xTrRound( 181 * ( A27 - A20 ) , DenShift32); |
---|
1195 | B27 = xTrRound( 181 * ( A27 + A20 ) , DenShift32); |
---|
1196 | B21 = xTrRound( 181 * ( A26 - A21 ) , DenShift32); |
---|
1197 | B26 = xTrRound( 181 * ( A26 + A21 ) , DenShift32); |
---|
1198 | B22 = xTrRound( 181 * ( A25 - A22 ) , DenShift32); |
---|
1199 | B25 = xTrRound( 181 * ( A25 + A22 ) , DenShift32); |
---|
1200 | B23 = xTrRound( 181 * ( A24 - A23 ) , DenShift32); |
---|
1201 | B24 = xTrRound( 181 * ( A24 + A23 ) , DenShift32);; |
---|
1202 | |
---|
1203 | C0 = B0 + B7; |
---|
1204 | C7 = B0 - B7; |
---|
1205 | C1 = B1 + B6; |
---|
1206 | C6 = B1 - B6; |
---|
1207 | C2 = B2 + B5; |
---|
1208 | C5 = B2 - B5; |
---|
1209 | C3 = B3 + B4; |
---|
1210 | C4 = B3 - B4; |
---|
1211 | C10 = xTrRound( 181 * ( B13 - B10 ) , DenShift32); |
---|
1212 | C13 = xTrRound( 181 * ( B13 + B10 ) , DenShift32); |
---|
1213 | C11 = xTrRound( 181 * ( B12 - B11 ) , DenShift32); |
---|
1214 | C12 = xTrRound( 181 * ( B12 + B11 ) , DenShift32); |
---|
1215 | C16 = A16 + B23; |
---|
1216 | C23 = A16 - B23; |
---|
1217 | C24 = A31 - B24; |
---|
1218 | C31 = A31 + B24; |
---|
1219 | C17 = A17 + B22; |
---|
1220 | C22 = A17 - B22; |
---|
1221 | C25 = A30 - B25; |
---|
1222 | C30 = A30 + B25; |
---|
1223 | C18 = A18 + B21; |
---|
1224 | C21 = A18 - B21; |
---|
1225 | C26 = A29 - B26; |
---|
1226 | C29 = A29 + B26; |
---|
1227 | C19 = A19 + B20; |
---|
1228 | C20 = A19 - B20; |
---|
1229 | C27 = A28 - B27; |
---|
1230 | C28 = A28 + B27; |
---|
1231 | |
---|
1232 | D0 = C0 + C3; |
---|
1233 | D3 = C0 - C3; |
---|
1234 | D8 = B8 + C11; |
---|
1235 | D11 = B8 - C11; |
---|
1236 | D12 = B15 - C12; |
---|
1237 | D15 = B15 + C12; |
---|
1238 | D1 = C1 + C2; |
---|
1239 | D2 = C1 - C2; |
---|
1240 | D9 = B9 + C10; |
---|
1241 | D10 = B9 - C10; |
---|
1242 | D13 = B14 - C13; |
---|
1243 | D14 = B14 + C13; |
---|
1244 | D5 = xTrRound( 181 * ( C6 - C5 ) , DenShift32); |
---|
1245 | D6 = xTrRound( 181 * ( C6 + C5 ) , DenShift32); |
---|
1246 | D18 = xTrRound( 97 * C29 - 236 * C18 , DenShift32); |
---|
1247 | D20 = xTrRound( - 236 * C27 - 97 * C20 , DenShift32); |
---|
1248 | D26 = xTrRound( - 236 * C21 + 97 * C26 , DenShift32); |
---|
1249 | D28 = xTrRound( 97 * C19 + 236 * C28 , DenShift32); |
---|
1250 | D19 = xTrRound( 97 * C28 - 236 * C19 , DenShift32); |
---|
1251 | D21 = xTrRound( - 236 * C26 - 97 * C21 , DenShift32); |
---|
1252 | D27 = xTrRound( - 236 * C20 + 97 * C27 , DenShift32); |
---|
1253 | D29 = xTrRound( 97 * C18 + 236 * C29 , DenShift32);; |
---|
1254 | |
---|
1255 | aaiTemp[0][y] = xTrRound( 181 * ( D0 + D1 ) , DenShift32); |
---|
1256 | aaiTemp[16][y] = xTrRound( 181 * ( D0 - D1 ) , DenShift32); |
---|
1257 | aaiTemp[8][y] = xTrRound( 236 * D3 + 97 * D2 , DenShift32); |
---|
1258 | aaiTemp[24][y] = xTrRound( 97 * D3 - 236 * D2 , DenShift32); |
---|
1259 | E4 = C4 + D5; |
---|
1260 | E5 = C4 - D5; |
---|
1261 | E6 = C7 - D6; |
---|
1262 | E7 = C7 + D6; |
---|
1263 | E9 = xTrRound( 97 * D14 - 236 * D9 , DenShift32); |
---|
1264 | E10 = xTrRound( - 236 * D13 - 97 * D10 , DenShift32); |
---|
1265 | E13 = xTrRound( 97 * D13 - 236 * D10 , DenShift32); |
---|
1266 | E14 = xTrRound( 236 * D14 + 97 * D9 , DenShift32); |
---|
1267 | E16 = C16 + D19; |
---|
1268 | E19 = C16 - D19; |
---|
1269 | E20 = C23 - D20; |
---|
1270 | E23 = C23 + D20; |
---|
1271 | E24 = C24 + D27; |
---|
1272 | E27 = C24 - D27; |
---|
1273 | E28 = C31 - D28; |
---|
1274 | E31 = C31 + D28; |
---|
1275 | E17 = C17 + D18; |
---|
1276 | E18 = C17 - D18; |
---|
1277 | E21 = C22 - D21; |
---|
1278 | E22 = C22 + D21; |
---|
1279 | E25 = C25 + D26; |
---|
1280 | E26 = C25 - D26; |
---|
1281 | E29 = C30 - D29; |
---|
1282 | E30 = C30 + D29; |
---|
1283 | |
---|
1284 | aaiTemp[4][y] = xTrRound( 49 * E4 + 251 * E7 , DenShift32); |
---|
1285 | aaiTemp[20][y] = xTrRound( 212 * E5 + 142 * E6 , DenShift32); |
---|
1286 | aaiTemp[12][y] = xTrRound( 212 * E6 - 142 * E5 , DenShift32); |
---|
1287 | aaiTemp[28][y] = xTrRound( 49 * E7 - 251 * E4 , DenShift32); |
---|
1288 | F8 = D8 + E9; |
---|
1289 | F9 = D8 - E9; |
---|
1290 | F10 = D11 - E10; |
---|
1291 | F11 = D11 + E10; |
---|
1292 | F12 = D12 + E13; |
---|
1293 | F13 = D12 - E13; |
---|
1294 | F14 = D15 - E14; |
---|
1295 | F15 = D15 + E14; |
---|
1296 | F17 = xTrRound( 49 * E30 - 251 * E17 , DenShift32); |
---|
1297 | F18 = xTrRound( - 251 * E29 - 49 * E18 , DenShift32); |
---|
1298 | F21 = xTrRound( 212 * E26 - 142 * E21 , DenShift32); |
---|
1299 | F22 = xTrRound( - 142 * E25 - 212 * E22 , DenShift32); |
---|
1300 | F25 = xTrRound( 212 * E25 - 142 * E22 , DenShift32); |
---|
1301 | F26 = xTrRound( 142 * E26 + 212 * E21 , DenShift32); |
---|
1302 | F29 = xTrRound( 49 * E29 - 251 * E18 , DenShift32); |
---|
1303 | F30 = xTrRound( 251 * E30 + 49 * E17 , DenShift32);; |
---|
1304 | |
---|
1305 | aaiTemp[2][y] = xTrRound( 25 * F8 + 254 * F15 , DenShift32); |
---|
1306 | aaiTemp[18][y] = xTrRound( 197 * F9 + 162 * F14 , DenShift32); |
---|
1307 | aaiTemp[10][y] = xTrRound( 120 * F10 + 225 * F13 , DenShift32); |
---|
1308 | aaiTemp[26][y] = xTrRound( 244 * F11 + 74 * F12 , DenShift32); |
---|
1309 | aaiTemp[6][y] = xTrRound( 244 * F12 - 74 * F11 , DenShift32); |
---|
1310 | aaiTemp[22][y] = xTrRound( 120 * F13 - 225 * F10 , DenShift32); |
---|
1311 | aaiTemp[14][y] = xTrRound( 197 * F14 - 162 * F9 , DenShift32); |
---|
1312 | aaiTemp[30][y] = xTrRound( 25 * F15 - 254 * F8 , DenShift32); |
---|
1313 | G16 = E16 + F17; |
---|
1314 | G17 = E16 - F17; |
---|
1315 | G18 = E19 - F18; |
---|
1316 | G19 = E19 + F18; |
---|
1317 | G20 = E20 + F21; |
---|
1318 | G21 = E20 - F21; |
---|
1319 | G22 = E23 - F22; |
---|
1320 | G23 = E23 + F22; |
---|
1321 | G24 = E24 + F25; |
---|
1322 | G25 = E24 - F25; |
---|
1323 | G26 = E27 - F26; |
---|
1324 | G27 = E27 + F26; |
---|
1325 | G28 = E28 + F29; |
---|
1326 | G29 = E28 - F29; |
---|
1327 | G30 = E31 - F30; |
---|
1328 | G31 = E31 + F30; |
---|
1329 | |
---|
1330 | aaiTemp[1][y] = xTrRound( 12 * G16 + 255 * G31 , DenShift32); |
---|
1331 | aaiTemp[17][y] = xTrRound( 189 * G17 + 171 * G30 , DenShift32); |
---|
1332 | aaiTemp[9][y] = xTrRound( 109 * G18 + 231 * G29 , DenShift32); |
---|
1333 | aaiTemp[25][y] = xTrRound( 241 * G19 + 86 * G28 , DenShift32); |
---|
1334 | aaiTemp[5][y] = xTrRound( 62 * G20 + 248 * G27 , DenShift32); |
---|
1335 | aaiTemp[21][y] = xTrRound( 219 * G21 + 131 * G26 , DenShift32); |
---|
1336 | aaiTemp[13][y] = xTrRound( 152 * G22 + 205 * G25 , DenShift32); |
---|
1337 | aaiTemp[29][y] = xTrRound( 253 * G23 + 37 * G24 , DenShift32); |
---|
1338 | aaiTemp[3][y] = xTrRound( 253 * G24 - 37 * G23 , DenShift32); |
---|
1339 | aaiTemp[19][y] = xTrRound( 152 * G25 - 205 * G22 , DenShift32); |
---|
1340 | aaiTemp[11][y] = xTrRound( 219 * G26 - 131 * G21 , DenShift32); |
---|
1341 | aaiTemp[27][y] = xTrRound( 62 * G27 - 248 * G20 , DenShift32); |
---|
1342 | aaiTemp[7][y] = xTrRound( 241 * G28 - 86 * G19 , DenShift32); |
---|
1343 | aaiTemp[23][y] = xTrRound( 109 * G29 - 231 * G18 , DenShift32); |
---|
1344 | aaiTemp[15][y] = xTrRound( 189 * G30 - 171 * G17 , DenShift32); |
---|
1345 | aaiTemp[31][y] = xTrRound( 12 * G31 - 255 * G16 , DenShift32); |
---|
1346 | |
---|
1347 | pSrc += uiStride; |
---|
1348 | } |
---|
1349 | |
---|
1350 | for( x=0 ; x<32 ; x++, pDes++ ) |
---|
1351 | { |
---|
1352 | A0 = aaiTemp[x][0] + aaiTemp[x][31]; |
---|
1353 | A31 = aaiTemp[x][0] - aaiTemp[x][31]; |
---|
1354 | A1 = aaiTemp[x][1] + aaiTemp[x][30]; |
---|
1355 | A30 = aaiTemp[x][1] - aaiTemp[x][30]; |
---|
1356 | A2 = aaiTemp[x][2] + aaiTemp[x][29]; |
---|
1357 | A29 = aaiTemp[x][2] - aaiTemp[x][29]; |
---|
1358 | A3 = aaiTemp[x][3] + aaiTemp[x][28]; |
---|
1359 | A28 = aaiTemp[x][3] - aaiTemp[x][28]; |
---|
1360 | A4 = aaiTemp[x][4] + aaiTemp[x][27]; |
---|
1361 | A27 = aaiTemp[x][4] - aaiTemp[x][27]; |
---|
1362 | A5 = aaiTemp[x][5] + aaiTemp[x][26]; |
---|
1363 | A26 = aaiTemp[x][5] - aaiTemp[x][26]; |
---|
1364 | A6 = aaiTemp[x][6] + aaiTemp[x][25]; |
---|
1365 | A25 = aaiTemp[x][6] - aaiTemp[x][25]; |
---|
1366 | A7 = aaiTemp[x][7] + aaiTemp[x][24]; |
---|
1367 | A24 = aaiTemp[x][7] - aaiTemp[x][24]; |
---|
1368 | A8 = aaiTemp[x][8] + aaiTemp[x][23]; |
---|
1369 | A23 = aaiTemp[x][8] - aaiTemp[x][23]; |
---|
1370 | A9 = aaiTemp[x][9] + aaiTemp[x][22]; |
---|
1371 | A22 = aaiTemp[x][9] - aaiTemp[x][22]; |
---|
1372 | A10 = aaiTemp[x][10] + aaiTemp[x][21]; |
---|
1373 | A21 = aaiTemp[x][10] - aaiTemp[x][21]; |
---|
1374 | A11 = aaiTemp[x][11] + aaiTemp[x][20]; |
---|
1375 | A20 = aaiTemp[x][11] - aaiTemp[x][20]; |
---|
1376 | A12 = aaiTemp[x][12] + aaiTemp[x][19]; |
---|
1377 | A19 = aaiTemp[x][12] - aaiTemp[x][19]; |
---|
1378 | A13 = aaiTemp[x][13] + aaiTemp[x][18]; |
---|
1379 | A18 = aaiTemp[x][13] - aaiTemp[x][18]; |
---|
1380 | A14 = aaiTemp[x][14] + aaiTemp[x][17]; |
---|
1381 | A17 = aaiTemp[x][14] - aaiTemp[x][17]; |
---|
1382 | A15 = aaiTemp[x][15] + aaiTemp[x][16]; |
---|
1383 | A16 = aaiTemp[x][15] - aaiTemp[x][16]; |
---|
1384 | |
---|
1385 | B0 = A0 + A15; |
---|
1386 | B15 = A0 - A15; |
---|
1387 | B1 = A1 + A14; |
---|
1388 | B14 = A1 - A14; |
---|
1389 | B2 = A2 + A13; |
---|
1390 | B13 = A2 - A13; |
---|
1391 | B3 = A3 + A12; |
---|
1392 | B12 = A3 - A12; |
---|
1393 | B4 = A4 + A11; |
---|
1394 | B11 = A4 - A11; |
---|
1395 | B5 = A5 + A10; |
---|
1396 | B10 = A5 - A10; |
---|
1397 | B6 = A6 + A9; |
---|
1398 | B9 = A6 - A9; |
---|
1399 | B7 = A7 + A8; |
---|
1400 | B8 = A7 - A8; |
---|
1401 | B20 = xTrRound( 181 * ( A27 - A20 ) , DenShift32); |
---|
1402 | B27 = xTrRound( 181 * ( A27 + A20 ) , DenShift32); |
---|
1403 | B21 = xTrRound( 181 * ( A26 - A21 ) , DenShift32); |
---|
1404 | B26 = xTrRound( 181 * ( A26 + A21 ) , DenShift32); |
---|
1405 | B22 = xTrRound( 181 * ( A25 - A22 ) , DenShift32); |
---|
1406 | B25 = xTrRound( 181 * ( A25 + A22 ) , DenShift32); |
---|
1407 | B23 = xTrRound( 181 * ( A24 - A23 ) , DenShift32); |
---|
1408 | B24 = xTrRound( 181 * ( A24 + A23 ) , DenShift32);; |
---|
1409 | |
---|
1410 | C0 = B0 + B7; |
---|
1411 | C7 = B0 - B7; |
---|
1412 | C1 = B1 + B6; |
---|
1413 | C6 = B1 - B6; |
---|
1414 | C2 = B2 + B5; |
---|
1415 | C5 = B2 - B5; |
---|
1416 | C3 = B3 + B4; |
---|
1417 | C4 = B3 - B4; |
---|
1418 | C10 = xTrRound( 181 * ( B13 - B10 ) , DenShift32); |
---|
1419 | C13 = xTrRound( 181 * ( B13 + B10 ) , DenShift32); |
---|
1420 | C11 = xTrRound( 181 * ( B12 - B11 ) , DenShift32); |
---|
1421 | C12 = xTrRound( 181 * ( B12 + B11 ) , DenShift32); |
---|
1422 | C16 = A16 + B23; |
---|
1423 | C23 = A16 - B23; |
---|
1424 | C24 = A31 - B24; |
---|
1425 | C31 = A31 + B24; |
---|
1426 | C17 = A17 + B22; |
---|
1427 | C22 = A17 - B22; |
---|
1428 | C25 = A30 - B25; |
---|
1429 | C30 = A30 + B25; |
---|
1430 | C18 = A18 + B21; |
---|
1431 | C21 = A18 - B21; |
---|
1432 | C26 = A29 - B26; |
---|
1433 | C29 = A29 + B26; |
---|
1434 | C19 = A19 + B20; |
---|
1435 | C20 = A19 - B20; |
---|
1436 | C27 = A28 - B27; |
---|
1437 | C28 = A28 + B27; |
---|
1438 | |
---|
1439 | D0 = C0 + C3; |
---|
1440 | D3 = C0 - C3; |
---|
1441 | D8 = B8 + C11; |
---|
1442 | D11 = B8 - C11; |
---|
1443 | D12 = B15 - C12; |
---|
1444 | D15 = B15 + C12; |
---|
1445 | D1 = C1 + C2; |
---|
1446 | D2 = C1 - C2; |
---|
1447 | D9 = B9 + C10; |
---|
1448 | D10 = B9 - C10; |
---|
1449 | D13 = B14 - C13; |
---|
1450 | D14 = B14 + C13; |
---|
1451 | D5 = xTrRound( 181 * ( C6 - C5 ) , DenShift32); |
---|
1452 | D6 = xTrRound( 181 * ( C6 + C5 ) , DenShift32); |
---|
1453 | D18 = xTrRound( 97 * C29 - 236 * C18 , DenShift32); |
---|
1454 | D20 = xTrRound( - 236 * C27 - 97 * C20 , DenShift32); |
---|
1455 | D26 = xTrRound( - 236 * C21 + 97 * C26 , DenShift32); |
---|
1456 | D28 = xTrRound( 97 * C19 + 236 * C28 , DenShift32); |
---|
1457 | D19 = xTrRound( 97 * C28 - 236 * C19 , DenShift32); |
---|
1458 | D21 = xTrRound( - 236 * C26 - 97 * C21 , DenShift32); |
---|
1459 | D27 = xTrRound( - 236 * C20 + 97 * C27 , DenShift32); |
---|
1460 | D29 = xTrRound( 97 * C18 + 236 * C29 , DenShift32);; |
---|
1461 | |
---|
1462 | pDes[0] = xTrRound( 181 * ( D0 + D1 ) , DenShift32); |
---|
1463 | pDes[512] = xTrRound( 181 * ( D0 - D1 ) , DenShift32); |
---|
1464 | pDes[256] = xTrRound( 236 * D3 + 97 * D2 , DenShift32); |
---|
1465 | pDes[768] = xTrRound( 97 * D3 - 236 * D2 , DenShift32); |
---|
1466 | #ifdef TRANS_PRECISION_EXT |
---|
1467 | pDes[0] = (pDes[0] +offset)>>uiBitDepthIncrease; |
---|
1468 | pDes[512] = (pDes[512]+offset)>>uiBitDepthIncrease; |
---|
1469 | pDes[256] = (pDes[256]+offset)>>uiBitDepthIncrease; |
---|
1470 | pDes[768] = (pDes[768]+offset)>>uiBitDepthIncrease; |
---|
1471 | #endif |
---|
1472 | E4 = C4 + D5; |
---|
1473 | E5 = C4 - D5; |
---|
1474 | E6 = C7 - D6; |
---|
1475 | E7 = C7 + D6; |
---|
1476 | E9 = xTrRound( 97 * D14 - 236 * D9 , DenShift32); |
---|
1477 | E10 = xTrRound( - 236 * D13 - 97 * D10 , DenShift32); |
---|
1478 | E13 = xTrRound( 97 * D13 - 236 * D10 , DenShift32); |
---|
1479 | E14 = xTrRound( 236 * D14 + 97 * D9 , DenShift32); |
---|
1480 | E16 = C16 + D19; |
---|
1481 | E19 = C16 - D19; |
---|
1482 | E20 = C23 - D20; |
---|
1483 | E23 = C23 + D20; |
---|
1484 | E24 = C24 + D27; |
---|
1485 | E27 = C24 - D27; |
---|
1486 | E28 = C31 - D28; |
---|
1487 | E31 = C31 + D28; |
---|
1488 | E17 = C17 + D18; |
---|
1489 | E18 = C17 - D18; |
---|
1490 | E21 = C22 - D21; |
---|
1491 | E22 = C22 + D21; |
---|
1492 | E25 = C25 + D26; |
---|
1493 | E26 = C25 - D26; |
---|
1494 | E29 = C30 - D29; |
---|
1495 | E30 = C30 + D29; |
---|
1496 | |
---|
1497 | pDes[128] = xTrRound( 49 * E4 + 251 * E7 , DenShift32); |
---|
1498 | pDes[640] = xTrRound( 212 * E5 + 142 * E6 , DenShift32); |
---|
1499 | pDes[384] = xTrRound( 212 * E6 - 142 * E5 , DenShift32); |
---|
1500 | pDes[896] = xTrRound( 49 * E7 - 251 * E4 , DenShift32); |
---|
1501 | #ifdef TRANS_PRECISION_EXT |
---|
1502 | pDes[128] = (pDes[128]+offset)>>uiBitDepthIncrease; |
---|
1503 | pDes[640] = (pDes[640]+offset)>>uiBitDepthIncrease; |
---|
1504 | pDes[384] = (pDes[384]+offset)>>uiBitDepthIncrease; |
---|
1505 | pDes[896] = (pDes[896]+offset)>>uiBitDepthIncrease; |
---|
1506 | #endif |
---|
1507 | F8 = D8 + E9; |
---|
1508 | F9 = D8 - E9; |
---|
1509 | F10 = D11 - E10; |
---|
1510 | F11 = D11 + E10; |
---|
1511 | F12 = D12 + E13; |
---|
1512 | F13 = D12 - E13; |
---|
1513 | F14 = D15 - E14; |
---|
1514 | F15 = D15 + E14; |
---|
1515 | F17 = xTrRound( 49 * E30 - 251 * E17 , DenShift32); |
---|
1516 | F18 = xTrRound( - 251 * E29 - 49 * E18 , DenShift32); |
---|
1517 | F21 = xTrRound( 212 * E26 - 142 * E21 , DenShift32); |
---|
1518 | F22 = xTrRound( - 142 * E25 - 212 * E22 , DenShift32); |
---|
1519 | F25 = xTrRound( 212 * E25 - 142 * E22 , DenShift32); |
---|
1520 | F26 = xTrRound( 142 * E26 + 212 * E21 , DenShift32); |
---|
1521 | F29 = xTrRound( 49 * E29 - 251 * E18 , DenShift32); |
---|
1522 | F30 = xTrRound( 251 * E30 + 49 * E17 , DenShift32);; |
---|
1523 | |
---|
1524 | pDes[64] = xTrRound( 25 * F8 + 254 * F15 , DenShift32); |
---|
1525 | pDes[576] = xTrRound( 197 * F9 + 162 * F14 , DenShift32); |
---|
1526 | pDes[320] = xTrRound( 120 * F10 + 225 * F13 , DenShift32); |
---|
1527 | pDes[832] = xTrRound( 244 * F11 + 74 * F12 , DenShift32); |
---|
1528 | pDes[192] = xTrRound( 244 * F12 - 74 * F11 , DenShift32); |
---|
1529 | pDes[704] = xTrRound( 120 * F13 - 225 * F10 , DenShift32); |
---|
1530 | pDes[448] = xTrRound( 197 * F14 - 162 * F9 , DenShift32); |
---|
1531 | pDes[960] = xTrRound( 25 * F15 - 254 * F8 , DenShift32); |
---|
1532 | #ifdef TRANS_PRECISION_EXT |
---|
1533 | pDes[64] = (pDes[64] +offset)>>uiBitDepthIncrease; |
---|
1534 | pDes[576] = (pDes[576]+offset)>>uiBitDepthIncrease; |
---|
1535 | pDes[320] = (pDes[320]+offset)>>uiBitDepthIncrease; |
---|
1536 | pDes[832] = (pDes[832]+offset)>>uiBitDepthIncrease; |
---|
1537 | pDes[192] = (pDes[192]+offset)>>uiBitDepthIncrease; |
---|
1538 | pDes[704] = (pDes[704]+offset)>>uiBitDepthIncrease; |
---|
1539 | pDes[448] = (pDes[448]+offset)>>uiBitDepthIncrease; |
---|
1540 | pDes[960] = (pDes[960]+offset)>>uiBitDepthIncrease; |
---|
1541 | #endif |
---|
1542 | G16 = E16 + F17; |
---|
1543 | G17 = E16 - F17; |
---|
1544 | G18 = E19 - F18; |
---|
1545 | G19 = E19 + F18; |
---|
1546 | G20 = E20 + F21; |
---|
1547 | G21 = E20 - F21; |
---|
1548 | G22 = E23 - F22; |
---|
1549 | G23 = E23 + F22; |
---|
1550 | G24 = E24 + F25; |
---|
1551 | G25 = E24 - F25; |
---|
1552 | G26 = E27 - F26; |
---|
1553 | G27 = E27 + F26; |
---|
1554 | G28 = E28 + F29; |
---|
1555 | G29 = E28 - F29; |
---|
1556 | G30 = E31 - F30; |
---|
1557 | G31 = E31 + F30; |
---|
1558 | |
---|
1559 | pDes[32] = xTrRound( 12 * G16 + 255 * G31 , DenShift32); |
---|
1560 | pDes[544] = xTrRound( 189 * G17 + 171 * G30 , DenShift32); |
---|
1561 | pDes[288] = xTrRound( 109 * G18 + 231 * G29 , DenShift32); |
---|
1562 | pDes[800] = xTrRound( 241 * G19 + 86 * G28 , DenShift32); |
---|
1563 | pDes[160] = xTrRound( 62 * G20 + 248 * G27 , DenShift32); |
---|
1564 | pDes[672] = xTrRound( 219 * G21 + 131 * G26 , DenShift32); |
---|
1565 | pDes[416] = xTrRound( 152 * G22 + 205 * G25 , DenShift32); |
---|
1566 | pDes[928] = xTrRound( 253 * G23 + 37 * G24 , DenShift32); |
---|
1567 | pDes[96] = xTrRound( 253 * G24 - 37 * G23 , DenShift32); |
---|
1568 | pDes[608] = xTrRound( 152 * G25 - 205 * G22 , DenShift32); |
---|
1569 | pDes[352] = xTrRound( 219 * G26 - 131 * G21 , DenShift32); |
---|
1570 | pDes[864] = xTrRound( 62 * G27 - 248 * G20 , DenShift32); |
---|
1571 | pDes[224] = xTrRound( 241 * G28 - 86 * G19 , DenShift32); |
---|
1572 | pDes[736] = xTrRound( 109 * G29 - 231 * G18 , DenShift32); |
---|
1573 | pDes[480] = xTrRound( 189 * G30 - 171 * G17 , DenShift32); |
---|
1574 | pDes[992] = xTrRound( 12 * G31 - 255 * G16 , DenShift32); |
---|
1575 | #ifdef TRANS_PRECISION_EXT |
---|
1576 | pDes[32] = (pDes[32] +offset)>>uiBitDepthIncrease; |
---|
1577 | pDes[544] = (pDes[544]+offset)>>uiBitDepthIncrease; |
---|
1578 | pDes[288] = (pDes[288]+offset)>>uiBitDepthIncrease; |
---|
1579 | pDes[800] = (pDes[800]+offset)>>uiBitDepthIncrease; |
---|
1580 | pDes[160] = (pDes[160]+offset)>>uiBitDepthIncrease; |
---|
1581 | pDes[672] = (pDes[672]+offset)>>uiBitDepthIncrease; |
---|
1582 | pDes[416] = (pDes[416]+offset)>>uiBitDepthIncrease; |
---|
1583 | pDes[928] = (pDes[928]+offset)>>uiBitDepthIncrease; |
---|
1584 | pDes[96] = (pDes[96] +offset)>>uiBitDepthIncrease; |
---|
1585 | pDes[608] = (pDes[608]+offset)>>uiBitDepthIncrease; |
---|
1586 | pDes[352] = (pDes[352]+offset)>>uiBitDepthIncrease; |
---|
1587 | pDes[864] = (pDes[864]+offset)>>uiBitDepthIncrease; |
---|
1588 | pDes[224] = (pDes[224]+offset)>>uiBitDepthIncrease; |
---|
1589 | pDes[736] = (pDes[736]+offset)>>uiBitDepthIncrease; |
---|
1590 | pDes[480] = (pDes[480]+offset)>>uiBitDepthIncrease; |
---|
1591 | pDes[992] = (pDes[992]+offset)>>uiBitDepthIncrease; |
---|
1592 | #endif |
---|
1593 | } |
---|
1594 | } |
---|
1595 | |
---|
1596 | Void TComTrQuant::xT16( Pel* pSrc, UInt uiStride, Long* pDes ) |
---|
1597 | { |
---|
1598 | Int x, y; |
---|
1599 | |
---|
1600 | Long aaiTemp[16][16]; |
---|
1601 | Long B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12, B13, B14, B15; |
---|
1602 | Long C0, C1, C2, C3, C4, C5, C6, C7, C10, C11, C12, C13; |
---|
1603 | Long D0, D1, D2, D3, D5, D6, D8, D9, D10, D11, D12, D13, D14, D15; |
---|
1604 | Long E4, E5, E6, E7, E9, E10, E13, E14; |
---|
1605 | Long F8, F9, F10, F11, F12, F13, F14, F15; |
---|
1606 | #ifdef TRANS_PRECISION_EXT |
---|
1607 | Int uiBitDepthIncrease=g_iShift16x16-g_uiBitIncrement; |
---|
1608 | Int offset = (uiBitDepthIncrease==0)? 0:(1<<(uiBitDepthIncrease-1)); |
---|
1609 | #endif |
---|
1610 | |
---|
1611 | //--Butterfly |
---|
1612 | for( y=0 ; y<16 ; y++ ) |
---|
1613 | { |
---|
1614 | #ifdef TRANS_PRECISION_EXT |
---|
1615 | B0 = (pSrc[0] + pSrc[15])<<uiBitDepthIncrease; |
---|
1616 | B15 = (pSrc[0] - pSrc[15])<<uiBitDepthIncrease; |
---|
1617 | B1 = (pSrc[1] + pSrc[14])<<uiBitDepthIncrease; |
---|
1618 | B14 = (pSrc[1] - pSrc[14])<<uiBitDepthIncrease; |
---|
1619 | B2 = (pSrc[2] + pSrc[13])<<uiBitDepthIncrease; |
---|
1620 | B13 = (pSrc[2] - pSrc[13])<<uiBitDepthIncrease; |
---|
1621 | B3 = (pSrc[3] + pSrc[12])<<uiBitDepthIncrease; |
---|
1622 | B12 = (pSrc[3] - pSrc[12])<<uiBitDepthIncrease; |
---|
1623 | B4 = (pSrc[4] + pSrc[11])<<uiBitDepthIncrease; |
---|
1624 | B11 = (pSrc[4] - pSrc[11])<<uiBitDepthIncrease; |
---|
1625 | B5 = (pSrc[5] + pSrc[10])<<uiBitDepthIncrease; |
---|
1626 | B10 = (pSrc[5] - pSrc[10])<<uiBitDepthIncrease; |
---|
1627 | B6 = (pSrc[6] + pSrc[9])<<uiBitDepthIncrease; |
---|
1628 | B9 = (pSrc[6] - pSrc[9])<<uiBitDepthIncrease; |
---|
1629 | B7 = (pSrc[7] + pSrc[8])<<uiBitDepthIncrease; |
---|
1630 | B8 = (pSrc[7] - pSrc[8])<<uiBitDepthIncrease; |
---|
1631 | #else |
---|
1632 | B0 = pSrc[0] + pSrc[15]; |
---|
1633 | B15 = pSrc[0] - pSrc[15]; |
---|
1634 | B1 = pSrc[1] + pSrc[14]; |
---|
1635 | B14 = pSrc[1] - pSrc[14]; |
---|
1636 | B2 = pSrc[2] + pSrc[13]; |
---|
1637 | B13 = pSrc[2] - pSrc[13]; |
---|
1638 | B3 = pSrc[3] + pSrc[12]; |
---|
1639 | B12 = pSrc[3] - pSrc[12]; |
---|
1640 | B4 = pSrc[4] + pSrc[11]; |
---|
1641 | B11 = pSrc[4] - pSrc[11]; |
---|
1642 | B5 = pSrc[5] + pSrc[10]; |
---|
1643 | B10 = pSrc[5] - pSrc[10]; |
---|
1644 | B6 = pSrc[6] + pSrc[9]; |
---|
1645 | B9 = pSrc[6] - pSrc[9]; |
---|
1646 | B7 = pSrc[7] + pSrc[8]; |
---|
1647 | B8 = pSrc[7] - pSrc[8]; |
---|
1648 | #endif |
---|
1649 | C0 = B0 + B7; |
---|
1650 | C7 = B0 - B7; |
---|
1651 | C1 = B1 + B6; |
---|
1652 | C6 = B1 - B6; |
---|
1653 | C2 = B2 + B5; |
---|
1654 | C5 = B2 - B5; |
---|
1655 | C3 = B3 + B4; |
---|
1656 | C4 = B3 - B4; |
---|
1657 | C10 = xTrRound( 45 * ( B13 - B10 ) , DenShift16); |
---|
1658 | C13 = xTrRound( 45 * ( B13 + B10 ) , DenShift16); |
---|
1659 | C11 = xTrRound( 45 * ( B12 - B11 ) , DenShift16); |
---|
1660 | C12 = xTrRound( 45 * ( B12 + B11 ) , DenShift16); |
---|
1661 | |
---|
1662 | D0 = C0 + C3; |
---|
1663 | D3 = C0 - C3; |
---|
1664 | D8 = B8 + C11; |
---|
1665 | D11 = B8 - C11; |
---|
1666 | D12 = B15 - C12; |
---|
1667 | D15 = B15 + C12; |
---|
1668 | D1 = C1 + C2; |
---|
1669 | D2 = C1 - C2; |
---|
1670 | D9 = B9 + C10; |
---|
1671 | D10 = B9 - C10; |
---|
1672 | D13 = B14 - C13; |
---|
1673 | D14 = B14 + C13; |
---|
1674 | D5 = xTrRound( 45 * ( C6 - C5 ) , DenShift16); |
---|
1675 | D6 = xTrRound( 45 * ( C6 + C5 ) , DenShift16); |
---|
1676 | |
---|
1677 | aaiTemp[0][y] = xTrRound( 45 * ( D0 + D1 ) , DenShift16); |
---|
1678 | aaiTemp[8][y] = xTrRound( 45 * ( D0 - D1 ) , DenShift16); |
---|
1679 | aaiTemp[4][y] = xTrRound( 59 * D3 + 24 * D2 , DenShift16); |
---|
1680 | aaiTemp[12][y] = xTrRound( 24 * D3 - 59 * D2 , DenShift16); |
---|
1681 | E4 = C4 + D5; |
---|
1682 | E5 = C4 - D5; |
---|
1683 | E6 = C7 - D6; |
---|
1684 | E7 = C7 + D6; |
---|
1685 | E9 = xTrRound( 24 * D14 - 59 * D9 , DenShift16); |
---|
1686 | E10 = xTrRound( -59 * D13 - 24 * D10 , DenShift16); |
---|
1687 | E13 = xTrRound( 24 * D13 - 59 * D10 , DenShift16); |
---|
1688 | E14 = xTrRound( 59 * D14 + 24 * D9 , DenShift16); |
---|
1689 | |
---|
1690 | aaiTemp[2][y] = xTrRound( 12 * E4 + 62 * E7 , DenShift16); |
---|
1691 | aaiTemp[10][y] = xTrRound( 53 * E5 + 35 * E6 , DenShift16); |
---|
1692 | aaiTemp[6][y] = xTrRound( 53 * E6 - 35 * E5 , DenShift16); |
---|
1693 | aaiTemp[14][y] = xTrRound( 12 * E7 - 62 * E4 , DenShift16); |
---|
1694 | F8 = D8 + E9; |
---|
1695 | F9 = D8 - E9; |
---|
1696 | F10 = D11 - E10; |
---|
1697 | F11 = D11 + E10; |
---|
1698 | F12 = D12 + E13; |
---|
1699 | F13 = D12 - E13; |
---|
1700 | F14 = D15 - E14; |
---|
1701 | F15 = D15 + E14; |
---|
1702 | |
---|
1703 | aaiTemp[1][y] = xTrRound( 6 * F8 + 63 * F15 , DenShift16); |
---|
1704 | aaiTemp[9][y] = xTrRound( 49 * F9 + 40 * F14 , DenShift16); |
---|
1705 | aaiTemp[5][y] = xTrRound( 30 * F10 + 56 * F13 , DenShift16); |
---|
1706 | aaiTemp[13][y] = xTrRound( 61 * F11 + 18 * F12 , DenShift16); |
---|
1707 | aaiTemp[3][y] = xTrRound( 61 * F12 - 18 * F11 , DenShift16); |
---|
1708 | aaiTemp[11][y] = xTrRound( 30 * F13 - 56 * F10 , DenShift16); |
---|
1709 | aaiTemp[7][y] = xTrRound( 49 * F14 - 40 * F9 , DenShift16); |
---|
1710 | aaiTemp[15][y] = xTrRound( 6 * F15 - 63 * F8 , DenShift16); |
---|
1711 | |
---|
1712 | pSrc += uiStride; |
---|
1713 | } |
---|
1714 | |
---|
1715 | for( x=0 ; x<16 ; x++, pDes++ ) |
---|
1716 | { |
---|
1717 | B0 = aaiTemp[x][0] + aaiTemp[x][15]; |
---|
1718 | B15 = aaiTemp[x][0] - aaiTemp[x][15]; |
---|
1719 | B1 = aaiTemp[x][1] + aaiTemp[x][14]; |
---|
1720 | B14 = aaiTemp[x][1] - aaiTemp[x][14]; |
---|
1721 | B2 = aaiTemp[x][2] + aaiTemp[x][13]; |
---|
1722 | B13 = aaiTemp[x][2] - aaiTemp[x][13]; |
---|
1723 | B3 = aaiTemp[x][3] + aaiTemp[x][12]; |
---|
1724 | B12 = aaiTemp[x][3] - aaiTemp[x][12]; |
---|
1725 | B4 = aaiTemp[x][4] + aaiTemp[x][11]; |
---|
1726 | B11 = aaiTemp[x][4] - aaiTemp[x][11]; |
---|
1727 | B5 = aaiTemp[x][5] + aaiTemp[x][10]; |
---|
1728 | B10 = aaiTemp[x][5] - aaiTemp[x][10]; |
---|
1729 | B6 = aaiTemp[x][6] + aaiTemp[x][9]; |
---|
1730 | B9 = aaiTemp[x][6] - aaiTemp[x][9]; |
---|
1731 | B7 = aaiTemp[x][7] + aaiTemp[x][8]; |
---|
1732 | B8 = aaiTemp[x][7] - aaiTemp[x][8]; |
---|
1733 | |
---|
1734 | C0 = B0 + B7; |
---|
1735 | C7 = B0 - B7; |
---|
1736 | C1 = B1 + B6; |
---|
1737 | C6 = B1 - B6; |
---|
1738 | C2 = B2 + B5; |
---|
1739 | C5 = B2 - B5; |
---|
1740 | C3 = B3 + B4; |
---|
1741 | C4 = B3 - B4; |
---|
1742 | C10 = xTrRound( 45 * ( B13 - B10 ) , DenShift16); |
---|
1743 | C13 = xTrRound( 45 * ( B13 + B10 ) , DenShift16); |
---|
1744 | C11 = xTrRound( 45 * ( B12 - B11 ) , DenShift16); |
---|
1745 | C12 = xTrRound( 45 * ( B12 + B11 ) , DenShift16); |
---|
1746 | |
---|
1747 | D0 = C0 + C3; |
---|
1748 | D3 = C0 - C3; |
---|
1749 | D8 = B8 + C11; |
---|
1750 | D11 = B8 - C11; |
---|
1751 | D12 = B15 - C12; |
---|
1752 | D15 = B15 + C12; |
---|
1753 | D1 = C1 + C2; |
---|
1754 | D2 = C1 - C2; |
---|
1755 | D9 = B9 + C10; |
---|
1756 | D10 = B9 - C10; |
---|
1757 | D13 = B14 - C13; |
---|
1758 | D14 = B14 + C13; |
---|
1759 | D5 = xTrRound( 45 * ( C6 - C5 ) , DenShift16); |
---|
1760 | D6 = xTrRound( 45 * ( C6 + C5 ) , DenShift16); |
---|
1761 | |
---|
1762 | pDes[0] = xTrRound( 45 * ( D0 + D1 ) , DenShift16); |
---|
1763 | pDes[128] = xTrRound( 45 * ( D0 - D1 ) , DenShift16); |
---|
1764 | pDes[64] = xTrRound( 59 * D3 + 24 * D2 , DenShift16); |
---|
1765 | pDes[192] = xTrRound( 24 * D3 - 59 * D2 , DenShift16); |
---|
1766 | #ifdef TRANS_PRECISION_EXT |
---|
1767 | pDes[0 ] = (pDes[0 ]+offset)>>uiBitDepthIncrease; |
---|
1768 | pDes[128] = (pDes[128]+offset)>>uiBitDepthIncrease; |
---|
1769 | pDes[64 ] = (pDes[64 ]+offset)>>uiBitDepthIncrease; |
---|
1770 | pDes[192] = (pDes[192]+offset)>>uiBitDepthIncrease; |
---|
1771 | #endif |
---|
1772 | E4 = C4 + D5; |
---|
1773 | E5 = C4 - D5; |
---|
1774 | E6 = C7 - D6; |
---|
1775 | E7 = C7 + D6; |
---|
1776 | E9 = xTrRound( 24 * D14 - 59 * D9 , DenShift16); |
---|
1777 | E10 = xTrRound( -59 * D13 - 24 * D10 , DenShift16); |
---|
1778 | E13 = xTrRound( 24 * D13 - 59 * D10 , DenShift16); |
---|
1779 | E14 = xTrRound( 59 * D14 + 24 * D9 , DenShift16); |
---|
1780 | |
---|
1781 | pDes[32] = xTrRound( 12 * E4 + 62 * E7 , DenShift16); |
---|
1782 | pDes[160] = xTrRound( 53 * E5 + 35 * E6 , DenShift16); |
---|
1783 | pDes[96] = xTrRound( 53 * E6 - 35 * E5 , DenShift16); |
---|
1784 | pDes[224] = xTrRound( 12 * E7 - 62 * E4 , DenShift16); |
---|
1785 | #ifdef TRANS_PRECISION_EXT |
---|
1786 | pDes[32] = (pDes[32] +offset)>>uiBitDepthIncrease; |
---|
1787 | pDes[160] = (pDes[160]+offset)>>uiBitDepthIncrease; |
---|
1788 | pDes[96] = (pDes[96] +offset)>>uiBitDepthIncrease; |
---|
1789 | pDes[224] = (pDes[224]+offset)>>uiBitDepthIncrease; |
---|
1790 | #endif |
---|
1791 | F8 = D8 + E9; |
---|
1792 | F9 = D8 - E9; |
---|
1793 | F10 = D11 - E10; |
---|
1794 | F11 = D11 + E10; |
---|
1795 | F12 = D12 + E13; |
---|
1796 | F13 = D12 - E13; |
---|
1797 | F14 = D15 - E14; |
---|
1798 | F15 = D15 + E14; |
---|
1799 | |
---|
1800 | pDes[16] = xTrRound( 6 * F8 + 63 * F15 , DenShift16); |
---|
1801 | pDes[144] = xTrRound( 49 * F9 + 40 * F14 , DenShift16); |
---|
1802 | pDes[80] = xTrRound( 30 * F10 + 56 * F13 , DenShift16); |
---|
1803 | pDes[208] = xTrRound( 61 * F11 + 18 * F12 , DenShift16); |
---|
1804 | pDes[48] = xTrRound( 61 * F12 - 18 * F11 , DenShift16); |
---|
1805 | pDes[176] = xTrRound( 30 * F13 - 56 * F10 , DenShift16); |
---|
1806 | pDes[112] = xTrRound( 49 * F14 - 40 * F9 , DenShift16); |
---|
1807 | pDes[240] = xTrRound( 6 * F15 - 63 * F8 , DenShift16); |
---|
1808 | #ifdef TRANS_PRECISION_EXT |
---|
1809 | pDes[16] = (pDes[16] +offset)>>uiBitDepthIncrease; |
---|
1810 | pDes[144] = (pDes[144]+offset)>>uiBitDepthIncrease; |
---|
1811 | pDes[80] = (pDes[80] +offset)>>uiBitDepthIncrease; |
---|
1812 | pDes[208] = (pDes[208]+offset)>>uiBitDepthIncrease; |
---|
1813 | pDes[48] = (pDes[48] +offset)>>uiBitDepthIncrease; |
---|
1814 | pDes[176] = (pDes[176]+offset)>>uiBitDepthIncrease; |
---|
1815 | pDes[112] = (pDes[112]+offset)>>uiBitDepthIncrease; |
---|
1816 | pDes[240] = (pDes[240]+offset)>>uiBitDepthIncrease; |
---|
1817 | #endif |
---|
1818 | } |
---|
1819 | } |
---|
1820 | #endif //E243_CORE_TRANSFORMS |
---|
1821 | |
---|
1822 | #if QC_MOD_LCEC_RDOQ |
---|
1823 | UInt TComTrQuant::xCountVlcBits(UInt uiTableNumber, UInt uiCodeNumber) |
---|
1824 | { |
---|
1825 | UInt uiLength = 0; |
---|
1826 | UInt uiCode = 0; |
---|
1827 | |
---|
1828 | if ( uiCodeNumber < 128 ) |
---|
1829 | { |
---|
1830 | uiLength=VLClength[uiTableNumber][uiCodeNumber]; |
---|
1831 | } |
---|
1832 | else |
---|
1833 | { |
---|
1834 | if ( uiTableNumber < 10 ) |
---|
1835 | { |
---|
1836 | if ( uiTableNumber < 5 ) |
---|
1837 | { |
---|
1838 | uiCode = uiCodeNumber - (6 * (1 << uiTableNumber)) + (1 << uiTableNumber); |
---|
1839 | uiLength = ( 6 - uiTableNumber ) + 1 + 2 * xLeadingZeros(uiCode); |
---|
1840 | } |
---|
1841 | else if ( uiTableNumber < 8 ) |
---|
1842 | { |
---|
1843 | uiLength = 1 + (uiTableNumber - 4) + (uiCodeNumber >> (uiTableNumber - 4)); |
---|
1844 | } |
---|
1845 | else if ( uiTableNumber == 9 ) |
---|
1846 | { |
---|
1847 | uiLength = 5 + ((uiCodeNumber + 5) >> 4); |
---|
1848 | } |
---|
1849 | } |
---|
1850 | else |
---|
1851 | { |
---|
1852 | if ( uiTableNumber == 10 ) |
---|
1853 | { |
---|
1854 | uiCode = uiCodeNumber + 1; |
---|
1855 | uiLength = 1 + 2 * xLeadingZeros(uiCode); |
---|
1856 | } |
---|
1857 | #if CAVLC_COEF_LRG_BLK |
---|
1858 | else if (uiTableNumber == 12) |
---|
1859 | { |
---|
1860 | uiLength = 7+(uiCodeNumber>>6); |
---|
1861 | } |
---|
1862 | else if(uiTableNumber == 13) |
---|
1863 | { |
---|
1864 | uiLength = 5+(uiCodeNumber>>4); |
---|
1865 | } |
---|
1866 | #endif |
---|
1867 | } |
---|
1868 | } |
---|
1869 | return uiLength; |
---|
1870 | } |
---|
1871 | |
---|
1872 | |
---|
1873 | #if CAVLC_COEF_LRG_BLK |
---|
1874 | Int TComTrQuant::bitCountRDOQ(Int coeff, Int pos, Int nTab, Int lastCoeffFlag,Int levelMode,Int run, Int maxrun, Int vlc_adaptive, Int N, |
---|
1875 | UInt uiTr1, Int iSum_big_coef, Int iBlockType, TComDataCU* pcCU, const UInt **pLumaRunTr1) |
---|
1876 | #else |
---|
1877 | Int TComTrQuant::bitCountRDOQ(Int coeff, Int pos, Int nTab, Int lastCoeffFlag,Int levelMode,Int run, Int maxrun, Int vlc_adaptive, Int N, |
---|
1878 | UInt uiTr1, Int iSum_big_coef, Int iBlockType, TComDataCU* pcCU) |
---|
1879 | #endif |
---|
1880 | { |
---|
1881 | UInt cn, n, level, lev; |
---|
1882 | Int vlc,x,cx,vlcNum,bits; |
---|
1883 | static const int vlcTable4[3] = {2,2,2}; // Y4x4I,Y4x4P,Y4x4B, |
---|
1884 | |
---|
1885 | Int sign = coeff < 0 ? 1 : 0; |
---|
1886 | |
---|
1887 | if ( N==4 ) |
---|
1888 | { |
---|
1889 | n = Max(0, nTab - 2); |
---|
1890 | } |
---|
1891 | else |
---|
1892 | { |
---|
1893 | n = nTab; |
---|
1894 | } |
---|
1895 | |
---|
1896 | UInt uiModZeroCoding = 0; |
---|
1897 | const UInt *uiVlcTableTemp; |
---|
1898 | |
---|
1899 | #if CAVLC_COEF_LRG_BLK |
---|
1900 | uiModZeroCoding = (m_uiRDOQOffset==1 || N>8)? 1:0; |
---|
1901 | int tmprun = Min(maxrun,28); |
---|
1902 | |
---|
1903 | if( N<=8 ) |
---|
1904 | { |
---|
1905 | uiVlcTableTemp = (nTab==2 || nTab==5)? g_auiVlcTable8x8Intra:g_auiVlcTable8x8Inter; |
---|
1906 | } |
---|
1907 | else |
---|
1908 | { |
---|
1909 | uiVlcTableTemp = (nTab==5)? g_auiVlcTable16x16Intra:g_auiVlcTable16x16Inter; |
---|
1910 | } |
---|
1911 | #else |
---|
1912 | if( nTab == 2 || nTab == 5 ){ |
---|
1913 | uiVlcTableTemp = g_auiVlcTable8x8Intra; |
---|
1914 | } |
---|
1915 | else |
---|
1916 | { |
---|
1917 | uiVlcTableTemp = g_auiVlcTable8x8Inter; |
---|
1918 | } |
---|
1919 | #endif |
---|
1920 | |
---|
1921 | level = abs(coeff); |
---|
1922 | lev = (level == 1) ? 0 : 1; |
---|
1923 | |
---|
1924 | if ( level ) |
---|
1925 | { |
---|
1926 | if ( lastCoeffFlag == 1 ) |
---|
1927 | { |
---|
1928 | x = pos + (level == 1 ? 0 : N * N); |
---|
1929 | if( N == 4 ) |
---|
1930 | { |
---|
1931 | cx = m_uiLPTableE4[(n << 5) + x]; |
---|
1932 | vlcNum = vlcTable4[n]; |
---|
1933 | } |
---|
1934 | else{ |
---|
1935 | #if CAVLC_COEF_LRG_BLK |
---|
1936 | cx = xLastLevelInd(lev, pos, N); |
---|
1937 | #else |
---|
1938 | cx = m_uiLPTableE8[(n << 7) + x]; |
---|
1939 | #endif |
---|
1940 | vlcNum = g_auiLastPosVlcNum[n][Min(16,m_uiLastPosVlcIndex[n])]; |
---|
1941 | } |
---|
1942 | bits=xCountVlcBits( vlcNum, cx ); |
---|
1943 | |
---|
1944 | if ( level > 1 ) |
---|
1945 | { |
---|
1946 | bits += xCountVlcBits( 0, 2 * (level - 2) + sign ); |
---|
1947 | } |
---|
1948 | else |
---|
1949 | { |
---|
1950 | bits++; |
---|
1951 | } |
---|
1952 | |
---|
1953 | } |
---|
1954 | else{ // Level !=0 && lastCoeffFlag==0 |
---|
1955 | |
---|
1956 | if ( !levelMode ){ |
---|
1957 | #if CAVLC_COEF_LRG_BLK |
---|
1958 | if(nTab == 2 || nTab == 5) |
---|
1959 | { |
---|
1960 | cn = xRunLevelInd(lev, run, maxrun, pLumaRunTr1[uiTr1][tmprun]); |
---|
1961 | } |
---|
1962 | else |
---|
1963 | { |
---|
1964 | cn = xRunLevelIndInter(lev, run, maxrun); |
---|
1965 | } |
---|
1966 | vlc = uiVlcTableTemp[tmprun]; |
---|
1967 | #else |
---|
1968 | if ( N == 4 ){ |
---|
1969 | // 4x4 |
---|
1970 | if ( nTab == 2 ){ |
---|
1971 | cn = xRunLevelInd(lev, run, maxrun, g_auiLumaRunTr14x4[uiTr1][maxrun]); |
---|
1972 | } |
---|
1973 | else{ |
---|
1974 | #if RUNLEVEL_TABLE_CUT |
---|
1975 | cn = xRunLevelIndInter(lev, run, maxrun); |
---|
1976 | #else |
---|
1977 | cn = g_auiLumaRun8x8[maxrun][lev][run]; |
---|
1978 | #endif |
---|
1979 | } |
---|
1980 | vlc = uiVlcTableTemp[maxrun]; |
---|
1981 | } |
---|
1982 | else { |
---|
1983 | // 8x8 |
---|
1984 | if(nTab == 2 || nTab == 5) |
---|
1985 | { |
---|
1986 | cn = xRunLevelInd(lev, run, maxrun, g_auiLumaRunTr18x8[uiTr1][Min(maxrun,28)]); |
---|
1987 | } |
---|
1988 | else |
---|
1989 | { |
---|
1990 | #if RUNLEVEL_TABLE_CUT |
---|
1991 | cn = xRunLevelIndInter(lev, run, maxrun); |
---|
1992 | #else |
---|
1993 | cn = g_auiLumaRun8x8[Min(maxrun,28)][lev][run]; |
---|
1994 | #endif |
---|
1995 | } |
---|
1996 | vlc = uiVlcTableTemp[Min(maxrun,28)]; |
---|
1997 | } |
---|
1998 | #endif |
---|
1999 | bits = xCountVlcBits( vlc, cn ); |
---|
2000 | if ( level > 1 ){ |
---|
2001 | bits += xCountVlcBits( 0, 2 * (level - 2) + sign ); |
---|
2002 | } |
---|
2003 | else{ |
---|
2004 | bits++; |
---|
2005 | } |
---|
2006 | |
---|
2007 | } |
---|
2008 | else{ // Level !=0 && lastCoeffFlag==0 && levelMode |
---|
2009 | bits = (xCountVlcBits( vlc_adaptive, level ) + 1); |
---|
2010 | } |
---|
2011 | } |
---|
2012 | } |
---|
2013 | else{ |
---|
2014 | |
---|
2015 | if (levelMode){ |
---|
2016 | bits=xCountVlcBits( vlc_adaptive, level ); |
---|
2017 | } |
---|
2018 | else{ |
---|
2019 | if ( pos == 0 && lastCoeffFlag == 0){ |
---|
2020 | |
---|
2021 | #if CAVLC_COEF_LRG_BLK |
---|
2022 | vlc = uiVlcTableTemp[tmprun]; |
---|
2023 | if(nTab == 2 || nTab == 5) |
---|
2024 | { |
---|
2025 | cn = xRunLevelInd(0, run + 1, maxrun, pLumaRunTr1[uiTr1][tmprun]); |
---|
2026 | } |
---|
2027 | else |
---|
2028 | { |
---|
2029 | cn = xRunLevelIndInter(0, run + 1, maxrun); |
---|
2030 | } |
---|
2031 | #else |
---|
2032 | if ( N == 4 ){ |
---|
2033 | // 4x4 |
---|
2034 | vlc = uiVlcTableTemp[maxrun]; |
---|
2035 | if ( nTab == 2 ){ |
---|
2036 | cn = xRunLevelInd(0, run + 1, maxrun, g_auiLumaRunTr14x4[uiTr1][maxrun]); |
---|
2037 | } |
---|
2038 | else{ |
---|
2039 | #if RUNLEVEL_TABLE_CUT |
---|
2040 | cn = xRunLevelIndInter(0, run+1, maxrun); |
---|
2041 | #else |
---|
2042 | cn = g_auiLumaRun8x8[maxrun][0][run + 1]; |
---|
2043 | #endif |
---|
2044 | } |
---|
2045 | } |
---|
2046 | else{ |
---|
2047 | // 8x8 |
---|
2048 | vlc = uiVlcTableTemp[Min(maxrun, 28)]; |
---|
2049 | if(nTab == 2 || nTab == 5){ |
---|
2050 | cn = xRunLevelInd(0, run + 1, maxrun, g_auiLumaRunTr18x8[uiTr1][Min(maxrun, 28)]); |
---|
2051 | } |
---|
2052 | else{ |
---|
2053 | #if RUNLEVEL_TABLE_CUT |
---|
2054 | cn = xRunLevelIndInter(0, run+1, maxrun); |
---|
2055 | #else |
---|
2056 | cn = g_auiLumaRun8x8[Min(maxrun, 28)][0][run + 1]; |
---|
2057 | #endif |
---|
2058 | } |
---|
2059 | } |
---|
2060 | #endif |
---|
2061 | bits=xCountVlcBits( vlc, cn ); |
---|
2062 | } |
---|
2063 | else{ |
---|
2064 | bits = 0; |
---|
2065 | |
---|
2066 | if ( pos > 0 && uiModZeroCoding == 1 ){ |
---|
2067 | |
---|
2068 | Int iSum_big_coefTemp, levelModeTemp, maxrunTemp; |
---|
2069 | UInt uiTr1Temp; |
---|
2070 | |
---|
2071 | if ( lastCoeffFlag == 0 ){ |
---|
2072 | |
---|
2073 | #if CAVLC_COEF_LRG_BLK |
---|
2074 | vlc = uiVlcTableTemp[tmprun]; |
---|
2075 | if(nTab == 2 || nTab == 5) |
---|
2076 | { |
---|
2077 | cn = xRunLevelInd(0, run + 1, maxrun, pLumaRunTr1[uiTr1][tmprun]); |
---|
2078 | } |
---|
2079 | else |
---|
2080 | { |
---|
2081 | cn = xRunLevelIndInter(0, run + 1, maxrun); |
---|
2082 | } |
---|
2083 | #else |
---|
2084 | if ( N == 4 ){ |
---|
2085 | // 4x4 |
---|
2086 | vlc = uiVlcTableTemp[maxrun]; |
---|
2087 | if ( nTab == 2 ){ |
---|
2088 | cn = xRunLevelInd(0, run + 1, maxrun, g_auiLumaRunTr14x4[uiTr1][maxrun]); |
---|
2089 | } |
---|
2090 | else{ |
---|
2091 | #if RUNLEVEL_TABLE_CUT |
---|
2092 | cn = xRunLevelIndInter(0, run+1, maxrun); |
---|
2093 | #else |
---|
2094 | cn = g_auiLumaRun8x8[maxrun][0][run + 1]; |
---|
2095 | #endif |
---|
2096 | } |
---|
2097 | } |
---|
2098 | else{ |
---|
2099 | // 8x8 |
---|
2100 | vlc = uiVlcTableTemp[Min(maxrun, 28)]; |
---|
2101 | if(nTab == 2 || nTab == 5){ |
---|
2102 | cn = xRunLevelInd(0, run + 1, maxrun, g_auiLumaRunTr18x8[uiTr1][Min(maxrun, 28)]); |
---|
2103 | } |
---|
2104 | else{ |
---|
2105 | #if RUNLEVEL_TABLE_CUT |
---|
2106 | cn = xRunLevelIndInter(0, run+1, maxrun); |
---|
2107 | #else |
---|
2108 | cn = g_auiLumaRun8x8[Min(maxrun,28)][0][run + 1]; |
---|
2109 | #endif |
---|
2110 | } |
---|
2111 | } |
---|
2112 | #endif |
---|
2113 | } |
---|
2114 | else{ |
---|
2115 | |
---|
2116 | x = (pos - 1); |
---|
2117 | if( N == 4 ) |
---|
2118 | { |
---|
2119 | cn = m_uiLPTableE4[(n << 5) + x]; |
---|
2120 | vlc = vlcTable4[n]; |
---|
2121 | } |
---|
2122 | else{ |
---|
2123 | #if CAVLC_COEF_LRG_BLK |
---|
2124 | cn = xLastLevelInd(lev, pos, N); |
---|
2125 | #else |
---|
2126 | cn = m_uiLPTableE8[(n << 7) + x]; |
---|
2127 | #endif |
---|
2128 | vlc = g_auiLastPosVlcNum[n][Min(16, m_uiLastPosVlcIndex[n])]; |
---|
2129 | } |
---|
2130 | } |
---|
2131 | bits+=xCountVlcBits( vlc, cn ); |
---|
2132 | |
---|
2133 | // Next coeff is 1 with run=0 |
---|
2134 | |
---|
2135 | iSum_big_coefTemp = iSum_big_coef; |
---|
2136 | levelModeTemp = levelMode; |
---|
2137 | Int switch_thr[10] = {49,49,0,49,49,0,49,49,49,49}; |
---|
2138 | |
---|
2139 | if ( N > 4 ){ |
---|
2140 | if ( level > 1 ){ |
---|
2141 | iSum_big_coefTemp += level; |
---|
2142 | if ((N * N - pos - 1) > switch_thr[iBlockType] || iSum_big_coefTemp > 2) levelModeTemp = 1; |
---|
2143 | } |
---|
2144 | } |
---|
2145 | else{ |
---|
2146 | if ( level > 1 ) levelModeTemp = 1; |
---|
2147 | } |
---|
2148 | |
---|
2149 | if ( levelModeTemp == 1 ){ |
---|
2150 | bits-=xCountVlcBits( vlc_adaptive, 1); |
---|
2151 | } |
---|
2152 | else{ |
---|
2153 | maxrunTemp = pos - 1; |
---|
2154 | uiTr1Temp = uiTr1; |
---|
2155 | |
---|
2156 | if ( uiTr1Temp > 0 && level < 2 ){ |
---|
2157 | uiTr1Temp++; |
---|
2158 | uiTr1Temp = Min(MAX_TR1, uiTr1Temp); |
---|
2159 | } |
---|
2160 | else{ |
---|
2161 | uiTr1Temp=0; |
---|
2162 | } |
---|
2163 | |
---|
2164 | #if CAVLC_COEF_LRG_BLK |
---|
2165 | vlc = uiVlcTableTemp[Min(maxrunTemp,28)]; |
---|
2166 | if(nTab == 2 || nTab == 5) |
---|
2167 | { |
---|
2168 | cn = xRunLevelInd(0, 0, maxrunTemp, pLumaRunTr1[uiTr1Temp][Min(maxrunTemp,28)]); |
---|
2169 | } |
---|
2170 | else |
---|
2171 | { |
---|
2172 | cn = xRunLevelIndInter(0, 0, maxrunTemp); |
---|
2173 | } |
---|
2174 | #else |
---|
2175 | if ( N == 4 ){ |
---|
2176 | // 4x4 |
---|
2177 | vlc = uiVlcTableTemp[maxrunTemp]; |
---|
2178 | if ( nTab == 2 ){ |
---|
2179 | cn = xRunLevelInd(0, 0, maxrunTemp, g_auiLumaRunTr14x4[uiTr1Temp][maxrunTemp]); |
---|
2180 | } |
---|
2181 | else{ |
---|
2182 | #if RUNLEVEL_TABLE_CUT |
---|
2183 | cn = xRunLevelIndInter(0, 0, maxrunTemp); |
---|
2184 | #else |
---|
2185 | cn = g_auiLumaRun8x8[maxrunTemp][0][0]; |
---|
2186 | #endif |
---|
2187 | } |
---|
2188 | } |
---|
2189 | else{ |
---|
2190 | // 8x8 |
---|
2191 | vlc = uiVlcTableTemp[Min(maxrunTemp,28)]; |
---|
2192 | if(nTab == 2 || nTab == 5){ |
---|
2193 | cn = xRunLevelInd(0, 0, maxrunTemp, g_auiLumaRunTr18x8[uiTr1Temp][Min(maxrunTemp,28)]); |
---|
2194 | } |
---|
2195 | else{ |
---|
2196 | #if RUNLEVEL_TABLE_CUT |
---|
2197 | cn = xRunLevelIndInter(0, 0, maxrunTemp); |
---|
2198 | #else |
---|
2199 | cn = g_auiLumaRun8x8[Min(maxrunTemp,28)][0][0]; |
---|
2200 | #endif |
---|
2201 | } |
---|
2202 | } |
---|
2203 | #endif |
---|
2204 | bits -= xCountVlcBits( vlc, cn ); |
---|
2205 | } |
---|
2206 | } // if ( pos > 0 && uiModZeroCoding == 1 ){ |
---|
2207 | |
---|
2208 | } |
---|
2209 | } |
---|
2210 | } |
---|
2211 | return bits; |
---|
2212 | } |
---|
2213 | |
---|
2214 | Int TComTrQuant::xCodeCoeffCountBitsLast(TCoeff* scoeff, levelDataStruct* levelData, Int nTab, UInt N) |
---|
2215 | { |
---|
2216 | Int i, prevCoeffInd, lastPosMin, iRate; |
---|
2217 | Int done,last_pos; |
---|
2218 | #if CAVLC_COEF_LRG_BLK |
---|
2219 | Int run_done, maxrun,run, bitsLast[1024], bitsRun[1024], bitsLastPrev; |
---|
2220 | quantLevelStruct quantCoeffInfo[1024]; |
---|
2221 | #else |
---|
2222 | Int run_done, maxrun,run, bitsLast[256], bitsRun[256], bitsLastPrev; |
---|
2223 | quantLevelStruct quantCoeffInfo[256]; |
---|
2224 | #endif |
---|
2225 | UInt last_pos_init, bitsLevel, sign, lev, cn, vlc, uiBitShift=15, uiNoCoeff=N*N, absLevel; |
---|
2226 | Int n; |
---|
2227 | double lagrMin, lagr, lagrPrev; |
---|
2228 | UInt uiLumaRunNoTr14x4[15]={2, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2}; |
---|
2229 | UInt uiLumaRunNoTr18x8[29]={2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 13}; |
---|
2230 | |
---|
2231 | |
---|
2232 | if ( N == 4 ){ |
---|
2233 | n = Max(0, nTab - 2); |
---|
2234 | } |
---|
2235 | else |
---|
2236 | { |
---|
2237 | n = nTab; |
---|
2238 | } |
---|
2239 | |
---|
2240 | /* Do the last coefficient first */ |
---|
2241 | i = uiNoCoeff - 1; |
---|
2242 | done = 0; |
---|
2243 | |
---|
2244 | while ( !done && i >= 0 ) |
---|
2245 | { |
---|
2246 | if (scoeff[i]) |
---|
2247 | { |
---|
2248 | done = 1; |
---|
2249 | } |
---|
2250 | else |
---|
2251 | { |
---|
2252 | i--; |
---|
2253 | } |
---|
2254 | } |
---|
2255 | if (i == -1) |
---|
2256 | { |
---|
2257 | return(-1); |
---|
2258 | } |
---|
2259 | |
---|
2260 | last_pos = last_pos_init = i; |
---|
2261 | prevCoeffInd = i; |
---|
2262 | |
---|
2263 | i--; |
---|
2264 | |
---|
2265 | if ( i >= 0 ){ |
---|
2266 | |
---|
2267 | /* Go into run mode */ |
---|
2268 | run_done = 0; |
---|
2269 | while ( !run_done ) |
---|
2270 | { |
---|
2271 | maxrun = i; |
---|
2272 | |
---|
2273 | run = 0; |
---|
2274 | done = 0; |
---|
2275 | while ( !done ) |
---|
2276 | { |
---|
2277 | if ( !scoeff[i] ) |
---|
2278 | { |
---|
2279 | run++; |
---|
2280 | } |
---|
2281 | else |
---|
2282 | { |
---|
2283 | quantCoeffInfo[prevCoeffInd].run=run; |
---|
2284 | quantCoeffInfo[prevCoeffInd].maxrun=maxrun; |
---|
2285 | quantCoeffInfo[prevCoeffInd].nextLev=(abs(scoeff[i]) == 1) ? 0 : 1; |
---|
2286 | quantCoeffInfo[prevCoeffInd].nexLevelVal=scoeff[i]; |
---|
2287 | |
---|
2288 | prevCoeffInd = i; |
---|
2289 | |
---|
2290 | run = 0; |
---|
2291 | done = 1; |
---|
2292 | } |
---|
2293 | if (i == 0) |
---|
2294 | { |
---|
2295 | quantCoeffInfo[prevCoeffInd].run=run; |
---|
2296 | quantCoeffInfo[prevCoeffInd].maxrun=maxrun; |
---|
2297 | quantCoeffInfo[prevCoeffInd].nextLev=0; |
---|
2298 | quantCoeffInfo[prevCoeffInd].nexLevelVal=0; |
---|
2299 | |
---|
2300 | done = 1; |
---|
2301 | run_done = 1; |
---|
2302 | } |
---|
2303 | i--; |
---|
2304 | } |
---|
2305 | } |
---|
2306 | } |
---|
2307 | |
---|
2308 | #if CAVLC_COEF_LRG_BLK |
---|
2309 | const UInt *vlcTableIntra = (N<=8)? g_auiVlcTable8x8Intra:g_auiVlcTable16x16Intra; |
---|
2310 | const UInt *vlcTableInter = (N<=8)? g_auiVlcTable8x8Inter:g_auiVlcTable16x16Inter; |
---|
2311 | const UInt *pLumaRunTr1 = (N==4)? uiLumaRunNoTr14x4:uiLumaRunNoTr18x8; |
---|
2312 | #endif |
---|
2313 | for (i = last_pos_init; i >= 0; i--){ |
---|
2314 | |
---|
2315 | if (scoeff[i]){ |
---|
2316 | |
---|
2317 | bitsLast[i] = bitsRun[i] = 0; |
---|
2318 | |
---|
2319 | last_pos = i; |
---|
2320 | { |
---|
2321 | int x,cx,vlcNum; |
---|
2322 | int vlcTable[3] = {2,2,2}; |
---|
2323 | |
---|
2324 | bitsLevel=0; |
---|
2325 | absLevel = abs(scoeff[i]); |
---|
2326 | sign = (scoeff[i] < 0) ? 1 : 0; |
---|
2327 | lev = (absLevel == 1) ? 0 : 1; |
---|
2328 | |
---|
2329 | if (absLevel > 1) |
---|
2330 | { |
---|
2331 | bitsLevel=xCountVlcBits( 0, 2*(absLevel-2)+sign ); |
---|
2332 | } |
---|
2333 | else |
---|
2334 | { |
---|
2335 | bitsLevel++; |
---|
2336 | } |
---|
2337 | |
---|
2338 | x = uiNoCoeff*lev + last_pos; |
---|
2339 | |
---|
2340 | if ( uiNoCoeff == 16 ){ |
---|
2341 | cx = m_uiLPTableE4[n * 32 + x]; |
---|
2342 | vlcNum = vlcTable[n]; |
---|
2343 | } |
---|
2344 | else { |
---|
2345 | #if CAVLC_COEF_LRG_BLK |
---|
2346 | cx = xLastLevelInd(lev, last_pos, N); |
---|
2347 | #else |
---|
2348 | cx = m_uiLPTableE8[n * 128 + x]; |
---|
2349 | #endif |
---|
2350 | vlcNum = g_auiLastPosVlcNum[n][Min(16,m_uiLastPosVlcIndex[n])]; |
---|
2351 | } |
---|
2352 | bitsLast[i]=bitsLevel + xCountVlcBits( vlcNum, cx); |
---|
2353 | } |
---|
2354 | |
---|
2355 | bitsRun[i]=0; |
---|
2356 | |
---|
2357 | if ( i > 0 ) |
---|
2358 | { |
---|
2359 | bitsLevel = 0; |
---|
2360 | if ( quantCoeffInfo[i].nexLevelVal != 0 ){ |
---|
2361 | absLevel = abs(quantCoeffInfo[i].nexLevelVal); |
---|
2362 | sign = (quantCoeffInfo[i].nexLevelVal < 0) ? 1 : 0; |
---|
2363 | lev = (absLevel == 1) ? 0 : 1; |
---|
2364 | |
---|
2365 | if (absLevel > 1) |
---|
2366 | { |
---|
2367 | bitsLevel = xCountVlcBits( 0, 2 * (absLevel - 2) + sign ); |
---|
2368 | } |
---|
2369 | else |
---|
2370 | { |
---|
2371 | bitsLevel++; |
---|
2372 | } |
---|
2373 | } |
---|
2374 | |
---|
2375 | bitsRun[i] = bitsLevel; |
---|
2376 | run = quantCoeffInfo[i].run; |
---|
2377 | maxrun = quantCoeffInfo[i].maxrun; |
---|
2378 | |
---|
2379 | #if CAVLC_COEF_LRG_BLK |
---|
2380 | Int tmprun = Min(maxrun,28); |
---|
2381 | if(nTab == 2 || nTab == 5) |
---|
2382 | { |
---|
2383 | vlc = vlcTableIntra[tmprun]; |
---|
2384 | cn = xRunLevelInd(quantCoeffInfo[i].nextLev, run, maxrun, pLumaRunTr1[tmprun]); |
---|
2385 | } |
---|
2386 | else |
---|
2387 | { |
---|
2388 | vlc = vlcTableInter[tmprun]; |
---|
2389 | cn = xRunLevelIndInter(quantCoeffInfo[i].nextLev, run, maxrun); |
---|
2390 | } |
---|
2391 | bitsRun[i] += xCountVlcBits( vlc, cn ); |
---|
2392 | #else |
---|
2393 | if ( uiNoCoeff == 16 ) |
---|
2394 | { |
---|
2395 | if ( nTab == 2 ){ |
---|
2396 | vlc = g_auiVlcTable8x8Intra[maxrun]; |
---|
2397 | cn = xRunLevelInd(quantCoeffInfo[i].nextLev, run, maxrun, uiLumaRunNoTr14x4[maxrun]); |
---|
2398 | } |
---|
2399 | else{ |
---|
2400 | vlc = g_auiVlcTable8x8Inter[maxrun]; |
---|
2401 | #if RUNLEVEL_TABLE_CUT |
---|
2402 | cn = xRunLevelIndInter(quantCoeffInfo[i].nextLev, run, maxrun); |
---|
2403 | #else |
---|
2404 | cn = g_auiLumaRun8x8[maxrun][quantCoeffInfo[i].nextLev][run]; |
---|
2405 | #endif |
---|
2406 | } |
---|
2407 | bitsRun[i] += xCountVlcBits( vlc, cn ); |
---|
2408 | } |
---|
2409 | else |
---|
2410 | { |
---|
2411 | if(nTab == 2 || nTab == 5){ |
---|
2412 | vlc = g_auiVlcTable8x8Intra[Min(maxrun,28)]; |
---|
2413 | cn = xRunLevelInd(quantCoeffInfo[i].nextLev, run, maxrun, uiLumaRunNoTr18x8[min(maxrun,28)]); |
---|
2414 | } |
---|
2415 | else{ |
---|
2416 | vlc = g_auiVlcTable8x8Inter[Min(maxrun,28)]; |
---|
2417 | #if RUNLEVEL_TABLE_CUT |
---|
2418 | cn = xRunLevelIndInter(quantCoeffInfo[i].nextLev, run, maxrun); |
---|
2419 | #else |
---|
2420 | cn = g_auiLumaRun8x8[min(maxrun,28)][quantCoeffInfo[i].nextLev][run]; |
---|
2421 | #endif |
---|
2422 | } |
---|
2423 | bitsRun[i] += xCountVlcBits( vlc, cn ); |
---|
2424 | } |
---|
2425 | #endif |
---|
2426 | } |
---|
2427 | } |
---|
2428 | } |
---|
2429 | |
---|
2430 | lagrMin=0; lastPosMin=-1; |
---|
2431 | for (i=0; i<uiNoCoeff; i++){ |
---|
2432 | if ( scoeff[i] != 0 ){ |
---|
2433 | lagrMin += levelData[i].errLevel[0]; |
---|
2434 | } |
---|
2435 | } |
---|
2436 | |
---|
2437 | UInt first=1; |
---|
2438 | |
---|
2439 | bitsLastPrev=0; lagrPrev=lagrMin; |
---|
2440 | for (i=0; i<uiNoCoeff; i++){ |
---|
2441 | if (scoeff[i]){ |
---|
2442 | iRate = (bitsRun[i] + bitsLast[i] - bitsLastPrev) << uiBitShift; |
---|
2443 | lagr = lagrPrev-levelData[i].errLevel[0] + levelData[i].errLevel[levelData[i].quantInd] + m_dLambda*iRate; |
---|
2444 | bitsLastPrev = bitsLast[i]; |
---|
2445 | lagrPrev = lagr; |
---|
2446 | |
---|
2447 | if ( lagr < lagrMin || abs(scoeff[i]) > 1 || first == 1){ |
---|
2448 | lagrMin = lagr; |
---|
2449 | lastPosMin =i; |
---|
2450 | first = 0; |
---|
2451 | } |
---|
2452 | } |
---|
2453 | } |
---|
2454 | |
---|
2455 | return(lastPosMin); |
---|
2456 | } |
---|
2457 | #else |
---|
2458 | #if QC_MOD_LCEC |
---|
2459 | Int TComTrQuant::bitCount_LCEC(Int k,Int pos,Int nTab, Int lpflag,Int levelMode,Int run, Int maxrun, Int vlc_adaptive, Int N, UInt uiTr1) |
---|
2460 | #else |
---|
2461 | Int TComTrQuant::bitCount_LCEC(Int k,Int pos,Int n,Int lpflag,Int levelMode,Int run,Int maxrun,Int vlc_adaptive,Int N) |
---|
2462 | #endif |
---|
2463 | { |
---|
2464 | UInt cn; |
---|
2465 | int vlc,x,cx,vlcNum,bits,temp; |
---|
2466 | #if QC_MOD_LCEC == 0 |
---|
2467 | static const int vlctable_8x8[28] = {8,0,0,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6}; |
---|
2468 | static const int vlcTable8[8] = {10,10,3,3,3,4,4,4}; // U,V,Y8x8I,Y8x8P,Y8x8B,Y16x16I,Y16x16P,Y16x16B |
---|
2469 | #endif |
---|
2470 | static const int vlcTable4[3] = {2,2,2}; // Y4x4I,Y4x4P,Y4x4B, |
---|
2471 | #if QC_MOD_LCEC == 0 |
---|
2472 | static const int VLClength[11][128] = |
---|
2473 | { |
---|
2474 | { 1, 2, 3, 4, 5, 6, 7, 9, 9,11,11,11,11,13,13,13,13,13,13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19}, |
---|
2475 | { 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8,10,10,10,10,12,12,12,12,12,12,12,12,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18}, |
---|
2476 | { 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,11,11,11,11,11,11,11,11,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17}, |
---|
2477 | { 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16}, |
---|
2478 | { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13}, |
---|
2479 | { 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,30,30,31,31,32,32,33,33,34,34,35,35,36,36,37,37,38,38,39,39,40,40,41,41,42,42,43,43,44,44,45,45,46,46,47,47,48,48,49,49,50,50,51,51,52,52,53,53,54,54,55,55,56,56,57,57,58,58,59,59,60,60,61,61,62,62,63,63,64,64,65,65}, |
---|
2480 | { 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,14,15,15,15,15,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,22,22,22,22,23,23,23,23,24,24,24,24,25,25,25,25,26,26,26,26,27,27,27,27,28,28,28,28,29,29,29,29,30,30,30,30,31,31,31,31,32,32,32,32,33,33,33,33,34,34,34,34}, |
---|
2481 | { 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19}, |
---|
2482 | { 1, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, |
---|
2483 | { 3, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13}, |
---|
2484 | { 1, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,15} |
---|
2485 | }; |
---|
2486 | #endif |
---|
2487 | int sign = k<0 ? 1 : 0; |
---|
2488 | |
---|
2489 | k = abs(k); |
---|
2490 | #if QC_MOD_LCEC |
---|
2491 | Int n; |
---|
2492 | Int lev = (k>1 ? 1 : 0); |
---|
2493 | if (N==4) |
---|
2494 | n=max(0,nTab-2); |
---|
2495 | else |
---|
2496 | n=nTab; |
---|
2497 | #endif |
---|
2498 | if (N != 4 && N!= 8) |
---|
2499 | { |
---|
2500 | FATAL_ERROR_0("unsupported block size in bitCount_LCEC()" , -1 ); |
---|
2501 | } |
---|
2502 | if (k) |
---|
2503 | { |
---|
2504 | if (lpflag==1) |
---|
2505 | { |
---|
2506 | x = pos + (k==1 ? 0 : N*N); |
---|
2507 | if (N==8) |
---|
2508 | { |
---|
2509 | cx = m_uiLPTableE8[n*128+x]; |
---|
2510 | #if QC_MOD_LCEC |
---|
2511 | vlcNum = g_auiLastPosVlcNum[n][Min(16,m_uiLastPosVlcIndex[n])]; |
---|
2512 | #else |
---|
2513 | vlcNum = vlcTable8[n]; |
---|
2514 | #endif |
---|
2515 | } |
---|
2516 | else // (N==4) |
---|
2517 | { |
---|
2518 | cx = m_uiLPTableE4[n*32+x]; |
---|
2519 | vlcNum = vlcTable4[n]; |
---|
2520 | } |
---|
2521 | bits = VLClength[vlcNum][cx]; |
---|
2522 | if (k>1) |
---|
2523 | { |
---|
2524 | temp = 2*(k-2)+sign; |
---|
2525 | if(temp > 127) |
---|
2526 | temp = 127; |
---|
2527 | bits += VLClength[0][temp]; |
---|
2528 | } |
---|
2529 | else |
---|
2530 | bits += 1; |
---|
2531 | } |
---|
2532 | else |
---|
2533 | { |
---|
2534 | if (!levelMode) |
---|
2535 | { |
---|
2536 | #if QC_MOD_LCEC |
---|
2537 | const UInt *p_auiLumaRunTr1 = g_auiLumaRunTr14x4[uiTr1]; |
---|
2538 | UInt ui_maxrun = maxrun; |
---|
2539 | if (N==8) |
---|
2540 | { |
---|
2541 | p_auiLumaRunTr1 = g_auiLumaRunTr18x8[uiTr1]; |
---|
2542 | ui_maxrun =min(maxrun,28); |
---|
2543 | } |
---|
2544 | if(nTab == 2 || nTab == 5) |
---|
2545 | { |
---|
2546 | cn = xRunLevelInd(lev, run, maxrun, p_auiLumaRunTr1[ui_maxrun]); |
---|
2547 | vlc = g_auiVlcTable8x8Intra[ui_maxrun]; |
---|
2548 | } |
---|
2549 | else |
---|
2550 | { |
---|
2551 | cn = g_auiLumaRun8x8[ui_maxrun][lev][run]; |
---|
2552 | vlc = g_auiVlcTable8x8Inter[ui_maxrun]; |
---|
2553 | } |
---|
2554 | #else |
---|
2555 | if (maxrun > 27) |
---|
2556 | { |
---|
2557 | cn = g_auiLumaRun8x8[28][k>1 ? 1 : 0][run]; |
---|
2558 | } |
---|
2559 | else |
---|
2560 | { |
---|
2561 | cn = g_auiLumaRun8x8[maxrun][k>1 ? 1 : 0][run]; |
---|
2562 | } |
---|
2563 | vlc = (maxrun>27) ? 3 : vlctable_8x8[maxrun]; |
---|
2564 | #endif |
---|
2565 | bits = VLClength[vlc][cn]; |
---|
2566 | if (k>1) |
---|
2567 | { |
---|
2568 | temp = 2*(k-2)+sign; |
---|
2569 | if(temp > 127) |
---|
2570 | temp = 127; |
---|
2571 | bits += VLClength[0][temp]; |
---|
2572 | } |
---|
2573 | else |
---|
2574 | bits += 1; |
---|
2575 | |
---|
2576 | } |
---|
2577 | else |
---|
2578 | { |
---|
2579 | if(k > 127) |
---|
2580 | k = 127; |
---|
2581 | bits = VLClength[vlc_adaptive][k] + 1; |
---|
2582 | } |
---|
2583 | } |
---|
2584 | } |
---|
2585 | else |
---|
2586 | { |
---|
2587 | if (levelMode) |
---|
2588 | bits = VLClength[vlc_adaptive][k]; |
---|
2589 | else |
---|
2590 | { |
---|
2591 | if (pos==0 && lpflag==0) |
---|
2592 | { |
---|
2593 | #if QC_MOD_LCEC |
---|
2594 | const UInt *p_auiLumaRunTr1 = g_auiLumaRunTr14x4[uiTr1]; |
---|
2595 | UInt ui_maxrun = maxrun; |
---|
2596 | if (N==8) |
---|
2597 | { |
---|
2598 | p_auiLumaRunTr1 = g_auiLumaRunTr18x8[uiTr1]; |
---|
2599 | ui_maxrun =min(maxrun,28); |
---|
2600 | } |
---|
2601 | if(nTab == 2 || nTab == 5) |
---|
2602 | { |
---|
2603 | cn = xRunLevelInd(0, run+1, maxrun, p_auiLumaRunTr1[ui_maxrun]); |
---|
2604 | vlc = g_auiVlcTable8x8Intra[ui_maxrun]; |
---|
2605 | } |
---|
2606 | else |
---|
2607 | { |
---|
2608 | cn = g_auiLumaRun8x8[ui_maxrun][0][run+1]; |
---|
2609 | vlc = g_auiVlcTable8x8Inter[ui_maxrun]; |
---|
2610 | } |
---|
2611 | #else |
---|
2612 | if (maxrun > 27) |
---|
2613 | { |
---|
2614 | cn = g_auiLumaRun8x8[28][0][run+1]; |
---|
2615 | } |
---|
2616 | else |
---|
2617 | { |
---|
2618 | cn = g_auiLumaRun8x8[maxrun][0][run+1]; |
---|
2619 | } |
---|
2620 | vlc = (maxrun>27) ? 3 : vlctable_8x8[maxrun]; |
---|
2621 | #endif |
---|
2622 | bits = VLClength[vlc][cn]; |
---|
2623 | } |
---|
2624 | else |
---|
2625 | bits = 0; |
---|
2626 | } |
---|
2627 | } |
---|
2628 | return bits; |
---|
2629 | } |
---|
2630 | #endif |
---|
2631 | #if QC_MOD_LCEC_RDOQ |
---|
2632 | static levelDataStruct slevelData [ MAX_CU_SIZE*MAX_CU_SIZE ]; |
---|
2633 | Void TComTrQuant::xRateDistOptQuant_LCEC(TComDataCU* pcCU, Long* pSrcCoeff, TCoeff*& pDstCoeff, UInt uiWidth, UInt uiHeight, UInt& uiAbsSum, TextType eTType, |
---|
2634 | UInt uiAbsPartIdx ) |
---|
2635 | { |
---|
2636 | Int i, j; |
---|
2637 | Int iShift = 0; |
---|
2638 | Int qp_rem, q_bits; |
---|
2639 | Double err, lagr, lagrMin; |
---|
2640 | Double normFact = 0.0; |
---|
2641 | Double OneOverNormFact = 0.0; |
---|
2642 | Double fTemp = 0.0; |
---|
2643 | Int iQuantCoeff; |
---|
2644 | |
---|
2645 | #if E243_CORE_TRANSFORMS |
---|
2646 | Int iShiftQBits, iSign, iRate, lastPosMin, iBlockType; |
---|
2647 | UInt uiBitShift = SCALE_BITS, uiScanPos, levelInd; |
---|
2648 | Int levelBest, iLevel; |
---|
2649 | #else |
---|
2650 | Bool bExt8x8Flag = false; |
---|
2651 | Int iShiftQBits, iSign, iRate, lastPosMin, iBlockType; |
---|
2652 | UInt uiBitShift = 15, uiScanPos, levelInd; |
---|
2653 | Int levelBest, iLevel, iAdd; |
---|
2654 | #endif |
---|
2655 | |
---|
2656 | levelDataStruct* levelData = &slevelData[0]; |
---|
2657 | |
---|
2658 | Int iPos, iScanning; |
---|
2659 | |
---|
2660 | #if CAVLC_COEF_LRG_BLK |
---|
2661 | static TCoeff sQuantCoeff[1024]; |
---|
2662 | #else |
---|
2663 | static TCoeff sQuantCoeff[256]; |
---|
2664 | #endif |
---|
2665 | |
---|
2666 | qp_rem = m_cQP.m_iRem; |
---|
2667 | q_bits = m_cQP.m_iBits; |
---|
2668 | |
---|
2669 | UInt noCoeff=(uiWidth < 8 ? 16 : 64); |
---|
2670 | #if CAVLC_COEF_LRG_BLK |
---|
2671 | UInt maxBlSize = (eTType==TEXT_LUMA)? 32:8; |
---|
2672 | UInt uiBlSize = Min(uiWidth,maxBlSize); |
---|
2673 | noCoeff = uiBlSize*uiBlSize; |
---|
2674 | #endif |
---|
2675 | |
---|
2676 | #if E243_CORE_TRANSFORMS |
---|
2677 | UInt uiLog2TrSize = g_aucConvertToBit[ uiWidth ] + 2; |
---|
2678 | UInt uiQ = g_auiQ[m_cQP.rem()]; |
---|
2679 | |
---|
2680 | #if FULL_NBIT |
---|
2681 | UInt uiBitDepth = g_uiBitDepth; |
---|
2682 | #else |
---|
2683 | UInt uiBitDepth = g_uiBitDepth + g_uiBitIncrement; |
---|
2684 | #endif |
---|
2685 | Int iTransformShift = MAX_TR_DYNAMIC_RANGE - uiBitDepth - uiLog2TrSize; // Represents scaling through forward transform |
---|
2686 | double dErrScale = (double)(1<<uiBitShift); // Compensate for scaling of bitcount in Lagrange cost function |
---|
2687 | dErrScale = dErrScale*pow(2.0,-2.0*iTransformShift); // Compensate for scaling through forward transform |
---|
2688 | dErrScale = dErrScale/(double)(uiQ*uiQ); // Compensate for qp-dependent multiplier applied before calculating the Lagrange cost function |
---|
2689 | dErrScale = dErrScale/(double)(1<<(2*g_uiBitIncrement)); // Compensate for Lagrange multiplier that is tuned towards 8-bit input |
---|
2690 | |
---|
2691 | q_bits = QUANT_SHIFT + m_cQP.m_iPer + iTransformShift; // Right shift of non-RDOQ quantizer; level = (coeff*uiQ + offset)>>q_bits |
---|
2692 | |
---|
2693 | iShift = uiLog2TrSize; |
---|
2694 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
2695 | { |
---|
2696 | iBlockType = eTType-2; |
---|
2697 | } |
---|
2698 | else |
---|
2699 | { |
---|
2700 | iBlockType = (uiWidth < 16 ? 2 : 5) + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
2701 | } |
---|
2702 | #else |
---|
2703 | if ( uiWidth == 4 && uiHeight == 4 ) |
---|
2704 | { |
---|
2705 | normFact = pow(2., (2 * DQ_BITS + 19)); |
---|
2706 | if ( g_uiBitIncrement ) normFact *= 1 << (2 * g_uiBitIncrement); |
---|
2707 | m_puiQuantMtx = &g_aiQuantCoef [m_cQP.m_iRem][0]; |
---|
2708 | iShift = 2; |
---|
2709 | iAdd = m_cQP.m_iAdd4x4; |
---|
2710 | |
---|
2711 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
2712 | iBlockType = eTType-2; |
---|
2713 | else |
---|
2714 | iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
2715 | } |
---|
2716 | else |
---|
2717 | if ( uiWidth == 8 && uiHeight == 8 ) |
---|
2718 | { |
---|
2719 | q_bits++; |
---|
2720 | normFact = pow(2., (2 * Q_BITS_8 + 9)); |
---|
2721 | if ( g_uiBitIncrement ) normFact *= 1<<(2*g_uiBitIncrement); |
---|
2722 | m_puiQuantMtx = &g_aiQuantCoef64[m_cQP.m_iRem][0]; |
---|
2723 | iShift = 3; |
---|
2724 | iAdd = m_cQP.m_iAdd8x8; |
---|
2725 | |
---|
2726 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
2727 | iBlockType = eTType-2; |
---|
2728 | else |
---|
2729 | iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
2730 | } |
---|
2731 | else |
---|
2732 | if ( uiWidth == 16 && uiHeight == 16 ) |
---|
2733 | { |
---|
2734 | q_bits = ECore16Shift + m_cQP.per(); |
---|
2735 | normFact = pow(2., 21); |
---|
2736 | if ( g_uiBitIncrement ) normFact *= 1 << (2 * g_uiBitIncrement); |
---|
2737 | fTemp = estErr16x16[qp_rem] / normFact; |
---|
2738 | |
---|
2739 | m_puiQuantMtx = ( &g_aiQuantCoef256[m_cQP.m_iRem][0] ); |
---|
2740 | iShift = 4; |
---|
2741 | iAdd = m_cQP.m_iAdd16x16; |
---|
2742 | bExt8x8Flag = true; |
---|
2743 | |
---|
2744 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
2745 | iBlockType = eTType-2; |
---|
2746 | else |
---|
2747 | iBlockType = 5 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
2748 | } |
---|
2749 | else |
---|
2750 | if ( uiWidth == 32 && uiHeight == 32 ) |
---|
2751 | { |
---|
2752 | q_bits = ECore32Shift + m_cQP.per(); |
---|
2753 | normFact = pow(2., 21); |
---|
2754 | if ( g_uiBitIncrement ) normFact *= 1<<(2*g_uiBitIncrement); |
---|
2755 | fTemp = estErr32x32[qp_rem]/normFact; |
---|
2756 | |
---|
2757 | m_puiQuantMtx = ( &g_aiQuantCoef1024[m_cQP.m_iRem][0] ); |
---|
2758 | iShift = 5; |
---|
2759 | iAdd = m_cQP.m_iAdd32x32; |
---|
2760 | bExt8x8Flag = true; |
---|
2761 | |
---|
2762 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
2763 | iBlockType = eTType-2; |
---|
2764 | else |
---|
2765 | iBlockType = 5 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
2766 | } |
---|
2767 | else |
---|
2768 | { |
---|
2769 | iBlockType =0; |
---|
2770 | |
---|
2771 | assert(0); |
---|
2772 | } |
---|
2773 | #endif //E243_CORE_TRANSFORMS |
---|
2774 | memset(&pDstCoeff[0],0,uiWidth*uiHeight*sizeof(TCoeff)); |
---|
2775 | |
---|
2776 | iShiftQBits = (1 <<( q_bits - 1)); |
---|
2777 | |
---|
2778 | |
---|
2779 | #if QC_MDCS |
---|
2780 | #if CAVLC_COEF_LRG_BLK |
---|
2781 | UInt uiLog2BlkSize = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : uiBlSize ] + 2; |
---|
2782 | #else |
---|
2783 | UInt uiLog2BlkSize = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : Min(8,uiWidth) ] + 2; |
---|
2784 | #endif |
---|
2785 | const UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
2786 | #else |
---|
2787 | const UInt* pucScan; |
---|
2788 | if( !pcCU->isIntra(uiAbsPartIdx )){ |
---|
2789 | #if CAVLC_COEF_LRG_BLK |
---|
2790 | pucScan = g_auiFrameScanXY[ g_aucConvertToBit[ uiBlSize ] + 1]; |
---|
2791 | #else |
---|
2792 | pucScan = g_auiFrameScanXY[ g_aucConvertToBit[ Min(uiWidth, 8) ] + 1]; |
---|
2793 | #endif |
---|
2794 | } |
---|
2795 | else{ |
---|
2796 | pucScan = g_auiFrameScanXY[ g_aucConvertToBit[ uiWidth ] + 1]; |
---|
2797 | } |
---|
2798 | #endif //QC_MDCS |
---|
2799 | |
---|
2800 | |
---|
2801 | |
---|
2802 | OneOverNormFact = 1.0 / normFact; |
---|
2803 | |
---|
2804 | UInt uiShift_local = iShift; |
---|
2805 | UInt uiRes_local = (uiWidth - 1); |
---|
2806 | UInt uiWidth_local = uiShift_local; |
---|
2807 | |
---|
2808 | #if CAVLC_COEF_LRG_BLK |
---|
2809 | if(!pcCU->isIntra(uiAbsPartIdx) && uiWidth > maxBlSize) |
---|
2810 | { |
---|
2811 | uiShift_local = g_aucConvertToBit[ maxBlSize ] + 2;; |
---|
2812 | uiRes_local = maxBlSize - 1; |
---|
2813 | } |
---|
2814 | #else |
---|
2815 | if( !pcCU->isIntra(uiAbsPartIdx) && uiWidth >= 16 ) |
---|
2816 | { |
---|
2817 | uiShift_local = 3; |
---|
2818 | uiRes_local = 7; |
---|
2819 | } |
---|
2820 | #endif |
---|
2821 | |
---|
2822 | Int iAddRDOQ = 0; |
---|
2823 | #if E243_CORE_TRANSFORMS |
---|
2824 | /* Code below is consistent with JCTVC-E243 but could preferably be replaced with iAddRDOQ = 171 << (q_bits-9); */ |
---|
2825 | if (q_bits>=15) |
---|
2826 | { |
---|
2827 | iAddRDOQ = (uiWidth<16 ? 10922 : 10880) << (q_bits-15); |
---|
2828 | } |
---|
2829 | else |
---|
2830 | { |
---|
2831 | iAddRDOQ = (uiWidth<16 ? 10922 : 10880) >> (15-q_bits); |
---|
2832 | } |
---|
2833 | #else |
---|
2834 | { |
---|
2835 | UInt uiSliceType = 0; |
---|
2836 | |
---|
2837 | Int iQP=pcCU->getSlice()->getSliceQp(); |
---|
2838 | if( eTType != TEXT_LUMA ) //Chroma |
---|
2839 | { |
---|
2840 | iQP = g_aucChromaScale[ iQP ]; |
---|
2841 | } |
---|
2842 | |
---|
2843 | Int iDefaultOffset; |
---|
2844 | Int iDefaultOffset_LTR; |
---|
2845 | Int iPer; |
---|
2846 | Int k = (iQP + 6 * g_uiBitIncrement) / 6; |
---|
2847 | #if FULL_NBIT |
---|
2848 | k += g_uiBitDepth - 8; |
---|
2849 | #endif |
---|
2850 | Bool bLowPass = (uiSliceType == 0); |
---|
2851 | iDefaultOffset = (bLowPass ? 10922 : 5462); |
---|
2852 | |
---|
2853 | bLowPass = (uiSliceType == 0); |
---|
2854 | iDefaultOffset_LTR = (bLowPass? 170 : 86); |
---|
2855 | |
---|
2856 | if ( uiWidth == 4 && uiWidth == 4 ){ |
---|
2857 | iPer = QP_BITS + k - QOFFSET_BITS; |
---|
2858 | iAddRDOQ = iDefaultOffset << iPer; |
---|
2859 | } |
---|
2860 | else if ( uiWidth == 8 && uiWidth == 8){ |
---|
2861 | iPer = QP_BITS + k + 1 - QOFFSET_BITS; |
---|
2862 | iAddRDOQ = iDefaultOffset << iPer; |
---|
2863 | } |
---|
2864 | else if ( uiWidth == 16 && uiHeight == 16 ){ |
---|
2865 | iPer = ECore16Shift + k - QOFFSET_BITS_LTR; |
---|
2866 | iAddRDOQ = iDefaultOffset_LTR << iPer; |
---|
2867 | } |
---|
2868 | else if ( uiWidth == 32 && uiHeight == 32 ){ |
---|
2869 | iPer = ECore32Shift + k - QOFFSET_BITS_LTR; |
---|
2870 | iAddRDOQ = iDefaultOffset_LTR << iPer; |
---|
2871 | } |
---|
2872 | } |
---|
2873 | #endif |
---|
2874 | if (m_uiRDOQOffset==1) |
---|
2875 | iAddRDOQ=iShiftQBits; |
---|
2876 | |
---|
2877 | for (iScanning=noCoeff-1; iScanning>=0; iScanning--) |
---|
2878 | { |
---|
2879 | #if QC_MDCS |
---|
2880 | iPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][iScanning]; |
---|
2881 | #else |
---|
2882 | iPos = pucScan[iScanning]; |
---|
2883 | #endif //QC_MDCS |
---|
2884 | j = iPos >> uiShift_local; |
---|
2885 | i = iPos & uiRes_local; |
---|
2886 | iPos = (j << uiWidth_local) + i; |
---|
2887 | |
---|
2888 | levelDataStruct *psLevelData = &levelData[iScanning]; |
---|
2889 | #if E243_CORE_TRANSFORMS |
---|
2890 | psLevelData->levelDouble = abs(pSrcCoeff[iPos]) * uiQ; |
---|
2891 | iQuantCoeff = (Int)((psLevelData->levelDouble + iAddRDOQ) >> q_bits); |
---|
2892 | |
---|
2893 | psLevelData->levelQ = (Long)( psLevelData->levelDouble >> q_bits ); |
---|
2894 | psLevelData->lowerInt = ( ( psLevelData->levelDouble - (psLevelData->levelQ << q_bits) ) < iShiftQBits ) ? true : false; |
---|
2895 | |
---|
2896 | iSign = pSrcCoeff[iPos] < 0 ? -1 : 1; |
---|
2897 | sQuantCoeff[iScanning] = iQuantCoeff*iSign; |
---|
2898 | |
---|
2899 | fTemp = dErrScale; |
---|
2900 | #else |
---|
2901 | psLevelData->levelDouble = abs( pSrcCoeff[iPos] * (Long) m_puiQuantMtx[iPos]); |
---|
2902 | iQuantCoeff=(Int)((psLevelData->levelDouble +iAddRDOQ) >> q_bits); |
---|
2903 | |
---|
2904 | psLevelData->levelQ = ( psLevelData->levelDouble >> q_bits ); |
---|
2905 | psLevelData->lowerInt = ( ( psLevelData->levelDouble - (psLevelData->levelQ << q_bits) ) < iShiftQBits ) ? true : false; |
---|
2906 | |
---|
2907 | iSign = pSrcCoeff[iPos] < 0 ? -1 : 1; |
---|
2908 | sQuantCoeff[iScanning] = iQuantCoeff*iSign; |
---|
2909 | |
---|
2910 | if ( uiWidth == 4 ) fTemp = estErr4x4[qp_rem][i][j] * OneOverNormFact; |
---|
2911 | else if ( uiWidth == 8 ) fTemp = estErr8x8[qp_rem][i][j] * OneOverNormFact; |
---|
2912 | #endif |
---|
2913 | psLevelData->level[0] = 0; |
---|
2914 | err = (Double)(psLevelData->levelDouble); |
---|
2915 | psLevelData->errLevel[0] = err * err * fTemp; |
---|
2916 | |
---|
2917 | if ( !psLevelData->levelQ ) |
---|
2918 | { |
---|
2919 | if ( psLevelData->lowerInt ) |
---|
2920 | { |
---|
2921 | psLevelData->noLevels = 1; |
---|
2922 | } |
---|
2923 | else |
---|
2924 | { |
---|
2925 | psLevelData->level[1] = 1; |
---|
2926 | psLevelData->noLevels = 2; |
---|
2927 | } |
---|
2928 | if (iQuantCoeff==0) |
---|
2929 | psLevelData->quantInd=0; |
---|
2930 | else |
---|
2931 | psLevelData->quantInd=1; |
---|
2932 | |
---|
2933 | } |
---|
2934 | else if ( psLevelData->lowerInt ) |
---|
2935 | { |
---|
2936 | psLevelData->level[1] = psLevelData->levelQ; |
---|
2937 | psLevelData->noLevels = 2; |
---|
2938 | |
---|
2939 | if ( psLevelData->levelQ > 1 ){ |
---|
2940 | psLevelData->noLevels++; |
---|
2941 | psLevelData->level[2] = 1; |
---|
2942 | } |
---|
2943 | |
---|
2944 | psLevelData->quantInd = 1; |
---|
2945 | } |
---|
2946 | else |
---|
2947 | { |
---|
2948 | psLevelData->level[1] = psLevelData->levelQ; |
---|
2949 | psLevelData->level[2] = psLevelData->levelQ + 1; |
---|
2950 | psLevelData->noLevels = 3; |
---|
2951 | |
---|
2952 | if ( psLevelData->levelQ > 1 ){ |
---|
2953 | psLevelData->noLevels++; |
---|
2954 | psLevelData->level[3] = 1; |
---|
2955 | } |
---|
2956 | if ( iQuantCoeff == psLevelData->level[1] ) |
---|
2957 | psLevelData->quantInd = 1; |
---|
2958 | else |
---|
2959 | psLevelData->quantInd = 2; |
---|
2960 | } |
---|
2961 | |
---|
2962 | for ( levelInd = 1; levelInd < psLevelData->noLevels; levelInd++ ){ |
---|
2963 | err = (Double)((psLevelData->level[levelInd] << q_bits) - psLevelData->levelDouble); |
---|
2964 | psLevelData->errLevel[levelInd] = err * err * fTemp; |
---|
2965 | psLevelData->level[levelInd] *= iSign; |
---|
2966 | } |
---|
2967 | } |
---|
2968 | |
---|
2969 | #if CAVLC_COEF_LRG_BLK==0 |
---|
2970 | UInt uiNum; |
---|
2971 | if ( uiWidth == 4 ) |
---|
2972 | uiNum = 4; |
---|
2973 | else |
---|
2974 | uiNum = 8; |
---|
2975 | #endif |
---|
2976 | |
---|
2977 | // Last Position |
---|
2978 | #if CAVLC_COEF_LRG_BLK |
---|
2979 | lastPosMin = xCodeCoeffCountBitsLast(sQuantCoeff, levelData, iBlockType, uiBlSize); |
---|
2980 | #else |
---|
2981 | lastPosMin = xCodeCoeffCountBitsLast(sQuantCoeff, levelData, iBlockType, uiNum); |
---|
2982 | #endif |
---|
2983 | memset(&sQuantCoeff[lastPosMin+1],0,sizeof(TCoeff) * (noCoeff - (lastPosMin + 1))); |
---|
2984 | |
---|
2985 | |
---|
2986 | Int iLpFlag = 1; |
---|
2987 | Int iLevelMode = 0; |
---|
2988 | Int iRun = 0; |
---|
2989 | Int iVlc_adaptive = 0; |
---|
2990 | Int iMaxrun = 0; |
---|
2991 | Int iSum_big_coef = 0; |
---|
2992 | |
---|
2993 | |
---|
2994 | UInt uiTr1=0; |
---|
2995 | UInt absBestLevel; |
---|
2996 | |
---|
2997 | Int atable[5] = {4,6,14,28,0xfffffff}; |
---|
2998 | Int switch_thr[10] = {49,49,0,49,49,0,49,49,49,49}; |
---|
2999 | |
---|
3000 | Int levelIndBest, iRateMin=0, levelStart; |
---|
3001 | Double lagrCoded=0, lagrNotCoded=0; |
---|
3002 | #if CAVLC_COEF_LRG_BLK |
---|
3003 | const UInt **pLumaRunTr1 = (uiWidth==4)? g_pLumaRunTr14x4:g_pLumaRunTr18x8; |
---|
3004 | UInt coeffBlkSize = (uiWidth==4)? 4:(noCoeff==64)? 8:(noCoeff==256)? 16:32; |
---|
3005 | #endif |
---|
3006 | |
---|
3007 | for (iScanning = lastPosMin; iScanning>=0; iScanning--){ |
---|
3008 | uiScanPos = iScanning; |
---|
3009 | levelStart = (iScanning == lastPosMin) ? 1 : 0; |
---|
3010 | |
---|
3011 | sQuantCoeff[uiScanPos] = levelBest = 0; |
---|
3012 | levelDataStruct *psLevelData = &levelData[uiScanPos]; |
---|
3013 | if ( psLevelData->noLevels >1 || iScanning == 0 ){ |
---|
3014 | |
---|
3015 | lagrMin = 0; iRateMin = 0; |
---|
3016 | for (levelInd = levelStart; levelInd < psLevelData->noLevels; levelInd++){ |
---|
3017 | |
---|
3018 | lagr = psLevelData->errLevel[levelInd]; |
---|
3019 | iLevel=psLevelData->level[levelInd]; |
---|
3020 | |
---|
3021 | #if CAVLC_COEF_LRG_BLK |
---|
3022 | iRate = bitCountRDOQ(iLevel,uiScanPos,iBlockType,iLpFlag,iLevelMode,iRun,iMaxrun,iVlc_adaptive, |
---|
3023 | coeffBlkSize,uiTr1, iSum_big_coef, iBlockType, pcCU, pLumaRunTr1)<<uiBitShift; |
---|
3024 | #else |
---|
3025 | if ( uiWidth == 4 ){ |
---|
3026 | iRate = bitCountRDOQ(iLevel,uiScanPos,iBlockType,iLpFlag,iLevelMode,iRun,iMaxrun,iVlc_adaptive,4,uiTr1, |
---|
3027 | iSum_big_coef,iBlockType, pcCU)<<uiBitShift; |
---|
3028 | } |
---|
3029 | else{ |
---|
3030 | iRate = bitCountRDOQ(iLevel,uiScanPos,iBlockType,iLpFlag,iLevelMode,iRun,iMaxrun,iVlc_adaptive,8,uiTr1, |
---|
3031 | iSum_big_coef, iBlockType, pcCU) << uiBitShift; |
---|
3032 | } |
---|
3033 | #endif |
---|
3034 | lagr += m_dLambda * iRate; |
---|
3035 | |
---|
3036 | if ( lagr < lagrMin || levelInd == levelStart){ |
---|
3037 | lagrMin = lagr; |
---|
3038 | iRateMin = iRate; |
---|
3039 | levelBest = iLevel; |
---|
3040 | levelIndBest = levelInd; |
---|
3041 | } |
---|
3042 | } |
---|
3043 | } |
---|
3044 | |
---|
3045 | if ( levelBest != 0 ){ |
---|
3046 | lagrCoded += lagrMin; |
---|
3047 | lagrNotCoded += psLevelData->errLevel[0]; |
---|
3048 | } |
---|
3049 | if ( uiScanPos == 0 && levelBest == 0 ){ |
---|
3050 | lagrCoded += m_dLambda * iRateMin; |
---|
3051 | } |
---|
3052 | |
---|
3053 | sQuantCoeff[uiScanPos] = levelBest; |
---|
3054 | |
---|
3055 | absBestLevel = abs(levelBest); |
---|
3056 | if ( levelBest != 0 ){ |
---|
3057 | |
---|
3058 | if ( uiWidth > 4 ){ |
---|
3059 | if ( !iLpFlag && absBestLevel > 1 ){ |
---|
3060 | iSum_big_coef += absBestLevel; |
---|
3061 | if ((noCoeff - uiScanPos - 1) > switch_thr[iBlockType] || iSum_big_coef > 2) iLevelMode = 1; |
---|
3062 | } |
---|
3063 | } |
---|
3064 | else{ |
---|
3065 | if ( absBestLevel > 1 ) iLevelMode = 1; |
---|
3066 | } |
---|
3067 | |
---|
3068 | if ( iLpFlag == 1 ) |
---|
3069 | { |
---|
3070 | uiTr1 = (absBestLevel > 1) ? 0 : 1; |
---|
3071 | } |
---|
3072 | else |
---|
3073 | { |
---|
3074 | if ( uiTr1 == 0 || absBestLevel >= 2 ) |
---|
3075 | { |
---|
3076 | uiTr1 = 0; |
---|
3077 | } |
---|
3078 | else if ( uiTr1 < MAX_TR1 ) |
---|
3079 | { |
---|
3080 | uiTr1++; |
---|
3081 | } |
---|
3082 | } |
---|
3083 | iMaxrun = iScanning - 1; |
---|
3084 | iLpFlag = 0; |
---|
3085 | iRun = 0; |
---|
3086 | if ( iLevelMode && (absBestLevel > atable[iVlc_adaptive])) iVlc_adaptive++; |
---|
3087 | } |
---|
3088 | else |
---|
3089 | { |
---|
3090 | iRun += 1; |
---|
3091 | } |
---|
3092 | } |
---|
3093 | |
---|
3094 | if (lastPosMin >= 0 && lagrCoded > lagrNotCoded){ |
---|
3095 | for (iScanning = lastPosMin; iScanning>=0; iScanning--){ |
---|
3096 | sQuantCoeff[iScanning] = 0; |
---|
3097 | } |
---|
3098 | } |
---|
3099 | |
---|
3100 | #if CAVLC_COEF_LRG_BLK |
---|
3101 | if ((!pcCU->isIntra(uiAbsPartIdx) && uiWidth > maxBlSize)) |
---|
3102 | { |
---|
3103 | for (iScanning=noCoeff-1; iScanning>=0; iScanning--) |
---|
3104 | { |
---|
3105 | #if QC_MDCS |
---|
3106 | iPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][iScanning]; |
---|
3107 | #else |
---|
3108 | iPos = pucScan[iScanning]; |
---|
3109 | #endif //QC_MDCS |
---|
3110 | j = iPos >> (g_aucConvertToBit[ maxBlSize ] + 2); |
---|
3111 | i = iPos & (maxBlSize-1); |
---|
3112 | iPos = (j<<(g_aucConvertToBit[ uiWidth ] + 2))+i; |
---|
3113 | pDstCoeff[iPos] = sQuantCoeff[iScanning]; |
---|
3114 | uiAbsSum += abs(sQuantCoeff[iScanning]); |
---|
3115 | } |
---|
3116 | } |
---|
3117 | #else |
---|
3118 | if ((!pcCU->isIntra(uiAbsPartIdx) && uiWidth >= 16)) |
---|
3119 | { |
---|
3120 | for (iScanning = noCoeff - 1; iScanning >= 0; iScanning--) |
---|
3121 | { |
---|
3122 | #if QC_MDCS |
---|
3123 | iPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][iScanning]; |
---|
3124 | #else |
---|
3125 | iPos = pucScan[iScanning]; |
---|
3126 | #endif //QC_MDCS |
---|
3127 | j = iPos >> 3; |
---|
3128 | i = iPos & 0x7; |
---|
3129 | iPos = uiWidth * j + i; |
---|
3130 | pDstCoeff[iPos] = sQuantCoeff[iScanning]; |
---|
3131 | uiAbsSum += abs(sQuantCoeff[iScanning]); |
---|
3132 | } |
---|
3133 | } |
---|
3134 | #endif |
---|
3135 | else |
---|
3136 | { |
---|
3137 | for (iScanning = noCoeff - 1; iScanning >= 0; iScanning--) |
---|
3138 | { |
---|
3139 | #if QC_MDCS |
---|
3140 | iPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][iScanning]; |
---|
3141 | #else |
---|
3142 | iPos = pucScan[iScanning]; |
---|
3143 | #endif //QC_MDCS |
---|
3144 | pDstCoeff[iPos] = sQuantCoeff[iScanning]; |
---|
3145 | uiAbsSum += abs(sQuantCoeff[iScanning]); |
---|
3146 | } |
---|
3147 | } |
---|
3148 | } |
---|
3149 | #else |
---|
3150 | Void TComTrQuant::xRateDistOptQuant_LCEC ( TComDataCU* pcCU, |
---|
3151 | Long* plSrcCoeff, |
---|
3152 | TCoeff*& piDstCoeff, |
---|
3153 | UInt uiWidth, |
---|
3154 | UInt uiHeight, |
---|
3155 | UInt& uiAbsSum, |
---|
3156 | TextType eTType, |
---|
3157 | UInt uiAbsPartIdx ) |
---|
3158 | { |
---|
3159 | Int iLpFlag,iLevelMode,iRun,iMaxrun,iVlc_adaptive,iSum_big_coef,iSign; |
---|
3160 | Int atable[5] = {4,6,14,28,0xfffffff}; |
---|
3161 | Int switch_thr[8] = {49,49,0,49,49,0,49,49}; |
---|
3162 | |
---|
3163 | const UInt* pucScan; |
---|
3164 | UInt* piQuantCoef = NULL; |
---|
3165 | UInt uiBlkPos,uiPosY,uiPosX,uiLog2BlkSize,uiConvBit,uiLevel,uiMaxLevel,uiMinLevel,uiAbsLevel,uiBestAbsLevel,uiBitShift; |
---|
3166 | Int iScanning,iQpRem,iBlockType,iRate; |
---|
3167 | Int iQBits = m_cQP.m_iBits; |
---|
3168 | Int64 lLevelDouble; |
---|
3169 | Double dErr,dTemp=0,dNormFactor,rd64UncodedCost,rd64CodedCost,dCurrCost; |
---|
3170 | |
---|
3171 | uiBitShift = 15; |
---|
3172 | iQpRem = m_cQP.m_iRem; |
---|
3173 | |
---|
3174 | Bool bExt8x8Flag = false; |
---|
3175 | uiLog2BlkSize = g_aucConvertToBit[ uiWidth ] + 2; |
---|
3176 | uiConvBit = g_aucConvertToBit[ uiWidth ]; |
---|
3177 | |
---|
3178 | #if QC_MDCS |
---|
3179 | const UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
3180 | #endif //QC_MDCS |
---|
3181 | |
---|
3182 | if (uiWidth == 4) |
---|
3183 | { |
---|
3184 | #if QC_MOD_LCEC |
---|
3185 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
3186 | iBlockType = eTType-2; |
---|
3187 | else |
---|
3188 | iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
3189 | #else |
---|
3190 | iBlockType = 0 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
3191 | #endif |
---|
3192 | iQBits = m_cQP.m_iBits; |
---|
3193 | dNormFactor = pow(2., (2*DQ_BITS+19)); |
---|
3194 | if ( g_uiBitIncrement ) dNormFactor *= 1<<(2*g_uiBitIncrement); |
---|
3195 | piQuantCoef = ( g_aiQuantCoef[m_cQP.rem()] ); |
---|
3196 | } |
---|
3197 | else if (uiWidth == 8) |
---|
3198 | { |
---|
3199 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
3200 | iBlockType = eTType-2; |
---|
3201 | else |
---|
3202 | iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
3203 | iQBits = m_cQP.m_iBits + 1; |
---|
3204 | dNormFactor = pow(2., (2*Q_BITS_8+9)); |
---|
3205 | if ( g_uiBitIncrement ) dNormFactor *= 1<<(2*g_uiBitIncrement); |
---|
3206 | piQuantCoef = ( g_aiQuantCoef64[m_cQP.rem()] ); |
---|
3207 | } |
---|
3208 | else |
---|
3209 | { |
---|
3210 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
3211 | iBlockType = eTType-2; |
---|
3212 | else |
---|
3213 | iBlockType = 5 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
3214 | |
---|
3215 | if(!pcCU->isIntra(uiAbsPartIdx)) |
---|
3216 | { |
---|
3217 | uiLog2BlkSize = g_aucConvertToBit[ 8 ] + 2; |
---|
3218 | uiConvBit = g_aucConvertToBit[ 8 ]; |
---|
3219 | } |
---|
3220 | dNormFactor = pow(2., 21); |
---|
3221 | if ( g_uiBitIncrement ) dNormFactor *= 1<<(2*g_uiBitIncrement); |
---|
3222 | |
---|
3223 | bExt8x8Flag = true; |
---|
3224 | |
---|
3225 | if ( uiWidth == 16) |
---|
3226 | { |
---|
3227 | piQuantCoef = ( g_aiQuantCoef256[m_cQP.rem()] ); |
---|
3228 | iQBits = ECore16Shift + m_cQP.per(); |
---|
3229 | dTemp = estErr16x16[iQpRem]/dNormFactor; |
---|
3230 | } |
---|
3231 | else if ( uiWidth == 32) |
---|
3232 | { |
---|
3233 | piQuantCoef = ( g_aiQuantCoef1024[m_cQP.rem()] ); |
---|
3234 | iQBits = ECore32Shift + m_cQP.per(); |
---|
3235 | dTemp = estErr32x32[iQpRem]/dNormFactor; |
---|
3236 | } |
---|
3237 | else |
---|
3238 | { |
---|
3239 | assert(0); |
---|
3240 | } |
---|
3241 | memset(&piDstCoeff[0],0,uiWidth*uiHeight*sizeof(TCoeff)); |
---|
3242 | } |
---|
3243 | |
---|
3244 | pucScan = g_auiFrameScanXY [ uiConvBit + 1 ]; |
---|
3245 | |
---|
3246 | iLpFlag = 1; // shawn note: last position flag |
---|
3247 | iLevelMode = 0; |
---|
3248 | iRun = 0; |
---|
3249 | iVlc_adaptive = 0; |
---|
3250 | iMaxrun = 0; |
---|
3251 | iSum_big_coef = 0; |
---|
3252 | #if QC_MOD_LCEC |
---|
3253 | UInt uiTr1=0; |
---|
3254 | #endif |
---|
3255 | |
---|
3256 | for (iScanning=(uiWidth<8 ? 15 : 63); iScanning>=0; iScanning--) |
---|
3257 | { |
---|
3258 | #if QC_MDCS |
---|
3259 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][iScanning]; |
---|
3260 | #else |
---|
3261 | uiBlkPos = pucScan[iScanning]; |
---|
3262 | #endif //QC_MDCS |
---|
3263 | uiPosY = uiBlkPos >> uiLog2BlkSize; |
---|
3264 | uiPosX = uiBlkPos - ( uiPosY << uiLog2BlkSize ); |
---|
3265 | |
---|
3266 | if (uiWidth==4) |
---|
3267 | dTemp = estErr4x4[ iQpRem ][ uiPosX ][ uiPosY ] / dNormFactor; |
---|
3268 | else if(uiWidth==8) |
---|
3269 | dTemp = estErr8x8[ iQpRem ][ uiPosX ][ uiPosY ] / dNormFactor; |
---|
3270 | else if(!pcCU->isIntra(uiAbsPartIdx)) |
---|
3271 | uiBlkPos = uiWidth*uiPosY+uiPosX; |
---|
3272 | |
---|
3273 | lLevelDouble = abs(plSrcCoeff[uiBlkPos]); |
---|
3274 | |
---|
3275 | lLevelDouble = lLevelDouble * (Int64) ( uiWidth == 64? piQuantCoef[m_cQP.rem()]: piQuantCoef[uiBlkPos] ); |
---|
3276 | |
---|
3277 | iSign = plSrcCoeff[uiBlkPos]<0 ? -1 : 1; |
---|
3278 | |
---|
3279 | |
---|
3280 | uiLevel = (UInt)(lLevelDouble >> iQBits); |
---|
3281 | uiMaxLevel = uiLevel + 1; |
---|
3282 | uiMinLevel = Max(1,(Int)uiLevel - 2); |
---|
3283 | |
---|
3284 | uiBestAbsLevel = 0; |
---|
3285 | #if QC_MOD_LCEC |
---|
3286 | if (uiWidth==4) |
---|
3287 | iRate = bitCount_LCEC(0,iScanning,iBlockType,iLpFlag,iLevelMode,iRun,iMaxrun,iVlc_adaptive,4,uiTr1)<<uiBitShift; |
---|
3288 | else |
---|
3289 | iRate = bitCount_LCEC(0,iScanning,iBlockType,iLpFlag,iLevelMode,iRun,iMaxrun,iVlc_adaptive,8,uiTr1)<<uiBitShift; |
---|
3290 | #else |
---|
3291 | if (uiWidth==4) |
---|
3292 | iRate = bitCount_LCEC(0,iScanning,iBlockType,iLpFlag,iLevelMode,iRun,iMaxrun,iVlc_adaptive,4)<<uiBitShift; |
---|
3293 | else |
---|
3294 | iRate = bitCount_LCEC(0,iScanning,iBlockType,iLpFlag,iLevelMode,iRun,iMaxrun,iVlc_adaptive,8)<<uiBitShift; |
---|
3295 | #endif |
---|
3296 | |
---|
3297 | dErr = Double( lLevelDouble ); |
---|
3298 | rd64UncodedCost = dErr * dErr * dTemp; |
---|
3299 | rd64CodedCost = rd64UncodedCost + xGetICost( iRate ); |
---|
3300 | for(uiAbsLevel = uiMinLevel; uiAbsLevel <= uiMaxLevel ; uiAbsLevel++ ) |
---|
3301 | { |
---|
3302 | #if QC_MOD_LCEC |
---|
3303 | if (uiWidth==4) |
---|
3304 | iRate = bitCount_LCEC(iSign*uiAbsLevel,iScanning,iBlockType,iLpFlag,iLevelMode,iRun,iMaxrun,iVlc_adaptive,4,uiTr1)<<uiBitShift; |
---|
3305 | else |
---|
3306 | iRate = bitCount_LCEC(iSign*uiAbsLevel,iScanning,iBlockType,iLpFlag,iLevelMode,iRun,iMaxrun,iVlc_adaptive,8,uiTr1)<<uiBitShift; |
---|
3307 | #else |
---|
3308 | if (uiWidth==4) |
---|
3309 | iRate = bitCount_LCEC(iSign*uiAbsLevel,iScanning,iBlockType,iLpFlag,iLevelMode,iRun,iMaxrun,iVlc_adaptive,4)<<uiBitShift; |
---|
3310 | else |
---|
3311 | iRate = bitCount_LCEC(iSign*uiAbsLevel,iScanning,iBlockType,iLpFlag,iLevelMode,iRun,iMaxrun,iVlc_adaptive,8)<<uiBitShift; |
---|
3312 | #endif |
---|
3313 | dErr = Double( lLevelDouble - (((Int64)uiAbsLevel) << iQBits ) ); |
---|
3314 | rd64UncodedCost = dErr * dErr * dTemp; |
---|
3315 | dCurrCost = rd64UncodedCost + xGetICost( iRate ); |
---|
3316 | if( dCurrCost < rd64CodedCost ) |
---|
3317 | { |
---|
3318 | uiBestAbsLevel = uiAbsLevel; |
---|
3319 | rd64CodedCost = dCurrCost; |
---|
3320 | } |
---|
3321 | } |
---|
3322 | |
---|
3323 | |
---|
3324 | if (uiBestAbsLevel) |
---|
3325 | { |
---|
3326 | if (uiWidth>4) |
---|
3327 | { |
---|
3328 | if (!iLpFlag && uiBestAbsLevel > 1) |
---|
3329 | { |
---|
3330 | iSum_big_coef += uiBestAbsLevel; |
---|
3331 | if ((63-iScanning) > switch_thr[iBlockType] || iSum_big_coef > 2) |
---|
3332 | iLevelMode = 1; |
---|
3333 | } |
---|
3334 | } |
---|
3335 | else |
---|
3336 | { |
---|
3337 | if (uiBestAbsLevel>1) |
---|
3338 | iLevelMode = 1; |
---|
3339 | } |
---|
3340 | #if QC_MOD_LCEC |
---|
3341 | if (iLpFlag==1){ |
---|
3342 | if (uiBestAbsLevel>1){ |
---|
3343 | uiTr1=0; |
---|
3344 | } |
---|
3345 | else{ |
---|
3346 | uiTr1=1; |
---|
3347 | } |
---|
3348 | } |
---|
3349 | else{ |
---|
3350 | if (uiTr1>0 && uiBestAbsLevel<2){ |
---|
3351 | uiTr1++; |
---|
3352 | uiTr1=Min(MAX_TR1,uiTr1); |
---|
3353 | } |
---|
3354 | else{ |
---|
3355 | uiTr1=0; |
---|
3356 | } |
---|
3357 | } |
---|
3358 | #endif |
---|
3359 | iMaxrun = iScanning-1; |
---|
3360 | iLpFlag = 0; |
---|
3361 | iRun = 0; |
---|
3362 | if (iLevelMode && (uiBestAbsLevel > atable[iVlc_adaptive])) |
---|
3363 | iVlc_adaptive++; |
---|
3364 | } |
---|
3365 | else |
---|
3366 | { |
---|
3367 | iRun += 1; |
---|
3368 | } |
---|
3369 | |
---|
3370 | uiAbsSum += uiBestAbsLevel; |
---|
3371 | piDstCoeff[uiBlkPos] = iSign*uiBestAbsLevel; |
---|
3372 | } // for uiScanning |
---|
3373 | } |
---|
3374 | #endif |
---|
3375 | |
---|
3376 | Void TComTrQuant::xQuantLTR (TComDataCU* pcCU, Long* pSrc, TCoeff*& pDes, Int iWidth, Int iHeight, UInt& uiAcSum, TextType eTType, UInt uiAbsPartIdx ) |
---|
3377 | { |
---|
3378 | Long* piCoef = pSrc; |
---|
3379 | TCoeff* piQCoef = pDes; |
---|
3380 | Int iAdd = 0; |
---|
3381 | |
---|
3382 | #if E243_CORE_TRANSFORMS |
---|
3383 | if ( m_bUseRDOQ && (eTType == TEXT_LUMA || RDOQ_CHROMA) ) |
---|
3384 | { |
---|
3385 | if ( m_iSymbolMode == 0) |
---|
3386 | xRateDistOptQuant_LCEC(pcCU, piCoef, pDes, iWidth, iHeight, uiAcSum, eTType, uiAbsPartIdx ); |
---|
3387 | else |
---|
3388 | xRateDistOptQuant( pcCU, piCoef, pDes, iWidth, iHeight, uiAcSum, eTType, uiAbsPartIdx ); |
---|
3389 | } |
---|
3390 | else |
---|
3391 | { |
---|
3392 | const UInt* pucScan; |
---|
3393 | UInt uiConvBit = g_aucConvertToBit[ iWidth ]; |
---|
3394 | pucScan = g_auiFrameScanXY [ uiConvBit + 1 ]; |
---|
3395 | |
---|
3396 | UInt uiLog2TrSize = g_aucConvertToBit[ iWidth ] + 2; |
---|
3397 | UInt uiQ = g_auiQ[m_cQP.rem()]; |
---|
3398 | |
---|
3399 | #if FULL_NBIT |
---|
3400 | UInt uiBitDepth = g_uiBitDepth; |
---|
3401 | #else |
---|
3402 | UInt uiBitDepth = g_uiBitDepth + g_uiBitIncrement; |
---|
3403 | #endif |
---|
3404 | UInt iTransformShift = MAX_TR_DYNAMIC_RANGE - uiBitDepth - uiLog2TrSize; // Represents scaling through forward transform |
---|
3405 | Int iQBits = QUANT_SHIFT + m_cQP.m_iPer + iTransformShift; // Right shift of non-RDOQ quantizer; level = (coeff*uiQ + offset)>>q_bits |
---|
3406 | |
---|
3407 | iAdd = (pcCU->getSlice()->getSliceType()==I_SLICE ? 171 : 85) << (iQBits-9); |
---|
3408 | |
---|
3409 | for( Int n = 0; n < iWidth*iHeight; n++ ) |
---|
3410 | { |
---|
3411 | Long iLevel; |
---|
3412 | Int iSign; |
---|
3413 | UInt uiBlockPos = pucScan[n]; |
---|
3414 | iLevel = (Long) piCoef[uiBlockPos]; |
---|
3415 | iSign = (iLevel < 0 ? -1: 1); |
---|
3416 | |
---|
3417 | iLevel = (abs(iLevel) * uiQ + iAdd ) >> iQBits; |
---|
3418 | #if CAVLC_COEF_LRG_BLK |
---|
3419 | if (m_iSymbolMode == 0 && n>=64 && eTType != TEXT_LUMA) |
---|
3420 | { |
---|
3421 | iLevel = 0; |
---|
3422 | } |
---|
3423 | #else |
---|
3424 | if (m_iSymbolMode == 0 && iWidth>8) |
---|
3425 | { |
---|
3426 | /* Two methods of limiting number of encoded coefficients to 8x8 for intra and inter respectively */ |
---|
3427 | if (pcCU->isIntra( uiAbsPartIdx )) |
---|
3428 | { |
---|
3429 | if(n>=64) iLevel = 0; |
---|
3430 | } |
---|
3431 | else |
---|
3432 | { |
---|
3433 | if ((uiBlockPos%iWidth)>=8 || (uiBlockPos/iWidth)>=8) iLevel = 0; |
---|
3434 | } |
---|
3435 | } |
---|
3436 | #endif |
---|
3437 | uiAcSum += iLevel; |
---|
3438 | iLevel *= iSign; |
---|
3439 | piQCoef[uiBlockPos] = iLevel; |
---|
3440 | } // for n |
---|
3441 | } //if RDOQ |
---|
3442 | //return; |
---|
3443 | |
---|
3444 | #else //E243_CORE_TRANSFORMS |
---|
3445 | |
---|
3446 | UInt* piQuantCoef = NULL; |
---|
3447 | Int iNewBits = 0; |
---|
3448 | switch(iWidth) |
---|
3449 | { |
---|
3450 | case 2: |
---|
3451 | { |
---|
3452 | m_puiQuantMtx = &g_aiQuantCoef4[m_cQP.m_iRem]; |
---|
3453 | xQuant2x2(piCoef, piQCoef, uiAcSum ); |
---|
3454 | return; |
---|
3455 | } |
---|
3456 | case 4: |
---|
3457 | { |
---|
3458 | m_puiQuantMtx = &g_aiQuantCoef[m_cQP.m_iRem][0]; |
---|
3459 | xQuant4x4(pcCU, piCoef, piQCoef, uiAcSum, eTType, uiAbsPartIdx ); |
---|
3460 | return; |
---|
3461 | } |
---|
3462 | case 8: |
---|
3463 | { |
---|
3464 | m_puiQuantMtx = &g_aiQuantCoef64[m_cQP.m_iRem][0]; |
---|
3465 | xQuant8x8(pcCU, piCoef, piQCoef, uiAcSum, eTType, uiAbsPartIdx ); |
---|
3466 | return; |
---|
3467 | } |
---|
3468 | case 16: |
---|
3469 | { |
---|
3470 | piQuantCoef = ( g_aiQuantCoef256[m_cQP.rem()] ); |
---|
3471 | iNewBits = ECore16Shift + m_cQP.per(); |
---|
3472 | iAdd = m_cQP.m_iAdd16x16; |
---|
3473 | break; |
---|
3474 | } |
---|
3475 | case 32: |
---|
3476 | { |
---|
3477 | piQuantCoef = ( g_aiQuantCoef1024[m_cQP.rem()] ); |
---|
3478 | iNewBits = ECore32Shift + m_cQP.per(); |
---|
3479 | iAdd = m_cQP.m_iAdd32x32; |
---|
3480 | break; |
---|
3481 | } |
---|
3482 | default: |
---|
3483 | assert(0); |
---|
3484 | break; |
---|
3485 | } |
---|
3486 | |
---|
3487 | if ( m_bUseRDOQ && (eTType == TEXT_LUMA || RDOQ_CHROMA) ) |
---|
3488 | { |
---|
3489 | if ( m_iSymbolMode == 0) |
---|
3490 | xRateDistOptQuant_LCEC(pcCU, piCoef, pDes, iWidth, iHeight, uiAcSum, eTType, uiAbsPartIdx ); |
---|
3491 | else |
---|
3492 | xRateDistOptQuant( pcCU, piCoef, pDes, iWidth, iHeight, uiAcSum, eTType, uiAbsPartIdx ); |
---|
3493 | } |
---|
3494 | else |
---|
3495 | { |
---|
3496 | UInt uiAcSum_init = uiAcSum; |
---|
3497 | for( Int n = 0; n < iWidth*iHeight; n++ ) |
---|
3498 | { |
---|
3499 | Long iLevel; |
---|
3500 | Int iSign; |
---|
3501 | iLevel = (Long) piCoef[n]; |
---|
3502 | iSign = (iLevel < 0 ? -1: 1); |
---|
3503 | if ( iWidth == 64 ) iLevel = abs( iLevel ) * piQuantCoef[m_cQP.rem()]; |
---|
3504 | else iLevel = abs( iLevel ) * piQuantCoef[n]; |
---|
3505 | |
---|
3506 | if (!pcCU->isIntra( uiAbsPartIdx ) && (m_iSymbolMode == 0) && ((n%iWidth)>=8 || (n/iWidth)>=8)) |
---|
3507 | iLevel = 0; |
---|
3508 | else |
---|
3509 | iLevel = ( iLevel + iAdd ) >> iNewBits; |
---|
3510 | |
---|
3511 | if( 0 != iLevel ) |
---|
3512 | { |
---|
3513 | uiAcSum += iLevel; |
---|
3514 | iLevel *= iSign; |
---|
3515 | piQCoef[n] = iLevel; |
---|
3516 | } |
---|
3517 | else |
---|
3518 | { |
---|
3519 | piQCoef[n] = 0; |
---|
3520 | } |
---|
3521 | } |
---|
3522 | |
---|
3523 | const UInt* pucScan; |
---|
3524 | if(pcCU->isIntra( uiAbsPartIdx ) && m_iSymbolMode == 0 && iWidth >= 16) |
---|
3525 | { |
---|
3526 | UInt uiConvBit = g_aucConvertToBit[ iWidth ]; |
---|
3527 | pucScan = g_auiFrameScanXY [ uiConvBit + 1 ]; |
---|
3528 | #if CAVLC_COEF_LRG_BLK |
---|
3529 | UInt noCoeff = (eTType == TEXT_LUMA)? (iWidth*iHeight):64; |
---|
3530 | |
---|
3531 | for( Int n = noCoeff; n < iWidth*iHeight; n++ ) |
---|
3532 | { |
---|
3533 | piQCoef[ pucScan[ n ] ] = 0; |
---|
3534 | } |
---|
3535 | uiAcSum = uiAcSum_init; |
---|
3536 | for( Int n = 0; n < noCoeff; n++ ) |
---|
3537 | { |
---|
3538 | uiAcSum += abs(piQCoef[ pucScan[ n ] ]); |
---|
3539 | } |
---|
3540 | #else |
---|
3541 | for( Int n = 64; n < iWidth*iHeight; n++ ) |
---|
3542 | { |
---|
3543 | piQCoef[ pucScan[ n ] ] = 0; |
---|
3544 | } |
---|
3545 | |
---|
3546 | uiAcSum = uiAcSum_init; |
---|
3547 | |
---|
3548 | for( Int n = 0; n < 64; n++ ) |
---|
3549 | { |
---|
3550 | uiAcSum += abs(piQCoef[ pucScan[ n ] ]); |
---|
3551 | } |
---|
3552 | #endif |
---|
3553 | } |
---|
3554 | } |
---|
3555 | #endif |
---|
3556 | } |
---|
3557 | |
---|
3558 | Void TComTrQuant::xDeQuantLTR( TCoeff* pSrc, Long*& pDes, Int iWidth, Int iHeight ) |
---|
3559 | { |
---|
3560 | |
---|
3561 | TCoeff* piQCoef = pSrc; |
---|
3562 | Long* piCoef = pDes; |
---|
3563 | |
---|
3564 | if ( iWidth > (Int)m_uiMaxTrSize ) |
---|
3565 | { |
---|
3566 | iWidth = m_uiMaxTrSize; |
---|
3567 | iHeight = m_uiMaxTrSize; |
---|
3568 | } |
---|
3569 | |
---|
3570 | #if E243_CORE_TRANSFORMS |
---|
3571 | Int iShift,iAdd,iCoeffQ; |
---|
3572 | UInt uiQ; |
---|
3573 | UInt uiLog2TrSize = g_aucConvertToBit[ iWidth ] + 2; |
---|
3574 | |
---|
3575 | #if FULL_NBIT |
---|
3576 | UInt uiBitDepth = g_uiBitDepth; |
---|
3577 | #else |
---|
3578 | UInt uiBitDepth = g_uiBitDepth + g_uiBitIncrement; |
---|
3579 | #endif |
---|
3580 | UInt iTransformShift = MAX_TR_DYNAMIC_RANGE - uiBitDepth - uiLog2TrSize; |
---|
3581 | iShift = QUANT_IQUANT_SHIFT - QUANT_SHIFT - iTransformShift; |
---|
3582 | iAdd = 1 << (iShift-1); |
---|
3583 | uiQ = g_auiIQ[m_cQP.m_iRem]; |
---|
3584 | |
---|
3585 | for( Int n = 0; n < iWidth*iHeight; n++ ) |
---|
3586 | { |
---|
3587 | iCoeffQ = ((piQCoef[n]*(Int)uiQ << m_cQP.m_iPer)+iAdd)>>iShift; |
---|
3588 | piCoef[n] = Clip3(-32768,32767,iCoeffQ); |
---|
3589 | } |
---|
3590 | #else |
---|
3591 | UInt* piDeQuantCoef = NULL; |
---|
3592 | switch(iWidth) |
---|
3593 | { |
---|
3594 | case 2: |
---|
3595 | { |
---|
3596 | xDeQuant2x2( piQCoef, piCoef ); |
---|
3597 | return; |
---|
3598 | } |
---|
3599 | case 4: |
---|
3600 | { |
---|
3601 | xDeQuant4x4( piQCoef, piCoef ); |
---|
3602 | return; |
---|
3603 | } |
---|
3604 | case 8: |
---|
3605 | { |
---|
3606 | xDeQuant8x8( piQCoef, piCoef ); |
---|
3607 | return; |
---|
3608 | } |
---|
3609 | case 16: |
---|
3610 | { |
---|
3611 | piDeQuantCoef = ( g_aiDeQuantCoef256[m_cQP.rem()] ); |
---|
3612 | break; |
---|
3613 | } |
---|
3614 | case 32: |
---|
3615 | { |
---|
3616 | piDeQuantCoef = ( g_aiDeQuantCoef1024[m_cQP.rem()] ); |
---|
3617 | break; |
---|
3618 | } |
---|
3619 | case 64: |
---|
3620 | { |
---|
3621 | piDeQuantCoef = ( g_aiDeQuantCoef4096 ); // To save the memory for g_aiDeQuantCoef4096 |
---|
3622 | break; |
---|
3623 | } |
---|
3624 | } |
---|
3625 | |
---|
3626 | Int iLevel; |
---|
3627 | Int iDeScale; |
---|
3628 | |
---|
3629 | for( Int n = 0; n < iWidth*iHeight; n++ ) |
---|
3630 | { |
---|
3631 | iLevel = piQCoef[n]; |
---|
3632 | |
---|
3633 | if( 0 != iLevel ) |
---|
3634 | { |
---|
3635 | if ( iWidth == 64 ) iDeScale = piDeQuantCoef[m_cQP.rem()]; |
---|
3636 | else iDeScale = piDeQuantCoef[n]; |
---|
3637 | piCoef[n] = (Long) (iLevel*iDeScale) << m_cQP.per(); |
---|
3638 | } |
---|
3639 | else |
---|
3640 | { |
---|
3641 | piCoef [n] = 0; |
---|
3642 | } |
---|
3643 | } |
---|
3644 | #endif |
---|
3645 | } |
---|
3646 | #if !E243_CORE_TRANSFORMS |
---|
3647 | Void TComTrQuant::xIT16( Long* pSrc, Pel* pDes, UInt uiStride ) |
---|
3648 | { |
---|
3649 | Int x, y; |
---|
3650 | Long aaiTemp[16][16]; |
---|
3651 | |
---|
3652 | Long B0, B1, B2, B3, B4, B5, B6, B7, B10, B11, B12, B13; |
---|
3653 | Long C0, C1, C2, C3, C5, C6, C8, C9, C10, C11, C12, C13, C14, C15; |
---|
3654 | Long D0, D1, D2, D3, D4, D5, D6, D7, D9, D10, D13, D14; |
---|
3655 | Long E4, E5, E6, E7, E8, E9, E10, E11, E12, E13, E14, E15; |
---|
3656 | Long F8, F9, F10, F11, F12, F13, F14, F15; |
---|
3657 | |
---|
3658 | UInt uiStride2 = uiStride<<1; |
---|
3659 | UInt uiStride3 = uiStride2 + uiStride; |
---|
3660 | UInt uiStride4 = uiStride3 + uiStride; |
---|
3661 | UInt uiStride5 = uiStride4 + uiStride; |
---|
3662 | UInt uiStride6 = uiStride5 + uiStride; |
---|
3663 | UInt uiStride7 = uiStride6 + uiStride; |
---|
3664 | UInt uiStride8 = uiStride7 + uiStride; |
---|
3665 | UInt uiStride9 = uiStride8 + uiStride; |
---|
3666 | UInt uiStride10 = uiStride9 + uiStride; |
---|
3667 | UInt uiStride11 = uiStride10 + uiStride; |
---|
3668 | UInt uiStride12 = uiStride11 + uiStride; |
---|
3669 | UInt uiStride13 = uiStride12 + uiStride; |
---|
3670 | UInt uiStride14 = uiStride13 + uiStride; |
---|
3671 | UInt uiStride15 = uiStride14 + uiStride; |
---|
3672 | #ifdef TRANS_PRECISION_EXT |
---|
3673 | #if FULL_NBIT |
---|
3674 | Int uiBitDepthIncrease=g_iShift16x16-g_uiBitIncrement-g_uiBitDepth+8; |
---|
3675 | #else |
---|
3676 | Int uiBitDepthIncrease=g_iShift16x16-g_uiBitIncrement; |
---|
3677 | #endif |
---|
3678 | Int offset = (uiBitDepthIncrease==0)? 0:(1<<(uiBitDepthIncrease-1)); |
---|
3679 | #endif |
---|
3680 | //--Butterfly |
---|
3681 | for( y=0 ; y<16 ; y++ ) |
---|
3682 | { |
---|
3683 | #ifdef TRANS_PRECISION_EXT |
---|
3684 | Long ai0[16]; |
---|
3685 | ai0[0] = pSrc[0]<<uiBitDepthIncrease; |
---|
3686 | ai0[1] = pSrc[1]<<uiBitDepthIncrease; |
---|
3687 | ai0[2] = pSrc[2]<<uiBitDepthIncrease; |
---|
3688 | ai0[3] = pSrc[3]<<uiBitDepthIncrease; |
---|
3689 | ai0[4] = pSrc[4]<<uiBitDepthIncrease; |
---|
3690 | ai0[5] = pSrc[5]<<uiBitDepthIncrease; |
---|
3691 | ai0[6] = pSrc[6]<<uiBitDepthIncrease; |
---|
3692 | ai0[7] = pSrc[7]<<uiBitDepthIncrease; |
---|
3693 | ai0[8 ] = pSrc[8 ]<<uiBitDepthIncrease; |
---|
3694 | ai0[9 ] = pSrc[9 ]<<uiBitDepthIncrease; |
---|
3695 | ai0[10] = pSrc[10]<<uiBitDepthIncrease; |
---|
3696 | ai0[11] = pSrc[11]<<uiBitDepthIncrease; |
---|
3697 | ai0[12] = pSrc[12]<<uiBitDepthIncrease; |
---|
3698 | ai0[13] = pSrc[13]<<uiBitDepthIncrease; |
---|
3699 | ai0[14] = pSrc[14]<<uiBitDepthIncrease; |
---|
3700 | ai0[15] = pSrc[15]<<uiBitDepthIncrease; |
---|
3701 | F8 = xTrRound( 6 * ai0[1] - 63 * ai0[15] , DenShift16); |
---|
3702 | F9 = xTrRound( 49 * ai0[9] - 40 * ai0[7] , DenShift16); |
---|
3703 | F10 = xTrRound( 30 * ai0[5] - 56 * ai0[11] , DenShift16); |
---|
3704 | F11 = xTrRound( 61 * ai0[13] - 18 * ai0[3] , DenShift16); |
---|
3705 | F12 = xTrRound( 61 * ai0[3] + 18 * ai0[13] , DenShift16); |
---|
3706 | F13 = xTrRound( 30 * ai0[11] + 56 * ai0[5] , DenShift16); |
---|
3707 | F14 = xTrRound( 49 * ai0[7] + 40 * ai0[9] , DenShift16); |
---|
3708 | F15 = xTrRound( 6 * ai0[15] + 63 * ai0[1] , DenShift16); |
---|
3709 | |
---|
3710 | E4 = xTrRound( 12 * ai0[2] - 62 * ai0[14] , DenShift16); |
---|
3711 | E5 = xTrRound( 53 * ai0[10] - 35 * ai0[6] , DenShift16); |
---|
3712 | E6 = xTrRound( 53 * ai0[6] + 35 * ai0[10] , DenShift16); |
---|
3713 | E7 = xTrRound( 12 * ai0[14] + 62 * ai0[2] , DenShift16); |
---|
3714 | #else |
---|
3715 | F8 = xTrRound( 6 * pSrc[1] - 63 * pSrc[15] , DenShift16); |
---|
3716 | F9 = xTrRound( 49 * pSrc[9] - 40 * pSrc[7] , DenShift16); |
---|
3717 | F10 = xTrRound( 30 * pSrc[5] - 56 * pSrc[11] , DenShift16); |
---|
3718 | F11 = xTrRound( 61 * pSrc[13] - 18 * pSrc[3] , DenShift16); |
---|
3719 | F12 = xTrRound( 61 * pSrc[3] + 18 * pSrc[13] , DenShift16); |
---|
3720 | F13 = xTrRound( 30 * pSrc[11] + 56 * pSrc[5] , DenShift16); |
---|
3721 | F14 = xTrRound( 49 * pSrc[7] + 40 * pSrc[9] , DenShift16); |
---|
3722 | F15 = xTrRound( 6 * pSrc[15] + 63 * pSrc[1] , DenShift16); |
---|
3723 | |
---|
3724 | E4 = xTrRound( 12 * pSrc[2] - 62 * pSrc[14] , DenShift16); |
---|
3725 | E5 = xTrRound( 53 * pSrc[10] - 35 * pSrc[6] , DenShift16); |
---|
3726 | E6 = xTrRound( 53 * pSrc[6] + 35 * pSrc[10] , DenShift16); |
---|
3727 | E7 = xTrRound( 12 * pSrc[14] + 62 * pSrc[2] , DenShift16); |
---|
3728 | #endif |
---|
3729 | E8 = F8 + F9; |
---|
3730 | E9 = F8 - F9; |
---|
3731 | E10 = F11 - F10; |
---|
3732 | E11 = F11 + F10; |
---|
3733 | E12 = F12 + F13; |
---|
3734 | E13 = F12 - F13; |
---|
3735 | E14 = F15 - F14; |
---|
3736 | E15 = F15 + F14; |
---|
3737 | #ifdef TRANS_PRECISION_EXT |
---|
3738 | D0 = xTrRound( 45 * ( ai0[0] + ai0[8] ) , DenShift16); |
---|
3739 | D1 = xTrRound( 45 * ( ai0[0] - ai0[8] ) , DenShift16); |
---|
3740 | D2 = xTrRound( 24 * ai0[4] - 59 * ai0[12] , DenShift16); |
---|
3741 | D3 = xTrRound( 59 * ai0[4] + 24 * ai0[12] , DenShift16); |
---|
3742 | #else |
---|
3743 | D0 = xTrRound( 45 * ( pSrc[0] + pSrc[8] ) , DenShift16); |
---|
3744 | D1 = xTrRound( 45 * ( pSrc[0] - pSrc[8] ) , DenShift16); |
---|
3745 | D2 = xTrRound( 24 * pSrc[4] - 59 * pSrc[12] , DenShift16); |
---|
3746 | D3 = xTrRound( 59 * pSrc[4] + 24 * pSrc[12] , DenShift16); |
---|
3747 | #endif |
---|
3748 | D4 = E4 + E5; |
---|
3749 | D5 = E4 - E5; |
---|
3750 | D6 = E7 - E6; |
---|
3751 | D7 = E7 + E6; |
---|
3752 | D9 = xTrRound( 24 * E14 - 59 * E9 , DenShift16); |
---|
3753 | D10 = xTrRound( - 59 * E13 - 24 * E10 , DenShift16); |
---|
3754 | D13 = xTrRound( 24 * E13 - 59 * E10 , DenShift16); |
---|
3755 | D14 = xTrRound( 59 * E14 + 24 * E9 , DenShift16); |
---|
3756 | |
---|
3757 | C0 = D0 + D3; |
---|
3758 | C3 = D0 - D3; |
---|
3759 | C8 = E8 + E11; |
---|
3760 | C11 = E8 - E11; |
---|
3761 | C12 = E15 - E12; |
---|
3762 | C15 = E15 + E12; |
---|
3763 | C1 = D1 + D2; |
---|
3764 | C2 = D1 - D2; |
---|
3765 | C9 = D9 + D10; |
---|
3766 | C10 = D9 - D10; |
---|
3767 | C13 = D14 - D13; |
---|
3768 | C14 = D14 + D13; |
---|
3769 | C5 = xTrRound( 45 * ( D6 - D5 ) , DenShift16); |
---|
3770 | C6 = xTrRound( 45 * ( D6 + D5 ) , DenShift16); |
---|
3771 | |
---|
3772 | B0 = C0 + D7; |
---|
3773 | B7 = C0 - D7; |
---|
3774 | B1 = C1 + C6; |
---|
3775 | B6 = C1 - C6; |
---|
3776 | B2 = C2 + C5; |
---|
3777 | B5 = C2 - C5; |
---|
3778 | B3 = C3 + D4; |
---|
3779 | B4 = C3 - D4; |
---|
3780 | B10 = xTrRound( 45 * ( C13 - C10 ) , DenShift16); |
---|
3781 | B13 = xTrRound( 45 * ( C13 + C10 ) , DenShift16); |
---|
3782 | B11 = xTrRound( 45 * ( C12 - C11 ) , DenShift16); |
---|
3783 | B12 = xTrRound( 45 * ( C12 + C11 ) , DenShift16); |
---|
3784 | |
---|
3785 | aaiTemp[0][y] = B0 + C15; |
---|
3786 | aaiTemp[15][y] = B0 - C15; |
---|
3787 | aaiTemp[1][y] = B1 + C14; |
---|
3788 | aaiTemp[14][y] = B1 - C14; |
---|
3789 | aaiTemp[2][y] = B2 + B13; |
---|
3790 | aaiTemp[13][y] = B2 - B13; |
---|
3791 | aaiTemp[3][y] = B3 + B12; |
---|
3792 | aaiTemp[12][y] = B3 - B12; |
---|
3793 | aaiTemp[4][y] = B4 + B11; |
---|
3794 | aaiTemp[11][y] = B4 - B11; |
---|
3795 | aaiTemp[5][y] = B5 + B10; |
---|
3796 | aaiTemp[10][y] = B5 - B10; |
---|
3797 | aaiTemp[6][y] = B6 + C9; |
---|
3798 | aaiTemp[9][y] = B6 - C9; |
---|
3799 | aaiTemp[7][y] = B7 + C8; |
---|
3800 | aaiTemp[8][y] = B7 - C8; |
---|
3801 | |
---|
3802 | pSrc += 16; |
---|
3803 | } |
---|
3804 | |
---|
3805 | for( x=0 ; x<16 ; x++, pDes++ ) |
---|
3806 | { |
---|
3807 | F8 = xTrRound( 6 * aaiTemp[x][1] - 63 * aaiTemp[x][15] , DenShift16); |
---|
3808 | F9 = xTrRound( 49 * aaiTemp[x][9] - 40 * aaiTemp[x][7] , DenShift16); |
---|
3809 | F10 = xTrRound( 30 * aaiTemp[x][5] - 56 * aaiTemp[x][11] , DenShift16); |
---|
3810 | F11 = xTrRound( 61 * aaiTemp[x][13] - 18 * aaiTemp[x][3] , DenShift16); |
---|
3811 | F12 = xTrRound( 61 * aaiTemp[x][3] + 18 * aaiTemp[x][13] , DenShift16); |
---|
3812 | F13 = xTrRound( 30 * aaiTemp[x][11] + 56 * aaiTemp[x][5] , DenShift16); |
---|
3813 | F14 = xTrRound( 49 * aaiTemp[x][7] + 40 * aaiTemp[x][9] , DenShift16); |
---|
3814 | F15 = xTrRound( 6 * aaiTemp[x][15] + 63 * aaiTemp[x][1] , DenShift16); |
---|
3815 | |
---|
3816 | E4 = xTrRound( 12 * aaiTemp[x][2] - 62 * aaiTemp[x][14] , DenShift16); |
---|
3817 | E5 = xTrRound( 53 * aaiTemp[x][10] - 35 * aaiTemp[x][6] , DenShift16); |
---|
3818 | E6 = xTrRound( 53 * aaiTemp[x][6] + 35 * aaiTemp[x][10] , DenShift16); |
---|
3819 | E7 = xTrRound( 12 * aaiTemp[x][14] + 62 * aaiTemp[x][2] , DenShift16); |
---|
3820 | E8 = F8 + F9; |
---|
3821 | E9 = F8 - F9; |
---|
3822 | E10 = F11 - F10; |
---|
3823 | E11 = F11 + F10; |
---|
3824 | E12 = F12 + F13; |
---|
3825 | E13 = F12 - F13; |
---|
3826 | E14 = F15 - F14; |
---|
3827 | E15 = F15 + F14; |
---|
3828 | |
---|
3829 | D0 = xTrRound( 45 * ( aaiTemp[x][0] + aaiTemp[x][8] ) , DenShift16); |
---|
3830 | D1 = xTrRound( 45 * ( aaiTemp[x][0] - aaiTemp[x][8] ) , DenShift16); |
---|
3831 | D2 = xTrRound( 24 * aaiTemp[x][4] - 59 * aaiTemp[x][12] , DenShift16); |
---|
3832 | D3 = xTrRound( 59 * aaiTemp[x][4] + 24 * aaiTemp[x][12] , DenShift16); |
---|
3833 | D4 = E4 + E5; |
---|
3834 | D5 = E4 - E5; |
---|
3835 | D6 = E7 - E6; |
---|
3836 | D7 = E7 + E6; |
---|
3837 | D9 = xTrRound( 24 * E14 - 59 * E9 , DenShift16); |
---|
3838 | D10 = xTrRound( - 59 * E13 - 24 * E10 , DenShift16); |
---|
3839 | D13 = xTrRound( 24 * E13 - 59 * E10 , DenShift16); |
---|
3840 | D14 = xTrRound( 59 * E14 + 24 * E9 , DenShift16); |
---|
3841 | |
---|
3842 | C0 = D0 + D3; |
---|
3843 | C3 = D0 - D3; |
---|
3844 | C8 = E8 + E11; |
---|
3845 | C11 = E8 - E11; |
---|
3846 | C12 = E15 - E12; |
---|
3847 | C15 = E15 + E12; |
---|
3848 | C1 = D1 + D2; |
---|
3849 | C2 = D1 - D2; |
---|
3850 | C9 = D9 + D10; |
---|
3851 | C10 = D9 - D10; |
---|
3852 | C13 = D14 - D13; |
---|
3853 | C14 = D14 + D13; |
---|
3854 | C5 = xTrRound( 45 * ( D6 - D5 ) , DenShift16); |
---|
3855 | C6 = xTrRound( 45 * ( D6 + D5 ) , DenShift16); |
---|
3856 | |
---|
3857 | B0 = C0 + D7; |
---|
3858 | B7 = C0 - D7; |
---|
3859 | B1 = C1 + C6; |
---|
3860 | B6 = C1 - C6; |
---|
3861 | B2 = C2 + C5; |
---|
3862 | B5 = C2 - C5; |
---|
3863 | B3 = C3 + D4; |
---|
3864 | B4 = C3 - D4; |
---|
3865 | B10 = xTrRound( 45 * ( C13 - C10 ) , DenShift16); |
---|
3866 | B13 = xTrRound( 45 * ( C13 + C10 ) , DenShift16); |
---|
3867 | B11 = xTrRound( 45 * ( C12 - C11 ) , DenShift16); |
---|
3868 | B12 = xTrRound( 45 * ( C12 + C11 ) , DenShift16); |
---|
3869 | |
---|
3870 | pDes[ 0] = (Pel)xTrRound(B0 + C15, DCore16Shift); |
---|
3871 | pDes[uiStride15] = (Pel)xTrRound(B0 - C15, DCore16Shift); |
---|
3872 | pDes[uiStride ] = (Pel)xTrRound(B1 + C14, DCore16Shift); |
---|
3873 | pDes[uiStride14] = (Pel)xTrRound(B1 - C14, DCore16Shift); |
---|
3874 | pDes[uiStride2 ] = (Pel)xTrRound(B2 + B13, DCore16Shift); |
---|
3875 | pDes[uiStride13] = (Pel)xTrRound(B2 - B13, DCore16Shift); |
---|
3876 | pDes[uiStride3 ] = (Pel)xTrRound(B3 + B12, DCore16Shift); |
---|
3877 | pDes[uiStride12] = (Pel)xTrRound(B3 - B12, DCore16Shift); |
---|
3878 | pDes[uiStride4 ] = (Pel)xTrRound(B4 + B11, DCore16Shift); |
---|
3879 | pDes[uiStride11] = (Pel)xTrRound(B4 - B11, DCore16Shift); |
---|
3880 | pDes[uiStride5 ] = (Pel)xTrRound(B5 + B10, DCore16Shift); |
---|
3881 | pDes[uiStride10] = (Pel)xTrRound(B5 - B10, DCore16Shift); |
---|
3882 | pDes[uiStride6 ] = (Pel)xTrRound(B6 + C9, DCore16Shift); |
---|
3883 | pDes[uiStride9 ] = (Pel)xTrRound(B6 - C9, DCore16Shift); |
---|
3884 | pDes[uiStride7 ] = (Pel)xTrRound(B7 + C8, DCore16Shift); |
---|
3885 | pDes[uiStride8 ] = (Pel)xTrRound(B7 - C8, DCore16Shift); |
---|
3886 | #ifdef TRANS_PRECISION_EXT |
---|
3887 | pDes[ 0 ] = (pDes[ 0 ]+offset)>>uiBitDepthIncrease; |
---|
3888 | pDes[uiStride ] = (pDes[uiStride ]+offset)>>uiBitDepthIncrease; |
---|
3889 | pDes[uiStride2 ] = (pDes[uiStride2 ]+offset)>>uiBitDepthIncrease; |
---|
3890 | pDes[uiStride3 ] = (pDes[uiStride3 ]+offset)>>uiBitDepthIncrease; |
---|
3891 | pDes[uiStride4 ] = (pDes[uiStride4 ]+offset)>>uiBitDepthIncrease; |
---|
3892 | pDes[uiStride5 ] = (pDes[uiStride5 ]+offset)>>uiBitDepthIncrease; |
---|
3893 | pDes[uiStride6 ] = (pDes[uiStride6 ]+offset)>>uiBitDepthIncrease; |
---|
3894 | pDes[uiStride7 ] = (pDes[uiStride7 ]+offset)>>uiBitDepthIncrease; |
---|
3895 | pDes[uiStride8 ] = (pDes[uiStride8 ]+offset)>>uiBitDepthIncrease; |
---|
3896 | pDes[uiStride9 ] = (pDes[uiStride9 ]+offset)>>uiBitDepthIncrease; |
---|
3897 | pDes[uiStride10] = (pDes[uiStride10]+offset)>>uiBitDepthIncrease; |
---|
3898 | pDes[uiStride11] = (pDes[uiStride11]+offset)>>uiBitDepthIncrease; |
---|
3899 | pDes[uiStride12] = (pDes[uiStride12]+offset)>>uiBitDepthIncrease; |
---|
3900 | pDes[uiStride13] = (pDes[uiStride13]+offset)>>uiBitDepthIncrease; |
---|
3901 | pDes[uiStride14] = (pDes[uiStride14]+offset)>>uiBitDepthIncrease; |
---|
3902 | pDes[uiStride15] = (pDes[uiStride15]+offset)>>uiBitDepthIncrease; |
---|
3903 | #endif |
---|
3904 | |
---|
3905 | } |
---|
3906 | } |
---|
3907 | |
---|
3908 | Void TComTrQuant::xIT32( Long* pSrc, Pel* pDes, UInt uiStride ) |
---|
3909 | { |
---|
3910 | Int x, y; |
---|
3911 | Long aaiTemp[32][32]; |
---|
3912 | |
---|
3913 | Long A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A20, A21, A22, A23, A24, A25, A26, A27; |
---|
3914 | Long B0, B1, B2, B3, B4, B5, B6, B7, B10, B11, B12, B13, B16, B17, B18, B19, B20, B21, B22, B23, B24, B25, B26, B27, B28, B29, B30, B31; |
---|
3915 | Long C0, C1, C2, C3, C5, C6, C8, C9, C10, C11, C12, C13, C14, C15, C18, C19, C20, C21, C26, C27, C28, C29; |
---|
3916 | Long D0, D1, D2, D3, D4, D5, D6, D7, D9, D10, D13, D14, D16, D17, D18, D19, D20, D21, D22, D23, D24, D25, D26, D27, D28, D29, D30, D31; |
---|
3917 | Long E4, E5, E6, E7, E8, E9, E10, E11, E12, E13, E14, E15, E17, E18, E21, E22, E25, E26, E29, E30; |
---|
3918 | Long F8, F9, F10, F11, F12, F13, F14, F15, F16, F17, F18, F19, F20, F21, F22, F23, F24, F25, F26, F27, F28, F29, F30, F31; |
---|
3919 | Long G16, G17, G18, G19, G20, G21, G22, G23, G24, G25, G26, G27, G28, G29, G30, G31; |
---|
3920 | |
---|
3921 | UInt uiStride2 = uiStride<<1; |
---|
3922 | UInt uiStride3 = uiStride2 + uiStride; |
---|
3923 | UInt uiStride4 = uiStride3 + uiStride; |
---|
3924 | UInt uiStride5 = uiStride4 + uiStride; |
---|
3925 | UInt uiStride6 = uiStride5 + uiStride; |
---|
3926 | UInt uiStride7 = uiStride6 + uiStride; |
---|
3927 | UInt uiStride8 = uiStride7 + uiStride; |
---|
3928 | UInt uiStride9 = uiStride8 + uiStride; |
---|
3929 | UInt uiStride10 = uiStride9 + uiStride; |
---|
3930 | UInt uiStride11 = uiStride10 + uiStride; |
---|
3931 | UInt uiStride12 = uiStride11 + uiStride; |
---|
3932 | UInt uiStride13 = uiStride12 + uiStride; |
---|
3933 | UInt uiStride14 = uiStride13 + uiStride; |
---|
3934 | UInt uiStride15 = uiStride14 + uiStride; |
---|
3935 | UInt uiStride16 = uiStride15 + uiStride; |
---|
3936 | UInt uiStride17 = uiStride16 + uiStride; |
---|
3937 | UInt uiStride18 = uiStride17 + uiStride; |
---|
3938 | UInt uiStride19 = uiStride18 + uiStride; |
---|
3939 | UInt uiStride20 = uiStride19 + uiStride; |
---|
3940 | UInt uiStride21 = uiStride20 + uiStride; |
---|
3941 | UInt uiStride22 = uiStride21 + uiStride; |
---|
3942 | UInt uiStride23 = uiStride22 + uiStride; |
---|
3943 | UInt uiStride24 = uiStride23 + uiStride; |
---|
3944 | UInt uiStride25 = uiStride24 + uiStride; |
---|
3945 | UInt uiStride26 = uiStride25 + uiStride; |
---|
3946 | UInt uiStride27 = uiStride26 + uiStride; |
---|
3947 | UInt uiStride28 = uiStride27 + uiStride; |
---|
3948 | UInt uiStride29 = uiStride28 + uiStride; |
---|
3949 | UInt uiStride30 = uiStride29 + uiStride; |
---|
3950 | UInt uiStride31 = uiStride30 + uiStride; |
---|
3951 | #ifdef TRANS_PRECISION_EXT |
---|
3952 | #if FULL_NBIT |
---|
3953 | Int uiBitDepthIncrease=g_iShift32x32-g_uiBitIncrement-g_uiBitDepth+8; |
---|
3954 | #else |
---|
3955 | Int uiBitDepthIncrease=g_iShift32x32-g_uiBitIncrement; |
---|
3956 | #endif |
---|
3957 | Int offset = (uiBitDepthIncrease==0)? 0:(1<<(uiBitDepthIncrease-1)); |
---|
3958 | #endif |
---|
3959 | //--Butterfly |
---|
3960 | for( y=0 ; y<32 ; y++ ) |
---|
3961 | { |
---|
3962 | #ifdef TRANS_PRECISION_EXT |
---|
3963 | Long ai0[32]; |
---|
3964 | ai0[0] = pSrc[0]<<uiBitDepthIncrease; |
---|
3965 | ai0[1] = pSrc[1]<<uiBitDepthIncrease; |
---|
3966 | ai0[2] = pSrc[2]<<uiBitDepthIncrease; |
---|
3967 | ai0[3] = pSrc[3]<<uiBitDepthIncrease; |
---|
3968 | ai0[4] = pSrc[4]<<uiBitDepthIncrease; |
---|
3969 | ai0[5] = pSrc[5]<<uiBitDepthIncrease; |
---|
3970 | ai0[6] = pSrc[6]<<uiBitDepthIncrease; |
---|
3971 | ai0[7] = pSrc[7]<<uiBitDepthIncrease; |
---|
3972 | ai0[8 ] = pSrc[8 ]<<uiBitDepthIncrease; |
---|
3973 | ai0[9 ] = pSrc[9 ]<<uiBitDepthIncrease; |
---|
3974 | ai0[10] = pSrc[10]<<uiBitDepthIncrease; |
---|
3975 | ai0[11] = pSrc[11]<<uiBitDepthIncrease; |
---|
3976 | ai0[12] = pSrc[12]<<uiBitDepthIncrease; |
---|
3977 | ai0[13] = pSrc[13]<<uiBitDepthIncrease; |
---|
3978 | ai0[14] = pSrc[14]<<uiBitDepthIncrease; |
---|
3979 | ai0[15] = pSrc[15]<<uiBitDepthIncrease; |
---|
3980 | ai0[16] = pSrc[16]<<uiBitDepthIncrease; |
---|
3981 | ai0[17] = pSrc[17]<<uiBitDepthIncrease; |
---|
3982 | ai0[18] = pSrc[18]<<uiBitDepthIncrease; |
---|
3983 | ai0[19] = pSrc[19]<<uiBitDepthIncrease; |
---|
3984 | ai0[20] = pSrc[20]<<uiBitDepthIncrease; |
---|
3985 | ai0[21] = pSrc[21]<<uiBitDepthIncrease; |
---|
3986 | ai0[22] = pSrc[22]<<uiBitDepthIncrease; |
---|
3987 | ai0[23] = pSrc[23]<<uiBitDepthIncrease; |
---|
3988 | ai0[24] = pSrc[24]<<uiBitDepthIncrease; |
---|
3989 | ai0[25] = pSrc[25]<<uiBitDepthIncrease; |
---|
3990 | ai0[26] = pSrc[26]<<uiBitDepthIncrease; |
---|
3991 | ai0[27] = pSrc[27]<<uiBitDepthIncrease; |
---|
3992 | ai0[28] = pSrc[28]<<uiBitDepthIncrease; |
---|
3993 | ai0[29] = pSrc[29]<<uiBitDepthIncrease; |
---|
3994 | ai0[30] = pSrc[30]<<uiBitDepthIncrease; |
---|
3995 | ai0[31] = pSrc[31]<<uiBitDepthIncrease; |
---|
3996 | G16 = xTrRound( 12 * ai0[1] - 255 * ai0[31], DenShift32); |
---|
3997 | G17 = xTrRound( 189 * ai0[17] - 171 * ai0[15], DenShift32); |
---|
3998 | G18 = xTrRound( 109 * ai0[9] - 231 * ai0[23], DenShift32); |
---|
3999 | G19 = xTrRound( 241 * ai0[25] - 86 * ai0[7], DenShift32); |
---|
4000 | G20 = xTrRound( 62 * ai0[5] - 248 * ai0[27], DenShift32); |
---|
4001 | G21 = xTrRound( 219 * ai0[21] - 131 * ai0[11], DenShift32); |
---|
4002 | G22 = xTrRound( 152 * ai0[13] - 205 * ai0[19], DenShift32); |
---|
4003 | G23 = xTrRound( 253 * ai0[29] - 37 * ai0[3], DenShift32); |
---|
4004 | G24 = xTrRound( 253 * ai0[3] + 37 * ai0[29], DenShift32); |
---|
4005 | G25 = xTrRound( 152 * ai0[19] + 205 * ai0[13], DenShift32); |
---|
4006 | G26 = xTrRound( 219 * ai0[11] + 131 * ai0[21], DenShift32); |
---|
4007 | G27 = xTrRound( 62 * ai0[27] + 248 * ai0[5], DenShift32); |
---|
4008 | G28 = xTrRound( 241 * ai0[7] + 86 * ai0[25], DenShift32); |
---|
4009 | G29 = xTrRound( 109 * ai0[23] + 231 * ai0[9], DenShift32); |
---|
4010 | G30 = xTrRound( 189 * ai0[15] + 171 * ai0[17], DenShift32); |
---|
4011 | G31 = xTrRound( 12 * ai0[31] + 255 * ai0[1], DenShift32); |
---|
4012 | |
---|
4013 | F8 = xTrRound( 25 * ai0[2] - 254 * ai0[30], DenShift32); |
---|
4014 | F9 = xTrRound( 197 * ai0[18] - 162 * ai0[14], DenShift32); |
---|
4015 | F10 = xTrRound( 120 * ai0[10] - 225 * ai0[22], DenShift32); |
---|
4016 | F11 = xTrRound( 244 * ai0[26] - 74 * ai0[6], DenShift32); |
---|
4017 | F12 = xTrRound( 244 * ai0[6] + 74 * ai0[26], DenShift32); |
---|
4018 | F13 = xTrRound( 120 * ai0[22] + 225 * ai0[10], DenShift32); |
---|
4019 | F14 = xTrRound( 197 * ai0[14] + 162 * ai0[18], DenShift32); |
---|
4020 | F15 = xTrRound( 25 * ai0[30] + 254 * ai0[2], DenShift32); |
---|
4021 | #else |
---|
4022 | G16 = xTrRound( 12 * pSrc[1] - 255 * pSrc[31], DenShift32); |
---|
4023 | G17 = xTrRound( 189 * pSrc[17] - 171 * pSrc[15], DenShift32); |
---|
4024 | G18 = xTrRound( 109 * pSrc[9] - 231 * pSrc[23], DenShift32); |
---|
4025 | G19 = xTrRound( 241 * pSrc[25] - 86 * pSrc[7], DenShift32); |
---|
4026 | G20 = xTrRound( 62 * pSrc[5] - 248 * pSrc[27], DenShift32); |
---|
4027 | G21 = xTrRound( 219 * pSrc[21] - 131 * pSrc[11], DenShift32); |
---|
4028 | G22 = xTrRound( 152 * pSrc[13] - 205 * pSrc[19], DenShift32); |
---|
4029 | G23 = xTrRound( 253 * pSrc[29] - 37 * pSrc[3], DenShift32); |
---|
4030 | G24 = xTrRound( 253 * pSrc[3] + 37 * pSrc[29], DenShift32); |
---|
4031 | G25 = xTrRound( 152 * pSrc[19] + 205 * pSrc[13], DenShift32); |
---|
4032 | G26 = xTrRound( 219 * pSrc[11] + 131 * pSrc[21], DenShift32); |
---|
4033 | G27 = xTrRound( 62 * pSrc[27] + 248 * pSrc[5], DenShift32); |
---|
4034 | G28 = xTrRound( 241 * pSrc[7] + 86 * pSrc[25], DenShift32); |
---|
4035 | G29 = xTrRound( 109 * pSrc[23] + 231 * pSrc[9], DenShift32); |
---|
4036 | G30 = xTrRound( 189 * pSrc[15] + 171 * pSrc[17], DenShift32); |
---|
4037 | G31 = xTrRound( 12 * pSrc[31] + 255 * pSrc[1], DenShift32); |
---|
4038 | |
---|
4039 | F8 = xTrRound( 25 * pSrc[2] - 254 * pSrc[30], DenShift32); |
---|
4040 | F9 = xTrRound( 197 * pSrc[18] - 162 * pSrc[14], DenShift32); |
---|
4041 | F10 = xTrRound( 120 * pSrc[10] - 225 * pSrc[22], DenShift32); |
---|
4042 | F11 = xTrRound( 244 * pSrc[26] - 74 * pSrc[6], DenShift32); |
---|
4043 | F12 = xTrRound( 244 * pSrc[6] + 74 * pSrc[26], DenShift32); |
---|
4044 | F13 = xTrRound( 120 * pSrc[22] + 225 * pSrc[10], DenShift32); |
---|
4045 | F14 = xTrRound( 197 * pSrc[14] + 162 * pSrc[18], DenShift32); |
---|
4046 | F15 = xTrRound( 25 * pSrc[30] + 254 * pSrc[2], DenShift32); |
---|
4047 | #endif |
---|
4048 | F16 = G16 + G17; |
---|
4049 | F17 = G16 - G17; |
---|
4050 | F18 = G19 - G18; |
---|
4051 | F19 = G19 + G18; |
---|
4052 | F20 = G20 + G21; |
---|
4053 | F21 = G20 - G21; |
---|
4054 | F22 = G23 - G22; |
---|
4055 | F23 = G23 + G22; |
---|
4056 | F24 = G24 + G25; |
---|
4057 | F25 = G24 - G25; |
---|
4058 | F26 = G27 - G26; |
---|
4059 | F27 = G27 + G26; |
---|
4060 | F28 = G28 + G29; |
---|
4061 | F29 = G28 - G29; |
---|
4062 | F30 = G31 - G30; |
---|
4063 | F31 = G31 + G30; |
---|
4064 | #ifdef TRANS_PRECISION_EXT |
---|
4065 | E4 = xTrRound( 49 * ai0[4] - 251 * ai0[28], DenShift32); |
---|
4066 | E5 = xTrRound( 212 * ai0[20] - 142 * ai0[12], DenShift32); |
---|
4067 | E6 = xTrRound( 212 * ai0[12] + 142 * ai0[20], DenShift32); |
---|
4068 | E7 = xTrRound( 49 * ai0[28] + 251 * ai0[4], DenShift32); |
---|
4069 | #else |
---|
4070 | E4 = xTrRound( 49 * pSrc[4] - 251 * pSrc[28], DenShift32); |
---|
4071 | E5 = xTrRound( 212 * pSrc[20] - 142 * pSrc[12], DenShift32); |
---|
4072 | E6 = xTrRound( 212 * pSrc[12] + 142 * pSrc[20], DenShift32); |
---|
4073 | E7 = xTrRound( 49 * pSrc[28] + 251 * pSrc[4], DenShift32); |
---|
4074 | #endif |
---|
4075 | E8 = F8 + F9; |
---|
4076 | E9 = F8 - F9; |
---|
4077 | E10 = F11 - F10; |
---|
4078 | E11 = F11 + F10; |
---|
4079 | E12 = F12 + F13; |
---|
4080 | E13 = F12 - F13; |
---|
4081 | E14 = F15 - F14; |
---|
4082 | E15 = F15 + F14; |
---|
4083 | E17 = xTrRound( 49 * F30 - 251 * F17, DenShift32); |
---|
4084 | E18 = xTrRound( - 251 * F29 - 49 * F18, DenShift32); |
---|
4085 | E21 = xTrRound( 212 * F26 - 142 * F21, DenShift32); |
---|
4086 | E22 = xTrRound( - 142 * F25 - 212 * F22, DenShift32); |
---|
4087 | E25 = xTrRound( 212 * F25 - 142 * F22, DenShift32); |
---|
4088 | E26 = xTrRound( 142 * F26 + 212 * F21, DenShift32); |
---|
4089 | E29 = xTrRound( 49 * F29 - 251 * F18, DenShift32); |
---|
4090 | E30 = xTrRound( 251 * F30 + 49 * F17, DenShift32); |
---|
4091 | #ifdef TRANS_PRECISION_EXT |
---|
4092 | D0 = xTrRound( 181 * ( ai0[0] + ai0[16] ), DenShift32); |
---|
4093 | D1 = xTrRound( 181 * ( ai0[0] - ai0[16] ), DenShift32); |
---|
4094 | D2 = xTrRound( 97 * ai0[8] - 236 * ai0[24], DenShift32); |
---|
4095 | D3 = xTrRound( 236 * ai0[8] + 97 * ai0[24], DenShift32); |
---|
4096 | #else |
---|
4097 | D0 = xTrRound( 181 * ( pSrc[0] + pSrc[16] ), DenShift32); |
---|
4098 | D1 = xTrRound( 181 * ( pSrc[0] - pSrc[16] ), DenShift32); |
---|
4099 | D2 = xTrRound( 97 * pSrc[8] - 236 * pSrc[24], DenShift32); |
---|
4100 | D3 = xTrRound( 236 * pSrc[8] + 97 * pSrc[24], DenShift32); |
---|
4101 | #endif |
---|
4102 | D4 = E4 + E5; |
---|
4103 | D5 = E4 - E5; |
---|
4104 | D6 = E7 - E6; |
---|
4105 | D7 = E7 + E6; |
---|
4106 | D9 = xTrRound( 97 * E14 - 236 * E9, DenShift32); |
---|
4107 | D10 = xTrRound( - 236 * E13 - 97 * E10, DenShift32); |
---|
4108 | D13 = xTrRound( 97 * E13 - 236 * E10, DenShift32); |
---|
4109 | D14 = xTrRound( 236 * E14 + 97 * E9, DenShift32); |
---|
4110 | D16 = F16 + F19; |
---|
4111 | D19 = F16 - F19; |
---|
4112 | D20 = F23 - F20; |
---|
4113 | D23 = F23 + F20; |
---|
4114 | D24 = F24 + F27; |
---|
4115 | D27 = F24 - F27; |
---|
4116 | D28 = F31 - F28; |
---|
4117 | D31 = F31 + F28; |
---|
4118 | D17 = E17 + E18; |
---|
4119 | D18 = E17 - E18; |
---|
4120 | D21 = E22 - E21; |
---|
4121 | D22 = E22 + E21; |
---|
4122 | D25 = E25 + E26; |
---|
4123 | D26 = E25 - E26; |
---|
4124 | D29 = E30 - E29; |
---|
4125 | D30 = E30 + E29; |
---|
4126 | |
---|
4127 | C0 = D0 + D3; |
---|
4128 | C3 = D0 - D3; |
---|
4129 | C8 = E8 + E11; |
---|
4130 | C11 = E8 - E11; |
---|
4131 | C12 = E15 - E12; |
---|
4132 | C15 = E15 + E12; |
---|
4133 | C1 = D1 + D2; |
---|
4134 | C2 = D1 - D2; |
---|
4135 | C9 = D9 + D10; |
---|
4136 | C10 = D9 - D10; |
---|
4137 | C13 = D14 - D13; |
---|
4138 | C14 = D14 + D13; |
---|
4139 | C5 = xTrRound( 181 * ( D6 - D5 ), DenShift32); |
---|
4140 | C6 = xTrRound( 181 * ( D6 + D5 ), DenShift32); |
---|
4141 | C18 = xTrRound( 97 * D29 - 236 * D18, DenShift32); |
---|
4142 | C20 = xTrRound( - 236 * D27 - 97 * D20, DenShift32); |
---|
4143 | C26 = xTrRound( - 236 * D21 + 97 * D26, DenShift32); |
---|
4144 | C28 = xTrRound( 97 * D19 + 236 * D28, DenShift32); |
---|
4145 | C19 = xTrRound( 97 * D28 - 236 * D19, DenShift32); |
---|
4146 | C21 = xTrRound( - 236 * D26 - 97 * D21, DenShift32); |
---|
4147 | C27 = xTrRound( - 236 * D20 + 97 * D27, DenShift32); |
---|
4148 | C29 = xTrRound( 97 * D18 + 236 * D29, DenShift32); |
---|
4149 | |
---|
4150 | B0 = C0 + D7; |
---|
4151 | B7 = C0 - D7; |
---|
4152 | B1 = C1 + C6; |
---|
4153 | B6 = C1 - C6; |
---|
4154 | B2 = C2 + C5; |
---|
4155 | B5 = C2 - C5; |
---|
4156 | B3 = C3 + D4; |
---|
4157 | B4 = C3 - D4; |
---|
4158 | B10 = xTrRound( 181 * ( C13 - C10 ), DenShift32); |
---|
4159 | B13 = xTrRound( 181 * ( C13 + C10 ), DenShift32); |
---|
4160 | B11 = xTrRound( 181 * ( C12 - C11 ), DenShift32); |
---|
4161 | B12 = xTrRound( 181 * ( C12 + C11 ), DenShift32); |
---|
4162 | B16 = D16 + D23; |
---|
4163 | B23 = D16 - D23; |
---|
4164 | B24 = D31 - D24; |
---|
4165 | B31 = D31 + D24; |
---|
4166 | B17 = D17 + D22; |
---|
4167 | B22 = D17 - D22; |
---|
4168 | B25 = D30 - D25; |
---|
4169 | B30 = D30 + D25; |
---|
4170 | B18 = C18 + C21; |
---|
4171 | B21 = C18 - C21; |
---|
4172 | B26 = C29 - C26; |
---|
4173 | B29 = C29 + C26; |
---|
4174 | B19 = C19 + C20; |
---|
4175 | B20 = C19 - C20; |
---|
4176 | B27 = C28 - C27; |
---|
4177 | B28 = C28 + C27; |
---|
4178 | |
---|
4179 | A0 = B0 + C15; |
---|
4180 | A15 = B0 - C15; |
---|
4181 | A1 = B1 + C14; |
---|
4182 | A14 = B1 - C14; |
---|
4183 | A2 = B2 + B13; |
---|
4184 | A13 = B2 - B13; |
---|
4185 | A3 = B3 + B12; |
---|
4186 | A12 = B3 - B12; |
---|
4187 | A4 = B4 + B11; |
---|
4188 | A11 = B4 - B11; |
---|
4189 | A5 = B5 + B10; |
---|
4190 | A10 = B5 - B10; |
---|
4191 | A6 = B6 + C9; |
---|
4192 | A9 = B6 - C9; |
---|
4193 | A7 = B7 + C8; |
---|
4194 | A8 = B7 - C8; |
---|
4195 | A20 = xTrRound( 181 * ( B27 - B20 ), DenShift32); |
---|
4196 | A27 = xTrRound( 181 * ( B27 + B20 ), DenShift32); |
---|
4197 | A21 = xTrRound( 181 * ( B26 - B21 ), DenShift32); |
---|
4198 | A26 = xTrRound( 181 * ( B26 + B21 ), DenShift32); |
---|
4199 | A22 = xTrRound( 181 * ( B25 - B22 ), DenShift32); |
---|
4200 | A25 = xTrRound( 181 * ( B25 + B22 ), DenShift32); |
---|
4201 | A23 = xTrRound( 181 * ( B24 - B23 ), DenShift32); |
---|
4202 | A24 = xTrRound( 181 * ( B24 + B23 ), DenShift32); |
---|
4203 | |
---|
4204 | aaiTemp[0][y] = A0 + B31; |
---|
4205 | aaiTemp[31][y] = A0 - B31; |
---|
4206 | aaiTemp[1][y] = A1 + B30; |
---|
4207 | aaiTemp[30][y] = A1 - B30; |
---|
4208 | aaiTemp[2][y] = A2 + B29; |
---|
4209 | aaiTemp[29][y] = A2 - B29; |
---|
4210 | aaiTemp[3][y] = A3 + B28; |
---|
4211 | aaiTemp[28][y] = A3 - B28; |
---|
4212 | aaiTemp[4][y] = A4 + A27; |
---|
4213 | aaiTemp[27][y] = A4 - A27; |
---|
4214 | aaiTemp[5][y] = A5 + A26; |
---|
4215 | aaiTemp[26][y] = A5 - A26; |
---|
4216 | aaiTemp[6][y] = A6 + A25; |
---|
4217 | aaiTemp[25][y] = A6 - A25; |
---|
4218 | aaiTemp[7][y] = A7 + A24; |
---|
4219 | aaiTemp[24][y] = A7 - A24; |
---|
4220 | aaiTemp[8][y] = A8 + A23; |
---|
4221 | aaiTemp[23][y] = A8 - A23; |
---|
4222 | aaiTemp[9][y] = A9 + A22; |
---|
4223 | aaiTemp[22][y] = A9 - A22; |
---|
4224 | aaiTemp[10][y] = A10 + A21; |
---|
4225 | aaiTemp[21][y] = A10 - A21; |
---|
4226 | aaiTemp[11][y] = A11 + A20; |
---|
4227 | aaiTemp[20][y] = A11 - A20; |
---|
4228 | aaiTemp[12][y] = A12 + B19; |
---|
4229 | aaiTemp[19][y] = A12 - B19; |
---|
4230 | aaiTemp[13][y] = A13 + B18; |
---|
4231 | aaiTemp[18][y] = A13 - B18; |
---|
4232 | aaiTemp[14][y] = A14 + B17; |
---|
4233 | aaiTemp[17][y] = A14 - B17; |
---|
4234 | aaiTemp[15][y] = A15 + B16; |
---|
4235 | aaiTemp[16][y] = A15 - B16; |
---|
4236 | |
---|
4237 | pSrc += 32; |
---|
4238 | } |
---|
4239 | |
---|
4240 | for( x=0 ; x<32 ; x++, pDes++ ) |
---|
4241 | { |
---|
4242 | G16 = xTrRound( 12 * aaiTemp[x][1] - 255 * aaiTemp[x][31], DenShift32); |
---|
4243 | G17 = xTrRound( 189 * aaiTemp[x][17] - 171 * aaiTemp[x][15], DenShift32); |
---|
4244 | G18 = xTrRound( 109 * aaiTemp[x][9] - 231 * aaiTemp[x][23], DenShift32); |
---|
4245 | G19 = xTrRound( 241 * aaiTemp[x][25] - 86 * aaiTemp[x][7], DenShift32); |
---|
4246 | G20 = xTrRound( 62 * aaiTemp[x][5] - 248 * aaiTemp[x][27], DenShift32); |
---|
4247 | G21 = xTrRound( 219 * aaiTemp[x][21] - 131 * aaiTemp[x][11], DenShift32); |
---|
4248 | G22 = xTrRound( 152 * aaiTemp[x][13] - 205 * aaiTemp[x][19], DenShift32); |
---|
4249 | G23 = xTrRound( 253 * aaiTemp[x][29] - 37 * aaiTemp[x][3], DenShift32); |
---|
4250 | G24 = xTrRound( 253 * aaiTemp[x][3] + 37 * aaiTemp[x][29], DenShift32); |
---|
4251 | G25 = xTrRound( 152 * aaiTemp[x][19] + 205 * aaiTemp[x][13], DenShift32); |
---|
4252 | G26 = xTrRound( 219 * aaiTemp[x][11] + 131 * aaiTemp[x][21], DenShift32); |
---|
4253 | G27 = xTrRound( 62 * aaiTemp[x][27] + 248 * aaiTemp[x][5], DenShift32); |
---|
4254 | G28 = xTrRound( 241 * aaiTemp[x][7] + 86 * aaiTemp[x][25], DenShift32); |
---|
4255 | G29 = xTrRound( 109 * aaiTemp[x][23] + 231 * aaiTemp[x][9], DenShift32); |
---|
4256 | G30 = xTrRound( 189 * aaiTemp[x][15] + 171 * aaiTemp[x][17], DenShift32); |
---|
4257 | G31 = xTrRound( 12 * aaiTemp[x][31] + 255 * aaiTemp[x][1], DenShift32); |
---|
4258 | |
---|
4259 | F8 = xTrRound( 25 * aaiTemp[x][2] - 254 * aaiTemp[x][30], DenShift32); |
---|
4260 | F9 = xTrRound( 197 * aaiTemp[x][18] - 162 * aaiTemp[x][14], DenShift32); |
---|
4261 | F10 = xTrRound( 120 * aaiTemp[x][10] - 225 * aaiTemp[x][22], DenShift32); |
---|
4262 | F11 = xTrRound( 244 * aaiTemp[x][26] - 74 * aaiTemp[x][6], DenShift32); |
---|
4263 | F12 = xTrRound( 244 * aaiTemp[x][6] + 74 * aaiTemp[x][26], DenShift32); |
---|
4264 | F13 = xTrRound( 120 * aaiTemp[x][22] + 225 * aaiTemp[x][10], DenShift32); |
---|
4265 | F14 = xTrRound( 197 * aaiTemp[x][14] + 162 * aaiTemp[x][18], DenShift32); |
---|
4266 | F15 = xTrRound( 25 * aaiTemp[x][30] + 254 * aaiTemp[x][2], DenShift32); |
---|
4267 | F16 = G16 + G17; |
---|
4268 | F17 = G16 - G17; |
---|
4269 | F18 = G19 - G18; |
---|
4270 | F19 = G19 + G18; |
---|
4271 | F20 = G20 + G21; |
---|
4272 | F21 = G20 - G21; |
---|
4273 | F22 = G23 - G22; |
---|
4274 | F23 = G23 + G22; |
---|
4275 | F24 = G24 + G25; |
---|
4276 | F25 = G24 - G25; |
---|
4277 | F26 = G27 - G26; |
---|
4278 | F27 = G27 + G26; |
---|
4279 | F28 = G28 + G29; |
---|
4280 | F29 = G28 - G29; |
---|
4281 | F30 = G31 - G30; |
---|
4282 | F31 = G31 + G30; |
---|
4283 | |
---|
4284 | E4 = xTrRound( 49 * aaiTemp[x][4] - 251 * aaiTemp[x][28], DenShift32); |
---|
4285 | E5 = xTrRound( 212 * aaiTemp[x][20] - 142 * aaiTemp[x][12], DenShift32); |
---|
4286 | E6 = xTrRound( 212 * aaiTemp[x][12] + 142 * aaiTemp[x][20], DenShift32); |
---|
4287 | E7 = xTrRound( 49 * aaiTemp[x][28] + 251 * aaiTemp[x][4], DenShift32); |
---|
4288 | E8 = F8 + F9; |
---|
4289 | E9 = F8 - F9; |
---|
4290 | E10 = F11 - F10; |
---|
4291 | E11 = F11 + F10; |
---|
4292 | E12 = F12 + F13; |
---|
4293 | E13 = F12 - F13; |
---|
4294 | E14 = F15 - F14; |
---|
4295 | E15 = F15 + F14; |
---|
4296 | E17 = xTrRound( 49 * F30 - 251 * F17, DenShift32); |
---|
4297 | E18 = xTrRound( - 251 * F29 - 49 * F18, DenShift32); |
---|
4298 | E21 = xTrRound( 212 * F26 - 142 * F21, DenShift32); |
---|
4299 | E22 = xTrRound( - 142 * F25 - 212 * F22, DenShift32); |
---|
4300 | E25 = xTrRound( 212 * F25 - 142 * F22, DenShift32); |
---|
4301 | E26 = xTrRound( 142 * F26 + 212 * F21, DenShift32); |
---|
4302 | E29 = xTrRound( 49 * F29 - 251 * F18, DenShift32); |
---|
4303 | E30 = xTrRound( 251 * F30 + 49 * F17, DenShift32); |
---|
4304 | |
---|
4305 | D0 = xTrRound( 181 * ( aaiTemp[x][0] + aaiTemp[x][16] ), DenShift32); |
---|
4306 | D1 = xTrRound( 181 * ( aaiTemp[x][0] - aaiTemp[x][16] ), DenShift32); |
---|
4307 | D2 = xTrRound( 97 * aaiTemp[x][8] - 236 * aaiTemp[x][24], DenShift32); |
---|
4308 | D3 = xTrRound( 236 * aaiTemp[x][8] + 97 * aaiTemp[x][24], DenShift32); |
---|
4309 | D4 = E4 + E5; |
---|
4310 | D5 = E4 - E5; |
---|
4311 | D6 = E7 - E6; |
---|
4312 | D7 = E7 + E6; |
---|
4313 | D9 = xTrRound( 97 * E14 - 236 * E9, DenShift32); |
---|
4314 | D10 = xTrRound( - 236 * E13 - 97 * E10, DenShift32); |
---|
4315 | D13 = xTrRound( 97 * E13 - 236 * E10, DenShift32); |
---|
4316 | D14 = xTrRound( 236 * E14 + 97 * E9, DenShift32); |
---|
4317 | D16 = F16 + F19; |
---|
4318 | D19 = F16 - F19; |
---|
4319 | D20 = F23 - F20; |
---|
4320 | D23 = F23 + F20; |
---|
4321 | D24 = F24 + F27; |
---|
4322 | D27 = F24 - F27; |
---|
4323 | D28 = F31 - F28; |
---|
4324 | D31 = F31 + F28; |
---|
4325 | D17 = E17 + E18; |
---|
4326 | D18 = E17 - E18; |
---|
4327 | D21 = E22 - E21; |
---|
4328 | D22 = E22 + E21; |
---|
4329 | D25 = E25 + E26; |
---|
4330 | D26 = E25 - E26; |
---|
4331 | D29 = E30 - E29; |
---|
4332 | D30 = E30 + E29; |
---|
4333 | |
---|
4334 | C0 = D0 + D3; |
---|
4335 | C3 = D0 - D3; |
---|
4336 | C8 = E8 + E11; |
---|
4337 | C11 = E8 - E11; |
---|
4338 | C12 = E15 - E12; |
---|
4339 | C15 = E15 + E12; |
---|
4340 | C1 = D1 + D2; |
---|
4341 | C2 = D1 - D2; |
---|
4342 | C9 = D9 + D10; |
---|
4343 | C10 = D9 - D10; |
---|
4344 | C13 = D14 - D13; |
---|
4345 | C14 = D14 + D13; |
---|
4346 | C5 = xTrRound( 181 * ( D6 - D5 ), DenShift32); |
---|
4347 | C6 = xTrRound( 181 * ( D6 + D5 ), DenShift32); |
---|
4348 | C18 = xTrRound( 97 * D29 - 236 * D18, DenShift32); |
---|
4349 | C20 = xTrRound( - 236 * D27 - 97 * D20, DenShift32); |
---|
4350 | C26 = xTrRound( - 236 * D21 + 97 * D26, DenShift32); |
---|
4351 | C28 = xTrRound( 97 * D19 + 236 * D28, DenShift32); |
---|
4352 | C19 = xTrRound( 97 * D28 - 236 * D19, DenShift32); |
---|
4353 | C21 = xTrRound( - 236 * D26 - 97 * D21, DenShift32); |
---|
4354 | C27 = xTrRound( - 236 * D20 + 97 * D27, DenShift32); |
---|
4355 | C29 = xTrRound( 97 * D18 + 236 * D29, DenShift32); |
---|
4356 | |
---|
4357 | B0 = C0 + D7; |
---|
4358 | B7 = C0 - D7; |
---|
4359 | B1 = C1 + C6; |
---|
4360 | B6 = C1 - C6; |
---|
4361 | B2 = C2 + C5; |
---|
4362 | B5 = C2 - C5; |
---|
4363 | B3 = C3 + D4; |
---|
4364 | B4 = C3 - D4; |
---|
4365 | B10 = xTrRound( 181 * ( C13 - C10 ), DenShift32); |
---|
4366 | B13 = xTrRound( 181 * ( C13 + C10 ), DenShift32); |
---|
4367 | B11 = xTrRound( 181 * ( C12 - C11 ), DenShift32); |
---|
4368 | B12 = xTrRound( 181 * ( C12 + C11 ), DenShift32); |
---|
4369 | B16 = D16 + D23; |
---|
4370 | B23 = D16 - D23; |
---|
4371 | B24 = D31 - D24; |
---|
4372 | B31 = D31 + D24; |
---|
4373 | B17 = D17 + D22; |
---|
4374 | B22 = D17 - D22; |
---|
4375 | B25 = D30 - D25; |
---|
4376 | B30 = D30 + D25; |
---|
4377 | B18 = C18 + C21; |
---|
4378 | B21 = C18 - C21; |
---|
4379 | B26 = C29 - C26; |
---|
4380 | B29 = C29 + C26; |
---|
4381 | B19 = C19 + C20; |
---|
4382 | B20 = C19 - C20; |
---|
4383 | B27 = C28 - C27; |
---|
4384 | B28 = C28 + C27; |
---|
4385 | |
---|
4386 | A0 = B0 + C15; |
---|
4387 | A15 = B0 - C15; |
---|
4388 | A1 = B1 + C14; |
---|
4389 | A14 = B1 - C14; |
---|
4390 | A2 = B2 + B13; |
---|
4391 | A13 = B2 - B13; |
---|
4392 | A3 = B3 + B12; |
---|
4393 | A12 = B3 - B12; |
---|
4394 | A4 = B4 + B11; |
---|
4395 | A11 = B4 - B11; |
---|
4396 | A5 = B5 + B10; |
---|
4397 | A10 = B5 - B10; |
---|
4398 | A6 = B6 + C9; |
---|
4399 | A9 = B6 - C9; |
---|
4400 | A7 = B7 + C8; |
---|
4401 | A8 = B7 - C8; |
---|
4402 | A20 = xTrRound( 181 * ( B27 - B20 ), DenShift32); |
---|
4403 | A27 = xTrRound( 181 * ( B27 + B20 ), DenShift32); |
---|
4404 | A21 = xTrRound( 181 * ( B26 - B21 ), DenShift32); |
---|
4405 | A26 = xTrRound( 181 * ( B26 + B21 ), DenShift32); |
---|
4406 | A22 = xTrRound( 181 * ( B25 - B22 ), DenShift32); |
---|
4407 | A25 = xTrRound( 181 * ( B25 + B22 ), DenShift32); |
---|
4408 | A23 = xTrRound( 181 * ( B24 - B23 ), DenShift32); |
---|
4409 | A24 = xTrRound( 181 * ( B24 + B23 ), DenShift32); |
---|
4410 | |
---|
4411 | pDes[ 0] = (Pel)xTrRound( A0 + B31 , DCore32Shift); |
---|
4412 | pDes[uiStride31] = (Pel)xTrRound( A0 - B31 , DCore32Shift); |
---|
4413 | pDes[uiStride ] = (Pel)xTrRound( A1 + B30 , DCore32Shift); |
---|
4414 | pDes[uiStride30] = (Pel)xTrRound( A1 - B30 , DCore32Shift); |
---|
4415 | pDes[uiStride2 ] = (Pel)xTrRound( A2 + B29 , DCore32Shift); |
---|
4416 | pDes[uiStride29] = (Pel)xTrRound( A2 - B29 , DCore32Shift); |
---|
4417 | pDes[uiStride3 ] = (Pel)xTrRound( A3 + B28 , DCore32Shift); |
---|
4418 | pDes[uiStride28] = (Pel)xTrRound( A3 - B28 , DCore32Shift); |
---|
4419 | pDes[uiStride4 ] = (Pel)xTrRound( A4 + A27 , DCore32Shift); |
---|
4420 | pDes[uiStride27] = (Pel)xTrRound( A4 - A27 , DCore32Shift); |
---|
4421 | pDes[uiStride5 ] = (Pel)xTrRound( A5 + A26 , DCore32Shift); |
---|
4422 | pDes[uiStride26] = (Pel)xTrRound( A5 - A26 , DCore32Shift); |
---|
4423 | pDes[uiStride6 ] = (Pel)xTrRound( A6 + A25 , DCore32Shift); |
---|
4424 | pDes[uiStride25] = (Pel)xTrRound( A6 - A25 , DCore32Shift); |
---|
4425 | pDes[uiStride7 ] = (Pel)xTrRound( A7 + A24 , DCore32Shift); |
---|
4426 | pDes[uiStride24] = (Pel)xTrRound( A7 - A24 , DCore32Shift); |
---|
4427 | pDes[uiStride8 ] = (Pel)xTrRound( A8 + A23 , DCore32Shift); |
---|
4428 | pDes[uiStride23] = (Pel)xTrRound( A8 - A23 , DCore32Shift); |
---|
4429 | pDes[uiStride9 ] = (Pel)xTrRound( A9 + A22 , DCore32Shift); |
---|
4430 | pDes[uiStride22] = (Pel)xTrRound( A9 - A22 , DCore32Shift); |
---|
4431 | pDes[uiStride10] = (Pel)xTrRound( A10 + A21 , DCore32Shift); |
---|
4432 | pDes[uiStride21] = (Pel)xTrRound( A10 - A21 , DCore32Shift); |
---|
4433 | pDes[uiStride11] = (Pel)xTrRound( A11 + A20 , DCore32Shift); |
---|
4434 | pDes[uiStride20] = (Pel)xTrRound( A11 - A20 , DCore32Shift); |
---|
4435 | pDes[uiStride12] = (Pel)xTrRound( A12 + B19 , DCore32Shift); |
---|
4436 | pDes[uiStride19] = (Pel)xTrRound( A12 - B19 , DCore32Shift); |
---|
4437 | pDes[uiStride13] = (Pel)xTrRound( A13 + B18 , DCore32Shift); |
---|
4438 | pDes[uiStride18] = (Pel)xTrRound( A13 - B18 , DCore32Shift); |
---|
4439 | pDes[uiStride14] = (Pel)xTrRound( A14 + B17 , DCore32Shift); |
---|
4440 | pDes[uiStride17] = (Pel)xTrRound( A14 - B17 , DCore32Shift); |
---|
4441 | pDes[uiStride15] = (Pel)xTrRound( A15 + B16 , DCore32Shift); |
---|
4442 | pDes[uiStride16] = (Pel)xTrRound( A15 - B16 , DCore32Shift); |
---|
4443 | |
---|
4444 | #ifdef TRANS_PRECISION_EXT |
---|
4445 | pDes[ 0 ] = (pDes[ 0 ]+offset)>>uiBitDepthIncrease; |
---|
4446 | pDes[uiStride ] = (pDes[uiStride ]+offset)>>uiBitDepthIncrease; |
---|
4447 | pDes[uiStride2 ] = (pDes[uiStride2 ]+offset)>>uiBitDepthIncrease; |
---|
4448 | pDes[uiStride3 ] = (pDes[uiStride3 ]+offset)>>uiBitDepthIncrease; |
---|
4449 | pDes[uiStride4 ] = (pDes[uiStride4 ]+offset)>>uiBitDepthIncrease; |
---|
4450 | pDes[uiStride5 ] = (pDes[uiStride5 ]+offset)>>uiBitDepthIncrease; |
---|
4451 | pDes[uiStride6 ] = (pDes[uiStride6 ]+offset)>>uiBitDepthIncrease; |
---|
4452 | pDes[uiStride7 ] = (pDes[uiStride7 ]+offset)>>uiBitDepthIncrease; |
---|
4453 | pDes[uiStride8 ] = (pDes[uiStride8 ]+offset)>>uiBitDepthIncrease; |
---|
4454 | pDes[uiStride9 ] = (pDes[uiStride9 ]+offset)>>uiBitDepthIncrease; |
---|
4455 | pDes[uiStride10] = (pDes[uiStride10]+offset)>>uiBitDepthIncrease; |
---|
4456 | pDes[uiStride11] = (pDes[uiStride11]+offset)>>uiBitDepthIncrease; |
---|
4457 | pDes[uiStride12] = (pDes[uiStride12]+offset)>>uiBitDepthIncrease; |
---|
4458 | pDes[uiStride13] = (pDes[uiStride13]+offset)>>uiBitDepthIncrease; |
---|
4459 | pDes[uiStride14] = (pDes[uiStride14]+offset)>>uiBitDepthIncrease; |
---|
4460 | pDes[uiStride15] = (pDes[uiStride15]+offset)>>uiBitDepthIncrease; |
---|
4461 | pDes[uiStride16] = (pDes[uiStride16]+offset)>>uiBitDepthIncrease; |
---|
4462 | pDes[uiStride17] = (pDes[uiStride17]+offset)>>uiBitDepthIncrease; |
---|
4463 | pDes[uiStride18] = (pDes[uiStride18]+offset)>>uiBitDepthIncrease; |
---|
4464 | pDes[uiStride19] = (pDes[uiStride19]+offset)>>uiBitDepthIncrease; |
---|
4465 | pDes[uiStride20] = (pDes[uiStride20]+offset)>>uiBitDepthIncrease; |
---|
4466 | pDes[uiStride21] = (pDes[uiStride21]+offset)>>uiBitDepthIncrease; |
---|
4467 | pDes[uiStride22] = (pDes[uiStride22]+offset)>>uiBitDepthIncrease; |
---|
4468 | pDes[uiStride23] = (pDes[uiStride23]+offset)>>uiBitDepthIncrease; |
---|
4469 | pDes[uiStride24] = (pDes[uiStride24]+offset)>>uiBitDepthIncrease; |
---|
4470 | pDes[uiStride25] = (pDes[uiStride25]+offset)>>uiBitDepthIncrease; |
---|
4471 | pDes[uiStride26] = (pDes[uiStride26]+offset)>>uiBitDepthIncrease; |
---|
4472 | pDes[uiStride27] = (pDes[uiStride27]+offset)>>uiBitDepthIncrease; |
---|
4473 | pDes[uiStride28] = (pDes[uiStride28]+offset)>>uiBitDepthIncrease; |
---|
4474 | pDes[uiStride29] = (pDes[uiStride29]+offset)>>uiBitDepthIncrease; |
---|
4475 | pDes[uiStride30] = (pDes[uiStride30]+offset)>>uiBitDepthIncrease; |
---|
4476 | pDes[uiStride31] = (pDes[uiStride31]+offset)>>uiBitDepthIncrease; |
---|
4477 | #endif |
---|
4478 | } |
---|
4479 | } |
---|
4480 | #endif //!E243_CORE_TRANSFORMS |
---|
4481 | #if QC_MOD_LCEC |
---|
4482 | Void TComTrQuant::init( UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxTrSize, Int iSymbolMode, UInt *aTableLP4, UInt *aTableLP8, UInt *aTableLastPosVlcIndex, |
---|
4483 | Bool bUseRDOQ, Bool bEnc ) |
---|
4484 | #else |
---|
4485 | Void TComTrQuant::init( UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxTrSize, Int iSymbolMode, UInt *aTableLP4, UInt *aTableLP8, Bool bUseRDOQ, Bool bEnc ) |
---|
4486 | #endif |
---|
4487 | { |
---|
4488 | m_uiMaxTrSize = uiMaxTrSize; |
---|
4489 | m_bEnc = bEnc; |
---|
4490 | m_bUseRDOQ = bUseRDOQ; |
---|
4491 | m_uiLPTableE8 = aTableLP8; |
---|
4492 | m_uiLPTableE4 = aTableLP4; |
---|
4493 | #if QC_MOD_LCEC |
---|
4494 | m_uiLastPosVlcIndex=aTableLastPosVlcIndex; |
---|
4495 | #endif |
---|
4496 | m_iSymbolMode = iSymbolMode; |
---|
4497 | |
---|
4498 | if ( m_bEnc ) |
---|
4499 | { |
---|
4500 | m_cQP.initOffsetParam( MIN_QP, MAX_QP ); |
---|
4501 | } |
---|
4502 | } |
---|
4503 | |
---|
4504 | Void TComTrQuant::xQuant( TComDataCU* pcCU, Long* pSrc, TCoeff*& pDes, Int iWidth, Int iHeight, UInt& uiAcSum, TextType eTType, UInt uiAbsPartIdx ) |
---|
4505 | { |
---|
4506 | xQuantLTR(pcCU, pSrc, pDes, iWidth, iHeight, uiAcSum, eTType, uiAbsPartIdx ); |
---|
4507 | } |
---|
4508 | |
---|
4509 | Void TComTrQuant::xDeQuant( TCoeff* pSrc, Long*& pDes, Int iWidth, Int iHeight ) |
---|
4510 | { |
---|
4511 | xDeQuantLTR( pSrc, pDes, iWidth, iHeight ); |
---|
4512 | } |
---|
4513 | |
---|
4514 | #if INTRA_DST_TYPE_7 |
---|
4515 | Void TComTrQuant::transformNxN( TComDataCU* pcCU, Pel* pcResidual, UInt uiStride, TCoeff*& rpcCoeff, UInt uiWidth, UInt uiHeight, UInt& uiAbsSum, TextType eTType, UInt uiAbsPartIdx ) |
---|
4516 | { |
---|
4517 | UInt uiMode; //luma intra pred |
---|
4518 | if(eTType == TEXT_LUMA && pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA ) |
---|
4519 | uiMode = pcCU->getLumaIntraDir( uiAbsPartIdx ); |
---|
4520 | else |
---|
4521 | uiMode = REG_DCT; |
---|
4522 | |
---|
4523 | uiAbsSum = 0; |
---|
4524 | assert( (pcCU->getSlice()->getSPS()->getMaxTrSize() >= uiWidth) ); |
---|
4525 | |
---|
4526 | xT( uiMode, pcResidual, uiStride, m_plTempCoeff, uiWidth ); |
---|
4527 | xQuant( pcCU, m_plTempCoeff, rpcCoeff, uiWidth, uiHeight, uiAbsSum, eTType, uiAbsPartIdx ); |
---|
4528 | } |
---|
4529 | #else |
---|
4530 | Void TComTrQuant::transformNxN( TComDataCU* pcCU, Pel* pcResidual, UInt uiStride, TCoeff*& rpcCoeff, UInt uiWidth, UInt uiHeight, UInt& uiAbsSum, TextType eTType, UInt uiAbsPartIdx ) |
---|
4531 | { |
---|
4532 | uiAbsSum = 0; |
---|
4533 | |
---|
4534 | assert( (pcCU->getSlice()->getSPS()->getMaxTrSize() >= uiWidth) ); |
---|
4535 | |
---|
4536 | xT( pcResidual, uiStride, m_plTempCoeff, uiWidth ); |
---|
4537 | xQuant( pcCU, m_plTempCoeff, rpcCoeff, uiWidth, uiHeight, uiAbsSum, eTType, uiAbsPartIdx ); |
---|
4538 | } |
---|
4539 | #endif |
---|
4540 | |
---|
4541 | |
---|
4542 | #if INTRA_DST_TYPE_7 |
---|
4543 | Void TComTrQuant::invtransformNxN( TextType eText,UInt uiMode, Pel*& rpcResidual, UInt uiStride, TCoeff* pcCoeff, UInt uiWidth, UInt uiHeight ) |
---|
4544 | { |
---|
4545 | xDeQuant( pcCoeff, m_plTempCoeff, uiWidth, uiHeight); |
---|
4546 | xIT( uiMode, m_plTempCoeff, rpcResidual, uiStride, uiWidth); |
---|
4547 | } |
---|
4548 | #else |
---|
4549 | Void TComTrQuant::invtransformNxN( Pel*& rpcResidual, UInt uiStride, TCoeff* pcCoeff, UInt uiWidth, UInt uiHeight ) |
---|
4550 | { |
---|
4551 | xDeQuant( pcCoeff, m_plTempCoeff, uiWidth, uiHeight); |
---|
4552 | xIT( m_plTempCoeff, rpcResidual, uiStride, uiWidth ); |
---|
4553 | } |
---|
4554 | #endif |
---|
4555 | |
---|
4556 | #if !E243_CORE_TRANSFORMS |
---|
4557 | Void TComTrQuant::xT2( Pel* piBlkResi, UInt uiStride, Long* psCoeff ) |
---|
4558 | { |
---|
4559 | Int itmp1, itmp2; |
---|
4560 | |
---|
4561 | itmp1 = piBlkResi[0] + piBlkResi[uiStride ]; |
---|
4562 | itmp2 = piBlkResi[1] + piBlkResi[uiStride+1]; |
---|
4563 | |
---|
4564 | psCoeff[0] = itmp1 + itmp2; |
---|
4565 | psCoeff[1] = itmp1 - itmp2; |
---|
4566 | |
---|
4567 | itmp1 = piBlkResi[0] - piBlkResi[uiStride ]; |
---|
4568 | itmp2 = piBlkResi[1] - piBlkResi[uiStride+1]; |
---|
4569 | |
---|
4570 | psCoeff[2] = itmp1 + itmp2; |
---|
4571 | psCoeff[3] = itmp1 - itmp2; |
---|
4572 | } |
---|
4573 | |
---|
4574 | Void TComTrQuant::xT4( Pel* piBlkResi, UInt uiStride, Long* psCoeff ) |
---|
4575 | { |
---|
4576 | Int aai[4][4]; |
---|
4577 | Int tmp1, tmp2; |
---|
4578 | |
---|
4579 | for( Int y = 0; y < 4; y++ ) |
---|
4580 | { |
---|
4581 | tmp1 = piBlkResi[0] + piBlkResi[3]; |
---|
4582 | tmp2 = piBlkResi[1] + piBlkResi[2]; |
---|
4583 | |
---|
4584 | aai[0][y] = tmp1 + tmp2; |
---|
4585 | aai[2][y] = tmp1 - tmp2; |
---|
4586 | |
---|
4587 | tmp1 = piBlkResi[0] - piBlkResi[3]; |
---|
4588 | tmp2 = piBlkResi[1] - piBlkResi[2]; |
---|
4589 | |
---|
4590 | aai[1][y] = tmp1 * 2 + tmp2 ; |
---|
4591 | aai[3][y] = tmp1 - tmp2 * 2; |
---|
4592 | piBlkResi += uiStride; |
---|
4593 | } |
---|
4594 | |
---|
4595 | for( Int x = 0; x < 4; x++, psCoeff++ ) |
---|
4596 | { |
---|
4597 | tmp1 = aai[x][0] + aai[x][3]; |
---|
4598 | tmp2 = aai[x][1] + aai[x][2]; |
---|
4599 | |
---|
4600 | psCoeff[0] = tmp1 + tmp2; |
---|
4601 | psCoeff[8] = tmp1 - tmp2; |
---|
4602 | |
---|
4603 | tmp1 = aai[x][0] - aai[x][3]; |
---|
4604 | tmp2 = aai[x][1] - aai[x][2]; |
---|
4605 | |
---|
4606 | psCoeff[4] = tmp1 * 2 + tmp2; |
---|
4607 | psCoeff[12] = tmp1 - tmp2 * 2; |
---|
4608 | } |
---|
4609 | } |
---|
4610 | |
---|
4611 | Void TComTrQuant::xT8( Pel* piBlkResi, UInt uiStride, Long* psCoeff ) |
---|
4612 | { |
---|
4613 | Int aai[8][8]; |
---|
4614 | #ifdef TRANS_PRECISION_EXT |
---|
4615 | Int uiBitDepthIncrease=g_iShift8x8-g_uiBitIncrement; |
---|
4616 | Int offset = (uiBitDepthIncrease==0)? 0:(1<<(uiBitDepthIncrease-1)); |
---|
4617 | #endif |
---|
4618 | for( Int i = 0; i < 8; i++, piBlkResi += uiStride ) |
---|
4619 | { |
---|
4620 | Int ai1 [8]; |
---|
4621 | Int ai2 [8]; |
---|
4622 | #ifdef TRANS_PRECISION_EXT |
---|
4623 | ai1[0] = (piBlkResi[0] + piBlkResi[7])<<uiBitDepthIncrease; |
---|
4624 | ai1[1] = (piBlkResi[1] + piBlkResi[6])<<uiBitDepthIncrease; |
---|
4625 | ai1[2] = (piBlkResi[2] + piBlkResi[5])<<uiBitDepthIncrease; |
---|
4626 | ai1[3] = (piBlkResi[3] + piBlkResi[4])<<uiBitDepthIncrease; |
---|
4627 | |
---|
4628 | ai1[4] = (piBlkResi[0] - piBlkResi[7])<<uiBitDepthIncrease; |
---|
4629 | ai1[5] = (piBlkResi[1] - piBlkResi[6])<<uiBitDepthIncrease; |
---|
4630 | ai1[6] = (piBlkResi[2] - piBlkResi[5])<<uiBitDepthIncrease; |
---|
4631 | ai1[7] = (piBlkResi[3] - piBlkResi[4])<<uiBitDepthIncrease; |
---|
4632 | #else |
---|
4633 | ai1[0] = piBlkResi[0] + piBlkResi[7]; |
---|
4634 | ai1[1] = piBlkResi[1] + piBlkResi[6]; |
---|
4635 | ai1[2] = piBlkResi[2] + piBlkResi[5]; |
---|
4636 | ai1[3] = piBlkResi[3] + piBlkResi[4]; |
---|
4637 | |
---|
4638 | ai1[4] = piBlkResi[0] - piBlkResi[7]; |
---|
4639 | ai1[5] = piBlkResi[1] - piBlkResi[6]; |
---|
4640 | ai1[6] = piBlkResi[2] - piBlkResi[5]; |
---|
4641 | ai1[7] = piBlkResi[3] - piBlkResi[4]; |
---|
4642 | #endif |
---|
4643 | ai2[0] = ai1[0] + ai1[3]; |
---|
4644 | ai2[1] = ai1[1] + ai1[2]; |
---|
4645 | ai2[2] = ai1[0] - ai1[3]; |
---|
4646 | ai2[3] = ai1[1] - ai1[2]; |
---|
4647 | ai2[4] = ai1[5] + ai1[6] + ((ai1[4]>>1) + ai1[4]); |
---|
4648 | ai2[5] = ai1[4] - ai1[7] - ((ai1[6]>>1) + ai1[6]); |
---|
4649 | ai2[6] = ai1[4] + ai1[7] - ((ai1[5]>>1) + ai1[5]); |
---|
4650 | ai2[7] = ai1[5] - ai1[6] + ((ai1[7]>>1) + ai1[7]); |
---|
4651 | |
---|
4652 | aai[0][i] = ai2[0] + ai2[1]; |
---|
4653 | aai[2][i] = ai2[2] + (ai2[3]>>1); |
---|
4654 | aai[4][i] = ai2[0] - ai2[1]; |
---|
4655 | aai[6][i] = (ai2[2]>>1) - ai2[3]; |
---|
4656 | |
---|
4657 | aai[1][i] = ai2[4] + (ai2[7]>>2); |
---|
4658 | aai[3][i] = ai2[5] + (ai2[6]>>2); |
---|
4659 | aai[5][i] = ai2[6] - (ai2[5]>>2); |
---|
4660 | aai[7][i] = (ai2[4]>>2) - ai2[7]; |
---|
4661 | } |
---|
4662 | |
---|
4663 | // vertical transform |
---|
4664 | for( Int n = 0; n < 8; n++, psCoeff++) |
---|
4665 | { |
---|
4666 | Int ai1[8]; |
---|
4667 | Int ai2[8]; |
---|
4668 | |
---|
4669 | ai1[0] = aai[n][0] + aai[n][7]; |
---|
4670 | ai1[1] = aai[n][1] + aai[n][6]; |
---|
4671 | ai1[2] = aai[n][2] + aai[n][5]; |
---|
4672 | ai1[3] = aai[n][3] + aai[n][4]; |
---|
4673 | ai1[4] = aai[n][0] - aai[n][7]; |
---|
4674 | ai1[5] = aai[n][1] - aai[n][6]; |
---|
4675 | ai1[6] = aai[n][2] - aai[n][5]; |
---|
4676 | ai1[7] = aai[n][3] - aai[n][4]; |
---|
4677 | |
---|
4678 | ai2[0] = ai1[0] + ai1[3]; |
---|
4679 | ai2[1] = ai1[1] + ai1[2]; |
---|
4680 | ai2[2] = ai1[0] - ai1[3]; |
---|
4681 | ai2[3] = ai1[1] - ai1[2]; |
---|
4682 | ai2[4] = ai1[5] + ai1[6] + ((ai1[4]>>1) + ai1[4]); |
---|
4683 | ai2[5] = ai1[4] - ai1[7] - ((ai1[6]>>1) + ai1[6]); |
---|
4684 | ai2[6] = ai1[4] + ai1[7] - ((ai1[5]>>1) + ai1[5]); |
---|
4685 | ai2[7] = ai1[5] - ai1[6] + ((ai1[7]>>1) + ai1[7]); |
---|
4686 | |
---|
4687 | psCoeff[ 0] = ai2[0] + ai2[1]; |
---|
4688 | psCoeff[16] = ai2[2] + (ai2[3]>>1); |
---|
4689 | psCoeff[32] = ai2[0] - ai2[1]; |
---|
4690 | psCoeff[48] = (ai2[2]>>1) - ai2[3]; |
---|
4691 | |
---|
4692 | psCoeff[ 8] = ai2[4] + (ai2[7]>>2); |
---|
4693 | psCoeff[24] = ai2[5] + (ai2[6]>>2); |
---|
4694 | psCoeff[40] = ai2[6] - (ai2[5]>>2); |
---|
4695 | psCoeff[56] = (ai2[4]>>2) - ai2[7]; |
---|
4696 | #ifdef TRANS_PRECISION_EXT |
---|
4697 | psCoeff[ 0] = (psCoeff[ 0]+offset)>>uiBitDepthIncrease; |
---|
4698 | psCoeff[16] = (psCoeff[16]+offset)>>uiBitDepthIncrease; |
---|
4699 | psCoeff[32] = (psCoeff[32]+offset)>>uiBitDepthIncrease; |
---|
4700 | psCoeff[48] = (psCoeff[48]+offset)>>uiBitDepthIncrease; |
---|
4701 | |
---|
4702 | psCoeff[ 8] = (psCoeff[ 8]+offset)>>uiBitDepthIncrease; |
---|
4703 | psCoeff[24] = (psCoeff[24]+offset)>>uiBitDepthIncrease; |
---|
4704 | psCoeff[40] = (psCoeff[40]+offset)>>uiBitDepthIncrease; |
---|
4705 | psCoeff[56] = (psCoeff[56]+offset)>>uiBitDepthIncrease; |
---|
4706 | #endif |
---|
4707 | } |
---|
4708 | } |
---|
4709 | |
---|
4710 | Void TComTrQuant::xQuant2x2( Long* plSrcCoef, TCoeff*& pDstCoef, UInt& uiAbsSum ) |
---|
4711 | { |
---|
4712 | Int iLevel; |
---|
4713 | Int iSign; |
---|
4714 | Int iOffset = 1<<(6+m_cQP.per()); |
---|
4715 | Int iBits = m_cQP.per()+7; |
---|
4716 | |
---|
4717 | iSign = plSrcCoef[0]>>31; |
---|
4718 | iLevel = abs(plSrcCoef[0]); |
---|
4719 | iLevel *= m_puiQuantMtx[0]; |
---|
4720 | iLevel = (iLevel + iOffset)>>iBits; |
---|
4721 | |
---|
4722 | if( iLevel != 0) |
---|
4723 | { |
---|
4724 | uiAbsSum += iLevel; |
---|
4725 | iLevel ^= iSign; |
---|
4726 | iLevel -= iSign; |
---|
4727 | pDstCoef[0] = iLevel; |
---|
4728 | } |
---|
4729 | else |
---|
4730 | { |
---|
4731 | pDstCoef[0] = 0; |
---|
4732 | } |
---|
4733 | |
---|
4734 | iSign = plSrcCoef[1]>>31; |
---|
4735 | iLevel = abs(plSrcCoef[1]); |
---|
4736 | iLevel *= m_puiQuantMtx[0]; |
---|
4737 | iLevel = (iLevel + iOffset)>>iBits; |
---|
4738 | |
---|
4739 | if( iLevel != 0) |
---|
4740 | { |
---|
4741 | uiAbsSum += iLevel; |
---|
4742 | iLevel ^= iSign; |
---|
4743 | iLevel -= iSign; |
---|
4744 | pDstCoef[1] = iLevel; |
---|
4745 | } |
---|
4746 | else |
---|
4747 | { |
---|
4748 | pDstCoef[1] = 0; |
---|
4749 | } |
---|
4750 | |
---|
4751 | iSign = plSrcCoef[2]>>31; |
---|
4752 | iLevel = abs(plSrcCoef[2]); |
---|
4753 | iLevel *= m_puiQuantMtx[0]; |
---|
4754 | iLevel = (iLevel + iOffset)>>iBits; |
---|
4755 | |
---|
4756 | if( iLevel != 0) |
---|
4757 | { |
---|
4758 | uiAbsSum += iLevel; |
---|
4759 | iLevel ^= iSign; |
---|
4760 | iLevel -= iSign; |
---|
4761 | pDstCoef[2] = iLevel; |
---|
4762 | } |
---|
4763 | else |
---|
4764 | { |
---|
4765 | pDstCoef[2] = 0; |
---|
4766 | } |
---|
4767 | |
---|
4768 | iSign = plSrcCoef[3]>>31; |
---|
4769 | iLevel = abs(plSrcCoef[3]); |
---|
4770 | iLevel *= m_puiQuantMtx[0]; |
---|
4771 | iLevel = (iLevel + iOffset)>>iBits; |
---|
4772 | |
---|
4773 | if( iLevel != 0) |
---|
4774 | { |
---|
4775 | uiAbsSum += iLevel; |
---|
4776 | iLevel ^= iSign; |
---|
4777 | iLevel -= iSign; |
---|
4778 | pDstCoef[3] = iLevel; |
---|
4779 | } |
---|
4780 | else |
---|
4781 | { |
---|
4782 | pDstCoef[3] = 0; |
---|
4783 | } |
---|
4784 | } |
---|
4785 | |
---|
4786 | Void TComTrQuant::xQuant4x4( TComDataCU* pcCU, Long* plSrcCoef, TCoeff*& pDstCoef, UInt& uiAbsSum, TextType eTType, UInt uiAbsPartIdx ) |
---|
4787 | { |
---|
4788 | if ( m_bUseRDOQ && (eTType == TEXT_LUMA || RDOQ_CHROMA) ) |
---|
4789 | { |
---|
4790 | if ( m_iSymbolMode == 0) |
---|
4791 | xRateDistOptQuant_LCEC(pcCU, plSrcCoef, pDstCoef, 4, 4, uiAbsSum, eTType, uiAbsPartIdx ); |
---|
4792 | else |
---|
4793 | xRateDistOptQuant(pcCU, plSrcCoef, pDstCoef, 4, 4, uiAbsSum, eTType, uiAbsPartIdx ); |
---|
4794 | } |
---|
4795 | else |
---|
4796 | { |
---|
4797 | for( Int n = 0; n < 16; n++ ) |
---|
4798 | { |
---|
4799 | Int iLevel, iSign; |
---|
4800 | iLevel = plSrcCoef[n]; |
---|
4801 | iSign = iLevel; |
---|
4802 | iLevel = abs( iLevel ) * m_puiQuantMtx[n]; |
---|
4803 | |
---|
4804 | iLevel = ( iLevel + m_cQP.m_iAdd4x4 ) >> m_cQP.m_iBits; |
---|
4805 | |
---|
4806 | if( 0 != iLevel ) |
---|
4807 | { |
---|
4808 | iSign >>= 31; |
---|
4809 | uiAbsSum += iLevel; |
---|
4810 | iLevel ^= iSign; |
---|
4811 | iLevel -= iSign; |
---|
4812 | pDstCoef[n] = iLevel; |
---|
4813 | } |
---|
4814 | else |
---|
4815 | { |
---|
4816 | pDstCoef [n] = 0; |
---|
4817 | } |
---|
4818 | } |
---|
4819 | } |
---|
4820 | } |
---|
4821 | |
---|
4822 | Void TComTrQuant::xQuant8x8( TComDataCU* pcCU, Long* plSrcCoef, TCoeff*& pDstCoef, UInt& uiAbsSum, TextType eTType, UInt uiAbsPartIdx ) |
---|
4823 | { |
---|
4824 | Int iBit = m_cQP.m_iBits + 1; |
---|
4825 | |
---|
4826 | if ( m_bUseRDOQ && (eTType == TEXT_LUMA || RDOQ_CHROMA) ) |
---|
4827 | { |
---|
4828 | if ( m_iSymbolMode == 0) |
---|
4829 | xRateDistOptQuant_LCEC(pcCU, plSrcCoef, pDstCoef, 8, 8, uiAbsSum, eTType, uiAbsPartIdx ); |
---|
4830 | else |
---|
4831 | xRateDistOptQuant(pcCU, plSrcCoef, pDstCoef, 8, 8, uiAbsSum, eTType, uiAbsPartIdx ); |
---|
4832 | } |
---|
4833 | else |
---|
4834 | { |
---|
4835 | for( Int n = 0; n < 64; n++ ) |
---|
4836 | { |
---|
4837 | Int iLevel, iSign; |
---|
4838 | |
---|
4839 | iLevel = plSrcCoef[n]; |
---|
4840 | iSign = iLevel; |
---|
4841 | iLevel = abs( iLevel ) * m_puiQuantMtx[n]; |
---|
4842 | |
---|
4843 | iLevel = ( iLevel + m_cQP.m_iAdd8x8 ) >> iBit; |
---|
4844 | |
---|
4845 | if( 0 != iLevel ) |
---|
4846 | { |
---|
4847 | iSign >>= 31; |
---|
4848 | uiAbsSum += iLevel; |
---|
4849 | iLevel ^= iSign; |
---|
4850 | iLevel -= iSign; |
---|
4851 | pDstCoef[n] = iLevel; |
---|
4852 | } |
---|
4853 | else |
---|
4854 | { |
---|
4855 | pDstCoef [n] = 0; |
---|
4856 | } |
---|
4857 | } |
---|
4858 | } |
---|
4859 | } |
---|
4860 | |
---|
4861 | Void TComTrQuant::xIT2( Long* plCoef, Pel* pResidual, UInt uiStride ) |
---|
4862 | { |
---|
4863 | Int itemp, itmp1, itmp2; |
---|
4864 | Int iSign; |
---|
4865 | UInt uiBits = 5; |
---|
4866 | UInt uiOffset = 1<<(uiBits-1); |
---|
4867 | |
---|
4868 | itmp1 = plCoef[0] + plCoef[2]; |
---|
4869 | itmp2 = plCoef[1] + plCoef[3]; |
---|
4870 | |
---|
4871 | itemp = itmp1 + itmp2; |
---|
4872 | iSign = itemp>>31; |
---|
4873 | pResidual[0] = (abs(itemp) + uiOffset)>>uiBits; |
---|
4874 | pResidual[0] ^= iSign; |
---|
4875 | pResidual[0] -= iSign; |
---|
4876 | |
---|
4877 | itemp = itmp1 - itmp2; |
---|
4878 | iSign = itemp>>31; |
---|
4879 | pResidual[1] = (abs(itemp) + uiOffset)>>uiBits; |
---|
4880 | pResidual[1] ^= iSign; |
---|
4881 | pResidual[1] -= iSign; |
---|
4882 | |
---|
4883 | itmp1 = plCoef[0] - plCoef[2]; |
---|
4884 | itmp2 = plCoef[1] - plCoef[3]; |
---|
4885 | |
---|
4886 | itemp = itmp1 + itmp2; |
---|
4887 | iSign = itemp>>31; |
---|
4888 | pResidual[uiStride] = (abs(itemp) + uiOffset)>>uiBits; |
---|
4889 | pResidual[uiStride] ^= iSign; |
---|
4890 | pResidual[uiStride] -= iSign; |
---|
4891 | |
---|
4892 | itemp = itmp1 - itmp2; |
---|
4893 | iSign = itemp>>31; |
---|
4894 | pResidual[uiStride+1] = (abs(itemp) + uiOffset)>>uiBits; |
---|
4895 | pResidual[uiStride+1] ^= iSign; |
---|
4896 | pResidual[uiStride+1] -= iSign; |
---|
4897 | } |
---|
4898 | |
---|
4899 | Void TComTrQuant::xIT4( Long* plCoef, Pel* pResidual, UInt uiStride ) |
---|
4900 | { |
---|
4901 | Int aai[4][4]; |
---|
4902 | Int tmp1, tmp2; |
---|
4903 | Int x, y; |
---|
4904 | Int uiStride2=(uiStride<<1); |
---|
4905 | Int uiStride3=uiStride2 + uiStride; |
---|
4906 | |
---|
4907 | for( x = 0; x < 4; x++, plCoef+=4 ) |
---|
4908 | { |
---|
4909 | tmp1 = plCoef[0] + plCoef[2]; |
---|
4910 | tmp2 = (plCoef[3]>>1) + plCoef[1]; |
---|
4911 | |
---|
4912 | aai[0][x] = tmp1 + tmp2; |
---|
4913 | aai[3][x] = tmp1 - tmp2; |
---|
4914 | |
---|
4915 | tmp1 = plCoef[0] - plCoef[2]; |
---|
4916 | tmp2 = (plCoef[1]>>1) - plCoef[3]; |
---|
4917 | |
---|
4918 | aai[1][x] = tmp1 + tmp2; |
---|
4919 | aai[2][x] = tmp1 - tmp2; |
---|
4920 | } |
---|
4921 | |
---|
4922 | for( y = 0; y < 4; y++, pResidual ++ ) |
---|
4923 | { |
---|
4924 | tmp1 = aai[y][0] + aai[y][2]; |
---|
4925 | tmp2 = (aai[y][3]>>1) + aai[y][1]; |
---|
4926 | |
---|
4927 | pResidual[0] = xRound( tmp1 + tmp2); |
---|
4928 | pResidual[uiStride3] = xRound( tmp1 - tmp2); |
---|
4929 | |
---|
4930 | tmp1 = aai[y][0] - aai[y][2]; |
---|
4931 | tmp2 = (aai[y][1]>>1) - aai[y][3]; |
---|
4932 | |
---|
4933 | pResidual[uiStride] = xRound( tmp1 + tmp2); |
---|
4934 | pResidual[uiStride2] = xRound( tmp1 - tmp2); |
---|
4935 | } |
---|
4936 | } |
---|
4937 | |
---|
4938 | Void TComTrQuant::xIT8( Long* plCoef, Pel* pResidual, UInt uiStride ) |
---|
4939 | { |
---|
4940 | Long aai[8][8]; |
---|
4941 | Int n; |
---|
4942 | #ifdef TRANS_PRECISION_EXT |
---|
4943 | #if FULL_NBIT |
---|
4944 | Int uiBitDepthIncrease=g_iShift8x8-g_uiBitIncrement-g_uiBitDepth+8; |
---|
4945 | #else |
---|
4946 | Int uiBitDepthIncrease=g_iShift8x8-g_uiBitIncrement; |
---|
4947 | #endif |
---|
4948 | Int offset = (uiBitDepthIncrease==0)? 0:(1<<(uiBitDepthIncrease-1)); |
---|
4949 | #endif |
---|
4950 | UInt uiStride2 = uiStride<<1; |
---|
4951 | UInt uiStride3 = uiStride2 + uiStride; |
---|
4952 | UInt uiStride4 = uiStride3 + uiStride; |
---|
4953 | UInt uiStride5 = uiStride4 + uiStride; |
---|
4954 | UInt uiStride6 = uiStride5 + uiStride; |
---|
4955 | UInt uiStride7 = uiStride6 + uiStride; |
---|
4956 | |
---|
4957 | for( n = 0; n < 8; n++ ) |
---|
4958 | { |
---|
4959 | Long* pi = plCoef + (n<<3); |
---|
4960 | Long ai1[8]; |
---|
4961 | Long ai2[8]; |
---|
4962 | #ifdef TRANS_PRECISION_EXT |
---|
4963 | Long ai0[8]; |
---|
4964 | ai0[0] = pi[0]<<uiBitDepthIncrease; |
---|
4965 | ai0[1] = pi[1]<<uiBitDepthIncrease; |
---|
4966 | ai0[2] = pi[2]<<uiBitDepthIncrease; |
---|
4967 | ai0[3] = pi[3]<<uiBitDepthIncrease; |
---|
4968 | ai0[4] = pi[4]<<uiBitDepthIncrease; |
---|
4969 | ai0[5] = pi[5]<<uiBitDepthIncrease; |
---|
4970 | ai0[6] = pi[6]<<uiBitDepthIncrease; |
---|
4971 | ai0[7] = pi[7]<<uiBitDepthIncrease; |
---|
4972 | ai1[0] = ai0[0] + ai0[4]; |
---|
4973 | ai1[2] = ai0[0] - ai0[4]; |
---|
4974 | |
---|
4975 | ai1[4] = (ai0[2]>>1) - ai0[6]; |
---|
4976 | ai1[6] = ai0[2] + (ai0[6]>>1); |
---|
4977 | |
---|
4978 | ai1[1] = ai0[5] - ai0[3] - ai0[7] - (ai0[7]>>1); |
---|
4979 | ai1[3] = ai0[1] + ai0[7] - ai0[3] - (ai0[3]>>1);; |
---|
4980 | ai1[5] = ai0[7] - ai0[1] + ai0[5] + (ai0[5]>>1); |
---|
4981 | ai1[7] = ai0[3] + ai0[5] + ai0[1] + (ai0[1]>>1); |
---|
4982 | #else |
---|
4983 | ai1[0] = pi[0] + pi[4]; |
---|
4984 | ai1[2] = pi[0] - pi[4]; |
---|
4985 | |
---|
4986 | ai1[4] = (pi[2]>>1) - pi[6]; |
---|
4987 | ai1[6] = pi[2] + (pi[6]>>1); |
---|
4988 | |
---|
4989 | ai1[1] = pi[5] - pi[3] - pi[7] - (pi[7]>>1); |
---|
4990 | ai1[3] = pi[1] + pi[7] - pi[3] - (pi[3]>>1);; |
---|
4991 | ai1[5] = pi[7] - pi[1] + pi[5] + (pi[5]>>1); |
---|
4992 | ai1[7] = pi[3] + pi[5] + pi[1] + (pi[1]>>1); |
---|
4993 | #endif |
---|
4994 | ai2[0] = ai1[0] + ai1[6]; |
---|
4995 | ai2[6] = ai1[0] - ai1[6]; |
---|
4996 | |
---|
4997 | ai2[2] = ai1[2] + ai1[4]; |
---|
4998 | ai2[4] = ai1[2] - ai1[4]; |
---|
4999 | |
---|
5000 | ai2[1] = ai1[1] + (ai1[7]>>2); |
---|
5001 | ai2[7] = ai1[7] - (ai1[1]>>2); |
---|
5002 | |
---|
5003 | ai2[3] = ai1[3] + (ai1[5]>>2); |
---|
5004 | ai2[5] = (ai1[3]>>2) - ai1[5]; |
---|
5005 | |
---|
5006 | aai[n][0] = ai2[0] + ai2[7]; |
---|
5007 | aai[n][1] = ai2[2] + ai2[5]; |
---|
5008 | aai[n][2] = ai2[4] + ai2[3]; |
---|
5009 | aai[n][3] = ai2[6] + ai2[1]; |
---|
5010 | aai[n][4] = ai2[6] - ai2[1]; |
---|
5011 | aai[n][5] = ai2[4] - ai2[3]; |
---|
5012 | aai[n][6] = ai2[2] - ai2[5]; |
---|
5013 | aai[n][7] = ai2[0] - ai2[7]; |
---|
5014 | } |
---|
5015 | |
---|
5016 | for( n = 0; n < 8; n++, pResidual++ ) |
---|
5017 | { |
---|
5018 | Int ai1[8]; |
---|
5019 | Int ai2[8]; |
---|
5020 | |
---|
5021 | ai1[0] = aai[0][n] + aai[4][n]; |
---|
5022 | ai1[1] = aai[5][n] - aai[3][n] - aai[7][n] - (aai[7][n]>>1); |
---|
5023 | ai1[2] = aai[0][n] - aai[4][n]; |
---|
5024 | ai1[3] = aai[1][n] + aai[7][n] - aai[3][n] - (aai[3][n]>>1); |
---|
5025 | ai1[4] = (aai[2][n]>>1) - aai[6][n]; |
---|
5026 | ai1[5] = aai[7][n] - aai[1][n] + aai[5][n] + (aai[5][n]>>1); |
---|
5027 | ai1[6] = aai[2][n] + (aai[6][n]>>1); |
---|
5028 | ai1[7] = aai[3][n] + aai[5][n] + aai[1][n] + (aai[1][n]>>1); |
---|
5029 | |
---|
5030 | ai2[2] = ai1[2] + ai1[4]; |
---|
5031 | ai2[4] = ai1[2] - ai1[4]; |
---|
5032 | |
---|
5033 | ai2[0] = ai1[0] + ai1[6]; |
---|
5034 | ai2[6] = ai1[0] - ai1[6]; |
---|
5035 | |
---|
5036 | ai2[1] = ai1[1] + (ai1[7]>>2); |
---|
5037 | ai2[7] = ai1[7] - (ai1[1]>>2); |
---|
5038 | |
---|
5039 | ai2[3] = ai1[3] + (ai1[5]>>2); |
---|
5040 | ai2[5] = (ai1[3]>>2) - ai1[5]; |
---|
5041 | |
---|
5042 | pResidual[ 0] = xRound( ai2[0] + ai2[7] ); |
---|
5043 | pResidual[uiStride ] = xRound( ai2[2] + ai2[5] ); |
---|
5044 | pResidual[uiStride2] = xRound( ai2[4] + ai2[3] ); |
---|
5045 | pResidual[uiStride3] = xRound( ai2[6] + ai2[1] ); |
---|
5046 | pResidual[uiStride4] = xRound( ai2[6] - ai2[1] ); |
---|
5047 | pResidual[uiStride5] = xRound( ai2[4] - ai2[3] ); |
---|
5048 | pResidual[uiStride6] = xRound( ai2[2] - ai2[5] ); |
---|
5049 | pResidual[uiStride7] = xRound( ai2[0] - ai2[7] ); |
---|
5050 | |
---|
5051 | #ifdef TRANS_PRECISION_EXT |
---|
5052 | pResidual[ 0] = (pResidual[ 0]+offset)>>uiBitDepthIncrease; |
---|
5053 | pResidual[uiStride ] = (pResidual[uiStride ]+offset)>>uiBitDepthIncrease; |
---|
5054 | pResidual[uiStride2] = (pResidual[uiStride2]+offset)>>uiBitDepthIncrease; |
---|
5055 | pResidual[uiStride3] = (pResidual[uiStride3]+offset)>>uiBitDepthIncrease; |
---|
5056 | pResidual[uiStride4] = (pResidual[uiStride4]+offset)>>uiBitDepthIncrease; |
---|
5057 | pResidual[uiStride5] = (pResidual[uiStride5]+offset)>>uiBitDepthIncrease; |
---|
5058 | pResidual[uiStride6] = (pResidual[uiStride6]+offset)>>uiBitDepthIncrease; |
---|
5059 | pResidual[uiStride7] = (pResidual[uiStride7]+offset)>>uiBitDepthIncrease; |
---|
5060 | #endif |
---|
5061 | } |
---|
5062 | } |
---|
5063 | |
---|
5064 | Void TComTrQuant::xDeQuant2x2( TCoeff* pSrcCoef, Long*& rplDstCoef ) |
---|
5065 | { |
---|
5066 | Int iDeScale = g_aiDequantCoef4[m_cQP.m_iRem]; |
---|
5067 | |
---|
5068 | if( pSrcCoef[0] != 0 ) |
---|
5069 | { |
---|
5070 | rplDstCoef[0] = pSrcCoef[0]*iDeScale<<m_cQP.per(); |
---|
5071 | } |
---|
5072 | else |
---|
5073 | { |
---|
5074 | rplDstCoef[0] = 0; |
---|
5075 | } |
---|
5076 | |
---|
5077 | if( pSrcCoef[1] != 0 ) |
---|
5078 | { |
---|
5079 | rplDstCoef[1] = pSrcCoef[1]*iDeScale<<m_cQP.per(); |
---|
5080 | } |
---|
5081 | else |
---|
5082 | { |
---|
5083 | rplDstCoef[1] = 0; |
---|
5084 | } |
---|
5085 | |
---|
5086 | if( pSrcCoef[2] != 0 ) |
---|
5087 | { |
---|
5088 | rplDstCoef[2] = pSrcCoef[2]*iDeScale<<m_cQP.per(); |
---|
5089 | } |
---|
5090 | else |
---|
5091 | { |
---|
5092 | rplDstCoef[2] = 0; |
---|
5093 | } |
---|
5094 | |
---|
5095 | if( pSrcCoef[3] != 0 ) |
---|
5096 | { |
---|
5097 | rplDstCoef[3] = pSrcCoef[3]*iDeScale<<m_cQP.per(); |
---|
5098 | } |
---|
5099 | else |
---|
5100 | { |
---|
5101 | rplDstCoef[3] = 0; |
---|
5102 | } |
---|
5103 | } |
---|
5104 | |
---|
5105 | Void TComTrQuant::xDeQuant4x4( TCoeff* pSrcCoef, Long*& rplDstCoef ) |
---|
5106 | { |
---|
5107 | Int iLevel; |
---|
5108 | Int iDeScale; |
---|
5109 | |
---|
5110 | for( Int n = 0; n < 16; n++ ) |
---|
5111 | { |
---|
5112 | iLevel = pSrcCoef[n]; |
---|
5113 | |
---|
5114 | if( 0 != iLevel ) |
---|
5115 | { |
---|
5116 | iDeScale = g_aiDequantCoef[m_cQP.m_iRem][n]; |
---|
5117 | |
---|
5118 | rplDstCoef[n] = iLevel*iDeScale << m_cQP.m_iPer; |
---|
5119 | } |
---|
5120 | else |
---|
5121 | { |
---|
5122 | rplDstCoef[n] = 0; |
---|
5123 | } |
---|
5124 | } |
---|
5125 | } |
---|
5126 | |
---|
5127 | Void TComTrQuant::xDeQuant8x8( TCoeff* pSrcCoef, Long*& rplDstCoef ) |
---|
5128 | { |
---|
5129 | Int iLevel; |
---|
5130 | Int iDeScale; |
---|
5131 | |
---|
5132 | Int iAdd = ( 1 << 5 ) >> m_cQP.m_iPer; |
---|
5133 | |
---|
5134 | for( Int n = 0; n < 64; n++ ) |
---|
5135 | { |
---|
5136 | iLevel = pSrcCoef[n]; |
---|
5137 | |
---|
5138 | if( 0 != iLevel ) |
---|
5139 | { |
---|
5140 | iDeScale = g_aiDequantCoef64[m_cQP.m_iRem][n]; |
---|
5141 | rplDstCoef[n] = ( (iLevel*iDeScale*16 + iAdd) << m_cQP.m_iPer ) >> 6; |
---|
5142 | } |
---|
5143 | else |
---|
5144 | { |
---|
5145 | rplDstCoef[n] = 0; |
---|
5146 | } |
---|
5147 | } |
---|
5148 | } |
---|
5149 | #endif //!E243_CORE_TRANSFORMS |
---|
5150 | |
---|
5151 | Void TComTrQuant::invRecurTransformNxN( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eTxt, Pel*& rpcResidual, UInt uiAddr, UInt uiStride, UInt uiWidth, UInt uiHeight, UInt uiMaxTrMode, UInt uiTrMode, TCoeff* rpcCoeff ) |
---|
5152 | { |
---|
5153 | if( !pcCU->getCbf(uiAbsPartIdx, eTxt, uiTrMode) ) |
---|
5154 | return; |
---|
5155 | |
---|
5156 | UInt uiLumaTrMode, uiChromaTrMode; |
---|
5157 | pcCU->convertTransIdx( uiAbsPartIdx, pcCU->getTransformIdx( uiAbsPartIdx ), uiLumaTrMode, uiChromaTrMode ); |
---|
5158 | const UInt uiStopTrMode = eTxt == TEXT_LUMA ? uiLumaTrMode : uiChromaTrMode; |
---|
5159 | |
---|
5160 | assert(1); // as long as quadtrees are not used for residual transform |
---|
5161 | |
---|
5162 | if( uiTrMode == uiStopTrMode ) |
---|
5163 | { |
---|
5164 | UInt uiDepth = pcCU->getDepth( uiAbsPartIdx ) + uiTrMode; |
---|
5165 | UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth ] + 2; |
---|
5166 | if( eTxt != TEXT_LUMA && uiLog2TrSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
5167 | { |
---|
5168 | UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
5169 | if( ( uiAbsPartIdx % uiQPDiv ) != 0 ) |
---|
5170 | { |
---|
5171 | return; |
---|
5172 | } |
---|
5173 | uiWidth <<= 1; |
---|
5174 | uiHeight <<= 1; |
---|
5175 | } |
---|
5176 | Pel* pResi = rpcResidual + uiAddr; |
---|
5177 | #if INTRA_DST_TYPE_7 |
---|
5178 | invtransformNxN( eTxt, REG_DCT, pResi, uiStride, rpcCoeff, uiWidth, uiHeight ); |
---|
5179 | #else |
---|
5180 | invtransformNxN( pResi, uiStride, rpcCoeff, uiWidth, uiHeight ); |
---|
5181 | #endif |
---|
5182 | } |
---|
5183 | else |
---|
5184 | { |
---|
5185 | uiTrMode++; |
---|
5186 | uiWidth >>= 1; |
---|
5187 | uiHeight >>= 1; |
---|
5188 | UInt uiAddrOffset = uiHeight * uiStride; |
---|
5189 | UInt uiCoefOffset = uiWidth * uiHeight; |
---|
5190 | UInt uiPartOffset = pcCU->getTotalNumPart() >> (uiTrMode<<1); |
---|
5191 | invRecurTransformNxN( pcCU, uiAbsPartIdx, eTxt, rpcResidual, uiAddr , uiStride, uiWidth, uiHeight, uiMaxTrMode, uiTrMode, rpcCoeff ); rpcCoeff += uiCoefOffset; uiAbsPartIdx += uiPartOffset; |
---|
5192 | invRecurTransformNxN( pcCU, uiAbsPartIdx, eTxt, rpcResidual, uiAddr + uiWidth , uiStride, uiWidth, uiHeight, uiMaxTrMode, uiTrMode, rpcCoeff ); rpcCoeff += uiCoefOffset; uiAbsPartIdx += uiPartOffset; |
---|
5193 | invRecurTransformNxN( pcCU, uiAbsPartIdx, eTxt, rpcResidual, uiAddr + uiAddrOffset , uiStride, uiWidth, uiHeight, uiMaxTrMode, uiTrMode, rpcCoeff ); rpcCoeff += uiCoefOffset; uiAbsPartIdx += uiPartOffset; |
---|
5194 | invRecurTransformNxN( pcCU, uiAbsPartIdx, eTxt, rpcResidual, uiAddr + uiAddrOffset + uiWidth, uiStride, uiWidth, uiHeight, uiMaxTrMode, uiTrMode, rpcCoeff ); |
---|
5195 | } |
---|
5196 | } |
---|
5197 | |
---|
5198 | // ------------------------------------------------------------------------------------------------ |
---|
5199 | // Logical transform |
---|
5200 | // ------------------------------------------------------------------------------------------------ |
---|
5201 | |
---|
5202 | #if E243_CORE_TRANSFORMS |
---|
5203 | /** Wrapper function between HM interface and core NxN forward transform (2D) |
---|
5204 | * \param piBlkResi input data (residual) |
---|
5205 | * \param psCoeff output data (transform coefficients) |
---|
5206 | * \param uiStride stride of input residual data |
---|
5207 | * \param iSize transform size (iSize x iSize) |
---|
5208 | * \param uiMode is Intra Prediction mode used in Mode-Dependent DCT/DST only |
---|
5209 | */ |
---|
5210 | #if INTRA_DST_TYPE_7 |
---|
5211 | Void TComTrQuant::xT( UInt uiMode, Pel* piBlkResi, UInt uiStride, Long* psCoeff, Int iSize ) |
---|
5212 | #else |
---|
5213 | Void TComTrQuant::xT( Pel* piBlkResi, UInt uiStride, Long* psCoeff, Int iSize ) |
---|
5214 | #endif |
---|
5215 | { |
---|
5216 | #if MATRIX_MULT |
---|
5217 | #if INTRA_DST_TYPE_7 |
---|
5218 | xTr(piBlkResi,psCoeff,uiStride,(UInt)iSize,uiMode); |
---|
5219 | #else |
---|
5220 | xTr(piBlkResi,psCoeff,uiStride,(UInt)iSize); |
---|
5221 | #endif |
---|
5222 | #else |
---|
5223 | Int j,k; |
---|
5224 | if (iSize==4) |
---|
5225 | { |
---|
5226 | short block[4][4]; |
---|
5227 | short coeff[4][4]; |
---|
5228 | for (j=0; j<4; j++) |
---|
5229 | { |
---|
5230 | memcpy(block[j],piBlkResi+j*uiStride,4*sizeof(short)); |
---|
5231 | } |
---|
5232 | #if INTRA_DST_TYPE_7 |
---|
5233 | xTr4(block,coeff,uiMode); |
---|
5234 | #else |
---|
5235 | xTr4(block,coeff); |
---|
5236 | #endif |
---|
5237 | for (j=0; j<4; j++) |
---|
5238 | { |
---|
5239 | for (k=0; k<4; k++) |
---|
5240 | { |
---|
5241 | psCoeff[j*4+k] = coeff[j][k]; |
---|
5242 | } |
---|
5243 | } |
---|
5244 | } |
---|
5245 | else if (iSize==8) |
---|
5246 | { |
---|
5247 | short block[8][8]; |
---|
5248 | short coeff[8][8]; |
---|
5249 | |
---|
5250 | for (j=0; j<8; j++) |
---|
5251 | { |
---|
5252 | memcpy(block[j],piBlkResi+j*uiStride,8*sizeof(short)); |
---|
5253 | } |
---|
5254 | |
---|
5255 | xTr8(block,coeff); |
---|
5256 | for (j=0; j<8; j++) |
---|
5257 | { |
---|
5258 | for (k=0; k<8; k++) |
---|
5259 | { |
---|
5260 | psCoeff[j*8+k] = coeff[j][k]; |
---|
5261 | } |
---|
5262 | } |
---|
5263 | } |
---|
5264 | else if (iSize==16) |
---|
5265 | { |
---|
5266 | short block[16][16]; |
---|
5267 | short coeff[16][16]; |
---|
5268 | |
---|
5269 | for (j=0; j<16; j++) |
---|
5270 | { |
---|
5271 | memcpy(block[j],piBlkResi+j*uiStride,16*sizeof(short)); |
---|
5272 | } |
---|
5273 | xTr16(block,coeff); |
---|
5274 | for (j=0; j<16; j++) |
---|
5275 | { |
---|
5276 | for (k=0; k<16; k++) |
---|
5277 | { |
---|
5278 | psCoeff[j*16+k] = coeff[j][k]; |
---|
5279 | } |
---|
5280 | } |
---|
5281 | } |
---|
5282 | else if (iSize==32) |
---|
5283 | { |
---|
5284 | short block[32][32]; |
---|
5285 | short coeff[32][32]; |
---|
5286 | |
---|
5287 | for (j=0; j<32; j++) |
---|
5288 | { |
---|
5289 | memcpy(block[j],piBlkResi+j*uiStride,32*sizeof(short)); |
---|
5290 | } |
---|
5291 | xTr32(block,coeff); |
---|
5292 | for (j=0; j<32; j++) |
---|
5293 | { |
---|
5294 | for (k=0; k<32; k++) |
---|
5295 | { |
---|
5296 | psCoeff[j*32+k] = coeff[j][k]; |
---|
5297 | } |
---|
5298 | } |
---|
5299 | } |
---|
5300 | #endif |
---|
5301 | } |
---|
5302 | |
---|
5303 | /** Wrapper function between HM interface and core NxN inverse transform (2D) |
---|
5304 | * \param plCoef input data (transform coefficients) |
---|
5305 | * \param pResidual output data (residual) |
---|
5306 | * \param uiStride stride of input residual data |
---|
5307 | * \param iSize transform size (iSize x iSize) |
---|
5308 | * \param uiMode is Intra Prediction mode used in Mode-Dependent DCT/DST only |
---|
5309 | */ |
---|
5310 | #if INTRA_DST_TYPE_7 |
---|
5311 | Void TComTrQuant::xIT( UInt uiMode, Long* plCoef, Pel* pResidual, UInt uiStride, Int iSize ) |
---|
5312 | #else |
---|
5313 | Void TComTrQuant::xIT( Long* plCoef, Pel* pResidual, UInt uiStride, Int iSize ) |
---|
5314 | #endif |
---|
5315 | { |
---|
5316 | #if MATRIX_MULT |
---|
5317 | #if INTRA_DST_TYPE_7 |
---|
5318 | xITr(plCoef,pResidual,uiStride,(UInt)iSize,uiMode); |
---|
5319 | #else |
---|
5320 | xITr(plCoef,pResidual,uiStride,(UInt)iSize); |
---|
5321 | #endif |
---|
5322 | #else |
---|
5323 | Int j,k; |
---|
5324 | if (iSize==4) |
---|
5325 | { |
---|
5326 | short block[4][4]; |
---|
5327 | short coeff[4][4]; |
---|
5328 | |
---|
5329 | for (j=0; j<4; j++) |
---|
5330 | { |
---|
5331 | for (k=0; k<4; k++) |
---|
5332 | { |
---|
5333 | coeff[j][k] = (short)plCoef[j*4+k]; |
---|
5334 | } |
---|
5335 | } |
---|
5336 | #if INTRA_DST_TYPE_7 |
---|
5337 | xITr4(coeff,block,uiMode); |
---|
5338 | #else |
---|
5339 | xITr4(coeff,block); |
---|
5340 | #endif |
---|
5341 | for (j=0; j<4; j++) |
---|
5342 | { |
---|
5343 | memcpy(pResidual+j*uiStride,block[j],4*sizeof(short)); |
---|
5344 | } |
---|
5345 | } |
---|
5346 | else if (iSize==8) |
---|
5347 | { |
---|
5348 | short block[8][8]; |
---|
5349 | short coeff[8][8]; |
---|
5350 | |
---|
5351 | for (j=0; j<8; j++) |
---|
5352 | { |
---|
5353 | for (k=0; k<8; k++) |
---|
5354 | { |
---|
5355 | coeff[j][k] = (short)plCoef[j*8+k]; |
---|
5356 | } |
---|
5357 | } |
---|
5358 | xITr8(coeff,block); |
---|
5359 | for (j=0; j<8; j++) |
---|
5360 | { |
---|
5361 | memcpy(pResidual+j*uiStride,block[j],8*sizeof(short)); |
---|
5362 | } |
---|
5363 | } |
---|
5364 | else if (iSize==16) |
---|
5365 | { |
---|
5366 | short block[16][16]; |
---|
5367 | short coeff[16][16]; |
---|
5368 | |
---|
5369 | for (j=0; j<16; j++) |
---|
5370 | { |
---|
5371 | for (k=0; k<16; k++) |
---|
5372 | { |
---|
5373 | coeff[j][k] = (short)plCoef[j*16+k]; |
---|
5374 | } |
---|
5375 | } |
---|
5376 | xITr16(coeff,block); |
---|
5377 | for (j=0; j<16; j++) |
---|
5378 | { |
---|
5379 | memcpy(pResidual+j*uiStride,block[j],16*sizeof(short)); |
---|
5380 | } |
---|
5381 | } |
---|
5382 | |
---|
5383 | else if (iSize==32) |
---|
5384 | { |
---|
5385 | short block[32][32]; |
---|
5386 | short coeff[32][32]; |
---|
5387 | |
---|
5388 | for (j=0; j<32; j++) |
---|
5389 | { |
---|
5390 | for (k=0; k<32; k++) |
---|
5391 | { |
---|
5392 | coeff[j][k] = (short)plCoef[j*32+k]; |
---|
5393 | } |
---|
5394 | } |
---|
5395 | xITr32(coeff,block); |
---|
5396 | for (j=0; j<32; j++) |
---|
5397 | { |
---|
5398 | memcpy(pResidual+j*uiStride,block[j],32*sizeof(short)); |
---|
5399 | } |
---|
5400 | } |
---|
5401 | #endif |
---|
5402 | } |
---|
5403 | #else |
---|
5404 | |
---|
5405 | Void TComTrQuant::xT( Pel* piBlkResi, UInt uiStride, Long* psCoeff, Int iSize ) |
---|
5406 | { |
---|
5407 | switch( iSize ) |
---|
5408 | { |
---|
5409 | case 2: xT2 ( piBlkResi, uiStride, psCoeff ); break; |
---|
5410 | case 4: xT4 ( piBlkResi, uiStride, psCoeff ); break; |
---|
5411 | case 8: xT8 ( piBlkResi, uiStride, psCoeff ); break; |
---|
5412 | case 16: xT16( piBlkResi, uiStride, psCoeff ); break; |
---|
5413 | case 32: xT32( piBlkResi, uiStride, psCoeff ); break; |
---|
5414 | default: assert(0); break; |
---|
5415 | } |
---|
5416 | } |
---|
5417 | |
---|
5418 | Void TComTrQuant::xIT( Long* plCoef, Pel* pResidual, UInt uiStride, Int iSize ) |
---|
5419 | { |
---|
5420 | switch( iSize ) |
---|
5421 | { |
---|
5422 | case 2: xIT2 ( plCoef, pResidual, uiStride ); break; |
---|
5423 | case 4: xIT4 ( plCoef, pResidual, uiStride ); break; |
---|
5424 | case 8: xIT8 ( plCoef, pResidual, uiStride ); break; |
---|
5425 | case 16: xIT16( plCoef, pResidual, uiStride ); break; |
---|
5426 | case 32: xIT32( plCoef, pResidual, uiStride ); break; |
---|
5427 | default: assert(0); break; |
---|
5428 | } |
---|
5429 | } |
---|
5430 | #endif //E243_CORE_TRANSFORMS |
---|
5431 | #if QC_MDCS |
---|
5432 | UInt TComTrQuant::getCurrLineNum(UInt uiScanIdx, UInt uiPosX, UInt uiPosY) |
---|
5433 | { |
---|
5434 | UInt uiLineNum = 0; |
---|
5435 | |
---|
5436 | switch (uiScanIdx) |
---|
5437 | { |
---|
5438 | case SCAN_ZIGZAG: |
---|
5439 | uiLineNum = uiPosY + uiPosX; |
---|
5440 | break; |
---|
5441 | case SCAN_HOR: |
---|
5442 | uiLineNum = uiPosY; |
---|
5443 | break; |
---|
5444 | case SCAN_VER: |
---|
5445 | uiLineNum = uiPosX; |
---|
5446 | break; |
---|
5447 | } |
---|
5448 | |
---|
5449 | return uiLineNum; |
---|
5450 | } |
---|
5451 | #endif |
---|
5452 | |
---|
5453 | /** RDOQ with CABAC |
---|
5454 | * \param pcCU pointer to coding unit structure |
---|
5455 | * \param plSrcCoeff pointer to input buffer |
---|
5456 | * \param piDstCoeff reference to pointer to output buffer |
---|
5457 | * \param uiWidth block width |
---|
5458 | * \param uiHeight block height |
---|
5459 | * \param uiAbsSum reference to absolute sum of quantized transform coefficient |
---|
5460 | * \param eTType plane type / luminance or chrominance |
---|
5461 | * \param uiAbsPartIdx absolute partition index |
---|
5462 | * \returns Void |
---|
5463 | * Rate distortion optimized quantization for entropy |
---|
5464 | * coding engines using probability models like CABAC |
---|
5465 | */ |
---|
5466 | Void TComTrQuant::xRateDistOptQuant ( TComDataCU* pcCU, |
---|
5467 | Long* plSrcCoeff, |
---|
5468 | TCoeff*& piDstCoeff, |
---|
5469 | UInt uiWidth, |
---|
5470 | UInt uiHeight, |
---|
5471 | UInt& uiAbsSum, |
---|
5472 | TextType eTType, |
---|
5473 | UInt uiAbsPartIdx ) |
---|
5474 | { |
---|
5475 | Int iQBits = m_cQP.m_iBits; |
---|
5476 | Double dTemp = 0; |
---|
5477 | |
---|
5478 | #if E243_CORE_TRANSFORMS |
---|
5479 | UInt uiLog2TrSize = g_aucConvertToBit[ uiWidth ] + 2; |
---|
5480 | UInt uiQ = g_auiQ[m_cQP.rem()]; |
---|
5481 | |
---|
5482 | #if FULL_NBIT |
---|
5483 | UInt uiBitDepth = g_uiBitDepth; |
---|
5484 | #else |
---|
5485 | UInt uiBitDepth = g_uiBitDepth + g_uiBitIncrement; |
---|
5486 | #endif |
---|
5487 | Int iTransformShift = MAX_TR_DYNAMIC_RANGE - uiBitDepth - uiLog2TrSize; // Represents scaling through forward transform |
---|
5488 | double dErrScale = (double)(1<<SCALE_BITS); // Compensate for scaling of bitcount in Lagrange cost function |
---|
5489 | dErrScale = dErrScale*pow(2.0,-2.0*iTransformShift); // Compensate for scaling through forward transform |
---|
5490 | dErrScale = dErrScale/(double)(uiQ*uiQ); // Compensate for qp-dependent multiplier applied before calculating the Lagrange cost function |
---|
5491 | dErrScale = dErrScale/(double)(1<<(2*g_uiBitIncrement)); // Compensate for Lagrange multiplier that is tuned towards 8-bit input |
---|
5492 | |
---|
5493 | iQBits = QUANT_SHIFT + m_cQP.m_iPer + iTransformShift; // Right shift of non-RDOQ quantizer; level = (coeff*uiQ + offset)>>q_bits |
---|
5494 | #else |
---|
5495 | Bool b64Flag = false; |
---|
5496 | Int iQuantCoeff = 0; |
---|
5497 | Int iQpRem = m_cQP.m_iRem; |
---|
5498 | Bool bExt8x8Flag = false; |
---|
5499 | Double dNormFactor = 0; |
---|
5500 | if( uiWidth == 4 && uiHeight == 4 ) |
---|
5501 | { |
---|
5502 | dNormFactor = pow( 2., ( 2 * DQ_BITS + 19 ) ); |
---|
5503 | if( g_uiBitIncrement ) |
---|
5504 | { |
---|
5505 | dNormFactor *= 1 << ( 2 * g_uiBitIncrement ); |
---|
5506 | } |
---|
5507 | m_puiQuantMtx = &g_aiQuantCoef[ m_cQP.m_iRem ][ 0 ]; |
---|
5508 | } |
---|
5509 | else if( uiWidth == 8 && uiHeight == 8 ) |
---|
5510 | { |
---|
5511 | iQBits++; |
---|
5512 | dNormFactor = pow( 2., ( 2 * Q_BITS_8 + 9 ) ); |
---|
5513 | if( g_uiBitIncrement ) |
---|
5514 | { |
---|
5515 | dNormFactor *= 1 << ( 2 * g_uiBitIncrement ); |
---|
5516 | } |
---|
5517 | m_puiQuantMtx = &g_aiQuantCoef64[ m_cQP.m_iRem ][ 0 ]; |
---|
5518 | } |
---|
5519 | else if( uiWidth == 16 && uiHeight == 16 ) |
---|
5520 | { |
---|
5521 | iQBits = ECore16Shift + m_cQP.per(); |
---|
5522 | dNormFactor = pow( 2., 21 ); |
---|
5523 | if( g_uiBitIncrement ) |
---|
5524 | { |
---|
5525 | dNormFactor *= 1 << ( 2 * g_uiBitIncrement ); |
---|
5526 | } |
---|
5527 | dTemp = estErr16x16[ iQpRem ] / dNormFactor; |
---|
5528 | m_puiQuantMtx = ( &g_aiQuantCoef256[ m_cQP.m_iRem ][ 0 ] ); |
---|
5529 | bExt8x8Flag = true; |
---|
5530 | } |
---|
5531 | else if ( uiWidth == 32 && uiHeight == 32 ) |
---|
5532 | { |
---|
5533 | iQBits = ECore32Shift + m_cQP.per(); |
---|
5534 | dNormFactor = pow( 2., 21 ); |
---|
5535 | if( g_uiBitIncrement ) |
---|
5536 | { |
---|
5537 | dNormFactor *= 1 << ( 2 * g_uiBitIncrement ); |
---|
5538 | } |
---|
5539 | dTemp = estErr32x32[ iQpRem ] / dNormFactor; |
---|
5540 | m_puiQuantMtx = ( &g_aiQuantCoef1024[ m_cQP.m_iRem ][ 0 ] ); |
---|
5541 | bExt8x8Flag = true; |
---|
5542 | } |
---|
5543 | else |
---|
5544 | { |
---|
5545 | assert( 0 ); |
---|
5546 | } |
---|
5547 | #endif |
---|
5548 | |
---|
5549 | #if E253 |
---|
5550 | UInt uiGoRiceParam = 0; |
---|
5551 | #endif |
---|
5552 | #if PCP_SIGMAP_SIMPLE_LAST |
---|
5553 | UInt uiLastScanPos = 0; |
---|
5554 | #else |
---|
5555 | UInt uiMaxLineNum = 0; |
---|
5556 | #endif |
---|
5557 | Double d64BlockUncodedCost = 0; |
---|
5558 | const UInt uiLog2BlkSize = g_aucConvertToBit[ uiWidth ] + 2; |
---|
5559 | const UInt uiMaxNumCoeff = 1 << ( uiLog2BlkSize << 1 ); |
---|
5560 | const UInt uiNum4x4Blk = max<UInt>( 1, uiMaxNumCoeff >> 4 ); |
---|
5561 | #if QC_MDCS |
---|
5562 | const UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
5563 | #endif //QC_MDCS |
---|
5564 | |
---|
5565 | Int piCoeff [ MAX_CU_SIZE * MAX_CU_SIZE ]; |
---|
5566 | Long plLevelDouble[ MAX_CU_SIZE * MAX_CU_SIZE ]; |
---|
5567 | #if E253 |
---|
5568 | UInt puiEstParams [ 16384 ]; |
---|
5569 | |
---|
5570 | ::memset( piDstCoeff, 0, sizeof(TCoeff) * uiMaxNumCoeff ); |
---|
5571 | ::memset( piCoeff, 0, sizeof(Int) * uiMaxNumCoeff ); |
---|
5572 | ::memset( plLevelDouble, 0, sizeof(Long) * uiMaxNumCoeff ); |
---|
5573 | ::memset( puiEstParams, 0, sizeof(UInt) * ( uiMaxNumCoeff << 2 ) ); |
---|
5574 | |
---|
5575 | UInt *puiOneCtx = puiEstParams; |
---|
5576 | UInt *puiAbsCtx = puiEstParams + uiMaxNumCoeff; |
---|
5577 | UInt *puiAbsGoRice = puiEstParams + ( uiMaxNumCoeff << 1 ); |
---|
5578 | UInt *puiBaseCtx = puiEstParams + ( uiMaxNumCoeff << 1 ) + uiMaxNumCoeff; |
---|
5579 | #else |
---|
5580 | UInt puiOneCtx [ MAX_CU_SIZE * MAX_CU_SIZE ]; |
---|
5581 | UInt puiAbsCtx [ MAX_CU_SIZE * MAX_CU_SIZE ]; |
---|
5582 | UInt puiBaseCtx [ ( MAX_CU_SIZE * MAX_CU_SIZE ) >> 4 ]; |
---|
5583 | |
---|
5584 | |
---|
5585 | ::memset( piDstCoeff, 0, sizeof(TCoeff) * uiMaxNumCoeff ); |
---|
5586 | ::memset( piCoeff, 0, sizeof(Int) * uiMaxNumCoeff ); |
---|
5587 | ::memset( plLevelDouble, 0, sizeof(Long) * uiMaxNumCoeff ); |
---|
5588 | ::memset( puiOneCtx, 0, sizeof(UInt) * uiMaxNumCoeff ); |
---|
5589 | ::memset( puiAbsCtx, 0, sizeof(UInt) * uiMaxNumCoeff ); |
---|
5590 | ::memset( puiBaseCtx, 0, sizeof(UInt) * ( uiMaxNumCoeff >> 4 ) ); |
---|
5591 | #endif |
---|
5592 | |
---|
5593 | //===== quantization ===== |
---|
5594 | for( UInt uiScanPos = 0; uiScanPos < uiMaxNumCoeff; uiScanPos++ ) |
---|
5595 | { |
---|
5596 | #if PCP_SIGMAP_SIMPLE_LAST |
---|
5597 | UInt uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanPos]; |
---|
5598 | #else |
---|
5599 | UInt uiBlkPos = g_auiFrameScanXY[ uiLog2BlkSize-1 ][ uiScanPos ]; |
---|
5600 | #endif |
---|
5601 | |
---|
5602 | Long lLevelDouble = plSrcCoeff[ uiBlkPos ]; |
---|
5603 | |
---|
5604 | #if E243_CORE_TRANSFORMS |
---|
5605 | dTemp = dErrScale; |
---|
5606 | lLevelDouble = abs(lLevelDouble * (Long)uiQ); |
---|
5607 | #else |
---|
5608 | UInt uiPosY = uiBlkPos >> uiLog2BlkSize; |
---|
5609 | UInt uiPosX = uiBlkPos - ( uiPosY << uiLog2BlkSize ); |
---|
5610 | if ( uiWidth == 4 ) dTemp = estErr4x4[ iQpRem ][ uiPosX ][ uiPosY ] / dNormFactor; |
---|
5611 | else if ( uiWidth == 8 ) dTemp = estErr8x8[ iQpRem ][ uiPosX ][ uiPosY ] / dNormFactor; |
---|
5612 | |
---|
5613 | lLevelDouble = abs( lLevelDouble * ( Long )( b64Flag ? iQuantCoeff : m_puiQuantMtx[ uiBlkPos ] ) ); |
---|
5614 | #endif |
---|
5615 | plLevelDouble[ uiBlkPos ] = lLevelDouble; |
---|
5616 | UInt uiMaxAbsLevel = lLevelDouble >> iQBits; |
---|
5617 | Bool bLowerInt = ( ( lLevelDouble - Long( uiMaxAbsLevel << iQBits ) ) < Long( 1 << ( iQBits - 1 ) ) ) ? true : false; |
---|
5618 | |
---|
5619 | if( !bLowerInt ) |
---|
5620 | { |
---|
5621 | uiMaxAbsLevel++; |
---|
5622 | } |
---|
5623 | |
---|
5624 | Double dErr = Double( lLevelDouble ); |
---|
5625 | d64BlockUncodedCost += dErr * dErr * dTemp; |
---|
5626 | |
---|
5627 | piCoeff[ uiBlkPos ] = plSrcCoeff[ uiBlkPos ] > 0 ? uiMaxAbsLevel : -Int( uiMaxAbsLevel ); |
---|
5628 | |
---|
5629 | if ( uiMaxAbsLevel > 0 ) |
---|
5630 | { |
---|
5631 | #if PCP_SIGMAP_SIMPLE_LAST |
---|
5632 | uiLastScanPos = uiScanPos; |
---|
5633 | #else |
---|
5634 | #if QC_MDCS |
---|
5635 | UInt uiLineNum = getCurrLineNum(uiScanIdx, uiPosX, uiPosY); |
---|
5636 | #else |
---|
5637 | UInt uiLineNum = uiPosY + uiPosX; |
---|
5638 | #endif //QC_MDCS |
---|
5639 | |
---|
5640 | if( uiLineNum > uiMaxLineNum ) |
---|
5641 | { |
---|
5642 | uiMaxLineNum = uiLineNum; |
---|
5643 | } |
---|
5644 | #endif |
---|
5645 | } |
---|
5646 | } |
---|
5647 | |
---|
5648 | #if PCP_SIGMAP_SIMPLE_LAST |
---|
5649 | uiLastScanPos++; |
---|
5650 | #endif |
---|
5651 | |
---|
5652 | //===== estimate context models ===== |
---|
5653 | if ( uiNum4x4Blk > 1 ) |
---|
5654 | { |
---|
5655 | Bool bFirstBlock = true; |
---|
5656 | UInt uiNumOne = 0; |
---|
5657 | |
---|
5658 | for( UInt uiSubBlk = 0; uiSubBlk < uiNum4x4Blk; uiSubBlk++ ) |
---|
5659 | { |
---|
5660 | UInt uiCtxSet = 0; |
---|
5661 | UInt uiSubNumSig = 0; |
---|
5662 | UInt uiSubPosX = 0; |
---|
5663 | UInt uiSubPosY = 0; |
---|
5664 | #if E253 |
---|
5665 | uiGoRiceParam = 0; |
---|
5666 | #endif |
---|
5667 | |
---|
5668 | uiSubPosX = g_auiFrameScanX[ g_aucConvertToBit[ uiWidth ] - 1 ][ uiSubBlk ] << 2; |
---|
5669 | uiSubPosY = g_auiFrameScanY[ g_aucConvertToBit[ uiWidth ] - 1 ][ uiSubBlk ] << 2; |
---|
5670 | |
---|
5671 | Int* piCurr = &piCoeff[ uiSubPosX + uiSubPosY * uiWidth ]; |
---|
5672 | |
---|
5673 | for( UInt uiY = 0; uiY < 4; uiY++ ) |
---|
5674 | { |
---|
5675 | for( UInt uiX = 0; uiX < 4; uiX++ ) |
---|
5676 | { |
---|
5677 | if( piCurr[ uiX ] ) |
---|
5678 | { |
---|
5679 | uiSubNumSig++; |
---|
5680 | } |
---|
5681 | } |
---|
5682 | piCurr += uiWidth; |
---|
5683 | } |
---|
5684 | |
---|
5685 | if( uiSubNumSig > 0 ) |
---|
5686 | { |
---|
5687 | Int c1 = 1; |
---|
5688 | Int c2 = 0; |
---|
5689 | UInt uiAbs = 0; |
---|
5690 | UInt uiSign = 0; |
---|
5691 | |
---|
5692 | if( bFirstBlock ) |
---|
5693 | { |
---|
5694 | bFirstBlock = false; |
---|
5695 | uiCtxSet = 5; |
---|
5696 | } |
---|
5697 | else |
---|
5698 | { |
---|
5699 | uiCtxSet = ( uiNumOne >> 2 ) + 1; |
---|
5700 | uiNumOne = 0; |
---|
5701 | } |
---|
5702 | |
---|
5703 | puiBaseCtx[ ( uiSubPosX >> 2 ) + ( uiSubPosY >> 2 ) * ( uiWidth >> 2 ) ] = uiCtxSet; |
---|
5704 | |
---|
5705 | for( UInt uiScanPos = 0; uiScanPos < 16; uiScanPos++ ) |
---|
5706 | { |
---|
5707 | UInt uiBlkPos = g_auiFrameScanXY[ 1 ][ 15 - uiScanPos ]; |
---|
5708 | UInt uiPosY = uiBlkPos >> 2; |
---|
5709 | UInt uiPosX = uiBlkPos - ( uiPosY << 2 ); |
---|
5710 | UInt uiIndex = (uiSubPosY + uiPosY) * uiWidth + uiSubPosX + uiPosX; |
---|
5711 | |
---|
5712 | puiOneCtx[ uiIndex ] = min<UInt>( c1, 4 ); |
---|
5713 | puiAbsCtx[ uiIndex ] = min<UInt>( c2, 4 ); |
---|
5714 | #if E253 |
---|
5715 | puiAbsGoRice[ uiIndex ] = uiGoRiceParam; |
---|
5716 | #endif |
---|
5717 | |
---|
5718 | if( piCoeff[ uiIndex ] ) |
---|
5719 | { |
---|
5720 | if( piCoeff[ uiIndex ] > 0) { uiAbs = static_cast<UInt>( piCoeff[ uiIndex ] ); uiSign = 0; } |
---|
5721 | else { uiAbs = static_cast<UInt>( -piCoeff[ uiIndex ] ); uiSign = 1; } |
---|
5722 | |
---|
5723 | UInt uiSymbol = uiAbs > 1 ? 1 : 0; |
---|
5724 | |
---|
5725 | if( uiSymbol ) |
---|
5726 | { |
---|
5727 | c1 = 0; c2++; |
---|
5728 | uiNumOne++; |
---|
5729 | #if E253 |
---|
5730 | if( uiAbs > 3 ) |
---|
5731 | { |
---|
5732 | uiAbs -= 4; |
---|
5733 | uiAbs = min<UInt>( uiAbs, 15 ); |
---|
5734 | uiGoRiceParam = g_aauiGoRiceUpdate[ uiGoRiceParam ][ uiAbs ]; |
---|
5735 | } |
---|
5736 | #endif |
---|
5737 | } |
---|
5738 | else if( c1 ) |
---|
5739 | { |
---|
5740 | c1++; |
---|
5741 | } |
---|
5742 | } |
---|
5743 | } |
---|
5744 | } |
---|
5745 | } |
---|
5746 | } |
---|
5747 | else |
---|
5748 | { |
---|
5749 | Int c1 = 1; |
---|
5750 | Int c2 = 0; |
---|
5751 | UInt uiAbs = 0; |
---|
5752 | UInt uiSign = 0; |
---|
5753 | |
---|
5754 | for ( UInt uiScanPos = 0; uiScanPos < uiWidth*uiHeight; uiScanPos++ ) |
---|
5755 | { |
---|
5756 | UInt uiIndex = g_auiFrameScanXY[ (int)g_aucConvertToBit[ uiWidth ] + 1 ][ uiWidth * uiHeight - uiScanPos - 1 ]; |
---|
5757 | |
---|
5758 | puiOneCtx[ uiIndex ] = min<UInt>( c1, 4 ); |
---|
5759 | puiAbsCtx[ uiIndex ] = min<UInt>( c2, 4 ); |
---|
5760 | #if E253 |
---|
5761 | puiAbsGoRice[ uiIndex ] = uiGoRiceParam; |
---|
5762 | #endif |
---|
5763 | |
---|
5764 | if( piCoeff[ uiIndex ] ) |
---|
5765 | { |
---|
5766 | if( piCoeff[ uiIndex ] > 0) { uiAbs = static_cast<UInt>( piCoeff[ uiIndex ] ); uiSign = 0; } |
---|
5767 | else { uiAbs = static_cast<UInt>( -piCoeff[ uiIndex ] ); uiSign = 1; } |
---|
5768 | |
---|
5769 | UInt uiSymbol = uiAbs > 1 ? 1 : 0; |
---|
5770 | |
---|
5771 | if( uiSymbol ) |
---|
5772 | { |
---|
5773 | c1 = 0; c2++; |
---|
5774 | #if E253 |
---|
5775 | if( uiAbs > 3 ) |
---|
5776 | { |
---|
5777 | uiAbs -= 4; |
---|
5778 | uiAbs = min<UInt>( uiAbs, 15 ); |
---|
5779 | uiGoRiceParam = g_aauiGoRiceUpdate[ uiGoRiceParam ][ uiAbs ]; |
---|
5780 | } |
---|
5781 | #endif |
---|
5782 | } |
---|
5783 | else if( c1 ) |
---|
5784 | { |
---|
5785 | c1++; |
---|
5786 | } |
---|
5787 | } |
---|
5788 | } |
---|
5789 | } |
---|
5790 | |
---|
5791 | Int ui16CtxCbf = 0; |
---|
5792 | UInt uiBestLastIdxP1 = 0; |
---|
5793 | Double d64BestCost = 0; |
---|
5794 | Double d64BaseCost = 0; |
---|
5795 | Double d64CodedCost = 0; |
---|
5796 | Double d64UncodedCost = 0; |
---|
5797 | |
---|
5798 | if( !pcCU->isIntra( uiAbsPartIdx ) && eTType == TEXT_LUMA && pcCU->getTransformIdx( uiAbsPartIdx ) == 0 ) |
---|
5799 | { |
---|
5800 | ui16CtxCbf = pcCU->getCtxQtRootCbf( uiAbsPartIdx ); |
---|
5801 | d64BestCost = d64BlockUncodedCost + xGetICost( m_pcEstBitsSbac->blockRootCbpBits[ ui16CtxCbf ][ 0 ] ); |
---|
5802 | d64BaseCost = d64BestCost - xGetICost( m_pcEstBitsSbac->blockRootCbpBits[ ui16CtxCbf ][ 0 ] ) + xGetICost( m_pcEstBitsSbac->blockRootCbpBits[ ui16CtxCbf ][ 1 ] ); |
---|
5803 | } |
---|
5804 | else |
---|
5805 | { |
---|
5806 | ui16CtxCbf = pcCU->getCtxQtCbf( uiAbsPartIdx, eTType, pcCU->getTransformIdx( uiAbsPartIdx ) ); |
---|
5807 | ui16CtxCbf = ( eTType ? eTType - 1 : eTType ) * NUM_QT_CBF_CTX + ui16CtxCbf; |
---|
5808 | d64BestCost = d64BlockUncodedCost + xGetICost( m_pcEstBitsSbac->blockCbpBits[ ui16CtxCbf ][ 0 ] ); |
---|
5809 | d64BaseCost = d64BestCost - xGetICost( m_pcEstBitsSbac->blockCbpBits[ ui16CtxCbf ][ 0 ] ) + xGetICost( m_pcEstBitsSbac->blockCbpBits[ ui16CtxCbf ][ 1 ] ); |
---|
5810 | } |
---|
5811 | |
---|
5812 | #if PCP_SIGMAP_SIMPLE_LAST |
---|
5813 | Double d64CostLast = 0; |
---|
5814 | TCoeff iLastCoeffLevel = 0; |
---|
5815 | UInt uiBestNonZeroLevel = 0; |
---|
5816 | UInt uiBestLastBlkPos = 0; |
---|
5817 | |
---|
5818 | for( UInt uiScanPos = 0; uiScanPos < uiLastScanPos; uiScanPos++ ) |
---|
5819 | { |
---|
5820 | UInt uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanPos]; |
---|
5821 | UInt uiPosY = uiBlkPos >> uiLog2BlkSize; |
---|
5822 | UInt uiPosX = uiBlkPos - ( uiPosY << uiLog2BlkSize ); |
---|
5823 | UInt uiCtxBase = uiNum4x4Blk > 0 ? puiBaseCtx[ ( uiPosX >> 2 ) + ( uiPosY >> 2 ) * ( uiWidth >> 2 ) ] : 0; |
---|
5824 | |
---|
5825 | #if E243_CORE_TRANSFORMS |
---|
5826 | dTemp = dErrScale; |
---|
5827 | #else |
---|
5828 | if ( uiWidth == 4 ) dTemp = estErr4x4[ iQpRem ][ uiPosX ][ uiPosY ] / dNormFactor; |
---|
5829 | else if ( uiWidth == 8 ) dTemp = estErr8x8[ iQpRem ][ uiPosX ][ uiPosY ] / dNormFactor; |
---|
5830 | #endif |
---|
5831 | |
---|
5832 | UShort uiCtxSig = getSigCtxInc( piDstCoeff, uiPosX, uiPosY, uiLog2BlkSize, uiWidth ); |
---|
5833 | UInt uiMaxAbsLevel = abs( piCoeff[ uiBlkPos ] ); |
---|
5834 | #if E253 |
---|
5835 | UInt uiLevel = xGetCodedLevel( d64UncodedCost, d64CodedCost, d64CostLast, uiBestNonZeroLevel, plLevelDouble[ uiBlkPos ], uiMaxAbsLevel, uiCtxSig, puiOneCtx[ uiBlkPos ], puiAbsCtx[ uiBlkPos ], puiAbsGoRice[ uiBlkPos ], iQBits, dTemp, uiCtxBase ); |
---|
5836 | #else |
---|
5837 | UInt uiLevel = xGetCodedLevel( d64UncodedCost, d64CodedCost, d64CostLast, uiBestNonZeroLevel, plLevelDouble[ uiBlkPos ], uiMaxAbsLevel, uiCtxSig, puiOneCtx[ uiBlkPos ], puiAbsCtx[ uiBlkPos ], iQBits, dTemp, uiCtxBase ); |
---|
5838 | #endif |
---|
5839 | piDstCoeff[ uiBlkPos ] = plSrcCoeff[ uiBlkPos ] < 0 ? -Int( uiLevel ) : uiLevel; |
---|
5840 | d64BaseCost -= d64UncodedCost; |
---|
5841 | |
---|
5842 | if( uiBestNonZeroLevel != 0 ) |
---|
5843 | { |
---|
5844 | d64CostLast += d64BaseCost; |
---|
5845 | d64CostLast += uiScanIdx == SCAN_VER ? xGetRateLast( uiPosY, uiPosX ) : xGetRateLast( uiPosX, uiPosY ); |
---|
5846 | if( d64CostLast < d64BestCost ) |
---|
5847 | { |
---|
5848 | d64BestCost = d64CostLast; |
---|
5849 | uiBestLastIdxP1 = uiScanPos + 1; |
---|
5850 | uiBestLastBlkPos = uiBlkPos; |
---|
5851 | iLastCoeffLevel = plSrcCoeff[ uiBlkPos ] < 0 ? -Int( uiBestNonZeroLevel ) : uiBestNonZeroLevel; |
---|
5852 | } |
---|
5853 | } |
---|
5854 | d64BaseCost += d64CodedCost; |
---|
5855 | } |
---|
5856 | if( uiBestLastBlkPos > 0) |
---|
5857 | { |
---|
5858 | piDstCoeff[ uiBestLastBlkPos ] = iLastCoeffLevel; |
---|
5859 | } |
---|
5860 | #else |
---|
5861 | for( UInt uiScanPos = 0; uiScanPos < uiMaxNumCoeff; uiScanPos++ ) |
---|
5862 | { |
---|
5863 | #if QC_MDCS |
---|
5864 | UInt uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanPos]; |
---|
5865 | #else |
---|
5866 | UInt uiBlkPos = g_auiFrameScanXY[ uiLog2BlkSize-1 ][ uiScanPos ]; |
---|
5867 | #endif //QC_MDCS |
---|
5868 | UInt uiPosY = uiBlkPos >> uiLog2BlkSize; |
---|
5869 | UInt uiPosX = uiBlkPos - ( uiPosY << uiLog2BlkSize ); |
---|
5870 | UInt uiCtxBase = uiNum4x4Blk > 0 ? puiBaseCtx[ ( uiPosX >> 2 ) + ( uiPosY >> 2 ) * ( uiWidth >> 2 ) ] : 0; |
---|
5871 | |
---|
5872 | #if QC_MDCS |
---|
5873 | UInt uiLineNum = getCurrLineNum(uiScanIdx, uiPosX, uiPosY); |
---|
5874 | if ( uiLineNum > uiMaxLineNum ) |
---|
5875 | { |
---|
5876 | break; |
---|
5877 | } |
---|
5878 | #else |
---|
5879 | if( uiPosY + uiPosX > uiMaxLineNum ) |
---|
5880 | { |
---|
5881 | break; |
---|
5882 | } |
---|
5883 | #endif //QC_MDCS |
---|
5884 | |
---|
5885 | if ( uiWidth == 4 ) dTemp = estErr4x4[ iQpRem ][ uiPosX ][ uiPosY ] / dNormFactor; |
---|
5886 | else if ( uiWidth == 8 ) dTemp = estErr8x8[ iQpRem ][ uiPosX ][ uiPosY ] / dNormFactor; |
---|
5887 | |
---|
5888 | UShort uiCtxSig = getSigCtxInc( piDstCoeff, uiPosX, uiPosY, uiLog2BlkSize, uiWidth ); |
---|
5889 | Bool bLastScanPos = ( uiScanPos == uiMaxNumCoeff - 1 ); |
---|
5890 | #if E253 |
---|
5891 | UInt uiLevel = xGetCodedLevel( d64UncodedCost, d64CodedCost, plLevelDouble[ uiBlkPos ], abs( piCoeff[ uiBlkPos ] ), bLastScanPos, uiCtxSig, puiOneCtx[ uiBlkPos ], puiAbsCtx[ uiBlkPos ], puiAbsGoRice[ uiBlkPos ], iQBits, dTemp, uiCtxBase ); |
---|
5892 | #else |
---|
5893 | UInt uiLevel = xGetCodedLevel( d64UncodedCost, d64CodedCost, plLevelDouble[ uiBlkPos ], abs( piCoeff[ uiBlkPos ] ), bLastScanPos, uiCtxSig, puiOneCtx[ uiBlkPos ], puiAbsCtx[ uiBlkPos ], iQBits, dTemp, uiCtxBase ); |
---|
5894 | #endif |
---|
5895 | piDstCoeff[ uiBlkPos ] = plSrcCoeff[ uiBlkPos ] < 0 ? -Int( uiLevel ) : uiLevel; |
---|
5896 | d64BaseCost -= d64UncodedCost; |
---|
5897 | d64BaseCost += d64CodedCost; |
---|
5898 | |
---|
5899 | if( uiLevel ) |
---|
5900 | { |
---|
5901 | //----- check for last flag ----- |
---|
5902 | UShort uiCtxLast = getLastCtxInc( uiPosX, uiPosY, uiLog2BlkSize ); |
---|
5903 | Double d64CostLastZero = xGetICost( m_pcEstBitsSbac->lastBits[ uiCtxLast ][ 0 ] ); |
---|
5904 | Double d64CostLastOne = xGetICost( m_pcEstBitsSbac->lastBits[ uiCtxLast ][ 1 ] ); |
---|
5905 | Double d64CurrIsLastCost = d64BaseCost + d64CostLastOne; |
---|
5906 | d64BaseCost += d64CostLastZero; |
---|
5907 | |
---|
5908 | if( d64CurrIsLastCost < d64BestCost ) |
---|
5909 | { |
---|
5910 | d64BestCost = d64CurrIsLastCost; |
---|
5911 | uiBestLastIdxP1 = uiScanPos + 1; |
---|
5912 | } |
---|
5913 | } |
---|
5914 | } |
---|
5915 | #endif |
---|
5916 | |
---|
5917 | //===== clean uncoded coefficients ===== |
---|
5918 | { |
---|
5919 | for( UInt uiScanPos = 0; uiScanPos < uiMaxNumCoeff; uiScanPos++ ) |
---|
5920 | { |
---|
5921 | #if QC_MDCS |
---|
5922 | UInt uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanPos]; |
---|
5923 | #else |
---|
5924 | UInt uiBlkPos = g_auiFrameScanXY[ uiLog2BlkSize-1 ][ uiScanPos ]; |
---|
5925 | #endif //QC_MDCS |
---|
5926 | |
---|
5927 | if( uiScanPos < uiBestLastIdxP1 ) |
---|
5928 | { |
---|
5929 | uiAbsSum += abs( piDstCoeff[ uiBlkPos ] ); |
---|
5930 | } |
---|
5931 | else |
---|
5932 | { |
---|
5933 | piDstCoeff[ uiBlkPos ] = 0; |
---|
5934 | } |
---|
5935 | } |
---|
5936 | } |
---|
5937 | } |
---|
5938 | |
---|
5939 | #if !SONY_SIG_CTX |
---|
5940 | /** Context derivation process of coeff_abs_significant_flag |
---|
5941 | * \param pcCoeff pointer to prior coded transform coefficients |
---|
5942 | * \param uiPosX column of current scan position |
---|
5943 | * \param uiPosY row of current scan position |
---|
5944 | * \param uiLog2BlkSize log2 value of block size |
---|
5945 | * \param uiStride stride of the block |
---|
5946 | * \returns ctxInc for current scan position |
---|
5947 | */ |
---|
5948 | UInt TComTrQuant::getSigCtxInc ( TCoeff* pcCoeff, |
---|
5949 | const UInt uiPosX, |
---|
5950 | const UInt uiPosY, |
---|
5951 | const UInt uiLog2BlkSize, |
---|
5952 | const UInt uiStride ) |
---|
5953 | { |
---|
5954 | UInt uiCtxInc = 0; |
---|
5955 | UInt uiSizeM1 = ( 1 << uiLog2BlkSize ) - 1; |
---|
5956 | if( uiLog2BlkSize <= 3 ) |
---|
5957 | { |
---|
5958 | UInt uiShift = uiLog2BlkSize > 2 ? uiLog2BlkSize - 2 : 0; |
---|
5959 | uiCtxInc = ( ( uiPosY >> uiShift ) << 2 ) + ( uiPosX >> uiShift ); |
---|
5960 | } |
---|
5961 | else if( uiPosX <= 1 && uiPosY <= 1 ) |
---|
5962 | { |
---|
5963 | uiCtxInc = ( uiPosY << 1 ) + uiPosX; |
---|
5964 | } |
---|
5965 | else if( uiPosY == 0 ) |
---|
5966 | { |
---|
5967 | const int* pData = &pcCoeff[ uiPosX + uiPosY * uiStride ]; |
---|
5968 | int iStride = uiStride; |
---|
5969 | UInt uiCnt = ( pData[ -1 ] ? 1 : 0 ); |
---|
5970 | uiCnt += ( pData[ -2 ] ? 1 : 0 ); |
---|
5971 | uiCnt += ( pData[ iStride -2 ] ? 1 : 0 ); |
---|
5972 | if( ! (uiPosX & 1) ) |
---|
5973 | { |
---|
5974 | uiCnt += ( pData[ iStride -1 ] ? 1 : 0 ); |
---|
5975 | } |
---|
5976 | uiCtxInc = 4 + ( ( uiCnt + 1 ) >> 1 ); |
---|
5977 | } |
---|
5978 | else if( uiPosX == 0 ) |
---|
5979 | { |
---|
5980 | const int* pData = &pcCoeff[ uiPosX + uiPosY * uiStride ]; |
---|
5981 | int iStride = uiStride; |
---|
5982 | int iStride2= iStride << 1; |
---|
5983 | UInt uiCnt = ( pData[ -iStride ] ? 1 : 0 ); |
---|
5984 | uiCnt += ( pData[ -iStride2 ] ? 1 : 0 ); |
---|
5985 | uiCnt += ( pData[ 1-iStride2 ] ? 1 : 0 ); |
---|
5986 | if( uiPosY & 1 ) |
---|
5987 | { |
---|
5988 | uiCnt += ( pData[ 1-iStride ] ? 1 : 0 ); |
---|
5989 | } |
---|
5990 | uiCtxInc = 7 + ( ( uiCnt + 1 ) >> 1 ); |
---|
5991 | } |
---|
5992 | else |
---|
5993 | { |
---|
5994 | const int* pData = &pcCoeff[ uiPosX + uiPosY * uiStride ]; |
---|
5995 | int iStride = uiStride; |
---|
5996 | int iStride2= iStride << 1; |
---|
5997 | UInt uiCnt = ( pData[ -iStride ] ? 1 : 0 ); |
---|
5998 | uiCnt += ( pData[ -1 ] ? 1 : 0 ); |
---|
5999 | uiCnt += ( pData[ -1 -iStride ] ? 1 : 0 ); |
---|
6000 | if( uiPosX > 1 ) |
---|
6001 | { |
---|
6002 | uiCnt += ( pData[ -2 ] ? 1 : 0 ); |
---|
6003 | uiCnt += ( pData[ -2 -iStride ] ? 1 : 0 ); |
---|
6004 | if( uiPosY < uiSizeM1 ) |
---|
6005 | { |
---|
6006 | uiCnt += ( pData[ -2 +iStride ] ? 1 : 0 ); |
---|
6007 | } |
---|
6008 | } |
---|
6009 | if( uiPosY > 1 ) |
---|
6010 | { |
---|
6011 | uiCnt += ( pData[ -iStride2 ] ? 1 : 0 ); |
---|
6012 | uiCnt += ( pData[ -1 -iStride2 ] ? 1 : 0 ); |
---|
6013 | if( uiPosX < uiSizeM1 ) |
---|
6014 | { |
---|
6015 | uiCnt += ( pData[ 1 -iStride2 ] ? 1 : 0 ); |
---|
6016 | } |
---|
6017 | } |
---|
6018 | if( (uiPosX + uiPosY) & 1 ) |
---|
6019 | { |
---|
6020 | if( uiPosX < uiSizeM1 ) |
---|
6021 | { |
---|
6022 | uiCnt += ( pData[ 1 -iStride ] ? 1 : 0 ); |
---|
6023 | } |
---|
6024 | } |
---|
6025 | else |
---|
6026 | { |
---|
6027 | if( uiPosY < uiSizeM1 ) |
---|
6028 | { |
---|
6029 | uiCnt += ( pData[ -1 +iStride ] ? 1 : 0 ); |
---|
6030 | } |
---|
6031 | } |
---|
6032 | uiCtxInc = 10 + min<UInt>( 4, ( uiCnt + 1 ) >> 1 ); |
---|
6033 | } |
---|
6034 | return uiCtxInc; |
---|
6035 | } |
---|
6036 | #else |
---|
6037 | /** Context derivation process of coeff_abs_significant_flag |
---|
6038 | * \param pcCoeff pointer to prior coded transform coefficients |
---|
6039 | * \param uiPosX column of current scan position |
---|
6040 | * \param uiPosY row of current scan position |
---|
6041 | * \param uiLog2BlkSize log2 value of block size |
---|
6042 | * \param uiStride stride of the block |
---|
6043 | * \returns ctxInc for current scan position |
---|
6044 | */ |
---|
6045 | UInt TComTrQuant::getSigCtxInc ( TCoeff* pcCoeff, |
---|
6046 | const UInt uiPosX, |
---|
6047 | const UInt uiPosY, |
---|
6048 | const UInt uiLog2BlkSize, |
---|
6049 | const UInt uiStride ) |
---|
6050 | { |
---|
6051 | UInt uiCtxInc = 0; |
---|
6052 | |
---|
6053 | if( uiLog2BlkSize <= 3 ) |
---|
6054 | { |
---|
6055 | UInt uiShift = uiLog2BlkSize > 2 ? uiLog2BlkSize - 2 : 0; |
---|
6056 | uiCtxInc = ( ( uiPosY >> uiShift ) << 2 ) + ( uiPosX >> uiShift ); |
---|
6057 | } |
---|
6058 | else if( uiPosX <= 1 && uiPosY <= 1 ) |
---|
6059 | { |
---|
6060 | uiCtxInc = ( uiPosY << 1 ) + uiPosX; |
---|
6061 | } |
---|
6062 | else if( uiPosY == 0 ) |
---|
6063 | { |
---|
6064 | const int* pData = &pcCoeff[ uiPosX + uiPosY * uiStride ]; |
---|
6065 | UInt uiCnt = ( pData[ -1 ] ? 1 : 0 ); |
---|
6066 | uiCnt += ( pData[ -2 ] ? 1 : 0 ); |
---|
6067 | uiCtxInc = 4 + uiCnt; |
---|
6068 | } |
---|
6069 | else if( uiPosX == 0 ) |
---|
6070 | { |
---|
6071 | const int* pData = &pcCoeff[ uiPosX + uiPosY * uiStride ]; |
---|
6072 | int iStride = uiStride; |
---|
6073 | int iStride2= iStride << 1; |
---|
6074 | UInt uiCnt = ( pData[ -iStride ] ? 1 : 0 ); |
---|
6075 | uiCnt += ( pData[ -iStride2 ] ? 1 : 0 ); |
---|
6076 | uiCtxInc = 7 + uiCnt; |
---|
6077 | } |
---|
6078 | else |
---|
6079 | { |
---|
6080 | const int* pData = &pcCoeff[ uiPosX + uiPosY * uiStride ]; |
---|
6081 | int iStride = uiStride; |
---|
6082 | int iStride2= iStride << 1; |
---|
6083 | UInt uiCnt = ( pData[ -1 -iStride ] ? 1 : 0 ); |
---|
6084 | uiCnt += ( pData[ -iStride ] ? 1 : 0 ); |
---|
6085 | uiCnt += ( pData[ -1 ] ? 1 : 0 ); |
---|
6086 | if( uiPosX > 1 ) |
---|
6087 | { |
---|
6088 | uiCnt += ( pData[ -2 ] ? 1 : 0 ); |
---|
6089 | } |
---|
6090 | if ( uiPosY > 1 ) |
---|
6091 | { |
---|
6092 | uiCnt += ( pData[ -iStride2 ] ? 1 : 0 ); |
---|
6093 | } |
---|
6094 | uiCtxInc = 10 + min<UInt>( 4, uiCnt); |
---|
6095 | } |
---|
6096 | return uiCtxInc; |
---|
6097 | } |
---|
6098 | #endif |
---|
6099 | |
---|
6100 | #if !PCP_SIGMAP_SIMPLE_LAST |
---|
6101 | /** Context derivation of coeff_abs_last_significant_flag |
---|
6102 | * \param uiPosX column of current scan position |
---|
6103 | * \param uiPosY row of current scan position |
---|
6104 | * \param uiLog2BlkSize log2 value of block size |
---|
6105 | * \returns ctxInc for current scan position |
---|
6106 | */ |
---|
6107 | UInt TComTrQuant::getLastCtxInc ( const UInt uiPosX, |
---|
6108 | const UInt uiPosY, |
---|
6109 | const UInt uiLog2BlkSize ) |
---|
6110 | { |
---|
6111 | if( uiLog2BlkSize <= 2 ) |
---|
6112 | { |
---|
6113 | return ( uiPosY << 2 ) + uiPosX; |
---|
6114 | } |
---|
6115 | else |
---|
6116 | { |
---|
6117 | return ( uiPosX + uiPosY ) >> ( uiLog2BlkSize - 3 ); |
---|
6118 | } |
---|
6119 | } |
---|
6120 | #endif |
---|
6121 | |
---|
6122 | #if E253 && PCP_SIGMAP_SIMPLE_LAST // only valid if both tools are enabled |
---|
6123 | /** Get the best level in RD sense |
---|
6124 | * \param rd64UncodedCost reference to uncoded cost |
---|
6125 | * \param rd64CodedCost reference to current coded cost |
---|
6126 | * \param rd64CodedLastCost reference to coded cost of coefficient without the significance cost |
---|
6127 | * \param uiBestNonZeroLevel !!! not available yet |
---|
6128 | * \param lLevelDouble reference to unscaled quantized level |
---|
6129 | * \param uiMaxAbsLevel scaled quantized level |
---|
6130 | * \param ui16CtxNumSig current ctxInc for coeff_abs_significant_flag |
---|
6131 | * \param ui16CtxNumOne current ctxInc for coeff_abs_level_greater1 (1st bin of coeff_abs_level_minus1 in AVC) |
---|
6132 | * \param ui16CtxNumAbs current ctxInc for coeff_abs_level_greater2 (remaining bins of coeff_abs_level_minus1 in AVC) |
---|
6133 | * \param ui16AbsGoRice current Rice parameter for coeff_abs_level_minus3 |
---|
6134 | * \param iQBits quantization step size |
---|
6135 | * \param dTemp correction factor |
---|
6136 | * \param ui16CtxBase current global offset for coeff_abs_level_greater1 and coeff_abs_level_greater2 |
---|
6137 | * \returns best quantized transform level for given scan position |
---|
6138 | * This method calculates the best quantized transform level for a given scan position. |
---|
6139 | */ |
---|
6140 | #else |
---|
6141 | /** Get the best level in RD sense |
---|
6142 | * \param rd64UncodedCost reference to uncoded cost |
---|
6143 | * \param rd64CodedCost reference to current coded cost |
---|
6144 | * \param lLevelDouble reference to unscaled quantized level |
---|
6145 | * \param uiMaxAbsLevel scaled quantized level |
---|
6146 | * \param bLastScanPos last scan position |
---|
6147 | * \param ui16CtxNumSig current ctxInc for coeff_abs_significant_flag |
---|
6148 | * \param ui16CtxNumOne current ctxInc for coeff_abs_level_greater1 (1st bin of coeff_abs_level_minus1 in AVC) |
---|
6149 | * \param ui16CtxNumAbs current ctxInc for coeff_abs_level_minus2 (remaining bins of coeff_abs_level_minus1 in AVC) |
---|
6150 | * \param iQBits quantization step size |
---|
6151 | * \param dTemp correction factor |
---|
6152 | * \param ui16CtxBase current global offset for coeff_abs_level_greater1 and coeff_abs_level_minus2 |
---|
6153 | * \returns best quantized transform level for given scan position |
---|
6154 | * This method calculates the best quantized transform level for a given scan position. |
---|
6155 | */ |
---|
6156 | #endif |
---|
6157 | __inline UInt TComTrQuant::xGetCodedLevel ( Double& rd64UncodedCost, |
---|
6158 | Double& rd64CodedCost, |
---|
6159 | #if PCP_SIGMAP_SIMPLE_LAST |
---|
6160 | Double& rd64CodedLastCost, |
---|
6161 | UInt& ruiBestNonZeroLevel, |
---|
6162 | Long lLevelDouble, |
---|
6163 | UInt uiMaxAbsLevel, |
---|
6164 | #else |
---|
6165 | Long lLevelDouble, |
---|
6166 | UInt uiMaxAbsLevel, |
---|
6167 | bool bLastScanPos, |
---|
6168 | #endif |
---|
6169 | UShort ui16CtxNumSig, |
---|
6170 | UShort ui16CtxNumOne, |
---|
6171 | UShort ui16CtxNumAbs, |
---|
6172 | #if E253 |
---|
6173 | UShort ui16AbsGoRice, |
---|
6174 | #endif |
---|
6175 | Int iQBits, |
---|
6176 | Double dTemp, |
---|
6177 | UShort ui16CtxBase ) const |
---|
6178 | { |
---|
6179 | UInt uiBestAbsLevel = 0; |
---|
6180 | Double dErr1 = Double( lLevelDouble ); |
---|
6181 | |
---|
6182 | rd64UncodedCost = dErr1 * dErr1 * dTemp; |
---|
6183 | #if PCP_SIGMAP_SIMPLE_LAST |
---|
6184 | rd64CodedCost = rd64UncodedCost + xGetRateSigCoef( 0, ui16CtxNumSig ); |
---|
6185 | |
---|
6186 | ruiBestNonZeroLevel = 0; |
---|
6187 | if( uiMaxAbsLevel ) |
---|
6188 | { |
---|
6189 | UInt uiAbsLevel = uiMaxAbsLevel; |
---|
6190 | ruiBestNonZeroLevel = uiMaxAbsLevel; |
---|
6191 | Double dErr = Double( lLevelDouble - Long( uiAbsLevel << iQBits ) ); |
---|
6192 | #if E253 |
---|
6193 | rd64CodedLastCost = dErr * dErr * dTemp + xGetICRateCost( uiAbsLevel, ui16CtxNumOne, ui16CtxNumAbs, ui16AbsGoRice, ui16CtxBase ); |
---|
6194 | #else |
---|
6195 | rd64CodedLastCost = dErr * dErr * dTemp + xGetICRateCost( uiAbsLevel, ui16CtxNumOne, ui16CtxNumAbs, ui16CtxBase ); |
---|
6196 | #endif |
---|
6197 | } |
---|
6198 | else |
---|
6199 | { |
---|
6200 | return uiBestAbsLevel; |
---|
6201 | } |
---|
6202 | |
---|
6203 | UInt uiAbsLevel = ( uiMaxAbsLevel > 1 ? uiMaxAbsLevel - 1 : 1 ); |
---|
6204 | if( uiAbsLevel != uiMaxAbsLevel ) |
---|
6205 | { |
---|
6206 | Double dErr = Double( lLevelDouble - Long( uiAbsLevel << iQBits ) ); |
---|
6207 | #if E253 |
---|
6208 | Double dCurrCost = dErr * dErr * dTemp + xGetICRateCost( uiAbsLevel, ui16CtxNumOne, ui16CtxNumAbs, ui16AbsGoRice, ui16CtxBase ); |
---|
6209 | #else |
---|
6210 | Double dCurrCost = dErr * dErr * dTemp + xGetICRateCost( uiAbsLevel, ui16CtxNumOne, ui16CtxNumAbs, ui16CtxBase ); |
---|
6211 | #endif |
---|
6212 | if( dCurrCost < rd64CodedLastCost ) |
---|
6213 | { |
---|
6214 | ruiBestNonZeroLevel = uiAbsLevel; |
---|
6215 | rd64CodedLastCost = dCurrCost; |
---|
6216 | } |
---|
6217 | } |
---|
6218 | |
---|
6219 | Double dCurrCost = rd64CodedLastCost + xGetRateSigCoef( 1, ui16CtxNumSig ); |
---|
6220 | |
---|
6221 | if( dCurrCost < rd64CodedCost ) |
---|
6222 | { |
---|
6223 | uiBestAbsLevel = ruiBestNonZeroLevel; |
---|
6224 | rd64CodedCost = dCurrCost; |
---|
6225 | } |
---|
6226 | #else |
---|
6227 | #if E253 |
---|
6228 | rd64CodedCost = rd64UncodedCost + xGetICRateCost( 0, bLastScanPos, ui16CtxNumSig, ui16CtxNumOne, ui16CtxNumAbs, ui16AbsGoRice, ui16CtxBase ); |
---|
6229 | #else |
---|
6230 | rd64CodedCost = rd64UncodedCost + xGetICRateCost( 0, bLastScanPos, ui16CtxNumSig, ui16CtxNumOne, ui16CtxNumAbs, ui16CtxBase ); |
---|
6231 | #endif |
---|
6232 | |
---|
6233 | UInt uiMinAbsLevel = ( uiMaxAbsLevel > 1 ? uiMaxAbsLevel - 1 : 1 ); |
---|
6234 | for( UInt uiAbsLevel = uiMaxAbsLevel; uiAbsLevel >= uiMinAbsLevel ; uiAbsLevel-- ) |
---|
6235 | { |
---|
6236 | Double i64Delta = Double( lLevelDouble - Long( uiAbsLevel << iQBits ) ); |
---|
6237 | Double dErr = Double( i64Delta ); |
---|
6238 | #if E253 |
---|
6239 | Double dCurrCost = dErr * dErr * dTemp + xGetICRateCost( uiAbsLevel, bLastScanPos, ui16CtxNumSig, ui16CtxNumOne, ui16CtxNumAbs, ui16AbsGoRice, ui16CtxBase ); |
---|
6240 | #else |
---|
6241 | Double dCurrCost = dErr * dErr * dTemp + xGetICRateCost( uiAbsLevel, bLastScanPos, ui16CtxNumSig, ui16CtxNumOne, ui16CtxNumAbs, ui16CtxBase ); |
---|
6242 | #endif |
---|
6243 | |
---|
6244 | if( dCurrCost < rd64CodedCost ) |
---|
6245 | { |
---|
6246 | uiBestAbsLevel = uiAbsLevel; |
---|
6247 | rd64CodedCost = dCurrCost; |
---|
6248 | } |
---|
6249 | } |
---|
6250 | #endif |
---|
6251 | return uiBestAbsLevel; |
---|
6252 | } |
---|
6253 | |
---|
6254 | #if E253 && PCP_SIGMAP_SIMPLE_LAST // only valid if both tools are enabled |
---|
6255 | /** Calculates the cost for specific absolute transform level |
---|
6256 | * \param uiAbsLevel scaled quantized level |
---|
6257 | * \param bLastScanPos last scan position |
---|
6258 | * \param ui16CtxNumSig current ctxInc for coeff_abs_significant_flag |
---|
6259 | * \param ui16CtxNumOne current ctxInc for coeff_abs_level_greater1 (1st bin of coeff_abs_level_minus1 in AVC) |
---|
6260 | * \param ui16CtxNumAbs current ctxInc for coeff_abs_level_greater2 (remaining bins of coeff_abs_level_minus1 in AVC) |
---|
6261 | * \param ui16AbsGoRice Rice parameter for coeff_abs_level_minus3 |
---|
6262 | * \param ui16CtxBase current global offset for coeff_abs_level_greater1 and coeff_abs_level_greater2 |
---|
6263 | * \returns cost of given absolute transform level |
---|
6264 | */ |
---|
6265 | #endif |
---|
6266 | __inline Double TComTrQuant::xGetICRateCost ( UInt uiAbsLevel, |
---|
6267 | #if !PCP_SIGMAP_SIMPLE_LAST |
---|
6268 | Bool bLastScanPos, |
---|
6269 | UShort ui16CtxNumSig, |
---|
6270 | #endif |
---|
6271 | UShort ui16CtxNumOne, |
---|
6272 | UShort ui16CtxNumAbs, |
---|
6273 | #if E253 |
---|
6274 | UShort ui16AbsGoRice, |
---|
6275 | #endif |
---|
6276 | UShort ui16CtxBase ) const |
---|
6277 | { |
---|
6278 | #if PCP_SIGMAP_SIMPLE_LAST |
---|
6279 | Double iRate = xGetIEPRate(); |
---|
6280 | #else |
---|
6281 | if( uiAbsLevel == 0 ) |
---|
6282 | { |
---|
6283 | Double iRate = 0; |
---|
6284 | if( !bLastScanPos ) |
---|
6285 | { |
---|
6286 | iRate += m_pcEstBitsSbac->significantBits[ ui16CtxNumSig ][ 0 ]; |
---|
6287 | } |
---|
6288 | return xGetICost( iRate ); |
---|
6289 | } |
---|
6290 | Double iRate = xGetIEPRate(); |
---|
6291 | if( !bLastScanPos ) |
---|
6292 | { |
---|
6293 | iRate += m_pcEstBitsSbac->significantBits[ ui16CtxNumSig ][ 1 ]; |
---|
6294 | } |
---|
6295 | #endif |
---|
6296 | if( uiAbsLevel == 1 ) |
---|
6297 | { |
---|
6298 | iRate += m_pcEstBitsSbac->greaterOneBits[ ui16CtxBase ][ 0 ][ ui16CtxNumOne ][ 0 ]; |
---|
6299 | } |
---|
6300 | #if E253 |
---|
6301 | else if( uiAbsLevel == 2 ) |
---|
6302 | { |
---|
6303 | iRate += m_pcEstBitsSbac->greaterOneBits[ ui16CtxBase ][ 0 ][ ui16CtxNumOne ][ 1 ]; |
---|
6304 | iRate += m_pcEstBitsSbac->greaterOneBits[ ui16CtxBase ][ 1 ][ ui16CtxNumAbs ][ 0 ]; |
---|
6305 | } |
---|
6306 | else |
---|
6307 | { |
---|
6308 | UInt uiSymbol = uiAbsLevel - 3; |
---|
6309 | UInt uiMaxVlc = g_auiGoRiceRange[ ui16AbsGoRice ]; |
---|
6310 | Bool bExpGolomb = ( uiSymbol > uiMaxVlc ); |
---|
6311 | |
---|
6312 | if( bExpGolomb ) |
---|
6313 | { |
---|
6314 | uiAbsLevel = uiSymbol - uiMaxVlc; |
---|
6315 | int iEGS = 1; for( UInt uiMax = 2; uiAbsLevel >= uiMax; uiMax <<= 1, iEGS += 2 ); |
---|
6316 | iRate += iEGS << 15; |
---|
6317 | uiSymbol = min<UInt>( uiSymbol, ( uiMaxVlc + 1 ) ); |
---|
6318 | } |
---|
6319 | |
---|
6320 | UShort ui16PrefLen = UShort( uiSymbol >> ui16AbsGoRice ) + 1; |
---|
6321 | UShort ui16NumBins = min<UInt>( ui16PrefLen, g_auiGoRicePrefixLen[ ui16AbsGoRice ] ) + ui16AbsGoRice; |
---|
6322 | |
---|
6323 | iRate += ui16NumBins << 15; |
---|
6324 | iRate += m_pcEstBitsSbac->greaterOneBits[ ui16CtxBase ][ 0 ][ ui16CtxNumOne ][ 1 ]; |
---|
6325 | iRate += m_pcEstBitsSbac->greaterOneBits[ ui16CtxBase ][ 1 ][ ui16CtxNumAbs ][ 1 ]; |
---|
6326 | } |
---|
6327 | #else |
---|
6328 | else if( uiAbsLevel < 15 ) |
---|
6329 | { |
---|
6330 | iRate += m_pcEstBitsSbac->greaterOneBits[ ui16CtxBase ][ 0 ][ ui16CtxNumOne ][ 1 ]; |
---|
6331 | iRate += m_pcEstBitsSbac->greaterOneBits[ ui16CtxBase ][ 1 ][ ui16CtxNumAbs ][ 0 ]; |
---|
6332 | iRate += m_pcEstBitsSbac->greaterOneBits[ ui16CtxBase ][ 1 ][ ui16CtxNumAbs ][ 1 ] * (int)( uiAbsLevel - 2 ); |
---|
6333 | } |
---|
6334 | else |
---|
6335 | { |
---|
6336 | uiAbsLevel -= 14; |
---|
6337 | int iEGS = 1; for( UInt uiMax = 2; uiAbsLevel >= uiMax; uiMax <<= 1, iEGS += 2 ); |
---|
6338 | iRate += m_pcEstBitsSbac->greaterOneBits[ ui16CtxBase ][ 0 ][ ui16CtxNumOne ][ 1 ]; |
---|
6339 | iRate += m_pcEstBitsSbac->greaterOneBits[ ui16CtxBase ][ 1 ][ ui16CtxNumAbs ][ 1 ] * 13; |
---|
6340 | iRate += xGetIEPRate() * iEGS; |
---|
6341 | } |
---|
6342 | #endif |
---|
6343 | return xGetICost( iRate ); |
---|
6344 | } |
---|
6345 | |
---|
6346 | #if PCP_SIGMAP_SIMPLE_LAST |
---|
6347 | /** Calculates the cost of signaling the last significant coefficient in the block |
---|
6348 | * \param uiPosX X coordinate of the last significant coefficient |
---|
6349 | * \param uiPosY Y coordinate of the last significant coefficient |
---|
6350 | * \returns cost of last significant coefficient |
---|
6351 | */ |
---|
6352 | __inline Double TComTrQuant::xGetRateLast ( UInt uiPosX, |
---|
6353 | UInt uiPosY ) const |
---|
6354 | { |
---|
6355 | return xGetICost( m_pcEstBitsSbac->lastXBits[ uiPosX ] + m_pcEstBitsSbac->lastYBits[ uiPosY ] ); |
---|
6356 | } |
---|
6357 | |
---|
6358 | /** Calculates the cost for specific absolute transform level |
---|
6359 | * \param uiAbsLevel scaled quantized level |
---|
6360 | * \param ui16CtxNumOne current ctxInc for coeff_abs_level_greater1 (1st bin of coeff_abs_level_minus1 in AVC) |
---|
6361 | * \param ui16CtxNumAbs current ctxInc for coeff_abs_level_greater2 (remaining bins of coeff_abs_level_minus1 in AVC) |
---|
6362 | * \param ui16CtxBase current global offset for coeff_abs_level_greater1 and coeff_abs_level_greater2 |
---|
6363 | * \returns cost of given absolute transform level |
---|
6364 | */ |
---|
6365 | __inline Double TComTrQuant::xGetRateSigCoef ( UShort uiSignificance, |
---|
6366 | UShort ui16CtxNumSig ) const |
---|
6367 | { |
---|
6368 | return xGetICost( m_pcEstBitsSbac->significantBits[ ui16CtxNumSig ][ uiSignificance ] ); |
---|
6369 | } |
---|
6370 | #endif |
---|
6371 | |
---|
6372 | /** Get the cost for a specific rate |
---|
6373 | * \param dRate rate of a bit |
---|
6374 | * \returns cost at the specific rate |
---|
6375 | */ |
---|
6376 | __inline Double TComTrQuant::xGetICost ( Double dRate ) const |
---|
6377 | { |
---|
6378 | return m_dLambda * dRate; |
---|
6379 | } |
---|
6380 | |
---|
6381 | /** Get the cost of an equal probable bit |
---|
6382 | * \returns cost of equal probable bit |
---|
6383 | */ |
---|
6384 | __inline Double TComTrQuant::xGetIEPRate ( ) const |
---|
6385 | { |
---|
6386 | return 32768; |
---|
6387 | } |
---|