[5] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
[56] | 4 | * granted under this license. |
---|
[5] | 5 | * |
---|
[608] | 6 | * Copyright (c) 2010-2013, ITU/ISO/IEC |
---|
[5] | 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
[56] | 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
[5] | 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
[2] | 33 | |
---|
| 34 | /** \file TComLoopFilter.cpp |
---|
| 35 | \brief deblocking filter |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include "TComLoopFilter.h" |
---|
| 39 | #include "TComSlice.h" |
---|
| 40 | #include "TComMv.h" |
---|
| 41 | |
---|
[56] | 42 | //! \ingroup TLibCommon |
---|
| 43 | //! \{ |
---|
| 44 | |
---|
[2] | 45 | // ==================================================================================================================== |
---|
| 46 | // Constants |
---|
| 47 | // ==================================================================================================================== |
---|
| 48 | |
---|
| 49 | #define EDGE_VER 0 |
---|
| 50 | #define EDGE_HOR 1 |
---|
[608] | 51 | #define QpUV(iQpY) ( ((iQpY) < 0) ? (iQpY) : (((iQpY) > 57) ? ((iQpY)-6) : g_aucChromaScale[(iQpY)]) ) |
---|
[2] | 52 | |
---|
[56] | 53 | #define DEFAULT_INTRA_TC_OFFSET 2 ///< Default intra TC offset |
---|
[2] | 54 | |
---|
| 55 | // ==================================================================================================================== |
---|
| 56 | // Tables |
---|
| 57 | // ==================================================================================================================== |
---|
| 58 | |
---|
[608] | 59 | const UChar TComLoopFilter::sm_tcTable[54] = |
---|
[2] | 60 | { |
---|
[608] | 61 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,5,5,6,6,7,8,9,10,11,13,14,16,18,20,22,24 |
---|
[2] | 62 | }; |
---|
| 63 | |
---|
[608] | 64 | const UChar TComLoopFilter::sm_betaTable[52] = |
---|
[2] | 65 | { |
---|
| 66 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,7,8,9,10,11,12,13,14,15,16,17,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64 |
---|
| 67 | }; |
---|
| 68 | |
---|
| 69 | // ==================================================================================================================== |
---|
| 70 | // Constructor / destructor / create / destroy |
---|
| 71 | // ==================================================================================================================== |
---|
| 72 | |
---|
| 73 | TComLoopFilter::TComLoopFilter() |
---|
[608] | 74 | : m_uiNumPartitions(0) |
---|
| 75 | , m_bLFCrossTileBoundary(true) |
---|
[2] | 76 | { |
---|
[608] | 77 | for( UInt uiDir = 0; uiDir < 2; uiDir++ ) |
---|
| 78 | { |
---|
| 79 | m_aapucBS [uiDir] = NULL; |
---|
| 80 | m_aapbEdgeFilter[uiDir] = NULL; |
---|
| 81 | } |
---|
[2] | 82 | } |
---|
| 83 | |
---|
| 84 | TComLoopFilter::~TComLoopFilter() |
---|
| 85 | { |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | // ==================================================================================================================== |
---|
| 89 | // Public member functions |
---|
| 90 | // ==================================================================================================================== |
---|
[608] | 91 | Void TComLoopFilter::setCfg( Bool bLFCrossTileBoundary ) |
---|
[2] | 92 | { |
---|
[56] | 93 | m_bLFCrossTileBoundary = bLFCrossTileBoundary; |
---|
[2] | 94 | } |
---|
| 95 | |
---|
| 96 | Void TComLoopFilter::create( UInt uiMaxCUDepth ) |
---|
| 97 | { |
---|
[608] | 98 | destroy(); |
---|
[2] | 99 | m_uiNumPartitions = 1 << ( uiMaxCUDepth<<1 ); |
---|
| 100 | for( UInt uiDir = 0; uiDir < 2; uiDir++ ) |
---|
| 101 | { |
---|
[56] | 102 | m_aapucBS [uiDir] = new UChar[m_uiNumPartitions]; |
---|
[608] | 103 | m_aapbEdgeFilter[uiDir] = new Bool [m_uiNumPartitions]; |
---|
[2] | 104 | } |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | Void TComLoopFilter::destroy() |
---|
| 108 | { |
---|
| 109 | for( UInt uiDir = 0; uiDir < 2; uiDir++ ) |
---|
| 110 | { |
---|
[608] | 111 | if (m_aapucBS) |
---|
[2] | 112 | { |
---|
[608] | 113 | delete [] m_aapucBS [uiDir]; |
---|
| 114 | m_aapucBS [uiDir] = NULL; |
---|
[2] | 115 | } |
---|
[608] | 116 | if (m_aapbEdgeFilter[uiDir]) |
---|
| 117 | { |
---|
| 118 | delete [] m_aapbEdgeFilter[uiDir]; |
---|
| 119 | m_aapbEdgeFilter[uiDir] = NULL; |
---|
| 120 | } |
---|
[2] | 121 | } |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | /** |
---|
| 125 | - call deblocking function for every CU |
---|
| 126 | . |
---|
| 127 | \param pcPic picture class (TComPic) pointer |
---|
| 128 | */ |
---|
| 129 | Void TComLoopFilter::loopFilterPic( TComPic* pcPic ) |
---|
| 130 | { |
---|
| 131 | // Horizontal filtering |
---|
| 132 | for ( UInt uiCUAddr = 0; uiCUAddr < pcPic->getNumCUsInFrame(); uiCUAddr++ ) |
---|
| 133 | { |
---|
| 134 | TComDataCU* pcCU = pcPic->getCU( uiCUAddr ); |
---|
| 135 | |
---|
[56] | 136 | ::memset( m_aapucBS [EDGE_VER], 0, sizeof( UChar ) * m_uiNumPartitions ); |
---|
[608] | 137 | ::memset( m_aapbEdgeFilter[EDGE_VER], 0, sizeof( Bool ) * m_uiNumPartitions ); |
---|
[2] | 138 | |
---|
| 139 | // CU-based deblocking |
---|
| 140 | xDeblockCU( pcCU, 0, 0, EDGE_VER ); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | // Vertical filtering |
---|
| 144 | for ( UInt uiCUAddr = 0; uiCUAddr < pcPic->getNumCUsInFrame(); uiCUAddr++ ) |
---|
| 145 | { |
---|
| 146 | TComDataCU* pcCU = pcPic->getCU( uiCUAddr ); |
---|
| 147 | |
---|
[608] | 148 | ::memset( m_aapucBS [EDGE_HOR], 0, sizeof( UChar ) * m_uiNumPartitions ); |
---|
| 149 | ::memset( m_aapbEdgeFilter[EDGE_HOR], 0, sizeof( Bool ) * m_uiNumPartitions ); |
---|
[2] | 150 | |
---|
| 151 | // CU-based deblocking |
---|
| 152 | xDeblockCU( pcCU, 0, 0, EDGE_HOR ); |
---|
| 153 | } |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | |
---|
| 157 | // ==================================================================================================================== |
---|
| 158 | // Protected member functions |
---|
| 159 | // ==================================================================================================================== |
---|
| 160 | |
---|
| 161 | /** |
---|
| 162 | - Deblocking filter process in CU-based (the same function as conventional's) |
---|
| 163 | . |
---|
| 164 | \param Edge the direction of the edge in block boundary (horizonta/vertical), which is added newly |
---|
| 165 | */ |
---|
| 166 | Void TComLoopFilter::xDeblockCU( TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth, Int Edge ) |
---|
| 167 | { |
---|
[56] | 168 | if(pcCU->getPic()==0||pcCU->getPartitionSize(uiAbsZorderIdx)==SIZE_NONE) |
---|
| 169 | { |
---|
| 170 | return; |
---|
| 171 | } |
---|
[2] | 172 | TComPic* pcPic = pcCU->getPic(); |
---|
| 173 | UInt uiCurNumParts = pcPic->getNumPartInCU() >> (uiDepth<<1); |
---|
| 174 | UInt uiQNumParts = uiCurNumParts>>2; |
---|
| 175 | |
---|
| 176 | if( pcCU->getDepth(uiAbsZorderIdx) > uiDepth ) |
---|
| 177 | { |
---|
| 178 | for ( UInt uiPartIdx = 0; uiPartIdx < 4; uiPartIdx++, uiAbsZorderIdx+=uiQNumParts ) |
---|
| 179 | { |
---|
| 180 | UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsZorderIdx] ]; |
---|
| 181 | UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsZorderIdx] ]; |
---|
[56] | 182 | if( ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
| 183 | { |
---|
[2] | 184 | xDeblockCU( pcCU, uiAbsZorderIdx, uiDepth+1, Edge ); |
---|
[56] | 185 | } |
---|
[2] | 186 | } |
---|
| 187 | return; |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | xSetLoopfilterParam( pcCU, uiAbsZorderIdx ); |
---|
| 191 | |
---|
[56] | 192 | xSetEdgefilterTU ( pcCU, uiAbsZorderIdx , uiAbsZorderIdx, uiDepth ); |
---|
[2] | 193 | xSetEdgefilterPU ( pcCU, uiAbsZorderIdx ); |
---|
| 194 | |
---|
| 195 | Int iDir = Edge; |
---|
[56] | 196 | for( UInt uiPartIdx = uiAbsZorderIdx; uiPartIdx < uiAbsZorderIdx + uiCurNumParts; uiPartIdx++ ) |
---|
[2] | 197 | { |
---|
[608] | 198 | UInt uiBSCheck; |
---|
| 199 | if( (g_uiMaxCUWidth >> g_uiMaxCUDepth) == 4 ) |
---|
[2] | 200 | { |
---|
[608] | 201 | uiBSCheck = (iDir == EDGE_VER && uiPartIdx%2 == 0) || (iDir == EDGE_HOR && (uiPartIdx-((uiPartIdx>>2)<<2))/2 == 0); |
---|
[2] | 202 | } |
---|
[608] | 203 | else |
---|
| 204 | { |
---|
| 205 | uiBSCheck = 1; |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | if ( m_aapbEdgeFilter[iDir][uiPartIdx] && uiBSCheck ) |
---|
| 209 | { |
---|
| 210 | xGetBoundaryStrengthSingle ( pcCU, iDir, uiPartIdx ); |
---|
| 211 | } |
---|
[2] | 212 | } |
---|
| 213 | |
---|
| 214 | UInt uiPelsInPart = g_uiMaxCUWidth >> g_uiMaxCUDepth; |
---|
| 215 | UInt PartIdxIncr = DEBLOCK_SMALLEST_BLOCK / uiPelsInPart ? DEBLOCK_SMALLEST_BLOCK / uiPelsInPart : 1 ; |
---|
| 216 | |
---|
| 217 | UInt uiSizeInPU = pcPic->getNumPartInWidth()>>(uiDepth); |
---|
| 218 | |
---|
| 219 | for ( UInt iEdge = 0; iEdge < uiSizeInPU ; iEdge+=PartIdxIncr) |
---|
| 220 | { |
---|
[56] | 221 | xEdgeFilterLuma ( pcCU, uiAbsZorderIdx, uiDepth, iDir, iEdge ); |
---|
[608] | 222 | if ( (uiPelsInPart>DEBLOCK_SMALLEST_BLOCK) || (iEdge % ( (DEBLOCK_SMALLEST_BLOCK<<1)/uiPelsInPart ) ) == 0 ) |
---|
[2] | 223 | { |
---|
[56] | 224 | xEdgeFilterChroma ( pcCU, uiAbsZorderIdx, uiDepth, iDir, iEdge ); |
---|
[2] | 225 | } |
---|
[56] | 226 | } |
---|
| 227 | } |
---|
| 228 | |
---|
[608] | 229 | Void TComLoopFilter::xSetEdgefilterMultiple( TComDataCU* pcCU, UInt uiScanIdx, UInt uiDepth, Int iDir, Int iEdgeIdx, Bool bValue,UInt uiWidthInBaseUnits, UInt uiHeightInBaseUnits ) |
---|
[56] | 230 | { |
---|
| 231 | if ( uiWidthInBaseUnits == 0 ) |
---|
[2] | 232 | { |
---|
[56] | 233 | uiWidthInBaseUnits = pcCU->getPic()->getNumPartInWidth () >> uiDepth; |
---|
| 234 | } |
---|
| 235 | if ( uiHeightInBaseUnits == 0 ) |
---|
[2] | 236 | { |
---|
[56] | 237 | uiHeightInBaseUnits = pcCU->getPic()->getNumPartInHeight() >> uiDepth; |
---|
[2] | 238 | } |
---|
| 239 | const UInt uiNumElem = iDir == 0 ? uiHeightInBaseUnits : uiWidthInBaseUnits; |
---|
| 240 | assert( uiNumElem > 0 ); |
---|
[56] | 241 | assert( uiWidthInBaseUnits > 0 ); |
---|
| 242 | assert( uiHeightInBaseUnits > 0 ); |
---|
[2] | 243 | for( UInt ui = 0; ui < uiNumElem; ui++ ) |
---|
| 244 | { |
---|
[56] | 245 | const UInt uiBsIdx = xCalcBsIdx( pcCU, uiScanIdx, iDir, iEdgeIdx, ui ); |
---|
[608] | 246 | m_aapbEdgeFilter[iDir][uiBsIdx] = bValue; |
---|
[56] | 247 | if (iEdgeIdx == 0) |
---|
| 248 | { |
---|
| 249 | m_aapucBS[iDir][uiBsIdx] = bValue; |
---|
| 250 | } |
---|
[2] | 251 | } |
---|
| 252 | } |
---|
| 253 | |
---|
[56] | 254 | Void TComLoopFilter::xSetEdgefilterTU( TComDataCU* pcCU, UInt absTUPartIdx, UInt uiAbsZorderIdx, UInt uiDepth ) |
---|
[2] | 255 | { |
---|
| 256 | if( pcCU->getTransformIdx( uiAbsZorderIdx ) + pcCU->getDepth( uiAbsZorderIdx) > uiDepth ) |
---|
| 257 | { |
---|
| 258 | const UInt uiCurNumParts = pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1); |
---|
| 259 | const UInt uiQNumParts = uiCurNumParts>>2; |
---|
| 260 | for ( UInt uiPartIdx = 0; uiPartIdx < 4; uiPartIdx++, uiAbsZorderIdx+=uiQNumParts ) |
---|
| 261 | { |
---|
[608] | 262 | UInt nsAddr = uiAbsZorderIdx; |
---|
[56] | 263 | xSetEdgefilterTU( pcCU,nsAddr, uiAbsZorderIdx, uiDepth + 1 ); |
---|
[2] | 264 | } |
---|
| 265 | return; |
---|
| 266 | } |
---|
[56] | 267 | |
---|
| 268 | Int trWidth = pcCU->getWidth( uiAbsZorderIdx ) >> pcCU->getTransformIdx( uiAbsZorderIdx ); |
---|
| 269 | Int trHeight = pcCU->getHeight( uiAbsZorderIdx ) >> pcCU->getTransformIdx( uiAbsZorderIdx ); |
---|
[608] | 270 | |
---|
| 271 | UInt uiWidthInBaseUnits = trWidth / (g_uiMaxCUWidth >> g_uiMaxCUDepth); |
---|
| 272 | UInt uiHeightInBaseUnits = trHeight / (g_uiMaxCUWidth >> g_uiMaxCUDepth); |
---|
[56] | 273 | |
---|
| 274 | xSetEdgefilterMultiple( pcCU, absTUPartIdx, uiDepth, EDGE_VER, 0, m_stLFCUParam.bInternalEdge, uiWidthInBaseUnits, uiHeightInBaseUnits ); |
---|
| 275 | xSetEdgefilterMultiple( pcCU, absTUPartIdx, uiDepth, EDGE_HOR, 0, m_stLFCUParam.bInternalEdge, uiWidthInBaseUnits, uiHeightInBaseUnits ); |
---|
[2] | 276 | } |
---|
| 277 | |
---|
| 278 | Void TComLoopFilter::xSetEdgefilterPU( TComDataCU* pcCU, UInt uiAbsZorderIdx ) |
---|
| 279 | { |
---|
| 280 | const UInt uiDepth = pcCU->getDepth( uiAbsZorderIdx ); |
---|
| 281 | const UInt uiWidthInBaseUnits = pcCU->getPic()->getNumPartInWidth () >> uiDepth; |
---|
| 282 | const UInt uiHeightInBaseUnits = pcCU->getPic()->getNumPartInHeight() >> uiDepth; |
---|
| 283 | const UInt uiHWidthInBaseUnits = uiWidthInBaseUnits >> 1; |
---|
| 284 | const UInt uiHHeightInBaseUnits = uiHeightInBaseUnits >> 1; |
---|
[56] | 285 | const UInt uiQWidthInBaseUnits = uiWidthInBaseUnits >> 2; |
---|
| 286 | const UInt uiQHeightInBaseUnits = uiHeightInBaseUnits >> 2; |
---|
[2] | 287 | |
---|
| 288 | xSetEdgefilterMultiple( pcCU, uiAbsZorderIdx, uiDepth, EDGE_VER, 0, m_stLFCUParam.bLeftEdge ); |
---|
| 289 | xSetEdgefilterMultiple( pcCU, uiAbsZorderIdx, uiDepth, EDGE_HOR, 0, m_stLFCUParam.bTopEdge ); |
---|
| 290 | |
---|
| 291 | switch ( pcCU->getPartitionSize( uiAbsZorderIdx ) ) |
---|
| 292 | { |
---|
| 293 | case SIZE_2Nx2N: |
---|
| 294 | { |
---|
| 295 | break; |
---|
| 296 | } |
---|
| 297 | case SIZE_2NxN: |
---|
| 298 | { |
---|
| 299 | xSetEdgefilterMultiple( pcCU, uiAbsZorderIdx, uiDepth, EDGE_HOR, uiHHeightInBaseUnits, m_stLFCUParam.bInternalEdge ); |
---|
| 300 | break; |
---|
| 301 | } |
---|
| 302 | case SIZE_Nx2N: |
---|
| 303 | { |
---|
| 304 | xSetEdgefilterMultiple( pcCU, uiAbsZorderIdx, uiDepth, EDGE_VER, uiHWidthInBaseUnits, m_stLFCUParam.bInternalEdge ); |
---|
| 305 | break; |
---|
| 306 | } |
---|
| 307 | case SIZE_NxN: |
---|
| 308 | { |
---|
| 309 | xSetEdgefilterMultiple( pcCU, uiAbsZorderIdx, uiDepth, EDGE_VER, uiHWidthInBaseUnits, m_stLFCUParam.bInternalEdge ); |
---|
| 310 | xSetEdgefilterMultiple( pcCU, uiAbsZorderIdx, uiDepth, EDGE_HOR, uiHHeightInBaseUnits, m_stLFCUParam.bInternalEdge ); |
---|
| 311 | break; |
---|
| 312 | } |
---|
[56] | 313 | case SIZE_2NxnU: |
---|
| 314 | { |
---|
| 315 | xSetEdgefilterMultiple( pcCU, uiAbsZorderIdx, uiDepth, EDGE_HOR, uiQHeightInBaseUnits, m_stLFCUParam.bInternalEdge ); |
---|
| 316 | break; |
---|
| 317 | } |
---|
| 318 | case SIZE_2NxnD: |
---|
| 319 | { |
---|
| 320 | xSetEdgefilterMultiple( pcCU, uiAbsZorderIdx, uiDepth, EDGE_HOR, uiHeightInBaseUnits - uiQHeightInBaseUnits, m_stLFCUParam.bInternalEdge ); |
---|
| 321 | break; |
---|
| 322 | } |
---|
| 323 | case SIZE_nLx2N: |
---|
| 324 | { |
---|
| 325 | xSetEdgefilterMultiple( pcCU, uiAbsZorderIdx, uiDepth, EDGE_VER, uiQWidthInBaseUnits, m_stLFCUParam.bInternalEdge ); |
---|
| 326 | break; |
---|
| 327 | } |
---|
| 328 | case SIZE_nRx2N: |
---|
| 329 | { |
---|
| 330 | xSetEdgefilterMultiple( pcCU, uiAbsZorderIdx, uiDepth, EDGE_VER, uiWidthInBaseUnits - uiQWidthInBaseUnits, m_stLFCUParam.bInternalEdge ); |
---|
| 331 | break; |
---|
| 332 | } |
---|
[2] | 333 | default: |
---|
| 334 | { |
---|
| 335 | break; |
---|
| 336 | } |
---|
| 337 | } |
---|
| 338 | } |
---|
| 339 | |
---|
| 340 | |
---|
| 341 | Void TComLoopFilter::xSetLoopfilterParam( TComDataCU* pcCU, UInt uiAbsZorderIdx ) |
---|
| 342 | { |
---|
| 343 | UInt uiX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsZorderIdx ] ]; |
---|
| 344 | UInt uiY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsZorderIdx ] ]; |
---|
| 345 | |
---|
| 346 | TComDataCU* pcTempCU; |
---|
| 347 | UInt uiTempPartIdx; |
---|
| 348 | |
---|
[608] | 349 | m_stLFCUParam.bInternalEdge = ! pcCU->getSlice()->getDeblockingFilterDisable(); |
---|
[2] | 350 | |
---|
[608] | 351 | if ( (uiX == 0) || pcCU->getSlice()->getDeblockingFilterDisable() ) |
---|
[56] | 352 | { |
---|
[2] | 353 | m_stLFCUParam.bLeftEdge = false; |
---|
[56] | 354 | } |
---|
[2] | 355 | else |
---|
[56] | 356 | { |
---|
[2] | 357 | m_stLFCUParam.bLeftEdge = true; |
---|
[56] | 358 | } |
---|
[2] | 359 | if ( m_stLFCUParam.bLeftEdge ) |
---|
| 360 | { |
---|
[608] | 361 | pcTempCU = pcCU->getPULeft( uiTempPartIdx, uiAbsZorderIdx, !pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), !m_bLFCrossTileBoundary); |
---|
[2] | 362 | if ( pcTempCU ) |
---|
[56] | 363 | { |
---|
[2] | 364 | m_stLFCUParam.bLeftEdge = true; |
---|
[56] | 365 | } |
---|
[2] | 366 | else |
---|
[56] | 367 | { |
---|
[2] | 368 | m_stLFCUParam.bLeftEdge = false; |
---|
[56] | 369 | } |
---|
[2] | 370 | } |
---|
| 371 | |
---|
[608] | 372 | if ( (uiY == 0 ) || pcCU->getSlice()->getDeblockingFilterDisable() ) |
---|
[56] | 373 | { |
---|
[2] | 374 | m_stLFCUParam.bTopEdge = false; |
---|
[56] | 375 | } |
---|
[2] | 376 | else |
---|
[56] | 377 | { |
---|
[2] | 378 | m_stLFCUParam.bTopEdge = true; |
---|
[56] | 379 | } |
---|
[2] | 380 | if ( m_stLFCUParam.bTopEdge ) |
---|
| 381 | { |
---|
[608] | 382 | pcTempCU = pcCU->getPUAbove( uiTempPartIdx, uiAbsZorderIdx, !pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), false, !m_bLFCrossTileBoundary); |
---|
| 383 | |
---|
[2] | 384 | if ( pcTempCU ) |
---|
[56] | 385 | { |
---|
[2] | 386 | m_stLFCUParam.bTopEdge = true; |
---|
[56] | 387 | } |
---|
[2] | 388 | else |
---|
[56] | 389 | { |
---|
[2] | 390 | m_stLFCUParam.bTopEdge = false; |
---|
[56] | 391 | } |
---|
[2] | 392 | } |
---|
| 393 | } |
---|
| 394 | |
---|
[608] | 395 | Void TComLoopFilter::xGetBoundaryStrengthSingle ( TComDataCU* pcCU, Int iDir, UInt uiAbsPartIdx ) |
---|
[2] | 396 | { |
---|
| 397 | TComSlice* const pcSlice = pcCU->getSlice(); |
---|
| 398 | |
---|
| 399 | const UInt uiPartQ = uiAbsPartIdx; |
---|
| 400 | TComDataCU* const pcCUQ = pcCU; |
---|
| 401 | |
---|
| 402 | UInt uiPartP; |
---|
| 403 | TComDataCU* pcCUP; |
---|
[56] | 404 | UInt uiBs = 0; |
---|
[2] | 405 | |
---|
| 406 | //-- Calculate Block Index |
---|
| 407 | if (iDir == EDGE_VER) |
---|
| 408 | { |
---|
[608] | 409 | pcCUP = pcCUQ->getPULeft(uiPartP, uiPartQ, !pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), !m_bLFCrossTileBoundary); |
---|
[2] | 410 | } |
---|
| 411 | else // (iDir == EDGE_HOR) |
---|
| 412 | { |
---|
[608] | 413 | pcCUP = pcCUQ->getPUAbove(uiPartP, uiPartQ, !pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), false, !m_bLFCrossTileBoundary); |
---|
[2] | 414 | } |
---|
| 415 | |
---|
| 416 | //-- Set BS for Intra MB : BS = 4 or 3 |
---|
[608] | 417 | if ( pcCUP->isIntra(uiPartP) || pcCUQ->isIntra(uiPartQ) ) |
---|
[2] | 418 | { |
---|
[56] | 419 | uiBs = 2; |
---|
[2] | 420 | } |
---|
| 421 | |
---|
| 422 | //-- Set BS for not Intra MB : BS = 2 or 1 or 0 |
---|
[608] | 423 | if ( !pcCUP->isIntra(uiPartP) && !pcCUQ->isIntra(uiPartQ) ) |
---|
[2] | 424 | { |
---|
[56] | 425 | UInt nsPartQ = uiPartQ; |
---|
| 426 | UInt nsPartP = uiPartP; |
---|
[608] | 427 | |
---|
[56] | 428 | if ( m_aapucBS[iDir][uiAbsPartIdx] && (pcCUQ->getCbf( nsPartQ, TEXT_LUMA, pcCUQ->getTransformIdx(nsPartQ)) != 0 || pcCUP->getCbf( nsPartP, TEXT_LUMA, pcCUP->getTransformIdx(nsPartP) ) != 0) ) |
---|
| 429 | { |
---|
| 430 | uiBs = 1; |
---|
| 431 | } |
---|
[2] | 432 | else |
---|
| 433 | { |
---|
[56] | 434 | if (iDir == EDGE_HOR) |
---|
| 435 | { |
---|
[608] | 436 | pcCUP = pcCUQ->getPUAbove(uiPartP, uiPartQ, !pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), false, !m_bLFCrossTileBoundary); |
---|
[56] | 437 | } |
---|
[608] | 438 | if (pcSlice->isInterB() || pcCUP->getSlice()->isInterB()) |
---|
[2] | 439 | { |
---|
| 440 | Int iRefIdx; |
---|
[608] | 441 | TComPic *piRefP0, *piRefP1, *piRefQ0, *piRefQ1; |
---|
[2] | 442 | iRefIdx = pcCUP->getCUMvField(REF_PIC_LIST_0)->getRefIdx(uiPartP); |
---|
[608] | 443 | piRefP0 = (iRefIdx < 0) ? NULL : pcCUP->getSlice()->getRefPic(REF_PIC_LIST_0, iRefIdx); |
---|
[2] | 444 | iRefIdx = pcCUP->getCUMvField(REF_PIC_LIST_1)->getRefIdx(uiPartP); |
---|
[608] | 445 | piRefP1 = (iRefIdx < 0) ? NULL : pcCUP->getSlice()->getRefPic(REF_PIC_LIST_1, iRefIdx); |
---|
[2] | 446 | iRefIdx = pcCUQ->getCUMvField(REF_PIC_LIST_0)->getRefIdx(uiPartQ); |
---|
[608] | 447 | piRefQ0 = (iRefIdx < 0) ? NULL : pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx); |
---|
[2] | 448 | iRefIdx = pcCUQ->getCUMvField(REF_PIC_LIST_1)->getRefIdx(uiPartQ); |
---|
[608] | 449 | piRefQ1 = (iRefIdx < 0) ? NULL : pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx); |
---|
[2] | 450 | |
---|
| 451 | TComMv pcMvP0 = pcCUP->getCUMvField(REF_PIC_LIST_0)->getMv(uiPartP); |
---|
| 452 | TComMv pcMvP1 = pcCUP->getCUMvField(REF_PIC_LIST_1)->getMv(uiPartP); |
---|
| 453 | TComMv pcMvQ0 = pcCUQ->getCUMvField(REF_PIC_LIST_0)->getMv(uiPartQ); |
---|
| 454 | TComMv pcMvQ1 = pcCUQ->getCUMvField(REF_PIC_LIST_1)->getMv(uiPartQ); |
---|
[608] | 455 | |
---|
| 456 | if (piRefP0 == NULL) pcMvP0.setZero(); |
---|
| 457 | if (piRefP1 == NULL) pcMvP1.setZero(); |
---|
| 458 | if (piRefQ0 == NULL) pcMvQ0.setZero(); |
---|
| 459 | if (piRefQ1 == NULL) pcMvQ1.setZero(); |
---|
| 460 | |
---|
[2] | 461 | if ( ((piRefP0==piRefQ0)&&(piRefP1==piRefQ1)) || ((piRefP0==piRefQ1)&&(piRefP1==piRefQ0)) ) |
---|
| 462 | { |
---|
| 463 | if ( piRefP0 != piRefP1 ) // Different L0 & L1 |
---|
| 464 | { |
---|
| 465 | if ( piRefP0 == piRefQ0 ) |
---|
| 466 | { |
---|
[608] | 467 | uiBs = ((abs(pcMvQ0.getHor() - pcMvP0.getHor()) >= 4) || |
---|
| 468 | (abs(pcMvQ0.getVer() - pcMvP0.getVer()) >= 4) || |
---|
| 469 | (abs(pcMvQ1.getHor() - pcMvP1.getHor()) >= 4) || |
---|
| 470 | (abs(pcMvQ1.getVer() - pcMvP1.getVer()) >= 4)) ? 1 : 0; |
---|
[2] | 471 | } |
---|
| 472 | else |
---|
| 473 | { |
---|
[608] | 474 | uiBs = ((abs(pcMvQ1.getHor() - pcMvP0.getHor()) >= 4) || |
---|
| 475 | (abs(pcMvQ1.getVer() - pcMvP0.getVer()) >= 4) || |
---|
| 476 | (abs(pcMvQ0.getHor() - pcMvP1.getHor()) >= 4) || |
---|
| 477 | (abs(pcMvQ0.getVer() - pcMvP1.getVer()) >= 4)) ? 1 : 0; |
---|
[2] | 478 | } |
---|
| 479 | } |
---|
| 480 | else // Same L0 & L1 |
---|
| 481 | { |
---|
[608] | 482 | uiBs = ((abs(pcMvQ0.getHor() - pcMvP0.getHor()) >= 4) || |
---|
| 483 | (abs(pcMvQ0.getVer() - pcMvP0.getVer()) >= 4) || |
---|
| 484 | (abs(pcMvQ1.getHor() - pcMvP1.getHor()) >= 4) || |
---|
| 485 | (abs(pcMvQ1.getVer() - pcMvP1.getVer()) >= 4)) && |
---|
| 486 | ((abs(pcMvQ1.getHor() - pcMvP0.getHor()) >= 4) || |
---|
| 487 | (abs(pcMvQ1.getVer() - pcMvP0.getVer()) >= 4) || |
---|
| 488 | (abs(pcMvQ0.getHor() - pcMvP1.getHor()) >= 4) || |
---|
| 489 | (abs(pcMvQ0.getVer() - pcMvP1.getVer()) >= 4)) ? 1 : 0; |
---|
[2] | 490 | } |
---|
| 491 | } |
---|
| 492 | else // for all different Ref_Idx |
---|
| 493 | { |
---|
| 494 | uiBs = 1; |
---|
| 495 | } |
---|
| 496 | } |
---|
| 497 | else // pcSlice->isInterP() |
---|
| 498 | { |
---|
| 499 | Int iRefIdx; |
---|
[608] | 500 | TComPic *piRefP0, *piRefQ0; |
---|
[2] | 501 | iRefIdx = pcCUP->getCUMvField(REF_PIC_LIST_0)->getRefIdx(uiPartP); |
---|
[608] | 502 | piRefP0 = (iRefIdx < 0) ? NULL : pcCUP->getSlice()->getRefPic(REF_PIC_LIST_0, iRefIdx); |
---|
[2] | 503 | iRefIdx = pcCUQ->getCUMvField(REF_PIC_LIST_0)->getRefIdx(uiPartQ); |
---|
[608] | 504 | piRefQ0 = (iRefIdx < 0) ? NULL : pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx); |
---|
[2] | 505 | TComMv pcMvP0 = pcCUP->getCUMvField(REF_PIC_LIST_0)->getMv(uiPartP); |
---|
| 506 | TComMv pcMvQ0 = pcCUQ->getCUMvField(REF_PIC_LIST_0)->getMv(uiPartQ); |
---|
[608] | 507 | |
---|
| 508 | if (piRefP0 == NULL) pcMvP0.setZero(); |
---|
| 509 | if (piRefQ0 == NULL) pcMvQ0.setZero(); |
---|
[2] | 510 | |
---|
[608] | 511 | uiBs = ((piRefP0 != piRefQ0) || |
---|
| 512 | (abs(pcMvQ0.getHor() - pcMvP0.getHor()) >= 4) || |
---|
| 513 | (abs(pcMvQ0.getVer() - pcMvP0.getVer()) >= 4)) ? 1 : 0; |
---|
[2] | 514 | } |
---|
| 515 | } // enf of "if( one of BCBP == 0 )" |
---|
| 516 | } // enf of "if( not Intra )" |
---|
| 517 | |
---|
[56] | 518 | m_aapucBS[iDir][uiAbsPartIdx] = uiBs; |
---|
[2] | 519 | } |
---|
| 520 | |
---|
| 521 | |
---|
| 522 | Void TComLoopFilter::xEdgeFilterLuma( TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth, Int iDir, Int iEdge ) |
---|
| 523 | { |
---|
| 524 | TComPicYuv* pcPicYuvRec = pcCU->getPic()->getPicYuvRec(); |
---|
| 525 | Pel* piSrc = pcPicYuvRec->getLumaAddr( pcCU->getAddr(), uiAbsZorderIdx ); |
---|
| 526 | Pel* piTmpSrc = piSrc; |
---|
[56] | 527 | |
---|
[2] | 528 | Int iStride = pcPicYuvRec->getStride(); |
---|
[56] | 529 | Int iQP = 0; |
---|
| 530 | Int iQP_P = 0; |
---|
| 531 | Int iQP_Q = 0; |
---|
[2] | 532 | UInt uiNumParts = pcCU->getPic()->getNumPartInWidth()>>uiDepth; |
---|
| 533 | |
---|
| 534 | UInt uiPelsInPart = g_uiMaxCUWidth >> g_uiMaxCUDepth; |
---|
[56] | 535 | UInt uiBsAbsIdx = 0, uiBs = 0; |
---|
[2] | 536 | Int iOffset, iSrcStep; |
---|
[56] | 537 | |
---|
| 538 | Bool bPCMFilter = (pcCU->getSlice()->getSPS()->getUsePCM() && pcCU->getSlice()->getSPS()->getPCMFilterDisableFlag())? true : false; |
---|
| 539 | Bool bPartPNoFilter = false; |
---|
| 540 | Bool bPartQNoFilter = false; |
---|
| 541 | UInt uiPartPIdx = 0; |
---|
| 542 | UInt uiPartQIdx = 0; |
---|
| 543 | TComDataCU* pcCUP = pcCU; |
---|
| 544 | TComDataCU* pcCUQ = pcCU; |
---|
[608] | 545 | Int betaOffsetDiv2 = pcCUQ->getSlice()->getDeblockingFilterBetaOffsetDiv2(); |
---|
| 546 | Int tcOffsetDiv2 = pcCUQ->getSlice()->getDeblockingFilterTcOffsetDiv2(); |
---|
| 547 | |
---|
[2] | 548 | if (iDir == EDGE_VER) |
---|
| 549 | { |
---|
| 550 | iOffset = 1; |
---|
| 551 | iSrcStep = iStride; |
---|
| 552 | piTmpSrc += iEdge*uiPelsInPart; |
---|
| 553 | } |
---|
| 554 | else // (iDir == EDGE_HOR) |
---|
| 555 | { |
---|
| 556 | iOffset = iStride; |
---|
| 557 | iSrcStep = 1; |
---|
| 558 | piTmpSrc += iEdge*uiPelsInPart*iStride; |
---|
| 559 | } |
---|
| 560 | |
---|
[56] | 561 | for ( UInt iIdx = 0; iIdx < uiNumParts; iIdx++ ) |
---|
| 562 | { |
---|
| 563 | uiBsAbsIdx = xCalcBsIdx( pcCU, uiAbsZorderIdx, iDir, iEdge, iIdx); |
---|
| 564 | uiBs = m_aapucBS[iDir][uiBsAbsIdx]; |
---|
| 565 | if ( uiBs ) |
---|
[2] | 566 | { |
---|
[56] | 567 | iQP_Q = pcCU->getQP( uiBsAbsIdx ); |
---|
| 568 | uiPartQIdx = uiBsAbsIdx; |
---|
| 569 | // Derive neighboring PU index |
---|
| 570 | if (iDir == EDGE_VER) |
---|
| 571 | { |
---|
[608] | 572 | pcCUP = pcCUQ->getPULeft (uiPartPIdx, uiPartQIdx,!pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), !m_bLFCrossTileBoundary); |
---|
[56] | 573 | } |
---|
| 574 | else // (iDir == EDGE_HOR) |
---|
| 575 | { |
---|
[608] | 576 | pcCUP = pcCUQ->getPUAbove(uiPartPIdx, uiPartQIdx,!pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), false, !m_bLFCrossTileBoundary); |
---|
[56] | 577 | } |
---|
| 578 | |
---|
| 579 | iQP_P = pcCUP->getQP(uiPartPIdx); |
---|
| 580 | iQP = (iQP_P + iQP_Q + 1) >> 1; |
---|
[608] | 581 | Int iBitdepthScale = 1 << (g_bitDepthY-8); |
---|
[56] | 582 | |
---|
[608] | 583 | Int iIndexTC = Clip3(0, MAX_QP+DEFAULT_INTRA_TC_OFFSET, Int(iQP + DEFAULT_INTRA_TC_OFFSET*(uiBs-1) + (tcOffsetDiv2 << 1))); |
---|
| 584 | Int iIndexB = Clip3(0, MAX_QP, iQP + (betaOffsetDiv2 << 1)); |
---|
[56] | 585 | |
---|
[608] | 586 | Int iTc = sm_tcTable[iIndexTC]*iBitdepthScale; |
---|
| 587 | Int iBeta = sm_betaTable[iIndexB]*iBitdepthScale; |
---|
[56] | 588 | Int iSideThreshold = (iBeta+(iBeta>>1))>>3; |
---|
| 589 | Int iThrCut = iTc*10; |
---|
[608] | 590 | |
---|
| 591 | UInt uiBlocksInPart = uiPelsInPart / 4 ? uiPelsInPart / 4 : 1; |
---|
| 592 | for (UInt iBlkIdx = 0; iBlkIdx<uiBlocksInPart; iBlkIdx ++) |
---|
| 593 | { |
---|
| 594 | Int dp0 = xCalcDP( piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+iBlkIdx*4+0), iOffset); |
---|
| 595 | Int dq0 = xCalcDQ( piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+iBlkIdx*4+0), iOffset); |
---|
| 596 | Int dp3 = xCalcDP( piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+iBlkIdx*4+3), iOffset); |
---|
| 597 | Int dq3 = xCalcDQ( piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+iBlkIdx*4+3), iOffset); |
---|
[56] | 598 | Int d0 = dp0 + dq0; |
---|
| 599 | Int d3 = dp3 + dq3; |
---|
[608] | 600 | |
---|
[56] | 601 | Int dp = dp0 + dp3; |
---|
| 602 | Int dq = dq0 + dq3; |
---|
| 603 | Int d = d0 + d3; |
---|
| 604 | |
---|
[608] | 605 | if (bPCMFilter || pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
[2] | 606 | { |
---|
[608] | 607 | // Check if each of PUs is I_PCM with LF disabling |
---|
| 608 | bPartPNoFilter = (bPCMFilter && pcCUP->getIPCMFlag(uiPartPIdx)); |
---|
| 609 | bPartQNoFilter = (bPCMFilter && pcCUQ->getIPCMFlag(uiPartQIdx)); |
---|
| 610 | |
---|
| 611 | // check if each of PUs is lossless coded |
---|
| 612 | bPartPNoFilter = bPartPNoFilter || (pcCUP->isLosslessCoded(uiPartPIdx) ); |
---|
| 613 | bPartQNoFilter = bPartQNoFilter || (pcCUQ->isLosslessCoded(uiPartQIdx) ); |
---|
[2] | 614 | } |
---|
[608] | 615 | |
---|
[56] | 616 | if (d < iBeta) |
---|
| 617 | { |
---|
| 618 | Bool bFilterP = (dp < iSideThreshold); |
---|
| 619 | Bool bFilterQ = (dq < iSideThreshold); |
---|
[608] | 620 | |
---|
| 621 | Bool sw = xUseStrongFiltering( iOffset, 2*d0, iBeta, iTc, piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+iBlkIdx*4+0)) |
---|
| 622 | && xUseStrongFiltering( iOffset, 2*d3, iBeta, iTc, piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+iBlkIdx*4+3)); |
---|
| 623 | |
---|
[56] | 624 | for ( Int i = 0; i < DEBLOCK_SMALLEST_BLOCK/2; i++) |
---|
[2] | 625 | { |
---|
[608] | 626 | xPelFilterLuma( piTmpSrc+iSrcStep*(iIdx*uiPelsInPart+iBlkIdx*4+i), iOffset, iTc, sw, bPartPNoFilter, bPartQNoFilter, iThrCut, bFilterP, bFilterQ); |
---|
[2] | 627 | } |
---|
| 628 | } |
---|
[608] | 629 | } |
---|
[2] | 630 | } |
---|
| 631 | } |
---|
| 632 | } |
---|
| 633 | |
---|
| 634 | |
---|
| 635 | Void TComLoopFilter::xEdgeFilterChroma( TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth, Int iDir, Int iEdge ) |
---|
| 636 | { |
---|
| 637 | TComPicYuv* pcPicYuvRec = pcCU->getPic()->getPicYuvRec(); |
---|
| 638 | Int iStride = pcPicYuvRec->getCStride(); |
---|
| 639 | Pel* piSrcCb = pcPicYuvRec->getCbAddr( pcCU->getAddr(), uiAbsZorderIdx ); |
---|
| 640 | Pel* piSrcCr = pcPicYuvRec->getCrAddr( pcCU->getAddr(), uiAbsZorderIdx ); |
---|
[56] | 641 | Int iQP = 0; |
---|
| 642 | Int iQP_P = 0; |
---|
| 643 | Int iQP_Q = 0; |
---|
[2] | 644 | |
---|
| 645 | UInt uiPelsInPartChroma = g_uiMaxCUWidth >> (g_uiMaxCUDepth+1); |
---|
| 646 | |
---|
| 647 | Int iOffset, iSrcStep; |
---|
| 648 | |
---|
| 649 | const UInt uiLCUWidthInBaseUnits = pcCU->getPic()->getNumPartInWidth(); |
---|
| 650 | |
---|
[56] | 651 | Bool bPCMFilter = (pcCU->getSlice()->getSPS()->getUsePCM() && pcCU->getSlice()->getSPS()->getPCMFilterDisableFlag())? true : false; |
---|
| 652 | Bool bPartPNoFilter = false; |
---|
| 653 | Bool bPartQNoFilter = false; |
---|
| 654 | UInt uiPartPIdx; |
---|
| 655 | UInt uiPartQIdx; |
---|
| 656 | TComDataCU* pcCUP; |
---|
| 657 | TComDataCU* pcCUQ = pcCU; |
---|
[608] | 658 | Int tcOffsetDiv2 = pcCU->getSlice()->getDeblockingFilterTcOffsetDiv2(); |
---|
[56] | 659 | |
---|
[2] | 660 | // Vertical Position |
---|
| 661 | UInt uiEdgeNumInLCUVert = g_auiZscanToRaster[uiAbsZorderIdx]%uiLCUWidthInBaseUnits + iEdge; |
---|
| 662 | UInt uiEdgeNumInLCUHor = g_auiZscanToRaster[uiAbsZorderIdx]/uiLCUWidthInBaseUnits + iEdge; |
---|
| 663 | |
---|
[608] | 664 | if ( (uiPelsInPartChroma < DEBLOCK_SMALLEST_BLOCK) && (( (uiEdgeNumInLCUVert%(DEBLOCK_SMALLEST_BLOCK/uiPelsInPartChroma))&&(iDir==0) ) || ( (uiEdgeNumInLCUHor%(DEBLOCK_SMALLEST_BLOCK/uiPelsInPartChroma))&& iDir ) )) |
---|
[2] | 665 | { |
---|
| 666 | return; |
---|
| 667 | } |
---|
| 668 | |
---|
| 669 | UInt uiNumParts = pcCU->getPic()->getNumPartInWidth()>>uiDepth; |
---|
| 670 | |
---|
| 671 | UInt uiBsAbsIdx; |
---|
| 672 | UChar ucBs; |
---|
| 673 | |
---|
| 674 | Pel* piTmpSrcCb = piSrcCb; |
---|
| 675 | Pel* piTmpSrcCr = piSrcCr; |
---|
| 676 | |
---|
| 677 | |
---|
| 678 | if (iDir == EDGE_VER) |
---|
| 679 | { |
---|
| 680 | iOffset = 1; |
---|
| 681 | iSrcStep = iStride; |
---|
| 682 | piTmpSrcCb += iEdge*uiPelsInPartChroma; |
---|
| 683 | piTmpSrcCr += iEdge*uiPelsInPartChroma; |
---|
| 684 | } |
---|
| 685 | else // (iDir == EDGE_HOR) |
---|
| 686 | { |
---|
| 687 | iOffset = iStride; |
---|
| 688 | iSrcStep = 1; |
---|
| 689 | piTmpSrcCb += iEdge*iStride*uiPelsInPartChroma; |
---|
| 690 | piTmpSrcCr += iEdge*iStride*uiPelsInPartChroma; |
---|
| 691 | } |
---|
| 692 | |
---|
| 693 | for ( UInt iIdx = 0; iIdx < uiNumParts; iIdx++ ) |
---|
| 694 | { |
---|
| 695 | uiBsAbsIdx = xCalcBsIdx( pcCU, uiAbsZorderIdx, iDir, iEdge, iIdx); |
---|
[56] | 696 | ucBs = m_aapucBS[iDir][uiBsAbsIdx]; |
---|
[2] | 697 | |
---|
[56] | 698 | if ( ucBs > 1) |
---|
[2] | 699 | { |
---|
[56] | 700 | iQP_Q = pcCU->getQP( uiBsAbsIdx ); |
---|
| 701 | uiPartQIdx = uiBsAbsIdx; |
---|
| 702 | // Derive neighboring PU index |
---|
| 703 | if (iDir == EDGE_VER) |
---|
| 704 | { |
---|
[608] | 705 | pcCUP = pcCUQ->getPULeft (uiPartPIdx, uiPartQIdx,!pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), !m_bLFCrossTileBoundary); |
---|
[56] | 706 | } |
---|
| 707 | else // (iDir == EDGE_HOR) |
---|
| 708 | { |
---|
[608] | 709 | pcCUP = pcCUQ->getPUAbove(uiPartPIdx, uiPartQIdx,!pcCU->getSlice()->getLFCrossSliceBoundaryFlag(), false, !m_bLFCrossTileBoundary); |
---|
[56] | 710 | } |
---|
| 711 | |
---|
| 712 | iQP_P = pcCUP->getQP(uiPartPIdx); |
---|
| 713 | |
---|
[608] | 714 | if (bPCMFilter || pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
[56] | 715 | { |
---|
[608] | 716 | // Check if each of PUs is I_PCM with LF disabling |
---|
| 717 | bPartPNoFilter = (bPCMFilter && pcCUP->getIPCMFlag(uiPartPIdx)); |
---|
| 718 | bPartQNoFilter = (bPCMFilter && pcCUQ->getIPCMFlag(uiPartQIdx)); |
---|
| 719 | |
---|
| 720 | // check if each of PUs is lossless coded |
---|
| 721 | bPartPNoFilter = bPartPNoFilter || (pcCUP->isLosslessCoded(uiPartPIdx)); |
---|
| 722 | bPartQNoFilter = bPartQNoFilter || (pcCUQ->isLosslessCoded(uiPartQIdx)); |
---|
[56] | 723 | } |
---|
| 724 | |
---|
[608] | 725 | for ( UInt chromaIdx = 0; chromaIdx < 2; chromaIdx++ ) |
---|
[56] | 726 | { |
---|
[608] | 727 | Int chromaQPOffset = (chromaIdx == 0) ? pcCU->getSlice()->getPPS()->getChromaCbQpOffset() : pcCU->getSlice()->getPPS()->getChromaCrQpOffset(); |
---|
| 728 | Pel* piTmpSrcChroma = (chromaIdx == 0) ? piTmpSrcCb : piTmpSrcCr; |
---|
| 729 | |
---|
| 730 | iQP = QpUV( ((iQP_P + iQP_Q + 1) >> 1) + chromaQPOffset ); |
---|
| 731 | Int iBitdepthScale = 1 << (g_bitDepthC-8); |
---|
| 732 | |
---|
| 733 | Int iIndexTC = Clip3(0, MAX_QP+DEFAULT_INTRA_TC_OFFSET, iQP + DEFAULT_INTRA_TC_OFFSET*(ucBs - 1) + (tcOffsetDiv2 << 1)); |
---|
| 734 | Int iTc = sm_tcTable[iIndexTC]*iBitdepthScale; |
---|
| 735 | |
---|
| 736 | for ( UInt uiStep = 0; uiStep < uiPelsInPartChroma; uiStep++ ) |
---|
| 737 | { |
---|
| 738 | xPelFilterChroma( piTmpSrcChroma + iSrcStep*(uiStep+iIdx*uiPelsInPartChroma), iOffset, iTc , bPartPNoFilter, bPartQNoFilter); |
---|
| 739 | } |
---|
[56] | 740 | } |
---|
[2] | 741 | } |
---|
| 742 | } |
---|
| 743 | } |
---|
| 744 | |
---|
| 745 | /** |
---|
| 746 | - Deblocking for the luminance component with strong or weak filter |
---|
| 747 | . |
---|
[56] | 748 | \param piSrc pointer to picture data |
---|
| 749 | \param iOffset offset value for picture data |
---|
| 750 | \param tc tc value |
---|
| 751 | \param sw decision strong/weak filter |
---|
| 752 | \param bPartPNoFilter indicator to disable filtering on partP |
---|
| 753 | \param bPartQNoFilter indicator to disable filtering on partQ |
---|
| 754 | \param iThrCut threshold value for weak filter decision |
---|
| 755 | \param bFilterSecondP decision weak filter/no filter for partP |
---|
| 756 | \param bFilterSecondQ decision weak filter/no filter for partQ |
---|
[2] | 757 | */ |
---|
[608] | 758 | __inline Void TComLoopFilter::xPelFilterLuma( Pel* piSrc, Int iOffset, Int tc , Bool sw, Bool bPartPNoFilter, Bool bPartQNoFilter, Int iThrCut, Bool bFilterSecondP, Bool bFilterSecondQ) |
---|
[2] | 759 | { |
---|
[56] | 760 | Int delta; |
---|
[2] | 761 | |
---|
| 762 | Pel m4 = piSrc[0]; |
---|
| 763 | Pel m3 = piSrc[-iOffset]; |
---|
| 764 | Pel m5 = piSrc[ iOffset]; |
---|
| 765 | Pel m2 = piSrc[-iOffset*2]; |
---|
| 766 | Pel m6 = piSrc[ iOffset*2]; |
---|
| 767 | Pel m1 = piSrc[-iOffset*3]; |
---|
| 768 | Pel m7 = piSrc[ iOffset*3]; |
---|
| 769 | Pel m0 = piSrc[-iOffset*4]; |
---|
| 770 | |
---|
[56] | 771 | if (sw) |
---|
| 772 | { |
---|
| 773 | piSrc[-iOffset] = Clip3(m3-2*tc, m3+2*tc, ((m1 + 2*m2 + 2*m3 + 2*m4 + m5 + 4) >> 3)); |
---|
| 774 | piSrc[0] = Clip3(m4-2*tc, m4+2*tc, ((m2 + 2*m3 + 2*m4 + 2*m5 + m6 + 4) >> 3)); |
---|
| 775 | piSrc[-iOffset*2] = Clip3(m2-2*tc, m2+2*tc, ((m1 + m2 + m3 + m4 + 2)>>2)); |
---|
| 776 | piSrc[ iOffset] = Clip3(m5-2*tc, m5+2*tc, ((m3 + m4 + m5 + m6 + 2)>>2)); |
---|
| 777 | piSrc[-iOffset*3] = Clip3(m1-2*tc, m1+2*tc, ((2*m0 + 3*m1 + m2 + m3 + m4 + 4 )>>3)); |
---|
| 778 | piSrc[ iOffset*2] = Clip3(m6-2*tc, m6+2*tc, ((m3 + m4 + m5 + 3*m6 + 2*m7 +4 )>>3)); |
---|
[2] | 779 | } |
---|
| 780 | else |
---|
| 781 | { |
---|
| 782 | /* Weak filter */ |
---|
[56] | 783 | delta = (9*(m4-m3) -3*(m5-m2) + 8)>>4 ; |
---|
| 784 | |
---|
| 785 | if ( abs(delta) < iThrCut ) |
---|
| 786 | { |
---|
| 787 | delta = Clip3(-tc, tc, delta); |
---|
[608] | 788 | piSrc[-iOffset] = ClipY((m3+delta)); |
---|
| 789 | piSrc[0] = ClipY((m4-delta)); |
---|
[56] | 790 | |
---|
| 791 | Int tc2 = tc>>1; |
---|
| 792 | if(bFilterSecondP) |
---|
| 793 | { |
---|
| 794 | Int delta1 = Clip3(-tc2, tc2, (( ((m1+m3+1)>>1)- m2+delta)>>1)); |
---|
[608] | 795 | piSrc[-iOffset*2] = ClipY((m2+delta1)); |
---|
[56] | 796 | } |
---|
| 797 | if(bFilterSecondQ) |
---|
| 798 | { |
---|
| 799 | Int delta2 = Clip3(-tc2, tc2, (( ((m6+m4+1)>>1)- m5-delta)>>1)); |
---|
[608] | 800 | piSrc[ iOffset] = ClipY((m5+delta2)); |
---|
[56] | 801 | } |
---|
| 802 | } |
---|
[2] | 803 | } |
---|
| 804 | |
---|
[56] | 805 | if(bPartPNoFilter) |
---|
[2] | 806 | { |
---|
[56] | 807 | piSrc[-iOffset] = m3; |
---|
| 808 | piSrc[-iOffset*2] = m2; |
---|
| 809 | piSrc[-iOffset*3] = m1; |
---|
[2] | 810 | } |
---|
[56] | 811 | if(bPartQNoFilter) |
---|
[2] | 812 | { |
---|
[56] | 813 | piSrc[0] = m4; |
---|
| 814 | piSrc[ iOffset] = m5; |
---|
| 815 | piSrc[ iOffset*2] = m6; |
---|
[2] | 816 | } |
---|
| 817 | } |
---|
| 818 | |
---|
[56] | 819 | /** |
---|
| 820 | - Deblocking of one line/column for the chrominance component |
---|
| 821 | . |
---|
| 822 | \param piSrc pointer to picture data |
---|
| 823 | \param iOffset offset value for picture data |
---|
| 824 | \param tc tc value |
---|
| 825 | \param bPartPNoFilter indicator to disable filtering on partP |
---|
| 826 | \param bPartQNoFilter indicator to disable filtering on partQ |
---|
| 827 | */ |
---|
| 828 | __inline Void TComLoopFilter::xPelFilterChroma( Pel* piSrc, Int iOffset, Int tc, Bool bPartPNoFilter, Bool bPartQNoFilter) |
---|
[2] | 829 | { |
---|
[608] | 830 | Int delta; |
---|
[2] | 831 | |
---|
| 832 | Pel m4 = piSrc[0]; |
---|
| 833 | Pel m3 = piSrc[-iOffset]; |
---|
| 834 | Pel m5 = piSrc[ iOffset]; |
---|
| 835 | Pel m2 = piSrc[-iOffset*2]; |
---|
| 836 | |
---|
| 837 | delta = Clip3(-tc,tc, (((( m4 - m3 ) << 2 ) + m2 - m5 + 4 ) >> 3) ); |
---|
[608] | 838 | piSrc[-iOffset] = ClipC(m3+delta); |
---|
| 839 | piSrc[0] = ClipC(m4-delta); |
---|
[56] | 840 | |
---|
| 841 | if(bPartPNoFilter) |
---|
| 842 | { |
---|
| 843 | piSrc[-iOffset] = m3; |
---|
| 844 | } |
---|
| 845 | if(bPartQNoFilter) |
---|
| 846 | { |
---|
| 847 | piSrc[0] = m4; |
---|
| 848 | } |
---|
[2] | 849 | } |
---|
| 850 | |
---|
[56] | 851 | /** |
---|
| 852 | - Decision between strong and weak filter |
---|
| 853 | . |
---|
| 854 | \param offset offset value for picture data |
---|
| 855 | \param d d value |
---|
| 856 | \param beta beta value |
---|
| 857 | \param tc tc value |
---|
| 858 | \param piSrc pointer to picture data |
---|
| 859 | */ |
---|
| 860 | __inline Bool TComLoopFilter::xUseStrongFiltering( Int offset, Int d, Int beta, Int tc, Pel* piSrc) |
---|
| 861 | { |
---|
| 862 | Pel m4 = piSrc[0]; |
---|
| 863 | Pel m3 = piSrc[-offset]; |
---|
| 864 | Pel m7 = piSrc[ offset*3]; |
---|
| 865 | Pel m0 = piSrc[-offset*4]; |
---|
[2] | 866 | |
---|
[56] | 867 | Int d_strong = abs(m0-m3) + abs(m7-m4); |
---|
| 868 | |
---|
| 869 | return ( (d_strong < (beta>>3)) && (d<(beta>>2)) && ( abs(m3-m4) < ((tc*5+1)>>1)) ); |
---|
| 870 | } |
---|
| 871 | |
---|
| 872 | __inline Int TComLoopFilter::xCalcDP( Pel* piSrc, Int iOffset) |
---|
[2] | 873 | { |
---|
[56] | 874 | return abs( piSrc[-iOffset*3] - 2*piSrc[-iOffset*2] + piSrc[-iOffset] ) ; |
---|
[2] | 875 | } |
---|
[56] | 876 | |
---|
| 877 | __inline Int TComLoopFilter::xCalcDQ( Pel* piSrc, Int iOffset) |
---|
| 878 | { |
---|
| 879 | return abs( piSrc[0] - 2*piSrc[iOffset] + piSrc[iOffset*2] ); |
---|
| 880 | } |
---|
| 881 | //! \} |
---|