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