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