HEVC Test Model (HM)  HM-16.18
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-2017, 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, const BitDepths &clipBitDepths );
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, const BitDepths &clipBitDepths );
140 
141  Void removeHighFreq ( const TComYuv* pcYuvSrc, const UInt uiPartIdx, const UInt uiWidth, const UInt uiHeight
142  , const Int bitDepths[MAX_NUM_CHANNEL_TYPE], const Bool bClipToBitDepths
143  );
144 
145  // ------------------------------------------------------------------------------------------------------------------
146  // Access function for YUV buffer
147  // ------------------------------------------------------------------------------------------------------------------
148 
149  // Access starting position of YUV buffer
150  Pel* getAddr (const ComponentID id) { return m_apiBuf[id]; }
151  const Pel* getAddr (const ComponentID id) const { return m_apiBuf[id]; }
152 
153  // Access starting position of YUV partition unit buffer
154  Pel* getAddr (const ComponentID id, const UInt uiPartUnitIdx)
155  {
156  Int blkX = g_auiRasterToPelX[ g_auiZscanToRaster[ uiPartUnitIdx ] ] >> getComponentScaleX(id);
157  Int blkY = g_auiRasterToPelY[ g_auiZscanToRaster[ uiPartUnitIdx ] ] >> getComponentScaleY(id);
158  assert((blkX<getWidth(id) && blkY<getHeight(id)));
159  return m_apiBuf[id] + blkX + blkY * getStride(id);
160  }
161  const Pel* getAddr (const ComponentID id, const UInt uiPartUnitIdx) const
162  {
163  Int blkX = g_auiRasterToPelX[ g_auiZscanToRaster[ uiPartUnitIdx ] ] >> getComponentScaleX(id);
164  Int blkY = g_auiRasterToPelY[ g_auiZscanToRaster[ uiPartUnitIdx ] ] >> getComponentScaleY(id);
165  assert((blkX<getWidth(id) && blkY<getHeight(id)));
166  return m_apiBuf[id] + blkX + blkY * getStride(id);
167  }
168 
169  // Access starting position of YUV transform unit buffer
170  Pel* getAddr (const ComponentID id, const UInt iTransUnitIdx, const UInt iBlkSizeForComponent)
171  {
172  UInt width=getWidth(id);
173  Int blkX = ( iTransUnitIdx * iBlkSizeForComponent ) & ( width - 1 );
174  Int blkY = ( iTransUnitIdx * iBlkSizeForComponent ) &~ ( width - 1 );
176  {
177  blkY<<=1;
178  }
179  return m_apiBuf[id] + blkX + blkY * iBlkSizeForComponent;
180  }
181 
182  const Pel* getAddr (const ComponentID id, const UInt iTransUnitIdx, const UInt iBlkSizeForComponent) const
183  {
184  UInt width=getWidth(id);
185  Int blkX = ( iTransUnitIdx * iBlkSizeForComponent ) & ( width - 1 );
186  Int blkY = ( iTransUnitIdx * iBlkSizeForComponent ) &~ ( width - 1 );
188  {
189  blkY<<=1;
190  }
191  return m_apiBuf[id] + blkX + blkY * iBlkSizeForComponent;
192  }
193 
194  // Access starting position of YUV transform unit buffer by pix offset for square & non-square blocks
195  Pel* getAddrPix (const ComponentID id, const UInt iPixX, const UInt iPixY ) { return m_apiBuf[id] + iPixY * getStride(id) + iPixX; }
196  const Pel* getAddrPix (const ComponentID id, const UInt iPixX, const UInt iPixY ) const { return m_apiBuf[id] + iPixY * getStride(id) + iPixX; }
197 
198  // Get stride value of YUV buffer
199  UInt getStride (const ComponentID id) const { return m_iWidth >> getComponentScaleX(id); }
200  UInt getHeight (const ComponentID id) const { return m_iHeight >> getComponentScaleY(id); }
201  UInt getWidth (const ComponentID id) const { return m_iWidth >> getComponentScaleX(id); }
206 
207 };// END CLASS DEFINITION TComYuv
208 
210 
211 #endif // __TCOMYUV__
Void destroy()
Destroy YUV buffer.
Definition: TComYuv.cpp:79
ChromaFormat m_chromaFormatIDC
Definition: TComYuv.h:70
Void copyToPartComponent(const ComponentID id, TComYuv *pcYuvDst, const UInt uiDstPartIdx) const
Definition: TComYuv.cpp:173
picture YUV buffer class
Definition: TComPicYuv.h:55
Defines version information, constants and small in-line functions.
void Void
Definition: TypeDef.h:203
Void copyPartToYuv(TComYuv *pcYuvDst, const UInt uiSrcPartIdx) const
Definition: TComYuv.cpp:194
TComYuv()
Definition: TComYuv.cpp:51
static UInt getComponentScaleY(const ComponentID id, const ChromaFormat fmt)
const Pel * getAddr(const ComponentID id) const
Definition: TComYuv.h:151
unsigned int UInt
Definition: TypeDef.h:212
static UInt getComponentScaleX(const ComponentID id, const ChromaFormat fmt)
Pel * getAddr(const ComponentID id, const UInt iTransUnitIdx, const UInt iBlkSizeForComponent)
Definition: TComYuv.h:170
Short Pel
pixel type
Definition: TypeDef.h:249
Pel * getAddr(const ComponentID id, const UInt uiPartUnitIdx)
Definition: TComYuv.h:154
Void copyPartToPartComponent(const ComponentID id, TComYuv *pcYuvDst, const UInt uiPartIdx, const UInt uiWidthComponent, const UInt uiHeightComponent) const
Definition: TComYuv.cpp:232
UInt getStride(const ComponentID id) const
Definition: TComYuv.h:199
Void copyToPicYuv(TComPicYuv *pcPicYuvDst, const UInt ctuRsAddr, const UInt uiAbsZorderIdx, const UInt uiPartDepth=0, const UInt uiPartIdx=0) const
Definition: TComYuv.cpp:106
UInt getHeight(const ComponentID id) const
Definition: TComYuv.h:200
UInt m_iHeight
Definition: TComYuv.h:69
Void copyPartToPartComponentMxN(const ComponentID id, TComYuv *pcYuvDst, const TComRectangle &rect) const
Definition: TComYuv.cpp:256
UInt m_iWidth
Definition: TComYuv.h:68
const Pel * getAddr(const ComponentID id, const UInt iTransUnitIdx, const UInt iBlkSizeForComponent) const
Definition: TComYuv.h:182
general YUV buffer class
Definition: TComYuv.h:54
const Pel * getAddrPix(const ComponentID id, const UInt iPixX, const UInt iPixY) const
Definition: TComYuv.h:196
bool Bool
Definition: TypeDef.h:204
UInt getWidth(const ComponentID id) const
Definition: TComYuv.h:201
UInt getComponentScaleX(const ComponentID id) const
Definition: TComYuv.h:204
const Pel * getAddr(const ComponentID id, const UInt uiPartUnitIdx) const
Definition: TComYuv.h:161
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:114
Void addClip(const TComYuv *pcYuvSrc0, const TComYuv *pcYuvSrc1, const UInt uiTrUnitIdx, const UInt uiPartSize, const BitDepths &clipBitDepths)
Definition: TComYuv.cpp:282
Void copyToPartYuv(TComYuv *pcYuvDst, const UInt uiDstPartIdx) const
Definition: TComYuv.cpp:165
UInt getComponentScaleY(const ComponentID id) const
Definition: TComYuv.h:205
Void create(const UInt iWidth, const UInt iHeight, const ChromaFormat chromaFormatIDC)
Create YUV buffer.
Definition: TComYuv.cpp:64
Void subtract(const TComYuv *pcYuvSrc0, const TComYuv *pcYuvSrc1, const UInt uiTrUnitIdx, const UInt uiPartSize)
Definition: TComYuv.cpp:322
Pel * getAddr(const ComponentID id)
Definition: TComYuv.h:150
ChromaFormat
chroma formats (according to semantics of chroma_format_idc)
Definition: TypeDef.h:292
Void removeHighFreq(const TComYuv *pcYuvSrc, const UInt uiPartIdx, const UInt uiWidth, const UInt uiHeight, const Int bitDepths[MAX_NUM_CHANNEL_TYPE], const Bool bClipToBitDepths)
Definition: TComYuv.cpp:411
UInt g_auiZscanToRaster[MAX_NUM_PART_IDXS_IN_CTU_WIDTH *MAX_NUM_PART_IDXS_IN_CTU_WIDTH]
Definition: TComRom.cpp:284
picture YUV buffer class (header)
virtual ~TComYuv()
Definition: TComYuv.cpp:59
Pel * m_apiBuf[MAX_NUM_COMPONENT]
Definition: TComYuv.h:62
ChromaFormat getChromaFormat() const
Definition: TComYuv.h:202
Void copyFromPicComponent(const ComponentID id, const TComPicYuv *pcPicYuvSrc, const UInt iCtuRsAddr, const UInt uiAbsZorderIdx)
Definition: TComYuv.cpp:144
Void addAvg(const TComYuv *pcYuvSrc0, const TComYuv *pcYuvSrc1, const UInt iPartUnitIdx, const UInt iWidth, const UInt iHeight, const BitDepths &clipBitDepths)
Definition: TComYuv.cpp:354
int Int
Definition: TypeDef.h:211
Void copyPartToComponent(const ComponentID id, TComYuv *pcYuvDst, const UInt uiSrcPartIdx) const
Definition: TComYuv.cpp:202
ComponentID
Definition: TypeDef.h:308
UInt g_auiRasterToPelX[MAX_NUM_PART_IDXS_IN_CTU_WIDTH *MAX_NUM_PART_IDXS_IN_CTU_WIDTH]
Definition: TComRom.cpp:286
static UInt getNumberValidComponents(const ChromaFormat fmt)
UInt getNumberValidComponents() const
Definition: TComYuv.h:203
Pel * getAddrPix(const ComponentID id, const UInt iPixX, const UInt iPixY)
Definition: TComYuv.h:195
Void copyPartToPartYuv(TComYuv *pcYuvDst, const UInt uiPartIdx, const UInt uiWidth, const UInt uiHeight) const
Definition: TComYuv.cpp:224
Void clear()
clear YUV buffer
Definition: TComYuv.cpp:92
Void copyFromPicYuv(const TComPicYuv *pcPicYuvSrc, const UInt ctuRsAddr, const UInt uiAbsZorderIdx)
Definition: TComYuv.cpp:136
UInt g_auiRasterToPelY[MAX_NUM_PART_IDXS_IN_CTU_WIDTH *MAX_NUM_PART_IDXS_IN_CTU_WIDTH]
Definition: TComRom.cpp:287