[5] | 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 |
---|
[1200] | 4 | * granted under this license. |
---|
[5] | 5 | * |
---|
[1200] | 6 | * Copyright (c) 2010-2015, ITU/ISO/IEC |
---|
[5] | 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. |
---|
[56] | 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
[5] | 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 | */ |
---|
[2] | 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" |
---|
[56] | 46 | #include "TComInterpolationFilter.h" |
---|
[2] | 47 | |
---|
[56] | 48 | //! \ingroup TLibCommon |
---|
| 49 | //! \{ |
---|
| 50 | |
---|
[2] | 51 | TComYuv::TComYuv() |
---|
| 52 | { |
---|
[1200] | 53 | for(Int comp=0; comp<MAX_NUM_COMPONENT; comp++) |
---|
| 54 | { |
---|
| 55 | m_apiBuf[comp] = NULL; |
---|
| 56 | } |
---|
[2] | 57 | } |
---|
| 58 | |
---|
| 59 | TComYuv::~TComYuv() |
---|
| 60 | { |
---|
| 61 | } |
---|
| 62 | |
---|
[1200] | 63 | Void TComYuv::create( UInt iWidth, UInt iHeight, ChromaFormat chromaFormatIDC ) |
---|
[2] | 64 | { |
---|
| 65 | // set width and height |
---|
| 66 | m_iWidth = iWidth; |
---|
| 67 | m_iHeight = iHeight; |
---|
[1200] | 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 | } |
---|
[2] | 75 | } |
---|
| 76 | |
---|
| 77 | Void TComYuv::destroy() |
---|
| 78 | { |
---|
| 79 | // memory free |
---|
[1200] | 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 | } |
---|
[2] | 88 | } |
---|
| 89 | |
---|
| 90 | Void TComYuv::clear() |
---|
| 91 | { |
---|
[1200] | 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 | } |
---|
[2] | 99 | } |
---|
| 100 | |
---|
[1200] | 101 | |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | Void TComYuv::copyToPicYuv ( TComPicYuv* pcPicYuvDst, const UInt ctuRsAddr, const UInt uiAbsZorderIdx, const UInt uiPartDepth, const UInt uiPartIdx ) const |
---|
[2] | 105 | { |
---|
[1200] | 106 | for(Int comp=0; comp<getNumberValidComponents(); comp++) |
---|
| 107 | { |
---|
| 108 | copyToPicComponent ( ComponentID(comp), pcPicYuvDst, ctuRsAddr, uiAbsZorderIdx, uiPartDepth, uiPartIdx ); |
---|
| 109 | } |
---|
[2] | 110 | } |
---|
| 111 | |
---|
[1200] | 112 | Void TComYuv::copyToPicComponent ( const ComponentID compID, TComPicYuv* pcPicYuvDst, const UInt ctuRsAddr, const UInt uiAbsZorderIdx, const UInt uiPartDepth, const UInt uiPartIdx ) const |
---|
[2] | 113 | { |
---|
[1200] | 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-- ) |
---|
[2] | 124 | { |
---|
| 125 | ::memcpy( pDst, pSrc, sizeof(Pel)*iWidth); |
---|
[622] | 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 |
---|
[2] | 136 | pDst += iDstStride; |
---|
| 137 | pSrc += iSrcStride; |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | |
---|
[1200] | 141 | |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | Void TComYuv::copyFromPicYuv ( const TComPicYuv* pcPicYuvSrc, const UInt ctuRsAddr, const UInt uiAbsZorderIdx ) |
---|
[2] | 145 | { |
---|
[1200] | 146 | for(Int comp=0; comp<getNumberValidComponents(); comp++) |
---|
[2] | 147 | { |
---|
[1200] | 148 | copyFromPicComponent ( ComponentID(comp), pcPicYuvSrc, ctuRsAddr, uiAbsZorderIdx ); |
---|
[2] | 149 | } |
---|
| 150 | } |
---|
| 151 | |
---|
[1200] | 152 | Void TComYuv::copyFromPicComponent ( const ComponentID compID, const TComPicYuv* pcPicYuvSrc, const UInt ctuRsAddr, const UInt uiAbsZorderIdx ) |
---|
[2] | 153 | { |
---|
[1200] | 154 | Pel* pDst = getAddr(compID); |
---|
| 155 | const Pel* pSrc = pcPicYuvSrc->getAddr ( compID, ctuRsAddr, uiAbsZorderIdx ); |
---|
[2] | 156 | |
---|
[1200] | 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-- ) |
---|
[2] | 163 | { |
---|
[1200] | 164 | ::memcpy( pDst, pSrc, sizeof(Pel)*iWidth); |
---|
[2] | 165 | pDst += iDstStride; |
---|
| 166 | pSrc += iSrcStride; |
---|
| 167 | } |
---|
| 168 | } |
---|
| 169 | |
---|
[1200] | 170 | |
---|
| 171 | |
---|
| 172 | |
---|
| 173 | Void TComYuv::copyToPartYuv( TComYuv* pcYuvDst, const UInt uiDstPartIdx ) const |
---|
[2] | 174 | { |
---|
[1200] | 175 | for(Int comp=0; comp<getNumberValidComponents(); comp++) |
---|
[2] | 176 | { |
---|
[1200] | 177 | copyToPartComponent ( ComponentID(comp), pcYuvDst, uiDstPartIdx ); |
---|
[2] | 178 | } |
---|
| 179 | } |
---|
| 180 | |
---|
[1200] | 181 | Void TComYuv::copyToPartComponent( const ComponentID compID, TComYuv* pcYuvDst, const UInt uiDstPartIdx ) const |
---|
[2] | 182 | { |
---|
[1200] | 183 | const Pel* pSrc = getAddr(compID); |
---|
| 184 | Pel* pDst = pcYuvDst->getAddr( compID, uiDstPartIdx ); |
---|
[2] | 185 | |
---|
[1200] | 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-- ) |
---|
[2] | 192 | { |
---|
[1200] | 193 | ::memcpy( pDst, pSrc, sizeof(Pel)*iWidth); |
---|
[2] | 194 | pDst += iDstStride; |
---|
| 195 | pSrc += iSrcStride; |
---|
| 196 | } |
---|
| 197 | } |
---|
| 198 | |
---|
[1200] | 199 | |
---|
| 200 | |
---|
| 201 | |
---|
| 202 | Void TComYuv::copyPartToYuv( TComYuv* pcYuvDst, const UInt uiSrcPartIdx ) const |
---|
[2] | 203 | { |
---|
[1200] | 204 | for(Int comp=0; comp<getNumberValidComponents(); comp++) |
---|
[2] | 205 | { |
---|
[1200] | 206 | copyPartToComponent ( ComponentID(comp), pcYuvDst, uiSrcPartIdx ); |
---|
[2] | 207 | } |
---|
| 208 | } |
---|
| 209 | |
---|
[1200] | 210 | Void TComYuv::copyPartToComponent( const ComponentID compID, TComYuv* pcYuvDst, const UInt uiSrcPartIdx ) const |
---|
[2] | 211 | { |
---|
[1200] | 212 | const Pel* pSrc = getAddr(compID, uiSrcPartIdx); |
---|
| 213 | Pel* pDst = pcYuvDst->getAddr(compID, 0 ); |
---|
[2] | 214 | |
---|
[1200] | 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-- ) |
---|
[2] | 222 | { |
---|
| 223 | ::memcpy( pDst, pSrc, sizeof(Pel)*uiWidth); |
---|
| 224 | pDst += iDstStride; |
---|
| 225 | pSrc += iSrcStride; |
---|
| 226 | } |
---|
| 227 | } |
---|
| 228 | |
---|
[1200] | 229 | |
---|
| 230 | |
---|
| 231 | |
---|
| 232 | Void TComYuv::copyPartToPartYuv ( TComYuv* pcYuvDst, const UInt uiPartIdx, const UInt iWidth, const UInt iHeight ) const |
---|
[2] | 233 | { |
---|
[1200] | 234 | for(Int comp=0; comp<getNumberValidComponents(); comp++) |
---|
[2] | 235 | { |
---|
[1200] | 236 | copyPartToPartComponent (ComponentID(comp), pcYuvDst, uiPartIdx, iWidth>>getComponentScaleX(ComponentID(comp)), iHeight>>getComponentScaleY(ComponentID(comp)) ); |
---|
[2] | 237 | } |
---|
| 238 | } |
---|
| 239 | |
---|
[1200] | 240 | Void TComYuv::copyPartToPartComponent ( const ComponentID compID, TComYuv* pcYuvDst, const UInt uiPartIdx, const UInt iWidthComponent, const UInt iHeightComponent ) const |
---|
[2] | 241 | { |
---|
[1200] | 242 | const Pel* pSrc = getAddr(compID, uiPartIdx); |
---|
| 243 | Pel* pDst = pcYuvDst->getAddr(compID, uiPartIdx); |
---|
[2] | 244 | if( pSrc == pDst ) |
---|
| 245 | { |
---|
| 246 | //th not a good idea |
---|
[1200] | 247 | //th best would be to fix the caller |
---|
[2] | 248 | return ; |
---|
| 249 | } |
---|
[1200] | 250 | |
---|
| 251 | const UInt iSrcStride = getStride(compID); |
---|
| 252 | const UInt iDstStride = pcYuvDst->getStride(compID); |
---|
| 253 | for ( UInt y = iHeightComponent; y != 0; y-- ) |
---|
[2] | 254 | { |
---|
[1200] | 255 | ::memcpy( pDst, pSrc, iWidthComponent * sizeof(Pel) ); |
---|
[2] | 256 | pSrc += iSrcStride; |
---|
| 257 | pDst += iDstStride; |
---|
| 258 | } |
---|
| 259 | } |
---|
| 260 | |
---|
[1200] | 261 | |
---|
| 262 | |
---|
| 263 | |
---|
| 264 | Void TComYuv::copyPartToPartComponentMxN ( const ComponentID compID, TComYuv* pcYuvDst, const TComRectangle &rect) const |
---|
[2] | 265 | { |
---|
[1200] | 266 | const Pel* pSrc = getAddrPix( compID, rect.x0, rect.y0 ); |
---|
| 267 | Pel* pDst = pcYuvDst->getAddrPix( compID, rect.x0, rect.y0 ); |
---|
| 268 | if( pSrc == pDst ) |
---|
[2] | 269 | { |
---|
| 270 | //th not a good idea |
---|
[1200] | 271 | //th best would be to fix the caller |
---|
[2] | 272 | return ; |
---|
| 273 | } |
---|
[1200] | 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-- ) |
---|
[2] | 280 | { |
---|
[1200] | 281 | ::memcpy( pDst, pSrc, uiWidthComponent * sizeof( Pel ) ); |
---|
| 282 | pSrc += iSrcStride; |
---|
| 283 | pDst += iDstStride; |
---|
[2] | 284 | } |
---|
| 285 | } |
---|
| 286 | |
---|
[1200] | 287 | |
---|
| 288 | |
---|
| 289 | |
---|
| 290 | Void TComYuv::addClip( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt uiTrUnitIdx, const UInt uiPartSize, const BitDepths &clipBitDepths ) |
---|
[2] | 291 | { |
---|
[1200] | 292 | for(Int comp=0; comp<getNumberValidComponents(); comp++) |
---|
[2] | 293 | { |
---|
[1200] | 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-- ) |
---|
[2] | 311 | { |
---|
[1200] | 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; |
---|
[2] | 323 | } |
---|
| 324 | } |
---|
| 325 | } |
---|
| 326 | |
---|
| 327 | |
---|
[1200] | 328 | |
---|
| 329 | |
---|
| 330 | Void TComYuv::subtract( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt uiTrUnitIdx, const UInt uiPartSize ) |
---|
[2] | 331 | { |
---|
[1200] | 332 | for(Int comp=0; comp<getNumberValidComponents(); comp++) |
---|
[2] | 333 | { |
---|
[1200] | 334 | const ComponentID compID=ComponentID(comp); |
---|
| 335 | const Int uiPartWidth =uiPartSize>>getComponentScaleX(compID); |
---|
| 336 | const Int uiPartHeight=uiPartSize>>getComponentScaleY(compID); |
---|
[2] | 337 | |
---|
[1200] | 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-- ) |
---|
[2] | 347 | { |
---|
[1200] | 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; |
---|
[2] | 355 | } |
---|
| 356 | } |
---|
| 357 | } |
---|
| 358 | |
---|
| 359 | |
---|
[1200] | 360 | |
---|
| 361 | |
---|
| 362 | Void TComYuv::addAvg( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt iPartUnitIdx, const UInt uiWidth, const UInt uiHeight, const BitDepths &clipBitDepths ) |
---|
[2] | 363 | { |
---|
[1200] | 364 | for(Int comp=0; comp<getNumberValidComponents(); comp++) |
---|
[2] | 365 | { |
---|
[1200] | 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 ); |
---|
[2] | 370 | |
---|
[1200] | 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) |
---|
[2] | 382 | { |
---|
[1200] | 383 | assert(0); |
---|
| 384 | exit(-1); |
---|
[2] | 385 | } |
---|
[1200] | 386 | else if (iWidth&2) |
---|
[2] | 387 | { |
---|
[1200] | 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 | } |
---|
[2] | 399 | } |
---|
[1200] | 400 | else |
---|
[2] | 401 | { |
---|
[1200] | 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 | } |
---|
[2] | 415 | } |
---|
| 416 | } |
---|
| 417 | } |
---|
| 418 | |
---|
[1200] | 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 | ) |
---|
[2] | 426 | { |
---|
[1200] | 427 | for(Int comp=0; comp<getNumberValidComponents(); comp++) |
---|
[2] | 428 | { |
---|
[1200] | 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) |
---|
[2] | 438 | { |
---|
[1200] | 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 | } |
---|
[2] | 449 | } |
---|
[1200] | 450 | else |
---|
[2] | 451 | { |
---|
[1200] | 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 | } |
---|
[2] | 461 | } |
---|
| 462 | } |
---|
| 463 | } |
---|
[1200] | 464 | |
---|
| 465 | #if NH_3D_VSO |
---|
| 466 | Void TComYuv::addClipPartLuma( Int bitDepth, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ) |
---|
[443] | 467 | { |
---|
[608] | 468 | Int x, y; |
---|
| 469 | |
---|
[1200] | 470 | Pel* pSrc0 = pcYuvSrc0->getAddr( COMPONENT_Y, uiTrUnitIdx); |
---|
| 471 | Pel* pSrc1 = pcYuvSrc1->getAddr( COMPONENT_Y, uiTrUnitIdx); |
---|
| 472 | Pel* pDst = getAddr( COMPONENT_Y, uiTrUnitIdx); |
---|
[608] | 473 | |
---|
[1200] | 474 | UInt iSrc0Stride = pcYuvSrc0->getStride( COMPONENT_Y ); |
---|
| 475 | UInt iSrc1Stride = pcYuvSrc1->getStride( COMPONENT_Y ); |
---|
| 476 | UInt iDstStride = getStride( COMPONENT_Y ); |
---|
[608] | 477 | for ( y = uiPartSize-1; y >= 0; y-- ) |
---|
| 478 | { |
---|
| 479 | for ( x = uiPartSize-1; x >= 0; x-- ) |
---|
| 480 | { |
---|
[1200] | 481 | pDst[x] = ClipBD( pSrc0[x] + pSrc1[x], bitDepth ); |
---|
[608] | 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 | { |
---|
[443] | 492 | addARPLuma ( pcYuvSrc0, pcYuvSrc1, uiAbsPartIdx, uiWidth , uiHeight , bClip ); |
---|
| 493 | addARPChroma ( pcYuvSrc0, pcYuvSrc1, uiAbsPartIdx, uiWidth>>1, uiHeight>>1 , bClip ); |
---|
| 494 | } |
---|
| 495 | |
---|
[608] | 496 | Void TComYuv::addARPLuma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Bool bClip ) |
---|
[443] | 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(); |
---|
[1039] | 507 | Int iIFshift = IF_INTERNAL_PREC - g_bitDepthY; |
---|
| 508 | Int iOffSet = ( 1 << ( iIFshift - 1 ) ) + IF_INTERNAL_OFFS; |
---|
[443] | 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 ) |
---|
[608] | 515 | { |
---|
[1039] | 516 | pDst[x] = ClipY( ( pDst[x] + iOffSet ) >> iIFshift ); |
---|
[608] | 517 | } |
---|
[443] | 518 | } |
---|
| 519 | pSrc0 += iSrc0Stride; |
---|
| 520 | pSrc1 += iSrc1Stride; |
---|
| 521 | pDst += iDstStride; |
---|
| 522 | } |
---|
| 523 | } |
---|
| 524 | |
---|
[608] | 525 | Void TComYuv::addARPChroma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Bool bClip ) |
---|
[443] | 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(); |
---|
[1084] | 539 | |
---|
[1039] | 540 | Int iIFshift = IF_INTERNAL_PREC - g_bitDepthC; |
---|
| 541 | Int iOffSet = ( 1 << ( iIFshift - 1 ) ) + IF_INTERNAL_OFFS; |
---|
[1084] | 542 | |
---|
[443] | 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 | { |
---|
[1039] | 551 | pDstU[x] = ClipC( ( pDstU[x] + iOffSet ) >> iIFshift ); |
---|
| 552 | pDstV[x] = ClipC( ( pDstV[x] + iOffSet ) >> iIFshift ); |
---|
[443] | 553 | } |
---|
| 554 | } |
---|
| 555 | |
---|
| 556 | pSrcU0 += iSrc0Stride; |
---|
| 557 | pSrcU1 += iSrc1Stride; |
---|
| 558 | pSrcV0 += iSrc0Stride; |
---|
| 559 | pSrcV1 += iSrc1Stride; |
---|
| 560 | pDstU += iDstStride; |
---|
| 561 | pDstV += iDstStride; |
---|
| 562 | } |
---|
| 563 | } |
---|
| 564 | |
---|
[608] | 565 | Void TComYuv::subtractARP( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight ) |
---|
[443] | 566 | { |
---|
| 567 | subtractARPLuma ( pcYuvSrc0, pcYuvSrc1, uiAbsPartIdx, uiWidth , uiHeight ); |
---|
[1084] | 568 | |
---|
[1039] | 569 | if (uiWidth > 8) |
---|
[1084] | 570 | subtractARPChroma( pcYuvSrc0, pcYuvSrc1, uiAbsPartIdx, uiWidth>>1 , uiHeight>>1 ); |
---|
[443] | 571 | } |
---|
| 572 | |
---|
[608] | 573 | Void TComYuv::subtractARPLuma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight ) |
---|
[443] | 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 | |
---|
[608] | 596 | Void TComYuv::subtractARPChroma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight ) |
---|
[443] | 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 ); |
---|
[1084] | 629 | |
---|
[1039] | 630 | if (uiWidth > 8) |
---|
[1084] | 631 | multiplyARPChroma( uiAbsPartIdx , uiWidth >> 1 , uiHeight >> 1 , dW ); |
---|
[443] | 632 | } |
---|
| 633 | |
---|
[608] | 634 | Void TComYuv::xxMultiplyLine( Pel* pSrcDst , UInt uiWidth , UChar dW ) |
---|
[443] | 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 |
---|
[608] | 667 | #endif |
---|
[872] | 668 | |
---|
[56] | 669 | //! \} |
---|