From: subhransu mohanty Date: Tue, 8 Oct 2019 04:33:57 +0000 (+0900) Subject: rlottie: support composition marker feature in lottie X-Git-Tag: submit/tizen/20191009.211935^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4bf52d7d9863e8350ec96b97ca3c4f2320ac1fc3;p=platform%2Fcore%2Fuifw%2Flottie-player.git rlottie: support composition marker feature in lottie --- diff --git a/inc/rlottie.h b/inc/rlottie.h index 6066c62..b37f67a 100644 --- a/inc/rlottie.h +++ b/inc/rlottie.h @@ -251,6 +251,14 @@ private: }mDrawArea; }; +using MarkerList = std::vector>; +/** + * @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>; 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. * diff --git a/src/lottie/lottieanimation.cpp b/src/lottie/lottieanimation.cpp index caf546d..ce40d4a 100644 --- a/src/lottie/lottieanimation.cpp +++ b/src/lottie/lottieanimation.cpp @@ -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) { diff --git a/src/lottie/lottiemodel.h b/src/lottie/lottiemodel.h index 456eeb5..3b69c82 100644 --- a/src/lottie/lottiemodel.h +++ b/src/lottie/lottiemodel.h @@ -650,13 +650,15 @@ public: std::unique_ptr mExtra{nullptr}; }; -using LayerInfo = std::tuple; +using Marker = std::tuple; +using LayerInfo = Marker; class LOTCompositionData : public LOTData { public: LOTCompositionData():LOTData(LOTData::Type::Composition){} const std::vector &layerInfoList() const { return mLayerInfoList;} + const std::vector &markers() const { return mMarkers;} double duration() const { return frameDuration() / frameRate(); // in second } @@ -688,6 +690,7 @@ public: std::shared_ptr> mAssets; std::vector mLayerInfoList; + std::vector 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 &layerInfoList() const { return mRoot->layerInfoList();} + const std::vector &markers() const { return mRoot->markers();} public: std::shared_ptr mRoot; }; diff --git a/src/lottie/lottieparser.cpp b/src/lottie/lottieparser.cpp index 53dd1c6..b4de830 100644 --- a/src/lottie/lottieparser.cpp +++ b/src/lottie/lottieparser.cpp @@ -205,6 +205,8 @@ public: return mComposition; } void parseComposition(); + void parseMarkers(); + void parseMarker(); void parseAssets(LOTCompositionData *comp); std::shared_ptr 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);