The expanses of WolfWings' land
scratched on the wall for all to see


February 15th, 2006
February 15th, 2006
February 15th, 2006
February 15th, 2006
February 15th, 2006

[User Picture]08:26 pm - Math-geekery Boredom...
Ever had an image set for a specific background color, that you wanted on some other background color?

Me too.

I decided to attack it from a mathematical angle.

It turned into something... mutant. Able to take two renderings with an object added, and convert that added object to an 'overlay' effect that could be toggled seamlessly on or off of the image.

But... it's still kinda slow for my tastes. Because I'm still trying to reduce the math to a fixed 'calculate alpha' approach instead of iterating through all the possible alpha values until it finds one that works.

Anyone out there feel like cracking their head against the math? I just figured this out in the last ten minutes or so, this is the basic formula set up for 0-255 integer-math images.

Test.Alpha = 1;
while (1) {
  Test.Color = (Overlay.Color - (Background.Color * (255 - Test.Alpha))) / Test.Alpha;
  if ((Test.Color >= 0) && (Test.Color <= 255))
    break;
  Test.Alpha++;
}


Color is to avoid having to repeat the same line identically for Red, Green, and Blue over and over again. It'll still be a maximum-of-alpha-needed-for-all-three-channels operation, but I'd like to avoid the 'step through all 200+ alpha values' problem this code runs into. It works wonderfully, but it's kinda obnoxious from a standpoint of effeciency.1 commentLeave a comment
?

Log in

No account? Create an account