From: Hermet Park Date: Thu, 29 Jul 2021 11:25:49 +0000 (+0900) Subject: tvg_format: optimize data format X-Git-Tag: submit/tizen/20210804.055919~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=419f64e29e62bee651906bc4ff9f9a135da805eb;p=platform%2Fcore%2Fgraphics%2Ftizenvg.git 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 --- diff --git a/src/examples/images/test.tvg b/src/examples/images/test.tvg index 80e5576..5a61851 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 ee2540d..7979fb2 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); + ptr += SIZE(cmdCnt); + READ_UI32(&ptsCnt, ptr); - ptr += SIZE(uint32_t); + ptr += SIZE(ptsCnt); - const PathCommand* cmds = (PathCommand*) ptr; - ptr += SIZE(PathCommand) * cmdCnt; - const Point* pts = (Point*) ptr; + 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 5a8ed42..131d9b5 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);