Bitwise operations for masks

This commit is contained in:
space-nuko 2023-05-27 21:48:49 -05:00
parent 9144947244
commit 00646b0813
1 changed files with 7 additions and 1 deletions

View File

@ -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)