Repository navigation
Expand file tree
/
Copy pathnode_utilities.py
More file actions
189 lines (174 loc) · 6.22 KB
/
Copy pathnode_utilities.py
File metadata and controls
189 lines (174 loc) · 6.22 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# pylint: disable=missing-module-docstring,disable=missing-class-docstring,missing-function-docstring,line-too-long
from comfy_api.latest import io, ui
from .helpers import Resolution, AspectRatio
ResolutionParam = io.Custom("IG1_RESOLUTION")
RatioParam = io.Custom("IG1_ASPECTRATIO")
class ResolutionPacker(io.ComfyNode):
@classmethod
def define_schema(cls) -> io.Schema:
return io.Schema(
node_id="IG1Resolution",
display_name="Resolution",
category="IG1 Tools",
description=f"""Pack a width and height as resolution""",
inputs=[
io.Int.Input(
"width",
tooltip="The resolution width",
min=1,
default=3840, # 4k
max=7680, # 8k
display_mode=io.NumberDisplay.number,
),
io.Int.Input(
"height",
tooltip="The resolution height",
min=1,
default=2160, # 4k
max=4320, # 8k
display_mode=io.NumberDisplay.number,
)
],
outputs=[
ResolutionParam.Output(
"resolution",
"RESOLUTION",
tooltip="The packed resolution",
)
],
)
@classmethod
def execute(cls, width, height) -> io.NodeOutput:
res = Resolution(width, height)
return io.NodeOutput(
res,
ui=ui.PreviewText(value=str(res.aspect_ratio())),
)
class ResolutionProperties(io.ComfyNode):
@classmethod
def define_schema(cls) -> io.Schema:
return io.Schema(
node_id="IG1ResolutionProperties",
display_name="Resolution Properties",
category="IG1 Tools",
description=f"""Extract a resolution properties""",
inputs=[
ResolutionParam.Input(
"resolution",
tooltip="The resolution to extract properties from",
)
],
outputs=[
io.Int.Output(
"width",
display_name="WIDTH",
tooltip="The resolution width",
),
io.Int.Output(
"height",
display_name="HEIGHT",
tooltip="The resolution height",
),
io.Float.Output(
"megapixels",
display_name="MEGAPIXELS",
tooltip="The resolution size in megapixels (rounded to 2 decimals)",
),
RatioParam.Output(
"ratio",
display_name="ASPECT_RATIO",
tooltip="The resolution aspect ratio",
),
],
)
@classmethod
def execute(cls, resolution: Resolution) -> io.NodeOutput:
ratio = resolution.aspect_ratio()
return io.NodeOutput(
resolution.width, resolution.height, resolution.mega_pixels(), ratio,
)
class AspectRatioProperties(io.ComfyNode):
@classmethod
def define_schema(cls) -> io.Schema:
return io.Schema(
node_id="IG1AspectRatioProperties",
display_name="Aspect Ratio Properties",
category="IG1 Tools",
description=f"""Extract an aspect ratio properties""",
inputs=[
RatioParam.Input(
"aspect_ratio",
tooltip="The aspect ratio you want to extract properties from",
),
],
outputs=[
io.Int.Output(
"numerator",
display_name="NUMERATOR",
tooltip="The aspect ratio numerator",
),
io.Int.Output(
"denominator",
display_name="DENOMINATOR",
tooltip="The aspect ratio denominator",
),
io.Float.Output(
"value",
display_name="VALUE",
tooltip="The aspect ratio value",
)
],
)
@classmethod
def execute(cls, aspect_ratio: AspectRatio) -> io.NodeOutput:
return io.NodeOutput(
aspect_ratio.numerator, aspect_ratio.denominator, aspect_ratio.value(),
)
class ImageSelector(io.ComfyNode):
@classmethod
def define_schema(cls) -> io.Schema:
return io.Schema(
node_id="IG1ImageSelector",
display_name="Image Selector",
category="IG1 Tools",
description=f"""A lazy selector that will require only one image to be generated depending on the use_upscaled value.
Use it with the advisor to automate the activation (or not) of HiRes and final upscale within your workflow.""",
inputs=[
io.Boolean.Input(
"use_upscaled",
tooltip="Select the upscaled image",
lazy=False,
default=False,
force_input=True,
),
io.Image.Input(
"original",
tooltip="The original image",
lazy=True,
),
io.Image.Input(
"upscaled",
tooltip="The upscaled image",
lazy=True,
)
],
outputs=[
io.Image.Output(
"image",
display_name="IMAGE",
tooltip="The selected image",
)
],
)
@classmethod
def check_lazy_status(cls, original, upscaled, use_upscaled):
if use_upscaled and upscaled is None:
return ["upscaled"]
if not use_upscaled and original is None:
return ["original"]
return []
@classmethod
def execute(cls, original, upscaled, use_upscaled) -> io.NodeOutput:
if use_upscaled:
return io.NodeOutput(upscaled)
return io.NodeOutput(original)