Bits and Bobs
Well not really bobs.
I was fiddling around with my alpha blending routines and we all know the fastest way to darken something is to do something like this:
Apply this mask:
"11110 111110 11110"
and then bitshift to the right (>>) by 1.
However I was wondering whether it could be applied the other way:
Eg. Apply this mask:
"01111 011111 01111"
and then bitshift to the left (<<) by 1, to lighten the image?
I tried it, but it didn''t seem to work.
Is this possible? If so, what am I doing wrong?
r.
Ok, it looks like you''re using 16 bit color in the 565 format. So the most brillaint white possible is 11111 111111 11111. If you mask it with anything other than 0xffff you get something with a zero in it. Which makes it less brilliant, no matter how you bit shift or rotate or whatever, there will still be that zero in there.
The bitshift down technique works because you can symmetrically reduce the intensity of each color component by the same approximate magnitude (divide by 2). However if the most significant bit is set on any of the colors, a multiply by 2 isn''t possible; there just isn''t enough bits to represent it. The best you can do is to set all the bits in that particular color component, something that you really can''t do with simple shifts without additional logic.
The bitshift down technique works because you can symmetrically reduce the intensity of each color component by the same approximate magnitude (divide by 2). However if the most significant bit is set on any of the colors, a multiply by 2 isn''t possible; there just isn''t enough bits to represent it. The best you can do is to set all the bits in that particular color component, something that you really can''t do with simple shifts without additional logic.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement