fix: Issue with SEGDetailer and SEGSPaste handling cropped_image in PIL instead of numpy.
101 lines
3.0 KiB
Python
101 lines
3.0 KiB
Python
from impact.utils import any_typ
|
|
|
|
class GeneralSwitch:
|
|
@classmethod
|
|
def INPUT_TYPES(s):
|
|
return {"required": {
|
|
"select": ("INT", {"default": 1, "min": 1, "max": 999999, "step": 1}),
|
|
"input1": (any_typ,),
|
|
},
|
|
}
|
|
|
|
RETURN_TYPES = (any_typ, )
|
|
FUNCTION = "doit"
|
|
|
|
CATEGORY = "ImpactPack/Util"
|
|
|
|
def doit(self, *args, **kwargs):
|
|
input_name = f"input{int(kwargs['select'])}"
|
|
|
|
if input_name in kwargs:
|
|
return (kwargs[input_name],)
|
|
else:
|
|
print(f"ImpactSwitch: invalid select index ('input1' is selected)")
|
|
return (kwargs['input1'],)
|
|
|
|
|
|
class ImageMaskSwitch:
|
|
@classmethod
|
|
def INPUT_TYPES(s):
|
|
return {"required": {
|
|
"select": ("INT", {"default": 1, "min": 1, "max": 4, "step": 1}),
|
|
"images1": ("IMAGE",),
|
|
},
|
|
|
|
"optional": {
|
|
"mask1_opt": ("MASK",),
|
|
"images2_opt": ("IMAGE",),
|
|
"mask2_opt": ("MASK",),
|
|
"images3_opt": ("IMAGE",),
|
|
"mask3_opt": ("MASK",),
|
|
"images4_opt": ("IMAGE",),
|
|
"mask4_opt": ("MASK",),
|
|
},
|
|
}
|
|
|
|
RETURN_TYPES = ("IMAGE", "MASK",)
|
|
FUNCTION = "doit"
|
|
|
|
CATEGORY = "ImpactPack/Util"
|
|
|
|
def doit(self, select, images1, mask1_opt=None, images2_opt=None, mask2_opt=None, images3_opt=None, mask3_opt=None,
|
|
images4_opt=None, mask4_opt=None):
|
|
if select == 1:
|
|
return images1, mask1_opt,
|
|
elif select == 2:
|
|
return images2_opt, mask2_opt,
|
|
elif select == 3:
|
|
return images3_opt, mask3_opt,
|
|
else:
|
|
return images4_opt, mask4_opt,
|
|
|
|
|
|
class RemoveNoiseMask:
|
|
@classmethod
|
|
def INPUT_TYPES(s):
|
|
return {"required": {"samples": ("LATENT",)}}
|
|
|
|
RETURN_TYPES = ("LATENT",)
|
|
FUNCTION = "doit"
|
|
|
|
CATEGORY = "ImpactPack/Util"
|
|
|
|
def doit(self, samples):
|
|
res = {key: value for key, value in samples.items() if key != 'noise_mask'}
|
|
return (res, )
|
|
|
|
MAX_RESOLUTION=8192
|
|
class ImagePasteMasked:
|
|
@classmethod
|
|
def INPUT_TYPES(s):
|
|
return {
|
|
"required": {
|
|
"destination": ("IMAGE",),
|
|
"source": ("IMAGE",),
|
|
"x": ("INT", {"default": 0, "min": 0, "max": MAX_RESOLUTION, "step": 1}),
|
|
"y": ("INT", {"default": 0, "min": 0, "max": MAX_RESOLUTION, "step": 1}),
|
|
"resize_source": ("BOOLEAN", {"default": False}),
|
|
},
|
|
"optional": {
|
|
"mask": ("MASK",),
|
|
}
|
|
}
|
|
RETURN_TYPES = ("IMAGE",)
|
|
FUNCTION = "composite"
|
|
|
|
CATEGORY = "image"
|
|
|
|
def composite(self, destination, source, x, y, resize_source, mask = None):
|
|
destination = destination.clone().movedim(-1, 1)
|
|
output = composite(destination, source.movedim(-1, 1), x, y, mask, 1, resize_source).movedim(1, -1)
|
|
return (output,) |