3
getColor: function(image, x, y)
7
var ctx = document.getElementById('wtpc').getContext('2d');
9
ctx.drawImage(img, 0, 0);
10
return ctx.getImageData(x, y, 1, 1).data;
13
getColors: function(image, jump)
15
if (jump == null) jump = 1;
19
var img = new Image();
22
var height = img.height;
23
var width = img.width;
32
colors[colors.length] = WTPImage.getColor(image, x, y);
43
similar: function(color1, color2, tolerance)
45
if (tolerance == null) tolerance = 0.01;
47
tolerance = tolerance * (255 * 255 *3) << 0;
51
distance += Math.pow(color1[0] - color2[0], 2);
52
distance += Math.pow(color1[1] - color2[1], 2);
53
distance += Math.pow(color1[2] - color2[2], 2);
55
return distance <= tolerance;
58
different: function(color, colors, tolerance)
60
if (tolerance == null) tolerance = 0.01;
62
for (var i = 0; i < colors.length; i++)
64
if (WTPImage.similar(color, colors[i], tolerance))
73
uniqueColors: function(colors, maximum, tolerance)
75
if (tolerance == null) tolerance = 0.01;
79
for (var i = 0; i < colors.length; i++)
81
if (unique.length >= maximum) return unique;
83
if (WTPImage.different(colors[i], unique, tolerance))
85
unique[unique.length] = colors[i];
92
getRGB: function(color)
94
return 'rgb(' + color[0] + ', ' + color[1] + ',' + color[2] + ')';
97
getRGBA: function(color)
99
return 'rgba(' + color[0] + ', ' + color[1] + ',' + color[2] + ', ' + color[3] + ')';
b'\\ No newline at end of file'