[x265-commits] [x265] Added support for the new HDR10+ LLC JSON format injectio...

Ashok Kumar Mishra ashok at multicorewareinc.com
Tue Jul 17 01:03:03 CEST 2018


details:   http://hg.videolan.org/x265/rev/7763d20f092a
branches:  
changeset: 12391:7763d20f092a
user:      Ashok Kumar Mishra <ashok at multicorewareinc.com>
date:      Thu Jul 12 12:14:00 2018 +0530
description:
Added support for the new HDR10+ LLC JSON format injection inside dynamicHDR10 library.
Subject: [x265] Fix HDR10+ LLC JSON support

details:   http://hg.videolan.org/x265/rev/18eaffdd3638
branches:  
changeset: 12392:18eaffdd3638
user:      indumathi at multicorewareinc.com
date:      Fri Jun 15 19:00:45 2018 +0530
description:
Fix HDR10+ LLC JSON support

diffstat:

 source/dynamicHDR10/SeiMetadataDictionary.cpp |    5 +
 source/dynamicHDR10/SeiMetadataDictionary.h   |    5 +
 source/dynamicHDR10/metadataFromJson.cpp      |  250 +++++++++++++++----------
 source/dynamicHDR10/metadataFromJson.h        |    2 +-
 4 files changed, 164 insertions(+), 98 deletions(-)

diffs (truncated from 548 to 300 lines):

diff -r 8bf51aa8a170 -r 18eaffdd3638 source/dynamicHDR10/SeiMetadataDictionary.cpp
--- a/source/dynamicHDR10/SeiMetadataDictionary.cpp	Thu Jul 12 17:23:26 2018 +0800
+++ b/source/dynamicHDR10/SeiMetadataDictionary.cpp	Fri Jun 15 19:00:45 2018 +0530
@@ -34,6 +34,7 @@ const std::string BezierCurveNames::TagN
 const std::string BezierCurveNames::NumberOfAnchors = std::string("NumberOfAnchors");
 const std::string BezierCurveNames::KneePointX = std::string("KneePointX");
 const std::string BezierCurveNames::KneePointY = std::string("KneePointY");
+const std::string BezierCurveNames::AnchorsTag = std::string("Anchors");
 const std::string BezierCurveNames::Anchors[] = {std::string("Anchor0"),
                                                  std::string("Anchor1"),
                                                  std::string("Anchor2"),
@@ -69,6 +70,8 @@ const std::string EllipseNames::SemiMajo
 
 const std::string PercentileNames::TagName = std::string("PercentileLuminance");
 const std::string PercentileNames::NumberOfPercentiles = std::string("NumberOfPercentiles");
+const std::string PercentileNames::DistributionIndex = std::string("DistributionIndex");
+const std::string PercentileNames::DistributionValues = std::string("DistributionValues");
 const std::string PercentileNames::PercentilePercentageValue[] = {std::string("PercentilePercentage0"),
                                                                   std::string("PercentilePercentage1"),
                                                                   std::string("PercentilePercentage2"),
@@ -104,7 +107,9 @@ const std::string PercentileNames::Perce
 
 
 const std::string LuminanceNames::TagName = std::string("LuminanceParameters");
+const std::string LuminanceNames::LlcTagName = std::string("LuminanceDistributions");
 const std::string LuminanceNames::AverageRGB = std::string("AverageRGB");
+const std::string LuminanceNames::MaxSCL = std::string("MaxScl");
 const std::string LuminanceNames::MaxSCL0 = std::string("MaxScl0");
 const std::string LuminanceNames::MaxSCL1 = std::string("MaxScl1");
 const std::string LuminanceNames::MaxSCL2 = std::string("MaxScl2");
diff -r 8bf51aa8a170 -r 18eaffdd3638 source/dynamicHDR10/SeiMetadataDictionary.h
--- a/source/dynamicHDR10/SeiMetadataDictionary.h	Thu Jul 12 17:23:26 2018 +0800
+++ b/source/dynamicHDR10/SeiMetadataDictionary.h	Fri Jun 15 19:00:45 2018 +0530
@@ -48,6 +48,7 @@ namespace SeiMetadataDictionary
         static const std::string NumberOfAnchors;
         static const std::string KneePointX;
         static const std::string KneePointY;
+        static const std::string AnchorsTag;
         static const std::string Anchors[14];
     };
     //Ellipse Selection Data
@@ -79,6 +80,8 @@ namespace SeiMetadataDictionary
         public:
         static const std::string TagName;
         static const std::string NumberOfPercentiles;
+        static const std::string DistributionIndex;
+        static const std::string DistributionValues;
         static const std::string PercentilePercentageValue[15];
         static const std::string PercentileLuminanceValue[15];
     };
@@ -87,7 +90,9 @@ namespace SeiMetadataDictionary
     {
         public:
         static const std::string TagName;
+        static const std::string LlcTagName;
         static const std::string AverageRGB;
+        static const std::string MaxSCL;
         static const std::string MaxSCL0;
         static const std::string MaxSCL1;
         static const std::string MaxSCL2;
diff -r 8bf51aa8a170 -r 18eaffdd3638 source/dynamicHDR10/metadataFromJson.cpp
--- a/source/dynamicHDR10/metadataFromJson.cpp	Thu Jul 12 17:23:26 2018 +0800
+++ b/source/dynamicHDR10/metadataFromJson.cpp	Fri Jun 15 19:00:45 2018 +0530
@@ -51,14 +51,13 @@ public:
         JsonObject lumJsonData = data.object_items();
         if(!lumJsonData.empty())
         {
-            JsonObject percentileData = lumJsonData[PercentileNames::TagName].object_items();
-            obj.order = percentileData[PercentileNames::NumberOfPercentiles].int_value();
-
             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);
@@ -69,7 +68,33 @@ public:
                     obj.percentiles[i] = static_cast<unsigned int>(percentileData[percentileTag].int_value());
                 }
             }
