From 8e8fa77d3613415fe54ed6cc0cd967a032090d0b Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Sun, 13 Jun 2021 16:46:22 +0000 Subject: [PATCH] Slight optimization for AA passes. --- bemani/format/afp/blend/blend.py | 7 ++++++- bemani/format/afp/blend/blendcppimpl.cxx | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bemani/format/afp/blend/blend.py b/bemani/format/afp/blend/blend.py index d4cc893..09d29d9 100644 --- a/bemani/format/afp/blend/blend.py +++ b/bemani/format/afp/blend/blend.py @@ -453,8 +453,13 @@ def pixel_renderer( # blend to ensure that partial transparency pixel values don't unnecessarily factor # into average calculations. texoff = (aax + (aay * texwidth)) * 4 - apercent = texbytes[texoff + 3] / 255.0 + # If this is a fully transparent pixel, the below formulas work out to adding nothing + # so we should skip this altogether. + if texbytes[texoff + 3] == 0: + continue + + apercent = texbytes[texoff + 3] / 255.0 r += int(texbytes[texoff] * apercent) g += int(texbytes[texoff + 1] * apercent) b += int(texbytes[texoff + 2] * apercent) diff --git a/bemani/format/afp/blend/blendcppimpl.cxx b/bemani/format/afp/blend/blendcppimpl.cxx index ee86316..ead3deb 100644 --- a/bemani/format/afp/blend/blendcppimpl.cxx +++ b/bemani/format/afp/blend/blendcppimpl.cxx @@ -294,8 +294,14 @@ extern "C" // blend to ensure that partial transparency pixel values don't unnecessarily factor // into average calculations. unsigned int texoff = aax + (aay * work->texwidth); - float apercent = work->texdata[texoff].a / 255.0; + // If this is a fully transparent pixel, the below formulas work out to adding nothing + // so we should skip this altogether. + if (work->texdata[texoff].a == 0) { + continue; + } + + float apercent = work->texdata[texoff].a / 255.0; r += (int)(work->texdata[texoff].r * apercent); g += (int)(work->texdata[texoff].g * apercent); b += (int)(work->texdata[texoff].b * apercent);