2026-03-09 13:17:15 +01:00
|
|
|
|
|
|
|
|
#include "../global.h"
|
|
|
|
|
|
2026-06-16 17:32:52 +02:00
|
|
|
static string_array_t *edit_image_node_flux_klein_args(char *dir) {
|
2026-05-29 20:02:12 +02:00
|
|
|
string_array_t *argv = any_array_create_from_raw(
|
|
|
|
|
(void *[]){
|
2026-06-18 12:42:54 +02:00
|
|
|
string("%s/%s", dir, neural_node_iris_bin()),
|
|
|
|
|
"-d",
|
|
|
|
|
string("%s", dir),
|
2026-05-29 20:02:12 +02:00
|
|
|
},
|
2026-06-18 12:42:54 +02:00
|
|
|
3);
|
2026-05-29 20:02:12 +02:00
|
|
|
return argv;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 12:56:38 +01:00
|
|
|
void edit_image_node_button(i32 node_id) {
|
|
|
|
|
ui_node_canvas_t *canvas = ui_nodes_get_canvas(true);
|
|
|
|
|
ui_node_t *node = ui_get_node(canvas->nodes, node_id);
|
2026-03-10 11:49:57 +01:00
|
|
|
char *node_name = parser_material_node_name(node, NULL);
|
2026-03-06 12:56:38 +01:00
|
|
|
ui_handle_t *h = ui_handle(node_name);
|
|
|
|
|
|
2026-06-18 12:42:54 +02:00
|
|
|
string_array_t *models = any_array_create_from_raw((void *[]){"FLUX 2 klein"}, 1);
|
2026-05-29 20:02:12 +02:00
|
|
|
i32 model = ui_combo(ui_nest(h, 0), models, tr("Model"), false, UI_ALIGN_LEFT, true);
|
|
|
|
|
char *prompt = ui_text_area(ui_nest(h, 1), UI_ALIGN_LEFT, true, tr("prompt"), true);
|
2026-06-16 17:32:52 +02:00
|
|
|
node->buttons->buffer[0]->height = string_split(prompt, "\n")->length + 4;
|
|
|
|
|
|
|
|
|
|
ui_handle_t *hs = ui_nest(h, 2);
|
|
|
|
|
if (hs->init) {
|
|
|
|
|
hs->f = 1.0;
|
|
|
|
|
}
|
|
|
|
|
f32 strength = ui_slider(hs, tr("Strength"), 0.0, 1.0, true, 100.0, true, UI_ALIGN_LEFT, true);
|
|
|
|
|
|
|
|
|
|
bool tiled = ui_check(ui_nest(h, 3), tr("Tiled"), "");
|
2026-03-06 12:56:38 +01:00
|
|
|
|
|
|
|
|
if (neural_node_button(node, models->buffer[model])) {
|
|
|
|
|
ui_node_t *from_node = neural_from_node(node->inputs->buffer[0], 0);
|
|
|
|
|
gpu_texture_t *input = ui_nodes_get_node_preview_image(from_node);
|
2026-03-07 21:12:59 +01:00
|
|
|
if (input != NULL) {
|
2026-03-10 11:49:57 +01:00
|
|
|
#ifdef IRON_BGRA
|
2026-06-05 14:48:27 +02:00
|
|
|
buffer_t *input_buf = buffer_bgra_swap(gpu_get_texture_pixels(input)); // Vulkan non-rt textures need a flip
|
2026-03-10 11:49:57 +01:00
|
|
|
#else
|
2026-03-06 12:56:38 +01:00
|
|
|
buffer_t *input_buf = gpu_get_texture_pixels(input);
|
2026-03-10 11:49:57 +01:00
|
|
|
#endif
|
2026-03-06 12:56:38 +01:00
|
|
|
|
2026-03-07 21:12:59 +01:00
|
|
|
char *dir = neural_node_dir();
|
2026-03-10 11:49:57 +01:00
|
|
|
iron_write_png(string("%s%sinput.png", dir, PATH_SEP), input_buf, input->width, input->height, 0);
|
2026-03-06 12:56:38 +01:00
|
|
|
|
2026-05-29 20:02:12 +02:00
|
|
|
string_array_t *argv;
|
|
|
|
|
if (model == 0) {
|
2026-06-16 17:32:52 +02:00
|
|
|
argv = edit_image_node_flux_klein_args(dir);
|
2026-05-29 20:02:12 +02:00
|
|
|
}
|
2026-06-16 17:32:52 +02:00
|
|
|
|
2026-06-18 12:42:54 +02:00
|
|
|
// string_array_push(argv, string("%f", strength));
|
|
|
|
|
string_array_push(argv, "--seed");
|
2026-06-16 17:32:52 +02:00
|
|
|
string_array_push(argv, "-1");
|
|
|
|
|
string_array_push(argv, "-W");
|
|
|
|
|
string_array_push(argv, string("%d", g_config->neural_res));
|
|
|
|
|
string_array_push(argv, "-H");
|
|
|
|
|
string_array_push(argv, string("%d", g_config->neural_res));
|
|
|
|
|
string_array_push(argv, "-p");
|
|
|
|
|
string_array_push(argv, prompt);
|
2026-06-18 12:42:54 +02:00
|
|
|
string_array_push(argv, "-i");
|
2026-06-16 17:32:52 +02:00
|
|
|
string_array_push(argv, string("%s/input.png", dir));
|
|
|
|
|
string_array_push(argv, "-o");
|
|
|
|
|
string_array_push(argv, string("%s/output.png", dir));
|
|
|
|
|
if (tiled) {
|
2026-06-18 12:42:54 +02:00
|
|
|
string_array_push(argv, "--tileable");
|
|
|
|
|
}
|
|
|
|
|
if (g_config->neural_res >= 2048) {
|
|
|
|
|
string_array_push(argv, "--vae-tiling");
|
2026-05-29 20:02:12 +02:00
|
|
|
}
|
2026-06-16 17:32:52 +02:00
|
|
|
string_array_push(argv, NULL);
|
2026-03-06 12:56:38 +01:00
|
|
|
|
|
|
|
|
iron_exec_async(argv->buffer[0], argv->buffer);
|
|
|
|
|
sys_notify_on_update(neural_node_check_result, node);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-04 21:38:20 +02:00
|
|
|
|
|
|
|
|
void edit_image_node_init() {
|
|
|
|
|
|
2026-04-05 16:09:00 +02:00
|
|
|
ui_node_t *edit_image_node_def =
|
|
|
|
|
GC_ALLOC_INIT(ui_node_t, {.id = 0,
|
|
|
|
|
.name = _tr("Edit Image"),
|
|
|
|
|
.type = "NEURAL_EDIT_IMAGE",
|
|
|
|
|
.x = 0,
|
|
|
|
|
.y = 0,
|
|
|
|
|
.color = 0xff4982a0,
|
|
|
|
|
.inputs = any_array_create_from_raw(
|
|
|
|
|
(void *[]){
|
|
|
|
|
GC_ALLOC_INIT(ui_node_socket_t, {.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}),
|
|
|
|
|
},
|
|
|
|
|
1),
|
|
|
|
|
.outputs = any_array_create_from_raw(
|
|
|
|
|
(void *[]){
|
|
|
|
|
GC_ALLOC_INIT(ui_node_socket_t, {.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}),
|
|
|
|
|
},
|
|
|
|
|
1),
|
|
|
|
|
.buttons = any_array_create_from_raw(
|
|
|
|
|
(void *[]){
|
|
|
|
|
GC_ALLOC_INIT(ui_node_button_t, {.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}),
|
|
|
|
|
},
|
|
|
|
|
1),
|
|
|
|
|
.width = 0,
|
|
|
|
|
.flags = 0});
|
2026-04-04 21:38:20 +02:00
|
|
|
|
|
|
|
|
any_array_push(nodes_material_neural, edit_image_node_def);
|
|
|
|
|
any_map_set(parser_material_node_vectors, "NEURAL_EDIT_IMAGE", neural_node_vector);
|
|
|
|
|
any_map_set(ui_nodes_custom_buttons, "edit_image_node_button", edit_image_node_button);
|
|
|
|
|
}
|