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