Files
armorpaint/paint/sources/neural_nodes/edit_image_node.ts
T

85 lines
2.5 KiB
TypeScript
Raw Normal View History

2025-09-01 14:48:43 +02:00
2025-10-14 21:46:04 +02:00
function edit_image_node_init() {
array_push(nodes_material_neural, edit_image_node_def);
2025-11-13 14:04:57 +01:00
map_set(parser_material_node_vectors, "NEURAL_EDIT_IMAGE", neural_node_vector);
2025-10-14 21:46:04 +02:00
map_set(ui_nodes_custom_buttons, "edit_image_node_button", edit_image_node_button);
2025-10-10 22:26:38 +02:00
}
2025-10-14 21:46:04 +02:00
function edit_image_node_button(node_id: i32) {
2025-10-13 16:35:03 +02:00
let canvas: ui_node_canvas_t = ui_nodes_get_canvas(true);
2025-10-15 18:39:55 +02:00
let node: ui_node_t = ui_get_node(canvas.nodes, node_id);
2025-10-13 16:35:03 +02:00
2025-10-15 18:39:55 +02:00
let models: string[] = [ "Qwen Image Edit" ];
let model: i32 = ui_combo(ui_handle(__ID__), models, tr("Model"));
2025-10-13 16:35:03 +02:00
2025-10-15 18:39:55 +02:00
let prompt: string = ui_text_area(ui_handle(__ID__), ui_align_t.LEFT, true, tr("prompt"), true);
2025-10-14 21:46:04 +02:00
node.buttons[0].height = string_split(prompt, "\n").length + 2;
2025-11-13 14:04:57 +01:00
if (neural_node_button()) {
let from_node: ui_node_t = neural_from_node(node.inputs[0]);
2025-10-13 16:35:03 +02:00
let input: gpu_texture_t = ui_nodes_get_node_preview_image(from_node);
if (input != null) {
2025-11-13 14:04:57 +01:00
let dir: string = neural_node_dir();
2025-10-13 16:35:03 +02:00
iron_write_png(dir + path_sep + "input.png", gpu_get_texture_pixels(input), input.width, input.height, 0);
2025-10-14 21:46:04 +02:00
2025-10-13 16:35:03 +02:00
let argv: string[] = [
2025-11-14 16:04:36 +01:00
dir + "/sd_vulkan", "--diffusion-model", dir + "/Qwen-Image-Edit-2509-Q4_K_S.gguf", "--vae", dir + "/Qwen_Image-VAE.safetensors", "--qwen2vl",
2025-11-13 14:04:57 +01:00
dir + "/Qwen2.5-VL-7B-Instruct-Q4_K_S.gguf", "--qwen2vl_vision", dir + "/mmproj-F16.gguf", "--sampling-method", "euler", "--offload-to-cpu",
2025-11-14 16:04:36 +01:00
"--diffusion-fa", "--steps", "30", "-s", "-1", "-W", "512", "-H", "512", "-p", prompt,
2025-11-06 19:16:12 +01:00
// "-n",
2025-11-14 16:04:36 +01:00
// negative,
2025-11-06 19:18:48 +01:00
"-r", dir + "/input.png", "-o", dir + "/output.png", null
2025-10-13 16:35:03 +02:00
];
2025-10-14 21:46:04 +02:00
2025-10-13 16:35:03 +02:00
iron_exec_async(argv[0], argv.buffer);
2025-11-13 14:04:57 +01:00
sys_notify_on_update(neural_node_check_result, node);
2025-10-13 16:35:03 +02:00
}
}
2025-10-10 22:26:38 +02:00
}
2025-10-14 21:46:04 +02:00
let edit_image_node_def: ui_node_t = {
2025-10-15 18:39:55 +02:00
id : 0,
name : _tr("Edit Image"),
type : "NEURAL_EDIT_IMAGE",
x : 0,
y : 0,
color : 0xff4982a0,
inputs : [ {
id : 0,
node_id : 0,
name : _tr("Color"),
type : "RGBA",
color : 0xffc7c729,
default_value : f32_array_create_xyzw(1.0, 1.0, 1.0, 1.0),
min : 0.0,
max : 1.0,
precision : 100,
display : 0
} ],
outputs : [ {
id : 0,
node_id : 0,
name : _tr("Color"),
type : "RGBA",
color : 0xffc7c729,
default_value : f32_array_create_xyzw(0.0, 0.0, 0.0, 1.0),
min : 0.0,
max : 1.0,
precision : 100,
display : 0
} ],
buttons : [ {
name : "edit_image_node_button",
type : "CUSTOM",
output : -1,
default_value : f32_array_create_x(0),
data : null,
min : 0.0,
max : 1.0,
precision : 100,
height : 0
} ],
width : 0,
flags : 0
2025-10-10 22:26:38 +02:00
};