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.cpp |
---|
35 | \brief general YUV buffer class |
---|
36 | \todo this should be merged with TComPicYuv |
---|
37 | */ |
---|
38 | |
---|
39 | #include <stdlib.h> |
---|
40 | #include <memory.h> |
---|
41 | #include <assert.h> |
---|
42 | #include <math.h> |
---|
43 | |
---|
44 | #include "CommonDef.h" |
---|
45 | #include "TComYuv.h" |
---|
46 | #include "TComInterpolationFilter.h" |
---|
47 | |
---|
48 | //! \ingroup TLibCommon |
---|
49 | //! \{ |
---|
50 | |
---|
51 | TComYuv::TComYuv() |
---|
52 | { |
---|
53 | m_apiBufY = NULL; |
---|
54 | m_apiBufU = NULL; |
---|
55 | m_apiBufV = NULL; |
---|
56 | } |
---|
57 | |
---|
58 | TComYuv::~TComYuv() |
---|
59 | { |
---|
60 | } |
---|
61 | |
---|
62 | Void TComYuv::create( UInt iWidth, UInt iHeight ) |
---|
63 | { |
---|
64 | // memory allocation |
---|
65 | m_apiBufY = (Pel*)xMalloc( Pel, iWidth*iHeight ); |
---|
66 | m_apiBufU = (Pel*)xMalloc( Pel, iWidth*iHeight >> 2 ); |
---|
67 | m_apiBufV = (Pel*)xMalloc( Pel, iWidth*iHeight >> 2 ); |
---|
68 | |
---|
69 | // set width and height |
---|
70 | m_iWidth = iWidth; |
---|
71 | m_iHeight = iHeight; |
---|
72 | m_iCWidth = iWidth >> 1; |
---|
73 | m_iCHeight = iHeight >> 1; |
---|
74 | } |
---|
75 | |
---|
76 | Void TComYuv::destroy() |
---|
77 | { |
---|
78 | // memory free |
---|
79 | xFree( m_apiBufY ); m_apiBufY = NULL; |
---|
80 | xFree( m_apiBufU ); m_apiBufU = NULL; |
---|
81 | xFree( m_apiBufV ); m_apiBufV = NULL; |
---|
82 | } |
---|
83 | |
---|
84 | Void TComYuv::clear() |
---|
85 | { |
---|
86 | ::memset( m_apiBufY, 0, ( m_iWidth * m_iHeight )*sizeof(Pel) ); |
---|
87 | ::memset( m_apiBufU, 0, ( m_iCWidth * m_iCHeight )*sizeof(Pel) ); |
---|
88 | ::memset( m_apiBufV, 0, ( m_iCWidth * m_iCHeight )*sizeof(Pel) ); |
---|
89 | } |
---|
90 | |
---|
91 | Void TComYuv::copyToPicYuv ( TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth, UInt uiPartIdx ) |
---|
92 | { |
---|
93 | copyToPicLuma ( pcPicYuvDst, iCuAddr, uiAbsZorderIdx, uiPartDepth, uiPartIdx ); |
---|
94 | copyToPicChroma( pcPicYuvDst, iCuAddr, uiAbsZorderIdx, uiPartDepth, uiPartIdx ); |
---|
95 | } |
---|
96 | |
---|
97 | Void TComYuv::copyToPicLuma ( TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth, UInt uiPartIdx ) |
---|
98 | { |
---|
99 | Int y, iWidth, iHeight; |
---|
100 | iWidth = m_iWidth >>uiPartDepth; |
---|
101 | iHeight = m_iHeight>>uiPartDepth; |
---|
102 | |
---|
103 | Pel* pSrc = getLumaAddr(uiPartIdx, iWidth); |
---|
104 | Pel* pDst = pcPicYuvDst->getLumaAddr ( iCuAddr, uiAbsZorderIdx ); |
---|
105 | |
---|
106 | UInt iSrcStride = getStride(); |
---|
107 | UInt iDstStride = pcPicYuvDst->getStride(); |
---|
108 | |
---|
109 | for ( y = iHeight; y != 0; y-- ) |
---|
110 | { |
---|
111 | ::memcpy( pDst, pSrc, sizeof(Pel)*iWidth); |
---|
112 | pDst += iDstStride; |
---|
113 | pSrc += iSrcStride; |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | Void TComYuv::copyToPicChroma( TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth, UInt uiPartIdx ) |
---|
118 | { |
---|
119 | Int y, iWidth, iHeight; |
---|
120 | iWidth = m_iCWidth >>uiPartDepth; |
---|
121 | iHeight = m_iCHeight>>uiPartDepth; |
---|
122 | |
---|
123 | Pel* pSrcU = getCbAddr(uiPartIdx, iWidth); |
---|
124 | Pel* pSrcV = getCrAddr(uiPartIdx, iWidth); |
---|
125 | Pel* pDstU = pcPicYuvDst->getCbAddr( iCuAddr, uiAbsZorderIdx ); |
---|
126 | Pel* pDstV = pcPicYuvDst->getCrAddr( iCuAddr, uiAbsZorderIdx ); |
---|
127 | |
---|
128 | UInt iSrcStride = getCStride(); |
---|
129 | UInt iDstStride = pcPicYuvDst->getCStride(); |
---|
130 | for ( y = iHeight; y != 0; y-- ) |
---|
131 | { |
---|
132 | ::memcpy( pDstU, pSrcU, sizeof(Pel)*(iWidth) ); |
---|
133 | ::memcpy( pDstV, pSrcV, sizeof(Pel)*(iWidth) ); |
---|
134 | pSrcU += iSrcStride; |
---|
135 | pSrcV += iSrcStride; |
---|
136 | pDstU += iDstStride; |
---|
137 | pDstV += iDstStride; |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | Void TComYuv::copyFromPicYuv ( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiAbsZorderIdx ) |
---|
142 | { |
---|
143 | copyFromPicLuma ( pcPicYuvSrc, iCuAddr, uiAbsZorderIdx ); |
---|
144 | copyFromPicChroma( pcPicYuvSrc, iCuAddr, uiAbsZorderIdx ); |
---|
145 | } |
---|
146 | |
---|
147 | Void TComYuv::copyFromPicLuma ( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiAbsZorderIdx ) |
---|
148 | { |
---|
149 | Int y; |
---|
150 | |
---|
151 | Pel* pDst = m_apiBufY; |
---|
152 | Pel* pSrc = pcPicYuvSrc->getLumaAddr ( iCuAddr, uiAbsZorderIdx ); |
---|
153 | |
---|
154 | UInt iDstStride = getStride(); |
---|
155 | UInt iSrcStride = pcPicYuvSrc->getStride(); |
---|
156 | for ( y = m_iHeight; y != 0; y-- ) |
---|
157 | { |
---|
158 | ::memcpy( pDst, pSrc, sizeof(Pel)*m_iWidth); |
---|
159 | pDst += iDstStride; |
---|
160 | pSrc += iSrcStride; |
---|
161 | } |
---|
162 | } |
---|
163 | |
---|
164 | Void TComYuv::copyFromPicChroma( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiAbsZorderIdx ) |
---|
165 | { |
---|
166 | Int y; |
---|
167 | |
---|
168 | Pel* pDstU = m_apiBufU; |
---|
169 | Pel* pDstV = m_apiBufV; |
---|
170 | Pel* pSrcU = pcPicYuvSrc->getCbAddr( iCuAddr, uiAbsZorderIdx ); |
---|
171 | Pel* pSrcV = pcPicYuvSrc->getCrAddr( iCuAddr, uiAbsZorderIdx ); |
---|
172 | |
---|
173 | UInt iDstStride = getCStride(); |
---|
174 | UInt iSrcStride = pcPicYuvSrc->getCStride(); |
---|
175 | for ( y = m_iCHeight; y != 0; y-- ) |
---|
176 | { |
---|
177 | ::memcpy( pDstU, pSrcU, sizeof(Pel)*(m_iCWidth) ); |
---|
178 | ::memcpy( pDstV, pSrcV, sizeof(Pel)*(m_iCWidth) ); |
---|
179 | pSrcU += iSrcStride; |
---|
180 | pSrcV += iSrcStride; |
---|
181 | pDstU += iDstStride; |
---|
182 | pDstV += iDstStride; |
---|
183 | } |
---|
184 | } |
---|
185 | |
---|
186 | #if NO_RESIDUAL_FLAG_FOR_BLPRED |
---|
187 | Void TComYuv::copyFromPicLuma ( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiZorderIdxInCU, UInt uiAbsZorderIdx, UInt uiWidth, UInt uiHeight ) |
---|
188 | { |
---|
189 | Int y; |
---|
190 | |
---|
191 | Pel* pDst = getLumaAddr(uiAbsZorderIdx); |
---|
192 | Pel* pSrc = pcPicYuvSrc->getLumaAddr ( iCuAddr, uiZorderIdxInCU + uiAbsZorderIdx ); |
---|
193 | |
---|
194 | UInt iDstStride = getStride(); |
---|
195 | UInt iSrcStride = pcPicYuvSrc->getStride(); |
---|
196 | for ( y = uiHeight; y != 0; y-- ) |
---|
197 | { |
---|
198 | ::memcpy( pDst, pSrc, sizeof(Pel)*uiWidth); |
---|
199 | pDst += iDstStride; |
---|
200 | pSrc += iSrcStride; |
---|
201 | } |
---|
202 | } |
---|
203 | |
---|
204 | Void TComYuv::copyFromPicChroma( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiZorderIdxInCU, UInt uiAbsZorderIdx, UInt uiCWidth, UInt uiCHeight, UInt uiChromaId ) |
---|
205 | { |
---|
206 | Int y; |
---|
207 | |
---|
208 | if (!uiChromaId) |
---|
209 | { |
---|
210 | Pel* pDstU = getCbAddr(uiAbsZorderIdx); |
---|
211 | Pel* pSrcU = pcPicYuvSrc->getCbAddr( iCuAddr, uiZorderIdxInCU + uiAbsZorderIdx ); |
---|
212 | |
---|
213 | UInt iDstStride = getCStride(); |
---|
214 | UInt iSrcStride = pcPicYuvSrc->getCStride(); |
---|
215 | for ( y = uiCHeight; y != 0; y-- ) |
---|
216 | { |
---|
217 | ::memcpy( pDstU, pSrcU, sizeof(Pel)*(uiCWidth) ); |
---|
218 | pSrcU += iSrcStride; |
---|
219 | pDstU += iDstStride; |
---|
220 | } |
---|
221 | } |
---|
222 | else |
---|
223 | { |
---|
224 | Pel* pDstV = getCrAddr(uiAbsZorderIdx); |
---|
225 | Pel* pSrcV = pcPicYuvSrc->getCrAddr( iCuAddr, uiZorderIdxInCU + uiAbsZorderIdx ); |
---|
226 | |
---|
227 | UInt iDstStride = getCStride(); |
---|
228 | UInt iSrcStride = pcPicYuvSrc->getCStride(); |
---|
229 | for ( y = uiCHeight; y != 0; y-- ) |
---|
230 | { |
---|
231 | ::memcpy( pDstV, pSrcV, sizeof(Pel)*(uiCWidth) ); |
---|
232 | pSrcV += iSrcStride; |
---|
233 | pDstV += iDstStride; |
---|
234 | } |
---|
235 | } |
---|
236 | } |
---|
237 | #endif |
---|
238 | |
---|
239 | Void TComYuv::copyToPartYuv( TComYuv* pcYuvDst, UInt uiDstPartIdx ) |
---|
240 | { |
---|
241 | copyToPartLuma ( pcYuvDst, uiDstPartIdx ); |
---|
242 | copyToPartChroma( pcYuvDst, uiDstPartIdx ); |
---|
243 | } |
---|
244 | |
---|
245 | Void TComYuv::copyToPartLuma( TComYuv* pcYuvDst, UInt uiDstPartIdx ) |
---|
246 | { |
---|
247 | Int y; |
---|
248 | |
---|
249 | Pel* pSrc = m_apiBufY; |
---|
250 | Pel* pDst = pcYuvDst->getLumaAddr( uiDstPartIdx ); |
---|
251 | |
---|
252 | UInt iSrcStride = getStride(); |
---|
253 | UInt iDstStride = pcYuvDst->getStride(); |
---|
254 | for ( y = m_iHeight; y != 0; y-- ) |
---|
255 | { |
---|
256 | ::memcpy( pDst, pSrc, sizeof(Pel)*m_iWidth); |
---|
257 | pDst += iDstStride; |
---|
258 | pSrc += iSrcStride; |
---|
259 | } |
---|
260 | } |
---|
261 | |
---|
262 | Void TComYuv::copyToPartChroma( TComYuv* pcYuvDst, UInt uiDstPartIdx ) |
---|
263 | { |
---|
264 | Int y; |
---|
265 | |
---|
266 | Pel* pSrcU = m_apiBufU; |
---|
267 | Pel* pSrcV = m_apiBufV; |
---|
268 | Pel* pDstU = pcYuvDst->getCbAddr( uiDstPartIdx ); |
---|
269 | Pel* pDstV = pcYuvDst->getCrAddr( uiDstPartIdx ); |
---|
270 | |
---|
271 | UInt iSrcStride = getCStride(); |
---|
272 | UInt iDstStride = pcYuvDst->getCStride(); |
---|
273 | for ( y = m_iCHeight; y != 0; y-- ) |
---|
274 | { |
---|
275 | ::memcpy( pDstU, pSrcU, sizeof(Pel)*(m_iCWidth) ); |
---|
276 | ::memcpy( pDstV, pSrcV, sizeof(Pel)*(m_iCWidth) ); |
---|
277 | pSrcU += iSrcStride; |
---|
278 | pSrcV += iSrcStride; |
---|
279 | pDstU += iDstStride; |
---|
280 | pDstV += iDstStride; |
---|
281 | } |
---|
282 | } |
---|
283 | |
---|
284 | Void TComYuv::copyPartToYuv( TComYuv* pcYuvDst, UInt uiSrcPartIdx ) |
---|
285 | { |
---|
286 | copyPartToLuma ( pcYuvDst, uiSrcPartIdx ); |
---|
287 | copyPartToChroma( pcYuvDst, uiSrcPartIdx ); |
---|
288 | } |
---|
289 | |
---|
290 | Void TComYuv::copyPartToLuma( TComYuv* pcYuvDst, UInt uiSrcPartIdx ) |
---|
291 | { |
---|
292 | Int y; |
---|
293 | |
---|
294 | Pel* pSrc = getLumaAddr(uiSrcPartIdx); |
---|
295 | Pel* pDst = pcYuvDst->getLumaAddr( 0 ); |
---|
296 | |
---|
297 | UInt iSrcStride = getStride(); |
---|
298 | UInt iDstStride = pcYuvDst->getStride(); |
---|
299 | |
---|
300 | UInt uiHeight = pcYuvDst->getHeight(); |
---|
301 | UInt uiWidth = pcYuvDst->getWidth(); |
---|
302 | |
---|
303 | for ( y = uiHeight; y != 0; y-- ) |
---|
304 | { |
---|
305 | ::memcpy( pDst, pSrc, sizeof(Pel)*uiWidth); |
---|
306 | pDst += iDstStride; |
---|
307 | pSrc += iSrcStride; |
---|
308 | } |
---|
309 | } |
---|
310 | |
---|
311 | Void TComYuv::copyPartToChroma( TComYuv* pcYuvDst, UInt uiSrcPartIdx ) |
---|
312 | { |
---|
313 | Int y; |
---|
314 | |
---|
315 | Pel* pSrcU = getCbAddr( uiSrcPartIdx ); |
---|
316 | Pel* pSrcV = getCrAddr( uiSrcPartIdx ); |
---|
317 | Pel* pDstU = pcYuvDst->getCbAddr( 0 ); |
---|
318 | Pel* pDstV = pcYuvDst->getCrAddr( 0 ); |
---|
319 | |
---|
320 | UInt iSrcStride = getCStride(); |
---|
321 | UInt iDstStride = pcYuvDst->getCStride(); |
---|
322 | |
---|
323 | UInt uiCHeight = pcYuvDst->getCHeight(); |
---|
324 | UInt uiCWidth = pcYuvDst->getCWidth(); |
---|
325 | |
---|
326 | for ( y = uiCHeight; y != 0; y-- ) |
---|
327 | { |
---|
328 | ::memcpy( pDstU, pSrcU, sizeof(Pel)*(uiCWidth) ); |
---|
329 | ::memcpy( pDstV, pSrcV, sizeof(Pel)*(uiCWidth) ); |
---|
330 | pSrcU += iSrcStride; |
---|
331 | pSrcV += iSrcStride; |
---|
332 | pDstU += iDstStride; |
---|
333 | pDstV += iDstStride; |
---|
334 | } |
---|
335 | } |
---|
336 | |
---|
337 | Void TComYuv::copyPartToPartYuv ( TComYuv* pcYuvDst, UInt uiPartIdx, UInt iWidth, UInt iHeight ) |
---|
338 | { |
---|
339 | copyPartToPartLuma (pcYuvDst, uiPartIdx, iWidth, iHeight ); |
---|
340 | copyPartToPartChroma (pcYuvDst, uiPartIdx, iWidth>>1, iHeight>>1 ); |
---|
341 | } |
---|
342 | |
---|
343 | Void TComYuv::copyPartToPartLuma ( TComYuv* pcYuvDst, UInt uiPartIdx, UInt iWidth, UInt iHeight ) |
---|
344 | { |
---|
345 | Pel* pSrc = getLumaAddr(uiPartIdx); |
---|
346 | Pel* pDst = pcYuvDst->getLumaAddr(uiPartIdx); |
---|
347 | if( pSrc == pDst ) |
---|
348 | { |
---|
349 | //th not a good idea |
---|
350 | //th best would be to fix the caller |
---|
351 | return ; |
---|
352 | } |
---|
353 | |
---|
354 | UInt iSrcStride = getStride(); |
---|
355 | UInt iDstStride = pcYuvDst->getStride(); |
---|
356 | for ( UInt y = iHeight; y != 0; y-- ) |
---|
357 | { |
---|
358 | ::memcpy( pDst, pSrc, iWidth * sizeof(Pel) ); |
---|
359 | pSrc += iSrcStride; |
---|
360 | pDst += iDstStride; |
---|
361 | } |
---|
362 | } |
---|
363 | |
---|
364 | Void TComYuv::copyPartToPartChroma( TComYuv* pcYuvDst, UInt uiPartIdx, UInt iWidth, UInt iHeight ) |
---|
365 | { |
---|
366 | Pel* pSrcU = getCbAddr(uiPartIdx); |
---|
367 | Pel* pSrcV = getCrAddr(uiPartIdx); |
---|
368 | Pel* pDstU = pcYuvDst->getCbAddr(uiPartIdx); |
---|
369 | Pel* pDstV = pcYuvDst->getCrAddr(uiPartIdx); |
---|
370 | |
---|
371 | if( pSrcU == pDstU && pSrcV == pDstV) |
---|
372 | { |
---|
373 | //th not a good idea |
---|
374 | //th best would be to fix the caller |
---|
375 | return ; |
---|
376 | } |
---|
377 | |
---|
378 | UInt iSrcStride = getCStride(); |
---|
379 | UInt iDstStride = pcYuvDst->getCStride(); |
---|
380 | for ( UInt y = iHeight; y != 0; y-- ) |
---|
381 | { |
---|
382 | ::memcpy( pDstU, pSrcU, iWidth * sizeof(Pel) ); |
---|
383 | ::memcpy( pDstV, pSrcV, iWidth * sizeof(Pel) ); |
---|
384 | pSrcU += iSrcStride; |
---|
385 | pSrcV += iSrcStride; |
---|
386 | pDstU += iDstStride; |
---|
387 | pDstV += iDstStride; |
---|
388 | } |
---|
389 | } |
---|
390 | |
---|
391 | Void TComYuv::copyPartToPartChroma( TComYuv* pcYuvDst, UInt uiPartIdx, UInt iWidth, UInt iHeight, UInt chromaId) |
---|
392 | { |
---|
393 | if(chromaId == 0) |
---|
394 | { |
---|
395 | Pel* pSrcU = getCbAddr(uiPartIdx); |
---|
396 | Pel* pDstU = pcYuvDst->getCbAddr(uiPartIdx); |
---|
397 | if( pSrcU == pDstU) |
---|
398 | { |
---|
399 | return ; |
---|
400 | } |
---|
401 | UInt iSrcStride = getCStride(); |
---|
402 | UInt iDstStride = pcYuvDst->getCStride(); |
---|
403 | for ( UInt y = iHeight; y != 0; y-- ) |
---|
404 | { |
---|
405 | ::memcpy( pDstU, pSrcU, iWidth * sizeof(Pel) ); |
---|
406 | pSrcU += iSrcStride; |
---|
407 | pDstU += iDstStride; |
---|
408 | } |
---|
409 | } |
---|
410 | else if (chromaId == 1) |
---|
411 | { |
---|
412 | Pel* pSrcV = getCrAddr(uiPartIdx); |
---|
413 | Pel* pDstV = pcYuvDst->getCrAddr(uiPartIdx); |
---|
414 | if( pSrcV == pDstV) |
---|
415 | { |
---|
416 | return; |
---|
417 | } |
---|
418 | UInt iSrcStride = getCStride(); |
---|
419 | UInt iDstStride = pcYuvDst->getCStride(); |
---|
420 | for ( UInt y = iHeight; y != 0; y-- ) |
---|
421 | { |
---|
422 | ::memcpy( pDstV, pSrcV, iWidth * sizeof(Pel) ); |
---|
423 | pSrcV += iSrcStride; |
---|
424 | pDstV += iDstStride; |
---|
425 | } |
---|
426 | } |
---|
427 | else |
---|
428 | { |
---|
429 | Pel* pSrcU = getCbAddr(uiPartIdx); |
---|
430 | Pel* pSrcV = getCrAddr(uiPartIdx); |
---|
431 | Pel* pDstU = pcYuvDst->getCbAddr(uiPartIdx); |
---|
432 | Pel* pDstV = pcYuvDst->getCrAddr(uiPartIdx); |
---|
433 | |
---|
434 | if( pSrcU == pDstU && pSrcV == pDstV) |
---|
435 | { |
---|
436 | //th not a good idea |
---|
437 | //th best would be to fix the caller |
---|
438 | return ; |
---|
439 | } |
---|
440 | UInt iSrcStride = getCStride(); |
---|
441 | UInt iDstStride = pcYuvDst->getCStride(); |
---|
442 | for ( UInt y = iHeight; y != 0; y-- ) |
---|
443 | { |
---|
444 | ::memcpy( pDstU, pSrcU, iWidth * sizeof(Pel) ); |
---|
445 | ::memcpy( pDstV, pSrcV, iWidth * sizeof(Pel) ); |
---|
446 | pSrcU += iSrcStride; |
---|
447 | pSrcV += iSrcStride; |
---|
448 | pDstU += iDstStride; |
---|
449 | pDstV += iDstStride; |
---|
450 | } |
---|
451 | } |
---|
452 | } |
---|
453 | |
---|
454 | Void TComYuv::addClip( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ) |
---|
455 | { |
---|
456 | addClipLuma ( pcYuvSrc0, pcYuvSrc1, uiTrUnitIdx, uiPartSize ); |
---|
457 | addClipChroma ( pcYuvSrc0, pcYuvSrc1, uiTrUnitIdx, uiPartSize>>1 ); |
---|
458 | } |
---|
459 | |
---|
460 | Void TComYuv::addClipLuma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ) |
---|
461 | { |
---|
462 | Int x, y; |
---|
463 | |
---|
464 | Pel* pSrc0 = pcYuvSrc0->getLumaAddr( uiTrUnitIdx, uiPartSize ); |
---|
465 | Pel* pSrc1 = pcYuvSrc1->getLumaAddr( uiTrUnitIdx, uiPartSize ); |
---|
466 | Pel* pDst = getLumaAddr( uiTrUnitIdx, uiPartSize ); |
---|
467 | |
---|
468 | UInt iSrc0Stride = pcYuvSrc0->getStride(); |
---|
469 | UInt iSrc1Stride = pcYuvSrc1->getStride(); |
---|
470 | UInt iDstStride = getStride(); |
---|
471 | for ( y = uiPartSize-1; y >= 0; y-- ) |
---|
472 | { |
---|
473 | for ( x = uiPartSize-1; x >= 0; x-- ) |
---|
474 | { |
---|
475 | pDst[x] = Clip( pSrc0[x] + pSrc1[x] ); |
---|
476 | } |
---|
477 | pSrc0 += iSrc0Stride; |
---|
478 | pSrc1 += iSrc1Stride; |
---|
479 | pDst += iDstStride; |
---|
480 | } |
---|
481 | } |
---|
482 | |
---|
483 | Void TComYuv::addClipChroma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ) |
---|
484 | { |
---|
485 | Int x, y; |
---|
486 | |
---|
487 | Pel* pSrcU0 = pcYuvSrc0->getCbAddr( uiTrUnitIdx, uiPartSize ); |
---|
488 | Pel* pSrcU1 = pcYuvSrc1->getCbAddr( uiTrUnitIdx, uiPartSize ); |
---|
489 | Pel* pSrcV0 = pcYuvSrc0->getCrAddr( uiTrUnitIdx, uiPartSize ); |
---|
490 | Pel* pSrcV1 = pcYuvSrc1->getCrAddr( uiTrUnitIdx, uiPartSize ); |
---|
491 | Pel* pDstU = getCbAddr( uiTrUnitIdx, uiPartSize ); |
---|
492 | Pel* pDstV = getCrAddr( uiTrUnitIdx, uiPartSize ); |
---|
493 | |
---|
494 | UInt iSrc0Stride = pcYuvSrc0->getCStride(); |
---|
495 | UInt iSrc1Stride = pcYuvSrc1->getCStride(); |
---|
496 | UInt iDstStride = getCStride(); |
---|
497 | for ( y = uiPartSize-1; y >= 0; y-- ) |
---|
498 | { |
---|
499 | for ( x = uiPartSize-1; x >= 0; x-- ) |
---|
500 | { |
---|
501 | pDstU[x] = Clip( pSrcU0[x] + pSrcU1[x] ); |
---|
502 | pDstV[x] = Clip( pSrcV0[x] + pSrcV1[x] ); |
---|
503 | } |
---|
504 | |
---|
505 | pSrcU0 += iSrc0Stride; |
---|
506 | pSrcU1 += iSrc1Stride; |
---|
507 | pSrcV0 += iSrc0Stride; |
---|
508 | pSrcV1 += iSrc1Stride; |
---|
509 | pDstU += iDstStride; |
---|
510 | pDstV += iDstStride; |
---|
511 | } |
---|
512 | } |
---|
513 | |
---|
514 | Void TComYuv::subtract( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ) |
---|
515 | { |
---|
516 | subtractLuma ( pcYuvSrc0, pcYuvSrc1, uiTrUnitIdx, uiPartSize ); |
---|
517 | subtractChroma( pcYuvSrc0, pcYuvSrc1, uiTrUnitIdx, uiPartSize>>1 ); |
---|
518 | } |
---|
519 | |
---|
520 | Void TComYuv::subtractLuma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ) |
---|
521 | { |
---|
522 | Int x, y; |
---|
523 | |
---|
524 | Pel* pSrc0 = pcYuvSrc0->getLumaAddr( uiTrUnitIdx, uiPartSize ); |
---|
525 | Pel* pSrc1 = pcYuvSrc1->getLumaAddr( uiTrUnitIdx, uiPartSize ); |
---|
526 | Pel* pDst = getLumaAddr( uiTrUnitIdx, uiPartSize ); |
---|
527 | |
---|
528 | Int iSrc0Stride = pcYuvSrc0->getStride(); |
---|
529 | Int iSrc1Stride = pcYuvSrc1->getStride(); |
---|
530 | Int iDstStride = getStride(); |
---|
531 | for ( y = uiPartSize-1; y >= 0; y-- ) |
---|
532 | { |
---|
533 | for ( x = uiPartSize-1; x >= 0; x-- ) |
---|
534 | { |
---|
535 | pDst[x] = pSrc0[x] - pSrc1[x]; |
---|
536 | } |
---|
537 | pSrc0 += iSrc0Stride; |
---|
538 | pSrc1 += iSrc1Stride; |
---|
539 | pDst += iDstStride; |
---|
540 | } |
---|
541 | } |
---|
542 | |
---|
543 | Void TComYuv::subtractChroma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ) |
---|
544 | { |
---|
545 | Int x, y; |
---|
546 | |
---|
547 | Pel* pSrcU0 = pcYuvSrc0->getCbAddr( uiTrUnitIdx, uiPartSize ); |
---|
548 | Pel* pSrcU1 = pcYuvSrc1->getCbAddr( uiTrUnitIdx, uiPartSize ); |
---|
549 | Pel* pSrcV0 = pcYuvSrc0->getCrAddr( uiTrUnitIdx, uiPartSize ); |
---|
550 | Pel* pSrcV1 = pcYuvSrc1->getCrAddr( uiTrUnitIdx, uiPartSize ); |
---|
551 | Pel* pDstU = getCbAddr( uiTrUnitIdx, uiPartSize ); |
---|
552 | Pel* pDstV = getCrAddr( uiTrUnitIdx, uiPartSize ); |
---|
553 | |
---|
554 | Int iSrc0Stride = pcYuvSrc0->getCStride(); |
---|
555 | Int iSrc1Stride = pcYuvSrc1->getCStride(); |
---|
556 | Int iDstStride = getCStride(); |
---|
557 | for ( y = uiPartSize-1; y >= 0; y-- ) |
---|
558 | { |
---|
559 | for ( x = uiPartSize-1; x >= 0; x-- ) |
---|
560 | { |
---|
561 | pDstU[x] = pSrcU0[x] - pSrcU1[x]; |
---|
562 | pDstV[x] = pSrcV0[x] - pSrcV1[x]; |
---|
563 | } |
---|
564 | pSrcU0 += iSrc0Stride; |
---|
565 | pSrcU1 += iSrc1Stride; |
---|
566 | pSrcV0 += iSrc0Stride; |
---|
567 | pSrcV1 += iSrc1Stride; |
---|
568 | pDstU += iDstStride; |
---|
569 | pDstV += iDstStride; |
---|
570 | } |
---|
571 | } |
---|
572 | |
---|
573 | Void TComYuv::addAvg( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt iPartUnitIdx, UInt iWidth, UInt iHeight ) |
---|
574 | { |
---|
575 | Int x, y; |
---|
576 | |
---|
577 | Pel* pSrcY0 = pcYuvSrc0->getLumaAddr( iPartUnitIdx ); |
---|
578 | Pel* pSrcU0 = pcYuvSrc0->getCbAddr ( iPartUnitIdx ); |
---|
579 | Pel* pSrcV0 = pcYuvSrc0->getCrAddr ( iPartUnitIdx ); |
---|
580 | |
---|
581 | Pel* pSrcY1 = pcYuvSrc1->getLumaAddr( iPartUnitIdx ); |
---|
582 | Pel* pSrcU1 = pcYuvSrc1->getCbAddr ( iPartUnitIdx ); |
---|
583 | Pel* pSrcV1 = pcYuvSrc1->getCrAddr ( iPartUnitIdx ); |
---|
584 | |
---|
585 | Pel* pDstY = getLumaAddr( iPartUnitIdx ); |
---|
586 | Pel* pDstU = getCbAddr ( iPartUnitIdx ); |
---|
587 | Pel* pDstV = getCrAddr ( iPartUnitIdx ); |
---|
588 | |
---|
589 | UInt iSrc0Stride = pcYuvSrc0->getStride(); |
---|
590 | UInt iSrc1Stride = pcYuvSrc1->getStride(); |
---|
591 | UInt iDstStride = getStride(); |
---|
592 | Int shiftNum = IF_INTERNAL_PREC + 1 - ( g_uiBitDepth + g_uiBitIncrement ); |
---|
593 | Int offset = ( 1 << ( shiftNum - 1 ) ) + 2 * IF_INTERNAL_OFFS; |
---|
594 | |
---|
595 | for ( y = 0; y < iHeight; y++ ) |
---|
596 | { |
---|
597 | for ( x = 0; x < iWidth; x += 4 ) |
---|
598 | { |
---|
599 | pDstY[ x + 0 ] = Clip( ( pSrcY0[ x + 0 ] + pSrcY1[ x + 0 ] + offset ) >> shiftNum ); |
---|
600 | pDstY[ x + 1 ] = Clip( ( pSrcY0[ x + 1 ] + pSrcY1[ x + 1 ] + offset ) >> shiftNum ); |
---|
601 | pDstY[ x + 2 ] = Clip( ( pSrcY0[ x + 2 ] + pSrcY1[ x + 2 ] + offset ) >> shiftNum ); |
---|
602 | pDstY[ x + 3 ] = Clip( ( pSrcY0[ x + 3 ] + pSrcY1[ x + 3 ] + offset ) >> shiftNum ); |
---|
603 | } |
---|
604 | pSrcY0 += iSrc0Stride; |
---|
605 | pSrcY1 += iSrc1Stride; |
---|
606 | pDstY += iDstStride; |
---|
607 | } |
---|
608 | |
---|
609 | iSrc0Stride = pcYuvSrc0->getCStride(); |
---|
610 | iSrc1Stride = pcYuvSrc1->getCStride(); |
---|
611 | iDstStride = getCStride(); |
---|
612 | |
---|
613 | iWidth >>=1; |
---|
614 | iHeight >>=1; |
---|
615 | |
---|
616 | for ( y = iHeight-1; y >= 0; y-- ) |
---|
617 | { |
---|
618 | for ( x = iWidth-1; x >= 0; ) |
---|
619 | { |
---|
620 | // note: chroma min width is 2 |
---|
621 | pDstU[x] = Clip((pSrcU0[x] + pSrcU1[x] + offset) >> shiftNum); |
---|
622 | pDstV[x] = Clip((pSrcV0[x] + pSrcV1[x] + offset) >> shiftNum); x--; |
---|
623 | pDstU[x] = Clip((pSrcU0[x] + pSrcU1[x] + offset) >> shiftNum); |
---|
624 | pDstV[x] = Clip((pSrcV0[x] + pSrcV1[x] + offset) >> shiftNum); x--; |
---|
625 | } |
---|
626 | |
---|
627 | pSrcU0 += iSrc0Stride; |
---|
628 | pSrcU1 += iSrc1Stride; |
---|
629 | pSrcV0 += iSrc0Stride; |
---|
630 | pSrcV1 += iSrc1Stride; |
---|
631 | pDstU += iDstStride; |
---|
632 | pDstV += iDstStride; |
---|
633 | } |
---|
634 | } |
---|
635 | |
---|
636 | Void TComYuv::removeHighFreq( TComYuv* pcYuvSrc, UInt uiPartIdx, UInt uiWidht, UInt uiHeight ) |
---|
637 | { |
---|
638 | Int x, y; |
---|
639 | |
---|
640 | Pel* pSrc = pcYuvSrc->getLumaAddr(uiPartIdx); |
---|
641 | Pel* pSrcU = pcYuvSrc->getCbAddr(uiPartIdx); |
---|
642 | Pel* pSrcV = pcYuvSrc->getCrAddr(uiPartIdx); |
---|
643 | |
---|
644 | Pel* pDst = getLumaAddr(uiPartIdx); |
---|
645 | Pel* pDstU = getCbAddr(uiPartIdx); |
---|
646 | Pel* pDstV = getCrAddr(uiPartIdx); |
---|
647 | |
---|
648 | Int iSrcStride = pcYuvSrc->getStride(); |
---|
649 | Int iDstStride = getStride(); |
---|
650 | |
---|
651 | for ( y = uiHeight-1; y >= 0; y-- ) |
---|
652 | { |
---|
653 | for ( x = uiWidht-1; x >= 0; x-- ) |
---|
654 | { |
---|
655 | #if DISABLING_CLIP_FOR_BIPREDME |
---|
656 | pDst[x ] = (pDst[x ]<<1) - pSrc[x ] ; |
---|
657 | #else |
---|
658 | pDst[x ] = Clip( (pDst[x ]<<1) - pSrc[x ] ); |
---|
659 | #endif |
---|
660 | } |
---|
661 | pSrc += iSrcStride; |
---|
662 | pDst += iDstStride; |
---|
663 | } |
---|
664 | |
---|
665 | iSrcStride = pcYuvSrc->getCStride(); |
---|
666 | iDstStride = getCStride(); |
---|
667 | |
---|
668 | uiHeight >>= 1; |
---|
669 | uiWidht >>= 1; |
---|
670 | |
---|
671 | for ( y = uiHeight-1; y >= 0; y-- ) |
---|
672 | { |
---|
673 | for ( x = uiWidht-1; x >= 0; x-- ) |
---|
674 | { |
---|
675 | #if DISABLING_CLIP_FOR_BIPREDME |
---|
676 | pDstU[x ] = (pDstU[x ]<<1) - pSrcU[x ] ; |
---|
677 | pDstV[x ] = (pDstV[x ]<<1) - pSrcV[x ] ; |
---|
678 | #else |
---|
679 | pDstU[x ] = Clip( (pDstU[x ]<<1) - pSrcU[x ] ); |
---|
680 | pDstV[x ] = Clip( (pDstV[x ]<<1) - pSrcV[x ] ); |
---|
681 | #endif |
---|
682 | } |
---|
683 | pSrcU += iSrcStride; |
---|
684 | pSrcV += iSrcStride; |
---|
685 | pDstU += iDstStride; |
---|
686 | pDstV += iDstStride; |
---|
687 | } |
---|
688 | } |
---|
689 | //! \} |
---|