1 module qrcode.renderer.color.gray;
2 
3 import qrcode.renderer.color.colorinterface;
4 import qrcode.renderer.color.rgb;
5 import qrcode.renderer.color.cmyk;
6 import std.conv;
7 
8 /**
9 * Gray color.
10 */
11 class Gray : ColorInterface
12 {
13 	/**
14 	* Gray value.
15 	*
16 	* @var integer
17 	*/
18     protected int gray;
19 	/**
20 	* Creates a new gray color.
21 	*
22 	* A low gray value means black, while a high value means white.
23 	*
24 	* @param integer $gray
25 	*/
26 	this(int _gray)
27 	{
28 		if (_gray < 0 || _gray > 100) {
29             throw new Exception("Gray must be between 0 and 100");
30         }
31         this.gray = _gray;
32 	}
33 
34 	/**
35 	* Returns the gray value.
36 	*
37 	* @return integer
38 	*/
39     public int getGray()
40     {
41         return this.gray;
42     }
43     /**
44 	* toRgb(): defined by ColorInterface.
45 	*
46 	* @see    ColorInterface::toRgb()
47 	* @return Rgb
48 	*/
49     public Rgb toRgb()
50     {
51         return new Rgb(to!int(this.gray * 2.55), to!int(this.gray * 2.55), to!int(this.gray * 2.55));
52     }
53     /**
54 	* toCmyk(): defined by ColorInterface.
55 	*
56 	* @see    ColorInterface::toCmyk()
57 	* @return Cmyk
58 	*/
59     public Cmyk toCmyk()
60     {
61         return new Cmyk(0, 0, 0, 100 - this.gray);
62     }
63     /**
64 	* toGray(): defined by ColorInterface.
65 	*
66 	* @see    ColorInterface::toGray()
67 	* @return Gray
68 	*/
69     public Gray toGray()
70     {
71         return this;
72     }
73 
74 	public override string toString(){
75 		return super.toString();
76 	}
77 }