From: subhransu mohanty Date: Tue, 23 Oct 2018 00:46:20 +0000 (+0900) Subject: lottie/feature: Added timeRemap feature implementation. X-Git-Tag: submit/tizen/20181129.071502~43 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4da0782f60960ecec679e163ec9ba52b1534b88f;p=platform%2Fcore%2Fuifw%2Flottie-player.git lottie/feature: Added timeRemap feature implementation. Change-Id: I89df91f3cc709fa8fa392586218676770c0aac84 --- diff --git a/src/lottie/lottieitem.cpp b/src/lottie/lottieitem.cpp index 25f39b1..37b6a5a 100644 --- a/src/lottie/lottieitem.cpp +++ b/src/lottie/lottieitem.cpp @@ -254,21 +254,21 @@ void LOTLayerItem::updateStaticProperty() mStatic = mPrecompLayer ? (mStatic & mPrecompLayer->isStatic()) : mStatic; } -void LOTLayerItem::update(int frameNo, const VMatrix &parentMatrix, +void LOTLayerItem::update(int frameNumber, const VMatrix &parentMatrix, float parentAlpha) { - mFrameNo = frameNo; + mFrameNo = mLayerData->timeRemap(frameNumber); // 1. check if the layer is part of the current frame if (!visible()) return; // 2. calculate the parent matrix and alpha - VMatrix m = matrix(frameNo); + VMatrix m = matrix(frameNo()); m *= parentMatrix; - float alpha = parentAlpha * opacity(frameNo); + float alpha = parentAlpha * opacity(frameNo()); // 6. update the mask if (hasMask()) { - for (auto &i : mMasks) i->update(frameNo, m, alpha, mDirtyFlag); + for (auto &i : mMasks) i->update(frameNo(), m, alpha, mDirtyFlag); } // 3. update the dirty flag based on the change diff --git a/src/lottie/lottiemodel.h b/src/lottie/lottiemodel.h index 7d61ebf..00e84f6 100644 --- a/src/lottie/lottiemodel.h +++ b/src/lottie/lottiemodel.h @@ -292,6 +292,7 @@ public: int solidWidth() const noexcept{return mSolidLayer.mWidth;} int solidHeight() const noexcept{return mSolidLayer.mHeight;} LottieColor solidColor() const noexcept{return mSolidLayer.mColor;} + int timeRemap(int frameNo) const; public: struct SolidLayer { int mWidth{0}; @@ -318,6 +319,7 @@ public: bool mHasGradient{false}; bool mRoot{false}; std::vector> mMasks; + LOTCompositionData *mCompRef; }; class LOTCompositionData : public LOTData @@ -334,6 +336,9 @@ public: return isStatic() ? startFrame() : startFrame() + pos * frameDuration(); } + long frameAtTime(double timeInSec) const { + return isStatic() ? startFrame() : frameAtPos(timeInSec / duration()); + } long frameDuration() const {return mEndFrame - mStartFrame -1;} float frameRate() const {return mFrameRate;} long startFrame() const {return mStartFrame;} @@ -355,6 +360,19 @@ public: }; +/** + * TimeRemap has the value in time domain(in sec) + * To get the proper mapping first we get the mapped time at the current frame Number + * then we need to convert mapped time to frame number using the composition time line + * Ex: at frame 10 the mappend time is 0.5(500 ms) which will be convert to frame number + * 30 if the frame rate is 60. or will result to frame number 15 if the frame rate is 30. + */ +inline int LOTLayerData::timeRemap(int frameNo) const +{ + return mTimeRemap.isStatic() ? frameNo : + mCompRef->frameAtTime(mTimeRemap.value(frameNo)); +} + class LOTTransformData : public LOTData { public: diff --git a/src/lottie/lottieparser.cpp b/src/lottie/lottieparser.cpp index 5902659..4c625e0 100644 --- a/src/lottie/lottieparser.cpp +++ b/src/lottie/lottieparser.cpp @@ -810,7 +810,7 @@ std::shared_ptr LottieParserImpl::parseLayer() layer->setStatic(staticFlag && layer->mTransform->isStatic() && !hasLayerRef); - + layer->mCompRef = compRef; return sharedLayer; }