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);