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