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