@@ -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 ,
0 commit comments