Changeset 1089 in SHVCSoftware for branches/SHM-dev/source/App/TAppDecoder
- Timestamp:
- 25 Jun 2015, 16:19:05 (9 years ago)
- Location:
- branches/SHM-dev/source/App/TAppDecoder
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SHM-dev/source/App/TAppDecoder/TAppDecCfg.cpp
r1057 r1089 136 136 #endif 137 137 #if Q0074_COLOUR_REMAPPING_SEI 138 ("SEIColourRemappingInfo ", m_colourRemapSEIEnabled, false, "Control handling of Colour Remapping Information SEI messages\n"138 ("SEIColourRemappingInfo,-cri", m_colourRemapSEIEnabled, false, "Control handling of Colour Remapping Information SEI messages\n" 139 139 "\t1: apply colour remapping on decoded pictures if available in the bitstream\n" 140 140 "\t0: ignore SEI message") -
branches/SHM-dev/source/App/TAppDecoder/TAppDecTop.cpp
r1077 r1089 56 56 //! \{ 57 57 58 #if Q0074_COLOUR_REMAPPING_SEI 59 static Void applyColourRemapping(TComPicYuv& pic, const SEIColourRemappingInfo* colourRemappingInfoSEI, UInt layerId=0 ); 60 static std::vector<SEIColourRemappingInfo> storeCriSEI; //Persistent Colour Remapping Information SEI 61 static SEIColourRemappingInfo *seiColourRemappingInfoPrevious=NULL ; 62 #endif 63 58 64 // ==================================================================================================================== 59 65 // Constructor / destructor / initialization / destroy … … 112 118 free (m_pchReconFile); 113 119 m_pchReconFile = NULL; 120 } 121 #endif 122 #if Q0074_COLOUR_REMAPPING_SEI 123 if (seiColourRemappingInfoPrevious != NULL) 124 { 125 delete seiColourRemappingInfoPrevious; 114 126 } 115 127 #endif … … 657 669 m_acTDecTop[layer].init(); 658 670 m_acTDecTop[layer].setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled); 659 #if Q0074_COLOUR_REMAPPING_SEI660 m_acTDecTop[layer].setColourRemappingInfoSEIEnabled(m_colourRemapSEIEnabled);661 #endif662 671 #if FIX_CONF_MODE 663 672 m_acTDecTop[layer].setNumLayer( MAX_LAYERS ); … … 690 699 m_cTDecTop.setDecodedSEIMessageOutputStream(&os); 691 700 } 692 #if Q0074_COLOUR_REMAPPING_SEI693 m_cTDecTop.setColourRemappingInfoSEIEnabled(m_colourRemapSEIEnabled);694 #endif695 701 #endif 696 702 } … … 958 964 } 959 965 966 #if Q0074_COLOUR_REMAPPING_SEI 967 if (m_colourRemapSEIEnabled) 968 { 969 SEIMessages colourRemappingInfo = getSeisByType(pcPic->getSEIs(), SEI::COLOUR_REMAPPING_INFO ); 970 const SEIColourRemappingInfo *seiColourRemappingInfo = ( colourRemappingInfo.size() > 0 ) ? (SEIColourRemappingInfo*) *(colourRemappingInfo.begin()) : NULL; 971 if (colourRemappingInfo.size() > 1) 972 { 973 printf ("Warning: Got multiple Colour Remapping Information SEI messages. Using first."); 974 } 975 if (seiColourRemappingInfo) 976 { 977 applyColourRemapping(*pcPic->getPicYuvRec(), seiColourRemappingInfo); 978 } 979 else // using the last CRI SEI received 980 { 981 const SEIColourRemappingInfo *seiColourRemappingInfoCopy; 982 seiColourRemappingInfoCopy = seiColourRemappingInfoPrevious; 983 applyColourRemapping(*pcPic->getPicYuvRec(), seiColourRemappingInfoCopy); 984 } 985 986 // save the last CRI SEI received 987 if( seiColourRemappingInfo != NULL){ 988 if (seiColourRemappingInfoPrevious != NULL) 989 { 990 delete seiColourRemappingInfoPrevious; 991 seiColourRemappingInfoPrevious = NULL; 992 } 993 if (seiColourRemappingInfo->m_colourRemapPersistenceFlag) 994 { 995 seiColourRemappingInfoPrevious = new SEIColourRemappingInfo(); 996 seiColourRemappingInfoPrevious->copyFrom(seiColourRemappingInfo); 997 } 998 } 999 } 1000 #endif 1001 960 1002 // update POC of display order 961 1003 m_iPOCLastDisplay = pcPic->getPOC(); … … 1161 1203 } 1162 1204 1205 #if Q0074_COLOUR_REMAPPING_SEI 1206 if (m_colourRemapSEIEnabled) 1207 { 1208 SEIMessages colourRemappingInfo = getSeisByType(pcPic->getSEIs(), SEI::COLOUR_REMAPPING_INFO ); 1209 const SEIColourRemappingInfo *seiColourRemappingInfo = ( colourRemappingInfo.size() > 0 ) ? (SEIColourRemappingInfo*) *(colourRemappingInfo.begin()) : NULL; 1210 if (colourRemappingInfo.size() > 1) 1211 { 1212 printf ("Warning: Got multiple Colour Remapping Information SEI messages. Using first."); 1213 } 1214 if (seiColourRemappingInfo) 1215 { 1216 applyColourRemapping(*pcPic->getPicYuvRec(), seiColourRemappingInfo); 1217 } 1218 else // using the last CRI SEI received 1219 { 1220 const SEIColourRemappingInfo *seiColourRemappingInfoCopy; 1221 seiColourRemappingInfoCopy = seiColourRemappingInfoPrevious; 1222 applyColourRemapping(*pcPic->getPicYuvRec(), seiColourRemappingInfoCopy); 1223 } 1224 1225 // save the last CRI SEI received 1226 if( seiColourRemappingInfo != NULL){ 1227 if (seiColourRemappingInfoPrevious != NULL) 1228 { 1229 delete seiColourRemappingInfoPrevious; 1230 seiColourRemappingInfoPrevious = NULL; 1231 } 1232 if (seiColourRemappingInfo->m_colourRemapPersistenceFlag) 1233 { 1234 seiColourRemappingInfoPrevious = new SEIColourRemappingInfo(); 1235 seiColourRemappingInfoPrevious->copyFrom(seiColourRemappingInfo); 1236 } 1237 } 1238 } 1239 #endif 1240 1163 1241 // update POC of display order 1164 1242 m_iPOCLastDisplay = pcPic->getPOC(); … … 1247 1325 conf.getWindowTopOffset() * yScal + defDisp.getWindowTopOffset(), 1248 1326 conf.getWindowBottomOffset()* yScal + defDisp.getWindowBottomOffset() ); 1327 1328 #if Q0074_COLOUR_REMAPPING_SEI 1329 if (m_colourRemapSEIEnabled) 1330 { 1331 SEIMessages colourRemappingInfo = getSeisByType(pic->getSEIs(), SEI::COLOUR_REMAPPING_INFO ); 1332 const SEIColourRemappingInfo *seiColourRemappingInfo = ( colourRemappingInfo.size() > 0 ) ? (SEIColourRemappingInfo*) *(colourRemappingInfo.begin()) : NULL; 1333 if (colourRemappingInfo.size() > 1) 1334 { 1335 printf ("Warning: Got multiple Colour Remapping Information SEI messages. Using first."); 1336 } 1337 1338 if (seiColourRemappingInfo) 1339 { 1340 //printf ("\n\nColour Remapping is applied to POC : %d and LayerId : %d ",pic->getPOC(), pic->getLayerId()); 1341 applyColourRemapping(*pic->getPicYuvRec(), seiColourRemappingInfo 1342 #if SVC_EXTENSION 1343 , pic->getLayerId() 1344 #endif 1345 ); 1346 } 1347 else // using the last CRI SEI received 1348 { 1349 const SEIColourRemappingInfo *seiColourRemappingInfoCopy; 1350 seiColourRemappingInfoCopy = seiColourRemappingInfoPrevious; 1351 applyColourRemapping(*pic->getPicYuvRec(), seiColourRemappingInfoCopy 1352 #if SVC_EXTENSION 1353 , pic->getLayerId() 1354 #endif 1355 ); 1356 } 1357 1358 // save the last CRI SEI received 1359 if( seiColourRemappingInfo != NULL){ 1360 if (seiColourRemappingInfoPrevious != NULL) 1361 { 1362 delete seiColourRemappingInfoPrevious; 1363 seiColourRemappingInfoPrevious = NULL; 1364 } 1365 if (seiColourRemappingInfo->m_colourRemapPersistenceFlag) 1366 { 1367 seiColourRemappingInfoPrevious = new SEIColourRemappingInfo(); 1368 seiColourRemappingInfoPrevious->copyFrom(seiColourRemappingInfo); 1369 } 1370 } 1371 } 1372 1373 #endif 1249 1374 } 1250 1375 // update POC of display order … … 1860 1985 #endif 1861 1986 #endif 1987 1988 #if Q0074_COLOUR_REMAPPING_SEI 1989 Void xInitColourRemappingLut( const Int bitDepthY, const Int bitDepthC, std::vector<Int>(&preLut)[3], std::vector<Int>(&postLut)[3], const SEIColourRemappingInfo* const pCriSEI ) 1990 { 1991 for ( Int c=0 ; c<3 ; c++ ) 1992 { 1993 Int bitDepth = c ? bitDepthC : bitDepthY ; 1994 preLut[c].resize(1 << bitDepth); 1995 postLut[c].resize(1 << pCriSEI->m_colourRemapBitDepth); 1996 1997 Int bitDepthDiff = pCriSEI->m_colourRemapBitDepth - bitDepth; 1998 Int iShift1 = (bitDepthDiff>0) ? bitDepthDiff : 0; //bit scale from bitdepth to ColourRemapBitdepth (manage only case colourRemapBitDepth>= bitdepth) 1999 if( bitDepthDiff<0 ) 2000 printf ("Warning: CRI SEI - colourRemapBitDepth (%d) <bitDepth (%d) - case not handled\n", pCriSEI->m_colourRemapBitDepth, bitDepth); 2001 bitDepthDiff = pCriSEI->m_colourRemapBitDepth - pCriSEI->m_colourRemapInputBitDepth; 2002 Int iShift2 = (bitDepthDiff>0) ? bitDepthDiff : 0; //bit scale from ColourRemapInputBitdepth to ColourRemapBitdepth (manage only case colourRemapBitDepth>= colourRemapInputBitDepth) 2003 if( bitDepthDiff<0 ) 2004 printf ("Warning: CRI SEI - colourRemapBitDepth (%d) <colourRemapInputBitDepth (%d) - case not handled\n", pCriSEI->m_colourRemapBitDepth, pCriSEI->m_colourRemapInputBitDepth); 2005 2006 //Fill preLut 2007 for ( Int k=0 ; k<(1<<bitDepth) ; k++ ) 2008 { 2009 Int iSample = k << iShift1 ; 2010 for ( Int iPivot=0 ; iPivot<=pCriSEI->m_preLutNumValMinus1[c] ; iPivot++ ) 2011 { 2012 Int iCodedPrev = pCriSEI->m_preLutCodedValue[c][iPivot] << iShift2; //Coded in CRInputBitdepth 2013 Int iCodedNext = pCriSEI->m_preLutCodedValue[c][iPivot+1] << iShift2; //Coded in CRInputBitdepth 2014 Int iTargetPrev = pCriSEI->m_preLutTargetValue[c][iPivot]; //Coded in CRBitdepth 2015 Int iTargetNext = pCriSEI->m_preLutTargetValue[c][iPivot+1]; //Coded in CRBitdepth 2016 if ( iCodedPrev <= iSample && iSample <= iCodedNext ) 2017 { 2018 Float fInterpol = (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) * 1.f / (Float)(iCodedNext - iCodedPrev); 2019 preLut[c][k] = (Int)( 0.5f + fInterpol ); 2020 iPivot = pCriSEI->m_preLutNumValMinus1[c] + 1; 2021 } 2022 } 2023 } 2024 2025 //Fill postLut 2026 for ( Int k=0 ; k<(1<<pCriSEI->m_colourRemapBitDepth) ; k++ ) 2027 { 2028 Int iSample = k; 2029 for ( Int iPivot=0 ; iPivot<=pCriSEI->m_postLutNumValMinus1[c] ; iPivot++ ) 2030 { 2031 Int iCodedPrev = pCriSEI->m_postLutCodedValue[c][iPivot]; //Coded in CRBitdepth 2032 Int iCodedNext = pCriSEI->m_postLutCodedValue[c][iPivot+1]; //Coded in CRBitdepth 2033 Int iTargetPrev = pCriSEI->m_postLutTargetValue[c][iPivot]; //Coded in CRBitdepth 2034 Int iTargetNext = pCriSEI->m_postLutTargetValue[c][iPivot+1]; //Coded in CRBitdepth 2035 if ( iCodedPrev <= iSample && iSample <= iCodedNext ) 2036 { 2037 Float fInterpol = (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) * 1.f / (Float)(iCodedNext - iCodedPrev) ; 2038 postLut[c][k] = (Int)( 0.5f + fInterpol ); 2039 iPivot = pCriSEI->m_postLutNumValMinus1[c] + 1; 2040 } 2041 } 2042 } 2043 } 2044 } 2045 2046 static void applyColourRemapping(TComPicYuv& pic, const SEIColourRemappingInfo* pCriSEI, UInt layerId ) 2047 { 2048 if( !storeCriSEI.size() ) 2049 #if SVC_EXTENSION 2050 storeCriSEI.resize(MAX_LAYERS); 2051 #else 2052 storeCriSEI.resize(1); 2053 #endif 2054 2055 if ( pCriSEI ) //if a CRI SEI has just been retrieved, keep it in memory (persistence management) 2056 storeCriSEI[layerId] = *pCriSEI; 2057 2058 if( !storeCriSEI[layerId].m_colourRemapCancelFlag && pCriSEI) 2059 { 2060 Int iHeight = pic.getHeight(COMPONENT_Y); 2061 Int iWidth = pic.getWidth(COMPONENT_Y); 2062 Int iStride = pic.getStride(COMPONENT_Y); 2063 Int iCStride = pic.getStride(COMPONENT_Cb); 2064 2065 Pel *YUVIn[3], *YUVOut[3]; 2066 YUVIn[0] = pic.getAddr(COMPONENT_Y); 2067 YUVIn[1] = pic.getAddr(COMPONENT_Cb); 2068 YUVIn[2] = pic.getAddr(COMPONENT_Cr); 2069 2070 TComPicYuv picColourRemapped; 2071 #if SVC_EXTENSION 2072 #if AUXILIARY_PICTURES 2073 picColourRemapped.create( pic.getWidth(COMPONENT_Y), pic.getHeight(COMPONENT_Y), pic.getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL ); 2074 #else 2075 picColourRemapped.create( pic.getWidth(), pic.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL ); 2076 #endif 2077 #else 2078 picColourRemapped.create( pic.getWidth(COMPONENT_Y), pic.getHeight(COMPONENT_Y), pic.getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); 2079 #endif 2080 YUVOut[0] = picColourRemapped.getAddr(COMPONENT_Y); 2081 YUVOut[1] = picColourRemapped.getAddr(COMPONENT_Cb); 2082 YUVOut[2] = picColourRemapped.getAddr(COMPONENT_Cr); 2083 2084 #if SVC_EXTENSION 2085 Int bitDepthY = g_bitDepthLayer[CHANNEL_TYPE_LUMA][layerId]; 2086 Int bitDepthC = g_bitDepthLayer[CHANNEL_TYPE_CHROMA][layerId]; 2087 2088 #else 2089 Int bitDepthY = g_bitDepth[CHANNEL_TYPE_LUMA]; 2090 Int bitDepthC = g_bitDepth[CHANNEL_TYPE_CHROMA]; 2091 #endif 2092 2093 std::vector<Int> preLut[3]; 2094 std::vector<Int> postLut[3]; 2095 xInitColourRemappingLut( bitDepthY, bitDepthC, preLut, postLut, &storeCriSEI[layerId] ); 2096 2097 Int roundingOffset = (storeCriSEI[layerId].m_log2MatrixDenom==0) ? 0 : (1 << (storeCriSEI[layerId].m_log2MatrixDenom - 1)); 2098 2099 for( Int y = 0; y < iHeight ; y++ ) 2100 { 2101 for( Int x = 0; x < iWidth ; x++ ) 2102 { 2103 Int YUVPre[3], YUVMat[3]; 2104 YUVPre[0] = preLut[0][ YUVIn[0][x] ]; 2105 YUVPre[1] = preLut[1][ YUVIn[1][x>>1] ]; 2106 YUVPre[2] = preLut[2][ YUVIn[2][x>>1] ]; 2107 2108 YUVMat[0] = ( storeCriSEI[layerId].m_colourRemapCoeffs[0][0]*YUVPre[0] 2109 + storeCriSEI[layerId].m_colourRemapCoeffs[0][1]*YUVPre[1] 2110 + storeCriSEI[layerId].m_colourRemapCoeffs[0][2]*YUVPre[2] 2111 + roundingOffset ) >> ( storeCriSEI[layerId].m_log2MatrixDenom ); 2112 YUVMat[0] = Clip3( 0, (1<<storeCriSEI[layerId].m_colourRemapBitDepth)-1, YUVMat[0] ); 2113 YUVOut[0][x] = postLut[0][ YUVMat[0] ]; 2114 2115 if( (y&1) && (x&1) ) 2116 { 2117 for(Int c=1 ; c<3 ; c++) 2118 { 2119 YUVMat[c] = ( storeCriSEI[layerId].m_colourRemapCoeffs[c][0]*YUVPre[0] 2120 + storeCriSEI[layerId].m_colourRemapCoeffs[c][1]*YUVPre[1] 2121 + storeCriSEI[layerId].m_colourRemapCoeffs[c][2]*YUVPre[2] 2122 + roundingOffset ) >> ( storeCriSEI[layerId].m_log2MatrixDenom ); 2123 YUVMat[c] = Clip3( 0, (1<<storeCriSEI[layerId].m_colourRemapBitDepth)-1, YUVMat[c] ); 2124 YUVOut[c][x>>1] = postLut[c][ YUVMat[c] ]; 2125 } 2126 } 2127 } 2128 YUVIn[0] += iStride; 2129 YUVOut[0] += iStride; 2130 if( y&1 ) 2131 { 2132 YUVIn[1] += iCStride; 2133 YUVIn[2] += iCStride; 2134 YUVOut[1] += iCStride; 2135 YUVOut[2] += iCStride; 2136 } 2137 } 2138 2139 //Write remapped picture in decoding order 2140 Char cTemp[255]; 2141 sprintf(cTemp, "seiColourRemappedPic_L%d_%dx%d_%dbits.yuv", layerId, iWidth, iHeight, storeCriSEI[layerId].m_colourRemapBitDepth ); 2142 picColourRemapped.dump( cTemp, true, storeCriSEI[layerId].m_colourRemapBitDepth ); 2143 2144 picColourRemapped.destroy(); 2145 2146 storeCriSEI[layerId].m_colourRemapCancelFlag = !storeCriSEI[layerId].m_colourRemapPersistenceFlag; //Handling persistence 2147 } 2148 else 2149 { 2150 //Write no remapped picture in decoding order 2151 if (storeCriSEI[layerId].m_colourRemapBitDepth == 8 || storeCriSEI[layerId].m_colourRemapBitDepth == 10) 2152 { 2153 Char cTemp[255]; 2154 sprintf(cTemp, "seiColourRemappedPic_L%d_%dx%d_%dbits.yuv", layerId, pic.getWidth(COMPONENT_Y), pic.getHeight(COMPONENT_Y), storeCriSEI[layerId].m_colourRemapBitDepth ); 2155 pic.dump( cTemp, true, storeCriSEI[layerId].m_colourRemapBitDepth ); 2156 } 2157 } 2158 } 2159 #endif 1862 2160 //! \}
Note: See TracChangeset for help on using the changeset viewer.