Skip to content

Commit d73d4d8

Browse files
committed
paint: use iris for neural nodes
1 parent 9630146 commit d73d4d8

9 files changed

Lines changed: 56 additions & 207 deletions

File tree

paint/sources/functions.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,6 @@ void neural_node_load_result(ui_node_t *node);
779779
void text_to_image_node_run(ui_node_t *node, void (*callback)(ui_node_t *));
780780
void upscale_image_node_init();
781781
void image_to_pbr_node_init();
782-
void inpaint_image_node_init();
783782
void text_to_image_node_init();
784783
void texture_mesh_node_init();
785784
void text_to_text_node_clear();

paint/sources/main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@
105105
#include "nodes_neural/edit_image_node.c"
106106
#include "nodes_neural/image_to_3d_mesh_node.c"
107107
#include "nodes_neural/image_to_pbr_node.c"
108-
#include "nodes_neural/inpaint_image_node.c"
109108
#include "nodes_neural/neural_node.c"
110109
#include "nodes_neural/neural_node_models.c"
111110
#include "nodes_neural/repeat_node.c"

paint/sources/nodes_material.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ void nodes_material_init() {
9191
image_to_3d_mesh_node_init();
9292
#endif
9393
image_to_pbr_node_init();
94-
inpaint_image_node_init();
9594
repeat_node_init();
9695
save_image_node_init();
9796
text_to_image_node_init();

paint/sources/nodes_neural/edit_image_node.c

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,52 @@ void edit_image_node_button(i32 node_id) {
2323
char *prompt = ui_text_area(ui_nest(h, 1), UI_ALIGN_LEFT, true, tr("prompt"), true);
2424
node->buttons->buffer[0]->height = string_split(prompt, "\n")->length + 4;
2525

26-
ui_handle_t *hs = ui_nest(h, 2);
27-
if (hs->init) {
28-
hs->f = 1.0;
29-
}
30-
f32 strength = ui_slider(hs, tr("Strength"), 0.0, 1.0, true, 100.0, true, UI_ALIGN_LEFT, true);
26+
f32 variance = ui_slider(ui_nest(h, 2), tr("Variance"), 0.0, 1.0, true, 100.0, true, UI_ALIGN_LEFT, true);
3127

32-
bool tiled = ui_check(ui_nest(h, 3), tr("Tiled"), "");
28+
bool tiled = ui_check(ui_nest(h, 3), tr("Tile"), "");
3329

3430
if (neural_node_button(node, models->buffer[model])) {
3531
ui_node_t *from_node = neural_from_node(node->inputs->buffer[0], 0);
3632
gpu_texture_t *input = ui_nodes_get_node_preview_image(from_node);
3733
if (input != NULL) {
34+
ui_node_t *mask_node = neural_from_node(node->inputs->buffer[1], 1);
35+
gpu_texture_t *mask = mask_node != NULL ? ui_nodes_get_node_preview_image(mask_node) : NULL;
36+
37+
char *dir = neural_node_dir();
38+
3839
#ifdef IRON_BGRA
3940
buffer_t *input_buf = buffer_bgra_swap(gpu_get_texture_pixels(input)); // Vulkan non-rt textures need a flip
4041
#else
4142
buffer_t *input_buf = gpu_get_texture_pixels(input);
4243
#endif
43-
44-
char *dir = neural_node_dir();
4544
iron_write_png(string("%s%sinput.png", dir, PATH_SEP), input_buf, input->width, input->height, 0);
4645

46+
if (mask != NULL) {
47+
buffer_t *mask_buf = gpu_get_texture_pixels(mask);
48+
for (uint32_t i = 0; i < mask_buf->length / 4; ++i) {
49+
if (mask_buf->buffer[i * 4] < 200 || mask_buf->buffer[i * 4 + 1] < 200 || mask_buf->buffer[i * 4 + 2] < 200) {
50+
mask_buf->buffer[i * 4] = 255;
51+
mask_buf->buffer[i * 4 + 1] = 255;
52+
mask_buf->buffer[i * 4 + 2] = 255;
53+
}
54+
else {
55+
mask_buf->buffer[i * 4] = 0;
56+
mask_buf->buffer[i * 4 + 1] = 0;
57+
mask_buf->buffer[i * 4 + 2] = 0;
58+
}
59+
}
60+
iron_write_png(string("%s%smask.png", dir, PATH_SEP), mask_buf, mask->width, mask->height, 0);
61+
}
62+
4763
string_array_t *argv;
4864
if (model == 0) {
4965
argv = edit_image_node_flux_klein_args(dir);
5066
}
5167

52-
// string_array_push(argv, string("%f", strength));
68+
if (variance > 0.0) {
69+
string_array_push(argv, "--vary");
70+
string_array_push(argv, string("%f", variance));
71+
}
5372
string_array_push(argv, "--seed");
5473
string_array_push(argv, "-1");
5574
string_array_push(argv, "-W");
@@ -60,10 +79,14 @@ void edit_image_node_button(i32 node_id) {
6079
string_array_push(argv, prompt);
6180
string_array_push(argv, "-i");
6281
string_array_push(argv, string("%s/input.png", dir));
82+
if (mask != NULL) {
83+
string_array_push(argv, "--mask");
84+
string_array_push(argv, string("%s/mask.png", dir));
85+
}
6386
string_array_push(argv, "-o");
6487
string_array_push(argv, string("%s/output.png", dir));
6588
if (tiled) {
66-
string_array_push(argv, "--tileable");
89+
string_array_push(argv, "--tile");
6790
}
6891
if (g_config->neural_res >= 2048) {
6992
string_array_push(argv, "--vae-tiling");
@@ -97,8 +120,18 @@ void edit_image_node_init() {
97120
.max = 1.0,
98121
.precision = 100,
99122
.display = 0}),
123+
GC_ALLOC_INIT(ui_node_socket_t, {.id = 0,
124+
.node_id = 0,
125+
.name = _tr("Mask"),
126+
.type = "VALUE",
127+
.color = 0xffa1a1a1,
128+
.default_value = f32_array_create_x(1.0),
129+
.min = 0.0,
130+
.max = 1.0,
131+
.precision = 100,
132+
.display = 0}),
100133
},
101-
1),
134+
2),
102135
.outputs = any_array_create_from_raw(
103136
(void *[]){
104137
GC_ALLOC_INIT(ui_node_socket_t, {.id = 0,

paint/sources/nodes_neural/image_to_pbr_node.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void image_to_pbr_node_check_result(void (*done)(gpu_texture_t *)) {
6363
}
6464
}
6565

66-
void image_to_pbr_node_run_da3(bool tileable, int width, int height, void (*done)(gpu_texture_t *)) {
66+
void image_to_pbr_node_run_da3(bool tile, int width, int height, void (*done)(gpu_texture_t *)) {
6767
char *dir = neural_node_dir();
6868
string_array_t *argv = any_array_create_from_raw(
6969
(void *[]){
@@ -81,8 +81,8 @@ void image_to_pbr_node_run_da3(bool tileable, int width, int height, void (*done
8181
string("%s/output.png", dir),
8282
},
8383
12);
84-
if (tileable) {
85-
string_array_push(argv, "--tileable");
84+
if (tile) {
85+
string_array_push(argv, "--tile");
8686
}
8787
string_array_push(argv, NULL);
8888

@@ -288,9 +288,9 @@ void image_to_pbr_node_button(i32 node_id) {
288288
#endif
289289
iron_write_png(string("%s%sinput.png", dir, PATH_SEP), input_buf, input->width, input->height, 0);
290290

291-
bool tileable = node->buttons->buffer[1]->default_value->buffer[0] > 0.0;
291+
bool tile = node->buttons->buffer[1]->default_value->buffer[0] > 0.0;
292292
image_to_pbr_node_node_id = node_id;
293-
image_to_pbr_node_run_da3(tileable, input->width, input->height, &image_to_pbr_node_depth_done);
293+
image_to_pbr_node_run_da3(tile, input->width, input->height, &image_to_pbr_node_depth_done);
294294
}
295295
}
296296
}
@@ -383,7 +383,7 @@ void image_to_pbr_node_init() {
383383
.max = 1.0,
384384
.precision = 100,
385385
.height = 2}),
386-
GC_ALLOC_INIT(ui_node_button_t, {.name = _tr("Tiled"),
386+
GC_ALLOC_INIT(ui_node_button_t, {.name = _tr("Tile"),
387387
.type = "BOOL",
388388
.output = 0,
389389
.default_value = f32_array_create_x(0),

paint/sources/nodes_neural/inpaint_image_node.c

Lines changed: 0 additions & 180 deletions
This file was deleted.

paint/sources/nodes_neural/text_to_image_node.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void text_to_image_node_run(ui_node_t *node, void (*callback)(ui_node_t *)) {
3838
string_array_push(argv, "-p");
3939
string_array_push(argv, string("'%s'", prompt));
4040
if (node->buttons->buffer[1]->default_value->buffer[0] > 0.0) {
41-
string_array_push(argv, "--tileable");
41+
string_array_push(argv, "--tile");
4242
}
4343
string_array_push(argv, NULL);
4444

@@ -112,7 +112,7 @@ void text_to_image_node_init() {
112112
.max = 1.0,
113113
.precision = 100,
114114
.height = 1}),
115-
GC_ALLOC_INIT(ui_node_button_t, {.name = _tr("Tiled"),
115+
GC_ALLOC_INIT(ui_node_button_t, {.name = _tr("Tile"),
116116
.type = "BOOL",
117117
.output = 0,
118118
.default_value = f32_array_create_x(0),

paint/sources/nodes_neural/upscale_image_node.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ void upscale_image_node_button(i32 node_id) {
3838
},
3939
8);
4040

41-
bool tileable = node->buttons->buffer[1]->default_value->buffer[0] > 0.0;
42-
if (tileable) {
43-
string_array_push(argv, "--tileable");
41+
if (node->buttons->buffer[1]->default_value->buffer[0] > 0.0) {
42+
string_array_push(argv, "--tile");
4443
}
4544
string_array_push(argv, NULL);
4645

@@ -98,7 +97,7 @@ void upscale_image_node_init() {
9897
.max = 1.0,
9998
.precision = 100,
10099
.height = 2}),
101-
GC_ALLOC_INIT(ui_node_button_t, {.name = _tr("Tiled"),
100+
GC_ALLOC_INIT(ui_node_button_t, {.name = _tr("Tile"),
102101
.type = "BOOL",
103102
.output = 0,
104103
.default_value = f32_array_create_x(0),

paint/sources/util/util_nodes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ gpu_texture_t *ui_nodes_get_node_preview_image(ui_node_t *n) {
100100
img = rt->_image;
101101
}
102102
}
103-
else if (starts_with(n->type, "NEURAL_")) {
103+
else if (starts_with(n->type, "NEURAL_") && n->outputs->length > 0) {
104104
i32 socket = i32_imap_get(g_context->node_preview_socket_map, n->id);
105105
if (socket < 0 || socket >= n->outputs->length) {
106106
socket = 0;

0 commit comments

Comments
 (0)