lottie/feature: Added timeRemap feature implementation. 22/191722/1
authorsubhransu mohanty <sub.mohanty@samsung.com>
Tue, 23 Oct 2018 00:46:20 +0000 (09:46 +0900)
committersubhransu mohanty <sub.mohanty@samsung.com>
Tue, 23 Oct 2018 00:49:26 +0000 (09:49 +0900)
Change-Id: I89df91f3cc709fa8fa392586218676770c0aac84

src/lottie/lottieitem.cpp
src/lottie/lottiemodel.h
src/lottie/lottieparser.cpp

index 25f39b1c2f882c45e33e8019e4ebc901eb7818d4..37b6a5a7abd4e446399bf4c604ca2fd4855716b7 100644 (file)
@@ -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
index 7d61ebf11c229ff00cca15baa356c07bb0f57321..00e84f645a887966c022db32ec8d5ba1f75a0675 100644 (file)
@@ -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<std::shared_ptr<LOTMaskData>>  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:
index 590265998853c46beca55664fd3003f197b0840b..4c625e0ff99aba2948fc2aa3b86dd06a6beb8484 100644 (file)
@@ -810,7 +810,7 @@ std::shared_ptr<LOTData> LottieParserImpl::parseLayer()
 
     layer->setStatic(staticFlag && layer->mTransform->isStatic() &&
                      !hasLayerRef);
-
+    layer->mCompRef = compRef;
     return sharedLayer;
 }