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