187 lines
8.2 KiB
C
187 lines
8.2 KiB
C
|
|
#include "../global.h"
|
|
|
|
void outpaint_image_node_button_on_next_frame(ui_node_t *node) {
|
|
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);
|
|
if (input != NULL) {
|
|
|
|
char *node_name = parser_material_node_name(node, NULL);
|
|
ui_handle_t *h = ui_handle(node_name);
|
|
i32 model = ui_nest(h, 0)->i;
|
|
char *prompt = ui_nest(h, 1)->text;
|
|
|
|
if (string_equals(prompt, "")) {
|
|
prompt = ".";
|
|
}
|
|
|
|
gpu_texture_t *mask = gpu_create_render_target(512, 512, GPU_TEXTURE_FORMAT_RGBA32);
|
|
draw_begin(mask, true, 0xffffffff);
|
|
draw_set_color(0xff000000);
|
|
draw_filled_rect(64, 64, 512 - 128, 512 - 128);
|
|
draw_end();
|
|
|
|
gpu_texture_t *input_scaled = gpu_create_render_target(512, 512, GPU_TEXTURE_FORMAT_RGBA32);
|
|
draw_begin(input_scaled, true, model == 0 ? 0xff808080 : 0xffff0000);
|
|
draw_scaled_image(input, 64, 64, 512 - 128, 512 - 128);
|
|
draw_end();
|
|
|
|
// #ifdef IRON_BGRA
|
|
// let input_buf: buffer_t = export_arm_bgra_swap(gpu_get_texture_pixels(input)); // Vulkan non-rt textures need a flip
|
|
// #else
|
|
// let input_buf: buffer_t = gpu_get_texture_pixels(input);
|
|
// #endif
|
|
|
|
char *dir = neural_node_dir();
|
|
iron_write_png(string("%s%sinput.png", dir, PATH_SEP), gpu_get_texture_pixels(input_scaled), input_scaled->width, input_scaled->height, 0);
|
|
iron_write_png(string("%s%smask.png", dir, PATH_SEP), gpu_get_texture_pixels(mask), mask->width, mask->height, 0);
|
|
|
|
string_array_t *argv;
|
|
if (model == 0) {
|
|
argv = any_array_create_from_raw(
|
|
(void *[]){
|
|
string("%s/%s", dir, neural_node_sd_bin()),
|
|
"-m",
|
|
string("%s/v1-5-pruned-emaonly.safetensors", dir),
|
|
"--offload-to-cpu",
|
|
"--steps",
|
|
"30",
|
|
"-s",
|
|
"-1",
|
|
"--cfg-scale",
|
|
"0",
|
|
"--strength",
|
|
"1",
|
|
"-W",
|
|
"512",
|
|
"-H",
|
|
"512",
|
|
"-p",
|
|
prompt,
|
|
"-i",
|
|
string("%s/input.png", dir),
|
|
"--mask",
|
|
string("%s/mask.png", dir),
|
|
"-o",
|
|
string("%s/output.png", dir),
|
|
NULL,
|
|
},
|
|
25);
|
|
}
|
|
else {
|
|
argv = any_array_create_from_raw(
|
|
(void *[]){
|
|
string("%s/%s", dir, neural_node_sd_bin()),
|
|
"--diffusion-model",
|
|
string("%s/qwen-image-edit-2511-Q4_K_S.gguf", dir),
|
|
"--vae",
|
|
string("%s/Qwen_Image-VAE.safetensors", dir),
|
|
"--llm",
|
|
string("%s/Qwen2.5-VL-7B-Instruct-Q4_K_S.gguf", dir),
|
|
"--llm_vision",
|
|
string("%s/mmproj-F16.gguf", dir),
|
|
"--offload-to-cpu",
|
|
"--diffusion-fa",
|
|
"--qwen-image-zero-cond-t",
|
|
"--steps",
|
|
"50",
|
|
"-s",
|
|
"-1",
|
|
"-W",
|
|
"512",
|
|
"-H",
|
|
"512",
|
|
"-p",
|
|
"replace red squares by extending image contents", // prompt,
|
|
"-r",
|
|
string("%s/input.png", dir),
|
|
"-o",
|
|
string("%s/output.png", dir),
|
|
NULL,
|
|
},
|
|
27);
|
|
}
|
|
|
|
iron_exec_async(argv->buffer[0], argv->buffer);
|
|
sys_notify_on_update(neural_node_check_result, node);
|
|
}
|
|
}
|
|
|
|
void outpaint_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);
|
|
char *node_name = parser_material_node_name(node, NULL);
|
|
ui_handle_t *h = ui_handle(node_name);
|
|
string_array_t *models = any_array_create_from_raw(
|
|
(void *[]){
|
|
"Stable Diffusion",
|
|
"Qwen Image Edit",
|
|
},
|
|
2);
|
|
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);
|
|
node->buttons->buffer[0]->height = string_split(prompt, "\n")->length + 2;
|
|
|
|
if (neural_node_button(node, models->buffer[model])) {
|
|
sys_notify_on_next_frame(&outpaint_image_node_button_on_next_frame, node);
|
|
}
|
|
}
|
|
|
|
void outpaint_image_node_init() {
|
|
|
|
ui_node_t *outpaint_image_node_def =
|
|
GC_ALLOC_INIT(ui_node_t, {.id = 0,
|
|
.name = _tr("Outpaint Image"),
|
|
.type = "NEURAL_OUTPAINT_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 = "outpaint_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});
|
|
|
|
any_array_push(nodes_material_neural, outpaint_image_node_def);
|
|
any_map_set(parser_material_node_vectors, "NEURAL_OUTPAINT_IMAGE", neural_node_vector);
|
|
any_map_set(ui_nodes_custom_buttons, "outpaint_image_node_button", outpaint_image_node_button);
|
|
}
|