[191] | 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-2013, 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 | /** |
---|
| 35 | \file TEncSampleAdaptiveOffset.h |
---|
| 36 | \brief estimation part of sample adaptive offset class (header) |
---|
| 37 | */ |
---|
| 38 | |
---|
| 39 | #ifndef __TENCSAMPLEADAPTIVEOFFSET__ |
---|
| 40 | #define __TENCSAMPLEADAPTIVEOFFSET__ |
---|
| 41 | |
---|
| 42 | #include "TLibCommon/TComSampleAdaptiveOffset.h" |
---|
| 43 | #include "TLibCommon/TComPic.h" |
---|
| 44 | |
---|
| 45 | #include "TEncEntropy.h" |
---|
| 46 | #include "TEncSbac.h" |
---|
| 47 | #include "TLibCommon/TComBitCounter.h" |
---|
| 48 | |
---|
| 49 | //! \ingroup TLibEncoder |
---|
| 50 | //! \{ |
---|
| 51 | |
---|
| 52 | // ==================================================================================================================== |
---|
| 53 | // Class definition |
---|
| 54 | // ==================================================================================================================== |
---|
| 55 | |
---|
| 56 | class TEncSampleAdaptiveOffset : public TComSampleAdaptiveOffset |
---|
| 57 | { |
---|
| 58 | private: |
---|
| 59 | TEncEntropy* m_pcEntropyCoder; |
---|
| 60 | TEncSbac*** m_pppcRDSbacCoder; ///< for CABAC |
---|
| 61 | TEncSbac* m_pcRDGoOnSbacCoder; |
---|
| 62 | #if FAST_BIT_EST |
---|
| 63 | TEncBinCABACCounter*** m_pppcBinCoderCABAC; ///< temporal CABAC state storage for RD computation |
---|
| 64 | #else |
---|
| 65 | TEncBinCABAC*** m_pppcBinCoderCABAC; ///< temporal CABAC state storage for RD computation |
---|
| 66 | #endif |
---|
| 67 | |
---|
| 68 | Int64 ***m_iCount; //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS]; |
---|
| 69 | Int64 ***m_iOffset; //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS]; |
---|
| 70 | Int64 ***m_iOffsetOrg; //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE]; |
---|
| 71 | Int64 ****m_count_PreDblk; //[LCU][YCbCr][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS]; |
---|
| 72 | Int64 ****m_offsetOrg_PreDblk; //[LCU][YCbCr][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS]; |
---|
| 73 | Int64 **m_iRate; //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE]; |
---|
| 74 | Int64 **m_iDist; //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE]; |
---|
| 75 | Double **m_dCost; //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE]; |
---|
| 76 | Double *m_dCostPartBest; //[MAX_NUM_SAO_PART]; |
---|
| 77 | Int64 *m_iDistOrg; //[MAX_NUM_SAO_PART]; |
---|
| 78 | Int *m_iTypePartBest; //[MAX_NUM_SAO_PART]; |
---|
| 79 | Int m_iOffsetThY; |
---|
| 80 | Int m_iOffsetThC; |
---|
| 81 | Bool m_bUseSBACRD; |
---|
| 82 | #if SAO_ENCODING_CHOICE |
---|
| 83 | #if SAO_ENCODING_CHOICE_CHROMA |
---|
| 84 | Double m_depthSaoRate[2][4]; |
---|
| 85 | #else |
---|
| 86 | Double m_depth0SaoRate; |
---|
| 87 | #endif |
---|
| 88 | #endif |
---|
| 89 | |
---|
| 90 | public: |
---|
| 91 | TEncSampleAdaptiveOffset (); |
---|
| 92 | virtual ~TEncSampleAdaptiveOffset(); |
---|
| 93 | |
---|
| 94 | Void startSaoEnc( TComPic* pcPic, TEncEntropy* pcEntropyCoder, TEncSbac*** pppcRDSbacCoder, TEncSbac* pcRDGoOnSbacCoder); |
---|
| 95 | Void endSaoEnc(); |
---|
| 96 | Void resetStats(); |
---|
| 97 | #if SAO_CHROMA_LAMBDA |
---|
| 98 | #if SAO_ENCODING_CHOICE |
---|
| 99 | Void SAOProcess(SAOParam *pcSaoParam, Double dLambda, Double dLambdaChroma, Int depth); |
---|
| 100 | #else |
---|
| 101 | Void SAOProcess(SAOParam *pcSaoParam, Double dLambda, Double dLambdaChroma); |
---|
| 102 | #endif |
---|
| 103 | #else |
---|
| 104 | Void SAOProcess(SAOParam *pcSaoParam, Double dLambda); |
---|
| 105 | #endif |
---|
| 106 | |
---|
| 107 | Void runQuadTreeDecision(SAOQTPart *psQTPart, Int iPartIdx, Double &dCostFinal, Int iMaxLevel, Double dLambda, Int yCbCr); |
---|
| 108 | Void rdoSaoOnePart(SAOQTPart *psQTPart, Int iPartIdx, Double dLambda, Int yCbCr); |
---|
| 109 | |
---|
| 110 | Void disablePartTree(SAOQTPart *psQTPart, Int iPartIdx); |
---|
| 111 | Void getSaoStats(SAOQTPart *psQTPart, Int iYCbCr); |
---|
| 112 | Void calcSaoStatsCu(Int iAddr, Int iPartIdx, Int iYCbCr); |
---|
| 113 | Void calcSaoStatsBlock( Pel* pRecStart, Pel* pOrgStart, Int stride, Int64** ppStats, Int64** ppCount, UInt width, UInt height, Bool* pbBorderAvail, Int iYCbCr); |
---|
| 114 | Void calcSaoStatsCuOrg(Int iAddr, Int iPartIdx, Int iYCbCr); |
---|
| 115 | Void calcSaoStatsCu_BeforeDblk( TComPic* pcPic ); |
---|
| 116 | Void destroyEncBuffer(); |
---|
| 117 | Void createEncBuffer(); |
---|
| 118 | Void assignSaoUnitSyntax(SaoLcuParam* saoLcuParam, SAOQTPart* saoPart, Bool &oneUnitFlag, Int yCbCr); |
---|
| 119 | Void checkMerge(SaoLcuParam * lcuParamCurr,SaoLcuParam * lcuParamCheck, Int dir); |
---|
| 120 | #if SAO_ENCODING_CHOICE |
---|
| 121 | Void rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma, Int depth); |
---|
| 122 | #else |
---|
| 123 | Void rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma); |
---|
| 124 | #endif |
---|
| 125 | Void saoComponentParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Int yCbCr, Double lambda, SaoLcuParam *compSaoParam, Double *distortion); |
---|
| 126 | Void sao2ChromaParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Double lambda, SaoLcuParam *crSaoParam, SaoLcuParam *cbSaoParam, Double *distortion); |
---|
| 127 | inline Int64 estSaoDist(Int64 count, Int64 offset, Int64 offsetOrg, Int shift); |
---|
| 128 | inline Int64 estIterOffset(Int typeIdx, Int classIdx, Double lambda, Int64 offsetInput, Int64 count, Int64 offsetOrg, Int shift, Int bitIncrease, Int *currentDistortionTableBo, Double *currentRdCostTableBo, Int offsetTh ); |
---|
| 129 | inline Int64 estSaoTypeDist(Int compIdx, Int typeIdx, Int shift, Double lambda, Int *currentDistortionTableBo, Double *currentRdCostTableBo); |
---|
| 130 | Void setMaxNumOffsetsPerPic(Int iVal) {m_maxNumOffsetsPerPic = iVal; } |
---|
| 131 | Int getMaxNumOffsetsPerPic() {return m_maxNumOffsetsPerPic; } |
---|
| 132 | }; |
---|
| 133 | |
---|
| 134 | //! \} |
---|
| 135 | |
---|
| 136 | #endif |
---|