47 #if RExt__DECODER_DEBUG_BIT_STATISTICS
60 ,m_pcSeiColourRemappingInfoPrevious(
NULL)
94 fprintf(stderr,
"\nfailed to open bitstream file `%s' for reading\n",
m_bitstreamFileName.c_str());
119 if (!ofile.good() || !ofile.is_open())
121 fprintf(stderr,
"\nUnable to open file '%s' for writing colour-remap-information-SEI video\n",
m_colourRemapSEIFileName.c_str());
127 Bool openedReconFile =
false;
128 Bool loopFiltered =
false;
130 while (!!bitstreamFile)
136 #if RExt__DECODER_DEBUG_BIT_STATISTICS
138 streampos location = bitstreamFile.tellg() - streampos(bytestream.GetNumBufferedBytes());
140 streampos location = bitstreamFile.tellg();
148 Bool bNewPicture =
false;
156 fprintf(stderr,
"Warning: Attempt to decode an empty NAL unit\n");
170 bitstreamFile.clear();
175 #if RExt__DECODER_DEBUG_BIT_STATISTICS
176 bitstreamFile.seekg(location);
180 bitstreamFile.seekg(location-streamoff(3));
190 if (!loopFiltered || bitstreamFile)
210 const BitDepths &bitDepths=pcListPic->front()->getPicSym()->getSPS().getBitDepths();
220 openedReconFile =
true;
297 #if O0043_BEST_EFFORT_DECODING
298 m_cTDecTop.setForceDecodeBitDepth(m_forceDecodeBitDepth);
317 if (pcListPic->empty())
323 Int numPicsNotYetDisplayed = 0;
325 const TComSPS* activeSPS = &(pcListPic->front()->getPicSym()->getSPS());
326 UInt numReorderPicsHighestTid;
327 UInt maxDecPicBufferingHighestTid;
341 while (iterPic != pcListPic->end())
346 numPicsNotYetDisplayed++;
356 iterPic = pcListPic->begin();
358 if (numPicsNotYetDisplayed>2)
364 if (numPicsNotYetDisplayed>2 && pcPic->
isField())
368 iterPic = pcListPic->begin();
369 while (iterPic != endPic)
371 TComPic* pcPicTop = *(iterPic);
373 TComPic* pcPicBottom = *(iterPic);
376 (numPicsNotYetDisplayed > numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid) &&
381 numPicsNotYetDisplayed = numPicsNotYetDisplayed-2;
393 if( (nd !=
NULL) && nd->m_noDisplay )
435 iterPic = pcListPic->begin();
437 while (iterPic != pcListPic->end())
442 (numPicsNotYetDisplayed > numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid))
445 numPicsNotYetDisplayed--;
493 if(!pcListPic || pcListPic->empty())
499 iterPic = pcListPic->begin();
507 while (iterPic != endPic)
509 pcPicTop = *(iterPic);
511 pcPicBottom = *(iterPic);
567 while (iterPic != pcListPic->end())
643 if (colourRemappingInfo.size() > 1)
645 printf (
"Warning: Got multiple Colour Remapping Information SEI messages. Using first.");
647 if (seiColourRemappingInfo)
665 printf(
"Warning No SEI-CRI message is present for the current picture, persistence of the CRI is not managed\n");
675 static std::vector<Int>
677 const Int nbDecimalValues,
678 const std::vector<SEIColourRemappingInfo::CRIlut> &lut,
682 const Int lutPoints = (1 << bitDepth_in) + 1 ;
683 std::vector<Int> retLut(lutPoints);
686 Int iTargetPrev = (lut.size() && lut[0].codedValue == 0) ? lut[0].targetValue: 0;
687 Int startPivot = (lut.size())? ((lut[0].codedValue == 0)? 1: 0): 1;
691 const Int maxValueFixedPoint = (maxValue << nbDecimalValues) + ((1 << nbDecimalValues) - 1);
695 for (
Int iPivot=startPivot ; iPivot < (
Int)lut.size(); iPivot++ )
697 Int iCodedNext = lut[iPivot].codedValue;
698 Int iTargetNext = lut[iPivot].targetValue;
701 Int iCodedNext_bitDepth = std::min(iCodedNext, (1 << bitDepth_in));
703 const Int divValue = (iCodedNext - iCodedPrev > 0)? (iCodedNext - iCodedPrev): 1;
704 const Int lutValInit = (lutOffset + iTargetPrev) << nbDecimalValues;
705 const Int roundValue = divValue / 2;
706 for ( ; iValue<iCodedNext_bitDepth; iValue++ )
709 Int interpol = ((((value-iCodedPrev) * (iTargetNext - iTargetPrev)) << nbDecimalValues) + roundValue) / divValue;
710 retLut[iValue] = std::min(lutValInit + interpol , maxValueFixedPoint);
712 iCodedPrev = iCodedNext;
713 iTargetPrev = iTargetNext;
716 if(iCodedPrev < (1 << bitDepth_in)+1)
718 Int iCodedNext = (1 << bitDepth_in);
719 Int iTargetNext = (1 << bitDepth_in) - 1;
721 const Int divValue = (iCodedNext - iCodedPrev > 0)? (iCodedNext - iCodedPrev): 1;
722 const Int lutValInit = (lutOffset + iTargetPrev) << nbDecimalValues;
723 const Int roundValue = divValue / 2;
725 for ( ; iValue<=iCodedNext; iValue++ )
728 Int interpol = ((((value-iCodedPrev) * (iTargetNext - iTargetPrev)) << nbDecimalValues) + roundValue) / divValue;
729 retLut[iValue] = std::min(lutValInit + interpol , maxValueFixedPoint);
737 std::vector<Int> (&postLut)[3],
739 const Int maxBitDepth)
742 for (
Int c=0 ; c<3 ; c++ )
757 const Int roundValue = (inValPrecisionBits)? 1 << (inValPrecisionBits - 1): 0;
758 inVal = std::min(std::max(0, inVal), (
Int)(((lut.size()-1) << inValPrecisionBits)));
759 Int index = (
Int) std::min((inVal >> inValPrecisionBits), (
Int)(lut.size()-2));
760 Int outVal = (( inVal - (index<<inValPrecisionBits) ) * (lut[index+1] - lut[index]) + roundValue) >> inValPrecisionBits;
761 outVal += lut[index] ;
767 applyColourRemappingInfoMatrix(
const Int (&colourRemapCoeffs)[3],
const Int postOffsetShift,
const Int p0,
const Int p1,
const Int p2,
const Int offset)
769 Int YUVMat = (colourRemapCoeffs[0]* p0 + colourRemapCoeffs[1]* p1 + colourRemapCoeffs[2]* p2 + offset) >> postOffsetShift;
783 Int (&matrixOutputOffset)[3],
785 const Bool crInputFullRangeFlag,
786 const Int crInputMatrixCoefficients,
787 const Bool crFullRangeFlag,
788 const Int crMatrixCoefficients)
791 Int crInputOffsetLuma = (crInputFullRangeFlag)? 0:-(16 << (bitDepth-8));
792 Int crOffsetLuma = (crFullRangeFlag)? 0:(16 << (bitDepth-8));
793 Int crInputOffsetChroma = 0;
794 Int crOffsetChroma = 0;
796 switch(crInputMatrixCoefficients)
799 crInputOffsetChroma = 0;
800 if(!crInputFullRangeFlag)
802 fprintf(stderr,
"WARNING: crInputMatrixCoefficients set to MATRIX_COEFFICIENTS_RGB and crInputFullRangeFlag not set\n");
803 crInputOffsetLuma = 0;
809 crInputOffsetChroma = -(1 << (bitDepth-1));
812 fprintf(stderr,
"WARNING: crInputMatrixCoefficients set to undefined value: %d\n", crInputMatrixCoefficients);
815 switch(crMatrixCoefficients)
821 fprintf(stderr,
"WARNING: crMatrixCoefficients set to MATRIX_COEFFICIENTS_RGB and crInputFullRangeFlag not set\n");
828 crOffsetChroma = (1 << (bitDepth-1));
831 fprintf(stderr,
"WARNING: crMatrixCoefficients set to undefined value: %d\n", crMatrixCoefficients);
834 setColourRemappingInfoMatrixOffset(matrixInputOffset, crInputOffsetLuma, crInputOffsetChroma, crInputOffsetChroma);
835 setColourRemappingInfoMatrixOffset(matrixOutputOffset, crOffsetLuma, crOffsetChroma, crOffsetChroma);
840 const Int maxBitDepth = 16;
860 std::vector<Int> preLut[3];
861 std::vector<Int> postLut[3];
862 Int matrixInputOffset[3];
863 Int matrixOutputOffset[3];
879 const Int matrixRound = 1 << (postOffsetShift - 1);
896 matrixOutputOffset[0] = (matrixOutputOffset[0] << postOffsetShift) + matrixRound;
897 matrixOutputOffset[1] = (matrixOutputOffset[1] << postOffsetShift) + matrixRound;
898 matrixOutputOffset[2] = (matrixOutputOffset[2] << postOffsetShift) + matrixRound;
901 matrixOutputOffset[0] += applyColourRemappingInfoMatrix(criSEI.
m_colourRemapCoeffs[0], 0, matrixInputOffset[0], matrixInputOffset[1], matrixInputOffset[2], 0);
902 matrixOutputOffset[1] += applyColourRemappingInfoMatrix(criSEI.
m_colourRemapCoeffs[1], 0, matrixInputOffset[0], matrixInputOffset[1], matrixInputOffset[2], 0);
903 matrixOutputOffset[2] += applyColourRemappingInfoMatrix(criSEI.
m_colourRemapCoeffs[2], 0, matrixInputOffset[0], matrixInputOffset[1], matrixInputOffset[2], 0);
906 const Int scaleShiftOut_neg = abs(bitDepth - maxBitDepth);
907 const Int scaleOut_round = 1 << (scaleShiftOut_neg-1);
913 const Int maxOutputValue = (1 << bitDepth) - 1;
915 for(
Int y = 0; y < iHeight; y++ )
917 for(
Int x = 0; x < iWidth; x++ )
919 const Int xc = (x>>hs);
920 Bool computeChroma = b444 || ((b422 || !(y&1)) && !(x&1));
926 Int YUVMat_0 = applyColourRemappingInfoMatrix(criSEI.
m_colourRemapCoeffs[0], postOffsetShift, YUVPre_0, YUVPre_1, YUVPre_2, matrixOutputOffset[0]);
928 YUVOut[
COMPONENT_Y][x] = std::min(maxOutputValue, (YUVLutB_0 + scaleOut_round) >> scaleShiftOut_neg);
932 Int YUVMat_1 = applyColourRemappingInfoMatrix(criSEI.
m_colourRemapCoeffs[1], postOffsetShift, YUVPre_0, YUVPre_1, YUVPre_2, matrixOutputOffset[1]);
934 YUVOut[
COMPONENT_Cb][xc] = std::min(maxOutputValue, (YUVLutB_1 + scaleOut_round) >> scaleShiftOut_neg);
936 Int YUVMat_2 = applyColourRemappingInfoMatrix(criSEI.
m_colourRemapCoeffs[2], postOffsetShift, YUVPre_0, YUVPre_1, YUVPre_2, matrixOutputOffset[2]);
938 YUVOut[
COMPONENT_Cr][xc] = std::min(maxOutputValue, (YUVLutB_2 + scaleOut_round) >> scaleShiftOut_neg);
944 if( !(b420 && !(y&1)) )
954 picYuvColourRemapped.
destroy();
Void xInitDecLib()
initialize decoder class
Void executeLoopFilters(Int &poc, TComList< TComPic * > *&rpcListPic)
Int m_outputBitDepth[MAX_NUM_CHANNEL_TYPE]
bit depth used for writing output
Void setDecodedSEIMessageOutputStream(std::ostream *pOpStream)
Int getWindowTopOffset() const
Void create()
create internal members
Bool write(TComPicYuv *pPicYuv, const InputColourSpaceConversion ipCSC, Int confLeft=0, Int confRight=0, Int confTop=0, Int confBottom=0, ChromaFormat fileFormat=NUM_CHROMA_FORMAT, const Bool bClipToRec709=false)
write one YUV frame with padding parameter
Bool getFirstSliceInSequence()
TVideoIOYuv m_cTVideoIOYuvReconFile
reconstruction YUV class
Bool getVideoFullRangeFlag() const
picture class (symbol + YUV buffers)
std::string m_reconFileName
output reconstruction file name
Int getStride(const ComponentID id) const
Int getWindowBottomOffset() const
reading functionality for NAL units
Int m_colourRemapMatrixCoefficients
Int getWindowLeftOffset() const
Void open(const std::string &fileName, Bool bWriteMode, const Int fileBitDepth[MAX_NUM_CHANNEL_TYPE], const Int MSBExtendedBitDepth[MAX_NUM_CHANNEL_TYPE], const Int internalBitDepth[MAX_NUM_CHANNEL_TYPE])
open or create file
SEIMessages getSeisByType(SEIMessages &seiList, SEI::PayloadType seiType)
output a selection of SEI messages by payload type. Ownership stays in original message list...
Void createWithoutCUInfo(const Int picWidth, const Int picHeight, const ChromaFormat chromaFormatIDC, const Bool bUseMargin=false, const UInt maxCUWidth=0, const UInt maxCUHeight=0)
used for margin only
Int getHeight(const ComponentID id) const
TComSlice * getSlice(Int i)
std::string m_colourRemapSEIFileName
output Colour Remapping file name
Bool getNoOutputPriorPicsFlag()
Int m_iMaxTemporalLayer
maximum temporal layer to be decoded
InputColourSpaceConversion m_outputColourSpaceConvert
static Void setColourRemappingInfoMatrixOffsets(Int(&matrixInputOffset)[3], Int(&matrixOutputOffset)[3], const Int bitDepth, const Bool crInputFullRangeFlag, const Int crInputMatrixCoefficients, const Bool crFullRangeFlag, const Int crMatrixCoefficients)
Void setFirstSliceInSequence(bool val)
Bool m_colourRemapVideoSignalInfoPresentFlag
NalUnitType m_nalUnitType
nal_unit_type
Bool isReferenced() const
UInt getMaxDecPicBuffering(UInt tlayer) const
Int recon[MAX_NUM_CHANNEL_TYPE]
the bit depth as indicated in the SPS
std::string m_bitstreamFileName
input bitstream file name
TComVUI * getVuiParameters()
Bool isNaluWithinTargetDecLayerIdSet(InputNALUnit *nalu)
check whether given Nalu is within targetDecLayerIdSet
const Window & getConformanceWindow() const
Bool m_colourRemapCancelFlag
TComPicYuv * getPicYuvRec()
std::vector< CRIlut > m_postLut[3]
Void xFlushOutput(TComList< TComPic * > *pcListPic)
flush all remaining decoded pictures to file
Bool m_colourRemapFullRangeFlag
Decoder application class (header)
Window getDefDisplayWindow() const
Int getWidth(const ComponentID id) const
Void setFirstSliceInPicture(bool val)
UInt getComponentScaleX(const ComponentID id) const
Int m_colourRemapCoeffs[3][3]
reading functions for Annex B byte streams
Void setDecodedPictureHashSEIEnabled(Int enabled)
static const Int MAX_INT
max. value of signed 32-bit integer
TDecTop m_cTDecTop
decoder class
Int getMatrixCoefficients() const
std::vector< CRIlut > m_preLut[3]
static std::vector< Int > initColourRemappingInfoLut(const Int bitDepth_in, const Int nbDecimalValues, const std::vector< SEIColourRemappingInfo::CRIlut > &lut, const Int maxValue, const Int lutOffset)
Void copyFrom(const SEIColourRemappingInfo &seiCriInput)
ChromaFormat
chroma formats (according to semantics of chroma_format_idc)
Bool m_bClipOutputVideoToRec709Range
If true, clip the output video to the Rec 709 range on saving.
Void xOutputColourRemapPic(TComPic *pcPic)
Int m_colourRemapInputBitDepth
Void setNoOutputPriorPicsFlag(Bool val)
UInt m_nuhLayerId
nuh_layer_id
Void decode()
main decoding function
static Void initColourRemappingInfoLuts(std::vector< Int >(&preLut)[3], std::vector< Int >(&postLut)[3], SEIColourRemappingInfo &pCriSEI, const Int maxBitDepth)
static Int applyColourRemappingInfoLut1D(Int inVal, const std::vector< Int > &lut, const Int inValPrecisionBits)
std::string m_outputDecodedSEIMessagesFilename
filename to output decoded SEI messages to. If '-', then use stdout. If empty, do not output details...
const TComSPS & getSPS() const
Void setOutputMark(Bool b)
Int m_iPOCLastDisplay
last POC in display order
Void setTMctsCheckEnabled(Bool enabled)
Void xWriteOutput(TComList< TComPic * > *pcListPic, UInt tId)
write YUV to file
Int m_iSkipFrame
counter for frames prior to the random access point to skip
Bool m_decodedNoDisplaySEIEnabled
Enable(true)/disable(false) writing only pictures that get displayed based on the no display SEI mess...
Void dump(const std::string &fileName, const BitDepths &bitDepths, const Bool bAppend=false, const Bool bForceTo8Bit=false) const
Void setReconMark(Bool b)
Pel * getAddr(const ComponentID ch)
std::list< SEI * > SEIMessages
Void xDestroyDecLib()
destroy internal classes
SEIColourRemappingInfo * m_pcSeiColourRemappingInfoPrevious
UInt getMaxTLayers() const
Int m_respectDefDispWindow
Only output content inside the default display window.
std::ofstream m_seiMessageFileStream
Used for outputing SEI messages.
Bool m_colourRemapPersistenceFlag
static const TComCodingStatisticsData & GetStatistics()
Int getWindowRightOffset() const
Bool getReconMark() const
Void read(InputNALUnit &nalu)
Void setBorderExtension(Bool b)
Void applyColourRemapping(const TComPicYuv &pic, SEIColourRemappingInfo &pCriSEI, const TComSPS &activeSPS)
Void destroy()
destroy internal members
Bool getOutputMark() const
UInt m_temporalId
temporal_id
Bool byteStreamNALUnit(InputByteStream &bs, vector< uint8_t > &nalUnit, AnnexBStats &stats)
Int m_colourRemapBitDepth
Bool decode(InputNALUnit &nalu, Int &iSkipFrame, Int &iPOCLastDisplay)
static Void SetStatistics(const TComCodingStatisticsData &src)
std::vector< Int > m_targetDecLayerIdSet
set of LayerIds to be included in the sub-bitstream extraction process.
Void checkNoOutputPriorPics(TComList< TComPic * > *rpcListPic)
Int m_decodedPictureHashSEIEnabled
Checksum(3)/CRC(2)/MD5(1)/disable(0) acting on decoded picture hash SEI message.
Void xCreateDecLib()
create internal classes
Int getNumReorderPics(UInt tlayer) const
ChromaFormat getChromaFormat() const