1 /** 2 Copyright: Copyright (c) 2016-2018 Andrey Penechko. 3 License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0). 4 Authors: Andrey Penechko. 5 */ 6 module voxelman.graphics.color; 7 8 import voxelman.math : Vector; 9 public import voxelman.math : ubvec3; 10 11 alias Color4ub = Vector!(ubyte, 4); 12 13 enum Colors : Color4ub 14 { 15 black = Color4ub(0, 0, 0, 255), 16 white = Color4ub(255, 255, 255, 255), 17 red = Color4ub(255, 0, 0, 255), 18 green = Color4ub(0, 255, 0, 255), 19 blue = Color4ub(0, 0, 255, 255), 20 cyan = Color4ub(0, 255, 255, 255), 21 magenta = Color4ub(255, 0, 255, 255), 22 yellow = Color4ub(255, 255, 0, 255), 23 gray = Color4ub(128, 128, 128, 255), 24 orange = Color4ub(255, 128, 0, 255), 25 orangeRed = Color4ub(255, 69, 0, 255), 26 pink = Color4ub(255, 192, 203, 255), 27 brown = Color4ub(128, 64, 0, 255), 28 purple = Color4ub(128, 0, 128, 255), 29 indigo = Color4ub(75, 0, 128, 255), 30 violet = Color4ub(143, 0, 255, 255), 31 } 32 33 Color4ub[] colorsArray = [ 34 Colors.black, Colors.white, Colors.red, 35 Colors.green, Colors.blue, Colors.cyan, 36 Colors.magenta, Colors.yellow, Colors.gray, 37 Colors.orange, Colors.orangeRed, Colors.pink, 38 Colors.brown, Colors.purple, Colors.indigo, 39 Colors.violet, 40 ]; 41 42 Color4ub rgb(ubyte r, ubyte g, ubyte b) 43 { 44 return Color4ub(r, g, b, 255); 45 } 46 47 ushort packColor(ubvec3 c) { 48 return (c.r>>3) | (c.g>>3) << 5 | (c.b>>3) << 10; 49 } 50 ushort packColor(ubyte[3] c) { 51 return (c[0]>>3) | (c[1]>>3) << 5 | (c[2]>>3) << 10; 52 } 53 ushort packColor(ubyte r, ubyte g, ubyte b) { 54 return (r>>3) | (g>>3) << 5 | (b>>3) << 10; 55 }