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;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -810,7 +810,7 @@ std::shared_ptr<LOTData> LottieParserImpl::parseLayer()
|
||||
|
||||
layer->setStatic(staticFlag && layer->mTransform->isStatic() &&
|
||||
!hasLayerRef);
|
||||
|
||||
layer->mCompRef = compRef;
|
||||
return sharedLayer;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user