lottie: try packing data compactly.

This commit is contained in:
Hermet Park 2024-05-30 00:09:59 +09:00
parent 71e3124469
commit 1823305ea3
4 changed files with 19 additions and 23 deletions

View file

@ -1191,14 +1191,14 @@ static void _updateMaskings(LottieLayer* layer, float frameNo, LottieExpressions
static bool _updateMatte(LottieLayer* root, LottieLayer* layer, float frameNo, LottieExpressions* exps)
{
auto target = layer->matte.target;
auto target = layer->matteTarget;
if (!target) return true;
_updateLayer(root, target, frameNo, exps);
if (target->scene) {
layer->scene->composite(cast(target->scene), layer->matte.type);
} else if (layer->matte.type == CompositeMethod::AlphaMask || layer->matte.type == CompositeMethod::LumaMask) {
layer->scene->composite(cast(target->scene), layer->matteType);
} else if (layer->matteType == CompositeMethod::AlphaMask || layer->matteType == CompositeMethod::LumaMask) {
//matte target is not exist. alpha blending definitely bring an invisible result
delete(layer->scene);
layer->scene = nullptr;
@ -1228,7 +1228,7 @@ static void _updateLayer(LottieLayer* root, LottieLayer* layer, float frameNo, L
layer->scene->transform(layer->cache.matrix);
if (layer->matte.target && layer->masks.count > 0) TVGERR("LOTTIE", "FIXME: Matte + Masking??");
if (layer->matteTarget && layer->masks.count > 0) TVGERR("LOTTIE", "FIXME: Matte + Masking??");
if (!_updateMatte(root, layer, frameNo, exps)) return;
@ -1283,8 +1283,8 @@ static void _bulidHierarchy(LottieGroup* parent, LottieLayer* child)
{
if (child->pidx == -1) return;
if (child->matte.target && child->pidx == child->matte.target->idx) {
child->parent = child->matte.target;
if (child->matteTarget && child->pidx == child->matteTarget->idx) {
child->parent = child->matteTarget;
return;
}
@ -1295,8 +1295,8 @@ static void _bulidHierarchy(LottieGroup* parent, LottieLayer* child)
child->parent = parent;
break;
}
if (parent->matte.target && parent->matte.target->idx == child->pidx) {
child->parent = parent->matte.target;
if (parent->matteTarget && parent->matteTarget->idx == child->pidx) {
child->parent = parent->matteTarget;
break;
}
}
@ -1335,25 +1335,25 @@ static bool _buildComposition(LottieComposition* comp, LottieGroup* parent)
//attach the precomp layer.
if (child->rid) _buildReference(comp, child);
if (child->matte.type != CompositeMethod::None) {
if (child->matteType != CompositeMethod::None) {
//no index of the matte layer is provided: the layer above is used as the matte source
if (child->mid == -1) {
if (c > parent->children.begin()) {
child->matte.target = static_cast<LottieLayer*>(*(c - 1));
child->matteTarget = static_cast<LottieLayer*>(*(c - 1));
}
//matte layer is specified by an index.
} else {
if (auto matte = comp->layer(child->mid)) {
child->matte.target = matte;
if (auto matte = comp->layerByIdx(child->mid)) {
child->matteTarget = matte;
}
}
}
if (child->matte.target) {
if (child->matteTarget) {
//parenting
_bulidHierarchy(parent, child->matte.target);
_bulidHierarchy(parent, child->matteTarget);
//precomp referencing
if (child->matte.target->rid) _buildReference(comp, child->matte.target);
if (child->matteTarget->rid) _buildReference(comp, child->matteTarget);
}
_bulidHierarchy(parent, child);

View file

@ -351,7 +351,6 @@ LottieLayer::~LottieLayer()
delete(*m);
}
matte.target = nullptr;
delete(transform);
free(name);
}

View file

@ -541,19 +541,14 @@ struct LottieLayer : LottieGroup
void prepare();
float remap(float frameNo, LottieExpressions* exp);
struct {
CompositeMethod type = CompositeMethod::None;
LottieLayer* target = nullptr;
} matte;
char* name = nullptr;
BlendMethod blendMethod = BlendMethod::Normal;
LottieLayer* parent = nullptr;
LottieFloat timeRemap = 0.0f;
LottieComposition* comp = nullptr;
LottieTransform* transform = nullptr;
Array<LottieMask*> masks;
RGB24 color; //used by Solid layer
LottieLayer* matteTarget = nullptr;
float timeStretch = 1.0f;
float w = 0.0f, h = 0.0f;
@ -571,6 +566,8 @@ struct LottieLayer : LottieGroup
uint8_t opacity;
} cache;
CompositeMethod matteType = CompositeMethod::None;
BlendMethod blendMethod = BlendMethod::Normal;
Type type = Null;
bool autoOrient = false;
bool matteSrc = false;

View file

@ -1216,7 +1216,7 @@ LottieLayer* LottieParser::parseLayer()
else if (KEY_AS("w") || KEY_AS("sw")) getLayerSize(layer->w);
else if (KEY_AS("h") || KEY_AS("sh")) getLayerSize(layer->h);
else if (KEY_AS("sc")) layer->color = getColor(getString());
else if (KEY_AS("tt")) layer->matte.type = getMatteType();
else if (KEY_AS("tt")) layer->matteType = getMatteType();
else if (KEY_AS("tp")) layer->mid = getInt();
else if (KEY_AS("masksProperties")) parseMasks(layer);
else if (KEY_AS("hd")) layer->hidden = getBool();