If I have a 16 bit PIXEL consisting of
RRRRRGGGGGGBBBBB how can I make the current content lighter and darker, keeping the same "Hue", i.e a dark red to a light red, is there a simple bit shift that can be performed am using easyce, does it have anything built in?
-B
To make a color darker, decrease each value by the same value until it reaches zero.
ex.
red (in rgb format)
255, 0, 0
to make a slightly darker red, subtract 25 from each value unless that value is 0, and if the value is < 25, set it to zero.
result: a slightly darker red
230, 0, 0
Now an example with R, G, and B values:
light gray:
192, 192, 192
reduced by 64 on each value yields dark gray
128, 128, 128
By subtracting the same number from each color value, you effectively lower the luminance of the color. To make the color lighter, simply add the same number to each of the R, G, and B values.
yep, I know that, I was hoping that there was a bit mask (somthing) etc that could be performed on it, otherwise I'll have to so some fancy shifting or splitting it up.....
sort of like this:
- Code:
colr = src >> 11;
colg = src >> 5;
colb = src
colg &= 31;
colb &= 31;
colr =- s;
colg =- s;
colb =- s;
if (colr < 0) colr = 0;
if (colg < 0) colg = 0;
if (colb < 0) colb = 0;
dest = colr << 11 | colg << 5 | colb;
of somthing like this, (that works, because it dont lol)
I don't think mine is any more efficient than that really. Basically reducing the value of the R, G and B separately then putting 'em back together.
A faster way might be to use a series of bitmasks which you prepare beforehand, like hardcoded or something, but it's obviously not as elegant.
- Code:
colr =- s;
colg =- s;
colb =- s;
You wanted -= .
That kind of thing is very elegant in ARM assembler because the shifts are "free".
Something like:
(presumes colour in r0, decrement in r1)
- Code:
MOV R2,#1F ' b00011111
AND R3,R2,R0,LSR #11 ' red
AND R4,R2,R0,LSR #5 ' green
AND R0,R2,R0 ' blue
SUBS R3,R3,R1 ' decrement r
MOVLT R3,#0
SUBS R4,R4,R1 ' decrement g
MOVLT R4,#0
SUBS R0,R0,R1 ' decrement b
MOVLT R0,#0
ORR R0,R0,R3,LSL #11
ORR R0,R0,R4,LSL #5
You could probably rearrange things a little and save a register. You could add another couple of instructions to get it to perform increments as well as decrements, too.
I think we've covered this kind of thing in the forum before, but I wouldn't know what to search for...
(Addendum - that doesn't
quite work 'cos I forgot that green has 6 bits.. but only the lowest bit disappears and that's not used on 4096 colour devices anyway. It's early and I'm knackered

).
Cheers,
Ref.
In Repton I create shadow boxes quickly by taking each pixel and >>=1 and then anding with a bitmask to remove the most significant bit in each attribute.
Nice and fast and should be fairly portable.
What if I just want to add two colors together, without getting overflows. Which is the most efficient way then? Here is some psuedo code of hwo I do now:
- Code:
int r = R(color0) + R(color1);
int g = G(color0) + G(color1);
int b = B(color0) + B(color1);
if(r > 255) r = 255;
if(g > 255) g = 255;
if(b > 255) b = 255;
*Dest = RGB(r, g, b);
One thing to consider is storing / manipulating all your bitmaps in 24 bit RGB, then converting to RGB 565 only while performing final GAPI blit. There would then be no unpacking from RGB 565 to access individual color components, and if you perform additional effects such as alpha blending at some other point than the color intensity, then you would save a lot of processing. Finally, if you have pixels that are hidden by sprites, etc, then those pixels will never have to be converted to RGB 565 at all, even if you perform effects on them.
Cons would be twice the memory requirements (if you use 4 bytes per pixel for alignment), and less efficiency if all of your bitmaps are preconverted to RGB 565 at load time and you do very little manipulation to the pixels.
Dan East
How about averaging two colours together? You could do that with two and opcodes and a plus.
Clipping to 255 is slow you see, because you have to do it three times and you can't do it in parallel afaik
Dan,
Interesting idea, but I would seriously suggest someone profile this approach before using it.
Taking 50% more cache hits because the data size increased from 2 bytes to 3 bytes per pixel is probably going to hurt performance more than the few logical ops to unpack a 16-bpp pixel value.
It actually gets worse than a 50% hit because you might end up having to read two DWORDs if the 3 bytes span a DWORD memory boundary. It might be worth investigating storing the images as 32-bpp instead of 24-bpp. You'll never have to read more than one DWORD to get the pixel value and you won't have to worry about shifting things to get the pixel into a register. Of course, now you're taking twice as many cache hits. The profiler is your friend.