Browse Source

Update comfy_extras/nodes_mask.py

Co-authored-by: missionfloyd <missionfloyd@users.noreply.github.com>
pull/422/head
comfyanonymous 2 years ago committed by GitHub
parent
commit
35a2c790b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      comfy_extras/nodes_mask.py

9
comfy_extras/nodes_mask.py

@ -9,8 +9,8 @@ class LatentCompositeMasked:
"required": {
"destination": ("LATENT",),
"source": ("LATENT",),
"x": ("INT", {"default": 0, "min": 0, "max": MAX_RESOLUTION, "step": 8}),
"y": ("INT", {"default": 0, "min": 0, "max": MAX_RESOLUTION, "step": 8}),
"x": ("INT", {"default": 0, "min": -MAX_RESOLUTION, "max": MAX_RESOLUTION, "step": 8}),
"y": ("INT", {"default": 0, "min": -MAX_RESOLUTION, "max": MAX_RESOLUTION, "step": 8}),
},
"optional": {
"mask": ("MASK",),
@ -26,6 +26,9 @@ class LatentCompositeMasked:
destination = destination["samples"].clone()
source = source["samples"]
x = max(-source.shape[3] * 8, min(x, destination.shape[3] * 8))
y = max(-source.shape[2] * 8, min(y, destination.shape[2] * 8))
left, top = (x // 8, y // 8)
right, bottom = (left + source.shape[3], top + source.shape[2],)
@ -40,7 +43,7 @@ class LatentCompositeMasked:
# calculate the bounds of the source that will be overlapping the destination
# this prevents the source trying to overwrite latent pixels that are out of bounds
# of the destination
visible_width, visible_height = (destination.shape[3] - left, destination.shape[2] - top,)
visible_width, visible_height = (destination.shape[3] - left + min(0, x), destination.shape[2] - top + min(0, y),)
mask = mask[:, :, :visible_height, :visible_width]
inverse_mask = torch.ones_like(mask) - mask

Loading…
Cancel
Save