1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AmaTeam\Image\Projection\Conversion\Processor\FXAA; |
4
|
|
|
|
5
|
|
|
use AmaTeam\Image\Projection\Image\Utility\Luma; |
6
|
|
|
|
7
|
|
|
class LumaGrid |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var float |
11
|
|
|
*/ |
12
|
|
|
public $center; |
13
|
|
|
/** |
14
|
|
|
* @var float |
15
|
|
|
*/ |
16
|
|
|
public $north; |
17
|
|
|
/** |
18
|
|
|
* @var float |
19
|
|
|
*/ |
20
|
|
|
public $northEast; |
21
|
|
|
/** |
22
|
|
|
* @var float |
23
|
|
|
*/ |
24
|
|
|
public $east; |
25
|
|
|
/** |
26
|
|
|
* @var float |
27
|
|
|
*/ |
28
|
|
|
public $southEast; |
29
|
|
|
/** |
30
|
|
|
* @var float |
31
|
|
|
*/ |
32
|
|
|
public $south; |
33
|
|
|
/** |
34
|
|
|
* @var float |
35
|
|
|
*/ |
36
|
|
|
public $southWest; |
37
|
|
|
/** |
38
|
|
|
* @var float |
39
|
|
|
*/ |
40
|
|
|
public $west; |
41
|
|
|
/** |
42
|
|
|
* @var float |
43
|
|
|
*/ |
44
|
|
|
public $northWest; |
45
|
|
|
/** |
46
|
|
|
* @var float |
47
|
|
|
*/ |
48
|
|
|
public $min; |
49
|
|
|
/** |
50
|
|
|
* @var float |
51
|
|
|
*/ |
52
|
|
|
public $max; |
53
|
|
|
/** |
54
|
|
|
* @var float |
55
|
|
|
*/ |
56
|
|
|
public $range; |
57
|
|
|
|
58
|
|
|
public function fill(ColorGrid $grid) |
59
|
|
|
{ |
60
|
|
|
$this->center = Luma::compute($grid->center); |
61
|
|
|
$this->north = Luma::compute($grid->north); |
62
|
|
|
$this->northEast = Luma::compute($grid->northEast); |
63
|
|
|
$this->east = Luma::compute($grid->east); |
64
|
|
|
$this->southEast = Luma::compute($grid->southEast); |
65
|
|
|
$this->south = Luma::compute($grid->south); |
66
|
|
|
$this->southWest = Luma::compute($grid->southWest); |
67
|
|
|
$this->west = Luma::compute($grid->west); |
68
|
|
|
$this->northWest = Luma::compute($grid->northWest); |
69
|
|
|
$this->min = min($this->center, $this->north, $this->east, $this->south, $this->west); |
70
|
|
|
$this->max = max($this->center, $this->north, $this->east, $this->south, $this->west); |
71
|
|
|
$this->range = $this->max - $this->min; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public static function fromArray(array $values) |
75
|
|
|
{ |
76
|
|
|
$grid = new LumaGrid(); |
77
|
|
|
$map = [ |
78
|
|
|
'northWest', 'north', 'northEast', |
79
|
|
|
'west', 'center', 'east', |
80
|
|
|
'southWest', 'south', 'southEast' |
81
|
|
|
]; |
82
|
|
|
foreach ($map as $position => $property) { |
83
|
|
|
$grid->$property = $values[$position]; |
84
|
|
|
} |
85
|
|
|
$grid->min = min($grid->center, $grid->north, $grid->east, $grid->south, $grid->west); |
86
|
|
|
$grid->max = max($grid->center, $grid->north, $grid->east, $grid->south, $grid->west); |
87
|
|
|
$grid->range = $grid->max - $grid->min; |
88
|
|
|
return $grid; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|