Ignore:
Timestamp:
25 Jun 2015, 16:19:05 (9 years ago)
Author:
seregin
Message:

Patch provided by Hiron Franck <franck.hiron@…> to complete implementation of the CRI (Colour remapping info) with the following features:

  • Management of SEI-CRI messages per picture
  • Management of the persistence of the colour remapping information (parameter “colour_remap_persistence_flag”)
  • Output the remapping picture in display order
  • Maintains the HM like mode (#define SVC_EXTENSION 0)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/SHM-dev/source/Lib/TLibDecoder/TDecGop.cpp

    r1049 r1089  
    6464//! \{
    6565static Void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI);
    66 #if Q0074_COLOUR_REMAPPING_SEI
    67 static Void applyColourRemapping(TComPicYuv& pic, const SEIColourRemappingInfo* colourRemappingInfoSEI, UInt layerId=0 );
    68 static std::vector<SEIColourRemappingInfo> storeCriSEI; //Persistent Colour Remapping Information SEI
    69 #endif
    7066// ====================================================================================================================
    7167// Constructor / destructor / initialization / destroy
     
    258254    thisLayerBuffer->push_back(*pcPic);
    259255    std::sort( thisLayerBuffer->begin(), thisLayerBuffer->end(), pocCompareFunction );
    260   }
    261 #endif
    262 #if Q0074_COLOUR_REMAPPING_SEI
    263   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(), seiColourRemappingInfo
    272 #if SVC_EXTENSION
    273      , pcPic->getLayerId()
    274 #endif
    275      );
    276256  }
    277257#endif
     
    354334}
    355335
    356 #if Q0074_COLOUR_REMAPPING_SEI
    357 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 preLut
    375     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 CRInputBitdepth
    381         Int iCodedNext  = pCriSEI->m_preLutCodedValue[c][iPivot+1]  << iShift2; //Coded in CRInputBitdepth
    382         Int iTargetPrev = pCriSEI->m_preLutTargetValue[c][iPivot];              //Coded in CRBitdepth
    383         Int iTargetNext = pCriSEI->m_preLutTargetValue[c][iPivot+1];            //Coded in CRBitdepth
    384         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 postLut
    394     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 CRBitdepth
    400         Int iCodedNext  = pCriSEI->m_postLutCodedValue[c][iPivot+1];  //Coded in CRBitdepth
    401         Int iTargetPrev = pCriSEI->m_postLutTargetValue[c][iPivot];   //Coded in CRBitdepth
    402         Int iTargetNext = pCriSEI->m_postLutTargetValue[c][iPivot+1]; //Coded in CRBitdepth
    403         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_EXTENSION
    418     storeCriSEI.resize(MAX_LAYERS);
    419 #else
    420     storeCriSEI.resize(1);
    421 #endif
    422 
    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_EXTENSION
    440     picColourRemapped.create( pic.getWidth(COMPONENT_Y), pic.getHeight(COMPONENT_Y), pic.getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL );
    441 #else
    442     picColourRemapped.create( pic.getWidth(COMPONENT_Y), pic.getHeight(COMPONENT_Y), pic.getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    443 #endif
    444     YUVOut[0] = picColourRemapped.getAddr(COMPONENT_Y);
    445     YUVOut[1] = picColourRemapped.getAddr(COMPONENT_Cb);
    446     YUVOut[2] = picColourRemapped.getAddr(COMPONENT_Cr);
    447 
    448 #if SVC_EXTENSION
    449     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 #else
    455     Int bitDepthY = g_bitDepth[CHANNEL_TYPE_LUMA];
    456     Int bitDepthC = g_bitDepth[CHANNEL_TYPE_CHROMA];
    457 #endif
    458 
    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 order
    506     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 persistence
    513   }
    514 }
    515 #endif
    516336//! \}
Note: See TracChangeset for help on using the changeset viewer.