+            return true;
+        }
+        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;
@@ -82,33 +107,33 @@ public:
         {
             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 percentagesFromJson(const Json &data, unsigned int *percentages)
+    bool percentagesFromLLCJson(const Json &data, std::vector<unsigned int> &percentages)
     {
-        JsonObject jsonData = data.object_items();
-        if(!jsonData.empty())
-        {
-            JsonObject percentileData = jsonData[PercentileNames::TagName].object_items();
-            int order = percentileData[PercentileNames::NumberOfPercentiles].int_value();
-
-            for(int i = 0; i < order; ++i)
+        JsonObject lumJsonData = data.object_items();
+        if(!lumJsonData.empty())
+        {            
+            JsonObject percentileData = lumJsonData[LuminanceNames::LlcTagName].object_items();
+            if(!percentileData.empty())
             {
-                std::string percentileTag = PercentileNames::PercentilePercentageValue[i];
-                percentages[i] = static_cast<unsigned int>(percentileData[percentileTag].int_value());
+                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;
@@ -119,15 +144,33 @@ public:
         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);
-            obj.sPx = jsonData[BezierCurveNames::KneePointX].int_value();
-            obj.sPy = jsonData[BezierCurveNames::KneePointY].int_value();
             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;
         }
         return false;
@@ -162,9 +205,7 @@ public:
     void setPayloadSize(uint8_t *dataStream, int positionOnStream, int payload)
     {
         int payloadBytes = 1;
-
         for(;payload >= 0xFF; payload -= 0xFF, ++payloadBytes);
-
         if(payloadBytes > 1)
         {
             shiftData(dataStream, payloadBytes-1, mCurrentStreamByte, positionOnStream);
@@ -196,8 +237,6 @@ public:
         }
     }
 
-//    const std::string LocalParameters = std::string("LocalParameters");
-//    const std::string TargetDisplayLuminance = std::string("TargetedSystemDisplayMaximumLuminance");
 };
 
 metadataFromJson::metadataFromJson() :
@@ -211,17 +250,17 @@ metadataFromJson::~metadataFromJson()
     delete mPimpl;
 }
 
-
 bool metadataFromJson::frameMetadataFromJson(const char* filePath,
                                               int frame,
                                               uint8_t *&metadata)
 {
     std::string path(filePath);
     JsonArray fileData = JsonHelper::readJsonArray(path);
-
+    bool isLLCJson = false;
     if(fileData.empty())
     {
-        return false;
+        isLLCJson = true;
+        fileData = JsonHelper::readJson(filePath).at("SceneInfo").array_items();
     }
 
 //    frame = frame + 1; //index on the array start at 0 frames starts at 1
@@ -233,7 +272,6 @@ bool metadataFromJson::frameMetadataFrom
     }
 
     int mSEIBytesToRead = 509;
-
     if(metadata)
     {
         delete(metadata);
@@ -241,13 +279,9 @@ bool metadataFromJson::frameMetadataFrom
     metadata = new uint8_t[mSEIBytesToRead];
     mPimpl->mCurrentStreamBit = 8;
     mPimpl->mCurrentStreamByte = 1;
+    memset(metadata, 0, mSEIBytesToRead);
 
-    for(int j = 0; j < mSEIBytesToRead; ++j)
-    {
-        (metadata)[j] = 0;
-    }
-
-    fillMetadataArray(fileData, frame, metadata);
+    fillMetadataArray(fileData, frame, isLLCJson, metadata);
     mPimpl->setPayloadSize(metadata, 0, mPimpl->mCurrentStreamByte);
     return true;
 }
@@ -256,9 +290,12 @@ int metadataFromJson::movieMetadataFromJ
 {
     std::string path(filePath);
     JsonArray fileData = JsonHelper::readJsonArray(path);
+    bool isLLCJson = false;
+
     if (fileData.empty())
     {
-        return -1;
+        isLLCJson = true;
+        fileData = JsonHelper::readJson(filePath).at("SceneInfo").array_items();
     }
 
     int numFrames = static_cast<int>(fileData.size());
@@ -266,17 +303,12 @@ int metadataFromJson::movieMetadataFromJ
     for (int frame = 0; frame < numFrames; ++frame)
     {
         metadata[frame] = new uint8_t[509];
-        for (int i = 0; i < 509; ++i)
-        {
-            metadata[frame][i] = 0;
-        }
+        memset(metadata[frame], 0, 509);
         mPimpl->mCurrentStreamBit = 8;
         mPimpl->mCurrentStreamByte = 1;
 
-        fillMetadataArray(fileData, frame, metadata[frame]);
-
+        fillMetadataArray(fileData, frame, isLLCJson, metadata[frame]);
         mPimpl->setPayloadSize(metadata[frame], 0, mPimpl->mCurrentStreamByte);
-
     }
 
     return numFrames;
@@ -321,7 +353,7 @@ bool metadataFromJson::extendedInfoFrame
     /* NOTE: We leave TWO BYTES of space for the payload */
     mPimpl->mCurrentStreamByte += 2;
 
-    fillMetadataArray(fileData, frame, metadata);


More information about the x265-commits mailing list