@@ -90,9 +90,11 @@ def define_schema(cls):
9090 category = "krita" ,
9191 inputs = [
9292 io .Image .Input ("images" ),
93+ io .Int .Input ("x" , "offset x" , default = 0 ),
94+ io .Int .Input ("y" , "offset y" , default = 0 ),
9395 io .String .Input ("name" , default = "" ),
9496 io .Combo .Input (
95- "batch_mode" , OutputBatchMode , "batch_mode " , default = OutputBatchMode .default
97+ "batch_mode" , OutputBatchMode , "batch mode " , default = OutputBatchMode .default
9698 ),
9799 io .Boolean .Input ("resize_canvas" , "resize canvas" , default = False ),
98100 ],
@@ -103,13 +105,17 @@ def define_schema(cls):
103105 def execute (
104106 cls ,
105107 images : torch .Tensor ,
108+ x : int = 0 ,
109+ y : int = 0 ,
106110 name = "" ,
107111 batch_mode : OutputBatchMode | str = OutputBatchMode .default ,
108112 resize_canvas = False ,
109113 ):
110114 batch_mode = batch_mode .value if isinstance (batch_mode , OutputBatchMode ) else batch_mode
111115 info = {
112116 "name" : name ,
117+ "offset_x" : x ,
118+ "offset_y" : y ,
113119 "batch_mode" : batch_mode ,
114120 "resize_canvas" : resize_canvas ,
115121 }
@@ -171,19 +177,48 @@ def execute(cls):
171177 return io .NodeOutput (_placeholder_image (), 512 , 512 , 0 )
172178
173179
180+ class SelectionContext (Enum ):
181+ automatic = "automatic"
182+ entire_image = "entire image"
183+ mask_bounds = "mask bounds"
184+
185+
186+ _selection_context_help = """
187+ Determines the section (crop bounding box) of the image and mask to transmit:
188+ - automatic: area around the selection determined by Krita settings
189+ - entire image: always use the entire canvas area
190+ - mask bounds: tight bounding box of the current selection
191+
192+ This affects the Selection and Canvas nodes. The offset x/y outputs indicate the top-left corner of the context area relative to the full canvas."""
193+
194+
174195class KritaSelection (io .ComfyNode ):
175196 @classmethod
176197 def define_schema (cls ):
177198 return io .Schema (
178199 node_id = "ETN_KritaSelection" ,
179200 display_name = "Krita Selection" ,
180201 category = "krita" ,
181- outputs = [io .Mask .Output (display_name = "mask" ), io .Boolean .Output (display_name = "active" )],
202+ inputs = [
203+ io .Combo .Input (
204+ "context" ,
205+ options = SelectionContext ,
206+ default = SelectionContext .entire_image ,
207+ tooltip = _selection_context_help ,
208+ ),
209+ io .Int .Input ("padding" , "padding" , default = 0 , min = 0 ),
210+ ],
211+ outputs = [
212+ io .Mask .Output ("mask" , "mask" ),
213+ io .Boolean .Output ("active" , "active" ),
214+ io .Int .Output ("x" , "offset x" ),
215+ io .Int .Output ("y" , "offset y" ),
216+ ],
182217 )
183218
184219 @classmethod
185- def execute (cls ):
186- return io .NodeOutput (torch .ones (1 , 512 , 512 ), False )
220+ def execute (cls , ** kwargs ):
221+ return io .NodeOutput (torch .ones (1 , 512 , 512 ), False , 0 , 0 )
187222
188223
189224class KritaImageLayer (io .ComfyNode ):
0 commit comments