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 |
---|
54 | class TComYuv |
---|
55 | { |
---|
56 | private: |
---|
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 | |
---|
91 | public: |
---|
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 | |
---|
149 | // pcYuvSrc0 - pcYuvSrc1 -> m_apiBuf |
---|
150 | Void subtract ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ); |
---|
151 | Void subtractLuma ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ); |
---|
152 | Void subtractChroma ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ); |
---|
153 | |
---|
154 | // (pcYuvSrc0 + pcYuvSrc1)/2 for YUV partition |
---|
155 | Void addAvg ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt iPartUnitIdx, UInt iWidth, UInt iHeight ); |
---|
156 | |
---|
157 | #if DEPTH_MAP_GENERATION |
---|
158 | Void addAvgPdm ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt iPartUnitIdx, UInt iWidth, UInt iHeight, UInt uiSubSampExpX, UInt uiSubSampExpY ); |
---|
159 | #endif |
---|
160 | |
---|
161 | // Remove High frequency |
---|
162 | Void removeHighFreq ( TComYuv* pcYuvSrc, UInt uiPartIdx, UInt uiWidht, UInt uiHeight ); |
---|
163 | |
---|
164 | Void add ( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract = false ); |
---|
165 | Void addLuma ( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract ); |
---|
166 | Void addChroma ( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract ); |
---|
167 | |
---|
168 | Void clip ( Int iWidth, Int iHeight ); |
---|
169 | Void clipLuma ( Int iWidth, Int iHeight ); |
---|
170 | Void clipChroma ( Int iWidth, Int iHeight ); |
---|
171 | // ------------------------------------------------------------------------------------------------------------------ |
---|
172 | // Access function for YUV buffer |
---|
173 | // ------------------------------------------------------------------------------------------------------------------ |
---|
174 | |
---|
175 | // Access starting position of YUV buffer |
---|
176 | Pel* getLumaAddr () { return m_apiBufY; } |
---|
177 | Pel* getCbAddr () { return m_apiBufU; } |
---|
178 | Pel* getCrAddr () { return m_apiBufV; } |
---|
179 | |
---|
180 | // Access starting position of YUV partition unit buffer |
---|
181 | Pel* getLumaAddr( UInt iPartUnitIdx ) { return m_apiBufY + getAddrOffset( iPartUnitIdx, m_iWidth ) ; } |
---|
182 | Pel* getCbAddr ( UInt iPartUnitIdx ) { return m_apiBufU + ( getAddrOffset( iPartUnitIdx, m_iCWidth ) >> 1 ); } |
---|
183 | Pel* getCrAddr ( UInt iPartUnitIdx ) { return m_apiBufV + ( getAddrOffset( iPartUnitIdx, m_iCWidth ) >> 1 ); } |
---|
184 | |
---|
185 | // Access starting position of YUV transform unit buffer |
---|
186 | Pel* getLumaAddr( UInt iTransUnitIdx, UInt iBlkSize ) { return m_apiBufY + getAddrOffset( iTransUnitIdx, iBlkSize, m_iWidth ); } |
---|
187 | Pel* getCbAddr ( UInt iTransUnitIdx, UInt iBlkSize ) { return m_apiBufU + getAddrOffset( iTransUnitIdx, iBlkSize, m_iCWidth ); } |
---|
188 | Pel* getCrAddr ( UInt iTransUnitIdx, UInt iBlkSize ) { return m_apiBufV + getAddrOffset( iTransUnitIdx, iBlkSize, m_iCWidth ); } |
---|
189 | |
---|
190 | // Get stride value of YUV buffer |
---|
191 | UInt getStride () { return m_iWidth; } |
---|
192 | UInt getCStride () { return m_iCWidth; } |
---|
193 | UInt getHeight () { return m_iHeight; } |
---|
194 | |
---|
195 | UInt getWidth () { return m_iWidth; } |
---|
196 | UInt getCHeight () { return m_iCHeight; } |
---|
197 | UInt getCWidth () { return m_iCWidth; } |
---|
198 | |
---|
199 | // ------------------------------------------------------------------------------------------------------------------ |
---|
200 | // Miscellaneous |
---|
201 | // ------------------------------------------------------------------------------------------------------------------ |
---|
202 | |
---|
203 | __inline Pel xClip (Pel x ) { return ( (x < 0) ? 0 : (x > (Pel)g_uiIBDI_MAX) ? (Pel)g_uiIBDI_MAX : x ); } |
---|
204 | };// END CLASS DEFINITION TComYuv |
---|
205 | |
---|
206 | //! \} |
---|
207 | |
---|
208 | #endif // __TCOMYUV__ |
---|