forked from jamesWalker55/comfyui-various
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomfyui_color_ops.py
More file actions
62 lines (46 loc) · 1.55 KB
/
comfyui_color_ops.py
File metadata and controls
62 lines (46 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import torch
NODE_CLASS_MAPPINGS = {}
NODE_DISPLAY_NAME_MAPPINGS = {}
def register_node(identifier: str, display_name: str):
def decorator(cls):
NODE_CLASS_MAPPINGS[identifier] = cls
NODE_DISPLAY_NAME_MAPPINGS[identifier] = display_name
return cls
return decorator
@register_node("JWImageMix", "Image Mix")
class _:
CATEGORY = "jamesWalker55"
BLEND_TYPES = ("mix", "multiply")
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"blend_type": (cls.BLEND_TYPES, {"default": "mix"}),
"factor": ("FLOAT", {"min": 0, "max": 1, "step": 0.01, "default": 0.5}),
"image_a": ("IMAGE",),
"image_b": ("IMAGE",),
}
}
RETURN_NAMES = ("IMAGE",)
RETURN_TYPES = ("IMAGE",)
OUTPUT_NODE = False
FUNCTION = "execute"
def execute(
self,
blend_type: str,
factor: float,
image_a: torch.Tensor,
image_b: torch.Tensor,
):
assert blend_type in self.BLEND_TYPES
assert isinstance(factor, float)
assert isinstance(image_a, torch.Tensor)
assert isinstance(image_b, torch.Tensor)
assert image_a.shape == image_b.shape
if blend_type == "mix":
mixed = image_a * (1 - factor) + image_b * factor
elif blend_type == "multiply":
mixed = image_a * (1 - factor + image_b * factor)
else:
raise NotImplementedError(f"Blend type not yet implemented: {blend_type}")
return (mixed,)