2023-02-28 09:43:01 +01:00
|
|
|
function Node_Find_Pixel(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
|
2023-02-14 02:48:33 +01:00
|
|
|
name = "Find pixel";
|
2024-05-02 11:05:02 +02:00
|
|
|
setDimension(96, 48);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2024-03-14 14:35:19 +01:00
|
|
|
inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
|
|
|
inputs[| 1] = nodeValue("Search color", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_black);
|
2023-10-31 13:33:36 +01:00
|
|
|
|
|
|
|
inputs[| 2] = nodeValue("Tolerance", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0)
|
|
|
|
.setDisplay(VALUE_DISPLAY.slider);
|
|
|
|
|
2024-03-14 14:35:19 +01:00
|
|
|
inputs[| 3] = nodeValue("Find all", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
|
2023-10-31 13:33:36 +01:00
|
|
|
|
2024-03-14 14:35:19 +01:00
|
|
|
inputs[| 4] = nodeValue("Include alpha", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
|
2024-01-10 06:36:33 +01:00
|
|
|
|
|
|
|
inputs[| 5] = nodeValue("Alpha tolerance", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.2)
|
|
|
|
.setDisplay(VALUE_DISPLAY.slider);
|
|
|
|
|
2024-05-17 05:19:11 +02:00
|
|
|
// inputs[| 6] = nodeValue("Axis", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1)
|
|
|
|
// .setDisplay(VALUE_DISPLAY.enum_button, [ "X", "Y" ]);
|
|
|
|
|
2023-02-14 02:48:33 +01:00
|
|
|
outputs[| 0] = nodeValue("Position", self, JUNCTION_CONNECT.output, VALUE_TYPE.integer, [ 0, 0 ])
|
|
|
|
.setDisplay(VALUE_DISPLAY.vector);
|
|
|
|
|
2024-01-10 06:36:33 +01:00
|
|
|
input_display_list = [ 0,
|
|
|
|
["Search", false], 1, 2, 3,
|
|
|
|
["Alpha", true, 4], 5,
|
|
|
|
]
|
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
static getPreviewValues = function() { return getInputData(0); }
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2023-02-23 07:02:19 +01:00
|
|
|
temp_surface = [ surface_create(1, 1) ];
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2024-05-17 05:19:11 +02:00
|
|
|
static step = function() { #region
|
|
|
|
// var _all = getInputData(3);
|
|
|
|
|
|
|
|
// inputs[| 6].setVisible(_all);
|
|
|
|
} #endregion
|
|
|
|
|
2023-10-31 13:33:36 +01:00
|
|
|
static processData = function(_output, _data, _output_index, _array_index = 0) { #region
|
2023-02-14 02:48:33 +01:00
|
|
|
var _surf = _data[0];
|
|
|
|
var _col = _data[1];
|
2023-10-31 13:33:36 +01:00
|
|
|
var _tol = _data[2];
|
|
|
|
var _all = _data[3];
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2024-01-10 06:36:33 +01:00
|
|
|
var _alp = _data[4];
|
|
|
|
var _alpT = _data[5];
|
2024-05-17 05:19:11 +02:00
|
|
|
// var _axis = _data[6];
|
2024-01-10 06:36:33 +01:00
|
|
|
|
2023-02-14 02:48:33 +01:00
|
|
|
if(!is_surface(_surf)) return [0, 0];
|
|
|
|
|
2023-10-31 13:33:36 +01:00
|
|
|
var _buff = buffer_from_surface(_surf, false);
|
|
|
|
var _sw = surface_get_width_safe(_surf);
|
|
|
|
var _sh = surface_get_height_safe(_surf);
|
|
|
|
buffer_seek(_buff, buffer_seek_start, 0);
|
|
|
|
|
|
|
|
var res = [];
|
2024-01-09 03:39:40 +01:00
|
|
|
var r = _color_get_red(_col);
|
|
|
|
var g = _color_get_green(_col);
|
|
|
|
var b = _color_get_blue(_col);
|
2024-01-10 06:36:33 +01:00
|
|
|
var a = _color_get_alpha(_col);
|
2023-10-31 13:33:36 +01:00
|
|
|
|
|
|
|
for( var i = 0; i < _sh; i++ )
|
|
|
|
for( var j = 0; j < _sw; j++ ) {
|
|
|
|
var _c = buffer_read(_buff, buffer_u32);
|
|
|
|
|
|
|
|
var _r = ((_c & 0x000000FF) >> 0) / 255;
|
|
|
|
var _g = ((_c & 0x0000FF00) >> 8) / 255;
|
|
|
|
var _b = ((_c & 0x00FF0000) >> 16) / 255;
|
|
|
|
var _a = ((_c & 0xFF000000) >> 24) / 255;
|
|
|
|
|
2024-01-10 06:36:33 +01:00
|
|
|
if(!_alp && _a == 0) continue;
|
|
|
|
|
|
|
|
var colMatch = (abs(r - _r) + abs(g - _g) + abs(b - _b)) / 3 <= _tol;
|
|
|
|
if(!colMatch) continue;
|
2023-10-31 13:33:36 +01:00
|
|
|
|
2024-01-10 06:36:33 +01:00
|
|
|
if(!_alp || abs(a - _a) <= _alpT) {
|
2023-10-31 13:33:36 +01:00
|
|
|
if(_all) array_push(res, [ j, i ]);
|
|
|
|
else return [ j, i ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer_delete(_buff);
|
|
|
|
return _all? res : [ -1, -1 ];
|
|
|
|
} #endregion
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2023-10-31 13:33:36 +01:00
|
|
|
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
|
2023-02-14 02:48:33 +01:00
|
|
|
var bbox = drawGetBbox(xx, yy, _s);
|
2024-01-10 06:36:33 +01:00
|
|
|
var col = getInputData(1);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
|
|
|
if(bbox.h <= 0) return;
|
|
|
|
|
|
|
|
if(is_array(col)) {
|
|
|
|
drawPalette(col, bbox.x0, bbox.y0, bbox.w, bbox.h);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-10 06:36:33 +01:00
|
|
|
drawColor(col, bbox.x0, bbox.y0, bbox.w, bbox.h);
|
2023-10-31 13:33:36 +01:00
|
|
|
} #endregion
|
2023-02-14 02:48:33 +01:00
|
|
|
}
|