scratched on the wall for all to see

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.

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

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-ch

lironess- 09:57 pmBack in the stone age when I programmed in Basic I did a black jack program. I had the pc (16k Ha!) look for a group of numbers that corresponded to suit so the max number of calculations to find the card was 14 instead of 52. Don't know if this applies but thought I would toss it at you:)

Link - Reply