saver/loader tvg: support picture mesh properties.

this mesh properites newly introduced in v0.8
(see: 3dd65dfed0)

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

@Issue: https://github.com/Samsung/thorvg/issues/1242
This commit is contained in:
Hermet Park 2022-12-07 16:20:47 +09:00
parent dc583325b3
commit d958fc7971
4 changed files with 50 additions and 17 deletions

Binary file not shown.

View 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_

View file

@ -357,8 +357,8 @@ static bool _parsePicture(TvgBinBlock block, Paint* paint)
{
auto picture = static_cast<Picture*>(paint);
//Case1: Image Picture
if (block.type == TVG_TAG_PICTURE_RAW_IMAGE) {
switch (block.type) {
case TVG_TAG_PICTURE_RAW_IMAGE: {
if (block.length < 2 * SIZE(uint32_t)) return false;
auto ptr = block.data;
@ -373,11 +373,29 @@ static bool _parsePicture(TvgBinBlock block, Paint* paint)
if (block.length != 2 * SIZE(uint32_t) + size) return false;
picture->load((uint32_t*) ptr, w, h, true);
return true;
}
case TVG_TAG_PICTURE_MESH: {
if (block.length < 1 * SIZE(uint32_t)) return false;
//Case2: Base Paint Properties
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;

View 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);