Test Failed
Push — master ( 9d3a5c...c5f273 )
by Sebastian
08:26
created

SevenBitChannel::getDecimal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * @package Application Utils
4
 * @subpackage RGBAColor
5
 * @see \AppUtils\RGBAColor\ColorChannel\SevenBitChannel
6
 */
7
8
declare(strict_types=1);
9
10
namespace AppUtils\RGBAColor\ColorChannel;
11
12
use AppUtils\RGBAColor\ColorChannel;
13
use AppUtils\RGBAColor\UnitsConverter;
14
15
/**
16
 * Color channel with values from 0 to 127.
17
 *
18
 * Native value: {@see self::get7Bit()}.
19
 *
20
 * @package Application Utils
21
 * @subpackage RGBAColor
22
 * @author Sebastian Mordziol <[email protected]>
23
 */
24
class SevenBitChannel extends ColorChannel
25
{
26
    public const VALUE_MIN = 0;
27
    public const VALUE_MAX = 127;
28
29
    /**
30
     * @var int
31
     */
32
    private int $value;
33
34
    /**
35
     * @param int $value 0-127
36
     */
37
    public function __construct(int $value)
38
    {
39
        if($value < self::VALUE_MIN) { $value = self::VALUE_MIN; }
40
        if($value > self::VALUE_MAX) { $value = self::VALUE_MAX; }
41
42
        $this->value = $value;
43
    }
44
45
    public function getValue() : int
46
    {
47
        return $this->value;
48
    }
49
50
    /**
51
     * @return int 0-255
52
     */
53
    public function get8Bit() : int
54
    {
55
        return UnitsConverter::intSevenBit2IntEightBit($this->value);
56
    }
57
58
    /**
59
     * @return int 0-127
60
     */
61
    public function get7Bit() : int
62
    {
63
        return $this->value;
64
    }
65
66
    /**
67
     * @return float 0-1
68
     */
69
    public function getAlpha() : float
70
    {
71
        return UnitsConverter::intSevenBit2Alpha($this->value);
72
    }
73
74
    /**
75
     * @return float 0-100
76
     */
77
    public function getPercent() : float
78
    {
79
        return UnitsConverter::intSevenBit2Percent($this->value);
80
    }
81
82
    public function invert() : SevenBitChannel
83
    {
84
        return ColorChannel::sevenBit(127-$this->value);
85
    }
86
}
87