lottie/model: revise the color stop population logic.

The omitted data must be generated with interpolation.
This change supplements that logic.
This commit is contained in:
Hermet Park 2023-09-22 19:09:30 +09:00 committed by Hermet Park
parent dc67c405f8
commit dc9e14a20f

View file

@ -94,12 +94,9 @@ struct LottieGradient
Fill::ColorStop cs; Fill::ColorStop cs;
//merge color stops //merge color stops.
uint32_t cnt = (colorStops.count > alphaCnt) ? colorStops.count : alphaCnt; for (uint32_t i = 0; i < color.input->count; ++i) {
for (uint32_t i = 0; i < cnt; ++i) {
if (cidx == clast || aidx == color.input->count) break; if (cidx == clast || aidx == color.input->count) break;
if ((*color.input)[cidx] == (*color.input)[aidx]) { if ((*color.input)[cidx] == (*color.input)[aidx]) {
cs.offset = (*color.input)[cidx]; cs.offset = (*color.input)[cidx];
cs.r = lroundf((*color.input)[cidx + 1] * 255.0f); cs.r = lroundf((*color.input)[cidx + 1] * 255.0f);
@ -113,18 +110,22 @@ struct LottieGradient
cs.r = lroundf((*color.input)[cidx + 1] * 255.0f); cs.r = lroundf((*color.input)[cidx + 1] * 255.0f);
cs.g = lroundf((*color.input)[cidx + 2] * 255.0f); cs.g = lroundf((*color.input)[cidx + 2] * 255.0f);
cs.b = lroundf((*color.input)[cidx + 3] * 255.0f); cs.b = lroundf((*color.input)[cidx + 3] * 255.0f);
cs.a = (output.count > 0) ? output.last().a : 255; //generate alpha value
if (output.count > 0) {
auto p = ((*color.input)[cidx] - output.last().offset) / ((*color.input)[aidx] - output.last().offset);
cs.a = mathLerp<uint8_t>(output.last().a, lroundf((*color.input)[aidx + 1] * 255.0f), p);
} else cs.a = 255;
cidx += 4; cidx += 4;
} else { } else {
cs.offset = (*color.input)[aidx]; cs.offset = (*color.input)[aidx];
if (output.count > 0) {
cs.r = output.last().r;
cs.g = output.last().g;
cs.b = output.last().b;
} else {
cs.r = cs.g = cs.b = 255;
}
cs.a = lroundf((*color.input)[aidx + 1] * 255.0f); cs.a = lroundf((*color.input)[aidx + 1] * 255.0f);
//generate color value
if (output.count > 0) {
auto p = ((*color.input)[aidx] - output.last().offset) / ((*color.input)[cidx] - output.last().offset);
cs.r = mathLerp<uint8_t>(output.last().r, lroundf((*color.input)[cidx + 1] * 255.0f), p);
cs.g = mathLerp<uint8_t>(output.last().g, lroundf((*color.input)[cidx + 2] * 255.0f), p);
cs.b = mathLerp<uint8_t>(output.last().b, lroundf((*color.input)[cidx + 3] * 255.0f), p);
} else cs.r = cs.g = cs.b = 255;
aidx += 2; aidx += 2;
} }
output.push(cs); output.push(cs);
@ -140,17 +141,16 @@ struct LottieGradient
output.push(cs); output.push(cs);
cidx += 4; cidx += 4;
} }
//alpha remains //alpha remains
while (aidx < color.input->count) { while (aidx < color.input->count) {
cs.offset = (*color.input)[aidx]; cs.offset = (*color.input)[aidx];
cs.a = lroundf((*color.input)[aidx + 1] * 255.0f);
if (output.count > 0) { if (output.count > 0) {
cs.r = output.last().r; cs.r = output.last().r;
cs.g = output.last().g; cs.g = output.last().g;
cs.b = output.last().b; cs.b = output.last().b;
} else { } else cs.r = cs.g = cs.b = 255;
cs.r = cs.g = cs.b = 255;
}
cs.a = lroundf((*color.input)[aidx + 1] * 255.0f);
output.push(cs); output.push(cs);
aidx += 2; aidx += 2;
} }