| 1 | /* The copyright in this software is being made available under the BSD |
|---|
| 2 | * License, included below. This software may be subject to other third party |
|---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
|---|
| 4 | * granted under this license. |
|---|
| 5 | * |
|---|
| 6 | * Copyright (c) 2010-2011, ISO/IEC |
|---|
| 7 | * All rights reserved. |
|---|
| 8 | * |
|---|
| 9 | * Redistribution and use in source and binary forms, with or without |
|---|
| 10 | * modification, are permitted provided that the following conditions are met: |
|---|
| 11 | * |
|---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
|---|
| 13 | * this list of conditions and the following disclaimer. |
|---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
|---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
|---|
| 16 | * and/or other materials provided with the distribution. |
|---|
| 17 | * * Neither the name of the ISO/IEC nor the names of its contributors may |
|---|
| 18 | * be used to endorse or promote products derived from this software without |
|---|
| 19 | * specific prior written permission. |
|---|
| 20 | * |
|---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
|---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
|---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 32 | */ |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | /** \file TComYuv.cpp |
|---|
| 37 | \brief general YUV buffer class |
|---|
| 38 | \todo this should be merged with TComPicYuv |
|---|
| 39 | */ |
|---|
| 40 | |
|---|
| 41 | #include <stdlib.h> |
|---|
| 42 | #include <memory.h> |
|---|
| 43 | #include <assert.h> |
|---|
| 44 | #include <math.h> |
|---|
| 45 | |
|---|
| 46 | #include "CommonDef.h" |
|---|
| 47 | #include "TComYuv.h" |
|---|
| 48 | |
|---|
| 49 | TComYuv::TComYuv() |
|---|
| 50 | { |
|---|
| 51 | m_apiBufY = NULL; |
|---|
| 52 | m_apiBufU = NULL; |
|---|
| 53 | m_apiBufV = NULL; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | TComYuv::~TComYuv() |
|---|
| 57 | { |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | Void TComYuv::printout() |
|---|
| 61 | { |
|---|
| 62 | Int x, y; |
|---|
| 63 | |
|---|
| 64 | Pel* pSrc = getLumaAddr( ); |
|---|
| 65 | Int iStride = getStride(); |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | printf("\nY ..."); |
|---|
| 69 | for ( y = 0; y < iStride; y++ ) |
|---|
| 70 | { |
|---|
| 71 | printf ("\n"); |
|---|
| 72 | for ( x = 0; x < iStride; x++ ) |
|---|
| 73 | { |
|---|
| 74 | printf ("%d ", pSrc[x]); |
|---|
| 75 | } |
|---|
| 76 | pSrc += iStride; |
|---|
| 77 | } |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | Void TComYuv::create( UInt iWidth, UInt iHeight ) |
|---|
| 81 | { |
|---|
| 82 | // memory allocation |
|---|
| 83 | m_apiBufY = (Pel*)xMalloc( Pel, iWidth*iHeight ); |
|---|
| 84 | m_apiBufU = (Pel*)xMalloc( Pel, iWidth*iHeight >> 2 ); |
|---|
| 85 | m_apiBufV = (Pel*)xMalloc( Pel, iWidth*iHeight >> 2 ); |
|---|
| 86 | |
|---|
| 87 | // set width and height |
|---|
| 88 | m_iWidth = iWidth; |
|---|
| 89 | m_iHeight = iHeight; |
|---|
| 90 | m_iCWidth = iWidth >> 1; |
|---|
| 91 | m_iCHeight = iHeight >> 1; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | Void TComYuv::destroy() |
|---|
| 95 | { |
|---|
| 96 | // memory free |
|---|
| 97 | xFree( m_apiBufY ); m_apiBufY = NULL; |
|---|
| 98 | xFree( m_apiBufU ); m_apiBufU = NULL; |
|---|
| 99 | xFree( m_apiBufV ); m_apiBufV = NULL; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | Void TComYuv::clear() |
|---|
| 103 | { |
|---|
| 104 | ::memset( m_apiBufY, 0, ( m_iWidth * m_iHeight )*sizeof(Pel) ); |
|---|
| 105 | ::memset( m_apiBufU, 0, ( m_iCWidth * m_iCHeight )*sizeof(Pel) ); |
|---|
| 106 | ::memset( m_apiBufV, 0, ( m_iCWidth * m_iCHeight )*sizeof(Pel) ); |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | Void TComYuv::copyToPicYuv ( TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth, UInt uiPartIdx ) |
|---|
| 110 | { |
|---|
| 111 | copyToPicLuma ( pcPicYuvDst, iCuAddr, uiAbsZorderIdx, uiPartDepth, uiPartIdx ); |
|---|
| 112 | copyToPicChroma( pcPicYuvDst, iCuAddr, uiAbsZorderIdx, uiPartDepth, uiPartIdx ); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | Void TComYuv::copyToPicLuma ( TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth, UInt uiPartIdx ) |
|---|
| 116 | { |
|---|
| 117 | Int y, iWidth, iHeight; |
|---|
| 118 | iWidth = m_iWidth >>uiPartDepth; |
|---|
| 119 | iHeight = m_iHeight>>uiPartDepth; |
|---|
| 120 | |
|---|
| 121 | Pel* pSrc = getLumaAddr(uiPartIdx, iWidth); |
|---|
| 122 | Pel* pDst = pcPicYuvDst->getLumaAddr ( iCuAddr, uiAbsZorderIdx ); |
|---|
| 123 | |
|---|
| 124 | UInt iSrcStride = getStride(); |
|---|
| 125 | UInt iDstStride = pcPicYuvDst->getStride(); |
|---|
| 126 | |
|---|
| 127 | for ( y = iHeight; y != 0; y-- ) |
|---|
| 128 | { |
|---|
| 129 | ::memcpy( pDst, pSrc, sizeof(Pel)*iWidth); |
|---|
| 130 | pDst += iDstStride; |
|---|
| 131 | pSrc += iSrcStride; |
|---|
| 132 | } |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | Void TComYuv::copyToPicChroma( TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth, UInt uiPartIdx ) |
|---|
| 136 | { |
|---|
| 137 | Int y, iWidth, iHeight; |
|---|
| 138 | iWidth = m_iCWidth >>uiPartDepth; |
|---|
| 139 | iHeight = m_iCHeight>>uiPartDepth; |
|---|
| 140 | |
|---|
| 141 | Pel* pSrcU = getCbAddr(uiPartIdx, iWidth); |
|---|
| 142 | Pel* pSrcV = getCrAddr(uiPartIdx, iWidth); |
|---|
| 143 | Pel* pDstU = pcPicYuvDst->getCbAddr( iCuAddr, uiAbsZorderIdx ); |
|---|
| 144 | Pel* pDstV = pcPicYuvDst->getCrAddr( iCuAddr, uiAbsZorderIdx ); |
|---|
| 145 | |
|---|
| 146 | UInt iSrcStride = getCStride(); |
|---|
| 147 | UInt iDstStride = pcPicYuvDst->getCStride(); |
|---|
| 148 | for ( y = iHeight; y != 0; y-- ) |
|---|
| 149 | { |
|---|
| 150 | ::memcpy( pDstU, pSrcU, sizeof(Pel)*(iWidth) ); |
|---|
| 151 | ::memcpy( pDstV, pSrcV, sizeof(Pel)*(iWidth) ); |
|---|
| 152 | pSrcU += iSrcStride; |
|---|
| 153 | pSrcV += iSrcStride; |
|---|
| 154 | pDstU += iDstStride; |
|---|
| 155 | pDstV += iDstStride; |
|---|
| 156 | } |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | Void TComYuv::copyFromPicYuv ( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiAbsZorderIdx ) |
|---|
| 160 | { |
|---|
| 161 | copyFromPicLuma ( pcPicYuvSrc, iCuAddr, uiAbsZorderIdx ); |
|---|
| 162 | copyFromPicChroma( pcPicYuvSrc, iCuAddr, uiAbsZorderIdx ); |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | Void TComYuv::copyFromPicLuma ( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiAbsZorderIdx ) |
|---|
| 166 | { |
|---|
| 167 | Int y; |
|---|
| 168 | |
|---|
| 169 | Pel* pDst = m_apiBufY; |
|---|
| 170 | Pel* pSrc = pcPicYuvSrc->getLumaAddr ( iCuAddr, uiAbsZorderIdx ); |
|---|
| 171 | |
|---|
| 172 | UInt iDstStride = getStride(); |
|---|
| 173 | UInt iSrcStride = pcPicYuvSrc->getStride(); |
|---|
| 174 | for ( y = m_iHeight; y != 0; y-- ) |
|---|
| 175 | { |
|---|
| 176 | ::memcpy( pDst, pSrc, sizeof(Pel)*m_iWidth); |
|---|
| 177 | pDst += iDstStride; |
|---|
| 178 | pSrc += iSrcStride; |
|---|
| 179 | } |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | Void TComYuv::copyFromPicChroma( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiAbsZorderIdx ) |
|---|
| 183 | { |
|---|
| 184 | Int y; |
|---|
| 185 | |
|---|
| 186 | Pel* pDstU = m_apiBufU; |
|---|
| 187 | Pel* pDstV = m_apiBufV; |
|---|
| 188 | Pel* pSrcU = pcPicYuvSrc->getCbAddr( iCuAddr, uiAbsZorderIdx ); |
|---|
| 189 | Pel* pSrcV = pcPicYuvSrc->getCrAddr( iCuAddr, uiAbsZorderIdx ); |
|---|
| 190 | |
|---|
| 191 | UInt iDstStride = getCStride(); |
|---|
| 192 | UInt iSrcStride = pcPicYuvSrc->getCStride(); |
|---|
| 193 | for ( y = m_iCHeight; y != 0; y-- ) |
|---|
| 194 | { |
|---|
| 195 | ::memcpy( pDstU, pSrcU, sizeof(Pel)*(m_iCWidth) ); |
|---|
| 196 | ::memcpy( pDstV, pSrcV, sizeof(Pel)*(m_iCWidth) ); |
|---|
| 197 | pSrcU += iSrcStride; |
|---|
| 198 | pSrcV += iSrcStride; |
|---|
| 199 | pDstU += iDstStride; |
|---|
| 200 | pDstV += iDstStride; |
|---|
| 201 | } |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | Void TComYuv::copyToPartYuv( TComYuv* pcYuvDst, UInt uiDstPartIdx ) |
|---|
| 205 | { |
|---|
| 206 | copyToPartLuma ( pcYuvDst, uiDstPartIdx ); |
|---|
| 207 | copyToPartChroma( pcYuvDst, uiDstPartIdx ); |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | Void TComYuv::copyToPartLuma( TComYuv* pcYuvDst, UInt uiDstPartIdx ) |
|---|
| 211 | { |
|---|
| 212 | Int y; |
|---|
| 213 | |
|---|
| 214 | Pel* pSrc = m_apiBufY; |
|---|
| 215 | Pel* pDst = pcYuvDst->getLumaAddr( uiDstPartIdx ); |
|---|
| 216 | |
|---|
| 217 | UInt iSrcStride = getStride(); |
|---|
| 218 | UInt iDstStride = pcYuvDst->getStride(); |
|---|
| 219 | for ( y = m_iHeight; y != 0; y-- ) |
|---|
| 220 | { |
|---|
| 221 | ::memcpy( pDst, pSrc, sizeof(Pel)*m_iWidth); |
|---|
| 222 | pDst += iDstStride; |
|---|
| 223 | pSrc += iSrcStride; |
|---|
| 224 | } |
|---|
| 225 | } |
|---|
| 226 | |
|---|
| 227 | Void TComYuv::copyToPartChroma( TComYuv* pcYuvDst, UInt uiDstPartIdx ) |
|---|
| 228 | { |
|---|
| 229 | Int y; |
|---|
| 230 | |
|---|
| 231 | Pel* pSrcU = m_apiBufU; |
|---|
| 232 | Pel* pSrcV = m_apiBufV; |
|---|
| 233 | Pel* pDstU = pcYuvDst->getCbAddr( uiDstPartIdx ); |
|---|
| 234 | Pel* pDstV = pcYuvDst->getCrAddr( uiDstPartIdx ); |
|---|
| 235 | |
|---|
| 236 | UInt iSrcStride = getCStride(); |
|---|
| 237 | UInt iDstStride = pcYuvDst->getCStride(); |
|---|
| 238 | for ( y = m_iCHeight; y != 0; y-- ) |
|---|
| 239 | { |
|---|
| 240 | ::memcpy( pDstU, pSrcU, sizeof(Pel)*(m_iCWidth) ); |
|---|
| 241 | ::memcpy( pDstV, pSrcV, sizeof(Pel)*(m_iCWidth) ); |
|---|
| 242 | pSrcU += iSrcStride; |
|---|
| 243 | pSrcV += iSrcStride; |
|---|
| 244 | pDstU += iDstStride; |
|---|
| 245 | pDstV += iDstStride; |
|---|
| 246 | } |
|---|
| 247 | } |
|---|
| 248 | |
|---|
| 249 | Void TComYuv::copyPartToYuv( TComYuv* pcYuvDst, UInt uiSrcPartIdx ) |
|---|
| 250 | { |
|---|
| 251 | copyPartToLuma ( pcYuvDst, uiSrcPartIdx ); |
|---|
| 252 | copyPartToChroma( pcYuvDst, uiSrcPartIdx ); |
|---|
| 253 | } |
|---|
| 254 | |
|---|
| 255 | Void TComYuv::copyPartToLuma( TComYuv* pcYuvDst, UInt uiSrcPartIdx ) |
|---|
| 256 | { |
|---|
| 257 | Int y; |
|---|
| 258 | |
|---|
| 259 | Pel* pSrc = getLumaAddr(uiSrcPartIdx); |
|---|
| 260 | Pel* pDst = pcYuvDst->getLumaAddr( 0 ); |
|---|
| 261 | |
|---|
| 262 | UInt iSrcStride = getStride(); |
|---|
| 263 | UInt iDstStride = pcYuvDst->getStride(); |
|---|
| 264 | |
|---|
| 265 | UInt uiHeight = pcYuvDst->getHeight(); |
|---|
| 266 | UInt uiWidth = pcYuvDst->getWidth(); |
|---|
| 267 | |
|---|
| 268 | for ( y = uiHeight; y != 0; y-- ) |
|---|
| 269 | { |
|---|
| 270 | ::memcpy( pDst, pSrc, sizeof(Pel)*uiWidth); |
|---|
| 271 | pDst += iDstStride; |
|---|
| 272 | pSrc += iSrcStride; |
|---|
| 273 | } |
|---|
| 274 | } |
|---|
| 275 | |
|---|
| 276 | Void TComYuv::copyPartToChroma( TComYuv* pcYuvDst, UInt uiSrcPartIdx ) |
|---|
| 277 | { |
|---|
| 278 | Int y; |
|---|
| 279 | |
|---|
| 280 | Pel* pSrcU = getCbAddr( uiSrcPartIdx ); |
|---|
| 281 | Pel* pSrcV = getCrAddr( uiSrcPartIdx ); |
|---|
| 282 | Pel* pDstU = pcYuvDst->getCbAddr( 0 ); |
|---|
| 283 | Pel* pDstV = pcYuvDst->getCrAddr( 0 ); |
|---|
| 284 | |
|---|
| 285 | UInt iSrcStride = getCStride(); |
|---|
| 286 | UInt iDstStride = pcYuvDst->getCStride(); |
|---|
| 287 | |
|---|
| 288 | UInt uiCHeight = pcYuvDst->getCHeight(); |
|---|
| 289 | UInt uiCWidth = pcYuvDst->getCWidth(); |
|---|
| 290 | |
|---|
| 291 | for ( y = uiCHeight; y != 0; y-- ) |
|---|
| 292 | { |
|---|
| 293 | ::memcpy( pDstU, pSrcU, sizeof(Pel)*(uiCWidth) ); |
|---|
| 294 | ::memcpy( pDstV, pSrcV, sizeof(Pel)*(uiCWidth) ); |
|---|
| 295 | pSrcU += iSrcStride; |
|---|
| 296 | pSrcV += iSrcStride; |
|---|
| 297 | pDstU += iDstStride; |
|---|
| 298 | pDstV += iDstStride; |
|---|
| 299 | } |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | Void TComYuv::copyPartToPartYuv ( TComYuv* pcYuvDst, UInt uiPartIdx, UInt iWidth, UInt iHeight ) |
|---|
| 303 | { |
|---|
| 304 | copyPartToPartLuma (pcYuvDst, uiPartIdx, iWidth, iHeight ); |
|---|
| 305 | copyPartToPartChroma (pcYuvDst, uiPartIdx, iWidth>>1, iHeight>>1 ); |
|---|
| 306 | } |
|---|
| 307 | |
|---|
| 308 | Void TComYuv::copyPartToPartLuma ( TComYuv* pcYuvDst, UInt uiPartIdx, UInt iWidth, UInt iHeight ) |
|---|
| 309 | { |
|---|
| 310 | Pel* pSrc = getLumaAddr(uiPartIdx); |
|---|
| 311 | Pel* pDst = pcYuvDst->getLumaAddr(uiPartIdx); |
|---|
| 312 | if( pSrc == pDst ) |
|---|
| 313 | { |
|---|
| 314 | //th not a good idea |
|---|
| 315 | //th best would be to fix the caller |
|---|
| 316 | return ; |
|---|
| 317 | } |
|---|
| 318 | |
|---|
| 319 | UInt iSrcStride = getStride(); |
|---|
| 320 | UInt iDstStride = pcYuvDst->getStride(); |
|---|
| 321 | for ( UInt y = iHeight; y != 0; y-- ) |
|---|
| 322 | { |
|---|
| 323 | ::memcpy( pDst, pSrc, iWidth * sizeof(Pel) ); |
|---|
| 324 | pSrc += iSrcStride; |
|---|
| 325 | pDst += iDstStride; |
|---|
| 326 | } |
|---|
| 327 | } |
|---|
| 328 | |
|---|
| 329 | Void TComYuv::copyPartToPartChroma( TComYuv* pcYuvDst, UInt uiPartIdx, UInt iWidth, UInt iHeight ) |
|---|
| 330 | { |
|---|
| 331 | Pel* pSrcU = getCbAddr(uiPartIdx); |
|---|
| 332 | Pel* pSrcV = getCrAddr(uiPartIdx); |
|---|
| 333 | Pel* pDstU = pcYuvDst->getCbAddr(uiPartIdx); |
|---|
| 334 | Pel* pDstV = pcYuvDst->getCrAddr(uiPartIdx); |
|---|
| 335 | |
|---|
| 336 | if( pSrcU == pDstU && pSrcV == pDstV) |
|---|
| 337 | { |
|---|
| 338 | //th not a good idea |
|---|
| 339 | //th best would be to fix the caller |
|---|
| 340 | return ; |
|---|
| 341 | } |
|---|
| 342 | |
|---|
| 343 | UInt iSrcStride = getCStride(); |
|---|
| 344 | UInt iDstStride = pcYuvDst->getCStride(); |
|---|
| 345 | for ( UInt y = iHeight; y != 0; y-- ) |
|---|
| 346 | { |
|---|
| 347 | ::memcpy( pDstU, pSrcU, iWidth * sizeof(Pel) ); |
|---|
| 348 | ::memcpy( pDstV, pSrcV, iWidth * sizeof(Pel) ); |
|---|
| 349 | pSrcU += iSrcStride; |
|---|
| 350 | pSrcV += iSrcStride; |
|---|
| 351 | pDstU += iDstStride; |
|---|
| 352 | pDstV += iDstStride; |
|---|
| 353 | } |
|---|
| 354 | } |
|---|
| 355 | |
|---|
| 356 | Void TComYuv::addClipPartLuma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ) |
|---|
| 357 | { |
|---|
| 358 | Int x, y; |
|---|
| 359 | |
|---|
| 360 | Pel* pSrc0 = pcYuvSrc0->getLumaAddr( uiTrUnitIdx); |
|---|
| 361 | Pel* pSrc1 = pcYuvSrc1->getLumaAddr( uiTrUnitIdx); |
|---|
| 362 | Pel* pDst = getLumaAddr( uiTrUnitIdx); |
|---|
| 363 | |
|---|
| 364 | UInt iSrc0Stride = pcYuvSrc0->getStride(); |
|---|
| 365 | UInt iSrc1Stride = pcYuvSrc1->getStride(); |
|---|
| 366 | UInt iDstStride = getStride(); |
|---|
| 367 | for ( y = uiPartSize-1; y >= 0; y-- ) |
|---|
| 368 | { |
|---|
| 369 | for ( x = uiPartSize-1; x >= 0; x-- ) |
|---|
| 370 | { |
|---|
| 371 | pDst[x] = xClip( pSrc0[x] + pSrc1[x] ); |
|---|
| 372 | } |
|---|
| 373 | pSrc0 += iSrc0Stride; |
|---|
| 374 | pSrc1 += iSrc1Stride; |
|---|
| 375 | pDst += iDstStride; |
|---|
| 376 | } |
|---|
| 377 | } |
|---|
| 378 | |
|---|
| 379 | Void |
|---|
| 380 | TComYuv::add( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract ) |
|---|
| 381 | { |
|---|
| 382 | addLuma ( pcYuvAdd, iWidth, iHeight, bSubtract ); |
|---|
| 383 | addChroma ( pcYuvAdd, iWidth>>1, iHeight>>1, bSubtract ); |
|---|
| 384 | } |
|---|
| 385 | |
|---|
| 386 | Void |
|---|
| 387 | TComYuv::addLuma( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract ) |
|---|
| 388 | { |
|---|
| 389 | Int iScale = ( bSubtract ? -1 : 1 ); |
|---|
| 390 | Int iAddStride = pcYuvAdd->getStride(); |
|---|
| 391 | Int iDstStride = getStride(); |
|---|
| 392 | Pel* pAddSamples = pcYuvAdd->getLumaAddr(); |
|---|
| 393 | Pel* pDstSamples = getLumaAddr(); |
|---|
| 394 | for( Int iY = 0; iY < iHeight; iY++, pDstSamples += iDstStride, pAddSamples += iAddStride ) |
|---|
| 395 | { |
|---|
| 396 | for( Int iX = 0; iX < iWidth; iX++ ) |
|---|
| 397 | { |
|---|
| 398 | pDstSamples[iX] += iScale * pAddSamples[iX]; |
|---|
| 399 | } |
|---|
| 400 | } |
|---|
| 401 | } |
|---|
| 402 | |
|---|
| 403 | Void |
|---|
| 404 | TComYuv::addChroma( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract ) |
|---|
| 405 | { |
|---|
| 406 | Int iScale = ( bSubtract ? -1 : 1 ); |
|---|
| 407 | Int iAddStride = pcYuvAdd->getCStride(); |
|---|
| 408 | Int iDstStride = getCStride(); |
|---|
| 409 | Pel* pAddSamplesCb = pcYuvAdd->getCbAddr(); |
|---|
| 410 | Pel* pAddSamplesCr = pcYuvAdd->getCrAddr(); |
|---|
| 411 | Pel* pDstSamplesCb = getCbAddr(); |
|---|
| 412 | Pel* pDstSamplesCr = getCrAddr(); |
|---|
| 413 | for( Int iY = 0; iY < iHeight; iY++, pDstSamplesCb += iDstStride, pAddSamplesCb += iAddStride, |
|---|
| 414 | pDstSamplesCr += iDstStride, pAddSamplesCr += iAddStride ) |
|---|
| 415 | { |
|---|
| 416 | for( Int iX = 0; iX < iWidth; iX++ ) |
|---|
| 417 | { |
|---|
| 418 | pDstSamplesCb[iX] += iScale * pAddSamplesCb[iX]; |
|---|
| 419 | pDstSamplesCr[iX] += iScale * pAddSamplesCr[iX]; |
|---|
| 420 | } |
|---|
| 421 | } |
|---|
| 422 | } |
|---|
| 423 | |
|---|
| 424 | Void |
|---|
| 425 | TComYuv::clip( Int iWidth, Int iHeight ) |
|---|
| 426 | { |
|---|
| 427 | clipLuma ( iWidth, iHeight ); |
|---|
| 428 | clipChroma ( iWidth>>1, iHeight>>1 ); |
|---|
| 429 | } |
|---|
| 430 | |
|---|
| 431 | Void |
|---|
| 432 | TComYuv::clipLuma( Int iWidth, Int iHeight ) |
|---|
| 433 | { |
|---|
| 434 | Int iStride = getStride(); |
|---|
| 435 | Pel* pSamples = getLumaAddr(); |
|---|
| 436 | for( Int iY = 0; iY < iHeight; iY++, pSamples += iStride ) |
|---|
| 437 | { |
|---|
| 438 | for( Int iX = 0; iX < iWidth; iX++ ) |
|---|
| 439 | { |
|---|
| 440 | pSamples[iX] = xClip( pSamples[iX] ); |
|---|
| 441 | } |
|---|
| 442 | } |
|---|
| 443 | } |
|---|
| 444 | |
|---|
| 445 | Void |
|---|
| 446 | TComYuv::clipChroma( Int iWidth, Int iHeight ) |
|---|
| 447 | { |
|---|
| 448 | Int iStride = getCStride(); |
|---|
| 449 | Pel* pSamplesCb = getCbAddr(); |
|---|
| 450 | Pel* pSamplesCr = getCrAddr(); |
|---|
| 451 | for( Int iY = 0; iY < iHeight; iY++, pSamplesCb += iStride, pSamplesCr += iStride ) |
|---|
| 452 | { |
|---|
| 453 | for( Int iX = 0; iX < iWidth; iX++ ) |
|---|
| 454 | { |
|---|
| 455 | pSamplesCb[iX] = xClip( pSamplesCb[iX] ); |
|---|
| 456 | pSamplesCr[iX] = xClip( pSamplesCr[iX] ); |
|---|
| 457 | } |
|---|
| 458 | } |
|---|
| 459 | } |
|---|
| 460 | |
|---|
| 461 | |
|---|
| 462 | Void TComYuv::addClip( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ) |
|---|
| 463 | { |
|---|
| 464 | addClipLuma ( pcYuvSrc0, pcYuvSrc1, uiTrUnitIdx, uiPartSize ); |
|---|
| 465 | addClipChroma ( pcYuvSrc0, pcYuvSrc1, uiTrUnitIdx, uiPartSize>>1 ); |
|---|
| 466 | } |
|---|
| 467 | |
|---|
| 468 | Void TComYuv::addClipLuma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ) |
|---|
| 469 | { |
|---|
| 470 | Int x, y; |
|---|
| 471 | |
|---|
| 472 | Pel* pSrc0 = pcYuvSrc0->getLumaAddr( uiTrUnitIdx, uiPartSize ); |
|---|
| 473 | Pel* pSrc1 = pcYuvSrc1->getLumaAddr( uiTrUnitIdx, uiPartSize ); |
|---|
| 474 | Pel* pDst = getLumaAddr( uiTrUnitIdx, uiPartSize ); |
|---|
| 475 | |
|---|
| 476 | UInt iSrc0Stride = pcYuvSrc0->getStride(); |
|---|
| 477 | UInt iSrc1Stride = pcYuvSrc1->getStride(); |
|---|
| 478 | UInt iDstStride = getStride(); |
|---|
| 479 | for ( y = uiPartSize-1; y >= 0; y-- ) |
|---|
| 480 | { |
|---|
| 481 | for ( x = uiPartSize-1; x >= 0; x-- ) |
|---|
| 482 | { |
|---|
| 483 | pDst[x] = xClip( pSrc0[x] + pSrc1[x] ); |
|---|
| 484 | } |
|---|
| 485 | pSrc0 += iSrc0Stride; |
|---|
| 486 | pSrc1 += iSrc1Stride; |
|---|
| 487 | pDst += iDstStride; |
|---|
| 488 | } |
|---|
| 489 | } |
|---|
| 490 | |
|---|
| 491 | Void TComYuv::addClipChroma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ) |
|---|
| 492 | { |
|---|
| 493 | Int x, y; |
|---|
| 494 | |
|---|
| 495 | Pel* pSrcU0 = pcYuvSrc0->getCbAddr( uiTrUnitIdx, uiPartSize ); |
|---|
| 496 | Pel* pSrcU1 = pcYuvSrc1->getCbAddr( uiTrUnitIdx, uiPartSize ); |
|---|
| 497 | Pel* pSrcV0 = pcYuvSrc0->getCrAddr( uiTrUnitIdx, uiPartSize ); |
|---|
| 498 | Pel* pSrcV1 = pcYuvSrc1->getCrAddr( uiTrUnitIdx, uiPartSize ); |
|---|
| 499 | Pel* pDstU = getCbAddr( uiTrUnitIdx, uiPartSize ); |
|---|
| 500 | Pel* pDstV = getCrAddr( uiTrUnitIdx, uiPartSize ); |
|---|
| 501 | |
|---|
| 502 | UInt iSrc0Stride = pcYuvSrc0->getCStride(); |
|---|
| 503 | UInt iSrc1Stride = pcYuvSrc1->getCStride(); |
|---|
| 504 | UInt iDstStride = getCStride(); |
|---|
| 505 | for ( y = uiPartSize-1; y >= 0; y-- ) |
|---|
| 506 | { |
|---|
| 507 | for ( x = uiPartSize-1; x >= 0; x-- ) |
|---|
| 508 | { |
|---|
| 509 | pDstU[x] = xClip( pSrcU0[x] + pSrcU1[x] ); |
|---|
| 510 | pDstV[x] = xClip( pSrcV0[x] + pSrcV1[x] ); |
|---|
| 511 | } |
|---|
| 512 | |
|---|
| 513 | pSrcU0 += iSrc0Stride; |
|---|
| 514 | pSrcU1 += iSrc1Stride; |
|---|
| 515 | pSrcV0 += iSrc0Stride; |
|---|
| 516 | pSrcV1 += iSrc1Stride; |
|---|
| 517 | pDstU += iDstStride; |
|---|
| 518 | pDstV += iDstStride; |
|---|
| 519 | } |
|---|
| 520 | } |
|---|
| 521 | |
|---|
| 522 | Void TComYuv::subtract( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ) |
|---|
| 523 | { |
|---|
| 524 | subtractLuma ( pcYuvSrc0, pcYuvSrc1, uiTrUnitIdx, uiPartSize ); |
|---|
| 525 | subtractChroma( pcYuvSrc0, pcYuvSrc1, uiTrUnitIdx, uiPartSize>>1 ); |
|---|
| 526 | } |
|---|
| 527 | |
|---|
| 528 | Void TComYuv::subtractLuma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ) |
|---|
| 529 | { |
|---|
| 530 | Int x, y; |
|---|
| 531 | |
|---|
| 532 | Pel* pSrc0 = pcYuvSrc0->getLumaAddr( uiTrUnitIdx, uiPartSize ); |
|---|
| 533 | Pel* pSrc1 = pcYuvSrc1->getLumaAddr( uiTrUnitIdx, uiPartSize ); |
|---|
| 534 | Pel* pDst = getLumaAddr( uiTrUnitIdx, uiPartSize ); |
|---|
| 535 | |
|---|
| 536 | Int iSrc0Stride = pcYuvSrc0->getStride(); |
|---|
| 537 | Int iSrc1Stride = pcYuvSrc1->getStride(); |
|---|
| 538 | Int iDstStride = getStride(); |
|---|
| 539 | for ( y = uiPartSize-1; y >= 0; y-- ) |
|---|
| 540 | { |
|---|
| 541 | for ( x = uiPartSize-1; x >= 0; x-- ) |
|---|
| 542 | { |
|---|
| 543 | pDst[x] = pSrc0[x] - pSrc1[x]; |
|---|
| 544 | } |
|---|
| 545 | pSrc0 += iSrc0Stride; |
|---|
| 546 | pSrc1 += iSrc1Stride; |
|---|
| 547 | pDst += iDstStride; |
|---|
| 548 | } |
|---|
| 549 | } |
|---|
| 550 | |
|---|
| 551 | Void TComYuv::subtractChroma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ) |
|---|
| 552 | { |
|---|
| 553 | Int x, y; |
|---|
| 554 | |
|---|
| 555 | Pel* pSrcU0 = pcYuvSrc0->getCbAddr( uiTrUnitIdx, uiPartSize ); |
|---|
| 556 | Pel* pSrcU1 = pcYuvSrc1->getCbAddr( uiTrUnitIdx, uiPartSize ); |
|---|
| 557 | Pel* pSrcV0 = pcYuvSrc0->getCrAddr( uiTrUnitIdx, uiPartSize ); |
|---|
| 558 | Pel* pSrcV1 = pcYuvSrc1->getCrAddr( uiTrUnitIdx, uiPartSize ); |
|---|
| 559 | Pel* pDstU = getCbAddr( uiTrUnitIdx, uiPartSize ); |
|---|
| 560 | Pel* pDstV = getCrAddr( uiTrUnitIdx, uiPartSize ); |
|---|
| 561 | |
|---|
| 562 | Int iSrc0Stride = pcYuvSrc0->getCStride(); |
|---|
| 563 | Int iSrc1Stride = pcYuvSrc1->getCStride(); |
|---|
| 564 | Int iDstStride = getCStride(); |
|---|
| 565 | for ( y = uiPartSize-1; y >= 0; y-- ) |
|---|
| 566 | { |
|---|
| 567 | for ( x = uiPartSize-1; x >= 0; x-- ) |
|---|
| 568 | { |
|---|
| 569 | pDstU[x] = pSrcU0[x] - pSrcU1[x]; |
|---|
| 570 | pDstV[x] = pSrcV0[x] - pSrcV1[x]; |
|---|
| 571 | } |
|---|
| 572 | pSrcU0 += iSrc0Stride; |
|---|
| 573 | pSrcU1 += iSrc1Stride; |
|---|
| 574 | pSrcV0 += iSrc0Stride; |
|---|
| 575 | pSrcV1 += iSrc1Stride; |
|---|
| 576 | pDstU += iDstStride; |
|---|
| 577 | pDstV += iDstStride; |
|---|
| 578 | } |
|---|
| 579 | } |
|---|
| 580 | |
|---|
| 581 | #ifdef ROUNDING_CONTROL_BIPRED |
|---|
| 582 | |
|---|
| 583 | Void TComYuv::addAvg( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt iPartUnitIdx, UInt iWidth, UInt iHeight, Bool bRound ) |
|---|
| 584 | { |
|---|
| 585 | Int x, y; |
|---|
| 586 | |
|---|
| 587 | Pel* pSrcY0 = pcYuvSrc0->getLumaAddr( iPartUnitIdx ); |
|---|
| 588 | Pel* pSrcU0 = pcYuvSrc0->getCbAddr ( iPartUnitIdx ); |
|---|
| 589 | Pel* pSrcV0 = pcYuvSrc0->getCrAddr ( iPartUnitIdx ); |
|---|
| 590 | |
|---|
| 591 | Pel* pSrcY1 = pcYuvSrc1->getLumaAddr( iPartUnitIdx ); |
|---|
| 592 | Pel* pSrcU1 = pcYuvSrc1->getCbAddr ( iPartUnitIdx ); |
|---|
| 593 | Pel* pSrcV1 = pcYuvSrc1->getCrAddr ( iPartUnitIdx ); |
|---|
| 594 | |
|---|
| 595 | Pel* pDstY = getLumaAddr( iPartUnitIdx ); |
|---|
| 596 | Pel* pDstU = getCbAddr ( iPartUnitIdx ); |
|---|
| 597 | Pel* pDstV = getCrAddr ( iPartUnitIdx ); |
|---|
| 598 | |
|---|
| 599 | UInt iSrc0Stride = pcYuvSrc0->getStride(); |
|---|
| 600 | UInt iSrc1Stride = pcYuvSrc1->getStride(); |
|---|
| 601 | UInt iDstStride = getStride(); |
|---|
| 602 | |
|---|
| 603 | #if HIGH_ACCURACY_BI |
|---|
| 604 | Int shiftNum = 15 - (g_uiBitDepth + g_uiBitIncrement); |
|---|
| 605 | Int offset = (1<<(shiftNum - 1)); |
|---|
| 606 | |
|---|
| 607 | for ( y = iHeight-1; y >= 0; y-- ) |
|---|
| 608 | { |
|---|
| 609 | for ( x = iWidth-1; x >= 0; ) |
|---|
| 610 | { |
|---|
| 611 | // note: luma min width is 4 |
|---|
| 612 | pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum ); x--; |
|---|
| 613 | pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--; |
|---|
| 614 | pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--; |
|---|
| 615 | pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--; |
|---|
| 616 | } |
|---|
| 617 | pSrcY0 += iSrc0Stride; |
|---|
| 618 | pSrcY1 += iSrc1Stride; |
|---|
| 619 | pDstY += iDstStride; |
|---|
| 620 | } |
|---|
| 621 | |
|---|
| 622 | iSrc0Stride = pcYuvSrc0->getCStride(); |
|---|
| 623 | iSrc1Stride = pcYuvSrc1->getCStride(); |
|---|
| 624 | iDstStride = getCStride(); |
|---|
| 625 | |
|---|
| 626 | iWidth >>=1; |
|---|
| 627 | iHeight >>=1; |
|---|
| 628 | |
|---|
| 629 | for ( y = iHeight-1; y >= 0; y-- ) |
|---|
| 630 | { |
|---|
| 631 | for ( x = iWidth-1; x >= 0; ) |
|---|
| 632 | { |
|---|
| 633 | // note: chroma min width is 2 |
|---|
| 634 | pDstU[x] = Clip((pSrcU0[x] + pSrcU1[x] + offset) >> shiftNum); |
|---|
| 635 | pDstV[x] = Clip((pSrcV0[x] + pSrcV1[x] + offset) >> shiftNum); x--; |
|---|
| 636 | pDstU[x] = Clip((pSrcU0[x] + pSrcU1[x] + offset) >> shiftNum); |
|---|
| 637 | pDstV[x] = Clip((pSrcV0[x] + pSrcV1[x] + offset) >> shiftNum); x--; |
|---|
| 638 | } |
|---|
| 639 | |
|---|
| 640 | pSrcU0 += iSrc0Stride; |
|---|
| 641 | pSrcU1 += iSrc1Stride; |
|---|
| 642 | pSrcV0 += iSrc0Stride; |
|---|
| 643 | pSrcV1 += iSrc1Stride; |
|---|
| 644 | pDstU += iDstStride; |
|---|
| 645 | pDstV += iDstStride; |
|---|
| 646 | } |
|---|
| 647 | |
|---|
| 648 | #else |
|---|
| 649 | |
|---|
| 650 | for ( y = iHeight-1; y >= 0; y-- ) |
|---|
| 651 | { |
|---|
| 652 | for ( x = iWidth-1; x >= 0; ) |
|---|
| 653 | { |
|---|
| 654 | // note: luma min width is 4 |
|---|
| 655 | pDstY[x] = (pSrcY0[x] + pSrcY1[x] + bRound) >> 1; x--; |
|---|
| 656 | pDstY[x] = (pSrcY0[x] + pSrcY1[x] + bRound) >> 1; x--; |
|---|
| 657 | pDstY[x] = (pSrcY0[x] + pSrcY1[x] + bRound) >> 1; x--; |
|---|
| 658 | pDstY[x] = (pSrcY0[x] + pSrcY1[x] + bRound) >> 1; x--; |
|---|
| 659 | } |
|---|
| 660 | pSrcY0 += iSrc0Stride; |
|---|
| 661 | pSrcY1 += iSrc1Stride; |
|---|
| 662 | pDstY += iDstStride; |
|---|
| 663 | } |
|---|
| 664 | |
|---|
| 665 | iSrc0Stride = pcYuvSrc0->getCStride(); |
|---|
| 666 | iSrc1Stride = pcYuvSrc1->getCStride(); |
|---|
| 667 | iDstStride = getCStride(); |
|---|
| 668 | |
|---|
| 669 | iWidth >>=1; |
|---|
| 670 | iHeight >>=1; |
|---|
| 671 | |
|---|
| 672 | for ( y = iHeight-1; y >= 0; y-- ) |
|---|
| 673 | { |
|---|
| 674 | for ( x = iWidth-1; x >= 0; ) |
|---|
| 675 | { |
|---|
| 676 | // note: chroma min width is 2 |
|---|
| 677 | pDstU[x] = (pSrcU0[x] + pSrcU1[x] + bRound) >> 1; |
|---|
| 678 | pDstV[x] = (pSrcV0[x] + pSrcV1[x] + bRound) >> 1; x--; |
|---|
| 679 | pDstU[x] = (pSrcU0[x] + pSrcU1[x] + bRound) >> 1; |
|---|
| 680 | pDstV[x] = (pSrcV0[x] + pSrcV1[x] + bRound) >> 1; x--; |
|---|
| 681 | } |
|---|
| 682 | |
|---|
| 683 | pSrcU0 += iSrc0Stride; |
|---|
| 684 | pSrcU1 += iSrc1Stride; |
|---|
| 685 | pSrcV0 += iSrc0Stride; |
|---|
| 686 | pSrcV1 += iSrc1Stride; |
|---|
| 687 | pDstU += iDstStride; |
|---|
| 688 | pDstV += iDstStride; |
|---|
| 689 | } |
|---|
| 690 | #endif |
|---|
| 691 | } |
|---|
| 692 | |
|---|
| 693 | #endif |
|---|
| 694 | |
|---|
| 695 | Void TComYuv::addAvg( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt iPartUnitIdx, UInt iWidth, UInt iHeight ) |
|---|
| 696 | { |
|---|
| 697 | Int x, y; |
|---|
| 698 | |
|---|
| 699 | Pel* pSrcY0 = pcYuvSrc0->getLumaAddr( iPartUnitIdx ); |
|---|
| 700 | Pel* pSrcU0 = pcYuvSrc0->getCbAddr ( iPartUnitIdx ); |
|---|
| 701 | Pel* pSrcV0 = pcYuvSrc0->getCrAddr ( iPartUnitIdx ); |
|---|
| 702 | |
|---|
| 703 | Pel* pSrcY1 = pcYuvSrc1->getLumaAddr( iPartUnitIdx ); |
|---|
| 704 | Pel* pSrcU1 = pcYuvSrc1->getCbAddr ( iPartUnitIdx ); |
|---|
| 705 | Pel* pSrcV1 = pcYuvSrc1->getCrAddr ( iPartUnitIdx ); |
|---|
| 706 | |
|---|
| 707 | Pel* pDstY = getLumaAddr( iPartUnitIdx ); |
|---|
| 708 | Pel* pDstU = getCbAddr ( iPartUnitIdx ); |
|---|
| 709 | Pel* pDstV = getCrAddr ( iPartUnitIdx ); |
|---|
| 710 | |
|---|
| 711 | UInt iSrc0Stride = pcYuvSrc0->getStride(); |
|---|
| 712 | UInt iSrc1Stride = pcYuvSrc1->getStride(); |
|---|
| 713 | UInt iDstStride = getStride(); |
|---|
| 714 | #if HIGH_ACCURACY_BI |
|---|
| 715 | Int shiftNum = 15 - (g_uiBitDepth + g_uiBitIncrement); |
|---|
| 716 | Int offset = (1<<(shiftNum - 1)); |
|---|
| 717 | |
|---|
| 718 | for ( y = iHeight-1; y >= 0; y-- ) |
|---|
| 719 | { |
|---|
| 720 | for ( x = iWidth-1; x >= 0; ) |
|---|
| 721 | { |
|---|
| 722 | // note: luma min width is 4 |
|---|
| 723 | pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum ); x--; |
|---|
| 724 | pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--; |
|---|
| 725 | pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--; |
|---|
| 726 | pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--; |
|---|
| 727 | } |
|---|
| 728 | pSrcY0 += iSrc0Stride; |
|---|
| 729 | pSrcY1 += iSrc1Stride; |
|---|
| 730 | pDstY += iDstStride; |
|---|
| 731 | } |
|---|
| 732 | |
|---|
| 733 | iSrc0Stride = pcYuvSrc0->getCStride(); |
|---|
| 734 | iSrc1Stride = pcYuvSrc1->getCStride(); |
|---|
| 735 | iDstStride = getCStride(); |
|---|
| 736 | |
|---|
| 737 | iWidth >>=1; |
|---|
| 738 | iHeight >>=1; |
|---|
| 739 | |
|---|
| 740 | for ( y = iHeight-1; y >= 0; y-- ) |
|---|
| 741 | { |
|---|
| 742 | for ( x = iWidth-1; x >= 0; ) |
|---|
| 743 | { |
|---|
| 744 | // note: chroma min width is 2 |
|---|
| 745 | pDstU[x] = Clip((pSrcU0[x] + pSrcU1[x] + offset) >> shiftNum); |
|---|
| 746 | pDstV[x] = Clip((pSrcV0[x] + pSrcV1[x] + offset) >> shiftNum); x--; |
|---|
| 747 | pDstU[x] = Clip((pSrcU0[x] + pSrcU1[x] + offset) >> shiftNum); |
|---|
| 748 | pDstV[x] = Clip((pSrcV0[x] + pSrcV1[x] + offset) >> shiftNum); x--; |
|---|
| 749 | } |
|---|
| 750 | |
|---|
| 751 | pSrcU0 += iSrc0Stride; |
|---|
| 752 | pSrcU1 += iSrc1Stride; |
|---|
| 753 | pSrcV0 += iSrc0Stride; |
|---|
| 754 | pSrcV1 += iSrc1Stride; |
|---|
| 755 | pDstU += iDstStride; |
|---|
| 756 | pDstV += iDstStride; |
|---|
| 757 | } |
|---|
| 758 | |
|---|
| 759 | #else |
|---|
| 760 | for ( y = iHeight-1; y >= 0; y-- ) |
|---|
| 761 | { |
|---|
| 762 | for ( x = iWidth-1; x >= 0; ) |
|---|
| 763 | { |
|---|
| 764 | // note: luma min width is 4 |
|---|
| 765 | pDstY[x] = (pSrcY0[x] + pSrcY1[x] + 1) >> 1; x--; |
|---|
| 766 | pDstY[x] = (pSrcY0[x] + pSrcY1[x] + 1) >> 1; x--; |
|---|
| 767 | pDstY[x] = (pSrcY0[x] + pSrcY1[x] + 1) >> 1; x--; |
|---|
| 768 | pDstY[x] = (pSrcY0[x] + pSrcY1[x] + 1) >> 1; x--; |
|---|
| 769 | } |
|---|
| 770 | pSrcY0 += iSrc0Stride; |
|---|
| 771 | pSrcY1 += iSrc1Stride; |
|---|
| 772 | pDstY += iDstStride; |
|---|
| 773 | } |
|---|
| 774 | |
|---|
| 775 | iSrc0Stride = pcYuvSrc0->getCStride(); |
|---|
| 776 | iSrc1Stride = pcYuvSrc1->getCStride(); |
|---|
| 777 | iDstStride = getCStride(); |
|---|
| 778 | |
|---|
| 779 | iWidth >>=1; |
|---|
| 780 | iHeight >>=1; |
|---|
| 781 | |
|---|
| 782 | for ( y = iHeight-1; y >= 0; y-- ) |
|---|
| 783 | { |
|---|
| 784 | for ( x = iWidth-1; x >= 0; ) |
|---|
| 785 | { |
|---|
| 786 | // note: chroma min width is 2 |
|---|
| 787 | pDstU[x] = (pSrcU0[x] + pSrcU1[x] + 1) >> 1; |
|---|
| 788 | pDstV[x] = (pSrcV0[x] + pSrcV1[x] + 1) >> 1; x--; |
|---|
| 789 | pDstU[x] = (pSrcU0[x] + pSrcU1[x] + 1) >> 1; |
|---|
| 790 | pDstV[x] = (pSrcV0[x] + pSrcV1[x] + 1) >> 1; x--; |
|---|
| 791 | } |
|---|
| 792 | |
|---|
| 793 | pSrcU0 += iSrc0Stride; |
|---|
| 794 | pSrcU1 += iSrc1Stride; |
|---|
| 795 | pSrcV0 += iSrc0Stride; |
|---|
| 796 | pSrcV1 += iSrc1Stride; |
|---|
| 797 | pDstU += iDstStride; |
|---|
| 798 | pDstV += iDstStride; |
|---|
| 799 | } |
|---|
| 800 | #endif |
|---|
| 801 | } |
|---|
| 802 | |
|---|
| 803 | Void TComYuv::removeHighFreq( TComYuv* pcYuvSrc, UInt uiWidht, UInt uiHeight ) |
|---|
| 804 | { |
|---|
| 805 | Int x, y; |
|---|
| 806 | |
|---|
| 807 | Pel* pSrc = pcYuvSrc->getLumaAddr(); |
|---|
| 808 | Pel* pSrcU = pcYuvSrc->getCbAddr(); |
|---|
| 809 | Pel* pSrcV = pcYuvSrc->getCrAddr(); |
|---|
| 810 | |
|---|
| 811 | Pel* pDst = m_apiBufY; |
|---|
| 812 | Pel* pDstU = m_apiBufU; |
|---|
| 813 | Pel* pDstV = m_apiBufV; |
|---|
| 814 | |
|---|
| 815 | Int iSrcStride = pcYuvSrc->getStride(); |
|---|
| 816 | Int iDstStride = getStride(); |
|---|
| 817 | |
|---|
| 818 | for ( y = uiHeight-1; y >= 0; y-- ) |
|---|
| 819 | { |
|---|
| 820 | for ( x = uiWidht-1; x >= 0; x-- ) |
|---|
| 821 | { |
|---|
| 822 | pDst[x ] = xClip( (pDst[x ]<<1) - pSrc[x ] ); |
|---|
| 823 | } |
|---|
| 824 | pSrc += iSrcStride; |
|---|
| 825 | pDst += iDstStride; |
|---|
| 826 | } |
|---|
| 827 | |
|---|
| 828 | iSrcStride = pcYuvSrc->getCStride(); |
|---|
| 829 | iDstStride = getCStride(); |
|---|
| 830 | |
|---|
| 831 | uiHeight >>= 1; |
|---|
| 832 | uiWidht >>= 1; |
|---|
| 833 | |
|---|
| 834 | for ( y = uiHeight-1; y >= 0; y-- ) |
|---|
| 835 | { |
|---|
| 836 | for ( x = uiWidht-1; x >= 0; x-- ) |
|---|
| 837 | { |
|---|
| 838 | pDstU[x ] = xClip( (pDstU[x ]<<1) - pSrcU[x ] ); |
|---|
| 839 | pDstV[x ] = xClip( (pDstV[x ]<<1) - pSrcV[x ] ); |
|---|
| 840 | } |
|---|
| 841 | pSrcU += iSrcStride; |
|---|
| 842 | pSrcV += iSrcStride; |
|---|
| 843 | pDstU += iDstStride; |
|---|
| 844 | pDstV += iDstStride; |
|---|
| 845 | } |
|---|
| 846 | } |
|---|
| 847 | |
|---|
| 848 | Void TComYuv::removeHighFreq( TComYuv* pcYuvSrc, UInt uiPartIdx, UInt uiWidht, UInt uiHeight ) |
|---|
| 849 | { |
|---|
| 850 | Int x, y; |
|---|
| 851 | |
|---|
| 852 | Pel* pSrc = pcYuvSrc->getLumaAddr(uiPartIdx); |
|---|
| 853 | Pel* pSrcU = pcYuvSrc->getCbAddr(uiPartIdx); |
|---|
| 854 | Pel* pSrcV = pcYuvSrc->getCrAddr(uiPartIdx); |
|---|
| 855 | |
|---|
| 856 | Pel* pDst = getLumaAddr(uiPartIdx); |
|---|
| 857 | Pel* pDstU = getCbAddr(uiPartIdx); |
|---|
| 858 | Pel* pDstV = getCrAddr(uiPartIdx); |
|---|
| 859 | |
|---|
| 860 | Int iSrcStride = pcYuvSrc->getStride(); |
|---|
| 861 | Int iDstStride = getStride(); |
|---|
| 862 | |
|---|
| 863 | for ( y = uiHeight-1; y >= 0; y-- ) |
|---|
| 864 | { |
|---|
| 865 | for ( x = uiWidht-1; x >= 0; x-- ) |
|---|
| 866 | { |
|---|
| 867 | pDst[x ] = xClip( (pDst[x ]<<1) - pSrc[x ] ); |
|---|
| 868 | } |
|---|
| 869 | pSrc += iSrcStride; |
|---|
| 870 | pDst += iDstStride; |
|---|
| 871 | } |
|---|
| 872 | |
|---|
| 873 | iSrcStride = pcYuvSrc->getCStride(); |
|---|
| 874 | iDstStride = getCStride(); |
|---|
| 875 | |
|---|
| 876 | uiHeight >>= 1; |
|---|
| 877 | uiWidht >>= 1; |
|---|
| 878 | |
|---|
| 879 | for ( y = uiHeight-1; y >= 0; y-- ) |
|---|
| 880 | { |
|---|
| 881 | for ( x = uiWidht-1; x >= 0; x-- ) |
|---|
| 882 | { |
|---|
| 883 | pDstU[x ] = xClip( (pDstU[x ]<<1) - pSrcU[x ] ); |
|---|
| 884 | pDstV[x ] = xClip( (pDstV[x ]<<1) - pSrcV[x ] ); |
|---|
| 885 | } |
|---|
| 886 | pSrcU += iSrcStride; |
|---|
| 887 | pSrcV += iSrcStride; |
|---|
| 888 | pDstU += iDstStride; |
|---|
| 889 | pDstV += iDstStride; |
|---|
| 890 | } |
|---|
| 891 | } |
|---|
| 892 | |
|---|
| 893 | |
|---|
| 894 | Pel* TComYuv::getLumaAddr( UInt uiPartUnitIdx ) |
|---|
| 895 | { |
|---|
| 896 | UInt iBlkX; |
|---|
| 897 | UInt iBlkY; |
|---|
| 898 | iBlkX = g_auiRasterToPelX[g_auiZscanToRaster[uiPartUnitIdx]]; |
|---|
| 899 | iBlkY = g_auiRasterToPelY[g_auiZscanToRaster[uiPartUnitIdx]]; |
|---|
| 900 | |
|---|
| 901 | return m_apiBufY + iBlkY*getStride() + iBlkX; |
|---|
| 902 | } |
|---|
| 903 | |
|---|
| 904 | Pel* TComYuv::getCbAddr( UInt uiPartUnitIdx ) |
|---|
| 905 | { |
|---|
| 906 | UInt iBlkX; |
|---|
| 907 | UInt iBlkY; |
|---|
| 908 | iBlkX = g_auiRasterToPelX[g_auiZscanToRaster[uiPartUnitIdx]] >> 1; |
|---|
| 909 | iBlkY = g_auiRasterToPelY[g_auiZscanToRaster[uiPartUnitIdx]] >> 1; |
|---|
| 910 | |
|---|
| 911 | return m_apiBufU + iBlkY*getCStride() + iBlkX; |
|---|
| 912 | } |
|---|
| 913 | |
|---|
| 914 | Pel* TComYuv::getCrAddr( UInt uiPartUnitIdx ) |
|---|
| 915 | { |
|---|
| 916 | UInt iBlkX; |
|---|
| 917 | UInt iBlkY; |
|---|
| 918 | iBlkX = g_auiRasterToPelX[g_auiZscanToRaster[uiPartUnitIdx]] >> 1; |
|---|
| 919 | iBlkY = g_auiRasterToPelY[g_auiZscanToRaster[uiPartUnitIdx]] >> 1; |
|---|
| 920 | |
|---|
| 921 | return m_apiBufV + iBlkY*getCStride() + iBlkX; |
|---|
| 922 | } |
|---|
| 923 | |
|---|
| 924 | Pel* TComYuv::getLumaAddr( UInt iTransUnitIdx, UInt iBlkSize ) |
|---|
| 925 | { |
|---|
| 926 | UInt uiNumTrInWidth = m_iWidth / iBlkSize; |
|---|
| 927 | UInt iBlkX = iTransUnitIdx % uiNumTrInWidth; |
|---|
| 928 | UInt iBlkY = iTransUnitIdx / uiNumTrInWidth; |
|---|
| 929 | |
|---|
| 930 | return m_apiBufY + (iBlkX + iBlkY * getStride()) * iBlkSize; |
|---|
| 931 | } |
|---|
| 932 | |
|---|
| 933 | Pel* TComYuv::getCbAddr( UInt iTransUnitIdx, UInt iBlkSize ) |
|---|
| 934 | { |
|---|
| 935 | UInt uiNumTrInWidth = m_iCWidth / iBlkSize; |
|---|
| 936 | UInt iBlkX = iTransUnitIdx % uiNumTrInWidth; |
|---|
| 937 | UInt iBlkY = iTransUnitIdx / uiNumTrInWidth; |
|---|
| 938 | |
|---|
| 939 | return m_apiBufU + (iBlkX + iBlkY * getCStride()) * iBlkSize; |
|---|
| 940 | } |
|---|
| 941 | |
|---|
| 942 | Pel* TComYuv::getCrAddr( UInt iTransUnitIdx, UInt iBlkSize ) |
|---|
| 943 | { |
|---|
| 944 | UInt uiNumTrInWidth = m_iCWidth / iBlkSize; |
|---|
| 945 | UInt iBlkX = iTransUnitIdx % uiNumTrInWidth; |
|---|
| 946 | UInt iBlkY = iTransUnitIdx / uiNumTrInWidth; |
|---|
| 947 | |
|---|
| 948 | return m_apiBufV + (iBlkX + iBlkY * getCStride()) * iBlkSize; |
|---|
| 949 | } |
|---|