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-2013, 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 | |
---|
63 | c=2; |
---|
64 | for ( i=0; i<MAX_CU_DEPTH; i++ ) |
---|
65 | { |
---|
66 | g_auiSigLastScan[0][i] = new UInt[ c*c ]; |
---|
67 | g_auiSigLastScan[1][i] = new UInt[ c*c ]; |
---|
68 | g_auiSigLastScan[2][i] = new UInt[ c*c ]; |
---|
69 | initSigLastScan( g_auiSigLastScan[0][i], g_auiSigLastScan[1][i], g_auiSigLastScan[2][i], c, c); |
---|
70 | |
---|
71 | c <<= 1; |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | Void destroyROM() |
---|
76 | { |
---|
77 | for (Int i=0; i<MAX_CU_DEPTH; i++ ) |
---|
78 | { |
---|
79 | delete[] g_auiSigLastScan[0][i]; |
---|
80 | delete[] g_auiSigLastScan[1][i]; |
---|
81 | delete[] g_auiSigLastScan[2][i]; |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | // ==================================================================================================================== |
---|
86 | // Data structure related table & variable |
---|
87 | // ==================================================================================================================== |
---|
88 | #if LAYER_CTB |
---|
89 | UInt g_auiLayerMaxCUWidth[MAX_LAYERS]; |
---|
90 | UInt g_auiLayerMaxCUHeight[MAX_LAYERS]; |
---|
91 | UInt g_auiLayerMaxCUDepth[MAX_LAYERS]; |
---|
92 | UInt g_auiLayerAddCUDepth[MAX_LAYERS]; |
---|
93 | UInt g_auiLayerZscanToRaster[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
---|
94 | UInt g_auiLayerRasterToZscan[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
---|
95 | UInt g_auiLayerRasterToPelX[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
---|
96 | UInt g_auiLayerRasterToPelY[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
---|
97 | #endif |
---|
98 | UInt g_uiMaxCUWidth = MAX_CU_SIZE; |
---|
99 | UInt g_uiMaxCUHeight = MAX_CU_SIZE; |
---|
100 | UInt g_uiMaxCUDepth = MAX_CU_DEPTH; |
---|
101 | UInt g_uiAddCUDepth = 0; |
---|
102 | UInt g_auiZscanToRaster [ MAX_NUM_SPU_W*MAX_NUM_SPU_W ] = { 0, }; |
---|
103 | UInt g_auiRasterToZscan [ MAX_NUM_SPU_W*MAX_NUM_SPU_W ] = { 0, }; |
---|
104 | UInt g_auiRasterToPelX [ MAX_NUM_SPU_W*MAX_NUM_SPU_W ] = { 0, }; |
---|
105 | UInt g_auiRasterToPelY [ MAX_NUM_SPU_W*MAX_NUM_SPU_W ] = { 0, }; |
---|
106 | |
---|
107 | UInt g_auiPUOffset[8] = { 0, 8, 4, 4, 2, 10, 1, 5}; |
---|
108 | |
---|
109 | #if FAST_INTRA_SHVC |
---|
110 | UInt g_reducedSetIntraModes[NUM_INTRA_MODE-1] = { 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 }; |
---|
111 | UInt g_predefSetIntraModes[NUM_INTRA_MODE-1] = {26,10,18,34,2,22,14,30,6,24,12,28,8,20,16,32,4,17,19,15,21,13,23,11,25,9,27,7,29,5,31,3,33,0,2}; |
---|
112 | #endif |
---|
113 | |
---|
114 | Void initZscanToRaster ( Int iMaxDepth, Int iDepth, UInt uiStartVal, UInt*& rpuiCurrIdx ) |
---|
115 | { |
---|
116 | Int iStride = 1 << ( iMaxDepth - 1 ); |
---|
117 | |
---|
118 | if ( iDepth == iMaxDepth ) |
---|
119 | { |
---|
120 | rpuiCurrIdx[0] = uiStartVal; |
---|
121 | rpuiCurrIdx++; |
---|
122 | } |
---|
123 | else |
---|
124 | { |
---|
125 | Int iStep = iStride >> iDepth; |
---|
126 | initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal, rpuiCurrIdx ); |
---|
127 | initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal+iStep, rpuiCurrIdx ); |
---|
128 | initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal+iStep*iStride, rpuiCurrIdx ); |
---|
129 | initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal+iStep*iStride+iStep, rpuiCurrIdx ); |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | Void initRasterToZscan ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth ) |
---|
134 | { |
---|
135 | UInt uiMinCUWidth = uiMaxCUWidth >> ( uiMaxDepth - 1 ); |
---|
136 | UInt uiMinCUHeight = uiMaxCUHeight >> ( uiMaxDepth - 1 ); |
---|
137 | |
---|
138 | UInt uiNumPartInWidth = (UInt)uiMaxCUWidth / uiMinCUWidth; |
---|
139 | UInt uiNumPartInHeight = (UInt)uiMaxCUHeight / uiMinCUHeight; |
---|
140 | |
---|
141 | for ( UInt i = 0; i < uiNumPartInWidth*uiNumPartInHeight; i++ ) |
---|
142 | { |
---|
143 | g_auiRasterToZscan[ g_auiZscanToRaster[i] ] = i; |
---|
144 | } |
---|
145 | } |
---|
146 | |
---|
147 | Void initRasterToPelXY ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth ) |
---|
148 | { |
---|
149 | UInt i; |
---|
150 | |
---|
151 | UInt* uiTempX = &g_auiRasterToPelX[0]; |
---|
152 | UInt* uiTempY = &g_auiRasterToPelY[0]; |
---|
153 | |
---|
154 | UInt uiMinCUWidth = uiMaxCUWidth >> ( uiMaxDepth - 1 ); |
---|
155 | UInt uiMinCUHeight = uiMaxCUHeight >> ( uiMaxDepth - 1 ); |
---|
156 | |
---|
157 | UInt uiNumPartInWidth = uiMaxCUWidth / uiMinCUWidth; |
---|
158 | UInt uiNumPartInHeight = uiMaxCUHeight / uiMinCUHeight; |
---|
159 | |
---|
160 | uiTempX[0] = 0; uiTempX++; |
---|
161 | for ( i = 1; i < uiNumPartInWidth; i++ ) |
---|
162 | { |
---|
163 | uiTempX[0] = uiTempX[-1] + uiMinCUWidth; uiTempX++; |
---|
164 | } |
---|
165 | for ( i = 1; i < uiNumPartInHeight; i++ ) |
---|
166 | { |
---|
167 | memcpy(uiTempX, uiTempX-uiNumPartInWidth, sizeof(UInt)*uiNumPartInWidth); |
---|
168 | uiTempX += uiNumPartInWidth; |
---|
169 | } |
---|
170 | |
---|
171 | for ( i = 1; i < uiNumPartInWidth*uiNumPartInHeight; i++ ) |
---|
172 | { |
---|
173 | uiTempY[i] = ( i / uiNumPartInWidth ) * uiMinCUWidth; |
---|
174 | } |
---|
175 | }; |
---|
176 | |
---|
177 | |
---|
178 | Int g_quantScales[6] = |
---|
179 | { |
---|
180 | 26214,23302,20560,18396,16384,14564 |
---|
181 | }; |
---|
182 | |
---|
183 | Int g_invQuantScales[6] = |
---|
184 | { |
---|
185 | 40,45,51,57,64,72 |
---|
186 | }; |
---|
187 | |
---|
188 | const Short g_aiT4[4][4] = |
---|
189 | { |
---|
190 | { 64, 64, 64, 64}, |
---|
191 | { 83, 36,-36,-83}, |
---|
192 | { 64,-64,-64, 64}, |
---|
193 | { 36,-83, 83,-36} |
---|
194 | }; |
---|
195 | |
---|
196 | const Short g_aiT8[8][8] = |
---|
197 | { |
---|
198 | { 64, 64, 64, 64, 64, 64, 64, 64}, |
---|
199 | { 89, 75, 50, 18,-18,-50,-75,-89}, |
---|
200 | { 83, 36,-36,-83,-83,-36, 36, 83}, |
---|
201 | { 75,-18,-89,-50, 50, 89, 18,-75}, |
---|
202 | { 64,-64,-64, 64, 64,-64,-64, 64}, |
---|
203 | { 50,-89, 18, 75,-75,-18, 89,-50}, |
---|
204 | { 36,-83, 83,-36,-36, 83,-83, 36}, |
---|
205 | { 18,-50, 75,-89, 89,-75, 50,-18} |
---|
206 | }; |
---|
207 | |
---|
208 | const Short g_aiT16[16][16] = |
---|
209 | { |
---|
210 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}, |
---|
211 | { 90, 87, 80, 70, 57, 43, 25, 9, -9,-25,-43,-57,-70,-80,-87,-90}, |
---|
212 | { 89, 75, 50, 18,-18,-50,-75,-89,-89,-75,-50,-18, 18, 50, 75, 89}, |
---|
213 | { 87, 57, 9,-43,-80,-90,-70,-25, 25, 70, 90, 80, 43, -9,-57,-87}, |
---|
214 | { 83, 36,-36,-83,-83,-36, 36, 83, 83, 36,-36,-83,-83,-36, 36, 83}, |
---|
215 | { 80, 9,-70,-87,-25, 57, 90, 43,-43,-90,-57, 25, 87, 70, -9,-80}, |
---|
216 | { 75,-18,-89,-50, 50, 89, 18,-75,-75, 18, 89, 50,-50,-89,-18, 75}, |
---|
217 | { 70,-43,-87, 9, 90, 25,-80,-57, 57, 80,-25,-90, -9, 87, 43,-70}, |
---|
218 | { 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64}, |
---|
219 | { 57,-80,-25, 90, -9,-87, 43, 70,-70,-43, 87, 9,-90, 25, 80,-57}, |
---|
220 | { 50,-89, 18, 75,-75,-18, 89,-50,-50, 89,-18,-75, 75, 18,-89, 50}, |
---|
221 | { 43,-90, 57, 25,-87, 70, 9,-80, 80, -9,-70, 87,-25,-57, 90,-43}, |
---|
222 | { 36,-83, 83,-36,-36, 83,-83, 36, 36,-83, 83,-36,-36, 83,-83, 36}, |
---|
223 | { 25,-70, 90,-80, 43, 9,-57, 87,-87, 57, -9,-43, 80,-90, 70,-25}, |
---|
224 | { 18,-50, 75,-89, 89,-75, 50,-18,-18, 50,-75, 89,-89, 75,-50, 18}, |
---|
225 | { 9,-25, 43,-57, 70,-80, 87,-90, 90,-87, 80,-70, 57,-43, 25, -9} |
---|
226 | }; |
---|
227 | |
---|
228 | const Short g_aiT32[32][32] = |
---|
229 | { |
---|
230 | { 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}, |
---|
231 | { 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}, |
---|
232 | { 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}, |
---|
233 | { 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}, |
---|
234 | { 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}, |
---|
235 | { 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}, |
---|
236 | { 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}, |
---|
237 | { 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}, |
---|
238 | { 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}, |
---|
239 | { 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}, |
---|
240 | { 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}, |
---|
241 | { 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}, |
---|
242 | { 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}, |
---|
243 | { 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}, |
---|
244 | { 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}, |
---|
245 | { 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}, |
---|
246 | { 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}, |
---|
247 | { 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}, |
---|
248 | { 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}, |
---|
249 | { 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}, |
---|
250 | { 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}, |
---|
251 | { 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}, |
---|
252 | { 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}, |
---|
253 | { 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}, |
---|
254 | { 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}, |
---|
255 | { 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}, |
---|
256 | { 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}, |
---|
257 | { 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}, |
---|
258 | { 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}, |
---|
259 | { 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}, |
---|
260 | { 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}, |
---|
261 | { 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} |
---|
262 | }; |
---|
263 | |
---|
264 | const UChar g_aucChromaScale[58]= |
---|
265 | { |
---|
266 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16, |
---|
267 | 17,18,19,20,21,22,23,24,25,26,27,28,29,29,30,31,32, |
---|
268 | 33,33,34,34,35,35,36,36,37,37,38,39,40,41,42,43,44, |
---|
269 | 45,46,47,48,49,50,51 |
---|
270 | }; |
---|
271 | |
---|
272 | |
---|
273 | // Mode-Dependent DCT/DST |
---|
274 | const Short g_as_DST_MAT_4 [4][4]= |
---|
275 | { |
---|
276 | {29, 55, 74, 84}, |
---|
277 | {74, 74, 0 , -74}, |
---|
278 | {84, -29, -74, 55}, |
---|
279 | {55, -84, 74, -29}, |
---|
280 | }; |
---|
281 | |
---|
282 | |
---|
283 | // ==================================================================================================================== |
---|
284 | // ADI |
---|
285 | // ==================================================================================================================== |
---|
286 | |
---|
287 | #if FAST_UDI_USE_MPM |
---|
288 | const UChar g_aucIntraModeNumFast[MAX_CU_DEPTH] = |
---|
289 | { |
---|
290 | 3, // 2x2 |
---|
291 | 8, // 4x4 |
---|
292 | 8, // 8x8 |
---|
293 | 3, // 16x16 |
---|
294 | 3, // 32x32 |
---|
295 | 3 // 64x64 |
---|
296 | }; |
---|
297 | #else // FAST_UDI_USE_MPM |
---|
298 | const UChar g_aucIntraModeNumFast[MAX_CU_DEPTH] = |
---|
299 | { |
---|
300 | 3, // 2x2 |
---|
301 | 9, // 4x4 |
---|
302 | 9, // 8x8 |
---|
303 | 4, // 16x16 33 |
---|
304 | 4, // 32x32 33 |
---|
305 | 5 // 64x64 33 |
---|
306 | }; |
---|
307 | #endif // FAST_UDI_USE_MPM |
---|
308 | |
---|
309 | // chroma |
---|
310 | |
---|
311 | const UChar g_aucConvertTxtTypeToIdx[4] = { 0, 1, 1, 2 }; |
---|
312 | |
---|
313 | |
---|
314 | // ==================================================================================================================== |
---|
315 | // Bit-depth |
---|
316 | // ==================================================================================================================== |
---|
317 | |
---|
318 | Int g_bitDepthY = 8; |
---|
319 | Int g_bitDepthC = 8; |
---|
320 | |
---|
321 | UInt g_uiPCMBitDepthLuma = 8; // PCM bit-depth |
---|
322 | UInt g_uiPCMBitDepthChroma = 8; // PCM bit-depth |
---|
323 | #if O0194_DIFFERENT_BITDEPTH_EL_BL |
---|
324 | Int g_bitDepthYLayer[MAX_LAYERS]; |
---|
325 | Int g_bitDepthCLayer[MAX_LAYERS]; |
---|
326 | |
---|
327 | UInt g_uiPCMBitDepthLumaDec[MAX_LAYERS]; // PCM bit-depth |
---|
328 | UInt g_uiPCMBitDepthChromaDec[MAX_LAYERS]; // PCM bit-depth |
---|
329 | #endif |
---|
330 | #if O0194_WEIGHTED_PREDICTION_CGS |
---|
331 | void * g_refWeightACDCParam; // type=wpACDCParam |
---|
332 | #endif |
---|
333 | // ==================================================================================================================== |
---|
334 | // Misc. |
---|
335 | // ==================================================================================================================== |
---|
336 | |
---|
337 | Char g_aucConvertToBit [ MAX_CU_SIZE+1 ]; |
---|
338 | |
---|
339 | #if ENC_DEC_TRACE |
---|
340 | FILE* g_hTrace = NULL; |
---|
341 | const Bool g_bEncDecTraceEnable = true; |
---|
342 | const Bool g_bEncDecTraceDisable = false; |
---|
343 | Bool g_HLSTraceEnable = true; |
---|
344 | Bool g_bJustDoIt = false; |
---|
345 | UInt64 g_nSymbolCounter = 0; |
---|
346 | #endif |
---|
347 | // ==================================================================================================================== |
---|
348 | // Scanning order & context model mapping |
---|
349 | // ==================================================================================================================== |
---|
350 | |
---|
351 | // scanning order table |
---|
352 | UInt* g_auiSigLastScan[ 3 ][ MAX_CU_DEPTH ]; |
---|
353 | |
---|
354 | const UInt g_sigLastScan8x8[ 3 ][ 4 ] = |
---|
355 | { |
---|
356 | {0, 2, 1, 3}, |
---|
357 | {0, 1, 2, 3}, |
---|
358 | {0, 2, 1, 3} |
---|
359 | }; |
---|
360 | UInt g_sigLastScanCG32x32[ 64 ]; |
---|
361 | |
---|
362 | const UInt g_uiMinInGroup[ 10 ] = {0,1,2,3,4,6,8,12,16,24}; |
---|
363 | 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}; |
---|
364 | |
---|
365 | Void initSigLastScan(UInt* pBuffD, UInt* pBuffH, UInt* pBuffV, Int iWidth, Int iHeight) |
---|
366 | { |
---|
367 | const UInt uiNumScanPos = UInt( iWidth * iWidth ); |
---|
368 | UInt uiNextScanPos = 0; |
---|
369 | |
---|
370 | if( iWidth < 16 ) |
---|
371 | { |
---|
372 | UInt* pBuffTemp = pBuffD; |
---|
373 | if( iWidth == 8 ) |
---|
374 | { |
---|
375 | pBuffTemp = g_sigLastScanCG32x32; |
---|
376 | } |
---|
377 | for( UInt uiScanLine = 0; uiNextScanPos < uiNumScanPos; uiScanLine++ ) |
---|
378 | { |
---|
379 | Int iPrimDim = Int( uiScanLine ); |
---|
380 | Int iScndDim = 0; |
---|
381 | while( iPrimDim >= iWidth ) |
---|
382 | { |
---|
383 | iScndDim++; |
---|
384 | iPrimDim--; |
---|
385 | } |
---|
386 | while( iPrimDim >= 0 && iScndDim < iWidth ) |
---|
387 | { |
---|
388 | pBuffTemp[ uiNextScanPos ] = iPrimDim * iWidth + iScndDim ; |
---|
389 | uiNextScanPos++; |
---|
390 | iScndDim++; |
---|
391 | iPrimDim--; |
---|
392 | } |
---|
393 | } |
---|
394 | } |
---|
395 | if( iWidth > 4 ) |
---|
396 | { |
---|
397 | UInt uiNumBlkSide = iWidth >> 2; |
---|
398 | UInt uiNumBlks = uiNumBlkSide * uiNumBlkSide; |
---|
399 | UInt log2Blk = g_aucConvertToBit[ uiNumBlkSide ] + 1; |
---|
400 | |
---|
401 | for( UInt uiBlk = 0; uiBlk < uiNumBlks; uiBlk++ ) |
---|
402 | { |
---|
403 | uiNextScanPos = 0; |
---|
404 | UInt initBlkPos = g_auiSigLastScan[ SCAN_DIAG ][ log2Blk ][ uiBlk ]; |
---|
405 | if( iWidth == 32 ) |
---|
406 | { |
---|
407 | initBlkPos = g_sigLastScanCG32x32[ uiBlk ]; |
---|
408 | } |
---|
409 | UInt offsetY = initBlkPos / uiNumBlkSide; |
---|
410 | UInt offsetX = initBlkPos - offsetY * uiNumBlkSide; |
---|
411 | UInt offsetD = 4 * ( offsetX + offsetY * iWidth ); |
---|
412 | UInt offsetScan = 16 * uiBlk; |
---|
413 | for( UInt uiScanLine = 0; uiNextScanPos < 16; uiScanLine++ ) |
---|
414 | { |
---|
415 | Int iPrimDim = Int( uiScanLine ); |
---|
416 | Int iScndDim = 0; |
---|
417 | while( iPrimDim >= 4 ) |
---|
418 | { |
---|
419 | iScndDim++; |
---|
420 | iPrimDim--; |
---|
421 | } |
---|
422 | while( iPrimDim >= 0 && iScndDim < 4 ) |
---|
423 | { |
---|
424 | pBuffD[ uiNextScanPos + offsetScan ] = iPrimDim * iWidth + iScndDim + offsetD; |
---|
425 | uiNextScanPos++; |
---|
426 | iScndDim++; |
---|
427 | iPrimDim--; |
---|
428 | } |
---|
429 | } |
---|
430 | } |
---|
431 | } |
---|
432 | |
---|
433 | UInt uiCnt = 0; |
---|
434 | if( iWidth > 2 ) |
---|
435 | { |
---|
436 | UInt numBlkSide = iWidth >> 2; |
---|
437 | for(Int blkY=0; blkY < numBlkSide; blkY++) |
---|
438 | { |
---|
439 | for(Int blkX=0; blkX < numBlkSide; blkX++) |
---|
440 | { |
---|
441 | UInt offset = blkY * 4 * iWidth + blkX * 4; |
---|
442 | for(Int y=0; y < 4; y++) |
---|
443 | { |
---|
444 | for(Int x=0; x < 4; x++) |
---|
445 | { |
---|
446 | pBuffH[uiCnt] = y*iWidth + x + offset; |
---|
447 | uiCnt ++; |
---|
448 | } |
---|
449 | } |
---|
450 | } |
---|
451 | } |
---|
452 | |
---|
453 | uiCnt = 0; |
---|
454 | for(Int blkX=0; blkX < numBlkSide; blkX++) |
---|
455 | { |
---|
456 | for(Int blkY=0; blkY < numBlkSide; blkY++) |
---|
457 | { |
---|
458 | UInt offset = blkY * 4 * iWidth + blkX * 4; |
---|
459 | for(Int x=0; x < 4; x++) |
---|
460 | { |
---|
461 | for(Int y=0; y < 4; y++) |
---|
462 | { |
---|
463 | pBuffV[uiCnt] = y*iWidth + x + offset; |
---|
464 | uiCnt ++; |
---|
465 | } |
---|
466 | } |
---|
467 | } |
---|
468 | } |
---|
469 | } |
---|
470 | else |
---|
471 | { |
---|
472 | for(Int iY=0; iY < iHeight; iY++) |
---|
473 | { |
---|
474 | for(Int iX=0; iX < iWidth; iX++) |
---|
475 | { |
---|
476 | pBuffH[uiCnt] = iY*iWidth + iX; |
---|
477 | uiCnt ++; |
---|
478 | } |
---|
479 | } |
---|
480 | |
---|
481 | uiCnt = 0; |
---|
482 | for(Int iX=0; iX < iWidth; iX++) |
---|
483 | { |
---|
484 | for(Int iY=0; iY < iHeight; iY++) |
---|
485 | { |
---|
486 | pBuffV[uiCnt] = iY*iWidth + iX; |
---|
487 | uiCnt ++; |
---|
488 | } |
---|
489 | } |
---|
490 | } |
---|
491 | } |
---|
492 | |
---|
493 | Int g_quantTSDefault4x4[16] = |
---|
494 | { |
---|
495 | 16,16,16,16, |
---|
496 | 16,16,16,16, |
---|
497 | 16,16,16,16, |
---|
498 | 16,16,16,16 |
---|
499 | }; |
---|
500 | |
---|
501 | Int g_quantIntraDefault8x8[64] = |
---|
502 | { |
---|
503 | 16,16,16,16,17,18,21,24, |
---|
504 | 16,16,16,16,17,19,22,25, |
---|
505 | 16,16,17,18,20,22,25,29, |
---|
506 | 16,16,18,21,24,27,31,36, |
---|
507 | 17,17,20,24,30,35,41,47, |
---|
508 | 18,19,22,27,35,44,54,65, |
---|
509 | 21,22,25,31,41,54,70,88, |
---|
510 | 24,25,29,36,47,65,88,115 |
---|
511 | }; |
---|
512 | |
---|
513 | Int g_quantInterDefault8x8[64] = |
---|
514 | { |
---|
515 | 16,16,16,16,17,18,20,24, |
---|
516 | 16,16,16,17,18,20,24,25, |
---|
517 | 16,16,17,18,20,24,25,28, |
---|
518 | 16,17,18,20,24,25,28,33, |
---|
519 | 17,18,20,24,25,28,33,41, |
---|
520 | 18,20,24,25,28,33,41,54, |
---|
521 | 20,24,25,28,33,41,54,71, |
---|
522 | 24,25,28,33,41,54,71,91 |
---|
523 | }; |
---|
524 | UInt g_scalingListSize [4] = {16,64,256,1024}; |
---|
525 | UInt g_scalingListSizeX [4] = { 4, 8, 16, 32}; |
---|
526 | UInt g_scalingListNum[SCALING_LIST_SIZE_NUM]={6,6,6,2}; |
---|
527 | Int g_eTTable[4] = {0,3,1,2}; |
---|
528 | |
---|
529 | #if SVC_EXTENSION |
---|
530 | Int g_mvScalingFactor [MAX_LAYERS][2] = {{0,0}, {0,0}}; |
---|
531 | Int g_posScalingFactor [MAX_LAYERS][2] = {{0,0}, {0,0}}; |
---|
532 | |
---|
533 | std::string NaluToStr( NalUnitType nalu ) |
---|
534 | { |
---|
535 | switch( nalu ) |
---|
536 | { |
---|
537 | case NAL_UNIT_CODED_SLICE_TRAIL_N: |
---|
538 | case NAL_UNIT_CODED_SLICE_TRAIL_R: |
---|
539 | return "TRAIL"; |
---|
540 | |
---|
541 | case NAL_UNIT_CODED_SLICE_TSA_N: |
---|
542 | case NAL_UNIT_CODED_SLICE_TSA_R: |
---|
543 | return " TSA"; |
---|
544 | |
---|
545 | case NAL_UNIT_CODED_SLICE_STSA_N: |
---|
546 | case NAL_UNIT_CODED_SLICE_STSA_R: |
---|
547 | return " STSA"; |
---|
548 | |
---|
549 | case NAL_UNIT_CODED_SLICE_RADL_N: |
---|
550 | case NAL_UNIT_CODED_SLICE_RADL_R: |
---|
551 | return " RADL"; |
---|
552 | |
---|
553 | case NAL_UNIT_CODED_SLICE_RASL_N: |
---|
554 | case NAL_UNIT_CODED_SLICE_RASL_R: |
---|
555 | return " RASL"; |
---|
556 | |
---|
557 | case NAL_UNIT_CODED_SLICE_BLA_W_LP: |
---|
558 | case NAL_UNIT_CODED_SLICE_BLA_W_RADL: |
---|
559 | case NAL_UNIT_CODED_SLICE_BLA_N_LP: |
---|
560 | return " BLA"; |
---|
561 | |
---|
562 | case NAL_UNIT_CODED_SLICE_IDR_W_RADL: |
---|
563 | case NAL_UNIT_CODED_SLICE_IDR_N_LP: |
---|
564 | return " IDR"; |
---|
565 | |
---|
566 | case NAL_UNIT_CODED_SLICE_CRA: |
---|
567 | return " CRA"; |
---|
568 | |
---|
569 | default: |
---|
570 | return " "; |
---|
571 | }; |
---|
572 | } |
---|
573 | #endif |
---|
574 | |
---|
575 | //! \} |
---|