[313] | 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 |
---|
[1029] | 4 | * granted under this license. |
---|
[313] | 5 | * |
---|
[1259] | 6 | * Copyright (c) 2010-2015, ITU/ISO/IEC |
---|
[313] | 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" |
---|
[1029] | 41 | #include "TComTU.h" |
---|
| 42 | #include "Debug.h" |
---|
| 43 | #include "TComPrediction.h" |
---|
[313] | 44 | |
---|
| 45 | //! \ingroup TLibCommon |
---|
| 46 | //! \{ |
---|
| 47 | |
---|
[1029] | 48 | // Forward declarations |
---|
[313] | 49 | |
---|
[1029] | 50 | /// padding of unavailable reference samples for intra prediction |
---|
[1307] | 51 | Void fillReferenceSamples( const Int bitDepth, |
---|
[1029] | 52 | #if O0043_BEST_EFFORT_DECODING |
---|
[1307] | 53 | const Int bitDepthDelta, |
---|
[1029] | 54 | #endif |
---|
[1307] | 55 | const Pel* piRoiOrigin, |
---|
| 56 | Pel* piAdiTemp, |
---|
| 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 ); |
---|
[313] | 66 | |
---|
[1029] | 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 | |
---|
[313] | 75 | // ==================================================================================================================== |
---|
| 76 | // Public member functions (TComPatternParam) |
---|
| 77 | // ==================================================================================================================== |
---|
| 78 | |
---|
[1260] | 79 | /** |
---|
| 80 | \param piTexture pixel data |
---|
[313] | 81 | \param iRoiWidth pattern width |
---|
| 82 | \param iRoiHeight pattern height |
---|
| 83 | \param iStride buffer stride |
---|
[1305] | 84 | \param bitDepth bit depth |
---|
[313] | 85 | */ |
---|
| 86 | Void TComPatternParam::setPatternParamPel ( Pel* piTexture, |
---|
| 87 | Int iRoiWidth, |
---|
| 88 | Int iRoiHeight, |
---|
[1287] | 89 | Int iStride, |
---|
| 90 | Int bitDepth |
---|
[1029] | 91 | ) |
---|
[313] | 92 | { |
---|
[1029] | 93 | m_piROIOrigin = piTexture; |
---|
[1287] | 94 | m_iROIWidth = iRoiWidth; |
---|
| 95 | m_iROIHeight = iRoiHeight; |
---|
| 96 | m_iPatternStride = iStride; |
---|
| 97 | m_bitDepth = bitDepth; |
---|
[313] | 98 | } |
---|
| 99 | |
---|
| 100 | // ==================================================================================================================== |
---|
| 101 | // Public member functions (TComPattern) |
---|
| 102 | // ==================================================================================================================== |
---|
| 103 | |
---|
[1029] | 104 | Void TComPattern::initPattern (Pel* piY, |
---|
[313] | 105 | Int iRoiWidth, |
---|
| 106 | Int iRoiHeight, |
---|
[1287] | 107 | Int iStride, |
---|
| 108 | Int bitDepthLuma) |
---|
[313] | 109 | { |
---|
[1287] | 110 | m_cPatternY. setPatternParamPel( piY, iRoiWidth, iRoiHeight, iStride, bitDepthLuma); |
---|
[313] | 111 | } |
---|
| 112 | |
---|
[1029] | 113 | |
---|
| 114 | // TODO: move this function to TComPrediction.cpp. |
---|
| 115 | Void TComPrediction::initAdiPatternChType( TComTU &rTu, Bool& bAbove, Bool& bLeft, const ComponentID compID, const Bool bFilterRefSamples DEBUG_STRING_FN_DECLARE(sDebug)) |
---|
[313] | 116 | { |
---|
[1029] | 117 | const ChannelType chType = toChannelType(compID); |
---|
[313] | 118 | |
---|
[1029] | 119 | TComDataCU *pcCU=rTu.getCU(); |
---|
[1289] | 120 | const TComSPS &sps = *(pcCU->getSlice()->getSPS()); |
---|
[1029] | 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 | |
---|
[1290] | 127 | const Int iBaseUnitSize = sps.getMaxCUWidth() >> sps.getMaxTotalCUDepth(); |
---|
[1029] | 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; |
---|
[1287] | 134 | #if SVC_EXTENSION |
---|
| 135 | const Int bitDepthForChannel = pcCU->getSlice()->getBitDepth(chType); |
---|
| 136 | #else |
---|
[1289] | 137 | const Int bitDepthForChannel = sps.getBitDepth(chType); |
---|
[1287] | 138 | #endif |
---|
[1029] | 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); |
---|
[313] | 148 | Bool bNeighborFlags[4 * MAX_NUM_SPU_W + 1]; |
---|
| 149 | Int iNumIntraNeighbor = 0; |
---|
| 150 | |
---|
[1029] | 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) ); |
---|
[313] | 157 | |
---|
| 158 | bAbove = true; |
---|
| 159 | bLeft = true; |
---|
| 160 | |
---|
[1029] | 161 | const UInt uiROIWidth = uiTuWidth2+1; |
---|
| 162 | const UInt uiROIHeight = uiTuHeight2+1; |
---|
[313] | 163 | |
---|
[1029] | 164 | assert(uiROIWidth*uiROIHeight <= m_iYuvExtSize); |
---|
[313] | 165 | |
---|
[1029] | 166 | #ifdef DEBUG_STRING |
---|
| 167 | std::stringstream ss(stringstream::out); |
---|
| 168 | #endif |
---|
[313] | 169 | |
---|
| 170 | { |
---|
[1029] | 171 | Pel *piAdiTemp = 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 |
---|
[1289] | 174 | const Int bitDepthForChannelInStream = sps.getStreamBitDepth(chType); |
---|
[1307] | 175 | fillReferenceSamples (bitDepthForChannelInStream, bitDepthForChannelInStream - bitDepthForChannel, |
---|
[1029] | 176 | #else |
---|
[1307] | 177 | fillReferenceSamples (bitDepthForChannel, |
---|
[1029] | 178 | #endif |
---|
[1307] | 179 | piRoiOrigin, piAdiTemp, bNeighborFlags, iNumIntraNeighbor, iUnitWidth, iUnitHeight, iAboveUnits, iLeftUnits, |
---|
| 180 | uiROIWidth, uiROIHeight, iPicStride); |
---|
[313] | 181 | |
---|
[1029] | 182 | |
---|
| 183 | #ifdef DEBUG_STRING |
---|
| 184 | if (DebugOptionList::DebugString_Pred.getInt()&DebugStringGetPredModeMask(MODE_INTRA)) |
---|
[313] | 185 | { |
---|
[1029] | 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++) |
---|
[313] | 188 | { |
---|
[1029] | 189 | ss << "###: - "; |
---|
| 190 | for (UInt x=0; x<uiROIWidth; x++) |
---|
| 191 | { |
---|
| 192 | if (x==0 || y==0) |
---|
[1246] | 193 | { |
---|
[1029] | 194 | ss << piAdiTemp[y*uiROIWidth + x] << ", "; |
---|
| 195 | // if (x%16==15) ss << "\nPart size: ~ "; |
---|
[1246] | 196 | } |
---|
[1029] | 197 | } |
---|
| 198 | ss << "\n"; |
---|
[313] | 199 | } |
---|
[1029] | 200 | } |
---|
| 201 | #endif |
---|
| 202 | |
---|
| 203 | if (bFilterRefSamples) |
---|
| 204 | { |
---|
| 205 | // generate filtered intra prediction samples |
---|
| 206 | |
---|
| 207 | Int stride = uiROIWidth; |
---|
| 208 | const Pel *piSrcPtr = piAdiTemp + (stride * uiTuHeight2); // bottom left |
---|
| 209 | Pel *piDestPtr = m_piYuvExt[compID][PRED_BUF_FILTERED] + (stride * uiTuHeight2); // bottom left |
---|
| 210 | |
---|
| 211 | //------------------------------------------------ |
---|
| 212 | |
---|
[1289] | 213 | Bool useStrongIntraSmoothing = isLuma(chType) && sps.getUseStrongIntraSmoothing(); |
---|
[1029] | 214 | |
---|
| 215 | const Pel bottomLeft = piAdiTemp[stride * uiTuHeight2]; |
---|
| 216 | const Pel topLeft = piAdiTemp[0]; |
---|
| 217 | const Pel topRight = piAdiTemp[uiTuWidth2]; |
---|
| 218 | |
---|
| 219 | if (useStrongIntraSmoothing) |
---|
[313] | 220 | { |
---|
[1029] | 221 | #if O0043_BEST_EFFORT_DECODING |
---|
[1287] | 222 | const Int threshold = 1 << (bitDepthForChannelInStream - 5); |
---|
[1029] | 223 | #else |
---|
[1287] | 224 | const Int threshold = 1 << (bitDepthForChannel - 5); |
---|
[1029] | 225 | #endif |
---|
| 226 | const Bool bilinearLeft = abs((bottomLeft + topLeft ) - (2 * piAdiTemp[stride * uiTuHeight])) < threshold; //difference between the |
---|
| 227 | const Bool bilinearAbove = abs((topLeft + topRight) - (2 * piAdiTemp[ uiTuWidth ])) < threshold; //ends and the middle |
---|
| 228 | if ((uiTuWidth < 32) || (!bilinearLeft) || (!bilinearAbove)) |
---|
[1246] | 229 | { |
---|
[1029] | 230 | useStrongIntraSmoothing = false; |
---|
[1246] | 231 | } |
---|
[313] | 232 | } |
---|
[1029] | 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 | #ifdef DEBUG_STRING |
---|
| 304 | if (DebugOptionList::DebugString_Pred.getInt()&DebugStringGetPredModeMask(MODE_INTRA)) |
---|
[313] | 305 | { |
---|
[1029] | 306 | ss << "###: filtered result for channel " << compID <<"\n"; |
---|
| 307 | for (UInt y=0; y<uiROIHeight; y++) |
---|
[313] | 308 | { |
---|
[1029] | 309 | ss << "###: - "; |
---|
| 310 | for (UInt x=0; x<uiROIWidth; x++) |
---|
| 311 | { |
---|
| 312 | if (x==0 || y==0) |
---|
[1246] | 313 | { |
---|
[1029] | 314 | ss << m_piYuvExt[compID][PRED_BUF_FILTERED][y*uiROIWidth + x] << ", "; |
---|
| 315 | // if (x%16==15) ss << "\nPart size: ~ "; |
---|
[1246] | 316 | } |
---|
[1029] | 317 | } |
---|
| 318 | ss << "\n"; |
---|
[313] | 319 | } |
---|
| 320 | } |
---|
[1029] | 321 | #endif |
---|
[313] | 322 | |
---|
| 323 | |
---|
[1029] | 324 | } |
---|
[313] | 325 | } |
---|
[1029] | 326 | DEBUG_STRING_APPEND(sDebug, ss.str()) |
---|
[313] | 327 | } |
---|
| 328 | |
---|
[1307] | 329 | Void fillReferenceSamples( const Int bitDepth, |
---|
[1029] | 330 | #if O0043_BEST_EFFORT_DECODING |
---|
[1307] | 331 | const Int bitDepthDelta, |
---|
[1029] | 332 | #endif |
---|
[1307] | 333 | const Pel* piRoiOrigin, |
---|
| 334 | Pel* piAdiTemp, |
---|
| 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 ) |
---|
[313] | 344 | { |
---|
[1029] | 345 | const Pel* piRoiTemp; |
---|
[313] | 346 | Int i, j; |
---|
| 347 | Int iDCValue = 1 << (bitDepth - 1); |
---|
[1029] | 348 | const Int iTotalUnits = iAboveUnits + iLeftUnits + 1; //+1 for top-left |
---|
[313] | 349 | |
---|
| 350 | if (iNumIntraNeighbor == 0) |
---|
| 351 | { |
---|
| 352 | // Fill border with DC value |
---|
| 353 | for (i=0; i<uiWidth; i++) |
---|
| 354 | { |
---|
| 355 | piAdiTemp[i] = iDCValue; |
---|
| 356 | } |
---|
| 357 | for (i=1; i<uiHeight; i++) |
---|
| 358 | { |
---|
| 359 | piAdiTemp[i*uiWidth] = iDCValue; |
---|
| 360 | } |
---|
| 361 | } |
---|
| 362 | else if (iNumIntraNeighbor == iTotalUnits) |
---|
| 363 | { |
---|
[1029] | 364 | // Fill top-left border and top and top right with rec. samples |
---|
[313] | 365 | piRoiTemp = piRoiOrigin - iPicStride - 1; |
---|
| 366 | |
---|
[1029] | 367 | for (i=0; i<uiWidth; i++) |
---|
[313] | 368 | { |
---|
[1029] | 369 | #if O0043_BEST_EFFORT_DECODING |
---|
| 370 | piAdiTemp[i] = piRoiTemp[i] << bitDepthDelta; |
---|
| 371 | #else |
---|
| 372 | piAdiTemp[i] = piRoiTemp[i]; |
---|
| 373 | #endif |
---|
[313] | 374 | } |
---|
| 375 | |
---|
[1029] | 376 | // Fill left and below left border with rec. samples |
---|
| 377 | piRoiTemp = piRoiOrigin - 1; |
---|
[313] | 378 | |
---|
[1029] | 379 | for (i=1; i<uiHeight; i++) |
---|
[313] | 380 | { |
---|
[1029] | 381 | #if O0043_BEST_EFFORT_DECODING |
---|
| 382 | piAdiTemp[i*uiWidth] = (*(piRoiTemp)) << bitDepthDelta; |
---|
| 383 | #else |
---|
| 384 | piAdiTemp[i*uiWidth] = *(piRoiTemp); |
---|
| 385 | #endif |
---|
[313] | 386 | piRoiTemp += iPicStride; |
---|
| 387 | } |
---|
| 388 | } |
---|
| 389 | else // reference samples are partially available |
---|
| 390 | { |
---|
[1029] | 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); |
---|
[313] | 393 | Pel piAdiLine[5 * MAX_CU_SIZE]; |
---|
[1029] | 394 | Pel *piAdiLineTemp; |
---|
| 395 | const Bool *pbNeighborFlags; |
---|
[313] | 396 | |
---|
[1029] | 397 | |
---|
[313] | 398 | // Initialize |
---|
| 399 | for (i=0; i<iTotalSamples; i++) |
---|
| 400 | { |
---|
| 401 | piAdiLine[i] = iDCValue; |
---|
| 402 | } |
---|
[1029] | 403 | |
---|
[313] | 404 | // Fill top-left sample |
---|
| 405 | piRoiTemp = piRoiOrigin - iPicStride - 1; |
---|
[1029] | 406 | piAdiLineTemp = piAdiLine + (iLeftUnits * unitHeight); |
---|
| 407 | pbNeighborFlags = bNeighborFlags + iLeftUnits; |
---|
[313] | 408 | if (*pbNeighborFlags) |
---|
| 409 | { |
---|
[1029] | 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++) |
---|
[313] | 416 | { |
---|
[1029] | 417 | piAdiLineTemp[i] = topLeftVal; |
---|
[313] | 418 | } |
---|
| 419 | } |
---|
| 420 | |
---|
[1029] | 421 | // Fill left & below-left samples (downwards) |
---|
[313] | 422 | piRoiTemp += iPicStride; |
---|
| 423 | piAdiLineTemp--; |
---|
| 424 | pbNeighborFlags--; |
---|
[1029] | 425 | |
---|
| 426 | for (j=0; j<iLeftUnits; j++) |
---|
[313] | 427 | { |
---|
| 428 | if (*pbNeighborFlags) |
---|
| 429 | { |
---|
[1029] | 430 | for (i=0; i<unitHeight; i++) |
---|
[313] | 431 | { |
---|
[1029] | 432 | #if O0043_BEST_EFFORT_DECODING |
---|
| 433 | piAdiLineTemp[-i] = piRoiTemp[i*iPicStride] << bitDepthDelta; |
---|
| 434 | #else |
---|
[313] | 435 | piAdiLineTemp[-i] = piRoiTemp[i*iPicStride]; |
---|
[1029] | 436 | #endif |
---|
[313] | 437 | } |
---|
| 438 | } |
---|
[1029] | 439 | piRoiTemp += unitHeight*iPicStride; |
---|
| 440 | piAdiLineTemp -= unitHeight; |
---|
[313] | 441 | pbNeighborFlags--; |
---|
| 442 | } |
---|
| 443 | |
---|
[1029] | 444 | // Fill above & above-right samples (left-to-right) (each unit has "unitWidth" samples) |
---|
[313] | 445 | piRoiTemp = piRoiOrigin - iPicStride; |
---|
[1029] | 446 | // offset line buffer by iNumUints2*unitHeight (for left/below-left) + unitWidth (for above-left) |
---|
| 447 | piAdiLineTemp = piAdiLine + (iLeftUnits * unitHeight) + unitWidth; |
---|
| 448 | pbNeighborFlags = bNeighborFlags + iLeftUnits + 1; |
---|
| 449 | for (j=0; j<iAboveUnits; j++) |
---|
[313] | 450 | { |
---|
| 451 | if (*pbNeighborFlags) |
---|
| 452 | { |
---|
[1029] | 453 | for (i=0; i<unitWidth; i++) |
---|
[313] | 454 | { |
---|
[1029] | 455 | #if O0043_BEST_EFFORT_DECODING |
---|
| 456 | piAdiLineTemp[i] = piRoiTemp[i] << bitDepthDelta; |
---|
| 457 | #else |
---|
[313] | 458 | piAdiLineTemp[i] = piRoiTemp[i]; |
---|
[1029] | 459 | #endif |
---|
[313] | 460 | } |
---|
| 461 | } |
---|
[1029] | 462 | piRoiTemp += unitWidth; |
---|
| 463 | piAdiLineTemp += unitWidth; |
---|
[313] | 464 | pbNeighborFlags++; |
---|
| 465 | } |
---|
| 466 | |
---|
| 467 | // Pad reference samples when necessary |
---|
[1029] | 468 | Int iCurrJnit = 0; |
---|
| 469 | Pel *piAdiLineCur = piAdiLine; |
---|
| 470 | const UInt piAdiLineTopRowOffset = iLeftUnits * (unitHeight - unitWidth); |
---|
| 471 | |
---|
| 472 | if (!bNeighborFlags[0]) |
---|
[313] | 473 | { |
---|
[1029] | 474 | // very bottom unit of bottom-left; at least one unit will be valid. |
---|
[313] | 475 | { |
---|
[1029] | 476 | Int iNext = 1; |
---|
| 477 | while (iNext < iTotalUnits && !bNeighborFlags[iNext]) |
---|
[313] | 478 | { |
---|
[1029] | 479 | iNext++; |
---|
| 480 | } |
---|
| 481 | Pel *piAdiLineNext = piAdiLine + ((iNext < iLeftUnits) ? (iNext * unitHeight) : (piAdiLineTopRowOffset + (iNext * unitWidth))); |
---|
| 482 | const Pel refSample = *piAdiLineNext; |
---|
| 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++) |
---|
[313] | 489 | { |
---|
[1029] | 490 | piAdiLineCur[i] = refSample; |
---|
[313] | 491 | } |
---|
[1029] | 492 | piAdiLineCur += unitHeight; |
---|
| 493 | iCurrJnit++; |
---|
| 494 | } |
---|
| 495 | // fill top row |
---|
| 496 | while (iCurrJnit < iNext) |
---|
| 497 | { |
---|
| 498 | for (i=0; i<unitWidth; i++) |
---|
[313] | 499 | { |
---|
[1029] | 500 | piAdiLineCur[i] = refSample; |
---|
[313] | 501 | } |
---|
[1029] | 502 | piAdiLineCur += unitWidth; |
---|
| 503 | iCurrJnit++; |
---|
[313] | 504 | } |
---|
[1029] | 505 | } |
---|
| 506 | } |
---|
| 507 | |
---|
| 508 | // pad all other reference samples. |
---|
| 509 | while (iCurrJnit < iTotalUnits) |
---|
| 510 | { |
---|
| 511 | if (!bNeighborFlags[iCurrJnit]) // samples not available |
---|
| 512 | { |
---|
[313] | 513 | { |
---|
[1029] | 514 | const Int numSamplesInCurrUnit = (iCurrJnit >= iLeftUnits) ? unitWidth : unitHeight; |
---|
| 515 | const Pel refSample = *(piAdiLineCur-1); |
---|
| 516 | for (i=0; i<numSamplesInCurrUnit; i++) |
---|
[313] | 517 | { |
---|
[1029] | 518 | piAdiLineCur[i] = refSample; |
---|
[313] | 519 | } |
---|
[1029] | 520 | piAdiLineCur += numSamplesInCurrUnit; |
---|
| 521 | iCurrJnit++; |
---|
[313] | 522 | } |
---|
| 523 | } |
---|
| 524 | else |
---|
| 525 | { |
---|
[1029] | 526 | piAdiLineCur += (iCurrJnit >= iLeftUnits) ? unitWidth : unitHeight; |
---|
| 527 | iCurrJnit++; |
---|
[313] | 528 | } |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | // Copy processed samples |
---|
[1029] | 532 | |
---|
| 533 | piAdiLineTemp = piAdiLine + uiHeight + unitWidth - 2; |
---|
| 534 | // top left, top and top right samples |
---|
[313] | 535 | for (i=0; i<uiWidth; i++) |
---|
| 536 | { |
---|
| 537 | piAdiTemp[i] = piAdiLineTemp[i]; |
---|
| 538 | } |
---|
[1029] | 539 | |
---|
[313] | 540 | piAdiLineTemp = piAdiLine + uiHeight - 1; |
---|
| 541 | for (i=1; i<uiHeight; i++) |
---|
| 542 | { |
---|
| 543 | piAdiTemp[i*uiWidth] = piAdiLineTemp[-i]; |
---|
| 544 | } |
---|
| 545 | } |
---|
| 546 | } |
---|
| 547 | |
---|
[1029] | 548 | Bool TComPrediction::filteringIntraReferenceSamples(const ComponentID compID, UInt uiDirMode, UInt uiTuChWidth, UInt uiTuChHeight, const ChromaFormat chFmt, const Bool intraReferenceSmoothingDisabled) |
---|
[313] | 549 | { |
---|
[1029] | 550 | Bool bFilter; |
---|
| 551 | |
---|
| 552 | if (!filterIntraReferenceSamples(toChannelType(compID), chFmt, intraReferenceSmoothingDisabled)) |
---|
[313] | 553 | { |
---|
[1029] | 554 | bFilter=false; |
---|
[313] | 555 | } |
---|
[1029] | 556 | else |
---|
| 557 | { |
---|
| 558 | assert(uiTuChWidth>=4 && uiTuChHeight>=4 && uiTuChWidth<128 && uiTuChHeight<128); |
---|
[313] | 559 | |
---|
[1029] | 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 | } |
---|
[313] | 571 | } |
---|
[1029] | 572 | return bFilter; |
---|
[313] | 573 | } |
---|
| 574 | |
---|
[1029] | 575 | Bool isAboveLeftAvailable( TComDataCU* pcCU, UInt uiPartIdxLT ) |
---|
[313] | 576 | { |
---|
| 577 | Bool bAboveLeftFlag; |
---|
| 578 | UInt uiPartAboveLeft; |
---|
| 579 | TComDataCU* pcCUAboveLeft = pcCU->getPUAboveLeft( uiPartAboveLeft, uiPartIdxLT ); |
---|
| 580 | if(pcCU->getSlice()->getPPS()->getConstrainedIntraPred()) |
---|
| 581 | { |
---|
[1029] | 582 | bAboveLeftFlag = ( pcCUAboveLeft && pcCUAboveLeft->isIntra( uiPartAboveLeft ) ); |
---|
[313] | 583 | } |
---|
| 584 | else |
---|
| 585 | { |
---|
| 586 | bAboveLeftFlag = (pcCUAboveLeft ? true : false); |
---|
| 587 | } |
---|
| 588 | return bAboveLeftFlag; |
---|
| 589 | } |
---|
| 590 | |
---|
[1029] | 591 | Int isAboveAvailable( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxRT, Bool *bValidFlags ) |
---|
[313] | 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 | { |
---|
[1029] | 605 | if ( pcCUAbove && pcCUAbove->isIntra( uiPartAbove ) ) |
---|
[313] | 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 | |
---|
[1029] | 632 | Int isLeftAvailable( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxLB, Bool *bValidFlags ) |
---|
[313] | 633 | { |
---|
| 634 | const UInt uiRasterPartBegin = g_auiZscanToRaster[uiPartIdxLT]; |
---|
| 635 | const UInt uiRasterPartEnd = g_auiZscanToRaster[uiPartIdxLB]+1; |
---|
[1029] | 636 | const UInt uiIdxStep = pcCU->getPic()->getNumPartInCtuWidth(); |
---|
[313] | 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 | { |
---|
[1029] | 646 | if ( pcCULeft && pcCULeft->isIntra( uiPartLeft ) ) |
---|
[313] | 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 | |
---|
[1029] | 674 | Int isAboveRightAvailable( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxRT, Bool *bValidFlags ) |
---|
[313] | 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->getPUAboveRightAdi( uiPartAboveRight, uiPartIdxRT, uiOffset ); |
---|
| 684 | if(pcCU->getSlice()->getPPS()->getConstrainedIntraPred()) |
---|
| 685 | { |
---|
[1029] | 686 | if ( pcCUAboveRight && pcCUAboveRight->isIntra( uiPartAboveRight ) ) |
---|
[313] | 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 | |
---|
[1029] | 714 | Int isBelowLeftAvailable( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxLB, Bool *bValidFlags ) |
---|
[313] | 715 | { |
---|
[1029] | 716 | const UInt uiNumUnitsInPU = (g_auiZscanToRaster[uiPartIdxLB] - g_auiZscanToRaster[uiPartIdxLT]) / pcCU->getPic()->getNumPartInCtuWidth() + 1; |
---|
[313] | 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->getPUBelowLeftAdi( uiPartBelowLeft, uiPartIdxLB, uiOffset ); |
---|
| 724 | if(pcCU->getSlice()->getPPS()->getConstrainedIntraPred()) |
---|
| 725 | { |
---|
[1029] | 726 | if ( pcCUBelowLeft && pcCUBelowLeft->isIntra( uiPartBelowLeft ) ) |
---|
[313] | 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 | //! \} |
---|