From e5611f2b637e86fdd318dd019474a4413ef5b1fc Mon Sep 17 00:00:00 2001 From: Terry Jia Date: Sat, 21 Mar 2026 10:52:22 -0400 Subject: [PATCH] feat: add HISTOGRAM type and histogram support to CurveEditor --- comfy_api/latest/_io.py | 7 +++++++ comfy_extras/nodes_curve.py | 25 +++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/comfy_api/latest/_io.py b/comfy_api/latest/_io.py index 8916772a3..f24a376f0 100644 --- a/comfy_api/latest/_io.py +++ b/comfy_api/latest/_io.py @@ -1260,6 +1260,12 @@ class Curve(ComfyTypeIO): return d +@comfytype(io_type="HISTOGRAM") +class Histogram(ComfyTypeIO): + """A histogram represented as a list of bin counts.""" + Type = list[int] + + DYNAMIC_INPUT_LOOKUP: dict[str, Callable[[dict[str, Any], dict[str, Any], tuple[str, dict[str, Any]], str, list[str] | None], None]] = {} def register_dynamic_input_func(io_type: str, func: Callable[[dict[str, Any], dict[str, Any], tuple[str, dict[str, Any]], str, list[str] | None], None]): DYNAMIC_INPUT_LOOKUP[io_type] = func @@ -2247,5 +2253,6 @@ __all__ = [ "PriceBadge", "BoundingBox", "Curve", + "Histogram", "NodeReplace", ] diff --git a/comfy_extras/nodes_curve.py b/comfy_extras/nodes_curve.py index fec3ebbda..ef215709c 100644 --- a/comfy_extras/nodes_curve.py +++ b/comfy_extras/nodes_curve.py @@ -14,6 +14,7 @@ class CurveEditor(io.ComfyNode): category="utils", inputs=[ io.Curve.Input("curve"), + io.Histogram.Input("histogram", optional=True), ], outputs=[ io.Curve.Output("curve"), @@ -21,15 +22,23 @@ class CurveEditor(io.ComfyNode): ) @classmethod - def execute(cls, curve) -> io.NodeOutput: + def execute(cls, curve, histogram=None) -> io.NodeOutput: if isinstance(curve, CurveInput): - return io.NodeOutput(curve) - raw_points = curve["points"] if isinstance(curve, dict) else curve - points = [(float(x), float(y)) for x, y in raw_points] - interpolation = curve.get("interpolation", "monotone_cubic") if isinstance(curve, dict) else "monotone_cubic" - if interpolation == "linear": - return io.NodeOutput(LinearCurve(points)) - return io.NodeOutput(MonotoneCubicCurve(points)) + result = curve + else: + raw_points = curve["points"] if isinstance(curve, dict) else curve + points = [(float(x), float(y)) for x, y in raw_points] + interpolation = curve.get("interpolation", "monotone_cubic") if isinstance(curve, dict) else "monotone_cubic" + if interpolation == "linear": + result = LinearCurve(points) + else: + result = MonotoneCubicCurve(points) + + ui = {} + if histogram is not None: + ui["histogram"] = histogram if isinstance(histogram, list) else list(histogram) + + return io.NodeOutput(result, ui=ui) if ui else io.NodeOutput(result) class CurveExtension(ComfyExtension):