[x265-commits] [x265] Added JsonType enum to differentiate between Legacy and L...

Ashok Kumar Mishra ashok at multicorewareinc.com
Wed Aug 8 01:03:02 CEST 2018


details:   http://hg.videolan.org/x265/rev/d17bc7714ed2
branches:  
changeset: 12406:d17bc7714ed2
user:      Ashok Kumar Mishra <ashok at multicorewareinc.com>
date:      Tue Aug 07 12:31:51 2018 +0530
description:
Added JsonType enum to differentiate between Legacy and LLC file format.
Added usage of switch inside parameter functions instead of multiple condition IF's

diffstat:

 source/dynamicHDR10/metadataFromJson.cpp |  277 ++++++++++++++----------------
 source/dynamicHDR10/metadataFromJson.h   |    7 +-
 2 files changed, 138 insertions(+), 146 deletions(-)

diffs (truncated from 417 to 300 lines):

diff -r eea92165b035 -r d17bc7714ed2 source/dynamicHDR10/metadataFromJson.cpp
--- a/source/dynamicHDR10/metadataFromJson.cpp	Fri Jul 20 14:57:04 2018 +0530
+++ b/source/dynamicHDR10/metadataFromJson.cpp	Tue Aug 07 12:31:51 2018 +0530
@@ -46,132 +46,133 @@ public:
     int mCurrentStreamBit;
     int mCurrentStreamByte;
 
-    bool luminanceParamFromJson(const Json &data, LuminanceParameters &obj)
+    bool luminanceParamFromJson(const Json &data, LuminanceParameters &obj, const JsonType jsonType)
     {
         JsonObject lumJsonData = data.object_items();
         if(!lumJsonData.empty())
         {
-            obj.averageLuminance = static_cast<float>(lumJsonData[LuminanceNames::AverageRGB].number_value());
-            obj.maxRLuminance = static_cast<float>(lumJsonData[LuminanceNames::MaxSCL0].number_value());
-            obj.maxGLuminance = static_cast<float>(lumJsonData[LuminanceNames::MaxSCL1].number_value());
-            obj.maxBLuminance = static_cast<float>(lumJsonData[LuminanceNames::MaxSCL2].number_value());
+			switch(jsonType)
+			{
+				case LEGACY:
+				{
+					obj.averageLuminance = static_cast<float>(lumJsonData[LuminanceNames::AverageRGB].number_value());
+					obj.maxRLuminance = static_cast<float>(lumJsonData[LuminanceNames::MaxSCL0].number_value());
+					obj.maxGLuminance = static_cast<float>(lumJsonData[LuminanceNames::MaxSCL1].number_value());
+					obj.maxBLuminance = static_cast<float>(lumJsonData[LuminanceNames::MaxSCL2].number_value());
 
-            JsonObject percentileData = lumJsonData[PercentileNames::TagName].object_items();
-            obj.order = percentileData[PercentileNames::NumberOfPercentiles].int_value();
-            if(!percentileData.empty())
-            {
-                obj.percentiles.resize(obj.order);
-                for(int i = 0; i < obj.order; ++i)
-                {
-                    std::string percentileTag = PercentileNames::TagName;
-                    percentileTag += std::to_string(i);
-                    obj.percentiles[i] = static_cast<unsigned int>(percentileData[percentileTag].int_value());
-                }
-            }
-            return true;
+					JsonObject percentileData = lumJsonData[PercentileNames::TagName].object_items();
+					obj.order = percentileData[PercentileNames::NumberOfPercentiles].int_value();
+					if(!percentileData.empty())
+					{
+						obj.percentiles.resize(obj.order);
+						for(int i = 0; i < obj.order; ++i)
+						{
+							std::string percentileTag = PercentileNames::TagName;
+							percentileTag += std::to_string(i);
+							obj.percentiles[i] = static_cast<unsigned int>(percentileData[percentileTag].int_value());
+						}
+					}
+					return true;
+				} break;
+				case LLC:
+				{
+					obj.averageLuminance = static_cast<float>(lumJsonData[LuminanceNames::AverageRGB].number_value());
+					JsonArray maxScl = lumJsonData[LuminanceNames::MaxSCL].array_items();
+					obj.maxRLuminance = static_cast<float>(maxScl[0].number_value());
+					obj.maxGLuminance = static_cast<float>(maxScl[1].number_value());
+					obj.maxBLuminance = static_cast<float>(maxScl[2].number_value());
+
+					JsonObject percentileData = lumJsonData[LuminanceNames::LlcTagName].object_items();
+					if(!percentileData.empty())
+					{
+						JsonArray distributionValues = percentileData[PercentileNames::DistributionValues].array_items();
+						obj.order = static_cast<int>(distributionValues.size());
+						obj.percentiles.resize(obj.order);
+						for(int i = 0; i < obj.order; ++i)
+						{
+							obj.percentiles[i] = static_cast<unsigned int>(distributionValues[i].int_value());
+						}
+					}
+					return true;
+				} break;
+			}
+		}
+        return false;
+    }
+
+    bool percentagesFromJson(const Json &data, std::vector<unsigned int> &percentages, const JsonType jsonType)
+    {
+        JsonObject jsonData = data.object_items();
+        if(!jsonData.empty())
+        {
+			switch(jsonType)
+			{
+				case LEGACY:
+				{
+					JsonObject percentileData = jsonData[PercentileNames::TagName].object_items();
+					int order = percentileData[PercentileNames::NumberOfPercentiles].int_value();
+					percentages.resize(order);
+					for(int i = 0; i < order; ++i)
+					{
+						std::string percentileTag = PercentileNames::PercentilePercentageValue[i];
+						percentages[i] = static_cast<unsigned int>(percentileData[percentileTag].int_value());
+					}
+					return true;
+				} break;
+				case LLC:
+				{
+					JsonObject percentileData = jsonData[LuminanceNames::LlcTagName].object_items();
+					if(!percentileData.empty())
+					{
+						JsonArray percentageValues = percentileData[PercentileNames::DistributionIndex].array_items();
+						int order = static_cast<int>(percentageValues.size());
+						percentages.resize(order);
+						for(int i = 0; i < order; ++i)
+						{
+							percentages[i] = static_cast<unsigned int>(percentageValues[i].int_value());
+						}
+					} 
+					return true;
+				} break;
+			}
+
         }
         return false;
     }
 
