mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-20 15:03:25 +00:00
tvg_format: optimize data format
This reduces tvg binary format size by converting PathCommand to more compact size. This optimization increase +12% compress rate with our example: 195,668 => 174,071 (sum of all converted tvgs from svgs) @Issues: https://github.com/Samsung/thorvg/issues/639
This commit is contained in:
parent
a91bd37ea9
commit
e59ba67b7c
3 changed files with 26 additions and 10 deletions
Binary file not shown.
|
@ -176,21 +176,30 @@ static bool _parseScene(TvgBinBlock block, Paint *paint)
|
||||||
|
|
||||||
static bool _parseShapePath(const char *ptr, const char *end, Shape *shape)
|
static bool _parseShapePath(const char *ptr, const char *end, Shape *shape)
|
||||||
{
|
{
|
||||||
//Shape Path
|
|
||||||
uint32_t cmdCnt, ptsCnt;
|
uint32_t cmdCnt, ptsCnt;
|
||||||
READ_UI32(&cmdCnt, ptr);
|
|
||||||
ptr += SIZE(uint32_t);
|
|
||||||
READ_UI32(&ptsCnt, ptr);
|
|
||||||
ptr += SIZE(uint32_t);
|
|
||||||
|
|
||||||
const PathCommand* cmds = (PathCommand*) ptr;
|
READ_UI32(&cmdCnt, ptr);
|
||||||
ptr += SIZE(PathCommand) * cmdCnt;
|
ptr += SIZE(cmdCnt);
|
||||||
const Point* pts = (Point*) ptr;
|
|
||||||
|
READ_UI32(&ptsCnt, ptr);
|
||||||
|
ptr += SIZE(ptsCnt);
|
||||||
|
|
||||||
|
auto cmds = (TvgBinFlag*) ptr;
|
||||||
|
ptr += SIZE(TvgBinFlag) * cmdCnt;
|
||||||
|
|
||||||
|
auto pts = (Point*) ptr;
|
||||||
ptr += SIZE(Point) * ptsCnt;
|
ptr += SIZE(Point) * ptsCnt;
|
||||||
|
|
||||||
if (ptr > end) return false;
|
if (ptr > end) return false;
|
||||||
|
|
||||||
shape->appendPath(cmds, cmdCnt, pts, ptsCnt);
|
/* Recover to PathCommand(4 bytes) from TvgBinFlag(1 byte) */
|
||||||
|
PathCommand inCmds[cmdCnt];
|
||||||
|
for (uint32_t i = 0; i < cmdCnt; ++i) {
|
||||||
|
inCmds[i] = static_cast<PathCommand>(cmds[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
shape->appendPath(inCmds, cmdCnt, pts, ptsCnt);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -273,9 +273,16 @@ TvgBinCounter TvgSaver::serializePath(const Shape* shape)
|
||||||
writeTag(TVG_TAG_SHAPE_PATH);
|
writeTag(TVG_TAG_SHAPE_PATH);
|
||||||
reserveCount();
|
reserveCount();
|
||||||
|
|
||||||
|
/* Reduce the binary size.
|
||||||
|
Convert PathCommand(4 bytes) to TvgBinFlag(1 byte) */
|
||||||
|
TvgBinFlag outCmds[cmdCnt];
|
||||||
|
for (uint32_t i = 0; i < cmdCnt; ++i) {
|
||||||
|
outCmds[i] = static_cast<TvgBinFlag>(cmds[i]);
|
||||||
|
}
|
||||||
|
|
||||||
auto cnt = writeData(&cmdCnt, SIZE(cmdCnt));
|
auto cnt = writeData(&cmdCnt, SIZE(cmdCnt));
|
||||||
cnt += writeData(&ptsCnt, SIZE(ptsCnt));
|
cnt += writeData(&ptsCnt, SIZE(ptsCnt));
|
||||||
cnt += writeData(cmds, cmdCnt * SIZE(cmds[0]));
|
cnt += writeData(outCmds, SIZE(outCmds));
|
||||||
cnt += writeData(pts, ptsCnt * SIZE(pts[0]));
|
cnt += writeData(pts, ptsCnt * SIZE(pts[0]));
|
||||||
|
|
||||||
writeReservedCount(cnt);
|
writeReservedCount(cnt);
|
||||||
|
|
Loading…
Add table
Reference in a new issue