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 TComPattern.cpp |
---|
35 | \brief neighbouring pixel access classes |
---|
36 | */ |
---|
37 | |
---|
38 | #include "TComPic.h" |
---|
39 | #include "TComPattern.h" |
---|
40 | #include "TComDataCU.h" |
---|
41 | #include "TComTU.h" |
---|
42 | #include "Debug.h" |
---|
43 | #include "TComPrediction.h" |
---|
44 | |
---|
45 | //! \ingroup TLibCommon |
---|
46 | //! \{ |
---|
47 | |
---|
48 | // Forward declarations |
---|
49 | |
---|
50 | /// padding of unavailable reference samples for intra prediction |
---|
51 | #if O0043_BEST_EFFORT_DECODING |
---|
52 | Void fillReferenceSamples( const Int bitDepth, const Int bitDepthDelta, TComDataCU* pcCU, const Pel* piRoiOrigin, Pel* piAdiTemp, const Bool* bNeighborFlags, |
---|
53 | #else |
---|
54 | Void fillReferenceSamples( const Int bitDepth, TComDataCU* pcCU, const Pel* piRoiOrigin, Pel* piAdiTemp, const Bool* bNeighborFlags, |
---|
55 | #endif |
---|
56 | const Int iNumIntraNeighbor, const Int unitWidth, const Int unitHeight, const Int iAboveUnits, const Int iLeftUnits, |
---|
57 | const UInt uiCuWidth, const UInt uiCuHeight, const UInt uiWidth, const UInt uiHeight, const Int iPicStride, |
---|
58 | const ChannelType chType, const ChromaFormat chFmt ); |
---|
59 | |
---|
60 | /// constrained intra prediction |
---|
61 | Bool isAboveLeftAvailable ( TComDataCU* pcCU, UInt uiPartIdxLT ); |
---|
62 | Int isAboveAvailable ( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxRT, Bool* bValidFlags ); |
---|
63 | Int isLeftAvailable ( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxLB, Bool* bValidFlags ); |
---|
64 | Int isAboveRightAvailable ( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxRT, Bool* bValidFlags ); |
---|
65 | Int isBelowLeftAvailable ( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxLB, Bool* bValidFlags ); |
---|
66 | |
---|
67 | |
---|
68 | // ==================================================================================================================== |
---|
69 | // Public member functions (TComPatternParam) |
---|
70 | // ==================================================================================================================== |
---|
71 | |
---|
72 | /** |
---|
73 | \param piTexture pixel data |
---|
74 | \param iRoiWidth pattern width |
---|
75 | \param iRoiHeight pattern height |
---|
76 | \param iStride buffer stride |
---|
77 | */ |
---|
78 | Void TComPatternParam::setPatternParamPel ( Pel* piTexture, |
---|
79 | Int iRoiWidth, |
---|
80 | Int iRoiHeight, |
---|
81 | Int iStride |
---|
82 | ) |
---|
83 | { |
---|
84 | m_piROIOrigin = piTexture; |
---|
85 | m_iROIWidth = iRoiWidth; |
---|
86 | m_iROIHeight = iRoiHeight; |
---|
87 | m_iPatternStride = iStride; |
---|
88 | } |
---|
89 | |
---|
90 | // ==================================================================================================================== |
---|
91 | // Public member functions (TComPattern) |
---|
92 | // ==================================================================================================================== |
---|
93 | |
---|
94 | Void TComPattern::initPattern (Pel* piY, |
---|
95 | Int iRoiWidth, |
---|
96 | Int iRoiHeight, |
---|
97 | Int iStride) |
---|
98 | { |
---|
99 | m_cPatternY. setPatternParamPel( piY, iRoiWidth, iRoiHeight, iStride); |
---|
100 | } |
---|
101 | |
---|
102 | |
---|
103 | // TODO: move this function to TComPrediction.cpp. |
---|
104 | Void TComPrediction::initAdiPatternChType( TComTU &rTu, Bool& bAbove, Bool& bLeft, const ComponentID compID, const Bool bFilterRefSamples DEBUG_STRING_FN_DECLARE(sDebug)) |
---|
105 | { |
---|
106 | const ChannelType chType = toChannelType(compID); |
---|
107 | |
---|
108 | TComDataCU *pcCU=rTu.getCU(); |
---|
109 | const UInt uiZorderIdxInPart=rTu.GetAbsPartIdxTU(); |
---|
110 | const UInt uiTuWidth = rTu.getRect(compID).width; |
---|
111 | const UInt uiTuHeight = rTu.getRect(compID).height; |
---|
112 | const UInt uiTuWidth2 = uiTuWidth << 1; |
---|
113 | const UInt uiTuHeight2 = uiTuHeight << 1; |
---|
114 | |
---|
115 | const Int iBaseUnitSize = g_uiMaxCUWidth >> g_uiMaxCUDepth; |
---|
116 | const Int iUnitWidth = iBaseUnitSize >> pcCU->getPic()->getPicYuvRec()->getComponentScaleX(compID); |
---|
117 | const Int iUnitHeight = iBaseUnitSize >> pcCU->getPic()->getPicYuvRec()->getComponentScaleY(compID); |
---|
118 | const Int iTUWidthInUnits = uiTuWidth / iUnitWidth; |
---|
119 | const Int iTUHeightInUnits = uiTuHeight / iUnitHeight; |
---|
120 | const Int iAboveUnits = iTUWidthInUnits << 1; |
---|
121 | const Int iLeftUnits = iTUHeightInUnits << 1; |
---|
122 | |
---|
123 | assert(iTUHeightInUnits > 0 && iTUWidthInUnits > 0); |
---|
124 | |
---|
125 | const Int iPartIdxStride = pcCU->getPic()->getNumPartInCtuWidth(); |
---|
126 | const UInt uiPartIdxLT = pcCU->getZorderIdxInCtu() + uiZorderIdxInPart; |
---|
127 | const UInt uiPartIdxRT = g_auiRasterToZscan[ g_auiZscanToRaster[ uiPartIdxLT ] + iTUWidthInUnits - 1 ]; |
---|
128 | const UInt uiPartIdxLB = g_auiRasterToZscan[ g_auiZscanToRaster[ uiPartIdxLT ] + ((iTUHeightInUnits - 1) * iPartIdxStride)]; |
---|
129 | |
---|
130 | Int iPicStride = pcCU->getPic()->getStride(compID); |
---|
131 | Bool bNeighborFlags[4 * MAX_NUM_SPU_W + 1]; |
---|
132 | Int iNumIntraNeighbor = 0; |
---|
133 | |
---|
134 | bNeighborFlags[iLeftUnits] = isAboveLeftAvailable( pcCU, uiPartIdxLT ); |
---|
135 | iNumIntraNeighbor += bNeighborFlags[iLeftUnits] ? 1 : 0; |
---|
136 | iNumIntraNeighbor += isAboveAvailable ( pcCU, uiPartIdxLT, uiPartIdxRT, (bNeighborFlags + iLeftUnits + 1) ); |
---|
137 | iNumIntraNeighbor += isAboveRightAvailable( pcCU, uiPartIdxLT, uiPartIdxRT, (bNeighborFlags + iLeftUnits + 1 + iTUWidthInUnits ) ); |
---|
138 | iNumIntraNeighbor += isLeftAvailable ( pcCU, uiPartIdxLT, uiPartIdxLB, (bNeighborFlags + iLeftUnits - 1) ); |
---|
139 | iNumIntraNeighbor += isBelowLeftAvailable ( pcCU, uiPartIdxLT, uiPartIdxLB, (bNeighborFlags + iLeftUnits - 1 - iTUHeightInUnits) ); |
---|
140 | |
---|
141 | bAbove = true; |
---|
142 | bLeft = true; |
---|
143 | |
---|
144 | const ChromaFormat chFmt = rTu.GetChromaFormat(); |
---|
145 | const UInt uiROIWidth = uiTuWidth2+1; |
---|
146 | const UInt uiROIHeight = uiTuHeight2+1; |
---|
147 | |
---|
148 | assert(uiROIWidth*uiROIHeight <= m_iYuvExtSize); |
---|
149 | |
---|
150 | #ifdef DEBUG_STRING |
---|
151 | std::stringstream ss(stringstream::out); |
---|
152 | #endif |
---|
153 | |
---|
154 | { |
---|
155 | Pel *piAdiTemp = m_piYuvExt[compID][PRED_BUF_UNFILTERED]; |
---|
156 | Pel *piRoiOrigin = pcCU->getPic()->getPicYuvRec()->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu()+uiZorderIdxInPart); |
---|
157 | #if O0043_BEST_EFFORT_DECODING |
---|
158 | fillReferenceSamples (g_bitDepthInStream[chType], g_bitDepthInStream[chType] - g_bitDepth[chType], pcCU, piRoiOrigin, piAdiTemp, bNeighborFlags, iNumIntraNeighbor, iUnitWidth, iUnitHeight, iAboveUnits, iLeftUnits, |
---|
159 | #else |
---|
160 | fillReferenceSamples (g_bitDepth[chType], pcCU, piRoiOrigin, piAdiTemp, bNeighborFlags, iNumIntraNeighbor, iUnitWidth, iUnitHeight, iAboveUnits, iLeftUnits, |
---|
161 | #endif |
---|
162 | uiTuWidth, uiTuHeight, uiROIWidth, uiROIHeight, iPicStride, toChannelType(compID), chFmt); |
---|
163 | |
---|
164 | |
---|
165 | #ifdef DEBUG_STRING |
---|
166 | if (DebugOptionList::DebugString_Pred.getInt()&DebugStringGetPredModeMask(MODE_INTRA)) |
---|
167 | { |
---|
168 | ss << "###: generating Ref Samples for channel " << compID << " and " << rTu.getRect(compID).width << " x " << rTu.getRect(compID).height << "\n"; |
---|
169 | for (UInt y=0; y<uiROIHeight; y++) |
---|
170 | { |
---|
171 | ss << "###: - "; |
---|
172 | for (UInt x=0; x<uiROIWidth; x++) |
---|
173 | { |
---|
174 | if (x==0 || y==0) |
---|
175 | { |
---|
176 | ss << piAdiTemp[y*uiROIWidth + x] << ", "; |
---|
177 | // if (x%16==15) ss << "\nPart size: ~ "; |
---|
178 | } |
---|
179 | } |
---|
180 | ss << "\n"; |
---|
181 | } |
---|
182 | } |
---|
183 | #endif |
---|
184 | |
---|
185 | if (bFilterRefSamples) |
---|
186 | { |
---|
187 | // generate filtered intra prediction samples |
---|
188 | |
---|
189 | Int stride = uiROIWidth; |
---|
190 | const Pel *piSrcPtr = piAdiTemp + (stride * uiTuHeight2); // bottom left |
---|
191 | Pel *piDestPtr = m_piYuvExt[compID][PRED_BUF_FILTERED] + (stride * uiTuHeight2); // bottom left |
---|
192 | |
---|
193 | //------------------------------------------------ |
---|
194 | |
---|
195 | Bool useStrongIntraSmoothing = isLuma(chType) && pcCU->getSlice()->getSPS()->getUseStrongIntraSmoothing(); |
---|
196 | |
---|
197 | const Pel bottomLeft = piAdiTemp[stride * uiTuHeight2]; |
---|
198 | const Pel topLeft = piAdiTemp[0]; |
---|
199 | const Pel topRight = piAdiTemp[uiTuWidth2]; |
---|
200 | |
---|
201 | if (useStrongIntraSmoothing) |
---|
202 | { |
---|
203 | #if O0043_BEST_EFFORT_DECODING |
---|
204 | const Int threshold = 1 << (g_bitDepthInStream[chType] - 5); |
---|
205 | #else |
---|
206 | const Int threshold = 1 << (g_bitDepth[chType] - 5); |
---|
207 | #endif |
---|
208 | const Bool bilinearLeft = abs((bottomLeft + topLeft ) - (2 * piAdiTemp[stride * uiTuHeight])) < threshold; //difference between the |
---|
209 | const Bool bilinearAbove = abs((topLeft + topRight) - (2 * piAdiTemp[ uiTuWidth ])) < threshold; //ends and the middle |
---|
210 | if ((uiTuWidth < 32) || (!bilinearLeft) || (!bilinearAbove)) |
---|
211 | { |
---|
212 | useStrongIntraSmoothing = false; |
---|
213 | } |
---|
214 | } |
---|
215 | |
---|
216 | *piDestPtr = *piSrcPtr; // bottom left is not filtered |
---|
217 | piDestPtr -= stride; |
---|
218 | piSrcPtr -= stride; |
---|
219 | |
---|
220 | //------------------------------------------------ |
---|
221 | |
---|
222 | //left column (bottom to top) |
---|
223 | |
---|
224 | if (useStrongIntraSmoothing) |
---|
225 | { |
---|
226 | const Int shift = g_aucConvertToBit[uiTuHeight] + 3; //log2(uiTuHeight2) |
---|
227 | |
---|
228 | for(UInt i=1; i<uiTuHeight2; i++, piDestPtr-=stride) |
---|
229 | { |
---|
230 | *piDestPtr = (((uiTuHeight2 - i) * bottomLeft) + (i * topLeft) + uiTuHeight) >> shift; |
---|
231 | } |
---|
232 | |
---|
233 | piSrcPtr -= stride * (uiTuHeight2 - 1); |
---|
234 | } |
---|
235 | else |
---|
236 | { |
---|
237 | for(UInt i=1; i<uiTuHeight2; i++, piDestPtr-=stride, piSrcPtr-=stride) |
---|
238 | { |
---|
239 | *piDestPtr = ( piSrcPtr[stride] + 2*piSrcPtr[0] + piSrcPtr[-stride] + 2 ) >> 2; |
---|
240 | } |
---|
241 | } |
---|
242 | |
---|
243 | //------------------------------------------------ |
---|
244 | |
---|
245 | //top-left |
---|
246 | |
---|
247 | if (useStrongIntraSmoothing) |
---|
248 | { |
---|
249 | *piDestPtr = piSrcPtr[0]; |
---|
250 | } |
---|
251 | else |
---|
252 | { |
---|
253 | *piDestPtr = ( piSrcPtr[stride] + 2*piSrcPtr[0] + piSrcPtr[1] + 2 ) >> 2; |
---|
254 | } |
---|
255 | piDestPtr += 1; |
---|
256 | piSrcPtr += 1; |
---|
257 | |
---|
258 | //------------------------------------------------ |
---|
259 | |
---|
260 | //top row (left-to-right) |
---|
261 | |
---|
262 | if (useStrongIntraSmoothing) |
---|
263 | { |
---|
264 | const Int shift = g_aucConvertToBit[uiTuWidth] + 3; //log2(uiTuWidth2) |
---|
265 | |
---|
266 | for(UInt i=1; i<uiTuWidth2; i++, piDestPtr++) |
---|
267 | { |
---|
268 | *piDestPtr = (((uiTuWidth2 - i) * topLeft) + (i * topRight) + uiTuWidth) >> shift; |
---|
269 | } |
---|
270 | |
---|
271 | piSrcPtr += uiTuWidth2 - 1; |
---|
272 | } |
---|
273 | else |
---|
274 | { |
---|
275 | for(UInt i=1; i<uiTuWidth2; i++, piDestPtr++, piSrcPtr++) |
---|
276 | { |
---|
277 | *piDestPtr = ( piSrcPtr[1] + 2*piSrcPtr[0] + piSrcPtr[-1] + 2 ) >> 2; |
---|
278 | } |
---|
279 | } |
---|
280 | |
---|
281 | //------------------------------------------------ |
---|
282 | |
---|
283 | *piDestPtr=*piSrcPtr; // far right is not filtered |
---|
284 | |
---|
285 | #ifdef DEBUG_STRING |
---|
286 | if (DebugOptionList::DebugString_Pred.getInt()&DebugStringGetPredModeMask(MODE_INTRA)) |
---|
287 | { |
---|
288 | ss << "###: filtered result for channel " << compID <<"\n"; |
---|
289 | for (UInt y=0; y<uiROIHeight; y++) |
---|
290 | { |
---|
291 | ss << "###: - "; |
---|
292 | for (UInt x=0; x<uiROIWidth; x++) |
---|
293 | { |
---|
294 | if (x==0 || y==0) |
---|
295 | { |
---|
296 | ss << m_piYuvExt[compID][PRED_BUF_FILTERED][y*uiROIWidth + x] << ", "; |
---|
297 | // if (x%16==15) ss << "\nPart size: ~ "; |
---|
298 | } |
---|
299 | } |
---|
300 | ss << "\n"; |
---|
301 | } |
---|
302 | } |
---|
303 | #endif |
---|
304 | |
---|
305 | |
---|
306 | } |
---|
307 | } |
---|
308 | DEBUG_STRING_APPEND(sDebug, ss.str()) |
---|
309 | } |
---|
310 | |
---|
311 | #if O0043_BEST_EFFORT_DECODING |
---|
312 | Void fillReferenceSamples( const Int bitDepth, const Int bitDepthDelta, TComDataCU* pcCU, const Pel* piRoiOrigin, Pel* piAdiTemp, const Bool* bNeighborFlags, |
---|
313 | #else |
---|
314 | Void fillReferenceSamples( const Int bitDepth, TComDataCU* pcCU, const Pel* piRoiOrigin, Pel* piAdiTemp, const Bool* bNeighborFlags, |
---|
315 | #endif |
---|
316 | const Int iNumIntraNeighbor, const Int unitWidth, const Int unitHeight, const Int iAboveUnits, const Int iLeftUnits, |
---|
317 | const UInt uiCuWidth, const UInt uiCuHeight, const UInt uiWidth, const UInt uiHeight, const Int iPicStride, |
---|
318 | const ChannelType chType, const ChromaFormat chFmt ) |
---|
319 | { |
---|
320 | const Pel* piRoiTemp; |
---|
321 | Int i, j; |
---|
322 | Int iDCValue = 1 << (bitDepth - 1); |
---|
323 | const Int iTotalUnits = iAboveUnits + iLeftUnits + 1; //+1 for top-left |
---|
324 | |
---|
325 | if (iNumIntraNeighbor == 0) |
---|
326 | { |
---|
327 | // Fill border with DC value |
---|
328 | for (i=0; i<uiWidth; i++) |
---|
329 | { |
---|
330 | piAdiTemp[i] = iDCValue; |
---|
331 | } |
---|
332 | for (i=1; i<uiHeight; i++) |
---|
333 | { |
---|
334 | piAdiTemp[i*uiWidth] = iDCValue; |
---|
335 | } |
---|
336 | } |
---|
337 | else if (iNumIntraNeighbor == iTotalUnits) |
---|
338 | { |
---|
339 | // Fill top-left border and top and top right with rec. samples |
---|
340 | piRoiTemp = piRoiOrigin - iPicStride - 1; |
---|
341 | |
---|
342 | for (i=0; i<uiWidth; i++) |
---|
343 | { |
---|
344 | #if O0043_BEST_EFFORT_DECODING |
---|
345 | piAdiTemp[i] = piRoiTemp[i] << bitDepthDelta; |
---|
346 | #else |
---|
347 | piAdiTemp[i] = piRoiTemp[i]; |
---|
348 | #endif |
---|
349 | } |
---|
350 | |
---|
351 | // Fill left and below left border with rec. samples |
---|
352 | piRoiTemp = piRoiOrigin - 1; |
---|
353 | |
---|
354 | for (i=1; i<uiHeight; i++) |
---|
355 | { |
---|
356 | #if O0043_BEST_EFFORT_DECODING |
---|
357 | piAdiTemp[i*uiWidth] = (*(piRoiTemp)) << bitDepthDelta; |
---|
358 | #else |
---|
359 | piAdiTemp[i*uiWidth] = *(piRoiTemp); |
---|
360 | #endif |
---|
361 | piRoiTemp += iPicStride; |
---|
362 | } |
---|
363 | } |
---|
364 | else // reference samples are partially available |
---|
365 | { |
---|
366 | // all above units have "unitWidth" samples each, all left/below-left units have "unitHeight" samples each |
---|
367 | const Int iTotalSamples = (iLeftUnits * unitHeight) + ((iAboveUnits + 1) * unitWidth); |
---|
368 | Pel piAdiLine[5 * MAX_CU_SIZE]; |
---|
369 | Pel *piAdiLineTemp; |
---|
370 | const Bool *pbNeighborFlags; |
---|
371 | |
---|
372 | |
---|
373 | // Initialize |
---|
374 | for (i=0; i<iTotalSamples; i++) |
---|
375 | { |
---|
376 | piAdiLine[i] = iDCValue; |
---|
377 | } |
---|
378 | |
---|
379 | // Fill top-left sample |
---|
380 | piRoiTemp = piRoiOrigin - iPicStride - 1; |
---|
381 | piAdiLineTemp = piAdiLine + (iLeftUnits * unitHeight); |
---|
382 | pbNeighborFlags = bNeighborFlags + iLeftUnits; |
---|
383 | if (*pbNeighborFlags) |
---|
384 | { |
---|
385 | #if O0043_BEST_EFFORT_DECODING |
---|
386 | Pel topLeftVal=piRoiTemp[0] << bitDepthDelta; |
---|
387 | #else |
---|
388 | Pel topLeftVal=piRoiTemp[0]; |
---|
389 | #endif |
---|
390 | for (i=0; i<unitWidth; i++) |
---|
391 | { |
---|
392 | piAdiLineTemp[i] = topLeftVal; |
---|
393 | } |
---|
394 | } |
---|
395 | |
---|
396 | // Fill left & below-left samples (downwards) |
---|
397 | piRoiTemp += iPicStride; |
---|
398 | piAdiLineTemp--; |
---|
399 | pbNeighborFlags--; |
---|
400 | |
---|
401 | for (j=0; j<iLeftUnits; j++) |
---|
402 | { |
---|
403 | if (*pbNeighborFlags) |
---|
404 | { |
---|
405 | for (i=0; i<unitHeight; i++) |
---|
406 | { |
---|
407 | #if O0043_BEST_EFFORT_DECODING |
---|
408 | piAdiLineTemp[-i] = piRoiTemp[i*iPicStride] << bitDepthDelta; |
---|
409 | #else |
---|
410 | piAdiLineTemp[-i] = piRoiTemp[i*iPicStride]; |
---|
411 | #endif |
---|
412 | } |
---|
413 | } |
---|
414 | piRoiTemp += unitHeight*iPicStride; |
---|
415 | piAdiLineTemp -= unitHeight; |
---|
416 | pbNeighborFlags--; |
---|
417 | } |
---|
418 | |
---|
419 | // Fill above & above-right samples (left-to-right) (each unit has "unitWidth" samples) |
---|
420 | piRoiTemp = piRoiOrigin - iPicStride; |
---|
421 | // offset line buffer by iNumUints2*unitHeight (for left/below-left) + unitWidth (for above-left) |
---|
422 | piAdiLineTemp = piAdiLine + (iLeftUnits * unitHeight) + unitWidth; |
---|
423 | pbNeighborFlags = bNeighborFlags + iLeftUnits + 1; |
---|
424 | for (j=0; j<iAboveUnits; j++) |
---|
425 | { |
---|
426 | if (*pbNeighborFlags) |
---|
427 | { |
---|
428 | for (i=0; i<unitWidth; i++) |
---|
429 | { |
---|
430 | #if O0043_BEST_EFFORT_DECODING |
---|
431 | piAdiLineTemp[i] = piRoiTemp[i] << bitDepthDelta; |
---|
432 | #else |
---|
433 | piAdiLineTemp[i] = piRoiTemp[i]; |
---|
434 | #endif |
---|
435 | } |
---|
436 | } |
---|
437 | piRoiTemp += unitWidth; |
---|
438 | piAdiLineTemp += unitWidth; |
---|
439 | pbNeighborFlags++; |
---|
440 | } |
---|
441 | |
---|
442 | // Pad reference samples when necessary |
---|
443 | Int iCurrJnit = 0; |
---|
444 | Pel *piAdiLineCur = piAdiLine; |
---|
445 | const UInt piAdiLineTopRowOffset = iLeftUnits * (unitHeight - unitWidth); |
---|
446 | |
---|
447 | if (!bNeighborFlags[0]) |
---|
448 | { |
---|
449 | // very bottom unit of bottom-left; at least one unit will be valid. |
---|
450 | { |
---|
451 | Int iNext = 1; |
---|
452 | while (iNext < iTotalUnits && !bNeighborFlags[iNext]) |
---|
453 | { |
---|
454 | iNext++; |
---|
455 | } |
---|
456 | Pel *piAdiLineNext = piAdiLine + ((iNext < iLeftUnits) ? (iNext * unitHeight) : (piAdiLineTopRowOffset + (iNext * unitWidth))); |
---|
457 | const Pel refSample = *piAdiLineNext; |
---|
458 | // Pad unavailable samples with new value |
---|
459 | Int iNextOrTop = std::min<Int>(iNext, iLeftUnits); |
---|
460 | // fill left column |
---|
461 | while (iCurrJnit < iNextOrTop) |
---|
462 | { |
---|
463 | for (i=0; i<unitHeight; i++) |
---|
464 | { |
---|
465 | piAdiLineCur[i] = refSample; |
---|
466 | } |
---|
467 | piAdiLineCur += unitHeight; |
---|
468 | iCurrJnit++; |
---|
469 | } |
---|
470 | // fill top row |
---|
471 | while (iCurrJnit < iNext) |
---|
472 | { |
---|
473 | for (i=0; i<unitWidth; i++) |
---|
474 | { |
---|
475 | piAdiLineCur[i] = refSample; |
---|
476 | } |
---|
477 | piAdiLineCur += unitWidth; |
---|
478 | iCurrJnit++; |
---|
479 | } |
---|
480 | } |
---|
481 | } |
---|
482 | |
---|
483 | // pad all other reference samples. |
---|
484 | while (iCurrJnit < iTotalUnits) |
---|
485 | { |
---|
486 | if (!bNeighborFlags[iCurrJnit]) // samples not available |
---|
487 | { |
---|
488 | { |
---|
489 | const Int numSamplesInCurrUnit = (iCurrJnit >= iLeftUnits) ? unitWidth : unitHeight; |
---|
490 | const Pel refSample = *(piAdiLineCur-1); |
---|
491 | for (i=0; i<numSamplesInCurrUnit; i++) |
---|
492 | { |
---|
493 | piAdiLineCur[i] = refSample; |
---|
494 | } |
---|
495 | piAdiLineCur += numSamplesInCurrUnit; |
---|
496 | iCurrJnit++; |
---|
497 | } |
---|
498 | } |
---|
499 | else |
---|
500 | { |
---|
501 | piAdiLineCur += (iCurrJnit >= iLeftUnits) ? unitWidth : unitHeight; |
---|
502 | iCurrJnit++; |
---|
503 | } |
---|
504 | } |
---|
505 | |
---|
506 | // Copy processed samples |
---|
507 | |
---|
508 | piAdiLineTemp = piAdiLine + uiHeight + unitWidth - 2; |
---|
509 | // top left, top and top right samples |
---|
510 | for (i=0; i<uiWidth; i++) |
---|
511 | { |
---|
512 | piAdiTemp[i] = piAdiLineTemp[i]; |
---|
513 | } |
---|
514 | |
---|
515 | piAdiLineTemp = piAdiLine + uiHeight - 1; |
---|
516 | for (i=1; i<uiHeight; i++) |
---|
517 | { |
---|
518 | piAdiTemp[i*uiWidth] = piAdiLineTemp[-i]; |
---|
519 | } |
---|
520 | } |
---|
521 | } |
---|
522 | |
---|
523 | Bool TComPrediction::filteringIntraReferenceSamples(const ComponentID compID, UInt uiDirMode, UInt uiTuChWidth, UInt uiTuChHeight, const ChromaFormat chFmt, const Bool intraReferenceSmoothingDisabled) |
---|
524 | { |
---|
525 | Bool bFilter; |
---|
526 | |
---|
527 | if (!filterIntraReferenceSamples(toChannelType(compID), chFmt, intraReferenceSmoothingDisabled)) |
---|
528 | { |
---|
529 | bFilter=false; |
---|
530 | } |
---|
531 | else |
---|
532 | { |
---|
533 | assert(uiTuChWidth>=4 && uiTuChHeight>=4 && uiTuChWidth<128 && uiTuChHeight<128); |
---|
534 | |
---|
535 | if (uiDirMode == DC_IDX) |
---|
536 | { |
---|
537 | bFilter=false; //no smoothing for DC or LM chroma |
---|
538 | } |
---|
539 | else |
---|
540 | { |
---|
541 | Int diff = min<Int>(abs((Int) uiDirMode - HOR_IDX), abs((Int)uiDirMode - VER_IDX)); |
---|
542 | UInt sizeIndex=g_aucConvertToBit[uiTuChWidth]; |
---|
543 | assert(sizeIndex < MAX_INTRA_FILTER_DEPTHS); |
---|
544 | bFilter = diff > m_aucIntraFilter[toChannelType(compID)][sizeIndex]; |
---|
545 | } |
---|
546 | } |
---|
547 | return bFilter; |
---|
548 | } |
---|
549 | |
---|
550 | Bool isAboveLeftAvailable( TComDataCU* pcCU, UInt uiPartIdxLT ) |
---|
551 | { |
---|
552 | Bool bAboveLeftFlag; |
---|
553 | UInt uiPartAboveLeft; |
---|
554 | TComDataCU* pcCUAboveLeft = pcCU->getPUAboveLeft( uiPartAboveLeft, uiPartIdxLT ); |
---|
555 | if(pcCU->getSlice()->getPPS()->getConstrainedIntraPred()) |
---|
556 | { |
---|
557 | bAboveLeftFlag = ( pcCUAboveLeft && pcCUAboveLeft->isIntra( uiPartAboveLeft ) ); |
---|
558 | } |
---|
559 | else |
---|
560 | { |
---|
561 | bAboveLeftFlag = (pcCUAboveLeft ? true : false); |
---|
562 | } |
---|
563 | return bAboveLeftFlag; |
---|
564 | } |
---|
565 | |
---|
566 | Int isAboveAvailable( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxRT, Bool *bValidFlags ) |
---|
567 | { |
---|
568 | const UInt uiRasterPartBegin = g_auiZscanToRaster[uiPartIdxLT]; |
---|
569 | const UInt uiRasterPartEnd = g_auiZscanToRaster[uiPartIdxRT]+1; |
---|
570 | const UInt uiIdxStep = 1; |
---|
571 | Bool *pbValidFlags = bValidFlags; |
---|
572 | Int iNumIntra = 0; |
---|
573 | |
---|
574 | for ( UInt uiRasterPart = uiRasterPartBegin; uiRasterPart < uiRasterPartEnd; uiRasterPart += uiIdxStep ) |
---|
575 | { |
---|
576 | UInt uiPartAbove; |
---|
577 | TComDataCU* pcCUAbove = pcCU->getPUAbove( uiPartAbove, g_auiRasterToZscan[uiRasterPart] ); |
---|
578 | if(pcCU->getSlice()->getPPS()->getConstrainedIntraPred()) |
---|
579 | { |
---|
580 | if ( pcCUAbove && pcCUAbove->isIntra( uiPartAbove ) ) |
---|
581 | { |
---|
582 | iNumIntra++; |
---|
583 | *pbValidFlags = true; |
---|
584 | } |
---|
585 | else |
---|
586 | { |
---|
587 | *pbValidFlags = false; |
---|
588 | } |
---|
589 | } |
---|
590 | else |
---|
591 | { |
---|
592 | if (pcCUAbove) |
---|
593 | { |
---|
594 | iNumIntra++; |
---|
595 | *pbValidFlags = true; |
---|
596 | } |
---|
597 | else |
---|
598 | { |
---|
599 | *pbValidFlags = false; |
---|
600 | } |
---|
601 | } |
---|
602 | pbValidFlags++; |
---|
603 | } |
---|
604 | return iNumIntra; |
---|
605 | } |
---|
606 | |
---|
607 | Int isLeftAvailable( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxLB, Bool *bValidFlags ) |
---|
608 | { |
---|
609 | const UInt uiRasterPartBegin = g_auiZscanToRaster[uiPartIdxLT]; |
---|
610 | const UInt uiRasterPartEnd = g_auiZscanToRaster[uiPartIdxLB]+1; |
---|
611 | const UInt uiIdxStep = pcCU->getPic()->getNumPartInCtuWidth(); |
---|
612 | Bool *pbValidFlags = bValidFlags; |
---|
613 | Int iNumIntra = 0; |
---|
614 | |
---|
615 | for ( UInt uiRasterPart = uiRasterPartBegin; uiRasterPart < uiRasterPartEnd; uiRasterPart += uiIdxStep ) |
---|
616 | { |
---|
617 | UInt uiPartLeft; |
---|
618 | TComDataCU* pcCULeft = pcCU->getPULeft( uiPartLeft, g_auiRasterToZscan[uiRasterPart] ); |
---|
619 | if(pcCU->getSlice()->getPPS()->getConstrainedIntraPred()) |
---|
620 | { |
---|
621 | if ( pcCULeft && pcCULeft->isIntra( uiPartLeft ) ) |
---|
622 | { |
---|
623 | iNumIntra++; |
---|
624 | *pbValidFlags = true; |
---|
625 | } |
---|
626 | else |
---|
627 | { |
---|
628 | *pbValidFlags = false; |
---|
629 | } |
---|
630 | } |
---|
631 | else |
---|
632 | { |
---|
633 | if ( pcCULeft ) |
---|
634 | { |
---|
635 | iNumIntra++; |
---|
636 | *pbValidFlags = true; |
---|
637 | } |
---|
638 | else |
---|
639 | { |
---|
640 | *pbValidFlags = false; |
---|
641 | } |
---|
642 | } |
---|
643 | pbValidFlags--; // opposite direction |
---|
644 | } |
---|
645 | |
---|
646 | return iNumIntra; |
---|
647 | } |
---|
648 | |
---|
649 | Int isAboveRightAvailable( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxRT, Bool *bValidFlags ) |
---|
650 | { |
---|
651 | const UInt uiNumUnitsInPU = g_auiZscanToRaster[uiPartIdxRT] - g_auiZscanToRaster[uiPartIdxLT] + 1; |
---|
652 | Bool *pbValidFlags = bValidFlags; |
---|
653 | Int iNumIntra = 0; |
---|
654 | |
---|
655 | for ( UInt uiOffset = 1; uiOffset <= uiNumUnitsInPU; uiOffset++ ) |
---|
656 | { |
---|
657 | UInt uiPartAboveRight; |
---|
658 | TComDataCU* pcCUAboveRight = pcCU->getPUAboveRightAdi( uiPartAboveRight, uiPartIdxRT, uiOffset ); |
---|
659 | if(pcCU->getSlice()->getPPS()->getConstrainedIntraPred()) |
---|
660 | { |
---|
661 | if ( pcCUAboveRight && pcCUAboveRight->isIntra( uiPartAboveRight ) ) |
---|
662 | { |
---|
663 | iNumIntra++; |
---|
664 | *pbValidFlags = true; |
---|
665 | } |
---|
666 | else |
---|
667 | { |
---|
668 | *pbValidFlags = false; |
---|
669 | } |
---|
670 | } |
---|
671 | else |
---|
672 | { |
---|
673 | if ( pcCUAboveRight ) |
---|
674 | { |
---|
675 | iNumIntra++; |
---|
676 | *pbValidFlags = true; |
---|
677 | } |
---|
678 | else |
---|
679 | { |
---|
680 | *pbValidFlags = false; |
---|
681 | } |
---|
682 | } |
---|
683 | pbValidFlags++; |
---|
684 | } |
---|
685 | |
---|
686 | return iNumIntra; |
---|
687 | } |
---|
688 | |
---|
689 | Int isBelowLeftAvailable( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxLB, Bool *bValidFlags ) |
---|
690 | { |
---|
691 | const UInt uiNumUnitsInPU = (g_auiZscanToRaster[uiPartIdxLB] - g_auiZscanToRaster[uiPartIdxLT]) / pcCU->getPic()->getNumPartInCtuWidth() + 1; |
---|
692 | Bool *pbValidFlags = bValidFlags; |
---|
693 | Int iNumIntra = 0; |
---|
694 | |
---|
695 | for ( UInt uiOffset = 1; uiOffset <= uiNumUnitsInPU; uiOffset++ ) |
---|
696 | { |
---|
697 | UInt uiPartBelowLeft; |
---|
698 | TComDataCU* pcCUBelowLeft = pcCU->getPUBelowLeftAdi( uiPartBelowLeft, uiPartIdxLB, uiOffset ); |
---|
699 | if(pcCU->getSlice()->getPPS()->getConstrainedIntraPred()) |
---|
700 | { |
---|
701 | if ( pcCUBelowLeft && pcCUBelowLeft->isIntra( uiPartBelowLeft ) ) |
---|
702 | { |
---|
703 | iNumIntra++; |
---|
704 | *pbValidFlags = true; |
---|
705 | } |
---|
706 | else |
---|
707 | { |
---|
708 | *pbValidFlags = false; |
---|
709 | } |
---|
710 | } |
---|
711 | else |
---|
712 | { |
---|
713 | if ( pcCUBelowLeft ) |
---|
714 | { |
---|
715 | iNumIntra++; |
---|
716 | *pbValidFlags = true; |
---|
717 | } |
---|
718 | else |
---|
719 | { |
---|
720 | *pbValidFlags = false; |
---|
721 | } |
---|
722 | } |
---|
723 | pbValidFlags--; // opposite direction |
---|
724 | } |
---|
725 | |
---|
726 | return iNumIntra; |
---|
727 | } |
---|
728 | //! \} |
---|