Can I also ask for help here?
I don't want to create an extra topic.
I have got a 16-bit color and want to adjust the lightness of the color with a function like this:
Code:
It should accept val >= 0 && val < 256, so I would have to act with percents or something similar...
I really don't have an idea how to do this in a fast bitshifting way
My approach:
Code:
I don't think that this works.
I don't want to create an extra topic.
I have got a 16-bit color and want to adjust the lightness of the color with a function like this:
Code:
color_t changelight(color_t color, unsigned char val)
{
//change red, green and blue with the same value
}
It should accept val >= 0 && val < 256, so I would have to act with percents or something similar...
I really don't have an idea how to do this in a fast bitshifting way
My approach:
Code:
unsigned char red, green, blue;
red = (color & 0b1111100000000000) >> 11;
green = (color & 0b1111110000) >> 5;
blue = color & 0b1111;
leeway = 0xFFFF - (~(red & blue & green) & (~(~red & ~blue & ~green));
//get the leeway of the darkness (probably wrong? No idea here.)
red += (val - 0x88) / leeway;
green += (val - 0x88) / leeway;
blue += (val - 0x88) / leeway;
I don't think that this works.