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.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 "CommonDef.h" |
---|
43 | #include "TComPicYuv.h" |
---|
44 | #include "TComRectangle.h" |
---|
45 | |
---|
46 | //! \ingroup TLibCommon |
---|
47 | //! \{ |
---|
48 | |
---|
49 | // ==================================================================================================================== |
---|
50 | // Class definition |
---|
51 | // ==================================================================================================================== |
---|
52 | |
---|
53 | /// general YUV buffer class |
---|
54 | class TComYuv |
---|
55 | { |
---|
56 | private: |
---|
57 | |
---|
58 | // ------------------------------------------------------------------------------------------------------------------ |
---|
59 | // YUV buffer |
---|
60 | // ------------------------------------------------------------------------------------------------------------------ |
---|
61 | |
---|
62 | Pel* m_apiBuf[MAX_NUM_COMPONENT]; |
---|
63 | |
---|
64 | // ------------------------------------------------------------------------------------------------------------------ |
---|
65 | // Parameter for general YUV buffer usage |
---|
66 | // ------------------------------------------------------------------------------------------------------------------ |
---|
67 | |
---|
68 | UInt m_iWidth; |
---|
69 | UInt m_iHeight; |
---|
70 | ChromaFormat m_chromaFormatIDC; ////< Chroma Format |
---|
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 ); ///< Create YUV buffer |
---|
98 | Void destroy (); ///< Destroy YUV buffer |
---|
99 | Void clear (); ///< clear YUV buffer |
---|
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 ); |
---|
175 | if (m_chromaFormatIDC==CHROMA_422 && id!=COMPONENT_Y) |
---|
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 ); |
---|
187 | if (m_chromaFormatIDC==CHROMA_422 && id!=COMPONENT_Y) |
---|
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); } |
---|
202 | ChromaFormat getChromaFormat () const { return m_chromaFormatIDC; } |
---|
203 | UInt getNumberValidComponents () const { return ::getNumberValidComponents(m_chromaFormatIDC); } |
---|
204 | UInt getComponentScaleX (const ComponentID id) const { return ::getComponentScaleX(id, m_chromaFormatIDC); } |
---|
205 | UInt getComponentScaleY (const ComponentID id) const { return ::getComponentScaleY(id, m_chromaFormatIDC); } |
---|
206 | #if NH_3D |
---|
207 | Void addClipPartLuma( Int bitDepth, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ); |
---|
208 | #if H_3D_ARP |
---|
209 | Void addARP ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight , Bool bClip ); |
---|
210 | Void addARPLuma ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight , Bool bClip ); |
---|
211 | Void addARPChroma ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight , Bool bClip ); |
---|
212 | Void subtractARP ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight ); |
---|
213 | Void subtractARPLuma ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight ); |
---|
214 | Void subtractARPChroma ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight ); |
---|
215 | Void multiplyARP ( UInt uiAbsPartIdx , UInt uiWidth , UInt uiHeight , UChar dW ); |
---|
216 | Void multiplyARPLuma ( UInt uiAbsPartIdx , UInt uiWidth , UInt uiHeight , UChar dW ); |
---|
217 | Void multiplyARPChroma ( UInt uiAbsPartIdx , UInt uiWidth , UInt uiHeight , UChar dW ); |
---|
218 | private: |
---|
219 | Void xxMultiplyLine ( Pel * pSrcDst , UInt uiWidth , UChar dW ); |
---|
220 | #endif |
---|
221 | #endif |
---|
222 | |
---|
223 | };// END CLASS DEFINITION TComYuv |
---|
224 | |
---|
225 | //! \} |
---|
226 | |
---|
227 | #endif // __TCOMYUV__ |
---|