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-2015, 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 | #include "TComPic.h" |
---|
41 | #include "TComTU.h" |
---|
42 | |
---|
43 | //! \ingroup TLibCommon |
---|
44 | //! \{ |
---|
45 | |
---|
46 | // ==================================================================================================================== |
---|
47 | // Tables |
---|
48 | // ==================================================================================================================== |
---|
49 | |
---|
50 | const UChar TComPrediction::m_aucIntraFilter[MAX_NUM_CHANNEL_TYPE][MAX_INTRA_FILTER_DEPTHS] = |
---|
51 | { |
---|
52 | { // Luma |
---|
53 | 10, //4x4 |
---|
54 | 7, //8x8 |
---|
55 | 1, //16x16 |
---|
56 | 0, //32x32 |
---|
57 | 10, //64x64 |
---|
58 | }, |
---|
59 | { // Chroma |
---|
60 | 10, //4xn |
---|
61 | 7, //8xn |
---|
62 | 1, //16xn |
---|
63 | 0, //32xn |
---|
64 | 10, //64xn |
---|
65 | } |
---|
66 | |
---|
67 | }; |
---|
68 | |
---|
69 | // ==================================================================================================================== |
---|
70 | // Constructor / destructor / initialize |
---|
71 | // ==================================================================================================================== |
---|
72 | |
---|
73 | TComPrediction::TComPrediction() |
---|
74 | : m_pLumaRecBuffer(0) |
---|
75 | , m_iLumaRecStride(0) |
---|
76 | { |
---|
77 | for(UInt ch=0; ch<MAX_NUM_COMPONENT; ch++) |
---|
78 | { |
---|
79 | for(UInt buf=0; buf<2; buf++) |
---|
80 | { |
---|
81 | m_piYuvExt[ch][buf] = NULL; |
---|
82 | } |
---|
83 | } |
---|
84 | #if H_3D_VSP |
---|
85 | m_pDepthBlock = (Int*) malloc(MAX_NUM_SPU_W*MAX_NUM_SPU_W*sizeof(Int)); |
---|
86 | if (m_pDepthBlock == NULL) |
---|
87 | { |
---|
88 | printf("ERROR: UKTGHU, No memory allocated.\n"); |
---|
89 | } |
---|
90 | #endif |
---|
91 | |
---|
92 | } |
---|
93 | |
---|
94 | TComPrediction::~TComPrediction() |
---|
95 | { |
---|
96 | #if H_3D_VSP |
---|
97 | if (m_pDepthBlock != NULL) |
---|
98 | { |
---|
99 | free(m_pDepthBlock); |
---|
100 | } |
---|
101 | m_cYuvDepthOnVsp.destroy(); |
---|
102 | #endif |
---|
103 | |
---|
104 | destroy(); |
---|
105 | } |
---|
106 | |
---|
107 | Void TComPrediction::destroy() |
---|
108 | { |
---|
109 | for(UInt ch=0; ch<MAX_NUM_COMPONENT; ch++) |
---|
110 | { |
---|
111 | for(UInt buf=0; buf<NUM_PRED_BUF; buf++) |
---|
112 | { |
---|
113 | delete [] m_piYuvExt[ch][buf]; |
---|
114 | m_piYuvExt[ch][buf] = NULL; |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++) |
---|
119 | { |
---|
120 | m_acYuvPred[i].destroy(); |
---|
121 | } |
---|
122 | |
---|
123 | m_cYuvPredTemp.destroy(); |
---|
124 | |
---|
125 | #if H_3D_ARP |
---|
126 | m_acYuvPredBase[0].destroy(); |
---|
127 | m_acYuvPredBase[1].destroy(); |
---|
128 | #endif |
---|
129 | if( m_pLumaRecBuffer ) |
---|
130 | { |
---|
131 | delete [] m_pLumaRecBuffer; |
---|
132 | m_pLumaRecBuffer = 0; |
---|
133 | } |
---|
134 | m_iLumaRecStride = 0; |
---|
135 | |
---|
136 | for (UInt i = 0; i < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; i++) |
---|
137 | { |
---|
138 | for (UInt j = 0; j < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; j++) |
---|
139 | { |
---|
140 | m_filteredBlock[i][j].destroy(); |
---|
141 | } |
---|
142 | m_filteredBlockTmp[i].destroy(); |
---|
143 | } |
---|
144 | } |
---|
145 | |
---|
146 | Void TComPrediction::initTempBuff(ChromaFormat chromaFormatIDC) |
---|
147 | { |
---|
148 | // if it has been initialised before, but the chroma format has changed, release the memory and start again. |
---|
149 | if( m_piYuvExt[COMPONENT_Y][PRED_BUF_UNFILTERED] != NULL && m_cYuvPredTemp.getChromaFormat()!=chromaFormatIDC) |
---|
150 | { |
---|
151 | destroy(); |
---|
152 | } |
---|
153 | |
---|
154 | if( m_piYuvExt[COMPONENT_Y][PRED_BUF_UNFILTERED] == NULL ) // check if first is null (in which case, nothing initialised yet) |
---|
155 | { |
---|
156 | Int extWidth = MAX_CU_SIZE + 16; |
---|
157 | Int extHeight = MAX_CU_SIZE + 1; |
---|
158 | |
---|
159 | for (UInt i = 0; i < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; i++) |
---|
160 | { |
---|
161 | m_filteredBlockTmp[i].create(extWidth, extHeight + 7, chromaFormatIDC); |
---|
162 | for (UInt j = 0; j < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; j++) |
---|
163 | { |
---|
164 | m_filteredBlock[i][j].create(extWidth, extHeight, chromaFormatIDC); |
---|
165 | } |
---|
166 | } |
---|
167 | |
---|
168 | m_iYuvExtSize = (MAX_CU_SIZE*2+1) * (MAX_CU_SIZE*2+1); |
---|
169 | for(UInt ch=0; ch<MAX_NUM_COMPONENT; ch++) |
---|
170 | { |
---|
171 | for(UInt buf=0; buf<NUM_PRED_BUF; buf++) |
---|
172 | { |
---|
173 | m_piYuvExt[ch][buf] = new Pel[ m_iYuvExtSize ]; |
---|
174 | } |
---|
175 | } |
---|
176 | |
---|
177 | // new structure |
---|
178 | for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++) |
---|
179 | { |
---|
180 | m_acYuvPred[i] .create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC ); |
---|
181 | } |
---|
182 | |
---|
183 | m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC ); |
---|
184 | #if H_3D_ARP |
---|
185 | m_acYuvPredBase[0] .create( g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
186 | m_acYuvPredBase[1] .create( g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
187 | #endif |
---|
188 | #if H_3D_VSP |
---|
189 | m_cYuvDepthOnVsp.create( g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
190 | #endif |
---|
191 | |
---|
192 | } |
---|
193 | |
---|
194 | |
---|
195 | if (m_iLumaRecStride != (MAX_CU_SIZE>>1) + 1) |
---|
196 | { |
---|
197 | m_iLumaRecStride = (MAX_CU_SIZE>>1) + 1; |
---|
198 | if (!m_pLumaRecBuffer) |
---|
199 | { |
---|
200 | m_pLumaRecBuffer = new Pel[ m_iLumaRecStride * m_iLumaRecStride ]; |
---|
201 | } |
---|
202 | } |
---|
203 | #if H_3D_IC |
---|
204 | m_uiaShift[0] = 0; |
---|
205 | for( Int i = 1; i < 64; i++ ) |
---|
206 | { |
---|
207 | m_uiaShift[i] = ( (1 << 15) + i/2 ) / i; |
---|
208 | } |
---|
209 | #endif |
---|
210 | } |
---|
211 | |
---|
212 | // ==================================================================================================================== |
---|
213 | // Public member functions |
---|
214 | // ==================================================================================================================== |
---|
215 | |
---|
216 | // Function for calculating DC value of the reference samples used in Intra prediction |
---|
217 | //NOTE: Bit-Limit - 25-bit source |
---|
218 | Pel TComPrediction::predIntraGetPredValDC( const Pel* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft ) |
---|
219 | { |
---|
220 | assert(iWidth > 0 && iHeight > 0); |
---|
221 | Int iInd, iSum = 0; |
---|
222 | Pel pDcVal; |
---|
223 | |
---|
224 | if (bAbove) |
---|
225 | { |
---|
226 | for (iInd = 0;iInd < iWidth;iInd++) |
---|
227 | { |
---|
228 | iSum += pSrc[iInd-iSrcStride]; |
---|
229 | } |
---|
230 | } |
---|
231 | if (bLeft) |
---|
232 | { |
---|
233 | for (iInd = 0;iInd < iHeight;iInd++) |
---|
234 | { |
---|
235 | iSum += pSrc[iInd*iSrcStride-1]; |
---|
236 | } |
---|
237 | } |
---|
238 | |
---|
239 | if (bAbove && bLeft) |
---|
240 | { |
---|
241 | pDcVal = (iSum + iWidth) / (iWidth + iHeight); |
---|
242 | } |
---|
243 | else if (bAbove) |
---|
244 | { |
---|
245 | pDcVal = (iSum + iWidth/2) / iWidth; |
---|
246 | } |
---|
247 | else if (bLeft) |
---|
248 | { |
---|
249 | pDcVal = (iSum + iHeight/2) / iHeight; |
---|
250 | } |
---|
251 | else |
---|
252 | { |
---|
253 | pDcVal = pSrc[-1]; // Default DC value already calculated and placed in the prediction array if no neighbors are available |
---|
254 | } |
---|
255 | |
---|
256 | return pDcVal; |
---|
257 | } |
---|
258 | |
---|
259 | // Function for deriving the angular Intra predictions |
---|
260 | |
---|
261 | /** Function for deriving the simplified angular intra predictions. |
---|
262 | * \param bitDepth bit depth |
---|
263 | * \param pSrc pointer to reconstructed sample array |
---|
264 | * \param srcStride the stride of the reconstructed sample array |
---|
265 | * \param pTrueDst reference to pointer for the prediction sample array |
---|
266 | * \param dstStrideTrue the stride of the prediction sample array |
---|
267 | * \param uiWidth the width of the block |
---|
268 | * \param uiHeight the height of the block |
---|
269 | * \param channelType type of pel array (luma/chroma) |
---|
270 | * \param format chroma format |
---|
271 | * \param dirMode the intra prediction mode index |
---|
272 | * \param blkAboveAvailable boolean indication if the block above is available |
---|
273 | * \param blkLeftAvailable boolean indication if the block to the left is available |
---|
274 | * \param bEnableEdgeFilters indication whether to enable edge filters |
---|
275 | * |
---|
276 | * This function derives the prediction samples for the angular mode based on the prediction direction indicated by |
---|
277 | * the prediction mode index. The prediction direction is given by the displacement of the bottom row of the block and |
---|
278 | * the reference row above the block in the case of vertical prediction or displacement of the rightmost column |
---|
279 | * of the block and reference column left from the block in the case of the horizontal prediction. The displacement |
---|
280 | * is signalled at 1/32 pixel accuracy. When projection of the predicted pixel falls inbetween reference samples, |
---|
281 | * the predicted value for the pixel is linearly interpolated from the reference samples. All reference samples are taken |
---|
282 | * from the extended main reference. |
---|
283 | */ |
---|
284 | //NOTE: Bit-Limit - 25-bit source |
---|
285 | Void TComPrediction::xPredIntraAng( Int bitDepth, |
---|
286 | const Pel* pSrc, Int srcStride, |
---|
287 | Pel* pTrueDst, Int dstStrideTrue, |
---|
288 | UInt uiWidth, UInt uiHeight, ChannelType channelType, |
---|
289 | UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable |
---|
290 | , const Bool bEnableEdgeFilters |
---|
291 | ) |
---|
292 | { |
---|
293 | Int width=Int(uiWidth); |
---|
294 | Int height=Int(uiHeight); |
---|
295 | |
---|
296 | // Map the mode index to main prediction direction and angle |
---|
297 | assert( dirMode != PLANAR_IDX ); //no planar |
---|
298 | const Bool modeDC = dirMode==DC_IDX; |
---|
299 | |
---|
300 | // Do the DC prediction |
---|
301 | if (modeDC) |
---|
302 | { |
---|
303 | const Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height, blkAboveAvailable, blkLeftAvailable); |
---|
304 | |
---|
305 | for (Int y=height;y>0;y--, pTrueDst+=dstStrideTrue) |
---|
306 | { |
---|
307 | for (Int x=0; x<width;) // width is always a multiple of 4. |
---|
308 | { |
---|
309 | pTrueDst[x++] = dcval; |
---|
310 | } |
---|
311 | } |
---|
312 | } |
---|
313 | else // Do angular predictions |
---|
314 | { |
---|
315 | const Bool bIsModeVer = (dirMode >= 18); |
---|
316 | const Int intraPredAngleMode = (bIsModeVer) ? (Int)dirMode - VER_IDX : -((Int)dirMode - HOR_IDX); |
---|
317 | const Int absAngMode = abs(intraPredAngleMode); |
---|
318 | const Int signAng = intraPredAngleMode < 0 ? -1 : 1; |
---|
319 | const Bool edgeFilter = bEnableEdgeFilters && isLuma(channelType) && (width <= MAXIMUM_INTRA_FILTERED_WIDTH) && (height <= MAXIMUM_INTRA_FILTERED_HEIGHT); |
---|
320 | |
---|
321 | // Set bitshifts and scale the angle parameter to block size |
---|
322 | static const Int angTable[9] = {0, 2, 5, 9, 13, 17, 21, 26, 32}; |
---|
323 | static const Int invAngTable[9] = {0, 4096, 1638, 910, 630, 482, 390, 315, 256}; // (256 * 32) / Angle |
---|
324 | Int invAngle = invAngTable[absAngMode]; |
---|
325 | Int absAng = angTable[absAngMode]; |
---|
326 | Int intraPredAngle = signAng * absAng; |
---|
327 | |
---|
328 | Pel* refMain; |
---|
329 | Pel* refSide; |
---|
330 | |
---|
331 | Pel refAbove[2*MAX_CU_SIZE+1]; |
---|
332 | Pel refLeft[2*MAX_CU_SIZE+1]; |
---|
333 | |
---|
334 | // Initialise the Main and Left reference array. |
---|
335 | if (intraPredAngle < 0) |
---|
336 | { |
---|
337 | const Int refMainOffsetPreScale = (bIsModeVer ? height : width ) - 1; |
---|
338 | const Int refMainOffset = height - 1; |
---|
339 | for (Int x=0;x<width+1;x++) |
---|
340 | { |
---|
341 | refAbove[x+refMainOffset] = pSrc[x-srcStride-1]; |
---|
342 | } |
---|
343 | for (Int y=0;y<height+1;y++) |
---|
344 | { |
---|
345 | refLeft[y+refMainOffset] = pSrc[(y-1)*srcStride-1]; |
---|
346 | } |
---|
347 | refMain = (bIsModeVer ? refAbove : refLeft) + refMainOffset; |
---|
348 | refSide = (bIsModeVer ? refLeft : refAbove) + refMainOffset; |
---|
349 | |
---|
350 | // Extend the Main reference to the left. |
---|
351 | Int invAngleSum = 128; // rounding for (shift by 8) |
---|
352 | for (Int k=-1; k>(refMainOffsetPreScale+1)*intraPredAngle>>5; k--) |
---|
353 | { |
---|
354 | invAngleSum += invAngle; |
---|
355 | refMain[k] = refSide[invAngleSum>>8]; |
---|
356 | } |
---|
357 | } |
---|
358 | else |
---|
359 | { |
---|
360 | for (Int x=0;x<2*width+1;x++) |
---|
361 | { |
---|
362 | refAbove[x] = pSrc[x-srcStride-1]; |
---|
363 | } |
---|
364 | for (Int y=0;y<2*height+1;y++) |
---|
365 | { |
---|
366 | refLeft[y] = pSrc[(y-1)*srcStride-1]; |
---|
367 | } |
---|
368 | refMain = bIsModeVer ? refAbove : refLeft ; |
---|
369 | refSide = bIsModeVer ? refLeft : refAbove; |
---|
370 | } |
---|
371 | |
---|
372 | // swap width/height if we are doing a horizontal mode: |
---|
373 | Pel tempArray[MAX_CU_SIZE*MAX_CU_SIZE]; |
---|
374 | const Int dstStride = bIsModeVer ? dstStrideTrue : MAX_CU_SIZE; |
---|
375 | Pel *pDst = bIsModeVer ? pTrueDst : tempArray; |
---|
376 | if (!bIsModeVer) |
---|
377 | { |
---|
378 | std::swap(width, height); |
---|
379 | } |
---|
380 | |
---|
381 | if (intraPredAngle == 0) // pure vertical or pure horizontal |
---|
382 | { |
---|
383 | for (Int y=0;y<height;y++) |
---|
384 | { |
---|
385 | for (Int x=0;x<width;x++) |
---|
386 | { |
---|
387 | pDst[y*dstStride+x] = refMain[x+1]; |
---|
388 | } |
---|
389 | } |
---|
390 | |
---|
391 | if (edgeFilter) |
---|
392 | { |
---|
393 | for (Int y=0;y<height;y++) |
---|
394 | { |
---|
395 | pDst[y*dstStride] = Clip3 (0, ((1 << bitDepth) - 1), pDst[y*dstStride] + (( refSide[y+1] - refSide[0] ) >> 1) ); |
---|
396 | } |
---|
397 | } |
---|
398 | } |
---|
399 | else |
---|
400 | { |
---|
401 | Pel *pDsty=pDst; |
---|
402 | |
---|
403 | for (Int y=0, deltaPos=intraPredAngle; y<height; y++, deltaPos+=intraPredAngle, pDsty+=dstStride) |
---|
404 | { |
---|
405 | const Int deltaInt = deltaPos >> 5; |
---|
406 | const Int deltaFract = deltaPos & (32 - 1); |
---|
407 | |
---|
408 | if (deltaFract) |
---|
409 | { |
---|
410 | // Do linear filtering |
---|
411 | const Pel *pRM=refMain+deltaInt+1; |
---|
412 | Int lastRefMainPel=*pRM++; |
---|
413 | for (Int x=0;x<width;pRM++,x++) |
---|
414 | { |
---|
415 | Int thisRefMainPel=*pRM; |
---|
416 | pDsty[x+0] = (Pel) ( ((32-deltaFract)*lastRefMainPel + deltaFract*thisRefMainPel +16) >> 5 ); |
---|
417 | lastRefMainPel=thisRefMainPel; |
---|
418 | } |
---|
419 | } |
---|
420 | else |
---|
421 | { |
---|
422 | // Just copy the integer samples |
---|
423 | for (Int x=0;x<width; x++) |
---|
424 | { |
---|
425 | pDsty[x] = refMain[x+deltaInt+1]; |
---|
426 | } |
---|
427 | } |
---|
428 | } |
---|
429 | } |
---|
430 | |
---|
431 | // Flip the block if this is the horizontal mode |
---|
432 | if (!bIsModeVer) |
---|
433 | { |
---|
434 | for (Int y=0; y<height; y++) |
---|
435 | { |
---|
436 | for (Int x=0; x<width; x++) |
---|
437 | { |
---|
438 | pTrueDst[x*dstStrideTrue] = pDst[x]; |
---|
439 | } |
---|
440 | pTrueDst++; |
---|
441 | pDst+=dstStride; |
---|
442 | } |
---|
443 | } |
---|
444 | } |
---|
445 | } |
---|
446 | |
---|
447 | Void TComPrediction::predIntraAng( const ComponentID compID, UInt uiDirMode, Pel* piOrg /* Will be null for decoding */, UInt uiOrgStride, Pel* piPred, UInt uiStride, TComTU &rTu, Bool bAbove, Bool bLeft, const Bool bUseFilteredPredSamples, const Bool bUseLosslessDPCM ) |
---|
448 | { |
---|
449 | const ChannelType channelType = toChannelType(compID); |
---|
450 | const TComRectangle &rect = rTu.getRect(isLuma(compID) ? COMPONENT_Y : COMPONENT_Cb); |
---|
451 | const Int iWidth = rect.width; |
---|
452 | const Int iHeight = rect.height; |
---|
453 | |
---|
454 | assert( g_aucConvertToBit[ iWidth ] >= 0 ); // 4x 4 |
---|
455 | assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128 |
---|
456 | //assert( iWidth == iHeight ); |
---|
457 | |
---|
458 | Pel *pDst = piPred; |
---|
459 | |
---|
460 | // get starting pixel in block |
---|
461 | const Int sw = (2 * iWidth + 1); |
---|
462 | |
---|
463 | if ( bUseLosslessDPCM ) |
---|
464 | { |
---|
465 | const Pel *ptrSrc = getPredictorPtr( compID, false ); |
---|
466 | // Sample Adaptive intra-Prediction (SAP) |
---|
467 | if (uiDirMode==HOR_IDX) |
---|
468 | { |
---|
469 | // left column filled with reference samples |
---|
470 | // remaining columns filled with piOrg data (if available). |
---|
471 | for(Int y=0; y<iHeight; y++) |
---|
472 | { |
---|
473 | piPred[y*uiStride+0] = ptrSrc[(y+1)*sw]; |
---|
474 | } |
---|
475 | if (piOrg!=0) |
---|
476 | { |
---|
477 | piPred+=1; // miss off first column |
---|
478 | for(Int y=0; y<iHeight; y++, piPred+=uiStride, piOrg+=uiOrgStride) |
---|
479 | { |
---|
480 | memcpy(piPred, piOrg, (iWidth-1)*sizeof(Pel)); |
---|
481 | } |
---|
482 | } |
---|
483 | } |
---|
484 | else // VER_IDX |
---|
485 | { |
---|
486 | // top row filled with reference samples |
---|
487 | // remaining rows filled with piOrd data (if available) |
---|
488 | for(Int x=0; x<iWidth; x++) |
---|
489 | { |
---|
490 | piPred[x] = ptrSrc[x+1]; |
---|
491 | } |
---|
492 | if (piOrg!=0) |
---|
493 | { |
---|
494 | piPred+=uiStride; // miss off the first row |
---|
495 | for(Int y=1; y<iHeight; y++, piPred+=uiStride, piOrg+=uiOrgStride) |
---|
496 | { |
---|
497 | memcpy(piPred, piOrg, iWidth*sizeof(Pel)); |
---|
498 | } |
---|
499 | } |
---|
500 | } |
---|
501 | } |
---|
502 | else |
---|
503 | { |
---|
504 | const Pel *ptrSrc = getPredictorPtr( compID, bUseFilteredPredSamples ); |
---|
505 | |
---|
506 | if ( uiDirMode == PLANAR_IDX ) |
---|
507 | { |
---|
508 | xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight ); |
---|
509 | } |
---|
510 | else |
---|
511 | { |
---|
512 | // Create the prediction |
---|
513 | TComDataCU *const pcCU = rTu.getCU(); |
---|
514 | const UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU(); |
---|
515 | const Bool enableEdgeFilters = !(pcCU->isRDPCMEnabled(uiAbsPartIdx) && pcCU->getCUTransquantBypass(uiAbsPartIdx)); |
---|
516 | #if O0043_BEST_EFFORT_DECODING |
---|
517 | const Int channelsBitDepthForPrediction = rTu.getCU()->getSlice()->getSPS()->getStreamBitDepth(channelType); |
---|
518 | #else |
---|
519 | const Int channelsBitDepthForPrediction = rTu.getCU()->getSlice()->getSPS()->getBitDepth(channelType); |
---|
520 | #endif |
---|
521 | xPredIntraAng( channelsBitDepthForPrediction, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType, uiDirMode, bAbove, bLeft, enableEdgeFilters ); |
---|
522 | |
---|
523 | if(( uiDirMode == DC_IDX ) && bAbove && bLeft ) |
---|
524 | { |
---|
525 | xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType ); |
---|
526 | } |
---|
527 | } |
---|
528 | } |
---|
529 | |
---|
530 | } |
---|
531 | |
---|
532 | #if NH_3D_DMM |
---|
533 | Void TComPrediction::predIntraLumaDmm( TComDataCU* pcCU, UInt uiAbsPartIdx, DmmID dmmType, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight ) |
---|
534 | { |
---|
535 | assert( iWidth == iHeight ); |
---|
536 | assert( iWidth >= DMM_MIN_SIZE && iWidth <= DMM_MAX_SIZE ); |
---|
537 | #if NH_3D_SDC_INTRA |
---|
538 | assert( !pcCU->getSDCFlag( uiAbsPartIdx ) ); |
---|
539 | #endif |
---|
540 | |
---|
541 | // get partition |
---|
542 | Bool* biSegPattern = new Bool[ (UInt)(iWidth*iHeight) ]; |
---|
543 | UInt patternStride = (UInt)iWidth; |
---|
544 | switch( dmmType ) |
---|
545 | { |
---|
546 | case( DMM1_IDX ): { (getWedgeListScaled( (UInt)iWidth )->at( pcCU->getDmm1WedgeTabIdx( uiAbsPartIdx ) )).getPatternScaledCopy( (UInt)iWidth, biSegPattern ); } break; |
---|
547 | case( DMM4_IDX ): { predContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, biSegPattern ); } break; |
---|
548 | default: assert(0); |
---|
549 | } |
---|
550 | |
---|
551 | // get predicted partition values |
---|
552 | Pel predDC1 = 0, predDC2 = 0; |
---|
553 | predBiSegDCs( pcCU, uiAbsPartIdx, iWidth, iHeight, biSegPattern, patternStride, predDC1, predDC2 ); |
---|
554 | |
---|
555 | // set segment values with deltaDC offsets |
---|
556 | Pel segDC1 = 0, segDC2 = 0; |
---|
557 | Pel deltaDC1 = pcCU->getDmmDeltaDC( dmmType, 0, uiAbsPartIdx ); |
---|
558 | Pel deltaDC2 = pcCU->getDmmDeltaDC( dmmType, 1, uiAbsPartIdx ); |
---|
559 | #if NH_3D_DLT |
---|
560 | segDC1 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 ) + deltaDC1 ); |
---|
561 | segDC2 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 ) + deltaDC2 ); |
---|
562 | #else |
---|
563 | segDC1 = ClipBD( predDC1 + deltaDC1, pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA) ); |
---|
564 | segDC2 = ClipBD( predDC2 + deltaDC2, pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA) ); |
---|
565 | #endif |
---|
566 | |
---|
567 | // set prediction signal |
---|
568 | Pel* pDst = piPred; |
---|
569 | assignBiSegDCs( pDst, uiStride, biSegPattern, patternStride, segDC1, segDC2 ); |
---|
570 | |
---|
571 | delete[] biSegPattern; |
---|
572 | } |
---|
573 | #endif |
---|
574 | |
---|
575 | /** Check for identical motion in both motion vector direction of a bi-directional predicted CU |
---|
576 | * \returns true, if motion vectors and reference pictures match |
---|
577 | */ |
---|
578 | Bool TComPrediction::xCheckIdenticalMotion ( TComDataCU* pcCU, UInt PartAddr ) |
---|
579 | { |
---|
580 | if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getPPS()->getWPBiPred() ) |
---|
581 | { |
---|
582 | if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr) >= 0 && pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr) >= 0) |
---|
583 | { |
---|
584 | Int RefPOCL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC(); |
---|
585 | Int RefPOCL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC(); |
---|
586 | #if H_3D_ARP |
---|
587 | if(!pcCU->getARPW(PartAddr) && RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr)) |
---|
588 | #else |
---|
589 | if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr)) |
---|
590 | #endif |
---|
591 | { |
---|
592 | return true; |
---|
593 | } |
---|
594 | } |
---|
595 | } |
---|
596 | return false; |
---|
597 | } |
---|
598 | |
---|
599 | #if H_3D_SPIVMP |
---|
600 | Void TComPrediction::xGetSubPUAddrAndMerge(TComDataCU* pcCU, UInt uiPartAddr, Int iSPWidth, Int iSPHeight, Int iNumSPInOneLine, Int iNumSP, UInt* uiMergedSPW, UInt* uiMergedSPH, UInt* uiSPAddr ) |
---|
601 | { |
---|
602 | for (Int i = 0; i < iNumSP; i++) |
---|
603 | { |
---|
604 | uiMergedSPW[i] = iSPWidth; |
---|
605 | uiMergedSPH[i] = iSPHeight; |
---|
606 | pcCU->getSPAbsPartIdx(uiPartAddr, iSPWidth, iSPHeight, i, iNumSPInOneLine, uiSPAddr[i]); |
---|
607 | } |
---|
608 | if( pcCU->getARPW( uiPartAddr ) != 0 ) |
---|
609 | { |
---|
610 | return; |
---|
611 | } |
---|
612 | |
---|
613 | // horizontal sub-PU merge |
---|
614 | for (Int i=0; i<iNumSP; i++) |
---|
615 | { |
---|
616 | if (i % iNumSPInOneLine == iNumSPInOneLine - 1 || uiMergedSPW[i]==0 || uiMergedSPH[i]==0) |
---|
617 | { |
---|
618 | continue; |
---|
619 | } |
---|
620 | for (Int j=i+1; j<i+iNumSPInOneLine-i%iNumSPInOneLine; j++) |
---|
621 | { |
---|
622 | if (xCheckTwoSPMotion(pcCU, uiSPAddr[i], uiSPAddr[j])) |
---|
623 | { |
---|
624 | uiMergedSPW[i] += iSPWidth; |
---|
625 | uiMergedSPW[j] = uiMergedSPH[j] = 0; |
---|
626 | } |
---|
627 | else |
---|
628 | { |
---|
629 | break; |
---|
630 | } |
---|
631 | } |
---|
632 | } |
---|
633 | //vertical sub-PU merge |
---|
634 | for (Int i=0; i<iNumSP-iNumSPInOneLine; i++) |
---|
635 | { |
---|
636 | if (uiMergedSPW[i]==0 || uiMergedSPH[i]==0) |
---|
637 | { |
---|
638 | continue; |
---|
639 | } |
---|
640 | for (Int j=i+iNumSPInOneLine; j<iNumSP; j+=iNumSPInOneLine) |
---|
641 | { |
---|
642 | if (xCheckTwoSPMotion(pcCU, uiSPAddr[i], uiSPAddr[j]) && uiMergedSPW[i]==uiMergedSPW[j]) |
---|
643 | { |
---|
644 | uiMergedSPH[i] += iSPHeight; |
---|
645 | uiMergedSPH[j] = uiMergedSPW[j] = 0; |
---|
646 | } |
---|
647 | else |
---|
648 | { |
---|
649 | break; |
---|
650 | } |
---|
651 | } |
---|
652 | } |
---|
653 | } |
---|
654 | |
---|
655 | Bool TComPrediction::xCheckTwoSPMotion ( TComDataCU* pcCU, UInt PartAddr0, UInt PartAddr1 ) |
---|
656 | { |
---|
657 | if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr1)) |
---|
658 | { |
---|
659 | return false; |
---|
660 | } |
---|
661 | if( pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr1)) |
---|
662 | { |
---|
663 | return false; |
---|
664 | } |
---|
665 | |
---|
666 | if (pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr0) >= 0) |
---|
667 | { |
---|
668 | if (pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr1)) |
---|
669 | { |
---|
670 | return false; |
---|
671 | } |
---|
672 | } |
---|
673 | |
---|
674 | if (pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr0) >= 0) |
---|
675 | { |
---|
676 | if (pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr1)) |
---|
677 | { |
---|
678 | return false; |
---|
679 | } |
---|
680 | } |
---|
681 | return true; |
---|
682 | } |
---|
683 | #endif |
---|
684 | |
---|
685 | #if H_3D_DBBP |
---|
686 | PartSize TComPrediction::getPartitionSizeFromDepth(Pel* pDepthPels, UInt uiDepthStride, UInt uiSize, TComDataCU*& pcCU) |
---|
687 | { |
---|
688 | // find virtual partitioning for this CU based on depth block |
---|
689 | // segmentation of texture block --> mask IDs |
---|
690 | Pel* pDepthBlockStart = pDepthPels; |
---|
691 | |
---|
692 | // first compute average of depth block for thresholding |
---|
693 | Int iSumDepth = 0; |
---|
694 | Int iSubSample = 4; |
---|
695 | Int iPictureWidth = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getWidth(); |
---|
696 | Int iPictureHeight = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getHeight(); |
---|
697 | TComMv cDv = pcCU->getSlice()->getDepthRefinementFlag( ) ? pcCU->getDvInfo(0).m_acDoNBDV : pcCU->getDvInfo(0).m_acNBDV; |
---|
698 | if( pcCU->getSlice()->getDepthRefinementFlag( ) ) |
---|
699 | { |
---|
700 | cDv.setVer(0); |
---|
701 | } |
---|
702 | Int iBlkX = ( pcCU->getAddr() % pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCU() ) * g_uiMaxCUWidth + g_auiRasterToPelX[ g_auiZscanToRaster[ pcCU->getZorderIdxInCU() ] ]+ ((cDv.getHor()+2)>>2); |
---|
703 | Int iBlkY = ( pcCU->getAddr() / pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ pcCU->getZorderIdxInCU() ] ]+ ((cDv.getVer()+2)>>2); |
---|
704 | |
---|
705 | UInt t=0; |
---|
706 | |
---|
707 | for (Int y=0; y<uiSize; y+=iSubSample) |
---|
708 | { |
---|
709 | for (Int x=0; x<uiSize; x+=iSubSample) |
---|
710 | { |
---|
711 | if (iBlkX+x>iPictureWidth) |
---|
712 | { |
---|
713 | Int depthPel = pDepthPels[t]; |
---|
714 | iSumDepth += depthPel; |
---|
715 | } |
---|
716 | else |
---|
717 | { |
---|
718 | Int depthPel = pDepthPels[x]; |
---|
719 | t=x; |
---|
720 | iSumDepth += depthPel; |
---|
721 | } |
---|
722 | } |
---|
723 | |
---|
724 | // next row |
---|
725 | if (!(iBlkY+y+4>iPictureHeight)) |
---|
726 | { |
---|
727 | pDepthPels += uiDepthStride*iSubSample; |
---|
728 | } |
---|
729 | } |
---|
730 | |
---|
731 | Int iSizeInBits = g_aucConvertToBit[uiSize] - g_aucConvertToBit[iSubSample]; // respect sub-sampling factor |
---|
732 | Int iMean = iSumDepth >> iSizeInBits*2; // iMean /= (uiSize*uiSize); |
---|
733 | |
---|
734 | // start again for segmentation |
---|
735 | pDepthPels = pDepthBlockStart; |
---|
736 | |
---|
737 | // start mapping process |
---|
738 | Int matchedPartSum[2][2] = {{0,0},{0,0}}; // counter for each part size and boolean option |
---|
739 | PartSize virtualPartSizes[2] = { SIZE_Nx2N, SIZE_2NxN}; |
---|
740 | |
---|
741 | UInt uiHalfSize = uiSize>>1; |
---|
742 | for (Int y=0; y<uiSize; y+=iSubSample) |
---|
743 | { |
---|
744 | for (Int x=0; x<uiSize; x+=iSubSample) |
---|
745 | { |
---|
746 | Int depthPel = 0; |
---|
747 | if (iBlkX+x>iPictureWidth) |
---|
748 | { |
---|
749 | depthPel = pDepthPels[t]; |
---|
750 | } |
---|
751 | else |
---|
752 | { |
---|
753 | depthPel = pDepthPels[x]; |
---|
754 | t=x; |
---|
755 | } |
---|
756 | |
---|
757 | // decide which segment this pixel belongs to |
---|
758 | Int ucSegment = (Int)(depthPel>iMean); |
---|
759 | |
---|
760 | // Matched Filter to find optimal (conventional) partitioning |
---|
761 | |
---|
762 | // SIZE_Nx2N |
---|
763 | if(x<uiHalfSize) // left |
---|
764 | { |
---|
765 | matchedPartSum[0][ucSegment]++; |
---|
766 | } |
---|
767 | else // right |
---|
768 | { |
---|
769 | matchedPartSum[0][1-ucSegment]++; |
---|
770 | } |
---|
771 | |
---|
772 | // SIZE_2NxN |
---|
773 | if(y<uiHalfSize) // top |
---|
774 | { |
---|
775 | matchedPartSum[1][ucSegment]++; |
---|
776 | } |
---|
777 | else // bottom |
---|
778 | { |
---|
779 | matchedPartSum[1][1-ucSegment]++; |
---|
780 | } |
---|
781 | } |
---|
782 | |
---|
783 | // next row |
---|
784 | if (!(iBlkY+y+4>iPictureHeight)) |
---|
785 | { |
---|
786 | pDepthPels += uiDepthStride*iSubSample; |
---|
787 | } |
---|
788 | } |
---|
789 | |
---|
790 | PartSize matchedPartSize = SIZE_NONE; |
---|
791 | |
---|
792 | Int iMaxMatchSum = 0; |
---|
793 | for(Int p=0; p<2; p++) // loop over partition |
---|
794 | { |
---|
795 | for( Int b=0; b<=1; b++ ) // loop over boolean options |
---|
796 | { |
---|
797 | if(matchedPartSum[p][b] > iMaxMatchSum) |
---|
798 | { |
---|
799 | iMaxMatchSum = matchedPartSum[p][b]; |
---|
800 | matchedPartSize = virtualPartSizes[p]; |
---|
801 | } |
---|
802 | } |
---|
803 | } |
---|
804 | |
---|
805 | AOF( matchedPartSize != SIZE_NONE ); |
---|
806 | |
---|
807 | return matchedPartSize; |
---|
808 | } |
---|
809 | |
---|
810 | Bool TComPrediction::getSegmentMaskFromDepth( Pel* pDepthPels, UInt uiDepthStride, UInt uiWidth, UInt uiHeight, Bool* pMask, TComDataCU*& pcCU) |
---|
811 | { |
---|
812 | // segmentation of texture block --> mask IDs |
---|
813 | Pel* pDepthBlockStart = pDepthPels; |
---|
814 | |
---|
815 | // first compute average of depth block for thresholding |
---|
816 | Int iSumDepth = 0; |
---|
817 | Int uiMinDepth = MAX_INT; |
---|
818 | Int uiMaxDepth = 0; |
---|
819 | uiMinDepth = pDepthPels[ 0 ]; |
---|
820 | uiMaxDepth = pDepthPels[ 0 ]; |
---|
821 | iSumDepth = pDepthPels[ 0 ]; |
---|
822 | |
---|
823 | Int iPictureWidth = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getWidth(); |
---|
824 | Int iPictureHeight = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getHeight(); |
---|
825 | TComMv cDv = pcCU->getSlice()->getDepthRefinementFlag( ) ? pcCU->getDvInfo(0).m_acDoNBDV : pcCU->getDvInfo(0).m_acNBDV; |
---|
826 | if( pcCU->getSlice()->getDepthRefinementFlag( ) ) |
---|
827 | { |
---|
828 | cDv.setVer(0); |
---|
829 | } |
---|
830 | Int iBlkX = ( pcCU->getAddr() % pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCU() ) * g_uiMaxCUWidth + g_auiRasterToPelX[ g_auiZscanToRaster[ pcCU->getZorderIdxInCU() ] ]+ ((cDv.getHor()+2)>>2); |
---|
831 | Int iBlkY = ( pcCU->getAddr() / pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ pcCU->getZorderIdxInCU() ] ]+ ((cDv.getVer()+2)>>2); |
---|
832 | if (iBlkX>(Int)(iPictureWidth - uiWidth)) |
---|
833 | { |
---|
834 | iSumDepth += pDepthPels[ iPictureWidth - iBlkX - 1 ]; |
---|
835 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ iPictureWidth - iBlkX - 1 ]); |
---|
836 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ iPictureWidth - iBlkX - 1 ]); |
---|
837 | } |
---|
838 | else |
---|
839 | { |
---|
840 | iSumDepth += pDepthPels[ uiWidth - 1 ]; |
---|
841 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiWidth - 1 ]); |
---|
842 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiWidth - 1 ]); |
---|
843 | } |
---|
844 | if (iBlkY>(Int)(iPictureHeight - uiHeight)) |
---|
845 | { |
---|
846 | iSumDepth += pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) ]; |
---|
847 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) ]); |
---|
848 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) ]); |
---|
849 | } |
---|
850 | else |
---|
851 | { |
---|
852 | iSumDepth += pDepthPels[ uiDepthStride * (uiHeight - 1) ]; |
---|
853 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) ]); |
---|
854 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) ]); |
---|
855 | } |
---|
856 | if (iBlkY>(Int)(iPictureHeight - uiHeight) && iBlkX>(Int)(iPictureWidth - uiWidth)) |
---|
857 | { |
---|
858 | iSumDepth += pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + iPictureWidth - iBlkX - 1 ]; |
---|
859 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + iPictureWidth - iBlkX - 1 ]); |
---|
860 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + iPictureWidth - iBlkX - 1 ]); |
---|
861 | } |
---|
862 | else if (iBlkY>(Int)(iPictureHeight - uiHeight)) |
---|
863 | { |
---|
864 | iSumDepth += pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + uiWidth - 1 ]; |
---|
865 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + uiWidth - 1 ]); |
---|
866 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + uiWidth - 1 ]); |
---|
867 | } |
---|
868 | else if (iBlkX>(Int)(iPictureWidth - uiWidth)) |
---|
869 | { |
---|
870 | iSumDepth += pDepthPels[ uiDepthStride * (uiHeight - 1) + iPictureWidth - iBlkX - 1 ]; |
---|
871 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + iPictureWidth - iBlkX - 1 ]); |
---|
872 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + iPictureWidth - iBlkX - 1 ]); |
---|
873 | } |
---|
874 | else |
---|
875 | { |
---|
876 | iSumDepth += pDepthPels[ uiDepthStride * (uiHeight - 1) + uiWidth - 1 ]; |
---|
877 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + uiWidth - 1 ]); |
---|
878 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + uiWidth - 1 ]); |
---|
879 | } |
---|
880 | |
---|
881 | // don't generate mask for blocks with small depth range (encoder decision) |
---|
882 | if( uiMaxDepth - uiMinDepth < 10 ) |
---|
883 | { |
---|
884 | return false; |
---|
885 | } |
---|
886 | |
---|
887 | AOF(uiWidth==uiHeight); |
---|
888 | Int iMean = iSumDepth >> 2; |
---|
889 | |
---|
890 | // start again for segmentation |
---|
891 | pDepthPels = pDepthBlockStart; |
---|
892 | |
---|
893 | Bool bInvertMask = pDepthPels[0]>iMean; // top-left segment needs to be mapped to partIdx 0 |
---|
894 | |
---|
895 | // generate mask |
---|
896 | UInt t=0; |
---|
897 | UInt uiSumPix[2] = {0,0}; |
---|
898 | for (Int y=0; y<uiHeight; y++) |
---|
899 | { |
---|
900 | for (Int x=0; x<uiHeight; x++) |
---|
901 | { |
---|
902 | Int depthPel = 0; |
---|
903 | if (iBlkX+x>iPictureWidth) |
---|
904 | { |
---|
905 | depthPel = pDepthPels[t]; |
---|
906 | } |
---|
907 | else |
---|
908 | { |
---|
909 | depthPel = pDepthPels[x]; |
---|
910 | t=x; |
---|
911 | } |
---|
912 | |
---|
913 | // decide which segment this pixel belongs to |
---|
914 | Int ucSegment = (Int)(depthPel>iMean); |
---|
915 | |
---|
916 | if( bInvertMask ) |
---|
917 | { |
---|
918 | ucSegment = 1-ucSegment; |
---|
919 | } |
---|
920 | |
---|
921 | // count pixels for each segment |
---|
922 | uiSumPix[ucSegment]++; |
---|
923 | |
---|
924 | // set mask value |
---|
925 | pMask[x] = (Bool)ucSegment; |
---|
926 | } |
---|
927 | |
---|
928 | // next row |
---|
929 | if (!(iBlkY+y+1>iPictureHeight)) |
---|
930 | pDepthPels += uiDepthStride; |
---|
931 | pMask += MAX_CU_SIZE; |
---|
932 | } |
---|
933 | |
---|
934 | // don't generate valid mask for tiny segments (encoder decision) |
---|
935 | // each segment needs to cover at least 1/8th of block |
---|
936 | UInt uiMinPixPerSegment = (uiWidth*uiHeight) >> 3; |
---|
937 | if( !( uiSumPix[0] > uiMinPixPerSegment && uiSumPix[1] > uiMinPixPerSegment ) ) |
---|
938 | { |
---|
939 | return false; |
---|
940 | } |
---|
941 | |
---|
942 | // all good |
---|
943 | return true; |
---|
944 | } |
---|
945 | |
---|
946 | Void TComPrediction::combineSegmentsWithMask( TComYuv* pInYuv[2], TComYuv* pOutYuv, Bool* pMask, UInt uiWidth, UInt uiHeight, UInt uiPartAddr, UInt partSize ) |
---|
947 | { |
---|
948 | Pel* piSrc[2] = {pInYuv[0]->getLumaAddr(uiPartAddr), pInYuv[1]->getLumaAddr(uiPartAddr)}; |
---|
949 | UInt uiSrcStride = pInYuv[0]->getStride(); |
---|
950 | Pel* piDst = pOutYuv->getLumaAddr(uiPartAddr); |
---|
951 | UInt uiDstStride = pOutYuv->getStride(); |
---|
952 | |
---|
953 | UInt uiMaskStride= MAX_CU_SIZE; |
---|
954 | Pel* tmpTar = 0; |
---|
955 | tmpTar = (Pel *)xMalloc(Pel, uiWidth*uiHeight); |
---|
956 | |
---|
957 | // backup pointer |
---|
958 | Bool* pMaskStart = pMask; |
---|
959 | |
---|
960 | // combine luma first |
---|
961 | for (Int y=0; y<uiHeight; y++) |
---|
962 | { |
---|
963 | for (Int x=0; x<uiWidth; x++) |
---|
964 | { |
---|
965 | UChar ucSegment = (UChar)pMask[x]; |
---|
966 | AOF( ucSegment < 2 ); |
---|
967 | |
---|
968 | // filtering |
---|
969 | tmpTar[y*uiWidth+x] = piSrc[ucSegment][x]; |
---|
970 | } |
---|
971 | |
---|
972 | piSrc[0] += uiSrcStride; |
---|
973 | piSrc[1] += uiSrcStride; |
---|
974 | pMask += uiMaskStride; |
---|
975 | } |
---|
976 | |
---|
977 | if (partSize == SIZE_Nx2N) |
---|
978 | { |
---|
979 | for (Int y=0; y<uiHeight; y++) |
---|
980 | { |
---|
981 | for (Int x=0; x<uiWidth; x++) |
---|
982 | { |
---|
983 | Bool l = (x==0)?pMaskStart[y*uiMaskStride+x]:pMaskStart[y*uiMaskStride+x-1]; |
---|
984 | Bool r = (x==uiWidth-1)?pMaskStart[y*uiMaskStride+x]:pMaskStart[y*uiMaskStride+x+1]; |
---|
985 | |
---|
986 | Pel left, right; |
---|
987 | left = (x==0) ? tmpTar[y*uiWidth+x] : tmpTar[y*uiWidth+x-1]; |
---|
988 | right = (x==uiWidth-1) ? tmpTar[y*uiWidth+x] : tmpTar[y*uiWidth+x+1]; |
---|
989 | |
---|
990 | piDst[x] = (l!=r) ? ClipY( Pel(( left + (tmpTar[y*uiWidth+x] << 1) + right ) >> 2 )) : tmpTar[y*uiWidth+x]; |
---|
991 | } |
---|
992 | piDst += uiDstStride; |
---|
993 | } |
---|
994 | } |
---|
995 | else // SIZE_2NxN |
---|
996 | { |
---|
997 | for (Int y=0; y<uiHeight; y++) |
---|
998 | { |
---|
999 | for (Int x=0; x<uiWidth; x++) |
---|
1000 | { |
---|
1001 | Bool t = (y==0)?pMaskStart[y*uiMaskStride+x]:pMaskStart[(y-1)*uiMaskStride+x]; |
---|
1002 | Bool b = (y==uiHeight-1)?pMaskStart[y*uiMaskStride+x]:pMaskStart[(y+1)*uiMaskStride+x]; |
---|
1003 | |
---|
1004 | Pel top, bottom; |
---|
1005 | top = (y==0) ? tmpTar[y*uiWidth+x] : tmpTar[(y-1)*uiWidth+x]; |
---|
1006 | bottom = (y==uiHeight-1) ? tmpTar[y*uiWidth+x] : tmpTar[(y+1)*uiWidth+x]; |
---|
1007 | |
---|
1008 | piDst[x] = (t!=b) ? ClipY( Pel(( top + (tmpTar[y*uiWidth+x] << 1) + bottom ) >> 2 )) : tmpTar[y*uiWidth+x]; |
---|
1009 | } |
---|
1010 | piDst += uiDstStride; |
---|
1011 | } |
---|
1012 | } |
---|
1013 | |
---|
1014 | if ( tmpTar ) |
---|
1015 | { |
---|
1016 | xFree(tmpTar); |
---|
1017 | tmpTar = NULL; |
---|
1018 | } |
---|
1019 | |
---|
1020 | // now combine chroma |
---|
1021 | Pel* piSrcU[2] = { pInYuv[0]->getCbAddr(uiPartAddr), pInYuv[1]->getCbAddr(uiPartAddr) }; |
---|
1022 | Pel* piSrcV[2] = { pInYuv[0]->getCrAddr(uiPartAddr), pInYuv[1]->getCrAddr(uiPartAddr) }; |
---|
1023 | UInt uiSrcStrideC = pInYuv[0]->getCStride(); |
---|
1024 | Pel* piDstU = pOutYuv->getCbAddr(uiPartAddr); |
---|
1025 | Pel* piDstV = pOutYuv->getCrAddr(uiPartAddr); |
---|
1026 | UInt uiDstStrideC = pOutYuv->getCStride(); |
---|
1027 | UInt uiWidthC = uiWidth >> 1; |
---|
1028 | UInt uiHeightC = uiHeight >> 1; |
---|
1029 | Pel filSrcU = 0, filSrcV = 0; |
---|
1030 | Pel* tmpTarU = 0, *tmpTarV = 0; |
---|
1031 | tmpTarU = (Pel *)xMalloc(Pel, uiWidthC*uiHeightC); |
---|
1032 | tmpTarV = (Pel *)xMalloc(Pel, uiWidthC*uiHeightC); |
---|
1033 | pMask = pMaskStart; |
---|
1034 | |
---|
1035 | for (Int y=0; y<uiHeightC; y++) |
---|
1036 | { |
---|
1037 | for (Int x=0; x<uiWidthC; x++) |
---|
1038 | { |
---|
1039 | UChar ucSegment = (UChar)pMask[x*2]; |
---|
1040 | AOF( ucSegment < 2 ); |
---|
1041 | |
---|
1042 | // filtering |
---|
1043 | tmpTarU[y*uiWidthC+x] = piSrcU[ucSegment][x]; |
---|
1044 | tmpTarV[y*uiWidthC+x] = piSrcV[ucSegment][x]; |
---|
1045 | } |
---|
1046 | |
---|
1047 | piSrcU[0] += uiSrcStrideC; |
---|
1048 | piSrcU[1] += uiSrcStrideC; |
---|
1049 | piSrcV[0] += uiSrcStrideC; |
---|
1050 | piSrcV[1] += uiSrcStrideC; |
---|
1051 | pMask += 2*uiMaskStride; |
---|
1052 | } |
---|
1053 | |
---|
1054 | if (partSize == SIZE_Nx2N) |
---|
1055 | { |
---|
1056 | for (Int y=0; y<uiHeightC; y++) |
---|
1057 | { |
---|
1058 | for (Int x=0; x<uiWidthC; x++) |
---|
1059 | { |
---|
1060 | Bool l = (x==0)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[y*2*uiMaskStride+(x-1)*2]; |
---|
1061 | Bool r = (x==uiWidthC-1)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[y*2*uiMaskStride+(x+1)*2]; |
---|
1062 | |
---|
1063 | Pel leftU, rightU; |
---|
1064 | leftU = (x==0) ? tmpTarU[y*uiWidthC+x] : tmpTarU[y*uiWidthC+x-1]; |
---|
1065 | rightU = (x==uiWidthC-1) ? tmpTarU[y*uiWidthC+x] : tmpTarU[y*uiWidthC+x+1]; |
---|
1066 | Pel leftV, rightV; |
---|
1067 | leftV = (x==0) ? tmpTarV[y*uiWidthC+x] : tmpTarV[y*uiWidthC+x-1]; |
---|
1068 | rightV = (x==uiWidthC-1) ? tmpTarV[y*uiWidthC+x] : tmpTarV[y*uiWidthC+x+1]; |
---|
1069 | |
---|
1070 | if (l!=r) |
---|
1071 | { |
---|
1072 | filSrcU = ClipC( Pel(( leftU + (tmpTarU[y*uiWidthC+x] << 1) + rightU ) >> 2 )); |
---|
1073 | filSrcV = ClipC( Pel(( leftV + (tmpTarV[y*uiWidthC+x] << 1) + rightV ) >> 2 )); |
---|
1074 | } |
---|
1075 | else |
---|
1076 | { |
---|
1077 | filSrcU = tmpTarU[y*uiWidthC+x]; |
---|
1078 | filSrcV = tmpTarV[y*uiWidthC+x]; |
---|
1079 | } |
---|
1080 | piDstU[x] = filSrcU; |
---|
1081 | piDstV[x] = filSrcV; |
---|
1082 | } |
---|
1083 | piDstU += uiDstStrideC; |
---|
1084 | piDstV += uiDstStrideC; |
---|
1085 | } |
---|
1086 | } |
---|
1087 | else |
---|
1088 | { |
---|
1089 | for (Int y=0; y<uiHeightC; y++) |
---|
1090 | { |
---|
1091 | for (Int x=0; x<uiWidthC; x++) |
---|
1092 | { |
---|
1093 | Bool t = (y==0)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[(y-1)*2*uiMaskStride+x*2]; |
---|
1094 | Bool b = (y==uiHeightC-1)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[(y+1)*2*uiMaskStride+x*2]; |
---|
1095 | |
---|
1096 | Pel topU, bottomU; |
---|
1097 | topU = (y==0) ? tmpTarU[y*uiWidthC+x] : tmpTarU[(y-1)*uiWidthC+x]; |
---|
1098 | bottomU = (y==uiHeightC-1) ? tmpTarU[y*uiWidthC+x] : tmpTarU[(y+1)*uiWidthC+x]; |
---|
1099 | Pel topV, bottomV; |
---|
1100 | topV = (y==0) ? tmpTarV[y*uiWidthC+x] : tmpTarV[(y-1)*uiWidthC+x]; |
---|
1101 | bottomV = (y==uiHeightC-1) ? tmpTarV[y*uiWidthC+x] : tmpTarV[(y+1)*uiWidthC+x]; |
---|
1102 | |
---|
1103 | if (t!=b) |
---|
1104 | { |
---|
1105 | filSrcU = ClipC( Pel(( topU + (tmpTarU[y*uiWidthC+x] << 1) + bottomU ) >> 2 )); |
---|
1106 | filSrcV = ClipC( Pel(( topV + (tmpTarV[y*uiWidthC+x] << 1) + bottomV ) >> 2 )); |
---|
1107 | } |
---|
1108 | else |
---|
1109 | { |
---|
1110 | filSrcU = tmpTarU[y*uiWidthC+x]; |
---|
1111 | filSrcV = tmpTarV[y*uiWidthC+x]; |
---|
1112 | } |
---|
1113 | piDstU[x] = filSrcU; |
---|
1114 | piDstV[x] = filSrcV; |
---|
1115 | } |
---|
1116 | piDstU += uiDstStrideC; |
---|
1117 | piDstV += uiDstStrideC; |
---|
1118 | } |
---|
1119 | } |
---|
1120 | |
---|
1121 | if( tmpTarU ) |
---|
1122 | { |
---|
1123 | xFree(tmpTarU); |
---|
1124 | tmpTarU = NULL; |
---|
1125 | } |
---|
1126 | if ( tmpTarV ) |
---|
1127 | { |
---|
1128 | xFree(tmpTarV); |
---|
1129 | tmpTarV = NULL; |
---|
1130 | } |
---|
1131 | } |
---|
1132 | #endif |
---|
1133 | |
---|
1134 | Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx ) |
---|
1135 | { |
---|
1136 | Int iWidth; |
---|
1137 | Int iHeight; |
---|
1138 | UInt uiPartAddr; |
---|
1139 | |
---|
1140 | if ( iPartIdx >= 0 ) |
---|
1141 | { |
---|
1142 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
1143 | #if H_3D_VSP |
---|
1144 | if ( pcCU->getVSPFlag(uiPartAddr) == 0) |
---|
1145 | { |
---|
1146 | #endif |
---|
1147 | if ( eRefPicList != REF_PIC_LIST_X ) |
---|
1148 | { |
---|
1149 | if( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
1150 | { |
---|
1151 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true ); |
---|
1152 | } |
---|
1153 | else |
---|
1154 | { |
---|
1155 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
1156 | } |
---|
1157 | if ( pcCU->getSlice()->getPPS()->getUseWP() ) |
---|
1158 | { |
---|
1159 | xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
1160 | } |
---|
1161 | } |
---|
1162 | else |
---|
1163 | { |
---|
1164 | #if H_3D_SPIVMP |
---|
1165 | if ( pcCU->getSPIVMPFlag(uiPartAddr)!=0) |
---|
1166 | { |
---|
1167 | Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight; |
---|
1168 | |
---|
1169 | pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight); |
---|
1170 | |
---|
1171 | UInt uiW[256], uiH[256]; |
---|
1172 | UInt uiSPAddr[256]; |
---|
1173 | |
---|
1174 | xGetSubPUAddrAndMerge(pcCU, uiPartAddr, iSPWidth, iSPHeight, iNumSPInOneLine, iNumSP, uiW, uiH, uiSPAddr); |
---|
1175 | |
---|
1176 | //MC |
---|
1177 | for (Int i = 0; i < iNumSP; i++) |
---|
1178 | { |
---|
1179 | if (uiW[i]==0 || uiH[i]==0) |
---|
1180 | { |
---|
1181 | continue; |
---|
1182 | } |
---|
1183 | if( xCheckIdenticalMotion( pcCU, uiSPAddr[i] )) |
---|
1184 | { |
---|
1185 | xPredInterUni (pcCU, uiSPAddr[i], uiW[i], uiH[i], REF_PIC_LIST_0, pcYuvPred ); |
---|
1186 | } |
---|
1187 | else |
---|
1188 | { |
---|
1189 | xPredInterBi (pcCU, uiSPAddr[i], uiW[i], uiH[i], pcYuvPred); |
---|
1190 | } |
---|
1191 | } |
---|
1192 | } |
---|
1193 | else |
---|
1194 | { |
---|
1195 | #endif |
---|
1196 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
1197 | { |
---|
1198 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
1199 | } |
---|
1200 | else |
---|
1201 | { |
---|
1202 | xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
1203 | } |
---|
1204 | #if H_3D_SPIVMP |
---|
1205 | } |
---|
1206 | #endif |
---|
1207 | } |
---|
1208 | #if H_3D_VSP |
---|
1209 | } |
---|
1210 | else |
---|
1211 | { |
---|
1212 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
1213 | { |
---|
1214 | xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
1215 | } |
---|
1216 | else |
---|
1217 | { |
---|
1218 | xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
1219 | } |
---|
1220 | } |
---|
1221 | #endif |
---|
1222 | return; |
---|
1223 | } |
---|
1224 | |
---|
1225 | for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartitions(); iPartIdx++ ) |
---|
1226 | { |
---|
1227 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
1228 | |
---|
1229 | #if H_3D_VSP |
---|
1230 | if ( pcCU->getVSPFlag(uiPartAddr) == 0 ) |
---|
1231 | { |
---|
1232 | #endif |
---|
1233 | if ( eRefPicList != REF_PIC_LIST_X ) |
---|
1234 | { |
---|
1235 | if( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
1236 | { |
---|
1237 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true ); |
---|
1238 | } |
---|
1239 | else |
---|
1240 | { |
---|
1241 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
1242 | } |
---|
1243 | if ( pcCU->getSlice()->getPPS()->getUseWP() ) |
---|
1244 | { |
---|
1245 | xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
1246 | } |
---|
1247 | } |
---|
1248 | else |
---|
1249 | { |
---|
1250 | #if H_3D_SPIVMP |
---|
1251 | if (pcCU->getSPIVMPFlag(uiPartAddr)!=0) |
---|
1252 | { |
---|
1253 | Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight; |
---|
1254 | |
---|
1255 | pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight); |
---|
1256 | |
---|
1257 | UInt uiW[256], uiH[256]; |
---|
1258 | UInt uiSPAddr[256]; |
---|
1259 | |
---|
1260 | xGetSubPUAddrAndMerge(pcCU, uiPartAddr, iSPWidth, iSPHeight, iNumSPInOneLine, iNumSP, uiW, uiH, uiSPAddr); |
---|
1261 | //MC |
---|
1262 | for (Int i = 0; i < iNumSP; i++) |
---|
1263 | { |
---|
1264 | if (uiW[i]==0 || uiH[i]==0) |
---|
1265 | { |
---|
1266 | continue; |
---|
1267 | } |
---|
1268 | if( xCheckIdenticalMotion( pcCU, uiSPAddr[i] )) |
---|
1269 | { |
---|
1270 | xPredInterUni (pcCU, uiSPAddr[i], uiW[i], uiH[i], REF_PIC_LIST_0, pcYuvPred ); |
---|
1271 | } |
---|
1272 | else |
---|
1273 | { |
---|
1274 | xPredInterBi (pcCU, uiSPAddr[i], uiW[i], uiH[i], pcYuvPred); |
---|
1275 | } |
---|
1276 | } |
---|
1277 | } |
---|
1278 | else |
---|
1279 | { |
---|
1280 | #endif |
---|
1281 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
1282 | { |
---|
1283 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
1284 | } |
---|
1285 | else |
---|
1286 | { |
---|
1287 | xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
1288 | } |
---|
1289 | #if H_3D_SPIVMP |
---|
1290 | } |
---|
1291 | #endif |
---|
1292 | } |
---|
1293 | #if H_3D_VSP |
---|
1294 | } |
---|
1295 | else |
---|
1296 | { |
---|
1297 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
1298 | { |
---|
1299 | xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
1300 | } |
---|
1301 | else |
---|
1302 | { |
---|
1303 | xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
1304 | } |
---|
1305 | } |
---|
1306 | #endif |
---|
1307 | } |
---|
1308 | return; |
---|
1309 | } |
---|
1310 | |
---|
1311 | Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv* pcYuvPred, Bool bi ) |
---|
1312 | { |
---|
1313 | Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); assert (iRefIdx >= 0); |
---|
1314 | TComMv cMv = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); |
---|
1315 | pcCU->clipMv(cMv); |
---|
1316 | #if NH_MV |
---|
1317 | pcCU->checkMvVertRest(cMv, eRefPicList, iRefIdx ); |
---|
1318 | #endif |
---|
1319 | #if H_3D_ARP |
---|
1320 | if(pcCU->getARPW( uiPartAddr ) > 0 && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()== pcCU->getSlice()->getPOC()) |
---|
1321 | { |
---|
1322 | xPredInterUniARPviewRef( pcCU , uiPartAddr , iWidth , iHeight , eRefPicList , rpcYuvPred , bi ); |
---|
1323 | } |
---|
1324 | else |
---|
1325 | { |
---|
1326 | if( pcCU->getARPW( uiPartAddr ) > 0 |
---|
1327 | && pcCU->getPartitionSize(uiPartAddr)==SIZE_2Nx2N |
---|
1328 | && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()!= pcCU->getSlice()->getPOC() |
---|
1329 | ) |
---|
1330 | { |
---|
1331 | xPredInterUniARP( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, rpcYuvPred, bi ); |
---|
1332 | } |
---|
1333 | else |
---|
1334 | { |
---|
1335 | #endif |
---|
1336 | #if H_3D_IC |
---|
1337 | Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() ); |
---|
1338 | xPredInterLumaBlk ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi |
---|
1339 | #if H_3D_ARP |
---|
1340 | , false |
---|
1341 | #endif |
---|
1342 | , bICFlag ); |
---|
1343 | bICFlag = bICFlag && (iWidth > 8); |
---|
1344 | xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi |
---|
1345 | #if H_3D_ARP |
---|
1346 | , false |
---|
1347 | #endif |
---|
1348 | , bICFlag ); |
---|
1349 | #else |
---|
1350 | |
---|
1351 | for (UInt comp=COMPONENT_Y; comp<pcYuvPred->getNumberValidComponents(); comp++) |
---|
1352 | { |
---|
1353 | const ComponentID compID=ComponentID(comp); |
---|
1354 | xPredInterBlk (compID, pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, pcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)) ); |
---|
1355 | } |
---|
1356 | #endif |
---|
1357 | #if H_3D_ARP |
---|
1358 | } |
---|
1359 | } |
---|
1360 | #endif |
---|
1361 | } |
---|
1362 | |
---|
1363 | #if H_3D_VSP |
---|
1364 | Void TComPrediction::xPredInterUniVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi ) |
---|
1365 | { |
---|
1366 | Int vspSize = pcCU->getVSPFlag( uiPartAddr ) >> 1; |
---|
1367 | |
---|
1368 | Int widthSubPU, heightSubPU; |
---|
1369 | if (vspSize) |
---|
1370 | { |
---|
1371 | widthSubPU = 8; |
---|
1372 | heightSubPU = 4; |
---|
1373 | } |
---|
1374 | else |
---|
1375 | { |
---|
1376 | widthSubPU = 4; |
---|
1377 | heightSubPU = 8; |
---|
1378 | } |
---|
1379 | xPredInterUniSubPU( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, rpcYuvPred, bi, widthSubPU, heightSubPU ); |
---|
1380 | } |
---|
1381 | |
---|
1382 | Void TComPrediction::xPredInterUniSubPU( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, Int widthSubPU, Int heightSubPU ) |
---|
1383 | { |
---|
1384 | UInt numPartsInLine = pcCU->getPic()->getNumPartInWidth(); |
---|
1385 | UInt horiNumPartsInSubPU = widthSubPU >> 2; |
---|
1386 | UInt vertNumPartsInSubPU = (heightSubPU >> 2) * numPartsInLine; |
---|
1387 | |
---|
1388 | UInt partAddrRasterLine = g_auiZscanToRaster[ uiPartAddr ]; |
---|
1389 | |
---|
1390 | for( Int posY=0; posY<iHeight; posY+=heightSubPU, partAddrRasterLine+=vertNumPartsInSubPU ) |
---|
1391 | { |
---|
1392 | UInt partAddrRasterSubPU = partAddrRasterLine; |
---|
1393 | for( Int posX=0; posX<iWidth; posX+=widthSubPU, partAddrRasterSubPU+=horiNumPartsInSubPU ) |
---|
1394 | { |
---|
1395 | UInt partAddrSubPU = g_auiRasterToZscan[ partAddrRasterSubPU ]; |
---|
1396 | Int refIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( partAddrSubPU ); assert (refIdx >= 0); |
---|
1397 | TComMv cMv = pcCU->getCUMvField( eRefPicList )->getMv( partAddrSubPU ); |
---|
1398 | pcCU->clipMv(cMv); |
---|
1399 | |
---|
1400 | xPredInterLumaBlk ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi ); |
---|
1401 | xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi ); |
---|
1402 | |
---|
1403 | } |
---|
1404 | } |
---|
1405 | } |
---|
1406 | |
---|
1407 | #endif |
---|
1408 | |
---|
1409 | #if H_3D_ARP |
---|
1410 | Void TComPrediction::xPredInterUniARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled ) |
---|
1411 | { |
---|
1412 | Int iRefIdx = pNewMvFiled ? pNewMvFiled->getRefIdx() : pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
1413 | TComMv cMv = pNewMvFiled ? pNewMvFiled->getMv() : pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); |
---|
1414 | Bool bTobeScaled = false; |
---|
1415 | TComPic* pcPicYuvBaseCol = NULL; |
---|
1416 | TComPic* pcPicYuvBaseRef = NULL; |
---|
1417 | |
---|
1418 | #if H_3D_NBDV |
---|
1419 | DisInfo cDistparity; |
---|
1420 | cDistparity.m_acNBDV = pcCU->getDvInfo(0).m_acNBDV; |
---|
1421 | cDistparity.m_aVIdxCan = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan; |
---|
1422 | #else |
---|
1423 | assert(0); // ARP can be applied only when a DV is available |
---|
1424 | #endif |
---|
1425 | UChar dW = pcCU->getARPW ( uiPartAddr ); |
---|
1426 | |
---|
1427 | { |
---|
1428 | Int arpRefIdx = pcCU->getSlice()->getFirstTRefIdx(eRefPicList); |
---|
1429 | if( dW > 0 && pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC()!= pcCU->getSlice()->getPOC() ) |
---|
1430 | { |
---|
1431 | bTobeScaled = true; |
---|
1432 | } |
---|
1433 | |
---|
1434 | pcPicYuvBaseCol = pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getPOC(), cDistparity.m_aVIdxCan ); |
---|
1435 | |
---|
1436 | pcPicYuvBaseRef = pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC(), cDistparity.m_aVIdxCan ); |
---|
1437 | |
---|
1438 | if (!pcCU->getSlice()->getArpRefPicAvailable( eRefPicList, cDistparity.m_aVIdxCan)) |
---|
1439 | { |
---|
1440 | dW = 0; |
---|
1441 | bTobeScaled = false; |
---|
1442 | } |
---|
1443 | else |
---|
1444 | { |
---|
1445 | assert( pcPicYuvBaseCol->getPOC() == pcCU->getSlice()->getPOC() && pcPicYuvBaseRef->getPOC() == pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC() ); |
---|
1446 | } |
---|
1447 | |
---|
1448 | if(bTobeScaled) |
---|
1449 | { |
---|
1450 | Int iCurrPOC = pcCU->getSlice()->getPOC(); |
---|
1451 | Int iColRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList, iRefIdx ); |
---|
1452 | Int iCurrRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList, 0); |
---|
1453 | Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iCurrPOC, iColRefPOC); |
---|
1454 | if ( iScale != 4096 ) |
---|
1455 | { |
---|
1456 | cMv = cMv.scaleMv( iScale ); |
---|
1457 | } |
---|
1458 | iRefIdx = 0; |
---|
1459 | } |
---|
1460 | } |
---|
1461 | |
---|
1462 | pcCU->clipMv(cMv); |
---|
1463 | TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(); |
---|
1464 | xPredInterLumaBlk ( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 ), true ); |
---|
1465 | xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 ), true ); |
---|
1466 | |
---|
1467 | if( dW > 0 ) |
---|
1468 | { |
---|
1469 | TComYuv * pYuvB0 = &m_acYuvPredBase[0]; |
---|
1470 | TComYuv * pYuvB1 = &m_acYuvPredBase[1]; |
---|
1471 | |
---|
1472 | TComMv cMVwithDisparity = cMv + cDistparity.m_acNBDV; |
---|
1473 | pcCU->clipMv(cMVwithDisparity); |
---|
1474 | if (iWidth <= 8) |
---|
1475 | { |
---|
1476 | pYuvB0->clear(); pYuvB1->clear(); |
---|
1477 | } |
---|
1478 | TComMv cNBDV = cDistparity.m_acNBDV; |
---|
1479 | pcCU->clipMv( cNBDV ); |
---|
1480 | |
---|
1481 | pcPicYuvRef = pcPicYuvBaseCol->getPicYuvRec(); |
---|
1482 | xPredInterLumaBlk ( pcCU, pcPicYuvRef, uiPartAddr, &cNBDV, iWidth, iHeight, pYuvB0, true, true ); |
---|
1483 | if (iWidth > 8) |
---|
1484 | xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cNBDV, iWidth, iHeight, pYuvB0, true, true ); |
---|
1485 | |
---|
1486 | pcPicYuvRef = pcPicYuvBaseRef->getPicYuvRec(); |
---|
1487 | xPredInterLumaBlk ( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, true, true ); |
---|
1488 | |
---|
1489 | if (iWidth > 8) |
---|
1490 | xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, true, true ); |
---|
1491 | |
---|
1492 | pYuvB0->subtractARP( pYuvB0 , pYuvB1 , uiPartAddr , iWidth , iHeight ); |
---|
1493 | |
---|
1494 | if( 2 == dW ) |
---|
1495 | { |
---|
1496 | pYuvB0->multiplyARP( uiPartAddr , iWidth , iHeight , dW ); |
---|
1497 | } |
---|
1498 | rpcYuvPred->addARP( rpcYuvPred , pYuvB0 , uiPartAddr , iWidth , iHeight , !bi ); |
---|
1499 | } |
---|
1500 | } |
---|
1501 | |
---|
1502 | Bool TComPrediction::xCheckBiInterviewARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eBaseRefPicList, TComPic*& pcPicYuvCurrTRef, TComMv& cBaseTMV, Int& iCurrTRefPoc ) |
---|
1503 | { |
---|
1504 | Int iRefIdx = pcCU->getCUMvField( eBaseRefPicList )->getRefIdx( uiPartAddr ); |
---|
1505 | TComMv cDMv = pcCU->getCUMvField( eBaseRefPicList )->getMv( uiPartAddr ); |
---|
1506 | TComPic* pcPicYuvBaseCol = pcCU->getSlice()->getRefPic( eBaseRefPicList, iRefIdx ); |
---|
1507 | TComPicYuv* pcYuvBaseCol = pcPicYuvBaseCol->getPicYuvRec(); |
---|
1508 | Int uiLCUAddr,uiAbsPartAddr; |
---|
1509 | Int irefPUX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[uiPartAddr]] + iWidth/2 + ((cDMv.getHor() + 2)>>2); |
---|
1510 | Int irefPUY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[uiPartAddr]] + iHeight/2 + ((cDMv.getVer() + 2)>>2); |
---|
1511 | |
---|
1512 | irefPUX = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()-> getPicWidthInLumaSamples()-1, irefPUX); |
---|
1513 | irefPUY = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples()-1, irefPUY); |
---|
1514 | pcYuvBaseCol->getCUAddrAndPartIdx( irefPUX, irefPUY, uiLCUAddr, uiAbsPartAddr); |
---|
1515 | TComDataCU *pColCU = pcPicYuvBaseCol->getCU( uiLCUAddr ); |
---|
1516 | |
---|
1517 | TComPic* pcPicYuvBaseTRef = NULL; |
---|
1518 | pcPicYuvCurrTRef = NULL; |
---|
1519 | |
---|
1520 | //If there is available motion in base reference list, use it |
---|
1521 | if(!pColCU->isIntra(uiAbsPartAddr)) |
---|
1522 | { |
---|
1523 | for(Int iList = 0; iList < (pColCU->getSlice()->isInterB() ? 2: 1); iList ++) |
---|
1524 | { |
---|
1525 | RefPicList eRefPicListCurr = RefPicList(iList); |
---|
1526 | Int iRef = pColCU->getCUMvField(eRefPicListCurr)->getRefIdx(uiAbsPartAddr); |
---|
1527 | if( iRef != -1) |
---|
1528 | { |
---|
1529 | pcPicYuvBaseTRef = pColCU->getSlice()->getRefPic(eRefPicListCurr, iRef); |
---|
1530 | Int iCurrPOC = pColCU->getSlice()->getPOC(); |
---|
1531 | Int iCurrRefPOC = pcPicYuvBaseTRef->getPOC(); |
---|
1532 | Int iCurrRef = pcCU->getSlice()->getFirstTRefIdx(eRefPicListCurr); |
---|
1533 | |
---|
1534 | if( iCurrRef >= 0 && iCurrPOC != iCurrRefPOC) |
---|
1535 | { |
---|
1536 | pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic(eRefPicListCurr,iCurrRef); |
---|
1537 | Int iTargetPOC = pcPicYuvCurrTRef->getPOC(); |
---|
1538 | pcPicYuvBaseTRef = pcCU->getSlice()->getBaseViewRefPic(iTargetPOC, pcPicYuvBaseCol->getViewIndex() ); |
---|
1539 | if(pcPicYuvBaseTRef) |
---|
1540 | { |
---|
1541 | cBaseTMV = pColCU->getCUMvField(eRefPicListCurr)->getMv(uiAbsPartAddr); |
---|
1542 | Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iTargetPOC, iCurrPOC, iCurrRefPOC); |
---|
1543 | if ( iScale != 4096 ) |
---|
1544 | { |
---|
1545 | cBaseTMV = cBaseTMV.scaleMv( iScale ); |
---|
1546 | } |
---|
1547 | iCurrTRefPoc = iTargetPOC; |
---|
1548 | return true; |
---|
1549 | } |
---|
1550 | } |
---|
1551 | } |
---|
1552 | } |
---|
1553 | } |
---|
1554 | |
---|
1555 | //If there is no available motion in base reference list, use ( 0, 0 ) |
---|
1556 | if( pcCU->getSlice()->getFirstTRefIdx( eBaseRefPicList ) >= 0 ) |
---|
1557 | { |
---|
1558 | cBaseTMV.set( 0, 0 ); |
---|
1559 | pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic( eBaseRefPicList, pcCU->getSlice()->getFirstTRefIdx( eBaseRefPicList ) ); |
---|
1560 | iCurrTRefPoc = pcPicYuvCurrTRef->getPOC(); |
---|
1561 | return true; |
---|
1562 | } |
---|
1563 | |
---|
1564 | return false; |
---|
1565 | } |
---|
1566 | |
---|
1567 | Void TComPrediction::xPredInterUniARPviewRef( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled ) |
---|
1568 | { |
---|
1569 | Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
1570 | TComMv cDMv = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); |
---|
1571 | TComMv cTempDMv = cDMv; |
---|
1572 | UChar dW = pcCU->getARPW ( uiPartAddr ); |
---|
1573 | |
---|
1574 | TComPic* pcPicYuvBaseTRef = NULL; |
---|
1575 | TComPic* pcPicYuvCurrTRef = NULL; |
---|
1576 | TComPic* pcPicYuvBaseCol = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx ); |
---|
1577 | TComPicYuv* pcYuvBaseCol = pcPicYuvBaseCol->getPicYuvRec(); |
---|
1578 | Bool bTMVAvai = false; |
---|
1579 | TComMv cBaseTMV; |
---|
1580 | if( pNewMvFiled ) |
---|
1581 | { |
---|
1582 | iRefIdx = pNewMvFiled->getRefIdx(); |
---|
1583 | cDMv = pNewMvFiled->getMv(); |
---|
1584 | } |
---|
1585 | pcCU->clipMv(cTempDMv); |
---|
1586 | |
---|
1587 | assert(dW > 0); |
---|
1588 | if (!pcCU->getSlice()->getArpRefPicAvailable( eRefPicList, pcPicYuvBaseCol->getViewIndex())) |
---|
1589 | { |
---|
1590 | dW = 0; |
---|
1591 | } |
---|
1592 | Int uiLCUAddr,uiAbsPartAddr; |
---|
1593 | Int irefPUX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[uiPartAddr]] + iWidth/2 + ((cDMv.getHor() + 2)>>2); |
---|
1594 | Int irefPUY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[uiPartAddr]] + iHeight/2 + ((cDMv.getVer() + 2)>>2); |
---|
1595 | |
---|
1596 | irefPUX = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()-> getPicWidthInLumaSamples()-1, irefPUX); |
---|
1597 | irefPUY = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples()-1, irefPUY); |
---|
1598 | pcYuvBaseCol->getCUAddrAndPartIdx( irefPUX, irefPUY, uiLCUAddr, uiAbsPartAddr); |
---|
1599 | TComDataCU *pColCU = pcPicYuvBaseCol->getCU( uiLCUAddr ); |
---|
1600 | if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getIsDepth() ) |
---|
1601 | { |
---|
1602 | RefPicList eOtherRefList = ( eRefPicList == REF_PIC_LIST_0 ) ? REF_PIC_LIST_1 : REF_PIC_LIST_0; |
---|
1603 | Int iOtherRefIdx = pcCU->getCUMvField( eOtherRefList )->getRefIdx( uiPartAddr ); |
---|
1604 | //The other prediction direction is temporal ARP |
---|
1605 | if( iOtherRefIdx >= 0 && pcCU->getSlice()->getViewIndex() == pcCU->getSlice()->getRefPic( eOtherRefList, iOtherRefIdx )->getViewIndex() ) |
---|
1606 | { |
---|
1607 | bTMVAvai = true; |
---|
1608 | pcPicYuvBaseTRef = pcCU->getSlice()->getRefPic( eOtherRefList, iOtherRefIdx ); |
---|
1609 | Int iCurrPOC = pcCU->getSlice()->getPOC(); |
---|
1610 | Int iCurrRefPOC = pcPicYuvBaseTRef->getPOC(); |
---|
1611 | Int iCurrRef = pcCU->getSlice()->getFirstTRefIdx( eOtherRefList ); |
---|
1612 | |
---|
1613 | if( iCurrRef >= 0 ) |
---|
1614 | { |
---|
1615 | pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic( eOtherRefList,iCurrRef ); |
---|
1616 | Int iTargetPOC = pcPicYuvCurrTRef->getPOC(); |
---|
1617 | pcPicYuvBaseTRef = pcCU->getSlice()->getBaseViewRefPic( iTargetPOC, pcPicYuvBaseCol->getViewIndex() ); |
---|
1618 | if( pcPicYuvBaseTRef ) |
---|
1619 | { |
---|
1620 | cBaseTMV = pcCU->getCUMvField( eOtherRefList )->getMv( uiPartAddr ); |
---|
1621 | Int iScale = pcCU-> xGetDistScaleFactor( iCurrPOC, iTargetPOC, iCurrPOC, iCurrRefPOC ); |
---|
1622 | if ( iScale != 4096 ) |
---|
1623 | { |
---|
1624 | cBaseTMV = cBaseTMV.scaleMv( iScale ); |
---|
1625 | } |
---|
1626 | } |
---|
1627 | else |
---|
1628 | { |
---|
1629 | dW = 0; |
---|
1630 | } |
---|
1631 | } |
---|
1632 | else |
---|
1633 | { |
---|
1634 | dW = 0; |
---|
1635 | } |
---|
1636 | } |
---|
1637 | |
---|
1638 | //Both prediction directions are inter-view ARP |
---|
1639 | if ( iOtherRefIdx >= 0 && !bTMVAvai ) |
---|
1640 | { |
---|
1641 | RefPicList eBaseList = REF_PIC_LIST_0; |
---|
1642 | Int iCurrTRefPoc; |
---|
1643 | bTMVAvai = ( eBaseList != eRefPicList ) && ( pcCU->getSlice()->getViewIndex() != pcCU->getSlice()->getRefPic( eOtherRefList, iOtherRefIdx )->getViewIndex() ); |
---|
1644 | |
---|
1645 | if ( bTMVAvai ) |
---|
1646 | { |
---|
1647 | if( xCheckBiInterviewARP( pcCU, uiPartAddr, iWidth, iHeight, eBaseList, pcPicYuvCurrTRef, cBaseTMV, iCurrTRefPoc ) ) |
---|
1648 | { |
---|
1649 | pcPicYuvBaseTRef = pcCU->getSlice()->getBaseViewRefPic( iCurrTRefPoc, pcPicYuvBaseCol->getViewIndex() ); |
---|
1650 | if ( pcPicYuvBaseTRef == NULL ) |
---|
1651 | { |
---|
1652 | dW = 0; |
---|
1653 | } |
---|
1654 | } |
---|
1655 | else |
---|
1656 | { |
---|
1657 | dW = 0; |
---|
1658 | } |
---|
1659 | } |
---|
1660 | } |
---|
1661 | } |
---|
1662 | |
---|
1663 | if( !pColCU->isIntra( uiAbsPartAddr ) && !bTMVAvai ) |
---|
1664 | { |
---|
1665 | TComMvField puMVField; |
---|
1666 | for(Int iList = 0; iList < (pColCU->getSlice()->isInterB() ? 2: 1) && !bTMVAvai; iList ++) |
---|
1667 | { |
---|
1668 | RefPicList eRefPicListCurr = RefPicList(iList); |
---|
1669 | Int iRef = pColCU->getCUMvField(eRefPicListCurr)->getRefIdx(uiAbsPartAddr); |
---|
1670 | if( iRef != -1) |
---|
1671 | { |
---|
1672 | pcPicYuvBaseTRef = pColCU->getSlice()->getRefPic(eRefPicListCurr, iRef); |
---|
1673 | Int iCurrPOC = pColCU->getSlice()->getPOC(); |
---|
1674 | Int iCurrRefPOC = pcPicYuvBaseTRef->getPOC(); |
---|
1675 | Int iCurrRef = pcCU->getSlice()->getFirstTRefIdx(eRefPicListCurr); |
---|
1676 | if (iCurrRef >= 0 && iCurrRefPOC != iCurrPOC) |
---|
1677 | { |
---|
1678 | pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic(eRefPicListCurr,iCurrRef); |
---|
1679 | Int iTargetPOC = pcPicYuvCurrTRef->getPOC(); |
---|
1680 | { |
---|
1681 | pcPicYuvBaseTRef = pcCU->getSlice()->getBaseViewRefPic(iTargetPOC, pcPicYuvBaseCol->getViewIndex() ); |
---|
1682 | if(pcPicYuvBaseTRef) |
---|
1683 | { |
---|
1684 | cBaseTMV = pColCU->getCUMvField(eRefPicListCurr)->getMv(uiAbsPartAddr); |
---|
1685 | Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iTargetPOC, iCurrPOC, iCurrRefPOC); |
---|
1686 | if ( iScale != 4096 ) |
---|
1687 | cBaseTMV = cBaseTMV.scaleMv( iScale ); |
---|
1688 | bTMVAvai = true; |
---|
1689 | break; |
---|
1690 | } |
---|
1691 | } |
---|
1692 | } |
---|
1693 | } |
---|
1694 | } |
---|
1695 | } |
---|
1696 | if (bTMVAvai == false) |
---|
1697 | { |
---|
1698 | bTMVAvai = true; |
---|
1699 | cBaseTMV.set(0, 0); |
---|
1700 | pcPicYuvBaseTRef = pColCU->getSlice()->getRefPic(eRefPicList, pcCU->getSlice()->getFirstTRefIdx(eRefPicList)); |
---|
1701 | pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic (eRefPicList, pcCU->getSlice()->getFirstTRefIdx(eRefPicList)); |
---|
1702 | } |
---|
1703 | |
---|
1704 | xPredInterLumaBlk ( pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 && bTMVAvai ), bTMVAvai); |
---|
1705 | xPredInterChromaBlk( pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 && bTMVAvai ), bTMVAvai); |
---|
1706 | |
---|
1707 | if( dW > 0 && bTMVAvai ) |
---|
1708 | { |
---|
1709 | TComYuv* pYuvCurrTRef = &m_acYuvPredBase[0]; |
---|
1710 | TComYuv* pYuvBaseTRef = &m_acYuvPredBase[1]; |
---|
1711 | TComPicYuv* pcYuvCurrTref = pcPicYuvCurrTRef->getPicYuvRec(); |
---|
1712 | TComPicYuv* pcYuvBaseTref = pcPicYuvBaseTRef->getPicYuvRec(); |
---|
1713 | TComMv cTempMv = cDMv + cBaseTMV; |
---|
1714 | |
---|
1715 | pcCU->clipMv(cBaseTMV); |
---|
1716 | pcCU->clipMv(cTempMv); |
---|
1717 | |
---|
1718 | if (iWidth <= 8) |
---|
1719 | { |
---|
1720 | pYuvCurrTRef->clear(); pYuvBaseTRef->clear(); |
---|
1721 | } |
---|
1722 | xPredInterLumaBlk ( pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, true, true); |
---|
1723 | |
---|
1724 | if (iWidth > 8) |
---|
1725 | xPredInterChromaBlk( pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, true, true); |
---|
1726 | |
---|
1727 | xPredInterLumaBlk ( pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv, iWidth, iHeight, pYuvBaseTRef, true, true); |
---|
1728 | |
---|
1729 | if (iWidth > 8) |
---|
1730 | xPredInterChromaBlk( pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv, iWidth, iHeight, pYuvBaseTRef, true, true); |
---|
1731 | |
---|
1732 | pYuvCurrTRef->subtractARP( pYuvCurrTRef , pYuvBaseTRef , uiPartAddr , iWidth , iHeight ); |
---|
1733 | if(dW == 2) |
---|
1734 | { |
---|
1735 | pYuvCurrTRef->multiplyARP( uiPartAddr , iWidth , iHeight , dW ); |
---|
1736 | } |
---|
1737 | rpcYuvPred->addARP( rpcYuvPred , pYuvCurrTRef , uiPartAddr , iWidth , iHeight , !bi ); |
---|
1738 | } |
---|
1739 | } |
---|
1740 | #endif |
---|
1741 | |
---|
1742 | Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv* pcYuvPred ) |
---|
1743 | { |
---|
1744 | TComYuv* pcMbYuv; |
---|
1745 | Int iRefIdx[NUM_REF_PIC_LIST_01] = {-1, -1}; |
---|
1746 | |
---|
1747 | for ( UInt refList = 0; refList < NUM_REF_PIC_LIST_01; refList++ ) |
---|
1748 | { |
---|
1749 | RefPicList eRefPicList = (refList ? REF_PIC_LIST_1 : REF_PIC_LIST_0); |
---|
1750 | iRefIdx[refList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
1751 | |
---|
1752 | if ( iRefIdx[refList] < 0 ) |
---|
1753 | { |
---|
1754 | continue; |
---|
1755 | } |
---|
1756 | |
---|
1757 | assert( iRefIdx[refList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) ); |
---|
1758 | |
---|
1759 | pcMbYuv = &m_acYuvPred[refList]; |
---|
1760 | if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 ) |
---|
1761 | { |
---|
1762 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true ); |
---|
1763 | } |
---|
1764 | else |
---|
1765 | { |
---|
1766 | if ( ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE ) || |
---|
1767 | ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) ) |
---|
1768 | { |
---|
1769 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true ); |
---|
1770 | } |
---|
1771 | else |
---|
1772 | { |
---|
1773 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv ); |
---|
1774 | } |
---|
1775 | } |
---|
1776 | } |
---|
1777 | |
---|
1778 | if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) |
---|
1779 | { |
---|
1780 | xWeightedPredictionBi( pcCU, &m_acYuvPred[REF_PIC_LIST_0], &m_acYuvPred[REF_PIC_LIST_1], iRefIdx[REF_PIC_LIST_0], iRefIdx[REF_PIC_LIST_1], uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
1781 | } |
---|
1782 | else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE ) |
---|
1783 | { |
---|
1784 | xWeightedPredictionUni( pcCU, &m_acYuvPred[REF_PIC_LIST_0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
1785 | } |
---|
1786 | else |
---|
1787 | { |
---|
1788 | xWeightedAverage( &m_acYuvPred[REF_PIC_LIST_0], &m_acYuvPred[REF_PIC_LIST_1], iRefIdx[REF_PIC_LIST_0], iRefIdx[REF_PIC_LIST_1], uiPartAddr, iWidth, iHeight, pcYuvPred, pcCU->getSlice()->getSPS()->getBitDepths() ); |
---|
1789 | } |
---|
1790 | } |
---|
1791 | |
---|
1792 | #if H_3D_VSP |
---|
1793 | |
---|
1794 | Void TComPrediction::xPredInterBiVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred ) |
---|
1795 | { |
---|
1796 | TComYuv* pcMbYuv; |
---|
1797 | Int iRefIdx[2] = {-1, -1}; |
---|
1798 | Bool bi = (pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0); |
---|
1799 | |
---|
1800 | for ( Int iRefList = 0; iRefList < 2; iRefList++ ) |
---|
1801 | { |
---|
1802 | RefPicList eRefPicList = RefPicList(iRefList); |
---|
1803 | iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
1804 | |
---|
1805 | if ( iRefIdx[iRefList] < 0 ) |
---|
1806 | { |
---|
1807 | continue; |
---|
1808 | } |
---|
1809 | assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) ); |
---|
1810 | |
---|
1811 | pcMbYuv = &m_acYuvPred[iRefList]; |
---|
1812 | xPredInterUniVSP ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, bi ); |
---|
1813 | } |
---|
1814 | |
---|
1815 | xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred ); |
---|
1816 | } |
---|
1817 | |
---|
1818 | #endif |
---|
1819 | |
---|
1820 | /** |
---|
1821 | * \brief Generate motion-compensated block |
---|
1822 | * |
---|
1823 | * \param compID Colour component ID |
---|
1824 | * \param cu Pointer to current CU |
---|
1825 | * \param refPic Pointer to reference picture |
---|
1826 | * \param partAddr Address of block within CU |
---|
1827 | * \param mv Motion vector |
---|
1828 | * \param width Width of block |
---|
1829 | * \param height Height of block |
---|
1830 | * \param dstPic Pointer to destination picture |
---|
1831 | * \param bi Flag indicating whether bipred is used |
---|
1832 | * \param bitDepth Bit depth |
---|
1833 | */ |
---|
1834 | |
---|
1835 | |
---|
1836 | Void TComPrediction::xPredInterBlk(const ComponentID compID, TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *dstPic, Bool bi, const Int bitDepth |
---|
1837 | #if H_3D_ARP |
---|
1838 | , Bool filterType |
---|
1839 | #endif |
---|
1840 | #if H_3D_IC |
---|
1841 | , Bool bICFlag |
---|
1842 | #endif |
---|
1843 | ) |
---|
1844 | { |
---|
1845 | Int refStride = refPic->getStride(compID); |
---|
1846 | Int dstStride = dstPic->getStride(compID); |
---|
1847 | Int shiftHor=(2+refPic->getComponentScaleX(compID)); |
---|
1848 | Int shiftVer=(2+refPic->getComponentScaleY(compID)); |
---|
1849 | |
---|
1850 | Int refOffset = (mv->getHor() >> shiftHor) + (mv->getVer() >> shiftVer) * refStride; |
---|
1851 | |
---|
1852 | Pel* ref = refPic->getAddr(compID, cu->getCtuRsAddr(), cu->getZorderIdxInCtu() + partAddr ) + refOffset; |
---|
1853 | |
---|
1854 | Pel* dst = dstPic->getAddr( compID, partAddr ); |
---|
1855 | |
---|
1856 | Int xFrac = mv->getHor() & ((1<<shiftHor)-1); |
---|
1857 | Int yFrac = mv->getVer() & ((1<<shiftVer)-1); |
---|
1858 | |
---|
1859 | #if H_3D_IC |
---|
1860 | if( cu->getSlice()->getIsDepth() ) |
---|
1861 | { |
---|
1862 | refOffset = mv->getHor() + mv->getVer() * refStride; |
---|
1863 | ref = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
1864 | xFrac = 0; |
---|
1865 | yFrac = 0; |
---|
1866 | } |
---|
1867 | #endif |
---|
1868 | |
---|
1869 | UInt cxWidth = width >> refPic->getComponentScaleX(compID); |
---|
1870 | UInt cxHeight = height >> refPic->getComponentScaleY(compID); |
---|
1871 | |
---|
1872 | const ChromaFormat chFmt = cu->getPic()->getChromaFormat(); |
---|
1873 | |
---|
1874 | if ( yFrac == 0 ) |
---|
1875 | { |
---|
1876 | #if H_3D_IC |
---|
1877 | m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac, !bi || bICFlag |
---|
1878 | #else |
---|
1879 | m_if.filterHor(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, xFrac, !bi, chFmt, bitDepth |
---|
1880 | #endif |
---|
1881 | #if H_3D_ARP |
---|
1882 | , filterType |
---|
1883 | #endif |
---|
1884 | ); |
---|
1885 | } |
---|
1886 | else if ( xFrac == 0 ) |
---|
1887 | { |
---|
1888 | #if H_3D_IC |
---|
1889 | m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi || bICFlag |
---|
1890 | #else |
---|
1891 | m_if.filterVer(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, yFrac, true, !bi, chFmt, bitDepth |
---|
1892 | #endif |
---|
1893 | #if H_3D_ARP |
---|
1894 | , filterType |
---|
1895 | #endif |
---|
1896 | ); |
---|
1897 | } |
---|
1898 | else |
---|
1899 | { |
---|
1900 | Int tmpStride = m_filteredBlockTmp[0].getStride(compID); |
---|
1901 | Pel* tmp = m_filteredBlockTmp[0].getAddr(compID); |
---|
1902 | |
---|
1903 | const Int vFilterSize = isLuma(compID) ? NTAPS_LUMA : NTAPS_CHROMA; |
---|
1904 | |
---|
1905 | m_if.filterHor(compID, ref - ((vFilterSize>>1) -1)*refStride, refStride, tmp, tmpStride, cxWidth, cxHeight+vFilterSize-1, xFrac, false, chFmt, bitDepth |
---|
1906 | #if H_3D_ARP |
---|
1907 | , filterType |
---|
1908 | #endif |
---|
1909 | ); |
---|
1910 | #if H_3D_IC |
---|
1911 | m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height, yFrac, false, !bi || bICFlag |
---|
1912 | #else |
---|
1913 | m_if.filterVer(compID, tmp + ((vFilterSize>>1) -1)*tmpStride, tmpStride, dst, dstStride, cxWidth, cxHeight, yFrac, false, !bi, chFmt, bitDepth |
---|
1914 | #endif |
---|
1915 | #if H_3D_ARP |
---|
1916 | , filterType |
---|
1917 | #endif |
---|
1918 | ); |
---|
1919 | } |
---|
1920 | |
---|
1921 | #if H_3D_IC |
---|
1922 | if( bICFlag ) |
---|
1923 | { |
---|
1924 | Int a, b, i, j; |
---|
1925 | const Int iShift = IC_CONST_SHIFT; |
---|
1926 | |
---|
1927 | xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_LUMA ); |
---|
1928 | |
---|
1929 | |
---|
1930 | for ( i = 0; i < height; i++ ) |
---|
1931 | { |
---|
1932 | for ( j = 0; j < width; j++ ) |
---|
1933 | { |
---|
1934 | dst[j] = Clip3( 0, ( 1 << g_bitDepthY ) - 1, ( ( a*dst[j] ) >> iShift ) + b ); |
---|
1935 | } |
---|
1936 | dst += dstStride; |
---|
1937 | } |
---|
1938 | |
---|
1939 | if(bi) |
---|
1940 | { |
---|
1941 | Pel *dst2 = dstPic->getLumaAddr( partAddr ); |
---|
1942 | Int shift = IF_INTERNAL_PREC - g_bitDepthY; |
---|
1943 | for (i = 0; i < height; i++) |
---|
1944 | { |
---|
1945 | for (j = 0; j < width; j++) |
---|
1946 | { |
---|
1947 | Short val = dst2[j] << shift; |
---|
1948 | dst2[j] = val - (Short)IF_INTERNAL_OFFS; |
---|
1949 | } |
---|
1950 | dst2 += dstStride; |
---|
1951 | } |
---|
1952 | } |
---|
1953 | } |
---|
1954 | #endif |
---|
1955 | |
---|
1956 | } |
---|
1957 | |
---|
1958 | |
---|
1959 | #if H_3D_ARP |
---|
1960 | , Bool filterType |
---|
1961 | #endif |
---|
1962 | #if H_3D_IC |
---|
1963 | , Bool bICFlag |
---|
1964 | #endif |
---|
1965 | #if H_3D_IC |
---|
1966 | m_if.filterHorChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag |
---|
1967 | #else |
---|
1968 | #endif |
---|
1969 | #if H_3D_ARP |
---|
1970 | , filterType |
---|
1971 | #endif |
---|
1972 | #if H_3D_IC |
---|
1973 | m_if.filterHorChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag |
---|
1974 | #else |
---|
1975 | #endif |
---|
1976 | #if H_3D_ARP |
---|
1977 | , filterType |
---|
1978 | #endif |
---|
1979 | #if H_3D_IC |
---|
1980 | m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag |
---|
1981 | #else |
---|
1982 | #endif |
---|
1983 | #if H_3D_ARP |
---|
1984 | , filterType |
---|
1985 | #endif |
---|
1986 | #if H_3D_IC |
---|
1987 | m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag |
---|
1988 | #else |
---|
1989 | #endif |
---|
1990 | #if H_3D_ARP |
---|
1991 | , filterType |
---|
1992 | #endif |
---|
1993 | #if H_3D_ARP |
---|
1994 | , filterType |
---|
1995 | #endif |
---|
1996 | #if H_3D_IC |
---|
1997 | m_if.filterVerChroma(extY + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight , yFrac, false, !bi || bICFlag |
---|
1998 | #else |
---|
1999 | #endif |
---|
2000 | #if H_3D_ARP |
---|
2001 | , filterType |
---|
2002 | #endif |
---|
2003 | #if H_3D_ARP |
---|
2004 | , filterType |
---|
2005 | #endif |
---|
2006 | #if H_3D_IC |
---|
2007 | m_if.filterVerChroma(extY + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight , yFrac, false, !bi || bICFlag |
---|
2008 | #else |
---|
2009 | #endif |
---|
2010 | #if H_3D_ARP |
---|
2011 | , filterType |
---|
2012 | #endif |
---|
2013 | #if H_3D_IC |
---|
2014 | if( bICFlag ) |
---|
2015 | { |
---|
2016 | Int a, b, i, j; |
---|
2017 | const Int iShift = IC_CONST_SHIFT; |
---|
2018 | |
---|
2019 | xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_U ); // Cb |
---|
2020 | for ( i = 0; i < cxHeight; i++ ) |
---|
2021 | { |
---|
2022 | for ( j = 0; j < cxWidth; j++ ) |
---|
2023 | { |
---|
2024 | dstCb[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCb[j] ) >> iShift ) + b ); |
---|
2025 | } |
---|
2026 | dstCb += dstStride; |
---|
2027 | } |
---|
2028 | xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_V ); // Cr |
---|
2029 | for ( i = 0; i < cxHeight; i++ ) |
---|
2030 | { |
---|
2031 | for ( j = 0; j < cxWidth; j++ ) |
---|
2032 | { |
---|
2033 | dstCr[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCr[j] ) >> iShift ) + b ); |
---|
2034 | } |
---|
2035 | dstCr += dstStride; |
---|
2036 | } |
---|
2037 | |
---|
2038 | if(bi) |
---|
2039 | { |
---|
2040 | Pel* dstCb2 = dstPic->getCbAddr( partAddr ); |
---|
2041 | Pel* dstCr2 = dstPic->getCrAddr( partAddr ); |
---|
2042 | Int shift = IF_INTERNAL_PREC - g_bitDepthC; |
---|
2043 | for (i = 0; i < cxHeight; i++) |
---|
2044 | { |
---|
2045 | for (j = 0; j < cxWidth; j++) |
---|
2046 | { |
---|
2047 | Short val = dstCb2[j] << shift; |
---|
2048 | dstCb2[j] = val - (Short)IF_INTERNAL_OFFS; |
---|
2049 | |
---|
2050 | val = dstCr2[j] << shift; |
---|
2051 | dstCr2[j] = val - (Short)IF_INTERNAL_OFFS; |
---|
2052 | } |
---|
2053 | dstCb2 += dstStride; |
---|
2054 | dstCr2 += dstStride; |
---|
2055 | } |
---|
2056 | } |
---|
2057 | } |
---|
2058 | #endif |
---|
2059 | Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv* pcYuvDst, const BitDepths &clipBitDepths |
---|
2060 | ) |
---|
2061 | { |
---|
2062 | if( iRefIdx0 >= 0 && iRefIdx1 >= 0 ) |
---|
2063 | { |
---|
2064 | pcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight, clipBitDepths ); |
---|
2065 | } |
---|
2066 | else if ( iRefIdx0 >= 0 && iRefIdx1 < 0 ) |
---|
2067 | { |
---|
2068 | pcYuvSrc0->copyPartToPartYuv( pcYuvDst, uiPartIdx, iWidth, iHeight ); |
---|
2069 | } |
---|
2070 | else if ( iRefIdx0 < 0 && iRefIdx1 >= 0 ) |
---|
2071 | { |
---|
2072 | pcYuvSrc1->copyPartToPartYuv( pcYuvDst, uiPartIdx, iWidth, iHeight ); |
---|
2073 | } |
---|
2074 | } |
---|
2075 | |
---|
2076 | // AMVP |
---|
2077 | Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred ) |
---|
2078 | { |
---|
2079 | AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo(); |
---|
2080 | |
---|
2081 | if( pcAMVPInfo->iN <= 1 ) |
---|
2082 | { |
---|
2083 | rcMvPred = pcAMVPInfo->m_acMvCand[0]; |
---|
2084 | |
---|
2085 | pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
2086 | pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
2087 | return; |
---|
2088 | } |
---|
2089 | |
---|
2090 | assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0); |
---|
2091 | rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)]; |
---|
2092 | return; |
---|
2093 | } |
---|
2094 | |
---|
2095 | /** Function for deriving planar intra prediction. |
---|
2096 | * \param pSrc pointer to reconstructed sample array |
---|
2097 | * \param srcStride the stride of the reconstructed sample array |
---|
2098 | * \param rpDst reference to pointer for the prediction sample array |
---|
2099 | * \param dstStride the stride of the prediction sample array |
---|
2100 | * \param width the width of the block |
---|
2101 | * \param height the height of the block |
---|
2102 | * \param channelType type of pel array (luma, chroma) |
---|
2103 | * \param format chroma format |
---|
2104 | * |
---|
2105 | * This function derives the prediction samples for planar mode (intra coding). |
---|
2106 | */ |
---|
2107 | //NOTE: Bit-Limit - 24-bit source |
---|
2108 | Void TComPrediction::xPredIntraPlanar( const Pel* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height ) |
---|
2109 | { |
---|
2110 | assert(width <= height); |
---|
2111 | |
---|
2112 | Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE]; |
---|
2113 | UInt shift1Dhor = g_aucConvertToBit[ width ] + 2; |
---|
2114 | UInt shift1Dver = g_aucConvertToBit[ height ] + 2; |
---|
2115 | |
---|
2116 | // Get left and above reference column and row |
---|
2117 | for(Int k=0;k<width+1;k++) |
---|
2118 | { |
---|
2119 | topRow[k] = pSrc[k-srcStride]; |
---|
2120 | } |
---|
2121 | |
---|
2122 | for (Int k=0; k < height+1; k++) |
---|
2123 | { |
---|
2124 | leftColumn[k] = pSrc[k*srcStride-1]; |
---|
2125 | } |
---|
2126 | |
---|
2127 | // Prepare intermediate variables used in interpolation |
---|
2128 | Int bottomLeft = leftColumn[height]; |
---|
2129 | Int topRight = topRow[width]; |
---|
2130 | |
---|
2131 | for(Int k=0;k<width;k++) |
---|
2132 | { |
---|
2133 | bottomRow[k] = bottomLeft - topRow[k]; |
---|
2134 | topRow[k] <<= shift1Dver; |
---|
2135 | } |
---|
2136 | |
---|
2137 | for(Int k=0;k<height;k++) |
---|
2138 | { |
---|
2139 | rightColumn[k] = topRight - leftColumn[k]; |
---|
2140 | leftColumn[k] <<= shift1Dhor; |
---|
2141 | } |
---|
2142 | |
---|
2143 | const UInt topRowShift = 0; |
---|
2144 | |
---|
2145 | // Generate prediction signal |
---|
2146 | for (Int y=0;y<height;y++) |
---|
2147 | { |
---|
2148 | Int horPred = leftColumn[y] + width; |
---|
2149 | for (Int x=0;x<width;x++) |
---|
2150 | { |
---|
2151 | horPred += rightColumn[y]; |
---|
2152 | topRow[x] += bottomRow[x]; |
---|
2153 | |
---|
2154 | Int vertPred = ((topRow[x] + topRowShift)>>topRowShift); |
---|
2155 | rpDst[y*dstStride+x] = ( horPred + vertPred ) >> (shift1Dhor+1); |
---|
2156 | } |
---|
2157 | } |
---|
2158 | } |
---|
2159 | |
---|
2160 | /** Function for filtering intra DC predictor. |
---|
2161 | * \param pSrc pointer to reconstructed sample array |
---|
2162 | * \param iSrcStride the stride of the reconstructed sample array |
---|
2163 | * \param pDst reference to pointer for the prediction sample array |
---|
2164 | * \param iDstStride the stride of the prediction sample array |
---|
2165 | * \param iWidth the width of the block |
---|
2166 | * \param iHeight the height of the block |
---|
2167 | * \param channelType type of pel array (luma, chroma) |
---|
2168 | * |
---|
2169 | * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding). |
---|
2170 | */ |
---|
2171 | Void TComPrediction::xDCPredFiltering( const Pel* pSrc, Int iSrcStride, Pel* pDst, Int iDstStride, Int iWidth, Int iHeight, ChannelType channelType ) |
---|
2172 | { |
---|
2173 | Int x, y, iDstStride2, iSrcStride2; |
---|
2174 | |
---|
2175 | if (isLuma(channelType) && (iWidth <= MAXIMUM_INTRA_FILTERED_WIDTH) && (iHeight <= MAXIMUM_INTRA_FILTERED_HEIGHT)) |
---|
2176 | { |
---|
2177 | //top-left |
---|
2178 | pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2); |
---|
2179 | |
---|
2180 | //top row (vertical filter) |
---|
2181 | for ( x = 1; x < iWidth; x++ ) |
---|
2182 | { |
---|
2183 | pDst[x] = (Pel)((pSrc[x - iSrcStride] + 3 * pDst[x] + 2) >> 2); |
---|
2184 | } |
---|
2185 | |
---|
2186 | //left column (horizontal filter) |
---|
2187 | for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride ) |
---|
2188 | { |
---|
2189 | pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2); |
---|
2190 | } |
---|
2191 | } |
---|
2192 | |
---|
2193 | return; |
---|
2194 | } |
---|
2195 | |
---|
2196 | /* Static member function */ |
---|
2197 | Bool TComPrediction::UseDPCMForFirstPassIntraEstimation(TComTU &rTu, const UInt uiDirMode) |
---|
2198 | { |
---|
2199 | return (rTu.getCU()->isRDPCMEnabled(rTu.GetAbsPartIdxTU()) ) && |
---|
2200 | rTu.getCU()->getCUTransquantBypass(rTu.GetAbsPartIdxTU()) && |
---|
2201 | (uiDirMode==HOR_IDX || uiDirMode==VER_IDX); |
---|
2202 | } |
---|
2203 | #if H_3D_IC |
---|
2204 | /** Function for deriving the position of first non-zero binary bit of a value |
---|
2205 | * \param x input value |
---|
2206 | * |
---|
2207 | * This function derives the position of first non-zero binary bit of a value |
---|
2208 | */ |
---|
2209 | Int GetMSB( UInt x ) |
---|
2210 | { |
---|
2211 | Int iMSB = 0, bits = ( sizeof( Int ) << 3 ), y = 1; |
---|
2212 | |
---|
2213 | while( x > 1 ) |
---|
2214 | { |
---|
2215 | bits >>= 1; |
---|
2216 | y = x >> bits; |
---|
2217 | |
---|
2218 | if( y ) |
---|
2219 | { |
---|
2220 | x = y; |
---|
2221 | iMSB += bits; |
---|
2222 | } |
---|
2223 | } |
---|
2224 | |
---|
2225 | iMSB+=y; |
---|
2226 | |
---|
2227 | return iMSB; |
---|
2228 | } |
---|
2229 | |
---|
2230 | |
---|
2231 | /** Function for deriving LM illumination compensation. |
---|
2232 | */ |
---|
2233 | Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, TextType eType ) |
---|
2234 | { |
---|
2235 | TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec(); |
---|
2236 | Pel *pRec = NULL, *pRef = NULL; |
---|
2237 | UInt uiWidth, uiHeight, uiTmpPartIdx; |
---|
2238 | Int iRecStride = ( eType == TEXT_LUMA ) ? pRecPic->getStride() : pRecPic->getCStride(); |
---|
2239 | Int iRefStride = ( eType == TEXT_LUMA ) ? pRefPic->getStride() : pRefPic->getCStride(); |
---|
2240 | Int iRefOffset, iHor, iVer; |
---|
2241 | iHor = pcCU->getSlice()->getIsDepth() ? pMv->getHor() : ( ( pMv->getHor() + 2 ) >> 2 ); |
---|
2242 | iVer = pcCU->getSlice()->getIsDepth() ? pMv->getVer() : ( ( pMv->getVer() + 2 ) >> 2 ); |
---|
2243 | if( eType != TEXT_LUMA ) |
---|
2244 | { |
---|
2245 | iHor = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getHor() + 1 ) >> 1 ) : ( ( pMv->getHor() + 4 ) >> 3 ); |
---|
2246 | iVer = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getVer() + 1 ) >> 1 ) : ( ( pMv->getVer() + 4 ) >> 3 ); |
---|
2247 | } |
---|
2248 | uiWidth = ( eType == TEXT_LUMA ) ? pcCU->getWidth( 0 ) : ( pcCU->getWidth( 0 ) >> 1 ); |
---|
2249 | uiHeight = ( eType == TEXT_LUMA ) ? pcCU->getHeight( 0 ) : ( pcCU->getHeight( 0 ) >> 1 ); |
---|
2250 | |
---|
2251 | Int i, j, iCountShift = 0; |
---|
2252 | |
---|
2253 | // LLS parameters estimation --> |
---|
2254 | |
---|
2255 | Int x = 0, y = 0, xx = 0, xy = 0; |
---|
2256 | Int precShift = std::max(0, (( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC) - 12); |
---|
2257 | |
---|
2258 | if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) ) |
---|
2259 | { |
---|
2260 | iRefOffset = iHor + iVer * iRefStride - iRefStride; |
---|
2261 | if( eType == TEXT_LUMA ) |
---|
2262 | { |
---|
2263 | pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2264 | pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride; |
---|
2265 | } |
---|
2266 | else if( eType == TEXT_CHROMA_U ) |
---|
2267 | { |
---|
2268 | pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2269 | pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride; |
---|
2270 | } |
---|
2271 | else |
---|
2272 | { |
---|
2273 | assert( eType == TEXT_CHROMA_V ); |
---|
2274 | pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2275 | pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride; |
---|
2276 | } |
---|
2277 | |
---|
2278 | for( j = 0; j < uiWidth; j+=2 ) |
---|
2279 | { |
---|
2280 | x += pRef[j]; |
---|
2281 | y += pRec[j]; |
---|
2282 | if ( eType == TEXT_LUMA ) |
---|
2283 | { |
---|
2284 | xx += (pRef[j] * pRef[j])>>precShift; |
---|
2285 | xy += (pRef[j] * pRec[j])>>precShift; |
---|
2286 | } |
---|
2287 | } |
---|
2288 | iCountShift += g_aucConvertToBit[ uiWidth ] + 1; |
---|
2289 | } |
---|
2290 | |
---|
2291 | if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) ) |
---|
2292 | { |
---|
2293 | iRefOffset = iHor + iVer * iRefStride - 1; |
---|
2294 | if( eType == TEXT_LUMA ) |
---|
2295 | { |
---|
2296 | pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2297 | pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1; |
---|
2298 | } |
---|
2299 | else if( eType == TEXT_CHROMA_U ) |
---|
2300 | { |
---|
2301 | pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2302 | pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1; |
---|
2303 | } |
---|
2304 | else |
---|
2305 | { |
---|
2306 | assert( eType == TEXT_CHROMA_V ); |
---|
2307 | pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2308 | pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1; |
---|
2309 | } |
---|
2310 | |
---|
2311 | for( i = 0; i < uiHeight; i+=2 ) |
---|
2312 | { |
---|
2313 | x += pRef[0]; |
---|
2314 | y += pRec[0]; |
---|
2315 | if ( eType == TEXT_LUMA ) |
---|
2316 | { |
---|
2317 | xx += (pRef[0] * pRef[0])>>precShift; |
---|
2318 | xy += (pRef[0] * pRec[0])>>precShift; |
---|
2319 | } |
---|
2320 | pRef += iRefStride*2; |
---|
2321 | pRec += iRecStride*2; |
---|
2322 | } |
---|
2323 | iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 1 ); |
---|
2324 | } |
---|
2325 | |
---|
2326 | if( iCountShift == 0 ) |
---|
2327 | { |
---|
2328 | a = ( 1 << IC_CONST_SHIFT ); |
---|
2329 | b = 0; |
---|
2330 | return; |
---|
2331 | } |
---|
2332 | |
---|
2333 | if ( eType != TEXT_LUMA ) |
---|
2334 | { |
---|
2335 | a = 32; |
---|
2336 | b = ( y - x + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift; |
---|
2337 | } |
---|
2338 | else |
---|
2339 | { |
---|
2340 | xy += xx >> IC_REG_COST_SHIFT; |
---|
2341 | xx += xx >> IC_REG_COST_SHIFT; |
---|
2342 | Int a1 = ( xy << iCountShift ) - ((y * x) >> precShift); |
---|
2343 | Int a2 = ( xx << iCountShift ) - ((x * x) >> precShift); |
---|
2344 | const Int iShift = IC_CONST_SHIFT; |
---|
2345 | { |
---|
2346 | { |
---|
2347 | const Int iShiftA2 = 6; |
---|
2348 | const Int iAccuracyShift = 15; |
---|
2349 | |
---|
2350 | Int iScaleShiftA2 = 0; |
---|
2351 | Int iScaleShiftA1 = 0; |
---|
2352 | Int a1s = a1; |
---|
2353 | Int a2s = a2; |
---|
2354 | |
---|
2355 | a1 = Clip3(0, 2*a2, a1); |
---|
2356 | iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2; |
---|
2357 | iScaleShiftA1 = iScaleShiftA2 - IC_SHIFT_DIFF; |
---|
2358 | |
---|
2359 | if( iScaleShiftA1 < 0 ) |
---|
2360 | { |
---|
2361 | iScaleShiftA1 = 0; |
---|
2362 | } |
---|
2363 | |
---|
2364 | if( iScaleShiftA2 < 0 ) |
---|
2365 | { |
---|
2366 | iScaleShiftA2 = 0; |
---|
2367 | } |
---|
2368 | |
---|
2369 | Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1; |
---|
2370 | |
---|
2371 | |
---|
2372 | a2s = a2 >> iScaleShiftA2; |
---|
2373 | |
---|
2374 | a1s = a1 >> iScaleShiftA1; |
---|
2375 | |
---|
2376 | a = a1s * m_uiaShift[ a2s ]; |
---|
2377 | a = a >> iScaleShiftA; |
---|
2378 | b = ( y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift; |
---|
2379 | } |
---|
2380 | } |
---|
2381 | } |
---|
2382 | } |
---|
2383 | #endif |
---|
2384 | |
---|
2385 | #if NH_3D_SDC_INTRA |
---|
2386 | Void TComPrediction::predConstantSDC( Pel* ptrSrc, UInt srcStride, UInt uiSize, Pel& predDC ) |
---|
2387 | { |
---|
2388 | Pel* pLeftTop = ptrSrc; |
---|
2389 | Pel* pRightTop = ptrSrc + (uiSize-1); |
---|
2390 | Pel* pLeftBottom = (ptrSrc+ (srcStride*(uiSize-1)) ); |
---|
2391 | Pel* pRightBottom = (ptrSrc+ (srcStride*(uiSize-1)) + (uiSize-1)); |
---|
2392 | predDC = (*pLeftTop + *pRightTop + *pLeftBottom + *pRightBottom + 2)>>2; |
---|
2393 | } |
---|
2394 | #endif // NH_3D_SDC_INTRA |
---|
2395 | |
---|
2396 | #if NH_3D_DMM |
---|
2397 | Void TComPrediction::predContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Bool* segPattern ) |
---|
2398 | { |
---|
2399 | // get copy of co-located texture luma block |
---|
2400 | TComYuv cTempYuv; |
---|
2401 | cTempYuv.create( uiWidth, uiHeight, CHROMA_400 ); |
---|
2402 | cTempYuv.clear(); |
---|
2403 | Pel* piRefBlkY = cTempYuv.getAddr( COMPONENT_Y ); |
---|
2404 | TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec(); |
---|
2405 | assert( pcPicYuvRef != NULL ); |
---|
2406 | Int iRefStride = pcPicYuvRef->getStride( COMPONENT_Y ); |
---|
2407 | Pel* piRefY = pcPicYuvRef->getAddr ( COMPONENT_Y, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + uiAbsPartIdx ); |
---|
2408 | |
---|
2409 | for( Int y = 0; y < uiHeight; y++ ) |
---|
2410 | { |
---|
2411 | ::memcpy(piRefBlkY, piRefY, sizeof(Pel)*uiWidth); |
---|
2412 | piRefBlkY += uiWidth; |
---|
2413 | piRefY += iRefStride; |
---|
2414 | } |
---|
2415 | |
---|
2416 | |
---|
2417 | // find contour for texture luma block |
---|
2418 | piRefBlkY = cTempYuv.getAddr( COMPONENT_Y ); |
---|
2419 | UInt iDC = 0; |
---|
2420 | iDC = piRefBlkY[ 0 ]; |
---|
2421 | iDC += piRefBlkY[ uiWidth - 1 ]; |
---|
2422 | iDC += piRefBlkY[ uiWidth * (uiHeight - 1) ]; |
---|
2423 | iDC += piRefBlkY[ uiWidth * (uiHeight - 1) + uiWidth - 1 ]; |
---|
2424 | iDC = iDC >> 2; |
---|
2425 | |
---|
2426 | piRefBlkY = cTempYuv.getAddr( COMPONENT_Y ); |
---|
2427 | for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) |
---|
2428 | { |
---|
2429 | segPattern[k] = (piRefBlkY[k] > iDC) ? true : false; |
---|
2430 | } |
---|
2431 | |
---|
2432 | cTempYuv.destroy(); |
---|
2433 | } |
---|
2434 | |
---|
2435 | Void TComPrediction::predBiSegDCs( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 ) |
---|
2436 | { |
---|
2437 | assert( biSegPattern ); |
---|
2438 | const Pel *piMask = getPredictorPtr( COMPONENT_Y, false ); |
---|
2439 | assert( piMask ); |
---|
2440 | Int srcStride = 2*uiWidth + 1; |
---|
2441 | const Pel *ptrSrc = piMask+srcStride+1; |
---|
2442 | |
---|
2443 | Int refDC1, refDC2; |
---|
2444 | const Int iTR = ( patternStride - 1 ) - srcStride; |
---|
2445 | const Int iTM = ( ( patternStride - 1 ) >> 1 ) - srcStride; |
---|
2446 | const Int iLB = ( patternStride - 1 ) * srcStride - 1; |
---|
2447 | const Int iLM = ( ( patternStride - 1 ) >> 1 ) * srcStride - 1; |
---|
2448 | |
---|
2449 | Bool bL = ( biSegPattern[0] != biSegPattern[(patternStride-1)*patternStride] ); |
---|
2450 | Bool bT = ( biSegPattern[0] != biSegPattern[(patternStride-1)] ); |
---|
2451 | |
---|
2452 | if( bL == bT ) |
---|
2453 | { |
---|
2454 | const Int iTRR = ( patternStride * 2 - 1 ) - srcStride; |
---|
2455 | const Int iLBB = ( patternStride * 2 - 1 ) * srcStride - 1; |
---|
2456 | refDC1 = bL ? ( ptrSrc[iTR] + ptrSrc[iLB] )>>1 : (abs(ptrSrc[iTRR] - ptrSrc[-(Int)srcStride]) > abs(ptrSrc[iLBB] - ptrSrc[ -1]) ? ptrSrc[iTRR] : ptrSrc[iLBB]); |
---|
2457 | refDC2 = ( ptrSrc[ -1] + ptrSrc[-(Int)srcStride] )>>1; |
---|
2458 | } |
---|
2459 | else |
---|
2460 | { |
---|
2461 | refDC1 = bL ? ptrSrc[iLB] : ptrSrc[iTR]; |
---|
2462 | refDC2 = bL ? ptrSrc[iTM] : ptrSrc[iLM]; |
---|
2463 | } |
---|
2464 | |
---|
2465 | predDC1 = biSegPattern[0] ? refDC1 : refDC2; |
---|
2466 | predDC2 = biSegPattern[0] ? refDC2 : refDC1; |
---|
2467 | } |
---|
2468 | |
---|
2469 | Void TComPrediction::assignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 ) |
---|
2470 | { |
---|
2471 | assert( biSegPattern ); |
---|
2472 | if( dstStride == patternStride ) |
---|
2473 | { |
---|
2474 | for( UInt k = 0; k < (patternStride * patternStride); k++ ) |
---|
2475 | { |
---|
2476 | if( true == biSegPattern[k] ) { ptrDst[k] = valDC2; } |
---|
2477 | else { ptrDst[k] = valDC1; } |
---|
2478 | } |
---|
2479 | } |
---|
2480 | else |
---|
2481 | { |
---|
2482 | Pel* piTemp = ptrDst; |
---|
2483 | for( UInt uiY = 0; uiY < patternStride; uiY++ ) |
---|
2484 | { |
---|
2485 | for( UInt uiX = 0; uiX < patternStride; uiX++ ) |
---|
2486 | { |
---|
2487 | if( true == biSegPattern[uiX] ) { piTemp[uiX] = valDC2; } |
---|
2488 | else { piTemp[uiX] = valDC1; } |
---|
2489 | } |
---|
2490 | piTemp += dstStride; |
---|
2491 | biSegPattern += patternStride; |
---|
2492 | } |
---|
2493 | } |
---|
2494 | } |
---|
2495 | #endif |
---|
2496 | //! \} |
---|