<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 7, 2018 at 1:30 PM, <span dir="ltr"><<a href="mailto:ashok@multicorewareinc.com" target="_blank">ashok@multicorewareinc.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># HG changeset patch<br>
# User Ashok Kumar Mishra <<a href="mailto:ashok@multicorewareinc.com">ashok@multicorewareinc.com</a>><br>
# Date 1533625311 -19800<br>
# Tue Aug 07 12:31:51 2018 +0530<br>
# Node ID d17bc7714ed2343b8349ffb32d4037<wbr>105d086c92<br>
# Parent eea92165b035db5ebb1f902debba17<wbr>1362fec783<br>
Added JsonType enum to differentiate between Legacy and LLC file format.<br>
Added usage of switch inside parameter functions instead of multiple condition IF's<br>
<br>
diff -r eea92165b035 -r d17bc7714ed2 source/dynamicHDR10/<wbr>metadataFromJson.cpp<br>
--- a/source/dynamicHDR10/<wbr>metadataFromJson.cpp Fri Jul 20 14:57:04 2018 +0530<br>
+++ b/source/dynamicHDR10/<wbr>metadataFromJson.cpp Tue Aug 07 12:31:51 2018 +0530<br>
@@ -46,132 +46,133 @@<br>
int mCurrentStreamBit;<br>
int mCurrentStreamByte;<br>
<br>
- bool luminanceParamFromJson(const Json &data, LuminanceParameters &obj)<br>
+ bool luminanceParamFromJson(const Json &data, LuminanceParameters &obj, const JsonType jsonType)<br>
{<br>
JsonObject lumJsonData = data.object_items();<br>
if(!lumJsonData.empty())<br>
{<br>
- obj.averageLuminance = static_cast<float>(<wbr>lumJsonData[LuminanceNames::<wbr>AverageRGB].number_value());<br>
- obj.maxRLuminance = static_cast<float>(<wbr>lumJsonData[LuminanceNames::<wbr>MaxSCL0].number_value());<br>
- obj.maxGLuminance = static_cast<float>(<wbr>lumJsonData[LuminanceNames::<wbr>MaxSCL1].number_value());<br>
- obj.maxBLuminance = static_cast<float>(<wbr>lumJsonData[LuminanceNames::<wbr>MaxSCL2].number_value());<br>
+ switch(jsonType)<br>
+ {<br>
+ case LEGACY:<br>
+ {<br>
+ obj.averageLuminance = static_cast<float>(<wbr>lumJsonData[LuminanceNames::<wbr>AverageRGB].number_value());<br>
+ obj.maxRLuminance = static_cast<float>(<wbr>lumJsonData[LuminanceNames::<wbr>MaxSCL0].number_value());<br>
+ obj.maxGLuminance = static_cast<float>(<wbr>lumJsonData[LuminanceNames::<wbr>MaxSCL1].number_value());<br>
+ obj.maxBLuminance = static_cast<float>(<wbr>lumJsonData[LuminanceNames::<wbr>MaxSCL2].number_value());<br>
<br>
- JsonObject percentileData = lumJsonData[PercentileNames::<wbr>TagName].object_items();<br>
- obj.order = percentileData[<wbr>PercentileNames::<wbr>NumberOfPercentiles].int_<wbr>value();<br>
- if(!percentileData.empty())<br>
- {<br>
- obj.percentiles.resize(obj.<wbr>order);<br>
- for(int i = 0; i < obj.order; ++i)<br>
- {<br>
- std::string percentileTag = PercentileNames::TagName;<br>
- percentileTag += std::to_string(i);<br>
- obj.percentiles[i] = static_cast<unsigned int>(percentileData[<wbr>percentileTag].int_value());<br>
- }<br>
- }<br>
- return true;<br>
- }<br>
+ JsonObject percentileData = lumJsonData[PercentileNames::<wbr>TagName].object_items();<br>
+ obj.order = percentileData[<wbr>PercentileNames::<wbr>NumberOfPercentiles].int_<wbr>value();<br>
+ if(!percentileData.empty())<br>
+ {<br>
+ obj.percentiles.resize(obj.<wbr>order);<br>
+ for(int i = 0; i < obj.order; ++i)<br>
+ {<br>
+ std::string percentileTag = PercentileNames::TagName;<br>
+ percentileTag += std::to_string(i);<br>
+ obj.percentiles[i] = static_cast<unsigned int>(percentileData[<wbr>percentileTag].int_value());<br>
+ }<br>
+ }<br>
+ return true;<br>
+ } break;<br>
+ case LLC:<br>
+ {<br>
+ obj.averageLuminance = static_cast<float>(<wbr>lumJsonData[LuminanceNames::<wbr>AverageRGB].number_value());<br>
+ JsonArray maxScl = lumJsonData[LuminanceNames::<wbr>MaxSCL].array_items();<br>
+ obj.maxRLuminance = static_cast<float>(maxScl[0].<wbr>number_value());<br>
+ obj.maxGLuminance = static_cast<float>(maxScl[1].<wbr>number_value());<br>
+ obj.maxBLuminance = static_cast<float>(maxScl[2].<wbr>number_value());<br>
+<br>
+ JsonObject percentileData = lumJsonData[LuminanceNames::<wbr>LlcTagName].object_items();<br>
+ if(!percentileData.empty())<br>
+ {<br>
+ JsonArray distributionValues = percentileData[<wbr>PercentileNames::<wbr>DistributionValues].array_<wbr>items();<br>
+ obj.order = static_cast<int>(<wbr>distributionValues.size());<br>
+ obj.percentiles.resize(obj.<wbr>order);<br>
+ for(int i = 0; i < obj.order; ++i)<br>
+ {<br>
+ obj.percentiles[i] = static_cast<unsigned int>(distributionValues[i].<wbr>int_value());<br>
+ }<br>
+ }<br>
+ return true;<br>
+ } break;<br>
+ }<br>
+ }<br>
return false;<br>
}<br>
<br>
- bool luminanceParamFromLLCJson(<wbr>const Json &data, LuminanceParameters &obj)<br>
- {<br>
- JsonObject lumJsonData = data.object_items();<br>
- if(!lumJsonData.empty())<br>
- {<br>
- obj.averageLuminance = static_cast<float>(<wbr>lumJsonData[LuminanceNames::<wbr>AverageRGB].number_value());<br>
- JsonArray maxScl = lumJsonData[LuminanceNames::<wbr>MaxSCL].array_items();<br>
- obj.maxRLuminance = static_cast<float>(maxScl[0].<wbr>number_value());<br>
- obj.maxGLuminance = static_cast<float>(maxScl[1].<wbr>number_value());<br>
- obj.maxBLuminance = static_cast<float>(maxScl[2].<wbr>number_value());<br>
-<br>
- JsonObject percentileData = lumJsonData[LuminanceNames::<wbr>LlcTagName].object_items();<br>
- if(!percentileData.empty())<br>
- {<br>
- JsonArray distributionValues = percentileData[<wbr>PercentileNames::<wbr>DistributionValues].array_<wbr>items();<br>
- obj.order = static_cast<int>(<wbr>distributionValues.size());<br>
- obj.percentiles.resize(obj.<wbr>order);<br>
- for(int i = 0; i < obj.order; ++i)<br>
- {<br>
- obj.percentiles[i] = static_cast<unsigned int>(distributionValues[i].<wbr>int_value());<br>
- }<br>
- }<br>
- return true;<br>
- }<br>
- return false;<br>
- }<br>
-<br>
- bool percentagesFromJson(const Json &data, std::vector<unsigned int> &percentages)<br>
+ bool percentagesFromJson(const Json &data, std::vector<unsigned int> &percentages, const JsonType jsonType)<br>
{<br>
JsonObject jsonData = data.object_items();<br>
if(!jsonData.empty())<br>
{<br>
- JsonObject percentileData = jsonData[PercentileNames::<wbr>TagName].object_items();<br>
- int order = percentileData[<wbr>PercentileNames::<wbr>NumberOfPercentiles].int_<wbr>value();<br>
- percentages.resize(order);<br>
- for(int i = 0; i < order; ++i)<br>
- {<br>
- std::string percentileTag = PercentileNames::<wbr>PercentilePercentageValue[i];<br>
- percentages[i] = static_cast<unsigned int>(percentileData[<wbr>percentileTag].int_value());<br>
- }<br>
- return true;<br>
+ switch(jsonType)<br>
+ {<br>
+ case LEGACY:<br>
+ {<br>
+ JsonObject percentileData = jsonData[PercentileNames::<wbr>TagName].object_items();<br>
+ int order = percentileData[<wbr>PercentileNames::<wbr>NumberOfPercentiles].int_<wbr>value();<br>
+ percentages.resize(order);<br>
+ for(int i = 0; i < order; ++i)<br>
+ {<br>
+ std::string percentileTag = PercentileNames::<wbr>PercentilePercentageValue[i];<br>
+ percentages[i] = static_cast<unsigned int>(percentileData[<wbr>percentileTag].int_value());<br>
+ }<br>
+ return true;<br>
+ } break;<br>
+ case LLC:<br>
+ {<br>
+ JsonObject percentileData = jsonData[LuminanceNames::<wbr>LlcTagName].object_items();<br>
+ if(!percentileData.empty())<br>
+ {<br>
+ JsonArray percentageValues = percentileData[<wbr>PercentileNames::<wbr>DistributionIndex].array_<wbr>items();<br>
+ int order = static_cast<int>(<wbr>percentageValues.size());<br>
+ percentages.resize(order);<br>
+ for(int i = 0; i < order; ++i)<br>
+ {<br>
+ percentages[i] = static_cast<unsigned int>(percentageValues[i].int_<wbr>value());<br>
+ }<br>
+ } <br>
+ return true;<br>
+ } break;<br>
+ }<br>
+<br>
}<br>
return false;<br>
}<br>
<br>
- bool percentagesFromLLCJson(const Json &data, std::vector<unsigned int> &percentages)<br>
- {<br>
- JsonObject lumJsonData = data.object_items();<br>
- if(!lumJsonData.empty())<br>
- { <br>
- JsonObject percentileData = lumJsonData[LuminanceNames::<wbr>LlcTagName].object_items();<br>
- if(!percentileData.empty())<br>
- {<br>
- JsonArray percentageValues = percentileData[<wbr>PercentileNames::<wbr>DistributionIndex].array_<wbr>items();<br>
- int order = static_cast<int>(<wbr>percentageValues.size());<br>
- percentages.resize(order);<br>
- for(int i = 0; i < order; ++i)<br>
- {<br>
- percentages[i] = static_cast<unsigned int>(percentageValues[i].int_<wbr>value());<br>
- }<br>
- }<br>
- return true;<br>
- }<br>
- return false;<br>
- }<br>
-<br>
- bool bezierCurveFromJson(const Json &data, BezierCurveData &obj)<br>
+ bool bezierCurveFromJson(const Json &data, BezierCurveData &obj, const JsonType jsonType)<br>
{<br>
JsonObject jsonData = data.object_items();<br>
if(!jsonData.empty())<br>
{<br>
- obj.sPx = jsonData[BezierCurveNames::<wbr>KneePointX].int_value();<br>
- obj.sPy = jsonData[BezierCurveNames::<wbr>KneePointY].int_value();<br>
- obj.order = jsonData[BezierCurveNames::<wbr>NumberOfAnchors].int_value();<br>
- obj.coeff.resize(obj.order);<br>
- for(int i = 0; i < obj.order; ++i)<br>
- {<br>
- obj.coeff[i] = jsonData[BezierCurveNames::<wbr>Anchors[i]].int_value();<br>
- }<br>
- return true;<br>
- }<br>
- return false;<br>
- }<br>
-<br>
- bool bezierCurveFromLLCJson(const Json &data, BezierCurveData &obj)<br>
- {<br>
- JsonObject jsonData = data.object_items();<br>
- if(!jsonData.empty())<br>
- {<br>
- obj.sPx = jsonData[BezierCurveNames::<wbr>KneePointX].int_value();<br>
- obj.sPy = jsonData[BezierCurveNames::<wbr>KneePointY].int_value();<br>
- JsonArray anchorValues = data[BezierCurveNames::<wbr>AnchorsTag].array_items();<br>
- obj.order = static_cast<int>(anchorValues.<wbr>size());<br>
- obj.coeff.resize(obj.order);<br>
- for(int i = 0; i < obj.order; ++i)<br>
- {<br>
- obj.coeff[i] = anchorValues[i].int_value();<br>
- }<br>
- return true;<br>
+ switch(jsonType)<br>
+ {<br>
+ case LEGACY:<br>
+ {<br>
+ obj.sPx = jsonData[BezierCurveNames::<wbr>KneePointX].int_value();<br>
+ obj.sPy = jsonData[BezierCurveNames::<wbr>KneePointY].int_value();<br>
+ obj.order = jsonData[BezierCurveNames::<wbr>NumberOfAnchors].int_value();<br>
+ obj.coeff.resize(obj.order);<br>
+ for(int i = 0; i < obj.order; ++i)<br>
+ {<br>
+ obj.coeff[i] = jsonData[BezierCurveNames::<wbr>Anchors[i]].int_value();<br>
+ }<br>
+ return true; <br>
+ } break;<br>
+ case LLC:<br>
+ {<br>
+ obj.sPx = jsonData[BezierCurveNames::<wbr>KneePointX].int_value();<br>
+ obj.sPy = jsonData[BezierCurveNames::<wbr>KneePointY].int_value();<br>
+ JsonArray anchorValues = data[BezierCurveNames::<wbr>AnchorsTag].array_items();<br>
+ obj.order = static_cast<int>(anchorValues.<wbr>size());<br>
+ obj.coeff.resize(obj.order);<br>
+ for(int i = 0; i < obj.order; ++i)<br>
+ {<br>
+ obj.coeff[i] = anchorValues[i].int_value();<br>
+ }<br>
+ return true;<br>
+ } break;<br>
+ }<br>
}<br>
return false;<br>
}<br>
@@ -256,10 +257,10 @@<br>
{<br>
std::string path(filePath);<br>
JsonArray fileData = JsonHelper::readJsonArray(<wbr>path);<br>
- bool isLLCJson = false;<br>
+ JsonType jsonType = LEGACY;<br>
if(fileData.empty())<br>
{<br>
- isLLCJson = true;<br>
+ jsonType = LLC;<br>
fileData = JsonHelper::readJson(filePath)<wbr>.at("SceneInfo").array_items()<wbr>;<br>
}<br>
<br>
@@ -281,7 +282,7 @@<br>
mPimpl->mCurrentStreamByte = 1;<br>
memset(metadata, 0, mSEIBytesToRead);<br>
<br>
- fillMetadataArray(fileData, frame, isLLCJson, metadata);<br>
+ fillMetadataArray(fileData, frame, jsonType, metadata);<br>
mPimpl->setPayloadSize(<wbr>metadata, 0, mPimpl->mCurrentStreamByte);<br>
return true;<br>
}<br>
@@ -290,11 +291,10 @@<br>
{<br>
std::string path(filePath);<br>
JsonArray fileData = JsonHelper::readJsonArray(<wbr>path);<br>
- bool isLLCJson = false;<br>
-<br>
+ JsonType jsonType = LEGACY;<br>
if (fileData.empty())<br>
{<br>
- isLLCJson = true;<br>
+ jsonType = LLC;<br>
fileData = JsonHelper::readJson(filePath)<wbr>.at("SceneInfo").array_items()<wbr>;<br>
}<br>
<br>
@@ -307,7 +307,7 @@<br>
mPimpl->mCurrentStreamBit = 8;<br>
mPimpl->mCurrentStreamByte = 1;<br>
<br>
- fillMetadataArray(fileData, frame, isLLCJson, metadata[frame]);<br>
+ fillMetadataArray(fileData, frame, jsonType, metadata[frame]);<br>
mPimpl->setPayloadSize(<wbr>metadata[frame], 0, mPimpl->mCurrentStreamByte);<br>
}<br>
<br>
@@ -353,7 +353,7 @@<br>
/* NOTE: We leave TWO BYTES of space for the payload */<br>
mPimpl->mCurrentStreamByte += 2;<br>
<br>
- fillMetadataArray(fileData, frame, false, metadata);<br>
+ fillMetadataArray(fileData, frame, LEGACY, metadata);<br>
<br>
/* Set payload in bytes 2 & 3 as indicated in Extended InfoFrame Type syntax */<br>
metadata[2] = (mPimpl->mCurrentStreamByte & 0xFF00) >> 8;<br>
@@ -388,7 +388,7 @@<br>
/* NOTE: We leave TWO BYTES of space for the payload */<br>
mPimpl->mCurrentStreamByte += 2;<br>
<br>
- fillMetadataArray(fileData, frame, false, metadata[frame]);<br>
+ fillMetadataArray(fileData, frame, LEGACY, metadata[frame]);<br>
<br>
/* Set payload in bytes 2 & 3 as indicated in Extended InfoFrame Type syntax */<br>
metadata[frame][2] = (mPimpl->mCurrentStreamByte & 0xFF00) >> 8;<br>
@@ -398,7 +398,7 @@<br>
return numFrames;<br>
}<br>
<br>
-void metadataFromJson::<wbr>fillMetadataArray(const JsonArray &fileData, int frame, const bool isLLCJson, uint8_t *&metadata)<br>
+void metadataFromJson::<wbr>fillMetadataArray(const JsonArray &fileData, int frame, const JsonType jsonType, uint8_t *&metadata)<br>
{<br>
const uint8_t countryCode = 0xB5;<br>
const uint16_t terminalProviderCode = 0x003C;<br>
@@ -415,7 +415,7 @@<br>
<br>
uint16_t numWindows = 0;<br>
/* HDR10+ LLC doesn't consider local windows */<br>
- if(isLLCJson)<br>
+ if(jsonType & LLC)<br>
{<br>
numWindows = 1;<br>
mPimpl->appendBits(metadata, numWindows, 2);<br>
@@ -488,8 +488,7 @@<br>
{<br>
Json lumObj = fileData[frame][<wbr>LuminanceNames::TagName];<br>
LuminanceParameters luminanceData;<br>
- if(!((isLLCJson && mPimpl-><wbr>luminanceParamFromLLCJson(<wbr>lumObj, luminanceData)) ||<br>
- !(mPimpl-><wbr>luminanceParamFromJson(lumObj, luminanceData) && isLLCJson)))<br>
+ if(!mPimpl-><wbr>luminanceParamFromJson(lumObj, luminanceData, jsonType))<br>
{<br>
std::cout << "error parsing luminance parameters frame: " << w << std::endl;<br>
}<br>
@@ -511,16 +510,7 @@<br>
mPimpl->appendBits(metadata, numDistributionMaxrgbPercentil<wbr>es, 4);<br>
<br>
std::vector<unsigned int>percentilePercentages;<br>
-<br>
- if(isLLCJson)<br>
- {<br>
- mPimpl-><wbr>percentagesFromLLCJson(lumObj, percentilePercentages);<br>
- }<br>
- else<br>
- {<br>
- mPimpl->percentagesFromJson(<wbr>lumObj, percentilePercentages);<br>
- }<br>
-<br>
+ mPimpl->percentagesFromJson(<wbr>lumObj, percentilePercentages, jsonType);<br>
<br>
for (int i = 0; i < numDistributionMaxrgbPercentil<wbr>es; ++i)<br>
{<br>
@@ -551,27 +541,24 @@<br>
/* Bezier Curve Data */<br>
for (int w = 0; w < numWindows; ++w)<br>
{<br>
- uint8_t toneMappingFlag = 1;<br>
+ uint8_t toneMappingFlag = 0;<br>
/* Check if the window contains tone mapping bezier curve data and set toneMappingFlag appropriately */<br>
- //Json bezierData = fileData[frame][<wbr>BezierCurveNames::TagName];<br>
BezierCurveData curveData;<br>
/* Select curve data based on global window */<br>
if (w == 0)<br>
- {<br>
- if(!((isLLCJson && mPimpl-><wbr>bezierCurveFromLLCJson(<wbr>fileData[frame][<wbr>BezierCurveNames::TagName], curveData)) ||<br>
- !(mPimpl->bezierCurveFromJson(<wbr>fileData[frame][<wbr>BezierCurveNames::TagName], curveData) && isLLCJson)))<br>
+ { <br>
+ if (mPimpl->bezierCurveFromJson(<wbr>fileData[frame][<wbr>BezierCurveNames::TagName], curveData, jsonType))<br>
{<br>
- toneMappingFlag = 0;<br>
+ toneMappingFlag = 1;<br>
}<br>
}<br>
-<br>
/* Select curve data based on local window */<br>
else<br>
{<br>
JsonArray jsonArray = fileData[frame][JsonDataKeys::<wbr>LocalParameters].array_items()<wbr>;<br>
- if (!mPimpl->bezierCurveFromJson(<wbr>jsonArray[w - 1][BezierCurveNames::TagName], curveData))<br>
+ if (mPimpl->bezierCurveFromJson(<wbr>jsonArray[w - 1][BezierCurveNames::TagName], curveData, jsonType))<br>
{<br>
- toneMappingFlag = 0;<br>
+ toneMappingFlag = 1;<br>
}<br>
} <br>
mPimpl->appendBits(metadata, toneMappingFlag, 1);<br>
diff -r eea92165b035 -r d17bc7714ed2 source/dynamicHDR10/<wbr>metadataFromJson.h<br>
--- a/source/dynamicHDR10/<wbr>metadataFromJson.h Fri Jul 20 14:57:04 2018 +0530<br>
+++ b/source/dynamicHDR10/<wbr>metadataFromJson.h Tue Aug 07 12:31:51 2018 +0530<br>
@@ -36,6 +36,11 @@<br>
metadataFromJson();<br>
~metadataFromJson();<br>
<br>
+ enum JsonType{<br>
+ LEGACY,<br>
+ LLC<br>
+ };<br>
+ <br>
<br>
/**<br>
* @brief frameMetadataFromJson: Generates a sigle frame metadata array from Json file with all<br>
@@ -98,7 +103,7 @@<br>
<br>
class DynamicMetaIO;<br>
DynamicMetaIO *mPimpl;<br>
- void fillMetadataArray(const JsonArray &fileData, int frame, const bool isLLCJson, uint8_t *&metadata);<br>
+ void fillMetadataArray(const JsonArray &fileData, int frame, const JsonType jsonType, uint8_t *&metadata);<br>
};<br>
<br>
#endif // METADATAFROMJSON_H<br>
</blockquote></div><br></div><div class="gmail_extra">Pushed to default.</div></div>