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 | /** \file WeightPredAnalysis.cpp |
---|
35 | \brief weighted prediction encoder class |
---|
36 | */ |
---|
37 | |
---|
38 | #include "../TLibCommon/TypeDef.h" |
---|
39 | #include "../TLibCommon/TComSlice.h" |
---|
40 | #include "../TLibCommon/TComPic.h" |
---|
41 | #include "../TLibCommon/TComPicYuv.h" |
---|
42 | #include "WeightPredAnalysis.h" |
---|
43 | |
---|
44 | #define ABS(a) ((a) < 0 ? - (a) : (a)) |
---|
45 | #define DTHRESH (0.99) |
---|
46 | |
---|
47 | WeightPredAnalysis::WeightPredAnalysis() |
---|
48 | { |
---|
49 | m_weighted_pred_flag = false; |
---|
50 | m_weighted_bipred_flag = false; |
---|
51 | for ( Int iList =0 ; iList<2 ; iList++ ) |
---|
52 | { |
---|
53 | for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) |
---|
54 | { |
---|
55 | for ( Int comp=0 ; comp<3 ;comp++ ) |
---|
56 | { |
---|
57 | wpScalingParam *pwp = &(m_wp[iList][iRefIdx][comp]); |
---|
58 | pwp->bPresentFlag = false; |
---|
59 | pwp->uiLog2WeightDenom = 0; |
---|
60 | pwp->iWeight = 1; |
---|
61 | pwp->iOffset = 0; |
---|
62 | } |
---|
63 | } |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | /** calculate AC and DC values for current original image |
---|
68 | * \param TComSlice *slice |
---|
69 | * \returns Void |
---|
70 | */ |
---|
71 | Bool WeightPredAnalysis::xCalcACDCParamSlice(TComSlice *slice) |
---|
72 | { |
---|
73 | //===== calculate AC/DC value ===== |
---|
74 | TComPicYuv* pPic = slice->getPic()->getPicYuvOrg(); |
---|
75 | Int iSample = 0; |
---|
76 | #if O0194_WEIGHTED_PREDICTION_CGS |
---|
77 | // Define here to assign the parameter of "iSample" |
---|
78 | wpACDCParam weightACDCParam[3]; |
---|
79 | #endif |
---|
80 | |
---|
81 | // calculate DC/AC value for Y |
---|
82 | Pel* pOrg = pPic->getLumaAddr(); |
---|
83 | Int64 iOrgDCY = xCalcDCValueSlice(slice, pOrg, &iSample); |
---|
84 | Int64 iOrgNormDCY = ((iOrgDCY+(iSample>>1)) / iSample); |
---|
85 | pOrg = pPic->getLumaAddr(); |
---|
86 | Int64 iOrgACY = xCalcACValueSlice(slice, pOrg, iOrgNormDCY); |
---|
87 | #if O0194_WEIGHTED_PREDICTION_CGS |
---|
88 | weightACDCParam[0].iSamples = iSample; |
---|
89 | #endif |
---|
90 | |
---|
91 | // calculate DC/AC value for Cb |
---|
92 | pOrg = pPic->getCbAddr(); |
---|
93 | Int64 iOrgDCCb = xCalcDCValueUVSlice(slice, pOrg, &iSample); |
---|
94 | Int64 iOrgNormDCCb = ((iOrgDCCb+(iSample>>1)) / (iSample)); |
---|
95 | pOrg = pPic->getCbAddr(); |
---|
96 | Int64 iOrgACCb = xCalcACValueUVSlice(slice, pOrg, iOrgNormDCCb); |
---|
97 | #if O0194_WEIGHTED_PREDICTION_CGS |
---|
98 | weightACDCParam[1].iSamples = iSample; |
---|
99 | #endif |
---|
100 | |
---|
101 | // calculate DC/AC value for Cr |
---|
102 | pOrg = pPic->getCrAddr(); |
---|
103 | Int64 iOrgDCCr = xCalcDCValueUVSlice(slice, pOrg, &iSample); |
---|
104 | Int64 iOrgNormDCCr = ((iOrgDCCr+(iSample>>1)) / (iSample)); |
---|
105 | pOrg = pPic->getCrAddr(); |
---|
106 | Int64 iOrgACCr = xCalcACValueUVSlice(slice, pOrg, iOrgNormDCCr); |
---|
107 | #if O0194_WEIGHTED_PREDICTION_CGS |
---|
108 | weightACDCParam[2].iSamples = iSample; |
---|
109 | #endif |
---|
110 | |
---|
111 | #if !O0194_WEIGHTED_PREDICTION_CGS |
---|
112 | wpACDCParam weightACDCParam[3]; |
---|
113 | #endif |
---|
114 | weightACDCParam[0].iAC = iOrgACY; |
---|
115 | weightACDCParam[0].iDC = iOrgNormDCY; |
---|
116 | weightACDCParam[1].iAC = iOrgACCb; |
---|
117 | weightACDCParam[1].iDC = iOrgNormDCCb; |
---|
118 | weightACDCParam[2].iAC = iOrgACCr; |
---|
119 | weightACDCParam[2].iDC = iOrgNormDCCr; |
---|
120 | |
---|
121 | slice->setWpAcDcParam(weightACDCParam); |
---|
122 | return (true); |
---|
123 | } |
---|
124 | |
---|
125 | /** store weighted_pred_flag and weighted_bipred_idc values |
---|
126 | * \param weighted_pred_flag |
---|
127 | * \param weighted_bipred_idc |
---|
128 | * \returns Void |
---|
129 | */ |
---|
130 | Void WeightPredAnalysis::xStoreWPparam(Bool weighted_pred_flag, Bool weighted_bipred_flag) |
---|
131 | { |
---|
132 | m_weighted_pred_flag = weighted_pred_flag; |
---|
133 | m_weighted_bipred_flag = weighted_bipred_flag; |
---|
134 | } |
---|
135 | |
---|
136 | /** restore weighted_pred_flag and weighted_bipred_idc values |
---|
137 | * \param TComSlice *slice |
---|
138 | * \returns Void |
---|
139 | */ |
---|
140 | Void WeightPredAnalysis::xRestoreWPparam(TComSlice *slice) |
---|
141 | { |
---|
142 | slice->getPPS()->setUseWP(m_weighted_pred_flag); |
---|
143 | slice->getPPS()->setWPBiPred(m_weighted_bipred_flag); |
---|
144 | } |
---|
145 | |
---|
146 | /** check weighted pred or non-weighted pred |
---|
147 | * \param TComSlice *slice |
---|
148 | * \returns Void |
---|
149 | */ |
---|
150 | Void WeightPredAnalysis::xCheckWPEnable(TComSlice *slice) |
---|
151 | { |
---|
152 | Int iPresentCnt = 0; |
---|
153 | for ( Int iList=0 ; iList<2 ; iList++ ) |
---|
154 | { |
---|
155 | for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) |
---|
156 | { |
---|
157 | for ( Int iComp=0 ; iComp<3 ;iComp++ ) |
---|
158 | { |
---|
159 | wpScalingParam *pwp = &(m_wp[iList][iRefIdx][iComp]); |
---|
160 | iPresentCnt += (Int)pwp->bPresentFlag; |
---|
161 | } |
---|
162 | } |
---|
163 | } |
---|
164 | |
---|
165 | if(iPresentCnt==0) |
---|
166 | { |
---|
167 | slice->getPPS()->setUseWP(false); |
---|
168 | slice->getPPS()->setWPBiPred(false); |
---|
169 | for ( Int iList=0 ; iList<2 ; iList++ ) |
---|
170 | { |
---|
171 | for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) |
---|
172 | { |
---|
173 | for ( Int iComp=0 ; iComp<3 ;iComp++ ) |
---|
174 | { |
---|
175 | wpScalingParam *pwp = &(m_wp[iList][iRefIdx][iComp]); |
---|
176 | pwp->bPresentFlag = false; |
---|
177 | pwp->uiLog2WeightDenom = 0; |
---|
178 | pwp->iWeight = 1; |
---|
179 | pwp->iOffset = 0; |
---|
180 | } |
---|
181 | } |
---|
182 | } |
---|
183 | slice->setWpScaling( m_wp ); |
---|
184 | } |
---|
185 | } |
---|
186 | |
---|
187 | /** estimate wp tables for explicit wp |
---|
188 | * \param TComSlice *slice |
---|
189 | * \returns Bool |
---|
190 | */ |
---|
191 | Bool WeightPredAnalysis::xEstimateWPParamSlice(TComSlice *slice) |
---|
192 | { |
---|
193 | Int iDenom = 6; |
---|
194 | Bool validRangeFlag = false; |
---|
195 | |
---|
196 | if(slice->getNumRefIdx(REF_PIC_LIST_0)>3) |
---|
197 | { |
---|
198 | iDenom = 7; |
---|
199 | } |
---|
200 | |
---|
201 | do |
---|
202 | { |
---|
203 | validRangeFlag = xUpdatingWPParameters(slice, m_wp, iDenom); |
---|
204 | if (!validRangeFlag) |
---|
205 | { |
---|
206 | iDenom--; // decrement to satisfy the range limitation |
---|
207 | } |
---|
208 | } while (validRangeFlag == false); |
---|
209 | |
---|
210 | // selecting whether WP is used, or not |
---|
211 | xSelectWP(slice, m_wp, iDenom); |
---|
212 | |
---|
213 | slice->setWpScaling( m_wp ); |
---|
214 | |
---|
215 | return (true); |
---|
216 | } |
---|
217 | |
---|
218 | /** update wp tables for explicit wp w.r.t ramge limitation |
---|
219 | * \param TComSlice *slice |
---|
220 | * \returns Bool |
---|
221 | */ |
---|
222 | Bool WeightPredAnalysis::xUpdatingWPParameters(TComSlice *slice, wpScalingParam weightPredTable[2][MAX_NUM_REF][3], Int log2Denom) |
---|
223 | { |
---|
224 | Int numPredDir = slice->isInterP() ? 1 : 2; |
---|
225 | for ( Int refList = 0; refList < numPredDir; refList++ ) |
---|
226 | { |
---|
227 | RefPicList eRefPicList = ( refList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); |
---|
228 | for ( Int refIdxTemp = 0; refIdxTemp < slice->getNumRefIdx(eRefPicList); refIdxTemp++ ) |
---|
229 | { |
---|
230 | wpACDCParam *currWeightACDCParam, *refWeightACDCParam; |
---|
231 | slice->getWpAcDcParam(currWeightACDCParam); |
---|
232 | slice->getRefPic(eRefPicList, refIdxTemp)->getSlice(0)->getWpAcDcParam(refWeightACDCParam); |
---|
233 | #if O0194_WEIGHTED_PREDICTION_CGS |
---|
234 | if (slice->getRefPic(eRefPicList, refIdxTemp)->isILR(slice->getLayerId())) |
---|
235 | { |
---|
236 | refWeightACDCParam = (wpACDCParam *)g_refWeightACDCParam; |
---|
237 | } |
---|
238 | #endif |
---|
239 | |
---|
240 | for ( Int comp = 0; comp < 3; comp++ ) |
---|
241 | { |
---|
242 | Int bitDepth = comp ? g_bitDepthC : g_bitDepthY; |
---|
243 | Int realLog2Denom = log2Denom + bitDepth-8; |
---|
244 | Int realOffset = ((Int)1<<(realLog2Denom-1)); |
---|
245 | |
---|
246 | // current frame |
---|
247 | Int64 currDC = currWeightACDCParam[comp].iDC; |
---|
248 | Int64 currAC = currWeightACDCParam[comp].iAC; |
---|
249 | // reference frame |
---|
250 | Int64 refDC = refWeightACDCParam[comp].iDC; |
---|
251 | Int64 refAC = refWeightACDCParam[comp].iAC; |
---|
252 | #if O0194_WEIGHTED_PREDICTION_CGS |
---|
253 | if (slice->getRefPic(eRefPicList, refIdxTemp)->isILR(slice->getLayerId())) |
---|
254 | { |
---|
255 | refAC = ( refAC * currWeightACDCParam[comp].iSamples ) /refWeightACDCParam[comp].iSamples; |
---|
256 | #if O0194_JOINT_US_BITSHIFT |
---|
257 | refAC <<= (g_bitDepthYLayer[1]-g_bitDepthYLayer[0]); |
---|
258 | refDC <<= (g_bitDepthYLayer[1]-g_bitDepthYLayer[0]); |
---|
259 | #endif |
---|
260 | } |
---|
261 | #endif |
---|
262 | |
---|
263 | // calculating iWeight and iOffset params |
---|
264 | Double dWeight = (refAC==0) ? (Double)1.0 : Clip3( -16.0, 15.0, ((Double)currAC / (Double)refAC) ); |
---|
265 | Int weight = (Int)( 0.5 + dWeight * (Double)(1<<log2Denom) ); |
---|
266 | Int offset = (Int)( ((currDC<<log2Denom) - ((Int64)weight * refDC) + (Int64)realOffset) >> realLog2Denom ); |
---|
267 | #if O0194_WEIGHTED_PREDICTION_CGS |
---|
268 | if (slice->getRefPic(eRefPicList, refIdxTemp)->isILR(slice->getLayerId())) |
---|
269 | { |
---|
270 | } |
---|
271 | else |
---|
272 | { |
---|
273 | dWeight = 1; |
---|
274 | offset = 0; |
---|
275 | } |
---|
276 | weight = (Int)( 0.5 + dWeight * (Double)(1<<log2Denom) ); |
---|
277 | #endif |
---|
278 | |
---|
279 | // Chroma offset range limitation |
---|
280 | if(comp) |
---|
281 | { |
---|
282 | Int pred = ( 128 - ( ( 128*weight)>>(log2Denom) ) ); |
---|
283 | Int deltaOffset = Clip3( -512, 511, (offset - pred) ); // signed 10bit |
---|
284 | offset = Clip3( -128, 127, (deltaOffset + pred) ); // signed 8bit |
---|
285 | } |
---|
286 | // Luma offset range limitation |
---|
287 | else |
---|
288 | { |
---|
289 | offset = Clip3( -128, 127, offset); |
---|
290 | } |
---|
291 | |
---|
292 | // Weighting factor limitation |
---|
293 | Int defaultWeight = (1<<log2Denom); |
---|
294 | Int deltaWeight = (defaultWeight - weight); |
---|
295 | if(deltaWeight > 127 || deltaWeight < -128) |
---|
296 | return (false); |
---|
297 | #if O0194_WEIGHTED_PREDICTION_CGS |
---|
298 | // make sure the reference frames other than ILR are not using weighted prediction |
---|
299 | if (!(slice->getRefPic(eRefPicList, refIdxTemp)->isILR(slice->getLayerId()))) |
---|
300 | { |
---|
301 | continue; |
---|
302 | } |
---|
303 | #endif |
---|
304 | |
---|
305 | m_wp[refList][refIdxTemp][comp].bPresentFlag = true; |
---|
306 | m_wp[refList][refIdxTemp][comp].iWeight = (Int)weight; |
---|
307 | m_wp[refList][refIdxTemp][comp].iOffset = (Int)offset; |
---|
308 | m_wp[refList][refIdxTemp][comp].uiLog2WeightDenom = (Int)log2Denom; |
---|
309 | } |
---|
310 | } |
---|
311 | } |
---|
312 | return (true); |
---|
313 | } |
---|
314 | |
---|
315 | /** select whether weighted pred enables or not. |
---|
316 | * \param TComSlice *slice |
---|
317 | * \param wpScalingParam |
---|
318 | * \param iDenom |
---|
319 | * \returns Bool |
---|
320 | */ |
---|
321 | Bool WeightPredAnalysis::xSelectWP(TComSlice *slice, wpScalingParam weightPredTable[2][MAX_NUM_REF][3], Int iDenom) |
---|
322 | { |
---|
323 | TComPicYuv* pPic = slice->getPic()->getPicYuvOrg(); |
---|
324 | Int iWidth = pPic->getWidth(); |
---|
325 | Int iHeight = pPic->getHeight(); |
---|
326 | Int iDefaultWeight = ((Int)1<<iDenom); |
---|
327 | Int iNumPredDir = slice->isInterP() ? 1 : 2; |
---|
328 | |
---|
329 | for ( Int iRefList = 0; iRefList < iNumPredDir; iRefList++ ) |
---|
330 | { |
---|
331 | Int64 iSADWP = 0, iSADnoWP = 0; |
---|
332 | RefPicList eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); |
---|
333 | for ( Int iRefIdxTemp = 0; iRefIdxTemp < slice->getNumRefIdx(eRefPicList); iRefIdxTemp++ ) |
---|
334 | { |
---|
335 | Pel* pOrg = pPic->getLumaAddr(); |
---|
336 | Pel* pRef = slice->getRefPic(eRefPicList, iRefIdxTemp)->getPicYuvRec()->getLumaAddr(); |
---|
337 | Int iOrgStride = pPic->getStride(); |
---|
338 | Int iRefStride = slice->getRefPic(eRefPicList, iRefIdxTemp)->getPicYuvRec()->getStride(); |
---|
339 | |
---|
340 | // calculate SAD costs with/without wp for luma |
---|
341 | iSADWP = this->xCalcSADvalueWP(g_bitDepthY, pOrg, pRef, iWidth, iHeight, iOrgStride, iRefStride, iDenom, weightPredTable[iRefList][iRefIdxTemp][0].iWeight, weightPredTable[iRefList][iRefIdxTemp][0].iOffset); |
---|
342 | iSADnoWP = this->xCalcSADvalueWP(g_bitDepthY, pOrg, pRef, iWidth, iHeight, iOrgStride, iRefStride, iDenom, iDefaultWeight, 0); |
---|
343 | |
---|
344 | pOrg = pPic->getCbAddr(); |
---|
345 | pRef = slice->getRefPic(eRefPicList, iRefIdxTemp)->getPicYuvRec()->getCbAddr(); |
---|
346 | iOrgStride = pPic->getCStride(); |
---|
347 | iRefStride = slice->getRefPic(eRefPicList, iRefIdxTemp)->getPicYuvRec()->getCStride(); |
---|
348 | |
---|
349 | // calculate SAD costs with/without wp for chroma cb |
---|
350 | iSADWP += this->xCalcSADvalueWP(g_bitDepthC, pOrg, pRef, iWidth>>1, iHeight>>1, iOrgStride, iRefStride, iDenom, weightPredTable[iRefList][iRefIdxTemp][1].iWeight, weightPredTable[iRefList][iRefIdxTemp][1].iOffset); |
---|
351 | iSADnoWP += this->xCalcSADvalueWP(g_bitDepthC, pOrg, pRef, iWidth>>1, iHeight>>1, iOrgStride, iRefStride, iDenom, iDefaultWeight, 0); |
---|
352 | |
---|
353 | pOrg = pPic->getCrAddr(); |
---|
354 | pRef = slice->getRefPic(eRefPicList, iRefIdxTemp)->getPicYuvRec()->getCrAddr(); |
---|
355 | |
---|
356 | // calculate SAD costs with/without wp for chroma cr |
---|
357 | iSADWP += this->xCalcSADvalueWP(g_bitDepthC, pOrg, pRef, iWidth>>1, iHeight>>1, iOrgStride, iRefStride, iDenom, weightPredTable[iRefList][iRefIdxTemp][2].iWeight, weightPredTable[iRefList][iRefIdxTemp][2].iOffset); |
---|
358 | iSADnoWP += this->xCalcSADvalueWP(g_bitDepthC, pOrg, pRef, iWidth>>1, iHeight>>1, iOrgStride, iRefStride, iDenom, iDefaultWeight, 0); |
---|
359 | |
---|
360 | Double dRatio = ((Double)iSADWP / (Double)iSADnoWP); |
---|
361 | if(dRatio >= (Double)DTHRESH) |
---|
362 | { |
---|
363 | for ( Int iComp = 0; iComp < 3; iComp++ ) |
---|
364 | { |
---|
365 | weightPredTable[iRefList][iRefIdxTemp][iComp].bPresentFlag = false; |
---|
366 | weightPredTable[iRefList][iRefIdxTemp][iComp].iOffset = (Int)0; |
---|
367 | weightPredTable[iRefList][iRefIdxTemp][iComp].iWeight = (Int)iDefaultWeight; |
---|
368 | weightPredTable[iRefList][iRefIdxTemp][iComp].uiLog2WeightDenom = (Int)iDenom; |
---|
369 | } |
---|
370 | } |
---|
371 | } |
---|
372 | } |
---|
373 | return (true); |
---|
374 | } |
---|
375 | |
---|
376 | /** calculate DC value of original image for luma. |
---|
377 | * \param TComSlice *slice |
---|
378 | * \param Pel *pPel |
---|
379 | * \param Int *iSample |
---|
380 | * \returns Int64 |
---|
381 | */ |
---|
382 | Int64 WeightPredAnalysis::xCalcDCValueSlice(TComSlice *slice, Pel *pPel, Int *iSample) |
---|
383 | { |
---|
384 | TComPicYuv* pPic = slice->getPic()->getPicYuvOrg(); |
---|
385 | Int iStride = pPic->getStride(); |
---|
386 | |
---|
387 | *iSample = 0; |
---|
388 | Int iWidth = pPic->getWidth(); |
---|
389 | Int iHeight = pPic->getHeight(); |
---|
390 | *iSample = iWidth*iHeight; |
---|
391 | Int64 iDC = xCalcDCValue(pPel, iWidth, iHeight, iStride); |
---|
392 | |
---|
393 | return (iDC); |
---|
394 | } |
---|
395 | |
---|
396 | /** calculate AC value of original image for luma. |
---|
397 | * \param TComSlice *slice |
---|
398 | * \param Pel *pPel |
---|
399 | * \param Int iDC |
---|
400 | * \returns Int64 |
---|
401 | */ |
---|
402 | Int64 WeightPredAnalysis::xCalcACValueSlice(TComSlice *slice, Pel *pPel, Int64 iDC) |
---|
403 | { |
---|
404 | TComPicYuv* pPic = slice->getPic()->getPicYuvOrg(); |
---|
405 | Int iStride = pPic->getStride(); |
---|
406 | |
---|
407 | Int iWidth = pPic->getWidth(); |
---|
408 | Int iHeight = pPic->getHeight(); |
---|
409 | Int64 iAC = xCalcACValue(pPel, iWidth, iHeight, iStride, iDC); |
---|
410 | |
---|
411 | return (iAC); |
---|
412 | } |
---|
413 | |
---|
414 | /** calculate DC value of original image for chroma. |
---|
415 | * \param TComSlice *slice |
---|
416 | * \param Pel *pPel |
---|
417 | * \param Int *iSample |
---|
418 | * \returns Int64 |
---|
419 | */ |
---|
420 | Int64 WeightPredAnalysis::xCalcDCValueUVSlice(TComSlice *slice, Pel *pPel, Int *iSample) |
---|
421 | { |
---|
422 | TComPicYuv* pPic = slice->getPic()->getPicYuvOrg(); |
---|
423 | Int iCStride = pPic->getCStride(); |
---|
424 | |
---|
425 | *iSample = 0; |
---|
426 | Int iWidth = pPic->getWidth()>>1; |
---|
427 | Int iHeight = pPic->getHeight()>>1; |
---|
428 | *iSample = iWidth*iHeight; |
---|
429 | Int64 iDC = xCalcDCValue(pPel, iWidth, iHeight, iCStride); |
---|
430 | |
---|
431 | return (iDC); |
---|
432 | } |
---|
433 | |
---|
434 | /** calculate AC value of original image for chroma. |
---|
435 | * \param TComSlice *slice |
---|
436 | * \param Pel *pPel |
---|
437 | * \param Int iDC |
---|
438 | * \returns Int64 |
---|
439 | */ |
---|
440 | Int64 WeightPredAnalysis::xCalcACValueUVSlice(TComSlice *slice, Pel *pPel, Int64 iDC) |
---|
441 | { |
---|
442 | TComPicYuv* pPic = slice->getPic()->getPicYuvOrg(); |
---|
443 | Int iCStride = pPic->getCStride(); |
---|
444 | |
---|
445 | Int iWidth = pPic->getWidth()>>1; |
---|
446 | Int iHeight = pPic->getHeight()>>1; |
---|
447 | Int64 iAC = xCalcACValue(pPel, iWidth, iHeight, iCStride, iDC); |
---|
448 | |
---|
449 | return (iAC); |
---|
450 | } |
---|
451 | |
---|
452 | /** calculate DC value. |
---|
453 | * \param Pel *pPel |
---|
454 | * \param Int iWidth |
---|
455 | * \param Int iHeight |
---|
456 | * \param Int iStride |
---|
457 | * \returns Int64 |
---|
458 | */ |
---|
459 | Int64 WeightPredAnalysis::xCalcDCValue(Pel *pPel, Int iWidth, Int iHeight, Int iStride) |
---|
460 | { |
---|
461 | Int x, y; |
---|
462 | Int64 iDC = 0; |
---|
463 | for( y = 0; y < iHeight; y++ ) |
---|
464 | { |
---|
465 | for( x = 0; x < iWidth; x++ ) |
---|
466 | { |
---|
467 | iDC += (Int)( pPel[x] ); |
---|
468 | } |
---|
469 | pPel += iStride; |
---|
470 | } |
---|
471 | return (iDC); |
---|
472 | } |
---|
473 | |
---|
474 | /** calculate AC value. |
---|
475 | * \param Pel *pPel |
---|
476 | * \param Int iWidth |
---|
477 | * \param Int iHeight |
---|
478 | * \param Int iStride |
---|
479 | * \param Int iDC |
---|
480 | * \returns Int64 |
---|
481 | */ |
---|
482 | Int64 WeightPredAnalysis::xCalcACValue(Pel *pPel, Int iWidth, Int iHeight, Int iStride, Int64 iDC) |
---|
483 | { |
---|
484 | Int x, y; |
---|
485 | Int64 iAC = 0; |
---|
486 | for( y = 0; y < iHeight; y++ ) |
---|
487 | { |
---|
488 | for( x = 0; x < iWidth; x++ ) |
---|
489 | { |
---|
490 | iAC += abs( (Int)pPel[x] - (Int)iDC ); |
---|
491 | } |
---|
492 | pPel += iStride; |
---|
493 | } |
---|
494 | return (iAC); |
---|
495 | } |
---|
496 | |
---|
497 | /** calculate SAD values for both WP version and non-WP version. |
---|
498 | * \param Pel *pOrgPel |
---|
499 | * \param Pel *pRefPel |
---|
500 | * \param Int iWidth |
---|
501 | * \param Int iHeight |
---|
502 | * \param Int iOrgStride |
---|
503 | * \param Int iRefStride |
---|
504 | * \param Int iDenom |
---|
505 | * \param Int iWeight |
---|
506 | * \param Int iOffset |
---|
507 | * \returns Int64 |
---|
508 | */ |
---|
509 | Int64 WeightPredAnalysis::xCalcSADvalueWP(Int bitDepth, Pel *pOrgPel, Pel *pRefPel, Int iWidth, Int iHeight, Int iOrgStride, Int iRefStride, Int iDenom, Int iWeight, Int iOffset) |
---|
510 | { |
---|
511 | Int x, y; |
---|
512 | Int64 iSAD = 0; |
---|
513 | Int64 iSize = iWidth*iHeight; |
---|
514 | Int64 iRealDenom = iDenom + bitDepth-8; |
---|
515 | for( y = 0; y < iHeight; y++ ) |
---|
516 | { |
---|
517 | for( x = 0; x < iWidth; x++ ) |
---|
518 | { |
---|
519 | iSAD += ABS(( ((Int64)pOrgPel[x]<<(Int64)iDenom) - ( (Int64)pRefPel[x] * (Int64)iWeight + ((Int64)iOffset<<iRealDenom) ) ) ); |
---|
520 | } |
---|
521 | pOrgPel += iOrgStride; |
---|
522 | pRefPel += iRefStride; |
---|
523 | } |
---|
524 | return (iSAD/iSize); |
---|
525 | } |
---|
526 | |
---|
527 | |
---|