PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

How to convert the color with GAPI?

thanks for your attention.

GAPI: one colour mode:kfDirect565, it means red:5 bits, green:6 bits, blue: 5 bits. so I wrote some codes as following:
[C]
Code:
#define MAKE_RGB_565( r, g, b ) (((r & 0x1f) << 11) | ((g & 0x3f) << 5) | (b & 0x1f))


but one day, I saw another codes at www.microsoft.com, following:
[C#]
Code:
public static ushort BGRToPixel565(byte blue, byte green, byte red)
{
return (ushort)((((ushort)red >> 3) << 11) |
(((ushort)green >> 2) << 5) | ((ushort)blue >> 3));
}


who can tell me that which one is right? and why?
thank you again.
It's the same kind of thing.

The C code expects the bits to already be in the bottom of the integer. The C# code expects 8 bits per colour.

The C code is masking the unwanted bits out with ANDs whereas the C# code is shifting right first to remove the same bits.
Thanks refractor.
:)