summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsubhransu mohanty <sub.mohanty@samsung.com>2018-04-12 17:10:57 +0900
committersubhransu mohanty <sub.mohanty@samsung.com>2018-04-12 17:10:57 +0900
commitc88ab3de682f7480912f7bd956bb94915ddea34b (patch)
treec6dbd6ed736cc9fdc28f87a2b5d06d14ee368b34
parentf62e2ccccd0716312fcb8489c76bcd84fd47f6d4 (diff)
ssg:Added asset class and parsing of "asset" property for lottiedevs/subhransu/ssg
-rw-r--r--ssg/include/lottiemodel.h13
-rw-r--r--ssg/src/lottie/lottieparser.cpp53
2 files changed, 66 insertions, 0 deletions
diff --git a/ssg/include/lottiemodel.h b/ssg/include/lottiemodel.h
index a013844d8b..18be7e6b78 100644
--- a/ssg/include/lottiemodel.h
+++ b/ssg/include/lottiemodel.h
@@ -113,6 +113,7 @@ class LottieObject
113public: 113public:
114 enum class Type { 114 enum class Type {
115 Composition = 1, 115 Composition = 1,
116 Asset,
116 Layer, 117 Layer,
117 ShapeGroup, 118 ShapeGroup,
118 Transform, 119 Transform,
@@ -159,6 +160,16 @@ public:
159 std::shared_ptr<LottieObject> mTransform; 160 std::shared_ptr<LottieObject> mTransform;
160}; 161};
161 162
163class LottieLayer;
164class LottieAsset : public LottieObject
165{
166public:
167 LottieAsset():LottieObject(LottieObject::Type::Asset){}
168 int mAssetType; //lottie aset type (precomp/char/image)
169 std::string mRefId; // ref id
170 std::vector<std::shared_ptr<LottieObject>> mLayers;
171};
172
162class LottieTransform; 173class LottieTransform;
163class LottieComposition : public LottieGroupObject 174class LottieComposition : public LottieGroupObject
164{ 175{
@@ -183,6 +194,7 @@ public:
183 LottieBlendMode mBlendMode; 194 LottieBlendMode mBlendMode;
184 std::unordered_map<std::string, 195 std::unordered_map<std::string,
185 std::shared_ptr<SGInterpolator>> mInterpolatorCache; 196 std::shared_ptr<SGInterpolator>> mInterpolatorCache;
197 std::vector<std::shared_ptr<LottieAsset>> mAssets;
186}; 198};
187 199
188class LottieLayer : public LottieGroupObject 200class LottieLayer : public LottieGroupObject
@@ -202,6 +214,7 @@ public:
202 long mStartTime; 214 long mStartTime;
203 LottieBlendMode mBlendMode; 215 LottieBlendMode mBlendMode;
204 float mTimeStreatch; 216 float mTimeStreatch;
217 std::string mPreCompRefId;
205 LottieAnimatable<float> mTimeRemap; /* "tm" */ 218 LottieAnimatable<float> mTimeRemap; /* "tm" */
206 std::shared_ptr<LottieObject> mTransform; 219 std::shared_ptr<LottieObject> mTransform;
207}; 220};
diff --git a/ssg/src/lottie/lottieparser.cpp b/ssg/src/lottie/lottieparser.cpp
index add86e0f94..ff9f27ab30 100644
--- a/ssg/src/lottie/lottieparser.cpp
+++ b/ssg/src/lottie/lottieparser.cpp
@@ -136,6 +136,8 @@ public:
136 LottieTrimObject::TrimType getTrimType(); 136 LottieTrimObject::TrimType getTrimType();
137 137
138 std::shared_ptr<LottieComposition> parseComposition(); 138 std::shared_ptr<LottieComposition> parseComposition();
139 void parseAssets(LottieComposition *comp);
140 std::shared_ptr<LottieAsset> parseAsset();
139 void parseLayers(LottieComposition *comp); 141 void parseLayers(LottieComposition *comp);
140 std::shared_ptr<LottieObject> parseLayer(); 142 std::shared_ptr<LottieObject> parseLayer();
141 void parseShapesAttr(LottieLayer *layer); 143 void parseShapesAttr(LottieLayer *layer);
@@ -449,6 +451,8 @@ LottieParser::parseComposition()
449 } else if (0 == strcmp(key, "fr")) { 451 } else if (0 == strcmp(key, "fr")) {
450 RAPIDJSON_ASSERT(PeekType() == kNumberType); 452 RAPIDJSON_ASSERT(PeekType() == kNumberType);
451 comp->mFrameRate = GetDouble(); 453 comp->mFrameRate = GetDouble();
454 } else if (0 == strcmp(key, "assets")) {
455 parseAssets(comp);
452 } else if (0 == strcmp(key, "layers")) { 456 } else if (0 == strcmp(key, "layers")) {
453 parseLayers(comp); 457 parseLayers(comp);
454 } else { 458 } else {
@@ -468,6 +472,51 @@ LottieParser::parseComposition()
468 return sharedComposition; 472 return sharedComposition;
469} 473}
470 474
475void LottieParser::parseAssets(LottieComposition *composition)
476{
477 RAPIDJSON_ASSERT(PeekType() == kArrayType);
478 EnterArray();
479 while (NextArrayValue()) {
480 std::shared_ptr<LottieAsset> asset = parseAsset();
481 composition->mAssets.push_back(asset);
482 }
483}
484
485/*
486 * https://github.com/airbnb/lottie-web/blob/master/docs/json/layers/shape.json
487 *
488 */
489std::shared_ptr<LottieAsset>
490LottieParser::parseAsset()
491{
492 RAPIDJSON_ASSERT(PeekType() == kObjectType);
493 std::shared_ptr<LottieAsset> sharedAsset = std::make_shared<LottieAsset>();
494 LottieAsset *asset = sharedAsset.get();
495 EnterObject();
496 while (const char* key = NextObjectKey()) {
497 if (0 == strcmp(key, "ty")) { /* Type of layer: Shape. Value 4.*/
498 RAPIDJSON_ASSERT(PeekType() == kNumberType);
499 asset->mAssetType = GetInt();
500 } else if (0 == strcmp(key, "id")) { /* reference id*/
501 RAPIDJSON_ASSERT(PeekType() == kStringType);
502 asset->mRefId = std::string(GetString());
503 }else if (0 == strcmp(key, "layers")) {
504 RAPIDJSON_ASSERT(PeekType() == kArrayType);
505 EnterArray();
506 while (NextArrayValue()) {
507 std::shared_ptr<LottieObject> layer = parseLayer();
508 asset->mLayers.push_back(layer);
509 }
510 } else {
511 #ifdef DEBUG_PARSER
512 sgWarning<<"Asset Attribute Skipped : "<<key;
513 #endif
514 Skip(key);
515 }
516 }
517 return sharedAsset;
518}
519
471void LottieParser::parseLayers(LottieComposition *composition) 520void LottieParser::parseLayers(LottieComposition *composition)
472{ 521{
473 RAPIDJSON_ASSERT(PeekType() == kArrayType); 522 RAPIDJSON_ASSERT(PeekType() == kArrayType);
@@ -499,6 +548,10 @@ LottieParser::parseLayer()
499 } else if (0 == strcmp(key, "parent")) { /*Layer Parent. Uses "ind" of parent.*/ 548 } else if (0 == strcmp(key, "parent")) { /*Layer Parent. Uses "ind" of parent.*/
500 RAPIDJSON_ASSERT(PeekType() == kNumberType); 549 RAPIDJSON_ASSERT(PeekType() == kNumberType);
501 layer->mParentId = GetInt(); 550 layer->mParentId = GetInt();
551 } else if (0 == strcmp(key, "refId")) { /*preComp Layer reference id*/
552 RAPIDJSON_ASSERT(PeekType() == kStringType);
553 layer->mPreCompRefId = std::string(GetString());
554 //TODO update the children with the layer list from asset
502 }else if (0 == strcmp(key, "sr")) { // "Layer Time Stretching" 555 }else if (0 == strcmp(key, "sr")) { // "Layer Time Stretching"
503 RAPIDJSON_ASSERT(PeekType() == kNumberType); 556 RAPIDJSON_ASSERT(PeekType() == kNumberType);
504 layer->mTimeStreatch = GetDouble(); 557 layer->mTimeStreatch = GetDouble();