Refactoring

This commit is contained in:
Isaac 2024-05-18 20:10:28 +04:00
parent 1ee81d91d2
commit 6f63e9a624
59 changed files with 433 additions and 455 deletions

View File

@ -9,63 +9,6 @@
namespace lottieRendering {
struct Color {
double r;
double g;
double b;
double a;
Color(double r_, double g_, double b_, double a_) :
r(r_), g(g_), b(b_), a(a_) {
}
bool operator==(Color const &rhs) const {
if (r != rhs.r) {
return false;
}
if (g != rhs.g) {
return false;
}
if (b != rhs.b) {
return false;
}
if (a != rhs.a) {
return false;
}
return true;
}
bool operator!=(Color const &rhs) const {
return !(*this == rhs);
}
};
enum class BlendMode {
Normal,
DestinationIn,
DestinationOut
};
enum class FillRule: int {
None = 0,
NonZeroWinding = 1,
EvenOdd = 2
};
enum class LineCap: int {
None = 0,
Butt = 1,
Round = 2,
Square = 3
};
enum class LineJoin: int {
None = 0,
Miter = 1,
Round = 2,
Bevel = 3
};
class Image {
public:
virtual ~Image() = default;
@ -73,23 +16,29 @@ public:
class Gradient {
public:
Gradient(std::vector<Color> const &colors, std::vector<double> const &locations) :
Gradient(std::vector<lottie::Color> const &colors, std::vector<float> const &locations) :
_colors(colors),
_locations(locations) {
assert(_colors.size() == _locations.size());
}
std::vector<Color> const &colors() const {
std::vector<lottie::Color> const &colors() const {
return _colors;
}
std::vector<double> const &locations() const {
std::vector<float> const &locations() const {
return _locations;
}
private:
std::vector<Color> _colors;
std::vector<double> _locations;
std::vector<lottie::Color> _colors;
std::vector<float> _locations;
};
enum class BlendMode {
Normal,
DestinationIn,
DestinationOut
};
class Canvas {
@ -104,18 +53,18 @@ public:
virtual void saveState() = 0;
virtual void restoreState() = 0;
virtual void fillPath(std::shared_ptr<lottie::CGPath> const &path, FillRule fillRule, Color const &color) = 0;
virtual void linearGradientFillPath(std::shared_ptr<lottie::CGPath> const &path, FillRule fillRule, Gradient const &gradient, lottie::Vector2D const &start, lottie::Vector2D const &end) = 0;
virtual void radialGradientFillPath(std::shared_ptr<lottie::CGPath> const &path, FillRule fillRule, Gradient const &gradient, lottie::Vector2D const &startCenter, double startRadius, lottie::Vector2D const &endCenter, double endRadius) = 0;
virtual void fillPath(std::shared_ptr<lottie::CGPath> const &path, lottie::FillRule fillRule, lottie::Color const &color) = 0;
virtual void linearGradientFillPath(std::shared_ptr<lottie::CGPath> const &path, lottie::FillRule fillRule, Gradient const &gradient, lottie::Vector2D const &start, lottie::Vector2D const &end) = 0;
virtual void radialGradientFillPath(std::shared_ptr<lottie::CGPath> const &path, lottie::FillRule fillRule, Gradient const &gradient, lottie::Vector2D const &startCenter, float startRadius, lottie::Vector2D const &endCenter, float endRadius) = 0;
virtual void strokePath(std::shared_ptr<lottie::CGPath> const &path, double lineWidth, LineJoin lineJoin, LineCap lineCap, double dashPhase, std::vector<double> const &dashPattern, Color const &color) = 0;
virtual void linearGradientStrokePath(std::shared_ptr<lottie::CGPath> const &path, double lineWidth, LineJoin lineJoin, LineCap lineCap, double dashPhase, std::vector<double> const &dashPattern, Gradient const &gradient, lottie::Vector2D const &start, lottie::Vector2D const &end) = 0;
virtual void radialGradientStrokePath(std::shared_ptr<lottie::CGPath> const &path, double lineWidth, LineJoin lineJoin, LineCap lineCap, double dashPhase, std::vector<double> const &dashPattern, Gradient const &gradient, lottie::Vector2D const &startCenter, double startRadius, lottie::Vector2D const &endCenter, double endRadius) = 0;
virtual void strokePath(std::shared_ptr<lottie::CGPath> const &path, float lineWidth, lottie::LineJoin lineJoin, lottie::LineCap lineCap, float dashPhase, std::vector<float> const &dashPattern, lottie::Color const &color) = 0;
virtual void linearGradientStrokePath(std::shared_ptr<lottie::CGPath> const &path, float lineWidth, lottie::LineJoin lineJoin, lottie::LineCap lineCap, float dashPhase, std::vector<float> const &dashPattern, Gradient const &gradient, lottie::Vector2D const &start, lottie::Vector2D const &end) = 0;
virtual void radialGradientStrokePath(std::shared_ptr<lottie::CGPath> const &path, float lineWidth, lottie::LineJoin lineJoin, lottie::LineCap lineCap, float dashPhase, std::vector<float> const &dashPattern, Gradient const &gradient, lottie::Vector2D const &startCenter, float startRadius, lottie::Vector2D const &endCenter, float endRadius) = 0;
virtual void fill(lottie::CGRect const &rect, Color const &fillColor) = 0;
virtual void fill(lottie::CGRect const &rect, lottie::Color const &fillColor) = 0;
virtual void setBlendMode(BlendMode blendMode) = 0;
virtual void setAlpha(double alpha) = 0;
virtual void setAlpha(float alpha) = 0;
virtual void concatenate(lottie::CATransform3D const &transform) = 0;

View File

@ -29,17 +29,17 @@ public:
virtual void saveState() override;
virtual void restoreState() override;
virtual void fillPath(std::shared_ptr<lottie::CGPath> const &path, FillRule fillRule, Color const &color) override;
virtual void linearGradientFillPath(std::shared_ptr<lottie::CGPath> const &path, FillRule fillRule, Gradient const &gradient, lottie::Vector2D const &start, lottie::Vector2D const &end) override;
virtual void radialGradientFillPath(std::shared_ptr<lottie::CGPath> const &path, FillRule fillRule, Gradient const &gradient, lottie::Vector2D const &startCenter, double startRadius, lottie::Vector2D const &endCenter, double endRadius) override;
virtual void fillPath(std::shared_ptr<lottie::CGPath> const &path, lottie::FillRule fillRule, lottie::Color const &color) override;
virtual void linearGradientFillPath(std::shared_ptr<lottie::CGPath> const &path, lottie::FillRule fillRule, Gradient const &gradient, lottie::Vector2D const &start, lottie::Vector2D const &end) override;
virtual void radialGradientFillPath(std::shared_ptr<lottie::CGPath> const &path, lottie::FillRule fillRule, Gradient const &gradient, lottie::Vector2D const &startCenter, float startRadius, lottie::Vector2D const &endCenter, float endRadius) override;
virtual void strokePath(std::shared_ptr<lottie::CGPath> const &path, double lineWidth, LineJoin lineJoin, LineCap lineCap, double dashPhase, std::vector<double> const &dashPattern, Color const &color) override;
virtual void linearGradientStrokePath(std::shared_ptr<lottie::CGPath> const &path, double lineWidth, LineJoin lineJoin, LineCap lineCap, double dashPhase, std::vector<double> const &dashPattern, Gradient const &gradient, lottie::Vector2D const &start, lottie::Vector2D const &end) override;
virtual void radialGradientStrokePath(std::shared_ptr<lottie::CGPath> const &path, double lineWidth, LineJoin lineJoin, LineCap lineCap, double dashPhase, std::vector<double> const &dashPattern, Gradient const &gradient, lottie::Vector2D const &startCenter, double startRadius, lottie::Vector2D const &endCenter, double endRadius) override;
virtual void strokePath(std::shared_ptr<lottie::CGPath> const &path, float lineWidth, lottie::LineJoin lineJoin, lottie::LineCap lineCap, float dashPhase, std::vector<float> const &dashPattern, lottie::Color const &color) override;
virtual void linearGradientStrokePath(std::shared_ptr<lottie::CGPath> const &path, float lineWidth, lottie::LineJoin lineJoin, lottie::LineCap lineCap, float dashPhase, std::vector<float> const &dashPattern, Gradient const &gradient, lottie::Vector2D const &start, lottie::Vector2D const &end) override;
virtual void radialGradientStrokePath(std::shared_ptr<lottie::CGPath> const &path, float lineWidth, lottie::LineJoin lineJoin, lottie::LineCap lineCap, float dashPhase, std::vector<float> const &dashPattern, Gradient const &gradient, lottie::Vector2D const &startCenter, float startRadius, lottie::Vector2D const &endCenter, float endRadius) override;
virtual void fill(lottie::CGRect const &rect, Color const &fillColor) override;
virtual void fill(lottie::CGRect const &rect, lottie::Color const &fillColor) override;
virtual void setBlendMode(BlendMode blendMode) override;
virtual void setAlpha(double alpha) override;
virtual void setAlpha(float alpha) override;
virtual void concatenate(lottie::CATransform3D const &transform) override;
virtual std::shared_ptr<Image> makeImage() const;

View File

@ -1,7 +1,5 @@
#include "CoreGraphicsCanvasImpl.h"
namespace lottieRendering {
namespace {
@ -89,7 +87,7 @@ void CanvasImpl::restoreState() {
CGContextRestoreGState(_context);
}
void CanvasImpl::fillPath(std::shared_ptr<lottie::CGPath> const &path, FillRule fillRule, Color const &color) {
void CanvasImpl::fillPath(std::shared_ptr<lottie::CGPath> const &path, lottie::FillRule fillRule, lottie::Color const &color) {
CGContextBeginPath(_context);
lottie::CGPathCocoaImpl::withNativePath(path, [context = _context](CGPathRef nativePath) {
CGContextAddPath(context, nativePath);
@ -101,7 +99,7 @@ void CanvasImpl::fillPath(std::shared_ptr<lottie::CGPath> const &path, FillRule
CFRelease(nativeColor);
switch (fillRule) {
case FillRule::EvenOdd: {
case lottie::FillRule::EvenOdd: {
CGContextEOFillPath(_context);
break;
}
@ -112,7 +110,7 @@ void CanvasImpl::fillPath(std::shared_ptr<lottie::CGPath> const &path, FillRule
}
}
void CanvasImpl::linearGradientFillPath(std::shared_ptr<lottie::CGPath> const &path, FillRule fillRule, Gradient const &gradient, lottie::Vector2D const &start, lottie::Vector2D const &end) {
void CanvasImpl::linearGradientFillPath(std::shared_ptr<lottie::CGPath> const &path, lottie::FillRule fillRule, Gradient const &gradient, lottie::Vector2D const &start, lottie::Vector2D const &end) {
CGContextSaveGState(_context);
CGContextBeginPath(_context);
lottie::CGPathCocoaImpl::withNativePath(path, [context = _context](CGPathRef nativePath) {
@ -120,7 +118,7 @@ void CanvasImpl::linearGradientFillPath(std::shared_ptr<lottie::CGPath> const &p
});
switch (fillRule) {
case FillRule::EvenOdd: {
case lottie::FillRule::EvenOdd: {
CGContextEOClip(_context);
break;
}
@ -142,7 +140,12 @@ void CanvasImpl::linearGradientFillPath(std::shared_ptr<lottie::CGPath> const &p
assert(gradient.colors().size() == gradient.locations().size());
CGGradientRef nativeGradient = CGGradientCreateWithColorComponents(CGBitmapContextGetColorSpace(_topContext), components.data(), gradient.locations().data(), gradient.locations().size());
std::vector<double> locations;
for (const auto location : gradient.locations()) {
locations.push_back(location);
}
CGGradientRef nativeGradient = CGGradientCreateWithColorComponents(CGBitmapContextGetColorSpace(_topContext), components.data(), locations.data(), locations.size());
if (nativeGradient) {
CGContextDrawLinearGradient(_context, nativeGradient, CGPointMake(start.x, start.y), CGPointMake(end.x, end.y), kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
CFRelease(nativeGradient);
@ -152,7 +155,7 @@ void CanvasImpl::linearGradientFillPath(std::shared_ptr<lottie::CGPath> const &p
CGContextRestoreGState(_context);
}
void CanvasImpl::radialGradientFillPath(std::shared_ptr<lottie::CGPath> const &path, FillRule fillRule, Gradient const &gradient, lottie::Vector2D const &startCenter, double startRadius, lottie::Vector2D const &endCenter, double endRadius) {
void CanvasImpl::radialGradientFillPath(std::shared_ptr<lottie::CGPath> const &path, lottie::FillRule fillRule, Gradient const &gradient, lottie::Vector2D const &startCenter, float startRadius, lottie::Vector2D const &endCenter, float endRadius) {
CGContextSaveGState(_context);
CGContextBeginPath(_context);
lottie::CGPathCocoaImpl::withNativePath(path, [context = _context](CGPathRef nativePath) {
@ -160,7 +163,7 @@ void CanvasImpl::radialGradientFillPath(std::shared_ptr<lottie::CGPath> const &p
});
switch (fillRule) {
case FillRule::EvenOdd: {
case lottie::FillRule::EvenOdd: {
CGContextEOClip(_context);
break;
}
@ -182,7 +185,12 @@ void CanvasImpl::radialGradientFillPath(std::shared_ptr<lottie::CGPath> const &p
assert(gradient.colors().size() == gradient.locations().size());
CGGradientRef nativeGradient = CGGradientCreateWithColorComponents(CGBitmapContextGetColorSpace(_topContext), components.data(), gradient.locations().data(), gradient.locations().size());
std::vector<double> locations;
for (const auto location : gradient.locations()) {
locations.push_back(location);
}
CGGradientRef nativeGradient = CGGradientCreateWithColorComponents(CGBitmapContextGetColorSpace(_topContext), components.data(), locations.data(), locations.size());
if (nativeGradient) {
CGContextDrawRadialGradient(_context, nativeGradient, CGPointMake(startCenter.x, startCenter.y), startRadius, CGPointMake(endCenter.x, endCenter.y), endRadius, kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
CFRelease(nativeGradient);
@ -192,7 +200,7 @@ void CanvasImpl::radialGradientFillPath(std::shared_ptr<lottie::CGPath> const &p
CGContextRestoreGState(_context);
}
void CanvasImpl::strokePath(std::shared_ptr<lottie::CGPath> const &path, double lineWidth, LineJoin lineJoin, LineCap lineCap, double dashPhase, std::vector<double> const &dashPattern, Color const &color) {
void CanvasImpl::strokePath(std::shared_ptr<lottie::CGPath> const &path, float lineWidth, lottie::LineJoin lineJoin, lottie::LineCap lineCap, float dashPhase, std::vector<float> const &dashPattern, lottie::Color const &color) {
CGContextBeginPath(_context);
lottie::CGPathCocoaImpl::withNativePath(path, [context = _context](CGPathRef nativePath) {
CGContextAddPath(context, nativePath);
@ -206,15 +214,15 @@ void CanvasImpl::strokePath(std::shared_ptr<lottie::CGPath> const &path, double
CGContextSetLineWidth(_context, lineWidth);
switch (lineJoin) {
case LineJoin::Miter: {
case lottie::LineJoin::Miter: {
CGContextSetLineJoin(_context, kCGLineJoinMiter);
break;
}
case LineJoin::Round: {
case lottie::LineJoin::Round: {
CGContextSetLineJoin(_context, kCGLineJoinRound);
break;
}
case LineJoin::Bevel: {
case lottie::LineJoin::Bevel: {
CGContextSetLineJoin(_context, kCGLineJoinBevel);
break;
}
@ -225,15 +233,15 @@ void CanvasImpl::strokePath(std::shared_ptr<lottie::CGPath> const &path, double
}
switch (lineCap) {
case LineCap::Butt: {
case lottie::LineCap::Butt: {
CGContextSetLineCap(_context, kCGLineCapButt);
break;
}
case LineCap::Round: {
case lottie::LineCap::Round: {
CGContextSetLineCap(_context, kCGLineCapRound);
break;
}
case LineCap::Square: {
case lottie::LineCap::Square: {
CGContextSetLineCap(_context, kCGLineCapSquare);
break;
}
@ -244,12 +252,16 @@ void CanvasImpl::strokePath(std::shared_ptr<lottie::CGPath> const &path, double
}
if (!dashPattern.empty()) {
CGContextSetLineDash(_context, dashPhase, dashPattern.data(), dashPattern.size());
std::vector<double> mappedDashPattern;
for (const auto value : dashPattern) {
mappedDashPattern.push_back(value);
}
CGContextSetLineDash(_context, dashPhase, mappedDashPattern.data(), mappedDashPattern.size());
}
CGContextStrokePath(_context);
}
void CanvasImpl::linearGradientStrokePath(std::shared_ptr<lottie::CGPath> const &path, double lineWidth, LineJoin lineJoin, LineCap lineCap, double dashPhase, std::vector<double> const &dashPattern, Gradient const &gradient, lottie::Vector2D const &start, lottie::Vector2D const &end) {
void CanvasImpl::linearGradientStrokePath(std::shared_ptr<lottie::CGPath> const &path, float lineWidth, lottie::LineJoin lineJoin, lottie::LineCap lineCap, float dashPhase, std::vector<float> const &dashPattern, Gradient const &gradient, lottie::Vector2D const &start, lottie::Vector2D const &end) {
CGContextSaveGState(_context);
CGContextBeginPath(_context);
lottie::CGPathCocoaImpl::withNativePath(path, [context = _context](CGPathRef nativePath) {
@ -259,15 +271,15 @@ void CanvasImpl::linearGradientStrokePath(std::shared_ptr<lottie::CGPath> const
CGContextSetLineWidth(_context, lineWidth);
switch (lineJoin) {
case LineJoin::Miter: {
case lottie::LineJoin::Miter: {
CGContextSetLineJoin(_context, kCGLineJoinMiter);
break;
}
case LineJoin::Round: {
case lottie::LineJoin::Round: {
CGContextSetLineJoin(_context, kCGLineJoinRound);
break;
}
case LineJoin::Bevel: {
case lottie::LineJoin::Bevel: {
CGContextSetLineJoin(_context, kCGLineJoinBevel);
break;
}
@ -278,15 +290,15 @@ void CanvasImpl::linearGradientStrokePath(std::shared_ptr<lottie::CGPath> const
}
switch (lineCap) {
case LineCap::Butt: {
case lottie::LineCap::Butt: {
CGContextSetLineCap(_context, kCGLineCapButt);
break;
}
case LineCap::Round: {
case lottie::LineCap::Round: {
CGContextSetLineCap(_context, kCGLineCapRound);
break;
}
case LineCap::Square: {
case lottie::LineCap::Square: {
CGContextSetLineCap(_context, kCGLineCapSquare);
break;
}
@ -297,7 +309,11 @@ void CanvasImpl::linearGradientStrokePath(std::shared_ptr<lottie::CGPath> const
}
if (!dashPattern.empty()) {
CGContextSetLineDash(_context, dashPhase, dashPattern.data(), dashPattern.size());
std::vector<double> mappedDashPattern;
for (const auto value : dashPattern) {
mappedDashPattern.push_back(value);
}
CGContextSetLineDash(_context, dashPhase, mappedDashPattern.data(), mappedDashPattern.size());
}
CGContextReplacePathWithStrokedPath(_context);
@ -315,7 +331,12 @@ void CanvasImpl::linearGradientStrokePath(std::shared_ptr<lottie::CGPath> const
assert(gradient.colors().size() == gradient.locations().size());
CGGradientRef nativeGradient = CGGradientCreateWithColorComponents(CGBitmapContextGetColorSpace(_topContext), components.data(), gradient.locations().data(), gradient.locations().size());
std::vector<double> locations;
for (const auto location : gradient.locations()) {
locations.push_back(location);
}
CGGradientRef nativeGradient = CGGradientCreateWithColorComponents(CGBitmapContextGetColorSpace(_topContext), components.data(), locations.data(), locations.size());
if (nativeGradient) {
CGContextDrawLinearGradient(_context, nativeGradient, CGPointMake(start.x, start.y), CGPointMake(end.x, end.y), kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
CFRelease(nativeGradient);
@ -325,7 +346,7 @@ void CanvasImpl::linearGradientStrokePath(std::shared_ptr<lottie::CGPath> const
CGContextRestoreGState(_context);
}
void CanvasImpl::radialGradientStrokePath(std::shared_ptr<lottie::CGPath> const &path, double lineWidth, LineJoin lineJoin, LineCap lineCap, double dashPhase, std::vector<double> const &dashPattern, Gradient const &gradient, lottie::Vector2D const &startCenter, double startRadius, lottie::Vector2D const &endCenter, double endRadius) {
void CanvasImpl::radialGradientStrokePath(std::shared_ptr<lottie::CGPath> const &path, float lineWidth, lottie::LineJoin lineJoin, lottie::LineCap lineCap, float dashPhase, std::vector<float> const &dashPattern, Gradient const &gradient, lottie::Vector2D const &startCenter, float startRadius, lottie::Vector2D const &endCenter, float endRadius) {
CGContextSaveGState(_context);
CGContextBeginPath(_context);
lottie::CGPathCocoaImpl::withNativePath(path, [context = _context](CGPathRef nativePath) {
@ -335,15 +356,15 @@ void CanvasImpl::radialGradientStrokePath(std::shared_ptr<lottie::CGPath> const
CGContextSetLineWidth(_context, lineWidth);
switch (lineJoin) {
case LineJoin::Miter: {
case lottie::LineJoin::Miter: {
CGContextSetLineJoin(_context, kCGLineJoinMiter);
break;
}
case LineJoin::Round: {
case lottie::LineJoin::Round: {
CGContextSetLineJoin(_context, kCGLineJoinRound);
break;
}
case LineJoin::Bevel: {
case lottie::LineJoin::Bevel: {
CGContextSetLineJoin(_context, kCGLineJoinBevel);
break;
}
@ -354,15 +375,15 @@ void CanvasImpl::radialGradientStrokePath(std::shared_ptr<lottie::CGPath> const
}
switch (lineCap) {
case LineCap::Butt: {
case lottie::LineCap::Butt: {
CGContextSetLineCap(_context, kCGLineCapButt);
break;
}
case LineCap::Round: {
case lottie::LineCap::Round: {
CGContextSetLineCap(_context, kCGLineCapRound);
break;
}
case LineCap::Square: {
case lottie::LineCap::Square: {
CGContextSetLineCap(_context, kCGLineCapSquare);
break;
}
@ -373,7 +394,11 @@ void CanvasImpl::radialGradientStrokePath(std::shared_ptr<lottie::CGPath> const
}
if (!dashPattern.empty()) {
CGContextSetLineDash(_context, dashPhase, dashPattern.data(), dashPattern.size());
std::vector<double> mappedDashPattern;
for (const auto value : dashPattern) {
mappedDashPattern.push_back(value);
}
CGContextSetLineDash(_context, dashPhase, mappedDashPattern.data(), mappedDashPattern.size());
}
CGContextReplacePathWithStrokedPath(_context);
@ -391,7 +416,12 @@ void CanvasImpl::radialGradientStrokePath(std::shared_ptr<lottie::CGPath> const
assert(gradient.colors().size() == gradient.locations().size());
CGGradientRef nativeGradient = CGGradientCreateWithColorComponents(CGBitmapContextGetColorSpace(_topContext), components.data(), gradient.locations().data(), gradient.locations().size());
std::vector<double> locations;
for (const auto location : gradient.locations()) {
locations.push_back(location);
}
CGGradientRef nativeGradient = CGGradientCreateWithColorComponents(CGBitmapContextGetColorSpace(_topContext), components.data(), locations.data(), locations.size());
if (nativeGradient) {
CGContextDrawRadialGradient(_context, nativeGradient, CGPointMake(startCenter.x, startCenter.y), startRadius, CGPointMake(endCenter.x, endCenter.y), endRadius, kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
CFRelease(nativeGradient);
@ -401,7 +431,7 @@ void CanvasImpl::radialGradientStrokePath(std::shared_ptr<lottie::CGPath> const
CGContextRestoreGState(_context);
}
void CanvasImpl::fill(lottie::CGRect const &rect, Color const &fillColor) {
void CanvasImpl::fill(lottie::CGRect const &rect, lottie::Color const &fillColor) {
CGFloat components[4] = { fillColor.r, fillColor.g, fillColor.b, fillColor.a };
CGColorRef nativeColor = CGColorCreate(CGBitmapContextGetColorSpace(_topContext), components);
CGContextSetFillColorWithColor(_context, nativeColor);
@ -429,7 +459,7 @@ void CanvasImpl::setBlendMode(BlendMode blendMode) {
CGContextSetBlendMode(_context, nativeMode);
}
void CanvasImpl::setAlpha(double alpha) {
void CanvasImpl::setAlpha(float alpha) {
CGContextSetAlpha(_context, alpha);
}

View File

@ -411,18 +411,18 @@ static void drawLottieContentItem(std::shared_ptr<lottieRendering::Canvas> paren
lottie::RenderTreeNodeContentItem::SolidShading *solidShading = (lottie::RenderTreeNodeContentItem::SolidShading *)shading->stroke->shading.get();
if (solidShading->opacity != 0.0) {
lottieRendering::LineJoin lineJoin = lottieRendering::LineJoin::Bevel;
lottie::LineJoin lineJoin = lottie::LineJoin::Bevel;
switch (shading->stroke->lineJoin) {
case lottie::LineJoin::Bevel: {
lineJoin = lottieRendering::LineJoin::Bevel;
lineJoin = lottie::LineJoin::Bevel;
break;
}
case lottie::LineJoin::Round: {
lineJoin = lottieRendering::LineJoin::Round;
lineJoin = lottie::LineJoin::Round;
break;
}
case lottie::LineJoin::Miter: {
lineJoin = lottieRendering::LineJoin::Miter;
lineJoin = lottie::LineJoin::Miter;
break;
}
default: {
@ -430,18 +430,18 @@ static void drawLottieContentItem(std::shared_ptr<lottieRendering::Canvas> paren
}
}
lottieRendering::LineCap lineCap = lottieRendering::LineCap::Square;
lottie::LineCap lineCap = lottie::LineCap::Square;
switch (shading->stroke->lineCap) {
case lottie::LineCap::Butt: {
lineCap = lottieRendering::LineCap::Butt;
lineCap = lottie::LineCap::Butt;
break;
}
case lottie::LineCap::Round: {
lineCap = lottieRendering::LineCap::Round;
lineCap = lottie::LineCap::Round;
break;
}
case lottie::LineCap::Square: {
lineCap = lottieRendering::LineCap::Square;
lineCap = lottie::LineCap::Square;
break;
}
default: {
@ -449,25 +449,25 @@ static void drawLottieContentItem(std::shared_ptr<lottieRendering::Canvas> paren
}
}
std::vector<double> dashPattern;
std::vector<float> dashPattern;
if (!shading->stroke->dashPattern.empty()) {
dashPattern = shading->stroke->dashPattern;
}
currentContext->strokePath(path, shading->stroke->lineWidth, lineJoin, lineCap, shading->stroke->dashPhase, dashPattern, lottieRendering::Color(solidShading->color.r, solidShading->color.g, solidShading->color.b, solidShading->color.a * solidShading->opacity * renderAlpha));
currentContext->strokePath(path, shading->stroke->lineWidth, lineJoin, lineCap, shading->stroke->dashPhase, dashPattern, lottie::Color(solidShading->color.r, solidShading->color.g, solidShading->color.b, solidShading->color.a * solidShading->opacity * renderAlpha));
} else if (shading->stroke->shading->type() == lottie::RenderTreeNodeContentItem::ShadingType::Gradient) {
//TODO:gradient stroke
}
}
} else if (shading->fill) {
lottieRendering::FillRule rule = lottieRendering::FillRule::NonZeroWinding;
lottie::FillRule rule = lottie::FillRule::NonZeroWinding;
switch (shading->fill->rule) {
case lottie::FillRule::EvenOdd: {
rule = lottieRendering::FillRule::EvenOdd;
rule = lottie::FillRule::EvenOdd;
break;
}
case lottie::FillRule::NonZeroWinding: {
rule = lottieRendering::FillRule::NonZeroWinding;
rule = lottie::FillRule::NonZeroWinding;
break;
}
default: {
@ -478,16 +478,16 @@ static void drawLottieContentItem(std::shared_ptr<lottieRendering::Canvas> paren
if (shading->fill->shading->type() == lottie::RenderTreeNodeContentItem::ShadingType::Solid) {
lottie::RenderTreeNodeContentItem::SolidShading *solidShading = (lottie::RenderTreeNodeContentItem::SolidShading *)shading->fill->shading.get();
if (solidShading->opacity != 0.0) {
currentContext->fillPath(path, rule, lottieRendering::Color(solidShading->color.r, solidShading->color.g, solidShading->color.b, solidShading->color.a * solidShading->opacity * renderAlpha));
currentContext->fillPath(path, rule, lottie::Color(solidShading->color.r, solidShading->color.g, solidShading->color.b, solidShading->color.a * solidShading->opacity * renderAlpha));
}
} else if (shading->fill->shading->type() == lottie::RenderTreeNodeContentItem::ShadingType::Gradient) {
lottie::RenderTreeNodeContentItem::GradientShading *gradientShading = (lottie::RenderTreeNodeContentItem::GradientShading *)shading->fill->shading.get();
if (gradientShading->opacity != 0.0) {
std::vector<lottieRendering::Color> colors;
std::vector<double> locations;
std::vector<lottie::Color> colors;
std::vector<float> locations;
for (const auto &color : gradientShading->colors) {
colors.push_back(lottieRendering::Color(color.r, color.g, color.b, color.a * gradientShading->opacity * renderAlpha));
colors.push_back(lottie::Color(color.r, color.g, color.b, color.a * gradientShading->opacity * renderAlpha));
}
locations = gradientShading->locations;
@ -562,7 +562,7 @@ static void renderLottieRenderNode(std::shared_ptr<lottie::RenderTreeNode> node,
maskBackingStorage->concatenate(node->renderData.globalTransform);
if (node->renderData.layer.masksToBounds()) {
maskBackingStorage->fill(lottie::CGRect(node->renderData.layer.bounds().x, node->renderData.layer.bounds().y, node->renderData.layer.bounds().width, node->renderData.layer.bounds().height), lottieRendering::Color(1.0, 1.0, 1.0, 1.0));
maskBackingStorage->fill(lottie::CGRect(node->renderData.layer.bounds().x, node->renderData.layer.bounds().y, node->renderData.layer.bounds().width, node->renderData.layer.bounds().height), lottie::Color(1.0, 1.0, 1.0, 1.0));
}
if (node->mask() && node->mask()->renderData.isValid) {
renderLottieRenderNode(node->mask(), maskBackingStorage, globalSize, 1.0);
@ -599,7 +599,7 @@ static void renderLottieRenderNode(std::shared_ptr<lottie::RenderTreeNode> node,
}
if (node->renderData.isInvertedMatte) {
currentContext->fill(lottie::CGRect(node->renderData.layer.bounds().x, node->renderData.layer.bounds().y, node->renderData.layer.bounds().width, node->renderData.layer.bounds().height), lottieRendering::Color(0.0, 0.0, 0.0, 1.0));
currentContext->fill(lottie::CGRect(node->renderData.layer.bounds().x, node->renderData.layer.bounds().y, node->renderData.layer.bounds().width, node->renderData.layer.bounds().height), lottie::Color(0.0, 0.0, 0.0, 1.0));
currentContext->setBlendMode(lottieRendering::BlendMode::DestinationOut);
}

View File

@ -20,17 +20,17 @@ public:
virtual void saveState() override;
virtual void restoreState() override;
virtual void fillPath(std::shared_ptr<lottie::CGPath> const &path, FillRule fillRule, Color const &color) override;
virtual void linearGradientFillPath(std::shared_ptr<lottie::CGPath> const &path, FillRule fillRule, lottieRendering::Gradient const &gradient, lottie::Vector2D const &start, lottie::Vector2D const &end) override;
virtual void radialGradientFillPath(std::shared_ptr<lottie::CGPath> const &path, FillRule fillRule, lottieRendering::Gradient const &gradient, lottie::Vector2D const &startCenter, double startRadius, lottie::Vector2D const &endCenter, double endRadius) override;
virtual void strokePath(std::shared_ptr<lottie::CGPath> const &path, double lineWidth, LineJoin lineJoin, LineCap lineCap, double dashPhase, std::vector<double> const &dashPattern, Color const &color) override;
virtual void linearGradientStrokePath(std::shared_ptr<lottie::CGPath> const &path, double lineWidth, LineJoin lineJoin, LineCap lineCap, double dashPhase, std::vector<double> const &dashPattern, Gradient const &gradient, lottie::Vector2D const &start, lottie::Vector2D const &end) override;
virtual void radialGradientStrokePath(std::shared_ptr<lottie::CGPath> const &path, double lineWidth, LineJoin lineJoin, LineCap lineCap, double dashPhase, std::vector<double> const &dashPattern, Gradient const &gradient, lottie::Vector2D const &startCenter, double startRadius, lottie::Vector2D const &endCenter, double endRadius) override;
virtual void fill(lottie::CGRect const &rect, Color const &fillColor) override;
virtual void fillPath(std::shared_ptr<lottie::CGPath> const &path, lottie::FillRule fillRule, lottie::Color const &color) override;
virtual void linearGradientFillPath(std::shared_ptr<lottie::CGPath> const &path, lottie::FillRule fillRule, lottieRendering::Gradient const &gradient, lottie::Vector2D const &start, lottie::Vector2D const &end) override;
virtual void radialGradientFillPath(std::shared_ptr<lottie::CGPath> const &path, lottie::FillRule fillRule, lottieRendering::Gradient const &gradient, lottie::Vector2D const &startCenter, float startRadius, lottie::Vector2D const &endCenter, float endRadius) override;
virtual void strokePath(std::shared_ptr<lottie::CGPath> const &path, float lineWidth, lottie::LineJoin lineJoin, lottie::LineCap lineCap, float dashPhase, std::vector<float> const &dashPattern, lottie::Color const &color) override;
virtual void linearGradientStrokePath(std::shared_ptr<lottie::CGPath> const &path, float lineWidth, lottie::LineJoin lineJoin, lottie::LineCap lineCap, float dashPhase, std::vector<float> const &dashPattern, Gradient const &gradient, lottie::Vector2D const &start, lottie::Vector2D const &end) override;
virtual void radialGradientStrokePath(std::shared_ptr<lottie::CGPath> const &path, float lineWidth, lottie::LineJoin lineJoin, lottie::LineCap lineCap, float dashPhase, std::vector<float> const &dashPattern, Gradient const &gradient, lottie::Vector2D const &startCenter, float startRadius, lottie::Vector2D const &endCenter, float endRadius) override;
virtual void fill(lottie::CGRect const &rect, lottie::Color const &fillColor) override;
virtual void setBlendMode(BlendMode blendMode) override;
virtual void setAlpha(double alpha) override;
virtual void setAlpha(float alpha) override;
virtual void concatenate(lottie::CATransform3D const &transform) override;
@ -51,8 +51,7 @@ private:
int _height = 0;
std::unique_ptr<tvg::SwCanvas> _canvas;
//SkBlendMode _blendMode = SkBlendMode::kSrcOver;
double _alpha = 1.0;
float _alpha = 1.0;
lottie::CATransform3D _transform;
std::vector<lottie::CATransform3D> _stateStack;
int _bytesPerRow = 0;

View File

@ -89,19 +89,19 @@ void ThorVGCanvasImpl::restoreState() {
_stateStack.pop_back();
}
void ThorVGCanvasImpl::fillPath(std::shared_ptr<lottie::CGPath> const &path, FillRule fillRule, Color const &color) {
void ThorVGCanvasImpl::fillPath(std::shared_ptr<lottie::CGPath> const &path, lottie::FillRule fillRule, lottie::Color const &color) {
auto shape = tvg::Shape::gen();
tvgPath(path, shape.get());
shape->transform(tvgTransform(_transform));
shape->fill((int)(color.r * 255.0), (int)(color.g * 255.0), (int)(color.b * 255.0), (int)(color.a * _alpha * 255.0));
shape->fill(fillRule == FillRule::EvenOdd ? tvg::FillRule::EvenOdd : tvg::FillRule::Winding);
shape->fill(fillRule == lottie::FillRule::EvenOdd ? tvg::FillRule::EvenOdd : tvg::FillRule::Winding);
_canvas->push(std::move(shape));
}
void ThorVGCanvasImpl::linearGradientFillPath(std::shared_ptr<lottie::CGPath> const &path, FillRule fillRule, Gradient const &gradient, lottie::Vector2D const &start, lottie::Vector2D const &end) {
void ThorVGCanvasImpl::linearGradientFillPath(std::shared_ptr<lottie::CGPath> const &path, lottie::FillRule fillRule, Gradient const &gradient, lottie::Vector2D const &start, lottie::Vector2D const &end) {
auto shape = tvg::Shape::gen();
tvgPath(path, shape.get());
@ -124,12 +124,12 @@ void ThorVGCanvasImpl::linearGradientFillPath(std::shared_ptr<lottie::CGPath> co
fill->colorStops(colors.data(), (uint32_t)colors.size());
shape->fill(std::move(fill));
shape->fill(fillRule == FillRule::EvenOdd ? tvg::FillRule::EvenOdd : tvg::FillRule::Winding);
shape->fill(fillRule == lottie::FillRule::EvenOdd ? tvg::FillRule::EvenOdd : tvg::FillRule::Winding);
_canvas->push(std::move(shape));
}
void ThorVGCanvasImpl::radialGradientFillPath(std::shared_ptr<lottie::CGPath> const &path, FillRule fillRule, Gradient const &gradient, lottie::Vector2D const &startCenter, double startRadius, lottie::Vector2D const &endCenter, double endRadius) {
void ThorVGCanvasImpl::radialGradientFillPath(std::shared_ptr<lottie::CGPath> const &path, lottie::FillRule fillRule, Gradient const &gradient, lottie::Vector2D const &startCenter, float startRadius, lottie::Vector2D const &endCenter, float endRadius) {
auto shape = tvg::Shape::gen();
tvgPath(path, shape.get());
@ -152,12 +152,12 @@ void ThorVGCanvasImpl::radialGradientFillPath(std::shared_ptr<lottie::CGPath> co
fill->colorStops(colors.data(), (uint32_t)colors.size());
shape->fill(std::move(fill));
shape->fill(fillRule == FillRule::EvenOdd ? tvg::FillRule::EvenOdd : tvg::FillRule::Winding);
shape->fill(fillRule == lottie::FillRule::EvenOdd ? tvg::FillRule::EvenOdd : tvg::FillRule::Winding);
_canvas->push(std::move(shape));
}
void ThorVGCanvasImpl::strokePath(std::shared_ptr<lottie::CGPath> const &path, double lineWidth, LineJoin lineJoin, LineCap lineCap, double dashPhase, std::vector<double> const &dashPattern, Color const &color) {
void ThorVGCanvasImpl::strokePath(std::shared_ptr<lottie::CGPath> const &path, float lineWidth, lottie::LineJoin lineJoin, lottie::LineCap lineCap, float dashPhase, std::vector<float> const &dashPattern, lottie::Color const &color) {
auto shape = tvg::Shape::gen();
tvgPath(path, shape.get());
@ -167,15 +167,15 @@ void ThorVGCanvasImpl::strokePath(std::shared_ptr<lottie::CGPath> const &path, d
shape->strokeWidth(lineWidth);
switch (lineJoin) {
case LineJoin::Miter: {
case lottie::LineJoin::Miter: {
shape->strokeJoin(tvg::StrokeJoin::Miter);
break;
}
case LineJoin::Round: {
case lottie::LineJoin::Round: {
shape->strokeJoin(tvg::StrokeJoin::Round);
break;
}
case LineJoin::Bevel: {
case lottie::LineJoin::Bevel: {
shape->strokeJoin(tvg::StrokeJoin::Bevel);
break;
}
@ -186,15 +186,15 @@ void ThorVGCanvasImpl::strokePath(std::shared_ptr<lottie::CGPath> const &path, d
}
switch (lineCap) {
case LineCap::Butt: {
case lottie::LineCap::Butt: {
shape->strokeCap(tvg::StrokeCap::Butt);
break;
}
case LineCap::Round: {
case lottie::LineCap::Round: {
shape->strokeCap(tvg::StrokeCap::Round);
break;
}
case LineCap::Square: {
case lottie::LineCap::Square: {
shape->strokeCap(tvg::StrokeCap::Square);
break;
}
@ -217,15 +217,15 @@ void ThorVGCanvasImpl::strokePath(std::shared_ptr<lottie::CGPath> const &path, d
_canvas->push(std::move(shape));
}
void ThorVGCanvasImpl::linearGradientStrokePath(std::shared_ptr<lottie::CGPath> const &path, double lineWidth, LineJoin lineJoin, LineCap lineCap, double dashPhase, std::vector<double> const &dashPattern, Gradient const &gradient, lottie::Vector2D const &start, lottie::Vector2D const &end) {
void ThorVGCanvasImpl::linearGradientStrokePath(std::shared_ptr<lottie::CGPath> const &path, float lineWidth, lottie::LineJoin lineJoin, lottie::LineCap lineCap, float dashPhase, std::vector<float> const &dashPattern, Gradient const &gradient, lottie::Vector2D const &start, lottie::Vector2D const &end) {
assert(false);
}
void ThorVGCanvasImpl::radialGradientStrokePath(std::shared_ptr<lottie::CGPath> const &path, double lineWidth, LineJoin lineJoin, LineCap lineCap, double dashPhase, std::vector<double> const &dashPattern, Gradient const &gradient, lottie::Vector2D const &startCenter, double startRadius, lottie::Vector2D const &endCenter, double endRadius) {
void ThorVGCanvasImpl::radialGradientStrokePath(std::shared_ptr<lottie::CGPath> const &path, float lineWidth, lottie::LineJoin lineJoin, lottie::LineCap lineCap, float dashPhase, std::vector<float> const &dashPattern, Gradient const &gradient, lottie::Vector2D const &startCenter, float startRadius, lottie::Vector2D const &endCenter, float endRadius) {
assert(false);
}
void ThorVGCanvasImpl::fill(lottie::CGRect const &rect, Color const &fillColor) {
void ThorVGCanvasImpl::fill(lottie::CGRect const &rect, lottie::Color const &fillColor) {
auto shape = tvg::Shape::gen();
shape->appendRect(rect.x, rect.y, rect.width, rect.height, 0.0f, 0.0f);
@ -257,7 +257,7 @@ void ThorVGCanvasImpl::setBlendMode(BlendMode blendMode) {
}*/
}
void ThorVGCanvasImpl::setAlpha(double alpha) {
void ThorVGCanvasImpl::setAlpha(float alpha) {
_alpha = alpha;
}

View File

@ -91,7 +91,7 @@ public:
/// TI and TO are the new tangents for the trimPoint
/// NO and NI are the new tangents for the startPoint and endPoints
/// S==NO=========TI==T==TO=======NI==E
CurveVertexSplitResult<CurveVertex> splitCurve(CurveVertex const &toVertex, double position) const {
CurveVertexSplitResult<CurveVertex> splitCurve(CurveVertex const &toVertex, float position) const {
/// If position is less than or equal to 0, trim at start.
if (position <= 0.0) {
return CurveVertexSplitResult<CurveVertex>(
@ -147,8 +147,8 @@ public:
///
/// This function should probably live in PathElement, since it deals with curve
/// lengths.
CurveVertexSplitResult<CurveVertex> trimCurve(CurveVertex const &toVertex, double atLength, double curveLength, int maxSamples, double accuracy = 1.0) const {
double currentPosition = atLength / curveLength;
CurveVertexSplitResult<CurveVertex> trimCurve(CurveVertex const &toVertex, float atLength, float curveLength, int maxSamples, float accuracy = 1.0f) const {
float currentPosition = atLength / curveLength;
auto results = splitCurve(toVertex, currentPosition);
if (maxSamples == 0) {
@ -162,7 +162,7 @@ public:
if (lengthDiff < accuracy) {
return results;
}
auto diffPosition = std::max(std::min((currentPosition / length) * lengthDiff, currentPosition * 0.5), currentPosition * (-0.5));
auto diffPosition = std::max(std::min((currentPosition / length) * lengthDiff, currentPosition * 0.5f), currentPosition * (-0.5f));
currentPosition = diffPosition + currentPosition;
results = splitCurve(toVertex, currentPosition);
}
@ -174,17 +174,17 @@ public:
/// For lines (zeroed tangents) the distance between the two points is measured.
/// For curves the curve is iterated over by sample count and the points are measured.
/// This is ~99% accurate at a sample count of 30
double distanceTo(CurveVertex const &toVertex, int sampleCount = 25) const {
float distanceTo(CurveVertex const &toVertex, int sampleCount = 25) const {
if (outTangentRelative().isZero() && toVertex.inTangentRelative().isZero()) {
/// Return a linear distance.
return point.distanceTo(toVertex.point);
}
double distance = 0.0;
float distance = 0.0;
auto previousPoint = point;
for (int i = 0; i < sampleCount; i++) {
auto pointOnCurve = splitCurve(toVertex, ((double)(i)) / ((double)(sampleCount))).trimPoint;
auto pointOnCurve = splitCurve(toVertex, ((float)(i)) / ((float)(sampleCount))).trimPoint;
distance = distance + previousPoint.distanceTo(pointOnCurve.point);
previousPoint = pointOnCurve.point;
}

View File

@ -25,7 +25,7 @@ typedef struct {
CGRect bounds;
CGPoint position;
CATransform3D transform;
double opacity;
float opacity;
bool masksToBounds;
bool isHidden;
} LottieRenderNodeLayerData;

View File

@ -41,7 +41,7 @@ struct __attribute__((packed)) PathElement {
}
/// Initializes a new path with length
explicit PathElement(std::optional<double> length_, CurveVertex const &vertex_) :
explicit PathElement(std::optional<float> length_, CurveVertex const &vertex_) :
vertex(vertex_) {
}
@ -58,7 +58,7 @@ struct __attribute__((packed)) PathElement {
}
/// Splits an element span defined by the receiver and fromElement to a position 0-1
PathSplitResult<PathElement> splitElementAtPosition(PathElement const &fromElement, double atLength) {
PathSplitResult<PathElement> splitElementAtPosition(PathElement const &fromElement, float atLength) {
/// Trim the span. Start and trim go into the first, trim and end go into second.
auto trimResults = fromElement.vertex.trimCurve(vertex, atLength, length(fromElement), 3);
@ -81,8 +81,8 @@ struct __attribute__((packed)) PathElement {
);
}
double length(PathElement const &previous) {
double result = previous.vertex.distanceTo(vertex);
float length(PathElement const &previous) {
float result = previous.vertex.distanceTo(vertex);
return result;
}
};

View File

@ -19,7 +19,7 @@ public:
CGRect _bounds;
Vector2D _position;
CATransform3D _transform;
double _opacity;
float _opacity;
bool _masksToBounds;
bool _isHidden;
@ -27,7 +27,7 @@ public:
CGRect bounds_,
Vector2D position_,
CATransform3D transform_,
double opacity_,
float opacity_,
bool masksToBounds_,
bool isHidden_
) :
@ -51,7 +51,7 @@ public:
return _transform;
}
double opacity() const {
float opacity() const {
return _opacity;
}
@ -135,19 +135,19 @@ public:
struct Stroke {
Color color;
double lineWidth = 0.0;
float lineWidth = 0.0;
LineJoin lineJoin = LineJoin::Round;
LineCap lineCap = LineCap::Square;
double dashPhase = 0.0;
std::vector<double> dashPattern;
float dashPhase = 0.0;
std::vector<float> dashPattern;
Stroke(
Color color_,
double lineWidth_,
float lineWidth_,
LineJoin lineJoin_,
LineCap lineCap_,
double dashPhase_,
std::vector<double> dashPattern_
float dashPhase_,
std::vector<float> dashPattern_
) :
color(color_),
lineWidth(lineWidth_),
@ -245,7 +245,7 @@ public:
FillRule pathFillRule_,
GradientType gradientType_,
std::vector<Color> const &colors_,
std::vector<double> const &locations_,
std::vector<float> const &locations_,
Vector2D const &start_,
Vector2D const &end_,
CGRect bounds_
@ -301,7 +301,7 @@ public:
FillRule pathFillRule;
GradientType gradientType;
std::vector<Color> colors;
std::vector<double> locations;
std::vector<float> locations;
Vector2D start;
Vector2D end;
CGRect bounds;
@ -328,7 +328,7 @@ public:
class SolidShading: public Shading {
public:
SolidShading(Color const &color_, double opacity_) :
SolidShading(Color const &color_, float opacity_) :
color(color_),
opacity(opacity_) {
}
@ -339,16 +339,16 @@ public:
public:
Color color;
double opacity = 0.0;
float opacity = 0.0;
};
class GradientShading: public Shading {
public:
GradientShading(
double opacity_,
float opacity_,
GradientType gradientType_,
std::vector<Color> const &colors_,
std::vector<double> const &locations_,
std::vector<float> const &locations_,
Vector2D const &start_,
Vector2D const &end_
) :
@ -365,31 +365,31 @@ public:
}
public:
double opacity = 0.0;
float opacity = 0.0;
GradientType gradientType;
std::vector<Color> colors;
std::vector<double> locations;
std::vector<float> locations;
Vector2D start;
Vector2D end;
};
struct Stroke {
std::shared_ptr<Shading> shading;
double lineWidth = 0.0;
float lineWidth = 0.0;
LineJoin lineJoin = LineJoin::Round;
LineCap lineCap = LineCap::Square;
double miterLimit = 4.0;
double dashPhase = 0.0;
std::vector<double> dashPattern;
float miterLimit = 4.0;
float dashPhase = 0.0;
std::vector<float> dashPattern;
Stroke(
std::shared_ptr<Shading> shading_,
double lineWidth_,
float lineWidth_,
LineJoin lineJoin_,
LineCap lineCap_,
double miterLimit_,
double dashPhase_,
std::vector<double> dashPattern_
float miterLimit_,
float dashPhase_,
std::vector<float> dashPattern_
) :
shading(shading_),
lineWidth(lineWidth_),
@ -421,7 +421,7 @@ public:
public:
bool isGroup = false;
CATransform3D transform = CATransform3D::identity();
double alpha = 0.0;
float alpha = 0.0;
std::optional<TrimParams> trimParams;
std::optional<BezierPath> path;
CGRect pathBoundingBox = CGRect(0.0, 0.0, 0.0, 0.0);
@ -450,7 +450,7 @@ public:
CGRect bounds_,
Vector2D position_,
CATransform3D transform_,
double alpha_,
float alpha_,
bool masksToBounds_,
bool isHidden_,
std::vector<std::shared_ptr<RenderTreeNode>> subnodes_,
@ -484,7 +484,7 @@ public:
return _transform;
}
double alpha() const {
float alpha() const {
return _alpha;
}
@ -512,7 +512,7 @@ public:
CGRect _bounds;
Vector2D _position;
CATransform3D _transform = CATransform3D::identity();
double _alpha = 1.0;
float _alpha = 1.0f;
bool _masksToBounds = false;
bool _isHidden = false;
std::shared_ptr<RenderTreeNodeContentItem> _contentItem;

View File

@ -37,12 +37,12 @@ enum class TrimType: int {
};
struct TrimParams {
double start = 0.0;
double end = 0.0;
double offset = 0.0;
float start = 0.0;
float end = 0.0;
float offset = 0.0;
TrimType type = TrimType::Simultaneously;
TrimParams(double start_, double end_, double offset_, TrimType type_) :
TrimParams(float start_, float end_, float offset_, TrimType type_) :
start(start_),
end(end_),
offset(offset_),

View File

@ -82,7 +82,7 @@ public:
return _contentsLayer;
}
void displayWithFrame(double frame, bool forceUpdates, BezierPathsBoundingBoxContext &boundingBoxContext) {
void displayWithFrame(float frame, bool forceUpdates, BezierPathsBoundingBoxContext &boundingBoxContext) {
bool layerVisible = isInRangeOrEqual(frame, _inFrame, _outFrame);
if (_transformNode->updateTree(frame, forceUpdates) || _contentsLayer->isHidden() != !layerVisible) {
@ -105,7 +105,7 @@ public:
virtual void updateContentsLayerParameters() {
}
virtual void displayContentsWithFrame(double frame, bool forceUpdates, BezierPathsBoundingBoxContext &boundingBoxContext) {
virtual void displayContentsWithFrame(float frame, bool forceUpdates, BezierPathsBoundingBoxContext &boundingBoxContext) {
/// To be overridden by subclass
}
@ -143,16 +143,16 @@ public:
return _matteType;
}
double inFrame() const {
float inFrame() const {
return _inFrame;
}
double outFrame() const {
float outFrame() const {
return _outFrame;
}
double startFrame() const {
float startFrame() const {
return _startFrame;
}
double timeStretch() const {
float timeStretch() const {
return _timeStretch;
}
@ -174,10 +174,10 @@ private:
std::shared_ptr<MaskContainerLayer> _maskLayer;
double _inFrame = 0.0;
double _outFrame = 0.0;
double _startFrame = 0.0;
double _timeStretch = 0.0;
float _inFrame = 0.0;
float _outFrame = 0.0;
float _startFrame = 0.0;
float _timeStretch = 0.0;
// MARK: Keypath Searchable

View File

@ -106,7 +106,7 @@ public:
virtual ~MaskLayer() = default;
void updateWithFrame(double frame, bool forceUpdates) {
void updateWithFrame(float frame, bool forceUpdates) {
if (_properties.opacity()->needsUpdate(frame) || forceUpdates) {
_properties.opacity()->update(frame);
setOpacity(_properties.opacity()->value().value);
@ -163,7 +163,7 @@ public:
// MARK: Internal
void updateWithFrame(double frame, bool forceUpdates) {
void updateWithFrame(float frame, bool forceUpdates) {
for (const auto &maskLayer : _maskLayers) {
maskLayer->updateWithFrame(frame, forceUpdates);
}

View File

@ -23,7 +23,7 @@ public:
std::shared_ptr<AnimationTextProvider> const &textProvider,
std::shared_ptr<AnimationFontProvider> const &fontProvider,
std::shared_ptr<AssetLibrary> const &assetLibrary,
double frameRate
float frameRate
) : CompositionLayer(precomp, Vector2D(precomp->width, precomp->height)) {
if (precomp->timeRemapping) {
_remappingNode = std::make_shared<NodeProperty<Vector1D>>(std::make_shared<KeyframeInterpolator<Vector1D>>(precomp->timeRemapping->keyframes));
@ -86,8 +86,8 @@ public:
return result;
}
virtual void displayContentsWithFrame(double frame, bool forceUpdates, BezierPathsBoundingBoxContext &boundingBoxContext) override {
double localFrame = 0.0;
virtual void displayContentsWithFrame(float frame, bool forceUpdates, BezierPathsBoundingBoxContext &boundingBoxContext) override {
float localFrame = 0.0;
if (_remappingNode) {
_remappingNode->update(frame);
localFrame = _remappingNode->value().value * _frameRate;
@ -195,7 +195,7 @@ public:
}
private:
double _frameRate = 0.0;
float _frameRate = 0.0;
std::shared_ptr<NodeProperty<Vector1D>> _remappingNode;
std::vector<std::shared_ptr<CompositionLayer>> _animationLayers;

View File

@ -74,7 +74,7 @@ public:
Color colorValue = Color(0.0, 0.0, 0.0, 0.0);
KeyframeInterpolator<Vector1D> opacity;
double opacityValue = 0.0;
float opacityValue = 0.0;
std::shared_ptr<RenderTreeNodeContentItem::Fill> _fill;
};
@ -93,7 +93,7 @@ public:
0.0,
gradientType,
std::vector<Color>(),
std::vector<double>(),
std::vector<float>(),
Vector2D(0.0, 0.0),
Vector2D(0.0, 0.0)
);
@ -130,7 +130,7 @@ public:
if (hasUpdates) {
std::vector<Color> colors;
std::vector<double> locations;
std::vector<float> locations;
getGradientParameters(numberOfColors, colorsValue, colors, locations);
RenderTreeNodeContentItem::GradientShading *gradient = ((RenderTreeNodeContentItem::GradientShading *)_fill->shading.get());
@ -161,7 +161,7 @@ public:
Vector3D endPointValue = Vector3D(0.0, 0.0, 0.0);
KeyframeInterpolator<Vector1D> opacity;
double opacityValue = 0.0;
float opacityValue = 0.0;
std::shared_ptr<RenderTreeNodeContentItem::Fill> _fill;
};
@ -202,7 +202,7 @@ public:
lineCap,
miterLimit,
0.0,
std::vector<double>()
std::vector<float>()
);
}
@ -257,7 +257,7 @@ public:
_stroke->lineWidth = widthValue;
_stroke->dashPhase = hasNonZeroDashes ? dashPhaseValue : 0.0;
_stroke->dashPattern = hasNonZeroDashes ? dashPatternValue.values : std::vector<double>();
_stroke->dashPattern = hasNonZeroDashes ? dashPatternValue.values : std::vector<float>();
}
}
@ -268,22 +268,22 @@ public:
private:
LineJoin lineJoin;
LineCap lineCap;
double miterLimit = 4.0;
float miterLimit = 4.0;
KeyframeInterpolator<Color> color;
Color colorValue = Color(0.0, 0.0, 0.0, 0.0);
KeyframeInterpolator<Vector1D> opacity;
double opacityValue = 0.0;
float opacityValue = 0.0;
KeyframeInterpolator<Vector1D> width;
double widthValue = 0.0;
float widthValue = 0.0;
std::unique_ptr<DashPatternInterpolator> dashPattern;
DashPattern dashPatternValue = DashPattern({});
std::unique_ptr<KeyframeInterpolator<Vector1D>> dashPhase;
double dashPhaseValue = 0.0;
float dashPhaseValue = 0.0;
std::shared_ptr<RenderTreeNodeContentItem::Stroke> _stroke;
};
@ -314,7 +314,7 @@ public:
0.0,
gradientType,
std::vector<Color>(),
std::vector<double>(),
std::vector<float>(),
Vector2D(0.0, 0.0),
Vector2D(0.0, 0.0)
);
@ -325,7 +325,7 @@ public:
lineCap,
miterLimit,
0.0,
std::vector<double>()
std::vector<float>()
);
}
@ -385,7 +385,7 @@ public:
}
std::vector<Color> colors;
std::vector<double> locations;
std::vector<float> locations;
getGradientParameters(numberOfColors, colorsValue, colors, locations);
RenderTreeNodeContentItem::GradientShading *gradient = ((RenderTreeNodeContentItem::GradientShading *)_stroke->shading.get());
@ -397,7 +397,7 @@ public:
_stroke->lineWidth = widthValue;
_stroke->dashPhase = hasNonZeroDashes ? dashPhaseValue : 0.0;
_stroke->dashPattern = hasNonZeroDashes ? dashPatternValue.values : std::vector<double>();
_stroke->dashPattern = hasNonZeroDashes ? dashPatternValue.values : std::vector<float>();
}
}
@ -408,7 +408,7 @@ public:
private:
LineJoin lineJoin;
LineCap lineCap;
double miterLimit = 4.0;
float miterLimit = 4.0;
int numberOfColors = 0;
GradientType gradientType;
@ -423,16 +423,16 @@ public:
Vector3D endPointValue = Vector3D(0.0, 0.0, 0.0);
KeyframeInterpolator<Vector1D> opacity;
double opacityValue = 0.0;
float opacityValue = 0.0;
KeyframeInterpolator<Vector1D> width;
double widthValue = 0.0;
float widthValue = 0.0;
std::unique_ptr<DashPatternInterpolator> dashPattern;
DashPattern dashPatternValue = DashPattern({});
std::unique_ptr<KeyframeInterpolator<Vector1D>> dashPhase;
double dashPhaseValue = 0.0;
float dashPhaseValue = 0.0;
std::shared_ptr<RenderTreeNodeContentItem::Stroke> _stroke;
};
@ -461,12 +461,12 @@ public:
}
TrimParams trimParams() {
double resolvedStartValue = startValue * 0.01;
double resolvedEndValue = endValue * 0.01;
double resolvedStart = std::min(resolvedStartValue, resolvedEndValue);
double resolvedEnd = std::max(resolvedStartValue, resolvedEndValue);
float resolvedStartValue = startValue * 0.01;
float resolvedEndValue = endValue * 0.01;
float resolvedStart = std::min(resolvedStartValue, resolvedEndValue);
float resolvedEnd = std::max(resolvedStartValue, resolvedEndValue);
double resolvedOffset = fmod(offsetValue, 360.0) / 360.0;
float resolvedOffset = fmod(offsetValue, 360.0) / 360.0;
return TrimParams(resolvedStart, resolvedEnd, resolvedOffset, type);
}
@ -475,13 +475,13 @@ public:
TrimType type;
KeyframeInterpolator<Vector1D> start;
double startValue = 0.0;
float startValue = 0.0;
KeyframeInterpolator<Vector1D> end;
double endValue = 0.0;
float endValue = 0.0;
KeyframeInterpolator<Vector1D> offset;
double offsetValue = 0.0;
float offsetValue = 0.0;
};
struct ShadingVariant {
@ -624,7 +624,7 @@ public:
Vector3D sizeValue = Vector3D(0.0, 0.0, 0.0);
KeyframeInterpolator<Vector1D> cornerRadius;
double cornerRadiusValue = 0.0;
float cornerRadiusValue = 0.0;
BezierPath resolvedPath;
CGRect resolvedPathBounds = CGRect(0.0, 0.0, 0.0, 0.0);
@ -768,22 +768,22 @@ public:
Vector3D positionValue = Vector3D(0.0, 0.0, 0.0);
KeyframeInterpolator<Vector1D> outerRadius;
double outerRadiusValue = 0.0;
float outerRadiusValue = 0.0;
KeyframeInterpolator<Vector1D> outerRoundedness;
double outerRoundednessValue = 0.0;
float outerRoundednessValue = 0.0;
std::unique_ptr<NodeProperty<Vector1D>> innerRadius;
double innerRadiusValue = 0.0;
float innerRadiusValue = 0.0;
std::unique_ptr<NodeProperty<Vector1D>> innerRoundedness;
double innerRoundednessValue = 0.0;
float innerRoundednessValue = 0.0;
KeyframeInterpolator<Vector1D> rotation;
double rotationValue = 0.0;
float rotationValue = 0.0;
KeyframeInterpolator<Vector1D> points;
double pointsValue = 0.0;
float pointsValue = 0.0;
BezierPath resolvedPath;
CGRect resolvedPathBounds = CGRect(0.0, 0.0, 0.0, 0.0);
@ -861,17 +861,17 @@ public:
scaleValue = _scale->value(frameTime);
}
double rotationValue = 0.0;
float rotationValue = 0.0;
if (_rotation) {
rotationValue = _rotation->value(frameTime).value;
}
double skewValue = 0.0;
float skewValue = 0.0;
if (_skew) {
skewValue = _skew->value(frameTime).value;
}
double skewAxisValue = 0.0;
float skewAxisValue = 0.0;
if (_skewAxis) {
skewAxisValue = _skewAxis->value(frameTime).value;
}
@ -892,7 +892,7 @@ public:
return _transformValue;
}
double opacity() {
float opacity() {
return _opacityValue;
}
@ -908,7 +908,7 @@ public:
std::unique_ptr<KeyframeInterpolator<Vector1D>> _opacity;
CATransform3D _transformValue = CATransform3D::identity();
double _opacityValue = 1.0;
float _opacityValue = 1.0;
};
class ContentItem {
@ -1089,7 +1089,7 @@ public:
void updateContents(std::optional<TrimParams> parentTrim) {
CATransform3D containerTransform = CATransform3D::identity();
double containerOpacity = 1.0;
float containerOpacity = 1.0;
if (transform) {
containerTransform = transform->transform();
containerOpacity = transform->opacity();
@ -1333,7 +1333,7 @@ CompositionLayer(solidLayer, Vector2D::Zero()) {
_contentTree = std::make_shared<ShapeLayerPresentationTree>(solidLayer);
}
void ShapeCompositionLayer::displayContentsWithFrame(double frame, bool forceUpdates, BezierPathsBoundingBoxContext &boundingBoxContext) {
void ShapeCompositionLayer::displayContentsWithFrame(float frame, bool forceUpdates, BezierPathsBoundingBoxContext &boundingBoxContext) {
_frameTime = frame;
_frameTimeInitialized = true;
_contentTree->itemTree->updateFrame(_frameTime, boundingBoxContext);

View File

@ -16,7 +16,7 @@ public:
ShapeCompositionLayer(std::shared_ptr<ShapeLayerModel> const &shapeLayer);
ShapeCompositionLayer(std::shared_ptr<SolidLayerModel> const &solidLayer);
virtual void displayContentsWithFrame(double frame, bool forceUpdates, BezierPathsBoundingBoxContext &boundingBoxContext) override;
virtual void displayContentsWithFrame(float frame, bool forceUpdates, BezierPathsBoundingBoxContext &boundingBoxContext) override;
virtual std::shared_ptr<RenderTreeNode> renderTreeNode(BezierPathsBoundingBoxContext &boundingBoxContext) override;
void initializeContentsLayerParameters();
virtual void updateContentsLayerParameters() override;

View File

@ -42,7 +42,7 @@ public:
_fontProvider = fontProvider;
}
virtual void displayContentsWithFrame(double frame, bool forceUpdates, BezierPathsBoundingBoxContext &boundingBoxContext) override {
virtual void displayContentsWithFrame(float frame, bool forceUpdates, BezierPathsBoundingBoxContext &boundingBoxContext) override {
if (!_textDocument) {
return;
}

View File

@ -98,7 +98,7 @@ public:
}
void display() {
double newFrame = currentFrame();
float newFrame = currentFrame();
if (_respectAnimationFrameRate) {
newFrame = floor(newFrame);
}
@ -140,7 +140,7 @@ public:
}*/
}
std::optional<AnyValue> getValue(AnimationKeypath const &keypath, std::optional<double> atFrame) {
std::optional<AnyValue> getValue(AnimationKeypath const &keypath, std::optional<float> atFrame) {
/*for (const auto &layer : _animationLayers) {
assert(false);
if
@ -153,7 +153,7 @@ public:
return std::nullopt;
}
std::optional<AnyValue> getOriginalValue(AnimationKeypath const &keypath, std::optional<double> atFrame) {
std::optional<AnyValue> getOriginalValue(AnimationKeypath const &keypath, std::optional<float> atFrame) {
/*for (const auto &layer : _animationLayers) {
assert(false);
if
@ -186,10 +186,10 @@ public:
return results;
}
double currentFrame() const {
float currentFrame() const {
return _currentFrame;
}
void setCurrentFrame(double currentFrame) {
void setCurrentFrame(float currentFrame) {
_currentFrame = currentFrame;
for (size_t i = 0; i < _animationLayers.size(); i++) {
@ -256,7 +256,7 @@ private:
// MARK: Internal
/// The animatable Current Frame Property
double _currentFrame = 0.0;
float _currentFrame = 0.0;
std::shared_ptr<AnimationImageProvider> _imageProvider;
std::shared_ptr<AnimationTextProvider> _textProvider;

View File

@ -14,7 +14,7 @@ std::vector<std::shared_ptr<CompositionLayer>> initializeCompositionLayers(
std::shared_ptr<LayerImageProvider> const &layerImageProvider,
std::shared_ptr<AnimationTextProvider> const &textProvider,
std::shared_ptr<AnimationFontProvider> const &fontProvider,
double frameRate
float frameRate
) {
std::vector<std::shared_ptr<CompositionLayer>> compositionLayers;
std::map<int, std::shared_ptr<CompositionLayer>> layerMap;

View File

@ -15,7 +15,7 @@ std::vector<std::shared_ptr<CompositionLayer>> initializeCompositionLayers(
std::shared_ptr<LayerImageProvider> const &layerImageProvider,
std::shared_ptr<AnimationTextProvider> const &textProvider,
std::shared_ptr<AnimationFontProvider> const &fontProvider,
double frameRate
float frameRate
);
}

View File

@ -136,11 +136,11 @@ public:
return _transformProperties;
}
virtual bool shouldRebuildOutputs(double frame) override {
virtual bool shouldRebuildOutputs(float frame) override {
return hasLocalUpdates() || hasUpstreamUpdates();
}
virtual void rebuildOutputs(double frame) override {
virtual void rebuildOutputs(float frame) override {
_opacity = ((float)_transformProperties->opacity()->value().value) * 0.01f;
Vector2D position(0.0, 0.0);

View File

@ -27,7 +27,7 @@ public:
return _typedContainer.outputValue();
}
virtual bool needsUpdate(double frame) const override {
virtual bool needsUpdate(float frame) const override {
return _typedContainer.needsUpdate() || _valueProvider->hasUpdate(frame);
}
@ -39,7 +39,7 @@ public:
_typedContainer.setNeedsUpdate();*/
}
virtual void update(double frame) override {
virtual void update(float frame) override {
_typedContainer.setValue(_valueProvider->value(frame), frame);
}

View File

@ -16,10 +16,10 @@ public:
public:
/// Returns true if the property needs to recompute its stored value
virtual bool needsUpdate(double frame) const = 0;
virtual bool needsUpdate(float frame) const = 0;
/// Updates the property for the frame
virtual void update(double frame) = 0;
virtual void update(float frame) = 0;
/// The Type of the value provider
virtual AnyValue::Type valueType() const = 0;

View File

@ -17,7 +17,7 @@ public:
virtual bool needsUpdate() const = 0;
/// The frame time of the last provided update
virtual double lastUpdateFrame() const = 0;
virtual float lastUpdateFrame() const = 0;
};
}

View File

@ -5,7 +5,7 @@ namespace lottie {
class HasRenderUpdates {
public:
virtual bool hasRenderUpdates(double forFrame) = 0;
virtual bool hasRenderUpdates(float forFrame) = 0;
};
}

View File

@ -13,7 +13,7 @@ class NodePropertyMap: virtual public HasChildKeypaths {
public:
virtual std::vector<std::shared_ptr<AnyNodeProperty>> &properties() = 0;
bool needsLocalUpdate(double frame) {
bool needsLocalUpdate(float frame) {
for (auto &property : properties()) {
if (property->needsUpdate(frame)) {
return true;
@ -22,7 +22,7 @@ public:
return false;
}
void updateNodeProperties(double frame) {
void updateNodeProperties(float frame) {
for (auto &property : properties()) {
property->update(frame);
}

View File

@ -15,7 +15,7 @@ public:
}
public:
double _lastUpdateFrame = std::numeric_limits<double>::infinity();
float _lastUpdateFrame = std::numeric_limits<float>::infinity();
bool _needsUpdate = true;
virtual AnyValue value() const override {
@ -26,7 +26,7 @@ public:
return _needsUpdate;
}
virtual double lastUpdateFrame() const override {
virtual float lastUpdateFrame() const override {
return _lastUpdateFrame;
}
@ -40,7 +40,7 @@ public:
_needsUpdate = false;
}
void setValue(AnyValue value, double forFrame) {
void setValue(AnyValue value, float forFrame) {
if (value.type() == AnyValueType<T>::type()) {
_needsUpdate = false;
_lastUpdateFrame = forFrame;

View File

@ -23,14 +23,14 @@ public:
}
virtual DashPattern value(AnimationFrameTime frame) override {
std::vector<double> values;
std::vector<float> values;
for (const auto &interpolator : _keyframeInterpolators) {
values.push_back(interpolator->value(frame).value);
}
return DashPattern(std::move(values));
}
virtual bool hasUpdate(double frame) const override {
virtual bool hasUpdate(float frame) const override {
for (const auto &interpolator : _keyframeInterpolators) {
if (interpolator->hasUpdate(frame)) {
return true;

View File

@ -62,7 +62,7 @@ public:
/// - If time is outside of the span, and there are more keyframes
/// - If a value delegate is set
/// - If leading and trailing are both nil.
virtual bool hasUpdate(double frame) const override {
virtual bool hasUpdate(float frame) const override {
if (!lastUpdatedFrame.has_value()) {
return true;
}
@ -94,7 +94,7 @@ public:
// MARK: Fileprivate
std::optional<double> lastUpdatedFrame;
std::optional<float> lastUpdatedFrame;
std::optional<int> leadingIndex;
std::optional<int> trailingIndex;
@ -102,7 +102,7 @@ public:
std::optional<Keyframe<T>> trailingKeyframe;
/// Finds the appropriate Leading and Trailing keyframe index for the given time.
void updateSpanIndices(double frame) {
void updateSpanIndices(float frame) {
if (keyframes.empty()) {
leadingIndex = std::nullopt;
trailingIndex = std::nullopt;
@ -270,7 +270,7 @@ public:
/// - If time is outside of the span, and there are more keyframes
/// - If a value delegate is set
/// - If leading and trailing are both nil.
bool hasUpdate(double frame) const {
bool hasUpdate(float frame) const {
if (!lastUpdatedFrame.has_value()) {
return true;
}
@ -302,7 +302,7 @@ public:
// MARK: Fileprivate
std::optional<double> lastUpdatedFrame;
std::optional<float> lastUpdatedFrame;
std::optional<int> leadingIndex;
std::optional<int> trailingIndex;
@ -310,7 +310,7 @@ public:
std::optional<Keyframe<BezierPath>> trailingKeyframe;
/// Finds the appropriate Leading and Trailing keyframe index for the given time.
void updateSpanIndices(double frame) {
void updateSpanIndices(float frame) {
if (keyframes.empty()) {
leadingIndex = std::nullopt;
trailingIndex = std::nullopt;
@ -434,7 +434,7 @@ private:
ValueInterpolator<BezierPath>::setInplace(from.value, outPath);
}
void interpolateInplace(Keyframe<BezierPath> const &from, Keyframe<BezierPath> const &to, double progress, BezierPath &outPath) {
void interpolateInplace(Keyframe<BezierPath> const &from, Keyframe<BezierPath> const &to, float progress, BezierPath &outPath) {
std::optional<Vector2D> spatialOutTangent2d;
if (from.spatialOutTangent) {
spatialOutTangent2d = Vector2D(from.spatialOutTangent->x, from.spatialOutTangent->y);

View File

@ -28,7 +28,7 @@ public:
return AnyValueType<T>::type();
}
virtual bool hasUpdate(double frame) const override {
virtual bool hasUpdate(float frame) const override {
return _hasUpdate;
}

View File

@ -40,7 +40,7 @@ public:
return nullptr;
}
virtual bool hasOutputUpdates(double forFrame) override {
virtual bool hasOutputUpdates(float forFrame) override {
/// Changes to this node do not affect downstream nodes.
bool parentUpdate = false;
if (_parent) {
@ -51,7 +51,7 @@ public:
return parentUpdate;
}
virtual bool hasRenderUpdates(double forFrame) override {
virtual bool hasRenderUpdates(float forFrame) override {
/// Return true if there are upstream updates or if this node has updates
bool upstreamUpdates = false;
if (_parent) {

View File

@ -112,16 +112,16 @@ public:
scale = Vector2D(scale3d.x, scale3d.y);
}
double rotation = 0.0;
float rotation = 0.0;
if (_rotation) {
rotation = _rotation->value().value;
}
std::optional<double> skew;
std::optional<float> skew;
if (_skew) {
skew = _skew->value().value;
}
std::optional<double> skewAxis;
std::optional<float> skewAxis;
if (_skewAxis) {
skewAxis = _skewAxis->value().value;
}
@ -140,7 +140,7 @@ public:
return nullptr;
}
double opacity() {
float opacity() {
if (_opacity) {
return _opacity->value().value;
} else {
@ -164,7 +164,7 @@ public:
}
}
double tracking() {
float tracking() {
if (_tracking) {
return _tracking->value().value;
} else {
@ -172,7 +172,7 @@ public:
}
}
double strokeWidth() {
float strokeWidth() {
if (_strokeWidth) {
return _strokeWidth->value().value;
} else {
@ -225,7 +225,7 @@ public:
_xform = xform;
}
double opacity() {
float opacity() {
if (_opacity.has_value()) {
return _opacity.value();
} else if (_parentTextNode) {
@ -234,7 +234,7 @@ public:
return 1.0;
}
}
void setOpacity(double opacity) {
void setOpacity(float opacity) {
_opacity = opacity;
}
@ -264,7 +264,7 @@ public:
_fillColor = fillColor;
}
double tracking() {
float tracking() {
if (_tracking.has_value()) {
return _tracking.value();
} else if (_parentTextNode) {
@ -273,11 +273,11 @@ public:
return 0.0;
}
}
void setTracking(double tracking) {
void setTracking(float tracking) {
_tracking = tracking;
}
double strokeWidth() {
float strokeWidth() {
if (_strokeWidth.has_value()) {
return _strokeWidth.value();
} else if (_parentTextNode) {
@ -286,11 +286,11 @@ public:
return 0.0;
}
}
void setStrokeWidth(double strokeWidth) {
void setStrokeWidth(float strokeWidth) {
_strokeWidth = strokeWidth;
}
virtual bool hasOutputUpdates(double frame) override {
virtual bool hasOutputUpdates(float frame) override {
// TODO Fix This
return true;
}
@ -313,11 +313,11 @@ private:
std::shared_ptr<CGPath> _outputPath;
std::optional<CATransform3D> _xform;
std::optional<double> _opacity;
std::optional<float> _opacity;
std::optional<Color> _strokeColor;
std::optional<Color> _fillColor;
std::optional<double> _tracking;
std::optional<double> _strokeWidth;
std::optional<float> _tracking;
std::optional<float> _strokeWidth;
};
class TextAnimatorNode: public AnimatorNode {
@ -347,7 +347,7 @@ public:
return true;
}
virtual void rebuildOutputs(double frame) override {
virtual void rebuildOutputs(float frame) override {
_textOutputNode->setXform(_textAnimatorProperties->caTransform());
_textOutputNode->setOpacity(((float)_textAnimatorProperties->opacity()) * 0.01f);
_textOutputNode->setStrokeColor(_textAnimatorProperties->strokeColor());

View File

@ -55,7 +55,7 @@ public:
virtual std::shared_ptr<NodeOutput> outputNode() = 0;
/// Update the outputs of the node. Called if local contents were update or if outputsNeedUpdate returns true.
virtual void rebuildOutputs(double frame) = 0;
virtual void rebuildOutputs(float frame) = 0;
/// Setters for marking current node state.
bool isEnabled() {
@ -79,10 +79,10 @@ public:
_hasUpstreamUpdates = hasUpstreamUpdates;
}
std::optional<double> lastUpdateFrame() {
std::optional<float> lastUpdateFrame() {
return _lastUpdateFrame;
}
virtual void setLastUpdateFrame(std::optional<double> lastUpdateFrame) {
virtual void setLastUpdateFrame(std::optional<float> lastUpdateFrame) {
_lastUpdateFrame = lastUpdateFrame;
}
@ -97,20 +97,20 @@ public:
}
/// Called at the end of this nodes update cycle. Always called. Optional.
virtual bool performAdditionalLocalUpdates(double frame, bool forceLocalUpdate) {
virtual bool performAdditionalLocalUpdates(float frame, bool forceLocalUpdate) {
/// Optional
return forceLocalUpdate;
}
virtual void performAdditionalOutputUpdates(double frame, bool forceOutputUpdate) {
virtual void performAdditionalOutputUpdates(float frame, bool forceOutputUpdate) {
/// Optional
}
/// The default simply returns `hasLocalUpdates`
virtual bool shouldRebuildOutputs(double frame) {
virtual bool shouldRebuildOutputs(float frame) {
return hasLocalUpdates();
}
virtual bool updateOutputs(double frame, bool forceOutputUpdate) {
virtual bool updateOutputs(float frame, bool forceOutputUpdate) {
if (!isEnabled()) {
setLastUpdateFrame(frame);
if (const auto parentNodeValue = parentNode()) {
@ -147,7 +147,7 @@ public:
}
/// Rebuilds the content of this node, and upstream nodes if necessary.
virtual bool updateContents(double frame, bool forceLocalUpdate) {
virtual bool updateContents(float frame, bool forceLocalUpdate) {
if (!isEnabled()) {
// Disabled node, pass through.
if (const auto parentNodeValue = parentNode()) {
@ -185,7 +185,7 @@ public:
return localUpdatesPermeateDownstream() ? hasUpstreamUpdates() || hasLocalUpdates() : hasUpstreamUpdates();
}
bool updateTree(double frame, bool forceUpdates) {
bool updateTree(float frame, bool forceUpdates) {
if (updateContents(frame, forceUpdates)) {
return updateOutputs(frame, forceUpdates);
} else {
@ -230,7 +230,7 @@ private:
bool _isEnabled = true;
bool _hasLocalUpdates = false;
bool _hasUpstreamUpdates = false;
std::optional<double> _lastUpdateFrame;
std::optional<float> _lastUpdateFrame;
};
}

View File

@ -15,7 +15,7 @@ public:
virtual std::shared_ptr<NodeOutput> parent() = 0;
/// Returns true if there are any updates upstream. OutputPath must be built before returning.
virtual bool hasOutputUpdates(double forFrame) = 0;
virtual bool hasOutputUpdates(float forFrame) = 0;
virtual std::shared_ptr<CGPath> outputPath() = 0;

View File

@ -2,13 +2,13 @@
namespace lottie {
void getGradientParameters(int numberOfColors, GradientColorSet const &colors, std::vector<Color> &outColors, std::vector<double> &outLocations) {
void getGradientParameters(int numberOfColors, GradientColorSet const &colors, std::vector<Color> &outColors, std::vector<float> &outLocations) {
std::vector<Color> alphaColors;
std::vector<double> alphaValues;
std::vector<double> alphaLocations;
std::vector<float> alphaValues;
std::vector<float> alphaLocations;
std::vector<Color> gradientColors;
std::vector<double> colorLocations;
std::vector<float> colorLocations;
for (int i = 0; i < numberOfColors; i++) {
int ix = i * 4;
@ -26,7 +26,7 @@ void getGradientParameters(int numberOfColors, GradientColorSet const &colors, s
bool drawMask = false;
for (int i = numberOfColors * 4; i < (int)colors.colors.size(); i += 2) {
double alpha = colors.colors[i + 1];
float alpha = colors.colors[i + 1];
if (alpha < 1.0) {
drawMask = true;
}
@ -36,7 +36,7 @@ void getGradientParameters(int numberOfColors, GradientColorSet const &colors, s
}
if (drawMask) {
std::vector<double> locations;
std::vector<float> locations;
for (size_t i = 0; i < std::min(gradientColors.size(), colorLocations.size()); i++) {
if (std::find(locations.begin(), locations.end(), colorLocations[i]) == locations.end()) {
locations.push_back(colorLocations[i]);
@ -62,7 +62,7 @@ void getGradientParameters(int numberOfColors, GradientColorSet const &colors, s
Color color = gradientColors[0];
for (size_t i = 0; i < std::min(gradientColors.size(), colorLocations.size()) - 1; i++) {
if (location >= colorLocations[i] && location <= colorLocations[i + 1]) {
double localLocation = 0.0;
float localLocation = 0.0;
if (colorLocations[i] != colorLocations[i + 1]) {
localLocation = remapFloat(location, colorLocations[i], colorLocations[i + 1], 0.0, 1.0);
}
@ -71,14 +71,14 @@ void getGradientParameters(int numberOfColors, GradientColorSet const &colors, s
}
}
double alpha = 1.0;
float alpha = 1.0;
for (size_t i = 0; i < std::min(alphaValues.size(), alphaLocations.size()) - 1; i++) {
if (location >= alphaLocations[i] && location <= alphaLocations[i + 1]) {
double localLocation = 0.0;
float localLocation = 0.0;
if (alphaLocations[i] != alphaLocations[i + 1]) {
localLocation = remapFloat(location, alphaLocations[i], alphaLocations[i + 1], 0.0, 1.0);
}
alpha = ValueInterpolator<double>::interpolate(alphaValues[i], alphaValues[i + 1], localLocation, std::nullopt, std::nullopt);
alpha = ValueInterpolator<float>::interpolate(alphaValues[i], alphaValues[i + 1], localLocation, std::nullopt, std::nullopt);
break;
}
}

View File

@ -6,7 +6,7 @@
namespace lottie {
void getGradientParameters(int numberOfColors, GradientColorSet const &colors, std::vector<Color> &outColors, std::vector<double> &outLocations);
void getGradientParameters(int numberOfColors, GradientColorSet const &colors, std::vector<Color> &outColors, std::vector<float> &outLocations);
}

View File

@ -32,7 +32,7 @@ public:
std::optional<int> tgs_,
AnimationFrameTime startFrame_,
AnimationFrameTime endFrame_,
double framerate_,
float framerate_,
std::string const &version_,
std::optional<CoordinateSpace> type_,
int width_,
@ -93,7 +93,7 @@ public:
AnimationFrameTime startFrame = getDouble(json, "ip");
AnimationFrameTime endFrame = getDouble(json, "op");
double framerate = getDouble(json, "fr");
float framerate = getDouble(json, "fr");
int width = getInt(json, "w");
int height = getInt(json, "h");
@ -256,7 +256,7 @@ public:
AnimationFrameTime endFrame;
/// The frame rate of the composition.
double framerate;
float framerate;
/// Return all marker names, in order, or an empty list if none are specified
std::vector<std::string> markerNames() {

View File

@ -18,8 +18,8 @@ public:
std::string id_,
std::string name_,
std::string directory_,
double width_,
double height_
float width_,
float height_
) : Asset(id_),
name(name_),
directory(directory_),
@ -64,8 +64,8 @@ public:
std::string directory;
/// Image Size
double width;
double height;
float width;
float height;
std::optional<int> _e;
std::optional<std::string> _t;

View File

@ -56,7 +56,7 @@ public:
/// Layers of the precomp
std::vector<std::shared_ptr<LayerModel>> layers;
std::optional<double> frameRate;
std::optional<float> frameRate;
};
}

View File

@ -255,7 +255,7 @@ public:
}
}
double timeStretch() {
float timeStretch() {
if (_timeStretch.has_value()) {
return _timeStretch.value();
} else {
@ -279,12 +279,12 @@ public:
std::optional<CoordinateSpace> coordinateSpace;
/// The in time of the layer in frames.
double inFrame;
float inFrame;
/// The out time of the layer in frames.
double outFrame;
float outFrame;
/// The start time of the layer in frames.
double startTime;
float startTime;
/// The transform of the layer
std::shared_ptr<Transform> transform;
@ -299,7 +299,7 @@ public:
std::optional<std::vector<std::shared_ptr<Mask>>> masks;
/// A number that stretches time by a multiplier
std::optional<double> _timeStretch;
std::optional<float> _timeStretch;
/// The type of matte if any.
std::optional<MatteType> matte;

View File

@ -46,10 +46,10 @@ public:
std::optional<KeyframeGroup<Vector1D>> timeRemapping;
/// Precomp Width
double width;
float width;
/// Precomp Height
double height;
float height;
};
}

View File

@ -31,10 +31,10 @@ public:
std::string colorHex;
/// The Width of the color layer
double width;
float width;
/// The height of the color layer
double height;
float height;
};
}

View File

@ -19,33 +19,33 @@ public:
lottiejson11::Json::object toJson() const {
lottiejson11::Json::object result;
result.insert(std::make_pair("o", (double)original));
result.insert(std::make_pair("o", (float)original));
if (type12.has_value()) {
result.insert(std::make_pair("f12", (double)type12.value()));
result.insert(std::make_pair("f12", (float)type12.value()));
}
if (type3.has_value()) {
result.insert(std::make_pair("f3", (double)type3.value()));
result.insert(std::make_pair("f3", (float)type3.value()));
}
if (type4.has_value()) {
result.insert(std::make_pair("f4", (double)type4.value()));
result.insert(std::make_pair("f4", (float)type4.value()));
}
if (type5.has_value()) {
result.insert(std::make_pair("f5", (double)type5.value()));
result.insert(std::make_pair("f5", (float)type5.value()));
}
if (type6.has_value()) {
result.insert(std::make_pair("f6", (double)type6.value()));
result.insert(std::make_pair("f6", (float)type6.value()));
}
return result;
}
public:
double original;
std::optional<double> type12;
std::optional<double> type3;
std::optional<double> type4;
std::optional<double> type5;
std::optional<double> type6;
float original;
std::optional<float> type12;
std::optional<float> type3;
std::optional<float> type4;
std::optional<float> type5;
std::optional<float> type6;
};
}

View File

@ -182,7 +182,7 @@ public:
LineJoin lineJoin;
/// Miter Limit
std::optional<double> miterLimit;
std::optional<float> miterLimit;
/// The dash pattern of the stroke
std::optional<std::vector<DashElement>> dashPattern;

View File

@ -128,7 +128,7 @@ public:
LineJoin lineJoin;
/// Miter Limit
std::optional<double> miterLimit;
std::optional<float> miterLimit;
/// The dash pattern of the stroke
std::optional<std::vector<DashElement>> dashPattern;

View File

@ -14,7 +14,7 @@ public:
std::string const &name_,
std::string const &familyName_,
std::string const &style_,
double ascent_
float ascent_
) :
name(name_),
familyName(familyName_),
@ -63,7 +63,7 @@ public:
std::optional<std::string> weight;
std::optional<std::string> fontClass;
std::string style;
double ascent;
float ascent;
std::optional<int> origin;
};

View File

@ -13,10 +13,10 @@ class Glyph {
public:
Glyph(
std::string const &character_,
double fontSize_,
float fontSize_,
std::string const &fontFamily_,
std::string const &fontStyle_,
double width_,
float width_,
std::optional<std::vector<std::shared_ptr<ShapeItem>>> shapes_
) :
character(character_),
@ -86,7 +86,7 @@ public:
std::string character;
/// The font size of the character
double fontSize;
float fontSize;
/// The font family of the character
std::string fontFamily;
@ -95,7 +95,7 @@ public:
std::string fontStyle;
/// The Width of the character
double width;
float width;
/// The Shape Data of the Character
std::optional<std::vector<std::shared_ptr<ShapeItem>>> shapes;

View File

@ -20,15 +20,15 @@ class TextDocument {
public:
TextDocument(
std::string const &text_,
double fontSize_,
float fontSize_,
std::string const &fontFamily_,
TextJustification justification_,
int tracking_,
double lineHeight_,
std::optional<double> baseline_,
float lineHeight_,
std::optional<float> baseline_,
std::optional<Color> fillColorData_,
std::optional<Color> strokeColorData_,
std::optional<double> strokeWidth_,
std::optional<float> strokeWidth_,
std::optional<bool> strokeOverFill_,
std::optional<Vector3D> textFramePosition_,
std::optional<Vector3D> textFrameSize_
@ -145,7 +145,7 @@ public:
std::string text;
/// The Font size
double fontSize;
float fontSize;
/// The Font Family
std::string fontFamily;
@ -157,10 +157,10 @@ public:
int tracking;
/// Line Height
double lineHeight;
float lineHeight;
/// Baseline
std::optional<double> baseline;
std::optional<float> baseline;
/// Fill Color data
std::optional<Color> fillColorData;
@ -169,7 +169,7 @@ public:
std::optional<Color> strokeColorData;
/// Stroke Width
std::optional<double> strokeWidth;
std::optional<float> strokeWidth;
/// Stroke Over Fill
std::optional<bool> strokeOverFill;

View File

@ -17,7 +17,7 @@ public:
paths({ path }) {
}
CompoundBezierPath(std::vector<BezierPath> paths_, std::optional<double> length_) :
CompoundBezierPath(std::vector<BezierPath> paths_, std::optional<float> length_) :
paths(paths_), _length(length_) {
}
@ -28,11 +28,11 @@ public:
public:
std::vector<BezierPath> paths;
double length() {
float length() {
if (_length.has_value()) {
return _length.value();
} else {
double l = 0.0;
float l = 0.0;
for (auto &path : paths) {
l += path.length();
}
@ -42,7 +42,7 @@ public:
}
private:
std::optional<double> _length;
std::optional<float> _length;
public:
std::shared_ptr<CompoundBezierPath> addingPath(BezierPath const &path) const {
@ -64,7 +64,7 @@ public:
return std::make_shared<CompoundBezierPath>(newPaths);
}
std::shared_ptr<CompoundBezierPath> trim(double fromPosition, double toPosition, double offset) {
std::shared_ptr<CompoundBezierPath> trim(float fromPosition, float toPosition, float offset) {
if (fromPosition == toPosition) {
return std::make_shared<CompoundBezierPath>();
}
@ -82,11 +82,11 @@ public:
return std::make_shared<CompoundBezierPath>(newPaths);
}*/
double lengthValue = length();
float lengthValue = length();
/// Normalize lengths to the curve length.
double startPosition = fmod(fromPosition + offset, 1.0);
double endPosition = fmod(toPosition + offset, 1.0);
float startPosition = fmod(fromPosition + offset, 1.0);
float endPosition = fmod(toPosition + offset, 1.0);
if (startPosition < 0.0) {
startPosition = 1.0 + startPosition;
@ -123,7 +123,7 @@ public:
auto compoundPath = std::make_shared<CompoundBezierPath>();
auto trim = positions[0];
positions.erase(positions.begin());
double pathStartPosition = 0.0;
float pathStartPosition = 0.0;
bool finishedTrimming = false;
int i = 0;

View File

@ -11,7 +11,7 @@ namespace lottie {
///
class AnimationFontProvider {
public:
virtual std::shared_ptr<CTFont> fontFor(std::string const &family, double size) = 0;
virtual std::shared_ptr<CTFont> fontFor(std::string const &family, float size) = 0;
};
/// Default Font provider.
@ -22,7 +22,7 @@ public:
virtual ~DefaultFontProvider() = default;
virtual std::shared_ptr<CTFont> fontFor(std::string const &family, double size) override {
virtual std::shared_ptr<CTFont> fontFor(std::string const &family, float size) override {
//CTFontCreateWithName(family as CFString, size, nil)
return nullptr;
}

View File

@ -65,7 +65,7 @@ public:
}
public:
T interpolate(Keyframe<T> const &to, double progress) {
T interpolate(Keyframe<T> const &to, float progress) {
std::optional<Vector2D> spatialOutTangent2d;
if (spatialOutTangent) {
spatialOutTangent2d = Vector2D(spatialOutTangent->x, spatialOutTangent->y);
@ -78,9 +78,9 @@ public:
}
/// Interpolates the keyTime into a value from 0-1
double interpolatedProgress(Keyframe<T> const &to, double keyTime) {
double startTime = time;
double endTime = to.time;
float interpolatedProgress(Keyframe<T> const &to, float keyTime) {
float startTime = time;
float endTime = to.time;
if (keyTime <= startTime) {
return 0.0;
}
@ -100,7 +100,7 @@ public:
if (to.inTangent.has_value()) {
inTanPoint = to.inTangent.value();
}
double progress = remapFloat(keyTime, startTime, endTime, 0.0f, 1.0f);
float progress = remapFloat(keyTime, startTime, endTime, 0.0f, 1.0f);
if (!outTanPoint.isZero() || inTanPoint != Vector2D(1.0f, 1.0f)) {
/// Cubic interpolation
progress = cubicBezierInterpolate(progress, Vector2D::Zero(), outTanPoint, inTanPoint, Vector2D(1.0, 1.0));

View File

@ -4,7 +4,7 @@
namespace lottie {
void batchInterpolate(std::vector<PathElement> const &from, std::vector<PathElement> const &to, BezierPath &resultPath, double amount) {
void batchInterpolate(std::vector<PathElement> const &from, std::vector<PathElement> const &to, BezierPath &resultPath, float amount) {
int elementCount = (int)from.size();
if (elementCount > (int)to.size()) {
elementCount = (int)to.size();

View File

@ -18,9 +18,9 @@ struct ValueInterpolator {
};
template<>
struct ValueInterpolator<double> {
struct ValueInterpolator<float> {
public:
static double interpolate(double value, double to, double amount, std::optional<Vector2D> spatialOutTangent, std::optional<Vector2D> spatialInTangent) {
static float interpolate(float value, float to, float amount, std::optional<Vector2D> spatialOutTangent, std::optional<Vector2D> spatialInTangent) {
return value + ((to - value) * amount);
}
};
@ -28,22 +28,22 @@ public:
template<>
struct ValueInterpolator<Vector1D> {
public:
static Vector1D interpolate(Vector1D const &value, Vector1D const &to, double amount, std::optional<Vector2D> spatialOutTangent, std::optional<Vector2D> spatialInTangent) {
return Vector1D(ValueInterpolator<double>::interpolate(value.value, to.value, amount, spatialOutTangent, spatialInTangent));
static Vector1D interpolate(Vector1D const &value, Vector1D const &to, float amount, std::optional<Vector2D> spatialOutTangent, std::optional<Vector2D> spatialInTangent) {
return Vector1D(ValueInterpolator<float>::interpolate(value.value, to.value, amount, spatialOutTangent, spatialInTangent));
}
};
template<>
struct ValueInterpolator<Vector2D> {
public:
static Vector2D interpolate(Vector2D const &value, Vector2D const &to, double amount, Vector2D spatialOutTangent, Vector2D spatialInTangent) {
static Vector2D interpolate(Vector2D const &value, Vector2D const &to, float amount, Vector2D spatialOutTangent, Vector2D spatialInTangent) {
auto cp1 = value + spatialOutTangent;
auto cp2 = to + spatialInTangent;
return value.interpolate(to, cp1, cp2, amount);
}
static Vector2D interpolate(Vector2D const &value, Vector2D const &to, double amount) {
static Vector2D interpolate(Vector2D const &value, Vector2D const &to, float amount) {
return value.interpolate(to, amount);
}
};
@ -51,7 +51,7 @@ public:
template<>
struct ValueInterpolator<Vector3D> {
public:
static Vector3D interpolate(Vector3D const &value, Vector3D const &to, double amount, std::optional<Vector2D> spatialOutTangent, std::optional<Vector2D> spatialInTangent) {
static Vector3D interpolate(Vector3D const &value, Vector3D const &to, float amount, std::optional<Vector2D> spatialOutTangent, std::optional<Vector2D> spatialInTangent) {
if (spatialOutTangent && spatialInTangent) {
Vector2D from2d(value.x, value.y);
Vector2D to2d(to.x, to.y);
@ -64,14 +64,14 @@ public:
return Vector3D(
result2d.x,
result2d.y,
ValueInterpolator<double>::interpolate(value.z, to.z, amount, spatialOutTangent, spatialInTangent)
ValueInterpolator<float>::interpolate(value.z, to.z, amount, spatialOutTangent, spatialInTangent)
);
}
return Vector3D(
ValueInterpolator<double>::interpolate(value.x, to.x, amount, spatialOutTangent, spatialInTangent),
ValueInterpolator<double>::interpolate(value.y, to.y, amount, spatialOutTangent, spatialInTangent),
ValueInterpolator<double>::interpolate(value.z, to.z, amount, spatialOutTangent, spatialInTangent)
ValueInterpolator<float>::interpolate(value.x, to.x, amount, spatialOutTangent, spatialInTangent),
ValueInterpolator<float>::interpolate(value.y, to.y, amount, spatialOutTangent, spatialInTangent),
ValueInterpolator<float>::interpolate(value.z, to.z, amount, spatialOutTangent, spatialInTangent)
);
}
};
@ -79,22 +79,22 @@ public:
template<>
struct ValueInterpolator<Color> {
public:
static Color interpolate(Color const &value, Color const &to, double amount, std::optional<Vector2D> spatialOutTangent, std::optional<Vector2D> spatialInTangent) {
static Color interpolate(Color const &value, Color const &to, float amount, std::optional<Vector2D> spatialOutTangent, std::optional<Vector2D> spatialInTangent) {
return Color(
ValueInterpolator<double>::interpolate(value.r, to.r, amount, spatialOutTangent, spatialInTangent),
ValueInterpolator<double>::interpolate(value.g, to.g, amount, spatialOutTangent, spatialInTangent),
ValueInterpolator<double>::interpolate(value.b, to.b, amount, spatialOutTangent, spatialInTangent),
ValueInterpolator<double>::interpolate(value.a, to.a, amount, spatialOutTangent, spatialInTangent)
ValueInterpolator<float>::interpolate(value.r, to.r, amount, spatialOutTangent, spatialInTangent),
ValueInterpolator<float>::interpolate(value.g, to.g, amount, spatialOutTangent, spatialInTangent),
ValueInterpolator<float>::interpolate(value.b, to.b, amount, spatialOutTangent, spatialInTangent),
ValueInterpolator<float>::interpolate(value.a, to.a, amount, spatialOutTangent, spatialInTangent)
);
}
};
void batchInterpolate(std::vector<PathElement> const &from, std::vector<PathElement> const &to, BezierPath &resultPath, double amount);
void batchInterpolate(std::vector<PathElement> const &from, std::vector<PathElement> const &to, BezierPath &resultPath, float amount);
template<>
struct ValueInterpolator<CurveVertex> {
public:
static CurveVertex interpolate(CurveVertex const &value, CurveVertex const &to, double amount, Vector2D spatialOutTangent, Vector2D spatialInTangent) {
static CurveVertex interpolate(CurveVertex const &value, CurveVertex const &to, float amount, Vector2D spatialOutTangent, Vector2D spatialInTangent) {
return CurveVertex::absolute(
ValueInterpolator<Vector2D>::interpolate(value.point, to.point, amount, spatialOutTangent, spatialInTangent),
ValueInterpolator<Vector2D>::interpolate(value.inTangent, to.inTangent, amount, spatialOutTangent, spatialInTangent),
@ -102,7 +102,7 @@ public:
);
}
static CurveVertex interpolate(CurveVertex const &value, CurveVertex const &to, double amount) {
static CurveVertex interpolate(CurveVertex const &value, CurveVertex const &to, float amount) {
return CurveVertex::absolute(
ValueInterpolator<Vector2D>::interpolate(value.point, to.point, amount),
ValueInterpolator<Vector2D>::interpolate(value.inTangent, to.inTangent, amount),
@ -114,7 +114,7 @@ public:
template<>
struct ValueInterpolator<BezierPath> {
public:
static BezierPath interpolate(BezierPath const &value, BezierPath const &to, double amount, std::optional<Vector2D> spatialOutTangent, std::optional<Vector2D> spatialInTangent) {
static BezierPath interpolate(BezierPath const &value, BezierPath const &to, float amount, std::optional<Vector2D> spatialOutTangent, std::optional<Vector2D> spatialInTangent) {
BezierPath newPath;
newPath.reserveCapacity(std::max(value.elements().size(), to.elements().size()));
//TODO:probably a bug in the upstream code, uncomment
@ -150,7 +150,7 @@ public:
memcpy(resultPath.mutableElements().data(), value.elements().data(), value.elements().size() * sizeof(PathElement));
}
static void interpolateInplace(BezierPath const &value, BezierPath const &to, double amount, std::optional<Vector2D> spatialOutTangent, std::optional<Vector2D> spatialInTangent, BezierPath &resultPath) {
static void interpolateInplace(BezierPath const &value, BezierPath const &to, float amount, std::optional<Vector2D> spatialOutTangent, std::optional<Vector2D> spatialInTangent, BezierPath &resultPath) {
/*if (value.elements().size() != to.elements().size()) {
return to;
}*/
@ -185,7 +185,7 @@ public:
template<>
struct ValueInterpolator<TextDocument> {
public:
static TextDocument interpolate(TextDocument const &value, TextDocument const &to, double amount, std::optional<Vector2D> spatialOutTangent, std::optional<Vector2D> spatialInTangent) {
static TextDocument interpolate(TextDocument const &value, TextDocument const &to, float amount, std::optional<Vector2D> spatialOutTangent, std::optional<Vector2D> spatialInTangent) {
if (amount == 1.0) {
return to;
} else {
@ -197,12 +197,12 @@ public:
template<>
struct ValueInterpolator<GradientColorSet> {
public:
static GradientColorSet interpolate(GradientColorSet const &value, GradientColorSet const &to, double amount, std::optional<Vector2D> spatialOutTangent, std::optional<Vector2D> spatialInTangent) {
static GradientColorSet interpolate(GradientColorSet const &value, GradientColorSet const &to, float amount, std::optional<Vector2D> spatialOutTangent, std::optional<Vector2D> spatialInTangent) {
assert(value.colors.size() == to.colors.size());
std::vector<double> colors;
std::vector<float> colors;
size_t colorCount = std::min(value.colors.size(), to.colors.size());
for (size_t i = 0; i < colorCount; i++) {
colors.push_back(ValueInterpolator<double>::interpolate(value.colors[i], to.colors[i], amount, spatialOutTangent, spatialInTangent));
colors.push_back(ValueInterpolator<float>::interpolate(value.colors[i], to.colors[i], amount, spatialOutTangent, spatialInTangent));
}
return GradientColorSet(colors);
}
@ -211,12 +211,12 @@ public:
template<>
struct ValueInterpolator<DashPattern> {
public:
static DashPattern interpolate(DashPattern const &value, DashPattern const &to, double amount, std::optional<Vector2D> spatialOutTangent, std::optional<Vector2D> spatialInTangent) {
static DashPattern interpolate(DashPattern const &value, DashPattern const &to, float amount, std::optional<Vector2D> spatialOutTangent, std::optional<Vector2D> spatialInTangent) {
assert(value.values.size() == to.values.size());
std::vector<double> values;
std::vector<float> values;
size_t colorCount = std::min(value.values.size(), to.values.size());
for (size_t i = 0; i < colorCount; i++) {
values.push_back(ValueInterpolator<double>::interpolate(value.values[i], to.values[i], amount, spatialOutTangent, spatialInTangent));
values.push_back(ValueInterpolator<float>::interpolate(value.values[i], to.values[i], amount, spatialOutTangent, spatialInTangent));
}
return DashPattern(std::move(values));
}

View File

@ -4,10 +4,10 @@
namespace lottie {
/// Defines animation time in Frames (Seconds * Framerate).
typedef double AnimationFrameTime;
typedef float AnimationFrameTime;
/// Defines animation time by a progress from 0 (beginning of the animation) to 1 (end of the animation)
typedef double AnimationProgressTime;
typedef float AnimationProgressTime;
}

View File

@ -16,7 +16,7 @@ namespace lottie {
class AnyValue {
public:
enum class Type {
Double,
Float,
Vector1D,
Vector2D,
Vector3D,
@ -28,9 +28,9 @@ public:
};
public:
AnyValue(double value) :
_type(Type::Double),
_doubleValue(value) {
AnyValue(float value) :
_type(Type::Float),
_floatValue(value) {
}
AnyValue(Vector1D const &value) :
@ -73,9 +73,9 @@ public:
_dashPatternValue(value) {
}
template<typename T, typename = std::enable_if_t<std::is_same<T, double>::value>>
double get() {
return asDouble();
template<typename T, typename = std::enable_if_t<std::is_same<T, float>::value>>
float get() {
return asFloat();
}
template<typename T, typename = std::enable_if_t<std::is_same<T, Vector1D>::value>>
@ -123,8 +123,8 @@ public:
return _type;
}
double asDouble() {
return _doubleValue.value();
float asFloat() {
return _floatValue.value();
}
Vector1D asVector1D() {
@ -162,7 +162,7 @@ public:
private:
Type _type;
std::optional<double> _doubleValue;
std::optional<float> _floatValue;
std::optional<Vector1D> _vector1DValue;
std::optional<Vector2D> _vector2DValue;
std::optional<Vector3D> _vector3DValue;
@ -178,9 +178,9 @@ struct AnyValueType {
};
template<>
struct AnyValueType<double> {
struct AnyValueType<float> {
static AnyValue::Type type() {
return AnyValue::Type::Double;
return AnyValue::Type::Float;
}
};

View File

@ -186,10 +186,10 @@ public:
_path = path;
}
double lineWidth() const {
float lineWidth() const {
return _lineWidth;
}
void setLineWidth(double lineWidth) {
void setLineWidth(float lineWidth) {
_lineWidth = lineWidth;
}
@ -207,17 +207,17 @@ public:
_lineCap = lineCap;
}
double lineDashPhase() const {
float lineDashPhase() const {
return _lineDashPhase;
}
void setLineDashPhase(double lineDashPhase) {
void setLineDashPhase(float lineDashPhase) {
_lineDashPhase = lineDashPhase;
}
std::vector<double> const &dashPattern() const {
std::vector<float> const &dashPattern() const {
return _dashPattern;
}
void setDashPattern(std::vector<double> const &dashPattern) {
void setDashPattern(std::vector<float> const &dashPattern) {
_dashPattern = dashPattern;
}
@ -243,11 +243,11 @@ private:
std::optional<Color> _fillColor = Color(0.0, 0.0, 0.0, 1.0);
FillRule _fillRule = FillRule::NonZeroWinding;
std::shared_ptr<CGPath> _path;
double _lineWidth = 1.0;
float _lineWidth = 1.0;
LineJoin _lineJoin = LineJoin::Miter;
LineCap _lineCap = LineCap::Butt;
double _lineDashPhase = 0.0;
std::vector<double> _dashPattern;
float _lineDashPhase = 0.0;
std::vector<float> _dashPattern;
};
}

View File

@ -6,11 +6,11 @@
namespace lottie {
struct DashPattern {
DashPattern(std::vector<double> &&values_) :
DashPattern(std::vector<float> &&values_) :
values(std::move(values_)) {
}
std::vector<double> values;
std::vector<float> values;
};
}

View File

@ -34,7 +34,7 @@ struct GradientColorSet {
return result;
}
std::vector<double> colors;
std::vector<float> colors;
};
}

View File

@ -468,7 +468,7 @@ private final class RenderFrameState {
restoreState()
}
func renderNode(animationContainer: LottieAnimationContainer, node: LottieRenderNodeProxy, globalSize: CGSize, parentAlpha: CGFloat) {
func renderNode(animationContainer: LottieAnimationContainer, node: LottieRenderNodeProxy, globalSize: CGSize, parentAlpha: Float) {
let normalizedOpacity = node.layer.opacity
let layerAlpha = normalizedOpacity * parentAlpha
@ -534,7 +534,7 @@ private final class RenderFrameState {
concat(node.layer.transform)
}
var renderAlpha: CGFloat = 1.0
var renderAlpha: Float = 1.0
if needsTempContext {
renderAlpha = 1.0
} else {