Changeset 1089 in SHVCSoftware for branches/SHM-dev/source/Lib/TLibDecoder/TDecGop.cpp
- Timestamp:
- 25 Jun 2015, 16:19:05 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SHM-dev/source/Lib/TLibDecoder/TDecGop.cpp
r1049 r1089 64 64 //! \{ 65 65 static Void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI); 66 #if Q0074_COLOUR_REMAPPING_SEI67 static Void applyColourRemapping(TComPicYuv& pic, const SEIColourRemappingInfo* colourRemappingInfoSEI, UInt layerId=0 );68 static std::vector<SEIColourRemappingInfo> storeCriSEI; //Persistent Colour Remapping Information SEI69 #endif70 66 // ==================================================================================================================== 71 67 // Constructor / destructor / initialization / destroy … … 258 254 thisLayerBuffer->push_back(*pcPic); 259 255 std::sort( thisLayerBuffer->begin(), thisLayerBuffer->end(), pocCompareFunction ); 260 }261 #endif262 #if Q0074_COLOUR_REMAPPING_SEI263 if (m_colourRemapSEIEnabled)264 {265 SEIMessages colourRemappingInfo = getSeisByType(pcPic->getSEIs(), SEI::COLOUR_REMAPPING_INFO );266 const SEIColourRemappingInfo *seiColourRemappingInfo = ( colourRemappingInfo.size() > 0 ) ? (SEIColourRemappingInfo*) *(colourRemappingInfo.begin()) : NULL;267 if (colourRemappingInfo.size() > 1)268 {269 printf ("Warning: Got multiple Colour Remapping Information SEI messages. Using first.");270 }271 applyColourRemapping(*pcPic->getPicYuvRec(), seiColourRemappingInfo272 #if SVC_EXTENSION273 , pcPic->getLayerId()274 #endif275 );276 256 } 277 257 #endif … … 354 334 } 355 335 356 #if Q0074_COLOUR_REMAPPING_SEI357 Void xInitColourRemappingLut( const Int bitDepthY, const Int bitDepthC, std::vector<Int>(&preLut)[3], std::vector<Int>(&postLut)[3], const SEIColourRemappingInfo* const pCriSEI )358 {359 for ( Int c=0 ; c<3 ; c++ )360 {361 Int bitDepth = c ? bitDepthC : bitDepthY ;362 preLut[c].resize(1 << bitDepth);363 postLut[c].resize(1 << pCriSEI->m_colourRemapBitDepth);364 365 Int bitDepthDiff = pCriSEI->m_colourRemapBitDepth - bitDepth;366 Int iShift1 = (bitDepthDiff>0) ? bitDepthDiff : 0; //bit scale from bitdepth to ColourRemapBitdepth (manage only case colourRemapBitDepth>= bitdepth)367 if( bitDepthDiff<0 )368 printf ("Warning: CRI SEI - colourRemapBitDepth (%d) <bitDepth (%d) - case not handled\n", pCriSEI->m_colourRemapBitDepth, bitDepth);369 bitDepthDiff = pCriSEI->m_colourRemapBitDepth - pCriSEI->m_colourRemapInputBitDepth;370 Int iShift2 = (bitDepthDiff>0) ? bitDepthDiff : 0; //bit scale from ColourRemapInputBitdepth to ColourRemapBitdepth (manage only case colourRemapBitDepth>= colourRemapInputBitDepth)371 if( bitDepthDiff<0 )372 printf ("Warning: CRI SEI - colourRemapBitDepth (%d) <colourRemapInputBitDepth (%d) - case not handled\n", pCriSEI->m_colourRemapBitDepth, pCriSEI->m_colourRemapInputBitDepth);373 374 //Fill preLut375 for ( Int k=0 ; k<(1<<bitDepth) ; k++ )376 {377 Int iSample = k << iShift1 ;378 for ( Int iPivot=0 ; iPivot<=pCriSEI->m_preLutNumValMinus1[c] ; iPivot++ )379 {380 Int iCodedPrev = pCriSEI->m_preLutCodedValue[c][iPivot] << iShift2; //Coded in CRInputBitdepth381 Int iCodedNext = pCriSEI->m_preLutCodedValue[c][iPivot+1] << iShift2; //Coded in CRInputBitdepth382 Int iTargetPrev = pCriSEI->m_preLutTargetValue[c][iPivot]; //Coded in CRBitdepth383 Int iTargetNext = pCriSEI->m_preLutTargetValue[c][iPivot+1]; //Coded in CRBitdepth384 if ( iCodedPrev <= iSample && iSample <= iCodedNext )385 {386 Float fInterpol = (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) * 1.f / (Float)(iCodedNext - iCodedPrev);387 preLut[c][k] = (Int)( 0.5f + fInterpol );388 iPivot = pCriSEI->m_preLutNumValMinus1[c] + 1;389 }390 }391 }392 393 //Fill postLut394 for ( Int k=0 ; k<(1<<pCriSEI->m_colourRemapBitDepth) ; k++ )395 {396 Int iSample = k;397 for ( Int iPivot=0 ; iPivot<=pCriSEI->m_postLutNumValMinus1[c] ; iPivot++ )398 {399 Int iCodedPrev = pCriSEI->m_postLutCodedValue[c][iPivot]; //Coded in CRBitdepth400 Int iCodedNext = pCriSEI->m_postLutCodedValue[c][iPivot+1]; //Coded in CRBitdepth401 Int iTargetPrev = pCriSEI->m_postLutTargetValue[c][iPivot]; //Coded in CRBitdepth402 Int iTargetNext = pCriSEI->m_postLutTargetValue[c][iPivot+1]; //Coded in CRBitdepth403 if ( iCodedPrev <= iSample && iSample <= iCodedNext )404 {405 Float fInterpol = (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) * 1.f / (Float)(iCodedNext - iCodedPrev) ;406 postLut[c][k] = (Int)( 0.5f + fInterpol );407 iPivot = pCriSEI->m_postLutNumValMinus1[c] + 1;408 }409 }410 }411 }412 }413 414 static Void applyColourRemapping(TComPicYuv& pic, const SEIColourRemappingInfo* pCriSEI, UInt layerId )415 {416 if( !storeCriSEI.size() )417 #if SVC_EXTENSION418 storeCriSEI.resize(MAX_LAYERS);419 #else420 storeCriSEI.resize(1);421 #endif422 423 if ( pCriSEI ) //if a CRI SEI has just been retrieved, keep it in memory (persistence management)424 storeCriSEI[layerId] = *pCriSEI;425 426 if( !storeCriSEI[layerId].m_colourRemapCancelFlag )427 {428 Int iHeight = pic.getHeight(COMPONENT_Y);429 Int iWidth = pic.getWidth(COMPONENT_Y);430 Int iStride = pic.getStride(COMPONENT_Y);431 Int iCStride = pic.getStride(COMPONENT_Cb);432 433 Pel *YUVIn[3], *YUVOut[3];434 YUVIn[0] = pic.getAddr(COMPONENT_Y);435 YUVIn[1] = pic.getAddr(COMPONENT_Cb);436 YUVIn[2] = pic.getAddr(COMPONENT_Cr);437 438 TComPicYuv picColourRemapped;439 #if SVC_EXTENSION440 picColourRemapped.create( pic.getWidth(COMPONENT_Y), pic.getHeight(COMPONENT_Y), pic.getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL );441 #else442 picColourRemapped.create( pic.getWidth(COMPONENT_Y), pic.getHeight(COMPONENT_Y), pic.getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );443 #endif444 YUVOut[0] = picColourRemapped.getAddr(COMPONENT_Y);445 YUVOut[1] = picColourRemapped.getAddr(COMPONENT_Cb);446 YUVOut[2] = picColourRemapped.getAddr(COMPONENT_Cr);447 448 #if SVC_EXTENSION449 Int bitDepthY = g_bitDepthLayer[CHANNEL_TYPE_LUMA][layerId];450 Int bitDepthC = g_bitDepthLayer[CHANNEL_TYPE_CHROMA][layerId];451 452 assert( g_bitDepth[CHANNEL_TYPE_LUMA] == bitDepthY );453 assert( g_bitDepth[CHANNEL_TYPE_CHROMA] == bitDepthC );454 #else455 Int bitDepthY = g_bitDepth[CHANNEL_TYPE_LUMA];456 Int bitDepthC = g_bitDepth[CHANNEL_TYPE_CHROMA];457 #endif458 459 std::vector<Int> preLut[3];460 std::vector<Int> postLut[3];461 xInitColourRemappingLut( bitDepthY, bitDepthC, preLut, postLut, &storeCriSEI[layerId] );462 463 Int roundingOffset = (storeCriSEI[layerId].m_log2MatrixDenom==0) ? 0 : (1 << (storeCriSEI[layerId].m_log2MatrixDenom - 1));464 465 for( Int y = 0; y < iHeight ; y++ )466 {467 for( Int x = 0; x < iWidth ; x++ )468 {469 Int YUVPre[3], YUVMat[3];470 YUVPre[0] = preLut[0][ YUVIn[0][x] ];471 YUVPre[1] = preLut[1][ YUVIn[1][x>>1] ];472 YUVPre[2] = preLut[2][ YUVIn[2][x>>1] ];473 474 YUVMat[0] = ( storeCriSEI[layerId].m_colourRemapCoeffs[0][0]*YUVPre[0]475 + storeCriSEI[layerId].m_colourRemapCoeffs[0][1]*YUVPre[1]476 + storeCriSEI[layerId].m_colourRemapCoeffs[0][2]*YUVPre[2]477 + roundingOffset ) >> ( storeCriSEI[layerId].m_log2MatrixDenom );478 YUVMat[0] = Clip3( 0, (1<<storeCriSEI[layerId].m_colourRemapBitDepth)-1, YUVMat[0] );479 YUVOut[0][x] = postLut[0][ YUVMat[0] ];480 481 if( (y&1) && (x&1) )482 {483 for(Int c=1 ; c<3 ; c++)484 {485 YUVMat[c] = ( storeCriSEI[layerId].m_colourRemapCoeffs[c][0]*YUVPre[0]486 + storeCriSEI[layerId].m_colourRemapCoeffs[c][1]*YUVPre[1]487 + storeCriSEI[layerId].m_colourRemapCoeffs[c][2]*YUVPre[2]488 + roundingOffset ) >> ( storeCriSEI[layerId].m_log2MatrixDenom );489 YUVMat[c] = Clip3( 0, (1<<storeCriSEI[layerId].m_colourRemapBitDepth)-1, YUVMat[c] );490 YUVOut[c][x>>1] = postLut[c][ YUVMat[c] ];491 }492 }493 }494 YUVIn[0] += iStride;495 YUVOut[0] += iStride;496 if( y&1 )497 {498 YUVIn[1] += iCStride;499 YUVIn[2] += iCStride;500 YUVOut[1] += iCStride;501 YUVOut[2] += iCStride;502 }503 }504 505 //Write remapped picture in decoding order506 Char cTemp[255];507 sprintf(cTemp, "seiColourRemappedPic_L%d_%dx%d_%dbits.yuv", layerId, iWidth, iHeight, storeCriSEI[layerId].m_colourRemapBitDepth );508 picColourRemapped.dump( cTemp, true, storeCriSEI[layerId].m_colourRemapBitDepth );509 510 picColourRemapped.destroy();511 512 storeCriSEI[layerId].m_colourRemapCancelFlag = !storeCriSEI[layerId].m_colourRemapPersistenceFlag; //Handling persistence513 }514 }515 #endif516 336 //! \}
Note: See TracChangeset for help on using the changeset viewer.