#### Archived

This topic is now archived and is closed to further replies.

# fastest RGB Makro?

This topic is 6023 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I want to have a very fast RGB Makro (16Bit 565). So, what''s faster? ((red >> 3) << 11) & ((green >> 2) << 5) & ((blue >> 3)) or ((red & 31) << 11) & ((green & 63) << 5) & ((blue & 31)) Shift or AND?

##### Share on other sites
I''m assuming this takes 3 8-bit values (24-bit) and converts it to a single 16-bit value (565)?

If you think about this logically... they both give VERY different results. You would want to use the one that does the shifting, and not the one that does the AND, as doing the AND would get rid of the MSB (most significant bits) and the one with the shifting drops the LSB (least significant bits). Obviuosly, you want to drop the least significant ones, and not the most significant ones.

Example:
Red=128
Green=128
Blue=128
Grey!

Lets run this through your shift function first.

128>>3 = 16 (on a 0->31 scale = 1/2 just like 128=1/2 in a 0->255 scale, so the color comes out correct.
128>>2 = 32
128>>3 = 16

So, now you have 16,32,16... in 16-bit mode, that''s grey, same as above.

Now, run this through your AND function...

128&31 = 0
128&63 = 0
128&31 = 0
Wait... you just lost ALL color information... that''s not good :D.

Billy - BillyB@mrsnj.com

thanx

##### Share on other sites
((red & 31) << 11) & ((green & 63) << 5) & ((blue & 31))

The colour compontents must be ORed or added, not anded. Like this:

((red & 31) << 11) | ((green & 63) << 5) | ((blue & 31))

But red has a input range of 0-31, green 0-63 and blue 0-31. Not 0-255.

For 0-255 the correct would be:

((red<<8)&63488) | ((green<<3)&2016) | ((blue>>3)&31))

The AND variant is probably faster on a Pentium because shifts can not pair with other shifts (not sure).

1. 1
Rutin
49
2. 2
3. 3
4. 4
5. 5

• 11
• 16
• 9
• 10
• 13
• ### Forum Statistics

• Total Topics
633003
• Total Posts
3009848
• ### Who's Online (See full list)

There are no registered users currently online

×