From ad335bbfafbc5326c62a84342f4e3792e79df8f9 Mon Sep 17 00:00:00 2001 From: Florin Malita Date: Mon, 22 Jan 2018 23:27:21 -0500 Subject: [skottie] Improved animation params parsing Some BM versions wrap the Bezier animation params into arrays. TBR= Change-Id: I376b1ed2079105066413b513c3df33a61440cf41 Reviewed-on: https://skia-review.googlesource.com/98580 Reviewed-by: Florin Malita Commit-Queue: Florin Malita --- experimental/skottie/SkottieAnimator.cpp | 12 ++++++++++++ experimental/skottie/SkottiePriv.h | 7 ------- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'experimental') diff --git a/experimental/skottie/SkottieAnimator.cpp b/experimental/skottie/SkottieAnimator.cpp index 296a96b1fd..6568d1b183 100644 --- a/experimental/skottie/SkottieAnimator.cpp +++ b/experimental/skottie/SkottieAnimator.cpp @@ -16,6 +16,18 @@ SkScalar lerp_scalar(float v0, float v1, float t) { return v0 * (1 - t) + v1 * t; } +static inline SkPoint ParsePoint(const Json::Value& v, const SkPoint& defaultValue) { + if (!v.isObject()) + return defaultValue; + + const auto& vx = v["x"]; + const auto& vy = v["y"]; + + // Some BM versions seem to store x/y as single-element arrays. + return SkPoint::Make(ParseScalar(vx.isArray() ? vx[0] : vx, defaultValue.x()), + ParseScalar(vy.isArray() ? vy[0] : vy, defaultValue.y())); +} + } // namespace bool KeyframeIntervalBase::parse(const Json::Value& k, KeyframeIntervalBase* prev) { diff --git a/experimental/skottie/SkottiePriv.h b/experimental/skottie/SkottiePriv.h index 0d047c5d37..663a3f3d4c 100644 --- a/experimental/skottie/SkottiePriv.h +++ b/experimental/skottie/SkottiePriv.h @@ -37,13 +37,6 @@ static inline bool ParseBool(const Json::Value& v, bool defaultValue) { ? v.asBool() : defaultValue; } -static inline SkPoint ParsePoint(const Json::Value& v, const SkPoint& defaultValue) { - return v.isObject() - ? SkPoint::Make(ParseScalar(v["x"], defaultValue.x()), - ParseScalar(v["y"], defaultValue.y())) - : defaultValue; -} - } // namespace #endif // SkottiePriv_DEFINED -- cgit v1.2.3