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
|
<?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;
/** * Gray color. */ class Gray implements ColorInterface { /** * Gray value. * * @var integer */ protected $gray;
/** * Creates a new gray color. * * A low gray value means black, while a high value means white. * * @param integer $gray */ public function __construct($gray) { if ($gray < 0 || $gray > 100) { throw new Exception\InvalidArgumentException('Gray must be between 0 and 100'); }
$this->gray = (int) $gray; }
/** * Returns the gray value. * * @return integer */ public function getGray() { return $this->gray; }
/** * toRgb(): defined by ColorInterface. * * @see ColorInterface::toRgb() * @return Rgb */ public function toRgb() { return new Rgb($this->gray * 2.55, $this->gray * 2.55, $this->gray * 2.55); }
/** * toCmyk(): defined by ColorInterface. * * @see ColorInterface::toCmyk() * @return Cmyk */ public function toCmyk() { return new Cmyk(0, 0, 0, 100 - $this->gray); }
/** * toGray(): defined by ColorInterface. * * @see ColorInterface::toGray() * @return Gray */ public function toGray() { return $this; } }
|