First off, sorry for the amount of threads i’ve been posting lately.
Anyways, the issue is this:
I have a method
private static int manipulate(int t, int[] c) {
int r = (int) ((t >> 16) & 0xFF) * (c[0] / 255.0f);
int g = (int) ((t >> 8) & 0xFF) * (c[1] / 255.0f);
int b = (int) ((t & 0xFF)) * (c[2] / 255.0f);
return ((r << 16) | (g << 8) | b);
}
This method does the following, it takes in a RGB packed color ‘t’ and manipulates its brightness.
The integer array ‘c’ contains three integers ranging from 0-255 and these represent the brightness for each color channel (R, G, B)
The integers in ‘c’ get converted to their fractional values by dividing by 255.0f and then get multiplied to each color channel.
This creates a color that is either darkened, left alone, or set to black.
My problem is that this method gets called per-pixel (and is actually called even more often since the z-buffer creates overdraw) and I believe that it can be optimized.
Bit manipulation to this caliber are not something I am good with, but the general solution that I want to look towards is keeping the integers in ‘c’ as integers and somehow, using bit manipulation, adjusting the channels’ brightness based on a value from 0-255 instead of a fraction.
Thank you