-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcolourProfile.php
234 lines (195 loc) · 6.79 KB
/
colourProfile.php
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php
/*
* Created on 21 Jan 2008
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
class ColourProfile {
private $accuracy = -1;
private $accuracyPercentage = 0;
private $colourType = "Unknown";
private $shade = "Unknown";
private $databaseId = -1;
private $shadeRed = -1;
private $shadeGreen = -1;
private $shadeBlue = -1;
//performance tweak
private $accuracyThreshold = 10;
private $testRed;
private $testGreen;
private $testBlue;
private $allColours;
private $ADJUSTMENT = 75;
function calculateAccuracyPercentage() {
$acc = $this->accuracy;
$total = 100;
$percentage = ($acc / $total) * 100;
$this->accuracyPercentage = $percentage;
}
function ColourProfile($testRed, $testGreen, $testBlue, $allColours) {
$this->testRed = $testRed;
$this->testGreen = $testGreen;
$this->testBlue = $testBlue;
$this->allColours = $allColours;
$this->analyseTestColours();
$this->calculateAccuracyPercentage();
}
function analyseTestColours() {
$allColours = $this->allColours;
$red = $this->testRed;
$green = $this->testGreen;
$blue = $this->testBlue;
$size = sizeof($allColours);
$previousOffset = 255;
if ($red == $green && $green == $blue && $red > 15 && $red < 239) {
//Performance tweak
//This will be a grey
$this->accuracy = 0;
$this->shade = $red;
$this->colourType = "Grey";
//$this->databaseId = $colourIndex;
// testing finds that this section will mean that a databaseId of -1 (default value) is returned. TH
// echo "This will be a grey\n";
// echo var_dump($this);
} else {
// echo "$size";
for ($i = 0; $i < $size; $i++) {
// echo "Here";
$test = $allColours[$i]; //Final adjustment is used for now - will be different in final code (I.e dynamic value from DB)
$STORED_RANGE = $this->workOutRange($test[0], $test[1], $test[2], $this->ADJUSTMENT);
$isStored = $this->colourTest($STORED_RANGE);
// echo var_dump($STORED_RANGE);
if ($isStored) {
$colourIndex = $i;
$colourName = $test[3];
$colourSubType = $test[4];
$offsetRed = $test[0] - $red;
$offsetGreen = $test[1] - $green;
$offsetBlue = $test[2] - $blue;
$offsetRed = SQRT($offsetRed * $offsetRed);
$offsetGreen = SQRT($offsetGreen * $offsetGreen);
$offsetBlue = SQRT($offsetBlue * $offsetBlue);
$newAccuracy = $offsetRed + $offsetGreen + $offsetBlue;
//$this->accuracy = $offsetRed + $offsetGreen + $offsetBlue;
//$fullListOfMatches[$totalMatches] = $colourIndex;
//$totalMatches++;
if ($newAccuracy < $previousOffset) {
$previousOffset = $newAccuracy;
$this->accuracy = $newAccuracy;
$this->shade = $colourName;
$this->colourType = $colourSubType;
$this->databaseId = $colourIndex;
//this is a performance tweak and might need to be adjusted if we are seriously missing accuracy
if ($newAccuracy <= 10) {
$i = $size;
}
}
}
}
}
}
function colourTest($testcriteria) {
$iscolour = false;
$r = $this->testRed;
$g = $this->testGreen;
$b = $this->testBlue;
if ($r >= $testcriteria[0] and $r <= $testcriteria[1] and $g >= $testcriteria[2] and $g <= $testcriteria[3] and $b >= $testcriteria[4] and $b <= $testcriteria[5]) {
$iscolour = true;
}
return $iscolour;
}
function workOutRange($red, $green, $blue, $adjustment) {
$low = 0;
$high = 255;
//fix for grey - eventually should be stored
//this should never happen now
// if ($red == $green && $green == $blue) {
// //the overall range for grey must be controlled to stop too many matches, as we get more colours the overall adjustment will be shrunk (50 is uesed by default)
// echo "all values equal";
// //$adjustment = 5;
// }
//$adjustment = 50;
$redLow = $this->workOutLow($red, $adjustment);
$redHigh = $this->workOutHigh($red, $adjustment);
$greenLow = $this->workOutLow($green, $adjustment);
$greenHigh = $this->workOutHigh($green, $adjustment);
$blueLow = $this->workOutLow($blue, $adjustment);
$blueHigh = $this->workOutHigh($blue, $adjustment);
$testArray = array(
$redLow,
$redHigh,
$greenLow,
$greenHigh,
$blueLow,
$blueHigh
);
return $testArray;
}
function getShadeRed() {
return $this->shadeRed;
}
function getShadeGreen() {
return $this->shadeGreen;
}
function getShadeBlue() {
return $this->shadeBlue;
}
function getAccuracyPercentage() {
return $this->accuracyPercentage;
}
function setShadeRed($shadeRed) {
$this->shadeRed = $shadeRed;
}
function setShadeGreen($shadeGreen) {
$this->shadeGreen = $shadeGreen;
}
function setShadeBlue($shadeBlue) {
$this->shadeBlue = $shadeBlue;
}
function setDatabaseId($databaseId) {
$this->databaseId = $databaseId;
}
function getDatabaseId() {
return $this->databaseId;
}
function setAccuracy($accuracy) {
$this->accuracy = $accuracy;
}
function getAccuracy() {
return $this->accuracy;
}
function setColourType($colourType) {
$this->colourType = $colourType;
}
function getColourType() {
return $this->colourType;
}
function setShade($shade) {
$this->shade = $shade;
}
function getShade() {
return $this->shade;
}
function workOutLow($colour, $percentage) {
$value = 50;
$value = $percentage;
$colour = $colour - $value;
// echo __CLASS__."::".__FUNCTION__."Colour Low: {$colour}";
if ($colour < 0) {
$colour = 0;
}
return $colour;
}
function workOutHigh($colour, $percentage) {
$value = 50;
$value = $percentage;
$colour = $colour + $value;
// echo __CLASS__."::".__FUNCTION__."Colour High: {$colour}";
if ($colour > 255) {
$colour = 255;
}
return $colour;
}
}
?>