using System; using System.Collections.Generic; using System.Text; namespace CommonUI.Display { public class Color { public const uint COLOR_NULL = 0; public const uint COLOR_WHITE = 0xffffffff; public const uint COLOR_LIGHT_GRAY = 0xa0a0a0ff; public const uint COLOR_GRAY = 0x808080ff; public const uint COLOR_DARK_GRAY = 0x404040ff; public const uint COLOR_BLACK = 0x000000ff; public const uint COLOR_RED = 0xff0000ff; public const uint COLOR_PINK = 0xffadadff; public const uint COLOR_ORANGE = 0xffc700ff; public const uint COLOR_YELLOW = 0xffff00ff; public const uint COLOR_GREEN = 0x00ff00ff; public const uint COLOR_MAGENTA = 0xff00ffff; public const uint COLOR_CYAN = 0x00ffffff; public const uint COLOR_BLUE = 0x0000ffff; static public uint toARGB(uint rgba) { uint ret = rgba >> 8; ret = (ret | ((rgba & 0x00ff) << 24)); return ret; } static public uint toRGBA(uint argb) { uint ret = (argb & 0x00ffffff) << 8; ret = (ret | (argb >> 24)); return ret; } static public uint toRGBA(float r, float g, float b, float a) { uint ret = 0; ret |= ((uint)(r * 255)) << 24; ret |= ((uint)(g * 255)) << 16; ret |= ((uint)(b * 255)) << 8; ret |= ((uint)(a * 255)); return ret; } static public uint toRGBA(uint rgb, int a) { uint ret = 0; ret |= ((uint)(rgb & 0x00FFFFFF) << 8); ret |= ((uint)(a & 0xFF)); return ret; } static public uint toRGBA(int r, int g, int b, int a) { uint ret = 0; ret |= ((uint)(r )) << 24; ret |= ((uint)(g )) << 16; ret |= ((uint)(b )) << 8; ret |= ((uint)(a )); return ret; } static public uint toARGB(float r, float g, float b, float a) { uint ret = 0; ret |= ((uint)(r * 255)) << 16; ret |= ((uint)(g * 255)) << 8; ret |= ((uint)(b * 255)) << 0; ret |= ((uint)(a * 255)) << 24; return ret; } static public uint toARGB(int r, int g, int b, int a) { uint ret = 0; ret |= ((uint)(r)) << 16; ret |= ((uint)(g)) << 8; ret |= ((uint)(b)) << 0; ret |= ((uint)(a)) << 24; return ret; } static public void toRGBAF(uint rgba, out float r, out float g, out float b, out float a) { r = ((0xff000000 & rgba) >> 24) / 255f; g = ((0x00ff0000 & rgba) >> 16) / 255f; b = ((0x0000ff00 & rgba) >> 8) / 255f; a = ((0x000000ff & rgba)) / 255f; } static public void toARGBF(uint rgba, out float r, out float g, out float b, out float a) { a = ((0xff000000 & rgba) >> 24) / 255f; r = ((0x00ff0000 & rgba) >> 16) / 255f; g = ((0x0000ff00 & rgba) >> 8) / 255f; b = ((0x000000ff & rgba)) / 255f; } static public byte[] fromRGBA(uint rgba) { return new byte[] { (byte)((0xff000000 & rgba) >> 24), (byte)((0x00ff0000 & rgba) >> 16), (byte)((0x0000ff00 & rgba) >> 8), (byte)((0x000000ff & rgba) >> 0) }; } static public byte[] fromARGB(uint argb) { return new byte[] { (byte)((0x00ff0000 & argb) >> 16), (byte)((0x0000ff00 & argb) >> 8), (byte)((0x000000ff & argb) >> 0), (byte)((0xff000000 & argb) >> 24), }; } } }