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-2012, ITU/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 ITU/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 | /** \file TComRom.cpp |
---|
35 | \brief global variables & functions |
---|
36 | */ |
---|
37 | |
---|
38 | #include "TComRom.h" |
---|
39 | #include <memory.h> |
---|
40 | #include <stdlib.h> |
---|
41 | #include <stdio.h> |
---|
42 | // ==================================================================================================================== |
---|
43 | // Initialize / destroy functions |
---|
44 | // ==================================================================================================================== |
---|
45 | |
---|
46 | //! \ingroup TLibCommon |
---|
47 | //! \{ |
---|
48 | |
---|
49 | // initialize ROM variables |
---|
50 | Void initROM() |
---|
51 | { |
---|
52 | Int i, c; |
---|
53 | |
---|
54 | // g_aucConvertToBit[ x ]: log2(x/4), if x=4 -> 0, x=8 -> 1, x=16 -> 2, ... |
---|
55 | ::memset( g_aucConvertToBit, -1, sizeof( g_aucConvertToBit ) ); |
---|
56 | c=0; |
---|
57 | for ( i=4; i<MAX_CU_SIZE; i*=2 ) |
---|
58 | { |
---|
59 | g_aucConvertToBit[ i ] = c; |
---|
60 | c++; |
---|
61 | } |
---|
62 | g_aucConvertToBit[ i ] = c; |
---|
63 | |
---|
64 | // g_auiFrameScanXY[ g_aucConvertToBit[ transformSize ] ]: zigzag scan array for transformSize |
---|
65 | c=2; |
---|
66 | for ( i=0; i<MAX_CU_DEPTH; i++ ) |
---|
67 | { |
---|
68 | g_auiFrameScanXY[ i ] = new UInt[ c*c ]; |
---|
69 | g_auiFrameScanX [ i ] = new UInt[ c*c ]; |
---|
70 | g_auiFrameScanY [ i ] = new UInt[ c*c ]; |
---|
71 | initFrameScanXY( g_auiFrameScanXY[i], g_auiFrameScanX[i], g_auiFrameScanY[i], c, c ); |
---|
72 | g_auiSigLastScan[0][i] = new UInt[ c*c ]; |
---|
73 | g_auiSigLastScan[1][i] = new UInt[ c*c ]; |
---|
74 | g_auiSigLastScan[2][i] = new UInt[ c*c ]; |
---|
75 | g_auiSigLastScan[3][i] = new UInt[ c*c ]; |
---|
76 | initSigLastScan( g_auiSigLastScan[0][i], g_auiSigLastScan[1][i], g_auiSigLastScan[2][i], g_auiSigLastScan[3][i], c, c, i); |
---|
77 | |
---|
78 | c <<= 1; |
---|
79 | } |
---|
80 | |
---|
81 | g_sigScanNSQT[0] = new UInt[ 64 ]; // 4x16 |
---|
82 | g_sigScanNSQT[1] = new UInt[ 256 ]; // 8x32 |
---|
83 | g_sigScanNSQT[2] = new UInt[ 64 ]; // 16x4 |
---|
84 | g_sigScanNSQT[3] = new UInt[ 256 ]; // 32x8 |
---|
85 | |
---|
86 | static int diagScanX[ 16 ] = |
---|
87 | { |
---|
88 | 0, 0, 1, 0, 1, 2, 0, 1, 2, 3, 1, 2, 3, 2, 3, 3 |
---|
89 | }; |
---|
90 | static int diagScanY[ 16 ] = |
---|
91 | { |
---|
92 | 0, 1, 0, 2, 1, 0, 3, 2, 1, 0, 3, 2, 1, 3, 2, 3 |
---|
93 | }; |
---|
94 | |
---|
95 | Int j; |
---|
96 | // 4x16 scan |
---|
97 | for (i = 0; i < 4; i++) |
---|
98 | { |
---|
99 | for (j = 0; j < 16; j++) |
---|
100 | { |
---|
101 | g_sigScanNSQT[ 0 ][ 16 * i + j ] = 16 * i + 4 * diagScanY[ j ] + diagScanX[ j ]; |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | // 8x32 scan |
---|
106 | for (i = 0; i < 16; i++) |
---|
107 | { |
---|
108 | Int x = g_sigCGScanNSQT[ 1 ][ i ] & 1; |
---|
109 | Int y = g_sigCGScanNSQT[ 1 ][ i ] >> 1; |
---|
110 | |
---|
111 | for (j = 0; j < 16; j++) |
---|
112 | { |
---|
113 | g_sigScanNSQT[ 1 ][ 16 * i + j ] = 32 * y + 4 * x + 8 * diagScanY[ j ] + diagScanX[ j ]; |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | // 16x4 scan |
---|
118 | for (i = 0; i < 4; i++) |
---|
119 | { |
---|
120 | for (j = 0; j < 16; j++) |
---|
121 | { |
---|
122 | g_sigScanNSQT[ 2 ][ 16 * i + j ] = 4 * i + 16 * diagScanY[ j ] + diagScanX[ j ]; |
---|
123 | } |
---|
124 | } |
---|
125 | |
---|
126 | // 32x8 scan |
---|
127 | for (i = 0; i < 16; i++) |
---|
128 | { |
---|
129 | Int x = g_sigCGScanNSQT[ 3 ][ i ] & 7; |
---|
130 | Int y = g_sigCGScanNSQT[ 3 ][ i ] >> 3; |
---|
131 | |
---|
132 | for (j = 0; j < 16; j++) |
---|
133 | { |
---|
134 | g_sigScanNSQT[ 3 ][ 16 * i + j ] = 128 * y + 4 * x + 32 * diagScanY[ j ] + diagScanX[ j ]; |
---|
135 | } |
---|
136 | } |
---|
137 | } |
---|
138 | |
---|
139 | Void destroyROM() |
---|
140 | { |
---|
141 | Int i; |
---|
142 | |
---|
143 | for ( i=0; i<MAX_CU_DEPTH; i++ ) |
---|
144 | { |
---|
145 | delete[] g_auiFrameScanXY[i]; |
---|
146 | delete[] g_auiFrameScanX [i]; |
---|
147 | delete[] g_auiFrameScanY [i]; |
---|
148 | delete[] g_auiSigLastScan[0][i]; |
---|
149 | delete[] g_auiSigLastScan[1][i]; |
---|
150 | delete[] g_auiSigLastScan[2][i]; |
---|
151 | delete[] g_auiSigLastScan[3][i]; |
---|
152 | } |
---|
153 | for (i = 0; i < 4; i++) |
---|
154 | { |
---|
155 | delete[] g_sigScanNSQT[ i ]; |
---|
156 | } |
---|
157 | |
---|
158 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
159 | if ( !g_aacWedgeLists.empty() ) |
---|
160 | { |
---|
161 | for ( UInt ui = 0; ui < g_aacWedgeLists.size(); ui++ ) |
---|
162 | { |
---|
163 | g_aacWedgeLists[ui].clear(); |
---|
164 | } |
---|
165 | g_aacWedgeLists.clear(); |
---|
166 | } |
---|
167 | |
---|
168 | if ( !g_aacWedgeRefLists.empty() ) |
---|
169 | { |
---|
170 | for ( UInt ui = 0; ui < g_aacWedgeRefLists.size(); ui++ ) |
---|
171 | { |
---|
172 | g_aacWedgeRefLists[ui].clear(); |
---|
173 | } |
---|
174 | g_aacWedgeRefLists.clear(); |
---|
175 | } |
---|
176 | |
---|
177 | if ( !g_aacWedgeNodeLists.empty() ) |
---|
178 | { |
---|
179 | for ( UInt ui = 0; ui < g_aacWedgeNodeLists.size(); ui++ ) |
---|
180 | { |
---|
181 | g_aacWedgeNodeLists[ui].clear(); |
---|
182 | } |
---|
183 | g_aacWedgeNodeLists.clear(); |
---|
184 | } |
---|
185 | |
---|
186 | #endif |
---|
187 | } |
---|
188 | |
---|
189 | // ==================================================================================================================== |
---|
190 | // Data structure related table & variable |
---|
191 | // ==================================================================================================================== |
---|
192 | |
---|
193 | UInt g_uiMaxCUWidth = MAX_CU_SIZE; |
---|
194 | UInt g_uiMaxCUHeight = MAX_CU_SIZE; |
---|
195 | UInt g_uiMaxCUDepth = MAX_CU_DEPTH; |
---|
196 | UInt g_uiAddCUDepth = 0; |
---|
197 | |
---|
198 | UInt g_auiZscanToRaster [ MAX_NUM_SPU_W*MAX_NUM_SPU_W ] = { 0, }; |
---|
199 | UInt g_auiRasterToZscan [ MAX_NUM_SPU_W*MAX_NUM_SPU_W ] = { 0, }; |
---|
200 | UInt g_auiRasterToPelX [ MAX_NUM_SPU_W*MAX_NUM_SPU_W ] = { 0, }; |
---|
201 | UInt g_auiRasterToPelY [ MAX_NUM_SPU_W*MAX_NUM_SPU_W ] = { 0, }; |
---|
202 | UInt g_motionRefer [ MAX_NUM_SPU_W*MAX_NUM_SPU_W ] = { 0, }; |
---|
203 | |
---|
204 | UInt g_auiPUOffset[8] = { 0, 8, 4, 4, 2, 10, 1, 5}; |
---|
205 | |
---|
206 | Void initZscanToRaster ( Int iMaxDepth, Int iDepth, UInt uiStartVal, UInt*& rpuiCurrIdx ) |
---|
207 | { |
---|
208 | Int iStride = 1 << ( iMaxDepth - 1 ); |
---|
209 | |
---|
210 | if ( iDepth == iMaxDepth ) |
---|
211 | { |
---|
212 | rpuiCurrIdx[0] = uiStartVal; |
---|
213 | rpuiCurrIdx++; |
---|
214 | } |
---|
215 | else |
---|
216 | { |
---|
217 | Int iStep = iStride >> iDepth; |
---|
218 | initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal, rpuiCurrIdx ); |
---|
219 | initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal+iStep, rpuiCurrIdx ); |
---|
220 | initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal+iStep*iStride, rpuiCurrIdx ); |
---|
221 | initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal+iStep*iStride+iStep, rpuiCurrIdx ); |
---|
222 | } |
---|
223 | } |
---|
224 | |
---|
225 | Void initRasterToZscan ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth ) |
---|
226 | { |
---|
227 | UInt uiMinCUWidth = uiMaxCUWidth >> ( uiMaxDepth - 1 ); |
---|
228 | UInt uiMinCUHeight = uiMaxCUHeight >> ( uiMaxDepth - 1 ); |
---|
229 | |
---|
230 | UInt uiNumPartInWidth = (UInt)uiMaxCUWidth / uiMinCUWidth; |
---|
231 | UInt uiNumPartInHeight = (UInt)uiMaxCUHeight / uiMinCUHeight; |
---|
232 | |
---|
233 | for ( UInt i = 0; i < uiNumPartInWidth*uiNumPartInHeight; i++ ) |
---|
234 | { |
---|
235 | g_auiRasterToZscan[ g_auiZscanToRaster[i] ] = i; |
---|
236 | } |
---|
237 | } |
---|
238 | |
---|
239 | /** generate motion data compression mapping table |
---|
240 | * \param uiMaxCUWidth, width of LCU |
---|
241 | * \param uiMaxCUHeight, hight of LCU |
---|
242 | * \param uiMaxDepth, max depth of LCU |
---|
243 | * \returns Void |
---|
244 | */ |
---|
245 | Void initMotionReferIdx ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth ) |
---|
246 | { |
---|
247 | Int minCUWidth = (Int)uiMaxCUWidth >> ( (Int)uiMaxDepth - 1 ); |
---|
248 | Int minCUHeight = (Int)uiMaxCUHeight >> ( (Int)uiMaxDepth - 1 ); |
---|
249 | |
---|
250 | Int numPartInWidth = (Int)uiMaxCUWidth / (Int)minCUWidth; |
---|
251 | Int numPartInHeight = (Int)uiMaxCUHeight / (Int)minCUHeight; |
---|
252 | |
---|
253 | for ( Int i = 0; i < numPartInWidth*numPartInHeight; i++ ) |
---|
254 | { |
---|
255 | g_motionRefer[i] = i; |
---|
256 | } |
---|
257 | |
---|
258 | Int compressionNum = 2; |
---|
259 | |
---|
260 | for ( Int i = numPartInWidth*(numPartInHeight-1); i < numPartInWidth*numPartInHeight; i += compressionNum*2) |
---|
261 | { |
---|
262 | for ( Int j = 1; j < compressionNum; j++ ) |
---|
263 | { |
---|
264 | g_motionRefer[g_auiRasterToZscan[i+j]] = g_auiRasterToZscan[i]; |
---|
265 | } |
---|
266 | } |
---|
267 | |
---|
268 | for ( Int i = numPartInWidth*(numPartInHeight-1)+compressionNum*2-1; i < numPartInWidth*numPartInHeight; i += compressionNum*2) |
---|
269 | { |
---|
270 | for ( Int j = 1; j < compressionNum; j++ ) |
---|
271 | { |
---|
272 | g_motionRefer[g_auiRasterToZscan[i-j]] = g_auiRasterToZscan[i]; |
---|
273 | } |
---|
274 | } |
---|
275 | } |
---|
276 | |
---|
277 | Void initRasterToPelXY ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth ) |
---|
278 | { |
---|
279 | UInt i; |
---|
280 | |
---|
281 | UInt* uiTempX = &g_auiRasterToPelX[0]; |
---|
282 | UInt* uiTempY = &g_auiRasterToPelY[0]; |
---|
283 | |
---|
284 | UInt uiMinCUWidth = uiMaxCUWidth >> ( uiMaxDepth - 1 ); |
---|
285 | UInt uiMinCUHeight = uiMaxCUHeight >> ( uiMaxDepth - 1 ); |
---|
286 | |
---|
287 | UInt uiNumPartInWidth = uiMaxCUWidth / uiMinCUWidth; |
---|
288 | UInt uiNumPartInHeight = uiMaxCUHeight / uiMinCUHeight; |
---|
289 | |
---|
290 | uiTempX[0] = 0; uiTempX++; |
---|
291 | for ( i = 1; i < uiNumPartInWidth; i++ ) |
---|
292 | { |
---|
293 | uiTempX[0] = uiTempX[-1] + uiMinCUWidth; uiTempX++; |
---|
294 | } |
---|
295 | for ( i = 1; i < uiNumPartInHeight; i++ ) |
---|
296 | { |
---|
297 | memcpy(uiTempX, uiTempX-uiNumPartInWidth, sizeof(UInt)*uiNumPartInWidth); |
---|
298 | uiTempX += uiNumPartInWidth; |
---|
299 | } |
---|
300 | |
---|
301 | for ( i = 1; i < uiNumPartInWidth*uiNumPartInHeight; i++ ) |
---|
302 | { |
---|
303 | uiTempY[i] = ( i / uiNumPartInWidth ) * uiMinCUWidth; |
---|
304 | } |
---|
305 | }; |
---|
306 | |
---|
307 | #if RWTH_SDC_DLT_B0036 |
---|
308 | #if SAIT_SDC_C0096 |
---|
309 | UInt g_auiSDCPredModes[RWTH_SDC_NUM_PRED_MODES] = { DC_IDX, DMM_WEDGE_FULL_IDX, PLANAR_IDX }; |
---|
310 | #else |
---|
311 | UInt g_auiSDCPredModes[RWTH_SDC_NUM_PRED_MODES] = { DC_IDX, DMM_WEDGE_FULL_IDX, DMM_WEDGE_PREDDIR_IDX, PLANAR_IDX }; |
---|
312 | #endif |
---|
313 | #endif |
---|
314 | |
---|
315 | Int g_quantScales[6] = |
---|
316 | { |
---|
317 | 26214,23302,20560,18396,16384,14564 |
---|
318 | }; |
---|
319 | |
---|
320 | Int g_invQuantScales[6] = |
---|
321 | { |
---|
322 | 40,45,51,57,64,72 |
---|
323 | }; |
---|
324 | |
---|
325 | const short g_aiT4[4][4] = |
---|
326 | { |
---|
327 | { 64, 64, 64, 64}, |
---|
328 | { 83, 36,-36,-83}, |
---|
329 | { 64,-64,-64, 64}, |
---|
330 | { 36,-83, 83,-36} |
---|
331 | }; |
---|
332 | |
---|
333 | const short g_aiT8[8][8] = |
---|
334 | { |
---|
335 | { 64, 64, 64, 64, 64, 64, 64, 64}, |
---|
336 | { 89, 75, 50, 18,-18,-50,-75,-89}, |
---|
337 | { 83, 36,-36,-83,-83,-36, 36, 83}, |
---|
338 | { 75,-18,-89,-50, 50, 89, 18,-75}, |
---|
339 | { 64,-64,-64, 64, 64,-64,-64, 64}, |
---|
340 | { 50,-89, 18, 75,-75,-18, 89,-50}, |
---|
341 | { 36,-83, 83,-36,-36, 83,-83, 36}, |
---|
342 | { 18,-50, 75,-89, 89,-75, 50,-18} |
---|
343 | }; |
---|
344 | |
---|
345 | const short g_aiT16[16][16] = |
---|
346 | { |
---|
347 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}, |
---|
348 | { 90, 87, 80, 70, 57, 43, 25, 9, -9,-25,-43,-57,-70,-80,-87,-90}, |
---|
349 | { 89, 75, 50, 18,-18,-50,-75,-89,-89,-75,-50,-18, 18, 50, 75, 89}, |
---|
350 | { 87, 57, 9,-43,-80,-90,-70,-25, 25, 70, 90, 80, 43, -9,-57,-87}, |
---|
351 | { 83, 36,-36,-83,-83,-36, 36, 83, 83, 36,-36,-83,-83,-36, 36, 83}, |
---|
352 | { 80, 9,-70,-87,-25, 57, 90, 43,-43,-90,-57, 25, 87, 70, -9,-80}, |
---|
353 | { 75,-18,-89,-50, 50, 89, 18,-75,-75, 18, 89, 50,-50,-89,-18, 75}, |
---|
354 | { 70,-43,-87, 9, 90, 25,-80,-57, 57, 80,-25,-90, -9, 87, 43,-70}, |
---|
355 | { 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64}, |
---|
356 | { 57,-80,-25, 90, -9,-87, 43, 70,-70,-43, 87, 9,-90, 25, 80,-57}, |
---|
357 | { 50,-89, 18, 75,-75,-18, 89,-50,-50, 89,-18,-75, 75, 18,-89, 50}, |
---|
358 | { 43,-90, 57, 25,-87, 70, 9,-80, 80, -9,-70, 87,-25,-57, 90,-43}, |
---|
359 | { 36,-83, 83,-36,-36, 83,-83, 36, 36,-83, 83,-36,-36, 83,-83, 36}, |
---|
360 | { 25,-70, 90,-80, 43, 9,-57, 87,-87, 57, -9,-43, 80,-90, 70,-25}, |
---|
361 | { 18,-50, 75,-89, 89,-75, 50,-18,-18, 50,-75, 89,-89, 75,-50, 18}, |
---|
362 | { 9,-25, 43,-57, 70,-80, 87,-90, 90,-87, 80,-70, 57,-43, 25, -9} |
---|
363 | }; |
---|
364 | |
---|
365 | const short g_aiT32[32][32] = |
---|
366 | { |
---|
367 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}, |
---|
368 | { 90, 90, 88, 85, 82, 78, 73, 67, 61, 54, 46, 38, 31, 22, 13, 4, -4,-13,-22,-31,-38,-46,-54,-61,-67,-73,-78,-82,-85,-88,-90,-90}, |
---|
369 | { 90, 87, 80, 70, 57, 43, 25, 9, -9,-25,-43,-57,-70,-80,-87,-90,-90,-87,-80,-70,-57,-43,-25, -9, 9, 25, 43, 57, 70, 80, 87, 90}, |
---|
370 | { 90, 82, 67, 46, 22, -4,-31,-54,-73,-85,-90,-88,-78,-61,-38,-13, 13, 38, 61, 78, 88, 90, 85, 73, 54, 31, 4,-22,-46,-67,-82,-90}, |
---|
371 | { 89, 75, 50, 18,-18,-50,-75,-89,-89,-75,-50,-18, 18, 50, 75, 89, 89, 75, 50, 18,-18,-50,-75,-89,-89,-75,-50,-18, 18, 50, 75, 89}, |
---|
372 | { 88, 67, 31,-13,-54,-82,-90,-78,-46, -4, 38, 73, 90, 85, 61, 22,-22,-61,-85,-90,-73,-38, 4, 46, 78, 90, 82, 54, 13,-31,-67,-88}, |
---|
373 | { 87, 57, 9,-43,-80,-90,-70,-25, 25, 70, 90, 80, 43, -9,-57,-87,-87,-57, -9, 43, 80, 90, 70, 25,-25,-70,-90,-80,-43, 9, 57, 87}, |
---|
374 | { 85, 46,-13,-67,-90,-73,-22, 38, 82, 88, 54, -4,-61,-90,-78,-31, 31, 78, 90, 61, 4,-54,-88,-82,-38, 22, 73, 90, 67, 13,-46,-85}, |
---|
375 | { 83, 36,-36,-83,-83,-36, 36, 83, 83, 36,-36,-83,-83,-36, 36, 83, 83, 36,-36,-83,-83,-36, 36, 83, 83, 36,-36,-83,-83,-36, 36, 83}, |
---|
376 | { 82, 22,-54,-90,-61, 13, 78, 85, 31,-46,-90,-67, 4, 73, 88, 38,-38,-88,-73, -4, 67, 90, 46,-31,-85,-78,-13, 61, 90, 54,-22,-82}, |
---|
377 | { 80, 9,-70,-87,-25, 57, 90, 43,-43,-90,-57, 25, 87, 70, -9,-80,-80, -9, 70, 87, 25,-57,-90,-43, 43, 90, 57,-25,-87,-70, 9, 80}, |
---|
378 | { 78, -4,-82,-73, 13, 85, 67,-22,-88,-61, 31, 90, 54,-38,-90,-46, 46, 90, 38,-54,-90,-31, 61, 88, 22,-67,-85,-13, 73, 82, 4,-78}, |
---|
379 | { 75,-18,-89,-50, 50, 89, 18,-75,-75, 18, 89, 50,-50,-89,-18, 75, 75,-18,-89,-50, 50, 89, 18,-75,-75, 18, 89, 50,-50,-89,-18, 75}, |
---|
380 | { 73,-31,-90,-22, 78, 67,-38,-90,-13, 82, 61,-46,-88, -4, 85, 54,-54,-85, 4, 88, 46,-61,-82, 13, 90, 38,-67,-78, 22, 90, 31,-73}, |
---|
381 | { 70,-43,-87, 9, 90, 25,-80,-57, 57, 80,-25,-90, -9, 87, 43,-70,-70, 43, 87, -9,-90,-25, 80, 57,-57,-80, 25, 90, 9,-87,-43, 70}, |
---|
382 | { 67,-54,-78, 38, 85,-22,-90, 4, 90, 13,-88,-31, 82, 46,-73,-61, 61, 73,-46,-82, 31, 88,-13,-90, -4, 90, 22,-85,-38, 78, 54,-67}, |
---|
383 | { 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64}, |
---|
384 | { 61,-73,-46, 82, 31,-88,-13, 90, -4,-90, 22, 85,-38,-78, 54, 67,-67,-54, 78, 38,-85,-22, 90, 4,-90, 13, 88,-31,-82, 46, 73,-61}, |
---|
385 | { 57,-80,-25, 90, -9,-87, 43, 70,-70,-43, 87, 9,-90, 25, 80,-57,-57, 80, 25,-90, 9, 87,-43,-70, 70, 43,-87, -9, 90,-25,-80, 57}, |
---|
386 | { 54,-85, -4, 88,-46,-61, 82, 13,-90, 38, 67,-78,-22, 90,-31,-73, 73, 31,-90, 22, 78,-67,-38, 90,-13,-82, 61, 46,-88, 4, 85,-54}, |
---|
387 | { 50,-89, 18, 75,-75,-18, 89,-50,-50, 89,-18,-75, 75, 18,-89, 50, 50,-89, 18, 75,-75,-18, 89,-50,-50, 89,-18,-75, 75, 18,-89, 50}, |
---|
388 | { 46,-90, 38, 54,-90, 31, 61,-88, 22, 67,-85, 13, 73,-82, 4, 78,-78, -4, 82,-73,-13, 85,-67,-22, 88,-61,-31, 90,-54,-38, 90,-46}, |
---|
389 | { 43,-90, 57, 25,-87, 70, 9,-80, 80, -9,-70, 87,-25,-57, 90,-43,-43, 90,-57,-25, 87,-70, -9, 80,-80, 9, 70,-87, 25, 57,-90, 43}, |
---|
390 | { 38,-88, 73, -4,-67, 90,-46,-31, 85,-78, 13, 61,-90, 54, 22,-82, 82,-22,-54, 90,-61,-13, 78,-85, 31, 46,-90, 67, 4,-73, 88,-38}, |
---|
391 | { 36,-83, 83,-36,-36, 83,-83, 36, 36,-83, 83,-36,-36, 83,-83, 36, 36,-83, 83,-36,-36, 83,-83, 36, 36,-83, 83,-36,-36, 83,-83, 36}, |
---|
392 | { 31,-78, 90,-61, 4, 54,-88, 82,-38,-22, 73,-90, 67,-13,-46, 85,-85, 46, 13,-67, 90,-73, 22, 38,-82, 88,-54, -4, 61,-90, 78,-31}, |
---|
393 | { 25,-70, 90,-80, 43, 9,-57, 87,-87, 57, -9,-43, 80,-90, 70,-25,-25, 70,-90, 80,-43, -9, 57,-87, 87,-57, 9, 43,-80, 90,-70, 25}, |
---|
394 | { 22,-61, 85,-90, 73,-38, -4, 46,-78, 90,-82, 54,-13,-31, 67,-88, 88,-67, 31, 13,-54, 82,-90, 78,-46, 4, 38,-73, 90,-85, 61,-22}, |
---|
395 | { 18,-50, 75,-89, 89,-75, 50,-18,-18, 50,-75, 89,-89, 75,-50, 18, 18,-50, 75,-89, 89,-75, 50,-18,-18, 50,-75, 89,-89, 75,-50, 18}, |
---|
396 | { 13,-38, 61,-78, 88,-90, 85,-73, 54,-31, 4, 22,-46, 67,-82, 90,-90, 82,-67, 46,-22, -4, 31,-54, 73,-85, 90,-88, 78,-61, 38,-13}, |
---|
397 | { 9,-25, 43,-57, 70,-80, 87,-90, 90,-87, 80,-70, 57,-43, 25, -9, -9, 25,-43, 57,-70, 80,-87, 90,-90, 87,-80, 70,-57, 43,-25, 9}, |
---|
398 | { 4,-13, 22,-31, 38,-46, 54,-61, 67,-73, 78,-82, 85,-88, 90,-90, 90,-90, 88,-85, 82,-78, 73,-67, 61,-54, 46,-38, 31,-22, 13, -4} |
---|
399 | }; |
---|
400 | |
---|
401 | const UChar g_aucChromaScale[52]= |
---|
402 | { |
---|
403 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11, |
---|
404 | 12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27, |
---|
405 | 28,29,29,30,31,32,32,33,34,34,35,35,36,36,37,37, |
---|
406 | 37,38,38,38,39,39,39,39 |
---|
407 | }; |
---|
408 | |
---|
409 | |
---|
410 | // Mode-Dependent DCT/DST |
---|
411 | const short g_as_DST_MAT_4 [4][4]= |
---|
412 | { |
---|
413 | {29, 55, 74, 84}, |
---|
414 | {74, 74, 0 , -74}, |
---|
415 | {84, -29, -74, 55}, |
---|
416 | {55, -84, 74, -29}, |
---|
417 | }; |
---|
418 | |
---|
419 | |
---|
420 | |
---|
421 | // ==================================================================================================================== |
---|
422 | // ADI |
---|
423 | // ==================================================================================================================== |
---|
424 | |
---|
425 | #if FAST_UDI_USE_MPM |
---|
426 | const UChar g_aucIntraModeNumFast[7] = |
---|
427 | { |
---|
428 | 3, // 2x2 |
---|
429 | 8, // 4x4 |
---|
430 | 8, // 8x8 |
---|
431 | 3, // 16x16 |
---|
432 | 3, // 32x32 |
---|
433 | 3, // 64x64 |
---|
434 | 3 // 128x128 |
---|
435 | }; |
---|
436 | #else // FAST_UDI_USE_MPM |
---|
437 | const UChar g_aucIntraModeNumFast[7] = |
---|
438 | { |
---|
439 | 3, // 2x2 |
---|
440 | 9, // 4x4 |
---|
441 | 9, // 8x8 |
---|
442 | 4, // 16x16 33 |
---|
443 | 4, // 32x32 33 |
---|
444 | 5, // 64x64 33 |
---|
445 | 4 // 128x128 33 |
---|
446 | }; |
---|
447 | #endif // FAST_UDI_USE_MPM |
---|
448 | |
---|
449 | // chroma |
---|
450 | |
---|
451 | const UChar g_aucConvertTxtTypeToIdx[4] = { 0, 1, 1, 2 }; |
---|
452 | |
---|
453 | |
---|
454 | // ==================================================================================================================== |
---|
455 | // Bit-depth |
---|
456 | // ==================================================================================================================== |
---|
457 | |
---|
458 | UInt g_uiBitDepth = 8; // base bit-depth |
---|
459 | UInt g_uiBitIncrement = 0; // increments |
---|
460 | UInt g_uiIBDI_MAX = 255; // max. value after IBDI |
---|
461 | UInt g_uiBASE_MAX = 255; // max. value before IBDI |
---|
462 | |
---|
463 | UInt g_uiPCMBitDepthLuma = 8; // PCM bit-depth |
---|
464 | UInt g_uiPCMBitDepthChroma = 8; // PCM bit-depth |
---|
465 | |
---|
466 | // ==================================================================================================================== |
---|
467 | // Depth model modes |
---|
468 | // ==================================================================================================================== |
---|
469 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
470 | Int g_iDeltaDCsQuantOffset = 0; |
---|
471 | |
---|
472 | const WedgeResolution g_aeWedgeResolutionList[5] = |
---|
473 | { |
---|
474 | HALF_PEL, // 4x4 |
---|
475 | HALF_PEL, // 8x8 |
---|
476 | FULL_PEL, // 16x16 |
---|
477 | DOUBLE_PEL, // 32x32 |
---|
478 | DOUBLE_PEL // 64x64 |
---|
479 | }; |
---|
480 | |
---|
481 | const UChar g_aucWedgeFullBitsListIdx[7] = |
---|
482 | { |
---|
483 | 0, // 2x2 |
---|
484 | 7, // 4x4 WedgeListSize[ HALF_PEL] 86 |
---|
485 | 10, // 8x8 WedgeListSize[ HALF_PEL] 782 |
---|
486 | 11, // 16x16 WedgeListSize[ FULL_PEL] 1394 |
---|
487 | 11, // 32x32 WedgeListSize[DOUBLE_PEL] 1503 |
---|
488 | 13, // 64x64 WedgeListSize[DOUBLE_PEL] 6079 |
---|
489 | 0 // 128x128 |
---|
490 | }; |
---|
491 | |
---|
492 | #if LGE_DMM3_SIMP_C0044 |
---|
493 | const UChar g_aucWedgeTexPredBitsListIdx[7] = |
---|
494 | { |
---|
495 | 0, // 2x2 |
---|
496 | 6, // 4x4 |
---|
497 | 9, // 8x8 |
---|
498 | 9, // 16x16 |
---|
499 | 9, // 32x32 |
---|
500 | 0, // 64x64 |
---|
501 | 0 // 128x128 |
---|
502 | }; |
---|
503 | #endif |
---|
504 | |
---|
505 | const UChar g_aucIntraSizeIdxToWedgeSize[7] = |
---|
506 | { |
---|
507 | 2, |
---|
508 | 4, |
---|
509 | 8, |
---|
510 | 16, |
---|
511 | 32, |
---|
512 | 64, |
---|
513 | 128 |
---|
514 | }; |
---|
515 | #endif |
---|
516 | |
---|
517 | // ==================================================================================================================== |
---|
518 | // Misc. |
---|
519 | // ==================================================================================================================== |
---|
520 | |
---|
521 | Char g_aucConvertToBit [ MAX_CU_SIZE+1 ]; |
---|
522 | |
---|
523 | #if ENC_DEC_TRACE |
---|
524 | FILE* g_hTrace = NULL; |
---|
525 | const Bool g_bEncDecTraceEnable = true; |
---|
526 | const Bool g_bEncDecTraceDisable = false; |
---|
527 | Bool g_bJustDoIt = false; |
---|
528 | UInt64 g_nSymbolCounter = 0; |
---|
529 | #endif |
---|
530 | // ==================================================================================================================== |
---|
531 | // Scanning order & context model mapping |
---|
532 | // ==================================================================================================================== |
---|
533 | |
---|
534 | // scanning order table |
---|
535 | UInt* g_auiFrameScanXY[ MAX_CU_DEPTH ]; |
---|
536 | UInt* g_auiFrameScanX [ MAX_CU_DEPTH ]; |
---|
537 | UInt* g_auiFrameScanY [ MAX_CU_DEPTH ]; |
---|
538 | UInt* g_auiSigLastScan[4][ MAX_CU_DEPTH ]; |
---|
539 | UInt *g_sigScanNSQT[ 4 ]; // scan for non-square partitions |
---|
540 | UInt g_sigCGScanNSQT[ 4 ][ 16 ] = |
---|
541 | { |
---|
542 | { 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
---|
543 | { 0, 2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 15 }, |
---|
544 | { 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
---|
545 | { 0, 8, 1, 9, 2, 10, 3, 11, 4, 12, 5, 13, 6, 14, 7, 15 } |
---|
546 | }; |
---|
547 | |
---|
548 | const UInt g_sigLastScan8x8[ 4 ][ 4 ] = |
---|
549 | { |
---|
550 | {0, 1, 2, 3}, |
---|
551 | {0, 1, 2, 3}, |
---|
552 | {0, 1, 2, 3}, |
---|
553 | {0, 2, 1, 3} |
---|
554 | }; |
---|
555 | UInt g_sigLastScanCG32x32[ 64 ]; |
---|
556 | |
---|
557 | UInt* g_auiNonSquareSigLastScan[ 4 ]; |
---|
558 | |
---|
559 | const UInt g_uiMinInGroup[ 10 ] = {0,1,2,3,4,6,8,12,16,24}; |
---|
560 | const UInt g_uiGroupIdx[ 32 ] = {0,1,2,3,4,4,5,5,6,6,6,6,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9}; |
---|
561 | const UInt g_uiLastCtx[ 28 ] = |
---|
562 | { |
---|
563 | 0, 1, 2, 2, // 4x4 4 |
---|
564 | 3, 4, 5, 5, 2, 2, // 8x8 6 |
---|
565 | 6, 7, 8, 8, 9, 9, 2, 2, // 16x16 8 |
---|
566 | 10, 11, 12, 12, 13, 13, 14, 14, 2, 2 // 32x32 10 |
---|
567 | }; |
---|
568 | |
---|
569 | // Rice parameters for absolute transform levels |
---|
570 | const UInt g_auiGoRiceRange[5] = |
---|
571 | { |
---|
572 | 7, 14, 26, 46, 78 |
---|
573 | }; |
---|
574 | |
---|
575 | const UInt g_auiGoRicePrefixLen[5] = |
---|
576 | { |
---|
577 | 8, 7, 6, 5, 4 |
---|
578 | }; |
---|
579 | |
---|
580 | const UInt g_aauiGoRiceUpdate[5][24] = |
---|
581 | { |
---|
582 | { |
---|
583 | 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4 |
---|
584 | }, |
---|
585 | { |
---|
586 | 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4 |
---|
587 | }, |
---|
588 | { |
---|
589 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4 |
---|
590 | }, |
---|
591 | { |
---|
592 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4 |
---|
593 | }, |
---|
594 | { |
---|
595 | 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 |
---|
596 | } |
---|
597 | }; |
---|
598 | |
---|
599 | // initialize g_auiFrameScanXY |
---|
600 | Void initFrameScanXY( UInt* pBuff, UInt* pBuffX, UInt* pBuffY, Int iWidth, Int iHeight ) |
---|
601 | { |
---|
602 | Int x, y, c = 0; |
---|
603 | |
---|
604 | // starting point |
---|
605 | pBuffX[ c ] = 0; |
---|
606 | pBuffY[ c ] = 0; |
---|
607 | pBuff[ c++ ] = 0; |
---|
608 | |
---|
609 | // loop |
---|
610 | x=1; y=0; |
---|
611 | while (1) |
---|
612 | { |
---|
613 | // decrease loop |
---|
614 | while ( x>=0 ) |
---|
615 | { |
---|
616 | if ( x >= 0 && x < iWidth && y >= 0 && y < iHeight ) |
---|
617 | { |
---|
618 | pBuffX[ c ] = x; |
---|
619 | pBuffY[ c ] = y; |
---|
620 | pBuff[ c++ ] = x+y*iWidth; |
---|
621 | } |
---|
622 | x--; y++; |
---|
623 | } |
---|
624 | x=0; |
---|
625 | |
---|
626 | // increase loop |
---|
627 | while ( y>=0 ) |
---|
628 | { |
---|
629 | if ( x >= 0 && x < iWidth && y >= 0 && y < iHeight ) |
---|
630 | { |
---|
631 | pBuffX[ c ] = x; |
---|
632 | pBuffY[ c ] = y; |
---|
633 | pBuff[ c++ ] = x+y*iWidth; |
---|
634 | } |
---|
635 | x++; y--; |
---|
636 | } |
---|
637 | y=0; |
---|
638 | |
---|
639 | // termination condition |
---|
640 | if ( c >= iWidth*iHeight ) break; |
---|
641 | } |
---|
642 | } |
---|
643 | |
---|
644 | Void initSigLastScan(UInt* pBuffZ, UInt* pBuffH, UInt* pBuffV, UInt* pBuffD, Int iWidth, Int iHeight, Int iDepth) |
---|
645 | { |
---|
646 | const UInt uiNumScanPos = UInt( iWidth * iWidth ); |
---|
647 | UInt uiNextScanPos = 0; |
---|
648 | |
---|
649 | if( iWidth < 16 ) |
---|
650 | { |
---|
651 | UInt* pBuffTemp = pBuffD; |
---|
652 | if( iWidth == 8 ) |
---|
653 | { |
---|
654 | pBuffTemp = g_sigLastScanCG32x32; |
---|
655 | } |
---|
656 | for( UInt uiScanLine = 0; uiNextScanPos < uiNumScanPos; uiScanLine++ ) |
---|
657 | { |
---|
658 | int iPrimDim = int( uiScanLine ); |
---|
659 | int iScndDim = 0; |
---|
660 | while( iPrimDim >= iWidth ) |
---|
661 | { |
---|
662 | iScndDim++; |
---|
663 | iPrimDim--; |
---|
664 | } |
---|
665 | while( iPrimDim >= 0 && iScndDim < iWidth ) |
---|
666 | { |
---|
667 | pBuffTemp[ uiNextScanPos ] = iPrimDim * iWidth + iScndDim ; |
---|
668 | uiNextScanPos++; |
---|
669 | iScndDim++; |
---|
670 | iPrimDim--; |
---|
671 | } |
---|
672 | } |
---|
673 | } |
---|
674 | if( iWidth > 4 ) |
---|
675 | { |
---|
676 | UInt uiNumBlkSide = iWidth >> 2; |
---|
677 | UInt uiNumBlks = uiNumBlkSide * uiNumBlkSide; |
---|
678 | UInt log2Blk = g_aucConvertToBit[ uiNumBlkSide ] + 1; |
---|
679 | |
---|
680 | for( UInt uiBlk = 0; uiBlk < uiNumBlks; uiBlk++ ) |
---|
681 | { |
---|
682 | uiNextScanPos = 0; |
---|
683 | UInt initBlkPos = g_auiSigLastScan[ SCAN_DIAG ][ log2Blk ][ uiBlk ]; |
---|
684 | if( iWidth == 32 ) |
---|
685 | { |
---|
686 | initBlkPos = g_sigLastScanCG32x32[ uiBlk ]; |
---|
687 | } |
---|
688 | UInt offsetY = initBlkPos / uiNumBlkSide; |
---|
689 | UInt offsetX = initBlkPos - offsetY * uiNumBlkSide; |
---|
690 | UInt offsetD = 4 * ( offsetX + offsetY * iWidth ); |
---|
691 | UInt offsetScan = 16 * uiBlk; |
---|
692 | for( UInt uiScanLine = 0; uiNextScanPos < 16; uiScanLine++ ) |
---|
693 | { |
---|
694 | int iPrimDim = int( uiScanLine ); |
---|
695 | int iScndDim = 0; |
---|
696 | while( iPrimDim >= 4 ) |
---|
697 | { |
---|
698 | iScndDim++; |
---|
699 | iPrimDim--; |
---|
700 | } |
---|
701 | while( iPrimDim >= 0 && iScndDim < 4 ) |
---|
702 | { |
---|
703 | pBuffD[ uiNextScanPos + offsetScan ] = iPrimDim * iWidth + iScndDim + offsetD; |
---|
704 | uiNextScanPos++; |
---|
705 | iScndDim++; |
---|
706 | iPrimDim--; |
---|
707 | } |
---|
708 | } |
---|
709 | } |
---|
710 | } |
---|
711 | |
---|
712 | memcpy(pBuffZ, g_auiFrameScanXY[iDepth], sizeof(UInt)*iWidth*iHeight); |
---|
713 | |
---|
714 | UInt uiCnt = 0; |
---|
715 | for(Int iY=0; iY < iHeight; iY++) |
---|
716 | { |
---|
717 | for(Int iX=0; iX < iWidth; iX++) |
---|
718 | { |
---|
719 | pBuffH[uiCnt] = iY*iWidth + iX; |
---|
720 | uiCnt ++; |
---|
721 | } |
---|
722 | } |
---|
723 | |
---|
724 | uiCnt = 0; |
---|
725 | for(Int iX=0; iX < iWidth; iX++) |
---|
726 | { |
---|
727 | for(Int iY=0; iY < iHeight; iY++) |
---|
728 | { |
---|
729 | pBuffV[uiCnt] = iY*iWidth + iX; |
---|
730 | uiCnt ++; |
---|
731 | } |
---|
732 | } |
---|
733 | } |
---|
734 | |
---|
735 | Void initNonSquareSigLastScan(UInt* pBuffZ, UInt uiWidth, UInt uiHeight) |
---|
736 | { |
---|
737 | |
---|
738 | Int x, y, c = 0; |
---|
739 | |
---|
740 | // starting point |
---|
741 | pBuffZ[ c++ ] = 0; |
---|
742 | |
---|
743 | // loop |
---|
744 | if ( uiWidth > uiHeight ) |
---|
745 | { |
---|
746 | x=0; y=1; |
---|
747 | while (1) |
---|
748 | { |
---|
749 | // increase loop |
---|
750 | while ( y>=0 ) |
---|
751 | { |
---|
752 | if ( x >= 0 && x < uiWidth && y >= 0 && y < uiHeight ) |
---|
753 | { |
---|
754 | pBuffZ[ c++ ] = x + y * uiWidth; |
---|
755 | } |
---|
756 | x++; |
---|
757 | y--; |
---|
758 | } |
---|
759 | y=0; |
---|
760 | |
---|
761 | // decrease loop |
---|
762 | while ( x>=0 ) |
---|
763 | { |
---|
764 | if ( x >= 0 && x < uiWidth && y >= 0 && y < uiHeight ) |
---|
765 | { |
---|
766 | pBuffZ[ c++ ] = x + y * uiWidth; |
---|
767 | } |
---|
768 | x--; |
---|
769 | y++; |
---|
770 | } |
---|
771 | x=0; |
---|
772 | |
---|
773 | // termination condition |
---|
774 | if ( c >= uiWidth * uiHeight ) |
---|
775 | break; |
---|
776 | } |
---|
777 | } |
---|
778 | else |
---|
779 | { |
---|
780 | x=1; y=0; |
---|
781 | while (1) |
---|
782 | { |
---|
783 | // increase loop |
---|
784 | while ( x>=0 ) |
---|
785 | { |
---|
786 | if ( x >= 0 && x < uiWidth && y >= 0 && y < uiHeight ) |
---|
787 | { |
---|
788 | pBuffZ[ c++ ] = x + y * uiWidth; |
---|
789 | } |
---|
790 | x--; |
---|
791 | y++; |
---|
792 | } |
---|
793 | x=0; |
---|
794 | |
---|
795 | // decrease loop |
---|
796 | while ( y>=0 ) |
---|
797 | { |
---|
798 | if ( x >= 0 && x < uiWidth && y >= 0 && y < uiHeight ) |
---|
799 | { |
---|
800 | pBuffZ[ c++ ] = x + y * uiWidth; |
---|
801 | } |
---|
802 | x++; |
---|
803 | y--; |
---|
804 | } |
---|
805 | y=0; |
---|
806 | |
---|
807 | // termination condition |
---|
808 | if ( c >= uiWidth * uiHeight ) |
---|
809 | break; |
---|
810 | } |
---|
811 | } |
---|
812 | } |
---|
813 | |
---|
814 | Int g_quantIntraDefault4x4[16] = |
---|
815 | { |
---|
816 | 16,16,17,21, |
---|
817 | 16,17,20,25, |
---|
818 | 17,20,30,41, |
---|
819 | 21,25,41,70 |
---|
820 | }; |
---|
821 | Int g_quantInterDefault4x4[16] = |
---|
822 | { |
---|
823 | 16,16,17,21, |
---|
824 | 16,17,21,24, |
---|
825 | 17,21,24,36, |
---|
826 | 21,24,36,57 |
---|
827 | }; |
---|
828 | |
---|
829 | Int g_quantIntraDefault8x8[64] = |
---|
830 | { |
---|
831 | 16,16,16,16,17,18,21,24, |
---|
832 | 16,16,16,16,17,19,22,25, |
---|
833 | 16,16,17,18,20,22,25,29, |
---|
834 | 16,16,18,21,24,27,31,36, |
---|
835 | 17,17,20,24,30,35,41,47, |
---|
836 | 18,19,22,27,35,44,54,65, |
---|
837 | 21,22,25,31,41,54,70,88, |
---|
838 | 24,25,29,36,47,65,88,115 |
---|
839 | }; |
---|
840 | |
---|
841 | Int g_quantInterDefault8x8[64] = |
---|
842 | { |
---|
843 | 16,16,16,16,17,18,20,24, |
---|
844 | 16,16,16,17,18,20,24,25, |
---|
845 | 16,16,17,18,20,24,25,28, |
---|
846 | 16,17,18,20,24,25,28,33, |
---|
847 | 17,18,20,24,25,28,33,41, |
---|
848 | 18,20,24,25,28,33,41,54, |
---|
849 | 20,24,25,28,33,41,54,71, |
---|
850 | 24,25,28,33,41,54,71,91 |
---|
851 | }; |
---|
852 | UInt g_scalingListSize [4] = {16,64,256,1024}; |
---|
853 | UInt g_scalingListSizeX [4] = { 4, 8, 16, 32}; |
---|
854 | UInt g_scalingListNum[SCALING_LIST_SIZE_NUM]={6,6,6,2}; |
---|
855 | Int g_eTTable[4] = {0,3,1,2}; |
---|
856 | |
---|
857 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
858 | std::vector< std::vector<TComWedgelet> > g_aacWedgeLists; |
---|
859 | std::vector< std::vector<TComWedgeRef> > g_aacWedgeRefLists; |
---|
860 | |
---|
861 | std::vector< std::vector< std::vector<UInt> > > g_aauiWdgLstM3; |
---|
862 | std::vector< std::vector< TComWedgeNode> > g_aacWedgeNodeLists; |
---|
863 | |
---|
864 | Void initWedgeLists() |
---|
865 | { |
---|
866 | for( UInt ui = g_aucConvertToBit[DMM_WEDGEMODEL_MIN_SIZE]; ui < (g_aucConvertToBit[DMM_WEDGEMODEL_MAX_SIZE]+1); ui++ ) |
---|
867 | { |
---|
868 | UInt uiWedgeBlockSize = ((UInt)DMM_WEDGEMODEL_MIN_SIZE)<<ui; |
---|
869 | std::vector<TComWedgelet> acWedgeList; |
---|
870 | std::vector<TComWedgeRef> acWedgeRefList; |
---|
871 | createWedgeList( uiWedgeBlockSize, uiWedgeBlockSize, acWedgeList, acWedgeRefList, g_aeWedgeResolutionList[ui] ); |
---|
872 | g_aacWedgeLists.push_back( acWedgeList ); |
---|
873 | g_aacWedgeRefLists.push_back( acWedgeRefList ); |
---|
874 | |
---|
875 | // create WedgeNodeList |
---|
876 | std::vector<TComWedgeNode> acWedgeNodeList; |
---|
877 | for( UInt uiPos = 0; uiPos < acWedgeList.size(); uiPos++ ) |
---|
878 | { |
---|
879 | if( acWedgeList[uiPos].getIsCoarse() ) |
---|
880 | { |
---|
881 | TComWedgeNode cWedgeNode; |
---|
882 | cWedgeNode.setPatternIdx( uiPos ); |
---|
883 | |
---|
884 | // set refinement idxs |
---|
885 | UInt uiRefPos = 0; |
---|
886 | for( Int iOffS = -1; iOffS <= 1; iOffS++ ) |
---|
887 | { |
---|
888 | for( Int iOffE = -1; iOffE <= 1; iOffE++ ) |
---|
889 | { |
---|
890 | if( iOffS == 0 && iOffE == 0 ) { continue; } |
---|
891 | |
---|
892 | Int iSx = (Int)acWedgeList[uiPos].getStartX(); |
---|
893 | Int iSy = (Int)acWedgeList[uiPos].getStartY(); |
---|
894 | Int iEx = (Int)acWedgeList[uiPos].getEndX(); |
---|
895 | Int iEy = (Int)acWedgeList[uiPos].getEndY(); |
---|
896 | |
---|
897 | switch( acWedgeList[uiPos].getOri() ) |
---|
898 | { |
---|
899 | case( 0 ): { iSx += iOffS; iEy += iOffE; } break; |
---|
900 | case( 1 ): { iSy += iOffS; iEx -= iOffE; } break; |
---|
901 | case( 2 ): { iSx -= iOffS; iEy -= iOffE; } break; |
---|
902 | case( 3 ): { iSy -= iOffS; iEx += iOffE; } break; |
---|
903 | case( 4 ): { iSx += iOffS; iEx += iOffE; } break; |
---|
904 | case( 5 ): { iSy += iOffS; iEy += iOffE; } break; |
---|
905 | default: assert( 0 ); |
---|
906 | } |
---|
907 | |
---|
908 | for( UInt k = 0; k < acWedgeRefList.size(); k++ ) |
---|
909 | { |
---|
910 | if( iSx == (Int)acWedgeRefList[k].getStartX() && |
---|
911 | iSy == (Int)acWedgeRefList[k].getStartY() && |
---|
912 | iEx == (Int)acWedgeRefList[k].getEndX() && |
---|
913 | iEy == (Int)acWedgeRefList[k].getEndY() ) |
---|
914 | { |
---|
915 | if( acWedgeRefList[k].getRefIdx() != cWedgeNode.getPatternIdx() ) |
---|
916 | { |
---|
917 | Bool bNew = true; |
---|
918 | for( UInt m = 0; m < uiRefPos; m++ ) { if( acWedgeRefList[k].getRefIdx() == cWedgeNode.getRefineIdx( m ) ) { bNew = false; break; } } |
---|
919 | |
---|
920 | if( bNew ) |
---|
921 | { |
---|
922 | cWedgeNode.setRefineIdx( acWedgeRefList[k].getRefIdx(), uiRefPos ); |
---|
923 | uiRefPos++; |
---|
924 | break; |
---|
925 | } |
---|
926 | } |
---|
927 | } |
---|
928 | } |
---|
929 | } |
---|
930 | } |
---|
931 | acWedgeNodeList.push_back( cWedgeNode ); |
---|
932 | } |
---|
933 | } |
---|
934 | g_aacWedgeNodeLists.push_back( acWedgeNodeList ); |
---|
935 | |
---|
936 | } |
---|
937 | return; |
---|
938 | } |
---|
939 | |
---|
940 | Void createWedgeList( UInt uiWidth, UInt uiHeight, std::vector<TComWedgelet> &racWedgeList, std::vector<TComWedgeRef> &racWedgeRefList, WedgeResolution eWedgeRes ) |
---|
941 | { |
---|
942 | assert( uiWidth == uiHeight ); |
---|
943 | |
---|
944 | UChar uhStartX = 0, uhStartY = 0, uhEndX = 0, uhEndY = 0; |
---|
945 | Int iStepStartX = 0, iStepStartY = 0, iStepEndX = 0, iStepEndY = 0; |
---|
946 | |
---|
947 | UInt uiBlockSize = 0; |
---|
948 | switch( eWedgeRes ) |
---|
949 | { |
---|
950 | case( DOUBLE_PEL ): { uiBlockSize = (uiWidth>>1); break; } |
---|
951 | case( FULL_PEL ): { uiBlockSize = uiWidth; break; } |
---|
952 | case( HALF_PEL ): { uiBlockSize = (uiWidth<<1); break; } |
---|
953 | } |
---|
954 | |
---|
955 | TComWedgelet cTempWedgelet( uiWidth, uiHeight ); |
---|
956 | for( UInt uiOri = 0; uiOri < 6; uiOri++ ) |
---|
957 | { |
---|
958 | // init the edge line parameters for each of the 6 wedgelet types |
---|
959 | switch( uiOri ) |
---|
960 | { |
---|
961 | case( 0 ): { uhStartX = 0; uhStartY = 0; uhEndX = 0; uhEndY = 0; iStepStartX = +1; iStepStartY = 0; iStepEndX = 0; iStepEndY = +1; break; } |
---|
962 | case( 1 ): { uhStartX = (uiBlockSize-1); uhStartY = 0; uhEndX = (uiBlockSize-1); uhEndY = 0; iStepStartX = 0; iStepStartY = +1; iStepEndX = -1; iStepEndY = 0; break; } |
---|
963 | case( 2 ): { uhStartX = (uiBlockSize-1); uhStartY = (uiBlockSize-1); uhEndX = (uiBlockSize-1); uhEndY = (uiBlockSize-1); iStepStartX = -1; iStepStartY = 0; iStepEndX = 0; iStepEndY = -1; break; } |
---|
964 | case( 3 ): { uhStartX = 0; uhStartY = (uiBlockSize-1); uhEndX = 0; uhEndY = (uiBlockSize-1); iStepStartX = 0; iStepStartY = -1; iStepEndX = +1; iStepEndY = 0; break; } |
---|
965 | case( 4 ): { uhStartX = 0; uhStartY = 0; uhEndX = 0; uhEndY = (uiBlockSize-1); iStepStartX = +1; iStepStartY = 0; iStepEndX = +1; iStepEndY = 0; break; } |
---|
966 | case( 5 ): { uhStartX = (uiBlockSize-1); uhStartY = 0; uhEndX = 0; uhEndY = 0; iStepStartX = 0; iStepStartY = +1; iStepEndX = 0; iStepEndY = +1; break; } |
---|
967 | } |
---|
968 | |
---|
969 | for( Int iK = 0; iK < uiBlockSize; iK++ ) |
---|
970 | { |
---|
971 | for( Int iL = 0; iL < uiBlockSize; iL++ ) |
---|
972 | { |
---|
973 | cTempWedgelet.setWedgelet( uhStartX + (iK*iStepStartX) , uhStartY + (iK*iStepStartY), uhEndX + (iL*iStepEndX), uhEndY + (iL*iStepEndY), (UChar)uiOri, eWedgeRes, ((iL%2)==0 && (iK%2)==0) ); |
---|
974 | addWedgeletToList( cTempWedgelet, racWedgeList, racWedgeRefList ); |
---|
975 | } |
---|
976 | } |
---|
977 | } |
---|
978 | UInt uiThrSz = DMM3_SIMPLIFY_TR; |
---|
979 | |
---|
980 | std::vector< std::vector<UInt> > auiWdgListSz; |
---|
981 | for( Int idxM=2; idxM<=34 ; idxM++) |
---|
982 | { |
---|
983 | std::vector<UInt> auiWdgList; |
---|
984 | for( Int idxW=0; idxW<racWedgeList.size(); idxW++) |
---|
985 | { |
---|
986 | UInt uiAbsDiff = abs(idxM-(Int)racWedgeList[idxW].getAng()); |
---|
987 | if( uiAbsDiff <= uiThrSz ) |
---|
988 | { |
---|
989 | auiWdgList.push_back(idxW); |
---|
990 | } |
---|
991 | } |
---|
992 | auiWdgListSz.push_back(auiWdgList); |
---|
993 | } |
---|
994 | g_aauiWdgLstM3.push_back(auiWdgListSz); |
---|
995 | } |
---|
996 | |
---|
997 | Void addWedgeletToList( TComWedgelet cWedgelet, std::vector<TComWedgelet> &racWedgeList, std::vector<TComWedgeRef> &racWedgeRefList ) |
---|
998 | { |
---|
999 | Bool bValid = cWedgelet.checkNotPlain(); |
---|
1000 | if( bValid ) |
---|
1001 | { |
---|
1002 | for( UInt uiPos = 0; uiPos < racWedgeList.size(); uiPos++ ) |
---|
1003 | { |
---|
1004 | if( cWedgelet.checkIdentical( racWedgeList[uiPos].getPattern() ) ) |
---|
1005 | { |
---|
1006 | TComWedgeRef cWedgeRef; |
---|
1007 | cWedgeRef.setWedgeRef( cWedgelet.getStartX(), cWedgelet.getStartY(), cWedgelet.getEndX(), cWedgelet.getEndY(), uiPos ); |
---|
1008 | racWedgeRefList.push_back( cWedgeRef ); |
---|
1009 | bValid = false; |
---|
1010 | return; |
---|
1011 | } |
---|
1012 | } |
---|
1013 | } |
---|
1014 | if( bValid ) |
---|
1015 | { |
---|
1016 | for( UInt uiPos = 0; uiPos < racWedgeList.size(); uiPos++ ) |
---|
1017 | { |
---|
1018 | if( cWedgelet.checkInvIdentical( racWedgeList[uiPos].getPattern() ) ) |
---|
1019 | { |
---|
1020 | TComWedgeRef cWedgeRef; |
---|
1021 | cWedgeRef.setWedgeRef( cWedgelet.getStartX(), cWedgelet.getStartY(), cWedgelet.getEndX(), cWedgelet.getEndY(), uiPos ); |
---|
1022 | racWedgeRefList.push_back( cWedgeRef ); |
---|
1023 | bValid = false; |
---|
1024 | return; |
---|
1025 | } |
---|
1026 | } |
---|
1027 | } |
---|
1028 | if( bValid ) |
---|
1029 | { |
---|
1030 | cWedgelet.findClosetAngle(); |
---|
1031 | racWedgeList.push_back( cWedgelet ); |
---|
1032 | TComWedgeRef cWedgeRef; |
---|
1033 | cWedgeRef.setWedgeRef( cWedgelet.getStartX(), cWedgelet.getStartY(), cWedgelet.getEndX(), cWedgelet.getEndY(), (UInt)(racWedgeList.size()-1) ); |
---|
1034 | racWedgeRefList.push_back( cWedgeRef ); |
---|
1035 | } |
---|
1036 | } |
---|
1037 | #endif //HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
1038 | |
---|
1039 | //! \} |
---|