Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lottie: data optimization #2216

Closed
wants to merge 1 commit into from
Closed

lottie: data optimization #2216

wants to merge 1 commit into from

Conversation

hermet
Copy link
Member

@hermet hermet commented Apr 23, 2024

lottie exclusively uses lines with the bezier curve. This approach consumes more points memory and requires additional computational processing. The Lottie loader converts 'CubicTo' to 'LineTo' only if possible,
specifically when the shape layer has only a single frame.

We've observed that thousands of commands can be converted with our Lottie example.

@hermet hermet added optimization Enhance performance / Reduce memory usage or binary size lottie Lottie animation labels Apr 23, 2024
@hermet hermet self-assigned this Apr 23, 2024
lottie exclusively uses lines with the bezier curve.
This approach consumes more points memory and requires
additional computational processing. The Lottie loader
converts 'CubicTo' to 'LineTo' only if possible,
specifically when the shape layer has only a single frame.

We've observed that thousands of commands can be converted
with our Lottie example.
Copy link
Collaborator

@mgrudzinska mgrudzinska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for a vertical line: (1,1), (1,2), (1,3), (1,4) functions returns false (also we get nan and inf inside it)

for points: (1,1), (2,2), (10,10), (4,4) - function returns true, although the end point should be changed to be (10,10) instead of (4,4)

auto cy = m * (c.x - a.x) + a.y;
if (!mathEqual(cy, c.y)) return false;
return true;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my propositioin:

static bool _isBetween(const Point& check, const Point& a, const Point& b)
{
    return check.x >= mathMin(a.x, b.x) && check.x <= mathMax(a.x, b.x) &&
           check.y >= mathMin(a.y, b.y) && check.y <= mathMax(a.y, b.y);
}

static bool _curve2line(const Point& a, const Point& b, const Point& c, const Point& d)
{
    //vertical line
    if (mathEqual(a.x, d.x) && mathEqual(a.x, c.x) && mathEqual(a.x, b.x)) {
        return _isBetween(b, a, d) && _isBetween(c, a, d);
    }

    auto m = (d.y - a.y) / (d.x - a.x);
    auto by = m * (b.x - a.x) + a.y;
    if (!mathEqual(by, b.y)) return false;
    auto cy = m * (c.x - a.x) + a.y;
    if (!mathEqual(cy, c.y)) return false;
    
    return _isBetween(b, a, d) && _isBetween(c, a, d);
}

tvgMath.h has to be included

ex. in the 'world_locations.json' happens that _isBetween returns false

@hermet hermet marked this pull request as draft April 25, 2024 01:40
@hermet hermet closed this May 15, 2024
@hermet hermet added the invalid This doesn't seem right label May 15, 2024
@hermet hermet deleted the hermet/lottie_optimize branch May 15, 2024 03:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right lottie Lottie animation optimization Enhance performance / Reduce memory usage or binary size
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants