HEVC Test Model (HM)  HM-16.3
TComYuv.h
Go to the documentation of this file.
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 
40 #ifndef __TCOMYUV__
41 #define __TCOMYUV__
42 #include "CommonDef.h"
43 #include "TComPicYuv.h"
44 #include "TComRectangle.h"
45 
48 
49 // ====================================================================================================================
50 // Class definition
51 // ====================================================================================================================
52 
54 class TComYuv
55 {
56 private:
57 
58  // ------------------------------------------------------------------------------------------------------------------
59  // YUV buffer
60  // ------------------------------------------------------------------------------------------------------------------
61 
63 
64  // ------------------------------------------------------------------------------------------------------------------
65  // Parameter for general YUV buffer usage
66  // ------------------------------------------------------------------------------------------------------------------
67 
71 
72  // dims 16x16
73  // blkSize=4x4
74 
75  // these functions assume a square CU, of size width*width, split into square TUs each of size blkSize*blkSize.
76  // iTransUnitIdx is the raster-scanned index of the sub-block (TU) in question.
77  // eg for a 16x16 CU, with 4x4 TUs:
78  // 0 1 2 3
79  // 4 5 6 7
80  // 8 9 10 11
81  // 12 13 14 15
82 
83  // So, for iTransUnitIdx=14, 14*4 & 15 =8=X offset.
84  // 14*4 / 16 =3=Y block offset
85  // 3*4*16 = Y offset within buffer
86 
87 
88 public:
89 
90  TComYuv ();
91  virtual ~TComYuv ();
92 
93  // ------------------------------------------------------------------------------------------------------------------
94  // Memory management
95  // ------------------------------------------------------------------------------------------------------------------
96 
97  Void create ( const UInt iWidth, const UInt iHeight, const ChromaFormat chromaFormatIDC );
98  Void destroy ();
99  Void clear ();
100 
101  // ------------------------------------------------------------------------------------------------------------------
102  // Copy, load, store YUV buffer
103  // ------------------------------------------------------------------------------------------------------------------
104 
105  // Copy YUV buffer to picture buffer
106  Void copyToPicYuv ( TComPicYuv* pcPicYuvDst, const UInt ctuRsAddr, const UInt uiAbsZorderIdx, const UInt uiPartDepth = 0, const UInt uiPartIdx = 0 ) const ;
107  Void copyToPicComponent ( const ComponentID id, TComPicYuv* pcPicYuvDst, const UInt iCtuRsAddr, const UInt uiAbsZorderIdx, const UInt uiPartDepth = 0, const UInt uiPartIdx = 0 ) const ;
108 
109  // Copy YUV buffer from picture buffer
110  Void copyFromPicYuv ( const TComPicYuv* pcPicYuvSrc, const UInt ctuRsAddr, const UInt uiAbsZorderIdx );
111  Void copyFromPicComponent ( const ComponentID id, const TComPicYuv* pcPicYuvSrc, const UInt iCtuRsAddr, const UInt uiAbsZorderIdx );
112 
113  // Copy Small YUV buffer to the part of other Big YUV buffer
114  Void copyToPartYuv ( TComYuv* pcYuvDst, const UInt uiDstPartIdx ) const ;
115  Void copyToPartComponent ( const ComponentID id, TComYuv* pcYuvDst, const UInt uiDstPartIdx ) const ;
116 
117  // Copy the part of Big YUV buffer to other Small YUV buffer
118  Void copyPartToYuv ( TComYuv* pcYuvDst, const UInt uiSrcPartIdx ) const;
119  Void copyPartToComponent ( const ComponentID id, TComYuv* pcYuvDst, const UInt uiSrcPartIdx ) const;
120 
121  // Copy YUV partition buffer to other YUV partition buffer
122  Void copyPartToPartYuv ( TComYuv* pcYuvDst, const UInt uiPartIdx, const UInt uiWidth, const UInt uiHeight ) const;
123  Void copyPartToPartComponent ( const ComponentID id, TComYuv* pcYuvDst, const UInt uiPartIdx, const UInt uiWidthComponent, const UInt uiHeightComponent ) const;
124 
125  // Copy YUV partition buffer to other YUV partition buffer for non-square blocks
126  Void copyPartToPartComponentMxN ( const ComponentID id, TComYuv* pcYuvDst, const TComRectangle &rect ) const;
127 
128  // ------------------------------------------------------------------------------------------------------------------
129  // Algebraic operation for YUV buffer
130  // ------------------------------------------------------------------------------------------------------------------
131 
132  // Clip(pcYuvSrc0 + pcYuvSrc1) -> m_apiBuf
133  Void addClip ( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt uiTrUnitIdx, const UInt uiPartSize );
134 
135  // pcYuvSrc0 - pcYuvSrc1 -> m_apiBuf
136  Void subtract ( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt uiTrUnitIdx, const UInt uiPartSize );
137 
138  // (pcYuvSrc0 + pcYuvSrc1)/2 for YUV partition
139  Void addAvg ( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt iPartUnitIdx, const UInt iWidth, const UInt iHeight );
140 
141  Void removeHighFreq ( const TComYuv* pcYuvSrc, const UInt uiPartIdx, const UInt uiWidth, const UInt uiHeight );
142 
143  // ------------------------------------------------------------------------------------------------------------------
144  // Access function for YUV buffer
145  // ------------------------------------------------------------------------------------------------------------------
146 
147  // Access starting position of YUV buffer
148  Pel* getAddr (const ComponentID id) { return m_apiBuf[id]; }
149  const Pel* getAddr (const ComponentID id) const { return m_apiBuf[id]; }
150 
151  // Access starting position of YUV partition unit buffer
152  Pel* getAddr (const ComponentID id, const UInt uiPartUnitIdx)
153  {
154  Int blkX = g_auiRasterToPelX[ g_auiZscanToRaster[ uiPartUnitIdx ] ] >> getComponentScaleX(id);
155  Int blkY = g_auiRasterToPelY[ g_auiZscanToRaster[ uiPartUnitIdx ] ] >> getComponentScaleY(id);
156  assert((blkX<getWidth(id) && blkY<getHeight(id)));
157  return m_apiBuf[id] + blkX + blkY * getStride(id);
158  }
159  const Pel* getAddr (const ComponentID id, const UInt uiPartUnitIdx) const
160  {
161  Int blkX = g_auiRasterToPelX[ g_auiZscanToRaster[ uiPartUnitIdx ] ] >> getComponentScaleX(id);
162  Int blkY = g_auiRasterToPelY[ g_auiZscanToRaster[ uiPartUnitIdx ] ] >> getComponentScaleY(id);
163  assert((blkX<getWidth(id) && blkY<getHeight(id)));
164  return m_apiBuf[id] + blkX + blkY * getStride(id);
165  }
166 
167  // Access starting position of YUV transform unit buffer
168  Pel* getAddr (const ComponentID id, const UInt iTransUnitIdx, const UInt iBlkSizeForComponent)
169  {
170  UInt width=getWidth(id);
171  Int blkX = ( iTransUnitIdx * iBlkSizeForComponent ) & ( width - 1 );
172  Int blkY = ( iTransUnitIdx * iBlkSizeForComponent ) &~ ( width - 1 );
173  if (m_chromaFormatIDC==CHROMA_422 && id!=COMPONENT_Y)
174  {
175  blkY<<=1;
176  }
177  return m_apiBuf[id] + blkX + blkY * iBlkSizeForComponent;
178  }
179 
180  const Pel* getAddr (const ComponentID id, const UInt iTransUnitIdx, const UInt iBlkSizeForComponent) const
181  {
182  UInt width=getWidth(id);
183  Int blkX = ( iTransUnitIdx * iBlkSizeForComponent ) & ( width - 1 );
184  Int blkY = ( iTransUnitIdx * iBlkSizeForComponent ) &~ ( width - 1 );
185  if (m_chromaFormatIDC==CHROMA_422 && id!=COMPONENT_Y)
186  {
187  blkY<<=1;
188  }
189  return m_apiBuf[id] + blkX + blkY * iBlkSizeForComponent;
190  }
191 
192  // Access starting position of YUV transform unit buffer by pix offset for square & non-square blocks
193  Pel* getAddrPix (const ComponentID id, const UInt iPixX, const UInt iPixY ) { return m_apiBuf[id] + iPixY * getStride(id) + iPixX; }
194  const Pel* getAddrPix (const ComponentID id, const UInt iPixX, const UInt iPixY ) const { return m_apiBuf[id] + iPixY * getStride(id) + iPixX; }
195 
196  // Get stride value of YUV buffer
197  UInt getStride (const ComponentID id) const { return m_iWidth >> getComponentScaleX(id); }
198  UInt getHeight (const ComponentID id) const { return m_iHeight >> getComponentScaleY(id); }
199  UInt getWidth (const ComponentID id) const { return m_iWidth >> getComponentScaleX(id); }
202  UInt getComponentScaleX (const ComponentID id) const { return ::getComponentScaleX(id, m_chromaFormatIDC); }
203  UInt getComponentScaleY (const ComponentID id) const { return ::getComponentScaleY(id, m_chromaFormatIDC); }
204 
205 };// END CLASS DEFINITION TComYuv
206 
208 
209 #endif // __TCOMYUV__
Void destroy()
Destroy YUV buffer.
Definition: TComYuv.cpp:77
ChromaFormat m_chromaFormatIDC
Definition: TComYuv.h:70
Void copyToPartComponent(const ComponentID id, TComYuv *pcYuvDst, const UInt uiDstPartIdx) const
Definition: TComYuv.cpp:171
picture YUV buffer class
Definition: TComPicYuv.h:55
Defines constants, macros and tool parameters.
void Void
Definition: TypeDef.h:285
UInt g_auiRasterToPelX[((1<<(6))/4)*((1<<(6))/4)]
Definition: TComRom.cpp:257
Void copyPartToYuv(TComYuv *pcYuvDst, const UInt uiSrcPartIdx) const
Definition: TComYuv.cpp:192
TComYuv()
Definition: TComYuv.cpp:51
static UInt getComponentScaleY(const ComponentID id, const ChromaFormat fmt)
const Pel * getAddr(const ComponentID id) const
Definition: TComYuv.h:149
unsigned int UInt
Definition: TypeDef.h:297
static UInt getComponentScaleX(const ComponentID id, const ChromaFormat fmt)
Pel * getAddr(const ComponentID id, const UInt iTransUnitIdx, const UInt iBlkSizeForComponent)
Definition: TComYuv.h:168
Short Pel
pixel type
Definition: TypeDef.h:692
Pel * getAddr(const ComponentID id, const UInt uiPartUnitIdx)
Definition: TComYuv.h:152
Void copyPartToPartComponent(const ComponentID id, TComYuv *pcYuvDst, const UInt uiPartIdx, const UInt uiWidthComponent, const UInt uiHeightComponent) const
Definition: TComYuv.cpp:230
UInt getStride(const ComponentID id) const
Definition: TComYuv.h:197
Void copyToPicYuv(TComPicYuv *pcPicYuvDst, const UInt ctuRsAddr, const UInt uiAbsZorderIdx, const UInt uiPartDepth=0, const UInt uiPartIdx=0) const
Definition: TComYuv.cpp:104
UInt getHeight(const ComponentID id) const
Definition: TComYuv.h:198
UInt m_iHeight
Definition: TComYuv.h:69
Void copyPartToPartComponentMxN(const ComponentID id, TComYuv *pcYuvDst, const TComRectangle &rect) const
Definition: TComYuv.cpp:254
Void removeHighFreq(const TComYuv *pcYuvSrc, const UInt uiPartIdx, const UInt uiWidth, const UInt uiHeight)
Definition: TComYuv.cpp:409
UInt m_iWidth
Definition: TComYuv.h:68
const Pel * getAddr(const ComponentID id, const UInt iTransUnitIdx, const UInt iBlkSizeForComponent) const
Definition: TComYuv.h:180
general YUV buffer class
Definition: TComYuv.h:54
const Pel * getAddrPix(const ComponentID id, const UInt iPixX, const UInt iPixY) const
Definition: TComYuv.h:194
Void addClip(const TComYuv *pcYuvSrc0, const TComYuv *pcYuvSrc1, const UInt uiTrUnitIdx, const UInt uiPartSize)
Definition: TComYuv.cpp:280
UInt getWidth(const ComponentID id) const
Definition: TComYuv.h:199
UInt getComponentScaleX(const ComponentID id) const
Definition: TComYuv.h:202
const Pel * getAddr(const ComponentID id, const UInt uiPartUnitIdx) const
Definition: TComYuv.h:159
Void copyToPicComponent(const ComponentID id, TComPicYuv *pcPicYuvDst, const UInt iCtuRsAddr, const UInt uiAbsZorderIdx, const UInt uiPartDepth=0, const UInt uiPartIdx=0) const
Definition: TComYuv.cpp:112
Void copyToPartYuv(TComYuv *pcYuvDst, const UInt uiDstPartIdx) const
Definition: TComYuv.cpp:163
UInt getComponentScaleY(const ComponentID id) const
Definition: TComYuv.h:203
Void create(const UInt iWidth, const UInt iHeight, const ChromaFormat chromaFormatIDC)
Create YUV buffer.
Definition: TComYuv.cpp:63
Void subtract(const TComYuv *pcYuvSrc0, const TComYuv *pcYuvSrc1, const UInt uiTrUnitIdx, const UInt uiPartSize)
Definition: TComYuv.cpp:320
UInt g_auiZscanToRaster[((1<<(6))/4)*((1<<(6))/4)]
Definition: TComRom.cpp:255
Pel * getAddr(const ComponentID id)
Definition: TComYuv.h:148
ChromaFormat
chroma formats (according to semantics of chroma_format_idc)
Definition: TypeDef.h:352
UInt g_auiRasterToPelY[((1<<(6))/4)*((1<<(6))/4)]
Definition: TComRom.cpp:258
picture YUV buffer class (header)
virtual ~TComYuv()
Definition: TComYuv.cpp:59
Pel * m_apiBuf[MAX_NUM_COMPONENT]
Definition: TComYuv.h:62
Void addAvg(const TComYuv *pcYuvSrc0, const TComYuv *pcYuvSrc1, const UInt iPartUnitIdx, const UInt iWidth, const UInt iHeight)
Definition: TComYuv.cpp:352
ChromaFormat getChromaFormat() const
Definition: TComYuv.h:200
Void copyFromPicComponent(const ComponentID id, const TComPicYuv *pcPicYuvSrc, const UInt iCtuRsAddr, const UInt uiAbsZorderIdx)
Definition: TComYuv.cpp:142
int Int
Definition: TypeDef.h:296
Void copyPartToComponent(const ComponentID id, TComYuv *pcYuvDst, const UInt uiSrcPartIdx) const
Definition: TComYuv.cpp:200
ComponentID
Definition: TypeDef.h:368
static UInt getNumberValidComponents(const ChromaFormat fmt)
UInt getNumberValidComponents() const
Definition: TComYuv.h:201
Pel * getAddrPix(const ComponentID id, const UInt iPixX, const UInt iPixY)
Definition: TComYuv.h:193
Void copyPartToPartYuv(TComYuv *pcYuvDst, const UInt uiPartIdx, const UInt uiWidth, const UInt uiHeight) const
Definition: TComYuv.cpp:222
Void clear()
clear YUV buffer
Definition: TComYuv.cpp:90
Void copyFromPicYuv(const TComPicYuv *pcPicYuvSrc, const UInt ctuRsAddr, const UInt uiAbsZorderIdx)
Definition: TComYuv.cpp:134