Skip to content

Commit

Permalink
rlottie: fix mask logic when inverted flag is set.
Browse files Browse the repository at this point in the history
Added the test resource that is fixed by this patch.
  • Loading branch information
smohantty committed Aug 14, 2020
1 parent 430304f commit 05ba5ee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions example/resource/29056-nepenthe-illustration.json

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions src/lottie/lottieitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ VRle renderer::Mask::rle()
mRasterRequest = false;
if (!vCompare(mCombinedAlpha, 1.0f))
mRasterizer.rle() *= uchar(mCombinedAlpha * 255);
if (mData->mInv) mRasterizer.rle().invert();
}
return mRasterizer.rle();
}
Expand Down Expand Up @@ -287,24 +286,27 @@ VRle renderer::LayerMask::maskRle(const VRect &clipRect)
if (!mDirty) return mRle;

VRle rle;
for (auto &i : mMasks) {
switch (i.maskMode()) {
for (auto &e : mMasks) {
auto cur = e.rle();
if (e.inverted()) cur = VRle::toRle(clipRect) - cur;

switch (e.maskMode()) {
case model::Mask::Mode::Add: {
rle = rle + i.rle();
rle = rle + cur;
break;
}
case model::Mask::Mode::Substarct: {
if (rle.empty() && !clipRect.empty()) rle = VRle::toRle(clipRect);
rle = rle - i.rle();
rle = rle - cur;
break;
}
case model::Mask::Mode::Intersect: {
if (rle.empty() && !clipRect.empty()) rle = VRle::toRle(clipRect);
rle = rle & i.rle();
rle = rle & cur;
break;
}
case model::Mask::Mode::Difference: {
rle = rle ^ i.rle();
rle = rle ^ cur;
break;
}
default:
Expand Down
2 changes: 1 addition & 1 deletion src/lottie/lottieitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class Mask {
model::Mask::Mode maskMode() const { return mData->mMode; }
VRle rle();
void preprocess(const VRect &clip);

bool inverted() const { return mData->mInv; }
public:
model::Mask *mData{nullptr};
VPath mLocalPath;
Expand Down

0 comments on commit 05ba5ee

Please sign in to comment.