tvg: revise the tvg binary format for 1.0 release

- The TVG binary format now consistently compresses the data.
- Removed redundant internal properties as part of this change.

Please note that this change will break compatibility with the TVG file format from version 1.0 onward.

Issue: https://github.com/thorvg/thorvg/issues/1372
This commit is contained in:
Hermet Park 2023-11-01 14:48:28 +09:00 committed by Hermet Park
parent d879e56856
commit d3c60955fa
53 changed files with 12 additions and 33 deletions

View file

@ -1,6 +1,7 @@
source_file = [
'tvgArray.h',
'tvgBezier.h',
'tvgFormat.h',
'tvgCompressor.h',
'tvgList.h',
'tvgMath.h',

View file

@ -20,8 +20,8 @@
* SOFTWARE.
*/
#ifndef _TVG_BINARY_DESC_H_
#define _TVG_BINARY_DESC_H_
#ifndef _TVG_FORMAT_H_
#define _TVG_FORMAT_H_
/* TODO: Need to consider whether uin8_t is enough size for extension...
Rather than optimal data, we can use enough size and data compress? */
@ -36,7 +36,7 @@ using TvgBinFlag = TvgBinByte;
#define TVG_HEADER_SIZE 33 //TVG_HEADER_SIGNATURE_LENGTH + TVG_HEADER_VERSION_LENGTH + 2*SIZE(float) + TVG_HEADER_RESERVED_LENGTH + TVG_HEADER_COMPRESS_SIZE
#define TVG_HEADER_SIGNATURE "ThorVG"
#define TVG_HEADER_SIGNATURE_LENGTH 6
#define TVG_HEADER_VERSION "001100" //Major 00, Minor 11, Micro 00
#define TVG_HEADER_VERSION "010000" //Major 01, Minor 00, Micro 00
#define TVG_HEADER_VERSION_LENGTH 6
#define TVG_HEADER_RESERVED_LENGTH 1 //Storing flags for extensions
#define TVG_HEADER_COMPRESS_SIZE 12 //TVG_HEADER_UNCOMPRESSED_SIZE + TVG_HEADER_COMPRESSED_SIZE + TVG_HEADER_COMPRESSED_SIZE_BITS
@ -60,11 +60,6 @@ using TvgBinFlag = TvgBinByte;
#define TVG_TAG_PAINT_CMP_METHOD (TvgBinTag)0x20
//TODO: Keep this for the compatibility, Remove in TVG 1.0 release
//Scene
#define TVG_TAG_SCENE_RESERVEDCNT (TvgBinTag)0x30
//Shape
#define TVG_TAG_SHAPE_PATH (TvgBinTag)0x40
#define TVG_TAG_SHAPE_STROKE (TvgBinTag)0x41
@ -97,4 +92,4 @@ using TvgBinFlag = TvgBinByte;
#define TVG_TAG_PICTURE_RAW_IMAGE (TvgBinTag)0x70
#define TVG_TAG_PICTURE_MESH (TvgBinTag)0x71
#endif //_TVG_BINARY_DESC_H_
#endif //_TVG_FORMAT_H_

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -110,16 +110,6 @@ static bool _parseScene(TvgBinBlock block, Paint *paint)
{
auto scene = static_cast<Scene*>(paint);
//TODO: Keep this for the compatibility, Remove in TVG 1.0 release
//Case1: scene reserve count
if (block.type == TVG_TAG_SCENE_RESERVEDCNT) {
if (block.length != SIZE(uint32_t)) return false;
uint32_t reservedCnt;
READ_UI32(&reservedCnt, block.data);
//scene->reserve(reservedCnt);
return true;
}
//Case2: Base Paint Properties
if (_parsePaintProperty(block, scene)) return true;

View file

@ -24,7 +24,7 @@
#define _TVG_TVG_COMMON_H_
#include "tvgCommon.h"
#include "tvgBinaryDesc.h"
#include "tvgFormat.h"
#define SIZE(A) sizeof(A)
#define READ_UI32(dst, src) memcpy(dst, (src), sizeof(uint32_t))

View file

@ -15,7 +15,6 @@ endif
source_file = [
'tvgCanvas.h',
'tvgCommon.h',
'tvgBinaryDesc.h',
'tvgFill.h',
'tvgFrameModule.h',
'tvgLoader.h',

View file

@ -378,7 +378,7 @@ TvgBinCounter TvgSaver::serializeScene(const Scene* scene, const Matrix* pTransf
//Case - Delegator Scene: This scene is just a delegator, we can skip this:
if (scene->composite(nullptr) == CompositeMethod::None && scene->opacity() == 255) {
auto ret = serializeChildren(it, cTransform, false);
auto ret = serializeChildren(it, cTransform);
delete(it);
return ret;
}
@ -387,7 +387,7 @@ TvgBinCounter TvgSaver::serializeScene(const Scene* scene, const Matrix* pTransf
writeTag(TVG_TAG_CLASS_SCENE);
reserveCount();
auto cnt = serializeChildren(it, cTransform, true) + serializePaint(scene, pTransform);
auto cnt = serializeChildren(it, cTransform) + serializePaint(scene, pTransform);
delete(it);
@ -609,7 +609,7 @@ TvgBinCounter TvgSaver::serializePicture(const Picture* picture, const Matrix* p
} else {
writeTag(TVG_TAG_CLASS_SCENE);
reserveCount();
auto cnt = serializeChildren(it, cTransform, true) + serializePaint(picture, pTransform);
auto cnt = serializeChildren(it, cTransform) + serializePaint(picture, pTransform);
writeReservedCount(cnt);
delete(it);
return SERIAL_DONE(cnt);
@ -678,7 +678,7 @@ TvgBinCounter TvgSaver::serializeComposite(const Paint* cmpTarget, CompositeMeth
}
TvgBinCounter TvgSaver::serializeChildren(Iterator* it, const Matrix* pTransform, bool reserved)
TvgBinCounter TvgSaver::serializeChildren(Iterator* it, const Matrix* pTransform)
{
TvgBinCounter cnt = 0;
@ -700,12 +700,6 @@ TvgBinCounter TvgSaver::serializeChildren(Iterator* it, const Matrix* pTransform
children.push(child);
}
//TODO: Keep this for the compatibility, Remove in TVG 1.0 release
//The children of a reserved scene
if (reserved && children.count > 1) {
cnt += writeTagProperty(TVG_TAG_SCENE_RESERVEDCNT, SIZE(children.count), &children.count);
}
//Serialize merged children.
auto child = children.data;
for (uint32_t i = 0; i < children.count; ++i, ++child) {

View file

@ -24,7 +24,7 @@
#define _TVG_TVGSAVER_H_
#include "tvgArray.h"
#include "tvgBinaryDesc.h"
#include "tvgFormat.h"
#include "tvgTaskScheduler.h"
namespace tvg
@ -61,7 +61,7 @@ private:
TvgBinCounter serializeStroke(const Shape* shape, const Matrix* pTransform, bool preTransform);
TvgBinCounter serializePath(const Shape* shape, const Matrix* transform, bool preTransform);
TvgBinCounter serializeComposite(const Paint* cmpTarget, CompositeMethod cmpMethod, const Matrix* pTransform);
TvgBinCounter serializeChildren(Iterator* it, const Matrix* transform, bool reserved);
TvgBinCounter serializeChildren(Iterator* it, const Matrix* transform);
TvgBinCounter serializeChild(const Paint* parent, const Paint* child, const Matrix* pTransform);
public:

Binary file not shown.

Binary file not shown.