saver/loader tvg: support picture mesh properties. 89/289789/1
authorHermet Park <hermetpark@gmail.com>
Wed, 7 Dec 2022 07:20:47 +0000 (16:20 +0900)
committerMichal Szczecinski <mihashco89@gmail.com>
Tue, 14 Mar 2023 08:55:14 +0000 (09:55 +0100)
this mesh properites newly introduced in v0.8
(see: 3dd65dfed00849f0bd9d0bb0ade177fa961cd7a5)

tvg saver/loader should implement mesh support to
properly capture/replay the scene snapshot.

@Issue: https://github.com/Samsung/thorvg/issues/1242

Change-Id: Id48e50be8093c2f13d3f3b4e1112151974597928

src/lib/tvgBinaryDesc.h
src/loaders/tvg/tvgTvgBinInterpreter.cpp
src/savers/tvg/tvgTvgSaver.cpp

index f139def..bab6b79 100644 (file)
@@ -92,5 +92,6 @@ using TvgBinFlag = TvgBinByte;
 
 //Picture
 #define TVG_TAG_PICTURE_RAW_IMAGE                   (TvgBinTag)0x70
+#define TVG_TAG_PICTURE_MESH                        (TvgBinTag)0x71
 
 #endif //_TVG_BINARY_DESC_H_
index 01a39b6..ffea9d2 100644 (file)
@@ -357,27 +357,45 @@ static bool _parsePicture(TvgBinBlock block, Paint* paint)
 {
     auto picture = static_cast<Picture*>(paint);
 
-    //Case1: Image Picture
-    if (block.type == TVG_TAG_PICTURE_RAW_IMAGE) {
-        if (block.length < 2 * SIZE(uint32_t)) return false;
+    switch (block.type) {
+        case TVG_TAG_PICTURE_RAW_IMAGE: {
+            if (block.length < 2 * SIZE(uint32_t)) return false;
 
-        auto ptr = block.data;
-        uint32_t w, h;
+            auto ptr = block.data;
+            uint32_t w, h;
 
-        READ_UI32(&w, ptr);
-        ptr += SIZE(uint32_t);
-        READ_UI32(&h, ptr);
-        ptr += SIZE(uint32_t);
+            READ_UI32(&w, ptr);
+            ptr += SIZE(uint32_t);
+            READ_UI32(&h, ptr);
+            ptr += SIZE(uint32_t);
 
-        auto size = w * h * SIZE(uint32_t);
-        if (block.length != 2 * SIZE(uint32_t) + size) return false;
+            auto size = w * h * SIZE(uint32_t);
+            if (block.length != 2 * SIZE(uint32_t) + size) return false;
 
-        picture->load((uint32_t*) ptr, w, h, true);
-        return true;
-    }
+            picture->load((uint32_t*) ptr, w, h, true);
 
-    //Case2: Base Paint Properties
-    if (_parsePaintProperty(block, picture)) return true;
+            return true;
+        }
+        case TVG_TAG_PICTURE_MESH: {
+            if (block.length < 1 * SIZE(uint32_t)) return false;
+
+            auto ptr = block.data;
+            uint32_t meshCnt;
+            READ_UI32(&meshCnt, ptr);
+            ptr += SIZE(uint32_t);
+
+            auto size = meshCnt * SIZE(Polygon);
+            if (block.length != SIZE(uint32_t) + size) return false;
+
+            picture->mesh((Polygon*) ptr, meshCnt);
+
+            return true;
+        }
+        //Base Paint Properties
+        default: {
+            if (_parsePaintProperty(block, picture)) return true;
+        }
+    }
 
     //Vector Picture won't be requested since Saver replaces it with the Scene
     return false;
@@ -414,7 +432,7 @@ static Paint* _parsePaint(TvgBinBlock baseBlock)
 
     auto ptr = baseBlock.data;
 
-    //2. Read Subsquent properties of the current paint.
+    //2. Read Subsequent properties of the current paint.
     while (ptr < baseBlock.end) {
         auto block = _readBlock(ptr);
         if (block.end > baseBlock.end) return paint;
index 57a21dc..e86c377 100644 (file)
@@ -609,6 +609,20 @@ TvgBinCounter TvgSaver::serializePicture(const Picture* picture, const Matrix* p
     cnt += writeData(pixels, imgSize);
     cnt += SIZE(TvgBinTag) + SIZE(TvgBinCounter);
 
+    //mesh: currently only available in bitmap image.
+    const Polygon* triangles = nullptr;
+    auto triangleCnt = picture->mesh(&triangles);
+    if (triangles && triangleCnt > 0) {
+        TvgBinCounter triangleCntSize = SIZE(triangleCnt);
+        TvgBinCounter trianglesSize = triangleCnt * SIZE(triangles[0]);
+
+        writeTag(TVG_TAG_PICTURE_MESH);
+        writeCount(triangleCntSize + trianglesSize);
+        cnt += writeData(&triangleCnt, triangleCntSize);
+        cnt += writeData(triangles, trianglesSize);
+        cnt += SIZE(TvgBinTag) + SIZE(TvgBinCounter);
+    }
+
     //Bitmap picture needs the transform info.
     cnt += writeTransform(cTransform, TVG_TAG_PAINT_TRANSFORM);