[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 <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
This commit is contained in:
Florin Malita 2018-01-22 23:27:21 -05:00 committed by Skia Commit-Bot
parent 055b0f5cb0
commit ad335bbfaf
2 changed files with 12 additions and 7 deletions

View File

@ -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) {

View File

@ -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