| 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 |
|---|
| 4 | * granted under this license. |
|---|
| 5 | * |
|---|
| 6 | * Copyright (c) 2010-2017, ITU/ISO/IEC |
|---|
| 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 TComLoopFilter.h |
|---|
| 35 | \brief deblocking filter (header) |
|---|
| 36 | */ |
|---|
| 37 | |
|---|
| 38 | #ifndef __TCOMLOOPFILTER__ |
|---|
| 39 | #define __TCOMLOOPFILTER__ |
|---|
| 40 | |
|---|
| 41 | #include "CommonDef.h" |
|---|
| 42 | #include "TComPic.h" |
|---|
| 43 | |
|---|
| 44 | //! \ingroup TLibCommon |
|---|
| 45 | //! \{ |
|---|
| 46 | |
|---|
| 47 | #define DEBLOCK_SMALLEST_BLOCK 8 |
|---|
| 48 | |
|---|
| 49 | // ==================================================================================================================== |
|---|
| 50 | // Class definition |
|---|
| 51 | // ==================================================================================================================== |
|---|
| 52 | |
|---|
| 53 | /// deblocking filter class |
|---|
| 54 | class TComLoopFilter |
|---|
| 55 | { |
|---|
| 56 | private: |
|---|
| 57 | |
|---|
| 58 | UInt m_uiNumPartitions; |
|---|
| 59 | UChar* m_aapucBS[NUM_EDGE_DIR]; ///< Bs for [Ver/Hor][Y/U/V][Blk_Idx] |
|---|
| 60 | Bool* m_aapbEdgeFilter[NUM_EDGE_DIR]; |
|---|
| 61 | LFCUParam m_stLFCUParam; ///< status structure |
|---|
| 62 | |
|---|
| 63 | Bool m_bLFCrossTileBoundary; |
|---|
| 64 | |
|---|
| 65 | protected: |
|---|
| 66 | /// CU-level deblocking function |
|---|
| 67 | Void xDeblockCU ( TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth, DeblockEdgeDir edgeDir ); |
|---|
| 68 | |
|---|
| 69 | // set / get functions |
|---|
| 70 | Void xSetLoopfilterParam ( TComDataCU* pcCU, UInt uiAbsZorderIdx ); |
|---|
| 71 | // filtering functions |
|---|
| 72 | Void xSetEdgefilterTU ( TComTU &rTu ); |
|---|
| 73 | Void xSetEdgefilterPU ( TComDataCU* pcCU, UInt uiAbsZorderIdx ); |
|---|
| 74 | Void xGetBoundaryStrengthSingle ( TComDataCU* pCtu, DeblockEdgeDir edgeDir, UInt uiPartIdx ); |
|---|
| 75 | UInt xCalcBsIdx ( TComDataCU* pcCU, UInt absZIdxInCtu, DeblockEdgeDir edgeDir, Int iEdgeIdx, Int iBaseUnitIdx, const struct TComRectangle *rect=NULL ) |
|---|
| 76 | { |
|---|
| 77 | TComPic* const pcPic = pcCU->getPic(); |
|---|
| 78 | const UInt ctuWidthInBaseUnits = pcPic->getNumPartInCtuWidth(); |
|---|
| 79 | Int rasterOffsetTU=0; |
|---|
| 80 | if (rect != NULL) |
|---|
| 81 | { |
|---|
| 82 | const UInt minCuWidth =pcPic->getMinCUWidth(); |
|---|
| 83 | const UInt minCuHeight=pcPic->getMinCUHeight(); |
|---|
| 84 | rasterOffsetTU = rect->x0/minCuWidth + (rect->y0/minCuHeight)*ctuWidthInBaseUnits; |
|---|
| 85 | } |
|---|
| 86 | if( edgeDir == EDGE_VER ) |
|---|
| 87 | { |
|---|
| 88 | return g_auiRasterToZscan[g_auiZscanToRaster[absZIdxInCtu] + iBaseUnitIdx * ctuWidthInBaseUnits + iEdgeIdx + rasterOffsetTU ]; |
|---|
| 89 | } |
|---|
| 90 | else |
|---|
| 91 | { |
|---|
| 92 | return g_auiRasterToZscan[g_auiZscanToRaster[absZIdxInCtu] + iEdgeIdx * ctuWidthInBaseUnits + iBaseUnitIdx + rasterOffsetTU ]; |
|---|
| 93 | } |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | Void xSetEdgefilterMultiple( TComDataCU* pcCU, |
|---|
| 97 | UInt uiAbsZorderIdx, |
|---|
| 98 | UInt uiDepth, |
|---|
| 99 | DeblockEdgeDir edgeDir, |
|---|
| 100 | Int iEdgeIdx, |
|---|
| 101 | Bool bValue, |
|---|
| 102 | UInt uiWidthInBaseUnits = 0, |
|---|
| 103 | UInt uiHeightInBaseUnits = 0, |
|---|
| 104 | const TComRectangle *rect = 0 |
|---|
| 105 | ); |
|---|
| 106 | |
|---|
| 107 | Void xEdgeFilterLuma ( TComDataCU* const pcCU, const UInt uiAbsZorderIdx, const UInt uiDepth, const DeblockEdgeDir edgeDir, const Int iEdge ); |
|---|
| 108 | Void xEdgeFilterChroma ( TComDataCU* const pcCU, const UInt uiAbsZorderIdx, const UInt uiDepth, const DeblockEdgeDir edgeDir, const Int iEdge ); |
|---|
| 109 | |
|---|
| 110 | __inline Void xPelFilterLuma( Pel* piSrc, Int iOffset, Int tc, Bool sw, Bool bPartPNoFilter, Bool bPartQNoFilter, Int iThrCut, Bool bFilterSecondP, Bool bFilterSecondQ, const Int bitDepthLuma); |
|---|
| 111 | __inline Void xPelFilterChroma( Pel* piSrc, Int iOffset, Int tc, Bool bPartPNoFilter, Bool bPartQNoFilter, const Int bitDepthChroma); |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | __inline Bool xUseStrongFiltering( Int offset, Int d, Int beta, Int tc, Pel* piSrc); |
|---|
| 115 | __inline Int xCalcDP( Pel* piSrc, Int iOffset); |
|---|
| 116 | __inline Int xCalcDQ( Pel* piSrc, Int iOffset); |
|---|
| 117 | |
|---|
| 118 | static const UChar sm_tcTable[54]; |
|---|
| 119 | static const UChar sm_betaTable[52]; |
|---|
| 120 | |
|---|
| 121 | public: |
|---|
| 122 | TComLoopFilter(); |
|---|
| 123 | virtual ~TComLoopFilter(); |
|---|
| 124 | |
|---|
| 125 | Void create ( UInt uiMaxCUDepth ); |
|---|
| 126 | Void destroy (); |
|---|
| 127 | |
|---|
| 128 | /// set configuration |
|---|
| 129 | Void setCfg( Bool bLFCrossTileBoundary ); |
|---|
| 130 | |
|---|
| 131 | /// picture-level deblocking filter |
|---|
| 132 | Void loopFilterPic( TComPic* pcPic ); |
|---|
| 133 | |
|---|
| 134 | static Int getBeta( Int qp ) |
|---|
| 135 | { |
|---|
| 136 | Int indexB = Clip3( 0, MAX_QP, qp ); |
|---|
| 137 | return sm_betaTable[ indexB ]; |
|---|
| 138 | } |
|---|
| 139 | }; |
|---|
| 140 | |
|---|
| 141 | //! \} |
|---|
| 142 | |
|---|
| 143 | #endif |
|---|