Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

Bitwise operations for masks

space-nuko00646b0813e4
diff --git a/comfy_extras/nodes_mask.py b/comfy_extras/nodes_mask.py
index 9916f3b21..9134c24da 100644
--- a/comfy_extras/nodes_mask.py
+++ b/comfy_extras/nodes_mask.py
@@ -167,7 +167,7 @@ class MaskComposite:
"source": ("MASK",),
"x": ("INT", {"default": 0, "min": 0, "max": MAX_RESOLUTION, "step": 1}),
"y": ("INT", {"default": 0, "min": 0, "max": MAX_RESOLUTION, "step": 1}),
- "operation": (["multiply", "add", "subtract"],),
+ "operation": (["multiply", "add", "subtract", "and", "or", "xor"],),
}
}
@@ -193,6 +193,12 @@ class MaskComposite:
output[top:bottom, left:right] = destination_portion + source_portion
elif operation == "subtract":
output[top:bottom, left:right] = destination_portion - source_portion
+ elif operation == "and":
+ output[top:bottom, left:right] = torch.bitwise_and(destination_portion.bool(), source_portion.bool()).float()
+ elif operation == "or":
+ output[top:bottom, left:right] = torch.bitwise_or(destination_portion.bool(), source_portion.bool()).float()
+ elif operation == "xor":
+ output[top:bottom, left:right] = torch.bitwise_xor(destination_portion.bool(), source_portion.bool()).float()
output = torch.clamp(output, 0.0, 1.0)