source: 3DVCSoftware/branches/HTM-14.1-update-dev3/source/Lib/TLibCommon/TComYuv.cpp @ 1270

Last change on this file since 1270 was 1270, checked in by tech, 9 years ago

Merged 14.1-update-dev4-Qualcomm@1266

  • Property svn:eol-style set to native
File size: 21.3 KB
Line 
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-2015, 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     TComYuv.cpp
35    \brief    general YUV buffer class
36    \todo     this should be merged with TComPicYuv
37*/
38
39#include <stdlib.h>
40#include <memory.h>
41#include <assert.h>
42#include <math.h>
43
44#include "CommonDef.h"
45#include "TComYuv.h"
46#include "TComInterpolationFilter.h"
47
48//! \ingroup TLibCommon
49//! \{
50
51TComYuv::TComYuv()
52{
53  for(Int comp=0; comp<MAX_NUM_COMPONENT; comp++)
54  {
55    m_apiBuf[comp] = NULL;
56  }
57}
58
59TComYuv::~TComYuv()
60{
61}
62
63Void TComYuv::create( UInt iWidth, UInt iHeight, ChromaFormat chromaFormatIDC )
64{
65  // set width and height
66  m_iWidth   = iWidth;
67  m_iHeight  = iHeight;
68  m_chromaFormatIDC = chromaFormatIDC;
69
70  for(Int comp=0; comp<MAX_NUM_COMPONENT; comp++)
71  {
72    // memory allocation
73    m_apiBuf[comp]  = (Pel*)xMalloc( Pel, getWidth(ComponentID(comp))*getHeight(ComponentID(comp)) );
74  }
75}
76
77Void TComYuv::destroy()
78{
79  // memory free
80  for(Int comp=0; comp<MAX_NUM_COMPONENT; comp++)
81  {
82    if (m_apiBuf[comp]!=NULL)
83    {
84      xFree( m_apiBuf[comp] );
85      m_apiBuf[comp] = NULL;
86    }
87  }
88}
89
90Void TComYuv::clear()
91{
92  for(Int comp=0; comp<MAX_NUM_COMPONENT; comp++)
93  {
94    if (m_apiBuf[comp]!=NULL)
95    {
96      ::memset( m_apiBuf[comp], 0, ( getWidth(ComponentID(comp)) * getHeight(ComponentID(comp))  )*sizeof(Pel) );
97    }
98  }
99}
100
101
102
103
104Void TComYuv::copyToPicYuv   ( TComPicYuv* pcPicYuvDst, const UInt ctuRsAddr, const UInt uiAbsZorderIdx, const UInt uiPartDepth, const UInt uiPartIdx ) const
105{
106  for(Int comp=0; comp<getNumberValidComponents(); comp++)
107  {
108    copyToPicComponent  ( ComponentID(comp), pcPicYuvDst, ctuRsAddr, uiAbsZorderIdx, uiPartDepth, uiPartIdx );
109  }
110}
111
112Void TComYuv::copyToPicComponent  ( const ComponentID compID, TComPicYuv* pcPicYuvDst, const UInt ctuRsAddr, const UInt uiAbsZorderIdx, const UInt uiPartDepth, const UInt uiPartIdx ) const
113{
114  const Int iWidth  = getWidth(compID) >>uiPartDepth;
115  const Int iHeight = getHeight(compID)>>uiPartDepth;
116
117  const Pel* pSrc     = getAddr(compID, uiPartIdx, iWidth);
118        Pel* pDst     = pcPicYuvDst->getAddr ( compID, ctuRsAddr, uiAbsZorderIdx );
119
120  const UInt  iSrcStride  = getStride(compID);
121  const UInt  iDstStride  = pcPicYuvDst->getStride(compID);
122
123  for ( Int y = iHeight; y != 0; y-- )
124  {
125    ::memcpy( pDst, pSrc, sizeof(Pel)*iWidth);
126#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC
127    if ( g_traceCopyBack && g_nSymbolCounter >= g_stopAtCounter )
128    { 
129      for ( Int x = 0; x < iWidth; x++)
130      {     
131        std::cout << pSrc[ x ] << " " ; 
132      }
133      std::cout << std::endl;
134    }
135#endif
136    pDst += iDstStride;
137    pSrc += iSrcStride;
138  }
139}
140
141
142
143
144Void TComYuv::copyFromPicYuv   ( const TComPicYuv* pcPicYuvSrc, const UInt ctuRsAddr, const UInt uiAbsZorderIdx )
145{
146  for(Int comp=0; comp<getNumberValidComponents(); comp++)
147  {
148    copyFromPicComponent  ( ComponentID(comp), pcPicYuvSrc, ctuRsAddr, uiAbsZorderIdx );
149  }
150}
151
152Void TComYuv::copyFromPicComponent  ( const ComponentID compID, const TComPicYuv* pcPicYuvSrc, const UInt ctuRsAddr, const UInt uiAbsZorderIdx )
153{
154        Pel* pDst     = getAddr(compID);
155  const Pel* pSrc     = pcPicYuvSrc->getAddr ( compID, ctuRsAddr, uiAbsZorderIdx );
156
157  const UInt iDstStride  = getStride(compID);
158  const UInt iSrcStride  = pcPicYuvSrc->getStride(compID);
159  const Int  iWidth=getWidth(compID);
160  const Int  iHeight=getHeight(compID);
161
162  for (Int y = iHeight; y != 0; y-- )
163  {
164    ::memcpy( pDst, pSrc, sizeof(Pel)*iWidth);
165    pDst += iDstStride;
166    pSrc += iSrcStride;
167  }
168}
169
170
171
172
173Void TComYuv::copyToPartYuv( TComYuv* pcYuvDst, const UInt uiDstPartIdx ) const
174{
175  for(Int comp=0; comp<getNumberValidComponents(); comp++)
176  {
177    copyToPartComponent  ( ComponentID(comp), pcYuvDst, uiDstPartIdx );
178  }
179}
180
181Void TComYuv::copyToPartComponent( const ComponentID compID, TComYuv* pcYuvDst, const UInt uiDstPartIdx ) const
182{
183  const Pel* pSrc     = getAddr(compID);
184        Pel* pDst     = pcYuvDst->getAddr( compID, uiDstPartIdx );
185
186  const UInt iSrcStride  = getStride(compID);
187  const UInt iDstStride  = pcYuvDst->getStride(compID);
188  const Int  iWidth=getWidth(compID);
189  const Int  iHeight=getHeight(compID);
190
191  for (Int y = iHeight; y != 0; y-- )
192  {
193    ::memcpy( pDst, pSrc, sizeof(Pel)*iWidth);
194    pDst += iDstStride;
195    pSrc += iSrcStride;
196  }
197}
198
199
200
201
202Void TComYuv::copyPartToYuv( TComYuv* pcYuvDst, const UInt uiSrcPartIdx ) const
203{
204  for(Int comp=0; comp<getNumberValidComponents(); comp++)
205  {
206    copyPartToComponent  ( ComponentID(comp), pcYuvDst, uiSrcPartIdx );
207  }
208}
209
210Void TComYuv::copyPartToComponent( const ComponentID compID, TComYuv* pcYuvDst, const UInt uiSrcPartIdx ) const
211{
212  const Pel* pSrc     = getAddr(compID, uiSrcPartIdx);
213        Pel* pDst     = pcYuvDst->getAddr(compID, 0 );
214
215  const UInt  iSrcStride  = getStride(compID);
216  const UInt  iDstStride  = pcYuvDst->getStride(compID);
217
218  const UInt uiHeight = pcYuvDst->getHeight(compID);
219  const UInt uiWidth = pcYuvDst->getWidth(compID);
220
221  for ( UInt y = uiHeight; y != 0; y-- )
222  {
223    ::memcpy( pDst, pSrc, sizeof(Pel)*uiWidth);
224    pDst += iDstStride;
225    pSrc += iSrcStride;
226  }
227}
228
229
230
231
232Void TComYuv::copyPartToPartYuv   ( TComYuv* pcYuvDst, const UInt uiPartIdx, const UInt iWidth, const UInt iHeight ) const
233{
234  for(Int comp=0; comp<getNumberValidComponents(); comp++)
235  {
236    copyPartToPartComponent   (ComponentID(comp), pcYuvDst, uiPartIdx, iWidth>>getComponentScaleX(ComponentID(comp)), iHeight>>getComponentScaleY(ComponentID(comp)) );
237  }
238}
239
240Void TComYuv::copyPartToPartComponent  ( const ComponentID compID, TComYuv* pcYuvDst, const UInt uiPartIdx, const UInt iWidthComponent, const UInt iHeightComponent ) const
241{
242  const Pel* pSrc =           getAddr(compID, uiPartIdx);
243        Pel* pDst = pcYuvDst->getAddr(compID, uiPartIdx);
244  if( pSrc == pDst )
245  {
246    //th not a good idea
247    //th best would be to fix the caller
248    return ;
249  }
250
251  const UInt  iSrcStride = getStride(compID);
252  const UInt  iDstStride = pcYuvDst->getStride(compID);
253  for ( UInt y = iHeightComponent; y != 0; y-- )
254  {
255    ::memcpy( pDst, pSrc, iWidthComponent * sizeof(Pel) );
256    pSrc += iSrcStride;
257    pDst += iDstStride;
258  }
259}
260
261
262
263
264Void TComYuv::copyPartToPartComponentMxN  ( const ComponentID compID, TComYuv* pcYuvDst, const TComRectangle &rect) const
265{
266  const Pel* pSrc =           getAddrPix( compID, rect.x0, rect.y0 );
267        Pel* pDst = pcYuvDst->getAddrPix( compID, rect.x0, rect.y0 );
268  if( pSrc == pDst )
269  {
270    //th not a good idea
271    //th best would be to fix the caller
272    return ;
273  }
274
275  const UInt  iSrcStride = getStride(compID);
276  const UInt  iDstStride = pcYuvDst->getStride(compID);
277  const UInt uiHeightComponent=rect.height;
278  const UInt uiWidthComponent=rect.width;
279  for ( UInt y = uiHeightComponent; y != 0; y-- )
280  {
281    ::memcpy( pDst, pSrc, uiWidthComponent * sizeof( Pel ) );
282    pSrc += iSrcStride;
283    pDst += iDstStride;
284  }
285}
286
287
288
289
290Void TComYuv::addClip( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt uiTrUnitIdx, const UInt uiPartSize, const BitDepths &clipBitDepths )
291{
292  for(Int comp=0; comp<getNumberValidComponents(); comp++)
293  {
294    const ComponentID compID=ComponentID(comp);
295    const Int uiPartWidth =uiPartSize>>getComponentScaleX(compID);
296    const Int uiPartHeight=uiPartSize>>getComponentScaleY(compID);
297
298    const Pel* pSrc0 = pcYuvSrc0->getAddr(compID, uiTrUnitIdx, uiPartWidth );
299    const Pel* pSrc1 = pcYuvSrc1->getAddr(compID, uiTrUnitIdx, uiPartWidth );
300          Pel* pDst  = getAddr(compID, uiTrUnitIdx, uiPartWidth );
301
302    const UInt iSrc0Stride = pcYuvSrc0->getStride(compID);
303    const UInt iSrc1Stride = pcYuvSrc1->getStride(compID);
304    const UInt iDstStride  = getStride(compID);
305    const Int clipbd = clipBitDepths.recon[toChannelType(compID)];
306#if O0043_BEST_EFFORT_DECODING
307    const Int bitDepthDelta = clipBitDepths.stream[toChannelType(compID)] - clipbd;
308#endif
309
310    for ( Int y = uiPartHeight-1; y >= 0; y-- )
311    {
312      for ( Int x = uiPartWidth-1; x >= 0; x-- )
313      {
314#if O0043_BEST_EFFORT_DECODING
315        pDst[x] = Pel(ClipBD<Int>( Int(pSrc0[x]) + rightShiftEvenRounding<Pel>(pSrc1[x], bitDepthDelta), clipbd));
316#else
317        pDst[x] = Pel(ClipBD<Int>( Int(pSrc0[x]) + Int(pSrc1[x]), clipbd));
318#endif
319      }
320      pSrc0 += iSrc0Stride;
321      pSrc1 += iSrc1Stride;
322      pDst  += iDstStride;
323    }
324  }
325}
326
327
328
329
330Void TComYuv::subtract( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt uiTrUnitIdx, const UInt uiPartSize )
331{
332  for(Int comp=0; comp<getNumberValidComponents(); comp++)
333  {
334    const ComponentID compID=ComponentID(comp);
335    const Int uiPartWidth =uiPartSize>>getComponentScaleX(compID);
336    const Int uiPartHeight=uiPartSize>>getComponentScaleY(compID);
337
338    const Pel* pSrc0 = pcYuvSrc0->getAddr( compID, uiTrUnitIdx, uiPartWidth );
339    const Pel* pSrc1 = pcYuvSrc1->getAddr( compID, uiTrUnitIdx, uiPartWidth );
340          Pel* pDst  = getAddr( compID, uiTrUnitIdx, uiPartWidth );
341
342    const Int  iSrc0Stride = pcYuvSrc0->getStride(compID);
343    const Int  iSrc1Stride = pcYuvSrc1->getStride(compID);
344    const Int  iDstStride  = getStride(compID);
345
346    for (Int y = uiPartHeight-1; y >= 0; y-- )
347    {
348      for (Int x = uiPartWidth-1; x >= 0; x-- )
349      {
350        pDst[x] = pSrc0[x] - pSrc1[x];
351      }
352      pSrc0 += iSrc0Stride;
353      pSrc1 += iSrc1Stride;
354      pDst  += iDstStride;
355    }
356  }
357}
358
359
360
361
362Void TComYuv::addAvg( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt iPartUnitIdx, const UInt uiWidth, const UInt uiHeight, const BitDepths &clipBitDepths )
363{
364  for(Int comp=0; comp<getNumberValidComponents(); comp++)
365  {
366    const ComponentID compID=ComponentID(comp);
367    const Pel* pSrc0  = pcYuvSrc0->getAddr( compID, iPartUnitIdx );
368    const Pel* pSrc1  = pcYuvSrc1->getAddr( compID, iPartUnitIdx );
369    Pel* pDst   = getAddr( compID, iPartUnitIdx );
370
371    const UInt  iSrc0Stride = pcYuvSrc0->getStride(compID);
372    const UInt  iSrc1Stride = pcYuvSrc1->getStride(compID);
373    const UInt  iDstStride  = getStride(compID);
374    const Int   clipbd      = clipBitDepths.recon[toChannelType(compID)];
375    const Int   shiftNum    = std::max<Int>(2, (IF_INTERNAL_PREC - clipbd)) + 1;
376    const Int   offset      = ( 1 << ( shiftNum - 1 ) ) + 2 * IF_INTERNAL_OFFS;
377
378    const Int   iWidth      = uiWidth  >> getComponentScaleX(compID);
379    const Int   iHeight     = uiHeight >> getComponentScaleY(compID);
380
381    if (iWidth&1)
382    {
383      assert(0);
384      exit(-1);
385    }
386    else if (iWidth&2)
387    {
388      for ( Int y = 0; y < iHeight; y++ )
389      {
390        for (Int x=0 ; x < iWidth; x+=2 )
391        {
392          pDst[ x + 0 ] = ClipBD( rightShift(( pSrc0[ x + 0 ] + pSrc1[ x + 0 ] + offset ), shiftNum), clipbd );
393          pDst[ x + 1 ] = ClipBD( rightShift(( pSrc0[ x + 1 ] + pSrc1[ x + 1 ] + offset ), shiftNum), clipbd );
394        }
395        pSrc0 += iSrc0Stride;
396        pSrc1 += iSrc1Stride;
397        pDst  += iDstStride;
398      }
399    }
400    else
401    {
402      for ( Int y = 0; y < iHeight; y++ )
403      {
404        for (Int x=0 ; x < iWidth; x+=4 )
405        {
406          pDst[ x + 0 ] = ClipBD( rightShift(( pSrc0[ x + 0 ] + pSrc1[ x + 0 ] + offset ), shiftNum), clipbd );
407          pDst[ x + 1 ] = ClipBD( rightShift(( pSrc0[ x + 1 ] + pSrc1[ x + 1 ] + offset ), shiftNum), clipbd );
408          pDst[ x + 2 ] = ClipBD( rightShift(( pSrc0[ x + 2 ] + pSrc1[ x + 2 ] + offset ), shiftNum), clipbd );
409          pDst[ x + 3 ] = ClipBD( rightShift(( pSrc0[ x + 3 ] + pSrc1[ x + 3 ] + offset ), shiftNum), clipbd );
410        }
411        pSrc0 += iSrc0Stride;
412        pSrc1 += iSrc1Stride;
413        pDst  += iDstStride;
414      }
415    }
416  }
417}
418
419Void TComYuv::removeHighFreq( const TComYuv* pcYuvSrc,
420                              const UInt uiPartIdx,
421                              const UInt uiWidth,
422                              const UInt uiHeight,
423                              const Int bitDepths[MAX_NUM_CHANNEL_TYPE],
424                              const Bool bClipToBitDepths
425                              )
426{
427  for(Int comp=0; comp<getNumberValidComponents(); comp++)
428  {
429    const ComponentID compID=ComponentID(comp);
430    const Pel* pSrc  = pcYuvSrc->getAddr(compID, uiPartIdx);
431    Pel* pDst  = getAddr(compID, uiPartIdx);
432
433    const Int iSrcStride = pcYuvSrc->getStride(compID);
434    const Int iDstStride = getStride(compID);
435    const Int iWidth  = uiWidth >>getComponentScaleX(compID);
436    const Int iHeight = uiHeight>>getComponentScaleY(compID);
437    if (bClipToBitDepths)
438    {
439      const Int clipBd=bitDepths[toChannelType(compID)];
440      for ( Int y = iHeight-1; y >= 0; y-- )
441      {
442        for ( Int x = iWidth-1; x >= 0; x-- )
443        {
444          pDst[x ] = ClipBD((2 * pDst[x]) - pSrc[x], clipBd);
445        }
446        pSrc += iSrcStride;
447        pDst += iDstStride;
448      }
449    }
450    else
451    {
452      for ( Int y = iHeight-1; y >= 0; y-- )
453      {
454        for ( Int x = iWidth-1; x >= 0; x-- )
455        {
456          pDst[x ] = (2 * pDst[x]) - pSrc[x];
457        }
458        pSrc += iSrcStride;
459        pDst += iDstStride;
460      }
461    }
462  }
463}
464
465#if NH_3D_VSO
466Void TComYuv::addClipPartLuma( Int bitDepth, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize )
467{
468  Int x, y;
469
470  Pel* pSrc0 = pcYuvSrc0->getAddr( COMPONENT_Y, uiTrUnitIdx);
471  Pel* pSrc1 = pcYuvSrc1->getAddr( COMPONENT_Y, uiTrUnitIdx);
472  Pel* pDst  =            getAddr( COMPONENT_Y, uiTrUnitIdx);
473
474  UInt iSrc0Stride = pcYuvSrc0->getStride( COMPONENT_Y );
475  UInt iSrc1Stride = pcYuvSrc1->getStride( COMPONENT_Y );
476  UInt iDstStride  =            getStride( COMPONENT_Y );
477  for ( y = uiPartSize-1; y >= 0; y-- )
478  {
479    for ( x = uiPartSize-1; x >= 0; x-- )
480    {
481      pDst[x] = ClipBD( pSrc0[x] + pSrc1[x], bitDepth );     
482    }
483    pSrc0 += iSrc0Stride;
484    pSrc1 += iSrc1Stride;
485    pDst  += iDstStride;
486  }
487}
488
489#if NH_3D_ARP
490Void TComYuv::addARP( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Bool bClip, const BitDepths &clipBitDepths )
491{
492  addARPLuma   ( pcYuvSrc0, pcYuvSrc1, uiAbsPartIdx, uiWidth   , uiHeight    , bClip , clipBitDepths);
493  addARPChroma ( pcYuvSrc0, pcYuvSrc1, uiAbsPartIdx, uiWidth>>1, uiHeight>>1 , bClip , clipBitDepths);
494}
495
496Void TComYuv::addARPLuma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Bool bClip, const BitDepths &clipBitDepths )
497{
498  Int x, y;
499
500  Pel* pSrc0 = pcYuvSrc0->getAddr( COMPONENT_Y, uiAbsPartIdx );
501  Pel* pSrc1 = pcYuvSrc1->getAddr( COMPONENT_Y, uiAbsPartIdx );
502  Pel* pDst  = getAddr( COMPONENT_Y, uiAbsPartIdx );
503
504  UInt iSrc0Stride = pcYuvSrc0->getStride(COMPONENT_Y);
505  UInt iSrc1Stride = pcYuvSrc1->getStride(COMPONENT_Y);
506  UInt iDstStride  = getStride(COMPONENT_Y);
507  const Int clipbd = clipBitDepths.recon[CHANNEL_TYPE_LUMA];
508  Int iIFshift = IF_INTERNAL_PREC - clipbd;
509  Int iOffSet  = ( 1 << ( iIFshift - 1 ) ) + IF_INTERNAL_OFFS;
510  for ( y = uiHeight-1; y >= 0; y-- )
511  {
512    for ( x = uiWidth-1; x >= 0; x-- )
513    {
514      pDst[x] = pSrc0[x] + pSrc1[x];
515      if( bClip )
516      {
517        pDst[x] = Pel(ClipBD<Int>(Int( ( pDst[x] + iOffSet ) >> iIFshift ), clipbd));
518      }
519    }
520    pSrc0 += iSrc0Stride;
521    pSrc1 += iSrc1Stride;
522    pDst  += iDstStride;
523  }
524}
525
526Void TComYuv::addARPChroma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Bool bClip, const BitDepths &clipBitDepths )
527{
528  Int x, y;
529
530  Pel* pSrcU0 = pcYuvSrc0->getAddr( COMPONENT_Cb, uiAbsPartIdx );
531  Pel* pSrcU1 = pcYuvSrc1->getAddr( COMPONENT_Cb, uiAbsPartIdx );
532  Pel* pSrcV0 = pcYuvSrc0->getAddr( COMPONENT_Cr, uiAbsPartIdx );
533  Pel* pSrcV1 = pcYuvSrc1->getAddr( COMPONENT_Cr, uiAbsPartIdx );
534  Pel* pDstU = getAddr( COMPONENT_Cb, uiAbsPartIdx );
535  Pel* pDstV = getAddr( COMPONENT_Cr, uiAbsPartIdx );
536
537  UInt  iSrc0StrideCb = pcYuvSrc0->getStride(COMPONENT_Cb);
538  UInt  iSrc1StrideCb = pcYuvSrc1->getStride(COMPONENT_Cb);
539  UInt  iDstStrideCb  = getStride(COMPONENT_Cb);
540
541  UInt  iSrc0StrideCr = pcYuvSrc0->getStride(COMPONENT_Cr);
542  UInt  iSrc1StrideCr = pcYuvSrc1->getStride(COMPONENT_Cr);
543  UInt  iDstStrideCr  = getStride(COMPONENT_Cr);
544
545  const Int clipbd = clipBitDepths.recon[CHANNEL_TYPE_CHROMA];
546  Int iIFshift = IF_INTERNAL_PREC - clipbd;
547  Int iOffSet  = ( 1 << ( iIFshift - 1 ) ) + IF_INTERNAL_OFFS;
548
549  for ( y = uiHeight-1; y >= 0; y-- )
550  {
551    for ( x = uiWidth-1; x >= 0; x-- )
552    {
553      pDstU[x] = pSrcU0[x] + pSrcU1[x];
554      pDstV[x] = pSrcV0[x] + pSrcV1[x];
555      if( bClip )
556      {
557        pDstU[x] = Pel(ClipBD<Int>( Int( ( pDstU[x] + iOffSet ) >> iIFshift ), clipbd));
558        pDstV[x] = Pel(ClipBD<Int>( Int( ( pDstV[x] + iOffSet ) >> iIFshift ), clipbd));
559      }
560    }
561
562    pSrcU0 += iSrc0StrideCb;
563    pSrcU1 += iSrc1StrideCb;
564    pSrcV0 += iSrc0StrideCr;
565    pSrcV1 += iSrc1StrideCr;
566    pDstU  += iDstStrideCb;
567    pDstV  += iDstStrideCr;
568  }
569}
570
571Void TComYuv::subtractARP( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight )
572{
573  subtractARPLuma  ( pcYuvSrc0, pcYuvSrc1,  uiAbsPartIdx, uiWidth    , uiHeight    );
574
575  if (uiWidth > 8 && pcYuvSrc1->getNumberValidComponents() > 1)
576  {
577    subtractARPChroma( pcYuvSrc0, pcYuvSrc1,  uiAbsPartIdx, uiWidth>>1 , uiHeight>>1 );
578}
579}
580
581Void TComYuv::subtractARPLuma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight )
582{
583  Int x, y;
584
585  Pel* pSrc0 = pcYuvSrc0->getAddr(COMPONENT_Y, uiAbsPartIdx );
586  Pel* pSrc1 = pcYuvSrc1->getAddr(COMPONENT_Y, uiAbsPartIdx );
587  Pel* pDst  = getAddr           (COMPONENT_Y, uiAbsPartIdx );
588
589  Int  iSrc0Stride = pcYuvSrc0->getStride(COMPONENT_Y);
590  Int  iSrc1Stride = pcYuvSrc1->getStride(COMPONENT_Y);
591  Int  iDstStride  = getStride(COMPONENT_Y);
592  for ( y = uiHeight-1; y >= 0; y-- )
593  {
594    for ( x = uiWidth-1; x >= 0; x-- )
595    {
596      pDst[x] = pSrc0[x] - pSrc1[x];
597    }
598    pSrc0 += iSrc0Stride;
599    pSrc1 += iSrc1Stride;
600    pDst  += iDstStride;
601  }
602}
603
604Void TComYuv::subtractARPChroma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight )
605{
606  Int x, y;
607
608  Pel* pSrcU0 = pcYuvSrc0->getAddr(COMPONENT_Cb, uiAbsPartIdx );
609  Pel* pSrcU1 = pcYuvSrc1->getAddr(COMPONENT_Cb, uiAbsPartIdx );
610  Pel* pSrcV0 = pcYuvSrc0->getAddr(COMPONENT_Cr, uiAbsPartIdx );
611  Pel* pSrcV1 = pcYuvSrc1->getAddr(COMPONENT_Cr, uiAbsPartIdx );
612  Pel* pDstU  = getAddr(COMPONENT_Cb, uiAbsPartIdx );
613  Pel* pDstV  = getAddr(COMPONENT_Cr, uiAbsPartIdx );
614
615  Int  iSrc0Stride = pcYuvSrc0->getStride(COMPONENT_Cb);
616  Int  iSrc1Stride = pcYuvSrc1->getStride(COMPONENT_Cb);
617  Int  iDstStride  = getStride( COMPONENT_Cb );
618  for ( y = uiHeight-1; y >= 0; y-- )
619  {
620    for ( x = uiWidth-1; x >= 0; x-- )
621    {
622      pDstU[x] = pSrcU0[x] - pSrcU1[x];
623      pDstV[x] = pSrcV0[x] - pSrcV1[x];
624    }
625    pSrcU0 += iSrc0Stride;
626    pSrcU1 += iSrc1Stride;
627    pSrcV0 += iSrc0Stride;
628    pSrcV1 += iSrc1Stride;
629    pDstU  += iDstStride;
630    pDstV  += iDstStride;
631  }
632}
633
634Void TComYuv::multiplyARP( UInt uiAbsPartIdx , UInt uiWidth , UInt uiHeight , UChar dW )
635{
636  multiplyARPLuma( uiAbsPartIdx , uiWidth , uiHeight , dW );
637
638  if ( uiWidth > 8 && getNumberValidComponents() > 1 )
639  {
640    multiplyARPChroma( uiAbsPartIdx , uiWidth >> 1 , uiHeight >> 1 , dW );
641}
642}
643
644Void TComYuv::xxMultiplyLine( Pel* pSrcDst , UInt uiWidth , UChar dW )
645{
646  assert( dW == 2 );
647  for( UInt x = 0 ; x < uiWidth ; x++ )
648    pSrcDst[x] =  pSrcDst[x] >> 1;
649}
650
651Void TComYuv::multiplyARPLuma( UInt uiAbsPartIdx , UInt uiWidth , UInt uiHeight , UChar dW )
652{
653  Pel* pDst  = getAddr(COMPONENT_Y, uiAbsPartIdx );
654  Int  iDstStride  = getStride(COMPONENT_Y);
655  for ( Int y = uiHeight-1; y >= 0; y-- )
656  {
657    xxMultiplyLine( pDst , uiWidth , dW );
658    pDst  += iDstStride;
659  }
660}
661
662Void TComYuv::multiplyARPChroma( UInt uiAbsPartIdx , UInt uiWidth , UInt uiHeight , UChar dW )
663{
664  Pel* pDstU  = getAddr( COMPONENT_Cb, uiAbsPartIdx );
665  Pel* pDstV  = getAddr( COMPONENT_Cr, uiAbsPartIdx );
666
667  Int  iDstStride  = getStride( COMPONENT_Cb );
668  for ( Int y = uiHeight-1; y >= 0; y-- )
669  {
670    xxMultiplyLine( pDstU , uiWidth , dW );
671    xxMultiplyLine( pDstV , uiWidth , dW );
672    pDstU  += iDstStride;
673    pDstV  += iDstStride;
674  }
675}
676#endif
677#endif
678
679//! \}
Note: See TracBrowser for help on using the repository browser.