Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve output type of Separate Color node #2910

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ class SeparateColorMode(Enum):
}


output_navi_type = """match Input1 {
output_navi_type = """
match Input1 {
SeparateColorMode::Uint8 => int(0..255),
SeparateColorMode::Percent => 0..100,
SeparateColorMode::Color => Color { channels: 1 },
_ => never }
SeparateColorMode::Color => Color { channels: 1 }
}
"""


Expand All @@ -41,7 +42,7 @@ class SeparateColorMode(Enum):
description="Separate a color into its RGBA values, either as numbers or grayscale colors.",
icon="MdColorLens",
inputs=[
ColorInput(),
ColorInput(channels=[1, 3, 4]),
EnumInput(
SeparateColorMode,
label="Mode",
Expand All @@ -53,7 +54,22 @@ class SeparateColorMode(Enum):
AnyOutput("Red", output_type=output_navi_type),
AnyOutput("Green", output_type=output_navi_type),
AnyOutput("Blue", output_type=output_navi_type),
AnyOutput("Alpha", output_type=output_navi_type),
AnyOutput(
"Alpha",
output_type="""
if Input0.channels != 4 {
match Input1 {
SeparateColorMode::Uint8 => 255,
SeparateColorMode::Percent => 100,
SeparateColorMode::Color => Color { channels: 1 }
}
} else {
"""
+ output_navi_type
+ """
}
""",
),
],
)
def separate_color_node(
Expand Down Expand Up @@ -94,5 +110,3 @@ def separate_color_node(
)
elif mode == SeparateColorMode.COLOR:
return Color.gray(r), Color.gray(g), Color.gray(b), Color.gray(a)
else:
raise AssertionError("Invalid mode")
Loading