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