source: 3DVCSoftware/branches/HTM-5.1-dev2-Mediatek/source/Lib/TLibCommon/TComYuv.h @ 261

Last change on this file since 261 was 244, checked in by mediatek-htm, 12 years ago

Implementation of C0138
Added macro "MTK_MDIVRP_C0138"

  • Property svn:eol-style set to native
File size: 11.7 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-2012, 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.h
35    \brief    general YUV buffer class (header)
36    \todo     this should be merged with TComPicYuv \n
37              check usage of removeHighFreq function
38*/
39
40#ifndef __TCOMYUV__
41#define __TCOMYUV__
42#include <assert.h>
43#include "CommonDef.h"
44#include "TComPicYuv.h"
45
46//! \ingroup TLibCommon
47//! \{
48
49// ====================================================================================================================
50// Class definition
51// ====================================================================================================================
52
53/// general YUV buffer class
54class TComYuv
55{
56private:
57 
58  // ------------------------------------------------------------------------------------------------------------------
59  //  YUV buffer
60  // ------------------------------------------------------------------------------------------------------------------
61 
62  Pel*    m_apiBufY;
63  Pel*    m_apiBufU;
64  Pel*    m_apiBufV;
65 
66  // ------------------------------------------------------------------------------------------------------------------
67  //  Parameter for general YUV buffer usage
68  // ------------------------------------------------------------------------------------------------------------------
69 
70  UInt     m_iWidth;
71  UInt     m_iHeight;
72  UInt     m_iCWidth;
73  UInt     m_iCHeight;
74 
75  static Int getAddrOffset( UInt uiPartUnitIdx, UInt width )
76  {
77    Int blkX = g_auiRasterToPelX[ g_auiZscanToRaster[ uiPartUnitIdx ] ];
78    Int blkY = g_auiRasterToPelY[ g_auiZscanToRaster[ uiPartUnitIdx ] ];
79   
80    return blkX + blkY * width;
81  }
82
83  static Int getAddrOffset( UInt iTransUnitIdx, UInt iBlkSize, UInt width )
84  {
85    Int blkX = ( iTransUnitIdx * iBlkSize ) &  ( width - 1 );
86    Int blkY = ( iTransUnitIdx * iBlkSize ) &~ ( width - 1 );
87   
88    return blkX + blkY * iBlkSize;
89  }
90 
91public:
92 
93  TComYuv();
94  virtual ~TComYuv();
95 
96  // ------------------------------------------------------------------------------------------------------------------
97  //  Memory management
98  // ------------------------------------------------------------------------------------------------------------------
99 
100  Void    create            ( UInt iWidth, UInt iHeight );  ///< Create  YUV buffer
101  Void    destroy           ();                             ///< Destroy YUV buffer
102  Void    clear             ();                             ///< clear   YUV buffer
103 
104  // ------------------------------------------------------------------------------------------------------------------
105  //  Copy, load, store YUV buffer
106  // ------------------------------------------------------------------------------------------------------------------
107 
108  //  Copy YUV buffer to picture buffer
109  Void    copyToPicYuv         ( TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth = 0, UInt uiPartIdx = 0 );
110  Void    copyToPicLuma        ( TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth = 0, UInt uiPartIdx = 0 );
111  Void    copyToPicChroma      ( TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth = 0, UInt uiPartIdx = 0 );
112 
113  //  Copy YUV buffer from picture buffer
114  Void    copyFromPicYuv       ( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiAbsZorderIdx );
115  Void    copyFromPicLuma      ( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiAbsZorderIdx );
116  Void    copyFromPicChroma    ( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiAbsZorderIdx );
117 
118  //  Copy Small YUV buffer to the part of other Big YUV buffer
119  Void    copyToPartYuv         ( TComYuv*    pcYuvDst,    UInt uiDstPartIdx );
120  Void    copyToPartLuma        ( TComYuv*    pcYuvDst,    UInt uiDstPartIdx );
121  Void    copyToPartChroma      ( TComYuv*    pcYuvDst,    UInt uiDstPartIdx );
122 
123  //  Copy the part of Big YUV buffer to other Small YUV buffer
124  Void    copyPartToYuv         ( TComYuv*    pcYuvDst,    UInt uiSrcPartIdx );
125  Void    copyPartToLuma        ( TComYuv*    pcYuvDst,    UInt uiSrcPartIdx );
126  Void    copyPartToChroma      ( TComYuv*    pcYuvDst,    UInt uiSrcPartIdx );
127 
128  //  Copy YUV partition buffer to other YUV partition buffer
129  Void    copyPartToPartYuv     ( TComYuv*    pcYuvDst, UInt uiPartIdx, UInt uiWidth, UInt uiHeight );
130  Void    copyPartToPartLuma    ( TComYuv*    pcYuvDst, UInt uiPartIdx, UInt uiWidth, UInt uiHeight );
131  Void    copyPartToPartChroma  ( TComYuv*    pcYuvDst, UInt uiPartIdx, UInt uiWidth, UInt uiHeight );
132
133#if DEPTH_MAP_GENERATION
134  Void    copyPartToPartYuvPdm  ( TComYuv*    pcYuvDst, UInt uiPartIdx, UInt uiWidth, UInt uiHeight, UInt uiSubSampExpX, UInt uiSubSampExpY );
135  Void    copyPartToPartLumaPdm ( TComYuv*    pcYuvDst, UInt uiPartIdx, UInt uiWidth, UInt uiHeight, UInt uiSubSampExpX, UInt uiSubSampExpY );
136#endif
137
138  // ------------------------------------------------------------------------------------------------------------------
139  //  Algebraic operation for YUV buffer
140  // ------------------------------------------------------------------------------------------------------------------
141 
142  //  Clip(pcYuvSrc0 + pcYuvSrc1) -> m_apiBuf
143  Void    addClip           ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize );
144  Void    addClipLuma       ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize );
145  Void    addClipChroma     ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize );
146  Void    addClipPartLuma   ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ); //GT
147
148#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
149  //  pcYuvSrc0 - pcYuvSrc1 -> m_apiBuf
150  Void    subtract          (Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize );
151  Void    subtractLuma      (Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize );
152  Void    subtractChroma    (Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize );
153#else
154  Void    subtract          ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize );
155  Void    subtractLuma      ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize );
156  Void    subtractChroma    ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize );
157#endif
158 
159  //  (pcYuvSrc0 + pcYuvSrc1)/2 for YUV partition
160  Void    addAvg            ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt iPartUnitIdx, UInt iWidth, UInt iHeight );
161
162#if DEPTH_MAP_GENERATION
163  Void    addAvgPdm         ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt iPartUnitIdx, UInt iWidth, UInt iHeight, UInt uiSubSampExpX, UInt uiSubSampExpY );
164#endif
165
166  //   Remove High frequency
167  Void    removeHighFreq    ( TComYuv* pcYuvSrc, UInt uiPartIdx, UInt uiWidht, UInt uiHeight );
168#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
169  Void    getPUXYOffset     (PartSize uhPartitionSize, Int iWidth, Int iHeight, Int &iXOffset, Int &iYOffset);
170  Void    add               (Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract = false );
171  Void    addLuma           (Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract );
172  Void    addChroma         (Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract );
173#else
174  Void    add               ( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract = false );
175  Void    addLuma           ( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract );
176  Void    addChroma         ( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract );
177#endif
178
179  Void    clip              ( Int iWidth, Int iHeight );
180  Void    clipLuma          ( Int iWidth, Int iHeight );
181  Void    clipChroma        ( Int iWidth, Int iHeight );
182  // ------------------------------------------------------------------------------------------------------------------
183  //  Access function for YUV buffer
184  // ------------------------------------------------------------------------------------------------------------------
185 
186  //  Access starting position of YUV buffer
187  Pel*    getLumaAddr ()    { return m_apiBufY; }
188  Pel*    getCbAddr   ()    { return m_apiBufU; }
189  Pel*    getCrAddr   ()    { return m_apiBufV; }
190 
191  //  Access starting position of YUV partition unit buffer
192  Pel* getLumaAddr( UInt iPartUnitIdx ) { return m_apiBufY +   getAddrOffset( iPartUnitIdx, m_iWidth  )       ; }
193  Pel* getCbAddr  ( UInt iPartUnitIdx ) { return m_apiBufU + ( getAddrOffset( iPartUnitIdx, m_iCWidth ) >> 1 ); }
194  Pel* getCrAddr  ( UInt iPartUnitIdx ) { return m_apiBufV + ( getAddrOffset( iPartUnitIdx, m_iCWidth ) >> 1 ); }
195 
196  //  Access starting position of YUV transform unit buffer
197  Pel* getLumaAddr( UInt iTransUnitIdx, UInt iBlkSize ) { return m_apiBufY + getAddrOffset( iTransUnitIdx, iBlkSize, m_iWidth  ); }
198  Pel* getCbAddr  ( UInt iTransUnitIdx, UInt iBlkSize ) { return m_apiBufU + getAddrOffset( iTransUnitIdx, iBlkSize, m_iCWidth ); }
199  Pel* getCrAddr  ( UInt iTransUnitIdx, UInt iBlkSize ) { return m_apiBufV + getAddrOffset( iTransUnitIdx, iBlkSize, m_iCWidth ); }
200
201  //  Get stride value of YUV buffer
202  UInt    getStride   ()    { return  m_iWidth;   }
203  UInt    getCStride  ()    { return  m_iCWidth;  }
204  UInt    getHeight   ()    { return  m_iHeight;  }
205 
206  UInt    getWidth    ()    { return  m_iWidth;   }
207  UInt    getCHeight  ()    { return  m_iCHeight; }
208  UInt    getCWidth   ()    { return  m_iCWidth;  } 
209
210  // ------------------------------------------------------------------------------------------------------------------
211  //  Miscellaneous
212  // ------------------------------------------------------------------------------------------------------------------
213
214  __inline Pel  xClip  (Pel x )      { return ( (x < 0) ? 0 : (x > (Pel)g_uiIBDI_MAX) ? (Pel)g_uiIBDI_MAX : x ); }
215};// END CLASS DEFINITION TComYuv
216
217//! \}
218
219#endif // __TCOMYUV__
Note: See TracBrowser for help on using the repository browser.