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 TEncSearch.cpp |
---|
35 | \brief encoder search class |
---|
36 | */ |
---|
37 | |
---|
38 | #include "TLibCommon/TypeDef.h" |
---|
39 | #include "TLibCommon/TComRom.h" |
---|
40 | #include "TLibCommon/TComMotionInfo.h" |
---|
41 | #include "TEncSearch.h" |
---|
42 | #include <math.h> |
---|
43 | |
---|
44 | //! \ingroup TLibEncoder |
---|
45 | //! \{ |
---|
46 | |
---|
47 | static const TComMv s_acMvRefineH[9] = |
---|
48 | { |
---|
49 | TComMv( 0, 0 ), // 0 |
---|
50 | TComMv( 0, -1 ), // 1 |
---|
51 | TComMv( 0, 1 ), // 2 |
---|
52 | TComMv( -1, 0 ), // 3 |
---|
53 | TComMv( 1, 0 ), // 4 |
---|
54 | TComMv( -1, -1 ), // 5 |
---|
55 | TComMv( 1, -1 ), // 6 |
---|
56 | TComMv( -1, 1 ), // 7 |
---|
57 | TComMv( 1, 1 ) // 8 |
---|
58 | }; |
---|
59 | |
---|
60 | static const TComMv s_acMvRefineQ[9] = |
---|
61 | { |
---|
62 | TComMv( 0, 0 ), // 0 |
---|
63 | TComMv( 0, -1 ), // 1 |
---|
64 | TComMv( 0, 1 ), // 2 |
---|
65 | TComMv( -1, -1 ), // 5 |
---|
66 | TComMv( 1, -1 ), // 6 |
---|
67 | TComMv( -1, 0 ), // 3 |
---|
68 | TComMv( 1, 0 ), // 4 |
---|
69 | TComMv( -1, 1 ), // 7 |
---|
70 | TComMv( 1, 1 ) // 8 |
---|
71 | }; |
---|
72 | |
---|
73 | static const UInt s_auiDFilter[9] = |
---|
74 | { |
---|
75 | 0, 1, 0, |
---|
76 | 2, 3, 2, |
---|
77 | 0, 1, 0 |
---|
78 | }; |
---|
79 | |
---|
80 | TEncSearch::TEncSearch() |
---|
81 | { |
---|
82 | m_ppcQTTempCoeffY = NULL; |
---|
83 | m_ppcQTTempCoeffCb = NULL; |
---|
84 | m_ppcQTTempCoeffCr = NULL; |
---|
85 | m_pcQTTempCoeffY = NULL; |
---|
86 | m_pcQTTempCoeffCb = NULL; |
---|
87 | m_pcQTTempCoeffCr = NULL; |
---|
88 | #if ADAPTIVE_QP_SELECTION |
---|
89 | m_ppcQTTempArlCoeffY = NULL; |
---|
90 | m_ppcQTTempArlCoeffCb = NULL; |
---|
91 | m_ppcQTTempArlCoeffCr = NULL; |
---|
92 | m_pcQTTempArlCoeffY = NULL; |
---|
93 | m_pcQTTempArlCoeffCb = NULL; |
---|
94 | m_pcQTTempArlCoeffCr = NULL; |
---|
95 | #endif |
---|
96 | m_puhQTTempTrIdx = NULL; |
---|
97 | m_puhQTTempCbf[0] = m_puhQTTempCbf[1] = m_puhQTTempCbf[2] = NULL; |
---|
98 | m_pcQTTempTComYuv = NULL; |
---|
99 | m_pcEncCfg = NULL; |
---|
100 | m_pcEntropyCoder = NULL; |
---|
101 | m_pTempPel = NULL; |
---|
102 | m_pSharedPredTransformSkip[0] = m_pSharedPredTransformSkip[1] = m_pSharedPredTransformSkip[2] = NULL; |
---|
103 | m_pcQTTempTUCoeffY = NULL; |
---|
104 | m_pcQTTempTUCoeffCb = NULL; |
---|
105 | m_pcQTTempTUCoeffCr = NULL; |
---|
106 | #if ADAPTIVE_QP_SELECTION |
---|
107 | m_ppcQTTempTUArlCoeffY = NULL; |
---|
108 | m_ppcQTTempTUArlCoeffCb = NULL; |
---|
109 | m_ppcQTTempTUArlCoeffCr = NULL; |
---|
110 | #endif |
---|
111 | m_puhQTTempTransformSkipFlag[0] = NULL; |
---|
112 | m_puhQTTempTransformSkipFlag[1] = NULL; |
---|
113 | m_puhQTTempTransformSkipFlag[2] = NULL; |
---|
114 | setWpScalingDistParam( NULL, -1, REF_PIC_LIST_X ); |
---|
115 | } |
---|
116 | |
---|
117 | TEncSearch::~TEncSearch() |
---|
118 | { |
---|
119 | if ( m_pTempPel ) |
---|
120 | { |
---|
121 | delete [] m_pTempPel; |
---|
122 | m_pTempPel = NULL; |
---|
123 | } |
---|
124 | |
---|
125 | if ( m_pcEncCfg ) |
---|
126 | { |
---|
127 | const UInt uiNumLayersAllocated = m_pcEncCfg->getQuadtreeTULog2MaxSize()-m_pcEncCfg->getQuadtreeTULog2MinSize()+1; |
---|
128 | for( UInt ui = 0; ui < uiNumLayersAllocated; ++ui ) |
---|
129 | { |
---|
130 | delete[] m_ppcQTTempCoeffY[ui]; |
---|
131 | delete[] m_ppcQTTempCoeffCb[ui]; |
---|
132 | delete[] m_ppcQTTempCoeffCr[ui]; |
---|
133 | #if ADAPTIVE_QP_SELECTION |
---|
134 | delete[] m_ppcQTTempArlCoeffY[ui]; |
---|
135 | delete[] m_ppcQTTempArlCoeffCb[ui]; |
---|
136 | delete[] m_ppcQTTempArlCoeffCr[ui]; |
---|
137 | #endif |
---|
138 | m_pcQTTempTComYuv[ui].destroy(); |
---|
139 | } |
---|
140 | } |
---|
141 | delete[] m_ppcQTTempCoeffY; |
---|
142 | delete[] m_ppcQTTempCoeffCb; |
---|
143 | delete[] m_ppcQTTempCoeffCr; |
---|
144 | delete[] m_pcQTTempCoeffY; |
---|
145 | delete[] m_pcQTTempCoeffCb; |
---|
146 | delete[] m_pcQTTempCoeffCr; |
---|
147 | #if ADAPTIVE_QP_SELECTION |
---|
148 | delete[] m_ppcQTTempArlCoeffY; |
---|
149 | delete[] m_ppcQTTempArlCoeffCb; |
---|
150 | delete[] m_ppcQTTempArlCoeffCr; |
---|
151 | delete[] m_pcQTTempArlCoeffY; |
---|
152 | delete[] m_pcQTTempArlCoeffCb; |
---|
153 | delete[] m_pcQTTempArlCoeffCr; |
---|
154 | #endif |
---|
155 | delete[] m_puhQTTempTrIdx; |
---|
156 | delete[] m_puhQTTempCbf[0]; |
---|
157 | delete[] m_puhQTTempCbf[1]; |
---|
158 | delete[] m_puhQTTempCbf[2]; |
---|
159 | delete[] m_pcQTTempTComYuv; |
---|
160 | delete[] m_pSharedPredTransformSkip[0]; |
---|
161 | delete[] m_pSharedPredTransformSkip[1]; |
---|
162 | delete[] m_pSharedPredTransformSkip[2]; |
---|
163 | delete[] m_pcQTTempTUCoeffY; |
---|
164 | delete[] m_pcQTTempTUCoeffCb; |
---|
165 | delete[] m_pcQTTempTUCoeffCr; |
---|
166 | #if ADAPTIVE_QP_SELECTION |
---|
167 | delete[] m_ppcQTTempTUArlCoeffY; |
---|
168 | delete[] m_ppcQTTempTUArlCoeffCb; |
---|
169 | delete[] m_ppcQTTempTUArlCoeffCr; |
---|
170 | #endif |
---|
171 | delete[] m_puhQTTempTransformSkipFlag[0]; |
---|
172 | delete[] m_puhQTTempTransformSkipFlag[1]; |
---|
173 | delete[] m_puhQTTempTransformSkipFlag[2]; |
---|
174 | m_pcQTTempTransformSkipTComYuv.destroy(); |
---|
175 | m_tmpYuvPred.destroy(); |
---|
176 | } |
---|
177 | |
---|
178 | void TEncSearch::init(TEncCfg* pcEncCfg, |
---|
179 | TComTrQuant* pcTrQuant, |
---|
180 | Int iSearchRange, |
---|
181 | Int bipredSearchRange, |
---|
182 | Int iFastSearch, |
---|
183 | Int iMaxDeltaQP, |
---|
184 | TEncEntropy* pcEntropyCoder, |
---|
185 | TComRdCost* pcRdCost, |
---|
186 | TEncSbac*** pppcRDSbacCoder, |
---|
187 | TEncSbac* pcRDGoOnSbacCoder |
---|
188 | ) |
---|
189 | { |
---|
190 | m_pcEncCfg = pcEncCfg; |
---|
191 | m_pcTrQuant = pcTrQuant; |
---|
192 | m_iSearchRange = iSearchRange; |
---|
193 | m_bipredSearchRange = bipredSearchRange; |
---|
194 | m_iFastSearch = iFastSearch; |
---|
195 | m_iMaxDeltaQP = iMaxDeltaQP; |
---|
196 | m_pcEntropyCoder = pcEntropyCoder; |
---|
197 | m_pcRdCost = pcRdCost; |
---|
198 | |
---|
199 | m_pppcRDSbacCoder = pppcRDSbacCoder; |
---|
200 | m_pcRDGoOnSbacCoder = pcRDGoOnSbacCoder; |
---|
201 | |
---|
202 | m_bUseSBACRD = pppcRDSbacCoder ? true : false; |
---|
203 | |
---|
204 | for (Int iDir = 0; iDir < 2; iDir++) |
---|
205 | { |
---|
206 | for (Int iRefIdx = 0; iRefIdx < 33; iRefIdx++) |
---|
207 | { |
---|
208 | m_aaiAdaptSR[iDir][iRefIdx] = iSearchRange; |
---|
209 | } |
---|
210 | } |
---|
211 | |
---|
212 | m_puiDFilter = s_auiDFilter + 4; |
---|
213 | |
---|
214 | // initialize motion cost |
---|
215 | #if !FIX203 |
---|
216 | m_pcRdCost->initRateDistortionModel( m_iSearchRange << 2 ); |
---|
217 | #endif |
---|
218 | |
---|
219 | for( Int iNum = 0; iNum < AMVP_MAX_NUM_CANDS+1; iNum++) |
---|
220 | { |
---|
221 | for( Int iIdx = 0; iIdx < AMVP_MAX_NUM_CANDS; iIdx++) |
---|
222 | { |
---|
223 | if (iIdx < iNum) |
---|
224 | m_auiMVPIdxCost[iIdx][iNum] = xGetMvpIdxBits(iIdx, iNum); |
---|
225 | else |
---|
226 | m_auiMVPIdxCost[iIdx][iNum] = MAX_INT; |
---|
227 | } |
---|
228 | } |
---|
229 | |
---|
230 | initTempBuff(); |
---|
231 | |
---|
232 | m_pTempPel = new Pel[g_uiMaxCUWidth*g_uiMaxCUHeight]; |
---|
233 | |
---|
234 | const UInt uiNumLayersToAllocate = pcEncCfg->getQuadtreeTULog2MaxSize()-pcEncCfg->getQuadtreeTULog2MinSize()+1; |
---|
235 | m_ppcQTTempCoeffY = new TCoeff*[uiNumLayersToAllocate]; |
---|
236 | m_ppcQTTempCoeffCb = new TCoeff*[uiNumLayersToAllocate]; |
---|
237 | m_ppcQTTempCoeffCr = new TCoeff*[uiNumLayersToAllocate]; |
---|
238 | m_pcQTTempCoeffY = new TCoeff [g_uiMaxCUWidth*g_uiMaxCUHeight ]; |
---|
239 | m_pcQTTempCoeffCb = new TCoeff [g_uiMaxCUWidth*g_uiMaxCUHeight>>2]; |
---|
240 | m_pcQTTempCoeffCr = new TCoeff [g_uiMaxCUWidth*g_uiMaxCUHeight>>2]; |
---|
241 | #if ADAPTIVE_QP_SELECTION |
---|
242 | m_ppcQTTempArlCoeffY = new Int*[uiNumLayersToAllocate]; |
---|
243 | m_ppcQTTempArlCoeffCb = new Int*[uiNumLayersToAllocate]; |
---|
244 | m_ppcQTTempArlCoeffCr = new Int*[uiNumLayersToAllocate]; |
---|
245 | m_pcQTTempArlCoeffY = new Int [g_uiMaxCUWidth*g_uiMaxCUHeight ]; |
---|
246 | m_pcQTTempArlCoeffCb = new Int [g_uiMaxCUWidth*g_uiMaxCUHeight>>2]; |
---|
247 | m_pcQTTempArlCoeffCr = new Int [g_uiMaxCUWidth*g_uiMaxCUHeight>>2]; |
---|
248 | #endif |
---|
249 | |
---|
250 | const UInt uiNumPartitions = 1<<(g_uiMaxCUDepth<<1); |
---|
251 | m_puhQTTempTrIdx = new UChar [uiNumPartitions]; |
---|
252 | m_puhQTTempCbf[0] = new UChar [uiNumPartitions]; |
---|
253 | m_puhQTTempCbf[1] = new UChar [uiNumPartitions]; |
---|
254 | m_puhQTTempCbf[2] = new UChar [uiNumPartitions]; |
---|
255 | m_pcQTTempTComYuv = new TComYuv[uiNumLayersToAllocate]; |
---|
256 | for( UInt ui = 0; ui < uiNumLayersToAllocate; ++ui ) |
---|
257 | { |
---|
258 | m_ppcQTTempCoeffY[ui] = new TCoeff[g_uiMaxCUWidth*g_uiMaxCUHeight ]; |
---|
259 | m_ppcQTTempCoeffCb[ui] = new TCoeff[g_uiMaxCUWidth*g_uiMaxCUHeight>>2]; |
---|
260 | m_ppcQTTempCoeffCr[ui] = new TCoeff[g_uiMaxCUWidth*g_uiMaxCUHeight>>2]; |
---|
261 | #if ADAPTIVE_QP_SELECTION |
---|
262 | m_ppcQTTempArlCoeffY[ui] = new Int[g_uiMaxCUWidth*g_uiMaxCUHeight ]; |
---|
263 | m_ppcQTTempArlCoeffCb[ui] = new Int[g_uiMaxCUWidth*g_uiMaxCUHeight>>2]; |
---|
264 | m_ppcQTTempArlCoeffCr[ui] = new Int[g_uiMaxCUWidth*g_uiMaxCUHeight>>2]; |
---|
265 | #endif |
---|
266 | m_pcQTTempTComYuv[ui].create( g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
267 | } |
---|
268 | m_pSharedPredTransformSkip[0] = new Pel[MAX_TS_WIDTH*MAX_TS_HEIGHT]; |
---|
269 | m_pSharedPredTransformSkip[1] = new Pel[MAX_TS_WIDTH*MAX_TS_HEIGHT]; |
---|
270 | m_pSharedPredTransformSkip[2] = new Pel[MAX_TS_WIDTH*MAX_TS_HEIGHT]; |
---|
271 | m_pcQTTempTUCoeffY = new TCoeff[MAX_TS_WIDTH*MAX_TS_HEIGHT]; |
---|
272 | m_pcQTTempTUCoeffCb = new TCoeff[MAX_TS_WIDTH*MAX_TS_HEIGHT]; |
---|
273 | m_pcQTTempTUCoeffCr = new TCoeff[MAX_TS_WIDTH*MAX_TS_HEIGHT]; |
---|
274 | #if ADAPTIVE_QP_SELECTION |
---|
275 | m_ppcQTTempTUArlCoeffY = new Int[MAX_TS_WIDTH*MAX_TS_HEIGHT]; |
---|
276 | m_ppcQTTempTUArlCoeffCb = new Int[MAX_TS_WIDTH*MAX_TS_HEIGHT]; |
---|
277 | m_ppcQTTempTUArlCoeffCr = new Int[MAX_TS_WIDTH*MAX_TS_HEIGHT]; |
---|
278 | #endif |
---|
279 | m_pcQTTempTransformSkipTComYuv.create( g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
280 | |
---|
281 | m_puhQTTempTransformSkipFlag[0] = new UChar [uiNumPartitions]; |
---|
282 | m_puhQTTempTransformSkipFlag[1] = new UChar [uiNumPartitions]; |
---|
283 | m_puhQTTempTransformSkipFlag[2] = new UChar [uiNumPartitions]; |
---|
284 | m_tmpYuvPred.create(MAX_CU_SIZE, MAX_CU_SIZE); |
---|
285 | } |
---|
286 | |
---|
287 | #if FASTME_SMOOTHER_MV |
---|
288 | #define FIRSTSEARCHSTOP 1 |
---|
289 | #else |
---|
290 | #define FIRSTSEARCHSTOP 0 |
---|
291 | #endif |
---|
292 | |
---|
293 | #define TZ_SEARCH_CONFIGURATION \ |
---|
294 | const Int iRaster = 5; /* TZ soll von aussen ?ergeben werden */ \ |
---|
295 | const Bool bTestOtherPredictedMV = 0; \ |
---|
296 | const Bool bTestZeroVector = 1; \ |
---|
297 | const Bool bTestZeroVectorStart = 0; \ |
---|
298 | const Bool bTestZeroVectorStop = 0; \ |
---|
299 | const Bool bFirstSearchDiamond = 1; /* 1 = xTZ8PointDiamondSearch 0 = xTZ8PointSquareSearch */ \ |
---|
300 | const Bool bFirstSearchStop = FIRSTSEARCHSTOP; \ |
---|
301 | const UInt uiFirstSearchRounds = 3; /* first search stop X rounds after best match (must be >=1) */ \ |
---|
302 | const Bool bEnableRasterSearch = 1; \ |
---|
303 | const Bool bAlwaysRasterSearch = 0; /* ===== 1: BETTER but factor 2 slower ===== */ \ |
---|
304 | const Bool bRasterRefinementEnable = 0; /* enable either raster refinement or star refinement */ \ |
---|
305 | const Bool bRasterRefinementDiamond = 0; /* 1 = xTZ8PointDiamondSearch 0 = xTZ8PointSquareSearch */ \ |
---|
306 | const Bool bStarRefinementEnable = 1; /* enable either star refinement or raster refinement */ \ |
---|
307 | const Bool bStarRefinementDiamond = 1; /* 1 = xTZ8PointDiamondSearch 0 = xTZ8PointSquareSearch */ \ |
---|
308 | const Bool bStarRefinementStop = 0; \ |
---|
309 | const UInt uiStarRefinementRounds = 2; /* star refinement stop X rounds after best match (must be >=1) */ \ |
---|
310 | |
---|
311 | |
---|
312 | __inline Void TEncSearch::xTZSearchHelp( TComPattern* pcPatternKey, IntTZSearchStruct& rcStruct, const Int iSearchX, const Int iSearchY, const UChar ucPointNr, const UInt uiDistance ) |
---|
313 | { |
---|
314 | UInt uiSad; |
---|
315 | |
---|
316 | Pel* piRefSrch; |
---|
317 | |
---|
318 | piRefSrch = rcStruct.piRefY + iSearchY * rcStruct.iYStride + iSearchX; |
---|
319 | |
---|
320 | //-- jclee for using the SAD function pointer |
---|
321 | m_pcRdCost->setDistParam( pcPatternKey, piRefSrch, rcStruct.iYStride, m_cDistParam ); |
---|
322 | |
---|
323 | // fast encoder decision: use subsampled SAD when rows > 8 for integer ME |
---|
324 | if ( m_pcEncCfg->getUseFastEnc() ) |
---|
325 | { |
---|
326 | if ( m_cDistParam.iRows > 8 ) |
---|
327 | { |
---|
328 | m_cDistParam.iSubShift = 1; |
---|
329 | } |
---|
330 | } |
---|
331 | |
---|
332 | setDistParamComp(0); // Y component |
---|
333 | |
---|
334 | // distortion |
---|
335 | m_cDistParam.bitDepth = g_bitDepthY; |
---|
336 | uiSad = m_cDistParam.DistFunc( &m_cDistParam ); |
---|
337 | |
---|
338 | // motion cost |
---|
339 | uiSad += m_pcRdCost->getCost( iSearchX, iSearchY ); |
---|
340 | |
---|
341 | if( uiSad < rcStruct.uiBestSad ) |
---|
342 | { |
---|
343 | rcStruct.uiBestSad = uiSad; |
---|
344 | rcStruct.iBestX = iSearchX; |
---|
345 | rcStruct.iBestY = iSearchY; |
---|
346 | rcStruct.uiBestDistance = uiDistance; |
---|
347 | rcStruct.uiBestRound = 0; |
---|
348 | rcStruct.ucPointNr = ucPointNr; |
---|
349 | } |
---|
350 | } |
---|
351 | |
---|
352 | __inline Void TEncSearch::xTZ2PointSearch( TComPattern* pcPatternKey, IntTZSearchStruct& rcStruct, TComMv* pcMvSrchRngLT, TComMv* pcMvSrchRngRB ) |
---|
353 | { |
---|
354 | Int iSrchRngHorLeft = pcMvSrchRngLT->getHor(); |
---|
355 | Int iSrchRngHorRight = pcMvSrchRngRB->getHor(); |
---|
356 | Int iSrchRngVerTop = pcMvSrchRngLT->getVer(); |
---|
357 | Int iSrchRngVerBottom = pcMvSrchRngRB->getVer(); |
---|
358 | |
---|
359 | // 2 point search, // 1 2 3 |
---|
360 | // check only the 2 untested points // 4 0 5 |
---|
361 | // around the start point // 6 7 8 |
---|
362 | Int iStartX = rcStruct.iBestX; |
---|
363 | Int iStartY = rcStruct.iBestY; |
---|
364 | switch( rcStruct.ucPointNr ) |
---|
365 | { |
---|
366 | case 1: |
---|
367 | { |
---|
368 | if ( (iStartX - 1) >= iSrchRngHorLeft ) |
---|
369 | { |
---|
370 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX - 1, iStartY, 0, 2 ); |
---|
371 | } |
---|
372 | if ( (iStartY - 1) >= iSrchRngVerTop ) |
---|
373 | { |
---|
374 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iStartY - 1, 0, 2 ); |
---|
375 | } |
---|
376 | } |
---|
377 | break; |
---|
378 | case 2: |
---|
379 | { |
---|
380 | if ( (iStartY - 1) >= iSrchRngVerTop ) |
---|
381 | { |
---|
382 | if ( (iStartX - 1) >= iSrchRngHorLeft ) |
---|
383 | { |
---|
384 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX - 1, iStartY - 1, 0, 2 ); |
---|
385 | } |
---|
386 | if ( (iStartX + 1) <= iSrchRngHorRight ) |
---|
387 | { |
---|
388 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX + 1, iStartY - 1, 0, 2 ); |
---|
389 | } |
---|
390 | } |
---|
391 | } |
---|
392 | break; |
---|
393 | case 3: |
---|
394 | { |
---|
395 | if ( (iStartY - 1) >= iSrchRngVerTop ) |
---|
396 | { |
---|
397 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iStartY - 1, 0, 2 ); |
---|
398 | } |
---|
399 | if ( (iStartX + 1) <= iSrchRngHorRight ) |
---|
400 | { |
---|
401 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX + 1, iStartY, 0, 2 ); |
---|
402 | } |
---|
403 | } |
---|
404 | break; |
---|
405 | case 4: |
---|
406 | { |
---|
407 | if ( (iStartX - 1) >= iSrchRngHorLeft ) |
---|
408 | { |
---|
409 | if ( (iStartY + 1) <= iSrchRngVerBottom ) |
---|
410 | { |
---|
411 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX - 1, iStartY + 1, 0, 2 ); |
---|
412 | } |
---|
413 | if ( (iStartY - 1) >= iSrchRngVerTop ) |
---|
414 | { |
---|
415 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX - 1, iStartY - 1, 0, 2 ); |
---|
416 | } |
---|
417 | } |
---|
418 | } |
---|
419 | break; |
---|
420 | case 5: |
---|
421 | { |
---|
422 | if ( (iStartX + 1) <= iSrchRngHorRight ) |
---|
423 | { |
---|
424 | if ( (iStartY - 1) >= iSrchRngVerTop ) |
---|
425 | { |
---|
426 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX + 1, iStartY - 1, 0, 2 ); |
---|
427 | } |
---|
428 | if ( (iStartY + 1) <= iSrchRngVerBottom ) |
---|
429 | { |
---|
430 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX + 1, iStartY + 1, 0, 2 ); |
---|
431 | } |
---|
432 | } |
---|
433 | } |
---|
434 | break; |
---|
435 | case 6: |
---|
436 | { |
---|
437 | if ( (iStartX - 1) >= iSrchRngHorLeft ) |
---|
438 | { |
---|
439 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX - 1, iStartY , 0, 2 ); |
---|
440 | } |
---|
441 | if ( (iStartY + 1) <= iSrchRngVerBottom ) |
---|
442 | { |
---|
443 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iStartY + 1, 0, 2 ); |
---|
444 | } |
---|
445 | } |
---|
446 | break; |
---|
447 | case 7: |
---|
448 | { |
---|
449 | if ( (iStartY + 1) <= iSrchRngVerBottom ) |
---|
450 | { |
---|
451 | if ( (iStartX - 1) >= iSrchRngHorLeft ) |
---|
452 | { |
---|
453 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX - 1, iStartY + 1, 0, 2 ); |
---|
454 | } |
---|
455 | if ( (iStartX + 1) <= iSrchRngHorRight ) |
---|
456 | { |
---|
457 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX + 1, iStartY + 1, 0, 2 ); |
---|
458 | } |
---|
459 | } |
---|
460 | } |
---|
461 | break; |
---|
462 | case 8: |
---|
463 | { |
---|
464 | if ( (iStartX + 1) <= iSrchRngHorRight ) |
---|
465 | { |
---|
466 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX + 1, iStartY, 0, 2 ); |
---|
467 | } |
---|
468 | if ( (iStartY + 1) <= iSrchRngVerBottom ) |
---|
469 | { |
---|
470 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iStartY + 1, 0, 2 ); |
---|
471 | } |
---|
472 | } |
---|
473 | break; |
---|
474 | default: |
---|
475 | { |
---|
476 | assert( false ); |
---|
477 | } |
---|
478 | break; |
---|
479 | } // switch( rcStruct.ucPointNr ) |
---|
480 | } |
---|
481 | |
---|
482 | __inline Void TEncSearch::xTZ8PointSquareSearch( TComPattern* pcPatternKey, IntTZSearchStruct& rcStruct, TComMv* pcMvSrchRngLT, TComMv* pcMvSrchRngRB, const Int iStartX, const Int iStartY, const Int iDist ) |
---|
483 | { |
---|
484 | Int iSrchRngHorLeft = pcMvSrchRngLT->getHor(); |
---|
485 | Int iSrchRngHorRight = pcMvSrchRngRB->getHor(); |
---|
486 | Int iSrchRngVerTop = pcMvSrchRngLT->getVer(); |
---|
487 | Int iSrchRngVerBottom = pcMvSrchRngRB->getVer(); |
---|
488 | |
---|
489 | // 8 point search, // 1 2 3 |
---|
490 | // search around the start point // 4 0 5 |
---|
491 | // with the required distance // 6 7 8 |
---|
492 | assert( iDist != 0 ); |
---|
493 | const Int iTop = iStartY - iDist; |
---|
494 | const Int iBottom = iStartY + iDist; |
---|
495 | const Int iLeft = iStartX - iDist; |
---|
496 | const Int iRight = iStartX + iDist; |
---|
497 | rcStruct.uiBestRound += 1; |
---|
498 | |
---|
499 | if ( iTop >= iSrchRngVerTop ) // check top |
---|
500 | { |
---|
501 | if ( iLeft >= iSrchRngHorLeft ) // check top left |
---|
502 | { |
---|
503 | xTZSearchHelp( pcPatternKey, rcStruct, iLeft, iTop, 1, iDist ); |
---|
504 | } |
---|
505 | // top middle |
---|
506 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iTop, 2, iDist ); |
---|
507 | |
---|
508 | if ( iRight <= iSrchRngHorRight ) // check top right |
---|
509 | { |
---|
510 | xTZSearchHelp( pcPatternKey, rcStruct, iRight, iTop, 3, iDist ); |
---|
511 | } |
---|
512 | } // check top |
---|
513 | if ( iLeft >= iSrchRngHorLeft ) // check middle left |
---|
514 | { |
---|
515 | xTZSearchHelp( pcPatternKey, rcStruct, iLeft, iStartY, 4, iDist ); |
---|
516 | } |
---|
517 | if ( iRight <= iSrchRngHorRight ) // check middle right |
---|
518 | { |
---|
519 | xTZSearchHelp( pcPatternKey, rcStruct, iRight, iStartY, 5, iDist ); |
---|
520 | } |
---|
521 | if ( iBottom <= iSrchRngVerBottom ) // check bottom |
---|
522 | { |
---|
523 | if ( iLeft >= iSrchRngHorLeft ) // check bottom left |
---|
524 | { |
---|
525 | xTZSearchHelp( pcPatternKey, rcStruct, iLeft, iBottom, 6, iDist ); |
---|
526 | } |
---|
527 | // check bottom middle |
---|
528 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iBottom, 7, iDist ); |
---|
529 | |
---|
530 | if ( iRight <= iSrchRngHorRight ) // check bottom right |
---|
531 | { |
---|
532 | xTZSearchHelp( pcPatternKey, rcStruct, iRight, iBottom, 8, iDist ); |
---|
533 | } |
---|
534 | } // check bottom |
---|
535 | } |
---|
536 | |
---|
537 | __inline Void TEncSearch::xTZ8PointDiamondSearch( TComPattern* pcPatternKey, IntTZSearchStruct& rcStruct, TComMv* pcMvSrchRngLT, TComMv* pcMvSrchRngRB, const Int iStartX, const Int iStartY, const Int iDist ) |
---|
538 | { |
---|
539 | Int iSrchRngHorLeft = pcMvSrchRngLT->getHor(); |
---|
540 | Int iSrchRngHorRight = pcMvSrchRngRB->getHor(); |
---|
541 | Int iSrchRngVerTop = pcMvSrchRngLT->getVer(); |
---|
542 | Int iSrchRngVerBottom = pcMvSrchRngRB->getVer(); |
---|
543 | |
---|
544 | // 8 point search, // 1 2 3 |
---|
545 | // search around the start point // 4 0 5 |
---|
546 | // with the required distance // 6 7 8 |
---|
547 | assert ( iDist != 0 ); |
---|
548 | const Int iTop = iStartY - iDist; |
---|
549 | const Int iBottom = iStartY + iDist; |
---|
550 | const Int iLeft = iStartX - iDist; |
---|
551 | const Int iRight = iStartX + iDist; |
---|
552 | rcStruct.uiBestRound += 1; |
---|
553 | |
---|
554 | if ( iDist == 1 ) // iDist == 1 |
---|
555 | { |
---|
556 | if ( iTop >= iSrchRngVerTop ) // check top |
---|
557 | { |
---|
558 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iTop, 2, iDist ); |
---|
559 | } |
---|
560 | if ( iLeft >= iSrchRngHorLeft ) // check middle left |
---|
561 | { |
---|
562 | xTZSearchHelp( pcPatternKey, rcStruct, iLeft, iStartY, 4, iDist ); |
---|
563 | } |
---|
564 | if ( iRight <= iSrchRngHorRight ) // check middle right |
---|
565 | { |
---|
566 | xTZSearchHelp( pcPatternKey, rcStruct, iRight, iStartY, 5, iDist ); |
---|
567 | } |
---|
568 | if ( iBottom <= iSrchRngVerBottom ) // check bottom |
---|
569 | { |
---|
570 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iBottom, 7, iDist ); |
---|
571 | } |
---|
572 | } |
---|
573 | else // if (iDist != 1) |
---|
574 | { |
---|
575 | if ( iDist <= 8 ) |
---|
576 | { |
---|
577 | const Int iTop_2 = iStartY - (iDist>>1); |
---|
578 | const Int iBottom_2 = iStartY + (iDist>>1); |
---|
579 | const Int iLeft_2 = iStartX - (iDist>>1); |
---|
580 | const Int iRight_2 = iStartX + (iDist>>1); |
---|
581 | |
---|
582 | if ( iTop >= iSrchRngVerTop && iLeft >= iSrchRngHorLeft && |
---|
583 | iRight <= iSrchRngHorRight && iBottom <= iSrchRngVerBottom ) // check border |
---|
584 | { |
---|
585 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iTop, 2, iDist ); |
---|
586 | xTZSearchHelp( pcPatternKey, rcStruct, iLeft_2, iTop_2, 1, iDist>>1 ); |
---|
587 | xTZSearchHelp( pcPatternKey, rcStruct, iRight_2, iTop_2, 3, iDist>>1 ); |
---|
588 | xTZSearchHelp( pcPatternKey, rcStruct, iLeft, iStartY, 4, iDist ); |
---|
589 | xTZSearchHelp( pcPatternKey, rcStruct, iRight, iStartY, 5, iDist ); |
---|
590 | xTZSearchHelp( pcPatternKey, rcStruct, iLeft_2, iBottom_2, 6, iDist>>1 ); |
---|
591 | xTZSearchHelp( pcPatternKey, rcStruct, iRight_2, iBottom_2, 8, iDist>>1 ); |
---|
592 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iBottom, 7, iDist ); |
---|
593 | } |
---|
594 | else // check border |
---|
595 | { |
---|
596 | if ( iTop >= iSrchRngVerTop ) // check top |
---|
597 | { |
---|
598 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iTop, 2, iDist ); |
---|
599 | } |
---|
600 | if ( iTop_2 >= iSrchRngVerTop ) // check half top |
---|
601 | { |
---|
602 | if ( iLeft_2 >= iSrchRngHorLeft ) // check half left |
---|
603 | { |
---|
604 | xTZSearchHelp( pcPatternKey, rcStruct, iLeft_2, iTop_2, 1, (iDist>>1) ); |
---|
605 | } |
---|
606 | if ( iRight_2 <= iSrchRngHorRight ) // check half right |
---|
607 | { |
---|
608 | xTZSearchHelp( pcPatternKey, rcStruct, iRight_2, iTop_2, 3, (iDist>>1) ); |
---|
609 | } |
---|
610 | } // check half top |
---|
611 | if ( iLeft >= iSrchRngHorLeft ) // check left |
---|
612 | { |
---|
613 | xTZSearchHelp( pcPatternKey, rcStruct, iLeft, iStartY, 4, iDist ); |
---|
614 | } |
---|
615 | if ( iRight <= iSrchRngHorRight ) // check right |
---|
616 | { |
---|
617 | xTZSearchHelp( pcPatternKey, rcStruct, iRight, iStartY, 5, iDist ); |
---|
618 | } |
---|
619 | if ( iBottom_2 <= iSrchRngVerBottom ) // check half bottom |
---|
620 | { |
---|
621 | if ( iLeft_2 >= iSrchRngHorLeft ) // check half left |
---|
622 | { |
---|
623 | xTZSearchHelp( pcPatternKey, rcStruct, iLeft_2, iBottom_2, 6, (iDist>>1) ); |
---|
624 | } |
---|
625 | if ( iRight_2 <= iSrchRngHorRight ) // check half right |
---|
626 | { |
---|
627 | xTZSearchHelp( pcPatternKey, rcStruct, iRight_2, iBottom_2, 8, (iDist>>1) ); |
---|
628 | } |
---|
629 | } // check half bottom |
---|
630 | if ( iBottom <= iSrchRngVerBottom ) // check bottom |
---|
631 | { |
---|
632 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iBottom, 7, iDist ); |
---|
633 | } |
---|
634 | } // check border |
---|
635 | } |
---|
636 | else // iDist > 8 |
---|
637 | { |
---|
638 | if ( iTop >= iSrchRngVerTop && iLeft >= iSrchRngHorLeft && |
---|
639 | iRight <= iSrchRngHorRight && iBottom <= iSrchRngVerBottom ) // check border |
---|
640 | { |
---|
641 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iTop, 0, iDist ); |
---|
642 | xTZSearchHelp( pcPatternKey, rcStruct, iLeft, iStartY, 0, iDist ); |
---|
643 | xTZSearchHelp( pcPatternKey, rcStruct, iRight, iStartY, 0, iDist ); |
---|
644 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iBottom, 0, iDist ); |
---|
645 | for ( Int index = 1; index < 4; index++ ) |
---|
646 | { |
---|
647 | Int iPosYT = iTop + ((iDist>>2) * index); |
---|
648 | Int iPosYB = iBottom - ((iDist>>2) * index); |
---|
649 | Int iPosXL = iStartX - ((iDist>>2) * index); |
---|
650 | Int iPosXR = iStartX + ((iDist>>2) * index); |
---|
651 | xTZSearchHelp( pcPatternKey, rcStruct, iPosXL, iPosYT, 0, iDist ); |
---|
652 | xTZSearchHelp( pcPatternKey, rcStruct, iPosXR, iPosYT, 0, iDist ); |
---|
653 | xTZSearchHelp( pcPatternKey, rcStruct, iPosXL, iPosYB, 0, iDist ); |
---|
654 | xTZSearchHelp( pcPatternKey, rcStruct, iPosXR, iPosYB, 0, iDist ); |
---|
655 | } |
---|
656 | } |
---|
657 | else // check border |
---|
658 | { |
---|
659 | if ( iTop >= iSrchRngVerTop ) // check top |
---|
660 | { |
---|
661 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iTop, 0, iDist ); |
---|
662 | } |
---|
663 | if ( iLeft >= iSrchRngHorLeft ) // check left |
---|
664 | { |
---|
665 | xTZSearchHelp( pcPatternKey, rcStruct, iLeft, iStartY, 0, iDist ); |
---|
666 | } |
---|
667 | if ( iRight <= iSrchRngHorRight ) // check right |
---|
668 | { |
---|
669 | xTZSearchHelp( pcPatternKey, rcStruct, iRight, iStartY, 0, iDist ); |
---|
670 | } |
---|
671 | if ( iBottom <= iSrchRngVerBottom ) // check bottom |
---|
672 | { |
---|
673 | xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iBottom, 0, iDist ); |
---|
674 | } |
---|
675 | for ( Int index = 1; index < 4; index++ ) |
---|
676 | { |
---|
677 | Int iPosYT = iTop + ((iDist>>2) * index); |
---|
678 | Int iPosYB = iBottom - ((iDist>>2) * index); |
---|
679 | Int iPosXL = iStartX - ((iDist>>2) * index); |
---|
680 | Int iPosXR = iStartX + ((iDist>>2) * index); |
---|
681 | |
---|
682 | if ( iPosYT >= iSrchRngVerTop ) // check top |
---|
683 | { |
---|
684 | if ( iPosXL >= iSrchRngHorLeft ) // check left |
---|
685 | { |
---|
686 | xTZSearchHelp( pcPatternKey, rcStruct, iPosXL, iPosYT, 0, iDist ); |
---|
687 | } |
---|
688 | if ( iPosXR <= iSrchRngHorRight ) // check right |
---|
689 | { |
---|
690 | xTZSearchHelp( pcPatternKey, rcStruct, iPosXR, iPosYT, 0, iDist ); |
---|
691 | } |
---|
692 | } // check top |
---|
693 | if ( iPosYB <= iSrchRngVerBottom ) // check bottom |
---|
694 | { |
---|
695 | if ( iPosXL >= iSrchRngHorLeft ) // check left |
---|
696 | { |
---|
697 | xTZSearchHelp( pcPatternKey, rcStruct, iPosXL, iPosYB, 0, iDist ); |
---|
698 | } |
---|
699 | if ( iPosXR <= iSrchRngHorRight ) // check right |
---|
700 | { |
---|
701 | xTZSearchHelp( pcPatternKey, rcStruct, iPosXR, iPosYB, 0, iDist ); |
---|
702 | } |
---|
703 | } // check bottom |
---|
704 | } // for ... |
---|
705 | } // check border |
---|
706 | } // iDist <= 8 |
---|
707 | } // iDist == 1 |
---|
708 | } |
---|
709 | |
---|
710 | //<-- |
---|
711 | |
---|
712 | UInt TEncSearch::xPatternRefinement( TComPattern* pcPatternKey, |
---|
713 | TComMv baseRefMv, |
---|
714 | Int iFrac, TComMv& rcMvFrac ) |
---|
715 | { |
---|
716 | UInt uiDist; |
---|
717 | UInt uiDistBest = MAX_UINT; |
---|
718 | UInt uiDirecBest = 0; |
---|
719 | |
---|
720 | Pel* piRefPos; |
---|
721 | Int iRefStride = m_filteredBlock[0][0].getStride(); |
---|
722 | #if NS_HAD |
---|
723 | m_pcRdCost->setDistParam( pcPatternKey, m_filteredBlock[0][0].getLumaAddr(), iRefStride, 1, m_cDistParam, m_pcEncCfg->getUseHADME(), m_pcEncCfg->getUseNSQT() ); |
---|
724 | #else |
---|
725 | m_pcRdCost->setDistParam( pcPatternKey, m_filteredBlock[0][0].getLumaAddr(), iRefStride, 1, m_cDistParam, m_pcEncCfg->getUseHADME() ); |
---|
726 | #endif |
---|
727 | |
---|
728 | const TComMv* pcMvRefine = (iFrac == 2 ? s_acMvRefineH : s_acMvRefineQ); |
---|
729 | |
---|
730 | for (UInt i = 0; i < 9; i++) |
---|
731 | { |
---|
732 | TComMv cMvTest = pcMvRefine[i]; |
---|
733 | cMvTest += baseRefMv; |
---|
734 | |
---|
735 | Int horVal = cMvTest.getHor() * iFrac; |
---|
736 | Int verVal = cMvTest.getVer() * iFrac; |
---|
737 | piRefPos = m_filteredBlock[ verVal & 3 ][ horVal & 3 ].getLumaAddr(); |
---|
738 | if ( horVal == 2 && ( verVal & 1 ) == 0 ) |
---|
739 | piRefPos += 1; |
---|
740 | if ( ( horVal & 1 ) == 0 && verVal == 2 ) |
---|
741 | piRefPos += iRefStride; |
---|
742 | cMvTest = pcMvRefine[i]; |
---|
743 | cMvTest += rcMvFrac; |
---|
744 | |
---|
745 | setDistParamComp(0); // Y component |
---|
746 | |
---|
747 | m_cDistParam.pCur = piRefPos; |
---|
748 | m_cDistParam.bitDepth = g_bitDepthY; |
---|
749 | uiDist = m_cDistParam.DistFunc( &m_cDistParam ); |
---|
750 | uiDist += m_pcRdCost->getCost( cMvTest.getHor(), cMvTest.getVer() ); |
---|
751 | |
---|
752 | if ( uiDist < uiDistBest ) |
---|
753 | { |
---|
754 | uiDistBest = uiDist; |
---|
755 | uiDirecBest = i; |
---|
756 | } |
---|
757 | } |
---|
758 | |
---|
759 | rcMvFrac = pcMvRefine[uiDirecBest]; |
---|
760 | |
---|
761 | return uiDistBest; |
---|
762 | } |
---|
763 | |
---|
764 | Void |
---|
765 | TEncSearch::xEncSubdivCbfQT( TComDataCU* pcCU, |
---|
766 | UInt uiTrDepth, |
---|
767 | UInt uiAbsPartIdx, |
---|
768 | Bool bLuma, |
---|
769 | Bool bChroma ) |
---|
770 | { |
---|
771 | UInt uiFullDepth = pcCU->getDepth(0) + uiTrDepth; |
---|
772 | UInt uiTrMode = pcCU->getTransformIdx( uiAbsPartIdx ); |
---|
773 | UInt uiSubdiv = ( uiTrMode > uiTrDepth ? 1 : 0 ); |
---|
774 | UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - uiFullDepth; |
---|
775 | |
---|
776 | { |
---|
777 | if( pcCU->getPredictionMode(0) == MODE_INTRA && pcCU->getPartitionSize(0) == SIZE_NxN && uiTrDepth == 0 ) |
---|
778 | { |
---|
779 | assert( uiSubdiv ); |
---|
780 | } |
---|
781 | else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
782 | { |
---|
783 | assert( uiSubdiv ); |
---|
784 | } |
---|
785 | else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
786 | { |
---|
787 | assert( !uiSubdiv ); |
---|
788 | } |
---|
789 | else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
790 | { |
---|
791 | assert( !uiSubdiv ); |
---|
792 | } |
---|
793 | else |
---|
794 | { |
---|
795 | assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ); |
---|
796 | if( bLuma ) |
---|
797 | { |
---|
798 | m_pcEntropyCoder->encodeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize ); |
---|
799 | } |
---|
800 | } |
---|
801 | } |
---|
802 | |
---|
803 | if ( bChroma ) |
---|
804 | { |
---|
805 | if( uiLog2TrafoSize > 2 ) |
---|
806 | { |
---|
807 | if( uiTrDepth==0 || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth-1 ) ) |
---|
808 | m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth ); |
---|
809 | if( uiTrDepth==0 || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth-1 ) ) |
---|
810 | m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth ); |
---|
811 | } |
---|
812 | } |
---|
813 | |
---|
814 | if( uiSubdiv ) |
---|
815 | { |
---|
816 | UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 ); |
---|
817 | for( UInt uiPart = 0; uiPart < 4; uiPart++ ) |
---|
818 | { |
---|
819 | xEncSubdivCbfQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiQPartNum, bLuma, bChroma ); |
---|
820 | } |
---|
821 | return; |
---|
822 | } |
---|
823 | |
---|
824 | { |
---|
825 | //===== Cbfs ===== |
---|
826 | if( bLuma ) |
---|
827 | { |
---|
828 | m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrMode ); |
---|
829 | } |
---|
830 | } |
---|
831 | } |
---|
832 | |
---|
833 | Void |
---|
834 | TEncSearch::xEncCoeffQT( TComDataCU* pcCU, |
---|
835 | UInt uiTrDepth, |
---|
836 | UInt uiAbsPartIdx, |
---|
837 | TextType eTextType, |
---|
838 | Bool bRealCoeff ) |
---|
839 | { |
---|
840 | UInt uiFullDepth = pcCU->getDepth(0) + uiTrDepth; |
---|
841 | UInt uiTrMode = pcCU->getTransformIdx( uiAbsPartIdx ); |
---|
842 | UInt uiSubdiv = ( uiTrMode > uiTrDepth ? 1 : 0 ); |
---|
843 | UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - uiFullDepth; |
---|
844 | UInt uiChroma = ( eTextType != TEXT_LUMA ? 1 : 0 ); |
---|
845 | |
---|
846 | if( uiSubdiv ) |
---|
847 | { |
---|
848 | UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 ); |
---|
849 | for( UInt uiPart = 0; uiPart < 4; uiPart++ ) |
---|
850 | { |
---|
851 | xEncCoeffQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiQPartNum, eTextType, bRealCoeff ); |
---|
852 | } |
---|
853 | return; |
---|
854 | } |
---|
855 | |
---|
856 | if( eTextType != TEXT_LUMA && uiLog2TrafoSize == 2 ) |
---|
857 | { |
---|
858 | assert( uiTrDepth > 0 ); |
---|
859 | uiTrDepth--; |
---|
860 | UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrDepth ) << 1 ); |
---|
861 | Bool bFirstQ = ( ( uiAbsPartIdx % uiQPDiv ) == 0 ); |
---|
862 | if( !bFirstQ ) |
---|
863 | { |
---|
864 | return; |
---|
865 | } |
---|
866 | } |
---|
867 | |
---|
868 | //===== coefficients ===== |
---|
869 | UInt uiWidth = pcCU->getWidth ( 0 ) >> ( uiTrDepth + uiChroma ); |
---|
870 | UInt uiHeight = pcCU->getHeight ( 0 ) >> ( uiTrDepth + uiChroma ); |
---|
871 | UInt uiCoeffOffset = ( pcCU->getPic()->getMinCUWidth() * pcCU->getPic()->getMinCUHeight() * uiAbsPartIdx ) >> ( uiChroma << 1 ); |
---|
872 | UInt uiQTLayer = pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() - uiLog2TrafoSize; |
---|
873 | TCoeff* pcCoeff = 0; |
---|
874 | switch( eTextType ) |
---|
875 | { |
---|
876 | case TEXT_LUMA: pcCoeff = ( bRealCoeff ? pcCU->getCoeffY () : m_ppcQTTempCoeffY [uiQTLayer] ); break; |
---|
877 | case TEXT_CHROMA_U: pcCoeff = ( bRealCoeff ? pcCU->getCoeffCb() : m_ppcQTTempCoeffCb[uiQTLayer] ); break; |
---|
878 | case TEXT_CHROMA_V: pcCoeff = ( bRealCoeff ? pcCU->getCoeffCr() : m_ppcQTTempCoeffCr[uiQTLayer] ); break; |
---|
879 | default: assert(0); |
---|
880 | } |
---|
881 | pcCoeff += uiCoeffOffset; |
---|
882 | |
---|
883 | m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiWidth, uiHeight, uiFullDepth, eTextType ); |
---|
884 | } |
---|
885 | |
---|
886 | |
---|
887 | Void |
---|
888 | TEncSearch::xEncIntraHeader( TComDataCU* pcCU, |
---|
889 | UInt uiTrDepth, |
---|
890 | UInt uiAbsPartIdx, |
---|
891 | Bool bLuma, |
---|
892 | Bool bChroma ) |
---|
893 | { |
---|
894 | if( bLuma ) |
---|
895 | { |
---|
896 | // CU header |
---|
897 | if( uiAbsPartIdx == 0 ) |
---|
898 | { |
---|
899 | if( !pcCU->getSlice()->isIntra() ) |
---|
900 | { |
---|
901 | if (pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
902 | { |
---|
903 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( pcCU, 0, true ); |
---|
904 | } |
---|
905 | m_pcEntropyCoder->encodeSkipFlag( pcCU, 0, true ); |
---|
906 | m_pcEntropyCoder->encodePredMode( pcCU, 0, true ); |
---|
907 | } |
---|
908 | |
---|
909 | m_pcEntropyCoder ->encodePartSize( pcCU, 0, pcCU->getDepth(0), true ); |
---|
910 | |
---|
911 | if (pcCU->isIntra(0) && pcCU->getPartitionSize(0) == SIZE_2Nx2N ) |
---|
912 | { |
---|
913 | m_pcEntropyCoder->encodeIPCMInfo( pcCU, 0, true ); |
---|
914 | |
---|
915 | if ( pcCU->getIPCMFlag (0)) |
---|
916 | { |
---|
917 | return; |
---|
918 | } |
---|
919 | } |
---|
920 | } |
---|
921 | // luma prediction mode |
---|
922 | if( pcCU->getPartitionSize(0) == SIZE_2Nx2N ) |
---|
923 | { |
---|
924 | if( uiAbsPartIdx == 0 ) |
---|
925 | { |
---|
926 | m_pcEntropyCoder->encodeIntraDirModeLuma ( pcCU, 0 ); |
---|
927 | } |
---|
928 | } |
---|
929 | else |
---|
930 | { |
---|
931 | UInt uiQNumParts = pcCU->getTotalNumPart() >> 2; |
---|
932 | if( uiTrDepth == 0 ) |
---|
933 | { |
---|
934 | assert( uiAbsPartIdx == 0 ); |
---|
935 | for( UInt uiPart = 0; uiPart < 4; uiPart++ ) |
---|
936 | { |
---|
937 | m_pcEntropyCoder->encodeIntraDirModeLuma ( pcCU, uiPart * uiQNumParts ); |
---|
938 | } |
---|
939 | } |
---|
940 | else if( ( uiAbsPartIdx % uiQNumParts ) == 0 ) |
---|
941 | { |
---|
942 | m_pcEntropyCoder->encodeIntraDirModeLuma ( pcCU, uiAbsPartIdx ); |
---|
943 | } |
---|
944 | } |
---|
945 | } |
---|
946 | |
---|
947 | if( bChroma ) |
---|
948 | { |
---|
949 | // chroma prediction mode |
---|
950 | if( uiAbsPartIdx == 0 ) |
---|
951 | { |
---|
952 | m_pcEntropyCoder->encodeIntraDirModeChroma( pcCU, 0, true ); |
---|
953 | } |
---|
954 | } |
---|
955 | } |
---|
956 | |
---|
957 | |
---|
958 | UInt |
---|
959 | TEncSearch::xGetIntraBitsQT( TComDataCU* pcCU, |
---|
960 | UInt uiTrDepth, |
---|
961 | UInt uiAbsPartIdx, |
---|
962 | Bool bLuma, |
---|
963 | Bool bChroma, |
---|
964 | Bool bRealCoeff /* just for test */ ) |
---|
965 | { |
---|
966 | m_pcEntropyCoder->resetBits(); |
---|
967 | xEncIntraHeader ( pcCU, uiTrDepth, uiAbsPartIdx, bLuma, bChroma ); |
---|
968 | xEncSubdivCbfQT ( pcCU, uiTrDepth, uiAbsPartIdx, bLuma, bChroma ); |
---|
969 | |
---|
970 | if( bLuma ) |
---|
971 | { |
---|
972 | xEncCoeffQT ( pcCU, uiTrDepth, uiAbsPartIdx, TEXT_LUMA, bRealCoeff ); |
---|
973 | } |
---|
974 | if( bChroma ) |
---|
975 | { |
---|
976 | xEncCoeffQT ( pcCU, uiTrDepth, uiAbsPartIdx, TEXT_CHROMA_U, bRealCoeff ); |
---|
977 | xEncCoeffQT ( pcCU, uiTrDepth, uiAbsPartIdx, TEXT_CHROMA_V, bRealCoeff ); |
---|
978 | } |
---|
979 | UInt uiBits = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
980 | return uiBits; |
---|
981 | } |
---|
982 | |
---|
983 | UInt |
---|
984 | TEncSearch::xGetIntraBitsQTChroma( TComDataCU* pcCU, |
---|
985 | UInt uiTrDepth, |
---|
986 | UInt uiAbsPartIdx, |
---|
987 | UInt uiChromaId, |
---|
988 | Bool bRealCoeff /* just for test */ ) |
---|
989 | { |
---|
990 | m_pcEntropyCoder->resetBits(); |
---|
991 | if( uiChromaId == TEXT_CHROMA_U) |
---|
992 | { |
---|
993 | xEncCoeffQT ( pcCU, uiTrDepth, uiAbsPartIdx, TEXT_CHROMA_U, bRealCoeff ); |
---|
994 | } |
---|
995 | else if(uiChromaId == TEXT_CHROMA_V) |
---|
996 | { |
---|
997 | xEncCoeffQT ( pcCU, uiTrDepth, uiAbsPartIdx, TEXT_CHROMA_V, bRealCoeff ); |
---|
998 | } |
---|
999 | |
---|
1000 | UInt uiBits = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
1001 | return uiBits; |
---|
1002 | } |
---|
1003 | |
---|
1004 | Void |
---|
1005 | TEncSearch::xIntraCodingLumaBlk( TComDataCU* pcCU, |
---|
1006 | UInt uiTrDepth, |
---|
1007 | UInt uiAbsPartIdx, |
---|
1008 | TComYuv* pcOrgYuv, |
---|
1009 | TComYuv* pcPredYuv, |
---|
1010 | TComYuv* pcResiYuv, |
---|
1011 | UInt& ruiDist, |
---|
1012 | Int default0Save1Load2 ) |
---|
1013 | { |
---|
1014 | UInt uiLumaPredMode = pcCU ->getLumaIntraDir ( uiAbsPartIdx ); |
---|
1015 | UInt uiFullDepth = pcCU ->getDepth ( 0 ) + uiTrDepth; |
---|
1016 | UInt uiWidth = pcCU ->getWidth ( 0 ) >> uiTrDepth; |
---|
1017 | UInt uiHeight = pcCU ->getHeight ( 0 ) >> uiTrDepth; |
---|
1018 | UInt uiStride = pcOrgYuv ->getStride (); |
---|
1019 | Pel* piOrg = pcOrgYuv ->getLumaAddr( uiAbsPartIdx ); |
---|
1020 | Pel* piPred = pcPredYuv->getLumaAddr( uiAbsPartIdx ); |
---|
1021 | Pel* piResi = pcResiYuv->getLumaAddr( uiAbsPartIdx ); |
---|
1022 | Pel* piReco = pcPredYuv->getLumaAddr( uiAbsPartIdx ); |
---|
1023 | |
---|
1024 | UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2; |
---|
1025 | UInt uiQTLayer = pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() - uiLog2TrSize; |
---|
1026 | UInt uiNumCoeffPerInc = pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ); |
---|
1027 | TCoeff* pcCoeff = m_ppcQTTempCoeffY[ uiQTLayer ] + uiNumCoeffPerInc * uiAbsPartIdx; |
---|
1028 | #if ADAPTIVE_QP_SELECTION |
---|
1029 | Int* pcArlCoeff = m_ppcQTTempArlCoeffY[ uiQTLayer ] + uiNumCoeffPerInc * uiAbsPartIdx; |
---|
1030 | #endif |
---|
1031 | Pel* piRecQt = m_pcQTTempTComYuv[ uiQTLayer ].getLumaAddr( uiAbsPartIdx ); |
---|
1032 | UInt uiRecQtStride = m_pcQTTempTComYuv[ uiQTLayer ].getStride (); |
---|
1033 | |
---|
1034 | UInt uiZOrder = pcCU->getZorderIdxInCU() + uiAbsPartIdx; |
---|
1035 | Pel* piRecIPred = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder ); |
---|
1036 | UInt uiRecIPredStride = pcCU->getPic()->getPicYuvRec()->getStride (); |
---|
1037 | Bool useTransformSkip = pcCU->getTransformSkip(uiAbsPartIdx, TEXT_LUMA); |
---|
1038 | //===== init availability pattern ===== |
---|
1039 | Bool bAboveAvail = false; |
---|
1040 | Bool bLeftAvail = false; |
---|
1041 | if(default0Save1Load2 != 2) |
---|
1042 | { |
---|
1043 | pcCU->getPattern()->initPattern ( pcCU, uiTrDepth, uiAbsPartIdx ); |
---|
1044 | pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, uiTrDepth, m_piYuvExt, m_iYuvExtStride, m_iYuvExtHeight, bAboveAvail, bLeftAvail ); |
---|
1045 | //===== get prediction signal ===== |
---|
1046 | predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail ); |
---|
1047 | // save prediction |
---|
1048 | if(default0Save1Load2 == 1) |
---|
1049 | { |
---|
1050 | Pel* pPred = piPred; |
---|
1051 | Pel* pPredBuf = m_pSharedPredTransformSkip[0]; |
---|
1052 | Int k = 0; |
---|
1053 | for( UInt uiY = 0; uiY < uiHeight; uiY++ ) |
---|
1054 | { |
---|
1055 | for( UInt uiX = 0; uiX < uiWidth; uiX++ ) |
---|
1056 | { |
---|
1057 | pPredBuf[ k ++ ] = pPred[ uiX ]; |
---|
1058 | } |
---|
1059 | pPred += uiStride; |
---|
1060 | } |
---|
1061 | } |
---|
1062 | } |
---|
1063 | else |
---|
1064 | { |
---|
1065 | // load prediction |
---|
1066 | Pel* pPred = piPred; |
---|
1067 | Pel* pPredBuf = m_pSharedPredTransformSkip[0]; |
---|
1068 | Int k = 0; |
---|
1069 | for( UInt uiY = 0; uiY < uiHeight; uiY++ ) |
---|
1070 | { |
---|
1071 | for( UInt uiX = 0; uiX < uiWidth; uiX++ ) |
---|
1072 | { |
---|
1073 | pPred[ uiX ] = pPredBuf[ k ++ ]; |
---|
1074 | } |
---|
1075 | pPred += uiStride; |
---|
1076 | } |
---|
1077 | } |
---|
1078 | //===== get residual signal ===== |
---|
1079 | { |
---|
1080 | // get residual |
---|
1081 | Pel* pOrg = piOrg; |
---|
1082 | Pel* pPred = piPred; |
---|
1083 | Pel* pResi = piResi; |
---|
1084 | for( UInt uiY = 0; uiY < uiHeight; uiY++ ) |
---|
1085 | { |
---|
1086 | for( UInt uiX = 0; uiX < uiWidth; uiX++ ) |
---|
1087 | { |
---|
1088 | pResi[ uiX ] = pOrg[ uiX ] - pPred[ uiX ]; |
---|
1089 | } |
---|
1090 | pOrg += uiStride; |
---|
1091 | pResi += uiStride; |
---|
1092 | pPred += uiStride; |
---|
1093 | } |
---|
1094 | } |
---|
1095 | |
---|
1096 | //===== transform and quantization ===== |
---|
1097 | //--- init rate estimation arrays for RDOQ --- |
---|
1098 | if( useTransformSkip? m_pcEncCfg->getUseRDOQTS():m_pcEncCfg->getUseRDOQ()) |
---|
1099 | { |
---|
1100 | m_pcEntropyCoder->estimateBit( m_pcTrQuant->m_pcEstBitsSbac, uiWidth, uiWidth, TEXT_LUMA ); |
---|
1101 | } |
---|
1102 | //--- transform and quantization --- |
---|
1103 | UInt uiAbsSum = 0; |
---|
1104 | pcCU ->setTrIdxSubParts ( uiTrDepth, uiAbsPartIdx, uiFullDepth ); |
---|
1105 | |
---|
1106 | #if REPN_FORMAT_IN_VPS |
---|
1107 | m_pcTrQuant->setQPforQuant ( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 ); |
---|
1108 | #else |
---|
1109 | m_pcTrQuant->setQPforQuant ( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 ); |
---|
1110 | #endif |
---|
1111 | |
---|
1112 | #if RDOQ_CHROMA_LAMBDA |
---|
1113 | m_pcTrQuant->selectLambda (TEXT_LUMA); |
---|
1114 | #endif |
---|
1115 | |
---|
1116 | m_pcTrQuant->transformNxN ( pcCU, piResi, uiStride, pcCoeff, |
---|
1117 | #if ADAPTIVE_QP_SELECTION |
---|
1118 | pcArlCoeff, |
---|
1119 | #endif |
---|
1120 | uiWidth, uiHeight, uiAbsSum, TEXT_LUMA, uiAbsPartIdx,useTransformSkip ); |
---|
1121 | |
---|
1122 | //--- set coded block flag --- |
---|
1123 | pcCU->setCbfSubParts ( ( uiAbsSum ? 1 : 0 ) << uiTrDepth, TEXT_LUMA, uiAbsPartIdx, uiFullDepth ); |
---|
1124 | //--- inverse transform --- |
---|
1125 | if( uiAbsSum ) |
---|
1126 | { |
---|
1127 | Int scalingListType = 0 + g_eTTable[(Int)TEXT_LUMA]; |
---|
1128 | assert(scalingListType < 6); |
---|
1129 | m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA,pcCU->getLumaIntraDir( uiAbsPartIdx ), piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkip ); |
---|
1130 | } |
---|
1131 | else |
---|
1132 | { |
---|
1133 | Pel* pResi = piResi; |
---|
1134 | memset( pcCoeff, 0, sizeof( TCoeff ) * uiWidth * uiHeight ); |
---|
1135 | for( UInt uiY = 0; uiY < uiHeight; uiY++ ) |
---|
1136 | { |
---|
1137 | memset( pResi, 0, sizeof( Pel ) * uiWidth ); |
---|
1138 | pResi += uiStride; |
---|
1139 | } |
---|
1140 | } |
---|
1141 | |
---|
1142 | //===== reconstruction ===== |
---|
1143 | { |
---|
1144 | Pel* pPred = piPred; |
---|
1145 | Pel* pResi = piResi; |
---|
1146 | Pel* pReco = piReco; |
---|
1147 | Pel* pRecQt = piRecQt; |
---|
1148 | Pel* pRecIPred = piRecIPred; |
---|
1149 | for( UInt uiY = 0; uiY < uiHeight; uiY++ ) |
---|
1150 | { |
---|
1151 | for( UInt uiX = 0; uiX < uiWidth; uiX++ ) |
---|
1152 | { |
---|
1153 | pReco [ uiX ] = ClipY( pPred[ uiX ] + pResi[ uiX ] ); |
---|
1154 | pRecQt [ uiX ] = pReco[ uiX ]; |
---|
1155 | pRecIPred[ uiX ] = pReco[ uiX ]; |
---|
1156 | } |
---|
1157 | pPred += uiStride; |
---|
1158 | pResi += uiStride; |
---|
1159 | pReco += uiStride; |
---|
1160 | pRecQt += uiRecQtStride; |
---|
1161 | pRecIPred += uiRecIPredStride; |
---|
1162 | } |
---|
1163 | } |
---|
1164 | |
---|
1165 | //===== update distortion ===== |
---|
1166 | ruiDist += m_pcRdCost->getDistPart(g_bitDepthY, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight ); |
---|
1167 | } |
---|
1168 | |
---|
1169 | Void |
---|
1170 | TEncSearch::xIntraCodingChromaBlk( TComDataCU* pcCU, |
---|
1171 | UInt uiTrDepth, |
---|
1172 | UInt uiAbsPartIdx, |
---|
1173 | TComYuv* pcOrgYuv, |
---|
1174 | TComYuv* pcPredYuv, |
---|
1175 | TComYuv* pcResiYuv, |
---|
1176 | UInt& ruiDist, |
---|
1177 | UInt uiChromaId, |
---|
1178 | Int default0Save1Load2 ) |
---|
1179 | { |
---|
1180 | UInt uiOrgTrDepth = uiTrDepth; |
---|
1181 | UInt uiFullDepth = pcCU->getDepth( 0 ) + uiTrDepth; |
---|
1182 | UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2; |
---|
1183 | if( uiLog2TrSize == 2 ) |
---|
1184 | { |
---|
1185 | assert( uiTrDepth > 0 ); |
---|
1186 | uiTrDepth--; |
---|
1187 | UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrDepth ) << 1 ); |
---|
1188 | Bool bFirstQ = ( ( uiAbsPartIdx % uiQPDiv ) == 0 ); |
---|
1189 | if( !bFirstQ ) |
---|
1190 | { |
---|
1191 | return; |
---|
1192 | } |
---|
1193 | } |
---|
1194 | |
---|
1195 | TextType eText = ( uiChromaId > 0 ? TEXT_CHROMA_V : TEXT_CHROMA_U ); |
---|
1196 | UInt uiChromaPredMode = pcCU ->getChromaIntraDir( uiAbsPartIdx ); |
---|
1197 | UInt uiWidth = pcCU ->getWidth ( 0 ) >> ( uiTrDepth + 1 ); |
---|
1198 | UInt uiHeight = pcCU ->getHeight ( 0 ) >> ( uiTrDepth + 1 ); |
---|
1199 | UInt uiStride = pcOrgYuv ->getCStride (); |
---|
1200 | Pel* piOrg = ( uiChromaId > 0 ? pcOrgYuv ->getCrAddr( uiAbsPartIdx ) : pcOrgYuv ->getCbAddr( uiAbsPartIdx ) ); |
---|
1201 | Pel* piPred = ( uiChromaId > 0 ? pcPredYuv->getCrAddr( uiAbsPartIdx ) : pcPredYuv->getCbAddr( uiAbsPartIdx ) ); |
---|
1202 | Pel* piResi = ( uiChromaId > 0 ? pcResiYuv->getCrAddr( uiAbsPartIdx ) : pcResiYuv->getCbAddr( uiAbsPartIdx ) ); |
---|
1203 | Pel* piReco = ( uiChromaId > 0 ? pcPredYuv->getCrAddr( uiAbsPartIdx ) : pcPredYuv->getCbAddr( uiAbsPartIdx ) ); |
---|
1204 | |
---|
1205 | UInt uiQTLayer = pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() - uiLog2TrSize; |
---|
1206 | UInt uiNumCoeffPerInc = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ) ) >> 2; |
---|
1207 | TCoeff* pcCoeff = ( uiChromaId > 0 ? m_ppcQTTempCoeffCr[ uiQTLayer ] : m_ppcQTTempCoeffCb[ uiQTLayer ] ) + uiNumCoeffPerInc * uiAbsPartIdx; |
---|
1208 | #if ADAPTIVE_QP_SELECTION |
---|
1209 | Int* pcArlCoeff = ( uiChromaId > 0 ? m_ppcQTTempArlCoeffCr[ uiQTLayer ] : m_ppcQTTempArlCoeffCb[ uiQTLayer ] ) + uiNumCoeffPerInc * uiAbsPartIdx; |
---|
1210 | #endif |
---|
1211 | Pel* piRecQt = ( uiChromaId > 0 ? m_pcQTTempTComYuv[ uiQTLayer ].getCrAddr( uiAbsPartIdx ) : m_pcQTTempTComYuv[ uiQTLayer ].getCbAddr( uiAbsPartIdx ) ); |
---|
1212 | UInt uiRecQtStride = m_pcQTTempTComYuv[ uiQTLayer ].getCStride(); |
---|
1213 | |
---|
1214 | UInt uiZOrder = pcCU->getZorderIdxInCU() + uiAbsPartIdx; |
---|
1215 | Pel* piRecIPred = ( uiChromaId > 0 ? pcCU->getPic()->getPicYuvRec()->getCrAddr( pcCU->getAddr(), uiZOrder ) : pcCU->getPic()->getPicYuvRec()->getCbAddr( pcCU->getAddr(), uiZOrder ) ); |
---|
1216 | UInt uiRecIPredStride = pcCU->getPic()->getPicYuvRec()->getCStride(); |
---|
1217 | Bool useTransformSkipChroma = pcCU->getTransformSkip(uiAbsPartIdx, eText); |
---|
1218 | //===== update chroma mode ===== |
---|
1219 | if( uiChromaPredMode == DM_CHROMA_IDX ) |
---|
1220 | { |
---|
1221 | uiChromaPredMode = pcCU->getLumaIntraDir( 0 ); |
---|
1222 | } |
---|
1223 | |
---|
1224 | //===== init availability pattern ===== |
---|
1225 | Bool bAboveAvail = false; |
---|
1226 | Bool bLeftAvail = false; |
---|
1227 | if( default0Save1Load2 != 2 ) |
---|
1228 | { |
---|
1229 | pcCU->getPattern()->initPattern ( pcCU, uiTrDepth, uiAbsPartIdx ); |
---|
1230 | |
---|
1231 | pcCU->getPattern()->initAdiPatternChroma( pcCU, uiAbsPartIdx, uiTrDepth, m_piYuvExt, m_iYuvExtStride, m_iYuvExtHeight, bAboveAvail, bLeftAvail ); |
---|
1232 | Int* pPatChroma = ( uiChromaId > 0 ? pcCU->getPattern()->getAdiCrBuf( uiWidth, uiHeight, m_piYuvExt ) : pcCU->getPattern()->getAdiCbBuf( uiWidth, uiHeight, m_piYuvExt ) ); |
---|
1233 | |
---|
1234 | //===== get prediction signal ===== |
---|
1235 | predIntraChromaAng( pPatChroma, uiChromaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail ); |
---|
1236 | |
---|
1237 | // save prediction |
---|
1238 | if( default0Save1Load2 == 1 ) |
---|
1239 | { |
---|
1240 | Pel* pPred = piPred; |
---|
1241 | Pel* pPredBuf = m_pSharedPredTransformSkip[1 + uiChromaId]; |
---|
1242 | Int k = 0; |
---|
1243 | for( UInt uiY = 0; uiY < uiHeight; uiY++ ) |
---|
1244 | { |
---|
1245 | for( UInt uiX = 0; uiX < uiWidth; uiX++ ) |
---|
1246 | { |
---|
1247 | pPredBuf[ k ++ ] = pPred[ uiX ]; |
---|
1248 | } |
---|
1249 | pPred += uiStride; |
---|
1250 | } |
---|
1251 | } |
---|
1252 | } |
---|
1253 | else |
---|
1254 | { |
---|
1255 | // load prediction |
---|
1256 | Pel* pPred = piPred; |
---|
1257 | Pel* pPredBuf = m_pSharedPredTransformSkip[1 + uiChromaId]; |
---|
1258 | Int k = 0; |
---|
1259 | for( UInt uiY = 0; uiY < uiHeight; uiY++ ) |
---|
1260 | { |
---|
1261 | for( UInt uiX = 0; uiX < uiWidth; uiX++ ) |
---|
1262 | { |
---|
1263 | pPred[ uiX ] = pPredBuf[ k ++ ]; |
---|
1264 | } |
---|
1265 | pPred += uiStride; |
---|
1266 | } |
---|
1267 | } |
---|
1268 | //===== get residual signal ===== |
---|
1269 | { |
---|
1270 | // get residual |
---|
1271 | Pel* pOrg = piOrg; |
---|
1272 | Pel* pPred = piPred; |
---|
1273 | Pel* pResi = piResi; |
---|
1274 | for( UInt uiY = 0; uiY < uiHeight; uiY++ ) |
---|
1275 | { |
---|
1276 | for( UInt uiX = 0; uiX < uiWidth; uiX++ ) |
---|
1277 | { |
---|
1278 | pResi[ uiX ] = pOrg[ uiX ] - pPred[ uiX ]; |
---|
1279 | } |
---|
1280 | pOrg += uiStride; |
---|
1281 | pResi += uiStride; |
---|
1282 | pPred += uiStride; |
---|
1283 | } |
---|
1284 | } |
---|
1285 | |
---|
1286 | //===== transform and quantization ===== |
---|
1287 | { |
---|
1288 | //--- init rate estimation arrays for RDOQ --- |
---|
1289 | if( useTransformSkipChroma? m_pcEncCfg->getUseRDOQTS():m_pcEncCfg->getUseRDOQ()) |
---|
1290 | { |
---|
1291 | m_pcEntropyCoder->estimateBit( m_pcTrQuant->m_pcEstBitsSbac, uiWidth, uiWidth, eText ); |
---|
1292 | } |
---|
1293 | //--- transform and quantization --- |
---|
1294 | UInt uiAbsSum = 0; |
---|
1295 | |
---|
1296 | Int curChromaQpOffset; |
---|
1297 | if(eText == TEXT_CHROMA_U) |
---|
1298 | { |
---|
1299 | curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb(); |
---|
1300 | } |
---|
1301 | else |
---|
1302 | { |
---|
1303 | curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr(); |
---|
1304 | } |
---|
1305 | m_pcTrQuant->setQPforQuant ( pcCU->getQP( 0 ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset ); |
---|
1306 | |
---|
1307 | #if RDOQ_CHROMA_LAMBDA |
---|
1308 | m_pcTrQuant->selectLambda (TEXT_CHROMA); |
---|
1309 | #endif |
---|
1310 | m_pcTrQuant->transformNxN ( pcCU, piResi, uiStride, pcCoeff, |
---|
1311 | #if ADAPTIVE_QP_SELECTION |
---|
1312 | pcArlCoeff, |
---|
1313 | #endif |
---|
1314 | uiWidth, uiHeight, uiAbsSum, eText, uiAbsPartIdx, useTransformSkipChroma ); |
---|
1315 | //--- set coded block flag --- |
---|
1316 | pcCU->setCbfSubParts ( ( uiAbsSum ? 1 : 0 ) << uiOrgTrDepth, eText, uiAbsPartIdx, pcCU->getDepth(0) + uiTrDepth ); |
---|
1317 | //--- inverse transform --- |
---|
1318 | if( uiAbsSum ) |
---|
1319 | { |
---|
1320 | Int scalingListType = 0 + g_eTTable[(Int)eText]; |
---|
1321 | assert(scalingListType < 6); |
---|
1322 | m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA, REG_DCT, piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkipChroma ); |
---|
1323 | } |
---|
1324 | else |
---|
1325 | { |
---|
1326 | Pel* pResi = piResi; |
---|
1327 | memset( pcCoeff, 0, sizeof( TCoeff ) * uiWidth * uiHeight ); |
---|
1328 | for( UInt uiY = 0; uiY < uiHeight; uiY++ ) |
---|
1329 | { |
---|
1330 | memset( pResi, 0, sizeof( Pel ) * uiWidth ); |
---|
1331 | pResi += uiStride; |
---|
1332 | } |
---|
1333 | } |
---|
1334 | } |
---|
1335 | |
---|
1336 | //===== reconstruction ===== |
---|
1337 | { |
---|
1338 | Pel* pPred = piPred; |
---|
1339 | Pel* pResi = piResi; |
---|
1340 | Pel* pReco = piReco; |
---|
1341 | Pel* pRecQt = piRecQt; |
---|
1342 | Pel* pRecIPred = piRecIPred; |
---|
1343 | for( UInt uiY = 0; uiY < uiHeight; uiY++ ) |
---|
1344 | { |
---|
1345 | for( UInt uiX = 0; uiX < uiWidth; uiX++ ) |
---|
1346 | { |
---|
1347 | pReco [ uiX ] = ClipC( pPred[ uiX ] + pResi[ uiX ] ); |
---|
1348 | pRecQt [ uiX ] = pReco[ uiX ]; |
---|
1349 | pRecIPred[ uiX ] = pReco[ uiX ]; |
---|
1350 | } |
---|
1351 | pPred += uiStride; |
---|
1352 | pResi += uiStride; |
---|
1353 | pReco += uiStride; |
---|
1354 | pRecQt += uiRecQtStride; |
---|
1355 | pRecIPred += uiRecIPredStride; |
---|
1356 | } |
---|
1357 | } |
---|
1358 | |
---|
1359 | //===== update distortion ===== |
---|
1360 | #if WEIGHTED_CHROMA_DISTORTION |
---|
1361 | ruiDist += m_pcRdCost->getDistPart(g_bitDepthC, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight, eText ); |
---|
1362 | #else |
---|
1363 | ruiDist += m_pcRdCost->getDistPart(g_bitDepthC, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight ); |
---|
1364 | #endif |
---|
1365 | } |
---|
1366 | |
---|
1367 | |
---|
1368 | |
---|
1369 | Void |
---|
1370 | TEncSearch::xRecurIntraCodingQT( TComDataCU* pcCU, |
---|
1371 | UInt uiTrDepth, |
---|
1372 | UInt uiAbsPartIdx, |
---|
1373 | Bool bLumaOnly, |
---|
1374 | TComYuv* pcOrgYuv, |
---|
1375 | TComYuv* pcPredYuv, |
---|
1376 | TComYuv* pcResiYuv, |
---|
1377 | UInt& ruiDistY, |
---|
1378 | UInt& ruiDistC, |
---|
1379 | #if HHI_RQT_INTRA_SPEEDUP |
---|
1380 | Bool bCheckFirst, |
---|
1381 | #endif |
---|
1382 | Double& dRDCost ) |
---|
1383 | { |
---|
1384 | UInt uiFullDepth = pcCU->getDepth( 0 ) + uiTrDepth; |
---|
1385 | UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2; |
---|
1386 | Bool bCheckFull = ( uiLog2TrSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ); |
---|
1387 | Bool bCheckSplit = ( uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ); |
---|
1388 | |
---|
1389 | #if HHI_RQT_INTRA_SPEEDUP |
---|
1390 | Int maxTuSize = pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize(); |
---|
1391 | Int isIntraSlice = (pcCU->getSlice()->getSliceType() == I_SLICE); |
---|
1392 | // don't check split if TU size is less or equal to max TU size |
---|
1393 | Bool noSplitIntraMaxTuSize = bCheckFull; |
---|
1394 | if(m_pcEncCfg->getRDpenalty() && ! isIntraSlice) |
---|
1395 | { |
---|
1396 | // in addition don't check split if TU size is less or equal to 16x16 TU size for non-intra slice |
---|
1397 | noSplitIntraMaxTuSize = ( uiLog2TrSize <= min(maxTuSize,4) ); |
---|
1398 | |
---|
1399 | // if maximum RD-penalty don't check TU size 32x32 |
---|
1400 | if(m_pcEncCfg->getRDpenalty()==2) |
---|
1401 | { |
---|
1402 | bCheckFull = ( uiLog2TrSize <= min(maxTuSize,4)); |
---|
1403 | } |
---|
1404 | } |
---|
1405 | if( bCheckFirst && noSplitIntraMaxTuSize ) |
---|
1406 | { |
---|
1407 | bCheckSplit = false; |
---|
1408 | } |
---|
1409 | #else |
---|
1410 | Int maxTuSize = pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize(); |
---|
1411 | Int isIntraSlice = (pcCU->getSlice()->getSliceType() == I_SLICE); |
---|
1412 | // if maximum RD-penalty don't check TU size 32x32 |
---|
1413 | if((m_pcEncCfg->getRDpenalty()==2) && !isIntraSlice) |
---|
1414 | { |
---|
1415 | bCheckFull = ( uiLog2TrSize <= min(maxTuSize,4)); |
---|
1416 | } |
---|
1417 | #endif |
---|
1418 | Double dSingleCost = MAX_DOUBLE; |
---|
1419 | UInt uiSingleDistY = 0; |
---|
1420 | UInt uiSingleDistC = 0; |
---|
1421 | UInt uiSingleCbfY = 0; |
---|
1422 | UInt uiSingleCbfU = 0; |
---|
1423 | UInt uiSingleCbfV = 0; |
---|
1424 | Bool checkTransformSkip = pcCU->getSlice()->getPPS()->getUseTransformSkip(); |
---|
1425 | UInt widthTransformSkip = pcCU->getWidth ( 0 ) >> uiTrDepth; |
---|
1426 | UInt heightTransformSkip = pcCU->getHeight( 0 ) >> uiTrDepth; |
---|
1427 | Int bestModeId = 0; |
---|
1428 | Int bestModeIdUV[2] = {0, 0}; |
---|
1429 | checkTransformSkip &= (widthTransformSkip == 4 && heightTransformSkip == 4); |
---|
1430 | checkTransformSkip &= (!pcCU->getCUTransquantBypass(0)); |
---|
1431 | checkTransformSkip &= (!((pcCU->getQP( 0 ) == 0) && (pcCU->getSlice()->getSPS()->getUseLossless()))); |
---|
1432 | if ( m_pcEncCfg->getUseTransformSkipFast() ) |
---|
1433 | { |
---|
1434 | checkTransformSkip &= (pcCU->getPartitionSize(uiAbsPartIdx)==SIZE_NxN); |
---|
1435 | } |
---|
1436 | if( bCheckFull ) |
---|
1437 | { |
---|
1438 | if(checkTransformSkip == true) |
---|
1439 | { |
---|
1440 | //----- store original entropy coding status ----- |
---|
1441 | if( m_bUseSBACRD) |
---|
1442 | { |
---|
1443 | m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] ); |
---|
1444 | } |
---|
1445 | UInt singleDistYTmp = 0; |
---|
1446 | UInt singleDistCTmp = 0; |
---|
1447 | UInt singleCbfYTmp = 0; |
---|
1448 | UInt singleCbfUTmp = 0; |
---|
1449 | UInt singleCbfVTmp = 0; |
---|
1450 | Double singleCostTmp = 0; |
---|
1451 | Int default0Save1Load2 = 0; |
---|
1452 | Int firstCheckId = 0; |
---|
1453 | |
---|
1454 | UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + (uiTrDepth - 1) ) << 1 ); |
---|
1455 | Bool bFirstQ = ( ( uiAbsPartIdx % uiQPDiv ) == 0 ); |
---|
1456 | |
---|
1457 | for(Int modeId = firstCheckId; modeId < 2; modeId ++) |
---|
1458 | { |
---|
1459 | singleDistYTmp = 0; |
---|
1460 | singleDistCTmp = 0; |
---|
1461 | pcCU ->setTransformSkipSubParts ( modeId, TEXT_LUMA, uiAbsPartIdx, uiFullDepth ); |
---|
1462 | if(modeId == firstCheckId) |
---|
1463 | { |
---|
1464 | default0Save1Load2 = 1; |
---|
1465 | } |
---|
1466 | else |
---|
1467 | { |
---|
1468 | default0Save1Load2 = 2; |
---|
1469 | } |
---|
1470 | //----- code luma block with given intra prediction mode and store Cbf----- |
---|
1471 | xIntraCodingLumaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcOrgYuv, pcPredYuv, pcResiYuv, singleDistYTmp,default0Save1Load2); |
---|
1472 | singleCbfYTmp = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth ); |
---|
1473 | //----- code chroma blocks with given intra prediction mode and store Cbf----- |
---|
1474 | if( !bLumaOnly ) |
---|
1475 | { |
---|
1476 | if(bFirstQ) |
---|
1477 | { |
---|
1478 | pcCU ->setTransformSkipSubParts ( modeId, TEXT_CHROMA_U, uiAbsPartIdx, uiFullDepth); |
---|
1479 | pcCU ->setTransformSkipSubParts ( modeId, TEXT_CHROMA_V, uiAbsPartIdx, uiFullDepth); |
---|
1480 | } |
---|
1481 | xIntraCodingChromaBlk ( pcCU, uiTrDepth, uiAbsPartIdx, pcOrgYuv, pcPredYuv, pcResiYuv, singleDistCTmp, 0, default0Save1Load2); |
---|
1482 | xIntraCodingChromaBlk ( pcCU, uiTrDepth, uiAbsPartIdx, pcOrgYuv, pcPredYuv, pcResiYuv, singleDistCTmp, 1, default0Save1Load2); |
---|
1483 | singleCbfUTmp = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth ); |
---|
1484 | singleCbfVTmp = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth ); |
---|
1485 | } |
---|
1486 | //----- determine rate and r-d cost ----- |
---|
1487 | if(modeId == 1 && singleCbfYTmp == 0) |
---|
1488 | { |
---|
1489 | //In order not to code TS flag when cbf is zero, the case for TS with cbf being zero is forbidden. |
---|
1490 | singleCostTmp = MAX_DOUBLE; |
---|
1491 | } |
---|
1492 | else |
---|
1493 | { |
---|
1494 | UInt uiSingleBits = xGetIntraBitsQT( pcCU, uiTrDepth, uiAbsPartIdx, true, !bLumaOnly, false ); |
---|
1495 | singleCostTmp = m_pcRdCost->calcRdCost( uiSingleBits, singleDistYTmp + singleDistCTmp ); |
---|
1496 | } |
---|
1497 | |
---|
1498 | if(singleCostTmp < dSingleCost) |
---|
1499 | { |
---|
1500 | dSingleCost = singleCostTmp; |
---|
1501 | uiSingleDistY = singleDistYTmp; |
---|
1502 | uiSingleDistC = singleDistCTmp; |
---|
1503 | uiSingleCbfY = singleCbfYTmp; |
---|
1504 | uiSingleCbfU = singleCbfUTmp; |
---|
1505 | uiSingleCbfV = singleCbfVTmp; |
---|
1506 | bestModeId = modeId; |
---|
1507 | if(bestModeId == firstCheckId) |
---|
1508 | { |
---|
1509 | xStoreIntraResultQT(pcCU, uiTrDepth, uiAbsPartIdx,bLumaOnly ); |
---|
1510 | if( m_bUseSBACRD) |
---|
1511 | { |
---|
1512 | m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] ); |
---|
1513 | } |
---|
1514 | } |
---|
1515 | } |
---|
1516 | if(modeId == firstCheckId) |
---|
1517 | { |
---|
1518 | m_pcRDGoOnSbacCoder->load ( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] ); |
---|
1519 | } |
---|
1520 | } |
---|
1521 | |
---|
1522 | pcCU ->setTransformSkipSubParts ( bestModeId, TEXT_LUMA, uiAbsPartIdx, uiFullDepth ); |
---|
1523 | |
---|
1524 | if(bestModeId == firstCheckId) |
---|
1525 | { |
---|
1526 | xLoadIntraResultQT(pcCU, uiTrDepth, uiAbsPartIdx,bLumaOnly ); |
---|
1527 | pcCU->setCbfSubParts ( uiSingleCbfY << uiTrDepth, TEXT_LUMA, uiAbsPartIdx, uiFullDepth ); |
---|
1528 | if( !bLumaOnly ) |
---|
1529 | { |
---|
1530 | if(bFirstQ) |
---|
1531 | { |
---|
1532 | pcCU->setCbfSubParts( uiSingleCbfU << uiTrDepth, TEXT_CHROMA_U, uiAbsPartIdx, pcCU->getDepth( 0 ) + uiTrDepth - 1 ); |
---|
1533 | pcCU->setCbfSubParts( uiSingleCbfV << uiTrDepth, TEXT_CHROMA_V, uiAbsPartIdx, pcCU->getDepth( 0 ) + uiTrDepth - 1 ); |
---|
1534 | } |
---|
1535 | } |
---|
1536 | if(m_bUseSBACRD) |
---|
1537 | { |
---|
1538 | m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] ); |
---|
1539 | } |
---|
1540 | } |
---|
1541 | |
---|
1542 | if( !bLumaOnly ) |
---|
1543 | { |
---|
1544 | bestModeIdUV[0] = bestModeIdUV[1] = bestModeId; |
---|
1545 | if(bFirstQ && bestModeId == 1) |
---|
1546 | { |
---|
1547 | //In order not to code TS flag when cbf is zero, the case for TS with cbf being zero is forbidden. |
---|
1548 | if(uiSingleCbfU == 0) |
---|
1549 | { |
---|
1550 | pcCU ->setTransformSkipSubParts ( 0, TEXT_CHROMA_U, uiAbsPartIdx, uiFullDepth); |
---|
1551 | bestModeIdUV[0] = 0; |
---|
1552 | } |
---|
1553 | if(uiSingleCbfV == 0) |
---|
1554 | { |
---|
1555 | pcCU ->setTransformSkipSubParts ( 0, TEXT_CHROMA_V, uiAbsPartIdx, uiFullDepth); |
---|
1556 | bestModeIdUV[1] = 0; |
---|
1557 | } |
---|
1558 | } |
---|
1559 | } |
---|
1560 | } |
---|
1561 | else |
---|
1562 | { |
---|
1563 | pcCU ->setTransformSkipSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiFullDepth ); |
---|
1564 | //----- store original entropy coding status ----- |
---|
1565 | if( m_bUseSBACRD && bCheckSplit ) |
---|
1566 | { |
---|
1567 | m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] ); |
---|
1568 | } |
---|
1569 | //----- code luma block with given intra prediction mode and store Cbf----- |
---|
1570 | dSingleCost = 0.0; |
---|
1571 | xIntraCodingLumaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcOrgYuv, pcPredYuv, pcResiYuv, uiSingleDistY ); |
---|
1572 | if( bCheckSplit ) |
---|
1573 | { |
---|
1574 | uiSingleCbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth ); |
---|
1575 | } |
---|
1576 | //----- code chroma blocks with given intra prediction mode and store Cbf----- |
---|
1577 | if( !bLumaOnly ) |
---|
1578 | { |
---|
1579 | pcCU ->setTransformSkipSubParts ( 0, TEXT_CHROMA_U, uiAbsPartIdx, uiFullDepth ); |
---|
1580 | pcCU ->setTransformSkipSubParts ( 0, TEXT_CHROMA_V, uiAbsPartIdx, uiFullDepth ); |
---|
1581 | xIntraCodingChromaBlk ( pcCU, uiTrDepth, uiAbsPartIdx, pcOrgYuv, pcPredYuv, pcResiYuv, uiSingleDistC, 0 ); |
---|
1582 | xIntraCodingChromaBlk ( pcCU, uiTrDepth, uiAbsPartIdx, pcOrgYuv, pcPredYuv, pcResiYuv, uiSingleDistC, 1 ); |
---|
1583 | if( bCheckSplit ) |
---|
1584 | { |
---|
1585 | uiSingleCbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth ); |
---|
1586 | uiSingleCbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth ); |
---|
1587 | } |
---|
1588 | } |
---|
1589 | //----- determine rate and r-d cost ----- |
---|
1590 | UInt uiSingleBits = xGetIntraBitsQT( pcCU, uiTrDepth, uiAbsPartIdx, true, !bLumaOnly, false ); |
---|
1591 | if(m_pcEncCfg->getRDpenalty() && (uiLog2TrSize==5) && !isIntraSlice) |
---|
1592 | { |
---|
1593 | uiSingleBits=uiSingleBits*4; |
---|
1594 | } |
---|
1595 | dSingleCost = m_pcRdCost->calcRdCost( uiSingleBits, uiSingleDistY + uiSingleDistC ); |
---|
1596 | } |
---|
1597 | } |
---|
1598 | |
---|
1599 | if( bCheckSplit ) |
---|
1600 | { |
---|
1601 | //----- store full entropy coding status, load original entropy coding status ----- |
---|
1602 | if( m_bUseSBACRD ) |
---|
1603 | { |
---|
1604 | if( bCheckFull ) |
---|
1605 | { |
---|
1606 | m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_TEST ] ); |
---|
1607 | m_pcRDGoOnSbacCoder->load ( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] ); |
---|
1608 | } |
---|
1609 | else |
---|
1610 | { |
---|
1611 | m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] ); |
---|
1612 | } |
---|
1613 | } |
---|
1614 | //----- code splitted block ----- |
---|
1615 | Double dSplitCost = 0.0; |
---|
1616 | UInt uiSplitDistY = 0; |
---|
1617 | UInt uiSplitDistC = 0; |
---|
1618 | UInt uiQPartsDiv = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 ); |
---|
1619 | UInt uiAbsPartIdxSub = uiAbsPartIdx; |
---|
1620 | |
---|
1621 | UInt uiSplitCbfY = 0; |
---|
1622 | UInt uiSplitCbfU = 0; |
---|
1623 | UInt uiSplitCbfV = 0; |
---|
1624 | |
---|
1625 | for( UInt uiPart = 0; uiPart < 4; uiPart++, uiAbsPartIdxSub += uiQPartsDiv ) |
---|
1626 | { |
---|
1627 | #if HHI_RQT_INTRA_SPEEDUP |
---|
1628 | xRecurIntraCodingQT( pcCU, uiTrDepth + 1, uiAbsPartIdxSub, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiSplitDistY, uiSplitDistC, bCheckFirst, dSplitCost ); |
---|
1629 | #else |
---|
1630 | xRecurIntraCodingQT( pcCU, uiTrDepth + 1, uiAbsPartIdxSub, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiSplitDistY, uiSplitDistC, dSplitCost ); |
---|
1631 | #endif |
---|
1632 | |
---|
1633 | uiSplitCbfY |= pcCU->getCbf( uiAbsPartIdxSub, TEXT_LUMA, uiTrDepth + 1 ); |
---|
1634 | if(!bLumaOnly) |
---|
1635 | { |
---|
1636 | uiSplitCbfU |= pcCU->getCbf( uiAbsPartIdxSub, TEXT_CHROMA_U, uiTrDepth + 1 ); |
---|
1637 | uiSplitCbfV |= pcCU->getCbf( uiAbsPartIdxSub, TEXT_CHROMA_V, uiTrDepth + 1 ); |
---|
1638 | } |
---|
1639 | } |
---|
1640 | |
---|
1641 | for( UInt uiOffs = 0; uiOffs < 4 * uiQPartsDiv; uiOffs++ ) |
---|
1642 | { |
---|
1643 | pcCU->getCbf( TEXT_LUMA )[ uiAbsPartIdx + uiOffs ] |= ( uiSplitCbfY << uiTrDepth ); |
---|
1644 | } |
---|
1645 | if( !bLumaOnly ) |
---|
1646 | { |
---|
1647 | for( UInt uiOffs = 0; uiOffs < 4 * uiQPartsDiv; uiOffs++ ) |
---|
1648 | { |
---|
1649 | pcCU->getCbf( TEXT_CHROMA_U )[ uiAbsPartIdx + uiOffs ] |= ( uiSplitCbfU << uiTrDepth ); |
---|
1650 | pcCU->getCbf( TEXT_CHROMA_V )[ uiAbsPartIdx + uiOffs ] |= ( uiSplitCbfV << uiTrDepth ); |
---|
1651 | } |
---|
1652 | } |
---|
1653 | //----- restore context states ----- |
---|
1654 | if( m_bUseSBACRD ) |
---|
1655 | { |
---|
1656 | m_pcRDGoOnSbacCoder->load ( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] ); |
---|
1657 | } |
---|
1658 | //----- determine rate and r-d cost ----- |
---|
1659 | UInt uiSplitBits = xGetIntraBitsQT( pcCU, uiTrDepth, uiAbsPartIdx, true, !bLumaOnly, false ); |
---|
1660 | dSplitCost = m_pcRdCost->calcRdCost( uiSplitBits, uiSplitDistY + uiSplitDistC ); |
---|
1661 | |
---|
1662 | //===== compare and set best ===== |
---|
1663 | if( dSplitCost < dSingleCost ) |
---|
1664 | { |
---|
1665 | //--- update cost --- |
---|
1666 | ruiDistY += uiSplitDistY; |
---|
1667 | ruiDistC += uiSplitDistC; |
---|
1668 | dRDCost += dSplitCost; |
---|
1669 | return; |
---|
1670 | } |
---|
1671 | //----- set entropy coding status ----- |
---|
1672 | if( m_bUseSBACRD ) |
---|
1673 | { |
---|
1674 | m_pcRDGoOnSbacCoder->load ( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_TEST ] ); |
---|
1675 | } |
---|
1676 | |
---|
1677 | //--- set transform index and Cbf values --- |
---|
1678 | pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiFullDepth ); |
---|
1679 | pcCU->setCbfSubParts ( uiSingleCbfY << uiTrDepth, TEXT_LUMA, uiAbsPartIdx, uiFullDepth ); |
---|
1680 | pcCU ->setTransformSkipSubParts ( bestModeId, TEXT_LUMA, uiAbsPartIdx, uiFullDepth ); |
---|
1681 | if( !bLumaOnly ) |
---|
1682 | { |
---|
1683 | pcCU->setCbfSubParts( uiSingleCbfU << uiTrDepth, TEXT_CHROMA_U, uiAbsPartIdx, uiFullDepth ); |
---|
1684 | pcCU->setCbfSubParts( uiSingleCbfV << uiTrDepth, TEXT_CHROMA_V, uiAbsPartIdx, uiFullDepth ); |
---|
1685 | pcCU->setTransformSkipSubParts ( bestModeIdUV[0], TEXT_CHROMA_U, uiAbsPartIdx, uiFullDepth); |
---|
1686 | pcCU->setTransformSkipSubParts ( bestModeIdUV[1], TEXT_CHROMA_V, uiAbsPartIdx, uiFullDepth); |
---|
1687 | } |
---|
1688 | |
---|
1689 | //--- set reconstruction for next intra prediction blocks --- |
---|
1690 | UInt uiWidth = pcCU->getWidth ( 0 ) >> uiTrDepth; |
---|
1691 | UInt uiHeight = pcCU->getHeight( 0 ) >> uiTrDepth; |
---|
1692 | UInt uiQTLayer = pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() - uiLog2TrSize; |
---|
1693 | UInt uiZOrder = pcCU->getZorderIdxInCU() + uiAbsPartIdx; |
---|
1694 | Pel* piSrc = m_pcQTTempTComYuv[ uiQTLayer ].getLumaAddr( uiAbsPartIdx ); |
---|
1695 | UInt uiSrcStride = m_pcQTTempTComYuv[ uiQTLayer ].getStride (); |
---|
1696 | Pel* piDes = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder ); |
---|
1697 | UInt uiDesStride = pcCU->getPic()->getPicYuvRec()->getStride (); |
---|
1698 | for( UInt uiY = 0; uiY < uiHeight; uiY++, piSrc += uiSrcStride, piDes += uiDesStride ) |
---|
1699 | { |
---|
1700 | for( UInt uiX = 0; uiX < uiWidth; uiX++ ) |
---|
1701 | { |
---|
1702 | piDes[ uiX ] = piSrc[ uiX ]; |
---|
1703 | } |
---|
1704 | } |
---|
1705 | if( !bLumaOnly ) |
---|
1706 | { |
---|
1707 | uiWidth >>= 1; |
---|
1708 | uiHeight >>= 1; |
---|
1709 | piSrc = m_pcQTTempTComYuv[ uiQTLayer ].getCbAddr ( uiAbsPartIdx ); |
---|
1710 | uiSrcStride = m_pcQTTempTComYuv[ uiQTLayer ].getCStride (); |
---|
1711 | piDes = pcCU->getPic()->getPicYuvRec()->getCbAddr ( pcCU->getAddr(), uiZOrder ); |
---|
1712 | uiDesStride = pcCU->getPic()->getPicYuvRec()->getCStride(); |
---|
1713 | for( UInt uiY = 0; uiY < uiHeight; uiY++, piSrc += uiSrcStride, piDes += uiDesStride ) |
---|
1714 | { |
---|
1715 | for( UInt uiX = 0; uiX < uiWidth; uiX++ ) |
---|
1716 | { |
---|
1717 | piDes[ uiX ] = piSrc[ uiX ]; |
---|
1718 | } |
---|
1719 | } |
---|
1720 | piSrc = m_pcQTTempTComYuv[ uiQTLayer ].getCrAddr ( uiAbsPartIdx ); |
---|
1721 | piDes = pcCU->getPic()->getPicYuvRec()->getCrAddr ( pcCU->getAddr(), uiZOrder ); |
---|
1722 | for( UInt uiY = 0; uiY < uiHeight; uiY++, piSrc += uiSrcStride, piDes += uiDesStride ) |
---|
1723 | { |
---|
1724 | for( UInt uiX = 0; uiX < uiWidth; uiX++ ) |
---|
1725 | { |
---|
1726 | piDes[ uiX ] = piSrc[ uiX ]; |
---|
1727 | } |
---|
1728 | } |
---|
1729 | } |
---|
1730 | } |
---|
1731 | ruiDistY += uiSingleDistY; |
---|
1732 | ruiDistC += uiSingleDistC; |
---|
1733 | dRDCost += dSingleCost; |
---|
1734 | } |
---|
1735 | |
---|
1736 | |
---|
1737 | Void |
---|
1738 | TEncSearch::xSetIntraResultQT( TComDataCU* pcCU, |
---|
1739 | UInt uiTrDepth, |
---|
1740 | UInt uiAbsPartIdx, |
---|
1741 | Bool bLumaOnly, |
---|
1742 | TComYuv* pcRecoYuv ) |
---|
1743 | { |
---|
1744 | UInt uiFullDepth = pcCU->getDepth(0) + uiTrDepth; |
---|
1745 | UInt uiTrMode = pcCU->getTransformIdx( uiAbsPartIdx ); |
---|
1746 | if( uiTrMode == uiTrDepth ) |
---|
1747 | { |
---|
1748 | UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2; |
---|
1749 | UInt uiQTLayer = pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() - uiLog2TrSize; |
---|
1750 | |
---|
1751 | Bool bSkipChroma = false; |
---|
1752 | Bool bChromaSame = false; |
---|
1753 | if( !bLumaOnly && uiLog2TrSize == 2 ) |
---|
1754 | { |
---|
1755 | assert( uiTrDepth > 0 ); |
---|
1756 | UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrDepth - 1 ) << 1 ); |
---|
1757 | bSkipChroma = ( ( uiAbsPartIdx % uiQPDiv ) != 0 ); |
---|
1758 | bChromaSame = true; |
---|
1759 | } |
---|
1760 | |
---|
1761 | //===== copy transform coefficients ===== |
---|
1762 | UInt uiNumCoeffY = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( uiFullDepth << 1 ); |
---|
1763 | UInt uiNumCoeffIncY = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ); |
---|
1764 | TCoeff* pcCoeffSrcY = m_ppcQTTempCoeffY [ uiQTLayer ] + ( uiNumCoeffIncY * uiAbsPartIdx ); |
---|
1765 | TCoeff* pcCoeffDstY = pcCU->getCoeffY () + ( uiNumCoeffIncY * uiAbsPartIdx ); |
---|
1766 | ::memcpy( pcCoeffDstY, pcCoeffSrcY, sizeof( TCoeff ) * uiNumCoeffY ); |
---|
1767 | #if ADAPTIVE_QP_SELECTION |
---|
1768 | Int* pcArlCoeffSrcY = m_ppcQTTempArlCoeffY [ uiQTLayer ] + ( uiNumCoeffIncY * uiAbsPartIdx ); |
---|
1769 | Int* pcArlCoeffDstY = pcCU->getArlCoeffY () + ( uiNumCoeffIncY * uiAbsPartIdx ); |
---|
1770 | ::memcpy( pcArlCoeffDstY, pcArlCoeffSrcY, sizeof( Int ) * uiNumCoeffY ); |
---|
1771 | #endif |
---|
1772 | if( !bLumaOnly && !bSkipChroma ) |
---|
1773 | { |
---|
1774 | UInt uiNumCoeffC = ( bChromaSame ? uiNumCoeffY : uiNumCoeffY >> 2 ); |
---|
1775 | UInt uiNumCoeffIncC = uiNumCoeffIncY >> 2; |
---|
1776 | TCoeff* pcCoeffSrcU = m_ppcQTTempCoeffCb[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
1777 | TCoeff* pcCoeffSrcV = m_ppcQTTempCoeffCr[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
1778 | TCoeff* pcCoeffDstU = pcCU->getCoeffCb() + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
1779 | TCoeff* pcCoeffDstV = pcCU->getCoeffCr() + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
1780 | ::memcpy( pcCoeffDstU, pcCoeffSrcU, sizeof( TCoeff ) * uiNumCoeffC ); |
---|
1781 | ::memcpy( pcCoeffDstV, pcCoeffSrcV, sizeof( TCoeff ) * uiNumCoeffC ); |
---|
1782 | #if ADAPTIVE_QP_SELECTION |
---|
1783 | Int* pcArlCoeffSrcU = m_ppcQTTempArlCoeffCb[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
1784 | Int* pcArlCoeffSrcV = m_ppcQTTempArlCoeffCr[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
1785 | Int* pcArlCoeffDstU = pcCU->getArlCoeffCb() + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
1786 | Int* pcArlCoeffDstV = pcCU->getArlCoeffCr() + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
1787 | ::memcpy( pcArlCoeffDstU, pcArlCoeffSrcU, sizeof( Int ) * uiNumCoeffC ); |
---|
1788 | ::memcpy( pcArlCoeffDstV, pcArlCoeffSrcV, sizeof( Int ) * uiNumCoeffC ); |
---|
1789 | #endif |
---|
1790 | } |
---|
1791 | |
---|
1792 | //===== copy reconstruction ===== |
---|
1793 | m_pcQTTempTComYuv[ uiQTLayer ].copyPartToPartLuma( pcRecoYuv, uiAbsPartIdx, 1 << uiLog2TrSize, 1 << uiLog2TrSize ); |
---|
1794 | if( !bLumaOnly && !bSkipChroma ) |
---|
1795 | { |
---|
1796 | UInt uiLog2TrSizeChroma = ( bChromaSame ? uiLog2TrSize : uiLog2TrSize - 1 ); |
---|
1797 | m_pcQTTempTComYuv[ uiQTLayer ].copyPartToPartChroma( pcRecoYuv, uiAbsPartIdx, 1 << uiLog2TrSizeChroma, 1 << uiLog2TrSizeChroma ); |
---|
1798 | } |
---|
1799 | } |
---|
1800 | else |
---|
1801 | { |
---|
1802 | UInt uiNumQPart = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 ); |
---|
1803 | for( UInt uiPart = 0; uiPart < 4; uiPart++ ) |
---|
1804 | { |
---|
1805 | xSetIntraResultQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, bLumaOnly, pcRecoYuv ); |
---|
1806 | } |
---|
1807 | } |
---|
1808 | } |
---|
1809 | |
---|
1810 | Void |
---|
1811 | TEncSearch::xStoreIntraResultQT( TComDataCU* pcCU, |
---|
1812 | UInt uiTrDepth, |
---|
1813 | UInt uiAbsPartIdx, |
---|
1814 | Bool bLumaOnly ) |
---|
1815 | { |
---|
1816 | UInt uiFullDepth = pcCU->getDepth(0) + uiTrDepth; |
---|
1817 | UInt uiTrMode = pcCU->getTransformIdx( uiAbsPartIdx ); |
---|
1818 | assert( uiTrMode == uiTrDepth ); |
---|
1819 | UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2; |
---|
1820 | UInt uiQTLayer = pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() - uiLog2TrSize; |
---|
1821 | |
---|
1822 | Bool bSkipChroma = false; |
---|
1823 | Bool bChromaSame = false; |
---|
1824 | if( !bLumaOnly && uiLog2TrSize == 2 ) |
---|
1825 | { |
---|
1826 | assert( uiTrDepth > 0 ); |
---|
1827 | UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrDepth - 1 ) << 1 ); |
---|
1828 | bSkipChroma = ( ( uiAbsPartIdx % uiQPDiv ) != 0 ); |
---|
1829 | bChromaSame = true; |
---|
1830 | } |
---|
1831 | |
---|
1832 | //===== copy transform coefficients ===== |
---|
1833 | UInt uiNumCoeffY = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( uiFullDepth << 1 ); |
---|
1834 | UInt uiNumCoeffIncY = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ); |
---|
1835 | TCoeff* pcCoeffSrcY = m_ppcQTTempCoeffY [ uiQTLayer ] + ( uiNumCoeffIncY * uiAbsPartIdx ); |
---|
1836 | TCoeff* pcCoeffDstY = m_pcQTTempTUCoeffY; |
---|
1837 | |
---|
1838 | ::memcpy( pcCoeffDstY, pcCoeffSrcY, sizeof( TCoeff ) * uiNumCoeffY ); |
---|
1839 | #if ADAPTIVE_QP_SELECTION |
---|
1840 | Int* pcArlCoeffSrcY = m_ppcQTTempArlCoeffY [ uiQTLayer ] + ( uiNumCoeffIncY * uiAbsPartIdx ); |
---|
1841 | Int* pcArlCoeffDstY = m_ppcQTTempTUArlCoeffY; |
---|
1842 | ::memcpy( pcArlCoeffDstY, pcArlCoeffSrcY, sizeof( Int ) * uiNumCoeffY ); |
---|
1843 | #endif |
---|
1844 | if( !bLumaOnly && !bSkipChroma ) |
---|
1845 | { |
---|
1846 | UInt uiNumCoeffC = ( bChromaSame ? uiNumCoeffY : uiNumCoeffY >> 2 ); |
---|
1847 | UInt uiNumCoeffIncC = uiNumCoeffIncY >> 2; |
---|
1848 | TCoeff* pcCoeffSrcU = m_ppcQTTempCoeffCb[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
1849 | TCoeff* pcCoeffSrcV = m_ppcQTTempCoeffCr[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
1850 | TCoeff* pcCoeffDstU = m_pcQTTempTUCoeffCb; |
---|
1851 | TCoeff* pcCoeffDstV = m_pcQTTempTUCoeffCr; |
---|
1852 | ::memcpy( pcCoeffDstU, pcCoeffSrcU, sizeof( TCoeff ) * uiNumCoeffC ); |
---|
1853 | ::memcpy( pcCoeffDstV, pcCoeffSrcV, sizeof( TCoeff ) * uiNumCoeffC ); |
---|
1854 | #if ADAPTIVE_QP_SELECTION |
---|
1855 | Int* pcArlCoeffSrcU = m_ppcQTTempArlCoeffCb[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
1856 | Int* pcArlCoeffSrcV = m_ppcQTTempArlCoeffCr[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
1857 | Int* pcArlCoeffDstU = m_ppcQTTempTUArlCoeffCb; |
---|
1858 | Int* pcArlCoeffDstV = m_ppcQTTempTUArlCoeffCr; |
---|
1859 | ::memcpy( pcArlCoeffDstU, pcArlCoeffSrcU, sizeof( Int ) * uiNumCoeffC ); |
---|
1860 | ::memcpy( pcArlCoeffDstV, pcArlCoeffSrcV, sizeof( Int ) * uiNumCoeffC ); |
---|
1861 | #endif |
---|
1862 | } |
---|
1863 | |
---|
1864 | //===== copy reconstruction ===== |
---|
1865 | m_pcQTTempTComYuv[ uiQTLayer ].copyPartToPartLuma( &m_pcQTTempTransformSkipTComYuv, uiAbsPartIdx, 1 << uiLog2TrSize, 1 << uiLog2TrSize ); |
---|
1866 | |
---|
1867 | if( !bLumaOnly && !bSkipChroma ) |
---|
1868 | { |
---|
1869 | UInt uiLog2TrSizeChroma = ( bChromaSame ? uiLog2TrSize : uiLog2TrSize - 1 ); |
---|
1870 | m_pcQTTempTComYuv[ uiQTLayer ].copyPartToPartChroma( &m_pcQTTempTransformSkipTComYuv, uiAbsPartIdx, 1 << uiLog2TrSizeChroma, 1 << uiLog2TrSizeChroma ); |
---|
1871 | } |
---|
1872 | } |
---|
1873 | |
---|
1874 | Void |
---|
1875 | TEncSearch::xLoadIntraResultQT( TComDataCU* pcCU, |
---|
1876 | UInt uiTrDepth, |
---|
1877 | UInt uiAbsPartIdx, |
---|
1878 | Bool bLumaOnly ) |
---|
1879 | { |
---|
1880 | UInt uiFullDepth = pcCU->getDepth(0) + uiTrDepth; |
---|
1881 | UInt uiTrMode = pcCU->getTransformIdx( uiAbsPartIdx ); |
---|
1882 | assert( uiTrMode == uiTrDepth ); |
---|
1883 | UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2; |
---|
1884 | UInt uiQTLayer = pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() - uiLog2TrSize; |
---|
1885 | |
---|
1886 | Bool bSkipChroma = false; |
---|
1887 | Bool bChromaSame = false; |
---|
1888 | if( !bLumaOnly && uiLog2TrSize == 2 ) |
---|
1889 | { |
---|
1890 | assert( uiTrDepth > 0 ); |
---|
1891 | UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrDepth - 1 ) << 1 ); |
---|
1892 | bSkipChroma = ( ( uiAbsPartIdx % uiQPDiv ) != 0 ); |
---|
1893 | bChromaSame = true; |
---|
1894 | } |
---|
1895 | |
---|
1896 | //===== copy transform coefficients ===== |
---|
1897 | UInt uiNumCoeffY = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( uiFullDepth << 1 ); |
---|
1898 | UInt uiNumCoeffIncY = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ); |
---|
1899 | TCoeff* pcCoeffDstY = m_ppcQTTempCoeffY [ uiQTLayer ] + ( uiNumCoeffIncY * uiAbsPartIdx ); |
---|
1900 | TCoeff* pcCoeffSrcY = m_pcQTTempTUCoeffY; |
---|
1901 | |
---|
1902 | ::memcpy( pcCoeffDstY, pcCoeffSrcY, sizeof( TCoeff ) * uiNumCoeffY ); |
---|
1903 | #if ADAPTIVE_QP_SELECTION |
---|
1904 | Int* pcArlCoeffDstY = m_ppcQTTempArlCoeffY [ uiQTLayer ] + ( uiNumCoeffIncY * uiAbsPartIdx ); |
---|
1905 | Int* pcArlCoeffSrcY = m_ppcQTTempTUArlCoeffY; |
---|
1906 | ::memcpy( pcArlCoeffDstY, pcArlCoeffSrcY, sizeof( Int ) * uiNumCoeffY ); |
---|
1907 | #endif |
---|
1908 | if( !bLumaOnly && !bSkipChroma ) |
---|
1909 | { |
---|
1910 | UInt uiNumCoeffC = ( bChromaSame ? uiNumCoeffY : uiNumCoeffY >> 2 ); |
---|
1911 | UInt uiNumCoeffIncC = uiNumCoeffIncY >> 2; |
---|
1912 | TCoeff* pcCoeffDstU = m_ppcQTTempCoeffCb[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
1913 | TCoeff* pcCoeffDstV = m_ppcQTTempCoeffCr[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
1914 | TCoeff* pcCoeffSrcU = m_pcQTTempTUCoeffCb; |
---|
1915 | TCoeff* pcCoeffSrcV = m_pcQTTempTUCoeffCr; |
---|
1916 | ::memcpy( pcCoeffDstU, pcCoeffSrcU, sizeof( TCoeff ) * uiNumCoeffC ); |
---|
1917 | ::memcpy( pcCoeffDstV, pcCoeffSrcV, sizeof( TCoeff ) * uiNumCoeffC ); |
---|
1918 | #if ADAPTIVE_QP_SELECTION |
---|
1919 | Int* pcArlCoeffDstU = m_ppcQTTempArlCoeffCb[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
1920 | Int* pcArlCoeffDstV = m_ppcQTTempArlCoeffCr[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
1921 | Int* pcArlCoeffSrcU = m_ppcQTTempTUArlCoeffCb; |
---|
1922 | Int* pcArlCoeffSrcV = m_ppcQTTempTUArlCoeffCr; |
---|
1923 | ::memcpy( pcArlCoeffDstU, pcArlCoeffSrcU, sizeof( Int ) * uiNumCoeffC ); |
---|
1924 | ::memcpy( pcArlCoeffDstV, pcArlCoeffSrcV, sizeof( Int ) * uiNumCoeffC ); |
---|
1925 | #endif |
---|
1926 | } |
---|
1927 | |
---|
1928 | //===== copy reconstruction ===== |
---|
1929 | m_pcQTTempTransformSkipTComYuv.copyPartToPartLuma( &m_pcQTTempTComYuv[ uiQTLayer ] , uiAbsPartIdx, 1 << uiLog2TrSize, 1 << uiLog2TrSize ); |
---|
1930 | |
---|
1931 | if( !bLumaOnly && !bSkipChroma ) |
---|
1932 | { |
---|
1933 | UInt uiLog2TrSizeChroma = ( bChromaSame ? uiLog2TrSize : uiLog2TrSize - 1 ); |
---|
1934 | m_pcQTTempTransformSkipTComYuv.copyPartToPartChroma( &m_pcQTTempTComYuv[ uiQTLayer ], uiAbsPartIdx, 1 << uiLog2TrSizeChroma, 1 << uiLog2TrSizeChroma ); |
---|
1935 | } |
---|
1936 | |
---|
1937 | UInt uiZOrder = pcCU->getZorderIdxInCU() + uiAbsPartIdx; |
---|
1938 | Pel* piRecIPred = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder ); |
---|
1939 | UInt uiRecIPredStride = pcCU->getPic()->getPicYuvRec()->getStride (); |
---|
1940 | Pel* piRecQt = m_pcQTTempTComYuv[ uiQTLayer ].getLumaAddr( uiAbsPartIdx ); |
---|
1941 | UInt uiRecQtStride = m_pcQTTempTComYuv[ uiQTLayer ].getStride (); |
---|
1942 | UInt uiWidth = pcCU ->getWidth ( 0 ) >> uiTrDepth; |
---|
1943 | UInt uiHeight = pcCU ->getHeight ( 0 ) >> uiTrDepth; |
---|
1944 | Pel* pRecQt = piRecQt; |
---|
1945 | Pel* pRecIPred = piRecIPred; |
---|
1946 | for( UInt uiY = 0; uiY < uiHeight; uiY++ ) |
---|
1947 | { |
---|
1948 | for( UInt uiX = 0; uiX < uiWidth; uiX++ ) |
---|
1949 | { |
---|
1950 | pRecIPred[ uiX ] = pRecQt [ uiX ]; |
---|
1951 | } |
---|
1952 | pRecQt += uiRecQtStride; |
---|
1953 | pRecIPred += uiRecIPredStride; |
---|
1954 | } |
---|
1955 | |
---|
1956 | if( !bLumaOnly && !bSkipChroma ) |
---|
1957 | { |
---|
1958 | piRecIPred = pcCU->getPic()->getPicYuvRec()->getCbAddr( pcCU->getAddr(), uiZOrder ); |
---|
1959 | piRecQt = m_pcQTTempTComYuv[ uiQTLayer ].getCbAddr( uiAbsPartIdx ); |
---|
1960 | pRecQt = piRecQt; |
---|
1961 | pRecIPred = piRecIPred; |
---|
1962 | for( UInt uiY = 0; uiY < uiHeight; uiY++ ) |
---|
1963 | { |
---|
1964 | for( UInt uiX = 0; uiX < uiWidth; uiX++ ) |
---|
1965 | { |
---|
1966 | pRecIPred[ uiX ] = pRecQt[ uiX ]; |
---|
1967 | } |
---|
1968 | pRecQt += uiRecQtStride; |
---|
1969 | pRecIPred += uiRecIPredStride; |
---|
1970 | } |
---|
1971 | |
---|
1972 | piRecIPred = pcCU->getPic()->getPicYuvRec()->getCrAddr( pcCU->getAddr(), uiZOrder ); |
---|
1973 | piRecQt = m_pcQTTempTComYuv[ uiQTLayer ].getCrAddr( uiAbsPartIdx ); |
---|
1974 | pRecQt = piRecQt; |
---|
1975 | pRecIPred = piRecIPred; |
---|
1976 | for( UInt uiY = 0; uiY < uiHeight; uiY++ ) |
---|
1977 | { |
---|
1978 | for( UInt uiX = 0; uiX < uiWidth; uiX++ ) |
---|
1979 | { |
---|
1980 | pRecIPred[ uiX ] = pRecQt[ uiX ]; |
---|
1981 | } |
---|
1982 | pRecQt += uiRecQtStride; |
---|
1983 | pRecIPred += uiRecIPredStride; |
---|
1984 | } |
---|
1985 | } |
---|
1986 | } |
---|
1987 | |
---|
1988 | Void |
---|
1989 | TEncSearch::xStoreIntraResultChromaQT( TComDataCU* pcCU, |
---|
1990 | UInt uiTrDepth, |
---|
1991 | UInt uiAbsPartIdx, |
---|
1992 | UInt stateU0V1Both2 ) |
---|
1993 | { |
---|
1994 | UInt uiFullDepth = pcCU->getDepth(0) + uiTrDepth; |
---|
1995 | UInt uiTrMode = pcCU->getTransformIdx( uiAbsPartIdx ); |
---|
1996 | if( uiTrMode == uiTrDepth ) |
---|
1997 | { |
---|
1998 | UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2; |
---|
1999 | UInt uiQTLayer = pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() - uiLog2TrSize; |
---|
2000 | |
---|
2001 | Bool bChromaSame = false; |
---|
2002 | if( uiLog2TrSize == 2 ) |
---|
2003 | { |
---|
2004 | assert( uiTrDepth > 0 ); |
---|
2005 | uiTrDepth --; |
---|
2006 | UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrDepth) << 1 ); |
---|
2007 | if( ( uiAbsPartIdx % uiQPDiv ) != 0 ) |
---|
2008 | { |
---|
2009 | return; |
---|
2010 | } |
---|
2011 | bChromaSame = true; |
---|
2012 | } |
---|
2013 | |
---|
2014 | //===== copy transform coefficients ===== |
---|
2015 | UInt uiNumCoeffC = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( uiFullDepth << 1 ); |
---|
2016 | if( !bChromaSame ) |
---|
2017 | { |
---|
2018 | uiNumCoeffC >>= 2; |
---|
2019 | } |
---|
2020 | UInt uiNumCoeffIncC = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ) + 2 ); |
---|
2021 | if(stateU0V1Both2 == 0 || stateU0V1Both2 == 2) |
---|
2022 | { |
---|
2023 | TCoeff* pcCoeffSrcU = m_ppcQTTempCoeffCb[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
2024 | TCoeff* pcCoeffDstU = m_pcQTTempTUCoeffCb; |
---|
2025 | ::memcpy( pcCoeffDstU, pcCoeffSrcU, sizeof( TCoeff ) * uiNumCoeffC ); |
---|
2026 | |
---|
2027 | #if ADAPTIVE_QP_SELECTION |
---|
2028 | Int* pcArlCoeffSrcU = m_ppcQTTempArlCoeffCb[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
2029 | Int* pcArlCoeffDstU = m_ppcQTTempTUArlCoeffCb; |
---|
2030 | ::memcpy( pcArlCoeffDstU, pcArlCoeffSrcU, sizeof( Int ) * uiNumCoeffC ); |
---|
2031 | #endif |
---|
2032 | } |
---|
2033 | if(stateU0V1Both2 == 1 || stateU0V1Both2 == 2) |
---|
2034 | { |
---|
2035 | TCoeff* pcCoeffSrcV = m_ppcQTTempCoeffCr[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
2036 | TCoeff* pcCoeffDstV = m_pcQTTempTUCoeffCr; |
---|
2037 | ::memcpy( pcCoeffDstV, pcCoeffSrcV, sizeof( TCoeff ) * uiNumCoeffC ); |
---|
2038 | #if ADAPTIVE_QP_SELECTION |
---|
2039 | Int* pcArlCoeffSrcV = m_ppcQTTempArlCoeffCr[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
2040 | Int* pcArlCoeffDstV = m_ppcQTTempTUArlCoeffCr; |
---|
2041 | ::memcpy( pcArlCoeffDstV, pcArlCoeffSrcV, sizeof( Int ) * uiNumCoeffC ); |
---|
2042 | #endif |
---|
2043 | } |
---|
2044 | |
---|
2045 | //===== copy reconstruction ===== |
---|
2046 | UInt uiLog2TrSizeChroma = ( bChromaSame ? uiLog2TrSize : uiLog2TrSize - 1 ); |
---|
2047 | m_pcQTTempTComYuv[ uiQTLayer ].copyPartToPartChroma(&m_pcQTTempTransformSkipTComYuv, uiAbsPartIdx, 1 << uiLog2TrSizeChroma, 1 << uiLog2TrSizeChroma, stateU0V1Both2 ); |
---|
2048 | } |
---|
2049 | } |
---|
2050 | |
---|
2051 | |
---|
2052 | Void |
---|
2053 | TEncSearch::xLoadIntraResultChromaQT( TComDataCU* pcCU, |
---|
2054 | UInt uiTrDepth, |
---|
2055 | UInt uiAbsPartIdx, |
---|
2056 | UInt stateU0V1Both2 ) |
---|
2057 | { |
---|
2058 | UInt uiFullDepth = pcCU->getDepth(0) + uiTrDepth; |
---|
2059 | UInt uiTrMode = pcCU->getTransformIdx( uiAbsPartIdx ); |
---|
2060 | if( uiTrMode == uiTrDepth ) |
---|
2061 | { |
---|
2062 | UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2; |
---|
2063 | UInt uiQTLayer = pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() - uiLog2TrSize; |
---|
2064 | |
---|
2065 | Bool bChromaSame = false; |
---|
2066 | if( uiLog2TrSize == 2 ) |
---|
2067 | { |
---|
2068 | assert( uiTrDepth > 0 ); |
---|
2069 | uiTrDepth --; |
---|
2070 | UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrDepth ) << 1 ); |
---|
2071 | if( ( uiAbsPartIdx % uiQPDiv ) != 0 ) |
---|
2072 | { |
---|
2073 | return; |
---|
2074 | } |
---|
2075 | bChromaSame = true; |
---|
2076 | } |
---|
2077 | |
---|
2078 | //===== copy transform coefficients ===== |
---|
2079 | UInt uiNumCoeffC = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( uiFullDepth << 1 ); |
---|
2080 | if( !bChromaSame ) |
---|
2081 | { |
---|
2082 | uiNumCoeffC >>= 2; |
---|
2083 | } |
---|
2084 | UInt uiNumCoeffIncC = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ) + 2 ); |
---|
2085 | |
---|
2086 | if(stateU0V1Both2 ==0 || stateU0V1Both2 == 2) |
---|
2087 | { |
---|
2088 | TCoeff* pcCoeffDstU = m_ppcQTTempCoeffCb[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
2089 | TCoeff* pcCoeffSrcU = m_pcQTTempTUCoeffCb; |
---|
2090 | ::memcpy( pcCoeffDstU, pcCoeffSrcU, sizeof( TCoeff ) * uiNumCoeffC ); |
---|
2091 | #if ADAPTIVE_QP_SELECTION |
---|
2092 | Int* pcArlCoeffDstU = m_ppcQTTempArlCoeffCb[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
2093 | Int* pcArlCoeffSrcU = m_ppcQTTempTUArlCoeffCb; |
---|
2094 | ::memcpy( pcArlCoeffDstU, pcArlCoeffSrcU, sizeof( Int ) * uiNumCoeffC ); |
---|
2095 | #endif |
---|
2096 | } |
---|
2097 | if(stateU0V1Both2 ==1 || stateU0V1Both2 == 2) |
---|
2098 | { |
---|
2099 | TCoeff* pcCoeffDstV = m_ppcQTTempCoeffCr[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
2100 | TCoeff* pcCoeffSrcV = m_pcQTTempTUCoeffCr; |
---|
2101 | ::memcpy( pcCoeffDstV, pcCoeffSrcV, sizeof( TCoeff ) * uiNumCoeffC ); |
---|
2102 | #if ADAPTIVE_QP_SELECTION |
---|
2103 | Int* pcArlCoeffDstV = m_ppcQTTempArlCoeffCr[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
2104 | Int* pcArlCoeffSrcV = m_ppcQTTempTUArlCoeffCr; |
---|
2105 | ::memcpy( pcArlCoeffDstV, pcArlCoeffSrcV, sizeof( Int ) * uiNumCoeffC ); |
---|
2106 | #endif |
---|
2107 | } |
---|
2108 | |
---|
2109 | //===== copy reconstruction ===== |
---|
2110 | UInt uiLog2TrSizeChroma = ( bChromaSame ? uiLog2TrSize : uiLog2TrSize - 1 ); |
---|
2111 | m_pcQTTempTransformSkipTComYuv.copyPartToPartChroma( &m_pcQTTempTComYuv[ uiQTLayer ], uiAbsPartIdx, 1 << uiLog2TrSizeChroma, 1 << uiLog2TrSizeChroma, stateU0V1Both2); |
---|
2112 | |
---|
2113 | UInt uiZOrder = pcCU->getZorderIdxInCU() + uiAbsPartIdx; |
---|
2114 | UInt uiWidth = pcCU->getWidth ( 0 ) >> (uiTrDepth + 1); |
---|
2115 | UInt uiHeight = pcCU->getHeight ( 0 ) >> (uiTrDepth + 1); |
---|
2116 | UInt uiRecQtStride = m_pcQTTempTComYuv[ uiQTLayer ].getCStride (); |
---|
2117 | UInt uiRecIPredStride = pcCU->getPic()->getPicYuvRec()->getCStride (); |
---|
2118 | |
---|
2119 | if(stateU0V1Both2 ==0 || stateU0V1Both2 == 2) |
---|
2120 | { |
---|
2121 | Pel* piRecIPred = pcCU->getPic()->getPicYuvRec()->getCbAddr( pcCU->getAddr(), uiZOrder ); |
---|
2122 | Pel* piRecQt = m_pcQTTempTComYuv[ uiQTLayer ].getCbAddr( uiAbsPartIdx ); |
---|
2123 | Pel* pRecQt = piRecQt; |
---|
2124 | Pel* pRecIPred = piRecIPred; |
---|
2125 | for( UInt uiY = 0; uiY < uiHeight; uiY++ ) |
---|
2126 | { |
---|
2127 | for( UInt uiX = 0; uiX < uiWidth; uiX++ ) |
---|
2128 | { |
---|
2129 | pRecIPred[ uiX ] = pRecQt[ uiX ]; |
---|
2130 | } |
---|
2131 | pRecQt += uiRecQtStride; |
---|
2132 | pRecIPred += uiRecIPredStride; |
---|
2133 | } |
---|
2134 | } |
---|
2135 | if(stateU0V1Both2 == 1 || stateU0V1Both2 == 2) |
---|
2136 | { |
---|
2137 | Pel* piRecIPred = pcCU->getPic()->getPicYuvRec()->getCrAddr( pcCU->getAddr(), uiZOrder ); |
---|
2138 | Pel* piRecQt = m_pcQTTempTComYuv[ uiQTLayer ].getCrAddr( uiAbsPartIdx ); |
---|
2139 | Pel* pRecQt = piRecQt; |
---|
2140 | Pel* pRecIPred = piRecIPred; |
---|
2141 | for( UInt uiY = 0; uiY < uiHeight; uiY++ ) |
---|
2142 | { |
---|
2143 | for( UInt uiX = 0; uiX < uiWidth; uiX++ ) |
---|
2144 | { |
---|
2145 | pRecIPred[ uiX ] = pRecQt[ uiX ]; |
---|
2146 | } |
---|
2147 | pRecQt += uiRecQtStride; |
---|
2148 | pRecIPred += uiRecIPredStride; |
---|
2149 | } |
---|
2150 | } |
---|
2151 | } |
---|
2152 | } |
---|
2153 | |
---|
2154 | Void |
---|
2155 | TEncSearch::xRecurIntraChromaCodingQT( TComDataCU* pcCU, |
---|
2156 | UInt uiTrDepth, |
---|
2157 | UInt uiAbsPartIdx, |
---|
2158 | TComYuv* pcOrgYuv, |
---|
2159 | TComYuv* pcPredYuv, |
---|
2160 | TComYuv* pcResiYuv, |
---|
2161 | UInt& ruiDist ) |
---|
2162 | { |
---|
2163 | UInt uiFullDepth = pcCU->getDepth( 0 ) + uiTrDepth; |
---|
2164 | UInt uiTrMode = pcCU->getTransformIdx( uiAbsPartIdx ); |
---|
2165 | if( uiTrMode == uiTrDepth ) |
---|
2166 | { |
---|
2167 | Bool checkTransformSkip = pcCU->getSlice()->getPPS()->getUseTransformSkip(); |
---|
2168 | UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2; |
---|
2169 | |
---|
2170 | UInt actualTrDepth = uiTrDepth; |
---|
2171 | if( uiLog2TrSize == 2 ) |
---|
2172 | { |
---|
2173 | assert( uiTrDepth > 0 ); |
---|
2174 | actualTrDepth--; |
---|
2175 | UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + actualTrDepth) << 1 ); |
---|
2176 | Bool bFirstQ = ( ( uiAbsPartIdx % uiQPDiv ) == 0 ); |
---|
2177 | if( !bFirstQ ) |
---|
2178 | { |
---|
2179 | return; |
---|
2180 | } |
---|
2181 | } |
---|
2182 | |
---|
2183 | checkTransformSkip &= (uiLog2TrSize <= 3); |
---|
2184 | if ( m_pcEncCfg->getUseTransformSkipFast() ) |
---|
2185 | { |
---|
2186 | checkTransformSkip &= (uiLog2TrSize < 3); |
---|
2187 | if (checkTransformSkip) |
---|
2188 | { |
---|
2189 | Int nbLumaSkip = 0; |
---|
2190 | for(UInt absPartIdxSub = uiAbsPartIdx; absPartIdxSub < uiAbsPartIdx + 4; absPartIdxSub ++) |
---|
2191 | { |
---|
2192 | nbLumaSkip += pcCU->getTransformSkip(absPartIdxSub, TEXT_LUMA); |
---|
2193 | } |
---|
2194 | checkTransformSkip &= (nbLumaSkip > 0); |
---|
2195 | } |
---|
2196 | } |
---|
2197 | |
---|
2198 | if(checkTransformSkip) |
---|
2199 | { |
---|
2200 | //use RDO to decide whether Cr/Cb takes TS |
---|
2201 | if( m_bUseSBACRD ) |
---|
2202 | { |
---|
2203 | m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[uiFullDepth][CI_QT_TRAFO_ROOT] ); |
---|
2204 | } |
---|
2205 | |
---|
2206 | for(Int chromaId = 0; chromaId < 2; chromaId ++) |
---|
2207 | { |
---|
2208 | Double dSingleCost = MAX_DOUBLE; |
---|
2209 | Int bestModeId = 0; |
---|
2210 | UInt singleDistC = 0; |
---|
2211 | UInt singleCbfC = 0; |
---|
2212 | UInt singleDistCTmp = 0; |
---|
2213 | Double singleCostTmp = 0; |
---|
2214 | UInt singleCbfCTmp = 0; |
---|
2215 | |
---|
2216 | Int default0Save1Load2 = 0; |
---|
2217 | Int firstCheckId = 0; |
---|
2218 | |
---|
2219 | for(Int chromaModeId = firstCheckId; chromaModeId < 2; chromaModeId ++) |
---|
2220 | { |
---|
2221 | pcCU->setTransformSkipSubParts ( chromaModeId, (TextType)(chromaId + 2), uiAbsPartIdx, pcCU->getDepth( 0 ) + actualTrDepth); |
---|
2222 | if(chromaModeId == firstCheckId) |
---|
2223 | { |
---|
2224 | default0Save1Load2 = 1; |
---|
2225 | } |
---|
2226 | else |
---|
2227 | { |
---|
2228 | default0Save1Load2 = 2; |
---|
2229 | } |
---|
2230 | singleDistCTmp = 0; |
---|
2231 | xIntraCodingChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcOrgYuv, pcPredYuv, pcResiYuv, singleDistCTmp, chromaId ,default0Save1Load2); |
---|
2232 | singleCbfCTmp = pcCU->getCbf( uiAbsPartIdx, (TextType)(chromaId + 2), uiTrDepth); |
---|
2233 | |
---|
2234 | if(chromaModeId == 1 && singleCbfCTmp == 0) |
---|
2235 | { |
---|
2236 | //In order not to code TS flag when cbf is zero, the case for TS with cbf being zero is forbidden. |
---|
2237 | singleCostTmp = MAX_DOUBLE; |
---|
2238 | } |
---|
2239 | else |
---|
2240 | { |
---|
2241 | UInt bitsTmp = xGetIntraBitsQTChroma( pcCU,uiTrDepth, uiAbsPartIdx,chromaId + 2, false ); |
---|
2242 | singleCostTmp = m_pcRdCost->calcRdCost( bitsTmp, singleDistCTmp); |
---|
2243 | } |
---|
2244 | |
---|
2245 | if(singleCostTmp < dSingleCost) |
---|
2246 | { |
---|
2247 | dSingleCost = singleCostTmp; |
---|
2248 | singleDistC = singleDistCTmp; |
---|
2249 | bestModeId = chromaModeId; |
---|
2250 | singleCbfC = singleCbfCTmp; |
---|
2251 | |
---|
2252 | if(bestModeId == firstCheckId) |
---|
2253 | { |
---|
2254 | xStoreIntraResultChromaQT(pcCU, uiTrDepth, uiAbsPartIdx,chromaId); |
---|
2255 | if( m_bUseSBACRD) |
---|
2256 | { |
---|
2257 | m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] ); |
---|
2258 | } |
---|
2259 | } |
---|
2260 | } |
---|
2261 | if(chromaModeId == firstCheckId) |
---|
2262 | { |
---|
2263 | m_pcRDGoOnSbacCoder->load ( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] ); |
---|
2264 | } |
---|
2265 | } |
---|
2266 | |
---|
2267 | if(bestModeId == firstCheckId) |
---|
2268 | { |
---|
2269 | xLoadIntraResultChromaQT(pcCU, uiTrDepth, uiAbsPartIdx,chromaId); |
---|
2270 | pcCU->setCbfSubParts ( singleCbfC << uiTrDepth, (TextType)(chromaId + 2), uiAbsPartIdx, pcCU->getDepth(0) + actualTrDepth ); |
---|
2271 | if(m_bUseSBACRD) |
---|
2272 | { |
---|
2273 | m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] ); |
---|
2274 | } |
---|
2275 | } |
---|
2276 | pcCU ->setTransformSkipSubParts( bestModeId, (TextType)(chromaId + 2), uiAbsPartIdx, pcCU->getDepth( 0 ) + actualTrDepth ); |
---|
2277 | ruiDist += singleDistC; |
---|
2278 | |
---|
2279 | if(chromaId == 0) |
---|
2280 | { |
---|
2281 | if( m_bUseSBACRD ) |
---|
2282 | { |
---|
2283 | m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[uiFullDepth][CI_QT_TRAFO_ROOT] ); |
---|
2284 | } |
---|
2285 | } |
---|
2286 | } |
---|
2287 | } |
---|
2288 | else |
---|
2289 | { |
---|
2290 | pcCU ->setTransformSkipSubParts( 0, TEXT_CHROMA_U, uiAbsPartIdx, pcCU->getDepth( 0 ) + actualTrDepth ); |
---|
2291 | pcCU ->setTransformSkipSubParts( 0, TEXT_CHROMA_V, uiAbsPartIdx, pcCU->getDepth( 0 ) + actualTrDepth ); |
---|
2292 | xIntraCodingChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcOrgYuv, pcPredYuv, pcResiYuv, ruiDist, 0 ); |
---|
2293 | xIntraCodingChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcOrgYuv, pcPredYuv, pcResiYuv, ruiDist, 1 ); |
---|
2294 | } |
---|
2295 | } |
---|
2296 | else |
---|
2297 | { |
---|
2298 | UInt uiSplitCbfU = 0; |
---|
2299 | UInt uiSplitCbfV = 0; |
---|
2300 | UInt uiQPartsDiv = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 ); |
---|
2301 | UInt uiAbsPartIdxSub = uiAbsPartIdx; |
---|
2302 | for( UInt uiPart = 0; uiPart < 4; uiPart++, uiAbsPartIdxSub += uiQPartsDiv ) |
---|
2303 | { |
---|
2304 | xRecurIntraChromaCodingQT( pcCU, uiTrDepth + 1, uiAbsPartIdxSub, pcOrgYuv, pcPredYuv, pcResiYuv, ruiDist ); |
---|
2305 | uiSplitCbfU |= pcCU->getCbf( uiAbsPartIdxSub, TEXT_CHROMA_U, uiTrDepth + 1 ); |
---|
2306 | uiSplitCbfV |= pcCU->getCbf( uiAbsPartIdxSub, TEXT_CHROMA_V, uiTrDepth + 1 ); |
---|
2307 | } |
---|
2308 | for( UInt uiOffs = 0; uiOffs < 4 * uiQPartsDiv; uiOffs++ ) |
---|
2309 | { |
---|
2310 | pcCU->getCbf( TEXT_CHROMA_U )[ uiAbsPartIdx + uiOffs ] |= ( uiSplitCbfU << uiTrDepth ); |
---|
2311 | pcCU->getCbf( TEXT_CHROMA_V )[ uiAbsPartIdx + uiOffs ] |= ( uiSplitCbfV << uiTrDepth ); |
---|
2312 | } |
---|
2313 | } |
---|
2314 | } |
---|
2315 | |
---|
2316 | Void |
---|
2317 | TEncSearch::xSetIntraResultChromaQT( TComDataCU* pcCU, |
---|
2318 | UInt uiTrDepth, |
---|
2319 | UInt uiAbsPartIdx, |
---|
2320 | TComYuv* pcRecoYuv ) |
---|
2321 | { |
---|
2322 | UInt uiFullDepth = pcCU->getDepth(0) + uiTrDepth; |
---|
2323 | UInt uiTrMode = pcCU->getTransformIdx( uiAbsPartIdx ); |
---|
2324 | if( uiTrMode == uiTrDepth ) |
---|
2325 | { |
---|
2326 | UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2; |
---|
2327 | UInt uiQTLayer = pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() - uiLog2TrSize; |
---|
2328 | |
---|
2329 | Bool bChromaSame = false; |
---|
2330 | if( uiLog2TrSize == 2 ) |
---|
2331 | { |
---|
2332 | assert( uiTrDepth > 0 ); |
---|
2333 | UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrDepth - 1 ) << 1 ); |
---|
2334 | if( ( uiAbsPartIdx % uiQPDiv ) != 0 ) |
---|
2335 | { |
---|
2336 | return; |
---|
2337 | } |
---|
2338 | bChromaSame = true; |
---|
2339 | } |
---|
2340 | |
---|
2341 | //===== copy transform coefficients ===== |
---|
2342 | UInt uiNumCoeffC = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( uiFullDepth << 1 ); |
---|
2343 | if( !bChromaSame ) |
---|
2344 | { |
---|
2345 | uiNumCoeffC >>= 2; |
---|
2346 | } |
---|
2347 | UInt uiNumCoeffIncC = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ) + 2 ); |
---|
2348 | TCoeff* pcCoeffSrcU = m_ppcQTTempCoeffCb[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
2349 | TCoeff* pcCoeffSrcV = m_ppcQTTempCoeffCr[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
2350 | TCoeff* pcCoeffDstU = pcCU->getCoeffCb() + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
2351 | TCoeff* pcCoeffDstV = pcCU->getCoeffCr() + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
2352 | ::memcpy( pcCoeffDstU, pcCoeffSrcU, sizeof( TCoeff ) * uiNumCoeffC ); |
---|
2353 | ::memcpy( pcCoeffDstV, pcCoeffSrcV, sizeof( TCoeff ) * uiNumCoeffC ); |
---|
2354 | #if ADAPTIVE_QP_SELECTION |
---|
2355 | Int* pcArlCoeffSrcU = m_ppcQTTempArlCoeffCb[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
2356 | Int* pcArlCoeffSrcV = m_ppcQTTempArlCoeffCr[ uiQTLayer ] + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
2357 | Int* pcArlCoeffDstU = pcCU->getArlCoeffCb() + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
2358 | Int* pcArlCoeffDstV = pcCU->getArlCoeffCr() + ( uiNumCoeffIncC * uiAbsPartIdx ); |
---|
2359 | ::memcpy( pcArlCoeffDstU, pcArlCoeffSrcU, sizeof( Int ) * uiNumCoeffC ); |
---|
2360 | ::memcpy( pcArlCoeffDstV, pcArlCoeffSrcV, sizeof( Int ) * uiNumCoeffC ); |
---|
2361 | #endif |
---|
2362 | |
---|
2363 | //===== copy reconstruction ===== |
---|
2364 | UInt uiLog2TrSizeChroma = ( bChromaSame ? uiLog2TrSize : uiLog2TrSize - 1 ); |
---|
2365 | m_pcQTTempTComYuv[ uiQTLayer ].copyPartToPartChroma( pcRecoYuv, uiAbsPartIdx, 1 << uiLog2TrSizeChroma, 1 << uiLog2TrSizeChroma ); |
---|
2366 | } |
---|
2367 | else |
---|
2368 | { |
---|
2369 | UInt uiNumQPart = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 ); |
---|
2370 | for( UInt uiPart = 0; uiPart < 4; uiPart++ ) |
---|
2371 | { |
---|
2372 | xSetIntraResultChromaQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv ); |
---|
2373 | } |
---|
2374 | } |
---|
2375 | } |
---|
2376 | |
---|
2377 | |
---|
2378 | Void |
---|
2379 | TEncSearch::preestChromaPredMode( TComDataCU* pcCU, |
---|
2380 | TComYuv* pcOrgYuv, |
---|
2381 | TComYuv* pcPredYuv ) |
---|
2382 | { |
---|
2383 | UInt uiWidth = pcCU->getWidth ( 0 ) >> 1; |
---|
2384 | UInt uiHeight = pcCU->getHeight( 0 ) >> 1; |
---|
2385 | UInt uiStride = pcOrgYuv ->getCStride(); |
---|
2386 | Pel* piOrgU = pcOrgYuv ->getCbAddr ( 0 ); |
---|
2387 | Pel* piOrgV = pcOrgYuv ->getCrAddr ( 0 ); |
---|
2388 | Pel* piPredU = pcPredYuv->getCbAddr ( 0 ); |
---|
2389 | Pel* piPredV = pcPredYuv->getCrAddr ( 0 ); |
---|
2390 | |
---|
2391 | //===== init pattern ===== |
---|
2392 | Bool bAboveAvail = false; |
---|
2393 | Bool bLeftAvail = false; |
---|
2394 | pcCU->getPattern()->initPattern ( pcCU, 0, 0 ); |
---|
2395 | pcCU->getPattern()->initAdiPatternChroma( pcCU, 0, 0, m_piYuvExt, m_iYuvExtStride, m_iYuvExtHeight, bAboveAvail, bLeftAvail ); |
---|
2396 | Int* pPatChromaU = pcCU->getPattern()->getAdiCbBuf( uiWidth, uiHeight, m_piYuvExt ); |
---|
2397 | Int* pPatChromaV = pcCU->getPattern()->getAdiCrBuf( uiWidth, uiHeight, m_piYuvExt ); |
---|
2398 | |
---|
2399 | //===== get best prediction modes (using SAD) ===== |
---|
2400 | UInt uiMinMode = 0; |
---|
2401 | UInt uiMaxMode = 4; |
---|
2402 | UInt uiBestMode = MAX_UINT; |
---|
2403 | UInt uiMinSAD = MAX_UINT; |
---|
2404 | for( UInt uiMode = uiMinMode; uiMode < uiMaxMode; uiMode++ ) |
---|
2405 | { |
---|
2406 | //--- get prediction --- |
---|
2407 | predIntraChromaAng( pPatChromaU, uiMode, piPredU, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail ); |
---|
2408 | predIntraChromaAng( pPatChromaV, uiMode, piPredV, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail ); |
---|
2409 | |
---|
2410 | //--- get SAD --- |
---|
2411 | UInt uiSAD = m_pcRdCost->calcHAD(g_bitDepthC, piOrgU, uiStride, piPredU, uiStride, uiWidth, uiHeight ); |
---|
2412 | uiSAD += m_pcRdCost->calcHAD(g_bitDepthC, piOrgV, uiStride, piPredV, uiStride, uiWidth, uiHeight ); |
---|
2413 | //--- check --- |
---|
2414 | if( uiSAD < uiMinSAD ) |
---|
2415 | { |
---|
2416 | uiMinSAD = uiSAD; |
---|
2417 | uiBestMode = uiMode; |
---|
2418 | } |
---|
2419 | } |
---|
2420 | |
---|
2421 | //===== set chroma pred mode ===== |
---|
2422 | pcCU->setChromIntraDirSubParts( uiBestMode, 0, pcCU->getDepth( 0 ) ); |
---|
2423 | } |
---|
2424 | |
---|
2425 | Void |
---|
2426 | TEncSearch::estIntraPredQT( TComDataCU* pcCU, |
---|
2427 | TComYuv* pcOrgYuv, |
---|
2428 | TComYuv* pcPredYuv, |
---|
2429 | TComYuv* pcResiYuv, |
---|
2430 | TComYuv* pcRecoYuv, |
---|
2431 | UInt& ruiDistC, |
---|
2432 | Bool bLumaOnly ) |
---|
2433 | { |
---|
2434 | UInt uiDepth = pcCU->getDepth(0); |
---|
2435 | UInt uiNumPU = pcCU->getNumPartInter(); |
---|
2436 | UInt uiInitTrDepth = pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1; |
---|
2437 | UInt uiWidth = pcCU->getWidth (0) >> uiInitTrDepth; |
---|
2438 | UInt uiHeight = pcCU->getHeight(0) >> uiInitTrDepth; |
---|
2439 | UInt uiQNumParts = pcCU->getTotalNumPart() >> 2; |
---|
2440 | UInt uiWidthBit = pcCU->getIntraSizeIdx(0); |
---|
2441 | UInt uiOverallDistY = 0; |
---|
2442 | UInt uiOverallDistC = 0; |
---|
2443 | UInt CandNum; |
---|
2444 | Double CandCostList[ FAST_UDI_MAX_RDMODE_NUM ]; |
---|
2445 | |
---|
2446 | //===== set QP and clear Cbf ===== |
---|
2447 | if ( pcCU->getSlice()->getPPS()->getUseDQP() == true) |
---|
2448 | { |
---|
2449 | pcCU->setQPSubParts( pcCU->getQP(0), 0, uiDepth ); |
---|
2450 | } |
---|
2451 | else |
---|
2452 | { |
---|
2453 | pcCU->setQPSubParts( pcCU->getSlice()->getSliceQp(), 0, uiDepth ); |
---|
2454 | } |
---|
2455 | |
---|
2456 | //===== loop over partitions ===== |
---|
2457 | UInt uiPartOffset = 0; |
---|
2458 | for( UInt uiPU = 0; uiPU < uiNumPU; uiPU++, uiPartOffset += uiQNumParts ) |
---|
2459 | { |
---|
2460 | //===== init pattern for luma prediction ===== |
---|
2461 | Bool bAboveAvail = false; |
---|
2462 | Bool bLeftAvail = false; |
---|
2463 | pcCU->getPattern()->initPattern ( pcCU, uiInitTrDepth, uiPartOffset ); |
---|
2464 | pcCU->getPattern()->initAdiPattern( pcCU, uiPartOffset, uiInitTrDepth, m_piYuvExt, m_iYuvExtStride, m_iYuvExtHeight, bAboveAvail, bLeftAvail ); |
---|
2465 | |
---|
2466 | //===== determine set of modes to be tested (using prediction signal only) ===== |
---|
2467 | Int numModesAvailable = 35; //total number of Intra modes |
---|
2468 | Pel* piOrg = pcOrgYuv ->getLumaAddr( uiPU, uiWidth ); |
---|
2469 | Pel* piPred = pcPredYuv->getLumaAddr( uiPU, uiWidth ); |
---|
2470 | UInt uiStride = pcPredYuv->getStride(); |
---|
2471 | UInt uiRdModeList[FAST_UDI_MAX_RDMODE_NUM]; |
---|
2472 | Int numModesForFullRD = g_aucIntraModeNumFast[ uiWidthBit ]; |
---|
2473 | |
---|
2474 | Bool doFastSearch = (numModesForFullRD != numModesAvailable); |
---|
2475 | if (doFastSearch) |
---|
2476 | { |
---|
2477 | assert(numModesForFullRD < numModesAvailable); |
---|
2478 | #if FAST_INTRA_SHVC |
---|
2479 | Int uiPreds[3] = {-1, -1, -1}; |
---|
2480 | Int iMode = -1; |
---|
2481 | Bool skipFastHAD = false; |
---|
2482 | Int numCand = pcCU->getIntraDirLumaPredictor( uiPartOffset, uiPreds, &iMode ); |
---|
2483 | |
---|
2484 | if ( m_pcEncCfg->getUseFastIntraScalable() ) |
---|
2485 | { |
---|
2486 | if( pcCU->getLayerId() > 0 ) |
---|
2487 | { |
---|
2488 | numModesAvailable = pcCU->reduceSetOfIntraModes(uiPartOffset, uiPreds, iMode ); |
---|
2489 | if( numModesForFullRD > numModesAvailable ) //fast HAD can be skipped |
---|
2490 | { |
---|
2491 | skipFastHAD = true; |
---|
2492 | numModesForFullRD = numModesAvailable; |
---|
2493 | for( Int i=0; i < numModesForFullRD; i++ ) |
---|
2494 | uiRdModeList[ i ] = g_reducedSetIntraModes[ i ]; |
---|
2495 | } |
---|
2496 | } |
---|
2497 | } |
---|
2498 | #endif |
---|
2499 | |
---|
2500 | for( Int i=0; i < numModesForFullRD; i++ ) |
---|
2501 | { |
---|
2502 | CandCostList[ i ] = MAX_DOUBLE; |
---|
2503 | } |
---|
2504 | CandNum = 0; |
---|
2505 | |
---|
2506 | for( Int modeIdx = 0; modeIdx < numModesAvailable; modeIdx++ ) |
---|
2507 | { |
---|
2508 | UInt uiMode = modeIdx; |
---|
2509 | #if FAST_INTRA_SHVC |
---|
2510 | if ( m_pcEncCfg->getUseFastIntraScalable() ) |
---|
2511 | { |
---|
2512 | if( skipFastHAD )//indicates that fast HAD can be skipped |
---|
2513 | break; |
---|
2514 | uiMode = ( iMode==0 ) ? g_reducedSetIntraModes[modeIdx] : uiMode; //(iMode=0) indicates reduced set of modes |
---|
2515 | } |
---|
2516 | #endif |
---|
2517 | |
---|
2518 | predIntraLumaAng( pcCU->getPattern(), uiMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail ); |
---|
2519 | |
---|
2520 | // use hadamard transform here |
---|
2521 | UInt uiSad = m_pcRdCost->calcHAD(g_bitDepthY, piOrg, uiStride, piPred, uiStride, uiWidth, uiHeight ); |
---|
2522 | |
---|
2523 | UInt iModeBits = xModeBitsIntra( pcCU, uiMode, uiPU, uiPartOffset, uiDepth, uiInitTrDepth ); |
---|
2524 | Double cost = (Double)uiSad + (Double)iModeBits * m_pcRdCost->getSqrtLambda(); |
---|
2525 | |
---|
2526 | CandNum += xUpdateCandList( uiMode, cost, numModesForFullRD, uiRdModeList, CandCostList ); |
---|
2527 | } |
---|
2528 | |
---|
2529 | #if FAST_UDI_USE_MPM |
---|
2530 | #if FAST_INTRA_SHVC == 0 |
---|
2531 | Int uiPreds[3] = {-1, -1, -1}; |
---|
2532 | Int iMode = -1; |
---|
2533 | Int numCand = pcCU->getIntraDirLumaPredictor( uiPartOffset, uiPreds, &iMode ); |
---|
2534 | #endif |
---|
2535 | if( iMode >= 0 ) |
---|
2536 | { |
---|
2537 | numCand = iMode; |
---|
2538 | } |
---|
2539 | |
---|
2540 | for( Int j=0; j < numCand; j++) |
---|
2541 | |
---|
2542 | { |
---|
2543 | Bool mostProbableModeIncluded = false; |
---|
2544 | Int mostProbableMode = uiPreds[j]; |
---|
2545 | |
---|
2546 | for( Int i=0; i < numModesForFullRD; i++) |
---|
2547 | { |
---|
2548 | mostProbableModeIncluded |= (mostProbableMode == uiRdModeList[i]); |
---|
2549 | } |
---|
2550 | if (!mostProbableModeIncluded) |
---|
2551 | { |
---|
2552 | uiRdModeList[numModesForFullRD++] = mostProbableMode; |
---|
2553 | } |
---|
2554 | } |
---|
2555 | #endif // FAST_UDI_USE_MPM |
---|
2556 | } |
---|
2557 | else |
---|
2558 | { |
---|
2559 | for( Int i=0; i < numModesForFullRD; i++) |
---|
2560 | { |
---|
2561 | uiRdModeList[i] = i; |
---|
2562 | } |
---|
2563 | } |
---|
2564 | |
---|
2565 | //===== check modes (using r-d costs) ===== |
---|
2566 | #if HHI_RQT_INTRA_SPEEDUP_MOD |
---|
2567 | UInt uiSecondBestMode = MAX_UINT; |
---|
2568 | Double dSecondBestPUCost = MAX_DOUBLE; |
---|
2569 | #endif |
---|
2570 | |
---|
2571 | UInt uiBestPUMode = 0; |
---|
2572 | UInt uiBestPUDistY = 0; |
---|
2573 | UInt uiBestPUDistC = 0; |
---|
2574 | Double dBestPUCost = MAX_DOUBLE; |
---|
2575 | for( UInt uiMode = 0; uiMode < numModesForFullRD; uiMode++ ) |
---|
2576 | { |
---|
2577 | // set luma prediction mode |
---|
2578 | UInt uiOrgMode = uiRdModeList[uiMode]; |
---|
2579 | |
---|
2580 | pcCU->setLumaIntraDirSubParts ( uiOrgMode, uiPartOffset, uiDepth + uiInitTrDepth ); |
---|
2581 | |
---|
2582 | // set context models |
---|
2583 | if( m_bUseSBACRD ) |
---|
2584 | { |
---|
2585 | m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); |
---|
2586 | } |
---|
2587 | |
---|
2588 | // determine residual for partition |
---|
2589 | UInt uiPUDistY = 0; |
---|
2590 | UInt uiPUDistC = 0; |
---|
2591 | Double dPUCost = 0.0; |
---|
2592 | #if HHI_RQT_INTRA_SPEEDUP |
---|
2593 | xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, true, dPUCost ); |
---|
2594 | #else |
---|
2595 | xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, dPUCost ); |
---|
2596 | #endif |
---|
2597 | |
---|
2598 | // check r-d cost |
---|
2599 | if( dPUCost < dBestPUCost ) |
---|
2600 | { |
---|
2601 | #if HHI_RQT_INTRA_SPEEDUP_MOD |
---|
2602 | uiSecondBestMode = uiBestPUMode; |
---|
2603 | dSecondBestPUCost = dBestPUCost; |
---|
2604 | #endif |
---|
2605 | uiBestPUMode = uiOrgMode; |
---|
2606 | uiBestPUDistY = uiPUDistY; |
---|
2607 | uiBestPUDistC = uiPUDistC; |
---|
2608 | dBestPUCost = dPUCost; |
---|
2609 | |
---|
2610 | xSetIntraResultQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcRecoYuv ); |
---|
2611 | |
---|
2612 | UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth(0) + uiInitTrDepth ) << 1 ); |
---|
2613 | ::memcpy( m_puhQTTempTrIdx, pcCU->getTransformIdx() + uiPartOffset, uiQPartNum * sizeof( UChar ) ); |
---|
2614 | ::memcpy( m_puhQTTempCbf[0], pcCU->getCbf( TEXT_LUMA ) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); |
---|
2615 | ::memcpy( m_puhQTTempCbf[1], pcCU->getCbf( TEXT_CHROMA_U ) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); |
---|
2616 | ::memcpy( m_puhQTTempCbf[2], pcCU->getCbf( TEXT_CHROMA_V ) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); |
---|
2617 | ::memcpy( m_puhQTTempTransformSkipFlag[0], pcCU->getTransformSkip(TEXT_LUMA) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); |
---|
2618 | ::memcpy( m_puhQTTempTransformSkipFlag[1], pcCU->getTransformSkip(TEXT_CHROMA_U) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); |
---|
2619 | ::memcpy( m_puhQTTempTransformSkipFlag[2], pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); |
---|
2620 | } |
---|
2621 | #if HHI_RQT_INTRA_SPEEDUP_MOD |
---|
2622 | else if( dPUCost < dSecondBestPUCost ) |
---|
2623 | { |
---|
2624 | uiSecondBestMode = uiOrgMode; |
---|
2625 | dSecondBestPUCost = dPUCost; |
---|
2626 | } |
---|
2627 | #endif |
---|
2628 | } // Mode loop |
---|
2629 | |
---|
2630 | #if HHI_RQT_INTRA_SPEEDUP |
---|
2631 | #if HHI_RQT_INTRA_SPEEDUP_MOD |
---|
2632 | for( UInt ui =0; ui < 2; ++ui ) |
---|
2633 | #endif |
---|
2634 | { |
---|
2635 | #if HHI_RQT_INTRA_SPEEDUP_MOD |
---|
2636 | UInt uiOrgMode = ui ? uiSecondBestMode : uiBestPUMode; |
---|
2637 | if( uiOrgMode == MAX_UINT ) |
---|
2638 | { |
---|
2639 | break; |
---|
2640 | } |
---|
2641 | #else |
---|
2642 | UInt uiOrgMode = uiBestPUMode; |
---|
2643 | #endif |
---|
2644 | |
---|
2645 | pcCU->setLumaIntraDirSubParts ( uiOrgMode, uiPartOffset, uiDepth + uiInitTrDepth ); |
---|
2646 | |
---|
2647 | // set context models |
---|
2648 | if( m_bUseSBACRD ) |
---|
2649 | { |
---|
2650 | m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); |
---|
2651 | } |
---|
2652 | |
---|
2653 | // determine residual for partition |
---|
2654 | UInt uiPUDistY = 0; |
---|
2655 | UInt uiPUDistC = 0; |
---|
2656 | Double dPUCost = 0.0; |
---|
2657 | xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, false, dPUCost ); |
---|
2658 | |
---|
2659 | // check r-d cost |
---|
2660 | if( dPUCost < dBestPUCost ) |
---|
2661 | { |
---|
2662 | uiBestPUMode = uiOrgMode; |
---|
2663 | uiBestPUDistY = uiPUDistY; |
---|
2664 | uiBestPUDistC = uiPUDistC; |
---|
2665 | dBestPUCost = dPUCost; |
---|
2666 | |
---|
2667 | xSetIntraResultQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcRecoYuv ); |
---|
2668 | |
---|
2669 | UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth(0) + uiInitTrDepth ) << 1 ); |
---|
2670 | ::memcpy( m_puhQTTempTrIdx, pcCU->getTransformIdx() + uiPartOffset, uiQPartNum * sizeof( UChar ) ); |
---|
2671 | ::memcpy( m_puhQTTempCbf[0], pcCU->getCbf( TEXT_LUMA ) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); |
---|
2672 | ::memcpy( m_puhQTTempCbf[1], pcCU->getCbf( TEXT_CHROMA_U ) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); |
---|
2673 | ::memcpy( m_puhQTTempCbf[2], pcCU->getCbf( TEXT_CHROMA_V ) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); |
---|
2674 | ::memcpy( m_puhQTTempTransformSkipFlag[0], pcCU->getTransformSkip(TEXT_LUMA) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); |
---|
2675 | ::memcpy( m_puhQTTempTransformSkipFlag[1], pcCU->getTransformSkip(TEXT_CHROMA_U) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); |
---|
2676 | ::memcpy( m_puhQTTempTransformSkipFlag[2], pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); |
---|
2677 | } |
---|
2678 | } // Mode loop |
---|
2679 | #endif |
---|
2680 | |
---|
2681 | //--- update overall distortion --- |
---|
2682 | uiOverallDistY += uiBestPUDistY; |
---|
2683 | uiOverallDistC += uiBestPUDistC; |
---|
2684 | |
---|
2685 | //--- update transform index and cbf --- |
---|
2686 | UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth(0) + uiInitTrDepth ) << 1 ); |
---|
2687 | ::memcpy( pcCU->getTransformIdx() + uiPartOffset, m_puhQTTempTrIdx, uiQPartNum * sizeof( UChar ) ); |
---|
2688 | ::memcpy( pcCU->getCbf( TEXT_LUMA ) + uiPartOffset, m_puhQTTempCbf[0], uiQPartNum * sizeof( UChar ) ); |
---|
2689 | ::memcpy( pcCU->getCbf( TEXT_CHROMA_U ) + uiPartOffset, m_puhQTTempCbf[1], uiQPartNum * sizeof( UChar ) ); |
---|
2690 | ::memcpy( pcCU->getCbf( TEXT_CHROMA_V ) + uiPartOffset, m_puhQTTempCbf[2], uiQPartNum * sizeof( UChar ) ); |
---|
2691 | ::memcpy( pcCU->getTransformSkip(TEXT_LUMA) + uiPartOffset, m_puhQTTempTransformSkipFlag[0], uiQPartNum * sizeof( UChar ) ); |
---|
2692 | ::memcpy( pcCU->getTransformSkip(TEXT_CHROMA_U) + uiPartOffset, m_puhQTTempTransformSkipFlag[1], uiQPartNum * sizeof( UChar ) ); |
---|
2693 | ::memcpy( pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, m_puhQTTempTransformSkipFlag[2], uiQPartNum * sizeof( UChar ) ); |
---|
2694 | //--- set reconstruction for next intra prediction blocks --- |
---|
2695 | if( uiPU != uiNumPU - 1 ) |
---|
2696 | { |
---|
2697 | Bool bSkipChroma = false; |
---|
2698 | Bool bChromaSame = false; |
---|
2699 | UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> ( pcCU->getDepth(0) + uiInitTrDepth ) ] + 2; |
---|
2700 | if( !bLumaOnly && uiLog2TrSize == 2 ) |
---|
2701 | { |
---|
2702 | assert( uiInitTrDepth > 0 ); |
---|
2703 | bSkipChroma = ( uiPU != 0 ); |
---|
2704 | bChromaSame = true; |
---|
2705 | } |
---|
2706 | |
---|
2707 | UInt uiCompWidth = pcCU->getWidth ( 0 ) >> uiInitTrDepth; |
---|
2708 | UInt uiCompHeight = pcCU->getHeight( 0 ) >> uiInitTrDepth; |
---|
2709 | UInt uiZOrder = pcCU->getZorderIdxInCU() + uiPartOffset; |
---|
2710 | Pel* piDes = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder ); |
---|
2711 | UInt uiDesStride = pcCU->getPic()->getPicYuvRec()->getStride(); |
---|
2712 | Pel* piSrc = pcRecoYuv->getLumaAddr( uiPartOffset ); |
---|
2713 | UInt uiSrcStride = pcRecoYuv->getStride(); |
---|
2714 | for( UInt uiY = 0; uiY < uiCompHeight; uiY++, piSrc += uiSrcStride, piDes += uiDesStride ) |
---|
2715 | { |
---|
2716 | for( UInt uiX = 0; uiX < uiCompWidth; uiX++ ) |
---|
2717 | { |
---|
2718 | piDes[ uiX ] = piSrc[ uiX ]; |
---|
2719 | } |
---|
2720 | } |
---|
2721 | if( !bLumaOnly && !bSkipChroma ) |
---|
2722 | { |
---|
2723 | if( !bChromaSame ) |
---|
2724 | { |
---|
2725 | uiCompWidth >>= 1; |
---|
2726 | uiCompHeight >>= 1; |
---|
2727 | } |
---|
2728 | piDes = pcCU->getPic()->getPicYuvRec()->getCbAddr( pcCU->getAddr(), uiZOrder ); |
---|
2729 | uiDesStride = pcCU->getPic()->getPicYuvRec()->getCStride(); |
---|
2730 | piSrc = pcRecoYuv->getCbAddr( uiPartOffset ); |
---|
2731 | uiSrcStride = pcRecoYuv->getCStride(); |
---|
2732 | for( UInt uiY = 0; uiY < uiCompHeight; uiY++, piSrc += uiSrcStride, piDes += uiDesStride ) |
---|
2733 | { |
---|
2734 | for( UInt uiX = 0; uiX < uiCompWidth; uiX++ ) |
---|
2735 | { |
---|
2736 | piDes[ uiX ] = piSrc[ uiX ]; |
---|
2737 | } |
---|
2738 | } |
---|
2739 | piDes = pcCU->getPic()->getPicYuvRec()->getCrAddr( pcCU->getAddr(), uiZOrder ); |
---|
2740 | piSrc = pcRecoYuv->getCrAddr( uiPartOffset ); |
---|
2741 | for( UInt uiY = 0; uiY < uiCompHeight; uiY++, piSrc += uiSrcStride, piDes += uiDesStride ) |
---|
2742 | { |
---|
2743 | for( UInt uiX = 0; uiX < uiCompWidth; uiX++ ) |
---|
2744 | { |
---|
2745 | piDes[ uiX ] = piSrc[ uiX ]; |
---|
2746 | } |
---|
2747 | } |
---|
2748 | } |
---|
2749 | } |
---|
2750 | |
---|
2751 | //=== update PU data ==== |
---|
2752 | pcCU->setLumaIntraDirSubParts ( uiBestPUMode, uiPartOffset, uiDepth + uiInitTrDepth ); |
---|
2753 | pcCU->copyToPic ( uiDepth, uiPU, uiInitTrDepth ); |
---|
2754 | } // PU loop |
---|
2755 | |
---|
2756 | |
---|
2757 | if( uiNumPU > 1 ) |
---|
2758 | { // set Cbf for all blocks |
---|
2759 | UInt uiCombCbfY = 0; |
---|
2760 | UInt uiCombCbfU = 0; |
---|
2761 | UInt uiCombCbfV = 0; |
---|
2762 | UInt uiPartIdx = 0; |
---|
2763 | for( UInt uiPart = 0; uiPart < 4; uiPart++, uiPartIdx += uiQNumParts ) |
---|
2764 | { |
---|
2765 | uiCombCbfY |= pcCU->getCbf( uiPartIdx, TEXT_LUMA, 1 ); |
---|
2766 | uiCombCbfU |= pcCU->getCbf( uiPartIdx, TEXT_CHROMA_U, 1 ); |
---|
2767 | uiCombCbfV |= pcCU->getCbf( uiPartIdx, TEXT_CHROMA_V, 1 ); |
---|
2768 | } |
---|
2769 | for( UInt uiOffs = 0; uiOffs < 4 * uiQNumParts; uiOffs++ ) |
---|
2770 | { |
---|
2771 | pcCU->getCbf( TEXT_LUMA )[ uiOffs ] |= uiCombCbfY; |
---|
2772 | pcCU->getCbf( TEXT_CHROMA_U )[ uiOffs ] |= uiCombCbfU; |
---|
2773 | pcCU->getCbf( TEXT_CHROMA_V )[ uiOffs ] |= uiCombCbfV; |
---|
2774 | } |
---|
2775 | } |
---|
2776 | |
---|
2777 | //===== reset context models ===== |
---|
2778 | if(m_bUseSBACRD) |
---|
2779 | { |
---|
2780 | m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
2781 | } |
---|
2782 | |
---|
2783 | //===== set distortion (rate and r-d costs are determined later) ===== |
---|
2784 | ruiDistC = uiOverallDistC; |
---|
2785 | pcCU->getTotalDistortion() = uiOverallDistY + uiOverallDistC; |
---|
2786 | } |
---|
2787 | |
---|
2788 | |
---|
2789 | |
---|
2790 | Void |
---|
2791 | TEncSearch::estIntraPredChromaQT( TComDataCU* pcCU, |
---|
2792 | TComYuv* pcOrgYuv, |
---|
2793 | TComYuv* pcPredYuv, |
---|
2794 | TComYuv* pcResiYuv, |
---|
2795 | TComYuv* pcRecoYuv, |
---|
2796 | UInt uiPreCalcDistC ) |
---|
2797 | { |
---|
2798 | UInt uiDepth = pcCU->getDepth(0); |
---|
2799 | UInt uiBestMode = 0; |
---|
2800 | UInt uiBestDist = 0; |
---|
2801 | Double dBestCost = MAX_DOUBLE; |
---|
2802 | |
---|
2803 | //----- init mode list ----- |
---|
2804 | UInt uiMinMode = 0; |
---|
2805 | UInt uiModeList[ NUM_CHROMA_MODE ]; |
---|
2806 | pcCU->getAllowedChromaDir( 0, uiModeList ); |
---|
2807 | UInt uiMaxMode = NUM_CHROMA_MODE; |
---|
2808 | |
---|
2809 | //----- check chroma modes ----- |
---|
2810 | for( UInt uiMode = uiMinMode; uiMode < uiMaxMode; uiMode++ ) |
---|
2811 | { |
---|
2812 | //----- restore context models ----- |
---|
2813 | if( m_bUseSBACRD ) |
---|
2814 | { |
---|
2815 | m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); |
---|
2816 | } |
---|
2817 | |
---|
2818 | //----- chroma coding ----- |
---|
2819 | UInt uiDist = 0; |
---|
2820 | pcCU->setChromIntraDirSubParts ( uiModeList[uiMode], 0, uiDepth ); |
---|
2821 | xRecurIntraChromaCodingQT ( pcCU, 0, 0, pcOrgYuv, pcPredYuv, pcResiYuv, uiDist ); |
---|
2822 | if( m_bUseSBACRD && pcCU->getSlice()->getPPS()->getUseTransformSkip() ) |
---|
2823 | { |
---|
2824 | m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); |
---|
2825 | } |
---|
2826 | UInt uiBits = xGetIntraBitsQT( pcCU, 0, 0, false, true, false ); |
---|
2827 | Double dCost = m_pcRdCost->calcRdCost( uiBits, uiDist ); |
---|
2828 | |
---|
2829 | //----- compare ----- |
---|
2830 | if( dCost < dBestCost ) |
---|
2831 | { |
---|
2832 | dBestCost = dCost; |
---|
2833 | uiBestDist = uiDist; |
---|
2834 | uiBestMode = uiModeList[uiMode]; |
---|
2835 | UInt uiQPN = pcCU->getPic()->getNumPartInCU() >> ( uiDepth << 1 ); |
---|
2836 | xSetIntraResultChromaQT( pcCU, 0, 0, pcRecoYuv ); |
---|
2837 | ::memcpy( m_puhQTTempCbf[1], pcCU->getCbf( TEXT_CHROMA_U ), uiQPN * sizeof( UChar ) ); |
---|
2838 | ::memcpy( m_puhQTTempCbf[2], pcCU->getCbf( TEXT_CHROMA_V ), uiQPN * sizeof( UChar ) ); |
---|
2839 | ::memcpy( m_puhQTTempTransformSkipFlag[1], pcCU->getTransformSkip( TEXT_CHROMA_U ), uiQPN * sizeof( UChar ) ); |
---|
2840 | ::memcpy( m_puhQTTempTransformSkipFlag[2], pcCU->getTransformSkip( TEXT_CHROMA_V ), uiQPN * sizeof( UChar ) ); |
---|
2841 | } |
---|
2842 | } |
---|
2843 | |
---|
2844 | //----- set data ----- |
---|
2845 | UInt uiQPN = pcCU->getPic()->getNumPartInCU() >> ( uiDepth << 1 ); |
---|
2846 | ::memcpy( pcCU->getCbf( TEXT_CHROMA_U ), m_puhQTTempCbf[1], uiQPN * sizeof( UChar ) ); |
---|
2847 | ::memcpy( pcCU->getCbf( TEXT_CHROMA_V ), m_puhQTTempCbf[2], uiQPN * sizeof( UChar ) ); |
---|
2848 | ::memcpy( pcCU->getTransformSkip( TEXT_CHROMA_U ), m_puhQTTempTransformSkipFlag[1], uiQPN * sizeof( UChar ) ); |
---|
2849 | ::memcpy( pcCU->getTransformSkip( TEXT_CHROMA_V ), m_puhQTTempTransformSkipFlag[2], uiQPN * sizeof( UChar ) ); |
---|
2850 | pcCU->setChromIntraDirSubParts( uiBestMode, 0, uiDepth ); |
---|
2851 | pcCU->getTotalDistortion () += uiBestDist - uiPreCalcDistC; |
---|
2852 | |
---|
2853 | //----- restore context models ----- |
---|
2854 | if( m_bUseSBACRD ) |
---|
2855 | { |
---|
2856 | m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); |
---|
2857 | } |
---|
2858 | } |
---|
2859 | |
---|
2860 | /** Function for encoding and reconstructing luma/chroma samples of a PCM mode CU. |
---|
2861 | * \param pcCU pointer to current CU |
---|
2862 | * \param uiAbsPartIdx part index |
---|
2863 | * \param piOrg pointer to original sample arrays |
---|
2864 | * \param piPCM pointer to PCM code arrays |
---|
2865 | * \param piPred pointer to prediction signal arrays |
---|
2866 | * \param piResi pointer to residual signal arrays |
---|
2867 | * \param piReco pointer to reconstructed sample arrays |
---|
2868 | * \param uiStride stride of the original/prediction/residual sample arrays |
---|
2869 | * \param uiWidth block width |
---|
2870 | * \param uiHeight block height |
---|
2871 | * \param ttText texture component type |
---|
2872 | * \returns Void |
---|
2873 | */ |
---|
2874 | Void TEncSearch::xEncPCM (TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piOrg, Pel* piPCM, Pel* piPred, Pel* piResi, Pel* piReco, UInt uiStride, UInt uiWidth, UInt uiHeight, TextType eText ) |
---|
2875 | { |
---|
2876 | UInt uiX, uiY; |
---|
2877 | UInt uiReconStride; |
---|
2878 | Pel* pOrg = piOrg; |
---|
2879 | Pel* pPCM = piPCM; |
---|
2880 | Pel* pPred = piPred; |
---|
2881 | Pel* pResi = piResi; |
---|
2882 | Pel* pReco = piReco; |
---|
2883 | Pel* pRecoPic; |
---|
2884 | Int shiftPcm; |
---|
2885 | |
---|
2886 | if( eText == TEXT_LUMA) |
---|
2887 | { |
---|
2888 | uiReconStride = pcCU->getPic()->getPicYuvRec()->getStride(); |
---|
2889 | pRecoPic = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiAbsPartIdx); |
---|
2890 | shiftPcm = g_bitDepthY - pcCU->getSlice()->getSPS()->getPCMBitDepthLuma(); |
---|
2891 | } |
---|
2892 | else |
---|
2893 | { |
---|
2894 | uiReconStride = pcCU->getPic()->getPicYuvRec()->getCStride(); |
---|
2895 | |
---|
2896 | if( eText == TEXT_CHROMA_U ) |
---|
2897 | { |
---|
2898 | pRecoPic = pcCU->getPic()->getPicYuvRec()->getCbAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiAbsPartIdx); |
---|
2899 | } |
---|
2900 | else |
---|
2901 | { |
---|
2902 | pRecoPic = pcCU->getPic()->getPicYuvRec()->getCrAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiAbsPartIdx); |
---|
2903 | } |
---|
2904 | shiftPcm = g_bitDepthC - pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
2905 | } |
---|
2906 | |
---|
2907 | // Reset pred and residual |
---|
2908 | for( uiY = 0; uiY < uiHeight; uiY++ ) |
---|
2909 | { |
---|
2910 | for( uiX = 0; uiX < uiWidth; uiX++ ) |
---|
2911 | { |
---|
2912 | pPred[uiX] = 0; |
---|
2913 | pResi[uiX] = 0; |
---|
2914 | } |
---|
2915 | pPred += uiStride; |
---|
2916 | pResi += uiStride; |
---|
2917 | } |
---|
2918 | |
---|
2919 | // Encode |
---|
2920 | for( uiY = 0; uiY < uiHeight; uiY++ ) |
---|
2921 | { |
---|
2922 | for( uiX = 0; uiX < uiWidth; uiX++ ) |
---|
2923 | { |
---|
2924 | pPCM[uiX] = pOrg[uiX]>> shiftPcm; |
---|
2925 | } |
---|
2926 | pPCM += uiWidth; |
---|
2927 | pOrg += uiStride; |
---|
2928 | } |
---|
2929 | |
---|
2930 | pPCM = piPCM; |
---|
2931 | |
---|
2932 | // Reconstruction |
---|
2933 | for( uiY = 0; uiY < uiHeight; uiY++ ) |
---|
2934 | { |
---|
2935 | for( uiX = 0; uiX < uiWidth; uiX++ ) |
---|
2936 | { |
---|
2937 | pReco [uiX] = pPCM[uiX]<< shiftPcm; |
---|
2938 | pRecoPic[uiX] = pReco[uiX]; |
---|
2939 | } |
---|
2940 | pPCM += uiWidth; |
---|
2941 | pReco += uiStride; |
---|
2942 | pRecoPic += uiReconStride; |
---|
2943 | } |
---|
2944 | } |
---|
2945 | |
---|
2946 | /** Function for PCM mode estimation. |
---|
2947 | * \param pcCU |
---|
2948 | * \param pcOrgYuv |
---|
2949 | * \param rpcPredYuv |
---|
2950 | * \param rpcResiYuv |
---|
2951 | * \param rpcRecoYuv |
---|
2952 | * \returns Void |
---|
2953 | */ |
---|
2954 | Void TEncSearch::IPCMSearch( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv ) |
---|
2955 | { |
---|
2956 | UInt uiDepth = pcCU->getDepth(0); |
---|
2957 | UInt uiWidth = pcCU->getWidth(0); |
---|
2958 | UInt uiHeight = pcCU->getHeight(0); |
---|
2959 | UInt uiStride = rpcPredYuv->getStride(); |
---|
2960 | UInt uiStrideC = rpcPredYuv->getCStride(); |
---|
2961 | UInt uiWidthC = uiWidth >> 1; |
---|
2962 | UInt uiHeightC = uiHeight >> 1; |
---|
2963 | UInt uiDistortion = 0; |
---|
2964 | UInt uiBits; |
---|
2965 | |
---|
2966 | Double dCost; |
---|
2967 | |
---|
2968 | Pel* pOrig; |
---|
2969 | Pel* pResi; |
---|
2970 | Pel* pReco; |
---|
2971 | Pel* pPred; |
---|
2972 | Pel* pPCM; |
---|
2973 | |
---|
2974 | UInt uiAbsPartIdx = 0; |
---|
2975 | |
---|
2976 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
2977 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
2978 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
2979 | |
---|
2980 | // Luminance |
---|
2981 | pOrig = pcOrgYuv->getLumaAddr(0, uiWidth); |
---|
2982 | pResi = rpcResiYuv->getLumaAddr(0, uiWidth); |
---|
2983 | pPred = rpcPredYuv->getLumaAddr(0, uiWidth); |
---|
2984 | pReco = rpcRecoYuv->getLumaAddr(0, uiWidth); |
---|
2985 | pPCM = pcCU->getPCMSampleY() + uiLumaOffset; |
---|
2986 | |
---|
2987 | xEncPCM ( pcCU, 0, pOrig, pPCM, pPred, pResi, pReco, uiStride, uiWidth, uiHeight, TEXT_LUMA ); |
---|
2988 | |
---|
2989 | // Chroma U |
---|
2990 | pOrig = pcOrgYuv->getCbAddr(); |
---|
2991 | pResi = rpcResiYuv->getCbAddr(); |
---|
2992 | pPred = rpcPredYuv->getCbAddr(); |
---|
2993 | pReco = rpcRecoYuv->getCbAddr(); |
---|
2994 | pPCM = pcCU->getPCMSampleCb() + uiChromaOffset; |
---|
2995 | |
---|
2996 | xEncPCM ( pcCU, 0, pOrig, pPCM, pPred, pResi, pReco, uiStrideC, uiWidthC, uiHeightC, TEXT_CHROMA_U ); |
---|
2997 | |
---|
2998 | // Chroma V |
---|
2999 | pOrig = pcOrgYuv->getCrAddr(); |
---|
3000 | pResi = rpcResiYuv->getCrAddr(); |
---|
3001 | pPred = rpcPredYuv->getCrAddr(); |
---|
3002 | pReco = rpcRecoYuv->getCrAddr(); |
---|
3003 | pPCM = pcCU->getPCMSampleCr() + uiChromaOffset; |
---|
3004 | |
---|
3005 | xEncPCM ( pcCU, 0, pOrig, pPCM, pPred, pResi, pReco, uiStrideC, uiWidthC, uiHeightC, TEXT_CHROMA_V ); |
---|
3006 | |
---|
3007 | m_pcEntropyCoder->resetBits(); |
---|
3008 | xEncIntraHeader ( pcCU, uiDepth, uiAbsPartIdx, true, false); |
---|
3009 | uiBits = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
3010 | |
---|
3011 | dCost = m_pcRdCost->calcRdCost( uiBits, uiDistortion ); |
---|
3012 | |
---|
3013 | if(m_bUseSBACRD) |
---|
3014 | { |
---|
3015 | m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
3016 | } |
---|
3017 | |
---|
3018 | pcCU->getTotalBits() = uiBits; |
---|
3019 | pcCU->getTotalCost() = dCost; |
---|
3020 | pcCU->getTotalDistortion() = uiDistortion; |
---|
3021 | |
---|
3022 | pcCU->copyToPic(uiDepth, 0, 0); |
---|
3023 | } |
---|
3024 | |
---|
3025 | Void TEncSearch::xGetInterPredictionError( TComDataCU* pcCU, TComYuv* pcYuvOrg, Int iPartIdx, UInt& ruiErr, Bool bHadamard ) |
---|
3026 | { |
---|
3027 | motionCompensation( pcCU, &m_tmpYuvPred, REF_PIC_LIST_X, iPartIdx ); |
---|
3028 | |
---|
3029 | UInt uiAbsPartIdx = 0; |
---|
3030 | Int iWidth = 0; |
---|
3031 | Int iHeight = 0; |
---|
3032 | pcCU->getPartIndexAndSize( iPartIdx, uiAbsPartIdx, iWidth, iHeight ); |
---|
3033 | |
---|
3034 | DistParam cDistParam; |
---|
3035 | |
---|
3036 | cDistParam.bApplyWeight = false; |
---|
3037 | |
---|
3038 | m_pcRdCost->setDistParam( cDistParam, g_bitDepthY, |
---|
3039 | pcYuvOrg->getLumaAddr( uiAbsPartIdx ), pcYuvOrg->getStride(), |
---|
3040 | m_tmpYuvPred .getLumaAddr( uiAbsPartIdx ), m_tmpYuvPred .getStride(), |
---|
3041 | #if NS_HAD |
---|
3042 | iWidth, iHeight, m_pcEncCfg->getUseHADME(), m_pcEncCfg->getUseNSQT() ); |
---|
3043 | #else |
---|
3044 | iWidth, iHeight, m_pcEncCfg->getUseHADME() ); |
---|
3045 | #endif |
---|
3046 | ruiErr = cDistParam.DistFunc( &cDistParam ); |
---|
3047 | } |
---|
3048 | |
---|
3049 | /** estimation of best merge coding |
---|
3050 | * \param pcCU |
---|
3051 | * \param pcYuvOrg |
---|
3052 | * \param iPUIdx |
---|
3053 | * \param uiInterDir |
---|
3054 | * \param pacMvField |
---|
3055 | * \param uiMergeIndex |
---|
3056 | * \param ruiCost |
---|
3057 | * \param ruiBits |
---|
3058 | * \param puhNeighCands |
---|
3059 | * \param bValid |
---|
3060 | * \returns Void |
---|
3061 | */ |
---|
3062 | Void TEncSearch::xMergeEstimation( TComDataCU* pcCU, TComYuv* pcYuvOrg, Int iPUIdx, UInt& uiInterDir, TComMvField* pacMvField, UInt& uiMergeIndex, UInt& ruiCost, TComMvField* cMvFieldNeighbours, UChar* uhInterDirNeighbours, Int& numValidMergeCand ) |
---|
3063 | { |
---|
3064 | UInt uiAbsPartIdx = 0; |
---|
3065 | Int iWidth = 0; |
---|
3066 | Int iHeight = 0; |
---|
3067 | |
---|
3068 | pcCU->getPartIndexAndSize( iPUIdx, uiAbsPartIdx, iWidth, iHeight ); |
---|
3069 | UInt uiDepth = pcCU->getDepth( uiAbsPartIdx ); |
---|
3070 | PartSize partSize = pcCU->getPartitionSize( 0 ); |
---|
3071 | if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && partSize != SIZE_2Nx2N && pcCU->getWidth( 0 ) <= 8 ) |
---|
3072 | { |
---|
3073 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
3074 | if ( iPUIdx == 0 ) |
---|
3075 | { |
---|
3076 | pcCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand ); |
---|
3077 | } |
---|
3078 | pcCU->setPartSizeSubParts( partSize, 0, uiDepth ); |
---|
3079 | } |
---|
3080 | else |
---|
3081 | { |
---|
3082 | pcCU->getInterMergeCandidates( uiAbsPartIdx, iPUIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand ); |
---|
3083 | } |
---|
3084 | xRestrictBipredMergeCand( pcCU, iPUIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand ); |
---|
3085 | |
---|
3086 | ruiCost = MAX_UINT; |
---|
3087 | for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand ) |
---|
3088 | { |
---|
3089 | #if REF_IDX_ME_ZEROMV |
---|
3090 | Bool bZeroMVILR = pcCU->xCheckZeroMVILRMerge(uhInterDirNeighbours[uiMergeCand], cMvFieldNeighbours[0 + 2*uiMergeCand], cMvFieldNeighbours[1 + 2*uiMergeCand]); |
---|
3091 | if(bZeroMVILR) |
---|
3092 | { |
---|
3093 | #endif |
---|
3094 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
3095 | if (!(pcCU->isInterLayerReference(uhInterDirNeighbours[uiMergeCand], cMvFieldNeighbours[0 + 2*uiMergeCand], cMvFieldNeighbours[1 + 2*uiMergeCand]) && m_disableILP)) |
---|
3096 | { |
---|
3097 | #endif |
---|
3098 | UInt uiCostCand = MAX_UINT; |
---|
3099 | UInt uiBitsCand = 0; |
---|
3100 | |
---|
3101 | PartSize ePartSize = pcCU->getPartitionSize( 0 ); |
---|
3102 | |
---|
3103 | pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], ePartSize, uiAbsPartIdx, 0, iPUIdx ); |
---|
3104 | pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], ePartSize, uiAbsPartIdx, 0, iPUIdx ); |
---|
3105 | |
---|
3106 | xGetInterPredictionError( pcCU, pcYuvOrg, iPUIdx, uiCostCand, m_pcEncCfg->getUseHADME() ); |
---|
3107 | uiBitsCand = uiMergeCand + 1; |
---|
3108 | if (uiMergeCand == m_pcEncCfg->getMaxNumMergeCand() -1) |
---|
3109 | { |
---|
3110 | uiBitsCand--; |
---|
3111 | } |
---|
3112 | uiCostCand = uiCostCand + m_pcRdCost->getCost( uiBitsCand ); |
---|
3113 | if ( uiCostCand < ruiCost ) |
---|
3114 | { |
---|
3115 | ruiCost = uiCostCand; |
---|
3116 | pacMvField[0] = cMvFieldNeighbours[0 + 2*uiMergeCand]; |
---|
3117 | pacMvField[1] = cMvFieldNeighbours[1 + 2*uiMergeCand]; |
---|
3118 | uiInterDir = uhInterDirNeighbours[uiMergeCand]; |
---|
3119 | uiMergeIndex = uiMergeCand; |
---|
3120 | } |
---|
3121 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
3122 | } |
---|
3123 | #endif |
---|
3124 | #if REF_IDX_ME_ZEROMV |
---|
3125 | } |
---|
3126 | #endif |
---|
3127 | } |
---|
3128 | } |
---|
3129 | |
---|
3130 | /** convert bi-pred merge candidates to uni-pred |
---|
3131 | * \param pcCU |
---|
3132 | * \param puIdx |
---|
3133 | * \param mvFieldNeighbours |
---|
3134 | * \param interDirNeighbours |
---|
3135 | * \param numValidMergeCand |
---|
3136 | * \returns Void |
---|
3137 | */ |
---|
3138 | Void TEncSearch::xRestrictBipredMergeCand( TComDataCU* pcCU, UInt puIdx, TComMvField* mvFieldNeighbours, UChar* interDirNeighbours, Int numValidMergeCand ) |
---|
3139 | { |
---|
3140 | if ( pcCU->isBipredRestriction(puIdx) ) |
---|
3141 | { |
---|
3142 | for( UInt mergeCand = 0; mergeCand < numValidMergeCand; ++mergeCand ) |
---|
3143 | { |
---|
3144 | if ( interDirNeighbours[mergeCand] == 3 ) |
---|
3145 | { |
---|
3146 | interDirNeighbours[mergeCand] = 1; |
---|
3147 | mvFieldNeighbours[(mergeCand << 1) + 1].setMvField(TComMv(0,0), -1); |
---|
3148 | } |
---|
3149 | } |
---|
3150 | } |
---|
3151 | } |
---|
3152 | |
---|
3153 | /** search of the best candidate for inter prediction |
---|
3154 | * \param pcCU |
---|
3155 | * \param pcOrgYuv |
---|
3156 | * \param rpcPredYuv |
---|
3157 | * \param rpcResiYuv |
---|
3158 | * \param rpcRecoYuv |
---|
3159 | * \param bUseRes |
---|
3160 | * \returns Void |
---|
3161 | */ |
---|
3162 | #if AMP_MRG |
---|
3163 | Void TEncSearch::predInterSearch( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv, Bool bUseRes, Bool bUseMRG ) |
---|
3164 | #else |
---|
3165 | Void TEncSearch::predInterSearch( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv, Bool bUseRes ) |
---|
3166 | #endif |
---|
3167 | { |
---|
3168 | m_acYuvPred[0].clear(); |
---|
3169 | m_acYuvPred[1].clear(); |
---|
3170 | m_cYuvPredTemp.clear(); |
---|
3171 | rpcPredYuv->clear(); |
---|
3172 | |
---|
3173 | if ( !bUseRes ) |
---|
3174 | { |
---|
3175 | rpcResiYuv->clear(); |
---|
3176 | } |
---|
3177 | |
---|
3178 | rpcRecoYuv->clear(); |
---|
3179 | |
---|
3180 | TComMv cMvSrchRngLT; |
---|
3181 | TComMv cMvSrchRngRB; |
---|
3182 | |
---|
3183 | TComMv cMvZero; |
---|
3184 | TComMv TempMv; //kolya |
---|
3185 | |
---|
3186 | TComMv cMv[2]; |
---|
3187 | TComMv cMvBi[2]; |
---|
3188 | TComMv cMvTemp[2][33]; |
---|
3189 | |
---|
3190 | Int iNumPart = pcCU->getNumPartInter(); |
---|
3191 | Int iNumPredDir = pcCU->getSlice()->isInterP() ? 1 : 2; |
---|
3192 | |
---|
3193 | TComMv cMvPred[2][33]; |
---|
3194 | |
---|
3195 | TComMv cMvPredBi[2][33]; |
---|
3196 | Int aaiMvpIdxBi[2][33]; |
---|
3197 | |
---|
3198 | Int aaiMvpIdx[2][33]; |
---|
3199 | Int aaiMvpNum[2][33]; |
---|
3200 | |
---|
3201 | AMVPInfo aacAMVPInfo[2][33]; |
---|
3202 | |
---|
3203 | Int iRefIdx[2]={0,0}; //If un-initialized, may cause SEGV in bi-directional prediction iterative stage. |
---|
3204 | Int iRefIdxBi[2]; |
---|
3205 | |
---|
3206 | UInt uiPartAddr; |
---|
3207 | Int iRoiWidth, iRoiHeight; |
---|
3208 | |
---|
3209 | UInt uiMbBits[3] = {1, 1, 0}; |
---|
3210 | |
---|
3211 | UInt uiLastMode = 0; |
---|
3212 | Int iRefStart, iRefEnd; |
---|
3213 | |
---|
3214 | PartSize ePartSize = pcCU->getPartitionSize( 0 ); |
---|
3215 | |
---|
3216 | Int bestBiPRefIdxL1 = 0; |
---|
3217 | Int bestBiPMvpL1 = 0; |
---|
3218 | UInt biPDistTemp = MAX_INT; |
---|
3219 | |
---|
3220 | #if ZERO_MVD_EST |
---|
3221 | Int aiZeroMvdMvpIdx[2] = {-1, -1}; |
---|
3222 | Int aiZeroMvdRefIdx[2] = {0, 0}; |
---|
3223 | Int iZeroMvdDir = -1; |
---|
3224 | #endif |
---|
3225 | |
---|
3226 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists |
---|
3227 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
---|
3228 | Int numValidMergeCand = 0 ; |
---|
3229 | |
---|
3230 | for ( Int iPartIdx = 0; iPartIdx < iNumPart; iPartIdx++ ) |
---|
3231 | { |
---|
3232 | UInt uiCost[2] = { MAX_UINT, MAX_UINT }; |
---|
3233 | UInt uiCostBi = MAX_UINT; |
---|
3234 | UInt uiCostTemp; |
---|
3235 | |
---|
3236 | UInt uiBits[3]; |
---|
3237 | UInt uiBitsTemp; |
---|
3238 | #if ZERO_MVD_EST |
---|
3239 | UInt uiZeroMvdCost = MAX_UINT; |
---|
3240 | UInt uiZeroMvdCostTemp; |
---|
3241 | UInt uiZeroMvdBitsTemp; |
---|
3242 | UInt uiZeroMvdDistTemp = MAX_UINT; |
---|
3243 | UInt auiZeroMvdBits[3]; |
---|
3244 | #endif |
---|
3245 | UInt bestBiPDist = MAX_INT; |
---|
3246 | |
---|
3247 | UInt uiCostTempL0[MAX_NUM_REF]; |
---|
3248 | for (Int iNumRef=0; iNumRef < MAX_NUM_REF; iNumRef++) uiCostTempL0[iNumRef] = MAX_UINT; |
---|
3249 | UInt uiBitsTempL0[MAX_NUM_REF]; |
---|
3250 | |
---|
3251 | TComMv mvValidList1; |
---|
3252 | Int refIdxValidList1 = 0; |
---|
3253 | UInt bitsValidList1 = MAX_UINT; |
---|
3254 | UInt costValidList1 = MAX_UINT; |
---|
3255 | |
---|
3256 | xGetBlkBits( ePartSize, pcCU->getSlice()->isInterP(), iPartIdx, uiLastMode, uiMbBits); |
---|
3257 | |
---|
3258 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iRoiWidth, iRoiHeight ); |
---|
3259 | |
---|
3260 | #if AMP_MRG |
---|
3261 | Bool bTestNormalMC = true; |
---|
3262 | |
---|
3263 | if ( bUseMRG && pcCU->getWidth( 0 ) > 8 && iNumPart == 2 ) |
---|
3264 | { |
---|
3265 | bTestNormalMC = false; |
---|
3266 | } |
---|
3267 | |
---|
3268 | if (bTestNormalMC) |
---|
3269 | { |
---|
3270 | #endif |
---|
3271 | |
---|
3272 | // Uni-directional prediction |
---|
3273 | for ( Int iRefList = 0; iRefList < iNumPredDir; iRefList++ ) |
---|
3274 | { |
---|
3275 | RefPicList eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); |
---|
3276 | |
---|
3277 | for ( Int iRefIdxTemp = 0; iRefIdxTemp < pcCU->getSlice()->getNumRefIdx(eRefPicList); iRefIdxTemp++ ) |
---|
3278 | { |
---|
3279 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
3280 | if (pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxTemp )->isILR(pcCU->getLayerId()) && m_disableILP) |
---|
3281 | { |
---|
3282 | continue; |
---|
3283 | } |
---|
3284 | #endif |
---|
3285 | #if (ENCODER_FAST_MODE) |
---|
3286 | TComPic* pcPic = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxTemp ); |
---|
3287 | if( pcPic->isILR(pcCU->getLayerId()) && (ePartSize == SIZE_2Nx2N) ) |
---|
3288 | { |
---|
3289 | continue; |
---|
3290 | } |
---|
3291 | #endif |
---|
3292 | |
---|
3293 | uiBitsTemp = uiMbBits[iRefList]; |
---|
3294 | if ( pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1 ) |
---|
3295 | { |
---|
3296 | uiBitsTemp += iRefIdxTemp+1; |
---|
3297 | if ( iRefIdxTemp == pcCU->getSlice()->getNumRefIdx(eRefPicList)-1 ) uiBitsTemp--; |
---|
3298 | } |
---|
3299 | #if ZERO_MVD_EST |
---|
3300 | xEstimateMvPredAMVP( pcCU, pcOrgYuv, iPartIdx, eRefPicList, iRefIdxTemp, cMvPred[iRefList][iRefIdxTemp], false, &biPDistTemp, &uiZeroMvdDistTemp); |
---|
3301 | #else |
---|
3302 | xEstimateMvPredAMVP( pcCU, pcOrgYuv, iPartIdx, eRefPicList, iRefIdxTemp, cMvPred[iRefList][iRefIdxTemp], false, &biPDistTemp); |
---|
3303 | #endif |
---|
3304 | aaiMvpIdx[iRefList][iRefIdxTemp] = pcCU->getMVPIdx(eRefPicList, uiPartAddr); |
---|
3305 | aaiMvpNum[iRefList][iRefIdxTemp] = pcCU->getMVPNum(eRefPicList, uiPartAddr); |
---|
3306 | |
---|
3307 | if(pcCU->getSlice()->getMvdL1ZeroFlag() && iRefList==1 && biPDistTemp < bestBiPDist) |
---|
3308 | { |
---|
3309 | #if REF_IDX_ME_ZEROMV |
---|
3310 | Bool bZeroMVILR = pcCU->xCheckZeroMVILRMvdL1Zero(iRefList, iRefIdxTemp, aaiMvpIdx[iRefList][iRefIdxTemp]); |
---|
3311 | if(bZeroMVILR) |
---|
3312 | { |
---|
3313 | #endif |
---|
3314 | bestBiPDist = biPDistTemp; |
---|
3315 | bestBiPMvpL1 = aaiMvpIdx[iRefList][iRefIdxTemp]; |
---|
3316 | bestBiPRefIdxL1 = iRefIdxTemp; |
---|
3317 | #if REF_IDX_ME_ZEROMV |
---|
3318 | } |
---|
3319 | #endif |
---|
3320 | } |
---|
3321 | |
---|
3322 | uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdx[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS]; |
---|
3323 | #if ZERO_MVD_EST |
---|
3324 | if ( iRefList == 0 || pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp ) < 0 ) |
---|
3325 | { |
---|
3326 | uiZeroMvdBitsTemp = uiBitsTemp; |
---|
3327 | uiZeroMvdBitsTemp += 2; //zero mvd bits |
---|
3328 | |
---|
3329 | m_pcRdCost->getMotionCost( 1, 0 ); |
---|
3330 | uiZeroMvdCostTemp = uiZeroMvdDistTemp + m_pcRdCost->getCost(uiZeroMvdBitsTemp); |
---|
3331 | |
---|
3332 | if (uiZeroMvdCostTemp < uiZeroMvdCost) |
---|
3333 | { |
---|
3334 | uiZeroMvdCost = uiZeroMvdCostTemp; |
---|
3335 | iZeroMvdDir = iRefList + 1; |
---|
3336 | aiZeroMvdRefIdx[iRefList] = iRefIdxTemp; |
---|
3337 | aiZeroMvdMvpIdx[iRefList] = aaiMvpIdx[iRefList][iRefIdxTemp]; |
---|
3338 | auiZeroMvdBits[iRefList] = uiZeroMvdBitsTemp; |
---|
3339 | } |
---|
3340 | } |
---|
3341 | #endif |
---|
3342 | |
---|
3343 | #if GPB_SIMPLE_UNI |
---|
3344 | if ( iRefList == 1 ) // list 1 |
---|
3345 | { |
---|
3346 | if ( pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp ) >= 0 ) |
---|
3347 | { |
---|
3348 | cMvTemp[1][iRefIdxTemp] = cMvTemp[0][pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp )]; |
---|
3349 | uiCostTemp = uiCostTempL0[pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp )]; |
---|
3350 | /*first subtract the bit-rate part of the cost of the other list*/ |
---|
3351 | uiCostTemp -= m_pcRdCost->getCost( uiBitsTempL0[pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp )] ); |
---|
3352 | /*correct the bit-rate part of the current ref*/ |
---|
3353 | m_pcRdCost->setPredictor ( cMvPred[iRefList][iRefIdxTemp] ); |
---|
3354 | uiBitsTemp += m_pcRdCost->getBits( cMvTemp[1][iRefIdxTemp].getHor(), cMvTemp[1][iRefIdxTemp].getVer() ); |
---|
3355 | /*calculate the correct cost*/ |
---|
3356 | uiCostTemp += m_pcRdCost->getCost( uiBitsTemp ); |
---|
3357 | } |
---|
3358 | else |
---|
3359 | { |
---|
3360 | xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp ); |
---|
3361 | } |
---|
3362 | } |
---|
3363 | else |
---|
3364 | { |
---|
3365 | xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp ); |
---|
3366 | } |
---|
3367 | #else |
---|
3368 | xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp ); |
---|
3369 | #endif |
---|
3370 | xCopyAMVPInfo(pcCU->getCUMvField(eRefPicList)->getAMVPInfo(), &aacAMVPInfo[iRefList][iRefIdxTemp]); // must always be done ( also when AMVP_MODE = AM_NONE ) |
---|
3371 | xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPred[iRefList][iRefIdxTemp], aaiMvpIdx[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp); |
---|
3372 | |
---|
3373 | if ( iRefList == 0 ) |
---|
3374 | { |
---|
3375 | uiCostTempL0[iRefIdxTemp] = uiCostTemp; |
---|
3376 | uiBitsTempL0[iRefIdxTemp] = uiBitsTemp; |
---|
3377 | } |
---|
3378 | if ( uiCostTemp < uiCost[iRefList] ) |
---|
3379 | { |
---|
3380 | uiCost[iRefList] = uiCostTemp; |
---|
3381 | uiBits[iRefList] = uiBitsTemp; // storing for bi-prediction |
---|
3382 | |
---|
3383 | // set motion |
---|
3384 | cMv[iRefList] = cMvTemp[iRefList][iRefIdxTemp]; |
---|
3385 | iRefIdx[iRefList] = iRefIdxTemp; |
---|
3386 | } |
---|
3387 | |
---|
3388 | if ( iRefList == 1 && uiCostTemp < costValidList1 && pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp ) < 0 ) |
---|
3389 | { |
---|
3390 | costValidList1 = uiCostTemp; |
---|
3391 | bitsValidList1 = uiBitsTemp; |
---|
3392 | |
---|
3393 | // set motion |
---|
3394 | mvValidList1 = cMvTemp[iRefList][iRefIdxTemp]; |
---|
3395 | refIdxValidList1 = iRefIdxTemp; |
---|
3396 | } |
---|
3397 | } |
---|
3398 | } |
---|
3399 | // Bi-directional prediction |
---|
3400 | #if REF_IDX_ME_ZEROMV |
---|
3401 | if ( (pcCU->getSlice()->isInterB()) && (pcCU->isBipredRestriction(iPartIdx) == false) && !(pcCU->getSlice()->getMvdL1ZeroFlag() && bestBiPDist == MAX_INT) ) |
---|
3402 | #else |
---|
3403 | if ( (pcCU->getSlice()->isInterB()) && (pcCU->isBipredRestriction(iPartIdx) == false) ) |
---|
3404 | #endif |
---|
3405 | { |
---|
3406 | |
---|
3407 | cMvBi[0] = cMv[0]; cMvBi[1] = cMv[1]; |
---|
3408 | iRefIdxBi[0] = iRefIdx[0]; iRefIdxBi[1] = iRefIdx[1]; |
---|
3409 | |
---|
3410 | ::memcpy(cMvPredBi, cMvPred, sizeof(cMvPred)); |
---|
3411 | ::memcpy(aaiMvpIdxBi, aaiMvpIdx, sizeof(aaiMvpIdx)); |
---|
3412 | |
---|
3413 | UInt uiMotBits[2]; |
---|
3414 | |
---|
3415 | if(pcCU->getSlice()->getMvdL1ZeroFlag()) |
---|
3416 | { |
---|
3417 | xCopyAMVPInfo(&aacAMVPInfo[1][bestBiPRefIdxL1], pcCU->getCUMvField(REF_PIC_LIST_1)->getAMVPInfo()); |
---|
3418 | pcCU->setMVPIdxSubParts( bestBiPMvpL1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3419 | aaiMvpIdxBi[1][bestBiPRefIdxL1] = bestBiPMvpL1; |
---|
3420 | cMvPredBi[1][bestBiPRefIdxL1] = pcCU->getCUMvField(REF_PIC_LIST_1)->getAMVPInfo()->m_acMvCand[bestBiPMvpL1]; |
---|
3421 | |
---|
3422 | cMvBi[1] = cMvPredBi[1][bestBiPRefIdxL1]; |
---|
3423 | iRefIdxBi[1] = bestBiPRefIdxL1; |
---|
3424 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( cMvBi[1], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3425 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( iRefIdxBi[1], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3426 | TComYuv* pcYuvPred = &m_acYuvPred[1]; |
---|
3427 | motionCompensation( pcCU, pcYuvPred, REF_PIC_LIST_1, iPartIdx ); |
---|
3428 | |
---|
3429 | uiMotBits[0] = uiBits[0] - uiMbBits[0]; |
---|
3430 | uiMotBits[1] = uiMbBits[1]; |
---|
3431 | |
---|
3432 | if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1) > 1 ) |
---|
3433 | { |
---|
3434 | uiMotBits[1] += bestBiPRefIdxL1+1; |
---|
3435 | if ( bestBiPRefIdxL1 == pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1)-1 ) uiMotBits[1]--; |
---|
3436 | } |
---|
3437 | |
---|
3438 | uiMotBits[1] += m_auiMVPIdxCost[aaiMvpIdxBi[1][bestBiPRefIdxL1]][AMVP_MAX_NUM_CANDS]; |
---|
3439 | |
---|
3440 | uiBits[2] = uiMbBits[2] + uiMotBits[0] + uiMotBits[1]; |
---|
3441 | |
---|
3442 | cMvTemp[1][bestBiPRefIdxL1] = cMvBi[1]; |
---|
3443 | } |
---|
3444 | else |
---|
3445 | { |
---|
3446 | uiMotBits[0] = uiBits[0] - uiMbBits[0]; |
---|
3447 | uiMotBits[1] = uiBits[1] - uiMbBits[1]; |
---|
3448 | uiBits[2] = uiMbBits[2] + uiMotBits[0] + uiMotBits[1]; |
---|
3449 | } |
---|
3450 | |
---|
3451 | // 4-times iteration (default) |
---|
3452 | Int iNumIter = 4; |
---|
3453 | |
---|
3454 | // fast encoder setting: only one iteration |
---|
3455 | if ( m_pcEncCfg->getUseFastEnc() || pcCU->getSlice()->getMvdL1ZeroFlag()) |
---|
3456 | { |
---|
3457 | iNumIter = 1; |
---|
3458 | } |
---|
3459 | |
---|
3460 | for ( Int iIter = 0; iIter < iNumIter; iIter++ ) |
---|
3461 | { |
---|
3462 | |
---|
3463 | Int iRefList = iIter % 2; |
---|
3464 | if ( m_pcEncCfg->getUseFastEnc() ) |
---|
3465 | { |
---|
3466 | if( uiCost[0] <= uiCost[1] ) |
---|
3467 | { |
---|
3468 | iRefList = 1; |
---|
3469 | } |
---|
3470 | else |
---|
3471 | { |
---|
3472 | iRefList = 0; |
---|
3473 | } |
---|
3474 | } |
---|
3475 | else if ( iIter == 0 ) |
---|
3476 | { |
---|
3477 | iRefList = 0; |
---|
3478 | } |
---|
3479 | if ( iIter == 0 && !pcCU->getSlice()->getMvdL1ZeroFlag()) |
---|
3480 | { |
---|
3481 | pcCU->getCUMvField(RefPicList(1-iRefList))->setAllMv( cMv[1-iRefList], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3482 | pcCU->getCUMvField(RefPicList(1-iRefList))->setAllRefIdx( iRefIdx[1-iRefList], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3483 | TComYuv* pcYuvPred = &m_acYuvPred[1-iRefList]; |
---|
3484 | motionCompensation ( pcCU, pcYuvPred, RefPicList(1-iRefList), iPartIdx ); |
---|
3485 | } |
---|
3486 | RefPicList eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); |
---|
3487 | |
---|
3488 | if(pcCU->getSlice()->getMvdL1ZeroFlag()) |
---|
3489 | { |
---|
3490 | iRefList = 0; |
---|
3491 | eRefPicList = REF_PIC_LIST_0; |
---|
3492 | } |
---|
3493 | |
---|
3494 | Bool bChanged = false; |
---|
3495 | |
---|
3496 | #if (ENCODER_FAST_MODE) |
---|
3497 | Bool testIter = true; |
---|
3498 | TComPic* pcPic = pcCU->getSlice()->getRefPic( RefPicList(1 - iRefList), iRefIdxBi[1 - iRefList] ); |
---|
3499 | if(pcPic->isILR(pcCU->getLayerId()) && (ePartSize == SIZE_2Nx2N)) |
---|
3500 | { |
---|
3501 | testIter = false; //the fixed part is ILR, skip this iteration |
---|
3502 | } |
---|
3503 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
3504 | if (pcPic->isILR(pcCU->getLayerId()) && m_disableILP) |
---|
3505 | { |
---|
3506 | testIter = false; |
---|
3507 | } |
---|
3508 | #endif |
---|
3509 | if(testIter) |
---|
3510 | { |
---|
3511 | #endif |
---|
3512 | iRefStart = 0; |
---|
3513 | iRefEnd = pcCU->getSlice()->getNumRefIdx(eRefPicList)-1; |
---|
3514 | |
---|
3515 | for ( Int iRefIdxTemp = iRefStart; iRefIdxTemp <= iRefEnd; iRefIdxTemp++ ) |
---|
3516 | { |
---|
3517 | #if (ENCODER_FAST_MODE) |
---|
3518 | Bool testRefIdx = true; |
---|
3519 | pcPic = pcCU->getSlice()->getRefPic( RefPicList(iRefList) , iRefIdxTemp ); |
---|
3520 | if(pcPic->isILR(pcCU->getLayerId()) && (ePartSize == SIZE_2Nx2N)) |
---|
3521 | { |
---|
3522 | testRefIdx = false; //the refined part is ILR, skip this reference pic |
---|
3523 | } |
---|
3524 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
3525 | if (pcPic->isILR(pcCU->getLayerId()) && m_disableILP) |
---|
3526 | { |
---|
3527 | testRefIdx = false; |
---|
3528 | } |
---|
3529 | #endif |
---|
3530 | if(testRefIdx) |
---|
3531 | { |
---|
3532 | #endif |
---|
3533 | uiBitsTemp = uiMbBits[2] + uiMotBits[1-iRefList]; |
---|
3534 | if ( pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1 ) |
---|
3535 | { |
---|
3536 | uiBitsTemp += iRefIdxTemp+1; |
---|
3537 | if ( iRefIdxTemp == pcCU->getSlice()->getNumRefIdx(eRefPicList)-1 ) uiBitsTemp--; |
---|
3538 | } |
---|
3539 | uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdxBi[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS]; |
---|
3540 | // call ME |
---|
3541 | xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPredBi[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp, true ); |
---|
3542 | xCopyAMVPInfo(&aacAMVPInfo[iRefList][iRefIdxTemp], pcCU->getCUMvField(eRefPicList)->getAMVPInfo()); |
---|
3543 | xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPredBi[iRefList][iRefIdxTemp], aaiMvpIdxBi[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp); |
---|
3544 | |
---|
3545 | if ( uiCostTemp < uiCostBi ) |
---|
3546 | { |
---|
3547 | bChanged = true; |
---|
3548 | |
---|
3549 | cMvBi[iRefList] = cMvTemp[iRefList][iRefIdxTemp]; |
---|
3550 | iRefIdxBi[iRefList] = iRefIdxTemp; |
---|
3551 | |
---|
3552 | uiCostBi = uiCostTemp; |
---|
3553 | uiMotBits[iRefList] = uiBitsTemp - uiMbBits[2] - uiMotBits[1-iRefList]; |
---|
3554 | uiBits[2] = uiBitsTemp; |
---|
3555 | |
---|
3556 | if(iNumIter!=1) |
---|
3557 | { |
---|
3558 | // Set motion |
---|
3559 | pcCU->getCUMvField( eRefPicList )->setAllMv( cMvBi[iRefList], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3560 | pcCU->getCUMvField( eRefPicList )->setAllRefIdx( iRefIdxBi[iRefList], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3561 | |
---|
3562 | TComYuv* pcYuvPred = &m_acYuvPred[iRefList]; |
---|
3563 | motionCompensation( pcCU, pcYuvPred, eRefPicList, iPartIdx ); |
---|
3564 | } |
---|
3565 | } |
---|
3566 | #if (ENCODER_FAST_MODE) |
---|
3567 | } |
---|
3568 | #endif |
---|
3569 | } |
---|
3570 | #if (ENCODER_FAST_MODE) |
---|
3571 | } // for loop-iRefIdxTemp |
---|
3572 | #endif |
---|
3573 | |
---|
3574 | if ( !bChanged ) |
---|
3575 | { |
---|
3576 | if ( uiCostBi <= uiCost[0] && uiCostBi <= uiCost[1] ) |
---|
3577 | { |
---|
3578 | xCopyAMVPInfo(&aacAMVPInfo[0][iRefIdxBi[0]], pcCU->getCUMvField(REF_PIC_LIST_0)->getAMVPInfo()); |
---|
3579 | xCheckBestMVP(pcCU, REF_PIC_LIST_0, cMvBi[0], cMvPredBi[0][iRefIdxBi[0]], aaiMvpIdxBi[0][iRefIdxBi[0]], uiBits[2], uiCostBi); |
---|
3580 | if(!pcCU->getSlice()->getMvdL1ZeroFlag()) |
---|
3581 | { |
---|
3582 | xCopyAMVPInfo(&aacAMVPInfo[1][iRefIdxBi[1]], pcCU->getCUMvField(REF_PIC_LIST_1)->getAMVPInfo()); |
---|
3583 | xCheckBestMVP(pcCU, REF_PIC_LIST_1, cMvBi[1], cMvPredBi[1][iRefIdxBi[1]], aaiMvpIdxBi[1][iRefIdxBi[1]], uiBits[2], uiCostBi); |
---|
3584 | } |
---|
3585 | } |
---|
3586 | break; |
---|
3587 | } |
---|
3588 | } // for loop-iter |
---|
3589 | } // if (B_SLICE) |
---|
3590 | #if ZERO_MVD_EST |
---|
3591 | if ( (pcCU->getSlice()->isInterB()) && (pcCU->isBipredRestriction(iPartIdx) == false) ) |
---|
3592 | { |
---|
3593 | m_pcRdCost->getMotionCost( 1, 0 ); |
---|
3594 | |
---|
3595 | for ( Int iL0RefIdxTemp = 0; iL0RefIdxTemp <= pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0)-1; iL0RefIdxTemp++ ) |
---|
3596 | for ( Int iL1RefIdxTemp = 0; iL1RefIdxTemp <= pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1)-1; iL1RefIdxTemp++ ) |
---|
3597 | { |
---|
3598 | UInt uiRefIdxBitsTemp = 0; |
---|
3599 | if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0) > 1 ) |
---|
3600 | { |
---|
3601 | uiRefIdxBitsTemp += iL0RefIdxTemp+1; |
---|
3602 | if ( iL0RefIdxTemp == pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0)-1 ) uiRefIdxBitsTemp--; |
---|
3603 | } |
---|
3604 | if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1) > 1 ) |
---|
3605 | { |
---|
3606 | uiRefIdxBitsTemp += iL1RefIdxTemp+1; |
---|
3607 | if ( iL1RefIdxTemp == pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1)-1 ) uiRefIdxBitsTemp--; |
---|
3608 | } |
---|
3609 | |
---|
3610 | Int iL0MVPIdx = 0; |
---|
3611 | Int iL1MVPIdx = 0; |
---|
3612 | |
---|
3613 | for (iL0MVPIdx = 0; iL0MVPIdx < aaiMvpNum[0][iL0RefIdxTemp]; iL0MVPIdx++) |
---|
3614 | { |
---|
3615 | for (iL1MVPIdx = 0; iL1MVPIdx < aaiMvpNum[1][iL1RefIdxTemp]; iL1MVPIdx++) |
---|
3616 | { |
---|
3617 | uiZeroMvdBitsTemp = uiRefIdxBitsTemp; |
---|
3618 | uiZeroMvdBitsTemp += uiMbBits[2]; |
---|
3619 | uiZeroMvdBitsTemp += m_auiMVPIdxCost[iL0MVPIdx][aaiMvpNum[0][iL0RefIdxTemp]] + m_auiMVPIdxCost[iL1MVPIdx][aaiMvpNum[1][iL1RefIdxTemp]]; |
---|
3620 | uiZeroMvdBitsTemp += 4; //zero mvd for both directions |
---|
3621 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( aacAMVPInfo[0][iL0RefIdxTemp].m_acMvCand[iL0MVPIdx], iL0RefIdxTemp, ePartSize, uiPartAddr, iPartIdx, 0 ); |
---|
3622 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( aacAMVPInfo[1][iL1RefIdxTemp].m_acMvCand[iL1MVPIdx], iL1RefIdxTemp, ePartSize, uiPartAddr, iPartIdx, 0 ); |
---|
3623 | |
---|
3624 | xGetInterPredictionError( pcCU, pcOrgYuv, iPartIdx, uiZeroMvdDistTemp, m_pcEncCfg->getUseHADME() ); |
---|
3625 | uiZeroMvdCostTemp = uiZeroMvdDistTemp + m_pcRdCost->getCost( uiZeroMvdBitsTemp ); |
---|
3626 | if (uiZeroMvdCostTemp < uiZeroMvdCost) |
---|
3627 | { |
---|
3628 | uiZeroMvdCost = uiZeroMvdCostTemp; |
---|
3629 | iZeroMvdDir = 3; |
---|
3630 | aiZeroMvdMvpIdx[0] = iL0MVPIdx; |
---|
3631 | aiZeroMvdMvpIdx[1] = iL1MVPIdx; |
---|
3632 | aiZeroMvdRefIdx[0] = iL0RefIdxTemp; |
---|
3633 | aiZeroMvdRefIdx[1] = iL1RefIdxTemp; |
---|
3634 | auiZeroMvdBits[2] = uiZeroMvdBitsTemp; |
---|
3635 | } |
---|
3636 | } |
---|
3637 | } |
---|
3638 | } |
---|
3639 | } |
---|
3640 | #endif |
---|
3641 | |
---|
3642 | #if AMP_MRG |
---|
3643 | } //end if bTestNormalMC |
---|
3644 | #endif |
---|
3645 | // Clear Motion Field |
---|
3646 | pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( TComMvField(), ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3647 | pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( TComMvField(), ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3648 | pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd ( cMvZero, ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3649 | pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd ( cMvZero, ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3650 | |
---|
3651 | pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3652 | pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3653 | pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3654 | pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3655 | |
---|
3656 | UInt uiMEBits = 0; |
---|
3657 | // Set Motion Field_ |
---|
3658 | cMv[1] = mvValidList1; |
---|
3659 | iRefIdx[1] = refIdxValidList1; |
---|
3660 | uiBits[1] = bitsValidList1; |
---|
3661 | uiCost[1] = costValidList1; |
---|
3662 | #if AMP_MRG |
---|
3663 | if (bTestNormalMC) |
---|
3664 | { |
---|
3665 | #endif |
---|
3666 | #if ZERO_MVD_EST |
---|
3667 | if (uiZeroMvdCost <= uiCostBi && uiZeroMvdCost <= uiCost[0] && uiZeroMvdCost <= uiCost[1]) |
---|
3668 | { |
---|
3669 | if (iZeroMvdDir == 3) |
---|
3670 | { |
---|
3671 | uiLastMode = 2; |
---|
3672 | |
---|
3673 | pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( aacAMVPInfo[0][aiZeroMvdRefIdx[0]].m_acMvCand[aiZeroMvdMvpIdx[0]], aiZeroMvdRefIdx[0], ePartSize, uiPartAddr, iPartIdx, 0 ); |
---|
3674 | pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( aacAMVPInfo[1][aiZeroMvdRefIdx[1]].m_acMvCand[aiZeroMvdMvpIdx[1]], aiZeroMvdRefIdx[1], ePartSize, uiPartAddr, iPartIdx, 0 ); |
---|
3675 | |
---|
3676 | pcCU->setInterDirSubParts( 3, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); |
---|
3677 | |
---|
3678 | pcCU->setMVPIdxSubParts( aiZeroMvdMvpIdx[0], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3679 | pcCU->setMVPNumSubParts( aaiMvpNum[0][aiZeroMvdRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3680 | pcCU->setMVPIdxSubParts( aiZeroMvdMvpIdx[1], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3681 | pcCU->setMVPNumSubParts( aaiMvpNum[1][aiZeroMvdRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3682 | uiMEBits = auiZeroMvdBits[2]; |
---|
3683 | } |
---|
3684 | else if (iZeroMvdDir == 1) |
---|
3685 | { |
---|
3686 | uiLastMode = 0; |
---|
3687 | |
---|
3688 | pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( aacAMVPInfo[0][aiZeroMvdRefIdx[0]].m_acMvCand[aiZeroMvdMvpIdx[0]], aiZeroMvdRefIdx[0], ePartSize, uiPartAddr, iPartIdx, 0 ); |
---|
3689 | |
---|
3690 | pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); |
---|
3691 | |
---|
3692 | pcCU->setMVPIdxSubParts( aiZeroMvdMvpIdx[0], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3693 | pcCU->setMVPNumSubParts( aaiMvpNum[0][aiZeroMvdRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3694 | uiMEBits = auiZeroMvdBits[0]; |
---|
3695 | } |
---|
3696 | else if (iZeroMvdDir == 2) |
---|
3697 | { |
---|
3698 | uiLastMode = 1; |
---|
3699 | |
---|
3700 | pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( aacAMVPInfo[1][aiZeroMvdRefIdx[1]].m_acMvCand[aiZeroMvdMvpIdx[1]], aiZeroMvdRefIdx[1], ePartSize, uiPartAddr, iPartIdx, 0 ); |
---|
3701 | |
---|
3702 | pcCU->setInterDirSubParts( 2, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); |
---|
3703 | |
---|
3704 | pcCU->setMVPIdxSubParts( aiZeroMvdMvpIdx[1], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3705 | pcCU->setMVPNumSubParts( aaiMvpNum[1][aiZeroMvdRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3706 | uiMEBits = auiZeroMvdBits[1]; |
---|
3707 | } |
---|
3708 | else |
---|
3709 | { |
---|
3710 | assert(0); |
---|
3711 | } |
---|
3712 | } |
---|
3713 | else |
---|
3714 | #endif |
---|
3715 | if ( uiCostBi <= uiCost[0] && uiCostBi <= uiCost[1]) |
---|
3716 | { |
---|
3717 | uiLastMode = 2; |
---|
3718 | { |
---|
3719 | pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMvBi[0], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3720 | pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdxBi[0], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3721 | pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMvBi[1], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3722 | pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdxBi[1], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3723 | } |
---|
3724 | { |
---|
3725 | TempMv = cMvBi[0] - cMvPredBi[0][iRefIdxBi[0]]; |
---|
3726 | pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3727 | } |
---|
3728 | { |
---|
3729 | TempMv = cMvBi[1] - cMvPredBi[1][iRefIdxBi[1]]; |
---|
3730 | pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3731 | } |
---|
3732 | |
---|
3733 | pcCU->setInterDirSubParts( 3, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); |
---|
3734 | |
---|
3735 | pcCU->setMVPIdxSubParts( aaiMvpIdxBi[0][iRefIdxBi[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3736 | pcCU->setMVPNumSubParts( aaiMvpNum[0][iRefIdxBi[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3737 | pcCU->setMVPIdxSubParts( aaiMvpIdxBi[1][iRefIdxBi[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3738 | pcCU->setMVPNumSubParts( aaiMvpNum[1][iRefIdxBi[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3739 | |
---|
3740 | uiMEBits = uiBits[2]; |
---|
3741 | } |
---|
3742 | else if ( uiCost[0] <= uiCost[1] ) |
---|
3743 | { |
---|
3744 | uiLastMode = 0; |
---|
3745 | pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMv[0], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3746 | pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdx[0], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3747 | { |
---|
3748 | TempMv = cMv[0] - cMvPred[0][iRefIdx[0]]; |
---|
3749 | pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3750 | } |
---|
3751 | pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); |
---|
3752 | |
---|
3753 | pcCU->setMVPIdxSubParts( aaiMvpIdx[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3754 | pcCU->setMVPNumSubParts( aaiMvpNum[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3755 | |
---|
3756 | uiMEBits = uiBits[0]; |
---|
3757 | } |
---|
3758 | else |
---|
3759 | { |
---|
3760 | uiLastMode = 1; |
---|
3761 | pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMv[1], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3762 | pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdx[1], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3763 | { |
---|
3764 | TempMv = cMv[1] - cMvPred[1][iRefIdx[1]]; |
---|
3765 | pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3766 | } |
---|
3767 | pcCU->setInterDirSubParts( 2, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); |
---|
3768 | |
---|
3769 | pcCU->setMVPIdxSubParts( aaiMvpIdx[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3770 | pcCU->setMVPNumSubParts( aaiMvpNum[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3771 | |
---|
3772 | uiMEBits = uiBits[1]; |
---|
3773 | } |
---|
3774 | #if AMP_MRG |
---|
3775 | } // end if bTestNormalMC |
---|
3776 | #endif |
---|
3777 | |
---|
3778 | if ( pcCU->getPartitionSize( uiPartAddr ) != SIZE_2Nx2N ) |
---|
3779 | { |
---|
3780 | UInt uiMRGInterDir = 0; |
---|
3781 | TComMvField cMRGMvField[2]; |
---|
3782 | UInt uiMRGIndex = 0; |
---|
3783 | |
---|
3784 | UInt uiMEInterDir = 0; |
---|
3785 | TComMvField cMEMvField[2]; |
---|
3786 | |
---|
3787 | m_pcRdCost->getMotionCost( 1, 0 ); |
---|
3788 | #if AMP_MRG |
---|
3789 | // calculate ME cost |
---|
3790 | UInt uiMEError = MAX_UINT; |
---|
3791 | UInt uiMECost = MAX_UINT; |
---|
3792 | |
---|
3793 | if (bTestNormalMC) |
---|
3794 | { |
---|
3795 | xGetInterPredictionError( pcCU, pcOrgYuv, iPartIdx, uiMEError, m_pcEncCfg->getUseHADME() ); |
---|
3796 | uiMECost = uiMEError + m_pcRdCost->getCost( uiMEBits ); |
---|
3797 | } |
---|
3798 | #else |
---|
3799 | // calculate ME cost |
---|
3800 | UInt uiMEError = MAX_UINT; |
---|
3801 | xGetInterPredictionError( pcCU, pcOrgYuv, iPartIdx, uiMEError, m_pcEncCfg->getUseHADME() ); |
---|
3802 | UInt uiMECost = uiMEError + m_pcRdCost->getCost( uiMEBits ); |
---|
3803 | #endif |
---|
3804 | // save ME result. |
---|
3805 | uiMEInterDir = pcCU->getInterDir( uiPartAddr ); |
---|
3806 | pcCU->getMvField( pcCU, uiPartAddr, REF_PIC_LIST_0, cMEMvField[0] ); |
---|
3807 | pcCU->getMvField( pcCU, uiPartAddr, REF_PIC_LIST_1, cMEMvField[1] ); |
---|
3808 | |
---|
3809 | // find Merge result |
---|
3810 | UInt uiMRGCost = MAX_UINT; |
---|
3811 | xMergeEstimation( pcCU, pcOrgYuv, iPartIdx, uiMRGInterDir, cMRGMvField, uiMRGIndex, uiMRGCost, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand); |
---|
3812 | if ( uiMRGCost < uiMECost ) |
---|
3813 | { |
---|
3814 | // set Merge result |
---|
3815 | pcCU->setMergeFlagSubParts ( true, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); |
---|
3816 | pcCU->setMergeIndexSubParts( uiMRGIndex, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); |
---|
3817 | pcCU->setInterDirSubParts ( uiMRGInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); |
---|
3818 | { |
---|
3819 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMRGMvField[0], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3820 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMRGMvField[1], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3821 | } |
---|
3822 | |
---|
3823 | pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd ( cMvZero, ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3824 | pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd ( cMvZero, ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3825 | |
---|
3826 | pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3827 | pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3828 | pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3829 | pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3830 | } |
---|
3831 | else |
---|
3832 | { |
---|
3833 | // set ME result |
---|
3834 | pcCU->setMergeFlagSubParts( false, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); |
---|
3835 | pcCU->setInterDirSubParts ( uiMEInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); |
---|
3836 | { |
---|
3837 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMEMvField[0], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3838 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMEMvField[1], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
3839 | } |
---|
3840 | } |
---|
3841 | } |
---|
3842 | |
---|
3843 | // MC |
---|
3844 | motionCompensation ( pcCU, rpcPredYuv, REF_PIC_LIST_X, iPartIdx ); |
---|
3845 | |
---|
3846 | } // end of for ( Int iPartIdx = 0; iPartIdx < iNumPart; iPartIdx++ ) |
---|
3847 | |
---|
3848 | setWpScalingDistParam( pcCU, -1, REF_PIC_LIST_X ); |
---|
3849 | |
---|
3850 | return; |
---|
3851 | } |
---|
3852 | |
---|
3853 | // AMVP |
---|
3854 | #if ZERO_MVD_EST |
---|
3855 | Void TEncSearch::xEstimateMvPredAMVP( TComDataCU* pcCU, TComYuv* pcOrgYuv, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMvPred, Bool bFilled, UInt* puiDistBiP, UInt* puiDist ) |
---|
3856 | #else |
---|
3857 | Void TEncSearch::xEstimateMvPredAMVP( TComDataCU* pcCU, TComYuv* pcOrgYuv, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMvPred, Bool bFilled, UInt* puiDistBiP ) |
---|
3858 | #endif |
---|
3859 | { |
---|
3860 | AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo(); |
---|
3861 | |
---|
3862 | TComMv cBestMv; |
---|
3863 | Int iBestIdx = 0; |
---|
3864 | TComMv cZeroMv; |
---|
3865 | TComMv cMvPred; |
---|
3866 | UInt uiBestCost = MAX_INT; |
---|
3867 | UInt uiPartAddr = 0; |
---|
3868 | Int iRoiWidth, iRoiHeight; |
---|
3869 | Int i; |
---|
3870 | |
---|
3871 | pcCU->getPartIndexAndSize( uiPartIdx, uiPartAddr, iRoiWidth, iRoiHeight ); |
---|
3872 | // Fill the MV Candidates |
---|
3873 | if (!bFilled) |
---|
3874 | { |
---|
3875 | pcCU->fillMvpCand( uiPartIdx, uiPartAddr, eRefPicList, iRefIdx, pcAMVPInfo ); |
---|
3876 | } |
---|
3877 | |
---|
3878 | // initialize Mvp index & Mvp |
---|
3879 | iBestIdx = 0; |
---|
3880 | cBestMv = pcAMVPInfo->m_acMvCand[0]; |
---|
3881 | #if !ZERO_MVD_EST |
---|
3882 | if (pcAMVPInfo->iN <= 1) |
---|
3883 | { |
---|
3884 | rcMvPred = cBestMv; |
---|
3885 | |
---|
3886 | pcCU->setMVPIdxSubParts( iBestIdx, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3887 | pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3888 | |
---|
3889 | if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefPicList==REF_PIC_LIST_1) |
---|
3890 | { |
---|
3891 | #if ZERO_MVD_EST |
---|
3892 | (*puiDistBiP) = xGetTemplateCost( pcCU, uiPartIdx, uiPartAddr, pcOrgYuv, &m_cYuvPredTemp, rcMvPred, 0, AMVP_MAX_NUM_CANDS, eRefPicList, iRefIdx, iRoiWidth, iRoiHeight, uiDist ); |
---|
3893 | #else |
---|
3894 | (*puiDistBiP) = xGetTemplateCost( pcCU, uiPartIdx, uiPartAddr, pcOrgYuv, &m_cYuvPredTemp, rcMvPred, 0, AMVP_MAX_NUM_CANDS, eRefPicList, iRefIdx, iRoiWidth, iRoiHeight); |
---|
3895 | #endif |
---|
3896 | } |
---|
3897 | return; |
---|
3898 | } |
---|
3899 | #endif |
---|
3900 | if (bFilled) |
---|
3901 | { |
---|
3902 | assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0); |
---|
3903 | rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)]; |
---|
3904 | return; |
---|
3905 | } |
---|
3906 | |
---|
3907 | m_cYuvPredTemp.clear(); |
---|
3908 | #if ZERO_MVD_EST |
---|
3909 | UInt uiDist; |
---|
3910 | #endif |
---|
3911 | //-- Check Minimum Cost. |
---|
3912 | for ( i = 0 ; i < pcAMVPInfo->iN; i++) |
---|
3913 | { |
---|
3914 | UInt uiTmpCost; |
---|
3915 | #if ZERO_MVD_EST |
---|
3916 | uiTmpCost = xGetTemplateCost( pcCU, uiPartIdx, uiPartAddr, pcOrgYuv, &m_cYuvPredTemp, pcAMVPInfo->m_acMvCand[i], i, AMVP_MAX_NUM_CANDS, eRefPicList, iRefIdx, iRoiWidth, iRoiHeight, uiDist ); |
---|
3917 | #else |
---|
3918 | uiTmpCost = xGetTemplateCost( pcCU, uiPartIdx, uiPartAddr, pcOrgYuv, &m_cYuvPredTemp, pcAMVPInfo->m_acMvCand[i], i, AMVP_MAX_NUM_CANDS, eRefPicList, iRefIdx, iRoiWidth, iRoiHeight); |
---|
3919 | #endif |
---|
3920 | if ( uiBestCost > uiTmpCost ) |
---|
3921 | { |
---|
3922 | uiBestCost = uiTmpCost; |
---|
3923 | cBestMv = pcAMVPInfo->m_acMvCand[i]; |
---|
3924 | iBestIdx = i; |
---|
3925 | (*puiDistBiP) = uiTmpCost; |
---|
3926 | #if ZERO_MVD_EST |
---|
3927 | (*puiDist) = uiDist; |
---|
3928 | #endif |
---|
3929 | } |
---|
3930 | } |
---|
3931 | |
---|
3932 | m_cYuvPredTemp.clear(); |
---|
3933 | |
---|
3934 | // Setting Best MVP |
---|
3935 | rcMvPred = cBestMv; |
---|
3936 | pcCU->setMVPIdxSubParts( iBestIdx, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3937 | pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
3938 | return; |
---|
3939 | } |
---|
3940 | |
---|
3941 | UInt TEncSearch::xGetMvpIdxBits(Int iIdx, Int iNum) |
---|
3942 | { |
---|
3943 | assert(iIdx >= 0 && iNum >= 0 && iIdx < iNum); |
---|
3944 | |
---|
3945 | if (iNum == 1) |
---|
3946 | return 0; |
---|
3947 | |
---|
3948 | UInt uiLength = 1; |
---|
3949 | Int iTemp = iIdx; |
---|
3950 | if ( iTemp == 0 ) |
---|
3951 | { |
---|
3952 | return uiLength; |
---|
3953 | } |
---|
3954 | |
---|
3955 | Bool bCodeLast = ( iNum-1 > iTemp ); |
---|
3956 | |
---|
3957 | uiLength += (iTemp-1); |
---|
3958 | |
---|
3959 | if( bCodeLast ) |
---|
3960 | { |
---|
3961 | uiLength++; |
---|
3962 | } |
---|
3963 | |
---|
3964 | return uiLength; |
---|
3965 | } |
---|
3966 | |
---|
3967 | Void TEncSearch::xGetBlkBits( PartSize eCUMode, Bool bPSlice, Int iPartIdx, UInt uiLastMode, UInt uiBlkBit[3]) |
---|
3968 | { |
---|
3969 | if ( eCUMode == SIZE_2Nx2N ) |
---|
3970 | { |
---|
3971 | uiBlkBit[0] = (! bPSlice) ? 3 : 1; |
---|
3972 | uiBlkBit[1] = 3; |
---|
3973 | uiBlkBit[2] = 5; |
---|
3974 | } |
---|
3975 | else if ( (eCUMode == SIZE_2NxN || eCUMode == SIZE_2NxnU) || eCUMode == SIZE_2NxnD ) |
---|
3976 | { |
---|
3977 | UInt aauiMbBits[2][3][3] = { { {0,0,3}, {0,0,0}, {0,0,0} } , { {5,7,7}, {7,5,7}, {9-3,9-3,9-3} } }; |
---|
3978 | if ( bPSlice ) |
---|
3979 | { |
---|
3980 | uiBlkBit[0] = 3; |
---|
3981 | uiBlkBit[1] = 0; |
---|
3982 | uiBlkBit[2] = 0; |
---|
3983 | } |
---|
3984 | else |
---|
3985 | { |
---|
3986 | ::memcpy( uiBlkBit, aauiMbBits[iPartIdx][uiLastMode], 3*sizeof(UInt) ); |
---|
3987 | } |
---|
3988 | } |
---|
3989 | else if ( (eCUMode == SIZE_Nx2N || eCUMode == SIZE_nLx2N) || eCUMode == SIZE_nRx2N ) |
---|
3990 | { |
---|
3991 | UInt aauiMbBits[2][3][3] = { { {0,2,3}, {0,0,0}, {0,0,0} } , { {5,7,7}, {7-2,7-2,9-2}, {9-3,9-3,9-3} } }; |
---|
3992 | if ( bPSlice ) |
---|
3993 | { |
---|
3994 | uiBlkBit[0] = 3; |
---|
3995 | uiBlkBit[1] = 0; |
---|
3996 | uiBlkBit[2] = 0; |
---|
3997 | } |
---|
3998 | else |
---|
3999 | { |
---|
4000 | ::memcpy( uiBlkBit, aauiMbBits[iPartIdx][uiLastMode], 3*sizeof(UInt) ); |
---|
4001 | } |
---|
4002 | } |
---|
4003 | else if ( eCUMode == SIZE_NxN ) |
---|
4004 | { |
---|
4005 | uiBlkBit[0] = (! bPSlice) ? 3 : 1; |
---|
4006 | uiBlkBit[1] = 3; |
---|
4007 | uiBlkBit[2] = 5; |
---|
4008 | } |
---|
4009 | else |
---|
4010 | { |
---|
4011 | printf("Wrong!\n"); |
---|
4012 | assert( 0 ); |
---|
4013 | } |
---|
4014 | } |
---|
4015 | |
---|
4016 | Void TEncSearch::xCopyAMVPInfo (AMVPInfo* pSrc, AMVPInfo* pDst) |
---|
4017 | { |
---|
4018 | pDst->iN = pSrc->iN; |
---|
4019 | for (Int i = 0; i < pSrc->iN; i++) |
---|
4020 | { |
---|
4021 | pDst->m_acMvCand[i] = pSrc->m_acMvCand[i]; |
---|
4022 | } |
---|
4023 | } |
---|
4024 | |
---|
4025 | Void TEncSearch::xCheckBestMVP ( TComDataCU* pcCU, RefPicList eRefPicList, TComMv cMv, TComMv& rcMvPred, Int& riMVPIdx, UInt& ruiBits, UInt& ruiCost ) |
---|
4026 | { |
---|
4027 | AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo(); |
---|
4028 | |
---|
4029 | assert(pcAMVPInfo->m_acMvCand[riMVPIdx] == rcMvPred); |
---|
4030 | |
---|
4031 | if (pcAMVPInfo->iN < 2) return; |
---|
4032 | |
---|
4033 | m_pcRdCost->getMotionCost( 1, 0 ); |
---|
4034 | m_pcRdCost->setCostScale ( 0 ); |
---|
4035 | |
---|
4036 | Int iBestMVPIdx = riMVPIdx; |
---|
4037 | |
---|
4038 | m_pcRdCost->setPredictor( rcMvPred ); |
---|
4039 | Int iOrgMvBits = m_pcRdCost->getBits(cMv.getHor(), cMv.getVer()); |
---|
4040 | iOrgMvBits += m_auiMVPIdxCost[riMVPIdx][AMVP_MAX_NUM_CANDS]; |
---|
4041 | Int iBestMvBits = iOrgMvBits; |
---|
4042 | |
---|
4043 | for (Int iMVPIdx = 0; iMVPIdx < pcAMVPInfo->iN; iMVPIdx++) |
---|
4044 | { |
---|
4045 | if (iMVPIdx == riMVPIdx) continue; |
---|
4046 | |
---|
4047 | m_pcRdCost->setPredictor( pcAMVPInfo->m_acMvCand[iMVPIdx] ); |
---|
4048 | |
---|
4049 | Int iMvBits = m_pcRdCost->getBits(cMv.getHor(), cMv.getVer()); |
---|
4050 | iMvBits += m_auiMVPIdxCost[iMVPIdx][AMVP_MAX_NUM_CANDS]; |
---|
4051 | |
---|
4052 | if (iMvBits < iBestMvBits) |
---|
4053 | { |
---|
4054 | iBestMvBits = iMvBits; |
---|
4055 | iBestMVPIdx = iMVPIdx; |
---|
4056 | } |
---|
4057 | } |
---|
4058 | |
---|
4059 | if (iBestMVPIdx != riMVPIdx) //if changed |
---|
4060 | { |
---|
4061 | rcMvPred = pcAMVPInfo->m_acMvCand[iBestMVPIdx]; |
---|
4062 | |
---|
4063 | riMVPIdx = iBestMVPIdx; |
---|
4064 | UInt uiOrgBits = ruiBits; |
---|
4065 | ruiBits = uiOrgBits - iOrgMvBits + iBestMvBits; |
---|
4066 | ruiCost = (ruiCost - m_pcRdCost->getCost( uiOrgBits )) + m_pcRdCost->getCost( ruiBits ); |
---|
4067 | } |
---|
4068 | } |
---|
4069 | |
---|
4070 | UInt TEncSearch::xGetTemplateCost( TComDataCU* pcCU, |
---|
4071 | UInt uiPartIdx, |
---|
4072 | UInt uiPartAddr, |
---|
4073 | TComYuv* pcOrgYuv, |
---|
4074 | TComYuv* pcTemplateCand, |
---|
4075 | TComMv cMvCand, |
---|
4076 | Int iMVPIdx, |
---|
4077 | Int iMVPNum, |
---|
4078 | RefPicList eRefPicList, |
---|
4079 | Int iRefIdx, |
---|
4080 | Int iSizeX, |
---|
4081 | Int iSizeY |
---|
4082 | #if ZERO_MVD_EST |
---|
4083 | , UInt& ruiDist |
---|
4084 | #endif |
---|
4085 | ) |
---|
4086 | { |
---|
4087 | UInt uiCost = MAX_INT; |
---|
4088 | |
---|
4089 | TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(); |
---|
4090 | |
---|
4091 | pcCU->clipMv( cMvCand ); |
---|
4092 | |
---|
4093 | // prediction pattern |
---|
4094 | #if O0194_WEIGHTED_PREDICTION_CGS |
---|
4095 | // Bug Fix (It did not check WP for BSlices) |
---|
4096 | if ( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
4097 | #else |
---|
4098 | if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType()==P_SLICE ) |
---|
4099 | #endif |
---|
4100 | { |
---|
4101 | xPredInterLumaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMvCand, iSizeX, iSizeY, pcTemplateCand, true ); |
---|
4102 | } |
---|
4103 | else |
---|
4104 | { |
---|
4105 | xPredInterLumaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMvCand, iSizeX, iSizeY, pcTemplateCand, false ); |
---|
4106 | } |
---|
4107 | |
---|
4108 | #if O0194_WEIGHTED_PREDICTION_CGS |
---|
4109 | if ( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
4110 | ///< Bug Fix (It did not check WP for BSlices) |
---|
4111 | #else |
---|
4112 | if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType()==P_SLICE ) |
---|
4113 | #endif |
---|
4114 | { |
---|
4115 | xWeightedPredictionUni( pcCU, pcTemplateCand, uiPartAddr, iSizeX, iSizeY, eRefPicList, pcTemplateCand, iRefIdx ); |
---|
4116 | } |
---|
4117 | |
---|
4118 | // calc distortion |
---|
4119 | #if ZERO_MVD_EST |
---|
4120 | m_pcRdCost->getMotionCost( 1, 0 ); |
---|
4121 | DistParam cDistParam; |
---|
4122 | m_pcRdCost->setDistParam( cDistParam, g_bitDepthY, |
---|
4123 | pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(), |
---|
4124 | pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(), |
---|
4125 | #if NS_HAD |
---|
4126 | iSizeX, iSizeY, m_pcEncCfg->getUseHADME(), m_pcEncCfg->getUseNSQT() ); |
---|
4127 | #else |
---|
4128 | iSizeX, iSizeY, m_pcEncCfg->getUseHADME() ); |
---|
4129 | #endif |
---|
4130 | ruiDist = cDistParam.DistFunc( &cDistParam ); |
---|
4131 | uiCost = ruiDist + m_pcRdCost->getCost( m_auiMVPIdxCost[iMVPIdx][iMVPNum] ); |
---|
4132 | #else |
---|
4133 | #if WEIGHTED_CHROMA_DISTORTION |
---|
4134 | uiCost = m_pcRdCost->getDistPart(g_bitDepthY, pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(), pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(), iSizeX, iSizeY, TEXT_LUMA, DF_SAD ); |
---|
4135 | #else |
---|
4136 | uiCost = m_pcRdCost->getDistPart(g_bitDepthY, pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(), pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(), iSizeX, iSizeY, DF_SAD ); |
---|
4137 | #endif |
---|
4138 | uiCost = (UInt) m_pcRdCost->calcRdCost( m_auiMVPIdxCost[iMVPIdx][iMVPNum], uiCost, false, DF_SAD ); |
---|
4139 | #endif |
---|
4140 | return uiCost; |
---|
4141 | } |
---|
4142 | |
---|
4143 | Void TEncSearch::xMotionEstimation( TComDataCU* pcCU, TComYuv* pcYuvOrg, Int iPartIdx, RefPicList eRefPicList, TComMv* pcMvPred, Int iRefIdxPred, TComMv& rcMv, UInt& ruiBits, UInt& ruiCost, Bool bBi ) |
---|
4144 | { |
---|
4145 | UInt uiPartAddr; |
---|
4146 | Int iRoiWidth; |
---|
4147 | Int iRoiHeight; |
---|
4148 | |
---|
4149 | TComMv cMvHalf, cMvQter; |
---|
4150 | TComMv cMvSrchRngLT; |
---|
4151 | TComMv cMvSrchRngRB; |
---|
4152 | |
---|
4153 | TComYuv* pcYuv = pcYuvOrg; |
---|
4154 | m_iSearchRange = m_aaiAdaptSR[eRefPicList][iRefIdxPred]; |
---|
4155 | |
---|
4156 | Int iSrchRng = ( bBi ? m_bipredSearchRange : m_iSearchRange ); |
---|
4157 | TComPattern* pcPatternKey = pcCU->getPattern (); |
---|
4158 | |
---|
4159 | Double fWeight = 1.0; |
---|
4160 | |
---|
4161 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iRoiWidth, iRoiHeight ); |
---|
4162 | |
---|
4163 | if ( bBi ) |
---|
4164 | { |
---|
4165 | TComYuv* pcYuvOther = &m_acYuvPred[1-(Int)eRefPicList]; |
---|
4166 | pcYuv = &m_cYuvPredTemp; |
---|
4167 | |
---|
4168 | pcYuvOrg->copyPartToPartYuv( pcYuv, uiPartAddr, iRoiWidth, iRoiHeight ); |
---|
4169 | |
---|
4170 | pcYuv->removeHighFreq( pcYuvOther, uiPartAddr, iRoiWidth, iRoiHeight ); |
---|
4171 | |
---|
4172 | fWeight = 0.5; |
---|
4173 | } |
---|
4174 | |
---|
4175 | // Search key pattern initialization |
---|
4176 | pcPatternKey->initPattern( pcYuv->getLumaAddr( uiPartAddr ), |
---|
4177 | pcYuv->getCbAddr ( uiPartAddr ), |
---|
4178 | pcYuv->getCrAddr ( uiPartAddr ), |
---|
4179 | iRoiWidth, |
---|
4180 | iRoiHeight, |
---|
4181 | pcYuv->getStride(), |
---|
4182 | 0, 0 ); |
---|
4183 | |
---|
4184 | Pel* piRefY = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxPred )->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ); |
---|
4185 | Int iRefStride = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxPred )->getPicYuvRec()->getStride(); |
---|
4186 | |
---|
4187 | TComMv cMvPred = *pcMvPred; |
---|
4188 | |
---|
4189 | if ( bBi ) xSetSearchRange ( pcCU, rcMv , iSrchRng, cMvSrchRngLT, cMvSrchRngRB ); |
---|
4190 | else xSetSearchRange ( pcCU, cMvPred, iSrchRng, cMvSrchRngLT, cMvSrchRngRB ); |
---|
4191 | |
---|
4192 | m_pcRdCost->getMotionCost ( 1, 0 ); |
---|
4193 | |
---|
4194 | m_pcRdCost->setPredictor ( *pcMvPred ); |
---|
4195 | m_pcRdCost->setCostScale ( 2 ); |
---|
4196 | |
---|
4197 | setWpScalingDistParam( pcCU, iRefIdxPred, eRefPicList ); |
---|
4198 | // Do integer search |
---|
4199 | #if REF_IDX_ME_ZEROMV |
---|
4200 | if( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxPred )->isILR(pcCU->getLayerId())) //ILR reference pic |
---|
4201 | { |
---|
4202 | rcMv.setZero(); //use Mv(0, 0) for integer ME |
---|
4203 | } |
---|
4204 | else //non ILR reference pic |
---|
4205 | { |
---|
4206 | if ( !m_iFastSearch || bBi ) |
---|
4207 | { |
---|
4208 | xPatternSearch ( pcPatternKey, piRefY, iRefStride, &cMvSrchRngLT, &cMvSrchRngRB, rcMv, ruiCost ); |
---|
4209 | } |
---|
4210 | else |
---|
4211 | { |
---|
4212 | rcMv = *pcMvPred; |
---|
4213 | xPatternSearchFast ( pcCU, pcPatternKey, piRefY, iRefStride, &cMvSrchRngLT, &cMvSrchRngRB, rcMv, ruiCost ); |
---|
4214 | } |
---|
4215 | } |
---|
4216 | #else |
---|
4217 | if ( !m_iFastSearch || bBi ) |
---|
4218 | { |
---|
4219 | xPatternSearch ( pcPatternKey, piRefY, iRefStride, &cMvSrchRngLT, &cMvSrchRngRB, rcMv, ruiCost ); |
---|
4220 | } |
---|
4221 | else |
---|
4222 | { |
---|
4223 | rcMv = *pcMvPred; |
---|
4224 | xPatternSearchFast ( pcCU, pcPatternKey, piRefY, iRefStride, &cMvSrchRngLT, &cMvSrchRngRB, rcMv, ruiCost ); |
---|
4225 | } |
---|
4226 | #endif |
---|
4227 | |
---|
4228 | m_pcRdCost->getMotionCost( 1, 0 ); |
---|
4229 | m_pcRdCost->setCostScale ( 1 ); |
---|
4230 | |
---|
4231 | { |
---|
4232 | #if REF_IDX_ME_ZEROMV |
---|
4233 | if( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxPred )->isILR(pcCU->getLayerId())) //ILR reference pic |
---|
4234 | { |
---|
4235 | xPatternSearchFracDIFMv0( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost, bBi ); |
---|
4236 | } |
---|
4237 | else //non ILR reference pic |
---|
4238 | { |
---|
4239 | xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost, bBi ); |
---|
4240 | } |
---|
4241 | #else |
---|
4242 | xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost |
---|
4243 | ,bBi |
---|
4244 | ); |
---|
4245 | #endif |
---|
4246 | } |
---|
4247 | |
---|
4248 | |
---|
4249 | |
---|
4250 | m_pcRdCost->setCostScale( 0 ); |
---|
4251 | rcMv <<= 2; |
---|
4252 | rcMv += (cMvHalf <<= 1); |
---|
4253 | rcMv += cMvQter; |
---|
4254 | |
---|
4255 | UInt uiMvBits = m_pcRdCost->getBits( rcMv.getHor(), rcMv.getVer() ); |
---|
4256 | |
---|
4257 | ruiBits += uiMvBits; |
---|
4258 | ruiCost = (UInt)( floor( fWeight * ( (Double)ruiCost - (Double)m_pcRdCost->getCost( uiMvBits ) ) ) + (Double)m_pcRdCost->getCost( ruiBits ) ); |
---|
4259 | } |
---|
4260 | |
---|
4261 | |
---|
4262 | Void TEncSearch::xSetSearchRange ( TComDataCU* pcCU, TComMv& cMvPred, Int iSrchRng, TComMv& rcMvSrchRngLT, TComMv& rcMvSrchRngRB ) |
---|
4263 | { |
---|
4264 | Int iMvShift = 2; |
---|
4265 | TComMv cTmpMvPred = cMvPred; |
---|
4266 | pcCU->clipMv( cTmpMvPred ); |
---|
4267 | |
---|
4268 | rcMvSrchRngLT.setHor( cTmpMvPred.getHor() - (iSrchRng << iMvShift) ); |
---|
4269 | rcMvSrchRngLT.setVer( cTmpMvPred.getVer() - (iSrchRng << iMvShift) ); |
---|
4270 | |
---|
4271 | rcMvSrchRngRB.setHor( cTmpMvPred.getHor() + (iSrchRng << iMvShift) ); |
---|
4272 | rcMvSrchRngRB.setVer( cTmpMvPred.getVer() + (iSrchRng << iMvShift) ); |
---|
4273 | pcCU->clipMv ( rcMvSrchRngLT ); |
---|
4274 | pcCU->clipMv ( rcMvSrchRngRB ); |
---|
4275 | |
---|
4276 | rcMvSrchRngLT >>= iMvShift; |
---|
4277 | rcMvSrchRngRB >>= iMvShift; |
---|
4278 | } |
---|
4279 | |
---|
4280 | Void TEncSearch::xPatternSearch( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, TComMv* pcMvSrchRngLT, TComMv* pcMvSrchRngRB, TComMv& rcMv, UInt& ruiSAD ) |
---|
4281 | { |
---|
4282 | Int iSrchRngHorLeft = pcMvSrchRngLT->getHor(); |
---|
4283 | Int iSrchRngHorRight = pcMvSrchRngRB->getHor(); |
---|
4284 | Int iSrchRngVerTop = pcMvSrchRngLT->getVer(); |
---|
4285 | Int iSrchRngVerBottom = pcMvSrchRngRB->getVer(); |
---|
4286 | |
---|
4287 | UInt uiSad; |
---|
4288 | UInt uiSadBest = MAX_UINT; |
---|
4289 | Int iBestX = 0; |
---|
4290 | Int iBestY = 0; |
---|
4291 | |
---|
4292 | Pel* piRefSrch; |
---|
4293 | |
---|
4294 | //-- jclee for using the SAD function pointer |
---|
4295 | m_pcRdCost->setDistParam( pcPatternKey, piRefY, iRefStride, m_cDistParam ); |
---|
4296 | |
---|
4297 | // fast encoder decision: use subsampled SAD for integer ME |
---|
4298 | if ( m_pcEncCfg->getUseFastEnc() ) |
---|
4299 | { |
---|
4300 | if ( m_cDistParam.iRows > 8 ) |
---|
4301 | { |
---|
4302 | m_cDistParam.iSubShift = 1; |
---|
4303 | } |
---|
4304 | } |
---|
4305 | |
---|
4306 | piRefY += (iSrchRngVerTop * iRefStride); |
---|
4307 | for ( Int y = iSrchRngVerTop; y <= iSrchRngVerBottom; y++ ) |
---|
4308 | { |
---|
4309 | for ( Int x = iSrchRngHorLeft; x <= iSrchRngHorRight; x++ ) |
---|
4310 | { |
---|
4311 | // find min. distortion position |
---|
4312 | piRefSrch = piRefY + x; |
---|
4313 | m_cDistParam.pCur = piRefSrch; |
---|
4314 | |
---|
4315 | setDistParamComp(0); |
---|
4316 | |
---|
4317 | m_cDistParam.bitDepth = g_bitDepthY; |
---|
4318 | uiSad = m_cDistParam.DistFunc( &m_cDistParam ); |
---|
4319 | |
---|
4320 | // motion cost |
---|
4321 | uiSad += m_pcRdCost->getCost( x, y ); |
---|
4322 | |
---|
4323 | if ( uiSad < uiSadBest ) |
---|
4324 | { |
---|
4325 | uiSadBest = uiSad; |
---|
4326 | iBestX = x; |
---|
4327 | iBestY = y; |
---|
4328 | } |
---|
4329 | } |
---|
4330 | piRefY += iRefStride; |
---|
4331 | } |
---|
4332 | |
---|
4333 | rcMv.set( iBestX, iBestY ); |
---|
4334 | |
---|
4335 | ruiSAD = uiSadBest - m_pcRdCost->getCost( iBestX, iBestY ); |
---|
4336 | return; |
---|
4337 | } |
---|
4338 | |
---|
4339 | Void TEncSearch::xPatternSearchFast( TComDataCU* pcCU, TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, TComMv* pcMvSrchRngLT, TComMv* pcMvSrchRngRB, TComMv& rcMv, UInt& ruiSAD ) |
---|
4340 | { |
---|
4341 | pcCU->getMvPredLeft ( m_acMvPredictors[0] ); |
---|
4342 | pcCU->getMvPredAbove ( m_acMvPredictors[1] ); |
---|
4343 | pcCU->getMvPredAboveRight ( m_acMvPredictors[2] ); |
---|
4344 | |
---|
4345 | switch ( m_iFastSearch ) |
---|
4346 | { |
---|
4347 | case 1: |
---|
4348 | xTZSearch( pcCU, pcPatternKey, piRefY, iRefStride, pcMvSrchRngLT, pcMvSrchRngRB, rcMv, ruiSAD ); |
---|
4349 | break; |
---|
4350 | |
---|
4351 | default: |
---|
4352 | break; |
---|
4353 | } |
---|
4354 | } |
---|
4355 | |
---|
4356 | Void TEncSearch::xTZSearch( TComDataCU* pcCU, TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, TComMv* pcMvSrchRngLT, TComMv* pcMvSrchRngRB, TComMv& rcMv, UInt& ruiSAD ) |
---|
4357 | { |
---|
4358 | Int iSrchRngHorLeft = pcMvSrchRngLT->getHor(); |
---|
4359 | Int iSrchRngHorRight = pcMvSrchRngRB->getHor(); |
---|
4360 | Int iSrchRngVerTop = pcMvSrchRngLT->getVer(); |
---|
4361 | Int iSrchRngVerBottom = pcMvSrchRngRB->getVer(); |
---|
4362 | |
---|
4363 | TZ_SEARCH_CONFIGURATION |
---|
4364 | |
---|
4365 | UInt uiSearchRange = m_iSearchRange; |
---|
4366 | pcCU->clipMv( rcMv ); |
---|
4367 | rcMv >>= 2; |
---|
4368 | // init TZSearchStruct |
---|
4369 | IntTZSearchStruct cStruct; |
---|
4370 | cStruct.iYStride = iRefStride; |
---|
4371 | cStruct.piRefY = piRefY; |
---|
4372 | cStruct.uiBestSad = MAX_UINT; |
---|
4373 | |
---|
4374 | // set rcMv (Median predictor) as start point and as best point |
---|
4375 | xTZSearchHelp( pcPatternKey, cStruct, rcMv.getHor(), rcMv.getVer(), 0, 0 ); |
---|
4376 | |
---|
4377 | // test whether one of PRED_A, PRED_B, PRED_C MV is better start point than Median predictor |
---|
4378 | if ( bTestOtherPredictedMV ) |
---|
4379 | { |
---|
4380 | for ( UInt index = 0; index < 3; index++ ) |
---|
4381 | { |
---|
4382 | TComMv cMv = m_acMvPredictors[index]; |
---|
4383 | pcCU->clipMv( cMv ); |
---|
4384 | cMv >>= 2; |
---|
4385 | xTZSearchHelp( pcPatternKey, cStruct, cMv.getHor(), cMv.getVer(), 0, 0 ); |
---|
4386 | } |
---|
4387 | } |
---|
4388 | |
---|
4389 | // test whether zero Mv is better start point than Median predictor |
---|
4390 | if ( bTestZeroVector ) |
---|
4391 | { |
---|
4392 | xTZSearchHelp( pcPatternKey, cStruct, 0, 0, 0, 0 ); |
---|
4393 | } |
---|
4394 | |
---|
4395 | // start search |
---|
4396 | Int iDist = 0; |
---|
4397 | Int iStartX = cStruct.iBestX; |
---|
4398 | Int iStartY = cStruct.iBestY; |
---|
4399 | |
---|
4400 | // first search |
---|
4401 | for ( iDist = 1; iDist <= (Int)uiSearchRange; iDist*=2 ) |
---|
4402 | { |
---|
4403 | if ( bFirstSearchDiamond == 1 ) |
---|
4404 | { |
---|
4405 | xTZ8PointDiamondSearch ( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB, iStartX, iStartY, iDist ); |
---|
4406 | } |
---|
4407 | else |
---|
4408 | { |
---|
4409 | xTZ8PointSquareSearch ( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB, iStartX, iStartY, iDist ); |
---|
4410 | } |
---|
4411 | |
---|
4412 | if ( bFirstSearchStop && ( cStruct.uiBestRound >= uiFirstSearchRounds ) ) // stop criterion |
---|
4413 | { |
---|
4414 | break; |
---|
4415 | } |
---|
4416 | } |
---|
4417 | |
---|
4418 | // test whether zero Mv is a better start point than Median predictor |
---|
4419 | if ( bTestZeroVectorStart && ((cStruct.iBestX != 0) || (cStruct.iBestY != 0)) ) |
---|
4420 | { |
---|
4421 | xTZSearchHelp( pcPatternKey, cStruct, 0, 0, 0, 0 ); |
---|
4422 | if ( (cStruct.iBestX == 0) && (cStruct.iBestY == 0) ) |
---|
4423 | { |
---|
4424 | // test its neighborhood |
---|
4425 | for ( iDist = 1; iDist <= (Int)uiSearchRange; iDist*=2 ) |
---|
4426 | { |
---|
4427 | xTZ8PointDiamondSearch( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB, 0, 0, iDist ); |
---|
4428 | if ( bTestZeroVectorStop && (cStruct.uiBestRound > 0) ) // stop criterion |
---|
4429 | { |
---|
4430 | break; |
---|
4431 | } |
---|
4432 | } |
---|
4433 | } |
---|
4434 | } |
---|
4435 | |
---|
4436 | // calculate only 2 missing points instead 8 points if cStruct.uiBestDistance == 1 |
---|
4437 | if ( cStruct.uiBestDistance == 1 ) |
---|
4438 | { |
---|
4439 | cStruct.uiBestDistance = 0; |
---|
4440 | xTZ2PointSearch( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB ); |
---|
4441 | } |
---|
4442 | |
---|
4443 | // raster search if distance is too big |
---|
4444 | if ( bEnableRasterSearch && ( ((Int)(cStruct.uiBestDistance) > iRaster) || bAlwaysRasterSearch ) ) |
---|
4445 | { |
---|
4446 | cStruct.uiBestDistance = iRaster; |
---|
4447 | for ( iStartY = iSrchRngVerTop; iStartY <= iSrchRngVerBottom; iStartY += iRaster ) |
---|
4448 | { |
---|
4449 | for ( iStartX = iSrchRngHorLeft; iStartX <= iSrchRngHorRight; iStartX += iRaster ) |
---|
4450 | { |
---|
4451 | xTZSearchHelp( pcPatternKey, cStruct, iStartX, iStartY, 0, iRaster ); |
---|
4452 | } |
---|
4453 | } |
---|
4454 | } |
---|
4455 | |
---|
4456 | // raster refinement |
---|
4457 | if ( bRasterRefinementEnable && cStruct.uiBestDistance > 0 ) |
---|
4458 | { |
---|
4459 | while ( cStruct.uiBestDistance > 0 ) |
---|
4460 | { |
---|
4461 | iStartX = cStruct.iBestX; |
---|
4462 | iStartY = cStruct.iBestY; |
---|
4463 | if ( cStruct.uiBestDistance > 1 ) |
---|
4464 | { |
---|
4465 | iDist = cStruct.uiBestDistance >>= 1; |
---|
4466 | if ( bRasterRefinementDiamond == 1 ) |
---|
4467 | { |
---|
4468 | xTZ8PointDiamondSearch ( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB, iStartX, iStartY, iDist ); |
---|
4469 | } |
---|
4470 | else |
---|
4471 | { |
---|
4472 | xTZ8PointSquareSearch ( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB, iStartX, iStartY, iDist ); |
---|
4473 | } |
---|
4474 | } |
---|
4475 | |
---|
4476 | // calculate only 2 missing points instead 8 points if cStruct.uiBestDistance == 1 |
---|
4477 | if ( cStruct.uiBestDistance == 1 ) |
---|
4478 | { |
---|
4479 | cStruct.uiBestDistance = 0; |
---|
4480 | if ( cStruct.ucPointNr != 0 ) |
---|
4481 | { |
---|
4482 | xTZ2PointSearch( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB ); |
---|
4483 | } |
---|
4484 | } |
---|
4485 | } |
---|
4486 | } |
---|
4487 | |
---|
4488 | // start refinement |
---|
4489 | if ( bStarRefinementEnable && cStruct.uiBestDistance > 0 ) |
---|
4490 | { |
---|
4491 | while ( cStruct.uiBestDistance > 0 ) |
---|
4492 | { |
---|
4493 | iStartX = cStruct.iBestX; |
---|
4494 | iStartY = cStruct.iBestY; |
---|
4495 | cStruct.uiBestDistance = 0; |
---|
4496 | cStruct.ucPointNr = 0; |
---|
4497 | for ( iDist = 1; iDist < (Int)uiSearchRange + 1; iDist*=2 ) |
---|
4498 | { |
---|
4499 | if ( bStarRefinementDiamond == 1 ) |
---|
4500 | { |
---|
4501 | xTZ8PointDiamondSearch ( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB, iStartX, iStartY, iDist ); |
---|
4502 | } |
---|
4503 | else |
---|
4504 | { |
---|
4505 | xTZ8PointSquareSearch ( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB, iStartX, iStartY, iDist ); |
---|
4506 | } |
---|
4507 | if ( bStarRefinementStop && (cStruct.uiBestRound >= uiStarRefinementRounds) ) // stop criterion |
---|
4508 | { |
---|
4509 | break; |
---|
4510 | } |
---|
4511 | } |
---|
4512 | |
---|
4513 | // calculate only 2 missing points instead 8 points if cStrukt.uiBestDistance == 1 |
---|
4514 | if ( cStruct.uiBestDistance == 1 ) |
---|
4515 | { |
---|
4516 | cStruct.uiBestDistance = 0; |
---|
4517 | if ( cStruct.ucPointNr != 0 ) |
---|
4518 | { |
---|
4519 | xTZ2PointSearch( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB ); |
---|
4520 | } |
---|
4521 | } |
---|
4522 | } |
---|
4523 | } |
---|
4524 | |
---|
4525 | // write out best match |
---|
4526 | rcMv.set( cStruct.iBestX, cStruct.iBestY ); |
---|
4527 | ruiSAD = cStruct.uiBestSad - m_pcRdCost->getCost( cStruct.iBestX, cStruct.iBestY ); |
---|
4528 | } |
---|
4529 | |
---|
4530 | Void TEncSearch::xPatternSearchFracDIF(TComDataCU* pcCU, |
---|
4531 | TComPattern* pcPatternKey, |
---|
4532 | Pel* piRefY, |
---|
4533 | Int iRefStride, |
---|
4534 | TComMv* pcMvInt, |
---|
4535 | TComMv& rcMvHalf, |
---|
4536 | TComMv& rcMvQter, |
---|
4537 | UInt& ruiCost |
---|
4538 | ,Bool biPred |
---|
4539 | ) |
---|
4540 | { |
---|
4541 | // Reference pattern initialization (integer scale) |
---|
4542 | TComPattern cPatternRoi; |
---|
4543 | Int iOffset = pcMvInt->getHor() + pcMvInt->getVer() * iRefStride; |
---|
4544 | cPatternRoi.initPattern( piRefY + iOffset, |
---|
4545 | NULL, |
---|
4546 | NULL, |
---|
4547 | pcPatternKey->getROIYWidth(), |
---|
4548 | pcPatternKey->getROIYHeight(), |
---|
4549 | iRefStride, |
---|
4550 | 0, 0 ); |
---|
4551 | |
---|
4552 | // Half-pel refinement |
---|
4553 | xExtDIFUpSamplingH ( &cPatternRoi, biPred ); |
---|
4554 | |
---|
4555 | rcMvHalf = *pcMvInt; rcMvHalf <<= 1; // for mv-cost |
---|
4556 | TComMv baseRefMv(0, 0); |
---|
4557 | ruiCost = xPatternRefinement( pcPatternKey, baseRefMv, 2, rcMvHalf ); |
---|
4558 | |
---|
4559 | m_pcRdCost->setCostScale( 0 ); |
---|
4560 | |
---|
4561 | xExtDIFUpSamplingQ ( &cPatternRoi, rcMvHalf, biPred ); |
---|
4562 | baseRefMv = rcMvHalf; |
---|
4563 | baseRefMv <<= 1; |
---|
4564 | |
---|
4565 | rcMvQter = *pcMvInt; rcMvQter <<= 1; // for mv-cost |
---|
4566 | rcMvQter += rcMvHalf; rcMvQter <<= 1; |
---|
4567 | ruiCost = xPatternRefinement( pcPatternKey, baseRefMv, 1, rcMvQter ); |
---|
4568 | } |
---|
4569 | |
---|
4570 | /** encode residual and calculate rate-distortion for a CU block |
---|
4571 | * \param pcCU |
---|
4572 | * \param pcYuvOrg |
---|
4573 | * \param pcYuvPred |
---|
4574 | * \param rpcYuvResi |
---|
4575 | * \param rpcYuvResiBest |
---|
4576 | * \param rpcYuvRec |
---|
4577 | * \param bSkipRes |
---|
4578 | * \returns Void |
---|
4579 | */ |
---|
4580 | Void TEncSearch::encodeResAndCalcRdInterCU( TComDataCU* pcCU, TComYuv* pcYuvOrg, TComYuv* pcYuvPred, TComYuv*& rpcYuvResi, TComYuv*& rpcYuvResiBest, TComYuv*& rpcYuvRec, Bool bSkipRes ) |
---|
4581 | { |
---|
4582 | if ( pcCU->isIntra(0) ) |
---|
4583 | { |
---|
4584 | return; |
---|
4585 | } |
---|
4586 | |
---|
4587 | Bool bHighPass = pcCU->getSlice()->getDepth() ? true : false; |
---|
4588 | UInt uiBits = 0, uiBitsBest = 0; |
---|
4589 | UInt uiDistortion = 0, uiDistortionBest = 0; |
---|
4590 | |
---|
4591 | UInt uiWidth = pcCU->getWidth ( 0 ); |
---|
4592 | UInt uiHeight = pcCU->getHeight( 0 ); |
---|
4593 | |
---|
4594 | // No residual coding : SKIP mode |
---|
4595 | if ( bSkipRes ) |
---|
4596 | { |
---|
4597 | pcCU->setSkipFlagSubParts( true, 0, pcCU->getDepth(0) ); |
---|
4598 | |
---|
4599 | rpcYuvResi->clear(); |
---|
4600 | |
---|
4601 | pcYuvPred->copyToPartYuv( rpcYuvRec, 0 ); |
---|
4602 | |
---|
4603 | #if WEIGHTED_CHROMA_DISTORTION |
---|
4604 | uiDistortion = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(), pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(), uiWidth, uiHeight ) |
---|
4605 | + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_U ) |
---|
4606 | + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_V ); |
---|
4607 | #else |
---|
4608 | uiDistortion = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(), pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(), uiWidth, uiHeight ) |
---|
4609 | + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 ) |
---|
4610 | + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 ); |
---|
4611 | #endif |
---|
4612 | |
---|
4613 | if( m_bUseSBACRD ) |
---|
4614 | m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST]); |
---|
4615 | |
---|
4616 | m_pcEntropyCoder->resetBits(); |
---|
4617 | if (pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
4618 | { |
---|
4619 | m_pcEntropyCoder->encodeCUTransquantBypassFlag(pcCU, 0, true); |
---|
4620 | } |
---|
4621 | m_pcEntropyCoder->encodeSkipFlag(pcCU, 0, true); |
---|
4622 | m_pcEntropyCoder->encodeMergeIndex( pcCU, 0, true ); |
---|
4623 | |
---|
4624 | uiBits = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
4625 | pcCU->getTotalBits() = uiBits; |
---|
4626 | pcCU->getTotalDistortion() = uiDistortion; |
---|
4627 | pcCU->getTotalCost() = m_pcRdCost->calcRdCost( uiBits, uiDistortion ); |
---|
4628 | |
---|
4629 | if( m_bUseSBACRD ) |
---|
4630 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_TEMP_BEST]); |
---|
4631 | |
---|
4632 | pcCU->setCbfSubParts( 0, 0, 0, 0, pcCU->getDepth( 0 ) ); |
---|
4633 | pcCU->setTrIdxSubParts( 0, 0, pcCU->getDepth(0) ); |
---|
4634 | |
---|
4635 | return; |
---|
4636 | } |
---|
4637 | |
---|
4638 | // Residual coding. |
---|
4639 | Int qp, qpBest = 0, qpMin, qpMax; |
---|
4640 | Double dCost, dCostBest = MAX_DOUBLE; |
---|
4641 | |
---|
4642 | UInt uiTrLevel = 0; |
---|
4643 | if( (pcCU->getWidth(0) > pcCU->getSlice()->getSPS()->getMaxTrSize()) ) |
---|
4644 | { |
---|
4645 | while( pcCU->getWidth(0) > (pcCU->getSlice()->getSPS()->getMaxTrSize()<<uiTrLevel) ) uiTrLevel++; |
---|
4646 | } |
---|
4647 | UInt uiMaxTrMode = 1 + uiTrLevel; |
---|
4648 | |
---|
4649 | while((uiWidth>>uiMaxTrMode) < (g_uiMaxCUWidth>>g_uiMaxCUDepth)) uiMaxTrMode--; |
---|
4650 | |
---|
4651 | #if REPN_FORMAT_IN_VPS |
---|
4652 | qpMin = bHighPass ? Clip3( -pcCU->getSlice()->getQpBDOffsetY(), MAX_QP, pcCU->getQP(0) - m_iMaxDeltaQP ) : pcCU->getQP( 0 ); |
---|
4653 | qpMax = bHighPass ? Clip3( -pcCU->getSlice()->getQpBDOffsetY(), MAX_QP, pcCU->getQP(0) + m_iMaxDeltaQP ) : pcCU->getQP( 0 ); |
---|
4654 | #else |
---|
4655 | qpMin = bHighPass ? Clip3( -pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, pcCU->getQP(0) - m_iMaxDeltaQP ) : pcCU->getQP( 0 ); |
---|
4656 | qpMax = bHighPass ? Clip3( -pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, pcCU->getQP(0) + m_iMaxDeltaQP ) : pcCU->getQP( 0 ); |
---|
4657 | #endif |
---|
4658 | |
---|
4659 | rpcYuvResi->subtract( pcYuvOrg, pcYuvPred, 0, uiWidth ); |
---|
4660 | |
---|
4661 | for ( qp = qpMin; qp <= qpMax; qp++ ) |
---|
4662 | { |
---|
4663 | dCost = 0.; |
---|
4664 | uiBits = 0; |
---|
4665 | uiDistortion = 0; |
---|
4666 | if( m_bUseSBACRD ) |
---|
4667 | { |
---|
4668 | m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_CURR_BEST ] ); |
---|
4669 | } |
---|
4670 | |
---|
4671 | UInt uiZeroDistortion = 0; |
---|
4672 | xEstimateResidualQT( pcCU, 0, 0, 0, rpcYuvResi, pcCU->getDepth(0), dCost, uiBits, uiDistortion, &uiZeroDistortion ); |
---|
4673 | |
---|
4674 | m_pcEntropyCoder->resetBits(); |
---|
4675 | m_pcEntropyCoder->encodeQtRootCbfZero( pcCU ); |
---|
4676 | UInt zeroResiBits = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
4677 | Double dZeroCost = m_pcRdCost->calcRdCost( zeroResiBits, uiZeroDistortion ); |
---|
4678 | if(pcCU->isLosslessCoded( 0 )) |
---|
4679 | { |
---|
4680 | dZeroCost = dCost + 1; |
---|
4681 | } |
---|
4682 | if ( dZeroCost < dCost ) |
---|
4683 | { |
---|
4684 | dCost = dZeroCost; |
---|
4685 | uiBits = 0; |
---|
4686 | uiDistortion = uiZeroDistortion; |
---|
4687 | |
---|
4688 | const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (pcCU->getDepth(0) << 1); |
---|
4689 | ::memset( pcCU->getTransformIdx() , 0, uiQPartNum * sizeof(UChar) ); |
---|
4690 | ::memset( pcCU->getCbf( TEXT_LUMA ) , 0, uiQPartNum * sizeof(UChar) ); |
---|
4691 | ::memset( pcCU->getCbf( TEXT_CHROMA_U ), 0, uiQPartNum * sizeof(UChar) ); |
---|
4692 | ::memset( pcCU->getCbf( TEXT_CHROMA_V ), 0, uiQPartNum * sizeof(UChar) ); |
---|
4693 | ::memset( pcCU->getCoeffY() , 0, uiWidth * uiHeight * sizeof( TCoeff ) ); |
---|
4694 | ::memset( pcCU->getCoeffCb() , 0, uiWidth * uiHeight * sizeof( TCoeff ) >> 2 ); |
---|
4695 | ::memset( pcCU->getCoeffCr() , 0, uiWidth * uiHeight * sizeof( TCoeff ) >> 2 ); |
---|
4696 | pcCU->setTransformSkipSubParts ( 0, 0, 0, 0, pcCU->getDepth(0) ); |
---|
4697 | } |
---|
4698 | else |
---|
4699 | { |
---|
4700 | xSetResidualQTData( pcCU, 0, 0, 0, NULL, pcCU->getDepth(0), false ); |
---|
4701 | } |
---|
4702 | |
---|
4703 | if( m_bUseSBACRD ) |
---|
4704 | { |
---|
4705 | m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST] ); |
---|
4706 | } |
---|
4707 | #if 0 // check |
---|
4708 | { |
---|
4709 | m_pcEntropyCoder->resetBits(); |
---|
4710 | m_pcEntropyCoder->encodeCoeff( pcCU, 0, pcCU->getDepth(0), pcCU->getWidth(0), pcCU->getHeight(0) ); |
---|
4711 | const UInt uiBitsForCoeff = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
4712 | if( m_bUseSBACRD ) |
---|
4713 | { |
---|
4714 | m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST] ); |
---|
4715 | } |
---|
4716 | if( uiBitsForCoeff != uiBits ) |
---|
4717 | assert( 0 ); |
---|
4718 | } |
---|
4719 | #endif |
---|
4720 | uiBits = 0; |
---|
4721 | { |
---|
4722 | TComYuv *pDummy = NULL; |
---|
4723 | xAddSymbolBitsInter( pcCU, 0, 0, uiBits, pDummy, NULL, pDummy ); |
---|
4724 | } |
---|
4725 | |
---|
4726 | |
---|
4727 | Double dExactCost = m_pcRdCost->calcRdCost( uiBits, uiDistortion ); |
---|
4728 | dCost = dExactCost; |
---|
4729 | |
---|
4730 | if ( dCost < dCostBest ) |
---|
4731 | { |
---|
4732 | if ( !pcCU->getQtRootCbf( 0 ) ) |
---|
4733 | { |
---|
4734 | rpcYuvResiBest->clear(); |
---|
4735 | } |
---|
4736 | else |
---|
4737 | { |
---|
4738 | xSetResidualQTData( pcCU, 0, 0, 0, rpcYuvResiBest, pcCU->getDepth(0), true ); |
---|
4739 | } |
---|
4740 | |
---|
4741 | if( qpMin != qpMax && qp != qpMax ) |
---|
4742 | { |
---|
4743 | const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (pcCU->getDepth(0) << 1); |
---|
4744 | ::memcpy( m_puhQTTempTrIdx, pcCU->getTransformIdx(), uiQPartNum * sizeof(UChar) ); |
---|
4745 | ::memcpy( m_puhQTTempCbf[0], pcCU->getCbf( TEXT_LUMA ), uiQPartNum * sizeof(UChar) ); |
---|
4746 | ::memcpy( m_puhQTTempCbf[1], pcCU->getCbf( TEXT_CHROMA_U ), uiQPartNum * sizeof(UChar) ); |
---|
4747 | ::memcpy( m_puhQTTempCbf[2], pcCU->getCbf( TEXT_CHROMA_V ), uiQPartNum * sizeof(UChar) ); |
---|
4748 | ::memcpy( m_pcQTTempCoeffY, pcCU->getCoeffY(), uiWidth * uiHeight * sizeof( TCoeff ) ); |
---|
4749 | ::memcpy( m_pcQTTempCoeffCb, pcCU->getCoeffCb(), uiWidth * uiHeight * sizeof( TCoeff ) >> 2 ); |
---|
4750 | ::memcpy( m_pcQTTempCoeffCr, pcCU->getCoeffCr(), uiWidth * uiHeight * sizeof( TCoeff ) >> 2 ); |
---|
4751 | #if ADAPTIVE_QP_SELECTION |
---|
4752 | ::memcpy( m_pcQTTempArlCoeffY, pcCU->getArlCoeffY(), uiWidth * uiHeight * sizeof( Int ) ); |
---|
4753 | ::memcpy( m_pcQTTempArlCoeffCb, pcCU->getArlCoeffCb(), uiWidth * uiHeight * sizeof( Int ) >> 2 ); |
---|
4754 | ::memcpy( m_pcQTTempArlCoeffCr, pcCU->getArlCoeffCr(), uiWidth * uiHeight * sizeof( Int ) >> 2 ); |
---|
4755 | #endif |
---|
4756 | ::memcpy( m_puhQTTempTransformSkipFlag[0], pcCU->getTransformSkip(TEXT_LUMA), uiQPartNum * sizeof( UChar ) ); |
---|
4757 | ::memcpy( m_puhQTTempTransformSkipFlag[1], pcCU->getTransformSkip(TEXT_CHROMA_U), uiQPartNum * sizeof( UChar ) ); |
---|
4758 | ::memcpy( m_puhQTTempTransformSkipFlag[2], pcCU->getTransformSkip(TEXT_CHROMA_V), uiQPartNum * sizeof( UChar ) ); |
---|
4759 | } |
---|
4760 | uiBitsBest = uiBits; |
---|
4761 | uiDistortionBest = uiDistortion; |
---|
4762 | dCostBest = dCost; |
---|
4763 | qpBest = qp; |
---|
4764 | if( m_bUseSBACRD ) |
---|
4765 | { |
---|
4766 | m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_TEMP_BEST ] ); |
---|
4767 | } |
---|
4768 | } |
---|
4769 | } |
---|
4770 | |
---|
4771 | assert ( dCostBest != MAX_DOUBLE ); |
---|
4772 | |
---|
4773 | if( qpMin != qpMax && qpBest != qpMax ) |
---|
4774 | { |
---|
4775 | if( m_bUseSBACRD ) |
---|
4776 | { |
---|
4777 | assert( 0 ); // check |
---|
4778 | m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_TEMP_BEST ] ); |
---|
4779 | } |
---|
4780 | // copy best cbf and trIdx to pcCU |
---|
4781 | const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (pcCU->getDepth(0) << 1); |
---|
4782 | ::memcpy( pcCU->getTransformIdx(), m_puhQTTempTrIdx, uiQPartNum * sizeof(UChar) ); |
---|
4783 | ::memcpy( pcCU->getCbf( TEXT_LUMA ), m_puhQTTempCbf[0], uiQPartNum * sizeof(UChar) ); |
---|
4784 | ::memcpy( pcCU->getCbf( TEXT_CHROMA_U ), m_puhQTTempCbf[1], uiQPartNum * sizeof(UChar) ); |
---|
4785 | ::memcpy( pcCU->getCbf( TEXT_CHROMA_V ), m_puhQTTempCbf[2], uiQPartNum * sizeof(UChar) ); |
---|
4786 | ::memcpy( pcCU->getCoeffY(), m_pcQTTempCoeffY, uiWidth * uiHeight * sizeof( TCoeff ) ); |
---|
4787 | ::memcpy( pcCU->getCoeffCb(), m_pcQTTempCoeffCb, uiWidth * uiHeight * sizeof( TCoeff ) >> 2 ); |
---|
4788 | ::memcpy( pcCU->getCoeffCr(), m_pcQTTempCoeffCr, uiWidth * uiHeight * sizeof( TCoeff ) >> 2 ); |
---|
4789 | #if ADAPTIVE_QP_SELECTION |
---|
4790 | ::memcpy( pcCU->getArlCoeffY(), m_pcQTTempArlCoeffY, uiWidth * uiHeight * sizeof( Int ) ); |
---|
4791 | ::memcpy( pcCU->getArlCoeffCb(), m_pcQTTempArlCoeffCb, uiWidth * uiHeight * sizeof( Int ) >> 2 ); |
---|
4792 | ::memcpy( pcCU->getArlCoeffCr(), m_pcQTTempArlCoeffCr, uiWidth * uiHeight * sizeof( Int ) >> 2 ); |
---|
4793 | #endif |
---|
4794 | ::memcpy( pcCU->getTransformSkip(TEXT_LUMA), m_puhQTTempTransformSkipFlag[0], uiQPartNum * sizeof( UChar ) ); |
---|
4795 | ::memcpy( pcCU->getTransformSkip(TEXT_CHROMA_U), m_puhQTTempTransformSkipFlag[1], uiQPartNum * sizeof( UChar ) ); |
---|
4796 | ::memcpy( pcCU->getTransformSkip(TEXT_CHROMA_V), m_puhQTTempTransformSkipFlag[2], uiQPartNum * sizeof( UChar ) ); |
---|
4797 | } |
---|
4798 | rpcYuvRec->addClip ( pcYuvPred, rpcYuvResiBest, 0, uiWidth ); |
---|
4799 | |
---|
4800 | // update with clipped distortion and cost (qp estimation loop uses unclipped values) |
---|
4801 | #if WEIGHTED_CHROMA_DISTORTION |
---|
4802 | uiDistortionBest = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(), pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(), uiWidth, uiHeight ) |
---|
4803 | + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_U ) |
---|
4804 | + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_V ); |
---|
4805 | #else |
---|
4806 | uiDistortionBest = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(), pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(), uiWidth, uiHeight ) |
---|
4807 | + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 ) |
---|
4808 | + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 ); |
---|
4809 | #endif |
---|
4810 | dCostBest = m_pcRdCost->calcRdCost( uiBitsBest, uiDistortionBest ); |
---|
4811 | |
---|
4812 | pcCU->getTotalBits() = uiBitsBest; |
---|
4813 | pcCU->getTotalDistortion() = uiDistortionBest; |
---|
4814 | pcCU->getTotalCost() = dCostBest; |
---|
4815 | |
---|
4816 | if ( pcCU->isSkipped(0) ) |
---|
4817 | { |
---|
4818 | pcCU->setCbfSubParts( 0, 0, 0, 0, pcCU->getDepth( 0 ) ); |
---|
4819 | } |
---|
4820 | |
---|
4821 | pcCU->setQPSubParts( qpBest, 0, pcCU->getDepth(0) ); |
---|
4822 | } |
---|
4823 | |
---|
4824 | Void TEncSearch::xEstimateResidualQT( TComDataCU* pcCU, UInt uiQuadrant, UInt uiAbsPartIdx, UInt absTUPartIdx, TComYuv* pcResi, const UInt uiDepth, Double &rdCost, UInt &ruiBits, UInt &ruiDist, UInt *puiZeroDist ) |
---|
4825 | { |
---|
4826 | const UInt uiTrMode = uiDepth - pcCU->getDepth( 0 ); |
---|
4827 | |
---|
4828 | assert( pcCU->getDepth( 0 ) == pcCU->getDepth( uiAbsPartIdx ) ); |
---|
4829 | const UInt uiLog2TrSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth]+2; |
---|
4830 | |
---|
4831 | UInt SplitFlag = ((pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N )); |
---|
4832 | Bool bCheckFull; |
---|
4833 | if ( SplitFlag && uiDepth == pcCU->getDepth(uiAbsPartIdx) && ( uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) ) |
---|
4834 | bCheckFull = false; |
---|
4835 | else |
---|
4836 | bCheckFull = ( uiLog2TrSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ); |
---|
4837 | |
---|
4838 | const Bool bCheckSplit = ( uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ); |
---|
4839 | |
---|
4840 | assert( bCheckFull || bCheckSplit ); |
---|
4841 | |
---|
4842 | Bool bCodeChroma = true; |
---|
4843 | UInt uiTrModeC = uiTrMode; |
---|
4844 | UInt uiLog2TrSizeC = uiLog2TrSize-1; |
---|
4845 | if( uiLog2TrSize == 2 ) |
---|
4846 | { |
---|
4847 | uiLog2TrSizeC++; |
---|
4848 | uiTrModeC --; |
---|
4849 | UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrModeC ) << 1 ); |
---|
4850 | bCodeChroma = ( ( uiAbsPartIdx % uiQPDiv ) == 0 ); |
---|
4851 | } |
---|
4852 | |
---|
4853 | const UInt uiSetCbf = 1 << uiTrMode; |
---|
4854 | // code full block |
---|
4855 | Double dSingleCost = MAX_DOUBLE; |
---|
4856 | UInt uiSingleBits = 0; |
---|
4857 | UInt uiSingleDist = 0; |
---|
4858 | UInt uiAbsSumY = 0, uiAbsSumU = 0, uiAbsSumV = 0; |
---|
4859 | UInt uiBestTransformMode[3] = {0}; |
---|
4860 | |
---|
4861 | if( m_bUseSBACRD ) |
---|
4862 | { |
---|
4863 | m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] ); |
---|
4864 | } |
---|
4865 | |
---|
4866 | if( bCheckFull ) |
---|
4867 | { |
---|
4868 | const UInt uiNumCoeffPerAbsPartIdxIncrement = pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ); |
---|
4869 | const UInt uiQTTempAccessLayer = pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() - uiLog2TrSize; |
---|
4870 | TCoeff *pcCoeffCurrY = m_ppcQTTempCoeffY [uiQTTempAccessLayer] + uiNumCoeffPerAbsPartIdxIncrement * uiAbsPartIdx; |
---|
4871 | TCoeff *pcCoeffCurrU = m_ppcQTTempCoeffCb[uiQTTempAccessLayer] + (uiNumCoeffPerAbsPartIdxIncrement * uiAbsPartIdx>>2); |
---|
4872 | TCoeff *pcCoeffCurrV = m_ppcQTTempCoeffCr[uiQTTempAccessLayer] + (uiNumCoeffPerAbsPartIdxIncrement * uiAbsPartIdx>>2); |
---|
4873 | #if ADAPTIVE_QP_SELECTION |
---|
4874 | Int *pcArlCoeffCurrY = m_ppcQTTempArlCoeffY [uiQTTempAccessLayer] + uiNumCoeffPerAbsPartIdxIncrement * uiAbsPartIdx; |
---|
4875 | Int *pcArlCoeffCurrU = m_ppcQTTempArlCoeffCb[uiQTTempAccessLayer] + (uiNumCoeffPerAbsPartIdxIncrement * uiAbsPartIdx>>2); |
---|
4876 | Int *pcArlCoeffCurrV = m_ppcQTTempArlCoeffCr[uiQTTempAccessLayer] + (uiNumCoeffPerAbsPartIdxIncrement * uiAbsPartIdx>>2); |
---|
4877 | #endif |
---|
4878 | |
---|
4879 | Int trWidth = 0, trHeight = 0, trWidthC = 0, trHeightC = 0; |
---|
4880 | UInt absTUPartIdxC = uiAbsPartIdx; |
---|
4881 | |
---|
4882 | trWidth = trHeight = 1 << uiLog2TrSize; |
---|
4883 | trWidthC = trHeightC = 1 <<uiLog2TrSizeC; |
---|
4884 | pcCU->setTrIdxSubParts( uiDepth - pcCU->getDepth( 0 ), uiAbsPartIdx, uiDepth ); |
---|
4885 | Double minCostY = MAX_DOUBLE; |
---|
4886 | Double minCostU = MAX_DOUBLE; |
---|
4887 | Double minCostV = MAX_DOUBLE; |
---|
4888 | Bool checkTransformSkipY = pcCU->getSlice()->getPPS()->getUseTransformSkip() && trWidth == 4 && trHeight == 4; |
---|
4889 | Bool checkTransformSkipUV = pcCU->getSlice()->getPPS()->getUseTransformSkip() && trWidthC == 4 && trHeightC == 4; |
---|
4890 | |
---|
4891 | checkTransformSkipY &= (!pcCU->isLosslessCoded(0)); |
---|
4892 | checkTransformSkipUV &= (!pcCU->isLosslessCoded(0)); |
---|
4893 | |
---|
4894 | pcCU->setTransformSkipSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiDepth ); |
---|
4895 | if( bCodeChroma ) |
---|
4896 | { |
---|
4897 | pcCU->setTransformSkipSubParts ( 0, TEXT_CHROMA_U, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC ); |
---|
4898 | pcCU->setTransformSkipSubParts ( 0, TEXT_CHROMA_V, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC ); |
---|
4899 | } |
---|
4900 | |
---|
4901 | if (m_pcEncCfg->getUseRDOQ()) |
---|
4902 | { |
---|
4903 | m_pcEntropyCoder->estimateBit(m_pcTrQuant->m_pcEstBitsSbac, trWidth, trHeight, TEXT_LUMA ); |
---|
4904 | } |
---|
4905 | |
---|
4906 | #if REPN_FORMAT_IN_VPS |
---|
4907 | m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 ); |
---|
4908 | #else |
---|
4909 | m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 ); |
---|
4910 | #endif |
---|
4911 | |
---|
4912 | #if RDOQ_CHROMA_LAMBDA |
---|
4913 | m_pcTrQuant->selectLambda(TEXT_LUMA); |
---|
4914 | #endif |
---|
4915 | m_pcTrQuant->transformNxN( pcCU, pcResi->getLumaAddr( absTUPartIdx ), pcResi->getStride (), pcCoeffCurrY, |
---|
4916 | #if ADAPTIVE_QP_SELECTION |
---|
4917 | pcArlCoeffCurrY, |
---|
4918 | #endif |
---|
4919 | trWidth, trHeight, uiAbsSumY, TEXT_LUMA, uiAbsPartIdx ); |
---|
4920 | |
---|
4921 | pcCU->setCbfSubParts( uiAbsSumY ? uiSetCbf : 0, TEXT_LUMA, uiAbsPartIdx, uiDepth ); |
---|
4922 | |
---|
4923 | if( bCodeChroma ) |
---|
4924 | { |
---|
4925 | if (m_pcEncCfg->getUseRDOQ()) |
---|
4926 | { |
---|
4927 | m_pcEntropyCoder->estimateBit(m_pcTrQuant->m_pcEstBitsSbac, trWidthC, trHeightC, TEXT_CHROMA ); |
---|
4928 | } |
---|
4929 | |
---|
4930 | Int curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb(); |
---|
4931 | m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset ); |
---|
4932 | |
---|
4933 | #if RDOQ_CHROMA_LAMBDA |
---|
4934 | m_pcTrQuant->selectLambda(TEXT_CHROMA); |
---|
4935 | #endif |
---|
4936 | |
---|
4937 | m_pcTrQuant->transformNxN( pcCU, pcResi->getCbAddr(absTUPartIdxC), pcResi->getCStride(), pcCoeffCurrU, |
---|
4938 | #if ADAPTIVE_QP_SELECTION |
---|
4939 | pcArlCoeffCurrU, |
---|
4940 | #endif |
---|
4941 | trWidthC, trHeightC, uiAbsSumU, TEXT_CHROMA_U, uiAbsPartIdx ); |
---|
4942 | |
---|
4943 | curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr(); |
---|
4944 | m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset ); |
---|
4945 | m_pcTrQuant->transformNxN( pcCU, pcResi->getCrAddr(absTUPartIdxC), pcResi->getCStride(), pcCoeffCurrV, |
---|
4946 | #if ADAPTIVE_QP_SELECTION |
---|
4947 | pcArlCoeffCurrV, |
---|
4948 | #endif |
---|
4949 | trWidthC, trHeightC, uiAbsSumV, TEXT_CHROMA_V, uiAbsPartIdx ); |
---|
4950 | |
---|
4951 | pcCU->setCbfSubParts( uiAbsSumU ? uiSetCbf : 0, TEXT_CHROMA_U, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC ); |
---|
4952 | pcCU->setCbfSubParts( uiAbsSumV ? uiSetCbf : 0, TEXT_CHROMA_V, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC ); |
---|
4953 | } |
---|
4954 | |
---|
4955 | m_pcEntropyCoder->resetBits(); |
---|
4956 | |
---|
4957 | { |
---|
4958 | m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrMode ); |
---|
4959 | } |
---|
4960 | |
---|
4961 | m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrY, uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); |
---|
4962 | const UInt uiSingleBitsY = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
4963 | |
---|
4964 | UInt uiSingleBitsU = 0; |
---|
4965 | UInt uiSingleBitsV = 0; |
---|
4966 | if( bCodeChroma ) |
---|
4967 | { |
---|
4968 | { |
---|
4969 | m_pcEntropyCoder->encodeQtCbf ( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrMode ); |
---|
4970 | } |
---|
4971 | m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrU, uiAbsPartIdx, trWidthC, trHeightC, uiDepth, TEXT_CHROMA_U ); |
---|
4972 | uiSingleBitsU = m_pcEntropyCoder->getNumberOfWrittenBits() - uiSingleBitsY; |
---|
4973 | |
---|
4974 | { |
---|
4975 | m_pcEntropyCoder->encodeQtCbf ( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrMode ); |
---|
4976 | } |
---|
4977 | m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrV, uiAbsPartIdx, trWidthC, trHeightC, uiDepth, TEXT_CHROMA_V ); |
---|
4978 | uiSingleBitsV = m_pcEntropyCoder->getNumberOfWrittenBits() - ( uiSingleBitsY + uiSingleBitsU ); |
---|
4979 | } |
---|
4980 | |
---|
4981 | const UInt uiNumSamplesLuma = 1 << (uiLog2TrSize<<1); |
---|
4982 | const UInt uiNumSamplesChro = 1 << (uiLog2TrSizeC<<1); |
---|
4983 | |
---|
4984 | ::memset( m_pTempPel, 0, sizeof( Pel ) * uiNumSamplesLuma ); // not necessary needed for inside of recursion (only at the beginning) |
---|
4985 | |
---|
4986 | UInt uiDistY = m_pcRdCost->getDistPart(g_bitDepthY, m_pTempPel, trWidth, pcResi->getLumaAddr( absTUPartIdx ), pcResi->getStride(), trWidth, trHeight ); // initialized with zero residual destortion |
---|
4987 | |
---|
4988 | if ( puiZeroDist ) |
---|
4989 | { |
---|
4990 | *puiZeroDist += uiDistY; |
---|
4991 | } |
---|
4992 | if( uiAbsSumY ) |
---|
4993 | { |
---|
4994 | Pel *pcResiCurrY = m_pcQTTempTComYuv[ uiQTTempAccessLayer ].getLumaAddr( absTUPartIdx ); |
---|
4995 | |
---|
4996 | #if REPN_FORMAT_IN_VPS |
---|
4997 | m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 ); |
---|
4998 | #else |
---|
4999 | m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 ); |
---|
5000 | #endif |
---|
5001 | |
---|
5002 | Int scalingListType = 3 + g_eTTable[(Int)TEXT_LUMA]; |
---|
5003 | assert(scalingListType < 6); |
---|
5004 | m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA,REG_DCT, pcResiCurrY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(), pcCoeffCurrY, trWidth, trHeight, scalingListType );//this is for inter mode only |
---|
5005 | const UInt uiNonzeroDistY = m_pcRdCost->getDistPart(g_bitDepthY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getLumaAddr( absTUPartIdx ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(), |
---|
5006 | pcResi->getLumaAddr( absTUPartIdx ), pcResi->getStride(), trWidth,trHeight ); |
---|
5007 | if (pcCU->isLosslessCoded(0)) |
---|
5008 | { |
---|
5009 | uiDistY = uiNonzeroDistY; |
---|
5010 | } |
---|
5011 | else |
---|
5012 | { |
---|
5013 | const Double singleCostY = m_pcRdCost->calcRdCost( uiSingleBitsY, uiNonzeroDistY ); |
---|
5014 | m_pcEntropyCoder->resetBits(); |
---|
5015 | m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_LUMA, uiTrMode ); |
---|
5016 | const UInt uiNullBitsY = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
5017 | const Double nullCostY = m_pcRdCost->calcRdCost( uiNullBitsY, uiDistY ); |
---|
5018 | if( nullCostY < singleCostY ) |
---|
5019 | { |
---|
5020 | uiAbsSumY = 0; |
---|
5021 | ::memset( pcCoeffCurrY, 0, sizeof( TCoeff ) * uiNumSamplesLuma ); |
---|
5022 | if( checkTransformSkipY ) |
---|
5023 | { |
---|
5024 | minCostY = nullCostY; |
---|
5025 | } |
---|
5026 | } |
---|
5027 | else |
---|
5028 | { |
---|
5029 | uiDistY = uiNonzeroDistY; |
---|
5030 | if( checkTransformSkipY ) |
---|
5031 | { |
---|
5032 | minCostY = singleCostY; |
---|
5033 | } |
---|
5034 | } |
---|
5035 | } |
---|
5036 | } |
---|
5037 | else if( checkTransformSkipY ) |
---|
5038 | { |
---|
5039 | m_pcEntropyCoder->resetBits(); |
---|
5040 | m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_LUMA, uiTrMode ); |
---|
5041 | const UInt uiNullBitsY = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
5042 | minCostY = m_pcRdCost->calcRdCost( uiNullBitsY, uiDistY ); |
---|
5043 | } |
---|
5044 | |
---|
5045 | if( !uiAbsSumY ) |
---|
5046 | { |
---|
5047 | Pel *pcPtr = m_pcQTTempTComYuv[uiQTTempAccessLayer].getLumaAddr( absTUPartIdx ); |
---|
5048 | const UInt uiStride = m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(); |
---|
5049 | for( UInt uiY = 0; uiY < trHeight; ++uiY ) |
---|
5050 | { |
---|
5051 | ::memset( pcPtr, 0, sizeof( Pel ) * trWidth ); |
---|
5052 | pcPtr += uiStride; |
---|
5053 | } |
---|
5054 | } |
---|
5055 | |
---|
5056 | UInt uiDistU = 0; |
---|
5057 | UInt uiDistV = 0; |
---|
5058 | if( bCodeChroma ) |
---|
5059 | { |
---|
5060 | uiDistU = m_pcRdCost->getDistPart(g_bitDepthC, m_pTempPel, trWidthC, pcResi->getCbAddr( absTUPartIdxC ), pcResi->getCStride(), trWidthC, trHeightC |
---|
5061 | #if WEIGHTED_CHROMA_DISTORTION |
---|
5062 | , TEXT_CHROMA_U |
---|
5063 | #endif |
---|
5064 | ); // initialized with zero residual destortion |
---|
5065 | if ( puiZeroDist ) |
---|
5066 | { |
---|
5067 | *puiZeroDist += uiDistU; |
---|
5068 | } |
---|
5069 | if( uiAbsSumU ) |
---|
5070 | { |
---|
5071 | Pel *pcResiCurrU = m_pcQTTempTComYuv[uiQTTempAccessLayer].getCbAddr( absTUPartIdxC ); |
---|
5072 | |
---|
5073 | Int curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb(); |
---|
5074 | m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset ); |
---|
5075 | |
---|
5076 | Int scalingListType = 3 + g_eTTable[(Int)TEXT_CHROMA_U]; |
---|
5077 | assert(scalingListType < 6); |
---|
5078 | m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA,REG_DCT, pcResiCurrU, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), pcCoeffCurrU, trWidthC, trHeightC, scalingListType ); |
---|
5079 | |
---|
5080 | const UInt uiNonzeroDistU = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCbAddr( absTUPartIdxC), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), |
---|
5081 | pcResi->getCbAddr( absTUPartIdxC), pcResi->getCStride(), trWidthC, trHeightC |
---|
5082 | #if WEIGHTED_CHROMA_DISTORTION |
---|
5083 | , TEXT_CHROMA_U |
---|
5084 | #endif |
---|
5085 | ); |
---|
5086 | |
---|
5087 | if(pcCU->isLosslessCoded(0)) |
---|
5088 | { |
---|
5089 | uiDistU = uiNonzeroDistU; |
---|
5090 | } |
---|
5091 | else |
---|
5092 | { |
---|
5093 | const Double dSingleCostU = m_pcRdCost->calcRdCost( uiSingleBitsU, uiNonzeroDistU ); |
---|
5094 | m_pcEntropyCoder->resetBits(); |
---|
5095 | m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_U, uiTrMode ); |
---|
5096 | const UInt uiNullBitsU = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
5097 | const Double dNullCostU = m_pcRdCost->calcRdCost( uiNullBitsU, uiDistU ); |
---|
5098 | if( dNullCostU < dSingleCostU ) |
---|
5099 | { |
---|
5100 | uiAbsSumU = 0; |
---|
5101 | ::memset( pcCoeffCurrU, 0, sizeof( TCoeff ) * uiNumSamplesChro ); |
---|
5102 | if( checkTransformSkipUV ) |
---|
5103 | { |
---|
5104 | minCostU = dNullCostU; |
---|
5105 | } |
---|
5106 | } |
---|
5107 | else |
---|
5108 | { |
---|
5109 | uiDistU = uiNonzeroDistU; |
---|
5110 | if( checkTransformSkipUV ) |
---|
5111 | { |
---|
5112 | minCostU = dSingleCostU; |
---|
5113 | } |
---|
5114 | } |
---|
5115 | } |
---|
5116 | } |
---|
5117 | else if( checkTransformSkipUV ) |
---|
5118 | { |
---|
5119 | m_pcEntropyCoder->resetBits(); |
---|
5120 | m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_U, uiTrModeC ); |
---|
5121 | const UInt uiNullBitsU = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
5122 | minCostU = m_pcRdCost->calcRdCost( uiNullBitsU, uiDistU ); |
---|
5123 | } |
---|
5124 | if( !uiAbsSumU ) |
---|
5125 | { |
---|
5126 | Pel *pcPtr = m_pcQTTempTComYuv[uiQTTempAccessLayer].getCbAddr( absTUPartIdxC ); |
---|
5127 | const UInt uiStride = m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(); |
---|
5128 | for( UInt uiY = 0; uiY < trHeightC; ++uiY ) |
---|
5129 | { |
---|
5130 | ::memset( pcPtr, 0, sizeof(Pel) * trWidthC ); |
---|
5131 | pcPtr += uiStride; |
---|
5132 | } |
---|
5133 | } |
---|
5134 | |
---|
5135 | uiDistV = m_pcRdCost->getDistPart(g_bitDepthC, m_pTempPel, trWidthC, pcResi->getCrAddr( absTUPartIdxC), pcResi->getCStride(), trWidthC, trHeightC |
---|
5136 | #if WEIGHTED_CHROMA_DISTORTION |
---|
5137 | , TEXT_CHROMA_V |
---|
5138 | #endif |
---|
5139 | ); // initialized with zero residual destortion |
---|
5140 | if ( puiZeroDist ) |
---|
5141 | { |
---|
5142 | *puiZeroDist += uiDistV; |
---|
5143 | } |
---|
5144 | if( uiAbsSumV ) |
---|
5145 | { |
---|
5146 | Pel *pcResiCurrV = m_pcQTTempTComYuv[uiQTTempAccessLayer].getCrAddr( absTUPartIdxC ); |
---|
5147 | Int curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr(); |
---|
5148 | m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset ); |
---|
5149 | |
---|
5150 | Int scalingListType = 3 + g_eTTable[(Int)TEXT_CHROMA_V]; |
---|
5151 | assert(scalingListType < 6); |
---|
5152 | m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA,REG_DCT, pcResiCurrV, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), pcCoeffCurrV, trWidthC, trHeightC, scalingListType ); |
---|
5153 | |
---|
5154 | const UInt uiNonzeroDistV = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCrAddr( absTUPartIdxC ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), |
---|
5155 | pcResi->getCrAddr( absTUPartIdxC ), pcResi->getCStride(), trWidthC, trHeightC |
---|
5156 | #if WEIGHTED_CHROMA_DISTORTION |
---|
5157 | , TEXT_CHROMA_V |
---|
5158 | #endif |
---|
5159 | ); |
---|
5160 | if (pcCU->isLosslessCoded(0)) |
---|
5161 | { |
---|
5162 | uiDistV = uiNonzeroDistV; |
---|
5163 | } |
---|
5164 | else |
---|
5165 | { |
---|
5166 | const Double dSingleCostV = m_pcRdCost->calcRdCost( uiSingleBitsV, uiNonzeroDistV ); |
---|
5167 | m_pcEntropyCoder->resetBits(); |
---|
5168 | m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_V, uiTrMode ); |
---|
5169 | const UInt uiNullBitsV = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
5170 | const Double dNullCostV = m_pcRdCost->calcRdCost( uiNullBitsV, uiDistV ); |
---|
5171 | if( dNullCostV < dSingleCostV ) |
---|
5172 | { |
---|
5173 | uiAbsSumV = 0; |
---|
5174 | ::memset( pcCoeffCurrV, 0, sizeof( TCoeff ) * uiNumSamplesChro ); |
---|
5175 | if( checkTransformSkipUV ) |
---|
5176 | { |
---|
5177 | minCostV = dNullCostV; |
---|
5178 | } |
---|
5179 | } |
---|
5180 | else |
---|
5181 | { |
---|
5182 | uiDistV = uiNonzeroDistV; |
---|
5183 | if( checkTransformSkipUV ) |
---|
5184 | { |
---|
5185 | minCostV = dSingleCostV; |
---|
5186 | } |
---|
5187 | } |
---|
5188 | } |
---|
5189 | } |
---|
5190 | else if( checkTransformSkipUV ) |
---|
5191 | { |
---|
5192 | m_pcEntropyCoder->resetBits(); |
---|
5193 | m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_V, uiTrModeC ); |
---|
5194 | const UInt uiNullBitsV = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
5195 | minCostV = m_pcRdCost->calcRdCost( uiNullBitsV, uiDistV ); |
---|
5196 | } |
---|
5197 | if( !uiAbsSumV ) |
---|
5198 | { |
---|
5199 | Pel *pcPtr = m_pcQTTempTComYuv[uiQTTempAccessLayer].getCrAddr( absTUPartIdxC ); |
---|
5200 | const UInt uiStride = m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(); |
---|
5201 | for( UInt uiY = 0; uiY < trHeightC; ++uiY ) |
---|
5202 | { |
---|
5203 | ::memset( pcPtr, 0, sizeof(Pel) * trWidthC ); |
---|
5204 | pcPtr += uiStride; |
---|
5205 | } |
---|
5206 | } |
---|
5207 | } |
---|
5208 | pcCU->setCbfSubParts( uiAbsSumY ? uiSetCbf : 0, TEXT_LUMA, uiAbsPartIdx, uiDepth ); |
---|
5209 | if( bCodeChroma ) |
---|
5210 | { |
---|
5211 | pcCU->setCbfSubParts( uiAbsSumU ? uiSetCbf : 0, TEXT_CHROMA_U, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC ); |
---|
5212 | pcCU->setCbfSubParts( uiAbsSumV ? uiSetCbf : 0, TEXT_CHROMA_V, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC ); |
---|
5213 | } |
---|
5214 | |
---|
5215 | if( checkTransformSkipY ) |
---|
5216 | { |
---|
5217 | UInt uiNonzeroDistY, uiAbsSumTransformSkipY; |
---|
5218 | Double dSingleCostY; |
---|
5219 | |
---|
5220 | Pel *pcResiCurrY = m_pcQTTempTComYuv[ uiQTTempAccessLayer ].getLumaAddr( absTUPartIdx ); |
---|
5221 | UInt resiYStride = m_pcQTTempTComYuv[ uiQTTempAccessLayer ].getStride(); |
---|
5222 | |
---|
5223 | TCoeff bestCoeffY[32*32]; |
---|
5224 | memcpy( bestCoeffY, pcCoeffCurrY, sizeof(TCoeff) * uiNumSamplesLuma ); |
---|
5225 | |
---|
5226 | #if ADAPTIVE_QP_SELECTION |
---|
5227 | TCoeff bestArlCoeffY[32*32]; |
---|
5228 | memcpy( bestArlCoeffY, pcArlCoeffCurrY, sizeof(TCoeff) * uiNumSamplesLuma ); |
---|
5229 | #endif |
---|
5230 | |
---|
5231 | Pel bestResiY[32*32]; |
---|
5232 | for ( Int i = 0; i < trHeight; ++i ) |
---|
5233 | { |
---|
5234 | memcpy( &bestResiY[i*trWidth], pcResiCurrY+i*resiYStride, sizeof(Pel) * trWidth ); |
---|
5235 | } |
---|
5236 | |
---|
5237 | if( m_bUseSBACRD ) |
---|
5238 | { |
---|
5239 | m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] ); |
---|
5240 | } |
---|
5241 | |
---|
5242 | pcCU->setTransformSkipSubParts ( 1, TEXT_LUMA, uiAbsPartIdx, uiDepth ); |
---|
5243 | |
---|
5244 | if (m_pcEncCfg->getUseRDOQTS()) |
---|
5245 | { |
---|
5246 | m_pcEntropyCoder->estimateBit( m_pcTrQuant->m_pcEstBitsSbac, trWidth, trHeight, TEXT_LUMA ); |
---|
5247 | } |
---|
5248 | |
---|
5249 | #if REPN_FORMAT_IN_VPS |
---|
5250 | m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 ); |
---|
5251 | #else |
---|
5252 | m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 ); |
---|
5253 | #endif |
---|
5254 | |
---|
5255 | #if RDOQ_CHROMA_LAMBDA |
---|
5256 | m_pcTrQuant->selectLambda(TEXT_LUMA); |
---|
5257 | #endif |
---|
5258 | m_pcTrQuant->transformNxN( pcCU, pcResi->getLumaAddr( absTUPartIdx ), pcResi->getStride (), pcCoeffCurrY, |
---|
5259 | #if ADAPTIVE_QP_SELECTION |
---|
5260 | pcArlCoeffCurrY, |
---|
5261 | #endif |
---|
5262 | trWidth, trHeight, uiAbsSumTransformSkipY, TEXT_LUMA, uiAbsPartIdx, true ); |
---|
5263 | pcCU->setCbfSubParts( uiAbsSumTransformSkipY ? uiSetCbf : 0, TEXT_LUMA, uiAbsPartIdx, uiDepth ); |
---|
5264 | |
---|
5265 | if( uiAbsSumTransformSkipY != 0 ) |
---|
5266 | { |
---|
5267 | m_pcEntropyCoder->resetBits(); |
---|
5268 | m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrMode ); |
---|
5269 | m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrY, uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); |
---|
5270 | const UInt uiTsSingleBitsY = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
5271 | |
---|
5272 | #if REPN_FORMAT_IN_VPS |
---|
5273 | m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 ); |
---|
5274 | #else |
---|
5275 | m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 ); |
---|
5276 | #endif |
---|
5277 | |
---|
5278 | Int scalingListType = 3 + g_eTTable[(Int)TEXT_LUMA]; |
---|
5279 | assert(scalingListType < 6); |
---|
5280 | |
---|
5281 | m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA,REG_DCT, pcResiCurrY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(), pcCoeffCurrY, trWidth, trHeight, scalingListType, true ); |
---|
5282 | |
---|
5283 | uiNonzeroDistY = m_pcRdCost->getDistPart(g_bitDepthY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getLumaAddr( absTUPartIdx ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(), |
---|
5284 | pcResi->getLumaAddr( absTUPartIdx ), pcResi->getStride(), trWidth, trHeight ); |
---|
5285 | |
---|
5286 | dSingleCostY = m_pcRdCost->calcRdCost( uiTsSingleBitsY, uiNonzeroDistY ); |
---|
5287 | } |
---|
5288 | |
---|
5289 | if( !uiAbsSumTransformSkipY || minCostY < dSingleCostY ) |
---|
5290 | { |
---|
5291 | pcCU->setTransformSkipSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiDepth ); |
---|
5292 | memcpy( pcCoeffCurrY, bestCoeffY, sizeof(TCoeff) * uiNumSamplesLuma ); |
---|
5293 | #if ADAPTIVE_QP_SELECTION |
---|
5294 | memcpy( pcArlCoeffCurrY, bestArlCoeffY, sizeof(TCoeff) * uiNumSamplesLuma ); |
---|
5295 | #endif |
---|
5296 | for( Int i = 0; i < trHeight; ++i ) |
---|
5297 | { |
---|
5298 | memcpy( pcResiCurrY+i*resiYStride, &bestResiY[i*trWidth], sizeof(Pel) * trWidth ); |
---|
5299 | } |
---|
5300 | } |
---|
5301 | else |
---|
5302 | { |
---|
5303 | uiDistY = uiNonzeroDistY; |
---|
5304 | uiAbsSumY = uiAbsSumTransformSkipY; |
---|
5305 | uiBestTransformMode[0] = 1; |
---|
5306 | } |
---|
5307 | |
---|
5308 | pcCU->setCbfSubParts( uiAbsSumY ? uiSetCbf : 0, TEXT_LUMA, uiAbsPartIdx, uiDepth ); |
---|
5309 | } |
---|
5310 | |
---|
5311 | if( bCodeChroma && checkTransformSkipUV ) |
---|
5312 | { |
---|
5313 | UInt uiNonzeroDistU, uiNonzeroDistV, uiAbsSumTransformSkipU, uiAbsSumTransformSkipV; |
---|
5314 | Double dSingleCostU, dSingleCostV; |
---|
5315 | |
---|
5316 | Pel *pcResiCurrU = m_pcQTTempTComYuv[uiQTTempAccessLayer].getCbAddr( absTUPartIdxC ); |
---|
5317 | Pel *pcResiCurrV = m_pcQTTempTComYuv[uiQTTempAccessLayer].getCrAddr( absTUPartIdxC ); |
---|
5318 | UInt resiCStride = m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(); |
---|
5319 | |
---|
5320 | TCoeff bestCoeffU[32*32], bestCoeffV[32*32]; |
---|
5321 | memcpy( bestCoeffU, pcCoeffCurrU, sizeof(TCoeff) * uiNumSamplesChro ); |
---|
5322 | memcpy( bestCoeffV, pcCoeffCurrV, sizeof(TCoeff) * uiNumSamplesChro ); |
---|
5323 | |
---|
5324 | #if ADAPTIVE_QP_SELECTION |
---|
5325 | TCoeff bestArlCoeffU[32*32], bestArlCoeffV[32*32]; |
---|
5326 | memcpy( bestArlCoeffU, pcArlCoeffCurrU, sizeof(TCoeff) * uiNumSamplesChro ); |
---|
5327 | memcpy( bestArlCoeffV, pcArlCoeffCurrV, sizeof(TCoeff) * uiNumSamplesChro ); |
---|
5328 | #endif |
---|
5329 | |
---|
5330 | Pel bestResiU[32*32], bestResiV[32*32]; |
---|
5331 | for (Int i = 0; i < trHeightC; ++i ) |
---|
5332 | { |
---|
5333 | memcpy( &bestResiU[i*trWidthC], pcResiCurrU+i*resiCStride, sizeof(Pel) * trWidthC ); |
---|
5334 | memcpy( &bestResiV[i*trWidthC], pcResiCurrV+i*resiCStride, sizeof(Pel) * trWidthC ); |
---|
5335 | } |
---|
5336 | |
---|
5337 | if( m_bUseSBACRD ) |
---|
5338 | { |
---|
5339 | m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] ); |
---|
5340 | } |
---|
5341 | |
---|
5342 | pcCU->setTransformSkipSubParts ( 1, TEXT_CHROMA_U, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC ); |
---|
5343 | pcCU->setTransformSkipSubParts ( 1, TEXT_CHROMA_V, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC ); |
---|
5344 | |
---|
5345 | if (m_pcEncCfg->getUseRDOQTS()) |
---|
5346 | { |
---|
5347 | m_pcEntropyCoder->estimateBit(m_pcTrQuant->m_pcEstBitsSbac, trWidthC, trHeightC, TEXT_CHROMA ); |
---|
5348 | } |
---|
5349 | |
---|
5350 | Int curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb(); |
---|
5351 | m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset ); |
---|
5352 | |
---|
5353 | #if RDOQ_CHROMA_LAMBDA |
---|
5354 | m_pcTrQuant->selectLambda(TEXT_CHROMA); |
---|
5355 | #endif |
---|
5356 | |
---|
5357 | m_pcTrQuant->transformNxN( pcCU, pcResi->getCbAddr(absTUPartIdxC), pcResi->getCStride(), pcCoeffCurrU, |
---|
5358 | #if ADAPTIVE_QP_SELECTION |
---|
5359 | pcArlCoeffCurrU, |
---|
5360 | #endif |
---|
5361 | trWidthC, trHeightC, uiAbsSumTransformSkipU, TEXT_CHROMA_U, uiAbsPartIdx, true ); |
---|
5362 | curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr(); |
---|
5363 | m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset ); |
---|
5364 | m_pcTrQuant->transformNxN( pcCU, pcResi->getCrAddr(absTUPartIdxC), pcResi->getCStride(), pcCoeffCurrV, |
---|
5365 | #if ADAPTIVE_QP_SELECTION |
---|
5366 | pcArlCoeffCurrV, |
---|
5367 | #endif |
---|
5368 | trWidthC, trHeightC, uiAbsSumTransformSkipV, TEXT_CHROMA_V, uiAbsPartIdx, true ); |
---|
5369 | |
---|
5370 | pcCU->setCbfSubParts( uiAbsSumTransformSkipU ? uiSetCbf : 0, TEXT_CHROMA_U, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC ); |
---|
5371 | pcCU->setCbfSubParts( uiAbsSumTransformSkipV ? uiSetCbf : 0, TEXT_CHROMA_V, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC ); |
---|
5372 | |
---|
5373 | m_pcEntropyCoder->resetBits(); |
---|
5374 | uiSingleBitsU = 0; |
---|
5375 | uiSingleBitsV = 0; |
---|
5376 | |
---|
5377 | if( uiAbsSumTransformSkipU ) |
---|
5378 | { |
---|
5379 | m_pcEntropyCoder->encodeQtCbf ( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrMode ); |
---|
5380 | m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrU, uiAbsPartIdx, trWidthC, trHeightC, uiDepth, TEXT_CHROMA_U ); |
---|
5381 | uiSingleBitsU = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
5382 | |
---|
5383 | curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb(); |
---|
5384 | m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset ); |
---|
5385 | |
---|
5386 | Int scalingListType = 3 + g_eTTable[(Int)TEXT_CHROMA_U]; |
---|
5387 | assert(scalingListType < 6); |
---|
5388 | |
---|
5389 | m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA,REG_DCT, pcResiCurrU, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), pcCoeffCurrU, trWidthC, trHeightC, scalingListType, true ); |
---|
5390 | |
---|
5391 | uiNonzeroDistU = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCbAddr( absTUPartIdxC), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), |
---|
5392 | pcResi->getCbAddr( absTUPartIdxC), pcResi->getCStride(), trWidthC, trHeightC |
---|
5393 | #if WEIGHTED_CHROMA_DISTORTION |
---|
5394 | , TEXT_CHROMA_U |
---|
5395 | #endif |
---|
5396 | ); |
---|
5397 | |
---|
5398 | dSingleCostU = m_pcRdCost->calcRdCost( uiSingleBitsU, uiNonzeroDistU ); |
---|
5399 | } |
---|
5400 | |
---|
5401 | if( !uiAbsSumTransformSkipU || minCostU < dSingleCostU ) |
---|
5402 | { |
---|
5403 | pcCU->setTransformSkipSubParts ( 0, TEXT_CHROMA_U, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC ); |
---|
5404 | |
---|
5405 | memcpy( pcCoeffCurrU, bestCoeffU, sizeof (TCoeff) * uiNumSamplesChro ); |
---|
5406 | #if ADAPTIVE_QP_SELECTION |
---|
5407 | memcpy( pcArlCoeffCurrU, bestArlCoeffU, sizeof (TCoeff) * uiNumSamplesChro ); |
---|
5408 | #endif |
---|
5409 | for( Int i = 0; i < trHeightC; ++i ) |
---|
5410 | { |
---|
5411 | memcpy( pcResiCurrU+i*resiCStride, &bestResiU[i*trWidthC], sizeof(Pel) * trWidthC ); |
---|
5412 | } |
---|
5413 | } |
---|
5414 | else |
---|
5415 | { |
---|
5416 | uiDistU = uiNonzeroDistU; |
---|
5417 | uiAbsSumU = uiAbsSumTransformSkipU; |
---|
5418 | uiBestTransformMode[1] = 1; |
---|
5419 | } |
---|
5420 | |
---|
5421 | if( uiAbsSumTransformSkipV ) |
---|
5422 | { |
---|
5423 | m_pcEntropyCoder->encodeQtCbf ( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrMode ); |
---|
5424 | m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrV, uiAbsPartIdx, trWidthC, trHeightC, uiDepth, TEXT_CHROMA_V ); |
---|
5425 | uiSingleBitsV = m_pcEntropyCoder->getNumberOfWrittenBits() - uiSingleBitsU; |
---|
5426 | |
---|
5427 | curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr(); |
---|
5428 | m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset ); |
---|
5429 | |
---|
5430 | Int scalingListType = 3 + g_eTTable[(Int)TEXT_CHROMA_V]; |
---|
5431 | assert(scalingListType < 6); |
---|
5432 | |
---|
5433 | m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA,REG_DCT, pcResiCurrV, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), pcCoeffCurrV, trWidthC, trHeightC, scalingListType, true ); |
---|
5434 | |
---|
5435 | uiNonzeroDistV = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCrAddr( absTUPartIdxC ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), |
---|
5436 | pcResi->getCrAddr( absTUPartIdxC ), pcResi->getCStride(), trWidthC, trHeightC |
---|
5437 | #if WEIGHTED_CHROMA_DISTORTION |
---|
5438 | , TEXT_CHROMA_V |
---|
5439 | #endif |
---|
5440 | ); |
---|
5441 | |
---|
5442 | dSingleCostV = m_pcRdCost->calcRdCost( uiSingleBitsV, uiNonzeroDistV ); |
---|
5443 | } |
---|
5444 | |
---|
5445 | if( !uiAbsSumTransformSkipV || minCostV < dSingleCostV ) |
---|
5446 | { |
---|
5447 | pcCU->setTransformSkipSubParts ( 0, TEXT_CHROMA_V, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC ); |
---|
5448 | |
---|
5449 | memcpy( pcCoeffCurrV, bestCoeffV, sizeof(TCoeff) * uiNumSamplesChro ); |
---|
5450 | #if ADAPTIVE_QP_SELECTION |
---|
5451 | memcpy( pcArlCoeffCurrV, bestArlCoeffV, sizeof(TCoeff) * uiNumSamplesChro ); |
---|
5452 | #endif |
---|
5453 | for( Int i = 0; i < trHeightC; ++i ) |
---|
5454 | { |
---|
5455 | memcpy( pcResiCurrV+i*resiCStride, &bestResiV[i*trWidthC], sizeof(Pel) * trWidthC ); |
---|
5456 | } |
---|
5457 | } |
---|
5458 | else |
---|
5459 | { |
---|
5460 | uiDistV = uiNonzeroDistV; |
---|
5461 | uiAbsSumV = uiAbsSumTransformSkipV; |
---|
5462 | uiBestTransformMode[2] = 1; |
---|
5463 | } |
---|
5464 | |
---|
5465 | pcCU->setCbfSubParts( uiAbsSumU ? uiSetCbf : 0, TEXT_CHROMA_U, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC ); |
---|
5466 | pcCU->setCbfSubParts( uiAbsSumV ? uiSetCbf : 0, TEXT_CHROMA_V, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC ); |
---|
5467 | } |
---|
5468 | |
---|
5469 | if( m_bUseSBACRD ) |
---|
5470 | { |
---|
5471 | m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] ); |
---|
5472 | } |
---|
5473 | |
---|
5474 | m_pcEntropyCoder->resetBits(); |
---|
5475 | |
---|
5476 | { |
---|
5477 | if( uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
5478 | { |
---|
5479 | m_pcEntropyCoder->encodeTransformSubdivFlag( 0, 5 - uiLog2TrSize ); |
---|
5480 | } |
---|
5481 | } |
---|
5482 | |
---|
5483 | { |
---|
5484 | if( bCodeChroma ) |
---|
5485 | { |
---|
5486 | m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrMode ); |
---|
5487 | m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrMode ); |
---|
5488 | } |
---|
5489 | |
---|
5490 | m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrMode ); |
---|
5491 | } |
---|
5492 | |
---|
5493 | m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrY, uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); |
---|
5494 | |
---|
5495 | if( bCodeChroma ) |
---|
5496 | { |
---|
5497 | m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrU, uiAbsPartIdx, trWidthC, trHeightC, uiDepth, TEXT_CHROMA_U ); |
---|
5498 | m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrV, uiAbsPartIdx, trWidthC, trHeightC, uiDepth, TEXT_CHROMA_V ); |
---|
5499 | } |
---|
5500 | |
---|
5501 | uiSingleBits = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
5502 | |
---|
5503 | uiSingleDist = uiDistY + uiDistU + uiDistV; |
---|
5504 | dSingleCost = m_pcRdCost->calcRdCost( uiSingleBits, uiSingleDist ); |
---|
5505 | } |
---|
5506 | |
---|
5507 | // code sub-blocks |
---|
5508 | if( bCheckSplit ) |
---|
5509 | { |
---|
5510 | if( m_bUseSBACRD && bCheckFull ) |
---|
5511 | { |
---|
5512 | m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_TEST ] ); |
---|
5513 | m_pcRDGoOnSbacCoder->load ( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] ); |
---|
5514 | } |
---|
5515 | UInt uiSubdivDist = 0; |
---|
5516 | UInt uiSubdivBits = 0; |
---|
5517 | Double dSubdivCost = 0.0; |
---|
5518 | |
---|
5519 | const UInt uiQPartNumSubdiv = pcCU->getPic()->getNumPartInCU() >> ((uiDepth + 1 ) << 1); |
---|
5520 | for( UInt ui = 0; ui < 4; ++ui ) |
---|
5521 | { |
---|
5522 | UInt nsAddr = uiAbsPartIdx + ui * uiQPartNumSubdiv; |
---|
5523 | xEstimateResidualQT( pcCU, ui, uiAbsPartIdx + ui * uiQPartNumSubdiv, nsAddr, pcResi, uiDepth + 1, dSubdivCost, uiSubdivBits, uiSubdivDist, bCheckFull ? NULL : puiZeroDist ); |
---|
5524 | } |
---|
5525 | |
---|
5526 | UInt uiYCbf = 0; |
---|
5527 | UInt uiUCbf = 0; |
---|
5528 | UInt uiVCbf = 0; |
---|
5529 | for( UInt ui = 0; ui < 4; ++ui ) |
---|
5530 | { |
---|
5531 | uiYCbf |= pcCU->getCbf( uiAbsPartIdx + ui * uiQPartNumSubdiv, TEXT_LUMA, uiTrMode + 1 ); |
---|
5532 | uiUCbf |= pcCU->getCbf( uiAbsPartIdx + ui * uiQPartNumSubdiv, TEXT_CHROMA_U, uiTrMode + 1 ); |
---|
5533 | uiVCbf |= pcCU->getCbf( uiAbsPartIdx + ui * uiQPartNumSubdiv, TEXT_CHROMA_V, uiTrMode + 1 ); |
---|
5534 | } |
---|
5535 | for( UInt ui = 0; ui < 4 * uiQPartNumSubdiv; ++ui ) |
---|
5536 | { |
---|
5537 | pcCU->getCbf( TEXT_LUMA )[uiAbsPartIdx + ui] |= uiYCbf << uiTrMode; |
---|
5538 | pcCU->getCbf( TEXT_CHROMA_U )[uiAbsPartIdx + ui] |= uiUCbf << uiTrMode; |
---|
5539 | pcCU->getCbf( TEXT_CHROMA_V )[uiAbsPartIdx + ui] |= uiVCbf << uiTrMode; |
---|
5540 | } |
---|
5541 | |
---|
5542 | if( m_bUseSBACRD ) |
---|
5543 | { |
---|
5544 | m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] ); |
---|
5545 | } |
---|
5546 | m_pcEntropyCoder->resetBits(); |
---|
5547 | |
---|
5548 | { |
---|
5549 | xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, true, TEXT_LUMA ); |
---|
5550 | xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_LUMA ); |
---|
5551 | xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_CHROMA_U ); |
---|
5552 | xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_CHROMA_V ); |
---|
5553 | } |
---|
5554 | |
---|
5555 | uiSubdivBits = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
5556 | dSubdivCost = m_pcRdCost->calcRdCost( uiSubdivBits, uiSubdivDist ); |
---|
5557 | |
---|
5558 | if( uiYCbf || uiUCbf || uiVCbf || !bCheckFull ) |
---|
5559 | { |
---|
5560 | if( dSubdivCost < dSingleCost ) |
---|
5561 | { |
---|
5562 | rdCost += dSubdivCost; |
---|
5563 | ruiBits += uiSubdivBits; |
---|
5564 | ruiDist += uiSubdivDist; |
---|
5565 | return; |
---|
5566 | } |
---|
5567 | } |
---|
5568 | pcCU->setTransformSkipSubParts ( uiBestTransformMode[0], TEXT_LUMA, uiAbsPartIdx, uiDepth ); |
---|
5569 | if(bCodeChroma) |
---|
5570 | { |
---|
5571 | pcCU->setTransformSkipSubParts ( uiBestTransformMode[1], TEXT_CHROMA_U, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC ); |
---|
5572 | pcCU->setTransformSkipSubParts ( uiBestTransformMode[2], TEXT_CHROMA_V, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC ); |
---|
5573 | } |
---|
5574 | assert( bCheckFull ); |
---|
5575 | if( m_bUseSBACRD ) |
---|
5576 | { |
---|
5577 | m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_TEST ] ); |
---|
5578 | } |
---|
5579 | } |
---|
5580 | rdCost += dSingleCost; |
---|
5581 | ruiBits += uiSingleBits; |
---|
5582 | ruiDist += uiSingleDist; |
---|
5583 | |
---|
5584 | pcCU->setTrIdxSubParts( uiTrMode, uiAbsPartIdx, uiDepth ); |
---|
5585 | |
---|
5586 | pcCU->setCbfSubParts( uiAbsSumY ? uiSetCbf : 0, TEXT_LUMA, uiAbsPartIdx, uiDepth ); |
---|
5587 | if( bCodeChroma ) |
---|
5588 | { |
---|
5589 | pcCU->setCbfSubParts( uiAbsSumU ? uiSetCbf : 0, TEXT_CHROMA_U, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC ); |
---|
5590 | pcCU->setCbfSubParts( uiAbsSumV ? uiSetCbf : 0, TEXT_CHROMA_V, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC ); |
---|
5591 | } |
---|
5592 | } |
---|
5593 | |
---|
5594 | Void TEncSearch::xEncodeResidualQT( TComDataCU* pcCU, UInt uiAbsPartIdx, const UInt uiDepth, Bool bSubdivAndCbf, TextType eType ) |
---|
5595 | { |
---|
5596 | assert( pcCU->getDepth( 0 ) == pcCU->getDepth( uiAbsPartIdx ) ); |
---|
5597 | const UInt uiCurrTrMode = uiDepth - pcCU->getDepth( 0 ); |
---|
5598 | const UInt uiTrMode = pcCU->getTransformIdx( uiAbsPartIdx ); |
---|
5599 | |
---|
5600 | const Bool bSubdiv = uiCurrTrMode != uiTrMode; |
---|
5601 | |
---|
5602 | const UInt uiLog2TrSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth]+2; |
---|
5603 | |
---|
5604 | { |
---|
5605 | if( bSubdivAndCbf && uiLog2TrSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() && uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
5606 | { |
---|
5607 | m_pcEntropyCoder->encodeTransformSubdivFlag( bSubdiv, 5 - uiLog2TrSize ); |
---|
5608 | } |
---|
5609 | } |
---|
5610 | |
---|
5611 | { |
---|
5612 | assert( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA ); |
---|
5613 | if( bSubdivAndCbf ) |
---|
5614 | { |
---|
5615 | const Bool bFirstCbfOfCU = uiCurrTrMode == 0; |
---|
5616 | if( bFirstCbfOfCU || uiLog2TrSize > 2 ) |
---|
5617 | { |
---|
5618 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiCurrTrMode - 1 ) ) |
---|
5619 | { |
---|
5620 | m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiCurrTrMode ); |
---|
5621 | } |
---|
5622 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiCurrTrMode - 1 ) ) |
---|
5623 | { |
---|
5624 | m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiCurrTrMode ); |
---|
5625 | } |
---|
5626 | } |
---|
5627 | else if( uiLog2TrSize == 2 ) |
---|
5628 | { |
---|
5629 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiCurrTrMode ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiCurrTrMode - 1 ) ); |
---|
5630 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiCurrTrMode ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiCurrTrMode - 1 ) ); |
---|
5631 | } |
---|
5632 | } |
---|
5633 | } |
---|
5634 | |
---|
5635 | if( !bSubdiv ) |
---|
5636 | { |
---|
5637 | const UInt uiNumCoeffPerAbsPartIdxIncrement = pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ); |
---|
5638 | //assert( 16 == uiNumCoeffPerAbsPartIdxIncrement ); // check |
---|
5639 | const UInt uiQTTempAccessLayer = pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() - uiLog2TrSize; |
---|
5640 | TCoeff *pcCoeffCurrY = m_ppcQTTempCoeffY [uiQTTempAccessLayer] + uiNumCoeffPerAbsPartIdxIncrement * uiAbsPartIdx; |
---|
5641 | TCoeff *pcCoeffCurrU = m_ppcQTTempCoeffCb[uiQTTempAccessLayer] + (uiNumCoeffPerAbsPartIdxIncrement * uiAbsPartIdx>>2); |
---|
5642 | TCoeff *pcCoeffCurrV = m_ppcQTTempCoeffCr[uiQTTempAccessLayer] + (uiNumCoeffPerAbsPartIdxIncrement * uiAbsPartIdx>>2); |
---|
5643 | |
---|
5644 | Bool bCodeChroma = true; |
---|
5645 | UInt uiTrModeC = uiTrMode; |
---|
5646 | UInt uiLog2TrSizeC = uiLog2TrSize-1; |
---|
5647 | if( uiLog2TrSize == 2 ) |
---|
5648 | { |
---|
5649 | uiLog2TrSizeC++; |
---|
5650 | uiTrModeC --; |
---|
5651 | UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrModeC ) << 1 ); |
---|
5652 | bCodeChroma = ( ( uiAbsPartIdx % uiQPDiv ) == 0 ); |
---|
5653 | } |
---|
5654 | |
---|
5655 | if( bSubdivAndCbf ) |
---|
5656 | { |
---|
5657 | { |
---|
5658 | m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrMode ); |
---|
5659 | } |
---|
5660 | } |
---|
5661 | else |
---|
5662 | { |
---|
5663 | if( eType == TEXT_LUMA && pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrMode ) ) |
---|
5664 | { |
---|
5665 | Int trWidth = 1 << uiLog2TrSize; |
---|
5666 | Int trHeight = 1 << uiLog2TrSize; |
---|
5667 | m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrY, uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); |
---|
5668 | } |
---|
5669 | if( bCodeChroma ) |
---|
5670 | { |
---|
5671 | Int trWidth = 1 << uiLog2TrSizeC; |
---|
5672 | Int trHeight = 1 << uiLog2TrSizeC; |
---|
5673 | if( eType == TEXT_CHROMA_U && pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrMode ) ) |
---|
5674 | { |
---|
5675 | m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrU, uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
5676 | } |
---|
5677 | if( eType == TEXT_CHROMA_V && pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrMode ) ) |
---|
5678 | { |
---|
5679 | m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrV, uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
5680 | } |
---|
5681 | } |
---|
5682 | } |
---|
5683 | } |
---|
5684 | else |
---|
5685 | { |
---|
5686 | if( bSubdivAndCbf || pcCU->getCbf( uiAbsPartIdx, eType, uiCurrTrMode ) ) |
---|
5687 | { |
---|
5688 | const UInt uiQPartNumSubdiv = pcCU->getPic()->getNumPartInCU() >> ((uiDepth + 1 ) << 1); |
---|
5689 | for( UInt ui = 0; ui < 4; ++ui ) |
---|
5690 | { |
---|
5691 | xEncodeResidualQT( pcCU, uiAbsPartIdx + ui * uiQPartNumSubdiv, uiDepth + 1, bSubdivAndCbf, eType ); |
---|
5692 | } |
---|
5693 | } |
---|
5694 | } |
---|
5695 | } |
---|
5696 | |
---|
5697 | Void TEncSearch::xSetResidualQTData( TComDataCU* pcCU, UInt uiQuadrant, UInt uiAbsPartIdx, UInt absTUPartIdx, TComYuv* pcResi, UInt uiDepth, Bool bSpatial ) |
---|
5698 | { |
---|
5699 | assert( pcCU->getDepth( 0 ) == pcCU->getDepth( uiAbsPartIdx ) ); |
---|
5700 | const UInt uiCurrTrMode = uiDepth - pcCU->getDepth( 0 ); |
---|
5701 | const UInt uiTrMode = pcCU->getTransformIdx( uiAbsPartIdx ); |
---|
5702 | |
---|
5703 | if( uiCurrTrMode == uiTrMode ) |
---|
5704 | { |
---|
5705 | const UInt uiLog2TrSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth]+2; |
---|
5706 | const UInt uiQTTempAccessLayer = pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() - uiLog2TrSize; |
---|
5707 | |
---|
5708 | Bool bCodeChroma = true; |
---|
5709 | UInt uiTrModeC = uiTrMode; |
---|
5710 | UInt uiLog2TrSizeC = uiLog2TrSize-1; |
---|
5711 | if( uiLog2TrSize == 2 ) |
---|
5712 | { |
---|
5713 | uiLog2TrSizeC++; |
---|
5714 | uiTrModeC --; |
---|
5715 | UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrModeC ) << 1 ); |
---|
5716 | bCodeChroma = ( ( uiAbsPartIdx % uiQPDiv ) == 0 ); |
---|
5717 | } |
---|
5718 | |
---|
5719 | if( bSpatial ) |
---|
5720 | { |
---|
5721 | Int trWidth = 1 << uiLog2TrSize; |
---|
5722 | Int trHeight = 1 << uiLog2TrSize; |
---|
5723 | m_pcQTTempTComYuv[uiQTTempAccessLayer].copyPartToPartLuma ( pcResi, absTUPartIdx, trWidth , trHeight ); |
---|
5724 | |
---|
5725 | if( bCodeChroma ) |
---|
5726 | { |
---|
5727 | { |
---|
5728 | m_pcQTTempTComYuv[uiQTTempAccessLayer].copyPartToPartChroma( pcResi, uiAbsPartIdx, 1 << uiLog2TrSizeC, 1 << uiLog2TrSizeC ); |
---|
5729 | } |
---|
5730 | } |
---|
5731 | } |
---|
5732 | else |
---|
5733 | { |
---|
5734 | UInt uiNumCoeffPerAbsPartIdxIncrement = pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ); |
---|
5735 | UInt uiNumCoeffY = ( 1 << ( uiLog2TrSize << 1 ) ); |
---|
5736 | TCoeff* pcCoeffSrcY = m_ppcQTTempCoeffY [uiQTTempAccessLayer] + uiNumCoeffPerAbsPartIdxIncrement * uiAbsPartIdx; |
---|
5737 | TCoeff* pcCoeffDstY = pcCU->getCoeffY() + uiNumCoeffPerAbsPartIdxIncrement * uiAbsPartIdx; |
---|
5738 | ::memcpy( pcCoeffDstY, pcCoeffSrcY, sizeof( TCoeff ) * uiNumCoeffY ); |
---|
5739 | #if ADAPTIVE_QP_SELECTION |
---|
5740 | Int* pcArlCoeffSrcY = m_ppcQTTempArlCoeffY [uiQTTempAccessLayer] + uiNumCoeffPerAbsPartIdxIncrement * uiAbsPartIdx; |
---|
5741 | Int* pcArlCoeffDstY = pcCU->getArlCoeffY() + uiNumCoeffPerAbsPartIdxIncrement * uiAbsPartIdx; |
---|
5742 | ::memcpy( pcArlCoeffDstY, pcArlCoeffSrcY, sizeof( Int ) * uiNumCoeffY ); |
---|
5743 | #endif |
---|
5744 | if( bCodeChroma ) |
---|
5745 | { |
---|
5746 | UInt uiNumCoeffC = ( 1 << ( uiLog2TrSizeC << 1 ) ); |
---|
5747 | TCoeff* pcCoeffSrcU = m_ppcQTTempCoeffCb[uiQTTempAccessLayer] + (uiNumCoeffPerAbsPartIdxIncrement * uiAbsPartIdx>>2); |
---|
5748 | TCoeff* pcCoeffSrcV = m_ppcQTTempCoeffCr[uiQTTempAccessLayer] + (uiNumCoeffPerAbsPartIdxIncrement * uiAbsPartIdx>>2); |
---|
5749 | TCoeff* pcCoeffDstU = pcCU->getCoeffCb() + (uiNumCoeffPerAbsPartIdxIncrement * uiAbsPartIdx>>2); |
---|
5750 | TCoeff* pcCoeffDstV = pcCU->getCoeffCr() + (uiNumCoeffPerAbsPartIdxIncrement * uiAbsPartIdx>>2); |
---|
5751 | ::memcpy( pcCoeffDstU, pcCoeffSrcU, sizeof( TCoeff ) * uiNumCoeffC ); |
---|
5752 | ::memcpy( pcCoeffDstV, pcCoeffSrcV, sizeof( TCoeff ) * uiNumCoeffC ); |
---|
5753 | #if ADAPTIVE_QP_SELECTION |
---|
5754 | Int* pcArlCoeffSrcU = m_ppcQTTempArlCoeffCb[uiQTTempAccessLayer] + (uiNumCoeffPerAbsPartIdxIncrement * uiAbsPartIdx>>2); |
---|
5755 | Int* pcArlCoeffSrcV = m_ppcQTTempArlCoeffCr[uiQTTempAccessLayer] + (uiNumCoeffPerAbsPartIdxIncrement * uiAbsPartIdx>>2); |
---|
5756 | Int* pcArlCoeffDstU = pcCU->getArlCoeffCb() + (uiNumCoeffPerAbsPartIdxIncrement * uiAbsPartIdx>>2); |
---|
5757 | Int* pcArlCoeffDstV = pcCU->getArlCoeffCr() + (uiNumCoeffPerAbsPartIdxIncrement * uiAbsPartIdx>>2); |
---|
5758 | ::memcpy( pcArlCoeffDstU, pcArlCoeffSrcU, sizeof( Int ) * uiNumCoeffC ); |
---|
5759 | ::memcpy( pcArlCoeffDstV, pcArlCoeffSrcV, sizeof( Int ) * uiNumCoeffC ); |
---|
5760 | #endif |
---|
5761 | } |
---|
5762 | } |
---|
5763 | } |
---|
5764 | else |
---|
5765 | { |
---|
5766 | const UInt uiQPartNumSubdiv = pcCU->getPic()->getNumPartInCU() >> ((uiDepth + 1 ) << 1); |
---|
5767 | for( UInt ui = 0; ui < 4; ++ui ) |
---|
5768 | { |
---|
5769 | UInt nsAddr = uiAbsPartIdx + ui * uiQPartNumSubdiv; |
---|
5770 | xSetResidualQTData( pcCU, ui, uiAbsPartIdx + ui * uiQPartNumSubdiv, nsAddr, pcResi, uiDepth + 1, bSpatial ); |
---|
5771 | } |
---|
5772 | } |
---|
5773 | } |
---|
5774 | |
---|
5775 | UInt TEncSearch::xModeBitsIntra( TComDataCU* pcCU, UInt uiMode, UInt uiPU, UInt uiPartOffset, UInt uiDepth, UInt uiInitTrDepth ) |
---|
5776 | { |
---|
5777 | if( m_bUseSBACRD ) |
---|
5778 | { |
---|
5779 | // Reload only contexts required for coding intra mode information |
---|
5780 | m_pcRDGoOnSbacCoder->loadIntraDirModeLuma( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); |
---|
5781 | } |
---|
5782 | |
---|
5783 | pcCU->setLumaIntraDirSubParts ( uiMode, uiPartOffset, uiDepth + uiInitTrDepth ); |
---|
5784 | |
---|
5785 | m_pcEntropyCoder->resetBits(); |
---|
5786 | m_pcEntropyCoder->encodeIntraDirModeLuma ( pcCU, uiPartOffset); |
---|
5787 | |
---|
5788 | return m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
5789 | } |
---|
5790 | |
---|
5791 | UInt TEncSearch::xUpdateCandList( UInt uiMode, Double uiCost, UInt uiFastCandNum, UInt * CandModeList, Double * CandCostList ) |
---|
5792 | { |
---|
5793 | UInt i; |
---|
5794 | UInt shift=0; |
---|
5795 | |
---|
5796 | while ( shift<uiFastCandNum && uiCost<CandCostList[ uiFastCandNum-1-shift ] ) shift++; |
---|
5797 | |
---|
5798 | if( shift!=0 ) |
---|
5799 | { |
---|
5800 | for(i=1; i<shift; i++) |
---|
5801 | { |
---|
5802 | CandModeList[ uiFastCandNum-i ] = CandModeList[ uiFastCandNum-1-i ]; |
---|
5803 | CandCostList[ uiFastCandNum-i ] = CandCostList[ uiFastCandNum-1-i ]; |
---|
5804 | } |
---|
5805 | CandModeList[ uiFastCandNum-shift ] = uiMode; |
---|
5806 | CandCostList[ uiFastCandNum-shift ] = uiCost; |
---|
5807 | return 1; |
---|
5808 | } |
---|
5809 | |
---|
5810 | return 0; |
---|
5811 | } |
---|
5812 | |
---|
5813 | /** add inter-prediction syntax elements for a CU block |
---|
5814 | * \param pcCU |
---|
5815 | * \param uiQp |
---|
5816 | * \param uiTrMode |
---|
5817 | * \param ruiBits |
---|
5818 | * \param rpcYuvRec |
---|
5819 | * \param pcYuvPred |
---|
5820 | * \param rpcYuvResi |
---|
5821 | * \returns Void |
---|
5822 | */ |
---|
5823 | Void TEncSearch::xAddSymbolBitsInter( TComDataCU* pcCU, UInt uiQp, UInt uiTrMode, UInt& ruiBits, TComYuv*& rpcYuvRec, TComYuv*pcYuvPred, TComYuv*& rpcYuvResi ) |
---|
5824 | { |
---|
5825 | if(pcCU->getMergeFlag( 0 ) && pcCU->getPartitionSize( 0 ) == SIZE_2Nx2N && !pcCU->getQtRootCbf( 0 )) |
---|
5826 | { |
---|
5827 | pcCU->setSkipFlagSubParts( true, 0, pcCU->getDepth(0) ); |
---|
5828 | |
---|
5829 | m_pcEntropyCoder->resetBits(); |
---|
5830 | if(pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
5831 | { |
---|
5832 | m_pcEntropyCoder->encodeCUTransquantBypassFlag(pcCU, 0, true); |
---|
5833 | } |
---|
5834 | m_pcEntropyCoder->encodeSkipFlag(pcCU, 0, true); |
---|
5835 | m_pcEntropyCoder->encodeMergeIndex(pcCU, 0, true); |
---|
5836 | ruiBits += m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
5837 | } |
---|
5838 | else |
---|
5839 | { |
---|
5840 | m_pcEntropyCoder->resetBits(); |
---|
5841 | if(pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
5842 | { |
---|
5843 | m_pcEntropyCoder->encodeCUTransquantBypassFlag(pcCU, 0, true); |
---|
5844 | } |
---|
5845 | m_pcEntropyCoder->encodeSkipFlag ( pcCU, 0, true ); |
---|
5846 | m_pcEntropyCoder->encodePredMode( pcCU, 0, true ); |
---|
5847 | m_pcEntropyCoder->encodePartSize( pcCU, 0, pcCU->getDepth(0), true ); |
---|
5848 | m_pcEntropyCoder->encodePredInfo( pcCU, 0, true ); |
---|
5849 | |
---|
5850 | Bool bDummy = false; |
---|
5851 | m_pcEntropyCoder->encodeCoeff ( pcCU, 0, pcCU->getDepth(0), pcCU->getWidth(0), pcCU->getHeight(0), bDummy ); |
---|
5852 | |
---|
5853 | ruiBits += m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
5854 | } |
---|
5855 | } |
---|
5856 | |
---|
5857 | /** |
---|
5858 | * \brief Generate half-sample interpolated block |
---|
5859 | * |
---|
5860 | * \param pattern Reference picture ROI |
---|
5861 | * \param biPred Flag indicating whether block is for biprediction |
---|
5862 | */ |
---|
5863 | Void TEncSearch::xExtDIFUpSamplingH( TComPattern* pattern, Bool biPred ) |
---|
5864 | { |
---|
5865 | Int width = pattern->getROIYWidth(); |
---|
5866 | Int height = pattern->getROIYHeight(); |
---|
5867 | Int srcStride = pattern->getPatternLStride(); |
---|
5868 | |
---|
5869 | Int intStride = m_filteredBlockTmp[0].getStride(); |
---|
5870 | Int dstStride = m_filteredBlock[0][0].getStride(); |
---|
5871 | Short *intPtr; |
---|
5872 | Short *dstPtr; |
---|
5873 | Int filterSize = NTAPS_LUMA; |
---|
5874 | Int halfFilterSize = (filterSize>>1); |
---|
5875 | Pel *srcPtr = pattern->getROIY() - halfFilterSize*srcStride - 1; |
---|
5876 | |
---|
5877 | m_if.filterHorLuma(srcPtr, srcStride, m_filteredBlockTmp[0].getLumaAddr(), intStride, width+1, height+filterSize, 0, false); |
---|
5878 | m_if.filterHorLuma(srcPtr, srcStride, m_filteredBlockTmp[2].getLumaAddr(), intStride, width+1, height+filterSize, 2, false); |
---|
5879 | |
---|
5880 | intPtr = m_filteredBlockTmp[0].getLumaAddr() + halfFilterSize * intStride + 1; |
---|
5881 | dstPtr = m_filteredBlock[0][0].getLumaAddr(); |
---|
5882 | m_if.filterVerLuma(intPtr, intStride, dstPtr, dstStride, width+0, height+0, 0, false, true); |
---|
5883 | |
---|
5884 | intPtr = m_filteredBlockTmp[0].getLumaAddr() + (halfFilterSize-1) * intStride + 1; |
---|
5885 | dstPtr = m_filteredBlock[2][0].getLumaAddr(); |
---|
5886 | m_if.filterVerLuma(intPtr, intStride, dstPtr, dstStride, width+0, height+1, 2, false, true); |
---|
5887 | |
---|
5888 | intPtr = m_filteredBlockTmp[2].getLumaAddr() + halfFilterSize * intStride; |
---|
5889 | dstPtr = m_filteredBlock[0][2].getLumaAddr(); |
---|
5890 | m_if.filterVerLuma(intPtr, intStride, dstPtr, dstStride, width+1, height+0, 0, false, true); |
---|
5891 | |
---|
5892 | intPtr = m_filteredBlockTmp[2].getLumaAddr() + (halfFilterSize-1) * intStride; |
---|
5893 | dstPtr = m_filteredBlock[2][2].getLumaAddr(); |
---|
5894 | m_if.filterVerLuma(intPtr, intStride, dstPtr, dstStride, width+1, height+1, 2, false, true); |
---|
5895 | } |
---|
5896 | |
---|
5897 | /** |
---|
5898 | * \brief Generate quarter-sample interpolated blocks |
---|
5899 | * |
---|
5900 | * \param pattern Reference picture ROI |
---|
5901 | * \param halfPelRef Half-pel mv |
---|
5902 | * \param biPred Flag indicating whether block is for biprediction |
---|
5903 | */ |
---|
5904 | Void TEncSearch::xExtDIFUpSamplingQ( TComPattern* pattern, TComMv halfPelRef, Bool biPred ) |
---|
5905 | { |
---|
5906 | Int width = pattern->getROIYWidth(); |
---|
5907 | Int height = pattern->getROIYHeight(); |
---|
5908 | Int srcStride = pattern->getPatternLStride(); |
---|
5909 | |
---|
5910 | Pel *srcPtr; |
---|
5911 | Int intStride = m_filteredBlockTmp[0].getStride(); |
---|
5912 | Int dstStride = m_filteredBlock[0][0].getStride(); |
---|
5913 | Short *intPtr; |
---|
5914 | Short *dstPtr; |
---|
5915 | Int filterSize = NTAPS_LUMA; |
---|
5916 | |
---|
5917 | Int halfFilterSize = (filterSize>>1); |
---|
5918 | |
---|
5919 | Int extHeight = (halfPelRef.getVer() == 0) ? height + filterSize : height + filterSize-1; |
---|
5920 | |
---|
5921 | // Horizontal filter 1/4 |
---|
5922 | srcPtr = pattern->getROIY() - halfFilterSize * srcStride - 1; |
---|
5923 | intPtr = m_filteredBlockTmp[1].getLumaAddr(); |
---|
5924 | if (halfPelRef.getVer() > 0) |
---|
5925 | { |
---|
5926 | srcPtr += srcStride; |
---|
5927 | } |
---|
5928 | if (halfPelRef.getHor() >= 0) |
---|
5929 | { |
---|
5930 | srcPtr += 1; |
---|
5931 | } |
---|
5932 | m_if.filterHorLuma(srcPtr, srcStride, intPtr, intStride, width, extHeight, 1, false); |
---|
5933 | |
---|
5934 | // Horizontal filter 3/4 |
---|
5935 | srcPtr = pattern->getROIY() - halfFilterSize*srcStride - 1; |
---|
5936 | intPtr = m_filteredBlockTmp[3].getLumaAddr(); |
---|
5937 | if (halfPelRef.getVer() > 0) |
---|
5938 | { |
---|
5939 | srcPtr += srcStride; |
---|
5940 | } |
---|
5941 | if (halfPelRef.getHor() > 0) |
---|
5942 | { |
---|
5943 | srcPtr += 1; |
---|
5944 | } |
---|
5945 | m_if.filterHorLuma(srcPtr, srcStride, intPtr, intStride, width, extHeight, 3, false); |
---|
5946 | |
---|
5947 | // Generate @ 1,1 |
---|
5948 | intPtr = m_filteredBlockTmp[1].getLumaAddr() + (halfFilterSize-1) * intStride; |
---|
5949 | dstPtr = m_filteredBlock[1][1].getLumaAddr(); |
---|
5950 | if (halfPelRef.getVer() == 0) |
---|
5951 | { |
---|
5952 | intPtr += intStride; |
---|
5953 | } |
---|
5954 | m_if.filterVerLuma(intPtr, intStride, dstPtr, dstStride, width, height, 1, false, true); |
---|
5955 | |
---|
5956 | // Generate @ 3,1 |
---|
5957 | intPtr = m_filteredBlockTmp[1].getLumaAddr() + (halfFilterSize-1) * intStride; |
---|
5958 | dstPtr = m_filteredBlock[3][1].getLumaAddr(); |
---|
5959 | m_if.filterVerLuma(intPtr, intStride, dstPtr, dstStride, width, height, 3, false, true); |
---|
5960 | |
---|
5961 | if (halfPelRef.getVer() != 0) |
---|
5962 | { |
---|
5963 | // Generate @ 2,1 |
---|
5964 | intPtr = m_filteredBlockTmp[1].getLumaAddr() + (halfFilterSize-1) * intStride; |
---|
5965 | dstPtr = m_filteredBlock[2][1].getLumaAddr(); |
---|
5966 | if (halfPelRef.getVer() == 0) |
---|
5967 | { |
---|
5968 | intPtr += intStride; |
---|
5969 | } |
---|
5970 | m_if.filterVerLuma(intPtr, intStride, dstPtr, dstStride, width, height, 2, false, true); |
---|
5971 | |
---|
5972 | // Generate @ 2,3 |
---|
5973 | intPtr = m_filteredBlockTmp[3].getLumaAddr() + (halfFilterSize-1) * intStride; |
---|
5974 | dstPtr = m_filteredBlock[2][3].getLumaAddr(); |
---|
5975 | if (halfPelRef.getVer() == 0) |
---|
5976 | { |
---|
5977 | intPtr += intStride; |
---|
5978 | } |
---|
5979 | m_if.filterVerLuma(intPtr, intStride, dstPtr, dstStride, width, height, 2, false, true); |
---|
5980 | } |
---|
5981 | else |
---|
5982 | { |
---|
5983 | // Generate @ 0,1 |
---|
5984 | intPtr = m_filteredBlockTmp[1].getLumaAddr() + halfFilterSize * intStride; |
---|
5985 | dstPtr = m_filteredBlock[0][1].getLumaAddr(); |
---|
5986 | m_if.filterVerLuma(intPtr, intStride, dstPtr, dstStride, width, height, 0, false, true); |
---|
5987 | |
---|
5988 | // Generate @ 0,3 |
---|
5989 | intPtr = m_filteredBlockTmp[3].getLumaAddr() + halfFilterSize * intStride; |
---|
5990 | dstPtr = m_filteredBlock[0][3].getLumaAddr(); |
---|
5991 | m_if.filterVerLuma(intPtr, intStride, dstPtr, dstStride, width, height, 0, false, true); |
---|
5992 | } |
---|
5993 | |
---|
5994 | if (halfPelRef.getHor() != 0) |
---|
5995 | { |
---|
5996 | // Generate @ 1,2 |
---|
5997 | intPtr = m_filteredBlockTmp[2].getLumaAddr() + (halfFilterSize-1) * intStride; |
---|
5998 | dstPtr = m_filteredBlock[1][2].getLumaAddr(); |
---|
5999 | if (halfPelRef.getHor() > 0) |
---|
6000 | { |
---|
6001 | intPtr += 1; |
---|
6002 | } |
---|
6003 | if (halfPelRef.getVer() >= 0) |
---|
6004 | { |
---|
6005 | intPtr += intStride; |
---|
6006 | } |
---|
6007 | m_if.filterVerLuma(intPtr, intStride, dstPtr, dstStride, width, height, 1, false, true); |
---|
6008 | |
---|
6009 | // Generate @ 3,2 |
---|
6010 | intPtr = m_filteredBlockTmp[2].getLumaAddr() + (halfFilterSize-1) * intStride; |
---|
6011 | dstPtr = m_filteredBlock[3][2].getLumaAddr(); |
---|
6012 | if (halfPelRef.getHor() > 0) |
---|
6013 | { |
---|
6014 | intPtr += 1; |
---|
6015 | } |
---|
6016 | if (halfPelRef.getVer() > 0) |
---|
6017 | { |
---|
6018 | intPtr += intStride; |
---|
6019 | } |
---|
6020 | m_if.filterVerLuma(intPtr, intStride, dstPtr, dstStride, width, height, 3, false, true); |
---|
6021 | } |
---|
6022 | else |
---|
6023 | { |
---|
6024 | // Generate @ 1,0 |
---|
6025 | intPtr = m_filteredBlockTmp[0].getLumaAddr() + (halfFilterSize-1) * intStride + 1; |
---|
6026 | dstPtr = m_filteredBlock[1][0].getLumaAddr(); |
---|
6027 | if (halfPelRef.getVer() >= 0) |
---|
6028 | { |
---|
6029 | intPtr += intStride; |
---|
6030 | } |
---|
6031 | m_if.filterVerLuma(intPtr, intStride, dstPtr, dstStride, width, height, 1, false, true); |
---|
6032 | |
---|
6033 | // Generate @ 3,0 |
---|
6034 | intPtr = m_filteredBlockTmp[0].getLumaAddr() + (halfFilterSize-1) * intStride + 1; |
---|
6035 | dstPtr = m_filteredBlock[3][0].getLumaAddr(); |
---|
6036 | if (halfPelRef.getVer() > 0) |
---|
6037 | { |
---|
6038 | intPtr += intStride; |
---|
6039 | } |
---|
6040 | m_if.filterVerLuma(intPtr, intStride, dstPtr, dstStride, width, height, 3, false, true); |
---|
6041 | } |
---|
6042 | |
---|
6043 | // Generate @ 1,3 |
---|
6044 | intPtr = m_filteredBlockTmp[3].getLumaAddr() + (halfFilterSize-1) * intStride; |
---|
6045 | dstPtr = m_filteredBlock[1][3].getLumaAddr(); |
---|
6046 | if (halfPelRef.getVer() == 0) |
---|
6047 | { |
---|
6048 | intPtr += intStride; |
---|
6049 | } |
---|
6050 | m_if.filterVerLuma(intPtr, intStride, dstPtr, dstStride, width, height, 1, false, true); |
---|
6051 | |
---|
6052 | // Generate @ 3,3 |
---|
6053 | intPtr = m_filteredBlockTmp[3].getLumaAddr() + (halfFilterSize-1) * intStride; |
---|
6054 | dstPtr = m_filteredBlock[3][3].getLumaAddr(); |
---|
6055 | m_if.filterVerLuma(intPtr, intStride, dstPtr, dstStride, width, height, 3, false, true); |
---|
6056 | } |
---|
6057 | |
---|
6058 | /** set wp tables |
---|
6059 | * \param TComDataCU* pcCU |
---|
6060 | * \param iRefIdx |
---|
6061 | * \param eRefPicListCur |
---|
6062 | * \returns Void |
---|
6063 | */ |
---|
6064 | Void TEncSearch::setWpScalingDistParam( TComDataCU* pcCU, Int iRefIdx, RefPicList eRefPicListCur ) |
---|
6065 | { |
---|
6066 | if ( iRefIdx<0 ) |
---|
6067 | { |
---|
6068 | m_cDistParam.bApplyWeight = false; |
---|
6069 | return; |
---|
6070 | } |
---|
6071 | |
---|
6072 | TComSlice *pcSlice = pcCU->getSlice(); |
---|
6073 | TComPPS *pps = pcCU->getSlice()->getPPS(); |
---|
6074 | wpScalingParam *wp0 , *wp1; |
---|
6075 | m_cDistParam.bApplyWeight = ( pcSlice->getSliceType()==P_SLICE && pps->getUseWP() ) || ( pcSlice->getSliceType()==B_SLICE && pps->getWPBiPred() ) ; |
---|
6076 | if ( !m_cDistParam.bApplyWeight ) return; |
---|
6077 | |
---|
6078 | Int iRefIdx0 = ( eRefPicListCur == REF_PIC_LIST_0 ) ? iRefIdx : (-1); |
---|
6079 | Int iRefIdx1 = ( eRefPicListCur == REF_PIC_LIST_1 ) ? iRefIdx : (-1); |
---|
6080 | |
---|
6081 | getWpScaling( pcCU, iRefIdx0, iRefIdx1, wp0 , wp1 ); |
---|
6082 | |
---|
6083 | if ( iRefIdx0 < 0 ) wp0 = NULL; |
---|
6084 | if ( iRefIdx1 < 0 ) wp1 = NULL; |
---|
6085 | |
---|
6086 | m_cDistParam.wpCur = NULL; |
---|
6087 | |
---|
6088 | if ( eRefPicListCur == REF_PIC_LIST_0 ) |
---|
6089 | { |
---|
6090 | m_cDistParam.wpCur = wp0; |
---|
6091 | } |
---|
6092 | else |
---|
6093 | { |
---|
6094 | m_cDistParam.wpCur = wp1; |
---|
6095 | } |
---|
6096 | } |
---|
6097 | |
---|
6098 | #if REF_IDX_ME_ZEROMV |
---|
6099 | Void TEncSearch::xPatternSearchFracDIFMv0(TComDataCU* pcCU, |
---|
6100 | TComPattern* pcPatternKey, |
---|
6101 | Pel* piRefY, |
---|
6102 | Int iRefStride, |
---|
6103 | TComMv* pcMvInt, |
---|
6104 | TComMv& rcMvHalf, |
---|
6105 | TComMv& rcMvQter, |
---|
6106 | UInt& ruiCost, |
---|
6107 | Bool biPred |
---|
6108 | ) |
---|
6109 | { |
---|
6110 | assert(pcMvInt->getHor() == 0 && pcMvInt->getVer() == 0); |
---|
6111 | Int iOffset = pcMvInt->getHor() + pcMvInt->getVer() * iRefStride; |
---|
6112 | m_pcRdCost->setDistParam( pcPatternKey, piRefY + iOffset, iRefStride, 1, m_cDistParam, m_pcEncCfg->getUseHADME() ); |
---|
6113 | m_pcRdCost->setCostScale ( 2 ); |
---|
6114 | setDistParamComp(0); |
---|
6115 | ruiCost = m_cDistParam.DistFunc( &m_cDistParam ); //SATD |
---|
6116 | ruiCost += m_pcRdCost->getCost( pcMvInt->getHor(), pcMvInt->getVer() ); //SATD rdCost |
---|
6117 | rcMvHalf.setZero(); |
---|
6118 | rcMvQter.setZero(); |
---|
6119 | } |
---|
6120 | #endif |
---|
6121 | |
---|
6122 | #if ENCODER_FAST_MODE |
---|
6123 | Bool TEncSearch::predInterSearchILRUni( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv, UInt refLayerId ) |
---|
6124 | { |
---|
6125 | rpcPredYuv->clear(); |
---|
6126 | rpcRecoYuv->clear(); |
---|
6127 | |
---|
6128 | Int iNumPredDir = pcCU->getSlice()->isInterP() ? 1 : 2; |
---|
6129 | |
---|
6130 | TComMv cMv[2]; |
---|
6131 | TComMv cMvPred[2][33]; |
---|
6132 | TComMv cMvTemp[2][33]; |
---|
6133 | TComMv TempMv; |
---|
6134 | |
---|
6135 | Int iRefIdx[2]={0,0}; |
---|
6136 | |
---|
6137 | Int aaiMvpIdx[2][33]; |
---|
6138 | Int aaiMvpNum[2][33]; |
---|
6139 | |
---|
6140 | UInt uiMbBits[3] = {1, 1, 0}; |
---|
6141 | UInt uiLastMode = 0; |
---|
6142 | |
---|
6143 | UInt uiCost[2] = { MAX_UINT, MAX_UINT }; //uni, rdCost |
---|
6144 | UInt uiCostTemp; |
---|
6145 | UInt biPDistTemp = MAX_INT; |
---|
6146 | UInt uiBitsTemp; |
---|
6147 | |
---|
6148 | PartSize ePartSize = pcCU->getPartitionSize( 0 ); //2Nx2N |
---|
6149 | Int iPartIdx = 0; //one PU in CU |
---|
6150 | UInt uiPartAddr; |
---|
6151 | Int iRoiWidth, iRoiHeight; |
---|
6152 | Bool bILRSearched = false; |
---|
6153 | |
---|
6154 | xGetBlkBits( ePartSize, pcCU->getSlice()->isInterP(), iPartIdx, uiLastMode, uiMbBits); |
---|
6155 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iRoiWidth, iRoiHeight ); |
---|
6156 | |
---|
6157 | for( Int iRefList = 0; iRefList < iNumPredDir; iRefList++) //list |
---|
6158 | { |
---|
6159 | if(bILRSearched) |
---|
6160 | continue; |
---|
6161 | |
---|
6162 | RefPicList eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); |
---|
6163 | |
---|
6164 | Int iRefIdxTemp = -1; |
---|
6165 | Bool foundILR = false; |
---|
6166 | |
---|
6167 | for( Int refIdx = 0; refIdx < pcCU->getSlice()->getNumRefIdx(eRefPicList); refIdx++ ) |
---|
6168 | { |
---|
6169 | if( pcCU->getSlice()->getRefPic(eRefPicList, refIdx)->isILR(pcCU->getLayerId()) && pcCU->getSlice()->getRefPic(eRefPicList, refIdx)->getLayerId() == refLayerId ) |
---|
6170 | { |
---|
6171 | iRefIdxTemp = refIdx; |
---|
6172 | foundILR = true; |
---|
6173 | bILRSearched = true; |
---|
6174 | break; |
---|
6175 | } |
---|
6176 | } |
---|
6177 | |
---|
6178 | if(!foundILR) //no ILR in eRefPiclist |
---|
6179 | { |
---|
6180 | continue; |
---|
6181 | } |
---|
6182 | |
---|
6183 | uiBitsTemp = uiMbBits[iRefList]; |
---|
6184 | if ( pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1 ) |
---|
6185 | { |
---|
6186 | uiBitsTemp += iRefIdxTemp+1; |
---|
6187 | if ( iRefIdxTemp == pcCU->getSlice()->getNumRefIdx(eRefPicList)-1 ) uiBitsTemp--; |
---|
6188 | } |
---|
6189 | |
---|
6190 | xEstimateMvPredAMVP( pcCU, pcOrgYuv, iPartIdx, eRefPicList, iRefIdxTemp, cMvPred[iRefList][iRefIdxTemp], false, &biPDistTemp); |
---|
6191 | aaiMvpIdx[iRefList][iRefIdxTemp] = pcCU->getMVPIdx(eRefPicList, uiPartAddr); |
---|
6192 | aaiMvpNum[iRefList][iRefIdxTemp] = pcCU->getMVPNum(eRefPicList, uiPartAddr); |
---|
6193 | |
---|
6194 | uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdx[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS]; |
---|
6195 | |
---|
6196 | xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp ); |
---|
6197 | xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPred[iRefList][iRefIdxTemp], aaiMvpIdx[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp); |
---|
6198 | |
---|
6199 | if( uiCostTemp < uiCost[iRefList] ) |
---|
6200 | { |
---|
6201 | uiCost[iRefList] = uiCostTemp; |
---|
6202 | |
---|
6203 | cMv[iRefList] = cMvTemp[iRefList][iRefIdxTemp]; |
---|
6204 | iRefIdx[iRefList] = iRefIdxTemp; |
---|
6205 | |
---|
6206 | pcCU->getCUMvField(eRefPicList)->setAllMv( cMv[iRefList], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
6207 | pcCU->getCUMvField(eRefPicList)->setAllRefIdx( iRefIdx[iRefList], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
6208 | } |
---|
6209 | } |
---|
6210 | |
---|
6211 | if( uiCost[0] == MAX_UINT && uiCost[1] == MAX_UINT ) //no ILR in both list0 and list1 |
---|
6212 | { |
---|
6213 | return false; |
---|
6214 | } |
---|
6215 | |
---|
6216 | // Clear Motion Field |
---|
6217 | pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( TComMvField(), ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
6218 | pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( TComMvField(), ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
6219 | pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd ( TComMv(), ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
6220 | pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd ( TComMv(), ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
6221 | |
---|
6222 | pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
6223 | pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
6224 | pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
6225 | pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
6226 | |
---|
6227 | if( uiCost[0] <= uiCost[1] ) //list0 ILR |
---|
6228 | { |
---|
6229 | pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv ( cMv[0], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
6230 | pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdx[0], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
6231 | |
---|
6232 | TempMv = cMv[0] - cMvPred[0][iRefIdx[0]]; |
---|
6233 | pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
6234 | |
---|
6235 | pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); |
---|
6236 | |
---|
6237 | pcCU->setMVPIdxSubParts( aaiMvpIdx[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
6238 | pcCU->setMVPNumSubParts( aaiMvpNum[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
6239 | } |
---|
6240 | else if( uiCost[1] < uiCost[0] ) //list1 ILR |
---|
6241 | { |
---|
6242 | pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv ( cMv[1], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
6243 | pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdx[1], ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
6244 | |
---|
6245 | TempMv = cMv[1] - cMvPred[1][iRefIdx[1]]; |
---|
6246 | pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); |
---|
6247 | |
---|
6248 | pcCU->setInterDirSubParts( 2, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); |
---|
6249 | |
---|
6250 | pcCU->setMVPIdxSubParts( aaiMvpIdx[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
6251 | pcCU->setMVPNumSubParts( aaiMvpNum[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
6252 | } |
---|
6253 | else |
---|
6254 | { |
---|
6255 | assert(0); |
---|
6256 | } |
---|
6257 | |
---|
6258 | pcCU->setMergeFlagSubParts( false, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); |
---|
6259 | |
---|
6260 | motionCompensation ( pcCU, rpcPredYuv, REF_PIC_LIST_X, iPartIdx ); |
---|
6261 | setWpScalingDistParam( pcCU, -1, REF_PIC_LIST_X ); |
---|
6262 | |
---|
6263 | return true; |
---|
6264 | } |
---|
6265 | #endif |
---|
6266 | |
---|
6267 | //! \} |
---|