-    bool luminanceParamFromLLCJson(const Json &data, LuminanceParameters &obj)
-    {
-        JsonObject lumJsonData = data.object_items();
-        if(!lumJsonData.empty())
-        {
-            obj.averageLuminance = static_cast<float>(lumJsonData[LuminanceNames::AverageRGB].number_value());
-            JsonArray maxScl = lumJsonData[LuminanceNames::MaxSCL].array_items();
-            obj.maxRLuminance = static_cast<float>(maxScl[0].number_value());
-            obj.maxGLuminance = static_cast<float>(maxScl[1].number_value());
-            obj.maxBLuminance = static_cast<float>(maxScl[2].number_value());
-
-            JsonObject percentileData = lumJsonData[LuminanceNames::LlcTagName].object_items();
-            if(!percentileData.empty())
-            {
-                JsonArray distributionValues = percentileData[PercentileNames::DistributionValues].array_items();
-                obj.order = static_cast<int>(distributionValues.size());
-                obj.percentiles.resize(obj.order);
-                for(int i = 0; i < obj.order; ++i)
-                {
-                    obj.percentiles[i] = static_cast<unsigned int>(distributionValues[i].int_value());
-                }
-            }
-            return true;
-        }
-        return false;
-    }
-
-    bool percentagesFromJson(const Json &data, std::vector<unsigned int> &percentages)
+    bool bezierCurveFromJson(const Json &data, BezierCurveData &obj, const JsonType jsonType)
     {
         JsonObject jsonData = data.object_items();
         if(!jsonData.empty())
         {
-            JsonObject percentileData = jsonData[PercentileNames::TagName].object_items();
-            int order = percentileData[PercentileNames::NumberOfPercentiles].int_value();
-            percentages.resize(order);
-            for(int i = 0; i < order; ++i)
-            {
-                std::string percentileTag = PercentileNames::PercentilePercentageValue[i];
-                percentages[i] = static_cast<unsigned int>(percentileData[percentileTag].int_value());
-            }
-            return true;
-        }
-        return false;
-    }
-
-    bool percentagesFromLLCJson(const Json &data, std::vector<unsigned int> &percentages)
-    {
-        JsonObject lumJsonData = data.object_items();
-        if(!lumJsonData.empty())
-        {            
-            JsonObject percentileData = lumJsonData[LuminanceNames::LlcTagName].object_items();
-            if(!percentileData.empty())
-            {
-                JsonArray percentageValues = percentileData[PercentileNames::DistributionIndex].array_items();
-                int order = static_cast<int>(percentageValues.size());
-                percentages.resize(order);
-                for(int i = 0; i < order; ++i)
-                {
-                    percentages[i] = static_cast<unsigned int>(percentageValues[i].int_value());
-                }
-            }
-            return true;
-        }
-        return false;
-    }
-
-    bool bezierCurveFromJson(const Json &data, BezierCurveData &obj)
-    {
-        JsonObject jsonData = data.object_items();
-        if(!jsonData.empty())
-        {
-            obj.sPx = jsonData[BezierCurveNames::KneePointX].int_value();
-            obj.sPy = jsonData[BezierCurveNames::KneePointY].int_value();
-            obj.order = jsonData[BezierCurveNames::NumberOfAnchors].int_value();
-            obj.coeff.resize(obj.order);
-            for(int i = 0; i < obj.order; ++i)
-            {
-                obj.coeff[i] = jsonData[BezierCurveNames::Anchors[i]].int_value();
-            }
-            return true;
-        }
-        return false;
-    }
-
-    bool bezierCurveFromLLCJson(const Json &data, BezierCurveData &obj)
-    {
-        JsonObject jsonData = data.object_items();
-        if(!jsonData.empty())
-        {
-            obj.sPx = jsonData[BezierCurveNames::KneePointX].int_value();
-            obj.sPy = jsonData[BezierCurveNames::KneePointY].int_value();
-            JsonArray anchorValues = data[BezierCurveNames::AnchorsTag].array_items();
-            obj.order = static_cast<int>(anchorValues.size());
-            obj.coeff.resize(obj.order);
-            for(int i = 0; i < obj.order; ++i)
-            {
-                obj.coeff[i] = anchorValues[i].int_value();
-            }
-            return true;
+			switch(jsonType)
+			{
+				case LEGACY:
+				{
+				    obj.sPx = jsonData[BezierCurveNames::KneePointX].int_value();
+					obj.sPy = jsonData[BezierCurveNames::KneePointY].int_value();
+					obj.order = jsonData[BezierCurveNames::NumberOfAnchors].int_value();
+					obj.coeff.resize(obj.order);
+					for(int i = 0; i < obj.order; ++i)
+					{
+						obj.coeff[i] = jsonData[BezierCurveNames::Anchors[i]].int_value();
+					}
+					return true;	
+				} break;
+				case LLC:
+				{
+					obj.sPx = jsonData[BezierCurveNames::KneePointX].int_value();
+					obj.sPy = jsonData[BezierCurveNames::KneePointY].int_value();
+					JsonArray anchorValues = data[BezierCurveNames::AnchorsTag].array_items();
+					obj.order = static_cast<int>(anchorValues.size());
+					obj.coeff.resize(obj.order);
+					for(int i = 0; i < obj.order; ++i)
+					{
+						obj.coeff[i] = anchorValues[i].int_value();
+					}
+					return true;
+				} break;
+			}
         }
         return false;
     }
