diff --git a/src/examples/images/test.tvg b/src/examples/images/test.tvg index 80e55768..5a61851b 100644 Binary files a/src/examples/images/test.tvg and b/src/examples/images/test.tvg differ diff --git a/src/loaders/tvg/tvgTvgLoadParser.cpp b/src/loaders/tvg/tvgTvgLoadParser.cpp index ee2540dd..7979fb2f 100644 --- a/src/loaders/tvg/tvgTvgLoadParser.cpp +++ b/src/loaders/tvg/tvgTvgLoadParser.cpp @@ -176,21 +176,30 @@ static bool _parseScene(TvgBinBlock block, Paint *paint) static bool _parseShapePath(const char *ptr, const char *end, Shape *shape) { - //Shape Path 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; - ptr += SIZE(PathCommand) * cmdCnt; - const Point* pts = (Point*) ptr; + READ_UI32(&cmdCnt, ptr); + ptr += SIZE(cmdCnt); + + READ_UI32(&ptsCnt, ptr); + ptr += SIZE(ptsCnt); + + auto cmds = (TvgBinFlag*) ptr; + ptr += SIZE(TvgBinFlag) * cmdCnt; + + auto pts = (Point*) ptr; ptr += SIZE(Point) * ptsCnt; 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(cmds[i]); + } + + shape->appendPath(inCmds, cmdCnt, pts, ptsCnt); + return true; } diff --git a/src/savers/tvg/tvgTvgSaver.cpp b/src/savers/tvg/tvgTvgSaver.cpp index 5a8ed420..131d9b5c 100644 --- a/src/savers/tvg/tvgTvgSaver.cpp +++ b/src/savers/tvg/tvgTvgSaver.cpp @@ -273,9 +273,16 @@ TvgBinCounter TvgSaver::serializePath(const Shape* shape) writeTag(TVG_TAG_SHAPE_PATH); 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(cmds[i]); + } + auto cnt = writeData(&cmdCnt, SIZE(cmdCnt)); cnt += writeData(&ptsCnt, SIZE(ptsCnt)); - cnt += writeData(cmds, cmdCnt * SIZE(cmds[0])); + cnt += writeData(outCmds, SIZE(outCmds)); cnt += writeData(pts, ptsCnt * SIZE(pts[0])); writeReservedCount(cnt);