@@ -16,23 +16,30 @@ def define_schema(cls) -> io.Schema:
1616 ],
1717 outputs = [
1818 io .Int .Output (display_name = "rgb_int" ),
19- io .Color .Output (display_name = "hex" )
19+ io .Color .Output (display_name = "hex" ),
20+ io .Float .Output (display_name = "alpha" ),
2021 ],
2122 )
2223
2324 @classmethod
2425 def execute (cls , color : str ) -> io .NodeOutput :
25- # expect format #RRGGBB
26- if len (color ) != 7 or color [0 ] != "#" :
27- raise ValueError ("Color must be in format #RRGGBB" )
26+ # expect format #RRGGBB or #RRGGBBAA
27+ if len (color ) not in ( 7 , 9 ) or color [0 ] != "#" :
28+ raise ValueError ("Color must be in format #RRGGBB or #RRGGBBAA " )
2829 try :
2930 int (color [1 :], 16 )
3031 except ValueError :
31- raise ValueError ("Color must be in format #RRGGBB" ) from None
32+ raise ValueError ("Color must be in format #RRGGBB or #RRGGBBAA" ) from None
33+
34+ alpha = 1.0
35+ if len (color ) == 9 :
36+ alpha = int (color [7 :9 ], 16 ) / 255.0
37+ color = color [:7 ]
38+
3239 r , g , b = hex_to_rgb (color )
3340
3441 rgb_int = r * 256 * 256 + g * 256 + b
35- return io .NodeOutput (rgb_int , color )
42+ return io .NodeOutput (rgb_int , color , alpha )
3643
3744
3845class ColorExtension (ComfyExtension ):
0 commit comments