Skip to content

Commit 8aabe24

Browse files
Add color type and Color to RGB Int node (#12145)
* add color type and color to rgb int node * review fix for allowing output --------- Co-authored-by: Jedrzej Kosinski <kosinkadink1@gmail.com>
1 parent 0167653 commit 8aabe24

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

comfy_api/latest/_io.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,20 @@ def __init__(self, id: str, display_name: str=None, optional=False, tooltip: str
11461146
def as_dict(self):
11471147
return super().as_dict()
11481148

1149+
1150+
@comfytype(io_type="COLOR")
1151+
class Color(ComfyTypeIO):
1152+
Type = str
1153+
1154+
class Input(WidgetInput):
1155+
def __init__(self, id: str, display_name: str=None, optional=False, tooltip: str=None,
1156+
socketless: bool=True, advanced: bool=None, default: str="#ffffff"):
1157+
super().__init__(id, display_name, optional, tooltip, None, default, socketless, None, None, None, None, advanced)
1158+
self.default: str
1159+
1160+
def as_dict(self):
1161+
return super().as_dict()
1162+
11491163
DYNAMIC_INPUT_LOOKUP: dict[str, Callable[[dict[str, Any], dict[str, Any], tuple[str, dict[str, Any]], str, list[str] | None], None]] = {}
11501164
def register_dynamic_input_func(io_type: str, func: Callable[[dict[str, Any], dict[str, Any], tuple[str, dict[str, Any]], str, list[str] | None], None]):
11511165
DYNAMIC_INPUT_LOOKUP[io_type] = func
@@ -2038,6 +2052,7 @@ def as_dict(self) -> dict:
20382052
"AnyType",
20392053
"MultiType",
20402054
"Tracks",
2055+
"Color",
20412056
# Dynamic Types
20422057
"MatchType",
20432058
"DynamicCombo",

comfy_extras/nodes_color.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from typing_extensions import override
2+
from comfy_api.latest import ComfyExtension, io
3+
4+
5+
class ColorToRGBInt(io.ComfyNode):
6+
@classmethod
7+
def define_schema(cls) -> io.Schema:
8+
return io.Schema(
9+
node_id="ColorToRGBInt",
10+
display_name="Color to RGB Int",
11+
category="utils",
12+
description="Convert a color to a RGB integer value.",
13+
inputs=[
14+
io.Color.Input("color"),
15+
],
16+
outputs=[
17+
io.Int.Output(display_name="rgb_int"),
18+
],
19+
)
20+
21+
@classmethod
22+
def execute(
23+
cls,
24+
color: str,
25+
) -> io.NodeOutput:
26+
# expect format #RRGGBB
27+
if len(color) != 7 or color[0] != "#":
28+
raise ValueError("Color must be in format #RRGGBB")
29+
r = int(color[1:3], 16)
30+
g = int(color[3:5], 16)
31+
b = int(color[5:7], 16)
32+
return io.NodeOutput(r * 256 * 256 + g * 256 + b)
33+
34+
35+
class ColorExtension(ComfyExtension):
36+
@override
37+
async def get_node_list(self) -> list[type[io.ComfyNode]]:
38+
return [ColorToRGBInt]
39+
40+
41+
async def comfy_entrypoint() -> ColorExtension:
42+
return ColorExtension()

nodes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2432,7 +2432,8 @@ async def init_builtin_extra_nodes():
24322432
"nodes_wanmove.py",
24332433
"nodes_image_compare.py",
24342434
"nodes_zimage.py",
2435-
"nodes_lora_debug.py"
2435+
"nodes_lora_debug.py",
2436+
"nodes_color.py"
24362437
]
24372438

24382439
import_failed = []

0 commit comments

Comments
 (0)