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