1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
<?php /** * BaconQrCode * * @link http://github.com/Bacon/BaconQrCode For the canonical source repository * @copyright 2013 Ben 'DASPRiD' Scholzen * @license http://opensource.org/licenses/BSD-2-Clause Simplified BSD License */
namespace BaconQrCode\Renderer\Color;
use BaconQrCode\Exception;
/** * RGB color. */ class Rgb implements ColorInterface { /** * Red value. * * @var integer */ protected $red;
/** * Green value. * * @var integer */ protected $green;
/** * Blue value. * * @var integer */ protected $blue;
/** * Creates a new RGB color. * * @param integer $red * @param integer $green * @param integer $blue */ public function __construct($red, $green, $blue) { if ($red < 0 || $red > 255) { throw new Exception\InvalidArgumentException('Red must be between 0 and 255'); }
if ($green < 0 || $green > 255) { throw new Exception\InvalidArgumentException('Green must be between 0 and 255'); }
if ($blue < 0 || $blue > 255) { throw new Exception\InvalidArgumentException('Blue must be between 0 and 255'); }
$this->red = (int) $red; $this->green = (int) $green; $this->blue = (int) $blue; }
/** * Returns the red value. * * @return integer */ public function getRed() { return $this->red; }
/** * Returns the green value. * * @return integer */ public function getGreen() { return $this->green; }
/** * Returns the blue value. * * @return integer */ public function getBlue() { return $this->blue; }
/** * Returns a hexadecimal string representation of the RGB value. * * @return string */ public function __toString() { return sprintf('%02x%02x%02x', $this->red, $this->green, $this->blue); }
/** * toRgb(): defined by ColorInterface. * * @see ColorInterface::toRgb() * @return Rgb */ public function toRgb() { return $this; }
/** * toCmyk(): defined by ColorInterface. * * @see ColorInterface::toCmyk() * @return Cmyk */ public function toCmyk() { $c = 1 - ($this->red / 255); $m = 1 - ($this->green / 255); $y = 1 - ($this->blue / 255); $k = min($c, $m, $y);
return new Cmyk( 100 * ($c - $k) / (1 - $k), 100 * ($m - $k) / (1 - $k), 100 * ($y - $k) / (1 - $k), 100 * $k ); }
/** * toGray(): defined by ColorInterface. * * @see ColorInterface::toGray() * @return Gray */ public function toGray() { return new Gray(($this->red * 0.21 + $this->green * 0.71 + $this->blue * 0.07) / 2.55); } }
|