Jump to content
  • Advertisement

Archived

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

En3my

Newbie need help with 16-bit color key

This topic is 6488 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

Hi, I''m a newbie trying my best to learn C++ and DirectX... I am trying to convert my current project from 8- to 16 bpp... Having a problem setting up the source RGB color key for 16-bit though... Here''s how I set up the color key: DDCOLORKEY key; key.dwColorSpaceLowValue = ? key.dwColorSpaceHighValue = ? The problem is that I have no idea how to set the transparent color using RGB-encoded words... Could someone please help me with a macro or some example code...

Share this post


Link to post
Share on other sites
Advertisement
#define _RGB16BIT565(r,g,b) ( (b%32) + ((g%64) << 5) + ((r%32) << 11) )
#define _RGB16BIT555(r,g,b) ( (b%32) + ((g%32) << 5) + ((r%32) << 10) )
#define _RGB32BIT(a,r,g,b) ( ((a) << 24) + ((r) << 16) + ((g) << 8) + b )


there ya go,

BrianH

Share this post


Link to post
Share on other sites
I think you will find these to be a little bit quicker:
        
#define RGB_555 ((b & 31)|((g & 31)<<5)|((r & 31)<<10))


#define RGB_565 ((b & 31)|((g&63)<<5)|((r&31)<<11)

This is because bitwise ors and ands are significantly faster than moduluses and pluses.

------------------------------
#pragma twice


sharewaregames.20m.com

Edited by - furby100 on October 6, 2000 5:58:33 AM

Share this post


Link to post
Share on other sites
quote:
Original post by furby100

This is because bitwise ors and ands are significantly faster than moduluses and pluses.



Not exactly...

unsigned int x;
x %= 16;
// With optimization this code will be compiled to
// x &= 15
// But for signed integer it''s more complex and slower.

Bitwise OR is not any faster then ADD (+).
Actually, sometimes compiler can optimize additions with LEA instruction - it allows 3-input operation:
r0 = r1 + (r2 << 0/1/2/3) + const

Share this post


Link to post
Share on other sites
I challenge you sir.
Have a look at the ASM produced by VC++. At least in my version it doesn''t perform the AND/MOD optimisation. It doesn''t even break up and add multiplications into shifts. for example, if I did:
x *= 69;
it would not turn it into:
x = (x << 6) + (x << 2) + x;

The compiler is too stupid to know this. Not only does this avoid multiplication, but the two shifts and the two adds can be paired, which adds to speed a bit.

------------------------------
#pragma twice


sharewaregames.20m.com

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!