1 module qrcode.renderer.color.cmyk;
2 
3 import qrcode.renderer.color.colorinterface;
4 import qrcode.renderer.color.rgb;
5 import qrcode.renderer.color.gray;
6 /**
7 * CMYK color.
8 */
9 class Cmyk : ColorInterface
10 {
11 	/**
12 	* Cyan value.
13 	*
14 	* @var integer
15 	*/
16     protected int cyan;
17     /**
18 	* Magenta value.
19 	*
20 	* @var integer
21 	*/
22     protected int magenta;
23     /**
24 	* Yellow value.
25 	*
26 	* @var integer
27 	*/
28     protected int yellow;
29     /**
30 	* Black value.
31 	*
32 	* @var integer
33 	*/
34     protected int black;
35 
36 	/**
37 	* Creates a new CMYK color.
38 	*
39 	* @param integer cyan
40 	* @param integer magenta
41 	* @param integer yellow
42 	* @param integer black
43 	*/
44     public this(int _cyan, int _magenta, int _yellow, int _black)
45     {
46         if (_cyan < 0 || _cyan > 100) {
47             throw new Exception("Cyan must be between 0 and 100");
48         }
49         if (_magenta < 0 || _magenta > 100) {
50             throw new Exception("Magenta must be between 0 and 100");
51         }
52         if (_yellow < 0 || _yellow > 100) {
53             throw new Exception("Yellow must be between 0 and 100");
54         }
55         if (_black < 0 || _black > 100) {
56             throw new Exception("Black must be between 0 and 100");
57         }
58         this.cyan    = _cyan;
59         this.magenta = _magenta;
60         this.yellow  = _yellow;
61         this.black   = _black;
62     }
63     /**
64 	* Returns the cyan value.
65 	*
66 	* @return integer
67 	*/
68     public int getCyan()
69     {
70         return this.cyan;
71     }
72     /**
73 	* Returns the magenta value.
74 	*
75 	* @return integer
76 	*/
77     public int getMagenta()
78     {
79         return this.magenta;
80     }
81     /**
82 	* Returns the yellow value.
83 	*
84 	* @return integer
85 	*/
86     public int getYellow()
87     {
88         return this.yellow;
89     }
90     /**
91 	* Returns the black value.
92 	*
93 	* @return integer
94 	*/
95     public int getBlack()
96     {
97         return this.black;
98     }
99     /**
100 	* toRgb(): defined by ColorInterface.
101 	*
102 	* @see    ColorInterface::toRgb()
103 	* @return Rgb
104 	*/
105     public Rgb toRgb()
106     {
107         auto k = this.black / 100;
108         auto c = (-k * this.cyan + k * 100 + this.cyan) / 100;
109         auto m = (-k * this.magenta + k * 100 + this.magenta) / 100;
110         auto y = (-k * this.yellow + k * 100 + this.yellow) / 100;
111         return new Rgb(
112 					   -c * 255 + 255,
113 					   -m * 255 + 255,
114 					   -y * 255 + 255
115 					   );
116     }
117     /**
118 	* toCmyk(): defined by ColorInterface.
119 	*
120 	* @see    ColorInterface::toCmyk()
121 	* @return Cmyk
122 	*/
123     public Cmyk toCmyk()
124     {
125         return this;
126     }
127     /**
128 	* toGray(): defined by ColorInterface.
129 	*
130 	* @see    ColorInterface::toGray()
131 	* @return Gray
132 	*/
133     public Gray toGray()
134     {
135         return this.toRgb().toGray();
136     }
137 	public override string toString(){
138 		return super.toString();
139 	}
140 }