mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-04-06 00:36:49 +08:00
feat: add HISTOGRAM type and histogram support to CurveEditor
Some checks failed
Python Linting / Run Ruff (push) Has been cancelled
Python Linting / Run Pylint (push) Has been cancelled
Build package / Build Test (3.11) (push) Has been cancelled
Build package / Build Test (3.12) (push) Has been cancelled
Build package / Build Test (3.13) (push) Has been cancelled
Build package / Build Test (3.14) (push) Has been cancelled
Build package / Build Test (3.10) (push) Has been cancelled
Some checks failed
Python Linting / Run Ruff (push) Has been cancelled
Python Linting / Run Pylint (push) Has been cancelled
Build package / Build Test (3.11) (push) Has been cancelled
Build package / Build Test (3.12) (push) Has been cancelled
Build package / Build Test (3.13) (push) Has been cancelled
Build package / Build Test (3.14) (push) Has been cancelled
Build package / Build Test (3.10) (push) Has been cancelled
This commit is contained in:
parent
06e6168275
commit
e5611f2b63
@ -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",
|
||||
]
|
||||
|
||||
@ -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):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user