Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp
- Timestamp:
- 13 Aug 2015, 17:38:13 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.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 … … 44 44 //! \ingroup TLibCommon 45 45 //! \{ 46 UInt g_saoMaxOffsetQVal[NUM_SAO_COMPONENTS];47 46 48 47 SAOOffset::SAOOffset() 49 { 48 { 50 49 reset(); 51 50 } … … 87 86 Void SAOBlkParam::reset() 88 87 { 89 for(Int compIdx =0; compIdx< 3; compIdx++)88 for(Int compIdx = 0; compIdx < MAX_NUM_COMPONENT; compIdx++) 90 89 { 91 90 offsetParam[compIdx].reset(); … … 95 94 const SAOBlkParam& SAOBlkParam::operator= (const SAOBlkParam& src) 96 95 { 97 for(Int compIdx =0; compIdx< 3; compIdx++)96 for(Int compIdx = 0; compIdx < MAX_NUM_COMPONENT; compIdx++) 98 97 { 99 98 offsetParam[compIdx] = src.offsetParam[compIdx]; … … 106 105 { 107 106 m_tempPicYuv = NULL; 108 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)109 {110 m_offsetClipTable[compIdx] = NULL;111 }112 #if !SAO_SGN_FUNC113 m_signTable = NULL;114 #endif115 116 107 m_lineBufWidth = 0; 117 108 m_signLineBuf1 = NULL; … … 123 114 { 124 115 destroy(); 125 126 if (m_signLineBuf1) delete[] m_signLineBuf1; m_signLineBuf1 = NULL; 127 if (m_signLineBuf2) delete[] m_signLineBuf2; m_signLineBuf2 = NULL; 128 } 129 130 Void TComSampleAdaptiveOffset::create( Int picWidth, Int picHeight, UInt maxCUWidth, UInt maxCUHeight, UInt maxCUDepth ) 116 117 if (m_signLineBuf1) 118 { 119 delete[] m_signLineBuf1; 120 m_signLineBuf1 = NULL; 121 } 122 if (m_signLineBuf2) 123 { 124 delete[] m_signLineBuf2; 125 m_signLineBuf2 = NULL; 126 } 127 } 128 129 Void TComSampleAdaptiveOffset::create( Int picWidth, Int picHeight, ChromaFormat format, UInt maxCUWidth, UInt maxCUHeight, UInt maxCUDepth, UInt lumaBitShift, UInt chromaBitShift ) 131 130 { 132 131 destroy(); 133 132 134 m_picWidth = picWidth; 135 m_picHeight= picHeight; 136 m_maxCUWidth= maxCUWidth; 137 m_maxCUHeight= maxCUHeight; 138 139 m_numCTUInWidth = (m_picWidth/m_maxCUWidth) + ((m_picWidth % m_maxCUWidth)?1:0); 140 m_numCTUInHeight= (m_picHeight/m_maxCUHeight) + ((m_picHeight % m_maxCUHeight)?1:0); 141 m_numCTUsPic = m_numCTUInHeight*m_numCTUInWidth; 133 m_picWidth = picWidth; 134 m_picHeight = picHeight; 135 m_chromaFormatIDC = format; 136 m_maxCUWidth = maxCUWidth; 137 m_maxCUHeight = maxCUHeight; 138 139 m_numCTUInWidth = (m_picWidth/m_maxCUWidth) + ((m_picWidth % m_maxCUWidth)?1:0); 140 m_numCTUInHeight = (m_picHeight/m_maxCUHeight) + ((m_picHeight % m_maxCUHeight)?1:0); 141 m_numCTUsPic = m_numCTUInHeight*m_numCTUInWidth; 142 142 143 143 //temporary picture buffer … … 145 145 { 146 146 m_tempPicYuv = new TComPicYuv; 147 m_tempPicYuv->create( m_picWidth, m_picHeight, m_ maxCUWidth, m_maxCUHeight, maxCUDepth);147 m_tempPicYuv->create( m_picWidth, m_picHeight, m_chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, maxCUDepth, true ); 148 148 } 149 149 150 150 //bit-depth related 151 for(Int compIdx =0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 152 { 153 Int bitDepthSample = (compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC; 154 m_offsetStepLog2 [compIdx] = max(bitDepthSample - MAX_SAO_TRUNCATED_BITDEPTH, 0); 155 g_saoMaxOffsetQVal[compIdx] = (1<<(min(bitDepthSample,MAX_SAO_TRUNCATED_BITDEPTH)-5))-1; //Table 9-32, inclusive 156 } 157 158 #if !SAO_SGN_FUNC 159 //look-up table for clipping 160 Int overallMaxSampleValue=0; 161 #endif 162 for(Int compIdx =0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 163 { 164 Int bitDepthSample = (compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC; //exclusive 165 Int maxSampleValue = (1<< bitDepthSample); //exclusive 166 Int maxOffsetValue = (g_saoMaxOffsetQVal[compIdx] << m_offsetStepLog2[compIdx]); 167 #if !SAO_SGN_FUNC 168 if (maxSampleValue>overallMaxSampleValue) overallMaxSampleValue=maxSampleValue; 169 #endif 170 171 m_offsetClipTable[compIdx] = new Int[(maxSampleValue + maxOffsetValue -1)+ (maxOffsetValue)+1 ]; //positive & negative range plus 0 172 m_offsetClip[compIdx] = &(m_offsetClipTable[compIdx][maxOffsetValue]); 173 174 //assign clipped values 175 Int* offsetClipPtr = m_offsetClip[compIdx]; 176 for(Int k=0; k< maxSampleValue; k++) 177 { 178 *(offsetClipPtr + k) = k; 179 } 180 for(Int k=0; k< maxOffsetValue; k++ ) 181 { 182 *(offsetClipPtr + maxSampleValue+ k) = maxSampleValue-1; 183 *(offsetClipPtr -k -1 ) = 0; 184 } 185 } 186 187 #if !SAO_SGN_FUNC 188 m_signTable = new Short[ 2*(overallMaxSampleValue-1) + 1 ]; 189 m_sign = &(m_signTable[overallMaxSampleValue-1]); 190 191 m_sign[0] = 0; 192 for(Int k=1; k< overallMaxSampleValue; k++) 193 { 194 m_sign[k] = 1; 195 m_sign[-k]= -1; 196 } 197 #endif 151 for(Int compIdx = 0; compIdx < MAX_NUM_COMPONENT; compIdx++) 152 { 153 m_offsetStepLog2 [compIdx] = isLuma(ComponentID(compIdx))? lumaBitShift : chromaBitShift; 154 } 198 155 } 199 156 … … 206 163 m_tempPicYuv = NULL; 207 164 } 208 209 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 210 { 211 if(m_offsetClipTable[compIdx]) 212 { 213 delete[] m_offsetClipTable[compIdx]; m_offsetClipTable[compIdx] = NULL; 214 } 215 } 216 #if !SAO_SGN_FUNC 217 if( m_signTable ) 218 { 219 delete[] m_signTable; m_signTable = NULL; 220 } 221 #endif 222 } 223 224 Void TComSampleAdaptiveOffset::invertQuantOffsets(Int compIdx, Int typeIdc, Int typeAuxInfo, Int* dstOffsets, Int* srcOffsets) 165 } 166 167 Void TComSampleAdaptiveOffset::invertQuantOffsets(ComponentID compIdx, Int typeIdc, Int typeAuxInfo, Int* dstOffsets, Int* srcOffsets) 225 168 { 226 169 Int codedOffset[MAX_NUM_SAO_CLASSES]; … … 247 190 } 248 191 249 Int TComSampleAdaptiveOffset::getMergeList(TComPic* pic, Int ctu , SAOBlkParam* blkParams, std::vector<SAOBlkParam*>& mergeList)250 { 251 Int ctuX = ctu % m_numCTUInWidth;252 Int ctuY = ctu / m_numCTUInWidth;192 Int TComSampleAdaptiveOffset::getMergeList(TComPic* pic, Int ctuRsAddr, SAOBlkParam* blkParams, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES]) 193 { 194 Int ctuX = ctuRsAddr % m_numCTUInWidth; 195 Int ctuY = ctuRsAddr / m_numCTUInWidth; 253 196 Int mergedCTUPos; 254 197 Int numValidMergeCandidates = 0; … … 264 207 if(ctuY > 0) 265 208 { 266 mergedCTUPos = ctu - m_numCTUInWidth;267 if( pic->getSAOMergeAvailability(ctu , mergedCTUPos) )209 mergedCTUPos = ctuRsAddr- m_numCTUInWidth; 210 if( pic->getSAOMergeAvailability(ctuRsAddr, mergedCTUPos) ) 268 211 { 269 212 mergeCandidate = &(blkParams[mergedCTUPos]); … … 276 219 if(ctuX > 0) 277 220 { 278 mergedCTUPos = ctu - 1;279 if( pic->getSAOMergeAvailability(ctu , mergedCTUPos) )221 mergedCTUPos = ctuRsAddr- 1; 222 if( pic->getSAOMergeAvailability(ctuRsAddr, mergedCTUPos) ) 280 223 { 281 224 mergeCandidate = &(blkParams[mergedCTUPos]); … … 292 235 } 293 236 294 mergeList .push_back(mergeCandidate);237 mergeList[mergeType]=mergeCandidate; 295 238 if (mergeCandidate != NULL) 296 239 { … … 303 246 304 247 305 Void TComSampleAdaptiveOffset::reconstructBlkSAOParam(SAOBlkParam& recParam, std::vector<SAOBlkParam*>& mergeList) 306 { 307 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++) 308 { 309 SAOOffset& offsetParam = recParam[compIdx]; 248 Void TComSampleAdaptiveOffset::reconstructBlkSAOParam(SAOBlkParam& recParam, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES]) 249 { 250 const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC); 251 for(Int compIdx = 0; compIdx < numberOfComponents; compIdx++) 252 { 253 const ComponentID component = ComponentID(compIdx); 254 SAOOffset& offsetParam = recParam[component]; 310 255 311 256 if(offsetParam.modeIdc == SAO_MODE_OFF) … … 318 263 case SAO_MODE_NEW: 319 264 { 320 invertQuantOffsets(comp Idx, offsetParam.typeIdc, offsetParam.typeAuxInfo, offsetParam.offset, offsetParam.offset);265 invertQuantOffsets(component, offsetParam.typeIdc, offsetParam.typeAuxInfo, offsetParam.offset, offsetParam.offset); 321 266 } 322 267 break; … … 326 271 assert(mergeTarget != NULL); 327 272 328 offsetParam = (*mergeTarget)[comp Idx];273 offsetParam = (*mergeTarget)[component]; 329 274 } 330 275 break; … … 341 286 Void TComSampleAdaptiveOffset::reconstructBlkSAOParams(TComPic* pic, SAOBlkParam* saoBlkParams) 342 287 { 343 m_picSAOEnabled[SAO_Y] = m_picSAOEnabled[SAO_Cb] = m_picSAOEnabled[SAO_Cr] = false; 344 345 for(Int ctu=0; ctu< m_numCTUsPic; ctu++) 346 { 347 std::vector<SAOBlkParam*> mergeList; 348 getMergeList(pic, ctu, saoBlkParams, mergeList); 349 350 reconstructBlkSAOParam(saoBlkParams[ctu], mergeList); 351 352 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++) 353 { 354 if(saoBlkParams[ctu][compIdx].modeIdc != SAO_MODE_OFF) 288 for(Int compIdx = 0; compIdx < MAX_NUM_COMPONENT; compIdx++) 289 { 290 m_picSAOEnabled[compIdx] = false; 291 } 292 293 const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC); 294 295 for(Int ctuRsAddr=0; ctuRsAddr< m_numCTUsPic; ctuRsAddr++) 296 { 297 SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES] = { NULL }; 298 getMergeList(pic, ctuRsAddr, saoBlkParams, mergeList); 299 300 reconstructBlkSAOParam(saoBlkParams[ctuRsAddr], mergeList); 301 302 for(Int compIdx = 0; compIdx < numberOfComponents; compIdx++) 303 { 304 if(saoBlkParams[ctuRsAddr][compIdx].modeIdc != SAO_MODE_OFF) 355 305 { 356 306 m_picSAOEnabled[compIdx] = true; … … 358 308 } 359 309 } 360 361 362 } 363 364 365 Void TComSampleAdaptiveOffset::offsetBlock(Int compIdx, Int typeIdx, Int* offset 310 } 311 312 313 Void TComSampleAdaptiveOffset::offsetBlock(const Int channelBitDepth, Int typeIdx, Int* offset 366 314 , Pel* srcBlk, Pel* resBlk, Int srcStride, Int resStride, Int width, Int height 367 315 , Bool isLeftAvail, Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail) … … 370 318 { 371 319 m_lineBufWidth = m_maxCUWidth; 372 373 if (m_signLineBuf1) delete[] m_signLineBuf1; m_signLineBuf1 = NULL; 320 321 if (m_signLineBuf1) 322 { 323 delete[] m_signLineBuf1; 324 m_signLineBuf1 = NULL; 325 } 374 326 m_signLineBuf1 = new Char[m_lineBufWidth+1]; 375 376 if (m_signLineBuf2) delete[] m_signLineBuf2; m_signLineBuf2 = NULL; 327 328 if (m_signLineBuf2) 329 { 330 delete[] m_signLineBuf2; 331 m_signLineBuf2 = NULL; 332 } 377 333 m_signLineBuf2 = new Char[m_lineBufWidth+1]; 378 334 } 379 335 380 Int* offsetClip = m_offsetClip[compIdx];336 const Int maxSampleValueIncl = (1<< channelBitDepth )-1; 381 337 382 338 Int x,y, startX, startY, endX, endY, edgeType; … … 396 352 for (y=0; y< height; y++) 397 353 { 398 #if SAO_SGN_FUNC399 354 signLeft = (Char)sgn(srcLine[startX] - srcLine[startX-1]); 400 #else401 signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];402 #endif403 355 for (x=startX; x< endX; x++) 404 356 { 405 #if SAO_SGN_FUNC406 357 signRight = (Char)sgn(srcLine[x] - srcLine[x+1]); 407 #else408 signRight = (Char)m_sign[srcLine[x] - srcLine[x+1]];409 #endif410 358 edgeType = signRight + signLeft; 411 359 signLeft = -signRight; 412 360 413 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];361 resLine[x] = Clip3<Int>(0, maxSampleValueIncl, srcLine[x] + offset[edgeType]); 414 362 } 415 363 srcLine += srcStride; … … 435 383 for (x=0; x< width; x++) 436 384 { 437 #if SAO_SGN_FUNC438 385 signUpLine[x] = (Char)sgn(srcLine[x] - srcLineAbove[x]); 439 #else440 signUpLine[x] = (Char)m_sign[srcLine[x] - srcLineAbove[x]];441 #endif442 386 } 443 387 … … 449 393 for (x=0; x< width; x++) 450 394 { 451 #if SAO_SGN_FUNC452 395 signDown = (Char)sgn(srcLine[x] - srcLineBelow[x]); 453 #else454 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x]];455 #endif456 396 edgeType = signDown + signUpLine[x]; 457 397 signUpLine[x]= -signDown; 458 398 459 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];399 resLine[x] = Clip3<Int>(0, maxSampleValueIncl, srcLine[x] + offset[edgeType]); 460 400 } 461 401 srcLine += srcStride; … … 480 420 for (x=startX; x< endX+1; x++) 481 421 { 482 #if SAO_SGN_FUNC483 422 signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x- 1]); 484 #else485 signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x- 1]];486 #endif487 423 } 488 424 … … 493 429 for(x= firstLineStartX; x< firstLineEndX; x++) 494 430 { 495 #if SAO_SGN_FUNC496 431 edgeType = sgn(srcLine[x] - srcLineAbove[x- 1]) - signUpLine[x+1]; 497 #else 498 edgeType = m_sign[srcLine[x] - srcLineAbove[x- 1]] - signUpLine[x+1]; 499 #endif 500 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]]; 432 433 resLine[x] = Clip3<Int>(0, maxSampleValueIncl, srcLine[x] + offset[edgeType]); 501 434 } 502 435 srcLine += srcStride; … … 511 444 for (x=startX; x<endX; x++) 512 445 { 513 #if SAO_SGN_FUNC514 446 signDown = (Char)sgn(srcLine[x] - srcLineBelow[x+ 1]); 515 #else516 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x+ 1]] ;517 #endif518 447 edgeType = signDown + signUpLine[x]; 519 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];520 521 signDownLine[x+1] = -signDown; 448 resLine[x] = Clip3<Int>(0, maxSampleValueIncl, srcLine[x] + offset[edgeType]); 449 450 signDownLine[x+1] = -signDown; 522 451 } 523 #if SAO_SGN_FUNC524 452 signDownLine[startX] = (Char)sgn(srcLineBelow[startX] - srcLine[startX-1]); 525 #else526 signDownLine[startX] = (Char)m_sign[srcLineBelow[startX] - srcLine[startX-1]];527 #endif528 453 529 454 signTmpLine = signUpLine; … … 541 466 for(x= lastLineStartX; x< lastLineEndX; x++) 542 467 { 543 #if SAO_SGN_FUNC544 468 edgeType = sgn(srcLine[x] - srcLineBelow[x+ 1]) + signUpLine[x]; 545 #else 546 edgeType = m_sign[srcLine[x] - srcLineBelow[x+ 1]] + signUpLine[x]; 547 #endif 548 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]]; 469 resLine[x] = Clip3<Int>(0, maxSampleValueIncl, srcLine[x] + offset[edgeType]); 549 470 550 471 } … … 563 484 for (x=startX-1; x< endX; x++) 564 485 { 565 #if SAO_SGN_FUNC566 486 signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x+1]); 567 #else568 signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x+1]];569 #endif570 487 } 571 488 … … 577 494 for(x= firstLineStartX; x< firstLineEndX; x++) 578 495 { 579 #if SAO_SGN_FUNC580 496 edgeType = sgn(srcLine[x] - srcLineAbove[x+1]) -signUpLine[x-1]; 581 #else 582 edgeType = m_sign[srcLine[x] - srcLineAbove[x+1]] -signUpLine[x-1]; 583 #endif 584 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]]; 497 resLine[x] = Clip3<Int>(0, maxSampleValueIncl, srcLine[x] + offset[edgeType]); 585 498 } 586 499 srcLine += srcStride; … … 594 507 for(x= startX; x< endX; x++) 595 508 { 596 #if SAO_SGN_FUNC597 509 signDown = (Char)sgn(srcLine[x] - srcLineBelow[x-1]); 598 #else599 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x-1]] ;600 #endif601 510 edgeType = signDown + signUpLine[x]; 602 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];603 signUpLine[x-1] = -signDown; 511 resLine[x] = Clip3<Int>(0, maxSampleValueIncl, srcLine[x] + offset[edgeType]); 512 signUpLine[x-1] = -signDown; 604 513 } 605 #if SAO_SGN_FUNC606 514 signUpLine[endX-1] = (Char)sgn(srcLineBelow[endX-1] - srcLine[endX]); 607 #else608 signUpLine[endX-1] = (Char)m_sign[srcLineBelow[endX-1] - srcLine[endX]];609 #endif610 515 srcLine += srcStride; 611 516 resLine += resStride; … … 618 523 for(x= lastLineStartX; x< lastLineEndX; x++) 619 524 { 620 #if SAO_SGN_FUNC621 525 edgeType = sgn(srcLine[x] - srcLineBelow[x-1]) + signUpLine[x]; 622 #else 623 edgeType = m_sign[srcLine[x] - srcLineBelow[x-1]] + signUpLine[x]; 624 #endif 625 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]]; 526 resLine[x] = Clip3<Int>(0, maxSampleValueIncl, srcLine[x] + offset[edgeType]); 626 527 627 528 } … … 630 531 case SAO_TYPE_BO: 631 532 { 632 Int shiftBits = ((compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC)- NUM_SAO_BO_CLASSES_LOG2;533 const Int shiftBits = channelBitDepth - NUM_SAO_BO_CLASSES_LOG2; 633 534 for (y=0; y< height; y++) 634 535 { 635 536 for (x=0; x< width; x++) 636 537 { 637 resLine[x] = offsetClip[ srcLine[x] + offset[srcLine[x] >> shiftBits] ];538 resLine[x] = Clip3<Int>(0, maxSampleValueIncl, srcLine[x] + offset[srcLine[x] >> shiftBits] ); 638 539 } 639 540 srcLine += srcStride; … … 649 550 } 650 551 } 651 652 653 } 654 655 Void TComSampleAdaptiveOffset::offsetCTU(Int ctu, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam& saoblkParam, TComPic* pPic) 552 } 553 554 Void TComSampleAdaptiveOffset::offsetCTU(Int ctuRsAddr, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam& saoblkParam, TComPic* pPic) 656 555 { 657 556 Bool isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail; 658 557 659 if( 660 (saoblkParam[SAO_Y ].modeIdc == SAO_MODE_OFF) && 661 (saoblkParam[SAO_Cb].modeIdc == SAO_MODE_OFF) && 662 (saoblkParam[SAO_Cr].modeIdc == SAO_MODE_OFF) 663 ) 558 const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC); 559 Bool bAllOff=true; 560 for(Int compIdx = 0; compIdx < numberOfComponents; compIdx++) 561 { 562 if (saoblkParam[compIdx].modeIdc != SAO_MODE_OFF) 563 { 564 bAllOff=false; 565 } 566 } 567 if (bAllOff) 664 568 { 665 569 return; … … 667 571 668 572 //block boundary availability 669 pPic->getPicSym()->deriveLoopFilterBoundaryAvailibility(ctu , isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail);670 671 Int yPos = (ctu / m_numCTUInWidth)*m_maxCUHeight;672 Int xPos = (ctu % m_numCTUInWidth)*m_maxCUWidth;573 pPic->getPicSym()->deriveLoopFilterBoundaryAvailibility(ctuRsAddr, isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail); 574 575 Int yPos = (ctuRsAddr / m_numCTUInWidth)*m_maxCUHeight; 576 Int xPos = (ctuRsAddr % m_numCTUInWidth)*m_maxCUWidth; 673 577 Int height = (yPos + m_maxCUHeight > m_picHeight)?(m_picHeight- yPos):m_maxCUHeight; 674 578 Int width = (xPos + m_maxCUWidth > m_picWidth )?(m_picWidth - xPos):m_maxCUWidth; 675 579 676 for(Int compIdx= 0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 677 { 580 for(Int compIdx = 0; compIdx < numberOfComponents; compIdx++) 581 { 582 const ComponentID component = ComponentID(compIdx); 678 583 SAOOffset& ctbOffset = saoblkParam[compIdx]; 679 584 680 585 if(ctbOffset.modeIdc != SAO_MODE_OFF) 681 586 { 682 Bool isLuma = (compIdx == SAO_Y);683 Int formatShift= isLuma?0:1;684 685 Int blkWidth = (width >> formatShift);686 Int blkHeight = (height >> formatShift);687 Int blk YPos = (yPos >> formatShift);688 Int blk XPos = (xPos >> formatShift);689 690 Int srcStride = isLuma?srcYuv->getStride():srcYuv->getCStride();691 Pel* srcBlk = getPicBuf(srcYuv, compIdx)+ (yPos >> formatShift)*srcStride+ (xPos >> formatShift);692 693 Int resStride = isLuma?resYuv->getStride():resYuv->getCStride();694 Pel* resBlk = getPicBuf(resYuv, compIdx)+ blkYPos*resStride+ blkXPos;695 696 offsetBlock( compIdx, ctbOffset.typeIdc, ctbOffset.offset587 const UInt componentScaleX = getComponentScaleX(component, pPic->getChromaFormat()); 588 const UInt componentScaleY = getComponentScaleY(component, pPic->getChromaFormat()); 589 590 Int blkWidth = (width >> componentScaleX); 591 Int blkHeight = (height >> componentScaleY); 592 Int blkXPos = (xPos >> componentScaleX); 593 Int blkYPos = (yPos >> componentScaleY); 594 595 Int srcStride = srcYuv->getStride(component); 596 Pel* srcBlk = srcYuv->getAddr(component) + blkYPos*srcStride + blkXPos; 597 598 Int resStride = resYuv->getStride(component); 599 Pel* resBlk = resYuv->getAddr(component) + blkYPos*resStride + blkXPos; 600 601 offsetBlock( pPic->getPicSym()->getSPS().getBitDepth(toChannelType(component)), ctbOffset.typeIdc, ctbOffset.offset 697 602 , srcBlk, resBlk, srcStride, resStride, blkWidth, blkHeight 698 603 , isLeftAvail, isRightAvail … … 709 614 Void TComSampleAdaptiveOffset::SAOProcess(TComPic* pDecPic) 710 615 { 711 if(!m_picSAOEnabled[SAO_Y] && !m_picSAOEnabled[SAO_Cb] && !m_picSAOEnabled[SAO_Cr]) 616 const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC); 617 Bool bAllDisabled=true; 618 for(Int compIdx = 0; compIdx < numberOfComponents; compIdx++) 619 { 620 if (m_picSAOEnabled[compIdx]) 621 { 622 bAllDisabled=false; 623 } 624 } 625 if (bAllDisabled) 712 626 { 713 627 return; 714 628 } 629 715 630 TComPicYuv* resYuv = pDecPic->getPicYuvRec(); 716 631 TComPicYuv* srcYuv = m_tempPicYuv; 717 632 resYuv->copyToPic(srcYuv); 718 for(Int ctu = 0; ctu < m_numCTUsPic; ctu++)719 { 720 offsetCTU(ctu , srcYuv, resYuv, (pDecPic->getPicSym()->getSAOBlkParam())[ctu], pDecPic);633 for(Int ctuRsAddr= 0; ctuRsAddr < m_numCTUsPic; ctuRsAddr++) 634 { 635 offsetCTU(ctuRsAddr, srcYuv, resYuv, (pDecPic->getPicSym()->getSAOBlkParam())[ctuRsAddr], pDecPic); 721 636 } //ctu 722 637 } 723 638 724 725 Pel* TComSampleAdaptiveOffset::getPicBuf(TComPicYuv* pPicYuv, Int compIdx)726 {727 Pel* pBuf = NULL;728 switch(compIdx)729 {730 case SAO_Y:731 {732 pBuf = pPicYuv->getLumaAddr();733 }734 break;735 case SAO_Cb:736 {737 pBuf = pPicYuv->getCbAddr();738 }739 break;740 case SAO_Cr:741 {742 pBuf = pPicYuv->getCrAddr();743 }744 break;745 default:746 {747 printf("Not a legal component ID for SAO\n");748 assert(0);749 exit(-1);750 }751 }752 753 return pBuf;754 }755 639 756 640 /** PCM LF disable process. 757 641 * \param pcPic picture (TComPic) pointer 758 * \returns Void759 642 * 760 643 * \note Replace filtered sample values of PCM mode blocks with the transmitted and reconstructed ones. … … 765 648 } 766 649 767 /** Picture-level PCM restoration. 650 /** Picture-level PCM restoration. 768 651 * \param pcPic picture (TComPic) pointer 769 * \returns Void770 652 */ 771 653 Void TComSampleAdaptiveOffset::xPCMRestoration(TComPic* pcPic) … … 775 657 if(bPCMFilter || pcPic->getSlice(0)->getPPS()->getTransquantBypassEnableFlag()) 776 658 { 777 for( UInt uiCUAddr = 0; uiCUAddr < pcPic->getNumCUsInFrame() ; uiCUAddr++ ) 778 { 779 TComDataCU* pcCU = pcPic->getCU(uiCUAddr); 780 781 xPCMCURestoration(pcCU, 0, 0); 782 } 783 } 784 } 785 786 /** PCM CU restoration. 787 * \param pcCU pointer to current CU 788 * \param uiAbsPartIdx part index 789 * \param uiDepth CU depth 790 * \returns Void 659 for( UInt ctuRsAddr = 0; ctuRsAddr < pcPic->getNumberOfCtusInFrame() ; ctuRsAddr++ ) 660 { 661 TComDataCU* pcCU = pcPic->getCtu(ctuRsAddr); 662 663 xPCMCURestoration(pcCU, 0, 0); 664 } 665 } 666 } 667 668 /** PCM CU restoration. 669 * \param pcCU pointer to current CU 670 * \param uiAbsZorderIdx part index 671 * \param uiDepth CU depth 791 672 */ 792 673 Void TComSampleAdaptiveOffset::xPCMCURestoration ( TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth ) 793 674 { 794 675 TComPic* pcPic = pcCU->getPic(); 795 UInt uiCurNumParts = pcPic->getNumPart InCU() >> (uiDepth<<1);676 UInt uiCurNumParts = pcPic->getNumPartitionsInCtu() >> (uiDepth<<1); 796 677 UInt uiQNumParts = uiCurNumParts>>2; 797 678 … … 804 685 UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsZorderIdx] ]; 805 686 if( ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) ) 687 { 806 688 xPCMCURestoration( pcCU, uiAbsZorderIdx, uiDepth+1 ); 689 } 807 690 } 808 691 return; … … 812 695 if ((pcCU->getIPCMFlag(uiAbsZorderIdx)&& pcPic->getSlice(0)->getSPS()->getPCMFilterDisableFlag()) || pcCU->isLosslessCoded( uiAbsZorderIdx)) 813 696 { 814 xPCMSampleRestoration (pcCU, uiAbsZorderIdx, uiDepth, TEXT_LUMA ); 815 xPCMSampleRestoration (pcCU, uiAbsZorderIdx, uiDepth, TEXT_CHROMA_U); 816 xPCMSampleRestoration (pcCU, uiAbsZorderIdx, uiDepth, TEXT_CHROMA_V); 817 } 818 } 819 820 /** PCM sample restoration. 821 * \param pcCU pointer to current CU 822 * \param uiAbsPartIdx part index 823 * \param uiDepth CU depth 824 * \param ttText texture component type 825 * \returns Void 697 const UInt numComponents=pcPic->getNumberValidComponents(); 698 for(UInt comp=0; comp<numComponents; comp++) 699 { 700 xPCMSampleRestoration (pcCU, uiAbsZorderIdx, uiDepth, ComponentID(comp)); 701 } 702 } 703 } 704 705 /** PCM sample restoration. 706 * \param pcCU pointer to current CU 707 * \param uiAbsZorderIdx part index 708 * \param uiDepth CU depth 709 * \param compID texture component type 826 710 */ 827 Void TComSampleAdaptiveOffset::xPCMSampleRestoration (TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth, TextType ttText) 828 { 829 TComPicYuv* pcPicYuvRec = pcCU->getPic()->getPicYuvRec(); 830 Pel* piSrc; 831 Pel* piPcm; 832 UInt uiStride; 833 UInt uiWidth; 834 UInt uiHeight; 835 UInt uiPcmLeftShiftBit; 836 UInt uiX, uiY; 837 UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); 838 UInt uiLumaOffset = uiMinCoeffSize*uiAbsZorderIdx; 839 UInt uiChromaOffset = uiLumaOffset>>2; 840 841 if( ttText == TEXT_LUMA ) 842 { 843 piSrc = pcPicYuvRec->getLumaAddr( pcCU->getAddr(), uiAbsZorderIdx); 844 piPcm = pcCU->getPCMSampleY() + uiLumaOffset; 845 uiStride = pcPicYuvRec->getStride(); 846 uiWidth = (g_uiMaxCUWidth >> uiDepth); 847 uiHeight = (g_uiMaxCUHeight >> uiDepth); 848 if ( pcCU->isLosslessCoded(uiAbsZorderIdx) && !pcCU->getIPCMFlag(uiAbsZorderIdx) ) 849 { 850 uiPcmLeftShiftBit = 0; 851 } 852 else 853 { 854 uiPcmLeftShiftBit = g_bitDepthY - pcCU->getSlice()->getSPS()->getPCMBitDepthLuma(); 855 } 711 Void TComSampleAdaptiveOffset::xPCMSampleRestoration (TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth, const ComponentID compID) 712 { 713 TComPicYuv* pcPicYuvRec = pcCU->getPic()->getPicYuvRec(); 714 UInt uiPcmLeftShiftBit; 715 const UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); 716 const UInt csx=pcPicYuvRec->getComponentScaleX(compID); 717 const UInt csy=pcPicYuvRec->getComponentScaleY(compID); 718 const UInt uiOffset = (uiMinCoeffSize*uiAbsZorderIdx)>>(csx+csy); 719 720 Pel *piSrc = pcPicYuvRec->getAddr(compID, pcCU->getCtuRsAddr(), uiAbsZorderIdx); 721 const Pel *piPcm = pcCU->getPCMSample(compID) + uiOffset; 722 const UInt uiStride = pcPicYuvRec->getStride(compID); 723 const TComSPS &sps = *(pcCU->getSlice()->getSPS()); 724 const UInt uiWidth = ((sps.getMaxCUWidth() >> uiDepth) >> csx); 725 const UInt uiHeight = ((sps.getMaxCUHeight() >> uiDepth) >> csy); 726 727 if ( pcCU->isLosslessCoded(uiAbsZorderIdx) && !pcCU->getIPCMFlag(uiAbsZorderIdx) ) 728 { 729 uiPcmLeftShiftBit = 0; 856 730 } 857 731 else 858 732 { 859 if( ttText == TEXT_CHROMA_U ) 860 { 861 piSrc = pcPicYuvRec->getCbAddr( pcCU->getAddr(), uiAbsZorderIdx ); 862 piPcm = pcCU->getPCMSampleCb() + uiChromaOffset; 863 } 864 else 865 { 866 piSrc = pcPicYuvRec->getCrAddr( pcCU->getAddr(), uiAbsZorderIdx ); 867 piPcm = pcCU->getPCMSampleCr() + uiChromaOffset; 868 } 869 870 uiStride = pcPicYuvRec->getCStride(); 871 uiWidth = ((g_uiMaxCUWidth >> uiDepth)/2); 872 uiHeight = ((g_uiMaxCUWidth >> uiDepth)/2); 873 if ( pcCU->isLosslessCoded(uiAbsZorderIdx) && !pcCU->getIPCMFlag(uiAbsZorderIdx) ) 874 { 875 uiPcmLeftShiftBit = 0; 876 } 877 else 878 { 879 uiPcmLeftShiftBit = g_bitDepthC - pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); 880 } 881 } 882 883 for( uiY = 0; uiY < uiHeight; uiY++ ) 884 { 885 for( uiX = 0; uiX < uiWidth; uiX++ ) 733 uiPcmLeftShiftBit = sps.getBitDepth(toChannelType(compID)) - sps.getPCMBitDepth(toChannelType(compID)); 734 } 735 736 for(UInt uiY = 0; uiY < uiHeight; uiY++ ) 737 { 738 for(UInt uiX = 0; uiX < uiWidth; uiX++ ) 886 739 { 887 740 piSrc[uiX] = (piPcm[uiX] << uiPcmLeftShiftBit);
Note: See TracChangeset for help on using the changeset viewer.