From: Andrew S. <ac...@sy...> - 2004-04-17 01:32:53
|
On Fri, 2004-04-16 at 07:10, Luke Dunstan wrote: > >From: Rob Lievaart <Rob...@no...> > >Reply-To: min...@li... > >To: "'min...@li...'" > ><min...@li...> > >Subject: RE: [Mingw-users] wingdi.h - buggy RGB macro ??? > >Date: Fri, 16 Apr 2004 09:12:54 +0200 > > > >Hi, > > > > > > I believe it should be: > > > > > > > > RGB(r,g,b) > >((DWORD)(((BYTE)(r)|((WORD)(BYTE)(g)<<8))|(((DWORD)(BYTE)(b))<<16))) > > > > > I agree, > > > > > > Actually this should be sufficient: > > > > > > #define RGB(r,g,b) ((COLORREF) ((BYTE)(r) | ((BYTE)(g) << 8) | > >((BYTE)(b) > ><< 16))) > > > >I think shifting a byte 8 bits to the left leaves you with a byt containing > >only 0's, and the > >original value disappearing because it does not fit into a byte anymore. > >The same > >holds for the 16 bit shift. It may depend on the compiler what actually > >happens, but > >I think the cast to WORD or DWORD are probably best left in. > >(Personally I'd use DWORD for everything) > > > > > >Rob Lievaart. > > Well I tried running it and it works, so apparently the BYTE values are > promoted to ints before shifting. On a 16-bit architecture a shift left 16 > would require a cast to DWORD though. > > Luke > Why not: #define RGB(r,g,b) ((COLORREF)((r&0xff)|(((DWORD)(g&0xff))<<8)|(((DWORD)(b&0xff))<<16))) Not extensively tested, and it assumes that the individual colour references and 8 bits, but so did the original. |