@@ -256,10 +257,10 @@ bool metadataFromJson::frameMetadataFrom
 {
     std::string path(filePath);
     JsonArray fileData = JsonHelper::readJsonArray(path);
-    bool isLLCJson = false;
+	JsonType jsonType = LEGACY;
     if(fileData.empty())
     {
-        isLLCJson = true;
+		jsonType = LLC;
         fileData = JsonHelper::readJson(filePath).at("SceneInfo").array_items();
     }
 
@@ -281,7 +282,7 @@ bool metadataFromJson::frameMetadataFrom
     mPimpl->mCurrentStreamByte = 1;
     memset(metadata, 0, mSEIBytesToRead);
 
-    fillMetadataArray(fileData, frame, isLLCJson, metadata);
+    fillMetadataArray(fileData, frame, jsonType, metadata);
     mPimpl->setPayloadSize(metadata, 0, mPimpl->mCurrentStreamByte);
     return true;
 }
@@ -290,11 +291,10 @@ int metadataFromJson::movieMetadataFromJ
 {
     std::string path(filePath);
     JsonArray fileData = JsonHelper::readJsonArray(path);
-    bool isLLCJson = false;
-
+	JsonType jsonType = LEGACY;
     if (fileData.empty())
     {
-        isLLCJson = true;
+		jsonType = LLC;
         fileData = JsonHelper::readJson(filePath).at("SceneInfo").array_items();
     }
 
@@ -307,7 +307,7 @@ int metadataFromJson::movieMetadataFromJ
         mPimpl->mCurrentStreamBit = 8;
         mPimpl->mCurrentStreamByte = 1;
 
-        fillMetadataArray(fileData, frame, isLLCJson, metadata[frame]);
+        fillMetadataArray(fileData, frame, jsonType, metadata[frame]);
         mPimpl->setPayloadSize(metadata[frame], 0, mPimpl->mCurrentStreamByte);
     }
 
@@ -353,7 +353,7 @@ bool metadataFromJson::extendedInfoFrame
     /* NOTE: We leave TWO BYTES of space for the payload */
     mPimpl->mCurrentStreamByte += 2;
 
-    fillMetadataArray(fileData, frame, false, metadata);


More information about the x265-commits mailing list