ComfyUI Node

BK Color Limit

Clamp a color into your palette's saturation and brightness range

By JayLyu·Created 2 years ago·Updated about a year ago· 8
BK Color Limit
    • STRING
    • PREVIEW
    hex_color#FF0036
    saturation_start0.00
    saturation_end1.00
    brightness_start0.00
    brightness_end1.00

    You've got a hex color you like, but it's too loud, or it's outside the mood you're going for. BK Color Limit takes that color and shoves it into whatever saturation and brightness ranges you set - then shows you exactly where it landed. It's the pack's "keep it in the family" node.

    The ComfyUI_BaiKong_Node pack is a no-models, CPU-only designer toolkit for color and layout, and this is one of the friendlier color utilities in it. Where BK Img To Color extracts a palette from an image, this node's job is constraint: given one hex, produce a new hex that obeys your rules. Great for muting an accent color to match a palette, or forcing every color feeding a workflow through the same saturation ceiling so nothing screams.

    How it works

    The mechanism is straightforward HSV math. The node parses your hex to RGB, converts to HSV (hue, saturation, value) via colorsys, clamps saturation into [saturation_start, saturation_end] and brightness (value) into [brightness_start, brightness_end], then converts back to RGB and formats a new hex. Hue is left untouched - you get the same color, just quieter or punchier.

    The best part is the PREVIEW output: a 512×512 image of the entire color domain at your hue (saturation across the x-axis, brightness down the y-axis), with your allowed range drawn as a dashed box, the original color marked with a ring, and an arrow pointing to where the new color landed. It's a genuinely useful visualization when you're building palettes - you can watch the color move inside its cage.

    Inputs and outputs

    • hex_color - any #RRGGBB (default #FF0036).
    • saturation_start / saturation_end - 0 to 1 sliders. The default 0→1 range is a no-op, so set at least one end to actually constrain.
    • brightness_start / brightness_end - same idea, same 0 to 1 range.

    It returns STRING (the new hex) and PREVIEW (the domain image). The node also paints an inline color swatch on itself after each run, courtesy of the pack's web extension - nice when you're iterating on a palette in a big graph.

    Install

    Same as the rest of the pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/JayLyu/ComfyUI_BaiKong_Node
    cd ComfyUI_BaiKong_Node
    pip install -r requirements.txt
    

    Restart ComfyUI. You can also install "ComfyUI_BaiKong_Node" from ComfyUI Manager. Requirements are scikit-learn, scipy, opencv-python, scikit-image, and matplotlib - no models, no downloads beyond the pip packages.

    Gotchas

    Malformed hex is handled gracefully (warning logged, falls back to red), and the code internally re-clamps your inputs so saturation_end can never be below saturation_start - you can't build an inverted range even if you try. One thing to keep in mind: the clamping works in HSV, so a very dark color with brightness forced up will get brighter but its perceived lightness will still be governed by saturation too. If you're trying to hit a target on-screen lightness, this node can only move the two axes it exposes. The new hex output is a plain string, so you can feed it straight into another color node, a text overlay, or anything that takes a hex.

    Category⭐️ Baikong/Color

    Inputs (5)

    NameTypeDefaultDescription
    hex_colorSTRING#FF0036
    saturation_startoptFLOAT0.000–1
    saturation_endoptFLOAT1.000–1
    brightness_startoptFLOAT0.000–1
    brightness_endoptFLOAT1.000–1

    Outputs (2)

    NameTypeDescription
    STRINGSTRING
    PREVIEWIMAGE