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

Optimize Split Transparency output for subsequent operations #2391

Merged
merged 1 commit into from
Dec 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from nodes.impl.image_utils import as_target_channels
from nodes.properties.inputs import ImageInput
from nodes.properties.outputs import ImageOutput
from nodes.utils.utils import get_h_w_c

from . import node_group

Expand Down Expand Up @@ -34,6 +35,14 @@
def split_transparency_node(img: np.ndarray) -> tuple[np.ndarray, np.ndarray]:
"""Split a multi-channel image into separate channels"""

c = get_h_w_c(img)[2]
if c == 3:
# Performance optimization:
# Subsequent operations will be faster since the underlying array will
# be contiguous in memory. The speed up can anything from nothing to
# 5x faster depending on the operation.
return img, np.ones(img.shape[:2], dtype=img.dtype)

img = as_target_channels(img, 4)

rgb = img[:, :, :3]
Expand Down