- [Posterize] Add color space setting.

This commit is contained in:
Tanasart 2024-05-03 18:40:46 +07:00
parent 57951203af
commit 9eadf0c979
34 changed files with 68 additions and 49 deletions

View file

@ -1,6 +1,6 @@
function Node_create_3D_Obj(_x, _y, _group = noone) { #region
var path = "";
if(!LOADING && !APPENDING && !CLONING) {
if(NODE_NEW_MANUAL) {
path = get_open_filename("3d object|*.obj", "");
key_release();
if(path == "") return noone;

View file

@ -6,7 +6,7 @@ function Node_FLIP_Group_Inline(_x, _y, _group = noone) : Node_Collection_Inline
is_simulation = true;
update_on_frame = true;
if(!LOADING && !APPENDING && !CLONING) {
if(NODE_NEW_MANUAL) {
var _domain = nodeBuild("Node_FLIP_Domain", x, y);
var _spawn = nodeBuild("Node_FLIP_Spawner", x + 160, y);
var _render = nodeBuild("Node_FLIP_Render", x + 320, y);

View file

@ -20,7 +20,7 @@ function Node_VFX_Group(_x, _y, _group = noone) : Node_Collection(_x, _y, _group
custom_input_index = ds_list_size(inputs);
if(!LOADING && !APPENDING && !CLONING) { #region
if(NODE_NEW_MANUAL) { #region
var input = nodeBuild("Node_VFX_Spawner", -256, -32, self);
var output = nodeBuild("Node_VFX_Renderer_Output", 256 + 32 * 5, -32, self);

View file

@ -15,7 +15,7 @@ function Node_VFX_Group_Inline(_x, _y, _group = noone) : Node_Collection_Inline(
prev_nodes = [];
if(!LOADING && !APPENDING && !CLONING) { #region
if(NODE_NEW_MANUAL) { #region
var input = nodeBuild("Node_VFX_Spawner", x, y);
var output = nodeBuild("Node_VFX_Renderer", x + 256, y);

View file

@ -1,6 +1,6 @@
function Node_create_ASE_File_Read(_x, _y, _group = noone) { #region
var path = "";
if(!LOADING && !APPENDING && !CLONING) {
if(NODE_NEW_MANUAL) {
path = get_open_filename("Aseprite file (*.aseprite, *.ase)|*.aseprite;*.ase", "");
key_release();
if(path == "") return noone;
@ -8,7 +8,7 @@ function Node_create_ASE_File_Read(_x, _y, _group = noone) { #region
var node = new Node_ASE_File_Read(_x, _y, _group);
node.inputs[| 0].setValue(path);
node.doUpdate();
if(NODE_NEW_MANUAL) node.doUpdate();
return node;
} #endregion

View file

@ -1,6 +1,6 @@
function Node_create_CSV_File_Read(_x, _y, _group = noone) { #region
var path = "";
if(!LOADING && !APPENDING && !CLONING) {
if(NODE_NEW_MANUAL) {
path = get_open_filename("comma separated value|*.csv", "");
key_release();
if(path == "") return noone;

View file

@ -1,6 +1,6 @@
function Node_create_Display_Image(_x, _y, _group = noone) { #region
var path = "";
if(!LOADING && !APPENDING && !CLONING) {
if(NODE_NEW_MANUAL) {
path = get_open_filename("image|*.png;*.jpg", "");
key_release();
if(path == "") return noone;

View file

@ -10,7 +10,7 @@ function Node_DynaSurf(_x, _y, _group = noone) : Node_Collection(_x, _y, _group)
custom_input_index = ds_list_size(inputs);
custom_output_index = ds_list_size(outputs);
if(!LOADING && !APPENDING && !CLONING) { #region
if(NODE_NEW_MANUAL) { #region
var _input = nodeBuild("Node_DynaSurf_In", -256, -32, self);
var _output = nodeBuild("Node_DynaSurf_Out", 256, -32, self);

View file

@ -1,6 +1,6 @@
function Node_create_Export(_x, _y, _group = noone) { #region
var path = "";
if(!LOADING && !APPENDING && !CLONING) {
if(NODE_NEW_MANUAL) {
path = get_save_filename(@"Portable Network Graphics (.png)|*.png|
Joint Photographic Experts Group (.jpg)|*.jpg|
Graphics Interchange Format (.gif)|*.gif|
@ -13,9 +13,8 @@ MPEG-4 (.mp4)|*.mp4",
var node = new Node_Export(_x, _y, _group);
node.inputs[| 1].setValue(path);
node.extensionCheck();
if(NODE_NEW_MANUAL) node.extensionCheck();
//ds_list_add(PANEL_GRAPH.nodes_list, node);
return node;
}

View file

@ -6,7 +6,7 @@ function Node_Feedback(_x, _y, _group = noone) : Node_Collection(_x, _y, _group)
update_on_frame = true;
reset_all_child = true;
if(!LOADING && !APPENDING && !CLONING) { #region
if(NODE_NEW_MANUAL) { #region
var input = nodeBuild("Node_Feedback_Input", -256, -32, self);
var output = nodeBuild("Node_Feedback_Output", 256, -32, self);

View file

@ -1,8 +1,7 @@
function Node_Flood_Fill(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "Flood Fill";
inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone)
.rejectArray();
inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone);
inputs[| 1] = nodeValue("Mask", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone);

View file

@ -3,6 +3,7 @@
#macro DEF_SURF PROJECT.attributes.surface_dimension
#macro DEF_PALETTE PROJECT.attributes.palette
#macro NODE_NEW_MANUAL !LOADING && !APPENDING && !CLONING
#region
function node_draw_transform_init() {

View file

@ -1,6 +1,6 @@
function Node_create_Image(_x, _y, _group = noone) { #region
var path = "";
if(!LOADING && !APPENDING && !CLONING) {
if(NODE_NEW_MANUAL) {
path = get_open_filename("image|*.png;*.jpg", "");
key_release();
if(path == "") return noone;
@ -8,7 +8,7 @@ function Node_create_Image(_x, _y, _group = noone) { #region
var node = new Node_Image(_x, _y, _group);
node.inputs[| 0].setValue(path);
if(path != "") node.doUpdate();
if(NODE_NEW_MANUAL) node.doUpdate();
return node;
} #endregion

View file

@ -1,6 +1,6 @@
function Node_create_Image_Animated(_x, _y, _group = noone) { #region
var path = "";
if(!LOADING && !APPENDING && !CLONING) {
if(NODE_NEW_MANUAL) {
path = get_open_filenames_compat("image|*.png;*.jpg", "");
key_release();
if(path == "") return noone;
@ -9,7 +9,7 @@ function Node_create_Image_Animated(_x, _y, _group = noone) { #region
var node = new Node_Image_Animated(_x, _y, _group);
var paths = string_splice(path, "\n");
node.inputs[| 0].setValue(paths);
node.doUpdate();
if(NODE_NEW_MANUAL) node.doUpdate();
return node;
} #endregion

View file

@ -1,6 +1,6 @@
function Node_create_Image_gif(_x, _y, _group = noone) { #region
var path = "";
if(!LOADING && !APPENDING && !CLONING) {
if(NODE_NEW_MANUAL) {
path = get_open_filename("animated gif|*.gif", "");
key_release();
if(path == "") return noone;
@ -8,7 +8,7 @@ function Node_create_Image_gif(_x, _y, _group = noone) { #region
var node = new Node_Image_gif(_x, _y, _group);
node.inputs[| 0].setValue(path);
node.doUpdate();
if(NODE_NEW_MANUAL) node.doUpdate();
return node;
} #endregion

View file

@ -1,6 +1,6 @@
function Node_create_Image_Sequence(_x, _y, _group = noone) { #region
var path = "";
if(!LOADING && !APPENDING && !CLONING) {
if(NODE_NEW_MANUAL) {
path = get_open_filenames_compat("image|*.png;*.jpg", "");
key_release();
if(path == "") return noone;
@ -9,7 +9,8 @@ function Node_create_Image_Sequence(_x, _y, _group = noone) { #region
var node = new Node_Image_Sequence(_x, _y, _group);
var paths = string_splice(path, "\n");
node.inputs[| 0].setValue(paths);
node.doUpdate();
if(NODE_NEW_MANUAL) node.doUpdate();
return node;
} #endregion

View file

@ -6,7 +6,7 @@ function Node_Iterate(_x, _y, _group = noone) : Node_Iterator(_x, _y, _group) co
custom_input_index = ds_list_size(inputs);
if(!LOADING && !APPENDING && !CLONING) { #region
if(NODE_NEW_MANUAL) { #region
var input = nodeBuild("Node_Iterator_Input", -256, -32, self);
var output = nodeBuild("Node_Iterator_Output", 256, -32, self);

View file

@ -9,7 +9,7 @@ function Node_Iterate_Each(_x, _y, _group = noone) : Node_Iterator(_x, _y, _grou
custom_input_index = ds_list_size(inputs);
custom_output_index = ds_list_size(inputs);
if(!LOADING && !APPENDING && !CLONING) { #region
if(NODE_NEW_MANUAL) { #region
var input = nodeBuild("Node_Iterator_Each_Input", -256, -32, self);
var output = nodeBuild("Node_Iterator_Each_Output", 256, -32, self);

View file

@ -9,7 +9,7 @@ function Node_Iterate_Filter(_x, _y, _group = noone) : Node_Iterator(_x, _y, _gr
custom_input_index = ds_list_size(inputs);
custom_output_index = ds_list_size(inputs);
if(!LOADING && !APPENDING && !CLONING) { #region
if(NODE_NEW_MANUAL) { #region
var input = nodeBuild("Node_Iterator_Filter_Input", -256, -32, self);
var output = nodeBuild("Node_Iterator_Filter_Output", 256, -32, self);

View file

@ -21,7 +21,7 @@ function Node_Iterate_Sort(_x, _y, _group = noone) : Node_Collection(_x, _y, _gr
outputNode = noone;
nodeValid = false;
if(!LOADING && !APPENDING && !CLONING) { #region
if(NODE_NEW_MANUAL) { #region
var input0 = nodeBuild("Node_Iterator_Sort_Input", -256, -64, self);
input0.setDisplayName("Value 1");
input0.attributes.sort_inputs = 1;

View file

@ -1,6 +1,6 @@
function Node_create_Json_File_Read(_x, _y, _group = noone) { #region
var path = "";
if(!LOADING && !APPENDING && !CLONING) {
if(NODE_NEW_MANUAL) {
path = get_open_filename("JSON file|*.json", "");
key_release();
if(path == "") return noone;

View file

@ -13,7 +13,7 @@ function Node_Pixel_Builder(_x, _y, _group = noone) : Node_Collection(_x, _y, _g
custom_input_index = ds_list_size(inputs);
custom_output_index = ds_list_size(outputs);
if(!LOADING && !APPENDING && !CLONING) {
if(NODE_NEW_MANUAL) {
var input = nodeBuild("Node_PB_Layer", -256, -32, self);
RENDER_ALL
}

View file

@ -26,8 +26,11 @@ function Node_Posterize(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
//////////////////////////////////////////////////////////////////////////////////////////////////
inputs[| 8] = nodeValue("Space", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_button, [ "RGB", "LAB" ]);
input_display_list = [ 5, 0,
["Palette", false, 2], 1, 3, 4, 7,
["Palette", false, 2], 1, 3, 4, 7, 8,
["Alpha", false, 6],
];
@ -42,18 +45,21 @@ function Node_Posterize(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
inputs[| 3].setVisible(!_use_pal);
inputs[| 4].setVisible(!_use_pal);
inputs[| 4].mappableStep();
inputs[| 8].setVisible(_use_pal);
}
static processData = function(_outSurf, _data, _output_index, _array_index) {
var _gra = _data[1];
var _use_gra = _data[2];
var _pal = _data[1];
var _use_pal = _data[2];
var _alp = _data[6];
var _spce = _data[8];
if(_use_gra) {
if(_use_pal) {
surface_set_shader(_outSurf, sh_posterize_palette);
shader_set_f("palette", paletteToArray(_gra));
shader_set_i("keys", array_length(_gra));
shader_set_f("palette", paletteToArray(_pal));
shader_set_i("keys", array_length(_pal));
shader_set_i("alpha", _alp);
shader_set_i("space", _spce);
draw_surface_safe(_data[0]);
surface_reset_shader();

View file

@ -99,7 +99,6 @@ function NodeObject(_name, _spr, _node, _create, tooltip = "", tags = []) constr
var _buildCon = createNode[0];
if(createUseParam) _param = struct_append(_param, createNode[2]);
print($" >> building {node}");
var _node = noone;
if(_buildCon) _node = new createNode[1](_x, _y, _group, _param);
else _node = createNode[1](_x, _y, _group, _param);

View file

@ -10,7 +10,7 @@ function Node_Rigid_Group(_x, _y, _group = noone) : Node_Collection(_x, _y, _gro
update_on_frame = true;
collIndex = irandom_range(1, 9999);
if(!LOADING && !APPENDING && !CLONING) {
if(NODE_NEW_MANUAL) {
var _output = nodeBuild("Node_Rigid_Render_Output", 256, -32, self);
}

View file

@ -9,7 +9,7 @@ function Node_Rigid_Group_Inline(_x, _y, _group = noone) : Node_Collection_Inlin
inputs[| 0] = nodeValue("Gravity", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 10 ])
.setDisplay(VALUE_DISPLAY.vector);
if(!LOADING && !APPENDING && !CLONING) {
if(NODE_NEW_MANUAL) {
var _object = nodeBuild("Node_Rigid_Object", x, y);
var _output = nodeBuild("Node_Rigid_Render", x + 160, y);

View file

@ -58,7 +58,7 @@ function Node_Smoke_Group(_x, _y, _group = noone) : Node_Collection(_x, _y, _gro
domain = fd_rectangle_create(PROJECT.attributes.surface_dimension[0], PROJECT.attributes.surface_dimension[1]);
if(!LOADING && !APPENDING && !CLONING) {
if(NODE_NEW_MANUAL) {
var _render = nodeBuild("Node_Smoke_Render_Output", 128, -32, self);
}

View file

@ -5,7 +5,7 @@ function Node_Smoke_Group_Inline(_x, _y, _group = noone) : Node_Collection_Inlin
is_simulation = true;
if(!LOADING && !APPENDING && !CLONING) {
if(NODE_NEW_MANUAL) {
var _domain = nodeBuild("Node_Smoke_Domain", x, y);
var _render = nodeBuild("Node_Smoke_Render", x + 320, y);

View file

@ -7,7 +7,7 @@ function Node_Strand_Group(_x, _y, _group = noone) : Node_Collection(_x, _y, _gr
ungroupable = false;
update_on_frame = true;
if(!LOADING && !APPENDING && !CLONING) {
if(NODE_NEW_MANUAL) {
var _create = nodeBuild("Node_Strand_Create", -384, -32, self);
var _update = nodeBuild("Node_Strand_Update", 0, -32, self);
var _render = nodeBuild("Node_Strand_Render", 128, -32, self);

View file

@ -6,7 +6,7 @@ function Node_Strand_Group_Inline(_x, _y, _group = noone) : Node_Collection_Inli
is_simulation = true;
update_on_frame = true;
if(!LOADING && !APPENDING && !CLONING) {
if(NODE_NEW_MANUAL) {
var _create = nodeBuild("Node_Strand_Create", x, y);
var _render = nodeBuild("Node_Strand_Render", x + 256, y);

View file

@ -1,6 +1,6 @@
function Node_create_Text_File_Read(_x, _y, _group = noone) { #region
var path = "";
if(!LOADING && !APPENDING && !CLONING) {
if(NODE_NEW_MANUAL) {
path = get_open_filename("text file|*.txt", "");
key_release();
if(path == "") return noone;

View file

@ -1,6 +1,6 @@
function Node_create_WAV_File_Read(_x, _y, _group = noone) { #region
var path = "";
if(!LOADING && !APPENDING && !CLONING) {
if(NODE_NEW_MANUAL) {
path = get_open_filename("audio|*.wav", "");
key_release();
if(path == "") return noone;
@ -8,7 +8,7 @@ function Node_create_WAV_File_Read(_x, _y, _group = noone) { #region
var node = new Node_WAV_File_Read(_x, _y, _group);
node.inputs[| 0].setValue(path);
node.doUpdate();
if(NODE_NEW_MANUAL) node.doUpdate();
return node;
} #endregion

View file

@ -1013,6 +1013,8 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
node_hover = node_hovering;
if(value_focus) {
print($"Right click value focus {value_focus}");
__junction_hovering = value_focus;
var menu = [ menu_junc_color ];
@ -1062,6 +1064,8 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
menuCall("graph_node_selected_menu",,, menu);
} else if(node_hover && node_hover.draggable) {
print($"Right click node hover {node_hover}");
var menu = [];
array_push(menu, menu_node_color, -1, menu_sent_to_preview, menu_send_to_window, menu_sent_to_inspector);
if(!DEMO)
@ -1084,6 +1088,8 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
menuCall("graph_node_selected_multiple_menu",,, menu );
} else if(node_hover == noone) {
print($"Right click not node hover");
var menu = [];
__junction_hovering = junction_hovering;

View file

@ -6,6 +6,7 @@ varying vec4 v_vColour;
uniform vec4 palette[PALETTE_LIMIT];
uniform int keys;
uniform int alpha;
uniform int space;
vec3 rgb2xyz( vec3 c ) {
vec3 tmp;
@ -32,23 +33,30 @@ vec3 rgb2lab(vec3 c) {
return vec3( lab.x / 100.0, 0.5 + 0.5 * ( lab.y / 127.0 ), 0.5 + 0.5 * ( lab.z / 127.0 ));
}
float colorDifferent(in vec4 c1, in vec4 c2) {
float colorDifferentLAB(in vec4 c1, in vec4 c2) {
vec3 lab1 = rgb2lab(c1.rgb);
vec3 lab2 = rgb2lab(c2.rgb);
return length(lab1 - lab2);
}
float colorDifferentRGB(in vec4 c1, in vec4 c2) {
return length(c1.rgb - c2.rgb);
}
void main() {
vec4 _col = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord );
vec4 col = alpha == 1? _col * _col.a : _col;
int closet_index = 0;
float closet_value = 99.;
int closet_index = 0;
float closet_value = 999.;
for(int i = 0; i < keys; i++) {
vec4 p_col = palette[i];
float dif = colorDifferent(p_col, col);
float dif = 0.;
if(space == 0) dif = colorDifferentRGB(p_col, col);
else if(space == 1) dif = colorDifferentLAB(p_col, col);
if(dif < closet_value) {
closet_value = dif;