Jump to content
  • Advertisement


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.

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
Share on other sites
Guest Anonymous Poster
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.


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

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
((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).

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!