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-2011, 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 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 | |
---|
35 | #include "TRenImage.h" |
---|
36 | #include "TRenImagePlane.h" |
---|
37 | #include "TRenFilter.h" |
---|
38 | #include "assert.h" |
---|
39 | |
---|
40 | template<typename T> |
---|
41 | TRenImage<T>::TRenImage( TRenImage& rcIn ) |
---|
42 | { |
---|
43 | allocatePlanes( rcIn.getPlane(0)->getWidth(), rcIn.getPlane(0)->getHeight(), rcIn.getNumberOfFullPlanes(), rcIn.getNumberOfQuaterPlanes() ) ; assign(&rcIn); |
---|
44 | } |
---|
45 | |
---|
46 | template<typename T> |
---|
47 | TRenImage<T>::TRenImage( UInt uiWidth, UInt uiHeight, UInt uiNumberOfFullPlanes, UInt uiNumberOfQuaterPlanes ) |
---|
48 | { |
---|
49 | allocatePlanes( uiWidth, uiHeight, uiNumberOfFullPlanes, uiNumberOfQuaterPlanes ); |
---|
50 | } |
---|
51 | |
---|
52 | template<typename T> |
---|
53 | TRenImage<T>::TRenImage() : m_uiNumberOfFullPlanes(0), m_uiNumberOfQuaterPlanes(0), m_uiNumberOfPlanes(0), m_apcPlanes(0) |
---|
54 | { |
---|
55 | |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | template<> |
---|
60 | TRenImage<Pel>::TRenImage( TComPicYuv* pcPicYuv, Bool bFirstPlaneOnly ) |
---|
61 | { |
---|
62 | if (bFirstPlaneOnly) //400 |
---|
63 | { |
---|
64 | m_uiNumberOfPlanes = 1; |
---|
65 | m_uiNumberOfFullPlanes = 1; |
---|
66 | m_uiNumberOfQuaterPlanes = 0; |
---|
67 | m_apcPlanes = new TRenImagePlane<Pel>*[ m_uiNumberOfPlanes ]; |
---|
68 | m_apcPlanes[0] = new TRenImagePlane<Pel>( pcPicYuv->getBufY(), pcPicYuv->getWidth() + (REN_LUMA_MARGIN << 1), pcPicYuv->getHeight()+ (REN_LUMA_MARGIN << 1), pcPicYuv->getStride (), REN_LUMA_MARGIN, g_uiPCMBitDepthLuma ); |
---|
69 | } |
---|
70 | else //420 |
---|
71 | { |
---|
72 | m_uiNumberOfPlanes = 3; |
---|
73 | m_uiNumberOfFullPlanes = 1; |
---|
74 | m_uiNumberOfQuaterPlanes = 2; |
---|
75 | |
---|
76 | m_apcPlanes = new TRenImagePlane<Pel>*[ m_uiNumberOfPlanes ]; |
---|
77 | m_apcPlanes[0] = new TRenImagePlane<Pel>( pcPicYuv->getBufY(), pcPicYuv->getWidth() + (REN_LUMA_MARGIN << 1), pcPicYuv->getHeight() + (REN_LUMA_MARGIN << 1), pcPicYuv->getStride (), REN_LUMA_MARGIN , g_uiPCMBitDepthLuma ); |
---|
78 | m_apcPlanes[1] = new TRenImagePlane<Pel>( pcPicYuv->getBufU(), (pcPicYuv->getWidth()>>1)+ REN_LUMA_MARGIN , (pcPicYuv->getHeight()>>1) + REN_LUMA_MARGIN , pcPicYuv->getCStride(), REN_LUMA_MARGIN >> 1, g_uiPCMBitDepthChroma ); |
---|
79 | m_apcPlanes[2] = new TRenImagePlane<Pel>( pcPicYuv->getBufV(), (pcPicYuv->getWidth()>>1)+ REN_LUMA_MARGIN , (pcPicYuv->getHeight()>>1) + REN_LUMA_MARGIN , pcPicYuv->getCStride(), REN_LUMA_MARGIN >> 1, g_uiPCMBitDepthChroma ); |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | template<typename T> |
---|
84 | TRenImage<T>* TRenImage<T>::create() |
---|
85 | { |
---|
86 | return new TRenImage( m_apcPlanes[0]->getWidth(), m_apcPlanes[0]->getHeight(), m_uiNumberOfFullPlanes, m_uiNumberOfQuaterPlanes ); |
---|
87 | } |
---|
88 | |
---|
89 | |
---|
90 | template<typename T> |
---|
91 | TRenImage<T>::TRenImage( TComPicYuv* pcPicYuv, Bool bFirstPlaneOnly ) |
---|
92 | { |
---|
93 | assert(0); |
---|
94 | } |
---|
95 | |
---|
96 | template<class T> |
---|
97 | TRenImagePlane<T>* TRenImage<T>::getPlane(UInt uiPlaneNumber) const |
---|
98 | { |
---|
99 | return m_apcPlanes[uiPlaneNumber]; |
---|
100 | } |
---|
101 | |
---|
102 | template<class T> |
---|
103 | TRenImagePlane<T>** TRenImage<T>::getPlanes() const |
---|
104 | { |
---|
105 | return m_apcPlanes; |
---|
106 | } |
---|
107 | |
---|
108 | template<typename T> |
---|
109 | Void TRenImage<T>::getDataAndStrides( T** pptData, Int* piStrides ) |
---|
110 | { |
---|
111 | for (UInt uiCurPlane = 0; uiCurPlane < m_uiNumberOfPlanes; uiCurPlane++ ) |
---|
112 | { |
---|
113 | piStrides[uiCurPlane] = m_apcPlanes[uiCurPlane]->getStride (); |
---|
114 | pptData [uiCurPlane] = m_apcPlanes[uiCurPlane]->getPlaneData(); |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | |
---|
119 | template<typename T> |
---|
120 | Void TRenImage<T>::getWidthAndHeight( Int* ppiWidths, Int* ppiHeights ) |
---|
121 | { |
---|
122 | for (UInt uiCurPlane = 0; uiCurPlane < m_uiNumberOfPlanes; uiCurPlane++ ) |
---|
123 | { |
---|
124 | ppiWidths [uiCurPlane] = m_apcPlanes[uiCurPlane]->getWidth (); |
---|
125 | ppiHeights[uiCurPlane] = m_apcPlanes[uiCurPlane]->getHeight(); |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | template<typename T> |
---|
130 | Void TRenImage<T>::allocatePlanes( UInt uiWidth, UInt uiHeight, UInt uiNumberOfFullPlanes, UInt uiNumberOfQuaterPlanes ) |
---|
131 | { |
---|
132 | assert( uiNumberOfFullPlanes + uiNumberOfQuaterPlanes); |
---|
133 | |
---|
134 | UInt uiHalfWidth = uiWidth >> 1; |
---|
135 | UInt uiHalfHeight = uiHeight >> 1; |
---|
136 | |
---|
137 | uiHalfWidth = (uiHalfWidth == 0) ? 1 : uiHalfWidth ; |
---|
138 | uiHalfHeight = (uiHalfHeight == 0) ? 1 : uiHalfHeight; |
---|
139 | |
---|
140 | m_uiNumberOfPlanes = uiNumberOfFullPlanes + uiNumberOfQuaterPlanes; ; |
---|
141 | m_uiNumberOfFullPlanes = uiNumberOfFullPlanes; |
---|
142 | m_uiNumberOfQuaterPlanes = uiNumberOfQuaterPlanes; |
---|
143 | |
---|
144 | this->m_apcPlanes = new TRenImagePlane<T>*[m_uiNumberOfPlanes]; |
---|
145 | |
---|
146 | for (UInt uiCurPlane = 0; uiCurPlane < uiNumberOfFullPlanes; uiCurPlane++) |
---|
147 | { |
---|
148 | this->m_apcPlanes[uiCurPlane] = new TRenImagePlane<T>(uiWidth, uiHeight, REN_LUMA_MARGIN, g_uiPCMBitDepthLuma ); |
---|
149 | }; |
---|
150 | |
---|
151 | for (UInt uiCurPlane = 0; uiCurPlane < uiNumberOfQuaterPlanes; uiCurPlane++) |
---|
152 | { |
---|
153 | this->m_apcPlanes[uiCurPlane+uiNumberOfFullPlanes] = new TRenImagePlane<T>(uiHalfWidth, uiHalfHeight, REN_LUMA_MARGIN >> 1, g_uiPCMBitDepthChroma); |
---|
154 | }; |
---|
155 | } |
---|
156 | |
---|
157 | |
---|
158 | template<class T> |
---|
159 | Void TRenImage<T>::assign(Int iVal) |
---|
160 | { |
---|
161 | for (UInt uiCurPlane = 0; uiCurPlane < m_uiNumberOfPlanes; uiCurPlane++) |
---|
162 | { |
---|
163 | m_apcPlanes[uiCurPlane]->assign( iVal); |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | |
---|
168 | template<class T> |
---|
169 | Void TRenImage<T>::devide( Double dDevisor ) |
---|
170 | { |
---|
171 | for (UInt uiCurPlane = 0; uiCurPlane < m_uiNumberOfPlanes; uiCurPlane++) |
---|
172 | { |
---|
173 | m_apcPlanes[uiCurPlane]->devide(dDevisor); |
---|
174 | } |
---|
175 | } |
---|
176 | |
---|
177 | |
---|
178 | template<class T> template<class S> |
---|
179 | Void TRenImage<T>::assign( TRenImage<S>* pcSrcImage ) |
---|
180 | { |
---|
181 | if (pcSrcImage->getNumberOfPlanes() != m_uiNumberOfPlanes ) |
---|
182 | { |
---|
183 | assert(0); |
---|
184 | } |
---|
185 | |
---|
186 | for (UInt uiCurPlane = 0; uiCurPlane < m_uiNumberOfPlanes; uiCurPlane++) |
---|
187 | { |
---|
188 | m_apcPlanes[uiCurPlane]->assign(pcSrcImage->getPlane(uiCurPlane)->getPlaneDataOrg(),pcSrcImage->getPlane(uiCurPlane)->getStride()); |
---|
189 | } |
---|
190 | } |
---|
191 | |
---|
192 | |
---|
193 | template<typename T> |
---|
194 | Void TRenImage<T>::setData( TRenImage* pcInputImage, Bool bClean ) |
---|
195 | { |
---|
196 | for (UInt uiPlane = 0; uiPlane < m_uiNumberOfPlanes; uiPlane++) |
---|
197 | { |
---|
198 | m_apcPlanes[uiPlane]->setData( pcInputImage->getPlane( uiPlane ), bClean ); |
---|
199 | } |
---|
200 | } |
---|
201 | |
---|
202 | template<typename T> |
---|
203 | Void TRenImage<T>::extendMargin() |
---|
204 | { |
---|
205 | for (UInt uiPlane = 0; uiPlane < m_uiNumberOfPlanes; uiPlane++) |
---|
206 | { |
---|
207 | m_apcPlanes[uiPlane]->extendMargin(); |
---|
208 | } |
---|
209 | } |
---|
210 | |
---|
211 | template<class T> |
---|
212 | Void TRenImage<T>::xDeletePlanes() |
---|
213 | { |
---|
214 | for (UInt uiCurPlane = 0; uiCurPlane < m_uiNumberOfPlanes; uiCurPlane++) |
---|
215 | { |
---|
216 | if ( m_apcPlanes[uiCurPlane]) |
---|
217 | { |
---|
218 | delete m_apcPlanes[uiCurPlane]; |
---|
219 | } |
---|
220 | m_apcPlanes[uiCurPlane] = 0; |
---|
221 | } |
---|
222 | } |
---|
223 | |
---|
224 | |
---|
225 | template<class T> |
---|
226 | Void TRenImage<T>::init() |
---|
227 | { |
---|
228 | // YUV-init |
---|
229 | m_apcPlanes[0]->assign((Pel) 0 ); |
---|
230 | |
---|
231 | for (UInt uiCurPlane = 1; uiCurPlane < m_uiNumberOfPlanes; uiCurPlane++) |
---|
232 | { |
---|
233 | m_apcPlanes[uiCurPlane]->assign( (Pel) ((g_uiIBDI_MAX+1) >> 1) ); |
---|
234 | } |
---|
235 | } |
---|
236 | |
---|
237 | |
---|
238 | template<class T> |
---|
239 | TRenImage<T>::~TRenImage() { |
---|
240 | xDeletePlanes(); |
---|
241 | delete[] m_apcPlanes; |
---|
242 | } |
---|
243 | |
---|
244 | |
---|
245 | |
---|
246 | template<class T> |
---|
247 | UInt TRenImage<T>::getNumberOfPlanes() const |
---|
248 | { |
---|
249 | return m_uiNumberOfPlanes; |
---|
250 | } |
---|
251 | |
---|
252 | template<class T> |
---|
253 | UInt TRenImage<T>::getNumberOfQuaterPlanes() const |
---|
254 | { |
---|
255 | return m_uiNumberOfQuaterPlanes; |
---|
256 | } |
---|
257 | |
---|
258 | template<class T> |
---|
259 | UInt TRenImage<T>::getNumberOfFullPlanes() const |
---|
260 | { |
---|
261 | return m_uiNumberOfFullPlanes; |
---|
262 | } |
---|
263 | |
---|
264 | template class TRenImage<Pel>; |
---|
265 | template class TRenImage<Int>; |
---|
266 | template class TRenImage<Double>; |
---|
267 | template class TRenImage<Bool>; |
---|
268 | |
---|
269 | |
---|
270 | template Void TRenImage<Pel>::assign<Pel> (TRenImage<Pel>* ); |
---|
271 | |
---|