Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
- Timestamp:
- 13 Aug 2015, 17:38:13 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
r1179 r1313 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-2015, ITU/ISO/IEC … … 32 32 */ 33 33 34 /** 34 /** 35 35 \file TEncSampleAdaptiveOffset.cpp 36 36 \brief estimation part of sample adaptive offset class … … 46 46 47 47 48 /** rounding with IBDI 49 * \param x 50 */ 48 //! rounding with IBDI 51 49 inline Double xRoundIbdi2(Int bitDepth, Double x) 52 50 { … … 62 60 TEncSampleAdaptiveOffset::TEncSampleAdaptiveOffset() 63 61 { 64 m_pppcRDSbacCoder = NULL; 62 m_pppcRDSbacCoder = NULL; 65 63 m_pcRDGoOnSbacCoder = NULL; 66 m_pppcBinCoderCABAC = NULL; 64 m_pppcBinCoderCABAC = NULL; 67 65 m_statData = NULL; 68 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK69 66 m_preDBFstatData = NULL; 70 #endif71 67 } 72 68 … … 76 72 } 77 73 78 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK79 74 Void TEncSampleAdaptiveOffset::createEncData(Bool isPreDBFSamplesUsed) 80 #else81 Void TEncSampleAdaptiveOffset::createEncData()82 #endif83 75 { 84 76 85 77 //cabac coder for RDO 86 78 m_pppcRDSbacCoder = new TEncSbac* [NUM_SAO_CABACSTATE_LABELS]; 79 #if FAST_BIT_EST 87 80 m_pppcBinCoderCABAC = new TEncBinCABACCounter* [NUM_SAO_CABACSTATE_LABELS]; 81 #else 82 m_pppcBinCoderCABAC = new TEncBinCABAC* [NUM_SAO_CABACSTATE_LABELS]; 83 #endif 88 84 89 85 for(Int cs=0; cs < NUM_SAO_CABACSTATE_LABELS; cs++) 90 86 { 91 87 m_pppcRDSbacCoder[cs] = new TEncSbac; 88 #if FAST_BIT_EST 92 89 m_pppcBinCoderCABAC[cs] = new TEncBinCABACCounter; 90 #else 91 m_pppcBinCoderCABAC[cs] = new TEncBinCABAC; 92 #endif 93 93 m_pppcRDSbacCoder [cs]->init( m_pppcBinCoderCABAC [cs] ); 94 94 } … … 99 99 for(Int i=0; i< m_numCTUsPic; i++) 100 100 { 101 m_statData[i] = new SAOStatData*[ NUM_SAO_COMPONENTS];102 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)101 m_statData[i] = new SAOStatData*[MAX_NUM_COMPONENT]; 102 for(Int compIdx=0; compIdx < MAX_NUM_COMPONENT; compIdx++) 103 103 { 104 104 m_statData[i][compIdx] = new SAOStatData[NUM_SAO_NEW_TYPES]; 105 105 } 106 106 } 107 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK108 107 if(isPreDBFSamplesUsed) 109 108 { … … 111 110 for(Int i=0; i< m_numCTUsPic; i++) 112 111 { 113 m_preDBFstatData[i] = new SAOStatData*[ NUM_SAO_COMPONENTS];114 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)112 m_preDBFstatData[i] = new SAOStatData*[MAX_NUM_COMPONENT]; 113 for(Int compIdx=0; compIdx < MAX_NUM_COMPONENT; compIdx++) 115 114 { 116 115 m_preDBFstatData[i][compIdx] = new SAOStatData[NUM_SAO_NEW_TYPES]; … … 119 118 120 119 } 121 #endif 122 123 #if SAO_ENCODING_CHOICE 120 124 121 ::memset(m_saoDisabledRate, 0, sizeof(m_saoDisabledRate)); 125 #endif126 122 127 123 for(Int typeIdc=0; typeIdc < NUM_SAO_NEW_TYPES; typeIdc++) 128 124 { 129 m_skipLinesR[SAO_Y ][typeIdc]= 5; 130 m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3; 131 132 m_skipLinesB[SAO_Y ][typeIdc]= 4; 133 m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2; 134 135 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 125 m_skipLinesR[COMPONENT_Y ][typeIdc]= 5; 126 m_skipLinesR[COMPONENT_Cb][typeIdc]= m_skipLinesR[COMPONENT_Cr][typeIdc]= 3; 127 128 m_skipLinesB[COMPONENT_Y ][typeIdc]= 4; 129 m_skipLinesB[COMPONENT_Cb][typeIdc]= m_skipLinesB[COMPONENT_Cr][typeIdc]= 2; 130 136 131 if(isPreDBFSamplesUsed) 137 132 { … … 140 135 case SAO_TYPE_EO_0: 141 136 { 142 m_skipLinesR[ SAO_Y ][typeIdc]= 5;143 m_skipLinesR[ SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3;144 145 m_skipLinesB[ SAO_Y ][typeIdc]= 3;146 m_skipLinesB[ SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 1;137 m_skipLinesR[COMPONENT_Y ][typeIdc]= 5; 138 m_skipLinesR[COMPONENT_Cb][typeIdc]= m_skipLinesR[COMPONENT_Cr][typeIdc]= 3; 139 140 m_skipLinesB[COMPONENT_Y ][typeIdc]= 3; 141 m_skipLinesB[COMPONENT_Cb][typeIdc]= m_skipLinesB[COMPONENT_Cr][typeIdc]= 1; 147 142 } 148 143 break; 149 144 case SAO_TYPE_EO_90: 150 145 { 151 m_skipLinesR[ SAO_Y ][typeIdc]= 4;152 m_skipLinesR[ SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 2;153 154 m_skipLinesB[ SAO_Y ][typeIdc]= 4;155 m_skipLinesB[ SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2;146 m_skipLinesR[COMPONENT_Y ][typeIdc]= 4; 147 m_skipLinesR[COMPONENT_Cb][typeIdc]= m_skipLinesR[COMPONENT_Cr][typeIdc]= 2; 148 149 m_skipLinesB[COMPONENT_Y ][typeIdc]= 4; 150 m_skipLinesB[COMPONENT_Cb][typeIdc]= m_skipLinesB[COMPONENT_Cr][typeIdc]= 2; 156 151 } 157 152 break; … … 159 154 case SAO_TYPE_EO_45: 160 155 { 161 m_skipLinesR[ SAO_Y ][typeIdc]= 5;162 m_skipLinesR[ SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3;163 164 m_skipLinesB[ SAO_Y ][typeIdc]= 4;165 m_skipLinesB[ SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2;156 m_skipLinesR[COMPONENT_Y ][typeIdc]= 5; 157 m_skipLinesR[COMPONENT_Cb][typeIdc]= m_skipLinesR[COMPONENT_Cr][typeIdc]= 3; 158 159 m_skipLinesB[COMPONENT_Y ][typeIdc]= 4; 160 m_skipLinesB[COMPONENT_Cb][typeIdc]= m_skipLinesB[COMPONENT_Cr][typeIdc]= 2; 166 161 } 167 162 break; 168 163 case SAO_TYPE_BO: 169 164 { 170 m_skipLinesR[ SAO_Y ][typeIdc]= 4;171 m_skipLinesR[ SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 2;172 173 m_skipLinesB[ SAO_Y ][typeIdc]= 3;174 m_skipLinesB[ SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 1;165 m_skipLinesR[COMPONENT_Y ][typeIdc]= 4; 166 m_skipLinesR[COMPONENT_Cb][typeIdc]= m_skipLinesR[COMPONENT_Cr][typeIdc]= 2; 167 168 m_skipLinesB[COMPONENT_Y ][typeIdc]= 3; 169 m_skipLinesB[COMPONENT_Cb][typeIdc]= m_skipLinesB[COMPONENT_Cr][typeIdc]= 1; 175 170 } 176 171 break; … … 183 178 } 184 179 } 185 #endif186 180 } 187 181 … … 212 206 for(Int i=0; i< m_numCTUsPic; i++) 213 207 { 214 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)208 for(Int compIdx=0; compIdx< MAX_NUM_COMPONENT; compIdx++) 215 209 { 216 210 delete[] m_statData[i][compIdx]; … … 220 214 delete[] m_statData; m_statData = NULL; 221 215 } 222 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK223 216 if(m_preDBFstatData != NULL) 224 217 { 225 218 for(Int i=0; i< m_numCTUsPic; i++) 226 219 { 227 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)220 for(Int compIdx=0; compIdx< MAX_NUM_COMPONENT; compIdx++) 228 221 { 229 222 delete[] m_preDBFstatData[i][compIdx]; … … 233 226 delete[] m_preDBFstatData; m_preDBFstatData = NULL; 234 227 } 235 236 #endif 237 } 238 239 Void TEncSampleAdaptiveOffset::initRDOCabacCoder(TEncSbac* pcRDGoOnSbacCoder, TComSlice* pcSlice) 228 } 229 230 Void TEncSampleAdaptiveOffset::initRDOCabacCoder(TEncSbac* pcRDGoOnSbacCoder, TComSlice* pcSlice) 240 231 { 241 232 m_pcRDGoOnSbacCoder = pcRDGoOnSbacCoder; 242 m_pcRDGoOnSbacCoder->setSlice(pcSlice); 243 m_pcRDGoOnSbacCoder->resetEntropy(); 233 m_pcRDGoOnSbacCoder->resetEntropy(pcSlice); 244 234 m_pcRDGoOnSbacCoder->resetBits(); 245 235 … … 249 239 250 240 251 Void TEncSampleAdaptiveOffset::SAOProcess(TComPic* pPic, Bool* sliceEnabled, const Double *lambdas 252 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 253 , Bool isPreDBFSamplesUsed 254 #endif 255 ) 241 Void TEncSampleAdaptiveOffset::SAOProcess(TComPic* pPic, Bool* sliceEnabled, const Double *lambdas, const Bool bTestSAODisableAtPictureLevel, const Double saoEncodingRate, const Double saoEncodingRateChroma, Bool isPreDBFSamplesUsed ) 256 242 { 257 243 TComPicYuv* orgYuv= pPic->getPicYuvOrg(); 258 244 TComPicYuv* resYuv= pPic->getPicYuvRec(); 259 m _lambda[SAO_Y]= lambdas[0]; m_lambda[SAO_Cb]= lambdas[1]; m_lambda[SAO_Cr]= lambdas[2];245 memcpy(m_lambda, lambdas, sizeof(m_lambda)); 260 246 TComPicYuv* srcYuv = m_tempPicYuv; 261 247 resYuv->copyToPic(srcYuv); … … 265 251 //collect statistics 266 252 getStatistics(m_statData, orgYuv, srcYuv, pPic); 267 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK268 253 if(isPreDBFSamplesUsed) 269 254 { 270 255 addPreDBFStatistics(m_statData); 271 256 } 272 #endif 273 //slice on/off 274 decidePicParams(sliceEnabled, pPic->getSlice(0)->getDepth()); 275 276 //block on/off 257 //slice on/off 258 decidePicParams(sliceEnabled, pPic->getSlice(0)->getDepth(), saoEncodingRate, saoEncodingRateChroma); 259 260 //block on/off 277 261 SAOBlkParam* reconParams = new SAOBlkParam[m_numCTUsPic]; //temporary parameter buffer for storing reconstructed SAO parameters 278 decideBlkParams(pPic, sliceEnabled, m_statData, srcYuv, resYuv, reconParams, pPic->getPicSym()->getSAOBlkParam() );262 decideBlkParams(pPic, sliceEnabled, m_statData, srcYuv, resYuv, reconParams, pPic->getPicSym()->getSAOBlkParam(), bTestSAODisableAtPictureLevel, saoEncodingRate, saoEncodingRateChroma); 279 263 delete[] reconParams; 280 281 } 282 283 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 264 } 265 284 266 Void TEncSampleAdaptiveOffset::getPreDBFStatistics(TComPic* pPic) 285 267 { … … 291 273 for(Int n=0; n< m_numCTUsPic; n++) 292 274 { 293 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)275 for(Int compIdx=0; compIdx < MAX_NUM_COMPONENT; compIdx++) 294 276 { 295 277 for(Int typeIdc=0; typeIdc < NUM_SAO_NEW_TYPES; typeIdc++) … … 301 283 } 302 284 303 #endif 304 305 Void TEncSampleAdaptiveOffset::getStatistics(SAOStatData*** blkStats, TComPicYuv* orgYuv, TComPicYuv* srcYuv, TComPic* pPic 306 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 307 , Bool isCalculatePreDeblockSamples 308 #endif 309 ) 285 Void TEncSampleAdaptiveOffset::getStatistics(SAOStatData*** blkStats, TComPicYuv* orgYuv, TComPicYuv* srcYuv, TComPic* pPic, Bool isCalculatePreDeblockSamples) 310 286 { 311 287 Bool isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail; 312 288 313 for(Int ctu= 0; ctu < m_numCTUsPic; ctu++) 314 { 315 Int yPos = (ctu / m_numCTUInWidth)*m_maxCUHeight; 316 Int xPos = (ctu % m_numCTUInWidth)*m_maxCUWidth; 289 const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC); 290 291 for(Int ctuRsAddr= 0; ctuRsAddr < m_numCTUsPic; ctuRsAddr++) 292 { 293 Int yPos = (ctuRsAddr / m_numCTUInWidth)*m_maxCUHeight; 294 Int xPos = (ctuRsAddr % m_numCTUInWidth)*m_maxCUWidth; 317 295 Int height = (yPos + m_maxCUHeight > m_picHeight)?(m_picHeight- yPos):m_maxCUHeight; 318 296 Int width = (xPos + m_maxCUWidth > m_picWidth )?(m_picWidth - xPos):m_maxCUWidth; 319 297 320 pPic->getPicSym()->deriveLoopFilterBoundaryAvailibility(ctu , isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail);298 pPic->getPicSym()->deriveLoopFilterBoundaryAvailibility(ctuRsAddr, isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail); 321 299 322 300 //NOTE: The number of skipped lines during gathering CTU statistics depends on the slice boundary availabilities. … … 329 307 isAboveRightAvail = ((yPos > 0) && (isRightAvail)); 330 308 331 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++) 332 { 333 Bool isLuma = (compIdx == SAO_Y); 334 Int formatShift= isLuma?0:1; 335 336 Int srcStride = isLuma?srcYuv->getStride():srcYuv->getCStride(); 337 Pel* srcBlk = getPicBuf(srcYuv, compIdx)+ (yPos >> formatShift)*srcStride+ (xPos >> formatShift); 338 339 Int orgStride = isLuma?orgYuv->getStride():orgYuv->getCStride(); 340 Pel* orgBlk = getPicBuf(orgYuv, compIdx)+ (yPos >> formatShift)*orgStride+ (xPos >> formatShift); 341 342 getBlkStats(compIdx, blkStats[ctu][compIdx] 343 , srcBlk, orgBlk, srcStride, orgStride, (width >> formatShift), (height >> formatShift) 344 , isLeftAvail, isRightAvail, isAboveAvail, isBelowAvail, isAboveLeftAvail, isAboveRightAvail, isBelowLeftAvail, isBelowRightAvail 345 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 309 for(Int compIdx = 0; compIdx < numberOfComponents; compIdx++) 310 { 311 const ComponentID component = ComponentID(compIdx); 312 313 const UInt componentScaleX = getComponentScaleX(component, pPic->getChromaFormat()); 314 const UInt componentScaleY = getComponentScaleY(component, pPic->getChromaFormat()); 315 316 Int srcStride = srcYuv->getStride(component); 317 Pel* srcBlk = srcYuv->getAddr(component) + ((yPos >> componentScaleY) * srcStride) + (xPos >> componentScaleX); 318 319 Int orgStride = orgYuv->getStride(component); 320 Pel* orgBlk = orgYuv->getAddr(component) + ((yPos >> componentScaleY) * orgStride) + (xPos >> componentScaleX); 321 322 getBlkStats(component, pPic->getPicSym()->getSPS().getBitDepth(toChannelType(component)), blkStats[ctuRsAddr][component] 323 , srcBlk, orgBlk, srcStride, orgStride, (width >> componentScaleX), (height >> componentScaleY) 324 , isLeftAvail, isRightAvail, isAboveAvail, isBelowAvail, isAboveLeftAvail, isAboveRightAvail 346 325 , isCalculatePreDeblockSamples 347 #endif348 326 ); 349 327 … … 352 330 } 353 331 354 Void TEncSampleAdaptiveOffset::decidePicParams(Bool* sliceEnabled, Int picTempLayer )332 Void TEncSampleAdaptiveOffset::decidePicParams(Bool* sliceEnabled, Int picTempLayer, const Double saoEncodingRate, const Double saoEncodingRateChroma) 355 333 { 356 334 //decide sliceEnabled[compIdx] 357 for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++) 335 const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC); 336 for (Int compIdx = 0; compIdx < MAX_NUM_COMPONENT; compIdx++) 337 { 338 sliceEnabled[compIdx] = false; 339 } 340 341 for (Int compIdx = 0; compIdx < numberOfComponents; compIdx++) 358 342 { 359 343 // reset flags & counters 360 344 sliceEnabled[compIdx] = true; 361 345 362 #if SAO_ENCODING_CHOICE 363 #if SAO_ENCODING_CHOICE_CHROMA 346 if (saoEncodingRate>0.0) 347 { 348 if (saoEncodingRateChroma>0.0) 349 { 364 350 // decide slice-level on/off based on previous results 365 if( (picTempLayer > 0) 366 && (m_saoDisabledRate[compIdx][picTempLayer-1] > ((compIdx==SAO_Y) ? SAO_ENCODING_RATE : SAO_ENCODING_RATE_CHROMA)) )351 if( (picTempLayer > 0) 352 && (m_saoDisabledRate[compIdx][picTempLayer-1] > ((compIdx==COMPONENT_Y) ? saoEncodingRate : saoEncodingRateChroma)) ) 367 353 { 368 354 sliceEnabled[compIdx] = false; 369 355 } 370 #else 356 } 357 else 358 { 371 359 // decide slice-level on/off based on previous results 372 if( (picTempLayer > 0) 373 && (m_saoDisabledRate[SAO_Y][0] > SAO_ENCODING_RATE) )360 if( (picTempLayer > 0) 361 && (m_saoDisabledRate[COMPONENT_Y][0] > saoEncodingRate) ) 374 362 { 375 363 sliceEnabled[compIdx] = false; 376 364 } 377 #endif 378 #endif 379 } 380 } 381 382 Int64 TEncSampleAdaptiveOffset::getDistortion(Int ctu, Int compIdx, Int typeIdc, Int typeAuxInfo, Int* invQuantOffset, SAOStatData& statData) 383 { 384 Int64 dist=0; 385 Int inputBitDepth = (compIdx == SAO_Y) ? g_bitDepthY : g_bitDepthC ; 386 Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(inputBitDepth-8); 365 } 366 } 367 } 368 } 369 370 Int64 TEncSampleAdaptiveOffset::getDistortion(const Int channelBitDepth, Int typeIdc, Int typeAuxInfo, Int* invQuantOffset, SAOStatData& statData) 371 { 372 Int64 dist = 0; 373 Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(channelBitDepth - 8); 387 374 388 375 switch(typeIdc) … … 396 383 { 397 384 dist += estSaoDist( statData.count[offsetIdx], invQuantOffset[offsetIdx], statData.diff[offsetIdx], shift); 398 } 385 } 399 386 } 400 387 break; … … 403 390 for (Int offsetIdx=typeAuxInfo; offsetIdx<typeAuxInfo+4; offsetIdx++) 404 391 { 405 Int bandIdx = offsetIdx % NUM_SAO_BO_CLASSES ; 392 Int bandIdx = offsetIdx % NUM_SAO_BO_CLASSES ; 406 393 dist += estSaoDist( statData.count[bandIdx], invQuantOffset[bandIdx], statData.diff[bandIdx], shift); 407 394 } … … 425 412 426 413 427 inline Int TEncSampleAdaptiveOffset::estIterOffset(Int typeIdx, Int classIdx,Double lambda, Int offsetInput, Int64 count, Int64 diffSum, Int shift, Int bitIncrease, Int64& bestDist, Double& bestCost, Int offsetTh )414 inline Int TEncSampleAdaptiveOffset::estIterOffset(Int typeIdx, Double lambda, Int offsetInput, Int64 count, Int64 diffSum, Int shift, Int bitIncrease, Int64& bestDist, Double& bestCost, Int offsetTh ) 428 415 { 429 416 Int iterOffset, tempOffset; … … 432 419 Int offsetOutput = 0; 433 420 iterOffset = offsetInput; 434 // Assuming sending quantized value 0 results in zero offset and sending the value zero needs 1 bit. entropy coder can be used to measure the exact rate here. 435 tempMinCost = lambda; 421 // Assuming sending quantized value 0 results in zero offset and sending the value zero needs 1 bit. entropy coder can be used to measure the exact rate here. 422 tempMinCost = lambda; 436 423 while (iterOffset != 0) 437 424 { 438 425 // Calculate the bits required for signaling the offset 439 tempRate = (typeIdx == SAO_TYPE_BO) ? (abs((Int)iterOffset)+2) : (abs((Int)iterOffset)+1); 440 if (abs((Int)iterOffset)==offsetTh) //inclusive 441 { 426 tempRate = (typeIdx == SAO_TYPE_BO) ? (abs((Int)iterOffset)+2) : (abs((Int)iterOffset)+1); 427 if (abs((Int)iterOffset)==offsetTh) //inclusive 428 { 442 429 tempRate --; 443 430 } … … 458 445 } 459 446 460 461 Void TEncSampleAdaptiveOffset::deriveOffsets(Int ctu, Int compIdx, Int typeIdc, SAOStatData& statData, Int* quantOffsets, Int& typeAuxInfo) 462 { 463 Int bitDepth = (compIdx== SAO_Y) ? g_bitDepthY : g_bitDepthC; 464 Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(bitDepth-8); 465 Int offsetTh = g_saoMaxOffsetQVal[compIdx]; //inclusive 447 Void TEncSampleAdaptiveOffset::deriveOffsets(ComponentID compIdx, const Int channelBitDepth, Int typeIdc, SAOStatData& statData, Int* quantOffsets, Int& typeAuxInfo) 448 { 449 Int bitDepth = channelBitDepth; 450 Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(bitDepth-8); 451 Int offsetTh = TComSampleAdaptiveOffset::getMaxOffsetQVal(channelBitDepth); //inclusive 466 452 467 453 ::memset(quantOffsets, 0, sizeof(Int)*MAX_NUM_SAO_CLASSES); 468 454 469 //derive initial offsets 455 //derive initial offsets 470 456 Int numClasses = (typeIdc == SAO_TYPE_BO)?((Int)NUM_SAO_BO_CLASSES):((Int)NUM_SAO_EO_CLASSES); 471 457 for(Int classIdx=0; classIdx< numClasses; classIdx++) 472 458 { 473 if( (typeIdc != SAO_TYPE_BO) && (classIdx==SAO_CLASS_EO_PLAIN) ) 459 if( (typeIdc != SAO_TYPE_BO) && (classIdx==SAO_CLASS_EO_PLAIN) ) 474 460 { 475 461 continue; //offset will be zero … … 481 467 } 482 468 483 quantOffsets[classIdx] = (Int) xRoundIbdi(bitDepth, (Double)( statData.diff[classIdx]<<(bitDepth-8)) 484 / 469 quantOffsets[classIdx] = (Int) xRoundIbdi(bitDepth, (Double)( statData.diff[classIdx]<<(bitDepth-8)) 470 / 485 471 (Double)( statData.count[classIdx]<< m_offsetStepLog2[compIdx]) 486 472 ); … … 498 484 Int64 classDist; 499 485 Double classCost; 500 for(Int classIdx=0; classIdx<NUM_SAO_EO_CLASSES; classIdx++) 501 { 502 if(classIdx==SAO_CLASS_EO_FULL_VALLEY && quantOffsets[classIdx] < 0) quantOffsets[classIdx] =0; 503 if(classIdx==SAO_CLASS_EO_HALF_VALLEY && quantOffsets[classIdx] < 0) quantOffsets[classIdx] =0; 504 if(classIdx==SAO_CLASS_EO_HALF_PEAK && quantOffsets[classIdx] > 0) quantOffsets[classIdx] =0; 505 if(classIdx==SAO_CLASS_EO_FULL_PEAK && quantOffsets[classIdx] > 0) quantOffsets[classIdx] =0; 486 for(Int classIdx=0; classIdx<NUM_SAO_EO_CLASSES; classIdx++) 487 { 488 if(classIdx==SAO_CLASS_EO_FULL_VALLEY && quantOffsets[classIdx] < 0) 489 { 490 quantOffsets[classIdx] =0; 491 } 492 if(classIdx==SAO_CLASS_EO_HALF_VALLEY && quantOffsets[classIdx] < 0) 493 { 494 quantOffsets[classIdx] =0; 495 } 496 if(classIdx==SAO_CLASS_EO_HALF_PEAK && quantOffsets[classIdx] > 0) 497 { 498 quantOffsets[classIdx] =0; 499 } 500 if(classIdx==SAO_CLASS_EO_FULL_PEAK && quantOffsets[classIdx] > 0) 501 { 502 quantOffsets[classIdx] =0; 503 } 506 504 507 505 if( quantOffsets[classIdx] != 0 ) //iterative adjustment only when derived offset is not zero 508 506 { 509 quantOffsets[classIdx] = estIterOffset( typeIdc, classIdx,m_lambda[compIdx], quantOffsets[classIdx], statData.count[classIdx], statData.diff[classIdx], shift, m_offsetStepLog2[compIdx], classDist , classCost , offsetTh );510 } 511 } 512 507 quantOffsets[classIdx] = estIterOffset( typeIdc, m_lambda[compIdx], quantOffsets[classIdx], statData.count[classIdx], statData.diff[classIdx], shift, m_offsetStepLog2[compIdx], classDist , classCost , offsetTh ); 508 } 509 } 510 513 511 typeAuxInfo =0; 514 512 } … … 520 518 ::memset(distBOClasses, 0, sizeof(Int64)*NUM_SAO_BO_CLASSES); 521 519 for(Int classIdx=0; classIdx< NUM_SAO_BO_CLASSES; classIdx++) 522 { 520 { 523 521 costBOClasses[classIdx]= m_lambda[compIdx]; 524 522 if( quantOffsets[classIdx] != 0 ) //iterative adjustment only when derived offset is not zero 525 523 { 526 quantOffsets[classIdx] = estIterOffset( typeIdc, classIdx,m_lambda[compIdx], quantOffsets[classIdx], statData.count[classIdx], statData.diff[classIdx], shift, m_offsetStepLog2[compIdx], distBOClasses[classIdx], costBOClasses[classIdx], offsetTh );524 quantOffsets[classIdx] = estIterOffset( typeIdc, m_lambda[compIdx], quantOffsets[classIdx], statData.count[classIdx], statData.diff[classIdx], shift, m_offsetStepLog2[compIdx], distBOClasses[classIdx], costBOClasses[classIdx], offsetTh ); 527 525 } 528 526 } … … 530 528 //decide the starting band index 531 529 Double minCost = MAX_DOUBLE, cost; 532 for(Int band=0; band< NUM_SAO_BO_CLASSES- 4+ 1; band++) 530 for(Int band=0; band< NUM_SAO_BO_CLASSES- 4+ 1; band++) 533 531 { 534 532 cost = costBOClasses[band ]; … … 546 544 Int clearQuantOffset[NUM_SAO_BO_CLASSES]; 547 545 ::memset(clearQuantOffset, 0, sizeof(Int)*NUM_SAO_BO_CLASSES); 548 for(Int i=0; i< 4; i++) 546 for(Int i=0; i< 4; i++) 549 547 { 550 548 Int band = (typeAuxInfo+i)%NUM_SAO_BO_CLASSES; 551 549 clearQuantOffset[band] = quantOffsets[band]; 552 550 } 553 ::memcpy(quantOffsets, clearQuantOffset, sizeof(Int)*NUM_SAO_BO_CLASSES); 551 ::memcpy(quantOffsets, clearQuantOffset, sizeof(Int)*NUM_SAO_BO_CLASSES); 554 552 } 555 553 break; … … 566 564 } 567 565 568 569 Void TEncSampleAdaptiveOffset::deriveModeNewRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel) 566 Void TEncSampleAdaptiveOffset::deriveModeNewRDO(const BitDepths &bitDepths, Int ctuRsAddr, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES], Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel) 570 567 { 571 568 Double minCost, cost; 572 Int rate;573 569 UInt previousWrittenBits; 574 Int64 dist[NUM_SAO_COMPONENTS], modeDist[NUM_SAO_COMPONENTS]; 575 SAOOffset testOffset[NUM_SAO_COMPONENTS]; 576 Int compIdx; 570 const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC); 571 572 Int64 dist[MAX_NUM_COMPONENT], modeDist[MAX_NUM_COMPONENT]; 573 SAOOffset testOffset[MAX_NUM_COMPONENT]; 577 574 Int invQuantOffset[MAX_NUM_SAO_CLASSES]; 578 579 modeDist[SAO_Y]= modeDist[SAO_Cb] = modeDist[SAO_Cr] = 0; 575 for(Int comp=0; comp < MAX_NUM_COMPONENT; comp++) 576 { 577 modeDist[comp] = 0; 578 } 580 579 581 580 //pre-encode merge flags 582 modeParam[ SAO_Y].modeIdc = SAO_MODE_OFF;581 modeParam[COMPONENT_Y].modeIdc = SAO_MODE_OFF; 583 582 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]); 584 m_pcRDGoOnSbacCoder->codeSAOBlkParam(modeParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), true);583 m_pcRDGoOnSbacCoder->codeSAOBlkParam(modeParam, bitDepths, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), true); 585 584 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]); 586 585 587 //------ luma --------// 588 compIdx = SAO_Y; 589 //"off" case as initial cost 590 modeParam[compIdx].modeIdc = SAO_MODE_OFF; 591 m_pcRDGoOnSbacCoder->resetBits(); 592 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, modeParam[compIdx], sliceEnabled[compIdx]); 593 modeDist[compIdx] = 0; 594 minCost= m_lambda[compIdx]*((Double)m_pcRDGoOnSbacCoder->getNumberOfWrittenBits()); 595 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 596 if(sliceEnabled[compIdx]) 597 { 598 for(Int typeIdc=0; typeIdc< NUM_SAO_NEW_TYPES; typeIdc++) 599 { 600 testOffset[compIdx].modeIdc = SAO_MODE_NEW; 601 testOffset[compIdx].typeIdc = typeIdc; 602 603 //derive coded offset 604 deriveOffsets(ctu, compIdx, typeIdc, blkStats[ctu][compIdx][typeIdc], testOffset[compIdx].offset, testOffset[compIdx].typeAuxInfo); 605 606 //inversed quantized offsets 607 invertQuantOffsets(compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, testOffset[compIdx].offset); 608 609 //get distortion 610 dist[compIdx] = getDistortion(ctu, compIdx, testOffset[compIdx].typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctu][compIdx][typeIdc]); 611 612 //get rate 613 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]); 614 m_pcRDGoOnSbacCoder->resetBits(); 615 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx]); 616 rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 617 cost = (Double)dist[compIdx] + m_lambda[compIdx]*((Double)rate); 618 if(cost < minCost) 619 { 620 minCost = cost; 621 modeDist[compIdx] = dist[compIdx]; 622 modeParam[compIdx]= testOffset[compIdx]; 623 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 624 } 625 } 626 } 627 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 628 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]); 586 //------ luma --------// 587 { 588 const ComponentID compIdx = COMPONENT_Y; 589 //"off" case as initial cost 590 modeParam[compIdx].modeIdc = SAO_MODE_OFF; 591 m_pcRDGoOnSbacCoder->resetBits(); 592 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, modeParam[compIdx], sliceEnabled[compIdx], bitDepths.recon[CHANNEL_TYPE_LUMA]); 593 modeDist[compIdx] = 0; 594 minCost= m_lambda[compIdx]*((Double)m_pcRDGoOnSbacCoder->getNumberOfWrittenBits()); 595 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 596 if(sliceEnabled[compIdx]) 597 { 598 for(Int typeIdc=0; typeIdc< NUM_SAO_NEW_TYPES; typeIdc++) 599 { 600 testOffset[compIdx].modeIdc = SAO_MODE_NEW; 601 testOffset[compIdx].typeIdc = typeIdc; 602 603 //derive coded offset 604 deriveOffsets(compIdx, bitDepths.recon[CHANNEL_TYPE_LUMA], typeIdc, blkStats[ctuRsAddr][compIdx][typeIdc], testOffset[compIdx].offset, testOffset[compIdx].typeAuxInfo); 605 606 //inversed quantized offsets 607 invertQuantOffsets(compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, testOffset[compIdx].offset); 608 609 //get distortion 610 dist[compIdx] = getDistortion(bitDepths.recon[CHANNEL_TYPE_LUMA], testOffset[compIdx].typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctuRsAddr][compIdx][typeIdc]); 611 612 //get rate 613 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]); 614 m_pcRDGoOnSbacCoder->resetBits(); 615 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx], bitDepths.recon[CHANNEL_TYPE_LUMA]); 616 Int rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 617 cost = (Double)dist[compIdx] + m_lambda[compIdx]*((Double)rate); 618 if(cost < minCost) 619 { 620 minCost = cost; 621 modeDist[compIdx] = dist[compIdx]; 622 modeParam[compIdx]= testOffset[compIdx]; 623 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 624 } 625 } 626 } 627 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 628 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]); 629 } 629 630 630 631 //------ chroma --------// 631 632 //"off" case as initial cost 632 633 cost = 0; 633 634 previousWrittenBits = 0; 634 635 m_pcRDGoOnSbacCoder->resetBits(); 635 for (Int component = SAO_Cb; component < NUM_SAO_COMPONENTS; component++) 636 { 637 modeParam[component].modeIdc = SAO_MODE_OFF; 638 modeDist [component] = 0; 639 640 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(component, modeParam[component], sliceEnabled[component]); 641 636 for(UInt componentIndex = COMPONENT_Cb; componentIndex < numberOfComponents; componentIndex++) 637 { 638 const ComponentID component = ComponentID(componentIndex); 639 640 modeParam[component].modeIdc = SAO_MODE_OFF; 641 modeDist [component] = 0; 642 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(component, modeParam[component], sliceEnabled[component], bitDepths.recon[CHANNEL_TYPE_CHROMA]); 643 642 644 const UInt currentWrittenBits = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 643 645 cost += m_lambda[component] * (currentWrittenBits - previousWrittenBits); … … 656 658 cost = 0; 657 659 658 for(compIdx= SAO_Cb; compIdx< NUM_SAO_COMPONENTS; compIdx++) 659 { 660 if(!sliceEnabled[compIdx]) 661 { 662 testOffset[compIdx].modeIdc = SAO_MODE_OFF; 663 dist[compIdx]= 0; 660 for(UInt componentIndex = COMPONENT_Cb; componentIndex < numberOfComponents; componentIndex++) 661 { 662 const ComponentID component = ComponentID(componentIndex); 663 if(!sliceEnabled[component]) 664 { 665 testOffset[component].modeIdc = SAO_MODE_OFF; 666 dist[component]= 0; 664 667 continue; 665 668 } 666 testOffset[comp Idx].modeIdc = SAO_MODE_NEW;667 testOffset[comp Idx].typeIdc = typeIdc;669 testOffset[component].modeIdc = SAO_MODE_NEW; 670 testOffset[component].typeIdc = typeIdc; 668 671 669 672 //derive offset & get distortion 670 deriveOffsets(c tu, compIdx, typeIdc, blkStats[ctu][compIdx][typeIdc], testOffset[compIdx].offset, testOffset[compIdx].typeAuxInfo);671 invertQuantOffsets(comp Idx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, testOffset[compIdx].offset);672 dist[comp Idx]= getDistortion(ctu, compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctu][compIdx][typeIdc]);673 674 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(comp Idx, testOffset[compIdx], sliceEnabled[compIdx]);673 deriveOffsets(component, bitDepths.recon[CHANNEL_TYPE_CHROMA], typeIdc, blkStats[ctuRsAddr][component][typeIdc], testOffset[component].offset, testOffset[component].typeAuxInfo); 674 invertQuantOffsets(component, typeIdc, testOffset[component].typeAuxInfo, invQuantOffset, testOffset[component].offset); 675 dist[component] = getDistortion(bitDepths.recon[CHANNEL_TYPE_CHROMA], typeIdc, testOffset[component].typeAuxInfo, invQuantOffset, blkStats[ctuRsAddr][component][typeIdc]); 676 677 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(component, testOffset[component], sliceEnabled[component], bitDepths.recon[CHANNEL_TYPE_CHROMA]); 675 678 676 679 const UInt currentWrittenBits = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 677 cost += dist[comp Idx] + (m_lambda[compIdx] * (currentWrittenBits - previousWrittenBits));680 cost += dist[component] + (m_lambda[component] * (currentWrittenBits - previousWrittenBits)); 678 681 previousWrittenBits = currentWrittenBits; 679 682 } … … 682 685 { 683 686 minCost = cost; 684 for( compIdx= SAO_Cb; compIdx< NUM_SAO_COMPONENTS; compIdx++)685 { 686 modeDist [compIdx] = dist [compIdx];687 modeParam[comp Idx] = testOffset[compIdx];688 } 689 } 690 } 691 687 for(UInt componentIndex = COMPONENT_Cb; componentIndex < numberOfComponents; componentIndex++) 688 { 689 modeDist[componentIndex] = dist[componentIndex]; 690 modeParam[componentIndex] = testOffset[componentIndex]; 691 } 692 } 693 694 } // SAO_TYPE loop 692 695 693 696 //----- re-gen rate & normalized cost----// 694 697 modeNormCost = 0; 695 for(UInt component = SAO_Y; component < NUM_SAO_COMPONENTS; component++) 696 { 697 modeNormCost += (Double)modeDist[component] / m_lambda[component]; 698 } 698 for(UInt componentIndex = COMPONENT_Y; componentIndex < numberOfComponents; componentIndex++) 699 { 700 modeNormCost += (Double)modeDist[componentIndex] / m_lambda[componentIndex]; 701 } 702 699 703 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]); 700 704 m_pcRDGoOnSbacCoder->resetBits(); 701 m_pcRDGoOnSbacCoder->codeSAOBlkParam(modeParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), false);705 m_pcRDGoOnSbacCoder->codeSAOBlkParam(modeParam, bitDepths, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), false); 702 706 modeNormCost += (Double)m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 703 704 } 705 706 Void TEncSampleAdaptiveOffset::deriveModeMergeRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel) 707 { 708 Int mergeListSize = (Int)mergeList.size(); 707 } 708 709 Void TEncSampleAdaptiveOffset::deriveModeMergeRDO(const BitDepths &bitDepths, Int ctuRsAddr, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES], Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel) 710 { 709 711 modeNormCost = MAX_DOUBLE; 710 712 711 713 Double cost; 712 714 SAOBlkParam testBlkParam; 713 714 for(Int mergeType=0; mergeType< mergeListSize; mergeType++) 715 const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC); 716 717 for(Int mergeType=0; mergeType< NUM_SAO_MERGE_TYPES; mergeType++) 715 718 { 716 719 if(mergeList[mergeType] == NULL) … … 722 725 //normalized distortion 723 726 Double normDist=0; 724 for(Int compIdx =0; compIdx< NUM_SAO_COMPONENTS; compIdx++)727 for(Int compIdx = 0; compIdx < numberOfComponents; compIdx++) 725 728 { 726 729 testBlkParam[compIdx].modeIdc = SAO_MODE_MERGE; … … 732 735 { 733 736 //offsets have been reconstructed. Don't call inversed quantization function. 734 normDist += (((Double)getDistortion( ctu, compIdx, mergedOffsetParam.typeIdc, mergedOffsetParam.typeAuxInfo, mergedOffsetParam.offset, blkStats[ctu][compIdx][mergedOffsetParam.typeIdc]))737 normDist += (((Double)getDistortion(bitDepths.recon[toChannelType(ComponentID(compIdx))], mergedOffsetParam.typeIdc, mergedOffsetParam.typeAuxInfo, mergedOffsetParam.offset, blkStats[ctuRsAddr][compIdx][mergedOffsetParam.typeIdc])) 735 738 /m_lambda[compIdx] 736 739 ); … … 742 745 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]); 743 746 m_pcRDGoOnSbacCoder->resetBits(); 744 m_pcRDGoOnSbacCoder->codeSAOBlkParam(testBlkParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), false);747 m_pcRDGoOnSbacCoder->codeSAOBlkParam(testBlkParam, bitDepths, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), false); 745 748 Int rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 746 749 … … 756 759 757 760 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 758 759 760 } 761 762 Void TEncSampleAdaptiveOffset::decideBlkParams(TComPic* pic, Bool* sliceEnabled, SAOStatData*** blkStats, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam* reconParams, SAOBlkParam* codedParams) 763 { 764 Bool isAllBlksDisabled = false; 765 if(!sliceEnabled[SAO_Y] && !sliceEnabled[SAO_Cb] && !sliceEnabled[SAO_Cr]) 766 { 767 isAllBlksDisabled = true; 761 } 762 763 Void TEncSampleAdaptiveOffset::decideBlkParams(TComPic* pic, Bool* sliceEnabled, SAOStatData*** blkStats, TComPicYuv* srcYuv, TComPicYuv* resYuv, 764 SAOBlkParam* reconParams, SAOBlkParam* codedParams, const Bool bTestSAODisableAtPictureLevel, 765 const Double saoEncodingRate, const Double saoEncodingRateChroma) 766 { 767 Bool allBlksDisabled = true; 768 const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC); 769 for(Int compId = COMPONENT_Y; compId < numberOfComponents; compId++) 770 { 771 if (sliceEnabled[compId]) 772 { 773 allBlksDisabled = false; 774 } 768 775 } 769 776 … … 773 780 Double minCost, modeCost; 774 781 775 for(Int ctu=0; ctu< m_numCTUsPic; ctu++) 776 { 777 if(isAllBlksDisabled) 778 { 779 codedParams[ctu].reset(); 782 783 Double totalCost = 0; // Used if bTestSAODisableAtPictureLevel==true 784 785 for(Int ctuRsAddr=0; ctuRsAddr< m_numCTUsPic; ctuRsAddr++) 786 { 787 if(allBlksDisabled) 788 { 789 codedParams[ctuRsAddr].reset(); 780 790 continue; 781 791 } … … 784 794 785 795 //get merge list 786 std::vector<SAOBlkParam*> mergeList;787 getMergeList(pic, ctu , reconParams, mergeList);796 SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES] = { NULL }; 797 getMergeList(pic, ctuRsAddr, reconParams, mergeList); 788 798 789 799 minCost = MAX_DOUBLE; … … 799 809 case SAO_MODE_NEW: 800 810 { 801 deriveModeNewRDO( ctu, mergeList, sliceEnabled, blkStats, modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR);811 deriveModeNewRDO(pic->getPicSym()->getSPS().getBitDepths(), ctuRsAddr, mergeList, sliceEnabled, blkStats, modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR); 802 812 803 813 } … … 805 815 case SAO_MODE_MERGE: 806 816 { 807 deriveModeMergeRDO( ctu, mergeList, sliceEnabled, blkStats , modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR);817 deriveModeMergeRDO(pic->getPicSym()->getSPS().getBitDepths(), ctuRsAddr, mergeList, sliceEnabled, blkStats , modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR); 808 818 } 809 819 break; … … 816 826 } 817 827 828 D_PRINT_INDENT( g_traceSAOCost, "SAO mode " + n2s( mode ) + " Cost: " + n2s( modeCost) ); 829 818 830 if(modeCost < minCost) 819 831 { 820 832 minCost = modeCost; 821 codedParams[ctu ] = modeParam;833 codedParams[ctuRsAddr] = modeParam; 822 834 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_NEXT ]); 823 824 835 } 825 836 } //mode 837 838 totalCost += minCost; 839 826 840 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_NEXT ]); 827 841 828 842 //apply reconstructed offsets 829 reconParams[ctu] = codedParams[ctu]; 830 reconstructBlkSAOParam(reconParams[ctu], mergeList); 831 offsetCTU(ctu, srcYuv, resYuv, reconParams[ctu], pic); 832 } //ctu 833 834 #if SAO_ENCODING_CHOICE 843 reconParams[ctuRsAddr] = codedParams[ctuRsAddr]; 844 reconstructBlkSAOParam(reconParams[ctuRsAddr], mergeList); 845 offsetCTU(ctuRsAddr, srcYuv, resYuv, reconParams[ctuRsAddr], pic); 846 } //ctuRsAddr 847 848 if (!allBlksDisabled && (totalCost >= 0) && bTestSAODisableAtPictureLevel) //SAO has not beneficial in this case - disable it 849 { 850 for(Int ctuRsAddr = 0; ctuRsAddr < m_numCTUsPic; ctuRsAddr++) 851 { 852 codedParams[ctuRsAddr].reset(); 853 } 854 855 for (UInt componentIndex = 0; componentIndex < MAX_NUM_COMPONENT; componentIndex++) 856 { 857 sliceEnabled[componentIndex] = false; 858 } 859 860 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[ SAO_CABACSTATE_PIC_INIT ]); 861 } 862 863 if (saoEncodingRate > 0.0) 864 { 835 865 Int picTempLayer = pic->getSlice(0)->getDepth(); 836 Int num LcusForSAOOff[NUM_SAO_COMPONENTS];837 numLcusForSAOOff[SAO_Y ] = numLcusForSAOOff[SAO_Cb]= numLcusForSAOOff[SAO_Cr]= 0; 838 839 for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++)840 {841 for(Int ctu =0; ctu< m_numCTUsPic; ctu++)842 { 843 if( reconParams[ctu ][compIdx].modeIdc == SAO_MODE_OFF)844 { 845 num LcusForSAOOff[compIdx]++;846 } 847 } 848 } 849 #if SAO_ENCODING_CHOICE_CHROMA 850 for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++)851 {852 m_saoDisabledRate[compIdx][picTempLayer] = (Double)numLcusForSAOOff[compIdx]/(Double)m_numCTUsPic;853 }854 #else 855 if (picTempLayer == 0)856 {857 m_saoDisabledRate[SAO_Y][0] = (Double)(numLcusForSAOOff[SAO_Y]+numLcusForSAOOff[SAO_Cb]+numLcusForSAOOff[SAO_Cr])/(Double)(m_numCTUsPic*3);858 }859 #endif 860 #endif 861 } 862 863 864 Void TEncSampleAdaptiveOffset::getBlkStats( Int compIdx, SAOStatData* statsDataTypes866 Int numCtusForSAOOff[MAX_NUM_COMPONENT]; 867 868 for (Int compIdx = 0; compIdx < numberOfComponents; compIdx++) 869 { 870 numCtusForSAOOff[compIdx] = 0; 871 for(Int ctuRsAddr=0; ctuRsAddr< m_numCTUsPic; ctuRsAddr++) 872 { 873 if( reconParams[ctuRsAddr][compIdx].modeIdc == SAO_MODE_OFF) 874 { 875 numCtusForSAOOff[compIdx]++; 876 } 877 } 878 } 879 if (saoEncodingRateChroma > 0.0) 880 { 881 for (Int compIdx = 0; compIdx < numberOfComponents; compIdx++) 882 { 883 m_saoDisabledRate[compIdx][picTempLayer] = (Double)numCtusForSAOOff[compIdx]/(Double)m_numCTUsPic; 884 } 885 } 886 else if (picTempLayer == 0) 887 { 888 m_saoDisabledRate[COMPONENT_Y][0] = (Double)(numCtusForSAOOff[COMPONENT_Y]+numCtusForSAOOff[COMPONENT_Cb]+numCtusForSAOOff[COMPONENT_Cr])/(Double)(m_numCTUsPic*3); 889 } 890 } 891 } 892 893 894 Void TEncSampleAdaptiveOffset::getBlkStats(const ComponentID compIdx, const Int channelBitDepth, SAOStatData* statsDataTypes 865 895 , Pel* srcBlk, Pel* orgBlk, Int srcStride, Int orgStride, Int width, Int height 866 , Bool isLeftAvail, Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail 867 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 896 , Bool isLeftAvail, Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail 868 897 , Bool isCalculatePreDeblockSamples 869 #endif870 898 ) 871 899 { … … 874 902 m_lineBufWidth = m_maxCUWidth; 875 903 876 if (m_signLineBuf1) delete[] m_signLineBuf1; m_signLineBuf1 = NULL; 877 m_signLineBuf1 = new Char[m_lineBufWidth+1]; 878 879 if (m_signLineBuf2) delete[] m_signLineBuf2; m_signLineBuf2 = NULL; 904 if (m_signLineBuf1) 905 { 906 delete[] m_signLineBuf1; 907 m_signLineBuf1 = NULL; 908 } 909 m_signLineBuf1 = new Char[m_lineBufWidth+1]; 910 911 if (m_signLineBuf2) 912 { 913 delete[] m_signLineBuf2; 914 m_signLineBuf2 = NULL; 915 } 880 916 m_signLineBuf2 = new Char[m_lineBufWidth+1]; 881 917 } … … 904 940 count+=2; 905 941 endY = (isBelowAvail) ? (height - skipLinesB[typeIdx]) : height; 906 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK907 942 startX = (!isCalculatePreDeblockSamples) ? (isLeftAvail ? 0 : 1) 908 943 : (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1)) 909 944 ; 910 #else911 startX = isLeftAvail ? 0 : 1;912 #endif913 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK914 945 endX = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1)) 915 946 : (isRightAvail ? width : (width - 1)) 916 947 ; 917 #else918 endX = isRightAvail ? (width - skipLinesR[typeIdx]): (width - 1);919 #endif920 948 for (y=0; y<endY; y++) 921 949 { 922 #if SAO_SGN_FUNC923 950 signLeft = (Char)sgn(srcLine[startX] - srcLine[startX-1]); 924 #else925 signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];926 #endif927 951 for (x=startX; x<endX; x++) 928 952 { 929 #if SAO_SGN_FUNC930 953 signRight = (Char)sgn(srcLine[x] - srcLine[x+1]); 931 #else932 signRight = (Char)m_sign[srcLine[x] - srcLine[x+1]];933 #endif934 954 edgeType = signRight + signLeft; 935 955 signLeft = -signRight; … … 941 961 orgLine += orgStride; 942 962 } 943 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK944 963 if(isCalculatePreDeblockSamples) 945 964 { … … 951 970 for(y=0; y<skipLinesB[typeIdx]; y++) 952 971 { 953 #if SAO_SGN_FUNC954 972 signLeft = (Char)sgn(srcLine[startX] - srcLine[startX-1]); 955 #else956 signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];957 #endif958 973 for (x=startX; x<endX; x++) 959 974 { 960 #if SAO_SGN_FUNC961 975 signRight = (Char)sgn(srcLine[x] - srcLine[x+1]); 962 #else963 signRight = (Char)m_sign[srcLine[x] - srcLine[x+1]];964 #endif965 976 edgeType = signRight + signLeft; 966 977 signLeft = -signRight; … … 974 985 } 975 986 } 976 #endif977 987 } 978 988 break; … … 983 993 Char *signUpLine = m_signLineBuf1; 984 994 985 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK986 995 startX = (!isCalculatePreDeblockSamples) ? 0 987 996 : (isRightAvail ? (width - skipLinesR[typeIdx]) : width) 988 997 ; 989 #endif990 998 startY = isAboveAvail ? 0 : 1; 991 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 992 endX = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : width) 999 endX = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : width) 993 1000 : width 994 1001 ; 995 #else996 endX = isRightAvail ? (width - skipLinesR[typeIdx]) : width ;997 #endif998 1002 endY = isBelowAvail ? (height - skipLinesB[typeIdx]) : (height - 1); 999 1003 if (!isAboveAvail) … … 1004 1008 1005 1009 Pel* srcLineAbove = srcLine - srcStride; 1006 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1007 for (x=startX; x<endX; x++) 1008 #else 1009 for (x=0; x< endX; x++) 1010 #endif 1011 { 1012 #if SAO_SGN_FUNC 1010 for (x=startX; x<endX; x++) 1011 { 1013 1012 signUpLine[x] = (Char)sgn(srcLine[x] - srcLineAbove[x]); 1014 #else1015 signUpLine[x] = (Char)m_sign[srcLine[x] - srcLineAbove[x]];1016 #endif1017 1013 } 1018 1014 … … 1022 1018 srcLineBelow = srcLine + srcStride; 1023 1019 1024 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK1025 1020 for (x=startX; x<endX; x++) 1026 #else 1027 for (x=0; x<endX; x++) 1028 #endif 1029 { 1030 #if SAO_SGN_FUNC 1021 { 1031 1022 signDown = (Char)sgn(srcLine[x] - srcLineBelow[x]); 1032 #else1033 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x]];1034 #endif1035 1023 edgeType = signDown + signUpLine[x]; 1036 1024 signUpLine[x]= -signDown; … … 1042 1030 orgLine += orgStride; 1043 1031 } 1044 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK1045 1032 if(isCalculatePreDeblockSamples) 1046 1033 { … … 1057 1044 for (x=startX; x<endX; x++) 1058 1045 { 1059 #if SAO_SGN_FUNC1060 1046 edgeType = sgn(srcLine[x] - srcLineBelow[x]) + sgn(srcLine[x] - srcLineAbove[x]); 1061 #else1062 edgeType = m_sign[srcLine[x] - srcLineBelow[x]] + m_sign[srcLine[x] - srcLineAbove[x]];1063 #endif1064 1047 diff [edgeType] += (orgLine[x] - srcLine[x]); 1065 1048 count[edgeType] ++; … … 1070 1053 } 1071 1054 } 1072 #endif1073 1055 1074 1056 } … … 1083 1065 signDownLine= m_signLineBuf2; 1084 1066 1085 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK1086 1067 startX = (!isCalculatePreDeblockSamples) ? (isLeftAvail ? 0 : 1) 1087 1068 : (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1)) 1088 1069 ; 1089 #else 1090 startX = isLeftAvail ? 0 : 1 ; 1091 #endif 1092 1093 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1070 1094 1071 endX = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]): (width - 1)) 1095 1072 : (isRightAvail ? width : (width - 1)) 1096 1073 ; 1097 #else1098 endX = isRightAvail ? (width - skipLinesR[typeIdx]): (width - 1);1099 #endif1100 1074 endY = isBelowAvail ? (height - skipLinesB[typeIdx]) : (height - 1); 1101 1075 … … 1104 1078 for (x=startX; x<endX+1; x++) 1105 1079 { 1106 #if SAO_SGN_FUNC1107 1080 signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x-1]); 1108 #else1109 signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x-1]];1110 #endif1111 1081 } 1112 1082 1113 1083 //1st line 1114 1084 Pel* srcLineAbove = srcLine - srcStride; 1115 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK1116 1085 firstLineStartX = (!isCalculatePreDeblockSamples) ? (isAboveLeftAvail ? 0 : 1) : startX; 1117 1086 firstLineEndX = (!isCalculatePreDeblockSamples) ? (isAboveAvail ? endX : 1) : endX; 1118 #else1119 firstLineStartX = isAboveLeftAvail ? 0 : 1;1120 firstLineEndX = isAboveAvail ? endX : 1;1121 #endif1122 1087 for(x=firstLineStartX; x<firstLineEndX; x++) 1123 1088 { 1124 #if SAO_SGN_FUNC1125 1089 edgeType = sgn(srcLine[x] - srcLineAbove[x-1]) - signUpLine[x+1]; 1126 #else1127 edgeType = m_sign[srcLine[x] - srcLineAbove[x-1]] - signUpLine[x+1];1128 #endif1129 1090 diff [edgeType] += (orgLine[x] - srcLine[x]); 1130 1091 count[edgeType] ++; … … 1141 1102 for (x=startX; x<endX; x++) 1142 1103 { 1143 #if SAO_SGN_FUNC1144 1104 signDown = (Char)sgn(srcLine[x] - srcLineBelow[x+1]); 1145 #else1146 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x+1]] ;1147 #endif1148 1105 edgeType = signDown + signUpLine[x]; 1149 1106 diff [edgeType] += (orgLine[x] - srcLine[x]); 1150 1107 count[edgeType] ++; 1151 1108 1152 signDownLine[x+1] = -signDown; 1153 } 1154 #if SAO_SGN_FUNC 1109 signDownLine[x+1] = -signDown; 1110 } 1155 1111 signDownLine[startX] = (Char)sgn(srcLineBelow[startX] - srcLine[startX-1]); 1156 #else1157 signDownLine[startX] = (Char)m_sign[srcLineBelow[startX] - srcLine[startX-1]];1158 #endif1159 1112 1160 1113 signTmpLine = signUpLine; … … 1165 1118 orgLine += orgStride; 1166 1119 } 1167 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK1168 1120 if(isCalculatePreDeblockSamples) 1169 1121 { … … 1180 1132 for (x=startX; x< endX; x++) 1181 1133 { 1182 #if SAO_SGN_FUNC1183 1134 edgeType = sgn(srcLine[x] - srcLineBelow[x+1]) + sgn(srcLine[x] - srcLineAbove[x-1]); 1184 #else1185 edgeType = m_sign[srcLine[x] - srcLineBelow[x+1]] + m_sign[srcLine[x] - srcLineAbove[x-1]];1186 #endif1187 1135 diff [edgeType] += (orgLine[x] - srcLine[x]); 1188 1136 count[edgeType] ++; … … 1193 1141 } 1194 1142 } 1195 #endif1196 1143 } 1197 1144 break; … … 1202 1149 Char *signUpLine = m_signLineBuf1+1; 1203 1150 1204 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK1205 1151 startX = (!isCalculatePreDeblockSamples) ? (isLeftAvail ? 0 : 1) 1206 1152 : (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1)) 1207 1153 ; 1208 #else1209 startX = isLeftAvail ? 0 : 1;1210 #endif1211 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK1212 1154 endX = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1)) 1213 1155 : (isRightAvail ? width : (width - 1)) 1214 1156 ; 1215 #else1216 endX = isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1);1217 #endif1218 1157 endY = isBelowAvail ? (height - skipLinesB[typeIdx]) : (height - 1); 1219 1158 … … 1222 1161 for (x=startX-1; x<endX; x++) 1223 1162 { 1224 #if SAO_SGN_FUNC1225 1163 signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x+1]); 1226 #else1227 signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x+1]];1228 #endif1229 1164 } 1230 1165 … … 1232 1167 //first line 1233 1168 Pel* srcLineAbove = srcLine - srcStride; 1234 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK1235 1169 firstLineStartX = (!isCalculatePreDeblockSamples) ? (isAboveAvail ? startX : endX) 1236 1170 : startX … … 1239 1173 : endX 1240 1174 ; 1241 #else1242 firstLineStartX = isAboveAvail ? startX : endX;1243 firstLineEndX = (!isRightAvail && isAboveRightAvail) ? width : endX;1244 #endif1245 1175 for(x=firstLineStartX; x<firstLineEndX; x++) 1246 1176 { 1247 #if SAO_SGN_FUNC1248 1177 edgeType = sgn(srcLine[x] - srcLineAbove[x+1]) - signUpLine[x-1]; 1249 #else1250 edgeType = m_sign[srcLine[x] - srcLineAbove[x+1]] - signUpLine[x-1];1251 #endif1252 1178 diff [edgeType] += (orgLine[x] - srcLine[x]); 1253 1179 count[edgeType] ++; … … 1264 1190 for(x=startX; x<endX; x++) 1265 1191 { 1266 #if SAO_SGN_FUNC1267 1192 signDown = (Char)sgn(srcLine[x] - srcLineBelow[x-1]); 1268 #else1269 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x-1]] ;1270 #endif1271 1193 edgeType = signDown + signUpLine[x]; 1272 1194 … … 1274 1196 count[edgeType] ++; 1275 1197 1276 signUpLine[x-1] = -signDown; 1277 } 1278 #if SAO_SGN_FUNC 1198 signUpLine[x-1] = -signDown; 1199 } 1279 1200 signUpLine[endX-1] = (Char)sgn(srcLineBelow[endX-1] - srcLine[endX]); 1280 #else1281 signUpLine[endX-1] = (Char)m_sign[srcLineBelow[endX-1] - srcLine[endX]];1282 #endif1283 1201 srcLine += srcStride; 1284 1202 orgLine += orgStride; 1285 1203 } 1286 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK1287 1204 if(isCalculatePreDeblockSamples) 1288 1205 { … … 1299 1216 for (x=startX; x<endX; x++) 1300 1217 { 1301 #if SAO_SGN_FUNC1302 1218 edgeType = sgn(srcLine[x] - srcLineBelow[x-1]) + sgn(srcLine[x] - srcLineAbove[x+1]); 1303 #else1304 edgeType = m_sign[srcLine[x] - srcLineBelow[x-1]] + m_sign[srcLine[x] - srcLineAbove[x+1]];1305 #endif1306 1219 diff [edgeType] += (orgLine[x] - srcLine[x]); 1307 1220 count[edgeType] ++; … … 1312 1225 } 1313 1226 } 1314 #endif1315 1227 } 1316 1228 break; 1317 1229 case SAO_TYPE_BO: 1318 1230 { 1319 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK1320 1231 startX = (!isCalculatePreDeblockSamples)?0 1321 1232 :( isRightAvail?(width- skipLinesR[typeIdx]):width) … … 1324 1235 :width 1325 1236 ; 1326 #else1327 endX = isRightAvail ? (width- skipLinesR[typeIdx]) : width;1328 #endif1329 1237 endY = isBelowAvail ? (height- skipLinesB[typeIdx]) : height; 1330 Int shiftBits = ((compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC)- NUM_SAO_BO_CLASSES_LOG2;1238 Int shiftBits = channelBitDepth - NUM_SAO_BO_CLASSES_LOG2; 1331 1239 for (y=0; y< endY; y++) 1332 1240 { 1333 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK1334 1241 for (x=startX; x< endX; x++) 1335 #else 1336 for (x=0; x< endX; x++) 1337 #endif 1338 { 1339 1340 Int bandIdx= srcLine[x] >> shiftBits; 1242 { 1243 1244 Int bandIdx= srcLine[x] >> shiftBits; 1341 1245 diff [bandIdx] += (orgLine[x] - srcLine[x]); 1342 1246 count[bandIdx] ++; … … 1345 1249 orgLine += orgStride; 1346 1250 } 1347 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK1348 1251 if(isCalculatePreDeblockSamples) 1349 1252 { … … 1357 1260 for (x=startX; x< endX; x++) 1358 1261 { 1359 Int bandIdx= srcLine[x] >> shiftBits; 1262 Int bandIdx= srcLine[x] >> shiftBits; 1360 1263 diff [bandIdx] += (orgLine[x] - srcLine[x]); 1361 1264 count[bandIdx] ++; … … 1368 1271 } 1369 1272 } 1370 #endif1371 1273 } 1372 1274 break; … … 1381 1283 } 1382 1284 1285 1383 1286 //! \}
Note: See TracChangeset for help on using the changeset viewer.