[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 |
---|
| 4 | * granted under this license. |
---|
| 5 | * |
---|
[595] | 6 | * Copyright (c) 2010-2014, 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 TComRdCost.h |
---|
| 35 | \brief RD cost computation classes (header) |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #ifndef __TCOMRDCOST__ |
---|
| 39 | #define __TCOMRDCOST__ |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | #include "CommonDef.h" |
---|
| 43 | #include "TComPattern.h" |
---|
| 44 | #include "TComMv.h" |
---|
| 45 | |
---|
| 46 | #include "TComSlice.h" |
---|
| 47 | #include "TComRdCostWeightPrediction.h" |
---|
| 48 | |
---|
| 49 | //! \ingroup TLibCommon |
---|
| 50 | //! \{ |
---|
| 51 | |
---|
| 52 | #define FIX203 1 |
---|
| 53 | |
---|
| 54 | class DistParam; |
---|
| 55 | class TComPattern; |
---|
| 56 | |
---|
| 57 | // ==================================================================================================================== |
---|
| 58 | // Type definition |
---|
| 59 | // ==================================================================================================================== |
---|
| 60 | |
---|
| 61 | // for function pointer |
---|
| 62 | typedef UInt (*FpDistFunc) (DistParam*); |
---|
| 63 | |
---|
| 64 | // ==================================================================================================================== |
---|
| 65 | // Class definition |
---|
| 66 | // ==================================================================================================================== |
---|
| 67 | |
---|
| 68 | /// distortion parameter class |
---|
| 69 | class DistParam |
---|
| 70 | { |
---|
| 71 | public: |
---|
| 72 | Pel* pOrg; |
---|
| 73 | Pel* pCur; |
---|
| 74 | Int iStrideOrg; |
---|
| 75 | Int iStrideCur; |
---|
| 76 | Int iRows; |
---|
| 77 | Int iCols; |
---|
| 78 | Int iStep; |
---|
| 79 | FpDistFunc DistFunc; |
---|
| 80 | Int bitDepth; |
---|
| 81 | |
---|
| 82 | Bool bApplyWeight; // whether weithed prediction is used or not |
---|
| 83 | wpScalingParam *wpCur; // weithed prediction scaling parameters for current ref |
---|
| 84 | UInt uiComp; // uiComp = 0 (luma Y), 1 (chroma U), 2 (chroma V) |
---|
| 85 | |
---|
| 86 | // (vertical) subsampling shift (for reducing complexity) |
---|
| 87 | // - 0 = no subsampling, 1 = even rows, 2 = every 4th, etc. |
---|
| 88 | Int iSubShift; |
---|
| 89 | |
---|
| 90 | DistParam() |
---|
| 91 | { |
---|
| 92 | pOrg = NULL; |
---|
| 93 | pCur = NULL; |
---|
| 94 | iStrideOrg = 0; |
---|
| 95 | iStrideCur = 0; |
---|
| 96 | iRows = 0; |
---|
| 97 | iCols = 0; |
---|
| 98 | iStep = 1; |
---|
| 99 | DistFunc = NULL; |
---|
| 100 | iSubShift = 0; |
---|
| 101 | bitDepth = 0; |
---|
| 102 | } |
---|
| 103 | }; |
---|
| 104 | |
---|
| 105 | /// RD cost computation class |
---|
| 106 | class TComRdCost |
---|
| 107 | : public TComRdCostWeightPrediction |
---|
| 108 | { |
---|
| 109 | private: |
---|
| 110 | // for distortion |
---|
| 111 | |
---|
| 112 | #if AMP_SAD |
---|
| 113 | FpDistFunc m_afpDistortFunc[64]; // [eDFunc] |
---|
| 114 | #else |
---|
| 115 | FpDistFunc m_afpDistortFunc[33]; // [eDFunc] |
---|
| 116 | #endif |
---|
| 117 | |
---|
| 118 | Double m_cbDistortionWeight; |
---|
| 119 | Double m_crDistortionWeight; |
---|
| 120 | Double m_dLambda; |
---|
| 121 | Double m_sqrtLambda; |
---|
| 122 | UInt m_uiLambdaMotionSAD; |
---|
| 123 | UInt m_uiLambdaMotionSSE; |
---|
| 124 | Double m_dFrameLambda; |
---|
| 125 | |
---|
| 126 | // for motion cost |
---|
| 127 | #if FIX203 |
---|
| 128 | TComMv m_mvPredictor; |
---|
| 129 | #else |
---|
| 130 | UInt* m_puiComponentCostOriginP; |
---|
| 131 | UInt* m_puiComponentCost; |
---|
| 132 | UInt* m_puiVerCost; |
---|
| 133 | UInt* m_puiHorCost; |
---|
| 134 | #endif |
---|
| 135 | UInt m_uiCost; |
---|
| 136 | Int m_iCostScale; |
---|
| 137 | #if !FIX203 |
---|
| 138 | Int m_iSearchLimit; |
---|
| 139 | #endif |
---|
| 140 | |
---|
| 141 | public: |
---|
| 142 | TComRdCost(); |
---|
| 143 | virtual ~TComRdCost(); |
---|
| 144 | |
---|
| 145 | Double calcRdCost ( UInt uiBits, UInt uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT ); |
---|
| 146 | Double calcRdCost64( UInt64 uiBits, UInt64 uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT ); |
---|
| 147 | |
---|
| 148 | Void setCbDistortionWeight ( Double cbDistortionWeight) { m_cbDistortionWeight = cbDistortionWeight; }; |
---|
| 149 | Void setCrDistortionWeight ( Double crDistortionWeight) { m_crDistortionWeight = crDistortionWeight; }; |
---|
| 150 | Void setLambda ( Double dLambda ); |
---|
| 151 | Void setFrameLambda ( Double dLambda ) { m_dFrameLambda = dLambda; } |
---|
| 152 | |
---|
| 153 | Double getSqrtLambda () { return m_sqrtLambda; } |
---|
| 154 | |
---|
| 155 | Double getLambda() { return m_dLambda; } |
---|
| 156 | Double getChromaWeight () {return((m_cbDistortionWeight+m_crDistortionWeight)/2.0);} |
---|
| 157 | |
---|
| 158 | // Distortion Functions |
---|
| 159 | Void init(); |
---|
| 160 | |
---|
| 161 | Void setDistParam( UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc, DistParam& rcDistParam ); |
---|
| 162 | Void setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, DistParam& rcDistParam ); |
---|
| 163 | Void setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false ); |
---|
| 164 | Void setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false ); |
---|
| 165 | |
---|
| 166 | UInt calcHAD(Int bitDepth, Pel* pi0, Int iStride0, Pel* pi1, Int iStride1, Int iWidth, Int iHeight ); |
---|
| 167 | |
---|
| 168 | // for motion cost |
---|
| 169 | #if !FIX203 |
---|
| 170 | Void initRateDistortionModel( Int iSubPelSearchLimit ); |
---|
| 171 | Void xUninit(); |
---|
| 172 | #endif |
---|
| 173 | UInt xGetComponentBits( Int iVal ); |
---|
| 174 | Void getMotionCost( Bool bSad, Int iAdd ) { m_uiCost = (bSad ? m_uiLambdaMotionSAD + iAdd : m_uiLambdaMotionSSE + iAdd); } |
---|
| 175 | Void setPredictor( TComMv& rcMv ) |
---|
| 176 | { |
---|
| 177 | #if FIX203 |
---|
| 178 | m_mvPredictor = rcMv; |
---|
| 179 | #else |
---|
| 180 | m_puiHorCost = m_puiComponentCost - rcMv.getHor(); |
---|
| 181 | m_puiVerCost = m_puiComponentCost - rcMv.getVer(); |
---|
| 182 | #endif |
---|
| 183 | } |
---|
| 184 | Void setCostScale( Int iCostScale ) { m_iCostScale = iCostScale; } |
---|
| 185 | __inline UInt getCost( Int x, Int y ) |
---|
| 186 | { |
---|
| 187 | #if FIX203 |
---|
| 188 | return m_uiCost * getBits(x, y) >> 16; |
---|
| 189 | #else |
---|
| 190 | return (( m_uiCost * (m_puiHorCost[ x * (1<<m_iCostScale) ] + m_puiVerCost[ y * (1<<m_iCostScale) ]) ) >> 16); |
---|
| 191 | #endif |
---|
| 192 | } |
---|
| 193 | UInt getCost( UInt b ) { return ( m_uiCost * b ) >> 16; } |
---|
| 194 | UInt getBits( Int x, Int y ) |
---|
| 195 | { |
---|
| 196 | #if FIX203 |
---|
| 197 | return xGetComponentBits((x << m_iCostScale) - m_mvPredictor.getHor()) |
---|
| 198 | + xGetComponentBits((y << m_iCostScale) - m_mvPredictor.getVer()); |
---|
| 199 | #else |
---|
| 200 | return m_puiHorCost[ x * (1<<m_iCostScale)] + m_puiVerCost[ y * (1<<m_iCostScale) ]; |
---|
| 201 | #endif |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | private: |
---|
| 205 | |
---|
| 206 | static UInt xGetSSE ( DistParam* pcDtParam ); |
---|
| 207 | static UInt xGetSSE4 ( DistParam* pcDtParam ); |
---|
| 208 | static UInt xGetSSE8 ( DistParam* pcDtParam ); |
---|
| 209 | static UInt xGetSSE16 ( DistParam* pcDtParam ); |
---|
| 210 | static UInt xGetSSE32 ( DistParam* pcDtParam ); |
---|
| 211 | static UInt xGetSSE64 ( DistParam* pcDtParam ); |
---|
| 212 | static UInt xGetSSE16N ( DistParam* pcDtParam ); |
---|
| 213 | |
---|
| 214 | static UInt xGetSAD ( DistParam* pcDtParam ); |
---|
| 215 | static UInt xGetSAD4 ( DistParam* pcDtParam ); |
---|
| 216 | static UInt xGetSAD8 ( DistParam* pcDtParam ); |
---|
| 217 | static UInt xGetSAD16 ( DistParam* pcDtParam ); |
---|
| 218 | static UInt xGetSAD32 ( DistParam* pcDtParam ); |
---|
| 219 | static UInt xGetSAD64 ( DistParam* pcDtParam ); |
---|
| 220 | static UInt xGetSAD16N ( DistParam* pcDtParam ); |
---|
| 221 | |
---|
| 222 | #if AMP_SAD |
---|
| 223 | static UInt xGetSAD12 ( DistParam* pcDtParam ); |
---|
| 224 | static UInt xGetSAD24 ( DistParam* pcDtParam ); |
---|
| 225 | static UInt xGetSAD48 ( DistParam* pcDtParam ); |
---|
| 226 | |
---|
| 227 | #endif |
---|
| 228 | |
---|
| 229 | static UInt xGetHADs4 ( DistParam* pcDtParam ); |
---|
| 230 | static UInt xGetHADs8 ( DistParam* pcDtParam ); |
---|
| 231 | static UInt xGetHADs ( DistParam* pcDtParam ); |
---|
| 232 | static UInt xCalcHADs2x2 ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep ); |
---|
| 233 | static UInt xCalcHADs4x4 ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep ); |
---|
| 234 | static UInt xCalcHADs8x8 ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep ); |
---|
| 235 | |
---|
| 236 | public: |
---|
| 237 | UInt getDistPart(Int bitDepth, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, TextType eText = TEXT_LUMA, DFunc eDFunc = DF_SSE ); |
---|
| 238 | |
---|
| 239 | };// END CLASS DEFINITION TComRdCost |
---|
| 240 | |
---|
| 241 | //! \} |
---|
| 242 | |
---|
| 243 | #endif // __TCOMRDCOST__ |
---|