fix: address compositor review feedback

This commit is contained in:
Terry Jia
2026-08-06 14:48:27 -04:00
parent 19467819d3
commit b6b2572cd9
2 changed files with 12 additions and 20 deletions

View File

@@ -214,7 +214,6 @@ def _from_space(rgb: np.ndarray, space: str) -> np.ndarray:
class EffectiveMode(NamedTuple):
blend: str
blend_space: str
composite_space: str
composite: str
@@ -253,7 +252,6 @@ def resolve_mode(blend: str = "normal") -> EffectiveMode:
return EffectiveMode(
blend=blend,
blend_space=blend_space,
composite_space="linear",
composite=composite,
)
@@ -273,20 +271,7 @@ def blend_composite(
layer_b = _to_space(layer[..., :3], mode.blend_space)
comp = _from_space(blend_pixel(mode.blend, in_b, layer_b), mode.blend_space)
if mode.composite_space == "linear":
return run_composite(mode.composite, backdrop, layer, comp, cov)
in_c = np.concatenate(
[_to_space(backdrop[..., :3], mode.composite_space), backdrop[..., 3:4]],
axis=-1,
)
layer_c = np.concatenate(
[_to_space(layer[..., :3], mode.composite_space), layer[..., 3:4]], axis=-1
)
comp_c = _to_space(comp, mode.composite_space)
out = run_composite(mode.composite, in_c, layer_c, comp_c, cov)
rgb = _from_space(out[..., :3], mode.composite_space)
return np.concatenate([rgb, out[..., 3:4]], axis=-1)
return run_composite(mode.composite, backdrop, layer, comp, cov)
def placed_bounds(

View File

@@ -16,6 +16,7 @@ from comfy_extras.compositor_blend import (
)
from comfy_extras.color_util import hex_to_rgb
from comfy_extras.nodes_bounding_boxes import boxes_from_input
from nodes import MAX_RESOLUTION
from typing_extensions import override
@@ -216,14 +217,15 @@ def _parse_background(entry) -> dict | None:
}
def _parse_order(value) -> list[int] | None:
def _parse_order(value, layer_count: int) -> list[int] | None:
if not isinstance(value, list) or not value:
return None
if not all(
isinstance(item, int) and not isinstance(item, bool) and item >= 0
for item in value
isinstance(item, int) and not isinstance(item, bool) for item in value
):
return None
if sorted(value) != list(range(layer_count)):
return None
return value
@@ -267,7 +269,7 @@ def parse_layer_state(raw) -> dict | None:
"layers": layers,
"inputs": inputs,
"background": _parse_background(state.get("background")),
"order": _parse_order(state.get("order")),
"order": _parse_order(state.get("order"), len(layers)),
}
@@ -357,6 +359,11 @@ def composite_from_state(
alphas: list[torch.Tensor | None],
) -> torch.Tensor:
cw, ch = state["canvas"]
if cw > MAX_RESOLUTION or ch > MAX_RESOLUTION:
raise ValueError(
f"Compositor canvas {cw}x{ch} exceeds the maximum supported size of "
f"{MAX_RESOLUTION}x{MAX_RESOLUTION}"
)
canvas = np.zeros((ch, cw, 4), dtype=np.float32)
background = state.get("background")
if background is not None and background["visible"] and background["opacity"] > 0: