1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
This file is part of WideImage. |
4
|
|
|
|
5
|
|
|
WideImage is free software; you can redistribute it and/or modify |
6
|
|
|
it under the terms of the GNU Lesser General Public License as published by |
7
|
|
|
the Free Software Foundation; either version 2.1 of the License, or |
8
|
|
|
(at your option) any later version. |
9
|
|
|
|
10
|
|
|
WideImage is distributed in the hope that it will be useful, |
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
GNU Lesser General Public License for more details. |
14
|
|
|
|
15
|
|
|
You should have received a copy of the GNU Lesser General Public License |
16
|
|
|
along with WideImage; if not, write to the Free Software |
17
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
18
|
|
|
|
19
|
|
|
* @package Tests |
20
|
|
|
**/ |
21
|
|
|
|
22
|
|
|
namespace Test\WideImage\Operation; |
23
|
|
|
|
24
|
|
|
use WideImage\WideImage; |
25
|
|
|
use WideImage\PaletteImage; |
26
|
|
|
use WideImage\TrueColorImage; |
27
|
|
|
use Test\WideImage_TestCase; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @package Tests |
31
|
|
|
*/ |
32
|
|
|
class GetChannelsTest extends WideImage_TestCase |
33
|
|
|
{ |
34
|
|
|
public function testCopyChannel8bit() |
35
|
|
|
{ |
36
|
|
|
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif'); |
37
|
|
|
|
38
|
|
|
$copy = $img->getChannels('red', 'alpha'); |
|
|
|
|
39
|
|
|
$this->assertTrue($copy instanceof PaletteImage); |
40
|
|
|
$this->assertTrue($copy->isValid()); |
41
|
|
|
$this->assertFalse($copy->isTrueColor()); |
42
|
|
|
$this->assertTrue($copy->isTransparent()); |
43
|
|
|
|
44
|
|
|
$this->assertRGBEqual($copy->getRGBAt(15, 15), 255, 0, 0); |
45
|
|
|
$this->assertRGBEqual($copy->getRGBAt(85, 15), 0, 0, 0); |
46
|
|
|
$this->assertRGBEqual($copy->getRGBAt(85, 85), 0, 0, 0); |
47
|
|
|
$this->assertRGBEqual($copy->getRGBAt(15, 85), 255, 0, 0); |
48
|
|
|
$this->assertEquals($copy->getTransparentColor(), $copy->getColorAt(50, 50)); |
49
|
|
|
|
50
|
|
|
$copy = $img->getChannels('red'); |
51
|
|
|
$this->assertTrue($copy instanceof PaletteImage); |
52
|
|
|
$this->assertTrue($copy->isValid()); |
53
|
|
|
$this->assertFalse($copy->isTrueColor()); |
54
|
|
|
$this->assertTrue($copy->isTransparent()); |
55
|
|
|
|
56
|
|
|
$this->assertRGBEqual($copy->getRGBAt(15, 15), 255, 0, 0); |
57
|
|
|
$this->assertRGBEqual($copy->getRGBAt(85, 15), 0, 0, 0); |
58
|
|
|
$this->assertRGBEqual($copy->getRGBAt(85, 85), 0, 0, 0); |
59
|
|
|
$this->assertRGBEqual($copy->getRGBAt(15, 85), 255, 0, 0); |
60
|
|
|
$this->assertEquals($copy->getTransparentColor(), $copy->getColorAt(50, 50)); |
61
|
|
|
|
62
|
|
|
$copy = $img->getChannels('green'); |
63
|
|
|
$this->assertTrue($copy instanceof PaletteImage); |
64
|
|
|
$this->assertTrue($copy->isValid()); |
65
|
|
|
$this->assertFalse($copy->isTrueColor()); |
66
|
|
|
$this->assertTrue($copy->isTransparent()); |
67
|
|
|
|
68
|
|
|
$this->assertRGBEqual($copy->getRGBAt(15, 15), 0, 255, 0); |
69
|
|
|
$this->assertRGBEqual($copy->getRGBAt(85, 15), 0, 0, 0); |
70
|
|
|
$this->assertRGBEqual($copy->getRGBAt(85, 85), 0, 255, 0); |
71
|
|
|
$this->assertRGBEqual($copy->getRGBAt(15, 85), 0, 0, 0); |
72
|
|
|
$this->assertEquals($copy->getTransparentColor(), $copy->getColorAt(50, 50)); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testCopySingleChannel() |
76
|
|
|
{ |
77
|
|
|
$img = WideImage::load(IMG_PATH . '100x100-rgbyg.png'); |
78
|
|
|
|
79
|
|
|
$copy = $img->getChannels('red'); |
|
|
|
|
80
|
|
|
$this->assertFalse($img->getHandle() === $copy->getHandle()); |
81
|
|
|
$this->assertTrue($copy instanceof TrueColorImage); |
82
|
|
|
$this->assertTrue($copy->isValid()); |
83
|
|
|
$this->assertTrue($copy->isTrueColor()); |
84
|
|
|
$this->assertRGBEqual($copy->getRGBAt(15, 15), 0, 0, 0, 0); |
85
|
|
|
$this->assertRGBEqual($copy->getRGBAt(85, 15), 255, 0, 0, 0); |
86
|
|
|
$this->assertRGBEqual($copy->getRGBAt(85, 85), 255, 0, 0, 0); |
87
|
|
|
$this->assertRGBEqual($copy->getRGBAt(15, 85), 0, 0, 0, 0); |
88
|
|
|
$this->assertRGBEqual($copy->getRGBAt(50, 50), 127, 0, 0, 0); |
89
|
|
|
/* |
90
|
|
|
$copy = $img->copyChannels('green'); |
91
|
|
|
$this->assertFalse($img->getHandle() === $copy->getHandle()); |
92
|
|
|
$this->assertTrue($copy instanceof TrueColorImage); |
93
|
|
|
$this->assertTrue($copy->isValid()); |
94
|
|
|
$this->assertTrue($copy->isTrueColor()); |
95
|
|
|
$this->assertRGBEqual($copy->getRGBAt(15, 15), 0, 0, 0); |
96
|
|
|
$this->assertRGBEqual($copy->getRGBAt(85, 15), 0, 0, 0); |
97
|
|
|
$this->assertRGBEqual($copy->getRGBAt(85, 85), 0, 255, 0); |
98
|
|
|
$this->assertRGBEqual($copy->getRGBAt(15, 85), 0, 255, 0); |
99
|
|
|
$this->assertRGBEqual($copy->getRGBAt(50, 50), 0, 127, 0); |
100
|
|
|
|
101
|
|
|
$copy = $img->copyChannels('blue'); |
102
|
|
|
$this->assertFalse($img->getHandle() === $copy->getHandle()); |
103
|
|
|
$this->assertTrue($copy instanceof TrueColorImage); |
104
|
|
|
$this->assertTrue($copy->isValid()); |
105
|
|
|
$this->assertTrue($copy->isTrueColor()); |
106
|
|
|
$this->assertRGBEqual($copy->getRGBAt(15, 15), 0, 0, 255); |
107
|
|
|
$this->assertRGBEqual($copy->getRGBAt(85, 15), 0, 0, 0); |
108
|
|
|
$this->assertRGBEqual($copy->getRGBAt(85, 85), 0, 0, 0); |
109
|
|
|
$this->assertRGBEqual($copy->getRGBAt(15, 85), 0, 0, 0); |
110
|
|
|
$this->assertRGBEqual($copy->getRGBAt(50, 50), 0, 0, 127); |
111
|
|
|
|
112
|
|
|
$img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png'); |
113
|
|
|
$copy = $img->copyChannels('alpha'); |
114
|
|
|
$this->assertRGBNear($copy->getRGBAt(25, 25), 0, 0, 0, 0.25 * 127); |
115
|
|
|
$this->assertRGBNear($copy->getRGBAt(75, 25), 0, 0, 0, 0.5 * 127); |
116
|
|
|
$this->assertRGBNear($copy->getRGBAt(75, 75), 0, 0, 0, 0.75 * 127); |
117
|
|
|
$this->assertRGBNear($copy->getRGBAt(25, 75), 0, 0, 0, 127); |
118
|
|
|
*/ |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function testCopyCombinedChannels() |
122
|
|
|
{ |
123
|
|
|
$img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png'); |
124
|
|
|
$copy = $img->getChannels('blue', 'alpha'); |
|
|
|
|
125
|
|
|
$this->assertRGBNear($copy->getRGBAt(25, 25), 0, 0, 255, 0.25 * 127); |
126
|
|
|
$this->assertRGBNear($copy->getRGBAt(75, 25), 0, 0, 255, 0.5 * 127); |
127
|
|
|
$this->assertRGBNear($copy->getRGBAt(75, 75), 0, 0, 255, 0.75 * 127); |
128
|
|
|
$this->assertRGBNear($copy->getRGBAt(25, 75), 0, 0, 0, 127); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.