mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-04-13 12:02:30 +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
|
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]] = {}
|
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]):
|
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
|
DYNAMIC_INPUT_LOOKUP[io_type] = func
|
||||||
@ -2247,5 +2253,6 @@ __all__ = [
|
|||||||
"PriceBadge",
|
"PriceBadge",
|
||||||
"BoundingBox",
|
"BoundingBox",
|
||||||
"Curve",
|
"Curve",
|
||||||
|
"Histogram",
|
||||||
"NodeReplace",
|
"NodeReplace",
|
||||||
]
|
]
|
||||||
|
|||||||
@ -14,6 +14,7 @@ class CurveEditor(io.ComfyNode):
|
|||||||
category="utils",
|
category="utils",
|
||||||
inputs=[
|
inputs=[
|
||||||
io.Curve.Input("curve"),
|
io.Curve.Input("curve"),
|
||||||
|
io.Histogram.Input("histogram", optional=True),
|
||||||
],
|
],
|
||||||
outputs=[
|
outputs=[
|
||||||
io.Curve.Output("curve"),
|
io.Curve.Output("curve"),
|
||||||
@ -21,15 +22,23 @@ class CurveEditor(io.ComfyNode):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def execute(cls, curve) -> io.NodeOutput:
|
def execute(cls, curve, histogram=None) -> io.NodeOutput:
|
||||||
if isinstance(curve, CurveInput):
|
if isinstance(curve, CurveInput):
|
||||||
return io.NodeOutput(curve)
|
result = curve
|
||||||
raw_points = curve["points"] if isinstance(curve, dict) else curve
|
else:
|
||||||
points = [(float(x), float(y)) for x, y in raw_points]
|
raw_points = curve["points"] if isinstance(curve, dict) else curve
|
||||||
interpolation = curve.get("interpolation", "monotone_cubic") if isinstance(curve, dict) else "monotone_cubic"
|
points = [(float(x), float(y)) for x, y in raw_points]
|
||||||
if interpolation == "linear":
|
interpolation = curve.get("interpolation", "monotone_cubic") if isinstance(curve, dict) else "monotone_cubic"
|
||||||
return io.NodeOutput(LinearCurve(points))
|
if interpolation == "linear":
|
||||||
return io.NodeOutput(MonotoneCubicCurve(points))
|
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):
|
class CurveExtension(ComfyExtension):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user