Skip to content

Commit e37dd1a

Browse files
committed
Add color input
1 parent c5ac1e7 commit e37dd1a

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

node_list.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
"Image Remove Background (rembg) [LP]":"Removes background for images with user-defined model. This node uses the rembg library. It is NOT recommended for use in normal scenarios.",
1414
"Image Remove Background (BiRefNet) [LP]":"Removes background for images with user-defined model type of BiRefNet. Recommended for fast and high-quality background removal",
1515
"Image Remove Background (RMBG) [LP]":"Removes background for images with user-defined model. This node uses the RMBG models. Recommended for ultra-high precision",
16+
"Color Input [LP]":"Color Input for remove background nodes.",
1617
"Multimodal Generator Advanced [LP]":"Node for Multimodal neural models based on GGUF. Supports Qwen2.5-VL of GGUF format. Based on llama-mtmd."
1718
}

nodes/image/rmbg_LP.py

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@
3535

3636
folder_paths.add_model_folder_path("rembg", os.path.join(folder_paths.models_dir, "rembg"))
3737

38+
COLOR_PRESETS = {
39+
"black": "#000000", "white": "#FFFFFF", "red": "#FF0000", "green": "#00FF00", "blue": "#0000FF",
40+
"yellow": "#FFFF00", "cyan": "#00FFFF", "magenta": "#FF00FF", "gray": "#808080", "silver": "#C0C0C0",
41+
"maroon": "#800000", "olive": "#808000", "purple": "#800080", "teal": "#008080", "navy": "#000080",
42+
"orange": "#FFA500", "pink": "#FFC0CB", "brown": "#A52A2A", "violet": "#EE82EE", "indigo": "#4B0082",
43+
"light_gray": "#D3D3D3", "dark_gray": "#A9A9A9", "light_blue": "#ADD8E6", "dark_blue": "#00008B",
44+
"light_blue": "#ADD8E6", "dark_blue": "#00008B", "light_green": "#90EE90", "dark_green": "#006400"
45+
}
46+
3847
AVAILABLE_MODELS = {
3948
"RMBG-2.0": {
4049
"type": "rmbg",
@@ -655,10 +664,59 @@ def hex_to_rgba(hex_color):
655664
empty_mask_image = empty_mask.reshape((-1, 1, empty_mask.shape[-2], empty_mask.shape[-1])).movedim(1, -1).expand(-1, -1, -1, 3)
656665
return (image, empty_mask, empty_mask_image)
657666

667+
def fix_color_format(color: str) -> str:
668+
"""Fix color format to valid hex code"""
669+
if not color:
670+
return ""
671+
672+
color = color.strip().upper()
673+
if not color.startswith('#'):
674+
color = f"#{color}"
675+
676+
color = color[1:]
677+
if len(color) == 3:
678+
r, g, b = color[0], color[1], color[2]
679+
return f"#{r}{r}{g}{g}{b}{b}"
680+
elif len(color) < 6:
681+
raise ValueError(f"Invalid color format: {color}")
682+
elif len(color) > 6:
683+
color = color[:6]
684+
685+
return f"#{color}"
686+
687+
class ColorInput:
688+
@classmethod
689+
def INPUT_TYPES(self):
690+
return {
691+
"required": {
692+
"preset": (list(COLOR_PRESETS.keys()),),
693+
"color": ("STRING", {"default": "", "placeholder": "Enter color code (e.g. #FF0000 or #F00)"}),
694+
},
695+
}
696+
697+
RETURN_TYPES = ("COLOR",)
698+
RETURN_NAMES = ("COLOR",)
699+
FUNCTION = 'get_color'
700+
CATEGORY = 'LevelPixel/Image'
701+
702+
def get_color(self, preset, color):
703+
if not color:
704+
return (COLOR_PRESETS[preset],)
705+
706+
try:
707+
fixed_color = fix_color_format(color)
708+
if not all(c in '0123456789ABCDEFabcdef' for c in fixed_color[1:]):
709+
raise ValueError(f"Invalid hex characters in {color}")
710+
return (fixed_color,)
711+
except Exception as e:
712+
raise RuntimeError(f"Invalid color format: {color}. Please use format like #FF0000 or #F00")
713+
658714
NODE_CLASS_MAPPINGS = {
659-
"ImageRemoveBackgroundRMBG|LP": ImageRemoveBackgroundRMBG
715+
"ImageRemoveBackgroundRMBG|LP": ImageRemoveBackgroundRMBG,
716+
"ColorInput|LP": ColorInput,
660717
}
661718

662719
NODE_DISPLAY_NAME_MAPPINGS = {
663720
"ImageRemoveBackgroundRMBG|LP": "Image Remove Background (RMBG) [LP]",
721+
"ColorInput|LP": "Color Input [LP]",
664722
}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "comfyui-levelpixel-advanced"
33
description = "Advanced nodes of the Level Pixel company (aka levelpixel, LP). Includes convenient advanced nodes for working with LLM и VLM models (LLaVa, Multimodal Generator) with GGUF format. Qwen2.5-VL and Qwen2.5 supported, based on llama-mtmd. Also included is a node for the RAM model. Nodes have the ability to automatically unload models from VRAM. This package also includes Autotagger (WD), Image Remove Background (based on RMBG-2.0, on BiRefNet, on BiRefNet-HR-Matter, on RemBG). Licensed under GNU GPLv3. Repository: https://github.com/LevelPixel/ComfyUI-LevelPixel-Advanced"
4-
version = "1.2.9"
4+
version = "1.3.0"
55
license = { file = "LICENSE.txt" }
66
dependencies = [
77
"torch>=2.0.1",

0 commit comments

Comments
 (0)