mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
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:
parent
dc583325b3
commit
d958fc7971
4 changed files with 50 additions and 17 deletions
Binary file not shown.
|
@ -92,5 +92,6 @@ using TvgBinFlag = TvgBinByte;
|
||||||
|
|
||||||
//Picture
|
//Picture
|
||||||
#define TVG_TAG_PICTURE_RAW_IMAGE (TvgBinTag)0x70
|
#define TVG_TAG_PICTURE_RAW_IMAGE (TvgBinTag)0x70
|
||||||
|
#define TVG_TAG_PICTURE_MESH (TvgBinTag)0x71
|
||||||
|
|
||||||
#endif //_TVG_BINARY_DESC_H_
|
#endif //_TVG_BINARY_DESC_H_
|
||||||
|
|
|
@ -357,28 +357,46 @@ static bool _parsePicture(TvgBinBlock block, Paint* paint)
|
||||||
{
|
{
|
||||||
auto picture = static_cast<Picture*>(paint);
|
auto picture = static_cast<Picture*>(paint);
|
||||||
|
|
||||||
//Case1: Image Picture
|
switch (block.type) {
|
||||||
if (block.type == TVG_TAG_PICTURE_RAW_IMAGE) {
|
case TVG_TAG_PICTURE_RAW_IMAGE: {
|
||||||
if (block.length < 2 * SIZE(uint32_t)) return false;
|
if (block.length < 2 * SIZE(uint32_t)) return false;
|
||||||
|
|
||||||
auto ptr = block.data;
|
auto ptr = block.data;
|
||||||
uint32_t w, h;
|
uint32_t w, h;
|
||||||
|
|
||||||
READ_UI32(&w, ptr);
|
READ_UI32(&w, ptr);
|
||||||
ptr += SIZE(uint32_t);
|
ptr += SIZE(uint32_t);
|
||||||
READ_UI32(&h, ptr);
|
READ_UI32(&h, ptr);
|
||||||
ptr += SIZE(uint32_t);
|
ptr += SIZE(uint32_t);
|
||||||
|
|
||||||
auto size = w * h * SIZE(uint32_t);
|
auto size = w * h * SIZE(uint32_t);
|
||||||
if (block.length != 2 * SIZE(uint32_t) + size) return false;
|
if (block.length != 2 * SIZE(uint32_t) + size) return false;
|
||||||
|
|
||||||
picture->load((uint32_t*) ptr, w, h, true);
|
picture->load((uint32_t*) ptr, w, h, true);
|
||||||
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Case2: Base Paint Properties
|
|
||||||
if (_parsePaintProperty(block, picture)) return true;
|
|
||||||
|
|
||||||
//Vector Picture won't be requested since Saver replaces it with the Scene
|
//Vector Picture won't be requested since Saver replaces it with the Scene
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -414,7 +432,7 @@ static Paint* _parsePaint(TvgBinBlock baseBlock)
|
||||||
|
|
||||||
auto ptr = baseBlock.data;
|
auto ptr = baseBlock.data;
|
||||||
|
|
||||||
//2. Read Subsquent properties of the current paint.
|
//2. Read Subsequent properties of the current paint.
|
||||||
while (ptr < baseBlock.end) {
|
while (ptr < baseBlock.end) {
|
||||||
auto block = _readBlock(ptr);
|
auto block = _readBlock(ptr);
|
||||||
if (block.end > baseBlock.end) return paint;
|
if (block.end > baseBlock.end) return paint;
|
||||||
|
|
|
@ -609,6 +609,20 @@ TvgBinCounter TvgSaver::serializePicture(const Picture* picture, const Matrix* p
|
||||||
cnt += writeData(pixels, imgSize);
|
cnt += writeData(pixels, imgSize);
|
||||||
cnt += SIZE(TvgBinTag) + SIZE(TvgBinCounter);
|
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.
|
//Bitmap picture needs the transform info.
|
||||||
cnt += writeTransform(cTransform, TVG_TAG_PAINT_TRANSFORM);
|
cnt += writeTransform(cTransform, TVG_TAG_PAINT_TRANSFORM);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue