lottie: Fine-tune for post-processing effect.

reduce quality for the post-processing effect to
improve general performance, while fine-tuning the quality
for lower resolutions.
This commit is contained in:
Hermet Park 2024-10-09 15:55:47 +09:00 committed by Hermet Park
parent 4feab345fb
commit 8cdc0da1e2
2 changed files with 14 additions and 7 deletions

View file

@ -1205,7 +1205,7 @@ void LottieBuilder::updateEffect(LottieLayer* layer, float frameNo)
switch ((*ef)->type) { switch ((*ef)->type) {
case LottieEffect::GaussianBlur: { case LottieEffect::GaussianBlur: {
auto effect = static_cast<LottieGaussianBlur*>(*ef); auto effect = static_cast<LottieGaussianBlur*>(*ef);
layer->scene->push(SceneEffect::GaussianBlur, sqrt(effect->blurness(frameNo)), effect->direction(frameNo) - 1, effect->wrap(frameNo), 50); layer->scene->push(SceneEffect::GaussianBlur, sqrt(effect->blurness(frameNo)), effect->direction(frameNo) - 1, effect->wrap(frameNo), 25);
break; break;
} }
default: break; default: break;

View file

@ -109,11 +109,13 @@ static void _gaussianBlur(uint8_t* src, uint8_t* dst, int32_t stride, int32_t w,
static int _gaussianInit(int* kernel, float sigma, int level) static int _gaussianInit(int* kernel, float sigma, int level)
{ {
const auto MAX_LEVEL = SwGaussianBlur::MAX_LEVEL;
//compute the kernel //compute the kernel
auto wl = (int) sqrt((12 * sigma / level) + 1); auto wl = (int) sqrt((12 * sigma / MAX_LEVEL) + 1);
if (wl % 2 == 0) --wl; if (wl % 2 == 0) --wl;
auto wu = wl + 2; auto wu = wl + 2;
auto mi = (12 * sigma - level * wl * wl - 4 * level * wl - 3 * level) / (-4 * wl - 4); auto mi = (12 * sigma - MAX_LEVEL * wl * wl - 4 * MAX_LEVEL * wl - 3 * MAX_LEVEL) / (-4 * wl - 4);
auto m = int(mi + 0.5f); auto m = int(mi + 0.5f);
auto extends = 0; auto extends = 0;
@ -169,13 +171,17 @@ bool effectGaussianBlur(SwImage& image, SwImage& buffer, const SwBBox& bbox, con
auto back = buffer.buf8; auto back = buffer.buf8;
auto swapped = false; auto swapped = false;
//fine-tuning for low-quality (experimental)
auto threshold = (std::min(w, h) < 300) ? 2 : 1;
TVGLOG("SW_ENGINE", "GaussianFilter region(%ld, %ld, %ld, %ld) params(%f %d %d), level(%d)", bbox.min.x, bbox.min.y, bbox.max.x, bbox.max.y, params->sigma, params->direction, params->border, data->level); TVGLOG("SW_ENGINE", "GaussianFilter region(%ld, %ld, %ld, %ld) params(%f %d %d), level(%d)", bbox.min.x, bbox.min.y, bbox.max.x, bbox.max.y, params->sigma, params->direction, params->border, data->level);
//horizontal //horizontal
if (params->direction == 0 || params->direction == 1) { if (params->direction == 0 || params->direction == 1) {
for (int i = 0; i < data->level; ++i) { for (int i = 0; i < data->level; ++i) {
if (data->kernel[i] == 0) continue; auto k = data->kernel[i] / threshold;
_gaussianBlur(front, back, stride, w, h, bbox, data->kernel[i], params->border, false); if (k == 0) continue;
_gaussianBlur(front, back, stride, w, h, bbox, k, params->border, false);
std::swap(front, back); std::swap(front, back);
swapped = !swapped; swapped = !swapped;
} }
@ -187,8 +193,9 @@ bool effectGaussianBlur(SwImage& image, SwImage& buffer, const SwBBox& bbox, con
std::swap(front, back); std::swap(front, back);
for (int i = 0; i < data->level; ++i) { for (int i = 0; i < data->level; ++i) {
if (data->kernel[i] == 0) continue; auto k = data->kernel[i] / threshold;
_gaussianBlur(front, back, stride, h, w, bbox, data->kernel[i], params->border, true); if (k == 0) continue;
_gaussianBlur(front, back, stride, h, w, bbox, k, params->border, true);
std::swap(front, back); std::swap(front, back);
swapped = !swapped; swapped = !swapped;
} }