[56] | 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 |
---|
[1313] | 4 | * granted under this license. |
---|
[56] | 5 | * |
---|
[1401] | 6 | * Copyright (c) 2010-2016, ITU/ISO/IEC |
---|
[56] | 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 | |
---|
[1313] | 34 | /** |
---|
[608] | 35 | \file TEncSampleAdaptiveOffset.h |
---|
[56] | 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 | |
---|
[872] | 56 | enum SAOCabacStateLablesRDO //CABAC state labels |
---|
[56] | 57 | { |
---|
[872] | 58 | SAO_CABACSTATE_PIC_INIT =0, |
---|
| 59 | SAO_CABACSTATE_BLK_CUR, |
---|
| 60 | SAO_CABACSTATE_BLK_NEXT, |
---|
| 61 | SAO_CABACSTATE_BLK_MID, |
---|
| 62 | SAO_CABACSTATE_BLK_TEMP, |
---|
| 63 | NUM_SAO_CABACSTATE_LABELS |
---|
| 64 | }; |
---|
| 65 | |
---|
| 66 | struct SAOStatData //data structure for SAO statistics |
---|
| 67 | { |
---|
| 68 | Int64 diff[MAX_NUM_SAO_CLASSES]; |
---|
| 69 | Int64 count[MAX_NUM_SAO_CLASSES]; |
---|
| 70 | |
---|
| 71 | SAOStatData(){} |
---|
| 72 | ~SAOStatData(){} |
---|
| 73 | Void reset() |
---|
| 74 | { |
---|
| 75 | ::memset(diff, 0, sizeof(Int64)*MAX_NUM_SAO_CLASSES); |
---|
| 76 | ::memset(count, 0, sizeof(Int64)*MAX_NUM_SAO_CLASSES); |
---|
| 77 | } |
---|
| 78 | const SAOStatData& operator=(const SAOStatData& src) |
---|
| 79 | { |
---|
| 80 | ::memcpy(diff, src.diff, sizeof(Int64)*MAX_NUM_SAO_CLASSES); |
---|
| 81 | ::memcpy(count, src.count, sizeof(Int64)*MAX_NUM_SAO_CLASSES); |
---|
| 82 | return *this; |
---|
| 83 | } |
---|
| 84 | const SAOStatData& operator+= (const SAOStatData& src) |
---|
| 85 | { |
---|
| 86 | for(Int i=0; i< MAX_NUM_SAO_CLASSES; i++) |
---|
| 87 | { |
---|
| 88 | diff[i] += src.diff[i]; |
---|
| 89 | count[i] += src.count[i]; |
---|
| 90 | } |
---|
| 91 | return *this; |
---|
| 92 | } |
---|
| 93 | }; |
---|
[56] | 94 | |
---|
[872] | 95 | class TEncSampleAdaptiveOffset : public TComSampleAdaptiveOffset |
---|
| 96 | { |
---|
[56] | 97 | public: |
---|
[872] | 98 | TEncSampleAdaptiveOffset(); |
---|
[56] | 99 | virtual ~TEncSampleAdaptiveOffset(); |
---|
| 100 | |
---|
[872] | 101 | //interface |
---|
| 102 | Void createEncData(Bool isPreDBFSamplesUsed); |
---|
| 103 | Void destroyEncData(); |
---|
| 104 | Void initRDOCabacCoder(TEncSbac* pcRDGoOnSbacCoder, TComSlice* pcSlice) ; |
---|
[1402] | 105 | #if OPTIONAL_RESET_SAO_ENCODING_AFTER_IRAP |
---|
| 106 | Void SAOProcess(TComPic* pPic, Bool* sliceEnabled, const Double *lambdas, const Bool bTestSAODisableAtPictureLevel, const Double saoEncodingRate, const Double saoEncodingRateChroma, const Bool isPreDBFSamplesUsed, const Bool bResetStateAfterIRAP); |
---|
| 107 | #else |
---|
[1313] | 108 | Void SAOProcess(TComPic* pPic, Bool* sliceEnabled, const Double *lambdas, const Bool bTestSAODisableAtPictureLevel, const Double saoEncodingRate, const Double saoEncodingRateChroma, Bool isPreDBFSamplesUsed); |
---|
[1402] | 109 | #endif |
---|
[872] | 110 | public: //methods |
---|
[1313] | 111 | Void getPreDBFStatistics(TComPic* pPic); |
---|
[872] | 112 | private: //methods |
---|
[1313] | 113 | Void getStatistics(SAOStatData*** blkStats, TComPicYuv* orgYuv, TComPicYuv* srcYuv,TComPic* pPic, Bool isCalculatePreDeblockSamples = false); |
---|
[1402] | 114 | #if OPTIONAL_RESET_SAO_ENCODING_AFTER_IRAP |
---|
| 115 | Void decidePicParams(Bool* sliceEnabled, const TComPic* pic, const Double saoEncodingRate, const Double saoEncodingRateChroma, const Bool bResetStateAfterIRAP); |
---|
| 116 | #else |
---|
[1313] | 117 | Void decidePicParams(Bool* sliceEnabled, Int picTempLayer, const Double saoEncodingRate, const Double saoEncodingRateChroma); |
---|
[1402] | 118 | #endif |
---|
[1313] | 119 | Void decideBlkParams(TComPic* pic, Bool* sliceEnabled, SAOStatData*** blkStats, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam* reconParams, SAOBlkParam* codedParams, const Bool bTestSAODisableAtPictureLevel, const Double saoEncodingRate, const Double saoEncodingRateChroma); |
---|
| 120 | Void getBlkStats(const ComponentID compIdx, const Int channelBitDepth, SAOStatData* statsDataTypes, Pel* srcBlk, Pel* orgBlk, Int srcStride, Int orgStride, Int width, Int height, Bool isLeftAvail, Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isCalculatePreDeblockSamples); |
---|
| 121 | Void deriveModeNewRDO(const BitDepths &bitDepths, Int ctuRsAddr, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES], Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel); |
---|
| 122 | Void deriveModeMergeRDO(const BitDepths &bitDepths, Int ctuRsAddr, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES], Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel); |
---|
| 123 | Int64 getDistortion(const Int channelBitDepth, Int typeIdc, Int typeAuxInfo, Int* offsetVal, SAOStatData& statData); |
---|
| 124 | Void deriveOffsets(ComponentID compIdx, const Int channelBitDepth, Int typeIdc, SAOStatData& statData, Int* quantOffsets, Int& typeAuxInfo); |
---|
[872] | 125 | inline Int64 estSaoDist(Int64 count, Int64 offset, Int64 diffSum, Int shift); |
---|
[1313] | 126 | inline Int estIterOffset(Int typeIdx, Double lambda, Int offsetInput, Int64 count, Int64 diffSum, Int shift, Int bitIncrease, Int64& bestDist, Double& bestCost, Int offsetTh ); |
---|
[872] | 127 | Void addPreDBFStatistics(SAOStatData*** blkStats); |
---|
| 128 | private: //members |
---|
| 129 | //for RDO |
---|
[1313] | 130 | TEncSbac** m_pppcRDSbacCoder; |
---|
[872] | 131 | TEncSbac* m_pcRDGoOnSbacCoder; |
---|
[1313] | 132 | #if FAST_BIT_EST |
---|
| 133 | TEncBinCABACCounter** m_pppcBinCoderCABAC; |
---|
| 134 | #else |
---|
| 135 | TEncBinCABAC** m_pppcBinCoderCABAC; |
---|
| 136 | #endif |
---|
| 137 | Double m_lambda[MAX_NUM_COMPONENT]; |
---|
[443] | 138 | |
---|
[872] | 139 | //statistics |
---|
| 140 | SAOStatData*** m_statData; //[ctu][comp][classes] |
---|
| 141 | SAOStatData*** m_preDBFstatData; |
---|
[1313] | 142 | Double m_saoDisabledRate[MAX_NUM_COMPONENT][MAX_TLAYER]; |
---|
[1402] | 143 | #if OPTIONAL_RESET_SAO_ENCODING_AFTER_IRAP |
---|
| 144 | Int m_lastIRAPPoc; |
---|
| 145 | #endif |
---|
[1313] | 146 | Int m_skipLinesR[MAX_NUM_COMPONENT][NUM_SAO_NEW_TYPES]; |
---|
| 147 | Int m_skipLinesB[MAX_NUM_COMPONENT][NUM_SAO_NEW_TYPES]; |
---|
[56] | 148 | }; |
---|
[1313] | 149 | |
---|
| 150 | |
---|
[56] | 151 | //! \} |
---|
| 152 | |
---|
| 153 | #endif |
---|