1 module skia.SKPMColor;
2 
3 import skia.SKColor;
4 import skia.SkiaApi;
5 import skia.SKImageInfo;
6 
7 // struct SKPMColor : IEquatable<SKPMColor>
8 struct SKPMColor
9 {
10 	private const uint color;
11 
12 	this (uint value)
13 	{
14 		color = value;
15 	}
16 
17 	const byte Alpha()
18   {
19     return cast(byte)((color >> SKImageInfo.PlatformColorAlphaShift) & 0xff);
20   } 
21 	const byte Red()
22   {
23     return cast(byte)((color >> SKImageInfo.PlatformColorRedShift) & 0xff);
24   } 
25 	const byte Green()
26   {
27     return cast(byte)((color >> SKImageInfo.PlatformColorGreenShift) & 0xff);
28   }
29 	const byte Blue()
30   {
31     return cast(byte)((color >> SKImageInfo.PlatformColorBlueShift) & 0xff);
32   } 
33 
34 	// PreMultiply
35 
36 	static SKPMColor PreMultiply (SKColor color)
37   {
38     return SKPMColor(SkiaApi.sk_color_premultiply (cast(uint)color));
39   }
40 		
41 
42 	static SKPMColor[] PreMultiply (SKColor[] colors)
43 	{
44 		auto pmcolors = new SKPMColor[colors.length];
45 		SKColor* c = colors.ptr;
46 		SKPMColor* pm = pmcolors.ptr;
47 		SkiaApi.sk_color_premultiply_array (cast(uint*)c, cast(int)colors.length, cast(uint*)pm);
48 		return pmcolors;
49 	}
50 
51 	// UnPreMultiply
52 
53 	static SKColor UnPreMultiply (SKPMColor pmcolor)
54   {
55     return SKColor(SkiaApi.sk_color_unpremultiply (pmcolor.color));
56   }
57 		
58 
59 	static SKColor[] UnPreMultiply (SKPMColor[] pmcolors)
60 	{
61 		auto colors = new SKColor[pmcolors.length];
62 		SKColor* c = colors.ptr;
63 		SKPMColor* pm = pmcolors.ptr;
64 		SkiaApi.sk_color_unpremultiply_array (cast(uint*)pm, cast(int)pmcolors.length, cast(uint*)c);
65 		return colors;
66 	}
67 
68 	// static explicit operator SKPMColor (SKColor color)
69   // {
70   //   return SKPMColor.PreMultiply (color);
71   // }
72 		
73 
74 	// static explicit operator SKColor (SKPMColor color)
75   // {
76   //   return SKPMColor.UnPreMultiply (color);
77   // }
78 		
79 
80 	const  string ToString ()
81   {
82     return "#{Alpha:x2}{Red:x2}{Green:x2}{Blue:x2}";
83   }
84 		
85 
86 	const bool Equals (SKPMColor obj)
87   {
88     return obj.color == color;
89   }
90 		
91 
92 	// const override bool Equals (object other)
93   // {
94   //   return 	other is SKPMColor f && Equals (f);
95   // }
96 	
97 
98 	// static bool operator == (SKPMColor left, SKPMColor right)
99   // {
100   //   return left.Equals (right);
101   // }
102 		
103 
104 	// static bool operator != (SKPMColor left, SKPMColor right)
105   // {
106   //   return 	!left.Equals (right);
107   // }
108 	
109 
110 	// const  int GetHashCode ()	
111   // {
112 	// 	return color.GetHashCode ();
113 	// }
114 
115 	// static implicit operator SKPMColor (uint color)	
116   // {
117 	// 	return new SKPMColor (color);
118 	// }
119 
120 	// static explicit operator uint (SKPMColor color)	
121   // {
122 	// 	return color.color;
123 	// }
124 }