Newbie need help with 16-bit color key
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...
#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
#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
I think you will find these to be a little bit quicker:
This is because bitwise ors and ands are significantly faster than moduluses and pluses.
------------------------------
#pragma twice
#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
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
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement