2020-03-08 01:13:35 +03:00
|
|
|
function isPixelEmpty(pixel) {
|
2020-06-20 00:31:36 +03:00
|
|
|
if (pixel == null || pixel === undefined) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-04 10:41:56 +03:00
|
|
|
if ((pixel[0] == 0 && pixel[1] == 0 && pixel[2] == 0) || pixel[3] == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-03-08 01:13:35 +03:00
|
|
|
|
2020-04-04 10:41:56 +03:00
|
|
|
return false;
|
2020-06-20 00:31:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getEyedropperColor(cursorLocation) {
|
|
|
|
let max = -1;
|
|
|
|
let tmpColour;
|
|
|
|
let selectedColor;
|
|
|
|
|
|
|
|
for (let i=1; i<layers.length; i++) {
|
|
|
|
tmpColour = layers[i].context.getImageData(Math.floor(cursorLocation[0]/zoom),Math.floor(cursorLocation[1]/zoom),1,1).data;
|
|
|
|
|
|
|
|
if (layers[i].canvas.style.zIndex > max || isPixelEmpty(selectedColor) || selectedColor === undefined) {
|
|
|
|
max = layers[i].canvas.style.zIndex;
|
|
|
|
|
|
|
|
if (!isPixelEmpty(tmpColour)) {
|
|
|
|
selectedColor = tmpColour;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isPixelEmpty(tmpColour) && selectedColor === undefined) {
|
|
|
|
selectedColor = [0, 0, 0];
|
|
|
|
}
|
|
|
|
|
|
|
|
return selectedColor;
|
2020-03-08 01:13:35 +03:00
|
|
|
}
|