summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsubhransu mohanty <sub.mohanty@samsung.com>2017-12-19 17:50:00 +0900
committersubhransu mohanty <sub.mohanty@samsung.com>2018-04-12 13:51:52 +0900
commitda02dc48e9706ee22d991120354d793d322c6faf (patch)
treec83ef03166b1c3bc7e2a6f574129e272aa509eeb
parentc4c8bdf944b0ed200c85aced3da4c29f241a2fe8 (diff)
lottie: add a visitor to process repeater object.
-rw-r--r--ssg/example/main.cpp2
-rwxr-xr-xssg/example/withrepeater.json1
-rw-r--r--ssg/src/lottie/lottiemodel.cpp46
-rw-r--r--ssg/src/lottie/lottiemodel.h8
-rw-r--r--ssg/src/lottie/lottieparser.cpp33
5 files changed, 76 insertions, 14 deletions
diff --git a/ssg/example/main.cpp b/ssg/example/main.cpp
index 84f8db0815..5e2398ef9a 100644
--- a/ssg/example/main.cpp
+++ b/ssg/example/main.cpp
@@ -14,7 +14,7 @@ using namespace std;
14int main() 14int main()
15{ 15{
16 std::string filepath = DEMO_DIR; 16 std::string filepath = DEMO_DIR;
17 filepath += "LightBulb.json"; 17 filepath += "withrepeater.json";
18 initialize(GuaranteedLogger(), "/tmp/", "ssglog", 1); 18 initialize(GuaranteedLogger(), "/tmp/", "ssglog", 1);
19 set_log_level(LogLevel::INFO); 19 set_log_level(LogLevel::INFO);
20 //SGJson json; 20 //SGJson json;
diff --git a/ssg/example/withrepeater.json b/ssg/example/withrepeater.json
new file mode 100755
index 0000000000..8d59673ca4
--- /dev/null
+++ b/ssg/example/withrepeater.json
@@ -0,0 +1 @@
{"v":"5.0.5","fr":60,"ip":0,"op":30,"w":500,"h":500,"nm":"Comp 1","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Shape Layer 1","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[250,250,0],"ix":2},"a":{"a":0,"k":[2,0,0],"ix":1},"s":{"a":0,"k":[381.25,412.5,100],"ix":6}},"ao":0,"shapes":[{"ty":"rc","d":1,"s":{"a":0,"k":[15,15],"ix":2},"p":{"a":0,"k":[-52.6,35],"ix":3},"r":{"a":0,"k":0,"ix":4},"nm":"Rectangle Path 1","mn":"ADBE Vector Shape - Rect","hd":false},{"ty":"gr","it":[{"ty":"gr","it":[{"d":1,"ty":"el","s":{"a":0,"k":[13,13],"ix":2},"p":{"a":0,"k":[-30,0],"ix":3},"nm":"Ellipse Path 1","mn":"ADBE Vector Shape - Ellipse","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 1","np":1,"cix":2,"ix":1,"mn":"ADBE Vector Group","hd":false},{"ty":"rc","d":1,"s":{"a":0,"k":[27,27],"ix":2},"p":{"a":0,"k":[6,-31],"ix":3},"r":{"a":0,"k":0,"ix":4},"nm":"Rectangle Path 2","mn":"ADBE Vector Shape - Rect","hd":false},{"ty":"fl","c":{"a":0,"k":[0.149019613862,0.031372550875,0.964705884457,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"nm":"Fill 2","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"rp","c":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":0,"s":[4],"e":[8]},{"t":8}],"ix":1},"o":{"a":0,"k":0,"ix":2},"m":2,"ix":4,"tr":{"ty":"tr","p":{"a":0,"k":[0,2],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[84,84],"ix":3},"r":{"a":0,"k":14,"ix":4},"so":{"a":0,"k":100,"ix":5},"eo":{"a":0,"k":100,"ix":6},"nm":"Transform"},"nm":"Repeater 1","mn":"ADBE Vector Filter - Repeater","hd":false},{"ty":"tm","s":{"a":0,"k":0,"ix":1},"e":{"a":0,"k":72,"ix":2},"o":{"a":0,"k":0,"ix":3},"m":1,"ix":5,"nm":"Trim Paths 1","mn":"ADBE Vector Filter - Trim","hd":false},{"ty":"rc","d":1,"s":{"a":0,"k":[100,100],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"r":{"a":0,"k":0,"ix":4},"nm":"Rectangle Path 1","mn":"ADBE Vector Shape - Rect","hd":false},{"ty":"fl","c":{"a":0,"k":[1,0,0,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[92,92],"ix":3},"r":{"a":0,"k":351,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 1","np":7,"cix":2,"ix":2,"mn":"ADBE Vector Group","hd":false},{"ty":"fl","c":{"a":0,"k":[1,0.113725490868,0.592156887054,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"rp","c":{"a":0,"k":58,"ix":1},"o":{"a":0,"k":0,"ix":2},"m":1,"ix":4,"tr":{"ty":"tr","p":{"a":0,"k":[37,0],"ix":2},"a":{"a":0,"k":[0,-1],"ix":1},"s":{"a":0,"k":[52,52],"ix":3},"r":{"a":0,"k":6,"ix":4},"so":{"a":0,"k":100,"ix":5},"eo":{"a":0,"k":100,"ix":6},"nm":"Transform"},"nm":"Repeater 1","mn":"ADBE Vector Filter - Repeater","hd":false}],"ip":0,"op":30,"st":0,"bm":0}],"markers":[]} \ No newline at end of file
diff --git a/ssg/src/lottie/lottiemodel.cpp b/ssg/src/lottie/lottiemodel.cpp
index 0cd113ba30..8ca0f69c92 100644
--- a/ssg/src/lottie/lottiemodel.cpp
+++ b/ssg/src/lottie/lottiemodel.cpp
@@ -1,5 +1,51 @@
1#include "lottiemodel.h" 1#include "lottiemodel.h"
2 2
3
4class LottieRepeaterProcesser : public LottieObjectVisitor
5{
6public:
7 LottieRepeaterProcesser():mRepeaterFound(false){}
8 void visit(LottieComposition *obj) {}
9 void visit(LottieLayer *obj) {}
10 void visit(LottieTransform *) {}
11 void visit(LottieShapeGroup *obj) {}
12 void visit(LottieShapeObject *) {}
13 void visit(LottieRectObject *) {}
14 void visit(LottieEllipseObject *) {}
15 void visit(LottieTrimObject *) {}
16 void visit(LottieRepeaterObject *) { mRepeaterFound = true;}
17 void visit(LottieFillObject *) {}
18 void visit(LottieStrokeObject *) {}
19 void visitChildren(LottieGroupObject *obj) {
20 for(auto child :obj->mChildren) {
21 child->accept(this);
22 if (mRepeaterFound) {
23 LottieRepeaterObject *repeater = static_cast<LottieRepeaterObject *>(child);
24 LottieShapeGroup *shapeGroup = new LottieShapeGroup();
25 repeater->mChildren.push_back(shapeGroup);
26 // copy all the child of the object till repeater and
27 // move that in to a group and then add that group to
28 // the repeater object.
29 for(auto cpChild :obj->mChildren) {
30 if (cpChild == child)
31 break;
32 shapeGroup->mChildren.push_back(cpChild->copy());
33 }
34 mRepeaterFound = false;
35 }
36 }
37 }
38public:
39 bool mRepeaterFound;
40};
41
42
43void LottieComposition::processRepeaterObjects()
44{
45 LottieRepeaterProcesser visitor;
46 accept(&visitor);
47}
48
3/* 49/*
4 * makes a deep copy of the object as well as all its children 50 * makes a deep copy of the object as well as all its children
5 * 51 *
diff --git a/ssg/src/lottie/lottiemodel.h b/ssg/src/lottie/lottiemodel.h
index f9893703d5..609d502c8c 100644
--- a/ssg/src/lottie/lottiemodel.h
+++ b/ssg/src/lottie/lottiemodel.h
@@ -130,6 +130,7 @@ public:
130 Trim, 130 Trim,
131 Repeater 131 Repeater
132 }; 132 };
133 inline LottieObject::Type type() const {return mType;}
133 virtual void accept(LottieObjectVisitor *){} 134 virtual void accept(LottieObjectVisitor *){}
134 virtual ~LottieObject(){} 135 virtual ~LottieObject(){}
135 LottieObject(LottieObject::Type type): mType(type){} 136 LottieObject(LottieObject::Type type): mType(type){}
@@ -166,6 +167,7 @@ class LottieTransform;
166class LottieComposition : public LottieGroupObject 167class LottieComposition : public LottieGroupObject
167{ 168{
168public: 169public:
170 void processRepeaterObjects();
169 void accept(LottieObjectVisitor *visitor) override 171 void accept(LottieObjectVisitor *visitor) override
170 {visitor->visit(this); visitor->visitChildren(this);} 172 {visitor->visit(this); visitor->visitChildren(this);}
171 LottieComposition():LottieGroupObject(LottieObject::Type::Composition){} 173 LottieComposition():LottieGroupObject(LottieObject::Type::Composition){}
@@ -341,12 +343,12 @@ public:
341 LottieTrimObject::TrimType mTrimType; 343 LottieTrimObject::TrimType mTrimType;
342}; 344};
343 345
344class LottieRepeaterObject : public LottieObject 346class LottieRepeaterObject : public LottieGroupObject
345{ 347{
346public: 348public:
347 void accept(LottieObjectVisitor *visitor) final 349 void accept(LottieObjectVisitor *visitor) final
348 {visitor->visit(this);} 350 {visitor->visit(this); visitor->visitChildren(this);}
349 LottieRepeaterObject():LottieObject(LottieObject::Type::Repeater), 351 LottieRepeaterObject():LottieGroupObject(LottieObject::Type::Repeater),
350 mCopies(0), 352 mCopies(0),
351 mOffset(0), 353 mOffset(0),
352 mTransform(nullptr){} 354 mTransform(nullptr){}
diff --git a/ssg/src/lottie/lottieparser.cpp b/ssg/src/lottie/lottieparser.cpp
index 086b72cdb1..443f287d25 100644
--- a/ssg/src/lottie/lottieparser.cpp
+++ b/ssg/src/lottie/lottieparser.cpp
@@ -467,7 +467,6 @@ void LottieParser::parseLayers(LottieComposition *composition)
467LottieLayer * LottieParser::parseLayer() 467LottieLayer * LottieParser::parseLayer()
468{ 468{
469 RAPIDJSON_ASSERT(PeekType() == kObjectType); 469 RAPIDJSON_ASSERT(PeekType() == kObjectType);
470 //sgDebug<<"parse LAYER: S";
471 LottieLayer *layer = new LottieLayer(); 470 LottieLayer *layer = new LottieLayer();
472 EnterObject(); 471 EnterObject();
473 while (const char* key = NextObjectKey()) { 472 while (const char* key = NextObjectKey()) {
@@ -507,19 +506,16 @@ LottieLayer * LottieParser::parseLayer()
507 Skip(key); 506 Skip(key);
508 } 507 }
509 } 508 }
510 //sgDebug<<"parse LAYER: E";
511 return layer; 509 return layer;
512} 510}
513 511
514void LottieParser::parseShapesAttr(LottieLayer *layer) 512void LottieParser::parseShapesAttr(LottieLayer *layer)
515{ 513{
516 //sgDebug<<"ENTER SHAPE ATTR";
517 RAPIDJSON_ASSERT(PeekType() == kArrayType); 514 RAPIDJSON_ASSERT(PeekType() == kArrayType);
518 EnterArray(); 515 EnterArray();
519 while (NextArrayValue()) { 516 while (NextArrayValue()) {
520 parseObject(layer); 517 parseObject(layer);
521 } 518 }
522 //sgDebug<<"EXIT SHAPE ATTR";
523} 519}
524 520
525LottieObject* 521LottieObject*
@@ -543,6 +539,8 @@ LottieParser::parseObjectTypeAttr()
543 return parseShapeObject(); 539 return parseShapeObject();
544 } else if (0 == strcmp(type, "tm")) { 540 } else if (0 == strcmp(type, "tm")) {
545 return parseTrimObject(); 541 return parseTrimObject();
542 } else if (0 == strcmp(type, "rp")) {
543 return parseReapeaterObject();
546 } else { 544 } else {
547 sgDebug<<"The Object Type not yet handled = "<< type; 545 sgDebug<<"The Object Type not yet handled = "<< type;
548 return nullptr; 546 return nullptr;
@@ -604,7 +602,7 @@ LottieParser::parseRectObject()
604 Skip(key); 602 Skip(key);
605 } 603 }
606 } 604 }
607 return nullptr; 605 return obj;
608} 606}
609 607
610/* 608/*
@@ -632,7 +630,6 @@ LottieParser::parseEllipseObject()
632LottieObject * 630LottieObject *
633LottieParser::parseShapeObject() 631LottieParser::parseShapeObject()
634{ 632{
635 //sgDebug<<"parse Shape START:";
636 LottieShapeObject *obj = new LottieShapeObject(); 633 LottieShapeObject *obj = new LottieShapeObject();
637 while (const char* key = NextObjectKey()) { 634 while (const char* key = NextObjectKey()) {
638 if (0 == strcmp(key, "ks")) { 635 if (0 == strcmp(key, "ks")) {
@@ -644,7 +641,6 @@ LottieParser::parseShapeObject()
644 Skip(key); 641 Skip(key);
645 } 642 }
646 } 643 }
647 //sgDebug<<"parse Shape item END:";
648 obj->process(); 644 obj->process();
649 return obj; 645 return obj;
650} 646}
@@ -850,8 +846,6 @@ void LottieParser::parseArrayValue(SGPointF &pt)
850 while (NextArrayValue()) { 846 while (NextArrayValue()) {
851 val[i++] = GetDouble(); 847 val[i++] = GetDouble();
852 } 848 }
853// sgDebug<<"Value parsed as point / size"<<i;
854
855 pt.setX(val[0]); 849 pt.setX(val[0]);
856 pt.setY(val[1]); 850 pt.setY(val[1]);
857} 851}
@@ -1151,7 +1145,7 @@ public:
1151 sgDebug<<"[SHAPE GROP: START]"; 1145 sgDebug<<"[SHAPE GROP: START]";
1152 } 1146 }
1153 void visit(LottieShapeObject *) { 1147 void visit(LottieShapeObject *) {
1154 sgDebug<<"[SHAPE: ]"; 1148 sgDebug<<"[SHAPEGROUP: ]";
1155 } 1149 }
1156 void visit(LottieRectObject *) { 1150 void visit(LottieRectObject *) {
1157 sgDebug<<"[RECT: ]"; 1151 sgDebug<<"[RECT: ]";
@@ -1174,6 +1168,22 @@ public:
1174 void visitChildren(LottieGroupObject *obj) { 1168 void visitChildren(LottieGroupObject *obj) {
1175 for(auto child :obj->mChildren) 1169 for(auto child :obj->mChildren)
1176 child->accept(this); 1170 child->accept(this);
1171 switch (obj->type()) {
1172 case LottieObject::Type::Layer:
1173 sgDebug<<"[LAYER End ]";
1174 break;
1175 case LottieObject::Type::ShapeGroup:
1176 sgDebug<<"[SHAPEGROUP End ]";
1177 break;
1178 case LottieObject::Type::Composition:
1179 sgDebug<<"[COMP End ]";
1180 break;
1181 case LottieObject::Type::Repeater:
1182 sgDebug<<"[REPEATER End ]";
1183 break;
1184 default:
1185 break;
1186 }
1177 } 1187 }
1178}; 1188};
1179 1189
@@ -1184,6 +1194,9 @@ SGJson::SGJson(const char *data)
1184 LottieComposition *comp = r.parseComposition(); 1194 LottieComposition *comp = r.parseComposition();
1185 LottieObjectInspector inspector; 1195 LottieObjectInspector inspector;
1186 comp->accept(&inspector); 1196 comp->accept(&inspector);
1197 comp->processRepeaterObjects();
1198 sgDebug<<"******** After Repeater Processing **********";
1199 comp->accept(&inspector);
1187} 1200}
1188 1201
1189RAPIDJSON_DIAG_POP 1202RAPIDJSON_DIAG_POP