2023-02-28 09:43:01 +01:00
|
|
|
function Node_Palette_Replace(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
|
2023-02-14 05:32:32 +01:00
|
|
|
name = "Palette Replace";
|
2023-01-09 03:14:20 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
w = 96;
|
2023-01-09 03:14:20 +01:00
|
|
|
|
2023-07-21 12:40:20 +02:00
|
|
|
inputs[| 0] = nodeValue("Palette in", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, DEF_PALETTE )
|
2023-02-14 05:32:32 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.palette)
|
|
|
|
.setVisible(true, true);
|
2023-01-09 03:14:20 +01:00
|
|
|
|
2023-07-21 12:40:20 +02:00
|
|
|
inputs[| 1] = nodeValue("Palette from", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, DEF_PALETTE )
|
2023-01-09 03:14:20 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.palette);
|
|
|
|
|
2023-07-21 12:40:20 +02:00
|
|
|
inputs[| 2] = nodeValue("Palette to", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, DEF_PALETTE )
|
2023-01-09 03:14:20 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.palette);
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 3] = nodeValue("Threshold", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.1)
|
2023-01-09 03:14:20 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider, [0, 1, 0.01]);
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
input_display_list = [ 0,
|
|
|
|
["Palette", false], 1, 2, 3,
|
2023-01-09 03:14:20 +01:00
|
|
|
];
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.color, [ ] )
|
|
|
|
.setDisplay(VALUE_DISPLAY.palette);
|
2023-01-09 03:14:20 +01:00
|
|
|
|
2023-08-17 16:56:54 +02:00
|
|
|
static processData = function(_outSurf, _data, _output_index, _array_index) {
|
2023-02-14 05:32:32 +01:00
|
|
|
var pal = _data[0];
|
|
|
|
var pfr = _data[1];
|
|
|
|
var pto = _data[2];
|
|
|
|
var thr = _data[3];
|
|
|
|
var palo = [];
|
2023-01-09 03:14:20 +01:00
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(pal); i < n; i++ ) {
|
2023-02-14 05:32:32 +01:00
|
|
|
var c = pal[i];
|
2023-01-09 03:14:20 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
var fromValue = 999;
|
|
|
|
var fromIndex = -1;
|
|
|
|
for( var j = 0; j < array_length(pfr); j++ ) {
|
|
|
|
var fr = pfr[j];
|
|
|
|
|
|
|
|
var dist = color_diff(c, fr);
|
|
|
|
if(dist <= thr && dist < fromValue) {
|
|
|
|
fromValue = dist;
|
|
|
|
fromIndex = j;
|
|
|
|
}
|
|
|
|
}
|
2023-01-09 03:14:20 +01:00
|
|
|
|
2023-08-10 11:51:16 +02:00
|
|
|
palo[i] = fromIndex == -1? c : array_safe_get(pto, fromIndex, c, ARRAY_OVERFLOW.loop);
|
2023-02-14 05:32:32 +01:00
|
|
|
}
|
2023-01-09 03:14:20 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
return palo;
|
|
|
|
}
|
|
|
|
|
2023-03-05 07:16:44 +01:00
|
|
|
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
|
2023-02-14 05:32:32 +01:00
|
|
|
var bbox = drawGetBbox(xx, yy, _s);
|
|
|
|
if(bbox.h < 1) return;
|
2023-01-09 03:14:20 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
var pal = outputs[| 0].getValue();
|
|
|
|
if(array_length(pal) && is_array(pal[0])) return;
|
|
|
|
drawPalette(pal, bbox.x0, bbox.y0, bbox.w, bbox.h);
|
2023-01-09 03:14:20 +01:00
|
|
|
}
|
|
|
|
}
|