@@ -5,21 +5,32 @@ part of tiled;
55class ColorData {
66 static int _sub (int hex, int index) => (hex >> index * 8 ) & 0x000000ff ;
77
8- final int red;
9- final int green;
10- final int blue;
11- final int alpha;
8+ final int _hex;
9+
10+ int get alpha => _sub (_hex, 3 );
11+
12+ int get red => _sub (_hex, 2 );
13+
14+ int get green => _sub (_hex, 1 );
15+
16+ int get blue => _sub (_hex, 0 );
1217
1318 /// Parses the Color from an int using the lower 32-bits and tiled's format: 0xaarrggbb
14- ColorData .hex (int hex)
15- : alpha = _sub (hex, 3 ),
16- red = _sub (hex, 2 ),
17- green = _sub (hex, 1 ),
18- blue = _sub (hex, 0 );
19+ const ColorData .hex (this ._hex);
20+
21+ const ColorData .rgb (int red, int green, int blue, [int alpha = 255 ])
22+ : assert (red >= 0 && red <= 255 ),
23+ assert (green >= 0 && green <= 255 ),
24+ assert (blue >= 0 && blue <= 255 ),
25+ assert (alpha >= 0 && alpha <= 255 ),
26+ _hex = (alpha << 3 * 8 ) + (red << 2 * 8 ) + (green << 1 * 8 ) +
27+ (blue << 0 * 8 );
1928
20- const ColorData .rgb ( this .red, this .green, this .blue, [ this .alpha = 255 ] )
29+ const ColorData .argb ( int alpha, int red, int green, int blue )
2130 : assert (red >= 0 && red <= 255 ),
2231 assert (green >= 0 && green <= 255 ),
2332 assert (blue >= 0 && blue <= 255 ),
24- assert (alpha >= 0 && alpha <= 255 );
33+ assert (alpha >= 0 && alpha <= 255 ),
34+ _hex = (alpha << 3 * 8 ) + (red << 2 * 8 ) + (green << 1 * 8 ) +
35+ (blue << 0 * 8 );
2536}
0 commit comments