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

Support passthrough/skipping nodes #2805

Merged
merged 5 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions backend/src/api/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(
self.never_reason: str | None = None
self.kind: OutputKind = kind
self.has_handle: bool = has_handle
self.pass_through_of: InputId | None = None
self.passthrough_of: InputId | None = None

self.associated_type: Any = associated_type

Expand All @@ -43,7 +43,7 @@ def to_dict(self):
"neverReason": self.never_reason,
"kind": self.kind,
"hasHandle": self.has_handle,
"passThroughOf": self.pass_through_of,
"passthroughOf": self.passthrough_of,
"description": self.description,
"suggest": self.should_suggest,
}
Expand All @@ -64,8 +64,8 @@ def suggest(self):
self.should_suggest = True
return self

def as_pass_through_of(self, input_id: InputId | int):
self.pass_through_of = InputId(input_id)
def as_passthrough_of(self, input_id: InputId | int):
self.passthrough_of = InputId(input_id)
return self

def get_broadcast_data(self, _value: T) -> BroadcastData | None:
Expand Down
2 changes: 1 addition & 1 deletion backend/src/nodes/properties/outputs/numpy_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(
self.assume_normalized: bool = assume_normalized

if shape_as is not None:
self.as_pass_through_of(shape_as)
self.as_passthrough_of(shape_as)

def get_broadcast_data(self, value: np.ndarray) -> BroadcastData:
h, w, c = get_h_w_c(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
controls_step=1,
),
],
outputs=[ImageOutput(image_type="Input0", assume_normalized=True)],
outputs=[
ImageOutput(shape_as=0, assume_normalized=True),
],
)
def brightness_and_contrast_node(
img: np.ndarray, brightness: float, contrast: float
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@
),
],
outputs=[
ImageOutput(
image_type="Input0",
assume_normalized=True,
)
ImageOutput(shape_as=0, assume_normalized=True),
],
)
def clamp_node(img: np.ndarray, minimum: float, maximum: float) -> np.ndarray:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@
controls_step=0.01,
),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[
ImageOutput(shape_as=0),
],
)
def color_levels_node(
img: np.ndarray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def with_lightness(img: np.ndarray, lightness: float) -> np.ndarray:
),
],
outputs=[
ImageOutput(image_type="Input0", assume_normalized=True),
ImageOutput(shape_as=0, assume_normalized=True),
],
)
def hue_and_saturation_node(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
description="Inverts all colors in an image.",
icon="MdInvertColors",
inputs=[ImageInput()],
outputs=[ImageOutput(image_type="Input0", assume_normalized=True)],
outputs=[ImageOutput(shape_as=0, assume_normalized=True)],
)
def invert_color_node(img: np.ndarray) -> np.ndarray:
c = get_h_w_c(img)[2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
controls_step=1,
),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(shape_as=0)],
)
def add_node(img: np.ndarray, add: float) -> np.ndarray:
if add == 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
scale="log",
),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(shape_as=0)],
)
def divide_node(img: np.ndarray, divide: float) -> np.ndarray:
if divide == 1.0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
scale="log",
),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(shape_as=0)],
)
def multiply_node(img: np.ndarray, mult: float) -> np.ndarray:
if mult == 1.0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AlphaAssociation(Enum):
},
),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(shape_as=0)],
)
def premultiplied_alpha_node(
img: np.ndarray, alpha_association: AlphaAssociation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@
),
BoolInput("Invert Gamma", default=False),
],
outputs=[
ImageOutput(
image_type="Input0",
assume_normalized=True,
)
],
outputs=[ImageOutput(shape_as=0, assume_normalized=True)],
)
def gamma_node(img: np.ndarray, gamma: float, invert_gamma: bool) -> np.ndarray:
if gamma == 1:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"When checked this will convert the input image back to the Kodak Cineon Logarithmic encoding"
),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(shape_as=0)],
)
def log_to_linear_node(
img: np.ndarray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ThresholdType(Enum):
),
],
outputs=[
ImageOutput(image_type="Input0"),
ImageOutput(shape_as=0),
],
key_info=KeyInfo.number(1),
see_also=[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class AdaptiveMethod(Enum):
"Assuming that **Threshold Type** is *Binary*, then higher values will result in more white pixels and lower values will result in more black pixels.",
),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(shape_as=0)],
limited_to_8bpc=True,
)
def threshold_adaptive_node(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def get_kernel_2d(radius_x: float, radius_y: float) -> np.ndarray:
),
),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(shape_as=0)],
)
def box_blur_node(
img: np.ndarray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
),
),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(shape_as=0)],
)
def gaussian_blur_node(
img: np.ndarray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def lens_blur(
scale="log",
),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(shape_as=0)],
)
def lens_blur_node(
img: np.ndarray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
ImageInput(),
SliderInput("Radius", minimum=0, maximum=1000, default=1, scale="log"),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(shape_as=0)],
limited_to_8bpc=True,
)
def median_blur_node(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
maximum=1000,
),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(shape_as=0)],
)
def surface_blur_node(
img: np.ndarray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
unit="%",
),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(shape_as=0)],
)
def average_color_fix_node(
input_img: np.ndarray, ref_img: np.ndarray, scale_factor: float
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class TransferColorAlgorithm(Enum):
BoolInput("Reciprocal Scaling Factor", default=True).with_id(4),
),
],
outputs=[ImageOutput("Image", image_type="Input0")],
outputs=[ImageOutput("Image", shape_as=0)],
)
def color_transfer_node(
img: np.ndarray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MorphShape(Enum):
scale="log",
),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(shape_as=0)],
)
def dilate_node(
img: np.ndarray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def binary_sdf(img: np.ndarray, spread: float) -> np.ndarray:
"Sub-pixel distance transform is implemented using the excellent [ESDF algorithm](https://acko.net/blog/subpixel-distance-transform/) by Steven Wittens.",
),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(shape_as=0)],
)
def distance_transform_node(
img: np.ndarray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class GradientComponent(Enum):
SliderInput("Radius 2", minimum=0, default=2, maximum=20, precision=3),
),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(shape_as=0)],
)
def edge_detection_node(
img: np.ndarray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MorphShape(Enum):
scale="log",
),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(shape_as=0)],
)
def erode_node(
img: np.ndarray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
SliderInput("Size Y", minimum=1, maximum=1024, default=10, scale="log"),
),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(shape_as=0)],
)
def pixelate_node(
img: np.ndarray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
NumberInput("Patch radius", minimum=1, default=3, maximum=30, precision=0),
NumberInput("Search radius", minimum=1, default=10, maximum=30, precision=0),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(shape_as=0)],
limited_to_8bpc=True,
)
def denoise_node(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class UniformDitherAlgorithm(Enum):
).with_id(5),
),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(shape_as=0)],
)
def dither_node(
img: np.ndarray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class PaletteDitherAlgorithm(Enum):
).with_id(4),
),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(shape_as=0)],
)
def dither_palette_node(
img: np.ndarray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class KernelType(Enum):
)
),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(shape_as=0)],
)
def high_boost_filter_node(
img: np.ndarray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
scale="log",
),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(shape_as=0)],
)
def unsharp_mask_node(
img: np.ndarray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
ImageInput("Image"),
EnumInput(FlipAxis),
],
outputs=[ImageOutput(image_type="Input0", assume_normalized=True)],
outputs=[ImageOutput(shape_as=0, assume_normalized=True)],
key_info=KeyInfo.enum(1),
)
def flip_node(img: np.ndarray, axis: FlipAxis) -> np.ndarray:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def metal_to_spec(
ImageInput("Roughness", channels=1).make_optional(),
],
outputs=[
ImageOutput("Diffuse", image_type="Input0"),
ImageOutput("Diffuse", shape_as=0),
ImageOutput(
"Specular",
image_type=navi.Image(size_as="Input1"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def spec_to_metal(
),
],
outputs=[
ImageOutput("Albedo", image_type="Input0"),
ImageOutput("Albedo", shape_as=0),
ImageOutput(
"Metal",
image_type=navi.Image(size_as="Input1"),
Expand Down
4 changes: 2 additions & 2 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ from .. import blur_group
NumberInput("Radius", minimum=0, default=2, precision=1),
],
outputs=[
ImageOutput(image_type="Input0"),
ImageOutput(shape_as=0),
],
)
def gaussian_blur_node(img: np.ndarray, radius: float) -> np.ndarray:
Expand All @@ -144,7 +144,7 @@ Let's go through the metadata:
- `schema_id` is a unique identifier for the node. The schema ID currently doesn't have a defined format, but we typically use `chainner:<category>:<node_name>`. In our example, we use `chainner:image_filter:gaussian_blur`.
- `name`, `description`, and `icon` are all displayed in the UI.
- `inputs` declares all arguments of the python function. In our case, we have 2 inputs: `img` and `radius`. `ImageInput` and `NumberInput` are classes that define the type of the input. `ImageInput` is used for images, and `NumberInput` is used for numbers. `NumberInput` takes a few arguments. `minimum` and `maximum` define the range of the number, `default` defines the default value, and `precision` defines the number of decimal places.
- `outputs` declares all return values of the python function. In our case, we return one image. `ImageOutput` is used for images. `image_type="Input0"` means that the output image has the same size and number of channels as the input image.
- `outputs` declares all return values of the python function. In our case, we return one image. `ImageOutput` is used for images. `shape_as=0` means that the output image has the same size and number of channels as the input image.

For more information about metadata, see the [Node Metadata docs](nodes.md#node-metadata).

Expand Down
Loading
Loading