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 TComPrediction.cpp |
---|
35 | \brief prediction class |
---|
36 | */ |
---|
37 | |
---|
38 | #include <memory.h> |
---|
39 | #include "TComPrediction.h" |
---|
40 | |
---|
41 | //! \ingroup TLibCommon |
---|
42 | //! \{ |
---|
43 | |
---|
44 | // ==================================================================================================================== |
---|
45 | // Constructor / destructor / initialize |
---|
46 | // ==================================================================================================================== |
---|
47 | |
---|
48 | TComPrediction::TComPrediction() |
---|
49 | : m_pLumaRecBuffer(0) |
---|
50 | , m_iLumaRecStride(0) |
---|
51 | { |
---|
52 | m_piYuvExt = NULL; |
---|
53 | #if H_3D_VSP |
---|
54 | m_pDepthBlock = (Int*) malloc(MAX_NUM_SPU_W*MAX_NUM_SPU_W*sizeof(Int)); |
---|
55 | if (m_pDepthBlock == NULL) |
---|
56 | printf("ERROR: UKTGHU, No memory allocated.\n"); |
---|
57 | #endif |
---|
58 | } |
---|
59 | |
---|
60 | TComPrediction::~TComPrediction() |
---|
61 | { |
---|
62 | #if H_3D_VSP |
---|
63 | if (m_pDepthBlock != NULL) |
---|
64 | free(m_pDepthBlock); |
---|
65 | #endif |
---|
66 | |
---|
67 | delete[] m_piYuvExt; |
---|
68 | |
---|
69 | m_acYuvPred[0].destroy(); |
---|
70 | m_acYuvPred[1].destroy(); |
---|
71 | |
---|
72 | m_cYuvPredTemp.destroy(); |
---|
73 | |
---|
74 | #if H_3D_ARP |
---|
75 | m_acYuvPredBase[0].destroy(); |
---|
76 | m_acYuvPredBase[1].destroy(); |
---|
77 | #endif |
---|
78 | if( m_pLumaRecBuffer ) |
---|
79 | { |
---|
80 | delete [] m_pLumaRecBuffer; |
---|
81 | } |
---|
82 | |
---|
83 | Int i, j; |
---|
84 | for (i = 0; i < 4; i++) |
---|
85 | { |
---|
86 | for (j = 0; j < 4; j++) |
---|
87 | { |
---|
88 | m_filteredBlock[i][j].destroy(); |
---|
89 | } |
---|
90 | m_filteredBlockTmp[i].destroy(); |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | Void TComPrediction::initTempBuff() |
---|
95 | { |
---|
96 | if( m_piYuvExt == NULL ) |
---|
97 | { |
---|
98 | Int extWidth = MAX_CU_SIZE + 16; |
---|
99 | Int extHeight = MAX_CU_SIZE + 1; |
---|
100 | Int i, j; |
---|
101 | for (i = 0; i < 4; i++) |
---|
102 | { |
---|
103 | m_filteredBlockTmp[i].create(extWidth, extHeight + 7); |
---|
104 | for (j = 0; j < 4; j++) |
---|
105 | { |
---|
106 | m_filteredBlock[i][j].create(extWidth, extHeight); |
---|
107 | } |
---|
108 | } |
---|
109 | m_iYuvExtHeight = ((MAX_CU_SIZE + 2) << 4); |
---|
110 | m_iYuvExtStride = ((MAX_CU_SIZE + 8) << 4); |
---|
111 | m_piYuvExt = new Int[ m_iYuvExtStride * m_iYuvExtHeight ]; |
---|
112 | |
---|
113 | // new structure |
---|
114 | m_acYuvPred[0] .create( MAX_CU_SIZE, MAX_CU_SIZE ); |
---|
115 | m_acYuvPred[1] .create( MAX_CU_SIZE, MAX_CU_SIZE ); |
---|
116 | |
---|
117 | m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE ); |
---|
118 | #if H_3D_ARP |
---|
119 | m_acYuvPredBase[0] .create( g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
120 | m_acYuvPredBase[1] .create( g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
121 | #endif |
---|
122 | } |
---|
123 | |
---|
124 | if (m_iLumaRecStride != (MAX_CU_SIZE>>1) + 1) |
---|
125 | { |
---|
126 | m_iLumaRecStride = (MAX_CU_SIZE>>1) + 1; |
---|
127 | if (!m_pLumaRecBuffer) |
---|
128 | { |
---|
129 | m_pLumaRecBuffer = new Pel[ m_iLumaRecStride * m_iLumaRecStride ]; |
---|
130 | } |
---|
131 | } |
---|
132 | #if H_3D_IC |
---|
133 | for( Int i = 1; i < 64; i++ ) |
---|
134 | { |
---|
135 | m_uiaShift[i-1] = ( (1 << 15) + i/2 ) / i; |
---|
136 | } |
---|
137 | #endif |
---|
138 | } |
---|
139 | |
---|
140 | // ==================================================================================================================== |
---|
141 | // Public member functions |
---|
142 | // ==================================================================================================================== |
---|
143 | |
---|
144 | // Function for calculating DC value of the reference samples used in Intra prediction |
---|
145 | Pel TComPrediction::predIntraGetPredValDC( Int* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft ) |
---|
146 | { |
---|
147 | assert(iWidth > 0 && iHeight > 0); |
---|
148 | Int iInd, iSum = 0; |
---|
149 | Pel pDcVal; |
---|
150 | |
---|
151 | if (bAbove) |
---|
152 | { |
---|
153 | for (iInd = 0;iInd < iWidth;iInd++) |
---|
154 | { |
---|
155 | iSum += pSrc[iInd-iSrcStride]; |
---|
156 | } |
---|
157 | } |
---|
158 | if (bLeft) |
---|
159 | { |
---|
160 | for (iInd = 0;iInd < iHeight;iInd++) |
---|
161 | { |
---|
162 | iSum += pSrc[iInd*iSrcStride-1]; |
---|
163 | } |
---|
164 | } |
---|
165 | |
---|
166 | if (bAbove && bLeft) |
---|
167 | { |
---|
168 | pDcVal = (iSum + iWidth) / (iWidth + iHeight); |
---|
169 | } |
---|
170 | else if (bAbove) |
---|
171 | { |
---|
172 | pDcVal = (iSum + iWidth/2) / iWidth; |
---|
173 | } |
---|
174 | else if (bLeft) |
---|
175 | { |
---|
176 | pDcVal = (iSum + iHeight/2) / iHeight; |
---|
177 | } |
---|
178 | else |
---|
179 | { |
---|
180 | pDcVal = pSrc[-1]; // Default DC value already calculated and placed in the prediction array if no neighbors are available |
---|
181 | } |
---|
182 | |
---|
183 | return pDcVal; |
---|
184 | } |
---|
185 | |
---|
186 | // Function for deriving the angular Intra predictions |
---|
187 | |
---|
188 | /** Function for deriving the simplified angular intra predictions. |
---|
189 | * \param pSrc pointer to reconstructed sample array |
---|
190 | * \param srcStride the stride of the reconstructed sample array |
---|
191 | * \param rpDst reference to pointer for the prediction sample array |
---|
192 | * \param dstStride the stride of the prediction sample array |
---|
193 | * \param width the width of the block |
---|
194 | * \param height the height of the block |
---|
195 | * \param dirMode the intra prediction mode index |
---|
196 | * \param blkAboveAvailable boolean indication if the block above is available |
---|
197 | * \param blkLeftAvailable boolean indication if the block to the left is available |
---|
198 | * |
---|
199 | * This function derives the prediction samples for the angular mode based on the prediction direction indicated by |
---|
200 | * the prediction mode index. The prediction direction is given by the displacement of the bottom row of the block and |
---|
201 | * the reference row above the block in the case of vertical prediction or displacement of the rightmost column |
---|
202 | * of the block and reference column left from the block in the case of the horizontal prediction. The displacement |
---|
203 | * is signalled at 1/32 pixel accuracy. When projection of the predicted pixel falls inbetween reference samples, |
---|
204 | * the predicted value for the pixel is linearly interpolated from the reference samples. All reference samples are taken |
---|
205 | * from the extended main reference. |
---|
206 | */ |
---|
207 | Void TComPrediction::xPredIntraAng(Int bitDepth, Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, UInt width, UInt height, UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable, Bool bFilter ) |
---|
208 | { |
---|
209 | Int k,l; |
---|
210 | Int blkSize = width; |
---|
211 | Pel* pDst = rpDst; |
---|
212 | |
---|
213 | // Map the mode index to main prediction direction and angle |
---|
214 | assert( dirMode > 0 ); //no planar |
---|
215 | Bool modeDC = dirMode < 2; |
---|
216 | Bool modeHor = !modeDC && (dirMode < 18); |
---|
217 | Bool modeVer = !modeDC && !modeHor; |
---|
218 | Int intraPredAngle = modeVer ? (Int)dirMode - VER_IDX : modeHor ? -((Int)dirMode - HOR_IDX) : 0; |
---|
219 | Int absAng = abs(intraPredAngle); |
---|
220 | Int signAng = intraPredAngle < 0 ? -1 : 1; |
---|
221 | |
---|
222 | // Set bitshifts and scale the angle parameter to block size |
---|
223 | Int angTable[9] = {0, 2, 5, 9, 13, 17, 21, 26, 32}; |
---|
224 | Int invAngTable[9] = {0, 4096, 1638, 910, 630, 482, 390, 315, 256}; // (256 * 32) / Angle |
---|
225 | Int invAngle = invAngTable[absAng]; |
---|
226 | absAng = angTable[absAng]; |
---|
227 | intraPredAngle = signAng * absAng; |
---|
228 | |
---|
229 | // Do the DC prediction |
---|
230 | if (modeDC) |
---|
231 | { |
---|
232 | Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height, blkAboveAvailable, blkLeftAvailable); |
---|
233 | |
---|
234 | for (k=0;k<blkSize;k++) |
---|
235 | { |
---|
236 | for (l=0;l<blkSize;l++) |
---|
237 | { |
---|
238 | pDst[k*dstStride+l] = dcval; |
---|
239 | } |
---|
240 | } |
---|
241 | } |
---|
242 | |
---|
243 | // Do angular predictions |
---|
244 | else |
---|
245 | { |
---|
246 | Pel* refMain; |
---|
247 | Pel* refSide; |
---|
248 | Pel refAbove[2*MAX_CU_SIZE+1]; |
---|
249 | Pel refLeft[2*MAX_CU_SIZE+1]; |
---|
250 | |
---|
251 | // Initialise the Main and Left reference array. |
---|
252 | if (intraPredAngle < 0) |
---|
253 | { |
---|
254 | for (k=0;k<blkSize+1;k++) |
---|
255 | { |
---|
256 | refAbove[k+blkSize-1] = pSrc[k-srcStride-1]; |
---|
257 | } |
---|
258 | for (k=0;k<blkSize+1;k++) |
---|
259 | { |
---|
260 | refLeft[k+blkSize-1] = pSrc[(k-1)*srcStride-1]; |
---|
261 | } |
---|
262 | refMain = (modeVer ? refAbove : refLeft) + (blkSize-1); |
---|
263 | refSide = (modeVer ? refLeft : refAbove) + (blkSize-1); |
---|
264 | |
---|
265 | // Extend the Main reference to the left. |
---|
266 | Int invAngleSum = 128; // rounding for (shift by 8) |
---|
267 | for (k=-1; k>blkSize*intraPredAngle>>5; k--) |
---|
268 | { |
---|
269 | invAngleSum += invAngle; |
---|
270 | refMain[k] = refSide[invAngleSum>>8]; |
---|
271 | } |
---|
272 | } |
---|
273 | else |
---|
274 | { |
---|
275 | for (k=0;k<2*blkSize+1;k++) |
---|
276 | { |
---|
277 | refAbove[k] = pSrc[k-srcStride-1]; |
---|
278 | } |
---|
279 | for (k=0;k<2*blkSize+1;k++) |
---|
280 | { |
---|
281 | refLeft[k] = pSrc[(k-1)*srcStride-1]; |
---|
282 | } |
---|
283 | refMain = modeVer ? refAbove : refLeft; |
---|
284 | refSide = modeVer ? refLeft : refAbove; |
---|
285 | } |
---|
286 | |
---|
287 | if (intraPredAngle == 0) |
---|
288 | { |
---|
289 | for (k=0;k<blkSize;k++) |
---|
290 | { |
---|
291 | for (l=0;l<blkSize;l++) |
---|
292 | { |
---|
293 | pDst[k*dstStride+l] = refMain[l+1]; |
---|
294 | } |
---|
295 | } |
---|
296 | |
---|
297 | if ( bFilter ) |
---|
298 | { |
---|
299 | for (k=0;k<blkSize;k++) |
---|
300 | { |
---|
301 | pDst[k*dstStride] = Clip3(0, (1<<bitDepth)-1, pDst[k*dstStride] + (( refSide[k+1] - refSide[0] ) >> 1) ); |
---|
302 | } |
---|
303 | } |
---|
304 | } |
---|
305 | else |
---|
306 | { |
---|
307 | Int deltaPos=0; |
---|
308 | Int deltaInt; |
---|
309 | Int deltaFract; |
---|
310 | Int refMainIndex; |
---|
311 | |
---|
312 | for (k=0;k<blkSize;k++) |
---|
313 | { |
---|
314 | deltaPos += intraPredAngle; |
---|
315 | deltaInt = deltaPos >> 5; |
---|
316 | deltaFract = deltaPos & (32 - 1); |
---|
317 | |
---|
318 | if (deltaFract) |
---|
319 | { |
---|
320 | // Do linear filtering |
---|
321 | for (l=0;l<blkSize;l++) |
---|
322 | { |
---|
323 | refMainIndex = l+deltaInt+1; |
---|
324 | pDst[k*dstStride+l] = (Pel) ( ((32-deltaFract)*refMain[refMainIndex]+deltaFract*refMain[refMainIndex+1]+16) >> 5 ); |
---|
325 | } |
---|
326 | } |
---|
327 | else |
---|
328 | { |
---|
329 | // Just copy the integer samples |
---|
330 | for (l=0;l<blkSize;l++) |
---|
331 | { |
---|
332 | pDst[k*dstStride+l] = refMain[l+deltaInt+1]; |
---|
333 | } |
---|
334 | } |
---|
335 | } |
---|
336 | } |
---|
337 | |
---|
338 | // Flip the block if this is the horizontal mode |
---|
339 | if (modeHor) |
---|
340 | { |
---|
341 | Pel tmp; |
---|
342 | for (k=0;k<blkSize-1;k++) |
---|
343 | { |
---|
344 | for (l=k+1;l<blkSize;l++) |
---|
345 | { |
---|
346 | tmp = pDst[k*dstStride+l]; |
---|
347 | pDst[k*dstStride+l] = pDst[l*dstStride+k]; |
---|
348 | pDst[l*dstStride+k] = tmp; |
---|
349 | } |
---|
350 | } |
---|
351 | } |
---|
352 | } |
---|
353 | } |
---|
354 | |
---|
355 | Void TComPrediction::predIntraLumaAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft ) |
---|
356 | { |
---|
357 | Pel *pDst = piPred; |
---|
358 | Int *ptrSrc; |
---|
359 | |
---|
360 | assert( g_aucConvertToBit[ iWidth ] >= 0 ); // 4x 4 |
---|
361 | assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128 |
---|
362 | assert( iWidth == iHeight ); |
---|
363 | |
---|
364 | ptrSrc = pcTComPattern->getPredictorPtr( uiDirMode, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt ); |
---|
365 | |
---|
366 | // get starting pixel in block |
---|
367 | Int sw = 2 * iWidth + 1; |
---|
368 | |
---|
369 | // Create the prediction |
---|
370 | if ( uiDirMode == PLANAR_IDX ) |
---|
371 | { |
---|
372 | xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight ); |
---|
373 | } |
---|
374 | else |
---|
375 | { |
---|
376 | if ( (iWidth > 16) || (iHeight > 16) ) |
---|
377 | { |
---|
378 | xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false ); |
---|
379 | } |
---|
380 | else |
---|
381 | { |
---|
382 | xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, true ); |
---|
383 | |
---|
384 | if( (uiDirMode == DC_IDX ) && bAbove && bLeft ) |
---|
385 | { |
---|
386 | xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight); |
---|
387 | } |
---|
388 | } |
---|
389 | } |
---|
390 | } |
---|
391 | |
---|
392 | // Angular chroma |
---|
393 | Void TComPrediction::predIntraChromaAng( Int* piSrc, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft ) |
---|
394 | { |
---|
395 | Pel *pDst = piPred; |
---|
396 | Int *ptrSrc = piSrc; |
---|
397 | |
---|
398 | // get starting pixel in block |
---|
399 | Int sw = 2 * iWidth + 1; |
---|
400 | |
---|
401 | if ( uiDirMode == PLANAR_IDX ) |
---|
402 | { |
---|
403 | xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight ); |
---|
404 | } |
---|
405 | else |
---|
406 | { |
---|
407 | // Create the prediction |
---|
408 | xPredIntraAng(g_bitDepthC, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false ); |
---|
409 | } |
---|
410 | } |
---|
411 | |
---|
412 | #if H_3D_DIM |
---|
413 | Void TComPrediction::predIntraLumaDepth( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiIntraMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bFastEnc ) |
---|
414 | { |
---|
415 | assert( iWidth == iHeight ); |
---|
416 | assert( iWidth >= DIM_MIN_SIZE && iWidth <= DIM_MAX_SIZE ); |
---|
417 | assert( isDimMode( uiIntraMode ) ); |
---|
418 | |
---|
419 | UInt dimType = getDimType ( uiIntraMode ); |
---|
420 | Bool dimDeltaDC = isDimDeltaDC( uiIntraMode ); |
---|
421 | Bool isDmmMode = (dimType < DMM_NUM_TYPE); |
---|
422 | Bool isRbcMode = (dimType == RBC_IDX); |
---|
423 | |
---|
424 | Bool* biSegPattern = NULL; |
---|
425 | UInt patternStride = 0; |
---|
426 | |
---|
427 | // get partiton |
---|
428 | #if H_3D_DIM_DMM |
---|
429 | TComWedgelet* dmmSegmentation = NULL; |
---|
430 | if( isDmmMode ) |
---|
431 | { |
---|
432 | switch( dimType ) |
---|
433 | { |
---|
434 | case( DMM1_IDX ): |
---|
435 | { |
---|
436 | dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ) ]); |
---|
437 | } break; |
---|
438 | #if !SEC_DMM2_E0146 |
---|
439 | case( DMM2_IDX ): |
---|
440 | { |
---|
441 | UInt uiTabIdx = 0; |
---|
442 | if( bFastEnc ) { uiTabIdx = pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ); } |
---|
443 | else |
---|
444 | { |
---|
445 | uiTabIdx = xPredWedgeFromIntra( pcCU, uiAbsPartIdx, iWidth, iHeight, pcCU->getDmm2DeltaEnd( uiAbsPartIdx ) ); |
---|
446 | pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, uiAbsPartIdx, (pcCU->getDepth(0) + (pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1)) ); |
---|
447 | } |
---|
448 | dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ uiTabIdx ]); |
---|
449 | } break; |
---|
450 | #endif |
---|
451 | case( DMM3_IDX ): |
---|
452 | { |
---|
453 | UInt uiTabIdx = 0; |
---|
454 | if( bFastEnc ) { uiTabIdx = pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ); } |
---|
455 | else |
---|
456 | { |
---|
457 | uiTabIdx = xPredWedgeFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, pcCU->getDmm3IntraTabIdx( uiAbsPartIdx ) ); |
---|
458 | pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, uiAbsPartIdx, (pcCU->getDepth(0) + (pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1)) ); |
---|
459 | } |
---|
460 | dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ uiTabIdx ]); |
---|
461 | } break; |
---|
462 | case( DMM4_IDX ): |
---|
463 | { |
---|
464 | dmmSegmentation = new TComWedgelet( iWidth, iHeight ); |
---|
465 | xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmmSegmentation ); |
---|
466 | } break; |
---|
467 | default: assert(0); |
---|
468 | } |
---|
469 | assert( dmmSegmentation ); |
---|
470 | biSegPattern = dmmSegmentation->getPattern(); |
---|
471 | patternStride = dmmSegmentation->getStride (); |
---|
472 | } |
---|
473 | #endif |
---|
474 | #if H_3D_DIM_RBC |
---|
475 | if( isRbcMode ) |
---|
476 | { |
---|
477 | biSegPattern = pcCU->getEdgePartition( uiAbsPartIdx ); |
---|
478 | patternStride = iWidth; |
---|
479 | } |
---|
480 | #endif |
---|
481 | |
---|
482 | // get predicted partition values |
---|
483 | assert( biSegPattern ); |
---|
484 | Int* piMask = NULL; |
---|
485 | if( isDmmMode ) piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt ); // no filtering for DMM |
---|
486 | else piMask = pcCU->getPattern()->getPredictorPtr( 0, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt ); |
---|
487 | assert( piMask ); |
---|
488 | Int maskStride = 2*iWidth + 1; |
---|
489 | Int* ptrSrc = piMask+maskStride+1; |
---|
490 | Pel predDC1 = 0; Pel predDC2 = 0; |
---|
491 | xPredBiSegDCs( ptrSrc, maskStride, biSegPattern, patternStride, predDC1, predDC2 ); |
---|
492 | |
---|
493 | // set segment values with deltaDC offsets |
---|
494 | Pel segDC1 = 0; |
---|
495 | Pel segDC2 = 0; |
---|
496 | if( dimDeltaDC ) |
---|
497 | { |
---|
498 | Pel deltaDC1 = pcCU->getDimDeltaDC( dimType, 0, uiAbsPartIdx ); |
---|
499 | Pel deltaDC2 = pcCU->getDimDeltaDC( dimType, 1, uiAbsPartIdx ); |
---|
500 | #if H_3D_DIM_DMM |
---|
501 | if( isDmmMode ) |
---|
502 | { |
---|
503 | #if H_3D_DIM_DLT |
---|
504 | segDC1 = pcCU->getSlice()->getVPS()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 ) + deltaDC1 ); |
---|
505 | segDC2 = pcCU->getSlice()->getVPS()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 ) + deltaDC2 ); |
---|
506 | #else |
---|
507 | segDC1 = ClipY( predDC1 + deltaDC1 ); |
---|
508 | segDC2 = ClipY( predDC2 + deltaDC2 ); |
---|
509 | #endif |
---|
510 | } |
---|
511 | #endif |
---|
512 | #if H_3D_DIM_RBC |
---|
513 | if( isRbcMode ) |
---|
514 | { |
---|
515 | xDeltaDCQuantScaleUp( pcCU, deltaDC1 ); |
---|
516 | xDeltaDCQuantScaleUp( pcCU, deltaDC2 ); |
---|
517 | segDC1 = ClipY( predDC1 + deltaDC1 ); |
---|
518 | segDC2 = ClipY( predDC2 + deltaDC2 ); |
---|
519 | } |
---|
520 | #endif |
---|
521 | } |
---|
522 | else |
---|
523 | { |
---|
524 | segDC1 = predDC1; |
---|
525 | segDC2 = predDC2; |
---|
526 | } |
---|
527 | |
---|
528 | // set prediction signal |
---|
529 | Pel* pDst = piPred; |
---|
530 | xAssignBiSegDCs( pDst, uiStride, biSegPattern, patternStride, segDC1, segDC2 ); |
---|
531 | |
---|
532 | #if H_3D_DIM_DMM |
---|
533 | if( dimType == DMM4_IDX ) { dmmSegmentation->destroy(); delete dmmSegmentation; } |
---|
534 | #endif |
---|
535 | } |
---|
536 | #endif |
---|
537 | |
---|
538 | /** Function for checking identical motion. |
---|
539 | * \param TComDataCU* pcCU |
---|
540 | * \param UInt PartAddr |
---|
541 | */ |
---|
542 | Bool TComPrediction::xCheckIdenticalMotion ( TComDataCU* pcCU, UInt PartAddr ) |
---|
543 | { |
---|
544 | if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getPPS()->getWPBiPred() ) |
---|
545 | { |
---|
546 | if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr) >= 0 && pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr) >= 0) |
---|
547 | { |
---|
548 | Int RefPOCL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC(); |
---|
549 | Int RefPOCL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC(); |
---|
550 | if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr)) |
---|
551 | { |
---|
552 | return true; |
---|
553 | } |
---|
554 | } |
---|
555 | } |
---|
556 | return false; |
---|
557 | } |
---|
558 | |
---|
559 | |
---|
560 | Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx ) |
---|
561 | { |
---|
562 | Int iWidth; |
---|
563 | Int iHeight; |
---|
564 | UInt uiPartAddr; |
---|
565 | |
---|
566 | if ( iPartIdx >= 0 ) |
---|
567 | { |
---|
568 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
569 | #if H_3D_VSP |
---|
570 | if ( 0 == pcCU->getVSPFlag(uiPartAddr) ) |
---|
571 | { |
---|
572 | #endif |
---|
573 | if ( eRefPicList != REF_PIC_LIST_X ) |
---|
574 | { |
---|
575 | if( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
576 | { |
---|
577 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true ); |
---|
578 | } |
---|
579 | else |
---|
580 | { |
---|
581 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
582 | } |
---|
583 | if ( pcCU->getSlice()->getPPS()->getUseWP() ) |
---|
584 | { |
---|
585 | xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
586 | } |
---|
587 | } |
---|
588 | else |
---|
589 | { |
---|
590 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
591 | { |
---|
592 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
593 | } |
---|
594 | else |
---|
595 | { |
---|
596 | xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
597 | } |
---|
598 | } |
---|
599 | #if H_3D_VSP |
---|
600 | } |
---|
601 | else |
---|
602 | { |
---|
603 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
604 | xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
605 | else |
---|
606 | xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
607 | } |
---|
608 | #endif |
---|
609 | return; |
---|
610 | } |
---|
611 | |
---|
612 | for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ ) |
---|
613 | { |
---|
614 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
615 | |
---|
616 | #if H_3D_VSP |
---|
617 | if ( 0 == pcCU->getVSPFlag(uiPartAddr) ) |
---|
618 | { |
---|
619 | #endif |
---|
620 | if ( eRefPicList != REF_PIC_LIST_X ) |
---|
621 | { |
---|
622 | if( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
623 | { |
---|
624 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true ); |
---|
625 | } |
---|
626 | else |
---|
627 | { |
---|
628 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
629 | } |
---|
630 | if ( pcCU->getSlice()->getPPS()->getUseWP() ) |
---|
631 | { |
---|
632 | xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
633 | } |
---|
634 | } |
---|
635 | else |
---|
636 | { |
---|
637 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
638 | { |
---|
639 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
640 | } |
---|
641 | else |
---|
642 | { |
---|
643 | xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
644 | } |
---|
645 | } |
---|
646 | #if H_3D_VSP |
---|
647 | } |
---|
648 | else |
---|
649 | { |
---|
650 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
651 | xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
652 | else |
---|
653 | xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
654 | } |
---|
655 | #endif |
---|
656 | } |
---|
657 | return; |
---|
658 | } |
---|
659 | |
---|
660 | Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi ) |
---|
661 | { |
---|
662 | Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); assert (iRefIdx >= 0); |
---|
663 | TComMv cMv = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); |
---|
664 | pcCU->clipMv(cMv); |
---|
665 | #if H_3D_ARP |
---|
666 | if( pcCU->getARPW( uiPartAddr ) > 0 |
---|
667 | && pcCU->getPartitionSize(uiPartAddr)==SIZE_2Nx2N |
---|
668 | && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()!= pcCU->getSlice()->getPOC() |
---|
669 | ) |
---|
670 | { |
---|
671 | xPredInterUniARP( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, rpcYuvPred, bi ); |
---|
672 | } |
---|
673 | else |
---|
674 | { |
---|
675 | #endif |
---|
676 | #if H_3D_IC |
---|
677 | Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() ); |
---|
678 | xPredInterLumaBlk ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi |
---|
679 | #if H_3D_ARP |
---|
680 | , false |
---|
681 | #endif |
---|
682 | , bICFlag ); |
---|
683 | xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi |
---|
684 | #if H_3D_ARP |
---|
685 | , false |
---|
686 | #endif |
---|
687 | , bICFlag ); |
---|
688 | #else |
---|
689 | xPredInterLumaBlk ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi ); |
---|
690 | xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi ); |
---|
691 | #endif |
---|
692 | #if H_3D_ARP |
---|
693 | } |
---|
694 | #endif |
---|
695 | } |
---|
696 | |
---|
697 | #if H_3D_VSP |
---|
698 | Void TComPrediction::xPredInterUniVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi ) |
---|
699 | { |
---|
700 | // Get depth reference |
---|
701 | Int depthRefViewIdx = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan; |
---|
702 | TComPic* pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx ); |
---|
703 | assert(pRefPicBaseDepth != NULL); |
---|
704 | TComPicYuv* pcBaseViewDepthPicYuv = pRefPicBaseDepth->getPicYuvRec(); |
---|
705 | assert(pcBaseViewDepthPicYuv != NULL); |
---|
706 | |
---|
707 | // Get texture reference |
---|
708 | Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
709 | assert(iRefIdx >= 0); |
---|
710 | TComPic* pRefPicBaseTxt = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx ); |
---|
711 | TComPicYuv* pcBaseViewTxtPicYuv = pRefPicBaseTxt->getPicYuvRec(); |
---|
712 | assert(pcBaseViewTxtPicYuv != NULL); |
---|
713 | |
---|
714 | // Initialize LUT according to the reference viewIdx |
---|
715 | Int txtRefViewIdx = pRefPicBaseTxt->getViewIndex(); |
---|
716 | Int* pShiftLUT = pcCU->getSlice()->getDepthToDisparityB( txtRefViewIdx ); |
---|
717 | assert( txtRefViewIdx < pcCU->getSlice()->getViewIndex() ); |
---|
718 | |
---|
719 | // Do compensation |
---|
720 | TComMv cDv = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); // cDv is the disparity vector derived from the neighbors |
---|
721 | pcCU->clipMv(cDv); |
---|
722 | UInt uiAbsPartIdx = pcCU->getZorderIdxInCU(); |
---|
723 | Int iBlkX = ( pcCU->getAddr() % pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ]; |
---|
724 | Int iBlkY = ( pcCU->getAddr() / pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ]; |
---|
725 | xPredInterLumaBlkFromDM ( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, &cDv, uiPartAddr, iBlkX, iBlkY, iWidth, iHeight, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi ); |
---|
726 | xPredInterChromaBlkFromDM( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, &cDv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi ); |
---|
727 | } |
---|
728 | #endif |
---|
729 | |
---|
730 | #if H_3D_ARP |
---|
731 | Void TComPrediction::xPredInterUniARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled ) |
---|
732 | { |
---|
733 | Int iRefIdx = pNewMvFiled ? pNewMvFiled->getRefIdx() : pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
734 | TComMv cMv = pNewMvFiled ? pNewMvFiled->getMv() : pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); |
---|
735 | Bool bTobeScaled = false; |
---|
736 | TComPic* pcPicYuvBaseCol = NULL; |
---|
737 | TComPic* pcPicYuvBaseRef = NULL; |
---|
738 | |
---|
739 | #if H_3D_NBDV |
---|
740 | DisInfo cDistparity; |
---|
741 | cDistparity.bDV = pcCU->getDvInfo(uiPartAddr).bDV; |
---|
742 | if( cDistparity.bDV ) |
---|
743 | { |
---|
744 | cDistparity.m_acNBDV = pcCU->getDvInfo(0).m_acNBDV; |
---|
745 | assert(pcCU->getDvInfo(uiPartAddr).bDV == pcCU->getDvInfo(0).bDV); |
---|
746 | cDistparity.m_aVIdxCan = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan; |
---|
747 | } |
---|
748 | #else |
---|
749 | assert(0); // ARP can be applied only when a DV is available |
---|
750 | #endif |
---|
751 | |
---|
752 | UChar dW = cDistparity.bDV ? pcCU->getARPW ( uiPartAddr ) : 0; |
---|
753 | |
---|
754 | if( cDistparity.bDV ) |
---|
755 | { |
---|
756 | if( dW > 0 && pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC()!= pcCU->getSlice()->getPOC() ) |
---|
757 | { |
---|
758 | bTobeScaled = true; |
---|
759 | } |
---|
760 | |
---|
761 | pcPicYuvBaseCol = pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getPOC(), cDistparity.m_aVIdxCan ); |
---|
762 | pcPicYuvBaseRef = pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC(), cDistparity.m_aVIdxCan ); |
---|
763 | |
---|
764 | if( ( !pcPicYuvBaseCol || pcPicYuvBaseCol->getPOC() != pcCU->getSlice()->getPOC() ) || ( !pcPicYuvBaseRef || pcPicYuvBaseRef->getPOC() != pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC() ) ) |
---|
765 | { |
---|
766 | dW = 0; |
---|
767 | bTobeScaled = false; |
---|
768 | } |
---|
769 | else |
---|
770 | { |
---|
771 | assert( pcPicYuvBaseCol->getPOC() == pcCU->getSlice()->getPOC() && pcPicYuvBaseRef->getPOC() == pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC() ); |
---|
772 | } |
---|
773 | |
---|
774 | if(bTobeScaled) |
---|
775 | { |
---|
776 | Int iCurrPOC = pcCU->getSlice()->getPOC(); |
---|
777 | Int iColRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList, iRefIdx ); |
---|
778 | Int iCurrRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList, 0); |
---|
779 | Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iCurrPOC, iColRefPOC); |
---|
780 | if ( iScale != 4096 ) |
---|
781 | { |
---|
782 | cMv = cMv.scaleMv( iScale ); |
---|
783 | } |
---|
784 | iRefIdx = 0; |
---|
785 | } |
---|
786 | } |
---|
787 | |
---|
788 | pcCU->clipMv(cMv); |
---|
789 | TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(); |
---|
790 | xPredInterLumaBlk ( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, true ); |
---|
791 | xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, true ); |
---|
792 | |
---|
793 | if( dW > 0 ) |
---|
794 | { |
---|
795 | TComYuv * pYuvB0 = &m_acYuvPredBase[0]; |
---|
796 | TComYuv * pYuvB1 = &m_acYuvPredBase[1]; |
---|
797 | |
---|
798 | TComMv cMVwithDisparity = cMv + cDistparity.m_acNBDV; |
---|
799 | pcCU->clipMv(cMVwithDisparity); |
---|
800 | |
---|
801 | assert ( cDistparity.bDV ); |
---|
802 | |
---|
803 | pcPicYuvRef = pcPicYuvBaseCol->getPicYuvRec(); |
---|
804 | xPredInterLumaBlk ( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acNBDV, iWidth, iHeight, pYuvB0, bi, true ); |
---|
805 | xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acNBDV, iWidth, iHeight, pYuvB0, bi, true ); |
---|
806 | |
---|
807 | pcPicYuvRef = pcPicYuvBaseRef->getPicYuvRec(); |
---|
808 | xPredInterLumaBlk ( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, bi, true ); |
---|
809 | xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, bi, true ); |
---|
810 | |
---|
811 | pYuvB0->subtractARP( pYuvB0 , pYuvB1 , uiPartAddr , iWidth , iHeight ); |
---|
812 | |
---|
813 | if( 2 == dW ) |
---|
814 | { |
---|
815 | pYuvB0->multiplyARP( uiPartAddr , iWidth , iHeight , dW ); |
---|
816 | } |
---|
817 | rpcYuvPred->addARP( rpcYuvPred , pYuvB0 , uiPartAddr , iWidth , iHeight , !bi ); |
---|
818 | } |
---|
819 | } |
---|
820 | #endif |
---|
821 | |
---|
822 | Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred ) |
---|
823 | { |
---|
824 | TComYuv* pcMbYuv; |
---|
825 | Int iRefIdx[2] = {-1, -1}; |
---|
826 | |
---|
827 | for ( Int iRefList = 0; iRefList < 2; iRefList++ ) |
---|
828 | { |
---|
829 | RefPicList eRefPicList = (iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0); |
---|
830 | iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
831 | |
---|
832 | if ( iRefIdx[iRefList] < 0 ) |
---|
833 | { |
---|
834 | continue; |
---|
835 | } |
---|
836 | |
---|
837 | assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) ); |
---|
838 | |
---|
839 | pcMbYuv = &m_acYuvPred[iRefList]; |
---|
840 | if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 ) |
---|
841 | { |
---|
842 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true ); |
---|
843 | } |
---|
844 | else |
---|
845 | { |
---|
846 | if ( ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE ) || |
---|
847 | ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) ) |
---|
848 | { |
---|
849 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true ); |
---|
850 | } |
---|
851 | else |
---|
852 | { |
---|
853 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv ); |
---|
854 | } |
---|
855 | } |
---|
856 | } |
---|
857 | |
---|
858 | if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) |
---|
859 | { |
---|
860 | xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred ); |
---|
861 | } |
---|
862 | else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE ) |
---|
863 | { |
---|
864 | xWeightedPredictionUni( pcCU, &m_acYuvPred[0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, rpcYuvPred ); |
---|
865 | } |
---|
866 | else |
---|
867 | { |
---|
868 | xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred ); |
---|
869 | } |
---|
870 | } |
---|
871 | |
---|
872 | #if H_3D_VSP |
---|
873 | |
---|
874 | Void TComPrediction::xPredInterBiVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred ) |
---|
875 | { |
---|
876 | TComYuv* pcMbYuv; |
---|
877 | Int iRefIdx[2] = {-1, -1}; |
---|
878 | Bool bi = (pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0); |
---|
879 | |
---|
880 | for ( Int iRefList = 0; iRefList < 2; iRefList++ ) |
---|
881 | { |
---|
882 | RefPicList eRefPicList = RefPicList(iRefList); |
---|
883 | iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
884 | |
---|
885 | if ( iRefIdx[iRefList] < 0 ) |
---|
886 | continue; |
---|
887 | assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) ); |
---|
888 | |
---|
889 | pcMbYuv = &m_acYuvPred[iRefList]; |
---|
890 | xPredInterUniVSP ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, bi ); |
---|
891 | } |
---|
892 | |
---|
893 | xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred ); |
---|
894 | } |
---|
895 | |
---|
896 | #endif |
---|
897 | |
---|
898 | /** |
---|
899 | * \brief Generate motion-compensated luma block |
---|
900 | * |
---|
901 | * \param cu Pointer to current CU |
---|
902 | * \param refPic Pointer to reference picture |
---|
903 | * \param partAddr Address of block within CU |
---|
904 | * \param mv Motion vector |
---|
905 | * \param width Width of block |
---|
906 | * \param height Height of block |
---|
907 | * \param dstPic Pointer to destination picture |
---|
908 | * \param bi Flag indicating whether bipred is used |
---|
909 | */ |
---|
910 | Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi |
---|
911 | #if H_3D_ARP |
---|
912 | , Bool filterType |
---|
913 | #endif |
---|
914 | #if H_3D_IC |
---|
915 | , Bool bICFlag |
---|
916 | #endif |
---|
917 | ) |
---|
918 | { |
---|
919 | Int refStride = refPic->getStride(); |
---|
920 | Int refOffset = ( mv->getHor() >> 2 ) + ( mv->getVer() >> 2 ) * refStride; |
---|
921 | Pel *ref = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
922 | |
---|
923 | Int dstStride = dstPic->getStride(); |
---|
924 | Pel *dst = dstPic->getLumaAddr( partAddr ); |
---|
925 | |
---|
926 | Int xFrac = mv->getHor() & 0x3; |
---|
927 | Int yFrac = mv->getVer() & 0x3; |
---|
928 | |
---|
929 | #if H_3D_IC |
---|
930 | if( cu->getSlice()->getIsDepth() ) |
---|
931 | { |
---|
932 | refOffset = mv->getHor() + mv->getVer() * refStride; |
---|
933 | ref = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
934 | xFrac = 0; |
---|
935 | yFrac = 0; |
---|
936 | } |
---|
937 | #endif |
---|
938 | if ( yFrac == 0 ) |
---|
939 | { |
---|
940 | m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac, !bi |
---|
941 | #if H_3D_ARP |
---|
942 | , filterType |
---|
943 | #endif |
---|
944 | ); |
---|
945 | } |
---|
946 | else if ( xFrac == 0 ) |
---|
947 | { |
---|
948 | m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi |
---|
949 | #if H_3D_ARP |
---|
950 | , filterType |
---|
951 | #endif |
---|
952 | ); |
---|
953 | } |
---|
954 | else |
---|
955 | { |
---|
956 | Int tmpStride = m_filteredBlockTmp[0].getStride(); |
---|
957 | Short *tmp = m_filteredBlockTmp[0].getLumaAddr(); |
---|
958 | |
---|
959 | Int filterSize = NTAPS_LUMA; |
---|
960 | Int halfFilterSize = ( filterSize >> 1 ); |
---|
961 | |
---|
962 | m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false |
---|
963 | #if H_3D_ARP |
---|
964 | , filterType |
---|
965 | #endif |
---|
966 | ); |
---|
967 | m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height, yFrac, false, !bi |
---|
968 | #if H_3D_ARP |
---|
969 | , filterType |
---|
970 | #endif |
---|
971 | ); |
---|
972 | } |
---|
973 | |
---|
974 | #if H_3D_IC |
---|
975 | if( bICFlag ) |
---|
976 | { |
---|
977 | Int a, b, iShift, i, j; |
---|
978 | |
---|
979 | xGetLLSICPrediction( cu, mv, refPic, a, b, iShift, TEXT_LUMA ); |
---|
980 | |
---|
981 | for ( i = 0; i < height; i++ ) |
---|
982 | { |
---|
983 | for ( j = 0; j < width; j++ ) |
---|
984 | { |
---|
985 | if( bi ) |
---|
986 | { |
---|
987 | Int iIFshift = IF_INTERNAL_PREC - g_bitDepthY; |
---|
988 | dst[j] = ( ( a*dst[j] + a*IF_INTERNAL_OFFS ) >> iShift ) + b*( 1 << iIFshift ) - IF_INTERNAL_OFFS; |
---|
989 | } |
---|
990 | else |
---|
991 | dst[j] = Clip3( 0, ( 1 << g_bitDepthY ) - 1, ( ( a*dst[j] ) >> iShift ) + b ); |
---|
992 | } |
---|
993 | dst += dstStride; |
---|
994 | } |
---|
995 | } |
---|
996 | #endif |
---|
997 | } |
---|
998 | |
---|
999 | /** |
---|
1000 | * \brief Generate motion-compensated chroma block |
---|
1001 | * |
---|
1002 | * \param cu Pointer to current CU |
---|
1003 | * \param refPic Pointer to reference picture |
---|
1004 | * \param partAddr Address of block within CU |
---|
1005 | * \param mv Motion vector |
---|
1006 | * \param width Width of block |
---|
1007 | * \param height Height of block |
---|
1008 | * \param dstPic Pointer to destination picture |
---|
1009 | * \param bi Flag indicating whether bipred is used |
---|
1010 | */ |
---|
1011 | Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi |
---|
1012 | #if H_3D_ARP |
---|
1013 | , Bool filterType |
---|
1014 | #endif |
---|
1015 | #if H_3D_IC |
---|
1016 | , Bool bICFlag |
---|
1017 | #endif |
---|
1018 | ) |
---|
1019 | { |
---|
1020 | Int refStride = refPic->getCStride(); |
---|
1021 | Int dstStride = dstPic->getCStride(); |
---|
1022 | |
---|
1023 | Int refOffset = (mv->getHor() >> 3) + (mv->getVer() >> 3) * refStride; |
---|
1024 | |
---|
1025 | Pel* refCb = refPic->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
1026 | Pel* refCr = refPic->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
1027 | |
---|
1028 | Pel* dstCb = dstPic->getCbAddr( partAddr ); |
---|
1029 | Pel* dstCr = dstPic->getCrAddr( partAddr ); |
---|
1030 | |
---|
1031 | Int xFrac = mv->getHor() & 0x7; |
---|
1032 | Int yFrac = mv->getVer() & 0x7; |
---|
1033 | UInt cxWidth = width >> 1; |
---|
1034 | UInt cxHeight = height >> 1; |
---|
1035 | |
---|
1036 | Int extStride = m_filteredBlockTmp[0].getStride(); |
---|
1037 | Short* extY = m_filteredBlockTmp[0].getLumaAddr(); |
---|
1038 | |
---|
1039 | Int filterSize = NTAPS_CHROMA; |
---|
1040 | |
---|
1041 | Int halfFilterSize = (filterSize>>1); |
---|
1042 | |
---|
1043 | if ( yFrac == 0 ) |
---|
1044 | { |
---|
1045 | m_if.filterHorChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, xFrac, !bi |
---|
1046 | #if H_3D_ARP |
---|
1047 | , filterType |
---|
1048 | #endif |
---|
1049 | ); |
---|
1050 | m_if.filterHorChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, xFrac, !bi |
---|
1051 | #if H_3D_ARP |
---|
1052 | , filterType |
---|
1053 | #endif |
---|
1054 | ); |
---|
1055 | } |
---|
1056 | else if ( xFrac == 0 ) |
---|
1057 | { |
---|
1058 | m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi |
---|
1059 | #if H_3D_ARP |
---|
1060 | , filterType |
---|
1061 | #endif |
---|
1062 | ); |
---|
1063 | m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi |
---|
1064 | #if H_3D_ARP |
---|
1065 | , filterType |
---|
1066 | #endif |
---|
1067 | ); |
---|
1068 | } |
---|
1069 | else |
---|
1070 | { |
---|
1071 | m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY, extStride, cxWidth, cxHeight+filterSize-1, xFrac, false |
---|
1072 | #if H_3D_ARP |
---|
1073 | , filterType |
---|
1074 | #endif |
---|
1075 | ); |
---|
1076 | m_if.filterVerChroma(extY + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight , yFrac, false, !bi |
---|
1077 | #if H_3D_ARP |
---|
1078 | , filterType |
---|
1079 | #endif |
---|
1080 | ); |
---|
1081 | |
---|
1082 | m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY, extStride, cxWidth, cxHeight+filterSize-1, xFrac, false |
---|
1083 | #if H_3D_ARP |
---|
1084 | , filterType |
---|
1085 | #endif |
---|
1086 | ); |
---|
1087 | m_if.filterVerChroma(extY + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight , yFrac, false, !bi |
---|
1088 | #if H_3D_ARP |
---|
1089 | , filterType |
---|
1090 | #endif |
---|
1091 | ); |
---|
1092 | } |
---|
1093 | |
---|
1094 | #if H_3D_IC |
---|
1095 | if( bICFlag ) |
---|
1096 | { |
---|
1097 | Int a, b, iShift, i, j; |
---|
1098 | xGetLLSICPrediction( cu, mv, refPic, a, b, iShift, TEXT_CHROMA_U ); // Cb |
---|
1099 | for ( i = 0; i < cxHeight; i++ ) |
---|
1100 | { |
---|
1101 | for ( j = 0; j < cxWidth; j++ ) |
---|
1102 | { |
---|
1103 | if( bi ) |
---|
1104 | { |
---|
1105 | Int iIFshift = IF_INTERNAL_PREC - g_bitDepthC; |
---|
1106 | dstCb[j] = ( ( a*dstCb[j] + a*IF_INTERNAL_OFFS ) >> iShift ) + b*( 1<<iIFshift ) - IF_INTERNAL_OFFS; |
---|
1107 | } |
---|
1108 | else |
---|
1109 | dstCb[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCb[j] ) >> iShift ) + b ); |
---|
1110 | } |
---|
1111 | dstCb += dstStride; |
---|
1112 | } |
---|
1113 | xGetLLSICPrediction( cu, mv, refPic, a, b, iShift, TEXT_CHROMA_V ); // Cr |
---|
1114 | for ( i = 0; i < cxHeight; i++ ) |
---|
1115 | { |
---|
1116 | for ( j = 0; j < cxWidth; j++ ) |
---|
1117 | { |
---|
1118 | if( bi ) |
---|
1119 | { |
---|
1120 | Int iIFshift = IF_INTERNAL_PREC - g_bitDepthC; |
---|
1121 | dstCr[j] = ( ( a*dstCr[j] + a*IF_INTERNAL_OFFS ) >> iShift ) + b*( 1<<iIFshift ) - IF_INTERNAL_OFFS; |
---|
1122 | } |
---|
1123 | else |
---|
1124 | dstCr[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCr[j] ) >> iShift ) + b ); |
---|
1125 | } |
---|
1126 | dstCr += dstStride; |
---|
1127 | } |
---|
1128 | } |
---|
1129 | #endif |
---|
1130 | } |
---|
1131 | |
---|
1132 | Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst ) |
---|
1133 | { |
---|
1134 | if( iRefIdx0 >= 0 && iRefIdx1 >= 0 ) |
---|
1135 | { |
---|
1136 | rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight ); |
---|
1137 | } |
---|
1138 | else if ( iRefIdx0 >= 0 && iRefIdx1 < 0 ) |
---|
1139 | { |
---|
1140 | pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight ); |
---|
1141 | } |
---|
1142 | else if ( iRefIdx0 < 0 && iRefIdx1 >= 0 ) |
---|
1143 | { |
---|
1144 | pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight ); |
---|
1145 | } |
---|
1146 | } |
---|
1147 | |
---|
1148 | // AMVP |
---|
1149 | Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred ) |
---|
1150 | { |
---|
1151 | AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo(); |
---|
1152 | if( pcAMVPInfo->iN <= 1 ) |
---|
1153 | { |
---|
1154 | rcMvPred = pcAMVPInfo->m_acMvCand[0]; |
---|
1155 | |
---|
1156 | pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
1157 | pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
1158 | return; |
---|
1159 | } |
---|
1160 | |
---|
1161 | assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0); |
---|
1162 | rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)]; |
---|
1163 | return; |
---|
1164 | } |
---|
1165 | |
---|
1166 | /** Function for deriving planar intra prediction. |
---|
1167 | * \param pSrc pointer to reconstructed sample array |
---|
1168 | * \param srcStride the stride of the reconstructed sample array |
---|
1169 | * \param rpDst reference to pointer for the prediction sample array |
---|
1170 | * \param dstStride the stride of the prediction sample array |
---|
1171 | * \param width the width of the block |
---|
1172 | * \param height the height of the block |
---|
1173 | * |
---|
1174 | * This function derives the prediction samples for planar mode (intra coding). |
---|
1175 | */ |
---|
1176 | Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height ) |
---|
1177 | { |
---|
1178 | assert(width == height); |
---|
1179 | |
---|
1180 | Int k, l, bottomLeft, topRight; |
---|
1181 | Int horPred; |
---|
1182 | Int leftColumn[MAX_CU_SIZE], topRow[MAX_CU_SIZE], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE]; |
---|
1183 | UInt blkSize = width; |
---|
1184 | UInt offset2D = width; |
---|
1185 | UInt shift1D = g_aucConvertToBit[ width ] + 2; |
---|
1186 | UInt shift2D = shift1D + 1; |
---|
1187 | |
---|
1188 | // Get left and above reference column and row |
---|
1189 | for(k=0;k<blkSize+1;k++) |
---|
1190 | { |
---|
1191 | topRow[k] = pSrc[k-srcStride]; |
---|
1192 | leftColumn[k] = pSrc[k*srcStride-1]; |
---|
1193 | } |
---|
1194 | |
---|
1195 | // Prepare intermediate variables used in interpolation |
---|
1196 | bottomLeft = leftColumn[blkSize]; |
---|
1197 | topRight = topRow[blkSize]; |
---|
1198 | for (k=0;k<blkSize;k++) |
---|
1199 | { |
---|
1200 | bottomRow[k] = bottomLeft - topRow[k]; |
---|
1201 | rightColumn[k] = topRight - leftColumn[k]; |
---|
1202 | topRow[k] <<= shift1D; |
---|
1203 | leftColumn[k] <<= shift1D; |
---|
1204 | } |
---|
1205 | |
---|
1206 | // Generate prediction signal |
---|
1207 | for (k=0;k<blkSize;k++) |
---|
1208 | { |
---|
1209 | horPred = leftColumn[k] + offset2D; |
---|
1210 | for (l=0;l<blkSize;l++) |
---|
1211 | { |
---|
1212 | horPred += rightColumn[k]; |
---|
1213 | topRow[l] += bottomRow[l]; |
---|
1214 | rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D ); |
---|
1215 | } |
---|
1216 | } |
---|
1217 | } |
---|
1218 | |
---|
1219 | /** Function for filtering intra DC predictor. |
---|
1220 | * \param pSrc pointer to reconstructed sample array |
---|
1221 | * \param iSrcStride the stride of the reconstructed sample array |
---|
1222 | * \param rpDst reference to pointer for the prediction sample array |
---|
1223 | * \param iDstStride the stride of the prediction sample array |
---|
1224 | * \param iWidth the width of the block |
---|
1225 | * \param iHeight the height of the block |
---|
1226 | * |
---|
1227 | * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding). |
---|
1228 | */ |
---|
1229 | Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight ) |
---|
1230 | { |
---|
1231 | Pel* pDst = rpDst; |
---|
1232 | Int x, y, iDstStride2, iSrcStride2; |
---|
1233 | |
---|
1234 | // boundary pixels processing |
---|
1235 | pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2); |
---|
1236 | |
---|
1237 | for ( x = 1; x < iWidth; x++ ) |
---|
1238 | { |
---|
1239 | pDst[x] = (Pel)((pSrc[x - iSrcStride] + 3 * pDst[x] + 2) >> 2); |
---|
1240 | } |
---|
1241 | |
---|
1242 | for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride ) |
---|
1243 | { |
---|
1244 | pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2); |
---|
1245 | } |
---|
1246 | |
---|
1247 | return; |
---|
1248 | } |
---|
1249 | #if H_3D_IC |
---|
1250 | /** Function for deriving the position of first non-zero binary bit of a value |
---|
1251 | * \param x input value |
---|
1252 | * |
---|
1253 | * This function derives the position of first non-zero binary bit of a value |
---|
1254 | */ |
---|
1255 | Int GetMSB( UInt x ) |
---|
1256 | { |
---|
1257 | Int iMSB = 0, bits = ( sizeof( Int ) << 3 ), y = 1; |
---|
1258 | |
---|
1259 | while( x > 1 ) |
---|
1260 | { |
---|
1261 | bits >>= 1; |
---|
1262 | y = x >> bits; |
---|
1263 | |
---|
1264 | if( y ) |
---|
1265 | { |
---|
1266 | x = y; |
---|
1267 | iMSB += bits; |
---|
1268 | } |
---|
1269 | } |
---|
1270 | |
---|
1271 | iMSB+=y; |
---|
1272 | |
---|
1273 | return iMSB; |
---|
1274 | } |
---|
1275 | |
---|
1276 | /** Function for counting leading number of zeros/ones |
---|
1277 | * \param x input value |
---|
1278 | \ This function counts leading number of zeros for positive numbers and |
---|
1279 | \ leading number of ones for negative numbers. This can be implemented in |
---|
1280 | \ single instructure cycle on many processors. |
---|
1281 | */ |
---|
1282 | |
---|
1283 | Short CountLeadingZerosOnes (Short x) |
---|
1284 | { |
---|
1285 | Short clz; |
---|
1286 | Short i; |
---|
1287 | |
---|
1288 | if(x == 0) |
---|
1289 | { |
---|
1290 | clz = 0; |
---|
1291 | } |
---|
1292 | else |
---|
1293 | { |
---|
1294 | if (x == -1) |
---|
1295 | { |
---|
1296 | clz = 15; |
---|
1297 | } |
---|
1298 | else |
---|
1299 | { |
---|
1300 | if(x < 0) |
---|
1301 | { |
---|
1302 | x = ~x; |
---|
1303 | } |
---|
1304 | clz = 15; |
---|
1305 | for(i = 0;i < 15;++i) |
---|
1306 | { |
---|
1307 | if(x) |
---|
1308 | { |
---|
1309 | clz --; |
---|
1310 | } |
---|
1311 | x = x >> 1; |
---|
1312 | } |
---|
1313 | } |
---|
1314 | } |
---|
1315 | return clz; |
---|
1316 | } |
---|
1317 | |
---|
1318 | /** Function for deriving LM illumination compensation. |
---|
1319 | */ |
---|
1320 | Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, Int &iShift, TextType eType ) |
---|
1321 | { |
---|
1322 | TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec(); |
---|
1323 | Pel *pRec = NULL, *pRef = NULL; |
---|
1324 | UInt uiWidth, uiHeight, uiTmpPartIdx; |
---|
1325 | Int iRecStride = ( eType == TEXT_LUMA ) ? pRecPic->getStride() : pRecPic->getCStride(); |
---|
1326 | Int iRefStride = ( eType == TEXT_LUMA ) ? pRefPic->getStride() : pRefPic->getCStride(); |
---|
1327 | Int iCUPelX, iCUPelY, iRefX, iRefY, iRefOffset, iHor, iVer; |
---|
1328 | |
---|
1329 | iCUPelX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]]; |
---|
1330 | iCUPelY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]]; |
---|
1331 | iHor = pcCU->getSlice()->getIsDepth() ? pMv->getHor() : ( ( pMv->getHor() + 2 ) >> 2 ); |
---|
1332 | iVer = pcCU->getSlice()->getIsDepth() ? pMv->getVer() : ( ( pMv->getVer() + 2 ) >> 2 ); |
---|
1333 | iRefX = iCUPelX + iHor; |
---|
1334 | iRefY = iCUPelY + iVer; |
---|
1335 | if( eType != TEXT_LUMA ) |
---|
1336 | { |
---|
1337 | iHor = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getHor() + 1 ) >> 1 ) : ( ( pMv->getHor() + 4 ) >> 3 ); |
---|
1338 | iVer = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getVer() + 1 ) >> 1 ) : ( ( pMv->getVer() + 4 ) >> 3 ); |
---|
1339 | } |
---|
1340 | uiWidth = ( eType == TEXT_LUMA ) ? pcCU->getWidth( 0 ) : ( pcCU->getWidth( 0 ) >> 1 ); |
---|
1341 | uiHeight = ( eType == TEXT_LUMA ) ? pcCU->getHeight( 0 ) : ( pcCU->getHeight( 0 ) >> 1 ); |
---|
1342 | |
---|
1343 | Int i, j, iCountShift = 0; |
---|
1344 | |
---|
1345 | // LLS parameters estimation --> |
---|
1346 | |
---|
1347 | Int x = 0, y = 0, xx = 0, xy = 0; |
---|
1348 | |
---|
1349 | if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelY > 0 && iRefY > 0 ) |
---|
1350 | { |
---|
1351 | iRefOffset = iHor + iVer * iRefStride - iRefStride; |
---|
1352 | if( eType == TEXT_LUMA ) |
---|
1353 | { |
---|
1354 | pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
1355 | pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride; |
---|
1356 | } |
---|
1357 | else if( eType == TEXT_CHROMA_U ) |
---|
1358 | { |
---|
1359 | pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
1360 | pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride; |
---|
1361 | } |
---|
1362 | else |
---|
1363 | { |
---|
1364 | assert( eType == TEXT_CHROMA_V ); |
---|
1365 | pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
1366 | pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride; |
---|
1367 | } |
---|
1368 | |
---|
1369 | for( j = 0; j < uiWidth; j++ ) |
---|
1370 | { |
---|
1371 | x += pRef[j]; |
---|
1372 | y += pRec[j]; |
---|
1373 | xx += pRef[j] * pRef[j]; |
---|
1374 | xy += pRef[j] * pRec[j]; |
---|
1375 | } |
---|
1376 | iCountShift += g_aucConvertToBit[ uiWidth ] + 2; |
---|
1377 | } |
---|
1378 | |
---|
1379 | |
---|
1380 | if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelX > 0 && iRefX > 0 ) |
---|
1381 | { |
---|
1382 | iRefOffset = iHor + iVer * iRefStride - 1; |
---|
1383 | if( eType == TEXT_LUMA ) |
---|
1384 | { |
---|
1385 | pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
1386 | pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1; |
---|
1387 | } |
---|
1388 | else if( eType == TEXT_CHROMA_U ) |
---|
1389 | { |
---|
1390 | pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
1391 | pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1; |
---|
1392 | } |
---|
1393 | else |
---|
1394 | { |
---|
1395 | assert( eType == TEXT_CHROMA_V ); |
---|
1396 | pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
1397 | pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1; |
---|
1398 | } |
---|
1399 | |
---|
1400 | for( i = 0; i < uiHeight; i++ ) |
---|
1401 | { |
---|
1402 | x += pRef[0]; |
---|
1403 | y += pRec[0]; |
---|
1404 | xx += pRef[0] * pRef[0]; |
---|
1405 | xy += pRef[0] * pRec[0]; |
---|
1406 | |
---|
1407 | pRef += iRefStride; |
---|
1408 | pRec += iRecStride; |
---|
1409 | } |
---|
1410 | iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 2 ); |
---|
1411 | } |
---|
1412 | |
---|
1413 | Int iTempShift = ( ( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC ) + g_aucConvertToBit[ uiWidth ] + 3 - 15; |
---|
1414 | |
---|
1415 | if( iTempShift > 0 ) |
---|
1416 | { |
---|
1417 | x = ( x + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift; |
---|
1418 | y = ( y + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift; |
---|
1419 | xx = ( xx + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift; |
---|
1420 | xy = ( xy + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift; |
---|
1421 | iCountShift -= iTempShift; |
---|
1422 | } |
---|
1423 | |
---|
1424 | iShift = 13; |
---|
1425 | |
---|
1426 | if( iCountShift == 0 ) |
---|
1427 | { |
---|
1428 | a = 1; |
---|
1429 | b = 0; |
---|
1430 | iShift = 0; |
---|
1431 | } |
---|
1432 | else |
---|
1433 | { |
---|
1434 | Int a1 = ( xy << iCountShift ) - y * x; |
---|
1435 | Int a2 = ( xx << iCountShift ) - x * x; |
---|
1436 | |
---|
1437 | { |
---|
1438 | const Int iShiftA2 = 6; |
---|
1439 | const Int iShiftA1 = 15; |
---|
1440 | const Int iAccuracyShift = 15; |
---|
1441 | |
---|
1442 | Int iScaleShiftA2 = 0; |
---|
1443 | Int iScaleShiftA1 = 0; |
---|
1444 | Int a1s = a1; |
---|
1445 | Int a2s = a2; |
---|
1446 | |
---|
1447 | iScaleShiftA1 = GetMSB( abs( a1 ) ) - iShiftA1; |
---|
1448 | iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2; |
---|
1449 | |
---|
1450 | if( iScaleShiftA1 < 0 ) |
---|
1451 | { |
---|
1452 | iScaleShiftA1 = 0; |
---|
1453 | } |
---|
1454 | |
---|
1455 | if( iScaleShiftA2 < 0 ) |
---|
1456 | { |
---|
1457 | iScaleShiftA2 = 0; |
---|
1458 | } |
---|
1459 | |
---|
1460 | Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1; |
---|
1461 | |
---|
1462 | a2s = a2 >> iScaleShiftA2; |
---|
1463 | |
---|
1464 | a1s = a1 >> iScaleShiftA1; |
---|
1465 | |
---|
1466 | if (a2s >= 1) |
---|
1467 | { |
---|
1468 | a = a1s * m_uiaShift[ a2s - 1]; |
---|
1469 | } |
---|
1470 | else |
---|
1471 | { |
---|
1472 | a = 0; |
---|
1473 | } |
---|
1474 | |
---|
1475 | if( iScaleShiftA < 0 ) |
---|
1476 | { |
---|
1477 | a = a << -iScaleShiftA; |
---|
1478 | } |
---|
1479 | else |
---|
1480 | { |
---|
1481 | a = a >> iScaleShiftA; |
---|
1482 | } |
---|
1483 | |
---|
1484 | a = Clip3( -( 1 << 15 ), ( 1 << 15 ) - 1, a ); |
---|
1485 | |
---|
1486 | Int minA = -(1 << (6)); |
---|
1487 | Int maxA = (1 << 6) - 1; |
---|
1488 | if( a <= maxA && a >= minA ) |
---|
1489 | { |
---|
1490 | // do nothing |
---|
1491 | } |
---|
1492 | else |
---|
1493 | { |
---|
1494 | Short n = CountLeadingZerosOnes( a ); |
---|
1495 | a = a >> (9-n); |
---|
1496 | iShift -= (9-n); |
---|
1497 | } |
---|
1498 | |
---|
1499 | b = ( y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift; |
---|
1500 | } |
---|
1501 | } |
---|
1502 | } |
---|
1503 | #endif |
---|
1504 | |
---|
1505 | #if H_3D_VSP |
---|
1506 | // Input: |
---|
1507 | // refPic: Ref picture. Full picture, with padding |
---|
1508 | // posX, posY: PU position, texture |
---|
1509 | // sizeX, sizeY: PU size |
---|
1510 | // partAddr: z-order index |
---|
1511 | // dv: disparity vector. derived from neighboring blocks |
---|
1512 | // |
---|
1513 | // Output: dstPic, PU predictor 64x64 |
---|
1514 | Void TComPrediction::xPredInterLumaBlkFromDM( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv* dv, UInt partAddr,Int posX, Int posY |
---|
1515 | , Int sizeX, Int sizeY, Bool isDepth, TComYuv *&dstPic, Bool bi ) |
---|
1516 | { |
---|
1517 | Int widthLuma; |
---|
1518 | Int heightLuma; |
---|
1519 | |
---|
1520 | if (isDepth) |
---|
1521 | { |
---|
1522 | widthLuma = pPicBaseDepth->getWidth(); |
---|
1523 | heightLuma = pPicBaseDepth->getHeight(); |
---|
1524 | } |
---|
1525 | else |
---|
1526 | { |
---|
1527 | widthLuma = refPic->getWidth(); |
---|
1528 | heightLuma = refPic->getHeight(); |
---|
1529 | } |
---|
1530 | |
---|
1531 | #if H_3D_VSP_BLOCKSIZE != 1 |
---|
1532 | Int widthDepth = pPicBaseDepth->getWidth(); |
---|
1533 | Int heightDepth = pPicBaseDepth->getHeight(); |
---|
1534 | #endif |
---|
1535 | |
---|
1536 | #if H_3D_VSP_CONSTRAINED |
---|
1537 | Int widthDepth = pPicBaseDepth->getWidth(); |
---|
1538 | Int heightDepth = pPicBaseDepth->getHeight(); |
---|
1539 | #endif |
---|
1540 | |
---|
1541 | Int nTxtPerDepthX = widthLuma / ( pPicBaseDepth->getWidth() ); // texture pixel # per depth pixel |
---|
1542 | Int nTxtPerDepthY = heightLuma / ( pPicBaseDepth->getHeight() ); |
---|
1543 | |
---|
1544 | Int refStride = refPic->getStride(); |
---|
1545 | Int dstStride = dstPic->getStride(); |
---|
1546 | Int depStride = pPicBaseDepth->getStride(); |
---|
1547 | Int depthPosX = Clip3(0, widthLuma - sizeX, (posX/nTxtPerDepthX) + ((dv->getHor()+2)>>2)); |
---|
1548 | Int depthPosY = Clip3(0, heightLuma- sizeY, (posY/nTxtPerDepthY) + ((dv->getVer()+2)>>2)); |
---|
1549 | Pel *ref = refPic->getLumaAddr() + posX + posY * refStride; |
---|
1550 | Pel *dst = dstPic->getLumaAddr(partAddr); |
---|
1551 | Pel *depth = pPicBaseDepth->getLumaAddr() + depthPosX + depthPosY * depStride; |
---|
1552 | |
---|
1553 | #if H_3D_VSP_BLOCKSIZE != 1 |
---|
1554 | #if H_3D_VSP_BLOCKSIZE == 2 |
---|
1555 | Int dW = sizeX>>1; |
---|
1556 | Int dH = sizeY>>1; |
---|
1557 | #endif |
---|
1558 | #if H_3D_VSP_BLOCKSIZE == 4 |
---|
1559 | Int dW = sizeX>>2; |
---|
1560 | Int dH = sizeY>>2; |
---|
1561 | #endif |
---|
1562 | { |
---|
1563 | Pel* depthi = depth; |
---|
1564 | for (Int j = 0; j < dH; j++) |
---|
1565 | { |
---|
1566 | for (Int i = 0; i < dW; i++) |
---|
1567 | { |
---|
1568 | Pel* depthTmp; |
---|
1569 | #if H_3D_VSP_BLOCKSIZE == 2 |
---|
1570 | if (depthPosX + (i<<1) < widthDepth) |
---|
1571 | depthTmp = depthi + (i << 1); |
---|
1572 | else |
---|
1573 | depthTmp = depthi + (widthDepth - depthPosX - 1); |
---|
1574 | #endif |
---|
1575 | #if H_3D_VSP_BLOCKSIZE == 4 |
---|
1576 | if (depthPosX + (i<<2) < widthDepth) |
---|
1577 | depthTmp = depthi + (i << 2); |
---|
1578 | else |
---|
1579 | depthTmp = depthi + (widthDepth - depthPosX - 1); |
---|
1580 | #endif |
---|
1581 | Int maxV = 0; |
---|
1582 | for (Int blockj = 0; blockj < H_3D_VSP_BLOCKSIZE; blockj+=(H_3D_VSP_BLOCKSIZE-1)) |
---|
1583 | { |
---|
1584 | Int iX = 0; |
---|
1585 | for (Int blocki = 0; blocki < H_3D_VSP_BLOCKSIZE; blocki+=(H_3D_VSP_BLOCKSIZE-1)) |
---|
1586 | { |
---|
1587 | if (maxV < depthTmp[iX]) |
---|
1588 | maxV = depthTmp[iX]; |
---|
1589 | #if H_3D_VSP_BLOCKSIZE == 2 |
---|
1590 | if (depthPosX + (i<<1) + blocki < widthDepth - 1) |
---|
1591 | #else // H_3D_VSP_BLOCKSIZE == 4 |
---|
1592 | if (depthPosX + (i<<2) + blocki < widthDepth - 1) |
---|
1593 | #endif |
---|
1594 | iX = (H_3D_VSP_BLOCKSIZE-1); |
---|
1595 | } |
---|
1596 | #if H_3D_VSP_BLOCKSIZE == 2 |
---|
1597 | if (depthPosY + (j<<1) + blockj < heightDepth - 1) |
---|
1598 | #else // H_3D_VSP_BLOCKSIZE == 4 |
---|
1599 | if (depthPosY + (j<<2) + blockj < heightDepth - 1) |
---|
1600 | #endif |
---|
1601 | depthTmp += depStride * (H_3D_VSP_BLOCKSIZE-1); |
---|
1602 | } |
---|
1603 | m_pDepthBlock[i+j*dW] = maxV; |
---|
1604 | } // end of i < dW |
---|
1605 | #if H_3D_VSP_BLOCKSIZE == 2 |
---|
1606 | if (depthPosY + ((j+1)<<1) < heightDepth) |
---|
1607 | depthi += (depStride << 1); |
---|
1608 | else |
---|
1609 | depthi = depth + (heightDepth-depthPosY-1)*depStride; |
---|
1610 | #endif |
---|
1611 | #if H_3D_VSP_BLOCKSIZE == 4 |
---|
1612 | if (depthPosY + ((j+1)<<2) < heightDepth) // heightDepth-1 |
---|
1613 | depthi += (depStride << 2); |
---|
1614 | else |
---|
1615 | depthi = depth + (heightDepth-depthPosY-1)*depStride; // the last line |
---|
1616 | #endif |
---|
1617 | } |
---|
1618 | } |
---|
1619 | #endif // H_3D_VSP_BLOCKSIZE != 1 |
---|
1620 | |
---|
1621 | #if H_3D_VSP_BLOCKSIZE == 1 |
---|
1622 | #if H_3D_VSP_CONSTRAINED |
---|
1623 | //get LUT based horizontal reference range |
---|
1624 | Int range = xGetConstrainedSize(sizeX, sizeY); |
---|
1625 | |
---|
1626 | // The minimum depth value |
---|
1627 | Int minRelativePos = MAX_INT; |
---|
1628 | Int maxRelativePos = MIN_INT; |
---|
1629 | |
---|
1630 | Pel* depthTemp, *depthInitial=depth; |
---|
1631 | for (Int yTxt = 0; yTxt < sizeY; yTxt++) |
---|
1632 | { |
---|
1633 | for (Int xTxt = 0; xTxt < sizeX; xTxt++) |
---|
1634 | { |
---|
1635 | if (depthPosX+xTxt < widthDepth) |
---|
1636 | depthTemp = depthInitial + xTxt; |
---|
1637 | else |
---|
1638 | depthTemp = depthInitial + (widthDepth - depthPosX - 1); |
---|
1639 | |
---|
1640 | Int disparity = pShiftLUT[ *depthTemp ]; // << iShiftPrec; |
---|
1641 | Int disparityInt = disparity >> 2; |
---|
1642 | |
---|
1643 | if( disparity <= 0) |
---|
1644 | { |
---|
1645 | if (minRelativePos > disparityInt+xTxt) |
---|
1646 | minRelativePos = disparityInt+xTxt; |
---|
1647 | } |
---|
1648 | else |
---|
1649 | { |
---|
1650 | if (maxRelativePos < disparityInt+xTxt) |
---|
1651 | maxRelativePos = disparityInt+xTxt; |
---|
1652 | } |
---|
1653 | } |
---|
1654 | if (depthPosY+yTxt < heightDepth) |
---|
1655 | depthInitial = depthInitial + depStride; |
---|
1656 | } |
---|
1657 | |
---|
1658 | Int disparity_tmp = pShiftLUT[ *depth ]; // << iShiftPrec; |
---|
1659 | if (disparity_tmp <= 0) |
---|
1660 | maxRelativePos = minRelativePos + range -1 ; |
---|
1661 | else |
---|
1662 | minRelativePos = maxRelativePos - range +1 ; |
---|
1663 | #endif |
---|
1664 | #endif // H_3D_VSP_BLOCKSIZE == 1 |
---|
1665 | |
---|
1666 | #if H_3D_VSP_BLOCKSIZE != 1 |
---|
1667 | Int yDepth = 0; |
---|
1668 | #endif |
---|
1669 | for ( Int yTxt = 0; yTxt < sizeY; yTxt += nTxtPerDepthY ) |
---|
1670 | { |
---|
1671 | for ( Int xTxt = 0, xDepth = 0; xTxt < sizeX; xTxt += nTxtPerDepthX, xDepth++ ) |
---|
1672 | { |
---|
1673 | Pel repDepth = 0; // to store the depth value used for warping |
---|
1674 | #if H_3D_VSP_BLOCKSIZE == 1 |
---|
1675 | repDepth = depth[xDepth]; |
---|
1676 | #endif |
---|
1677 | #if H_3D_VSP_BLOCKSIZE == 2 |
---|
1678 | repDepth = m_pDepthBlock[(xTxt>>1) + (yTxt>>1)*dW]; |
---|
1679 | #endif |
---|
1680 | #if H_3D_VSP_BLOCKSIZE == 4 |
---|
1681 | repDepth = m_pDepthBlock[(xTxt>>2) + (yTxt>>2)*dW]; |
---|
1682 | #endif |
---|
1683 | |
---|
1684 | assert( repDepth >= 0 && repDepth <= 255 ); |
---|
1685 | Int disparity = pShiftLUT[ repDepth ]; // remove << iShiftPrec ?? |
---|
1686 | Int refOffset = xTxt + (disparity >> 2); |
---|
1687 | Int xFrac = disparity & 0x3; |
---|
1688 | #if H_3D_VSP_CONSTRAINED |
---|
1689 | if(refOffset<minRelativePos || refOffset>maxRelativePos) |
---|
1690 | xFrac = 0; |
---|
1691 | refOffset = Clip3(minRelativePos, maxRelativePos, refOffset); |
---|
1692 | #endif |
---|
1693 | Int absX = posX + refOffset; |
---|
1694 | |
---|
1695 | if (xFrac == 0) |
---|
1696 | absX = Clip3(0, widthLuma-1, absX); |
---|
1697 | else |
---|
1698 | absX = Clip3(4, widthLuma-5, absX); |
---|
1699 | |
---|
1700 | refOffset = absX - posX; |
---|
1701 | |
---|
1702 | assert( ref[refOffset] >= 0 && ref[refOffset]<= 255 ); |
---|
1703 | m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi ); |
---|
1704 | } |
---|
1705 | ref += refStride*nTxtPerDepthY; |
---|
1706 | dst += dstStride*nTxtPerDepthY; |
---|
1707 | depth += depStride; |
---|
1708 | #if H_3D_VSP_BLOCKSIZE != 1 |
---|
1709 | yDepth++; |
---|
1710 | #endif |
---|
1711 | |
---|
1712 | } |
---|
1713 | } |
---|
1714 | |
---|
1715 | Void TComPrediction::xPredInterChromaBlkFromDM ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv*dv, UInt partAddr, Int posX, Int posY |
---|
1716 | , Int sizeX, Int sizeY, Bool isDepth, TComYuv *&dstPic, Bool bi) |
---|
1717 | { |
---|
1718 | Int refStride = refPic->getCStride(); |
---|
1719 | Int dstStride = dstPic->getCStride(); |
---|
1720 | Int depStride = pPicBaseDepth->getStride(); |
---|
1721 | |
---|
1722 | Int widthChroma, heightChroma; |
---|
1723 | if( isDepth) |
---|
1724 | { |
---|
1725 | widthChroma = pPicBaseDepth->getWidth()>>1; |
---|
1726 | heightChroma = pPicBaseDepth->getHeight()>>1; |
---|
1727 | } |
---|
1728 | else |
---|
1729 | { |
---|
1730 | widthChroma = refPic->getWidth()>>1; |
---|
1731 | heightChroma = refPic->getHeight()>>1; |
---|
1732 | } |
---|
1733 | |
---|
1734 | // Below is only for Texture chroma component |
---|
1735 | |
---|
1736 | Int widthDepth = pPicBaseDepth->getWidth(); |
---|
1737 | Int heightDepth = pPicBaseDepth->getHeight(); |
---|
1738 | |
---|
1739 | Int nTxtPerDepthX, nTxtPerDepthY; // Number of texture samples per one depth sample |
---|
1740 | Int nDepthPerTxtX, nDepthPerTxtY; // Number of depth samples per one texture sample |
---|
1741 | |
---|
1742 | Int depthPosX; // Starting position in depth image |
---|
1743 | Int depthPosY; |
---|
1744 | |
---|
1745 | if ( widthChroma > widthDepth ) |
---|
1746 | { |
---|
1747 | nTxtPerDepthX = widthChroma / widthDepth; |
---|
1748 | nDepthPerTxtX = 1; |
---|
1749 | depthPosX = posX / nTxtPerDepthX + ((dv->getHor()+2)>>2); |
---|
1750 | } |
---|
1751 | else |
---|
1752 | { |
---|
1753 | nTxtPerDepthX = 1; |
---|
1754 | nDepthPerTxtX = widthDepth / widthChroma; |
---|
1755 | depthPosX = posX * nDepthPerTxtX + ((dv->getHor()+2)>>2); |
---|
1756 | } |
---|
1757 | depthPosX = Clip3(0, widthDepth - (sizeX<<1), depthPosX); |
---|
1758 | if ( heightChroma > heightDepth ) |
---|
1759 | { |
---|
1760 | nTxtPerDepthY = heightChroma / heightDepth; |
---|
1761 | nDepthPerTxtY = 1; |
---|
1762 | depthPosY = posY / nTxtPerDepthY + ((dv->getVer()+2)>>2); |
---|
1763 | } |
---|
1764 | else |
---|
1765 | { |
---|
1766 | nTxtPerDepthY = 1; |
---|
1767 | nDepthPerTxtY = heightDepth / heightChroma; |
---|
1768 | depthPosY = posY * nDepthPerTxtY + ((dv->getVer()+2)>>2); |
---|
1769 | } |
---|
1770 | depthPosY = Clip3(0, heightDepth - (sizeY<<1), depthPosY); |
---|
1771 | |
---|
1772 | Pel *refCb = refPic->getCbAddr() + posX + posY * refStride; |
---|
1773 | Pel *refCr = refPic->getCrAddr() + posX + posY * refStride; |
---|
1774 | Pel *dstCb = dstPic->getCbAddr(partAddr); |
---|
1775 | Pel *dstCr = dstPic->getCrAddr(partAddr); |
---|
1776 | Pel *depth = pPicBaseDepth->getLumaAddr() + depthPosX + depthPosY * depStride; // move the pointer to the current depth pixel position |
---|
1777 | |
---|
1778 | Int refStrideBlock = refStride * nTxtPerDepthY; |
---|
1779 | Int dstStrideBlock = dstStride * nTxtPerDepthY; |
---|
1780 | Int depStrideBlock = depStride * nDepthPerTxtY; |
---|
1781 | |
---|
1782 | if ( widthChroma > widthDepth ) // We assume |
---|
1783 | { |
---|
1784 | assert( heightChroma > heightDepth ); |
---|
1785 | printf("This branch should never been reached.\n"); |
---|
1786 | exit(0); |
---|
1787 | } |
---|
1788 | else |
---|
1789 | { |
---|
1790 | #if H_3D_VSP_BLOCKSIZE == 1 |
---|
1791 | Int dW = sizeX; |
---|
1792 | Int dH = sizeY; |
---|
1793 | Int sW = 2; // search window size |
---|
1794 | Int sH = 2; |
---|
1795 | #endif |
---|
1796 | #if H_3D_VSP_BLOCKSIZE == 2 |
---|
1797 | Int dW = sizeX; |
---|
1798 | Int dH = sizeY; |
---|
1799 | Int sW = 2; // search window size |
---|
1800 | Int sH = 2; |
---|
1801 | #endif |
---|
1802 | #if H_3D_VSP_BLOCKSIZE == 4 |
---|
1803 | Int dW = sizeX>>1; |
---|
1804 | Int dH = sizeY>>1; |
---|
1805 | Int sW = 4; // search window size |
---|
1806 | Int sH = 4; |
---|
1807 | #endif |
---|
1808 | |
---|
1809 | { |
---|
1810 | Pel* depthi = depth; |
---|
1811 | for (Int j = 0; j < dH; j++) |
---|
1812 | { |
---|
1813 | for (Int i = 0; i < dW; i++) |
---|
1814 | { |
---|
1815 | Pel* depthTmp; |
---|
1816 | #if H_3D_VSP_BLOCKSIZE == 1 |
---|
1817 | depthTmp = depthi + (i << 1); |
---|
1818 | #endif |
---|
1819 | #if H_3D_VSP_BLOCKSIZE == 2 |
---|
1820 | if (depthPosX + (i<<1) < widthDepth) |
---|
1821 | depthTmp = depthi + (i << 1); |
---|
1822 | else |
---|
1823 | depthTmp = depthi + (widthDepth - depthPosX - 1); |
---|
1824 | #endif |
---|
1825 | #if H_3D_VSP_BLOCKSIZE == 4 |
---|
1826 | if (depthPosX + (i<<2) < widthDepth) |
---|
1827 | depthTmp = depthi + (i << 2); |
---|
1828 | else |
---|
1829 | depthTmp = depthi + (widthDepth - depthPosX - 1); |
---|
1830 | #endif |
---|
1831 | Int maxV = 0; |
---|
1832 | for (Int blockj = 0; blockj < sH; blockj+=(sH-1)) |
---|
1833 | { |
---|
1834 | Int iX = 0; |
---|
1835 | for (Int blocki = 0; blocki < sW; blocki+=(sW-1)) |
---|
1836 | { |
---|
1837 | if (maxV < depthTmp[iX]) |
---|
1838 | maxV = depthTmp[iX]; |
---|
1839 | if (depthPosX + i*sW + blocki < widthDepth - 1) |
---|
1840 | iX = (sW-1); |
---|
1841 | } |
---|
1842 | if (depthPosY + j*sH + blockj < heightDepth - 1) |
---|
1843 | depthTmp += depStride * (sH-1); |
---|
1844 | } |
---|
1845 | m_pDepthBlock[i+j*dW] = maxV; |
---|
1846 | } // end of i < dW |
---|
1847 | #if H_3D_VSP_BLOCKSIZE == 1 |
---|
1848 | if (depthPosY + ((j+1)<<1) < heightDepth) |
---|
1849 | depthi += (depStride << 1); |
---|
1850 | else |
---|
1851 | depthi = depth + (heightDepth-1)*depStride; |
---|
1852 | #endif |
---|
1853 | #if H_3D_VSP_BLOCKSIZE == 2 |
---|
1854 | if (depthPosY + ((j+1)<<1) < heightDepth) |
---|
1855 | depthi += (depStride << 1); |
---|
1856 | else |
---|
1857 | depthi = depth + (heightDepth-depthPosY-1)*depStride; |
---|
1858 | #endif |
---|
1859 | #if H_3D_VSP_BLOCKSIZE == 4 |
---|
1860 | if (depthPosY + ((j+1)<<2) < heightDepth) // heightDepth-1 |
---|
1861 | depthi += (depStride << 2); |
---|
1862 | else |
---|
1863 | depthi = depth + (heightDepth-depthPosY-1)*depStride; // the last line |
---|
1864 | #endif |
---|
1865 | } |
---|
1866 | } |
---|
1867 | |
---|
1868 | |
---|
1869 | #if H_3D_VSP_BLOCKSIZE == 1 |
---|
1870 | #if H_3D_VSP_CONSTRAINED |
---|
1871 | //get LUT based horizontal reference range |
---|
1872 | Int range = xGetConstrainedSize(sizeX, sizeY, false); |
---|
1873 | |
---|
1874 | // The minimum depth value |
---|
1875 | Int minRelativePos = MAX_INT; |
---|
1876 | Int maxRelativePos = MIN_INT; |
---|
1877 | |
---|
1878 | Int depthTmp; |
---|
1879 | for (Int yTxt=0; yTxt<sizeY; yTxt++) |
---|
1880 | { |
---|
1881 | for (Int xTxt=0; xTxt<sizeX; xTxt++) |
---|
1882 | { |
---|
1883 | depthTmp = m_pDepthBlock[xTxt+yTxt*dW]; |
---|
1884 | Int disparity = pShiftLUT[ depthTmp ]; // << iShiftPrec; |
---|
1885 | Int disparityInt = disparity >> 3;//in chroma resolution |
---|
1886 | |
---|
1887 | if (disparityInt < 0) |
---|
1888 | { |
---|
1889 | if (minRelativePos > disparityInt+xTxt) |
---|
1890 | minRelativePos = disparityInt+xTxt; |
---|
1891 | } |
---|
1892 | else |
---|
1893 | { |
---|
1894 | if (maxRelativePos < disparityInt+xTxt) |
---|
1895 | maxRelativePos = disparityInt+xTxt; |
---|
1896 | } |
---|
1897 | } |
---|
1898 | } |
---|
1899 | |
---|
1900 | depthTmp = m_pDepthBlock[0]; |
---|
1901 | Int disparity_tmp = pShiftLUT[ depthTmp ]; // << iShiftPrec; |
---|
1902 | if ( disparity_tmp < 0 ) |
---|
1903 | maxRelativePos = minRelativePos + range - 1; |
---|
1904 | else |
---|
1905 | minRelativePos = maxRelativePos - range + 1; |
---|
1906 | |
---|
1907 | #endif // H_3D_VSP_CONSTRAINED |
---|
1908 | #endif // H_3D_VSP_BLOCKSIZE == 1 |
---|
1909 | |
---|
1910 | // (sizeX, sizeY) is Chroma block size |
---|
1911 | for ( Int yTxt = 0, yDepth = 0; yTxt < sizeY; yTxt += nTxtPerDepthY, yDepth += nDepthPerTxtY ) |
---|
1912 | { |
---|
1913 | for ( Int xTxt = 0, xDepth = 0; xTxt < sizeX; xTxt += nTxtPerDepthX, xDepth += nDepthPerTxtX ) |
---|
1914 | { |
---|
1915 | Pel repDepth = 0; // to store the depth value used for warping |
---|
1916 | #if H_3D_VSP_BLOCKSIZE == 1 |
---|
1917 | repDepth = m_pDepthBlock[(xTxt) + (yTxt)*dW]; |
---|
1918 | #endif |
---|
1919 | #if H_3D_VSP_BLOCKSIZE == 2 |
---|
1920 | repDepth = m_pDepthBlock[(xTxt) + (yTxt)*dW]; |
---|
1921 | #endif |
---|
1922 | #if H_3D_VSP_BLOCKSIZE == 4 |
---|
1923 | repDepth = m_pDepthBlock[(xTxt>>1) + (yTxt>>1)*dW]; |
---|
1924 | #endif |
---|
1925 | |
---|
1926 | // calculate the offset in the reference picture |
---|
1927 | Int disparity = pShiftLUT[ repDepth ]; // Remove << iShiftPrec; |
---|
1928 | Int refOffset = xTxt + (disparity >> 3); // in integer pixel in chroma image |
---|
1929 | Int xFrac = disparity & 0x7; |
---|
1930 | #if H_3D_VSP_CONSTRAINED |
---|
1931 | if(refOffset < minRelativePos || refOffset > maxRelativePos) |
---|
1932 | xFrac = 0; |
---|
1933 | refOffset = Clip3(minRelativePos, maxRelativePos, refOffset); |
---|
1934 | #endif |
---|
1935 | Int absX = posX + refOffset; |
---|
1936 | |
---|
1937 | if (xFrac == 0) |
---|
1938 | absX = Clip3(0, widthChroma-1, absX); |
---|
1939 | else |
---|
1940 | absX = Clip3(4, widthChroma-5, absX); |
---|
1941 | |
---|
1942 | refOffset = absX - posX; |
---|
1943 | |
---|
1944 | assert( refCb[refOffset] >= 0 && refCb[refOffset]<= 255 ); |
---|
1945 | assert( refCr[refOffset] >= 0 && refCr[refOffset]<= 255 ); |
---|
1946 | m_if.filterHorChroma(&refCb[refOffset], refStride, &dstCb[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi); |
---|
1947 | m_if.filterHorChroma(&refCr[refOffset], refStride, &dstCr[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi); |
---|
1948 | } |
---|
1949 | refCb += refStrideBlock; |
---|
1950 | refCr += refStrideBlock; |
---|
1951 | dstCb += dstStrideBlock; |
---|
1952 | dstCr += dstStrideBlock; |
---|
1953 | depth += depStrideBlock; |
---|
1954 | } |
---|
1955 | } |
---|
1956 | |
---|
1957 | } |
---|
1958 | |
---|
1959 | #if H_3D_VSP_CONSTRAINED |
---|
1960 | Int TComPrediction::xGetConstrainedSize(Int nPbW, Int nPbH, Bool bLuma) |
---|
1961 | { |
---|
1962 | Int iSize = 0; |
---|
1963 | if (bLuma) |
---|
1964 | { |
---|
1965 | Int iArea = (nPbW+7) * (nPbH+7); |
---|
1966 | Int iAlpha = iArea / nPbH - nPbW - 7; |
---|
1967 | iSize = iAlpha + nPbW; |
---|
1968 | } |
---|
1969 | else // chroma |
---|
1970 | { |
---|
1971 | Int iArea = (nPbW+2) * (nPbH+2); |
---|
1972 | Int iAlpha = iArea / nPbH - nPbW - 4; |
---|
1973 | iSize = iAlpha + nPbW; |
---|
1974 | } |
---|
1975 | return iSize; |
---|
1976 | } |
---|
1977 | #endif // H_3D_VSP_CONSTRAINED |
---|
1978 | |
---|
1979 | #endif // H_3D_VSP |
---|
1980 | |
---|
1981 | #if H_3D_DIM |
---|
1982 | Void TComPrediction::xPredBiSegDCs( Int* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 ) |
---|
1983 | { |
---|
1984 | Int refDC1, refDC2; |
---|
1985 | const Int iTR = ( patternStride - 1 ) - srcStride; |
---|
1986 | const Int iTM = ( ( patternStride - 1 ) >> 1 ) - srcStride; |
---|
1987 | const Int iLB = ( patternStride - 1 ) * srcStride - 1; |
---|
1988 | const Int iLM = ( ( patternStride - 1 ) >> 1 ) * srcStride - 1; |
---|
1989 | |
---|
1990 | Bool bL = ( biSegPattern[0] != biSegPattern[(patternStride-1)*patternStride] ); |
---|
1991 | Bool bT = ( biSegPattern[0] != biSegPattern[(patternStride-1)] ); |
---|
1992 | |
---|
1993 | if( bL == bT ) |
---|
1994 | { |
---|
1995 | refDC1 = bL ? ( ptrSrc[iTR] + ptrSrc[iLB] )>>1 : 1<<( g_bitDepthY - 1 ); |
---|
1996 | refDC2 = ( ptrSrc[ -1] + ptrSrc[-(Int)srcStride] )>>1; |
---|
1997 | } |
---|
1998 | else |
---|
1999 | { |
---|
2000 | refDC1 = bL ? ptrSrc[iLB] : ptrSrc[iTR]; |
---|
2001 | refDC2 = bL ? ptrSrc[iTM] : ptrSrc[iLM]; |
---|
2002 | } |
---|
2003 | |
---|
2004 | predDC1 = biSegPattern[0] ? refDC1 : refDC2; |
---|
2005 | predDC2 = biSegPattern[0] ? refDC2 : refDC1; |
---|
2006 | } |
---|
2007 | |
---|
2008 | Void TComPrediction::xAssignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 ) |
---|
2009 | { |
---|
2010 | if( dstStride == patternStride ) |
---|
2011 | { |
---|
2012 | for( UInt k = 0; k < (patternStride * patternStride); k++ ) |
---|
2013 | { |
---|
2014 | if( true == biSegPattern[k] ) { ptrDst[k] = valDC2; } |
---|
2015 | else { ptrDst[k] = valDC1; } |
---|
2016 | } |
---|
2017 | } |
---|
2018 | else |
---|
2019 | { |
---|
2020 | Pel* piTemp = ptrDst; |
---|
2021 | for( UInt uiY = 0; uiY < patternStride; uiY++ ) |
---|
2022 | { |
---|
2023 | for( UInt uiX = 0; uiX < patternStride; uiX++ ) |
---|
2024 | { |
---|
2025 | if( true == biSegPattern[uiX] ) { piTemp[uiX] = valDC2; } |
---|
2026 | else { piTemp[uiX] = valDC1; } |
---|
2027 | } |
---|
2028 | piTemp += dstStride; |
---|
2029 | biSegPattern += patternStride; |
---|
2030 | } |
---|
2031 | } |
---|
2032 | } |
---|
2033 | |
---|
2034 | #if H_3D_DIM_DMM |
---|
2035 | UInt TComPrediction::xPredWedgeFromIntra( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Int iDeltaEnd ) |
---|
2036 | { |
---|
2037 | UInt uiThisBlockSize = uiWidth; |
---|
2038 | |
---|
2039 | TComDataCU* pcTempCU; |
---|
2040 | UInt uiTempPartIdx; |
---|
2041 | // 1st: try continue above wedgelet |
---|
2042 | pcTempCU = pcCU->getPUAbove( uiTempPartIdx, pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
2043 | if( pcTempCU && isDimMode( pcTempCU->getLumaIntraDir( uiTempPartIdx ) ) ) |
---|
2044 | { |
---|
2045 | UInt dimType = getDimType( pcTempCU->getLumaIntraDir( uiTempPartIdx ) ); |
---|
2046 | #if SEC_DMM2_E0146 |
---|
2047 | if( DMM1_IDX == dimType || DMM3_IDX == dimType ) |
---|
2048 | #else |
---|
2049 | if( DMM1_IDX == dimType || DMM2_IDX == dimType || DMM3_IDX == dimType ) |
---|
2050 | #endif |
---|
2051 | { |
---|
2052 | // get offset between current and reference block |
---|
2053 | UInt uiOffsetX = 0, uiOffsetY = 0; |
---|
2054 | xGetBlockOffset( pcCU, uiAbsPartIdx, pcTempCU, uiTempPartIdx, uiOffsetX, uiOffsetY ); |
---|
2055 | |
---|
2056 | // get reference wedgelet |
---|
2057 | WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[(pcTempCU->getWidth( uiTempPartIdx )>>((pcTempCU->getPartitionSize( uiTempPartIdx ) == SIZE_NxN) ? 1 : 0))])]; |
---|
2058 | TComWedgelet* pcRefWedgelet = &(pacWedgeList->at( pcTempCU->getDmmWedgeTabIdx( dimType, uiTempPartIdx ) ) ); |
---|
2059 | |
---|
2060 | // find wedgelet, if direction is suitable for continue wedge |
---|
2061 | if( pcRefWedgelet->checkPredDirAbovePossible( uiThisBlockSize, uiOffsetX ) ) |
---|
2062 | { |
---|
2063 | UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye; |
---|
2064 | pcRefWedgelet->getPredDirStartEndAbove( uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, uiThisBlockSize, uiOffsetX, iDeltaEnd ); |
---|
2065 | return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye ); |
---|
2066 | } |
---|
2067 | } |
---|
2068 | } |
---|
2069 | |
---|
2070 | // 2nd: try continue left wedglelet |
---|
2071 | pcTempCU = pcCU->getPULeft( uiTempPartIdx, pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
2072 | if( pcTempCU && isDimMode( pcTempCU->getLumaIntraDir( uiTempPartIdx ) ) ) |
---|
2073 | { |
---|
2074 | UInt dimType = getDimType( pcTempCU->getLumaIntraDir( uiTempPartIdx ) ); |
---|
2075 | #if SEC_DMM2_E0146 |
---|
2076 | if( DMM1_IDX == dimType || DMM3_IDX == dimType ) |
---|
2077 | #else |
---|
2078 | if( DMM1_IDX == dimType || DMM2_IDX == dimType || DMM3_IDX == dimType ) |
---|
2079 | #endif |
---|
2080 | { |
---|
2081 | // get offset between current and reference block |
---|
2082 | UInt uiOffsetX = 0, uiOffsetY = 0; |
---|
2083 | xGetBlockOffset( pcCU, uiAbsPartIdx, pcTempCU, uiTempPartIdx, uiOffsetX, uiOffsetY ); |
---|
2084 | |
---|
2085 | // get reference wedgelet |
---|
2086 | WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[(pcTempCU->getWidth( uiTempPartIdx )>>((pcTempCU->getPartitionSize( uiTempPartIdx ) == SIZE_NxN) ? 1 : 0))])]; |
---|
2087 | TComWedgelet* pcRefWedgelet = &(pacWedgeList->at( pcTempCU->getDmmWedgeTabIdx( dimType, uiTempPartIdx ) ) ); |
---|
2088 | |
---|
2089 | // find wedgelet, if direction is suitable for continue wedge |
---|
2090 | if( pcRefWedgelet->checkPredDirLeftPossible( uiThisBlockSize, uiOffsetY ) ) |
---|
2091 | { |
---|
2092 | UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye; |
---|
2093 | pcRefWedgelet->getPredDirStartEndLeft( uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, uiThisBlockSize, uiOffsetY, iDeltaEnd ); |
---|
2094 | return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye ); |
---|
2095 | } |
---|
2096 | } |
---|
2097 | } |
---|
2098 | |
---|
2099 | // 3rd: (default) make wedglet from intra dir and max slope point |
---|
2100 | Int iSlopeX = 0, iSlopeY = 0; |
---|
2101 | UInt uiStartPosX = 0, uiStartPosY = 0; |
---|
2102 | if( xGetWedgeIntraDirPredData( pcCU, uiAbsPartIdx, uiThisBlockSize, iSlopeX, iSlopeY, uiStartPosX, uiStartPosY ) ) |
---|
2103 | { |
---|
2104 | UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye; |
---|
2105 | xGetWedgeIntraDirStartEnd( pcCU, uiAbsPartIdx, uiThisBlockSize, iSlopeX, iSlopeY, uiStartPosX, uiStartPosY, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, iDeltaEnd ); |
---|
2106 | return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye ); |
---|
2107 | } |
---|
2108 | |
---|
2109 | return 0; |
---|
2110 | } |
---|
2111 | |
---|
2112 | UInt TComPrediction::xPredWedgeFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt intraTabIdx ) |
---|
2113 | { |
---|
2114 | TComPic* pcPicTex = pcCU->getSlice()->getTexturePic(); |
---|
2115 | assert( pcPicTex != NULL ); |
---|
2116 | TComDataCU* pcColTexCU = pcPicTex->getCU(pcCU->getAddr()); |
---|
2117 | UInt uiTexPartIdx = pcCU->getZorderIdxInCU() + uiAbsPartIdx; |
---|
2118 | Int uiColTexIntraDir = pcColTexCU->isIntra( uiTexPartIdx ) ? pcColTexCU->getLumaIntraDir( uiTexPartIdx ) : 255; |
---|
2119 | |
---|
2120 | if( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 ) { return g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]][uiColTexIntraDir-2].at(intraTabIdx); } |
---|
2121 | else { return g_dmmWedgeNodeLists[(g_aucConvertToBit[uiWidth])].at(intraTabIdx).getPatternIdx(); } |
---|
2122 | } |
---|
2123 | |
---|
2124 | Void TComPrediction::xPredContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge ) |
---|
2125 | { |
---|
2126 | pcContourWedge->clear(); |
---|
2127 | |
---|
2128 | // get copy of co-located texture luma block |
---|
2129 | TComYuv cTempYuv; |
---|
2130 | cTempYuv.create( uiWidth, uiHeight ); |
---|
2131 | cTempYuv.clear(); |
---|
2132 | Pel* piRefBlkY = cTempYuv.getLumaAddr(); |
---|
2133 | xCopyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight ); |
---|
2134 | piRefBlkY = cTempYuv.getLumaAddr(); |
---|
2135 | |
---|
2136 | // find contour for texture luma block |
---|
2137 | UInt iDC = 0; |
---|
2138 | for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) |
---|
2139 | { |
---|
2140 | iDC += piRefBlkY[k]; |
---|
2141 | } |
---|
2142 | iDC /= (uiWidth*uiHeight); |
---|
2143 | piRefBlkY = cTempYuv.getLumaAddr(); |
---|
2144 | |
---|
2145 | Bool* pabContourPattern = pcContourWedge->getPattern(); |
---|
2146 | for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) |
---|
2147 | { |
---|
2148 | pabContourPattern[k] = (piRefBlkY[k] > iDC) ? true : false; |
---|
2149 | } |
---|
2150 | |
---|
2151 | cTempYuv.destroy(); |
---|
2152 | } |
---|
2153 | |
---|
2154 | |
---|
2155 | Void TComPrediction::xCopyTextureLumaBlock( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight ) |
---|
2156 | { |
---|
2157 | TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec(); |
---|
2158 | assert( pcPicYuvRef != NULL ); |
---|
2159 | Int iRefStride = pcPicYuvRef->getStride(); |
---|
2160 | Pel* piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
2161 | |
---|
2162 | for ( Int y = 0; y < uiHeight; y++ ) |
---|
2163 | { |
---|
2164 | ::memcpy(piDestBlockY, piRefY, sizeof(Pel)*uiWidth); |
---|
2165 | piDestBlockY += uiWidth; |
---|
2166 | piRefY += iRefStride; |
---|
2167 | } |
---|
2168 | } |
---|
2169 | |
---|
2170 | Void TComPrediction::xGetBlockOffset( TComDataCU* pcCU, UInt uiAbsPartIdx, TComDataCU* pcRefCU, UInt uiRefAbsPartIdx, UInt& ruiOffsetX, UInt& ruiOffsetY ) |
---|
2171 | { |
---|
2172 | ruiOffsetX = 0; |
---|
2173 | ruiOffsetY = 0; |
---|
2174 | |
---|
2175 | // get offset between current and above/left block |
---|
2176 | UInt uiThisOriginX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
2177 | UInt uiThisOriginY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
2178 | |
---|
2179 | UInt uiNumPartInRefCU = pcRefCU->getTotalNumPart(); |
---|
2180 | UInt uiMaxDepthRefCU = 0; |
---|
2181 | while( uiNumPartInRefCU > 1 ) |
---|
2182 | { |
---|
2183 | uiNumPartInRefCU >>= 2; |
---|
2184 | uiMaxDepthRefCU++; |
---|
2185 | } |
---|
2186 | |
---|
2187 | UInt uiDepthRefPU = (pcRefCU->getDepth(uiRefAbsPartIdx)) + (pcRefCU->getPartitionSize(uiRefAbsPartIdx) == SIZE_2Nx2N ? 0 : 1); |
---|
2188 | UInt uiShifts = (uiMaxDepthRefCU - uiDepthRefPU)*2; |
---|
2189 | UInt uiRefBlockOriginPartIdx = (uiRefAbsPartIdx>>uiShifts)<<uiShifts; |
---|
2190 | |
---|
2191 | UInt uiRefOriginX = pcRefCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiRefBlockOriginPartIdx] ]; |
---|
2192 | UInt uiRefOriginY = pcRefCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiRefBlockOriginPartIdx] ]; |
---|
2193 | |
---|
2194 | if( (uiThisOriginX - uiRefOriginX) > 0 ) { ruiOffsetX = (UInt)(uiThisOriginX - uiRefOriginX); } |
---|
2195 | if( (uiThisOriginY - uiRefOriginY) > 0 ) { ruiOffsetY = (UInt)(uiThisOriginY - uiRefOriginY); } |
---|
2196 | } |
---|
2197 | |
---|
2198 | Bool TComPrediction::xGetWedgeIntraDirPredData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiBlockSize, Int& riSlopeX, Int& riSlopeY, UInt& ruiStartPosX, UInt& ruiStartPosY ) |
---|
2199 | { |
---|
2200 | riSlopeX = 0, riSlopeY = 0, ruiStartPosX = 0, ruiStartPosY = 0; |
---|
2201 | |
---|
2202 | // 1st step: get wedge start point (max. slope) |
---|
2203 | Int* piSource = pcCU->getPattern()->getAdiOrgBuf( uiBlockSize, uiBlockSize, m_piYuvExt ); |
---|
2204 | Int iSourceStride = ( uiBlockSize<<1 ) + 1; |
---|
2205 | |
---|
2206 | UInt uiSlopeMaxAbove = 0, uiPosSlopeMaxAbove = 0; |
---|
2207 | for( UInt uiPosHor = 0; uiPosHor < (uiBlockSize-1); uiPosHor++ ) |
---|
2208 | { |
---|
2209 | if( abs( piSource[uiPosHor+1] - piSource[uiPosHor] ) > uiSlopeMaxAbove ) |
---|
2210 | { |
---|
2211 | uiSlopeMaxAbove = abs( piSource[uiPosHor+1] - piSource[uiPosHor] ); |
---|
2212 | uiPosSlopeMaxAbove = uiPosHor; |
---|
2213 | } |
---|
2214 | } |
---|
2215 | |
---|
2216 | UInt uiSlopeMaxLeft = 0, uiPosSlopeMaxLeft = 0; |
---|
2217 | for( UInt uiPosVer = 0; uiPosVer < (uiBlockSize-1); uiPosVer++ ) |
---|
2218 | { |
---|
2219 | if( abs( piSource[(uiPosVer+1)*iSourceStride] - piSource[uiPosVer*iSourceStride] ) > uiSlopeMaxLeft ) |
---|
2220 | { |
---|
2221 | uiSlopeMaxLeft = abs( piSource[(uiPosVer+1)*iSourceStride] - piSource[uiPosVer*iSourceStride] ); |
---|
2222 | uiPosSlopeMaxLeft = uiPosVer; |
---|
2223 | } |
---|
2224 | } |
---|
2225 | |
---|
2226 | if( uiSlopeMaxAbove == 0 && uiSlopeMaxLeft == 0 ) |
---|
2227 | { |
---|
2228 | return false; |
---|
2229 | } |
---|
2230 | |
---|
2231 | ruiStartPosX = ( uiSlopeMaxAbove > uiSlopeMaxLeft ) ? uiPosSlopeMaxAbove : 0; |
---|
2232 | ruiStartPosY = ( uiSlopeMaxLeft >= uiSlopeMaxAbove ) ? uiPosSlopeMaxLeft : 0; |
---|
2233 | |
---|
2234 | // 2nd step: derive wedge direction |
---|
2235 | Int uiPreds[3] = {-1, -1, -1}; |
---|
2236 | Int iMode = -1; |
---|
2237 | Int iPredNum = pcCU->getIntraDirLumaPredictor( uiAbsPartIdx, uiPreds, &iMode ); |
---|
2238 | |
---|
2239 | UInt uiDirMode = 0; |
---|
2240 | if( iMode >= 0 ) { iPredNum = iMode; } |
---|
2241 | if( iPredNum == 1 ) { uiDirMode = uiPreds[0]; } |
---|
2242 | if( iPredNum == 2 ) { uiDirMode = uiPreds[1]; } |
---|
2243 | |
---|
2244 | if( uiDirMode < 2 ) { return false; } // no planar & DC |
---|
2245 | |
---|
2246 | Bool modeHor = (uiDirMode < 18); |
---|
2247 | Bool modeVer = !modeHor; |
---|
2248 | Int intraPredAngle = modeVer ? (Int)uiDirMode - VER_IDX : modeHor ? -((Int)uiDirMode - HOR_IDX) : 0; |
---|
2249 | Int absAng = abs(intraPredAngle); |
---|
2250 | Int signAng = intraPredAngle < 0 ? -1 : 1; |
---|
2251 | Int angTable[9] = {0,2,5,9,13,17,21,26,32}; |
---|
2252 | absAng = angTable[absAng]; |
---|
2253 | intraPredAngle = signAng * absAng; |
---|
2254 | |
---|
2255 | // 3rd step: set slope for direction |
---|
2256 | if( modeHor ) |
---|
2257 | { |
---|
2258 | riSlopeX = ( intraPredAngle > 0 ) ? -32 : 32; |
---|
2259 | riSlopeY = ( intraPredAngle > 0 ) ? intraPredAngle : -intraPredAngle; |
---|
2260 | } |
---|
2261 | else if( modeVer ) |
---|
2262 | { |
---|
2263 | riSlopeX = ( intraPredAngle > 0 ) ? intraPredAngle : -intraPredAngle; |
---|
2264 | riSlopeY = ( intraPredAngle > 0 ) ? -32 : 32; |
---|
2265 | } |
---|
2266 | |
---|
2267 | return true; |
---|
2268 | } |
---|
2269 | |
---|
2270 | Void TComPrediction::xGetWedgeIntraDirStartEnd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiBlockSize, Int iDeltaX, Int iDeltaY, UInt uiPMSPosX, UInt uiPMSPosY, UChar& ruhXs, UChar& ruhYs, UChar& ruhXe, UChar& ruhYe, Int iDeltaEnd ) |
---|
2271 | { |
---|
2272 | ruhXs = 0; |
---|
2273 | ruhYs = 0; |
---|
2274 | ruhXe = 0; |
---|
2275 | ruhYe = 0; |
---|
2276 | |
---|
2277 | // scaling of start pos and block size to wedge resolution |
---|
2278 | UInt uiScaledStartPosX = 0; |
---|
2279 | UInt uiScaledStartPosY = 0; |
---|
2280 | UInt uiScaledBlockSize = 0; |
---|
2281 | WedgeResolution eWedgeRes = g_dmmWedgeResolution[(UInt)g_aucConvertToBit[uiBlockSize]]; |
---|
2282 | switch( eWedgeRes ) |
---|
2283 | { |
---|
2284 | case( DOUBLE_PEL ): { uiScaledStartPosX = (uiPMSPosX>>1); uiScaledStartPosY = (uiPMSPosY>>1); uiScaledBlockSize = (uiBlockSize>>1); break; } |
---|
2285 | case( FULL_PEL ): { uiScaledStartPosX = uiPMSPosX; uiScaledStartPosY = uiPMSPosY; uiScaledBlockSize = uiBlockSize; break; } |
---|
2286 | case( HALF_PEL ): { uiScaledStartPosX = (uiPMSPosX<<1); uiScaledStartPosY = (uiPMSPosY<<1); uiScaledBlockSize = (uiBlockSize<<1); break; } |
---|
2287 | } |
---|
2288 | Int iMaxPos = (Int)uiScaledBlockSize - 1; |
---|
2289 | |
---|
2290 | // case above |
---|
2291 | if( uiScaledStartPosX > 0 && uiScaledStartPosY == 0 ) |
---|
2292 | { |
---|
2293 | ruhXs = (UChar)uiScaledStartPosX; |
---|
2294 | ruhYs = 0; |
---|
2295 | |
---|
2296 | if( iDeltaY == 0 ) |
---|
2297 | { |
---|
2298 | if( iDeltaX < 0 ) |
---|
2299 | { |
---|
2300 | ruhXe = 0; |
---|
2301 | ruhYe = (UChar)std::min( std::max( iDeltaEnd, 0 ), iMaxPos ); |
---|
2302 | return; |
---|
2303 | } |
---|
2304 | else |
---|
2305 | { |
---|
2306 | ruhXe = (UChar)iMaxPos; |
---|
2307 | ruhYe = (UChar)std::min( std::max( -iDeltaEnd, 0 ), iMaxPos ); |
---|
2308 | std::swap( ruhXs, ruhXe ); |
---|
2309 | std::swap( ruhYs, ruhYe ); |
---|
2310 | return; |
---|
2311 | } |
---|
2312 | } |
---|
2313 | |
---|
2314 | // regular case |
---|
2315 | Int iVirtualEndX = (Int)ruhXs + roftoi( (Double)iMaxPos * ((Double)iDeltaX / (Double)iDeltaY) ); |
---|
2316 | |
---|
2317 | if( iVirtualEndX < 0 ) |
---|
2318 | { |
---|
2319 | Int iYe = roftoi( (Double)(0 - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) + iDeltaEnd; |
---|
2320 | if( iYe < (Int)uiScaledBlockSize ) |
---|
2321 | { |
---|
2322 | ruhXe = 0; |
---|
2323 | ruhYe = (UChar)std::max( iYe, 0 ); |
---|
2324 | return; |
---|
2325 | } |
---|
2326 | else |
---|
2327 | { |
---|
2328 | ruhXe = (UChar)std::min( (iYe - iMaxPos), iMaxPos ); |
---|
2329 | ruhYe = (UChar)iMaxPos; |
---|
2330 | return; |
---|
2331 | } |
---|
2332 | } |
---|
2333 | else if( iVirtualEndX > iMaxPos ) |
---|
2334 | { |
---|
2335 | Int iYe = roftoi( (Double)(iMaxPos - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) - iDeltaEnd; |
---|
2336 | if( iYe < (Int)uiScaledBlockSize ) |
---|
2337 | { |
---|
2338 | ruhXe = (UChar)iMaxPos; |
---|
2339 | ruhYe = (UChar)std::max( iYe, 0 ); |
---|
2340 | std::swap( ruhXs, ruhXe ); |
---|
2341 | std::swap( ruhYs, ruhYe ); |
---|
2342 | return; |
---|
2343 | } |
---|
2344 | else |
---|
2345 | { |
---|
2346 | ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 ); |
---|
2347 | ruhYe = (UChar)iMaxPos; |
---|
2348 | return; |
---|
2349 | } |
---|
2350 | } |
---|
2351 | else |
---|
2352 | { |
---|
2353 | Int iXe = iVirtualEndX + iDeltaEnd; |
---|
2354 | if( iXe < 0 ) |
---|
2355 | { |
---|
2356 | ruhXe = 0; |
---|
2357 | ruhYe = (UChar)std::max( (iMaxPos + iXe), 0 ); |
---|
2358 | return; |
---|
2359 | } |
---|
2360 | else if( iXe > iMaxPos ) |
---|
2361 | { |
---|
2362 | ruhXe = (UChar)iMaxPos; |
---|
2363 | ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 ); |
---|
2364 | std::swap( ruhXs, ruhXe ); |
---|
2365 | std::swap( ruhYs, ruhYe ); |
---|
2366 | return; |
---|
2367 | } |
---|
2368 | else |
---|
2369 | { |
---|
2370 | ruhXe = (UChar)iXe; |
---|
2371 | ruhYe = (UChar)iMaxPos; |
---|
2372 | return; |
---|
2373 | } |
---|
2374 | } |
---|
2375 | } |
---|
2376 | |
---|
2377 | // case left |
---|
2378 | if( uiScaledStartPosY > 0 && uiScaledStartPosX == 0 ) |
---|
2379 | { |
---|
2380 | ruhXs = 0; |
---|
2381 | ruhYs = (UChar)uiScaledStartPosY; |
---|
2382 | |
---|
2383 | if( iDeltaX == 0 ) |
---|
2384 | { |
---|
2385 | if( iDeltaY < 0 ) |
---|
2386 | { |
---|
2387 | ruhXe = (UChar)std::min( std::max( -iDeltaEnd, 0 ), iMaxPos ); |
---|
2388 | ruhYe = 0; |
---|
2389 | std::swap( ruhXs, ruhXe ); |
---|
2390 | std::swap( ruhYs, ruhYe ); |
---|
2391 | return; |
---|
2392 | } |
---|
2393 | else |
---|
2394 | { |
---|
2395 | ruhXe = (UChar)std::min( std::max( iDeltaEnd, 0 ), iMaxPos ); |
---|
2396 | ruhYe = (UChar)iMaxPos; |
---|
2397 | return; |
---|
2398 | } |
---|
2399 | } |
---|
2400 | |
---|
2401 | // regular case |
---|
2402 | Int iVirtualEndY = (Int)ruhYs + roftoi( (Double)iMaxPos * ((Double)iDeltaY / (Double)iDeltaX) ); |
---|
2403 | |
---|
2404 | if( iVirtualEndY < 0 ) |
---|
2405 | { |
---|
2406 | Int iXe = roftoi( (Double)(0 - (Int)ruhYs ) * ((Double)iDeltaX / (Double)iDeltaY) ) - iDeltaEnd; |
---|
2407 | if( iXe < (Int)uiScaledBlockSize ) |
---|
2408 | { |
---|
2409 | ruhXe = (UChar)std::max( iXe, 0 ); |
---|
2410 | ruhYe = 0; |
---|
2411 | std::swap( ruhXs, ruhXe ); |
---|
2412 | std::swap( ruhYs, ruhYe ); |
---|
2413 | return; |
---|
2414 | } |
---|
2415 | else |
---|
2416 | { |
---|
2417 | ruhXe = (UChar)iMaxPos; |
---|
2418 | ruhYe = (UChar)std::min( (iXe - iMaxPos), iMaxPos ); |
---|
2419 | std::swap( ruhXs, ruhXe ); |
---|
2420 | std::swap( ruhYs, ruhYe ); |
---|
2421 | return; |
---|
2422 | } |
---|
2423 | } |
---|
2424 | else if( iVirtualEndY > (uiScaledBlockSize-1) ) |
---|
2425 | { |
---|
2426 | Int iXe = roftoi( (Double)((Int)(uiScaledBlockSize-1) - (Int)ruhYs ) * ((Double)iDeltaX / (Double)iDeltaY) ) + iDeltaEnd; |
---|
2427 | if( iXe < (Int)uiScaledBlockSize ) |
---|
2428 | { |
---|
2429 | ruhXe = (UChar)std::max( iXe, 0 ); |
---|
2430 | ruhYe = (UChar)(uiScaledBlockSize-1); |
---|
2431 | return; |
---|
2432 | } |
---|
2433 | else |
---|
2434 | { |
---|
2435 | ruhXe = (UChar)iMaxPos; |
---|
2436 | ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 ); |
---|
2437 | std::swap( ruhXs, ruhXe ); |
---|
2438 | std::swap( ruhYs, ruhYe ); |
---|
2439 | return; |
---|
2440 | } |
---|
2441 | } |
---|
2442 | else |
---|
2443 | { |
---|
2444 | Int iYe = iVirtualEndY - iDeltaEnd; |
---|
2445 | if( iYe < 0 ) |
---|
2446 | { |
---|
2447 | ruhXe = (UChar)std::max( (iMaxPos + iYe), 0 ); |
---|
2448 | ruhYe = 0; |
---|
2449 | std::swap( ruhXs, ruhXe ); |
---|
2450 | std::swap( ruhYs, ruhYe ); |
---|
2451 | return; |
---|
2452 | } |
---|
2453 | else if( iYe > iMaxPos ) |
---|
2454 | { |
---|
2455 | ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 ); |
---|
2456 | ruhYe = (UChar)iMaxPos; |
---|
2457 | return; |
---|
2458 | } |
---|
2459 | else |
---|
2460 | { |
---|
2461 | ruhXe = (UChar)iMaxPos; |
---|
2462 | ruhYe = (UChar)iYe; |
---|
2463 | std::swap( ruhXs, ruhXe ); |
---|
2464 | std::swap( ruhYs, ruhYe ); |
---|
2465 | return; |
---|
2466 | } |
---|
2467 | } |
---|
2468 | } |
---|
2469 | |
---|
2470 | // case origin |
---|
2471 | if( uiScaledStartPosX == 0 && uiScaledStartPosY == 0 ) |
---|
2472 | { |
---|
2473 | if( iDeltaX*iDeltaY < 0 ) |
---|
2474 | { |
---|
2475 | return; |
---|
2476 | } |
---|
2477 | |
---|
2478 | ruhXs = 0; |
---|
2479 | ruhYs = 0; |
---|
2480 | |
---|
2481 | if( iDeltaY == 0 ) |
---|
2482 | { |
---|
2483 | ruhXe = (UChar)iMaxPos; |
---|
2484 | ruhYe = 0; |
---|
2485 | std::swap( ruhXs, ruhXe ); |
---|
2486 | std::swap( ruhYs, ruhYe ); |
---|
2487 | return; |
---|
2488 | } |
---|
2489 | |
---|
2490 | if( iDeltaX == 0 ) |
---|
2491 | { |
---|
2492 | ruhXe = 0; |
---|
2493 | ruhYe = (UChar)iMaxPos; |
---|
2494 | return; |
---|
2495 | } |
---|
2496 | |
---|
2497 | Int iVirtualEndX = (Int)ruhXs + roftoi( (Double)iMaxPos * ((Double)iDeltaX / (Double)iDeltaY) ); |
---|
2498 | |
---|
2499 | if( iVirtualEndX > iMaxPos ) |
---|
2500 | { |
---|
2501 | Int iYe = roftoi( (Double)((Int)iMaxPos - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) - iDeltaEnd; |
---|
2502 | if( iYe < (Int)uiScaledBlockSize ) |
---|
2503 | { |
---|
2504 | ruhXe = (UChar)(uiScaledBlockSize-1); |
---|
2505 | ruhYe = (UChar)std::max( iYe, 0 ); |
---|
2506 | std::swap( ruhXs, ruhXe ); |
---|
2507 | std::swap( ruhYs, ruhYe ); |
---|
2508 | return; |
---|
2509 | } |
---|
2510 | else |
---|
2511 | { |
---|
2512 | ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 ); |
---|
2513 | ruhYe = (UChar)(uiScaledBlockSize-1); |
---|
2514 | return; |
---|
2515 | } |
---|
2516 | } |
---|
2517 | else |
---|
2518 | { |
---|
2519 | Int iXe = iVirtualEndX + iDeltaEnd; |
---|
2520 | if( iXe < 0 ) |
---|
2521 | { |
---|
2522 | ruhXe = 0; |
---|
2523 | ruhYe = (UChar)std::max( (iMaxPos + iXe), 0 ); |
---|
2524 | return; |
---|
2525 | } |
---|
2526 | else if( iXe > iMaxPos ) |
---|
2527 | { |
---|
2528 | ruhXe = (UChar)(uiScaledBlockSize-1); |
---|
2529 | ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 ); |
---|
2530 | std::swap( ruhXs, ruhXe ); |
---|
2531 | std::swap( ruhYs, ruhYe ); |
---|
2532 | return; |
---|
2533 | } |
---|
2534 | else |
---|
2535 | { |
---|
2536 | ruhXe = (UChar)iXe; |
---|
2537 | ruhYe = (UChar)(uiScaledBlockSize-1); |
---|
2538 | return; |
---|
2539 | } |
---|
2540 | } |
---|
2541 | } |
---|
2542 | } |
---|
2543 | |
---|
2544 | UInt TComPrediction::xGetWedgePatternIdx( UInt uiBlockSize, UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe ) |
---|
2545 | { |
---|
2546 | WedgeRefList* pcWedgeRefList = &g_dmmWedgeRefLists[(g_aucConvertToBit[uiBlockSize])]; |
---|
2547 | for( UInt uiIdx = 0; uiIdx < pcWedgeRefList->size(); uiIdx++ ) |
---|
2548 | { |
---|
2549 | TComWedgeRef* pcTestWedgeRef = &(pcWedgeRefList->at(uiIdx)); |
---|
2550 | if( pcTestWedgeRef->getStartX() == uhXs && pcTestWedgeRef->getStartY() == uhYs && pcTestWedgeRef->getEndX() == uhXe && pcTestWedgeRef->getEndY() == uhYe ) |
---|
2551 | { |
---|
2552 | return pcTestWedgeRef->getRefIdx(); |
---|
2553 | } |
---|
2554 | } |
---|
2555 | return 0; |
---|
2556 | } |
---|
2557 | #endif |
---|
2558 | #if H_3D_DIM_RBC |
---|
2559 | Void TComPrediction::xDeltaDCQuantScaleUp( TComDataCU* pcCU, Pel& rDeltaDC ) |
---|
2560 | { |
---|
2561 | Int iSign = rDeltaDC < 0 ? -1 : 1; |
---|
2562 | UInt uiAbs = abs( rDeltaDC ); |
---|
2563 | |
---|
2564 | Int iQp = pcCU->getQP(0); |
---|
2565 | Double dMax = (Double)( 1<<( g_bitDepthY - 1 ) ); |
---|
2566 | Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 - 2.0 ) ); |
---|
2567 | |
---|
2568 | rDeltaDC = iSign * roftoi( uiAbs * dStepSize ); |
---|
2569 | return; |
---|
2570 | } |
---|
2571 | |
---|
2572 | Void TComPrediction::xDeltaDCQuantScaleDown( TComDataCU* pcCU, Pel& rDeltaDC ) |
---|
2573 | { |
---|
2574 | Int iSign = rDeltaDC < 0 ? -1 : 1; |
---|
2575 | UInt uiAbs = abs( rDeltaDC ); |
---|
2576 | |
---|
2577 | Int iQp = pcCU->getQP(0); |
---|
2578 | Double dMax = (Double)( 1<<( g_bitDepthY - 1 ) ); |
---|
2579 | Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 - 2.0 ) ); |
---|
2580 | |
---|
2581 | rDeltaDC = iSign * roftoi( uiAbs / dStepSize ); |
---|
2582 | return; |
---|
2583 | } |
---|
2584 | #endif |
---|
2585 | #if H_3D_DIM_SDC |
---|
2586 | Void TComPrediction::analyzeSegmentsSDC( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride ) |
---|
2587 | { |
---|
2588 | Int iSumDepth[2]; |
---|
2589 | memset(iSumDepth, 0, sizeof(Int)*2); |
---|
2590 | Int iSumPix[2]; |
---|
2591 | memset(iSumPix, 0, sizeof(Int)*2); |
---|
2592 | |
---|
2593 | Int subSamplePix; |
---|
2594 | if ( uiSize == 64 || uiSize == 32 ) |
---|
2595 | { |
---|
2596 | subSamplePix = 2; |
---|
2597 | } |
---|
2598 | else |
---|
2599 | { |
---|
2600 | subSamplePix = 1; |
---|
2601 | } |
---|
2602 | for (Int y=0; y<uiSize; y+=subSamplePix) |
---|
2603 | { |
---|
2604 | for (Int x=0; x<uiSize; x+=subSamplePix) |
---|
2605 | { |
---|
2606 | UChar ucSegment = pMask?(UChar)pMask[x]:0; |
---|
2607 | assert( ucSegment < uiNumSegments ); |
---|
2608 | |
---|
2609 | iSumDepth[ucSegment] += pOrig[x]; |
---|
2610 | iSumPix[ucSegment] += 1; |
---|
2611 | } |
---|
2612 | |
---|
2613 | pOrig += uiStride*subSamplePix; |
---|
2614 | pMask += uiMaskStride*subSamplePix; |
---|
2615 | } |
---|
2616 | |
---|
2617 | // compute mean for each segment |
---|
2618 | for( UChar ucSeg = 0; ucSeg < uiNumSegments; ucSeg++ ) |
---|
2619 | { |
---|
2620 | if( iSumPix[ucSeg] > 0 ) |
---|
2621 | rpSegMeans[ucSeg] = iSumDepth[ucSeg] / iSumPix[ucSeg]; |
---|
2622 | else |
---|
2623 | rpSegMeans[ucSeg] = 0; // this happens for zero-segments |
---|
2624 | } |
---|
2625 | } |
---|
2626 | #endif // H_3D_DIM_SDC |
---|
2627 | #endif |
---|
2628 | //! \} |
---|