rlottie: support composition marker feature in lottie accepted/tizen/unified/20191011.015420 submit/tizen/20191009.211935
authorsubhransu mohanty <sub.mohanty@samsung.com>
Tue, 8 Oct 2019 04:33:57 +0000 (13:33 +0900)
committerJongmin Lee <jm105.lee@samsung.com>
Wed, 9 Oct 2019 21:16:04 +0000 (06:16 +0900)
inc/rlottie.h
src/lottie/lottieanimation.cpp
src/lottie/lottiemodel.h
src/lottie/lottieparser.cpp

index 6066c628dd7ccd39ab162428d99b4c9e2ae79f66..b37f67aa6776e147c88ffc432ef635ce7d55687b 100644 (file)
@@ -251,6 +251,14 @@ private:
     }mDrawArea;
 };
 
+using MarkerList = std::vector<std::tuple<std::string, int , int>>;
+/**
+ *  @brief https://helpx.adobe.com/after-effects/using/layer-markers-composition-markers.html
+ *  Markers exported form AE are used to describe a segmnet of an animation {comment/tag , startFrame, endFrame}
+ *  Marker can be use to devide a resource in to separate animations by tagging the segment with comment string ,
+ *  start frame and duration of that segment.
+ */
+
 using LayerInfoList = std::vector<std::tuple<std::string, int , int>>;
 
 class LOT_EXPORT Animation {
@@ -403,6 +411,17 @@ public:
      */
     const LOTLayerNode * renderTree(size_t frameNo, size_t width, size_t height) const;
 
+    /**
+     *  @brief Returns Composition Markers.
+     *
+     *
+     *  @return returns MarkerList of the Composition.
+     *
+     *  @see MarkerList
+     *  @internal
+     */
+    const MarkerList& markers() const;
+
     /**
      *  @brief Returns Layer information{name, inFrame, outFrame} of all the child layers  of the composition.
      *
index caf546da8fbcbbb5b1c31e299570f4c50658a1be..ce40d4ab2a8efa6d5c5b0b8fa90f0f3cfba9bc0d 100644 (file)
@@ -58,6 +58,10 @@ public:
     {
         return mModel->layerInfoList();
     }
+    const MarkerList &markers() const
+    {
+        return mModel->markers();
+    }
     void setValue(const std::string &keypath, LOTVariant &&value);
     void removeFilter(const std::string &keypath, Property prop);
 
@@ -323,6 +327,11 @@ const LayerInfoList &Animation::layers() const
     return d->layerInfoList();
 }
 
+const MarkerList &Animation::markers() const
+{
+    return d->markers();
+}
+
 void Animation::setValue(Color_Type, Property prop, const std::string &keypath,
                          Color value)
 {
index 456eeb55bbe8a4051c5010137f2c4fefe47c0cf1..3b69c82aaf2cdfe48af9584cf3b38874786965f5 100644 (file)
@@ -650,13 +650,15 @@ public:
     std::unique_ptr<ExtraLayerData> mExtra{nullptr};
 };
 
-using LayerInfo = std::tuple<std::string, int , int>;
+using Marker = std::tuple<std::string, int , int>;
+using LayerInfo = Marker;
 
 class LOTCompositionData : public LOTData
 {
 public:
     LOTCompositionData():LOTData(LOTData::Type::Composition){}
     const std::vector<LayerInfo> &layerInfoList() const { return  mLayerInfoList;}
+    const std::vector<Marker> &markers() const { return  mMarkers;}
     double duration() const {
         return frameDuration() / frameRate(); // in second
     }
@@ -688,6 +690,7 @@ public:
                        std::shared_ptr<LOTAsset>>    mAssets;
 
     std::vector<LayerInfo>  mLayerInfoList;
+    std::vector<Marker>     mMarkers;
     LOTModelStat            mStats;
 };
 
@@ -1087,6 +1090,7 @@ public:
    size_t endFrame() const {return mRoot->endFrame();}
    size_t frameAtPos(double pos) const {return mRoot->frameAtPos(pos);}
    const std::vector<LayerInfo> &layerInfoList() const { return mRoot->layerInfoList();}
+   const std::vector<Marker> &markers() const { return mRoot->markers();}
 public:
     std::shared_ptr<LOTCompositionData> mRoot;
 };
index 53dd1c6c8389f7fee09f894953b0cd4b1b50488a..b4de8306098203ab8fa0c3a8f50ef290286ef78b 100644 (file)
@@ -205,6 +205,8 @@ public:
         return mComposition;
     }
     void                         parseComposition();
+    void                         parseMarkers();
+    void                         parseMarker();
     void                         parseAssets(LOTCompositionData *comp);
     std::shared_ptr<LOTAsset>    parseAsset();
     void                         parseLayers(LOTCompositionData *comp);
@@ -584,6 +586,8 @@ void LottieParserImpl::parseComposition()
             parseAssets(comp);
         } else if (0 == strcmp(key, "layers")) {
             parseLayers(comp);
+        } else if (0 == strcmp(key, "markers")) {
+            parseMarkers();
         } else {
 #ifdef DEBUG_PARSER
             vWarning << "Composition Attribute Skipped : " << key;
@@ -607,6 +611,44 @@ void LottieParserImpl::parseComposition()
     mComposition = sharedComposition;
 }
 
+void LottieParserImpl::parseMarker()
+{
+    RAPIDJSON_ASSERT(PeekType() == kObjectType);
+    EnterObject();
+    std::string comment;
+    int         timeframe{0};
+    int          duration{0};
+    while (const char *key = NextObjectKey()) {
+        if (0 == strcmp(key, "cm")) {
+            RAPIDJSON_ASSERT(PeekType() == kStringType);
+            comment = std::string(GetString());
+        } else if (0 == strcmp(key, "tm")) {
+            RAPIDJSON_ASSERT(PeekType() == kNumberType);
+            timeframe = GetDouble();
+        } else if (0 == strcmp(key, "dr")) {
+            RAPIDJSON_ASSERT(PeekType() == kNumberType);
+            duration = GetDouble();
+
+        } else {
+#ifdef DEBUG_PARSER
+            vWarning << "Marker Attribute Skipped : " << key;
+#endif
+            Skip(key);
+        }
+    }
+    compRef->mMarkers.emplace_back(std::move(comment), timeframe, timeframe + duration);
+}
+
+void LottieParserImpl::parseMarkers()
+{
+    RAPIDJSON_ASSERT(PeekType() == kArrayType);
+    EnterArray();
+    while (NextArrayValue()) {
+        parseMarker();
+    }
+    // update the precomp layers with the actual layer object
+}
+
 void LottieParserImpl::parseAssets(LOTCompositionData *composition)
 {
     RAPIDJSON_ASSERT(PeekType() == kArrayType);