Changeset 916 in SHVCSoftware for branches/SHM-upgrade/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
- Timestamp:
- 12 Nov 2014, 08:09:17 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SHM-upgrade/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
r713 r916 2 2 * License, included below. This software may be subject to other third party 3 3 * and contributor rights, including patent rights, and no such rights are 4 * granted under this license. 4 * granted under this license. 5 5 * 6 6 * Copyright (c) 2010-2014, ITU/ISO/IEC … … 32 32 */ 33 33 34 /** 34 /** 35 35 \file TEncSampleAdaptiveOffset.cpp 36 36 \brief estimation part of sample adaptive offset class … … 62 62 TEncSampleAdaptiveOffset::TEncSampleAdaptiveOffset() 63 63 { 64 m_pppcRDSbacCoder = NULL; 64 m_pppcRDSbacCoder = NULL; 65 65 m_pcRDGoOnSbacCoder = NULL; 66 m_pppcBinCoderCABAC = NULL; 66 m_pppcBinCoderCABAC = NULL; 67 67 m_statData = NULL; 68 68 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK … … 85 85 //cabac coder for RDO 86 86 m_pppcRDSbacCoder = new TEncSbac* [NUM_SAO_CABACSTATE_LABELS]; 87 #if FAST_BIT_EST 87 88 m_pppcBinCoderCABAC = new TEncBinCABACCounter* [NUM_SAO_CABACSTATE_LABELS]; 89 #else 90 m_pppcBinCoderCABAC = new TEncBinCABAC* [NUM_SAO_CABACSTATE_LABELS]; 91 #endif 88 92 89 93 for(Int cs=0; cs < NUM_SAO_CABACSTATE_LABELS; cs++) 90 94 { 91 95 m_pppcRDSbacCoder[cs] = new TEncSbac; 96 #if FAST_BIT_EST 92 97 m_pppcBinCoderCABAC[cs] = new TEncBinCABACCounter; 98 #else 99 m_pppcBinCoderCABAC[cs] = new TEncBinCABAC; 100 #endif 93 101 m_pppcRDSbacCoder [cs]->init( m_pppcBinCoderCABAC [cs] ); 94 102 } … … 99 107 for(Int i=0; i< m_numCTUsPic; i++) 100 108 { 101 m_statData[i] = new SAOStatData*[ NUM_SAO_COMPONENTS];102 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)109 m_statData[i] = new SAOStatData*[MAX_NUM_COMPONENT]; 110 for(Int compIdx=0; compIdx < MAX_NUM_COMPONENT; compIdx++) 103 111 { 104 112 m_statData[i][compIdx] = new SAOStatData[NUM_SAO_NEW_TYPES]; … … 111 119 for(Int i=0; i< m_numCTUsPic; i++) 112 120 { 113 m_preDBFstatData[i] = new SAOStatData*[ NUM_SAO_COMPONENTS];114 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)121 m_preDBFstatData[i] = new SAOStatData*[MAX_NUM_COMPONENT]; 122 for(Int compIdx=0; compIdx < MAX_NUM_COMPONENT; compIdx++) 115 123 { 116 124 m_preDBFstatData[i][compIdx] = new SAOStatData[NUM_SAO_NEW_TYPES]; … … 127 135 for(Int typeIdc=0; typeIdc < NUM_SAO_NEW_TYPES; typeIdc++) 128 136 { 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;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]= 4; 141 m_skipLinesB[COMPONENT_Cb][typeIdc]= m_skipLinesB[COMPONENT_Cr][typeIdc]= 2; 134 142 135 143 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK … … 140 148 case SAO_TYPE_EO_0: 141 149 { 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;150 m_skipLinesR[COMPONENT_Y ][typeIdc]= 5; 151 m_skipLinesR[COMPONENT_Cb][typeIdc]= m_skipLinesR[COMPONENT_Cr][typeIdc]= 3; 152 153 m_skipLinesB[COMPONENT_Y ][typeIdc]= 3; 154 m_skipLinesB[COMPONENT_Cb][typeIdc]= m_skipLinesB[COMPONENT_Cr][typeIdc]= 1; 147 155 } 148 156 break; 149 157 case SAO_TYPE_EO_90: 150 158 { 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;159 m_skipLinesR[COMPONENT_Y ][typeIdc]= 4; 160 m_skipLinesR[COMPONENT_Cb][typeIdc]= m_skipLinesR[COMPONENT_Cr][typeIdc]= 2; 161 162 m_skipLinesB[COMPONENT_Y ][typeIdc]= 4; 163 m_skipLinesB[COMPONENT_Cb][typeIdc]= m_skipLinesB[COMPONENT_Cr][typeIdc]= 2; 156 164 } 157 165 break; … … 159 167 case SAO_TYPE_EO_45: 160 168 { 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;169 m_skipLinesR[COMPONENT_Y ][typeIdc]= 5; 170 m_skipLinesR[COMPONENT_Cb][typeIdc]= m_skipLinesR[COMPONENT_Cr][typeIdc]= 3; 171 172 m_skipLinesB[COMPONENT_Y ][typeIdc]= 4; 173 m_skipLinesB[COMPONENT_Cb][typeIdc]= m_skipLinesB[COMPONENT_Cr][typeIdc]= 2; 166 174 } 167 175 break; 168 176 case SAO_TYPE_BO: 169 177 { 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;178 m_skipLinesR[COMPONENT_Y ][typeIdc]= 4; 179 m_skipLinesR[COMPONENT_Cb][typeIdc]= m_skipLinesR[COMPONENT_Cr][typeIdc]= 2; 180 181 m_skipLinesB[COMPONENT_Y ][typeIdc]= 3; 182 m_skipLinesB[COMPONENT_Cb][typeIdc]= m_skipLinesB[COMPONENT_Cr][typeIdc]= 1; 175 183 } 176 184 break; … … 183 191 } 184 192 } 185 #endif 193 #endif 186 194 } 187 195 … … 212 220 for(Int i=0; i< m_numCTUsPic; i++) 213 221 { 214 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)222 for(Int compIdx=0; compIdx< MAX_NUM_COMPONENT; compIdx++) 215 223 { 216 224 delete[] m_statData[i][compIdx]; … … 225 233 for(Int i=0; i< m_numCTUsPic; i++) 226 234 { 227 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)235 for(Int compIdx=0; compIdx< MAX_NUM_COMPONENT; compIdx++) 228 236 { 229 237 delete[] m_preDBFstatData[i][compIdx]; … … 237 245 } 238 246 239 Void TEncSampleAdaptiveOffset::initRDOCabacCoder(TEncSbac* pcRDGoOnSbacCoder, TComSlice* pcSlice) 247 Void TEncSampleAdaptiveOffset::initRDOCabacCoder(TEncSbac* pcRDGoOnSbacCoder, TComSlice* pcSlice) 240 248 { 241 249 m_pcRDGoOnSbacCoder = pcRDGoOnSbacCoder; … … 257 265 TComPicYuv* orgYuv= pPic->getPicYuvOrg(); 258 266 TComPicYuv* resYuv= pPic->getPicYuvRec(); 259 m _lambda[SAO_Y]= lambdas[0]; m_lambda[SAO_Cb]= lambdas[1]; m_lambda[SAO_Cr]= lambdas[2];267 memcpy(m_lambda, lambdas, sizeof(m_lambda)); 260 268 TComPicYuv* srcYuv = m_tempPicYuv; 261 269 resYuv->copyToPic(srcYuv); … … 271 279 } 272 280 #endif 273 //slice on/off 274 decidePicParams(sliceEnabled, pPic->getSlice(0)->getDepth()); 275 276 //block on/off 281 //slice on/off 282 decidePicParams(sliceEnabled, pPic->getSlice(0)->getDepth()); 283 284 //block on/off 277 285 SAOBlkParam* reconParams = new SAOBlkParam[m_numCTUsPic]; //temporary parameter buffer for storing reconstructed SAO parameters 278 286 decideBlkParams(pPic, sliceEnabled, m_statData, srcYuv, resYuv, reconParams, pPic->getPicSym()->getSAOBlkParam()); 279 287 delete[] reconParams; 280 281 288 } 282 289 … … 291 298 for(Int n=0; n< m_numCTUsPic; n++) 292 299 { 293 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)300 for(Int compIdx=0; compIdx < MAX_NUM_COMPONENT; compIdx++) 294 301 { 295 302 for(Int typeIdc=0; typeIdc < NUM_SAO_NEW_TYPES; typeIdc++) … … 311 318 Bool isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail; 312 319 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; 320 const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC); 321 322 for(Int ctuRsAddr= 0; ctuRsAddr < m_numCTUsPic; ctuRsAddr++) 323 { 324 Int yPos = (ctuRsAddr / m_numCTUInWidth)*m_maxCUHeight; 325 Int xPos = (ctuRsAddr % m_numCTUInWidth)*m_maxCUWidth; 317 326 Int height = (yPos + m_maxCUHeight > m_picHeight)?(m_picHeight- yPos):m_maxCUHeight; 318 327 Int width = (xPos + m_maxCUWidth > m_picWidth )?(m_picWidth - xPos):m_maxCUWidth; 319 328 320 pPic->getPicSym()->deriveLoopFilterBoundaryAvailibility(ctu , isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail);329 pPic->getPicSym()->deriveLoopFilterBoundaryAvailibility(ctuRsAddr, isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail); 321 330 322 331 //NOTE: The number of skipped lines during gathering CTU statistics depends on the slice boundary availabilities. … … 329 338 isAboveRightAvail = ((yPos > 0) && (isRightAvail)); 330 339 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) 340 for(Int compIdx = 0; compIdx < numberOfComponents; compIdx++) 341 { 342 const ComponentID component = ComponentID(compIdx); 343 344 const UInt componentScaleX = getComponentScaleX(component, pPic->getChromaFormat()); 345 const UInt componentScaleY = getComponentScaleY(component, pPic->getChromaFormat()); 346 347 Int srcStride = srcYuv->getStride(component); 348 Pel* srcBlk = srcYuv->getAddr(component) + ((yPos >> componentScaleY) * srcStride) + (xPos >> componentScaleX); 349 350 Int orgStride = orgYuv->getStride(component); 351 Pel* orgBlk = orgYuv->getAddr(component) + ((yPos >> componentScaleY) * orgStride) + (xPos >> componentScaleX); 352 353 getBlkStats(component, blkStats[ctuRsAddr][component] 354 , srcBlk, orgBlk, srcStride, orgStride, (width >> componentScaleX), (height >> componentScaleY) 344 355 , isLeftAvail, isRightAvail, isAboveAvail, isBelowAvail, isAboveLeftAvail, isAboveRightAvail, isBelowLeftAvail, isBelowRightAvail 345 356 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK … … 355 366 { 356 367 //decide sliceEnabled[compIdx] 357 for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++) 368 const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC); 369 for (Int compIdx = 0; compIdx < MAX_NUM_COMPONENT; compIdx++) 370 { 371 sliceEnabled[compIdx] = false; 372 } 373 374 for (Int compIdx = 0; compIdx < numberOfComponents; compIdx++) 358 375 { 359 376 // reset flags & counters … … 363 380 #if SAO_ENCODING_CHOICE_CHROMA 364 381 // 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)) )382 if( (picTempLayer > 0) 383 && (m_saoDisabledRate[compIdx][picTempLayer-1] > ((compIdx==COMPONENT_Y) ? SAO_ENCODING_RATE : SAO_ENCODING_RATE_CHROMA)) ) 367 384 { 368 385 sliceEnabled[compIdx] = false; … … 370 387 #else 371 388 // decide slice-level on/off based on previous results 372 if( (picTempLayer > 0) 373 && (m_saoDisabledRate[ SAO_Y][0] > SAO_ENCODING_RATE) )389 if( (picTempLayer > 0) 390 && (m_saoDisabledRate[COMPONENT_Y][0] > SAO_ENCODING_RATE) ) 374 391 { 375 392 sliceEnabled[compIdx] = false; … … 380 397 } 381 398 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); 399 Int64 TEncSampleAdaptiveOffset::getDistortion(ComponentID compIdx, Int typeIdc, Int typeAuxInfo, Int* invQuantOffset, SAOStatData& statData) 400 { 401 Int64 dist = 0; 402 Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(g_bitDepth[toChannelType(compIdx)] - 8); 387 403 388 404 switch(typeIdc) … … 396 412 { 397 413 dist += estSaoDist( statData.count[offsetIdx], invQuantOffset[offsetIdx], statData.diff[offsetIdx], shift); 398 } 414 } 399 415 } 400 416 break; … … 403 419 for (Int offsetIdx=typeAuxInfo; offsetIdx<typeAuxInfo+4; offsetIdx++) 404 420 { 405 Int bandIdx = offsetIdx % NUM_SAO_BO_CLASSES ; 421 Int bandIdx = offsetIdx % NUM_SAO_BO_CLASSES ; 406 422 dist += estSaoDist( statData.count[bandIdx], invQuantOffset[bandIdx], statData.diff[bandIdx], shift); 407 423 } … … 432 448 Int offsetOutput = 0; 433 449 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; 450 // 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. 451 tempMinCost = lambda; 436 452 while (iterOffset != 0) 437 453 { 438 454 // 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 { 455 tempRate = (typeIdx == SAO_TYPE_BO) ? (abs((Int)iterOffset)+2) : (abs((Int)iterOffset)+1); 456 if (abs((Int)iterOffset)==offsetTh) //inclusive 457 { 442 458 tempRate --; 443 459 } … … 458 474 } 459 475 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); 476 Void TEncSampleAdaptiveOffset::deriveOffsets(ComponentID compIdx, Int typeIdc, SAOStatData& statData, Int* quantOffsets, Int& typeAuxInfo) 477 { 478 Int bitDepth = g_bitDepth[toChannelType(compIdx)]; 479 Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(bitDepth-8); 465 480 #if SVC_EXTENSION 466 481 Int offsetTh = getSaoMaxOffsetQVal()[compIdx]; //inclusive … … 471 486 ::memset(quantOffsets, 0, sizeof(Int)*MAX_NUM_SAO_CLASSES); 472 487 473 //derive initial offsets 488 //derive initial offsets 474 489 Int numClasses = (typeIdc == SAO_TYPE_BO)?((Int)NUM_SAO_BO_CLASSES):((Int)NUM_SAO_EO_CLASSES); 475 490 for(Int classIdx=0; classIdx< numClasses; classIdx++) 476 491 { 477 if( (typeIdc != SAO_TYPE_BO) && (classIdx==SAO_CLASS_EO_PLAIN) ) 492 if( (typeIdc != SAO_TYPE_BO) && (classIdx==SAO_CLASS_EO_PLAIN) ) 478 493 { 479 494 continue; //offset will be zero … … 485 500 } 486 501 487 quantOffsets[classIdx] = (Int) xRoundIbdi(bitDepth, (Double)( statData.diff[classIdx]<<(bitDepth-8)) 488 / 502 quantOffsets[classIdx] = (Int) xRoundIbdi(bitDepth, (Double)( statData.diff[classIdx]<<(bitDepth-8)) 503 / 489 504 (Double)( statData.count[classIdx]<< m_offsetStepLog2[compIdx]) 490 505 ); … … 502 517 Int64 classDist; 503 518 Double classCost; 504 for(Int classIdx=0; classIdx<NUM_SAO_EO_CLASSES; classIdx++) 505 { 519 for(Int classIdx=0; classIdx<NUM_SAO_EO_CLASSES; classIdx++) 520 { 506 521 if(classIdx==SAO_CLASS_EO_FULL_VALLEY && quantOffsets[classIdx] < 0) quantOffsets[classIdx] =0; 507 522 if(classIdx==SAO_CLASS_EO_HALF_VALLEY && quantOffsets[classIdx] < 0) quantOffsets[classIdx] =0; … … 514 529 } 515 530 } 516 531 517 532 typeAuxInfo =0; 518 533 } … … 524 539 ::memset(distBOClasses, 0, sizeof(Int64)*NUM_SAO_BO_CLASSES); 525 540 for(Int classIdx=0; classIdx< NUM_SAO_BO_CLASSES; classIdx++) 526 { 541 { 527 542 costBOClasses[classIdx]= m_lambda[compIdx]; 528 543 if( quantOffsets[classIdx] != 0 ) //iterative adjustment only when derived offset is not zero … … 534 549 //decide the starting band index 535 550 Double minCost = MAX_DOUBLE, cost; 536 for(Int band=0; band< NUM_SAO_BO_CLASSES- 4+ 1; band++) 551 for(Int band=0; band< NUM_SAO_BO_CLASSES- 4+ 1; band++) 537 552 { 538 553 cost = costBOClasses[band ]; … … 550 565 Int clearQuantOffset[NUM_SAO_BO_CLASSES]; 551 566 ::memset(clearQuantOffset, 0, sizeof(Int)*NUM_SAO_BO_CLASSES); 552 for(Int i=0; i< 4; i++) 567 for(Int i=0; i< 4; i++) 553 568 { 554 569 Int band = (typeAuxInfo+i)%NUM_SAO_BO_CLASSES; 555 570 clearQuantOffset[band] = quantOffsets[band]; 556 571 } 557 ::memcpy(quantOffsets, clearQuantOffset, sizeof(Int)*NUM_SAO_BO_CLASSES); 572 ::memcpy(quantOffsets, clearQuantOffset, sizeof(Int)*NUM_SAO_BO_CLASSES); 558 573 } 559 574 break; … … 570 585 } 571 586 572 573 Void TEncSampleAdaptiveOffset::deriveModeNewRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel) 587 Void TEncSampleAdaptiveOffset::deriveModeNewRDO(Int ctuRsAddr, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES], Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel) 574 588 { 575 589 Double minCost, cost; 576 Int rate;577 590 UInt previousWrittenBits; 578 Int64 dist[NUM_SAO_COMPONENTS], modeDist[NUM_SAO_COMPONENTS]; 579 SAOOffset testOffset[NUM_SAO_COMPONENTS]; 580 Int compIdx; 591 const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC); 592 593 Int64 dist[MAX_NUM_COMPONENT], modeDist[MAX_NUM_COMPONENT]; 594 SAOOffset testOffset[MAX_NUM_COMPONENT]; 581 595 Int invQuantOffset[MAX_NUM_SAO_CLASSES]; 582 583 modeDist[SAO_Y]= modeDist[SAO_Cb] = modeDist[SAO_Cr] = 0; 596 for(Int comp=0; comp < MAX_NUM_COMPONENT; comp++) 597 { 598 modeDist[comp] = 0; 599 } 584 600 585 601 //pre-encode merge flags 586 modeParam[ SAO_Y].modeIdc = SAO_MODE_OFF;602 modeParam[COMPONENT_Y].modeIdc = SAO_MODE_OFF; 587 603 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]); 588 604 #if SVC_EXTENSION … … 593 609 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]); 594 610 595 //------ luma --------// 596 compIdx = SAO_Y; 597 //"off" case as initial cost 598 modeParam[compIdx].modeIdc = SAO_MODE_OFF; 599 m_pcRDGoOnSbacCoder->resetBits(); 611 //------ luma --------// 612 { 613 ComponentID compIdx = COMPONENT_Y; 614 //"off" case as initial cost 615 modeParam[compIdx].modeIdc = SAO_MODE_OFF; 616 m_pcRDGoOnSbacCoder->resetBits(); 600 617 #if SVC_EXTENSION 601 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, modeParam[compIdx], sliceEnabled[compIdx], getSaoMaxOffsetQVal());602 #else 603 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, modeParam[compIdx], sliceEnabled[compIdx]);604 #endif 605 modeDist[compIdx] = 0;606 minCost= m_lambda[compIdx]*((Double)m_pcRDGoOnSbacCoder->getNumberOfWrittenBits());607 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);608 if(sliceEnabled[compIdx])609 {610 for(Int typeIdc=0; typeIdc< NUM_SAO_NEW_TYPES; typeIdc++)611 {612 testOffset[compIdx].modeIdc = SAO_MODE_NEW;613 testOffset[compIdx].typeIdc = typeIdc;614 615 //derive coded offset616 deriveOffsets(ctu, compIdx, typeIdc, blkStats[ctu][compIdx][typeIdc], testOffset[compIdx].offset, testOffset[compIdx].typeAuxInfo);617 618 //inversed quantized offsets619 invertQuantOffsets(compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, testOffset[compIdx].offset);620 621 //get distortion622 dist[compIdx] = getDistortion(ctu, compIdx, testOffset[compIdx].typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctu][compIdx][typeIdc]);623 624 //get rate625 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]);626 m_pcRDGoOnSbacCoder->resetBits();618 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, modeParam[compIdx], sliceEnabled[compIdx], getSaoMaxOffsetQVal()); 619 #else 620 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, modeParam[compIdx], sliceEnabled[compIdx]); 621 #endif 622 modeDist[compIdx] = 0; 623 minCost= m_lambda[compIdx]*((Double)m_pcRDGoOnSbacCoder->getNumberOfWrittenBits()); 624 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 625 if(sliceEnabled[compIdx]) 626 { 627 for(Int typeIdc=0; typeIdc< NUM_SAO_NEW_TYPES; typeIdc++) 628 { 629 testOffset[compIdx].modeIdc = SAO_MODE_NEW; 630 testOffset[compIdx].typeIdc = typeIdc; 631 632 //derive coded offset 633 deriveOffsets(compIdx, typeIdc, blkStats[ctuRsAddr][compIdx][typeIdc], testOffset[compIdx].offset, testOffset[compIdx].typeAuxInfo); 634 635 //inversed quantized offsets 636 invertQuantOffsets(compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, testOffset[compIdx].offset); 637 638 //get distortion 639 dist[compIdx] = getDistortion(compIdx, testOffset[compIdx].typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctuRsAddr][compIdx][typeIdc]); 640 641 //get rate 642 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]); 643 m_pcRDGoOnSbacCoder->resetBits(); 627 644 #if SVC_EXTENSION 628 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx], getSaoMaxOffsetQVal()); 629 #else 630 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx]); 631 #endif 632 rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 633 cost = (Double)dist[compIdx] + m_lambda[compIdx]*((Double)rate); 634 if(cost < minCost) 635 { 636 minCost = cost; 637 modeDist[compIdx] = dist[compIdx]; 638 modeParam[compIdx]= testOffset[compIdx]; 639 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 640 } 641 } 642 } 643 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 644 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]); 645 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx], getSaoMaxOffsetQVal()); 646 #else 647 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx]); 648 #endif 649 Int rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 650 cost = (Double)dist[compIdx] + m_lambda[compIdx]*((Double)rate); 651 if(cost < minCost) 652 { 653 minCost = cost; 654 modeDist[compIdx] = dist[compIdx]; 655 modeParam[compIdx]= testOffset[compIdx]; 656 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 657 } 658 } 659 } 660 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 661 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]); 662 } 645 663 646 664 //------ chroma --------// 647 665 //"off" case as initial cost 648 666 cost = 0; 649 667 previousWrittenBits = 0; 650 668 m_pcRDGoOnSbacCoder->resetBits(); 651 for (Int component = SAO_Cb; component < NUM_SAO_COMPONENTS; component++) 652 { 653 modeParam[component].modeIdc = SAO_MODE_OFF; 654 modeDist [component] = 0; 669 for(UInt componentIndex = COMPONENT_Cb; componentIndex < numberOfComponents; componentIndex++) 670 { 671 const ComponentID component = ComponentID(componentIndex); 672 673 modeParam[component].modeIdc = SAO_MODE_OFF; 674 modeDist [component] = 0; 655 675 656 676 #if SVC_EXTENSION … … 676 696 cost = 0; 677 697 678 for(compIdx= SAO_Cb; compIdx< NUM_SAO_COMPONENTS; compIdx++) 679 { 680 if(!sliceEnabled[compIdx]) 681 { 682 testOffset[compIdx].modeIdc = SAO_MODE_OFF; 683 dist[compIdx]= 0; 698 for(UInt componentIndex = COMPONENT_Cb; componentIndex < numberOfComponents; componentIndex++) 699 { 700 const ComponentID component = ComponentID(componentIndex); 701 if(!sliceEnabled[component]) 702 { 703 testOffset[component].modeIdc = SAO_MODE_OFF; 704 dist[component]= 0; 684 705 continue; 685 706 } 686 testOffset[comp Idx].modeIdc = SAO_MODE_NEW;687 testOffset[comp Idx].typeIdc = typeIdc;707 testOffset[component].modeIdc = SAO_MODE_NEW; 708 testOffset[component].typeIdc = typeIdc; 688 709 689 710 //derive offset & get distortion 690 deriveOffsets(c tu, compIdx, typeIdc, blkStats[ctu][compIdx][typeIdc], testOffset[compIdx].offset, testOffset[compIdx].typeAuxInfo);691 invertQuantOffsets(comp Idx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, testOffset[compIdx].offset);692 dist[comp Idx]= getDistortion(ctu, compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctu][compIdx][typeIdc]);711 deriveOffsets(component, typeIdc, blkStats[ctuRsAddr][component][typeIdc], testOffset[component].offset, testOffset[component].typeAuxInfo); 712 invertQuantOffsets(component, typeIdc, testOffset[component].typeAuxInfo, invQuantOffset, testOffset[component].offset); 713 dist[component] = getDistortion(component, typeIdc, testOffset[component].typeAuxInfo, invQuantOffset, blkStats[ctuRsAddr][component][typeIdc]); 693 714 694 715 #if SVC_EXTENSION 695 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(comp Idx, testOffset[compIdx], sliceEnabled[compIdx], getSaoMaxOffsetQVal());696 #else 697 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(comp Idx, testOffset[compIdx], sliceEnabled[compIdx]);716 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(component, testOffset[component], sliceEnabled[component], getSaoMaxOffsetQVal()); 717 #else 718 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(component, testOffset[component], sliceEnabled[component]); 698 719 #endif 699 720 700 721 const UInt currentWrittenBits = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 701 cost += dist[comp Idx] + (m_lambda[compIdx] * (currentWrittenBits - previousWrittenBits));722 cost += dist[component] + (m_lambda[component] * (currentWrittenBits - previousWrittenBits)); 702 723 previousWrittenBits = currentWrittenBits; 703 724 } … … 706 727 { 707 728 minCost = cost; 708 for( compIdx= SAO_Cb; compIdx< NUM_SAO_COMPONENTS; compIdx++)709 { 710 modeDist [compIdx] = dist [compIdx];711 modeParam[comp Idx] = testOffset[compIdx];712 } 713 } 714 } 715 729 for(UInt componentIndex = COMPONENT_Cb; componentIndex < numberOfComponents; componentIndex++) 730 { 731 modeDist[componentIndex] = dist[componentIndex]; 732 modeParam[componentIndex] = testOffset[componentIndex]; 733 } 734 } 735 736 } // SAO_TYPE loop 716 737 717 738 //----- re-gen rate & normalized cost----// 718 739 modeNormCost = 0; 719 for(UInt component = SAO_Y; component < NUM_SAO_COMPONENTS; component++) 720 { 721 modeNormCost += (Double)modeDist[component] / m_lambda[component]; 722 } 740 for(UInt componentIndex = COMPONENT_Y; componentIndex < numberOfComponents; componentIndex++) 741 { 742 modeNormCost += (Double)modeDist[componentIndex] / m_lambda[componentIndex]; 743 } 744 723 745 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]); 724 746 m_pcRDGoOnSbacCoder->resetBits(); … … 729 751 #endif 730 752 modeNormCost += (Double)m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 731 732 } 733 734 Void TEncSampleAdaptiveOffset::deriveModeMergeRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel) 735 { 736 Int mergeListSize = (Int)mergeList.size(); 753 } 754 755 Void TEncSampleAdaptiveOffset::deriveModeMergeRDO(Int ctuRsAddr, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES], Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel) 756 { 737 757 modeNormCost = MAX_DOUBLE; 738 758 739 759 Double cost; 740 760 SAOBlkParam testBlkParam; 741 742 for(Int mergeType=0; mergeType< mergeListSize; mergeType++) 761 const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC); 762 763 for(Int mergeType=0; mergeType< NUM_SAO_MERGE_TYPES; mergeType++) 743 764 { 744 765 if(mergeList[mergeType] == NULL) … … 750 771 //normalized distortion 751 772 Double normDist=0; 752 for(Int compIdx =0; compIdx< NUM_SAO_COMPONENTS; compIdx++)773 for(Int compIdx = 0; compIdx < numberOfComponents; compIdx++) 753 774 { 754 775 testBlkParam[compIdx].modeIdc = SAO_MODE_MERGE; … … 760 781 { 761 782 //offsets have been reconstructed. Don't call inversed quantization function. 762 normDist += (((Double)getDistortion( ctu, compIdx, mergedOffsetParam.typeIdc, mergedOffsetParam.typeAuxInfo, mergedOffsetParam.offset, blkStats[ctu][compIdx][mergedOffsetParam.typeIdc]))783 normDist += (((Double)getDistortion(ComponentID(compIdx), mergedOffsetParam.typeIdc, mergedOffsetParam.typeAuxInfo, mergedOffsetParam.offset, blkStats[ctuRsAddr][compIdx][mergedOffsetParam.typeIdc])) 763 784 /m_lambda[compIdx] 764 785 ); … … 788 809 789 810 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 790 791 792 811 } 793 812 794 813 Void TEncSampleAdaptiveOffset::decideBlkParams(TComPic* pic, Bool* sliceEnabled, SAOStatData*** blkStats, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam* reconParams, SAOBlkParam* codedParams) 795 814 { 796 Bool isAllBlksDisabled = false; 797 if(!sliceEnabled[SAO_Y] && !sliceEnabled[SAO_Cb] && !sliceEnabled[SAO_Cr]) 798 { 799 isAllBlksDisabled = true; 815 Bool allBlksDisabled = true; 816 const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC); 817 for(Int compId = COMPONENT_Y; compId < numberOfComponents; compId++) 818 { 819 if (sliceEnabled[compId]) 820 allBlksDisabled = false; 800 821 } 801 822 … … 805 826 Double minCost, modeCost; 806 827 807 for(Int ctu=0; ctu< m_numCTUsPic; ctu++) 808 { 809 if(isAllBlksDisabled) 810 { 811 codedParams[ctu].reset(); 828 829 #if RD_TEST_SAO_DISABLE_AT_PICTURE_LEVEL 830 Double totalCost = 0; 831 #endif 832 833 for(Int ctuRsAddr=0; ctuRsAddr< m_numCTUsPic; ctuRsAddr++) 834 { 835 if(allBlksDisabled) 836 { 837 codedParams[ctuRsAddr].reset(); 812 838 continue; 813 839 } … … 816 842 817 843 //get merge list 818 std::vector<SAOBlkParam*> mergeList;819 getMergeList(pic, ctu , reconParams, mergeList);844 SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES] = { NULL }; 845 getMergeList(pic, ctuRsAddr, reconParams, mergeList); 820 846 821 847 minCost = MAX_DOUBLE; … … 831 857 case SAO_MODE_NEW: 832 858 { 833 deriveModeNewRDO(ctu , mergeList, sliceEnabled, blkStats, modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR);859 deriveModeNewRDO(ctuRsAddr, mergeList, sliceEnabled, blkStats, modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR); 834 860 835 861 } … … 837 863 case SAO_MODE_MERGE: 838 864 { 839 deriveModeMergeRDO(ctu , mergeList, sliceEnabled, blkStats , modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR);865 deriveModeMergeRDO(ctuRsAddr, mergeList, sliceEnabled, blkStats , modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR); 840 866 } 841 867 break; … … 851 877 { 852 878 minCost = modeCost; 853 codedParams[ctu ] = modeParam;879 codedParams[ctuRsAddr] = modeParam; 854 880 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_NEXT ]); 855 856 881 } 857 882 } //mode 883 884 #if RD_TEST_SAO_DISABLE_AT_PICTURE_LEVEL 885 totalCost += minCost; 886 #endif 887 858 888 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_NEXT ]); 859 889 860 890 //apply reconstructed offsets 861 reconParams[ctu] = codedParams[ctu]; 862 reconstructBlkSAOParam(reconParams[ctu], mergeList); 863 offsetCTU(ctu, srcYuv, resYuv, reconParams[ctu], pic); 864 } //ctu 865 866 #if SAO_ENCODING_CHOICE 891 reconParams[ctuRsAddr] = codedParams[ctuRsAddr]; 892 reconstructBlkSAOParam(reconParams[ctuRsAddr], mergeList); 893 offsetCTU(ctuRsAddr, srcYuv, resYuv, reconParams[ctuRsAddr], pic); 894 } //ctuRsAddr 895 896 #if RD_TEST_SAO_DISABLE_AT_PICTURE_LEVEL 897 if (!allBlksDisabled && (totalCost >= 0)) //SAO is not beneficial - disable it 898 { 899 for(Int ctuRsAddr = 0; ctuRsAddr < m_numCTUsPic; ctuRsAddr++) 900 { 901 codedParams[ctuRsAddr].reset(); 902 } 903 904 for (UInt componentIndex = 0; componentIndex < MAX_NUM_COMPONENT; componentIndex++) 905 { 906 sliceEnabled[componentIndex] = false; 907 } 908 909 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[ SAO_CABACSTATE_PIC_INIT ]); 910 } 911 #endif 912 913 #if SAO_ENCODING_CHOICE 867 914 Int picTempLayer = pic->getSlice(0)->getDepth(); 868 Int num LcusForSAOOff[NUM_SAO_COMPONENTS];869 numLcusForSAOOff[SAO_Y ] = numLcusForSAOOff[SAO_Cb]= numLcusForSAOOff[SAO_Cr]= 0; 870 871 for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++)872 {873 for(Int ctu =0; ctu< m_numCTUsPic; ctu++)874 { 875 if( reconParams[ctu ][compIdx].modeIdc == SAO_MODE_OFF)876 { 877 num LcusForSAOOff[compIdx]++;915 Int numCtusForSAOOff[MAX_NUM_COMPONENT]; 916 917 for (Int compIdx = 0; compIdx < numberOfComponents; compIdx++) 918 { 919 numCtusForSAOOff[compIdx] = 0; 920 for(Int ctuRsAddr=0; ctuRsAddr< m_numCTUsPic; ctuRsAddr++) 921 { 922 if( reconParams[ctuRsAddr][compIdx].modeIdc == SAO_MODE_OFF) 923 { 924 numCtusForSAOOff[compIdx]++; 878 925 } 879 926 } 880 927 } 881 928 #if SAO_ENCODING_CHOICE_CHROMA 882 for (Int compIdx =0; compIdx<NUM_SAO_COMPONENTS; compIdx++)883 { 884 m_saoDisabledRate[compIdx][picTempLayer] = (Double)num LcusForSAOOff[compIdx]/(Double)m_numCTUsPic;929 for (Int compIdx = 0; compIdx < numberOfComponents; compIdx++) 930 { 931 m_saoDisabledRate[compIdx][picTempLayer] = (Double)numCtusForSAOOff[compIdx]/(Double)m_numCTUsPic; 885 932 } 886 933 #else 887 934 if (picTempLayer == 0) 888 935 { 889 m_saoDisabledRate[ SAO_Y][0] = (Double)(numLcusForSAOOff[SAO_Y]+numLcusForSAOOff[SAO_Cb]+numLcusForSAOOff[SAO_Cr])/(Double)(m_numCTUsPic*3);890 } 891 #endif 892 #endif 893 } 894 895 896 Void TEncSampleAdaptiveOffset::getBlkStats( Int compIdx, SAOStatData* statsDataTypes936 m_saoDisabledRate[COMPONENT_Y][0] = (Double)(numCtusForSAOOff[COMPONENT_Y]+numCtusForSAOOff[COMPONENT_Cb]+numCtusForSAOOff[COMPONENT_Cr])/(Double)(m_numCTUsPic*3); 937 } 938 #endif 939 #endif 940 } 941 942 943 Void TEncSampleAdaptiveOffset::getBlkStats(ComponentID compIdx, SAOStatData* statsDataTypes 897 944 , Pel* srcBlk, Pel* orgBlk, Int srcStride, Int orgStride, Int width, Int height 898 945 , Bool isLeftAvail, Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail … … 907 954 908 955 if (m_signLineBuf1) delete[] m_signLineBuf1; m_signLineBuf1 = NULL; 909 m_signLineBuf1 = new Char[m_lineBufWidth+1]; 956 m_signLineBuf1 = new Char[m_lineBufWidth+1]; 910 957 911 958 if (m_signLineBuf2) delete[] m_signLineBuf2; m_signLineBuf2 = NULL; … … 952 999 for (y=0; y<endY; y++) 953 1000 { 954 #if SAO_SGN_FUNC955 1001 signLeft = (Char)sgn(srcLine[startX] - srcLine[startX-1]); 956 #else957 signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];958 #endif959 1002 for (x=startX; x<endX; x++) 960 1003 { 961 #if SAO_SGN_FUNC962 1004 signRight = (Char)sgn(srcLine[x] - srcLine[x+1]); 963 #else964 signRight = (Char)m_sign[srcLine[x] - srcLine[x+1]];965 #endif966 1005 edgeType = signRight + signLeft; 967 1006 signLeft = -signRight; … … 983 1022 for(y=0; y<skipLinesB[typeIdx]; y++) 984 1023 { 985 #if SAO_SGN_FUNC986 1024 signLeft = (Char)sgn(srcLine[startX] - srcLine[startX-1]); 987 #else988 signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];989 #endif990 1025 for (x=startX; x<endX; x++) 991 1026 { 992 #if SAO_SGN_FUNC993 1027 signRight = (Char)sgn(srcLine[x] - srcLine[x+1]); 994 #else995 signRight = (Char)m_sign[srcLine[x] - srcLine[x+1]];996 #endif997 1028 edgeType = signRight + signLeft; 998 1029 signLeft = -signRight; … … 1022 1053 startY = isAboveAvail ? 0 : 1; 1023 1054 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1024 endX = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : width) 1055 endX = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : width) 1025 1056 : width 1026 1057 ; … … 1037 1068 Pel* srcLineAbove = srcLine - srcStride; 1038 1069 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1039 for (x=startX; x<endX; x++) 1040 #else 1041 for (x=0; x< endX; x++) 1042 #endif 1043 { 1044 #if SAO_SGN_FUNC 1070 for (x=startX; x<endX; x++) 1071 #else 1072 for (x=0; x< endX; x++) 1073 #endif 1074 { 1045 1075 signUpLine[x] = (Char)sgn(srcLine[x] - srcLineAbove[x]); 1046 #else1047 signUpLine[x] = (Char)m_sign[srcLine[x] - srcLineAbove[x]];1048 #endif1049 1076 } 1050 1077 … … 1060 1087 #endif 1061 1088 { 1062 #if SAO_SGN_FUNC1063 1089 signDown = (Char)sgn(srcLine[x] - srcLineBelow[x]); 1064 #else1065 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x]];1066 #endif1067 1090 edgeType = signDown + signUpLine[x]; 1068 1091 signUpLine[x]= -signDown; … … 1089 1112 for (x=startX; x<endX; x++) 1090 1113 { 1091 #if SAO_SGN_FUNC1092 1114 edgeType = sgn(srcLine[x] - srcLineBelow[x]) + sgn(srcLine[x] - srcLineAbove[x]); 1093 #else1094 edgeType = m_sign[srcLine[x] - srcLineBelow[x]] + m_sign[srcLine[x] - srcLineAbove[x]];1095 #endif1096 1115 diff [edgeType] += (orgLine[x] - srcLine[x]); 1097 1116 count[edgeType] ++; … … 1136 1155 for (x=startX; x<endX+1; x++) 1137 1156 { 1138 #if SAO_SGN_FUNC1139 1157 signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x-1]); 1140 #else1141 signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x-1]];1142 #endif1143 1158 } 1144 1159 … … 1154 1169 for(x=firstLineStartX; x<firstLineEndX; x++) 1155 1170 { 1156 #if SAO_SGN_FUNC1157 1171 edgeType = sgn(srcLine[x] - srcLineAbove[x-1]) - signUpLine[x+1]; 1158 #else1159 edgeType = m_sign[srcLine[x] - srcLineAbove[x-1]] - signUpLine[x+1];1160 #endif1161 1172 diff [edgeType] += (orgLine[x] - srcLine[x]); 1162 1173 count[edgeType] ++; … … 1173 1184 for (x=startX; x<endX; x++) 1174 1185 { 1175 #if SAO_SGN_FUNC1176 1186 signDown = (Char)sgn(srcLine[x] - srcLineBelow[x+1]); 1177 #else1178 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x+1]] ;1179 #endif1180 1187 edgeType = signDown + signUpLine[x]; 1181 1188 diff [edgeType] += (orgLine[x] - srcLine[x]); 1182 1189 count[edgeType] ++; 1183 1190 1184 signDownLine[x+1] = -signDown; 1191 signDownLine[x+1] = -signDown; 1185 1192 } 1186 #if SAO_SGN_FUNC1187 1193 signDownLine[startX] = (Char)sgn(srcLineBelow[startX] - srcLine[startX-1]); 1188 #else1189 signDownLine[startX] = (Char)m_sign[srcLineBelow[startX] - srcLine[startX-1]];1190 #endif1191 1194 1192 1195 signTmpLine = signUpLine; … … 1212 1215 for (x=startX; x< endX; x++) 1213 1216 { 1214 #if SAO_SGN_FUNC1215 1217 edgeType = sgn(srcLine[x] - srcLineBelow[x+1]) + sgn(srcLine[x] - srcLineAbove[x-1]); 1216 #else1217 edgeType = m_sign[srcLine[x] - srcLineBelow[x+1]] + m_sign[srcLine[x] - srcLineAbove[x-1]];1218 #endif1219 1218 diff [edgeType] += (orgLine[x] - srcLine[x]); 1220 1219 count[edgeType] ++; … … 1254 1253 for (x=startX-1; x<endX; x++) 1255 1254 { 1256 #if SAO_SGN_FUNC1257 1255 signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x+1]); 1258 #else1259 signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x+1]];1260 #endif1261 1256 } 1262 1257 … … 1277 1272 for(x=firstLineStartX; x<firstLineEndX; x++) 1278 1273 { 1279 #if SAO_SGN_FUNC1280 1274 edgeType = sgn(srcLine[x] - srcLineAbove[x+1]) - signUpLine[x-1]; 1281 #else1282 edgeType = m_sign[srcLine[x] - srcLineAbove[x+1]] - signUpLine[x-1];1283 #endif1284 1275 diff [edgeType] += (orgLine[x] - srcLine[x]); 1285 1276 count[edgeType] ++; … … 1296 1287 for(x=startX; x<endX; x++) 1297 1288 { 1298 #if SAO_SGN_FUNC1299 1289 signDown = (Char)sgn(srcLine[x] - srcLineBelow[x-1]); 1300 #else1301 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x-1]] ;1302 #endif1303 1290 edgeType = signDown + signUpLine[x]; 1304 1291 … … 1306 1293 count[edgeType] ++; 1307 1294 1308 signUpLine[x-1] = -signDown; 1295 signUpLine[x-1] = -signDown; 1309 1296 } 1310 #if SAO_SGN_FUNC1311 1297 signUpLine[endX-1] = (Char)sgn(srcLineBelow[endX-1] - srcLine[endX]); 1312 #else1313 signUpLine[endX-1] = (Char)m_sign[srcLineBelow[endX-1] - srcLine[endX]];1314 #endif1315 1298 srcLine += srcStride; 1316 1299 orgLine += orgStride; … … 1331 1314 for (x=startX; x<endX; x++) 1332 1315 { 1333 #if SAO_SGN_FUNC1334 1316 edgeType = sgn(srcLine[x] - srcLineBelow[x-1]) + sgn(srcLine[x] - srcLineAbove[x+1]); 1335 #else1336 edgeType = m_sign[srcLine[x] - srcLineBelow[x-1]] + m_sign[srcLine[x] - srcLineAbove[x+1]];1337 #endif1338 1317 diff [edgeType] += (orgLine[x] - srcLine[x]); 1339 1318 count[edgeType] ++; … … 1360 1339 #endif 1361 1340 endY = isBelowAvail ? (height- skipLinesB[typeIdx]) : height; 1362 Int shiftBits = ((compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC)- NUM_SAO_BO_CLASSES_LOG2;1341 Int shiftBits = g_bitDepth[toChannelType(compIdx)] - NUM_SAO_BO_CLASSES_LOG2; 1363 1342 for (y=0; y< endY; y++) 1364 1343 { … … 1370 1349 { 1371 1350 1372 Int bandIdx= srcLine[x] >> shiftBits; 1351 Int bandIdx= srcLine[x] >> shiftBits; 1373 1352 diff [bandIdx] += (orgLine[x] - srcLine[x]); 1374 1353 count[bandIdx] ++; … … 1389 1368 for (x=startX; x< endX; x++) 1390 1369 { 1391 Int bandIdx= srcLine[x] >> shiftBits; 1370 Int bandIdx= srcLine[x] >> shiftBits; 1392 1371 diff [bandIdx] += (orgLine[x] - srcLine[x]); 1393 1372 count[bandIdx] ++; … … 1413 1392 } 1414 1393 1394 1415 1395 //! \}
Note: See TracChangeset for help on using the changeset viewer.