Changeset 1460 in SHVCSoftware


Ignore:
Timestamp:
20 Aug 2015, 20:54:17 (9 years ago)
Author:
seregin
Message:

port rev 4594

Location:
branches/SHM-dev
Files:
6 added
23 edited

Legend:

Unmodified
Added
Removed
  • branches/SHM-dev/source/App/TAppDecoder/TAppDecCfg.cpp

    r1442 r1460  
    113113  ("TarDecLayerIdSetFile,l",    cfg_TargetDecLayerIdSetFile,           string(""), "targetDecLayerIdSet file name. The file should include white space separated LayerId values to be decoded. Omitting the option or a value of -1 in the file decodes all layers.")
    114114  ("RespectDefDispWindow,w",    m_respectDefDispWindow,                0,          "Only output content inside the default display window\n")
     115#if Q0074_COLOUR_REMAPPING_SEI
     116  ("SEIColourRemappingInfoFilename",  m_colourRemapSEIFileName,        string(""), "Colour Remapping YUV output file name. If empty, no remapping is applied (ignore SEI message)\n")
     117#endif
    115118#if O0043_BEST_EFFORT_DECODING
    116119  ("ForceDecodeBitDepth",       m_forceDecodeBitDepth,                 0U,         "Force the decoder to operate at a particular bit-depth (best effort decoding)")
     
    118121  ("OutputDecodedSEIMessagesFilename",  m_outputDecodedSEIMessagesFilename,    string(""), "When non empty, output decoded SEI messages to the indicated file. If file is '-', then output to stdout\n")
    119122  ("ClipOutputVideoToRec709Range",      m_bClipOutputVideoToRec709Range,  false, "If true then clip output video to the Rec. 709 Range on saving")
    120 #if Q0074_COLOUR_REMAPPING_SEI
    121   ("SEIColourRemappingInfo,-cri", m_colourRemapSEIEnabled, false, "Control handling of Colour Remapping Information SEI messages\n"
    122                                               "\t1: apply colour remapping on decoded pictures if available in the bitstream\n"
    123                                               "\t0: ignore SEI message")
    124 #endif
    125123  ;
    126124
  • branches/SHM-dev/source/App/TAppDecoder/TAppDecCfg.h

    r1445 r1460  
    7171  Bool          m_decodedNoDisplaySEIEnabled;         ///< Enable(true)/disable(false) writing only pictures that get displayed based on the no display SEI message
    7272#if Q0074_COLOUR_REMAPPING_SEI
    73   Bool          m_colourRemapSEIEnabled;              ///< Enable the Colour Remapping Information SEI message if available (remapping decoded pictures)
     73  std::string   m_colourRemapSEIFileName;             ///< output Colour Remapping file name
    7474#endif
    75 
    7675  std::vector<Int> m_targetDecLayerIdSet;             ///< set of LayerIds to be included in the sub-bitstream extraction process.
    7776  Int           m_respectDefDispWindow;               ///< Only output content inside the default display window
     
    110109  , m_decodedNoDisplaySEIEnabled(false)
    111110#if Q0074_COLOUR_REMAPPING_SEI
    112   , m_colourRemapSEIEnabled(false)
     111  , m_colourRemapSEIFileName()
    113112#endif
    114113  , m_targetDecLayerIdSet()
  • branches/SHM-dev/source/App/TAppDecoder/TAppDecTop.cpp

    r1445 r1460  
    6363TAppDecTop::TAppDecTop()
    6464#if Q0074_COLOUR_REMAPPING_SEI
    65 : seiColourRemappingInfoPrevious(NULL)
     65: m_pcSeiColourRemappingInfoPrevious(NULL)
     66, m_pcPicYuvColourRemapped(NULL)
    6667#endif
    6768{
     
    7879: m_iPOCLastDisplay(-MAX_INT)
    7980#if Q0074_COLOUR_REMAPPING_SEI
    80 , seiColourRemappingInfoPrevious(NULL)
     81 ,m_pcSeiColourRemappingInfoPrevious(NULL)
     82 ,m_pcPicYuvColourRemapped(NULL)
    8183#endif
    8284{
     
    117119#else
    118120  m_reconFileName.clear();
    119 #endif
    120 #if Q0074_COLOUR_REMAPPING_SEI
    121   if (seiColourRemappingInfoPrevious != NULL)
    122   {
    123     delete seiColourRemappingInfoPrevious;
    124   }
    125121#endif
    126122}
     
    688684  }
    689685#endif
     686#if Q0074_COLOUR_REMAPPING_SEI
     687  if (m_pcSeiColourRemappingInfoPrevious != NULL)
     688  {
     689    delete m_pcSeiColourRemappingInfoPrevious;
     690    m_pcSeiColourRemappingInfoPrevious = NULL;
     691  }
     692  if (m_pcPicYuvColourRemapped != NULL)
     693  {
     694    m_pcPicYuvColourRemapped->destroy();
     695    delete m_pcPicYuvColourRemapped;
     696    m_pcPicYuvColourRemapped  = NULL;
     697  }
     698#endif
    690699}
    691700
     
    919928
    920929#if Q0074_COLOUR_REMAPPING_SEI
    921         if (m_colourRemapSEIEnabled)
    922         {
    923           SEIMessages colourRemappingInfo = getSeisByType(pcPic->getSEIs(), SEI::COLOUR_REMAPPING_INFO );
    924           const SEIColourRemappingInfo *seiColourRemappingInfo = ( colourRemappingInfo.size() > 0 ) ? (SEIColourRemappingInfo*) *(colourRemappingInfo.begin()) : NULL;
    925           const TComSPS *sps = pcPic->getSlice(0)->getSPS();
    926 
    927           if (colourRemappingInfo.size() > 1)
    928           {
    929             printf ("Warning: Got multiple Colour Remapping Information SEI messages. Using first.");
    930           }
    931           if (seiColourRemappingInfo)
    932           {
    933             xApplyColourRemapping(sps, *pcPic->getPicYuvRec(), seiColourRemappingInfo);
    934           }
    935           else  // using the last CRI SEI received
    936           {
    937             const SEIColourRemappingInfo *seiColourRemappingInfoCopy;
    938             seiColourRemappingInfoCopy = seiColourRemappingInfoPrevious;
    939             xApplyColourRemapping(sps, *pcPic->getPicYuvRec(), seiColourRemappingInfoCopy);
    940           }
    941 
    942           // save the last CRI SEI received
    943           if( seiColourRemappingInfo != NULL){
    944             if (seiColourRemappingInfoPrevious != NULL)
    945             {
    946               delete seiColourRemappingInfoPrevious;
    947               seiColourRemappingInfoPrevious = NULL;
    948             }
    949             if (seiColourRemappingInfo->m_colourRemapPersistenceFlag)
    950             {
    951               seiColourRemappingInfoPrevious = new SEIColourRemappingInfo();
    952               seiColourRemappingInfoPrevious->copyFrom(seiColourRemappingInfo);
    953             }
    954           }
     930        if (!m_colourRemapSEIFileName.empty())
     931        {
     932          xOutputColourRemapPic(pcPic, activeSPS);
    955933        }
    956934#endif
     
    11221100
    11231101#if Q0074_COLOUR_REMAPPING_SEI
    1124         if (m_colourRemapSEIEnabled)
    1125         {
    1126           SEIMessages colourRemappingInfo = getSeisByType(pcPic->getSEIs(), SEI::COLOUR_REMAPPING_INFO );
    1127           const SEIColourRemappingInfo *seiColourRemappingInfo = ( colourRemappingInfo.size() > 0 ) ? (SEIColourRemappingInfo*) *(colourRemappingInfo.begin()) : NULL;
    1128           const TComSPS *sps = pcPic->getSlice(0)->getSPS();
    1129 
    1130           if (colourRemappingInfo.size() > 1)
    1131           {
    1132             printf ("Warning: Got multiple Colour Remapping Information SEI messages. Using first.");
    1133           }
    1134           if (seiColourRemappingInfo)
    1135           {
    1136             xApplyColourRemapping( sps, *pcPic->getPicYuvRec(), seiColourRemappingInfo );
    1137           }
    1138           else  // using the last CRI SEI received
    1139           {
    1140             const SEIColourRemappingInfo *seiColourRemappingInfoCopy;
    1141             seiColourRemappingInfoCopy = seiColourRemappingInfoPrevious;
    1142             xApplyColourRemapping( sps, *pcPic->getPicYuvRec(), seiColourRemappingInfoCopy );
    1143           }
    1144 
    1145           // save the last CRI SEI received
    1146           if( seiColourRemappingInfo != NULL){
    1147             if (seiColourRemappingInfoPrevious != NULL)
    1148             {
    1149               delete seiColourRemappingInfoPrevious;
    1150               seiColourRemappingInfoPrevious = NULL;
    1151             }
    1152             if (seiColourRemappingInfo->m_colourRemapPersistenceFlag)
    1153             {
    1154               seiColourRemappingInfoPrevious = new SEIColourRemappingInfo();
    1155               seiColourRemappingInfoPrevious->copyFrom(seiColourRemappingInfo);
    1156             }
    1157           }
     1102        if (!m_colourRemapSEIFileName.empty())
     1103        {
     1104          xOutputColourRemapPic(pcPic, &(pcPic->getPicSym()->getSPS()));
    11581105        }
    11591106#endif
     
    12151162  return false;
    12161163}
     1164
     1165#if Q0074_COLOUR_REMAPPING_SEI
     1166
     1167Void TAppDecTop::xOutputColourRemapPic(TComPic* pcPic, const TComSPS* activeSPS)
     1168{
     1169  SEIMessages colourRemappingInfo = getSeisByType(pcPic->getSEIs(), SEI::COLOUR_REMAPPING_INFO );
     1170  SEIColourRemappingInfo *seiColourRemappingInfo = ( colourRemappingInfo.size() > 0 ) ? (SEIColourRemappingInfo*) *(colourRemappingInfo.begin()) : NULL;
     1171
     1172  if (colourRemappingInfo.size() > 1)
     1173  {
     1174    printf ("Warning: Got multiple Colour Remapping Information SEI messages. Using first.");
     1175  }
     1176  if (seiColourRemappingInfo)
     1177  {
     1178    applyColourRemapping(*pcPic->getPicYuvRec(), *seiColourRemappingInfo, *activeSPS);
     1179  }
     1180  else  // using the last CRI SEI received
     1181  {
     1182    if (m_pcSeiColourRemappingInfoPrevious != NULL)
     1183    {
     1184      if (m_pcSeiColourRemappingInfoPrevious->m_colourRemapPersistenceFlag == false)
     1185      {
     1186        printf("Warning No SEI-CRI message is present for the current picture, persistence of the CRI is not managed\n");
     1187      }
     1188      SEIColourRemappingInfo *seiColourRemappingInfoCopy;
     1189      seiColourRemappingInfoCopy = m_pcSeiColourRemappingInfoPrevious;
     1190      applyColourRemapping(*pcPic->getPicYuvRec(), *seiColourRemappingInfoCopy, *activeSPS);
     1191    }
     1192  }
     1193
     1194  // save the last CRI SEI received
     1195  if( seiColourRemappingInfo != NULL)
     1196  {
     1197    if (m_pcSeiColourRemappingInfoPrevious != NULL)
     1198    {
     1199      delete m_pcSeiColourRemappingInfoPrevious;
     1200      m_pcSeiColourRemappingInfoPrevious = NULL;
     1201    }
     1202    m_pcSeiColourRemappingInfoPrevious = new SEIColourRemappingInfo();
     1203    m_pcSeiColourRemappingInfoPrevious->copyFrom(*seiColourRemappingInfo);
     1204  }
     1205}
     1206
     1207// compute lut from SEI
     1208// use at lutPoints points aligned on a power of 2 value
     1209// SEI Lut must be in ascending values of coded Values
     1210static std::vector<Int>
     1211initColourRemappingInfoLut(const Int                                          bitDepth_in,     // bit-depth of the input values of the LUT
     1212                           const Int                                          nbDecimalValues, // Position of the fixed point
     1213                           const std::vector<SEIColourRemappingInfo::CRIlut> &lut,
     1214                           const Int                                          maxValue, // maximum output value
     1215                           const Int                                          lutOffset)
     1216{
     1217  const Int lutPoints = (1 << bitDepth_in) + 1 ;
     1218  std::vector<Int> retLut(lutPoints);
     1219
     1220  // missing values: need to define default values before first definition (check codedValue[0] == 0)
     1221  Int iTargetPrev = (lut.size() && lut[0].codedValue == 0) ? lut[0].targetValue: 0;
     1222  Int startPivot = (lut.size())? ((lut[0].codedValue == 0)? 1: 0): 1;
     1223  Int iCodedPrev  = 0;
     1224  // set max value with the coded bit-depth
     1225  // + ((1 << nbDecimalValues) - 1) is for the added bits
     1226  const Int maxValueFixedPoint = (maxValue << nbDecimalValues) + ((1 << nbDecimalValues) - 1);
     1227
     1228  Int iValue = 0;
     1229
     1230  for ( Int iPivot=startPivot ; iPivot < (Int)lut.size(); iPivot++ )
     1231  {
     1232    Int iCodedNext  = lut[iPivot].codedValue;
     1233    Int iTargetNext = lut[iPivot].targetValue;
     1234
     1235    // ensure correct bit depth and avoid overflow in lut address
     1236    Int iCodedNext_bitDepth = std::min(iCodedNext, (1 << bitDepth_in));
     1237
     1238    const Int divValue =  (iCodedNext - iCodedPrev > 0)? (iCodedNext - iCodedPrev): 1;
     1239    const Int lutValInit = (lutOffset + iTargetPrev) << nbDecimalValues;
     1240    const Int roundValue = divValue / 2;
     1241    for ( ; iValue<iCodedNext_bitDepth; iValue++ )
     1242    {
     1243      Int value = iValue;
     1244      Int interpol = ((((value-iCodedPrev) * (iTargetNext - iTargetPrev)) << nbDecimalValues) + roundValue) / divValue;               
     1245      retLut[iValue]  = std::min(lutValInit + interpol , maxValueFixedPoint);
     1246    }
     1247    iCodedPrev  = iCodedNext;
     1248    iTargetPrev = iTargetNext;
     1249  }
     1250  // fill missing values if necessary
     1251  if(iCodedPrev < (1 << bitDepth_in)+1)
     1252  {
     1253    Int iCodedNext  = (1 << bitDepth_in);
     1254    Int iTargetNext = (1 << bitDepth_in) - 1;
     1255
     1256    const Int divValue =  (iCodedNext - iCodedPrev > 0)? (iCodedNext - iCodedPrev): 1;
     1257    const Int lutValInit = (lutOffset + iTargetPrev) << nbDecimalValues;
     1258    const Int roundValue = divValue / 2;
     1259
     1260    for ( ; iValue<=iCodedNext; iValue++ )
     1261    {
     1262      Int value = iValue;
     1263      Int interpol = ((((value-iCodedPrev) * (iTargetNext - iTargetPrev)) << nbDecimalValues) + roundValue) / divValue;
     1264      retLut[iValue]  = std::min(lutValInit + interpol , maxValueFixedPoint);
     1265    }
     1266  }
     1267  return retLut;
     1268}
     1269
     1270static Void
     1271initColourRemappingInfoLuts(std::vector<Int>      (&preLut)[3],
     1272                            std::vector<Int>      (&postLut)[3],
     1273                            SEIColourRemappingInfo &pCriSEI,
     1274                            const Int               maxBitDepth)
     1275{
     1276  Int internalBitDepth = pCriSEI.m_colourRemapBitDepth;
     1277  for ( Int c=0 ; c<3 ; c++ )
     1278  {
     1279    std::sort(pCriSEI.m_preLut[c].begin(), pCriSEI.m_preLut[c].end()); // ensure preLut is ordered in ascending values of codedValues   
     1280    preLut[c] = initColourRemappingInfoLut(pCriSEI.m_colourRemapInputBitDepth, maxBitDepth - pCriSEI.m_colourRemapInputBitDepth, pCriSEI.m_preLut[c], ((1 << internalBitDepth) - 1), 0); //Fill preLut
     1281
     1282    std::sort(pCriSEI.m_postLut[c].begin(), pCriSEI.m_postLut[c].end()); // ensure postLut is ordered in ascending values of codedValues       
     1283    postLut[c] = initColourRemappingInfoLut(pCriSEI.m_colourRemapBitDepth, maxBitDepth - pCriSEI.m_colourRemapBitDepth, pCriSEI.m_postLut[c], (1 << internalBitDepth) - 1, 0); //Fill postLut
     1284  }
     1285}
     1286
     1287// apply lut.
     1288// Input lut values are aligned on power of 2 boundaries
     1289static Int
     1290applyColourRemappingInfoLut1D(Int inVal, const std::vector<Int> &lut, const Int inValPrecisionBits)
     1291{
     1292  const Int roundValue = (inValPrecisionBits)? 1 << (inValPrecisionBits - 1): 0;
     1293  inVal = std::min(std::max(0, inVal), (Int)(((lut.size()-1) << inValPrecisionBits)));
     1294  Int index  = (Int) std::min((inVal >> inValPrecisionBits), (Int)(lut.size()-2));
     1295  Int outVal = (( inVal - (index<<inValPrecisionBits) ) * (lut[index+1] - lut[index]) + roundValue) >> inValPrecisionBits;
     1296  outVal +=  lut[index] ;
     1297
     1298  return outVal;
     1299
     1300
     1301static Int
     1302applyColourRemappingInfoMatrix(const Int (&colourRemapCoeffs)[3], const Int postOffsetShift, const Int p0, const Int p1, const Int p2, const Int offset)
     1303{
     1304  Int YUVMat = (colourRemapCoeffs[0]* p0 + colourRemapCoeffs[1]* p1 + colourRemapCoeffs[2]* p2  + offset) >> postOffsetShift;
     1305  return YUVMat;
     1306}
     1307
     1308static Void
     1309setColourRemappingInfoMatrixOffset(Int (&matrixOffset)[3], Int offset0, Int offset1, Int offset2)
     1310{
     1311  matrixOffset[0] = offset0;
     1312  matrixOffset[1] = offset1;
     1313  matrixOffset[2] = offset2;
     1314}
     1315
     1316static Void
     1317setColourRemappingInfoMatrixOffsets(      Int  (&matrixInputOffset)[3],
     1318                                          Int  (&matrixOutputOffset)[3],
     1319                                    const Int  bitDepth,
     1320                                    const Bool crInputFullRangeFlag,
     1321                                    const Int  crInputMatrixCoefficients,
     1322                                    const Bool crFullRangeFlag,
     1323                                    const Int  crMatrixCoefficients)
     1324{
     1325  // set static matrix offsets
     1326  Int crInputOffsetLuma = (crInputFullRangeFlag)? 0:-(16 << (bitDepth-8));
     1327  Int crOffsetLuma = (crFullRangeFlag)? 0:(16 << (bitDepth-8));
     1328  Int crInputOffsetChroma = 0;
     1329  Int crOffsetChroma = 0;
     1330
     1331  switch(crInputMatrixCoefficients)
     1332  {
     1333    case MATRIX_COEFFICIENTS_RGB:
     1334      crInputOffsetChroma = 0;
     1335      if(!crInputFullRangeFlag)
     1336      {
     1337        fprintf(stderr, "WARNING: crInputMatrixCoefficients set to MATRIX_COEFFICIENTS_RGB and crInputFullRangeFlag not set\n");
     1338        crInputOffsetLuma = 0;
     1339      }
     1340      break;
     1341    case MATRIX_COEFFICIENTS_UNSPECIFIED:
     1342    case MATRIX_COEFFICIENTS_BT709:
     1343    case MATRIX_COEFFICIENTS_BT2020_NON_CONSTANT_LUMINANCE:
     1344      crInputOffsetChroma = -(1 << (bitDepth-1));
     1345      break;
     1346    default:
     1347      fprintf(stderr, "WARNING: crInputMatrixCoefficients set to undefined value: %d\n", crInputMatrixCoefficients);
     1348  }
     1349
     1350  switch(crMatrixCoefficients)
     1351  {
     1352    case MATRIX_COEFFICIENTS_RGB:
     1353      crOffsetChroma = 0;
     1354      if(!crFullRangeFlag)
     1355      {
     1356        fprintf(stderr, "WARNING: crMatrixCoefficients set to MATRIX_COEFFICIENTS_RGB and crInputFullRangeFlag not set\n");
     1357        crOffsetLuma = 0;
     1358      }
     1359      break;
     1360    case MATRIX_COEFFICIENTS_UNSPECIFIED:
     1361    case MATRIX_COEFFICIENTS_BT709:
     1362    case MATRIX_COEFFICIENTS_BT2020_NON_CONSTANT_LUMINANCE:
     1363      crOffsetChroma = (1 << (bitDepth-1));
     1364      break;
     1365    default:
     1366      fprintf(stderr, "WARNING: crMatrixCoefficients set to undefined value: %d\n", crMatrixCoefficients);
     1367  }
     1368
     1369  setColourRemappingInfoMatrixOffset(matrixInputOffset, crInputOffsetLuma, crInputOffsetChroma, crInputOffsetChroma);
     1370  setColourRemappingInfoMatrixOffset(matrixOutputOffset, crOffsetLuma, crOffsetChroma, crOffsetChroma);
     1371}
     1372
     1373Void TAppDecTop::applyColourRemapping(const TComPicYuv& pic, SEIColourRemappingInfo& criSEI, const TComSPS &activeSPS)
     1374
     1375  const Int maxBitDepth = 16;
     1376  Bool firstPicture = true;
     1377
     1378  // create colour remapped picture
     1379  if ( m_pcPicYuvColourRemapped == NULL )
     1380  {
     1381    const ChromaFormat chromaFormatIDC = activeSPS.getChromaFormatIdc();
     1382    const Int          iWidth          = activeSPS.getPicWidthInLumaSamples();
     1383    const Int          iHeight         = activeSPS.getPicHeightInLumaSamples();
     1384    const UInt         uiMaxCuWidth    = activeSPS.getMaxCUWidth();
     1385    const UInt         uiMaxCuHeight   = activeSPS.getMaxCUHeight();
     1386    const UInt         uiMaxDepth      = activeSPS.getMaxTotalCUDepth();
     1387    m_pcPicYuvColourRemapped  = new TComPicYuv;
     1388    m_pcPicYuvColourRemapped->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true );
     1389  }
     1390  else
     1391  {
     1392    firstPicture = false;
     1393  }
     1394
     1395  if( !criSEI.m_colourRemapCancelFlag )
     1396  {
     1397    const Int  iHeight  = pic.getHeight(COMPONENT_Y);
     1398    const Int  iWidth   = pic.getWidth(COMPONENT_Y);
     1399    const Int  iStride  = pic.getStride(COMPONENT_Y);
     1400    const Int  iCStride = pic.getStride(COMPONENT_Cb);
     1401    const Bool b444     = ( pic.getChromaFormat() == CHROMA_444 );
     1402    const Bool b422     = ( pic.getChromaFormat() == CHROMA_422 );
     1403    const Bool b420     = ( pic.getChromaFormat() == CHROMA_420 );
     1404
     1405    std::vector<Int> preLut[3];
     1406    std::vector<Int> postLut[3];
     1407    Int matrixInputOffset[3];
     1408    Int matrixOutputOffset[3];
     1409    const Pel *YUVIn[MAX_NUM_COMPONENT];
     1410    Pel *YUVOut[MAX_NUM_COMPONENT];
     1411    YUVIn[COMPONENT_Y]  = pic.getAddr(COMPONENT_Y);
     1412    YUVIn[COMPONENT_Cb] = pic.getAddr(COMPONENT_Cb);
     1413    YUVIn[COMPONENT_Cr] = pic.getAddr(COMPONENT_Cr);
     1414    YUVOut[COMPONENT_Y]  = m_pcPicYuvColourRemapped->getAddr(COMPONENT_Y);
     1415    YUVOut[COMPONENT_Cb] = m_pcPicYuvColourRemapped->getAddr(COMPONENT_Cb);
     1416    YUVOut[COMPONENT_Cr] = m_pcPicYuvColourRemapped->getAddr(COMPONENT_Cr);
     1417
     1418    Int bitDepthY = activeSPS.getBitDepth(CHANNEL_TYPE_LUMA);
     1419    assert(bitDepthY == activeSPS.getBitDepth(CHANNEL_TYPE_CHROMA)); // Different bitdepth is not implemented
     1420
     1421    const Int postOffsetShift = criSEI.m_log2MatrixDenom;
     1422    const Int matrixRound = 1 << (postOffsetShift - 1);
     1423    const Int postLutInputPrecision = (maxBitDepth - criSEI.m_colourRemapBitDepth);
     1424
     1425    if ( ! criSEI.m_colourRemapVideoSignalInfoPresentFlag ) // setting default
     1426    {
     1427      setColourRemappingInfoMatrixOffsets(matrixInputOffset, matrixOutputOffset, maxBitDepth,
     1428          activeSPS.getVuiParameters()->getVideoFullRangeFlag(), activeSPS.getVuiParameters()->getMatrixCoefficients(),
     1429          activeSPS.getVuiParameters()->getVideoFullRangeFlag(), activeSPS.getVuiParameters()->getMatrixCoefficients());
     1430    }
     1431    else
     1432    {
     1433      setColourRemappingInfoMatrixOffsets(matrixInputOffset, matrixOutputOffset, maxBitDepth,
     1434          activeSPS.getVuiParameters()->getVideoFullRangeFlag(), activeSPS.getVuiParameters()->getMatrixCoefficients(),
     1435          criSEI.m_colourRemapFullRangeFlag, criSEI.m_colourRemapMatrixCoefficients);
     1436    }
     1437
     1438    // add matrix rounding to output matrix offsets
     1439    matrixOutputOffset[0] = (matrixOutputOffset[0] << postOffsetShift) + matrixRound;
     1440    matrixOutputOffset[1] = (matrixOutputOffset[1] << postOffsetShift) + matrixRound;
     1441    matrixOutputOffset[2] = (matrixOutputOffset[2] << postOffsetShift) + matrixRound;
     1442
     1443    // Merge   matrixInputOffset and matrixOutputOffset to matrixOutputOffset
     1444    matrixOutputOffset[0] += applyColourRemappingInfoMatrix(criSEI.m_colourRemapCoeffs[0], 0, matrixInputOffset[0], matrixInputOffset[1], matrixInputOffset[2], 0);
     1445    matrixOutputOffset[1] += applyColourRemappingInfoMatrix(criSEI.m_colourRemapCoeffs[1], 0, matrixInputOffset[0], matrixInputOffset[1], matrixInputOffset[2], 0);
     1446    matrixOutputOffset[2] += applyColourRemappingInfoMatrix(criSEI.m_colourRemapCoeffs[2], 0, matrixInputOffset[0], matrixInputOffset[1], matrixInputOffset[2], 0);
     1447
     1448    // rescaling output: include CRI/output frame difference
     1449    const Int scaleShiftOut_neg = abs(bitDepthY - maxBitDepth);
     1450    const Int scaleOut_round = 1 << (scaleShiftOut_neg-1);
     1451
     1452    initColourRemappingInfoLuts(preLut, postLut, criSEI, maxBitDepth);
     1453
     1454    assert(pic.getChromaFormat() != CHROMA_400);
     1455    const Int hs = pic.getComponentScaleX(ComponentID(COMPONENT_Cb));
     1456
     1457    for( Int y = 0; y < iHeight; y++ )
     1458    {
     1459      for( Int x = 0; x < iWidth; x++ )
     1460      {
     1461        const Int xc = (x>>hs);
     1462        Bool computeChroma = b444 || ((b422 || !(y&1)) && !(x&1));
     1463
     1464        Int YUVPre_0 = applyColourRemappingInfoLut1D(YUVIn[COMPONENT_Y][x], preLut[0], 0);
     1465        Int YUVPre_1 = applyColourRemappingInfoLut1D(YUVIn[COMPONENT_Cb][xc], preLut[1], 0);
     1466        Int YUVPre_2 = applyColourRemappingInfoLut1D(YUVIn[COMPONENT_Cr][xc], preLut[2], 0);
     1467
     1468        Int YUVMat_0 = applyColourRemappingInfoMatrix(criSEI.m_colourRemapCoeffs[0], postOffsetShift, YUVPre_0, YUVPre_1, YUVPre_2, matrixOutputOffset[0]);
     1469        Int YUVLutB_0 = applyColourRemappingInfoLut1D(YUVMat_0, postLut[0], postLutInputPrecision);
     1470        YUVOut[COMPONENT_Y][x] = (YUVLutB_0 + scaleOut_round) >> scaleShiftOut_neg; // scaling output
     1471
     1472        if( computeChroma )
     1473        {
     1474          Int YUVMat_1 = applyColourRemappingInfoMatrix(criSEI.m_colourRemapCoeffs[1], postOffsetShift, YUVPre_0, YUVPre_1, YUVPre_2, matrixOutputOffset[1]);
     1475          Int YUVLutB_1 = applyColourRemappingInfoLut1D(YUVMat_1, postLut[1], postLutInputPrecision);
     1476          YUVOut[COMPONENT_Cb][xc] = (YUVLutB_1 + scaleOut_round) >> scaleShiftOut_neg; // scaling output
     1477
     1478          Int YUVMat_2 = applyColourRemappingInfoMatrix(criSEI.m_colourRemapCoeffs[2], postOffsetShift, YUVPre_0, YUVPre_1, YUVPre_2, matrixOutputOffset[2]);
     1479          Int YUVLutB_2 = applyColourRemappingInfoLut1D(YUVMat_2, postLut[2], postLutInputPrecision);
     1480          YUVOut[COMPONENT_Cr][xc] = (YUVLutB_2 + scaleOut_round) >> scaleShiftOut_neg; // scaling output
     1481        }
     1482      }
     1483
     1484      YUVIn[COMPONENT_Y]  += iStride;
     1485      YUVOut[COMPONENT_Y] += iStride;
     1486      if( !(b420 && !(y&1)) )
     1487      {
     1488         YUVIn[COMPONENT_Cb]  += iCStride;
     1489         YUVIn[COMPONENT_Cr]  += iCStride;
     1490         YUVOut[COMPONENT_Cb] += iCStride;
     1491         YUVOut[COMPONENT_Cr] += iCStride;
     1492      }
     1493    }
     1494    //Write remapped picture in display order
     1495    m_pcPicYuvColourRemapped->dump( m_colourRemapSEIFileName, activeSPS.getBitDepths(), !firstPicture );
     1496  }
     1497}
     1498#endif
    12171499
    12181500#if ALIGNED_BUMPING
     
    12381520
    12391521#if Q0074_COLOUR_REMAPPING_SEI
    1240     if( m_colourRemapSEIEnabled )
    1241     {
    1242       const TComSPS *sps = pic->getSlice(0)->getSPS();
    1243       SEIMessages colourRemappingInfo = getSeisByType(pic->getSEIs(), SEI::COLOUR_REMAPPING_INFO );
    1244       const SEIColourRemappingInfo *seiColourRemappingInfo = ( colourRemappingInfo.size() > 0 ) ? (SEIColourRemappingInfo*) *(colourRemappingInfo.begin()) : NULL;
    1245 
    1246       if (colourRemappingInfo.size() > 1)
    1247       {
    1248         printf ("Warning: Got multiple Colour Remapping Information SEI messages. Using first.");
    1249       }
    1250 
    1251       if (seiColourRemappingInfo)
    1252       {
    1253         //printf ("\n\nColour Remapping is applied to POC : %d and LayerId : %d ",pic->getPOC(), pic->getLayerId());
    1254         xApplyColourRemapping( sps, *pic->getPicYuvRec(), seiColourRemappingInfo, pic->getLayerId() );
    1255       }
    1256       else  // using the last CRI SEI received
    1257       {
    1258         const SEIColourRemappingInfo *seiColourRemappingInfoCopy;
    1259         seiColourRemappingInfoCopy = seiColourRemappingInfoPrevious;
    1260         xApplyColourRemapping( sps, *pic->getPicYuvRec(), seiColourRemappingInfoCopy, pic->getLayerId() );
    1261       }
    1262 
    1263       // save the last CRI SEI received
    1264       if( seiColourRemappingInfo != NULL){
    1265         if (seiColourRemappingInfoPrevious != NULL)
    1266         {
    1267           delete seiColourRemappingInfoPrevious;
    1268           seiColourRemappingInfoPrevious = NULL;
    1269         }
    1270         if (seiColourRemappingInfo->m_colourRemapPersistenceFlag)
    1271         {
    1272           seiColourRemappingInfoPrevious = new SEIColourRemappingInfo();
    1273           seiColourRemappingInfoPrevious->copyFrom(seiColourRemappingInfo);
    1274         }
    1275       }
    1276     }
    1277 
     1522    if (!m_colourRemapSEIFileName.empty())
     1523    {
     1524      xOutputColourRemapPic(pic, pic->getSlice(0)->getSPS());
     1525    }
    12781526#endif
    12791527  }
     
    17952043#endif //ALIGNED_BUMPING
    17962044
    1797 #if Q0074_COLOUR_REMAPPING_SEI
    1798 Void TAppDecTop::xInitColourRemappingLut( const BitDepths &bitDepths, std::vector<Int>(&preLut)[3], std::vector<Int>(&postLut)[3], const SEIColourRemappingInfo* const pCriSEI )
    1799 {
    1800   for ( Int c=0 ; c<3 ; c++ )
    1801   { 
    1802     Int bitDepth = bitDepths.recon[toChannelType(ComponentID(c))];
    1803     preLut[c].resize(1 << bitDepth);
    1804     postLut[c].resize(1 << pCriSEI->m_colourRemapBitDepth);
    1805    
    1806     Int bitDepthDiff = pCriSEI->m_colourRemapBitDepth - bitDepth;
    1807     Int iShift1 = (bitDepthDiff>0) ? bitDepthDiff : 0; //bit scale from bitdepth to ColourRemapBitdepth (manage only case colourRemapBitDepth>= bitdepth)
    1808     if( bitDepthDiff<0 )
    1809       printf ("Warning: CRI SEI - colourRemapBitDepth (%d) <bitDepth (%d) - case not handled\n", pCriSEI->m_colourRemapBitDepth, bitDepth);
    1810     bitDepthDiff = pCriSEI->m_colourRemapBitDepth - pCriSEI->m_colourRemapInputBitDepth;
    1811     Int iShift2 = (bitDepthDiff>0) ? bitDepthDiff : 0; //bit scale from ColourRemapInputBitdepth to ColourRemapBitdepth (manage only case colourRemapBitDepth>= colourRemapInputBitDepth)
    1812     if( bitDepthDiff<0 )
    1813       printf ("Warning: CRI SEI - colourRemapBitDepth (%d) <colourRemapInputBitDepth (%d) - case not handled\n", pCriSEI->m_colourRemapBitDepth, pCriSEI->m_colourRemapInputBitDepth);
    1814 
    1815     //Fill preLut
    1816     for ( Int k=0 ; k<(1<<bitDepth) ; k++ )
    1817     {
    1818       Int iSample = k << iShift1 ;
    1819       for ( Int iPivot=0 ; iPivot<=pCriSEI->m_preLutNumValMinus1[c] ; iPivot++ )
    1820       {
    1821         Int iCodedPrev  = pCriSEI->m_preLutCodedValue[c][iPivot]    << iShift2; //Coded in CRInputBitdepth
    1822         Int iCodedNext  = pCriSEI->m_preLutCodedValue[c][iPivot+1]  << iShift2; //Coded in CRInputBitdepth
    1823         Int iTargetPrev = pCriSEI->m_preLutTargetValue[c][iPivot];              //Coded in CRBitdepth
    1824         Int iTargetNext = pCriSEI->m_preLutTargetValue[c][iPivot+1];            //Coded in CRBitdepth
    1825         if ( iCodedPrev <= iSample && iSample <= iCodedNext )
    1826         {
    1827           Float fInterpol = (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) * 1.f / (Float)(iCodedNext - iCodedPrev);
    1828           preLut[c][k]  = (Int)( 0.5f + fInterpol );
    1829           iPivot = pCriSEI->m_preLutNumValMinus1[c] + 1;
    1830         }
    1831       }
    1832     }
    1833    
    1834     //Fill postLut
    1835     for ( Int k=0 ; k<(1<<pCriSEI->m_colourRemapBitDepth) ; k++ )
    1836     {
    1837       Int iSample = k;
    1838       for ( Int iPivot=0 ; iPivot<=pCriSEI->m_postLutNumValMinus1[c] ; iPivot++ )
    1839       {
    1840         Int iCodedPrev  = pCriSEI->m_postLutCodedValue[c][iPivot];    //Coded in CRBitdepth
    1841         Int iCodedNext  = pCriSEI->m_postLutCodedValue[c][iPivot+1];  //Coded in CRBitdepth
    1842         Int iTargetPrev = pCriSEI->m_postLutTargetValue[c][iPivot];   //Coded in CRBitdepth
    1843         Int iTargetNext = pCriSEI->m_postLutTargetValue[c][iPivot+1]; //Coded in CRBitdepth
    1844         if ( iCodedPrev <= iSample && iSample <= iCodedNext )
    1845         {
    1846           Float fInterpol =  (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) * 1.f / (Float)(iCodedNext - iCodedPrev) ;
    1847           postLut[c][k]  = (Int)( 0.5f + fInterpol );
    1848           iPivot = pCriSEI->m_postLutNumValMinus1[c] + 1;
    1849         }
    1850       }
    1851     }
    1852   }
    1853 }
    1854 
    1855 Void TAppDecTop::xApplyColourRemapping( const TComSPS *sps, TComPicYuv& pic, const SEIColourRemappingInfo* pCriSEI, UInt layerId )
    1856 {
    1857   const BitDepths& bitDpeths = sps->getBitDepths();
    1858 
    1859   if( !storeCriSEI.size() )
    1860   {
    1861 #if SVC_EXTENSION
    1862     storeCriSEI.resize(MAX_LAYERS);
    1863 #else
    1864     storeCriSEI.resize(1);
    1865 #endif
    1866   }
    1867 
    1868   if ( pCriSEI ) //if a CRI SEI has just been retrieved, keep it in memory (persistence management)
    1869   {
    1870     storeCriSEI[layerId] = *pCriSEI;
    1871   }
    1872 
    1873   if( !storeCriSEI[layerId].m_colourRemapCancelFlag && pCriSEI)
    1874   {
    1875     Int iHeight  = pic.getHeight(COMPONENT_Y);
    1876     Int iWidth   = pic.getWidth(COMPONENT_Y);
    1877     Int iStride  = pic.getStride(COMPONENT_Y);
    1878     Int iCStride = pic.getStride(COMPONENT_Cb);
    1879 
    1880     Pel *YUVIn[3], *YUVOut[3];
    1881     YUVIn[0] = pic.getAddr(COMPONENT_Y);
    1882     YUVIn[1] = pic.getAddr(COMPONENT_Cb);
    1883     YUVIn[2] = pic.getAddr(COMPONENT_Cr);
    1884    
    1885     TComPicYuv picColourRemapped;
    1886 
    1887 #if SVC_EXTENSION
    1888 #if AUXILIARY_PICTURES
    1889     picColourRemapped.create( pic.getWidth(COMPONENT_Y), pic.getHeight(COMPONENT_Y), pic.getChromaFormat(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxTotalCUDepth(), true, NULL );
    1890 #else
    1891     picColourRemapped.create( pic.getWidth(), pic.getHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxTotalCUDepth(), true, NULL );
    1892 #endif
    1893 #else
    1894     picColourRemapped.create( pic.getWidth(COMPONENT_Y), pic.getHeight(COMPONENT_Y), pic.getChromaFormat(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxTotalCUDepth(), true );
    1895 #endif
    1896     YUVOut[0] = picColourRemapped.getAddr(COMPONENT_Y);
    1897     YUVOut[1] = picColourRemapped.getAddr(COMPONENT_Cb);
    1898     YUVOut[2] = picColourRemapped.getAddr(COMPONENT_Cr);
    1899 
    1900     std::vector<Int> preLut[3];
    1901     std::vector<Int> postLut[3];
    1902     xInitColourRemappingLut( bitDpeths, preLut, postLut, &storeCriSEI[layerId] );
    1903    
    1904     Int roundingOffset = (storeCriSEI[layerId].m_log2MatrixDenom==0) ? 0 : (1 << (storeCriSEI[layerId].m_log2MatrixDenom - 1));
    1905 
    1906     for( Int y = 0; y < iHeight ; y++ )
    1907     {
    1908       for( Int x = 0; x < iWidth ; x++ )
    1909       {
    1910         Int YUVPre[3], YUVMat[3];
    1911         YUVPre[0] = preLut[0][ YUVIn[0][x]   ];
    1912         YUVPre[1] = preLut[1][ YUVIn[1][x>>1] ];
    1913         YUVPre[2] = preLut[2][ YUVIn[2][x>>1] ];
    1914 
    1915         YUVMat[0] = ( storeCriSEI[layerId].m_colourRemapCoeffs[0][0]*YUVPre[0]
    1916                     + storeCriSEI[layerId].m_colourRemapCoeffs[0][1]*YUVPre[1]
    1917                     + storeCriSEI[layerId].m_colourRemapCoeffs[0][2]*YUVPre[2]
    1918                     + roundingOffset ) >> ( storeCriSEI[layerId].m_log2MatrixDenom );
    1919         YUVMat[0] = Clip3( 0, (1<<storeCriSEI[layerId].m_colourRemapBitDepth)-1, YUVMat[0] );
    1920         YUVOut[0][x] = postLut[0][ YUVMat[0] ];
    1921 
    1922         if( (y&1) && (x&1) )
    1923         {
    1924           for(Int c=1 ; c<3 ; c++)
    1925           {
    1926             YUVMat[c] = ( storeCriSEI[layerId].m_colourRemapCoeffs[c][0]*YUVPre[0]
    1927                         + storeCriSEI[layerId].m_colourRemapCoeffs[c][1]*YUVPre[1]
    1928                         + storeCriSEI[layerId].m_colourRemapCoeffs[c][2]*YUVPre[2]
    1929                         + roundingOffset ) >> ( storeCriSEI[layerId].m_log2MatrixDenom );
    1930             YUVMat[c] = Clip3( 0, (1<<storeCriSEI[layerId].m_colourRemapBitDepth)-1, YUVMat[c] );
    1931             YUVOut[c][x>>1] = postLut[c][ YUVMat[c] ];   
    1932           }
    1933         }
    1934       }
    1935       YUVIn[0]  += iStride;
    1936       YUVOut[0] += iStride;
    1937       if( y&1 )
    1938       {
    1939         YUVIn[1]  += iCStride;
    1940         YUVIn[2]  += iCStride;
    1941         YUVOut[1] += iCStride;
    1942         YUVOut[2] += iCStride;
    1943       }
    1944     }
    1945 
    1946     //Write remapped picture in decoding order
    1947     TChar  cTemp[255];
    1948     sprintf(cTemp, "seiColourRemappedPic_L%d_%dx%d_%dbits.yuv", layerId, iWidth, iHeight, storeCriSEI[layerId].m_colourRemapBitDepth );
    1949     picColourRemapped.dump( cTemp, true, storeCriSEI[layerId].m_colourRemapBitDepth );
    1950 
    1951     picColourRemapped.destroy();
    1952 
    1953     storeCriSEI[layerId].m_colourRemapCancelFlag = !storeCriSEI[layerId].m_colourRemapPersistenceFlag; //Handling persistence
    1954   }
    1955   else
    1956   {
    1957     //Write no remapped picture in decoding order
    1958     if (storeCriSEI[layerId].m_colourRemapBitDepth == 8 || storeCriSEI[layerId].m_colourRemapBitDepth == 10)
    1959     {
    1960       TChar  cTemp[255];
    1961       sprintf(cTemp, "seiColourRemappedPic_L%d_%dx%d_%dbits.yuv", layerId, pic.getWidth(COMPONENT_Y), pic.getHeight(COMPONENT_Y), storeCriSEI[layerId].m_colourRemapBitDepth );
    1962       pic.dump( cTemp, true, storeCriSEI[layerId].m_colourRemapBitDepth );
    1963     }
    1964   }
    1965 }
    1966 #endif
    19672045//! \}
  • branches/SHM-dev/source/App/TAppDecoder/TAppDecTop.h

    r1442 r1460  
    6666  TDecTop*                        m_apcTDecTop[MAX_NUM_LAYER_IDS];                     ///< decoder point class
    6767  TVideoIOYuv*                    m_apcTVideoIOYuvReconFile[MAX_NUM_LAYER_IDS];        ///< reconstruction YUV class
     68#if CONFORMANCE_BITSTREAM_MODE
     69  TVideoIOYuv                     m_confReconFile[63];        ///< decode YUV files
     70#endif
     71  // for output control
     72  Int                             m_aiPOCLastDisplay [MAX_LAYERS]; ///< last POC in display order
    6873#else
    6974  TDecTop                         m_cTDecTop;                     ///< decoder class
    7075  TVideoIOYuv                     m_cTVideoIOYuvReconFile;        ///< reconstruction YUV class
     76
     77  // for output control
     78  Int                             m_iPOCLastDisplay;              ///< last POC in display order
    7179#endif
    72  
    73   // for output control 
     80
    7481  std::ofstream                   m_seiMessageFileStream;         ///< Used for outputing SEI messages.
    7582
    76 #if SVC_EXTENSION
    77 #if CONFORMANCE_BITSTREAM_MODE
    78   TVideoIOYuv                     m_confReconFile[63];        ///< decode YUV files
    79 #endif
    80   Int                             m_aiPOCLastDisplay [MAX_LAYERS]; ///< last POC in display order
    81 #else
    82   Int                             m_iPOCLastDisplay;              ///< last POC in display order
    83 #endif
    8483#if Q0074_COLOUR_REMAPPING_SEI
    85   std::vector<SEIColourRemappingInfo> storeCriSEI; //Persistent Colour Remapping Information SEI
    86   SEIColourRemappingInfo *seiColourRemappingInfoPrevious;
     84  SEIColourRemappingInfo*         m_pcSeiColourRemappingInfoPrevious;
     85  TComPicYuv*                     m_pcPicYuvColourRemapped;       ///< Colour Remapped picture
    8786#endif
    8887
     
    117116  Void  xDestroyDecLib    (); ///< destroy internal classes
    118117  Void  xInitDecLib       (); ///< initialize decoder class
    119  
    120 #if Q0074_COLOUR_REMAPPING_SEI
    121   Void  xInitColourRemappingLut( const BitDepths &bitDepths, std::vector<Int>(&preLut)[3], std::vector<Int>(&postLut)[3], const SEIColourRemappingInfo* const pCriSEI );
    122   Void  xApplyColourRemapping( const TComSPS *sps, TComPicYuv& pic, const SEIColourRemappingInfo* pCriSEI, UInt layerId = 0 );
    123 #endif
     118
    124119#if SVC_EXTENSION
    125120  Void  xWriteOutput      ( TComList<TComPic*>* pcListPic, UInt layerId, UInt tId ); ///< write YUV to file
     
    130125#endif
    131126  Bool  isNaluWithinTargetDecLayerIdSet ( InputNALUnit* nalu ); ///< check whether given Nalu is within targetDecLayerIdSet
     127
     128#if Q0074_COLOUR_REMAPPING_SEI
     129private:
     130  Void applyColourRemapping(const TComPicYuv& pic, SEIColourRemappingInfo& pCriSEI, const TComSPS &activeSPS);
     131  Void xOutputColourRemapPic(TComPic* pcPic, const TComSPS* activeSPS);
     132#endif
    132133#if ALIGNED_BUMPING
    133134  Void checkOutputBeforeDecoding(Int layerIdx);
  • branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp

    r1459 r1460  
    774774  Int*    cfg_maxTidIlRefPicsPlus1[MAX_LAYERS];
    775775#if Q0074_COLOUR_REMAPPING_SEI
    776   string* cfg_colourRemapSEIFileName[MAX_LAYERS];
     776  string* cfg_colourRemapSEIFileRoot[MAX_LAYERS];
    777777#endif
    778778  Bool*   cfg_entropyCodingSyncEnabledFlag[MAX_LAYERS];
     
    793793    cfg_fQP[layer]          = &m_apcLayerCfg[layer]->m_fQP;
    794794#if Q0074_COLOUR_REMAPPING_SEI
    795     cfg_colourRemapSEIFileName[layer] = &m_apcLayerCfg[layer]->m_colourRemapSEIFileName;
     795    cfg_colourRemapSEIFileRoot[layer] = &m_apcLayerCfg[layer]->m_colourRemapSEIFileRoot;
    796796#endif
    797797    cfg_repFormatIdx[layer]         = &m_apcLayerCfg[layer]->m_repFormatIdx;
     
    10731073  ("PhaseVerChroma%d",                              cfg_phaseVerChromaPtr,            string(""), m_numLayers, "chroma shift in the vertical   direction used in resampling proces")
    10741074#if Q0074_COLOUR_REMAPPING_SEI
    1075   ("SEIColourRemappingInfoFileRoot%d",              cfg_colourRemapSEIFileName,       string(""), m_numLayers, "Colour Remapping Information SEI parameters file name for layer %d")
     1075  ("SEIColourRemappingInfoFileRoot%d,-cri",         cfg_colourRemapSEIFileRoot,       string(""), m_numLayers, "Colour Remapping Information SEI parameters root file name (wo num ext)")
    10761076#endif
    10771077  ("InputBitDepth%d",                                cfg_InputBitDepth[CHANNEL_TYPE_LUMA],     8, m_numLayers, "Bit-depth of input file for layer %d")
     
    11411141#if !SVC_EXTENSION
    11421142  ("FrameRate,-fr",                                   m_iFrameRate,                                         0, "Frame rate")
    1143 #if Q0074_COLOUR_REMAPPING_SEI
    1144   ("SEIColourRemappingInfoFileRoot",                  m_colourRemapSEIFileName,                    string(""), "Colour Remapping Information SEI parameters file name")
    1145 #endif
    1146 #endif //SVC_EXTENSION
     1143#endif
    11471144  ("FrameSkip,-fs",                                   m_FrameSkip,                                         0u, "Number of frames to skip at start of input YUV")
    11481145  ("FramesToBeEncoded,f",                             m_framesToBeEncoded,                                  0, "Number of frames to be encoded (default=all)")
     
    14621459  ("Log2MaxMvLengthHorizontal",                       m_log2MaxMvLengthHorizontal,                         15, "Indicate the maximum absolute value of a decoded horizontal MV component in quarter-pel luma units")
    14631460  ("Log2MaxMvLengthVertical",                         m_log2MaxMvLengthVertical,                           15, "Indicate the maximum absolute value of a decoded vertical MV component in quarter-pel luma units")
     1461#if !SVC_EXTENSION
     1462#if Q0074_COLOUR_REMAPPING_SEI
     1463  ("SEIColourRemappingInfoFileRoot,-cri",             m_colourRemapSEIFileRoot,                    string(""), "Colour Remapping Information SEI parameters root file name (wo num ext)")
     1464#endif
     1465#endif
    14641466  ("SEIRecoveryPoint",                                m_recoveryPointSEIEnabled,                        false, "Control generation of recovery point SEI messages")
    14651467  ("SEIBufferingPeriod",                              m_bufferingPeriodSEIEnabled,                      false, "Control generation of buffering period SEI messages")
     
    15661568  ("SEIMasteringDisplayPrimaries",                    cfg_DisplayPrimariesCode,       cfg_DisplayPrimariesCode, "Mastering display primaries for all three colour planes in CIE xy coordinates in increments of 1/50000 (results in the ranges 0 to 50000 inclusive)")
    15671569  ("SEIMasteringDisplayWhitePoint",                   cfg_DisplayWhitePointCode,     cfg_DisplayWhitePointCode, "Mastering display white point CIE xy coordinates in normalised increments of 1/50000 (e.g. 0.333 = 16667)")
    1568  
     1570
    15691571#if LAYERS_NOT_PRESENT_SEI
    15701572  ("SEILayersNotPresent",                             m_layersNotPresentSEIEnabled,             0, "Control generation of layers not present SEI message")
  • branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.h

    r1459 r1460  
    457457  Int       m_log2MaxMvLengthHorizontal;                      ///< Indicate the maximum absolute value of a decoded horizontal MV component in quarter-pel luma units
    458458  Int       m_log2MaxMvLengthVertical;                        ///< Indicate the maximum absolute value of a decoded vertical MV component in quarter-pel luma units
     459#if !SVC_EXTENSION
     460#if Q0074_COLOUR_REMAPPING_SEI
     461  std::string m_colourRemapSEIFileRoot;
     462#endif
     463#endif
    459464
    460465  std::string m_summaryOutFilename;                           ///< filename to use for producing summary output file.
     
    486491  Bool      m_elRapSliceBEnabled;
    487492#endif
    488 #if Q0074_COLOUR_REMAPPING_SEI
    489 #if !SVC_EXTENSION
    490   string    m_colourRemapSEIFileName;
    491 #endif
    492 #endif
     493
    493494  // internal member functions
    494495#if SVC_EXTENSION
  • branches/SHM-dev/source/App/TAppEncoder/TAppEncLayerCfg.cpp

    r1451 r1460  
    3131, m_repFormatIdx(-1)
    3232{
    33 #if Q0074_COLOUR_REMAPPING_SEI
    34   memset( m_colourRemapSEIPreLutCodedValue,   0, sizeof(m_colourRemapSEIPreLutCodedValue) );
    35   memset( m_colourRemapSEIPreLutTargetValue,  0, sizeof(m_colourRemapSEIPreLutTargetValue) );
    36   memset( m_colourRemapSEIPostLutCodedValue,  0, sizeof(m_colourRemapSEIPostLutCodedValue) );
    37   memset( m_colourRemapSEIPostLutTargetValue, 0, sizeof(m_colourRemapSEIPostLutTargetValue) );
    38 #endif
    3933  m_confWinLeft = m_confWinRight = m_confWinTop = m_confWinBottom = 0;
    4034  m_aiPad[1] = m_aiPad[0] = 0;
     
    6458    delete[] m_aidQP;
    6559  }
    66 #if Q0074_COLOUR_REMAPPING_SEI
    67   for( Int c=0 ; c<3 ; c++)
    68   {
    69     if ( m_colourRemapSEIPreLutCodedValue[c] )
    70     {
    71       delete[] m_colourRemapSEIPreLutCodedValue[c];
    72     }
    73     if ( m_colourRemapSEIPreLutTargetValue[c] )
    74     {
    75       delete[] m_colourRemapSEIPreLutTargetValue[c];
    76     }
    77     if ( m_colourRemapSEIPostLutCodedValue[c] )
    78     {
    79       delete[] m_colourRemapSEIPostLutCodedValue[c];
    80     }
    81     if ( m_colourRemapSEIPostLutTargetValue[c] )
    82     {
    83       delete[] m_colourRemapSEIPostLutTargetValue[c];
    84     }
    85   }
    86 #endif
    8760}
    8861
  • branches/SHM-dev/source/App/TAppEncoder/TAppEncLayerCfg.h

    r1459 r1460  
    135135  Int       m_repFormatIdx;
    136136#if Q0074_COLOUR_REMAPPING_SEI
    137   string    m_colourRemapSEIFileName;                         ///< Colour Remapping Information SEI message parameters file
    138   Int       m_colourRemapSEIId;
    139   Bool      m_colourRemapSEICancelFlag;
    140   Bool      m_colourRemapSEIPersistenceFlag;
    141   Bool      m_colourRemapSEIVideoSignalInfoPresentFlag;
    142   Bool      m_colourRemapSEIFullRangeFlag;
    143   Int       m_colourRemapSEIPrimaries;
    144   Int       m_colourRemapSEITransferFunction;
    145   Int       m_colourRemapSEIMatrixCoefficients;
    146   Int       m_colourRemapSEIInputBitDepth;
    147   Int       m_colourRemapSEIBitDepth;
    148   Int       m_colourRemapSEIPreLutNumValMinus1[3];
    149   Int*      m_colourRemapSEIPreLutCodedValue[3];
    150   Int*      m_colourRemapSEIPreLutTargetValue[3];
    151   Bool      m_colourRemapSEIMatrixPresentFlag;
    152   Int       m_colourRemapSEILog2MatrixDenom;
    153   Int       m_colourRemapSEICoeffs[3][3];
    154   Int       m_colourRemapSEIPostLutNumValMinus1[3];
    155   Int*      m_colourRemapSEIPostLutCodedValue[3];
    156   Int*      m_colourRemapSEIPostLutTargetValue[3];
     137  string    m_colourRemapSEIFileRoot;
    157138#endif
    158139
  • branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp

    r1459 r1460  
    505505    Bool&          m_bUseSAO                                    = m_apcLayerCfg[layer]->m_bUseSAO;
    506506
    507     string&        m_colourRemapSEIFileName                     = m_apcLayerCfg[layer]->m_colourRemapSEIFileName;
    508 
    509507    GOPEntry*      m_GOPList                                    = m_apcLayerCfg[layer]->m_GOPList;
    510508    Int&           m_extraRPSs                                  = m_apcLayerCfg[layer]->m_extraRPSs;
    511509    Int&           m_maxTempLayer                               = m_apcLayerCfg[layer]->m_maxTempLayer;
     510
     511#if Q0074_COLOUR_REMAPPING_SEI
     512    string&        m_colourRemapSEIFileRoot                     = m_apcLayerCfg[layer]->m_colourRemapSEIFileRoot;
     513#endif
    512514#endif
    513515
     
    542544  m_cTEncTop.setGopList                                           ( m_GOPList );
    543545  m_cTEncTop.setExtraRPSs                                         ( m_extraRPSs );
    544 
    545546  for(Int i = 0; i < MAX_TLAYER; i++)
    546547  {
     
    765766  m_cTEncTop.setKneeSEIInputKneePoint                             ( m_kneeSEIInputKneePoint );
    766767  m_cTEncTop.setKneeSEIOutputKneePoint                            ( m_kneeSEIOutputKneePoint );
     768#if Q0074_COLOUR_REMAPPING_SEI
     769  m_cTEncTop.setColourRemapInfoSEIFileRoot                        ( m_colourRemapSEIFileRoot );
     770#endif
    767771  m_cTEncTop.setMasteringDisplaySEI                               ( m_masteringDisplay );
    768772
     
    842846  m_cTEncTop.setSummaryVerboseness                                ( m_summaryVerboseness );
    843847
    844 #if Q0074_COLOUR_REMAPPING_SEI
    845   m_cTEncTop.xSetCRISEIFileRoot                                   ( m_colourRemapSEIFileName );
    846 #endif
    847848#if LAYERS_NOT_PRESENT_SEI
    848849  m_cTEncTop.setLayersNotPresentSEIEnabled                        ( m_layersNotPresentSEIEnabled );
  • branches/SHM-dev/source/Lib/TLibCommon/SEI.cpp

    r1442 r1460  
    150150    case SEI::CHROMA_RESAMPLING_FILTER_HINT:        return "Chroma sampling filter hint";
    151151#if Q0074_COLOUR_REMAPPING_SEI
    152     case SEI::COLOUR_REMAPPING_INFO:                return "Colour Remapping Information";
     152    case SEI::COLOUR_REMAPPING_INFO:                return "Colour remapping info";
    153153#endif
    154154#if SVC_EXTENSION
     
    196196}
    197197#endif
    198 
    199 #if Q0074_COLOUR_REMAPPING_SEI
    200 Void  SEIColourRemappingInfo::copyFrom( SEIColourRemappingInfo const * SeiCriInput)
    201 {
    202   m_colourRemapId                         = SeiCriInput->m_colourRemapId;
    203   m_colourRemapCancelFlag                 = SeiCriInput->m_colourRemapCancelFlag;
    204   m_colourRemapPersistenceFlag            = SeiCriInput->m_colourRemapPersistenceFlag;
    205   m_colourRemapVideoSignalInfoPresentFlag = SeiCriInput->m_colourRemapVideoSignalInfoPresentFlag;
    206   m_colourRemapFullRangeFlag              = SeiCriInput->m_colourRemapFullRangeFlag;
    207   m_colourRemapPrimaries                  = SeiCriInput->m_colourRemapPrimaries;
    208   m_colourRemapTransferFunction           = SeiCriInput->m_colourRemapTransferFunction;
    209   m_colourRemapMatrixCoefficients         = SeiCriInput->m_colourRemapMatrixCoefficients;
    210   m_colourRemapInputBitDepth              = SeiCriInput->m_colourRemapInputBitDepth;
    211   m_colourRemapBitDepth                   = SeiCriInput->m_colourRemapBitDepth;
    212 
    213   for( Int c=0 ; c<3 ; c++ )
    214   {
    215     m_preLutNumValMinus1[c] = SeiCriInput->m_preLutNumValMinus1[c];
    216     m_preLutCodedValue[c].resize(m_preLutNumValMinus1[c]+1);
    217     m_preLutTargetValue[c].resize(m_preLutNumValMinus1[c]+1);
    218     for ( Int i=0 ; i <= SeiCriInput->m_preLutNumValMinus1[c] ; i++ )
    219     {
    220         m_preLutCodedValue[c][i]   = SeiCriInput->m_preLutCodedValue[c][i];
    221         m_preLutTargetValue[c][i]  = SeiCriInput->m_preLutTargetValue[c][i];
    222     }
    223   }
    224    
    225   m_colourRemapMatrixPresentFlag  = SeiCriInput->m_colourRemapMatrixPresentFlag;
    226   m_log2MatrixDenom               = SeiCriInput->m_log2MatrixDenom;
    227 
    228   for ( Int c=0 ; c<3 ; c++ )
    229     for ( Int i=0 ; i<3 ; i++ )
    230       m_colourRemapCoeffs[c][i] = SeiCriInput->m_colourRemapCoeffs[c][i];
    231 
    232   for( Int c=0 ; c<3 ; c++ )
    233   {
    234     m_postLutNumValMinus1[c] = SeiCriInput->m_postLutNumValMinus1[c];
    235     m_postLutCodedValue[c].resize(m_postLutNumValMinus1[c]+1);
    236     m_postLutTargetValue[c].resize(m_postLutNumValMinus1[c]+1);
    237     for ( Int i=0 ; i <= m_postLutNumValMinus1[c] ; i++ )
    238     {
    239         m_postLutCodedValue[c][i]  = SeiCriInput->m_postLutCodedValue[c][i];
    240         m_postLutTargetValue[c][i] = SeiCriInput->m_postLutTargetValue[c][i];
    241     }
    242   }
    243 }
    244 #endif
  • branches/SHM-dev/source/Lib/TLibCommon/SEI.h

    r1459 r1460  
    459459};
    460460
     461#if Q0074_COLOUR_REMAPPING_SEI
     462class SEIColourRemappingInfo : public SEI
     463{
     464public:
     465
     466  struct CRIlut
     467  {
     468    Int codedValue;
     469    Int targetValue;
     470    bool operator < (const CRIlut& a) const
     471    {
     472      return codedValue < a.codedValue;
     473    }
     474  };
     475
     476  PayloadType payloadType() const { return COLOUR_REMAPPING_INFO; }
     477  SEIColourRemappingInfo() {}
     478  ~SEIColourRemappingInfo() {}
     479
     480  Void copyFrom( const SEIColourRemappingInfo &seiCriInput)
     481  {
     482    (*this) = seiCriInput;
     483  }
     484
     485  UInt                m_colourRemapId;
     486  Bool                m_colourRemapCancelFlag;
     487  Bool                m_colourRemapPersistenceFlag;
     488  Bool                m_colourRemapVideoSignalInfoPresentFlag;
     489  Bool                m_colourRemapFullRangeFlag;
     490  Int                 m_colourRemapPrimaries;
     491  Int                 m_colourRemapTransferFunction;
     492  Int                 m_colourRemapMatrixCoefficients;
     493  Int                 m_colourRemapInputBitDepth;
     494  Int                 m_colourRemapBitDepth;
     495  Int                 m_preLutNumValMinus1[3];
     496  std::vector<CRIlut> m_preLut[3];
     497  Bool                m_colourRemapMatrixPresentFlag;
     498  Int                 m_log2MatrixDenom;
     499  Int                 m_colourRemapCoeffs[3][3];
     500  Int                 m_postLutNumValMinus1[3];
     501  std::vector<CRIlut> m_postLut[3];
     502};
     503#endif
     504
    461505class SEIChromaResamplingFilterHint : public SEI
    462506{
     
    673717#endif
    674718
    675 #if Q0074_COLOUR_REMAPPING_SEI
    676 struct TComSEIColourRemappingInfo
    677 {
    678   std::string             m_colourRemapSEIFile;
    679   Int                     m_colourRemapSEIId;
    680   Bool                    m_colourRemapSEICancelFlag;
    681   Bool                    m_colourRemapSEIPersistenceFlag;
    682   Bool                    m_colourRemapSEIVideoSignalInfoPresentFlag;
    683   Bool                    m_colourRemapSEIFullRangeFlag;
    684   Int                     m_colourRemapSEIPrimaries;
    685   Int                     m_colourRemapSEITransferFunction;
    686   Int                     m_colourRemapSEIMatrixCoefficients;
    687   Int                     m_colourRemapSEIInputBitDepth;
    688   Int                     m_colourRemapSEIBitDepth;
    689   Int                     m_colourRemapSEIPreLutNumValMinus1[3];
    690   Int*                    m_colourRemapSEIPreLutCodedValue[3];
    691   Int*                    m_colourRemapSEIPreLutTargetValue[3];
    692   Bool                    m_colourRemapSEIMatrixPresentFlag;
    693   Int                     m_colourRemapSEILog2MatrixDenom;
    694   Int                     m_colourRemapSEICoeffs[3][3];
    695   Int                     m_colourRemapSEIPostLutNumValMinus1[3];
    696   Int*                    m_colourRemapSEIPostLutCodedValue[3];
    697   Int*                    m_colourRemapSEIPostLutTargetValue[3];
    698 };
    699 
    700 class SEIColourRemappingInfo : public SEI
    701 {
    702 public:
    703   PayloadType payloadType() const { return COLOUR_REMAPPING_INFO; }
    704   SEIColourRemappingInfo() {}
    705   ~SEIColourRemappingInfo() {}
    706 
    707   Void  copyFrom( SEIColourRemappingInfo const * SeiCriInput);
    708  
    709   Int   m_colourRemapId;
    710   Bool  m_colourRemapCancelFlag;
    711   Bool  m_colourRemapPersistenceFlag;
    712   Bool  m_colourRemapVideoSignalInfoPresentFlag;
    713   Bool  m_colourRemapFullRangeFlag;
    714   Int   m_colourRemapPrimaries;
    715   Int   m_colourRemapTransferFunction;
    716   Int   m_colourRemapMatrixCoefficients;
    717   Int   m_colourRemapInputBitDepth;
    718   Int   m_colourRemapBitDepth;
    719   Int   m_preLutNumValMinus1[3];
    720   std::vector<Int> m_preLutCodedValue[3];
    721   std::vector<Int> m_preLutTargetValue[3];
    722   Bool  m_colourRemapMatrixPresentFlag;
    723   Int   m_log2MatrixDenom;
    724   Int   m_colourRemapCoeffs[3][3];
    725   Int   m_postLutNumValMinus1[3];
    726   std::vector<Int> m_postLutCodedValue[3];
    727   std::vector<Int> m_postLutTargetValue[3];
    728 };
    729 #endif
    730 
    731719#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    732720class SEIInterLayerConstrainedTileSets : public SEI
  • branches/SHM-dev/source/Lib/TLibCommon/TComPicYuv.cpp

    r1442 r1460  
    296296
    297297// NOTE: This function is never called, but may be useful for developers.
    298 Void TComPicYuv::dump (const std::string &fileName, const BitDepths &bitDepths, Bool bAdd) const
    299 {
    300   FILE* pFile = fopen (fileName.c_str(), bAdd?"ab":"wb");
     298Void TComPicYuv::dump (const std::string &fileName, const BitDepths &bitDepths, const Bool bAppend, const Bool bForceTo8Bit) const
     299{
     300  FILE *pFile = fopen (fileName.c_str(), bAppend?"ab":"wb");
     301
     302  Bool is16bit=false;
     303  for(Int comp = 0; comp < getNumberValidComponents() && !bForceTo8Bit; comp++)
     304  {
     305    if (bitDepths.recon[toChannelType(ComponentID(comp))]>8)
     306    {
     307      is16bit=true;
     308    }
     309  }
    301310
    302311  for(Int comp = 0; comp < getNumberValidComponents(); comp++)
    303312  {
    304313    const ComponentID  compId = ComponentID(comp);
    305     const Int          shift  = bitDepths.recon[toChannelType(compId)] - 8;
    306     const Int          offset = (shift>0)?(1<<(shift-1)):0;
    307314    const Pel         *pi     = getAddr(compId);
    308315    const Int          stride = getStride(compId);
     
    310317    const Int          width  = getWidth(compId);
    311318
    312     for (Int y = 0; y < height; y++ )
    313     {
    314       for (Int x = 0; x < width; x++ )
    315       {
    316         UChar uc = (UChar)Clip3<Pel>(0, 255, (pi[x]+offset)>>shift);
    317         fwrite( &uc, sizeof(UChar), 1, pFile );
    318       }
    319       pi += stride;
    320     }
    321   }
    322 
    323   fclose(pFile);
    324 }
    325 
    326 Void TComPicYuv::dump( const std::string &fileName, const Bool bAdd, const Int bitDepth )
    327 {
    328   FILE* pFile = fopen (fileName.c_str(), bAdd?"ab":"wb");
    329 
    330   if( bitDepth == 8 )
    331   {
    332     dump( fileName, bitDepth, bAdd );
    333     return;
    334   }
    335 
    336   for(Int chan = 0; chan < getNumberValidComponents(); chan++)
    337   {
    338     const ComponentID  ch     = ComponentID(chan);
    339     const Pel         *pi     = getAddr(ch);
    340     const Int          stride = getStride(ch);
    341     const Int          height = getHeight(ch);
    342     const Int          width  = getWidth(ch);
    343 
    344     for (Int y = 0; y < height; y++ )
    345     {
    346       for (Int x = 0; x < width; x++ )
    347       {
    348         Pel pix = pi[x];
    349 
    350         UChar uc = pix & 0xff;     
    351         fwrite( &uc, sizeof(UChar), 1, pFile );
    352         uc = (pix >> 8) & 0xff;     
    353         fwrite( &uc, sizeof(UChar), 1, pFile );
    354       }
    355       pi += stride;
    356     }
    357   }
    358  
     319    if (is16bit)
     320    {
     321      for (Int y = 0; y < height; y++ )
     322      {
     323        for (Int x = 0; x < width; x++ )
     324        {
     325          UChar uc = (UChar)((pi[x]>>0) & 0xff);
     326          fwrite( &uc, sizeof(UChar), 1, pFile );
     327          uc = (UChar)((pi[x]>>8) & 0xff);
     328          fwrite( &uc, sizeof(UChar), 1, pFile );
     329        }
     330        pi += stride;
     331      }
     332    }
     333    else
     334    {
     335      const Int shift  = bitDepths.recon[toChannelType(compId)] - 8;
     336      const Int offset = (shift>0)?(1<<(shift-1)):0;
     337      for (Int y = 0; y < height; y++ )
     338      {
     339        for (Int x = 0; x < width; x++ )
     340        {
     341          UChar uc = (UChar)Clip3<Pel>(0, 255, (pi[x]+offset)>>shift);
     342          fwrite( &uc, sizeof(UChar), 1, pFile );
     343        }
     344        pi += stride;
     345      }
     346    }
     347  }
     348
    359349  fclose(pFile);
    360350}
  • branches/SHM-dev/source/Lib/TLibCommon/TComPicYuv.h

    r1442 r1460  
    180180
    181181  //  Dump picture
    182   Void          dump              (const std::string &fileName, const BitDepths &bitDepths, Bool bAdd = false) const ;
     182  Void          dump              (const std::string &fileName, const BitDepths &bitDepths, const Bool bAppend=false, const Bool bForceTo8Bit=false) const ;
    183183
    184184  // Set border extension flag
     
    196196#endif
    197197
    198   Void          dump( const std::string &fileName, const Bool bAdd, const Int bitDepth );
    199 
    200198};// END CLASS DEFINITION TComPicYuv
    201199
  • branches/SHM-dev/source/Lib/TLibCommon/TypeDef.h

    r1459 r1460  
    127127
    128128#endif // SVC_EXTENSION
    129 #define Q0074_COLOUR_REMAPPING_SEI       1      ///< JCTVC-Q0074, JCTVC-R0344: SEI Colour Remapping Information
    130129
    131130//! \ingroup TLibCommon
     
    166165#define T0196_SELECTIVE_RDOQ                              1 ///< selective RDOQ
    167166#define U0040_MODIFIED_WEIGHTEDPREDICTION_WITH_BIPRED_AND_CLIPPING 1
     167#define Q0074_COLOUR_REMAPPING_SEI                        1      ///< JCTVC-Q0074, JCTVC-R0344: SEI Colour Remapping Information
    168168
    169169// ====================================================================================================================
     
    377377  NUMBER_INPUT_COLOUR_SPACE_CONVERSIONS = 4
    378378};
     379
     380#if Q0074_COLOUR_REMAPPING_SEI
     381enum MATRIX_COEFFICIENTS // Table E.5 (Matrix coefficients)
     382{
     383  MATRIX_COEFFICIENTS_RGB                           = 0,
     384  MATRIX_COEFFICIENTS_BT709                         = 1,
     385  MATRIX_COEFFICIENTS_UNSPECIFIED                   = 2,
     386  MATRIX_COEFFICIENTS_RESERVED_BY_ITUISOIEC         = 3,
     387  MATRIX_COEFFICIENTS_USFCCT47                      = 4,
     388  MATRIX_COEFFICIENTS_BT601_625                     = 5,
     389  MATRIX_COEFFICIENTS_BT601_525                     = 6,
     390  MATRIX_COEFFICIENTS_SMPTE240                      = 7,
     391  MATRIX_COEFFICIENTS_YCGCO                         = 8,
     392  MATRIX_COEFFICIENTS_BT2020_NON_CONSTANT_LUMINANCE = 9,
     393  MATRIX_COEFFICIENTS_BT2020_CONSTANT_LUMINANCE     = 10,
     394};
     395#endif
    379396
    380397enum DeblockEdgeDir
  • branches/SHM-dev/source/Lib/TLibDecoder/SEIread.cpp

    r1459 r1460  
    308308      xParseSEIKneeFunctionInfo((SEIKneeFunctionInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
    309309      break;
    310     case SEI::MASTERING_DISPLAY_COLOUR_VOLUME:
    311       sei = new SEIMasteringDisplayColourVolume;
    312       xParseSEIMasteringDisplayColourVolume((SEIMasteringDisplayColourVolume&) *sei, payloadSize, pDecodedMessageOutputStream);
    313       break;
    314310#if Q0074_COLOUR_REMAPPING_SEI
    315311    case SEI::COLOUR_REMAPPING_INFO:
     
    318314      break;
    319315#endif
     316    case SEI::MASTERING_DISPLAY_COLOUR_VOLUME:
     317      sei = new SEIMasteringDisplayColourVolume;
     318      xParseSEIMasteringDisplayColourVolume((SEIMasteringDisplayColourVolume&) *sei, payloadSize, pDecodedMessageOutputStream);
     319      break;
    320320#if SVC_EXTENSION
    321321#if LAYERS_NOT_PRESENT_SEI
     
    13351335}
    13361336
    1337 Void SEIReader::xParseSEIMasteringDisplayColourVolume(SEIMasteringDisplayColourVolume& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
    1338 {
    1339   UInt code;
    1340   output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
    1341 
    1342   sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[0]" ); sei.values.primaries[0][0] = code;
    1343   sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[0]" ); sei.values.primaries[0][1] = code;
    1344 
    1345   sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[1]" ); sei.values.primaries[1][0] = code;
    1346   sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[1]" ); sei.values.primaries[1][1] = code;
    1347 
    1348   sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[2]" ); sei.values.primaries[2][0] = code;
    1349   sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[2]" ); sei.values.primaries[2][1] = code;
    1350 
    1351 
    1352   sei_read_code( pDecodedMessageOutputStream, 16, code, "white_point_x" ); sei.values.whitePoint[0] = code;
    1353   sei_read_code( pDecodedMessageOutputStream, 16, code, "white_point_y" ); sei.values.whitePoint[1] = code;
    1354 
    1355   sei_read_code( pDecodedMessageOutputStream, 32, code, "max_display_mastering_luminance" ); sei.values.maxLuminance = code;
    1356   sei_read_code( pDecodedMessageOutputStream, 32, code, "min_display_mastering_luminance" ); sei.values.minLuminance = code;
    1357 }
    1358 
    13591337#if Q0074_COLOUR_REMAPPING_SEI
    1360 Void SEIReader::xParseSEIColourRemappingInfo(SEIColourRemappingInfo& sei, UInt /*payloadSize*/, std::ostream *pDecodedMessageOutputStream)
     1338Void SEIReader::xParseSEIColourRemappingInfo(SEIColourRemappingInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
    13611339{
    13621340  UInt  uiVal;
    13631341  Int   iVal;
     1342  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
    13641343
    13651344  sei_read_uvlc( pDecodedMessageOutputStream, uiVal, "colour_remap_id" );          sei.m_colourRemapId = uiVal;
     
    13711350    if ( sei.m_colourRemapVideoSignalInfoPresentFlag )
    13721351    {
    1373       sei_read_flag( pDecodedMessageOutputStream, uiVal,    "colour_remap_full_range_flag" );           sei.m_colourRemapFullRangeFlag = uiVal;
    1374       sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_primaries" );                 sei.m_colourRemapPrimaries = uiVal;
    1375       sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_transfer_function" );         sei.m_colourRemapTransferFunction = uiVal;
    1376       sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_matrix_coefficients" );       sei.m_colourRemapMatrixCoefficients = uiVal;
    1377     }
    1378     sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_input_bit_depth" ); sei.m_colourRemapInputBitDepth = uiVal;
    1379     sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_bit_depth" ); sei.m_colourRemapBitDepth = uiVal;
     1352      sei_read_flag( pDecodedMessageOutputStream, uiVal,    "colour_remap_full_range_flag" );            sei.m_colourRemapFullRangeFlag = uiVal;
     1353      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_primaries" );                  sei.m_colourRemapPrimaries = uiVal;
     1354      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_transfer_function" );          sei.m_colourRemapTransferFunction = uiVal;
     1355      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_matrix_coefficients" );        sei.m_colourRemapMatrixCoefficients = uiVal;
     1356    }
     1357    sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_input_bit_depth" );              sei.m_colourRemapInputBitDepth = uiVal;
     1358    sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_bit_depth" );                    sei.m_colourRemapBitDepth = uiVal;
    13801359 
    13811360    for( Int c=0 ; c<3 ; c++ )
    13821361    {
    13831362      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "pre_lut_num_val_minus1[c]" ); sei.m_preLutNumValMinus1[c] = (uiVal==0) ? 1 : uiVal;
    1384       sei.m_preLutCodedValue[c].resize(sei.m_preLutNumValMinus1[c]+1);
    1385       sei.m_preLutTargetValue[c].resize(sei.m_preLutNumValMinus1[c]+1);
     1363      sei.m_preLut[c].resize(sei.m_preLutNumValMinus1[c]+1);
    13861364      if( uiVal> 0 )
     1365      {
    13871366        for ( Int i=0 ; i<=sei.m_preLutNumValMinus1[c] ; i++ )
    13881367        {
    1389           sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapInputBitDepth   + 7 ) >> 3 ) << 3, uiVal, "pre_lut_coded_value[c][i]" );  sei.m_preLutCodedValue[c][i]  = uiVal;
    1390           sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "pre_lut_target_value[c][i]" ); sei.m_preLutTargetValue[c][i] = uiVal;
    1391         }
     1368          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapInputBitDepth   + 7 ) >> 3 ) << 3, uiVal, "pre_lut_coded_value[c][i]" );  sei.m_preLut[c][i].codedValue  = uiVal;
     1369          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "pre_lut_target_value[c][i]" ); sei.m_preLut[c][i].targetValue = uiVal;
     1370        }
     1371      }
    13921372      else // pre_lut_num_val_minus1[c] == 0
    13931373      {
    1394         sei.m_preLutCodedValue[c][0]  = 0;
    1395         sei.m_preLutTargetValue[c][0] = 0;
    1396         sei.m_preLutCodedValue[c][1]  = (1 << sei.m_colourRemapInputBitDepth) - 1 ;
    1397         sei.m_preLutTargetValue[c][1] = (1 << sei.m_colourRemapBitDepth) - 1 ;
     1374        sei.m_preLut[c][0].codedValue  = 0;
     1375        sei.m_preLut[c][0].targetValue = 0;
     1376        sei.m_preLut[c][1].codedValue  = (1 << sei.m_colourRemapInputBitDepth) - 1 ;
     1377        sei.m_preLut[c][1].targetValue = (1 << sei.m_colourRemapBitDepth) - 1 ;
    13981378      }
    13991379    }
     
    14041384      sei_read_code( pDecodedMessageOutputStream, 4, uiVal, "log2_matrix_denom" ); sei.m_log2MatrixDenom = uiVal;
    14051385      for ( Int c=0 ; c<3 ; c++ )
     1386      {
    14061387        for ( Int i=0 ; i<3 ; i++ )
    14071388        {
    14081389          sei_read_svlc( pDecodedMessageOutputStream, iVal, "colour_remap_coeffs[c][i]" ); sei.m_colourRemapCoeffs[c][i] = iVal;
    14091390        }
     1391      }
    14101392    }
    14111393    else // setting default matrix (I3)
    14121394    {
    1413       sei.m_log2MatrixDenom = 0;
     1395      sei.m_log2MatrixDenom = 10;
    14141396      for ( Int c=0 ; c<3 ; c++ )
     1397      {
    14151398        for ( Int i=0 ; i<3 ; i++ )
    1416           sei.m_colourRemapCoeffs[c][i] = (c==i) ? 1 : 0;
     1399        {
     1400          sei.m_colourRemapCoeffs[c][i] = (c==i) << sei.m_log2MatrixDenom;
     1401        }
     1402      }
    14171403    }
    14181404    for( Int c=0 ; c<3 ; c++ )
    14191405    {
    14201406      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "post_lut_num_val_minus1[c]" ); sei.m_postLutNumValMinus1[c] = (uiVal==0) ? 1 : uiVal;
    1421       sei.m_postLutCodedValue[c].resize(sei.m_postLutNumValMinus1[c]+1);
    1422       sei.m_postLutTargetValue[c].resize(sei.m_postLutNumValMinus1[c]+1);
     1407      sei.m_postLut[c].resize(sei.m_postLutNumValMinus1[c]+1);
    14231408      if( uiVal > 0 )
     1409      {
    14241410        for ( Int i=0 ; i<=sei.m_postLutNumValMinus1[c] ; i++ )
    14251411        {
    1426           sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_coded_value[c][i]" );  sei.m_postLutCodedValue[c][i] = uiVal;
    1427           sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_target_value[c][i]" ); sei.m_postLutTargetValue[c][i] = uiVal;
    1428         }
     1412          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_coded_value[c][i]" );  sei.m_postLut[c][i].codedValue = uiVal;
     1413          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_target_value[c][i]" ); sei.m_postLut[c][i].targetValue = uiVal;
     1414        }
     1415      }
    14291416      else
    14301417      {
    1431         sei.m_postLutCodedValue[c][0]  = 0;
    1432         sei.m_postLutTargetValue[c][0] = 0;
    1433         sei.m_postLutTargetValue[c][1] = (1 << sei.m_colourRemapBitDepth) - 1;
    1434         sei.m_postLutCodedValue[c][1]  = (1 << sei.m_colourRemapBitDepth) - 1;
    1435       }
    1436     }
    1437   }
    1438 }
    1439 #endif
    1440 
     1418        sei.m_postLut[c][0].codedValue  = 0;
     1419        sei.m_postLut[c][0].targetValue = 0;
     1420        sei.m_postLut[c][1].targetValue = (1 << sei.m_colourRemapBitDepth) - 1;
     1421        sei.m_postLut[c][1].codedValue  = (1 << sei.m_colourRemapBitDepth) - 1;
     1422      }
     1423    }
     1424  }
     1425}
     1426#endif
     1427
     1428Void SEIReader::xParseSEIMasteringDisplayColourVolume(SEIMasteringDisplayColourVolume& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
     1429{
     1430  UInt code;
     1431  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     1432
     1433  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[0]" ); sei.values.primaries[0][0] = code;
     1434  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[0]" ); sei.values.primaries[0][1] = code;
     1435
     1436  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[1]" ); sei.values.primaries[1][0] = code;
     1437  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[1]" ); sei.values.primaries[1][1] = code;
     1438
     1439  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[2]" ); sei.values.primaries[2][0] = code;
     1440  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[2]" ); sei.values.primaries[2][1] = code;
     1441
     1442
     1443  sei_read_code( pDecodedMessageOutputStream, 16, code, "white_point_x" ); sei.values.whitePoint[0] = code;
     1444  sei_read_code( pDecodedMessageOutputStream, 16, code, "white_point_y" ); sei.values.whitePoint[1] = code;
     1445
     1446  sei_read_code( pDecodedMessageOutputStream, 32, code, "max_display_mastering_luminance" ); sei.values.maxLuminance = code;
     1447  sei_read_code( pDecodedMessageOutputStream, 32, code, "min_display_mastering_luminance" ); sei.values.minLuminance = code;
     1448}
    14411449
    14421450#if SVC_EXTENSION
  • branches/SHM-dev/source/Lib/TLibDecoder/SEIread.h

    r1442 r1460  
    108108  Void xParseSEIKneeFunctionInfo              (SEIKneeFunctionInfo& sei,              UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
    109109  Void xParseSEIMasteringDisplayColourVolume  (SEIMasteringDisplayColourVolume& sei,  UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
     110#if Q0074_COLOUR_REMAPPING_SEI
     111  Void xParseSEIColourRemappingInfo           (SEIColourRemappingInfo& sei,           UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
     112#endif
    110113
    111114  Void sei_read_code(std::ostream *pOS, UInt uiLength, UInt& ruiCode, const TChar *pSymbolName);
     
    114117  Void sei_read_flag(std::ostream *pOS,                UInt& ruiCode, const TChar *pSymbolName);
    115118
    116 #if Q0074_COLOUR_REMAPPING_SEI
    117   Void xParseSEIColourRemappingInfo           (SEIColourRemappingInfo& sei,           UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
    118 #endif
    119119#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    120120  Void xParseSEIInterLayerConstrainedTileSets (SEIInterLayerConstrainedTileSets &sei, UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
  • branches/SHM-dev/source/Lib/TLibEncoder/SEIEncoder.cpp

    r1459 r1460  
    421421}
    422422
     423#if Q0074_COLOUR_REMAPPING_SEI
     424template <typename T>
     425static Void readTokenValue(T            &returnedValue, /// value returned
     426                           Bool         &failed,        /// used and updated
     427                           std::istream &is,            /// stream to read token from
     428                           const TChar  *pToken)        /// token string
     429{
     430  returnedValue=T();
     431  if (failed)
     432  {
     433    return;
     434  }
     435
     436  Int c;
     437  // Ignore any whitespace
     438  while ((c=is.get())!=EOF && isspace(c));
     439  // test for comment mark
     440  while (c=='#')
     441  {
     442    // Ignore to the end of the line
     443    while ((c=is.get())!=EOF && (c!=10 && c!=13));
     444    // Ignore any white space at the start of the next line
     445    while ((c=is.get())!=EOF && isspace(c));
     446  }
     447  // test first character of token
     448  failed=(c!=pToken[0]);
     449  // test remaining characters of token
     450  Int pos;
     451  for(pos=1;!failed && pToken[pos]!=0 && is.get()==pToken[pos]; pos++);
     452  failed|=(pToken[pos]!=0);
     453  // Ignore any whitespace before the ':'
     454  while (!failed && (c=is.get())!=EOF && isspace(c));
     455  failed|=(c!=':');
     456  // Now read the value associated with the token:
     457  if (!failed)
     458  {
     459    is >> returnedValue;
     460    failed=!is.good();
     461    if (!failed)
     462    {
     463      c=is.get();
     464      failed=(c!=EOF && !isspace(c));
     465    }
     466  }
     467  if (failed)
     468  {
     469    std::cerr << "Unable to read token '" << pToken << "'\n";
     470  }
     471}
     472
     473template <typename T>
     474static Void readTokenValueAndValidate(T            &returnedValue, /// value returned
     475                                      Bool         &failed,        /// used and updated
     476                                      std::istream &is,            /// stream to read token from
     477                                      const TChar  *pToken,        /// token string
     478                                      const T      &minInclusive,  /// minimum value allowed, inclusive
     479                                      const T      &maxInclusive)  /// maximum value allowed, inclusive
     480{
     481  readTokenValue(returnedValue, failed, is, pToken);
     482  if (!failed)
     483  {
     484    if (returnedValue<minInclusive || returnedValue>maxInclusive)
     485    {
     486      failed=true;
     487      std::cerr << "Value for token " << pToken << " must be in the range " << minInclusive << " to " << maxInclusive << " (inclusive); value read: " << returnedValue << std::endl;
     488    }
     489  }
     490}
     491
     492// Bool version does not have maximum and minimum values.
     493static Void readTokenValueAndValidate(Bool         &returnedValue, /// value returned
     494                                      Bool         &failed,        /// used and updated
     495                                      std::istream &is,            /// stream to read token from
     496                                      const TChar  *pToken)        /// token string
     497{
     498  readTokenValue(returnedValue, failed, is, pToken);
     499}
     500
     501Bool SEIEncoder::initSEIColourRemappingInfo(SEIColourRemappingInfo* seiColourRemappingInfo, Int currPOC) // returns true on success, false on failure.
     502{
     503  assert (m_isInitialized);
     504  assert (seiColourRemappingInfo!=NULL);
     505
     506  // reading external Colour Remapping Information SEI message parameters from file
     507  if( !m_pcCfg->getColourRemapInfoSEIFileRoot().empty())
     508  {
     509    Bool failed=false;
     510
     511    // building the CRI file name with poc num in prefix "_poc.txt"
     512    std::string colourRemapSEIFileWithPoc(m_pcCfg->getColourRemapInfoSEIFileRoot());
     513    {
     514      std::stringstream suffix;
     515      suffix << "_" << currPOC << ".txt";
     516      colourRemapSEIFileWithPoc+=suffix.str();
     517    }
     518
     519    std::ifstream fic(colourRemapSEIFileWithPoc.c_str());
     520    if (!fic.good() || !fic.is_open())
     521    {
     522      std::cerr <<  "No Colour Remapping Information SEI parameters file " << colourRemapSEIFileWithPoc << " for POC " << currPOC << std::endl;
     523      return false;
     524    }
     525
     526    // TODO: identify and remove duplication with decoder parsing through abstraction.
     527
     528    readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapId,         failed, fic, "colour_remap_id",        UInt(0), UInt(0x7fffffff) );
     529    readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapCancelFlag, failed, fic, "colour_remap_cancel_flag" );
     530    if( !seiColourRemappingInfo->m_colourRemapCancelFlag )
     531    {
     532      readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapPersistenceFlag,            failed, fic, "colour_remap_persistence_flag" );
     533      readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapVideoSignalInfoPresentFlag, failed, fic, "colour_remap_video_signal_info_present_flag");
     534      if( seiColourRemappingInfo->m_colourRemapVideoSignalInfoPresentFlag )
     535      {
     536        readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapFullRangeFlag,      failed, fic, "colour_remap_full_range_flag" );
     537        readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapPrimaries,          failed, fic, "colour_remap_primaries",           Int(0), Int(255) );
     538        readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapTransferFunction,   failed, fic, "colour_remap_transfer_function",   Int(0), Int(255) );
     539        readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapMatrixCoefficients, failed, fic, "colour_remap_matrix_coefficients", Int(0), Int(255) );
     540      }
     541      readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapInputBitDepth, failed, fic, "colour_remap_input_bit_depth",            Int(8), Int(16) );
     542      readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapBitDepth,      failed, fic, "colour_remap_bit_depth",                  Int(8), Int(16) );
     543
     544      const Int maximumInputValue    = (1<<seiColourRemappingInfo->m_colourRemapInputBitDepth)-1;
     545      const Int maximumRemappedValue = (1<<seiColourRemappingInfo->m_colourRemapBitDepth)-1;
     546
     547      for( Int c=0 ; c<3 ; c++ )
     548      {
     549        readTokenValueAndValidate(seiColourRemappingInfo->m_preLutNumValMinus1[c],         failed, fic, "pre_lut_num_val_minus1[c]",        Int(0), Int(32) );
     550        if( seiColourRemappingInfo->m_preLutNumValMinus1[c]>0 )
     551        {
     552          seiColourRemappingInfo->m_preLut[c].resize(seiColourRemappingInfo->m_preLutNumValMinus1[c]+1);
     553          for( Int i=0 ; i<=seiColourRemappingInfo->m_preLutNumValMinus1[c] ; i++ )
     554          {
     555            readTokenValueAndValidate(seiColourRemappingInfo->m_preLut[c][i].codedValue,   failed, fic, "pre_lut_coded_value[c][i]",  Int(0), maximumInputValue    );
     556            readTokenValueAndValidate(seiColourRemappingInfo->m_preLut[c][i].targetValue,  failed, fic, "pre_lut_target_value[c][i]", Int(0), maximumRemappedValue );
     557          }
     558        }
     559      }
     560      readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapMatrixPresentFlag, failed, fic, "colour_remap_matrix_present_flag" );
     561      if( seiColourRemappingInfo->m_colourRemapMatrixPresentFlag )
     562      {
     563        readTokenValueAndValidate(seiColourRemappingInfo->m_log2MatrixDenom, failed, fic, "log2_matrix_denom", Int(0), Int(15) );
     564        for( Int c=0 ; c<3 ; c++ )
     565        {
     566          for( Int i=0 ; i<3 ; i++ )
     567          {
     568            readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapCoeffs[c][i], failed, fic, "colour_remap_coeffs[c][i]", -32768, 32767 );
     569          }
     570        }
     571      }
     572      for( Int c=0 ; c<3 ; c++ )
     573      {
     574        readTokenValueAndValidate(seiColourRemappingInfo->m_postLutNumValMinus1[c], failed, fic, "post_lut_num_val_minus1[c]", Int(0), Int(32) );
     575        if( seiColourRemappingInfo->m_postLutNumValMinus1[c]>0 )
     576        {
     577          seiColourRemappingInfo->m_postLut[c].resize(seiColourRemappingInfo->m_postLutNumValMinus1[c]+1);
     578          for( Int i=0 ; i<=seiColourRemappingInfo->m_postLutNumValMinus1[c] ; i++ )
     579          {
     580            readTokenValueAndValidate(seiColourRemappingInfo->m_postLut[c][i].codedValue,  failed, fic, "post_lut_coded_value[c][i]",  Int(0), maximumRemappedValue );
     581            readTokenValueAndValidate(seiColourRemappingInfo->m_postLut[c][i].targetValue, failed, fic, "post_lut_target_value[c][i]", Int(0), maximumRemappedValue );
     582          }
     583        }
     584      }
     585    }
     586
     587    if( failed )
     588    {
     589      std::cerr << "Error while reading Colour Remapping Information SEI parameters file '" << colourRemapSEIFileWithPoc << "'" << std::endl;
     590      exit(EXIT_FAILURE);
     591    }
     592  }
     593  return true;
     594}
     595#endif
     596
    423597Void SEIEncoder::initSEIChromaResamplingFilterHint(SEIChromaResamplingFilterHint *seiChromaResamplingFilterHint, Int iHorFilterIndex, Int iVerFilterIndex)
    424598{
     
    646820#endif
    647821
    648 #if Q0074_COLOUR_REMAPPING_SEI
    649 Void SEIEncoder::initSEIColourRemappingInfo(SEIColourRemappingInfo *seiColourRemappingInfo, TComSEIColourRemappingInfo* cfgSeiColourRemappingInfo)
    650 {
    651   seiColourRemappingInfo->m_colourRemapId         = cfgSeiColourRemappingInfo->m_colourRemapSEIId;
    652   seiColourRemappingInfo->m_colourRemapCancelFlag = cfgSeiColourRemappingInfo->m_colourRemapSEICancelFlag;
    653   printf("xCreateSEIColourRemappingInfo - m_colourRemapId = %d m_colourRemapCancelFlag = %d \n",seiColourRemappingInfo->m_colourRemapId, seiColourRemappingInfo->m_colourRemapCancelFlag);
    654 
    655   if( !seiColourRemappingInfo->m_colourRemapCancelFlag )
    656   {
    657     seiColourRemappingInfo->m_colourRemapPersistenceFlag            = cfgSeiColourRemappingInfo->m_colourRemapSEIPersistenceFlag;
    658     seiColourRemappingInfo->m_colourRemapVideoSignalInfoPresentFlag = cfgSeiColourRemappingInfo->m_colourRemapSEIVideoSignalInfoPresentFlag;
    659     if( seiColourRemappingInfo->m_colourRemapVideoSignalInfoPresentFlag )
    660     {
    661       seiColourRemappingInfo->m_colourRemapFullRangeFlag           = cfgSeiColourRemappingInfo->m_colourRemapSEIFullRangeFlag;
    662       seiColourRemappingInfo->m_colourRemapPrimaries               = cfgSeiColourRemappingInfo->m_colourRemapSEIPrimaries;
    663       seiColourRemappingInfo->m_colourRemapTransferFunction        = cfgSeiColourRemappingInfo->m_colourRemapSEITransferFunction;
    664       seiColourRemappingInfo->m_colourRemapMatrixCoefficients      = cfgSeiColourRemappingInfo->m_colourRemapSEIMatrixCoefficients;
    665     }
    666     seiColourRemappingInfo->m_colourRemapInputBitDepth             = cfgSeiColourRemappingInfo->m_colourRemapSEIInputBitDepth;
    667     seiColourRemappingInfo->m_colourRemapBitDepth                  = cfgSeiColourRemappingInfo->m_colourRemapSEIBitDepth;
    668     for( Int c=0 ; c<3 ; c++ )
    669     {
    670       seiColourRemappingInfo->m_preLutNumValMinus1[c] = cfgSeiColourRemappingInfo->m_colourRemapSEIPreLutNumValMinus1[c];
    671       if( seiColourRemappingInfo->m_preLutNumValMinus1[c]>0 )
    672       {
    673         seiColourRemappingInfo->m_preLutCodedValue[c].resize(seiColourRemappingInfo->m_preLutNumValMinus1[c]+1);
    674         seiColourRemappingInfo->m_preLutTargetValue[c].resize(seiColourRemappingInfo->m_preLutNumValMinus1[c]+1);
    675         for( Int i=0 ; i<=seiColourRemappingInfo->m_preLutNumValMinus1[c] ; i++)
    676         {
    677           seiColourRemappingInfo->m_preLutCodedValue[c][i]  = cfgSeiColourRemappingInfo->m_colourRemapSEIPreLutCodedValue[c][i];
    678           seiColourRemappingInfo->m_preLutTargetValue[c][i] = cfgSeiColourRemappingInfo->m_colourRemapSEIPreLutTargetValue[c][i];
    679         }
    680       }
    681     }
    682     seiColourRemappingInfo->m_colourRemapMatrixPresentFlag = cfgSeiColourRemappingInfo->m_colourRemapSEIMatrixPresentFlag;
    683     if( seiColourRemappingInfo->m_colourRemapMatrixPresentFlag )
    684     {
    685       seiColourRemappingInfo->m_log2MatrixDenom = cfgSeiColourRemappingInfo->m_colourRemapSEILog2MatrixDenom;
    686       for( Int c=0 ; c<3 ; c++ )
    687         for( Int i=0 ; i<3 ; i++ )
    688           seiColourRemappingInfo->m_colourRemapCoeffs[c][i] = cfgSeiColourRemappingInfo->m_colourRemapSEICoeffs[c][i];
    689     }
    690     for( Int c=0 ; c<3 ; c++ )
    691     {
    692       seiColourRemappingInfo->m_postLutNumValMinus1[c] = cfgSeiColourRemappingInfo->m_colourRemapSEIPostLutNumValMinus1[c];
    693       if( seiColourRemappingInfo->m_postLutNumValMinus1[c]>0 )
    694       {
    695         seiColourRemappingInfo->m_postLutCodedValue[c].resize(seiColourRemappingInfo->m_postLutNumValMinus1[c]+1);
    696         seiColourRemappingInfo->m_postLutTargetValue[c].resize(seiColourRemappingInfo->m_postLutNumValMinus1[c]+1);
    697         for( Int i=0 ; i<=seiColourRemappingInfo->m_postLutNumValMinus1[c] ; i++)
    698         {
    699           seiColourRemappingInfo->m_postLutCodedValue[c][i]  = cfgSeiColourRemappingInfo->m_colourRemapSEIPostLutCodedValue[c][i];
    700           seiColourRemappingInfo->m_postLutTargetValue[c][i] = cfgSeiColourRemappingInfo->m_colourRemapSEIPostLutTargetValue[c][i];
    701         }
    702       }
    703     }
    704   }
    705 }
    706 #endif
    707 
    708 
    709822#if O0164_MULTI_LAYER_HRD
    710823Void SEIEncoder::initBspNestingSEI(SEIScalableNesting *seiScalableNesting, const TComVPS *vps, const TComSPS *sps, Int olsIdx, Int partitioningSchemeIdx, Int bspIdx)
  • branches/SHM-dev/source/Lib/TLibEncoder/SEIEncoder.h

    r1434 r1460  
    8181  Void initSEIChromaResamplingFilterHint(SEIChromaResamplingFilterHint *sei, Int iHorFilterIndex, Int iVerFilterIndex);
    8282  Void initSEITimeCode(SEITimeCode *sei);
     83#if Q0074_COLOUR_REMAPPING_SEI
     84  Bool initSEIColourRemappingInfo(SEIColourRemappingInfo *sei, Int currPOC); // returns true on success, false on failure.
     85#endif
    8386
    8487#if LAYERS_NOT_PRESENT_SEI
     
    9396#if Q0096_OVERLAY_SEI
    9497  Void initSEIOverlayInfo(SEIOverlayInfo *seiOverlayInfo);
    95 #endif
    96 #if Q0074_COLOUR_REMAPPING_SEI
    97   Void initSEIColourRemappingInfo(SEIColourRemappingInfo *seiColourRemappingInfo, TComSEIColourRemappingInfo* cfgSeiColourRemappingInfo);
    9898#endif
    9999#if O0164_MULTI_LAYER_HRD
  • branches/SHM-dev/source/Lib/TLibEncoder/SEIwrite.cpp

    r1459 r1460  
    152152    xWriteSEIKneeFunctionInfo(*static_cast<const SEIKneeFunctionInfo*>(&sei));
    153153    break;
    154   case SEI::MASTERING_DISPLAY_COLOUR_VOLUME:
    155     xWriteSEIMasteringDisplayColourVolume(*static_cast<const SEIMasteringDisplayColourVolume*>(&sei));
    156     break;
    157154#if Q0074_COLOUR_REMAPPING_SEI
    158155  case SEI::COLOUR_REMAPPING_INFO:
     
    160157    break;
    161158#endif
     159  case SEI::MASTERING_DISPLAY_COLOUR_VOLUME:
     160    xWriteSEIMasteringDisplayColourVolume(*static_cast<const SEIMasteringDisplayColourVolume*>(&sei));
     161    break;
    162162#if SVC_EXTENSION
    163163#if LAYERS_NOT_PRESENT_SEI
     
    987987}
    988988
     989#if Q0074_COLOUR_REMAPPING_SEI
     990Void SEIWriter::xWriteSEIColourRemappingInfo(const SEIColourRemappingInfo& sei)
     991{
     992  WRITE_UVLC( sei.m_colourRemapId,                             "colour_remap_id" );
     993  WRITE_FLAG( sei.m_colourRemapCancelFlag,                     "colour_remap_cancel_flag" );
     994  if( !sei.m_colourRemapCancelFlag )
     995  {
     996    WRITE_FLAG( sei.m_colourRemapPersistenceFlag,              "colour_remap_persistence_flag" );
     997    WRITE_FLAG( sei.m_colourRemapVideoSignalInfoPresentFlag,   "colour_remap_video_signal_info_present_flag" );
     998    if ( sei.m_colourRemapVideoSignalInfoPresentFlag )
     999    {
     1000      WRITE_FLAG( sei.m_colourRemapFullRangeFlag,              "colour_remap_full_range_flag" );
     1001      WRITE_CODE( sei.m_colourRemapPrimaries,               8, "colour_remap_primaries" );
     1002      WRITE_CODE( sei.m_colourRemapTransferFunction,        8, "colour_remap_transfer_function" );
     1003      WRITE_CODE( sei.m_colourRemapMatrixCoefficients,      8, "colour_remap_matrix_coefficients" );
     1004    }
     1005    WRITE_CODE( sei.m_colourRemapInputBitDepth,             8, "colour_remap_input_bit_depth" );
     1006    WRITE_CODE( sei.m_colourRemapBitDepth,                  8, "colour_remap_bit_depth" );
     1007    for( Int c=0 ; c<3 ; c++ )
     1008    {
     1009      WRITE_CODE( sei.m_preLutNumValMinus1[c],              8, "pre_lut_num_val_minus1[c]" );
     1010      if( sei.m_preLutNumValMinus1[c]>0 )
     1011      {
     1012        for( Int i=0 ; i<=sei.m_preLutNumValMinus1[c] ; i++ )
     1013        {
     1014          WRITE_CODE( sei.m_preLut[c][i].codedValue,  (( sei.m_colourRemapInputBitDepth + 7 ) >> 3 ) << 3, "pre_lut_coded_value[c][i]" );
     1015          WRITE_CODE( sei.m_preLut[c][i].targetValue, (( sei.m_colourRemapBitDepth      + 7 ) >> 3 ) << 3, "pre_lut_target_value[c][i]" );
     1016        }
     1017      }
     1018    }
     1019    WRITE_FLAG( sei.m_colourRemapMatrixPresentFlag,            "colour_remap_matrix_present_flag" );
     1020    if( sei.m_colourRemapMatrixPresentFlag )
     1021    {
     1022      WRITE_CODE( sei.m_log2MatrixDenom,                    4, "log2_matrix_denom" );
     1023      for( Int c=0 ; c<3 ; c++ )
     1024      {
     1025        for( Int i=0 ; i<3 ; i++ )
     1026        {
     1027          WRITE_SVLC( sei.m_colourRemapCoeffs[c][i],           "colour_remap_coeffs[c][i]" );
     1028        }
     1029      }
     1030    }
     1031
     1032    for( Int c=0 ; c<3 ; c++ )
     1033    {
     1034      WRITE_CODE( sei.m_postLutNumValMinus1[c],             8, "m_postLutNumValMinus1[c]" );
     1035      if( sei.m_postLutNumValMinus1[c]>0 )
     1036      {
     1037        for( Int i=0 ; i<=sei.m_postLutNumValMinus1[c] ; i++ )
     1038        {
     1039          WRITE_CODE( sei.m_postLut[c][i].codedValue, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, "post_lut_coded_value[c][i]" );
     1040          WRITE_CODE( sei.m_postLut[c][i].targetValue, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, "post_lut_target_value[c][i]" );
     1041        }
     1042      }
     1043    }
     1044  }
     1045}
     1046#endif
    9891047
    9901048Void SEIWriter::xWriteSEIMasteringDisplayColourVolume(const SEIMasteringDisplayColourVolume& sei)
     
    13261384#endif //SVC_EXTENSION
    13271385
    1328 #if Q0074_COLOUR_REMAPPING_SEI
    1329 Void SEIWriter::xWriteSEIColourRemappingInfo(const SEIColourRemappingInfo& sei)
    1330 {
    1331   WRITE_UVLC( sei.m_colourRemapId,                             "colour_remap_id" );
    1332   WRITE_FLAG( sei.m_colourRemapCancelFlag,                     "colour_remap_cancel_flag" );
    1333   if( !sei.m_colourRemapCancelFlag )
    1334   {
    1335     WRITE_FLAG( sei.m_colourRemapPersistenceFlag,              "colour_remap_persistence_flag" );
    1336     WRITE_FLAG( sei.m_colourRemapVideoSignalInfoPresentFlag,   "colour_remap_video_signal_info_present_flag" );
    1337     if ( sei.m_colourRemapVideoSignalInfoPresentFlag )
    1338     {
    1339       WRITE_FLAG( sei.m_colourRemapFullRangeFlag,              "colour_remap_full_range_flag" );
    1340       WRITE_CODE( sei.m_colourRemapPrimaries,               8, "colour_remap_primaries" );
    1341       WRITE_CODE( sei.m_colourRemapTransferFunction,        8, "colour_remap_transfer_function" );
    1342       WRITE_CODE( sei.m_colourRemapMatrixCoefficients,      8, "colour_remap_matrix_coefficients" );
    1343     }
    1344     WRITE_CODE( sei.m_colourRemapInputBitDepth,             8, "colour_remap_input_bit_depth" );
    1345     WRITE_CODE( sei.m_colourRemapBitDepth,                  8, "colour_remap_bit_depth" );
    1346     for( Int c=0 ; c<3 ; c++ )
    1347     {
    1348       WRITE_CODE( sei.m_preLutNumValMinus1[c],              8, "pre_lut_num_val_minus1[c]" );
    1349       if( sei.m_preLutNumValMinus1[c]>0 )
    1350         for( Int i=0 ; i<=sei.m_preLutNumValMinus1[c] ; i++ )
    1351         {
    1352           WRITE_CODE( sei.m_preLutCodedValue[c][i], (( sei.m_colourRemapInputBitDepth + 7 ) >> 3 ) << 3, "pre_lut_coded_value[c][i]" );
    1353           WRITE_CODE( sei.m_preLutTargetValue[c][i], (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, "pre_lut_target_value[c][i]" );
    1354         }
    1355     }
    1356     WRITE_FLAG( sei.m_colourRemapMatrixPresentFlag,            "colour_remap_matrix_present_flag" );
    1357     if( sei.m_colourRemapMatrixPresentFlag )
    1358     {
    1359       WRITE_CODE( sei.m_log2MatrixDenom,                    4, "log2_matrix_denom" );
    1360       for( Int c=0 ; c<3 ; c++ )
    1361         for( Int i=0 ; i<3 ; i++ )
    1362           WRITE_SVLC( sei.m_colourRemapCoeffs[c][i],           "colour_remap_coeffs[c][i]" );
    1363     }
    1364 
    1365     for( Int c=0 ; c<3 ; c++ )
    1366     {
    1367       WRITE_CODE( sei.m_postLutNumValMinus1[c],             8, "m_postLutNumValMinus1[c]" );
    1368       if( sei.m_postLutNumValMinus1[c]>0 )
    1369         for( Int i=0 ; i<=sei.m_postLutNumValMinus1[c] ; i++ )
    1370         {
    1371           WRITE_CODE( sei.m_postLutCodedValue[c][i], (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, "post_lut_coded_value[c][i]" );       
    1372           WRITE_CODE( sei.m_postLutTargetValue[c][i], (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, "post_lut_target_value[c][i]" );
    1373         }
    1374     }
    1375   }
    1376 }
    1377 #endif
    1378 
    13791386//! \}
  • branches/SHM-dev/source/Lib/TLibEncoder/SEIwrite.h

    r1434 r1460  
    8989  Void xWriteSEIChromaResamplingFilterHint(const SEIChromaResamplingFilterHint& sei);
    9090  Void xWriteSEIKneeFunctionInfo(const SEIKneeFunctionInfo &sei);
     91#if Q0074_COLOUR_REMAPPING_SEI
     92  Void xWriteSEIColourRemappingInfo(const SEIColourRemappingInfo& sei);
     93#endif
    9194  Void xWriteSEIMasteringDisplayColourVolume( const SEIMasteringDisplayColourVolume& sei);
    9295
     
    97100#endif
    98101  Void xWriteByteAlign();
    99 #if Q0074_COLOUR_REMAPPING_SEI
    100   Void xWriteSEIColourRemappingInfo(const SEIColourRemappingInfo& sei);
    101 #endif
     102
    102103#if SVC_EXTENSION
    103104#if LAYERS_NOT_PRESENT_SEI
  • branches/SHM-dev/source/Lib/TLibEncoder/TEncCfg.h

    r1459 r1460  
    321321  Int*      m_kneeSEIInputKneePoint;
    322322  Int*      m_kneeSEIOutputKneePoint;
     323#if Q0074_COLOUR_REMAPPING_SEI
     324  std::string m_colourRemapSEIFileRoot;          ///< SEI Colour Remapping File (initialized from external file)
     325#endif
    323326  TComSEIMasteringDisplay m_masteringDisplay;
    324327  //====== Weighted Prediction ========
     
    907910  Void  setKneeSEIOutputKneePoint(Int *p)                            { m_kneeSEIOutputKneePoint = p; }
    908911  Int*  getKneeSEIOutputKneePoint()                                  { return m_kneeSEIOutputKneePoint; }
     912#if Q0074_COLOUR_REMAPPING_SEI
     913  Void  setColourRemapInfoSEIFileRoot( const std::string &s )        { m_colourRemapSEIFileRoot = s; }
     914  const std::string &getColourRemapInfoSEIFileRoot() const           { return m_colourRemapSEIFileRoot; }
     915#endif
    909916  Void  setMasteringDisplaySEI(const TComSEIMasteringDisplay &src)   { m_masteringDisplay = src; }
    910917  const TComSEIMasteringDisplay &getMasteringDisplaySEI() const      { return m_masteringDisplay; }
     
    10991106  Bool  getAlphaClipTypeFlag()                               { return m_alphaClipTypeFlag; }
    11001107#endif
    1101 #if Q0074_COLOUR_REMAPPING_SEI
    1102   Void  xSetCRISEIFileRoot( std::string pch )                { m_colourRemapSEIFileName = pch; }
    1103   std::string& getCRISEIFileRoot()                           { return m_colourRemapSEIFileName; }
    1104 #endif
    11051108#if SVC_EXTENSION
    11061109  UInt      getLayerId()                                     { return m_layerId;    }
  • branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp

    r1459 r1460  
    117117  m_prevPicHasEos    = false;
    118118#endif //SVC_EXTENSION
    119 
    120 #if Q0074_COLOUR_REMAPPING_SEI
    121   memset( m_seiColourRemappingInfo.m_colourRemapSEIPreLutCodedValue,   0, sizeof(m_seiColourRemappingInfo.m_colourRemapSEIPreLutCodedValue));
    122   memset( m_seiColourRemappingInfo.m_colourRemapSEIPreLutTargetValue,  0, sizeof(m_seiColourRemappingInfo.m_colourRemapSEIPreLutTargetValue));
    123   memset( m_seiColourRemappingInfo.m_colourRemapSEIPostLutCodedValue,  0, sizeof(m_seiColourRemappingInfo.m_colourRemapSEIPostLutCodedValue));
    124   memset( m_seiColourRemappingInfo.m_colourRemapSEIPostLutTargetValue, 0, sizeof(m_seiColourRemappingInfo.m_colourRemapSEIPostLutTargetValue));
    125 #endif
    126119  return;
    127120}
     
    702695}
    703696
    704 #if Q0074_COLOUR_REMAPPING_SEI
    705 Void TEncGOP::xFreeColourCRI()
    706 {
    707   for( Int c=0 ; c<3 ; c++)
    708   {
    709     if ( m_seiColourRemappingInfo.m_colourRemapSEIPreLutCodedValue[c] != NULL)
    710     {
    711       delete[] m_seiColourRemappingInfo.m_colourRemapSEIPreLutCodedValue[c];
    712       m_seiColourRemappingInfo.m_colourRemapSEIPreLutCodedValue[c] = NULL;
    713     }
    714     if ( m_seiColourRemappingInfo.m_colourRemapSEIPreLutTargetValue[c] != NULL)
    715     {
    716       delete[] m_seiColourRemappingInfo.m_colourRemapSEIPreLutTargetValue[c];
    717       m_seiColourRemappingInfo.m_colourRemapSEIPreLutTargetValue[c] = NULL;
    718     }
    719     if ( m_seiColourRemappingInfo.m_colourRemapSEIPostLutCodedValue[c] != NULL)
    720     {
    721       delete[] m_seiColourRemappingInfo.m_colourRemapSEIPostLutCodedValue[c];
    722       m_seiColourRemappingInfo.m_colourRemapSEIPostLutCodedValue[c] = NULL;
    723     }
    724     if ( m_seiColourRemappingInfo.m_colourRemapSEIPostLutTargetValue[c] != NULL)
    725     {
    726       delete[] m_seiColourRemappingInfo.m_colourRemapSEIPostLutTargetValue[c];
    727       m_seiColourRemappingInfo.m_colourRemapSEIPostLutTargetValue[c] = NULL;
    728     }
    729   }
    730 }
    731 
    732 Int TEncGOP::xReadingCRIparameters(){
    733 
    734   // reading external Colour Remapping Information SEI message parameters from file
    735   if( m_seiColourRemappingInfo.m_colourRemapSEIFile.c_str() )
    736   {
    737     FILE* fic;
    738     Int retval;
    739     if((fic = fopen(m_seiColourRemappingInfo.m_colourRemapSEIFile.c_str(),"r")) == (FILE*)NULL)
    740     {
    741       //fprintf(stderr, "Can't open Colour Remapping Information SEI parameters file %s\n", m_colourRemapSEIFile.c_str());
    742       //exit(EXIT_FAILURE);
    743       return (-1);
    744     }
    745     Int tempCode;
    746     retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEIId );
    747     retval = fscanf( fic, "%d", &tempCode ); m_seiColourRemappingInfo.m_colourRemapSEICancelFlag = tempCode ? 1 : 0;
    748     if( !m_seiColourRemappingInfo.m_colourRemapSEICancelFlag )
    749     {
    750       retval = fscanf( fic, "%d", &tempCode ); m_seiColourRemappingInfo.m_colourRemapSEIPersistenceFlag= tempCode ? 1 : 0;
    751       retval = fscanf( fic, "%d", &tempCode); m_seiColourRemappingInfo.m_colourRemapSEIVideoSignalInfoPresentFlag = tempCode ? 1 : 0;
    752       if( m_seiColourRemappingInfo.m_colourRemapSEIVideoSignalInfoPresentFlag )
    753       {
    754         retval = fscanf( fic, "%d", &tempCode  ); m_seiColourRemappingInfo.m_colourRemapSEIFullRangeFlag = tempCode ? 1 : 0;
    755         retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEIPrimaries );
    756         retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEITransferFunction );
    757         retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEIMatrixCoefficients );
    758       }
    759 
    760       retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEIInputBitDepth );
    761       retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEIBitDepth );
    762  
    763       for( Int c=0 ; c<3 ; c++ )
    764       {
    765         retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEIPreLutNumValMinus1[c] );
    766         if( m_seiColourRemappingInfo.m_colourRemapSEIPreLutNumValMinus1[c]>0 )
    767         {
    768           m_seiColourRemappingInfo.m_colourRemapSEIPreLutCodedValue[c]  = new Int[m_seiColourRemappingInfo.m_colourRemapSEIPreLutNumValMinus1[c]+1];
    769           m_seiColourRemappingInfo.m_colourRemapSEIPreLutTargetValue[c] = new Int[m_seiColourRemappingInfo.m_colourRemapSEIPreLutNumValMinus1[c]+1];
    770           for( Int i=0 ; i<=m_seiColourRemappingInfo.m_colourRemapSEIPreLutNumValMinus1[c] ; i++ )
    771           {
    772             retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEIPreLutCodedValue[c][i] );
    773             retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEIPreLutTargetValue[c][i] );
    774           }
    775         }
    776       }
    777 
    778       retval = fscanf( fic, "%d", &tempCode ); m_seiColourRemappingInfo.m_colourRemapSEIMatrixPresentFlag = tempCode ? 1 : 0;
    779       if( m_seiColourRemappingInfo.m_colourRemapSEIMatrixPresentFlag )
    780       {
    781         retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEILog2MatrixDenom );
    782         for( Int c=0 ; c<3 ; c++ )
    783         {
    784           for( Int i=0 ; i<3 ; i++ )
    785           {
    786             retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEICoeffs[c][i] );
    787           }
    788         }
    789       }
    790 
    791       for( Int c=0 ; c<3 ; c++ )
    792       {
    793         retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEIPostLutNumValMinus1[c] );
    794         if( m_seiColourRemappingInfo.m_colourRemapSEIPostLutNumValMinus1[c]>0 )
    795         {
    796           m_seiColourRemappingInfo.m_colourRemapSEIPostLutCodedValue[c]  = new Int[m_seiColourRemappingInfo.m_colourRemapSEIPostLutNumValMinus1[c]+1];
    797           m_seiColourRemappingInfo.m_colourRemapSEIPostLutTargetValue[c] = new Int[m_seiColourRemappingInfo.m_colourRemapSEIPostLutNumValMinus1[c]+1];
    798           for( Int i=0 ; i<= m_seiColourRemappingInfo.m_colourRemapSEIPostLutNumValMinus1[c] ; i++ )
    799           {
    800             retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEIPostLutCodedValue[c][i] );
    801             retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEIPostLutTargetValue[c][i] );
    802           }
    803         }
    804       }
    805     }
    806 
    807     fclose( fic );
    808     if( retval != 1 )
    809     {
    810       fprintf(stderr, "Error while reading Colour Remapping Information SEI parameters file\n");
    811       exit(EXIT_FAILURE);
    812     }
    813   }
    814   return 1;
    815 }
    816 
    817 Bool confirmParameter(Bool bflag, const TChar* message);
    818 // ====================================================================================================================
    819 // Private member functions
    820 // ====================================================================================================================
    821 
    822 Void TEncGOP::xCheckParameter()
    823 {
    824   Bool check_failed = false; /* abort if there is a fatal configuration problem */
    825 #define xConfirmParameter(a,b) check_failed |= confirmParameter(a,b)
    826 
    827   if ( m_seiColourRemappingInfo.m_colourRemapSEIFile.c_str() && !m_seiColourRemappingInfo.m_colourRemapSEICancelFlag )
    828   {
    829     xConfirmParameter( m_seiColourRemappingInfo.m_colourRemapSEIInputBitDepth < 8 || m_seiColourRemappingInfo.m_colourRemapSEIInputBitDepth > 16 , "colour_remap_coded_data_bit_depth shall be in the range of 8 to 16, inclusive");
    830     xConfirmParameter( m_seiColourRemappingInfo.m_colourRemapSEIBitDepth < 8 || (m_seiColourRemappingInfo.m_colourRemapSEIBitDepth > 16 && m_seiColourRemappingInfo.m_colourRemapSEIBitDepth < 255) , "colour_remap_target_bit_depth shall be in the range of 8 to 16, inclusive");
    831     for( Int c=0 ; c<3 ; c++)
    832     {
    833       xConfirmParameter( m_seiColourRemappingInfo.m_colourRemapSEIPreLutNumValMinus1[c] < 0 || m_seiColourRemappingInfo.m_colourRemapSEIPreLutNumValMinus1[c] > 32, "pre_lut_num_val_minus1[c] shall be in the range of 0 to 32, inclusive");
    834       if( m_seiColourRemappingInfo.m_colourRemapSEIPreLutNumValMinus1[c]>0 )
    835         for( Int i=0 ; i<= m_seiColourRemappingInfo.m_colourRemapSEIPreLutNumValMinus1[c] ; i++)
    836         {
    837           xConfirmParameter( m_seiColourRemappingInfo.m_colourRemapSEIPreLutCodedValue[c][i] < 0 || m_seiColourRemappingInfo.m_colourRemapSEIPreLutCodedValue[c][i] > ((1<<m_seiColourRemappingInfo.m_colourRemapSEIInputBitDepth)-1), "pre_lut_coded_value[c][i] shall be in the range of 0 to (1<<colour_remap_coded_data_bit_depth)-1, inclusive");
    838           xConfirmParameter( m_seiColourRemappingInfo.m_colourRemapSEIPreLutTargetValue[c][i] < 0 || m_seiColourRemappingInfo.m_colourRemapSEIPreLutTargetValue[c][i] > ((1<<m_seiColourRemappingInfo.m_colourRemapSEIBitDepth)-1), "pre_lut_target_value[c][i] shall be in the range of 0 to (1<<colour_remap_target_bit_depth)-1, inclusive");
    839         }
    840       xConfirmParameter( m_seiColourRemappingInfo.m_colourRemapSEIPostLutNumValMinus1[c] < 0 || m_seiColourRemappingInfo.m_colourRemapSEIPostLutNumValMinus1[c] > 32, "post_lut_num_val_minus1[c] shall be in the range of 0 to 32, inclusive");
    841       if( m_seiColourRemappingInfo.m_colourRemapSEIPostLutNumValMinus1[c]>0 )
    842         for( Int i=0 ; i<= m_seiColourRemappingInfo.m_colourRemapSEIPostLutNumValMinus1[c] ; i++)
    843         {
    844           xConfirmParameter( m_seiColourRemappingInfo.m_colourRemapSEIPostLutCodedValue[c][i] < 0 || m_seiColourRemappingInfo.m_colourRemapSEIPostLutCodedValue[c][i] > ((1<<m_seiColourRemappingInfo.m_colourRemapSEIBitDepth)-1), "post_lut_coded_value[c][i] shall be in the range of 0 to (1<<colour_remap_target_bit_depth)-1, inclusive");
    845           xConfirmParameter( m_seiColourRemappingInfo.m_colourRemapSEIPostLutTargetValue[c][i] < 0 || m_seiColourRemappingInfo.m_colourRemapSEIPostLutTargetValue[c][i] > ((1<<m_seiColourRemappingInfo.m_colourRemapSEIBitDepth)-1), "post_lut_target_value[c][i] shall be in the range of 0 to (1<<colour_remap_target_bit_depth)-1, inclusive");
    846         }
    847     }
    848     if ( m_seiColourRemappingInfo.m_colourRemapSEIMatrixPresentFlag )
    849     {
    850       xConfirmParameter( m_seiColourRemappingInfo.m_colourRemapSEILog2MatrixDenom < 0 || m_seiColourRemappingInfo.m_colourRemapSEILog2MatrixDenom > 15, "log2_matrix_denom shall be in the range of 0 to 15, inclusive");
    851       for( Int c=0 ; c<3 ; c++)
    852         for( Int i=0 ; i<3 ; i++)
    853           xConfirmParameter( m_seiColourRemappingInfo.m_colourRemapSEICoeffs[c][i] < -32768 || m_seiColourRemappingInfo.m_colourRemapSEICoeffs[c][i] > 32767, "colour_remap_coeffs[c][i] shall be in the range of -32768 and 32767, inclusive");
    854     }
    855   }
    856 }
    857 #endif
    858 
    859697Void TEncGOP::xCreatePerPictureSEIMessages (Int picInGOP, SEIMessages& seiMessages, SEIMessages& nestedSeiMessages, TComSlice *slice)
    860698{
     
    912750  }
    913751
     752#if Q0074_COLOUR_REMAPPING_SEI
     753  // insert one Colour Remapping Info SEI for the picture (if the file exists)
     754  if (!m_pcCfg->getColourRemapInfoSEIFileRoot().empty())
     755  {
     756    SEIColourRemappingInfo *seiColourRemappingInfo = new SEIColourRemappingInfo();
     757    const Bool success = m_seiEncoder.initSEIColourRemappingInfo(seiColourRemappingInfo, slice->getPOC() );
     758
     759    if(success)
     760    {
     761      seiMessages.push_back(seiColourRemappingInfo);
     762    }
     763    else
     764    {
     765      delete seiColourRemappingInfo;
     766    }
     767  }
     768#endif
     769
    914770#if Q0189_TMVP_CONSTRAINTS
    915771  if( m_pcEncTop->getTMVPConstraintsSEIEnabled() == 1 && (m_pcEncTop->getTMVPModeId() == 1 || m_pcEncTop->getTMVPModeId() == 2) &&
     
    930786    seiMessages.push_back(seiFFInfo);
    931787  }
    932 #endif
    933 #if Q0074_COLOUR_REMAPPING_SEI
    934     // insert one CRI by picture (if the file exist)   
    935     xFreeColourCRI();
    936 
    937     // building the CRI file name with poc num in suffix "_poc.txt"
    938     char suffix[10];
    939     sprintf(suffix, "_%d.txt",  slice->getPOC());
    940     string  colourRemapSEIFileWithPoc(m_pcCfg->getCRISEIFileRoot());
    941     colourRemapSEIFileWithPoc.append(suffix);
    942     xSetCRISEIFile( colourRemapSEIFileWithPoc );
    943  
    944     Int ret = xReadingCRIparameters();
    945 
    946     if(ret != -1 && !m_pcCfg->getCRISEIFileRoot().empty())
    947     {
    948       // check validity of input parameters
    949       xCheckParameter();
    950 
    951       SEIColourRemappingInfo *seiColourRemappingInfo = new SEIColourRemappingInfo;
    952       m_seiEncoder.initSEIColourRemappingInfo(seiColourRemappingInfo, &m_seiColourRemappingInfo);
    953       seiMessages.push_back(seiColourRemappingInfo);
    954     }
    955788#endif
    956789}
     
    45904423#endif //SVC_EXTENSION
    45914424
    4592 #if Q0074_COLOUR_REMAPPING_SEI
    4593 Bool confirmParameter(Bool bflag, const TChar* message)
    4594 {
    4595   if (!bflag)
    4596     return false;
    4597 
    4598   printf("Error: %s\n",message);
    4599   return true;
    4600 }
    4601 #endif
    4602 
    46034425//! \}
  • branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.h

    r1442 r1460  
    138138  SEIEncoder              m_seiEncoder;
    139139
    140 #if Q0074_COLOUR_REMAPPING_SEI
    141   TComSEIColourRemappingInfo m_seiColourRemappingInfo; 
    142 #endif
    143140#if SVC_EXTENSION
    144141  Int                     m_pocCraWithoutReset;
     
    274271  Void applyDeblockingFilterMetric( TComPic* pcPic, UInt uiNumSlices );
    275272
    276 #if Q0074_COLOUR_REMAPPING_SEI
    277   TComSEIColourRemappingInfo* xGetSEIColourRemappingInfo()  { return &m_seiColourRemappingInfo; }
    278   Void xSetCRISEIFile( std::string pch )                    { m_seiColourRemappingInfo.m_colourRemapSEIFile = pch; }
    279 
    280   Void xFreeColourCRI();
    281   Int  xReadingCRIparameters();
    282   Void xCheckParameter();
    283 #endif
    284273#if SVC_EXTENSION
    285274#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
Note: See TracChangeset for help on using the changeset viewer.