9 #define MASK2BYTES 0xC0
10 #define MASK3BYTES 0xE0
11 #define MASK4BYTES 0xF0
12 #define MASK5BYTES 0xF8
13 #define MASK6BYTES 0xFC
19 T AlignUp(
const T in, u32 align)
25 out += align - (out % align);
32 T AlignDown(
const T in, u32 align)
44 inline void ConvertColourU32ToFloat(
float* floatCol,
const u32 colour)
46 floatCol[0] = ((float)((colour & 0xff000000) >> 24))/255.0f;
47 floatCol[1] = ((float)((colour & 0x00ff0000) >> 16))/255.0f;
48 floatCol[2] = ((float)((colour & 0x0000ff00) >> 8))/255.0f;
49 floatCol[3] = ((float)((colour & 0x000000ff) >> 0))/255.0f;
52 inline u32 ConvertColourFloatToU32(
const float* floatCol)
54 return (((u32)(floatCol[0] * 255.0f)) << 24) | (((u32)(floatCol[1] * 255.0f)) << 16) | (((u32)(floatCol[2] * 255.0f)) << 8) | (((u32)(floatCol[3] * 255.0f)));
57 inline u32 MakeRGBAu8(u8 r, u8 g, u8 b, u8 a)
59 return ((u32)(r) << 0) | ((u32)(g) << 8) | ((u32)(b) << 16) | ((u32)(a) << 24);
63 inline u32 UTF8ToU16(u16& dst,
const char* utf8)
65 const u8* pBytes = (
const u8*)utf8;
68 if((pBytes[0] & MASK3BYTES) == MASK3BYTES)
70 dst = ((pBytes[0] & 0x0F) << 12) | ((pBytes[1] & MASKBITS) << 6) | (pBytes[2] & MASKBITS);
74 else if((pBytes[0] & MASK2BYTES) == MASK2BYTES)
76 dst = ((pBytes[0] & 0x1F) << 6) | (pBytes[1] & MASKBITS);
87 inline u32 U16ToUTF8(
char* utf8, u16 src)
92 utf8[0] = ((char) src);
98 utf8[0] = (char)(MASK2BYTES | (src >> 6));
99 utf8[1] = (char)(MASKBYTE | (src & MASKBITS));
105 utf8[0] = (char)(MASK3BYTES | (src >> 12));
106 utf8[1] = (char)(MASKBYTE | ((src >> 6) & MASKBITS));
107 utf8[2] = (char)(MASKBYTE | (src & MASKBITS));