mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-04 21:41:45 +00:00
lottie/feature: Added timeRemap feature implementation.
Change-Id: I89df91f3cc709fa8fa392586218676770c0aac84
This commit is contained in:
parent
416adb599e
commit
4da0782f60
@ -254,21 +254,21 @@ void LOTLayerItem::updateStaticProperty()
|
|||||||
mStatic = mPrecompLayer ? (mStatic & mPrecompLayer->isStatic()) : mStatic;
|
mStatic = mPrecompLayer ? (mStatic & mPrecompLayer->isStatic()) : mStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LOTLayerItem::update(int frameNo, const VMatrix &parentMatrix,
|
void LOTLayerItem::update(int frameNumber, const VMatrix &parentMatrix,
|
||||||
float parentAlpha)
|
float parentAlpha)
|
||||||
{
|
{
|
||||||
mFrameNo = frameNo;
|
mFrameNo = mLayerData->timeRemap(frameNumber);
|
||||||
// 1. check if the layer is part of the current frame
|
// 1. check if the layer is part of the current frame
|
||||||
if (!visible()) return;
|
if (!visible()) return;
|
||||||
|
|
||||||
// 2. calculate the parent matrix and alpha
|
// 2. calculate the parent matrix and alpha
|
||||||
VMatrix m = matrix(frameNo);
|
VMatrix m = matrix(frameNo());
|
||||||
m *= parentMatrix;
|
m *= parentMatrix;
|
||||||
float alpha = parentAlpha * opacity(frameNo);
|
float alpha = parentAlpha * opacity(frameNo());
|
||||||
|
|
||||||
// 6. update the mask
|
// 6. update the mask
|
||||||
if (hasMask()) {
|
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
|
// 3. update the dirty flag based on the change
|
||||||
|
|||||||
@ -292,6 +292,7 @@ public:
|
|||||||
int solidWidth() const noexcept{return mSolidLayer.mWidth;}
|
int solidWidth() const noexcept{return mSolidLayer.mWidth;}
|
||||||
int solidHeight() const noexcept{return mSolidLayer.mHeight;}
|
int solidHeight() const noexcept{return mSolidLayer.mHeight;}
|
||||||
LottieColor solidColor() const noexcept{return mSolidLayer.mColor;}
|
LottieColor solidColor() const noexcept{return mSolidLayer.mColor;}
|
||||||
|
int timeRemap(int frameNo) const;
|
||||||
public:
|
public:
|
||||||
struct SolidLayer {
|
struct SolidLayer {
|
||||||
int mWidth{0};
|
int mWidth{0};
|
||||||
@ -318,6 +319,7 @@ public:
|
|||||||
bool mHasGradient{false};
|
bool mHasGradient{false};
|
||||||
bool mRoot{false};
|
bool mRoot{false};
|
||||||
std::vector<std::shared_ptr<LOTMaskData>> mMasks;
|
std::vector<std::shared_ptr<LOTMaskData>> mMasks;
|
||||||
|
LOTCompositionData *mCompRef;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LOTCompositionData : public LOTData
|
class LOTCompositionData : public LOTData
|
||||||
@ -334,6 +336,9 @@ public:
|
|||||||
return isStatic() ? startFrame() :
|
return isStatic() ? startFrame() :
|
||||||
startFrame() + pos * frameDuration();
|
startFrame() + pos * frameDuration();
|
||||||
}
|
}
|
||||||
|
long frameAtTime(double timeInSec) const {
|
||||||
|
return isStatic() ? startFrame() : frameAtPos(timeInSec / duration());
|
||||||
|
}
|
||||||
long frameDuration() const {return mEndFrame - mStartFrame -1;}
|
long frameDuration() const {return mEndFrame - mStartFrame -1;}
|
||||||
float frameRate() const {return mFrameRate;}
|
float frameRate() const {return mFrameRate;}
|
||||||
long startFrame() const {return mStartFrame;}
|
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
|
class LOTTransformData : public LOTData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -810,7 +810,7 @@ std::shared_ptr<LOTData> LottieParserImpl::parseLayer()
|
|||||||
|
|
||||||
layer->setStatic(staticFlag && layer->mTransform->isStatic() &&
|
layer->setStatic(staticFlag && layer->mTransform->isStatic() &&
|
||||||
!hasLayerRef);
|
!hasLayerRef);
|
||||||
|
layer->mCompRef = compRef;
|
||||||
return sharedLayer;
|
return sharedLayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user