Changeset 1029 in SHVCSoftware for branches/SHM-dev/source/Lib/TLibCommon/TComYuv.cpp
- Timestamp:
- 26 Feb 2015, 00:21:54 (10 years ago)
- Location:
- branches/SHM-dev
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SHM-dev
- Property svn:mergeinfo changed
-
branches/SHM-dev/source
- Property svn:mergeinfo changed
-
branches/SHM-dev/source/Lib/TLibCommon/TComYuv.cpp
r595 r1029 2 2 * License, included below. This software may be subject to other third party 3 3 * and contributor rights, including patent rights, and no such rights are 4 * granted under this license. 4 * granted under this license. 5 5 * 6 6 * Copyright (c) 2010-2014, ITU/ISO/IEC … … 51 51 TComYuv::TComYuv() 52 52 { 53 m_apiBufY = NULL; 54 m_apiBufU = NULL; 55 m_apiBufV = NULL; 53 for(Int comp=0; comp<MAX_NUM_COMPONENT; comp++) 54 { 55 m_apiBuf[comp] = NULL; 56 } 56 57 } 57 58 … … 60 61 } 61 62 62 Void TComYuv::create( UInt iWidth, UInt iHeight ) 63 { 64 // memory allocation 65 m_apiBufY = (Pel*)xMalloc( Pel, iWidth*iHeight ); 66 m_apiBufU = (Pel*)xMalloc( Pel, iWidth*iHeight >> 2 ); 67 m_apiBufV = (Pel*)xMalloc( Pel, iWidth*iHeight >> 2 ); 68 63 Void TComYuv::create( UInt iWidth, UInt iHeight, ChromaFormat chromaFormatIDC ) 64 { 69 65 // set width and height 70 66 m_iWidth = iWidth; 71 67 m_iHeight = iHeight; 72 m_iCWidth = iWidth >> 1; 73 m_iCHeight = iHeight >> 1; 68 m_chromaFormatIDC = chromaFormatIDC; 69 70 for(Int ch=0; ch<MAX_NUM_COMPONENT; ch++) 71 { 72 // memory allocation 73 m_apiBuf[ch] = (Pel*)xMalloc( Pel, getWidth(ComponentID(ch))*getHeight(ComponentID(ch)) ); 74 } 74 75 } 75 76 … … 77 78 { 78 79 // memory free 79 xFree( m_apiBufY ); m_apiBufY = NULL; 80 xFree( m_apiBufU ); m_apiBufU = NULL; 81 xFree( m_apiBufV ); m_apiBufV = NULL; 80 for(Int ch=0; ch<MAX_NUM_COMPONENT; ch++) 81 { 82 if (m_apiBuf[ch]!=NULL) { xFree( m_apiBuf[ch] ); m_apiBuf[ch] = NULL; } 83 } 82 84 } 83 85 84 86 Void TComYuv::clear() 85 87 { 86 ::memset( m_apiBufY, 0, ( m_iWidth * m_iHeight )*sizeof(Pel) ); 87 ::memset( m_apiBufU, 0, ( m_iCWidth * m_iCHeight )*sizeof(Pel) ); 88 ::memset( m_apiBufV, 0, ( m_iCWidth * m_iCHeight )*sizeof(Pel) ); 89 } 90 91 Void TComYuv::copyToPicYuv ( TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth, UInt uiPartIdx ) 92 { 93 copyToPicLuma ( pcPicYuvDst, iCuAddr, uiAbsZorderIdx, uiPartDepth, uiPartIdx ); 94 copyToPicChroma( pcPicYuvDst, iCuAddr, uiAbsZorderIdx, uiPartDepth, uiPartIdx ); 95 } 96 97 Void TComYuv::copyToPicLuma ( TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth, UInt uiPartIdx ) 98 { 99 Int y, iWidth, iHeight; 100 iWidth = m_iWidth >>uiPartDepth; 101 iHeight = m_iHeight>>uiPartDepth; 102 103 Pel* pSrc = getLumaAddr(uiPartIdx, iWidth); 104 Pel* pDst = pcPicYuvDst->getLumaAddr ( iCuAddr, uiAbsZorderIdx ); 105 106 UInt iSrcStride = getStride(); 107 UInt iDstStride = pcPicYuvDst->getStride(); 108 109 for ( y = iHeight; y != 0; y-- ) 88 for(Int ch=0; ch<MAX_NUM_COMPONENT; ch++) 89 { 90 if (m_apiBuf[ch]!=NULL) 91 ::memset( m_apiBuf[ch], 0, ( getWidth(ComponentID(ch)) * getHeight(ComponentID(ch)) )*sizeof(Pel) ); 92 } 93 } 94 95 96 97 98 Void TComYuv::copyToPicYuv ( TComPicYuv* pcPicYuvDst, const UInt ctuRsAddr, const UInt uiAbsZorderIdx, const UInt uiPartDepth, const UInt uiPartIdx ) const 99 { 100 for(Int ch=0; ch<getNumberValidComponents(); ch++) 101 copyToPicComponent ( ComponentID(ch), pcPicYuvDst, ctuRsAddr, uiAbsZorderIdx, uiPartDepth, uiPartIdx ); 102 } 103 104 Void TComYuv::copyToPicComponent ( const ComponentID ch, TComPicYuv* pcPicYuvDst, const UInt ctuRsAddr, const UInt uiAbsZorderIdx, const UInt uiPartDepth, const UInt uiPartIdx ) const 105 { 106 const Int iWidth = getWidth(ch) >>uiPartDepth; 107 const Int iHeight = getHeight(ch)>>uiPartDepth; 108 109 const Pel* pSrc = getAddr(ch, uiPartIdx, iWidth); 110 Pel* pDst = pcPicYuvDst->getAddr ( ch, ctuRsAddr, uiAbsZorderIdx ); 111 112 const UInt iSrcStride = getStride(ch); 113 const UInt iDstStride = pcPicYuvDst->getStride(ch); 114 115 for ( Int y = iHeight; y != 0; y-- ) 110 116 { 111 117 ::memcpy( pDst, pSrc, sizeof(Pel)*iWidth); … … 115 121 } 116 122 117 Void TComYuv::copyToPicChroma( TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth, UInt uiPartIdx ) 118 { 119 Int y, iWidth, iHeight; 120 iWidth = m_iCWidth >>uiPartDepth; 121 iHeight = m_iCHeight>>uiPartDepth; 122 123 Pel* pSrcU = getCbAddr(uiPartIdx, iWidth); 124 Pel* pSrcV = getCrAddr(uiPartIdx, iWidth); 125 Pel* pDstU = pcPicYuvDst->getCbAddr( iCuAddr, uiAbsZorderIdx ); 126 Pel* pDstV = pcPicYuvDst->getCrAddr( iCuAddr, uiAbsZorderIdx ); 127 128 UInt iSrcStride = getCStride(); 129 UInt iDstStride = pcPicYuvDst->getCStride(); 130 for ( y = iHeight; y != 0; y-- ) 131 { 132 ::memcpy( pDstU, pSrcU, sizeof(Pel)*(iWidth) ); 133 ::memcpy( pDstV, pSrcV, sizeof(Pel)*(iWidth) ); 134 pSrcU += iSrcStride; 135 pSrcV += iSrcStride; 136 pDstU += iDstStride; 137 pDstV += iDstStride; 138 } 139 } 140 141 Void TComYuv::copyFromPicYuv ( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiAbsZorderIdx ) 142 { 143 copyFromPicLuma ( pcPicYuvSrc, iCuAddr, uiAbsZorderIdx ); 144 copyFromPicChroma( pcPicYuvSrc, iCuAddr, uiAbsZorderIdx ); 145 } 146 147 Void TComYuv::copyFromPicLuma ( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiAbsZorderIdx ) 148 { 149 Int y; 150 151 Pel* pDst = m_apiBufY; 152 Pel* pSrc = pcPicYuvSrc->getLumaAddr ( iCuAddr, uiAbsZorderIdx ); 153 154 UInt iDstStride = getStride(); 155 UInt iSrcStride = pcPicYuvSrc->getStride(); 156 for ( y = m_iHeight; y != 0; y-- ) 157 { 158 ::memcpy( pDst, pSrc, sizeof(Pel)*m_iWidth); 159 pDst += iDstStride; 160 pSrc += iSrcStride; 161 } 162 } 163 164 Void TComYuv::copyFromPicChroma( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiAbsZorderIdx ) 165 { 166 Int y; 167 168 Pel* pDstU = m_apiBufU; 169 Pel* pDstV = m_apiBufV; 170 Pel* pSrcU = pcPicYuvSrc->getCbAddr( iCuAddr, uiAbsZorderIdx ); 171 Pel* pSrcV = pcPicYuvSrc->getCrAddr( iCuAddr, uiAbsZorderIdx ); 172 173 UInt iDstStride = getCStride(); 174 UInt iSrcStride = pcPicYuvSrc->getCStride(); 175 for ( y = m_iCHeight; y != 0; y-- ) 176 { 177 ::memcpy( pDstU, pSrcU, sizeof(Pel)*(m_iCWidth) ); 178 ::memcpy( pDstV, pSrcV, sizeof(Pel)*(m_iCWidth) ); 179 pSrcU += iSrcStride; 180 pSrcV += iSrcStride; 181 pDstU += iDstStride; 182 pDstV += iDstStride; 183 } 184 } 185 186 Void TComYuv::copyToPartYuv( TComYuv* pcYuvDst, UInt uiDstPartIdx ) 187 { 188 copyToPartLuma ( pcYuvDst, uiDstPartIdx ); 189 copyToPartChroma( pcYuvDst, uiDstPartIdx ); 190 } 191 192 Void TComYuv::copyToPartLuma( TComYuv* pcYuvDst, UInt uiDstPartIdx ) 193 { 194 Int y; 195 196 Pel* pSrc = m_apiBufY; 197 Pel* pDst = pcYuvDst->getLumaAddr( uiDstPartIdx ); 198 199 UInt iSrcStride = getStride(); 200 UInt iDstStride = pcYuvDst->getStride(); 201 for ( y = m_iHeight; y != 0; y-- ) 202 { 203 ::memcpy( pDst, pSrc, sizeof(Pel)*m_iWidth); 204 pDst += iDstStride; 205 pSrc += iSrcStride; 206 } 207 } 208 209 Void TComYuv::copyToPartChroma( TComYuv* pcYuvDst, UInt uiDstPartIdx ) 210 { 211 Int y; 212 213 Pel* pSrcU = m_apiBufU; 214 Pel* pSrcV = m_apiBufV; 215 Pel* pDstU = pcYuvDst->getCbAddr( uiDstPartIdx ); 216 Pel* pDstV = pcYuvDst->getCrAddr( uiDstPartIdx ); 217 218 UInt iSrcStride = getCStride(); 219 UInt iDstStride = pcYuvDst->getCStride(); 220 for ( y = m_iCHeight; y != 0; y-- ) 221 { 222 ::memcpy( pDstU, pSrcU, sizeof(Pel)*(m_iCWidth) ); 223 ::memcpy( pDstV, pSrcV, sizeof(Pel)*(m_iCWidth) ); 224 pSrcU += iSrcStride; 225 pSrcV += iSrcStride; 226 pDstU += iDstStride; 227 pDstV += iDstStride; 228 } 229 } 230 231 Void TComYuv::copyPartToYuv( TComYuv* pcYuvDst, UInt uiSrcPartIdx ) 232 { 233 copyPartToLuma ( pcYuvDst, uiSrcPartIdx ); 234 copyPartToChroma( pcYuvDst, uiSrcPartIdx ); 235 } 236 237 Void TComYuv::copyPartToLuma( TComYuv* pcYuvDst, UInt uiSrcPartIdx ) 238 { 239 Int y; 240 241 Pel* pSrc = getLumaAddr(uiSrcPartIdx); 242 Pel* pDst = pcYuvDst->getLumaAddr( 0 ); 243 244 UInt iSrcStride = getStride(); 245 UInt iDstStride = pcYuvDst->getStride(); 246 247 UInt uiHeight = pcYuvDst->getHeight(); 248 UInt uiWidth = pcYuvDst->getWidth(); 249 250 for ( y = uiHeight; y != 0; y-- ) 123 124 125 126 Void TComYuv::copyFromPicYuv ( const TComPicYuv* pcPicYuvSrc, const UInt ctuRsAddr, const UInt uiAbsZorderIdx ) 127 { 128 for(Int ch=0; ch<getNumberValidComponents(); ch++) 129 copyFromPicComponent ( ComponentID(ch), pcPicYuvSrc, ctuRsAddr, uiAbsZorderIdx ); 130 } 131 132 Void TComYuv::copyFromPicComponent ( const ComponentID ch, const TComPicYuv* pcPicYuvSrc, const UInt ctuRsAddr, const UInt uiAbsZorderIdx ) 133 { 134 Pel* pDst = getAddr(ch); 135 const Pel* pSrc = pcPicYuvSrc->getAddr ( ch, ctuRsAddr, uiAbsZorderIdx ); 136 137 const UInt iDstStride = getStride(ch); 138 const UInt iSrcStride = pcPicYuvSrc->getStride(ch); 139 const Int iWidth=getWidth(ch); 140 const Int iHeight=getHeight(ch); 141 142 for (Int y = iHeight; y != 0; y-- ) 143 { 144 ::memcpy( pDst, pSrc, sizeof(Pel)*iWidth); 145 pDst += iDstStride; 146 pSrc += iSrcStride; 147 } 148 } 149 150 151 152 153 Void TComYuv::copyToPartYuv( TComYuv* pcYuvDst, const UInt uiDstPartIdx ) const 154 { 155 for(Int ch=0; ch<getNumberValidComponents(); ch++) 156 copyToPartComponent ( ComponentID(ch), pcYuvDst, uiDstPartIdx ); 157 } 158 159 Void TComYuv::copyToPartComponent( const ComponentID ch, TComYuv* pcYuvDst, const UInt uiDstPartIdx ) const 160 { 161 const Pel* pSrc = getAddr(ch); 162 Pel* pDst = pcYuvDst->getAddr( ch, uiDstPartIdx ); 163 164 const UInt iSrcStride = getStride(ch); 165 const UInt iDstStride = pcYuvDst->getStride(ch); 166 const Int iWidth=getWidth(ch); 167 const Int iHeight=getHeight(ch); 168 169 for (Int y = iHeight; y != 0; y-- ) 170 { 171 ::memcpy( pDst, pSrc, sizeof(Pel)*iWidth); 172 pDst += iDstStride; 173 pSrc += iSrcStride; 174 } 175 } 176 177 178 179 180 Void TComYuv::copyPartToYuv( TComYuv* pcYuvDst, const UInt uiSrcPartIdx ) const 181 { 182 for(Int ch=0; ch<getNumberValidComponents(); ch++) 183 copyPartToComponent ( ComponentID(ch), pcYuvDst, uiSrcPartIdx ); 184 } 185 186 Void TComYuv::copyPartToComponent( const ComponentID ch, TComYuv* pcYuvDst, const UInt uiSrcPartIdx ) const 187 { 188 const Pel* pSrc = getAddr(ch, uiSrcPartIdx); 189 Pel* pDst = pcYuvDst->getAddr(ch, 0 ); 190 191 const UInt iSrcStride = getStride(ch); 192 const UInt iDstStride = pcYuvDst->getStride(ch); 193 194 const UInt uiHeight = pcYuvDst->getHeight(ch); 195 const UInt uiWidth = pcYuvDst->getWidth(ch); 196 197 for ( UInt y = uiHeight; y != 0; y-- ) 251 198 { 252 199 ::memcpy( pDst, pSrc, sizeof(Pel)*uiWidth); … … 256 203 } 257 204 258 Void TComYuv::copyPartToChroma( TComYuv* pcYuvDst, UInt uiSrcPartIdx ) 259 { 260 Int y; 261 262 Pel* pSrcU = getCbAddr( uiSrcPartIdx ); 263 Pel* pSrcV = getCrAddr( uiSrcPartIdx ); 264 Pel* pDstU = pcYuvDst->getCbAddr( 0 ); 265 Pel* pDstV = pcYuvDst->getCrAddr( 0 ); 266 267 UInt iSrcStride = getCStride(); 268 UInt iDstStride = pcYuvDst->getCStride(); 269 270 UInt uiCHeight = pcYuvDst->getCHeight(); 271 UInt uiCWidth = pcYuvDst->getCWidth(); 272 273 for ( y = uiCHeight; y != 0; y-- ) 274 { 275 ::memcpy( pDstU, pSrcU, sizeof(Pel)*(uiCWidth) ); 276 ::memcpy( pDstV, pSrcV, sizeof(Pel)*(uiCWidth) ); 277 pSrcU += iSrcStride; 278 pSrcV += iSrcStride; 279 pDstU += iDstStride; 280 pDstV += iDstStride; 281 } 282 } 283 284 Void TComYuv::copyPartToPartYuv ( TComYuv* pcYuvDst, UInt uiPartIdx, UInt iWidth, UInt iHeight ) 285 { 286 copyPartToPartLuma (pcYuvDst, uiPartIdx, iWidth, iHeight ); 287 copyPartToPartChroma (pcYuvDst, uiPartIdx, iWidth>>1, iHeight>>1 ); 288 } 289 290 Void TComYuv::copyPartToPartLuma ( TComYuv* pcYuvDst, UInt uiPartIdx, UInt iWidth, UInt iHeight ) 291 { 292 Pel* pSrc = getLumaAddr(uiPartIdx); 293 Pel* pDst = pcYuvDst->getLumaAddr(uiPartIdx); 205 206 207 208 Void TComYuv::copyPartToPartYuv ( TComYuv* pcYuvDst, const UInt uiPartIdx, const UInt iWidth, const UInt iHeight ) const 209 { 210 for(Int ch=0; ch<getNumberValidComponents(); ch++) 211 copyPartToPartComponent (ComponentID(ch), pcYuvDst, uiPartIdx, iWidth>>getComponentScaleX(ComponentID(ch)), iHeight>>getComponentScaleY(ComponentID(ch)) ); 212 } 213 214 Void TComYuv::copyPartToPartComponent ( const ComponentID ch, TComYuv* pcYuvDst, const UInt uiPartIdx, const UInt iWidthComponent, const UInt iHeightComponent ) const 215 { 216 const Pel* pSrc = getAddr(ch, uiPartIdx); 217 Pel* pDst = pcYuvDst->getAddr(ch, uiPartIdx); 294 218 if( pSrc == pDst ) 295 219 { 296 220 //th not a good idea 297 //th best would be to fix the caller 221 //th best would be to fix the caller 298 222 return ; 299 223 } 300 301 UInt iSrcStride = getStride();302 UInt iDstStride = pcYuvDst->getStride();303 for ( UInt y = iHeight ; y != 0; y-- )304 { 305 ::memcpy( pDst, pSrc, iWidth * sizeof(Pel) );306 pSrc += iSrcStride; 307 pDst += iDstStride; 308 } 309 } 310 311 Void TComYuv::copyPartToPartChroma( TComYuv* pcYuvDst, UInt uiPartIdx, UInt iWidth, UInt iHeight ) 312 { 313 Pel* pSrcU = getCbAddr(uiPartIdx); 314 Pel* pSrcV = getCrAddr(uiPartIdx); 315 Pel* pDstU = pcYuvDst->getCbAddr(uiPartIdx); 316 Pel* pDstV = pcYuvDst->getCrAddr(uiPartIdx);317 318 if( pSrc U == pDstU && pSrcV == pDstV)224 225 const UInt iSrcStride = getStride(ch); 226 const UInt iDstStride = pcYuvDst->getStride(ch); 227 for ( UInt y = iHeightComponent; y != 0; y-- ) 228 { 229 ::memcpy( pDst, pSrc, iWidthComponent * sizeof(Pel) ); 230 pSrc += iSrcStride; 231 pDst += iDstStride; 232 } 233 } 234 235 236 237 238 Void TComYuv::copyPartToPartComponentMxN ( const ComponentID ch, TComYuv* pcYuvDst, const TComRectangle &rect) const 239 { 240 const Pel* pSrc = getAddrPix( ch, rect.x0, rect.y0 ); 241 Pel* pDst = pcYuvDst->getAddrPix( ch, rect.x0, rect.y0 ); 242 if( pSrc == pDst ) 319 243 { 320 244 //th not a good idea 321 //th best would be to fix the caller 245 //th best would be to fix the caller 322 246 return ; 323 247 } 324 325 UInt iSrcStride = getCStride(); 326 UInt iDstStride = pcYuvDst->getCStride(); 327 for ( UInt y = iHeight; y != 0; y-- ) 328 { 329 ::memcpy( pDstU, pSrcU, iWidth * sizeof(Pel) ); 330 ::memcpy( pDstV, pSrcV, iWidth * sizeof(Pel) ); 331 pSrcU += iSrcStride; 332 pSrcV += iSrcStride; 333 pDstU += iDstStride; 334 pDstV += iDstStride; 335 } 336 } 337 338 Void TComYuv::copyPartToPartChroma( TComYuv* pcYuvDst, UInt uiPartIdx, UInt iWidth, UInt iHeight, UInt chromaId) 339 { 340 if(chromaId == 0) 341 { 342 Pel* pSrcU = getCbAddr(uiPartIdx); 343 Pel* pDstU = pcYuvDst->getCbAddr(uiPartIdx); 344 if( pSrcU == pDstU) 345 { 346 return ; 347 } 348 UInt iSrcStride = getCStride(); 349 UInt iDstStride = pcYuvDst->getCStride(); 350 for ( UInt y = iHeight; y != 0; y-- ) 351 { 352 ::memcpy( pDstU, pSrcU, iWidth * sizeof(Pel) ); 353 pSrcU += iSrcStride; 354 pDstU += iDstStride; 355 } 356 } 357 else if (chromaId == 1) 358 { 359 Pel* pSrcV = getCrAddr(uiPartIdx); 360 Pel* pDstV = pcYuvDst->getCrAddr(uiPartIdx); 361 if( pSrcV == pDstV) 362 { 363 return; 364 } 365 UInt iSrcStride = getCStride(); 366 UInt iDstStride = pcYuvDst->getCStride(); 367 for ( UInt y = iHeight; y != 0; y-- ) 368 { 369 ::memcpy( pDstV, pSrcV, iWidth * sizeof(Pel) ); 370 pSrcV += iSrcStride; 371 pDstV += iDstStride; 372 } 373 } 374 else 375 { 376 Pel* pSrcU = getCbAddr(uiPartIdx); 377 Pel* pSrcV = getCrAddr(uiPartIdx); 378 Pel* pDstU = pcYuvDst->getCbAddr(uiPartIdx); 379 Pel* pDstV = pcYuvDst->getCrAddr(uiPartIdx); 380 381 if( pSrcU == pDstU && pSrcV == pDstV) 382 { 383 //th not a good idea 384 //th best would be to fix the caller 385 return ; 386 } 387 UInt iSrcStride = getCStride(); 388 UInt iDstStride = pcYuvDst->getCStride(); 389 for ( UInt y = iHeight; y != 0; y-- ) 390 { 391 ::memcpy( pDstU, pSrcU, iWidth * sizeof(Pel) ); 392 ::memcpy( pDstV, pSrcV, iWidth * sizeof(Pel) ); 393 pSrcU += iSrcStride; 394 pSrcV += iSrcStride; 395 pDstU += iDstStride; 396 pDstV += iDstStride; 397 } 398 } 399 } 400 401 Void TComYuv::addClip( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ) 402 { 403 addClipLuma ( pcYuvSrc0, pcYuvSrc1, uiTrUnitIdx, uiPartSize ); 404 addClipChroma ( pcYuvSrc0, pcYuvSrc1, uiTrUnitIdx, uiPartSize>>1 ); 405 } 406 407 Void TComYuv::addClipLuma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ) 408 { 409 Int x, y; 410 411 Pel* pSrc0 = pcYuvSrc0->getLumaAddr( uiTrUnitIdx, uiPartSize ); 412 Pel* pSrc1 = pcYuvSrc1->getLumaAddr( uiTrUnitIdx, uiPartSize ); 413 Pel* pDst = getLumaAddr( uiTrUnitIdx, uiPartSize ); 414 415 UInt iSrc0Stride = pcYuvSrc0->getStride(); 416 UInt iSrc1Stride = pcYuvSrc1->getStride(); 417 UInt iDstStride = getStride(); 418 for ( y = uiPartSize-1; y >= 0; y-- ) 419 { 420 for ( x = uiPartSize-1; x >= 0; x-- ) 421 { 422 pDst[x] = ClipY( pSrc0[x] + pSrc1[x] ); 423 } 424 pSrc0 += iSrc0Stride; 425 pSrc1 += iSrc1Stride; 426 pDst += iDstStride; 427 } 428 } 429 430 Void TComYuv::addClipChroma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ) 431 { 432 Int x, y; 433 434 Pel* pSrcU0 = pcYuvSrc0->getCbAddr( uiTrUnitIdx, uiPartSize ); 435 Pel* pSrcU1 = pcYuvSrc1->getCbAddr( uiTrUnitIdx, uiPartSize ); 436 Pel* pSrcV0 = pcYuvSrc0->getCrAddr( uiTrUnitIdx, uiPartSize ); 437 Pel* pSrcV1 = pcYuvSrc1->getCrAddr( uiTrUnitIdx, uiPartSize ); 438 Pel* pDstU = getCbAddr( uiTrUnitIdx, uiPartSize ); 439 Pel* pDstV = getCrAddr( uiTrUnitIdx, uiPartSize ); 440 441 UInt iSrc0Stride = pcYuvSrc0->getCStride(); 442 UInt iSrc1Stride = pcYuvSrc1->getCStride(); 443 UInt iDstStride = getCStride(); 444 for ( y = uiPartSize-1; y >= 0; y-- ) 445 { 446 for ( x = uiPartSize-1; x >= 0; x-- ) 447 { 448 pDstU[x] = ClipC( pSrcU0[x] + pSrcU1[x] ); 449 pDstV[x] = ClipC( pSrcV0[x] + pSrcV1[x] ); 450 } 451 452 pSrcU0 += iSrc0Stride; 453 pSrcU1 += iSrc1Stride; 454 pSrcV0 += iSrc0Stride; 455 pSrcV1 += iSrc1Stride; 456 pDstU += iDstStride; 457 pDstV += iDstStride; 458 } 459 } 460 461 Void TComYuv::subtract( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ) 462 { 463 subtractLuma ( pcYuvSrc0, pcYuvSrc1, uiTrUnitIdx, uiPartSize ); 464 subtractChroma( pcYuvSrc0, pcYuvSrc1, uiTrUnitIdx, uiPartSize>>1 ); 465 } 466 467 Void TComYuv::subtractLuma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ) 468 { 469 Int x, y; 470 471 Pel* pSrc0 = pcYuvSrc0->getLumaAddr( uiTrUnitIdx, uiPartSize ); 472 Pel* pSrc1 = pcYuvSrc1->getLumaAddr( uiTrUnitIdx, uiPartSize ); 473 Pel* pDst = getLumaAddr( uiTrUnitIdx, uiPartSize ); 474 475 Int iSrc0Stride = pcYuvSrc0->getStride(); 476 Int iSrc1Stride = pcYuvSrc1->getStride(); 477 Int iDstStride = getStride(); 478 for ( y = uiPartSize-1; y >= 0; y-- ) 479 { 480 for ( x = uiPartSize-1; x >= 0; x-- ) 481 { 482 pDst[x] = pSrc0[x] - pSrc1[x]; 483 } 484 pSrc0 += iSrc0Stride; 485 pSrc1 += iSrc1Stride; 486 pDst += iDstStride; 487 } 488 } 489 490 Void TComYuv::subtractChroma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ) 491 { 492 Int x, y; 493 494 Pel* pSrcU0 = pcYuvSrc0->getCbAddr( uiTrUnitIdx, uiPartSize ); 495 Pel* pSrcU1 = pcYuvSrc1->getCbAddr( uiTrUnitIdx, uiPartSize ); 496 Pel* pSrcV0 = pcYuvSrc0->getCrAddr( uiTrUnitIdx, uiPartSize ); 497 Pel* pSrcV1 = pcYuvSrc1->getCrAddr( uiTrUnitIdx, uiPartSize ); 498 Pel* pDstU = getCbAddr( uiTrUnitIdx, uiPartSize ); 499 Pel* pDstV = getCrAddr( uiTrUnitIdx, uiPartSize ); 500 501 Int iSrc0Stride = pcYuvSrc0->getCStride(); 502 Int iSrc1Stride = pcYuvSrc1->getCStride(); 503 Int iDstStride = getCStride(); 504 for ( y = uiPartSize-1; y >= 0; y-- ) 505 { 506 for ( x = uiPartSize-1; x >= 0; x-- ) 507 { 508 pDstU[x] = pSrcU0[x] - pSrcU1[x]; 509 pDstV[x] = pSrcV0[x] - pSrcV1[x]; 510 } 511 pSrcU0 += iSrc0Stride; 512 pSrcU1 += iSrc1Stride; 513 pSrcV0 += iSrc0Stride; 514 pSrcV1 += iSrc1Stride; 515 pDstU += iDstStride; 516 pDstV += iDstStride; 517 } 518 } 519 520 Void TComYuv::addAvg( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt iPartUnitIdx, UInt iWidth, UInt iHeight ) 521 { 522 Int x, y; 523 524 Pel* pSrcY0 = pcYuvSrc0->getLumaAddr( iPartUnitIdx ); 525 Pel* pSrcU0 = pcYuvSrc0->getCbAddr ( iPartUnitIdx ); 526 Pel* pSrcV0 = pcYuvSrc0->getCrAddr ( iPartUnitIdx ); 527 528 Pel* pSrcY1 = pcYuvSrc1->getLumaAddr( iPartUnitIdx ); 529 Pel* pSrcU1 = pcYuvSrc1->getCbAddr ( iPartUnitIdx ); 530 Pel* pSrcV1 = pcYuvSrc1->getCrAddr ( iPartUnitIdx ); 531 532 Pel* pDstY = getLumaAddr( iPartUnitIdx ); 533 Pel* pDstU = getCbAddr ( iPartUnitIdx ); 534 Pel* pDstV = getCrAddr ( iPartUnitIdx ); 535 536 UInt iSrc0Stride = pcYuvSrc0->getStride(); 537 UInt iSrc1Stride = pcYuvSrc1->getStride(); 538 UInt iDstStride = getStride(); 539 Int shiftNum = IF_INTERNAL_PREC + 1 - g_bitDepthY; 540 Int offset = ( 1 << ( shiftNum - 1 ) ) + 2 * IF_INTERNAL_OFFS; 541 542 for ( y = 0; y < iHeight; y++ ) 543 { 544 for ( x = 0; x < iWidth; x += 4 ) 545 { 546 pDstY[ x + 0 ] = ClipY( ( pSrcY0[ x + 0 ] + pSrcY1[ x + 0 ] + offset ) >> shiftNum ); 547 pDstY[ x + 1 ] = ClipY( ( pSrcY0[ x + 1 ] + pSrcY1[ x + 1 ] + offset ) >> shiftNum ); 548 pDstY[ x + 2 ] = ClipY( ( pSrcY0[ x + 2 ] + pSrcY1[ x + 2 ] + offset ) >> shiftNum ); 549 pDstY[ x + 3 ] = ClipY( ( pSrcY0[ x + 3 ] + pSrcY1[ x + 3 ] + offset ) >> shiftNum ); 550 } 551 pSrcY0 += iSrc0Stride; 552 pSrcY1 += iSrc1Stride; 553 pDstY += iDstStride; 554 } 555 556 shiftNum = IF_INTERNAL_PREC + 1 - g_bitDepthC; 557 offset = ( 1 << ( shiftNum - 1 ) ) + 2 * IF_INTERNAL_OFFS; 558 559 iSrc0Stride = pcYuvSrc0->getCStride(); 560 iSrc1Stride = pcYuvSrc1->getCStride(); 561 iDstStride = getCStride(); 562 563 iWidth >>=1; 564 iHeight >>=1; 565 566 for ( y = iHeight-1; y >= 0; y-- ) 567 { 568 for ( x = iWidth-1; x >= 0; ) 569 { 570 // note: chroma min width is 2 571 pDstU[x] = ClipC((pSrcU0[x] + pSrcU1[x] + offset) >> shiftNum); 572 pDstV[x] = ClipC((pSrcV0[x] + pSrcV1[x] + offset) >> shiftNum); x--; 573 pDstU[x] = ClipC((pSrcU0[x] + pSrcU1[x] + offset) >> shiftNum); 574 pDstV[x] = ClipC((pSrcV0[x] + pSrcV1[x] + offset) >> shiftNum); x--; 575 } 576 577 pSrcU0 += iSrc0Stride; 578 pSrcU1 += iSrc1Stride; 579 pSrcV0 += iSrc0Stride; 580 pSrcV1 += iSrc1Stride; 581 pDstU += iDstStride; 582 pDstV += iDstStride; 583 } 584 } 585 586 Void TComYuv::removeHighFreq( TComYuv* pcYuvSrc, UInt uiPartIdx, UInt uiWidht, UInt uiHeight ) 587 { 588 Int x, y; 589 590 Pel* pSrc = pcYuvSrc->getLumaAddr(uiPartIdx); 591 Pel* pSrcU = pcYuvSrc->getCbAddr(uiPartIdx); 592 Pel* pSrcV = pcYuvSrc->getCrAddr(uiPartIdx); 593 594 Pel* pDst = getLumaAddr(uiPartIdx); 595 Pel* pDstU = getCbAddr(uiPartIdx); 596 Pel* pDstV = getCrAddr(uiPartIdx); 597 598 Int iSrcStride = pcYuvSrc->getStride(); 599 Int iDstStride = getStride(); 600 601 for ( y = uiHeight-1; y >= 0; y-- ) 602 { 603 for ( x = uiWidht-1; x >= 0; x-- ) 604 { 248 249 const UInt iSrcStride = getStride(ch); 250 const UInt iDstStride = pcYuvDst->getStride(ch); 251 const UInt uiHeightComponent=rect.height; 252 const UInt uiWidthComponent=rect.width; 253 for ( UInt y = uiHeightComponent; y != 0; y-- ) 254 { 255 ::memcpy( pDst, pSrc, uiWidthComponent * sizeof( Pel ) ); 256 pSrc += iSrcStride; 257 pDst += iDstStride; 258 } 259 } 260 261 262 263 264 Void TComYuv::addClip( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt uiTrUnitIdx, const UInt uiPartSize ) 265 { 266 for(Int chan=0; chan<getNumberValidComponents(); chan++) 267 { 268 const ComponentID ch=ComponentID(chan); 269 const Int uiPartWidth =uiPartSize>>getComponentScaleX(ch); 270 const Int uiPartHeight=uiPartSize>>getComponentScaleY(ch); 271 272 const Pel* pSrc0 = pcYuvSrc0->getAddr(ch, uiTrUnitIdx, uiPartWidth ); 273 const Pel* pSrc1 = pcYuvSrc1->getAddr(ch, uiTrUnitIdx, uiPartWidth ); 274 Pel* pDst = getAddr(ch, uiTrUnitIdx, uiPartWidth ); 275 276 const UInt iSrc0Stride = pcYuvSrc0->getStride(ch); 277 const UInt iSrc1Stride = pcYuvSrc1->getStride(ch); 278 const UInt iDstStride = getStride(ch); 279 const Int clipbd = g_bitDepth[toChannelType(ch)]; 280 #if O0043_BEST_EFFORT_DECODING 281 const Int bitDepthDelta = g_bitDepthInStream[toChannelType(ch)] - g_bitDepth[toChannelType(ch)]; 282 #endif 283 284 for ( Int y = uiPartHeight-1; y >= 0; y-- ) 285 { 286 for ( Int x = uiPartWidth-1; x >= 0; x-- ) 287 { 288 #if O0043_BEST_EFFORT_DECODING 289 pDst[x] = Pel(ClipBD<Int>( Int(pSrc0[x]) + rightShiftEvenRounding<Pel>(pSrc1[x], bitDepthDelta), clipbd)); 290 #else 291 pDst[x] = Pel(ClipBD<Int>( Int(pSrc0[x]) + Int(pSrc1[x]), clipbd)); 292 #endif 293 } 294 pSrc0 += iSrc0Stride; 295 pSrc1 += iSrc1Stride; 296 pDst += iDstStride; 297 } 298 } 299 } 300 301 302 303 304 Void TComYuv::subtract( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt uiTrUnitIdx, const UInt uiPartSize ) 305 { 306 for(Int chan=0; chan<getNumberValidComponents(); chan++) 307 { 308 const ComponentID ch=ComponentID(chan); 309 const Int uiPartWidth =uiPartSize>>getComponentScaleX(ch); 310 const Int uiPartHeight=uiPartSize>>getComponentScaleY(ch); 311 312 const Pel* pSrc0 = pcYuvSrc0->getAddr( ch, uiTrUnitIdx, uiPartWidth ); 313 const Pel* pSrc1 = pcYuvSrc1->getAddr( ch, uiTrUnitIdx, uiPartWidth ); 314 Pel* pDst = getAddr( ch, uiTrUnitIdx, uiPartWidth ); 315 316 const Int iSrc0Stride = pcYuvSrc0->getStride(ch); 317 const Int iSrc1Stride = pcYuvSrc1->getStride(ch); 318 const Int iDstStride = getStride(ch); 319 320 for (Int y = uiPartHeight-1; y >= 0; y-- ) 321 { 322 for (Int x = uiPartWidth-1; x >= 0; x-- ) 323 { 324 pDst[x] = pSrc0[x] - pSrc1[x]; 325 } 326 pSrc0 += iSrc0Stride; 327 pSrc1 += iSrc1Stride; 328 pDst += iDstStride; 329 } 330 } 331 } 332 333 334 335 336 Void TComYuv::addAvg( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt iPartUnitIdx, const UInt uiWidth, const UInt uiHeight ) 337 { 338 for(Int chan=0; chan<getNumberValidComponents(); chan++) 339 { 340 const ComponentID ch=ComponentID(chan); 341 const Pel* pSrc0 = pcYuvSrc0->getAddr( ch, iPartUnitIdx ); 342 const Pel* pSrc1 = pcYuvSrc1->getAddr( ch, iPartUnitIdx ); 343 Pel* pDst = getAddr( ch, iPartUnitIdx ); 344 345 const UInt iSrc0Stride = pcYuvSrc0->getStride(ch); 346 const UInt iSrc1Stride = pcYuvSrc1->getStride(ch); 347 const UInt iDstStride = getStride(ch); 348 const Int clipbd = g_bitDepth[toChannelType(ch)]; 349 const Int shiftNum = std::max<Int>(2, (IF_INTERNAL_PREC - clipbd)) + 1; 350 const Int offset = ( 1 << ( shiftNum - 1 ) ) + 2 * IF_INTERNAL_OFFS; 351 352 const Int iWidth = uiWidth >> getComponentScaleX(ch); 353 const Int iHeight = uiHeight >> getComponentScaleY(ch); 354 355 if (iWidth&1) 356 { 357 assert(0); 358 exit(-1); 359 } 360 else if (iWidth&2) 361 { 362 for ( Int y = 0; y < iHeight; y++ ) 363 { 364 for (Int x=0 ; x < iWidth; x+=2 ) 365 { 366 pDst[ x + 0 ] = ClipBD( rightShift(( pSrc0[ x + 0 ] + pSrc1[ x + 0 ] + offset ), shiftNum), clipbd ); 367 pDst[ x + 1 ] = ClipBD( rightShift(( pSrc0[ x + 1 ] + pSrc1[ x + 1 ] + offset ), shiftNum), clipbd ); 368 } 369 pSrc0 += iSrc0Stride; 370 pSrc1 += iSrc1Stride; 371 pDst += iDstStride; 372 } 373 } 374 else 375 { 376 for ( Int y = 0; y < iHeight; y++ ) 377 { 378 for (Int x=0 ; x < iWidth; x+=4 ) 379 { 380 pDst[ x + 0 ] = ClipBD( rightShift(( pSrc0[ x + 0 ] + pSrc1[ x + 0 ] + offset ), shiftNum), clipbd ); 381 pDst[ x + 1 ] = ClipBD( rightShift(( pSrc0[ x + 1 ] + pSrc1[ x + 1 ] + offset ), shiftNum), clipbd ); 382 pDst[ x + 2 ] = ClipBD( rightShift(( pSrc0[ x + 2 ] + pSrc1[ x + 2 ] + offset ), shiftNum), clipbd ); 383 pDst[ x + 3 ] = ClipBD( rightShift(( pSrc0[ x + 3 ] + pSrc1[ x + 3 ] + offset ), shiftNum), clipbd ); 384 } 385 pSrc0 += iSrc0Stride; 386 pSrc1 += iSrc1Stride; 387 pDst += iDstStride; 388 } 389 } 390 } 391 } 392 393 Void TComYuv::removeHighFreq( const TComYuv* pcYuvSrc, const UInt uiPartIdx, const UInt uiWidth, UInt const uiHeight ) 394 { 395 for(Int chan=0; chan<getNumberValidComponents(); chan++) 396 { 397 const ComponentID ch=ComponentID(chan); 398 #if !DISABLING_CLIP_FOR_BIPREDME 399 const ChannelType chType=toChannelType(ch); 400 #endif 401 402 const Pel* pSrc = pcYuvSrc->getAddr(ch, uiPartIdx); 403 Pel* pDst = getAddr(ch, uiPartIdx); 404 405 const Int iSrcStride = pcYuvSrc->getStride(ch); 406 const Int iDstStride = getStride(ch); 407 const Int iWidth = uiWidth >>getComponentScaleX(ch); 408 const Int iHeight = uiHeight>>getComponentScaleY(ch); 409 410 for ( Int y = iHeight-1; y >= 0; y-- ) 411 { 412 for ( Int x = iWidth-1; x >= 0; x-- ) 413 { 605 414 #if DISABLING_CLIP_FOR_BIPREDME 606 pDst[x ] = 2 * pDst[x]- pSrc[x];415 pDst[x ] = (2 * pDst[x]) - pSrc[x]; 607 416 #else 608 pDst[x ] = ClipY(2 * pDst[x] - pSrc[x]);417 pDst[x ] = Clip((2 * pDst[x]) - pSrc[x], chType); 609 418 #endif 610 } 611 pSrc += iSrcStride; 612 pDst += iDstStride; 613 } 614 615 iSrcStride = pcYuvSrc->getCStride(); 616 iDstStride = getCStride(); 617 618 uiHeight >>= 1; 619 uiWidht >>= 1; 620 621 for ( y = uiHeight-1; y >= 0; y-- ) 622 { 623 for ( x = uiWidht-1; x >= 0; x-- ) 624 { 625 #if DISABLING_CLIP_FOR_BIPREDME 626 pDstU[x ] = 2 * pDstU[x] - pSrcU[x]; 627 pDstV[x ] = 2 * pDstV[x] - pSrcV[x]; 628 #else 629 pDstU[x ] = ClipC(2 * pDstU[x] - pSrcU[x]); 630 pDstV[x ] = ClipC(2 * pDstV[x] - pSrcV[x]); 631 #endif 632 } 633 pSrcU += iSrcStride; 634 pSrcV += iSrcStride; 635 pDstU += iDstStride; 636 pDstV += iDstStride; 637 } 638 } 419 } 420 pSrc += iSrcStride; 421 pDst += iDstStride; 422 } 423 } 424 } 425 639 426 //! \}
Note: See TracChangeset for help on using the changeset viewer.