loader/lottie: filled a missing gradient stroke dash body.

This commit is contained in:
Hermet Park 2023-09-05 12:08:04 +09:00 committed by Hermet Park
parent 204c87b470
commit dae6636d29
5 changed files with 27 additions and 27 deletions

View file

@ -29,8 +29,8 @@
/* Drawing Commands */ /* Drawing Commands */
/************************************************************************/ /************************************************************************/
#define NUM_PER_ROW 9 #define NUM_PER_ROW 10
#define NUM_PER_COL 9 #define NUM_PER_COL 10
#define SIZE (WIDTH/NUM_PER_ROW) #define SIZE (WIDTH/NUM_PER_ROW)
static int counter = 0; static int counter = 0;

File diff suppressed because one or more lines are too long

View file

@ -134,7 +134,6 @@ static Shape* _updateGroup(LottieGroup* parent, LottieGroup* group, int32_t fram
static Shape* _updateFill(LottieSolidFill* fill, int32_t frameNo, Shape* baseShape) static Shape* _updateFill(LottieSolidFill* fill, int32_t frameNo, Shape* baseShape)
{ {
if (fill->disabled) return nullptr;
auto color = fill->color(frameNo); auto color = fill->color(frameNo);
baseShape->fill(color.rgb[0], color.rgb[1], color.rgb[2], fill->opacity(frameNo)); baseShape->fill(color.rgb[0], color.rgb[1], color.rgb[2], fill->opacity(frameNo));
baseShape->fill(fill->rule); baseShape->fill(fill->rule);
@ -142,18 +141,17 @@ static Shape* _updateFill(LottieSolidFill* fill, int32_t frameNo, Shape* baseSha
} }
static Shape* _updateStroke(LottieSolidStroke* stroke, int32_t frameNo, Shape* baseShape) static Shape* _updateStroke(LottieStroke* stroke, int32_t frameNo, Shape* baseShape)
{ {
if (stroke->disabled) return nullptr;
baseShape->stroke(stroke->width(frameNo)); baseShape->stroke(stroke->width(frameNo));
auto color = stroke->color(frameNo);
baseShape->stroke(color.rgb[0], color.rgb[1], color.rgb[2], stroke->opacity(frameNo));
baseShape->stroke(stroke->cap); baseShape->stroke(stroke->cap);
baseShape->stroke(stroke->join); baseShape->stroke(stroke->join);
baseShape->strokeMiterlimit(stroke->miterLimit); baseShape->strokeMiterlimit(stroke->miterLimit);
if (stroke->dashattr) { if (stroke->dashattr) {
float dashes[2] = { stroke->dashSize(frameNo), stroke->dashGap(frameNo) }; float dashes[2];
dashes[0] = stroke->dashSize(frameNo);
dashes[1] = dashes[0] + stroke->dashGap(frameNo);
P(baseShape)->strokeDash(dashes, 2, stroke->dashOffset(frameNo)); P(baseShape)->strokeDash(dashes, 2, stroke->dashOffset(frameNo));
} else { } else {
baseShape->stroke(nullptr, 0); baseShape->stroke(nullptr, 0);
@ -163,24 +161,27 @@ static Shape* _updateStroke(LottieSolidStroke* stroke, int32_t frameNo, Shape* b
} }
static Shape* _updateFill(LottieGradientFill* fill, int32_t frameNo, Shape* baseShape) static Shape* _updateStroke(LottieSolidStroke* stroke, int32_t frameNo, Shape* baseShape)
{ {
baseShape->opacity(fill->opacity(frameNo)); auto color = stroke->color(frameNo);
//TODO: reuse the fill instance? baseShape->stroke(color.rgb[0], color.rgb[1], color.rgb[2], stroke->opacity(frameNo));
baseShape->fill(unique_ptr<Fill>(fill->fill(frameNo)));
baseShape->fill(fill->rule); return _updateStroke(static_cast<LottieStroke*>(stroke), frameNo, baseShape);
return nullptr;
} }
static Shape* _updateStroke(LottieGradientStroke* stroke, int32_t frameNo, Shape* baseShape) static Shape* _updateStroke(LottieGradientStroke* stroke, int32_t frameNo, Shape* baseShape)
{ {
baseShape->opacity(stroke->opacity(frameNo));
baseShape->stroke(stroke->width(frameNo));
baseShape->stroke(unique_ptr<Fill>(stroke->fill(frameNo))); baseShape->stroke(unique_ptr<Fill>(stroke->fill(frameNo)));
baseShape->stroke(stroke->cap); return _updateStroke(static_cast<LottieStroke*>(stroke), frameNo, baseShape);
baseShape->stroke(stroke->join); }
baseShape->strokeMiterlimit(stroke->miterLimit);
static Shape* _updateFill(LottieGradientFill* fill, int32_t frameNo, Shape* baseShape)
{
//TODO: reuse the fill instance?
baseShape->fill(unique_ptr<Fill>(fill->fill(frameNo)));
baseShape->fill(fill->rule);
return nullptr; return nullptr;
} }

View file

@ -61,7 +61,9 @@ struct LottieStroke
float dashSize(int32_t frameNo) float dashSize(int32_t frameNo)
{ {
return dash(1)(frameNo); auto d = dash(1)(frameNo);
if (d == 0.0f) return 0.1f;
else return d;
} }
bool dynamic() bool dynamic()
@ -82,7 +84,7 @@ struct LottieGradient
{ {
bool dynamic() bool dynamic()
{ {
if (start.frames || end.frames || opacity.frames || height.frames || angle.frames || colorStops.frames) return true; if (start.frames || end.frames || height.frames || angle.frames || colorStops.frames) return true;
return false; return false;
} }
@ -90,7 +92,6 @@ struct LottieGradient
LottiePoint start = Point{0.0f, 0.0f}; LottiePoint start = Point{0.0f, 0.0f};
LottiePoint end = Point{0.0f, 0.0f}; LottiePoint end = Point{0.0f, 0.0f};
LottieOpacity opacity = 255;
LottieFloat height = 0.0f; LottieFloat height = 0.0f;
LottieFloat angle = 0.0f; LottieFloat angle = 0.0f;
LottieColorStop colorStops; LottieColorStop colorStops;
@ -285,7 +286,6 @@ struct LottieSolidStroke : LottieObject, LottieStroke
LottieColor color = RGB24{255, 255, 255}; LottieColor color = RGB24{255, 255, 255};
LottieOpacity opacity = 255; LottieOpacity opacity = 255;
bool disabled = false; //TODO: can't replace with hidden?
}; };
@ -300,7 +300,6 @@ struct LottieSolidFill : LottieObject
LottieColor color = RGB24{255, 255, 255}; LottieColor color = RGB24{255, 255, 255};
LottieOpacity opacity = 255; LottieOpacity opacity = 255;
FillRule rule = FillRule::Winding; FillRule rule = FillRule::Winding;
bool disabled = false; //TODO: can't replace with hidden?
}; };

View file

@ -546,7 +546,7 @@ LottieSolidFill* LottieParser::parseSolidFill()
if (!strcmp(key, "nm")) fill->name = getStringCopy(); if (!strcmp(key, "nm")) fill->name = getStringCopy();
else if (!strcmp(key, "c")) parseProperty(fill->color); else if (!strcmp(key, "c")) parseProperty(fill->color);
else if (!strcmp(key, "o")) parseProperty(fill->opacity); else if (!strcmp(key, "o")) parseProperty(fill->opacity);
else if (!strcmp(key, "fillEnabled")) fill->disabled = !getBool(); else if (!strcmp(key, "fillEnabled")) fill->hidden |= !getBool();
else if (!strcmp(key, "r")) fill->rule = getFillRule(); else if (!strcmp(key, "r")) fill->rule = getFillRule();
else if (!strcmp(key, "hd")) fill->hidden = getBool(); else if (!strcmp(key, "hd")) fill->hidden = getBool();
else skip(key); else skip(key);
@ -590,7 +590,7 @@ LottieSolidStroke* LottieParser::parseSolidStroke()
else if (!strcmp(key, "ml")) stroke->miterLimit = getFloat(); else if (!strcmp(key, "ml")) stroke->miterLimit = getFloat();
else if (!strcmp(key, "nm")) stroke->name = getStringCopy(); else if (!strcmp(key, "nm")) stroke->name = getStringCopy();
else if (!strcmp(key, "hd")) stroke->hidden = getBool(); else if (!strcmp(key, "hd")) stroke->hidden = getBool();
else if (!strcmp(key, "fillEnabled")) stroke->disabled = !getBool(); else if (!strcmp(key, "fillEnabled")) stroke->hidden |= !getBool();
else if (!strcmp(key, "d")) parseStrokeDash(stroke); else if (!strcmp(key, "d")) parseStrokeDash(stroke);
else skip(key); else skip(key);
} }
@ -681,7 +681,6 @@ LottieRoundedCorner* LottieParser::parseRoundedCorner()
void LottieParser::parseGradient(LottieGradient* gradient, const char* key) void LottieParser::parseGradient(LottieGradient* gradient, const char* key)
{ {
if (!strcmp(key, "t")) gradient->id = getInt(); if (!strcmp(key, "t")) gradient->id = getInt();
else if (!strcmp(key, "o")) parseProperty(gradient->opacity);
else if (!strcmp(key, "g")) else if (!strcmp(key, "g"))
{ {
enterObject(); enterObject();