77# Custom Library
88
99# Custom Packages
10- from AthenaColor .InitClass import init
1110import AthenaColor .Objects .Color .ColorTupleConversion as CTC
12- from AthenaColor .Objects .Color .ColorSystem import ColorSystem ,RGB ,HEX ,CMYK ,HSL ,HSV ,RGBA ,HEXA
11+ from AthenaColor .Objects .Color .ColorSystem import ColorSystem ,RGB ,HEX ,CMYK ,HSL ,HSV ,RGBA ,HEXA , color_conversions_mapped
1312
1413# ----------------------------------------------------------------------------------------------------------------------
1514# - All -
@@ -26,19 +25,9 @@ def to_RGB(color:ColorSystem|RGB|HEX|CMYK|HSL|HSV|RGBA|HEXA) -> RGB:
2625 """
2726 Function which converts any Color Object to an RGB object
2827 """
29- if isinstance (color , HEX ):
30- return RGB (* CTC .hex_to_rgb (str (color )))
31- elif isinstance (color , RGB ):
32- return RGB (* color .export ())
33- elif isinstance (color ,(RGBA ,HEXA )):
34- return RGB (* color .export ()[:- 1 ])
35- elif isinstance (color , HSV ):
36- return RGB (* CTC .hsv_to_rgb (* color .export ()))
37- elif isinstance (color , HSL ):
38- return RGB (* CTC .hsl_to_rgb (* color .export ()))
39- elif isinstance (color , CMYK ):
40- return RGB (* CTC .cmyk_to_rgb (* color .export ()))
41- else :
28+ try :
29+ return RGB (* color_conversions_mapped [RGB ][type (color )](color ))
30+ except KeyError :
4231 return NotImplemented
4332
4433# ----------------------------------------------------------------------------------------------------------------------
@@ -49,17 +38,9 @@ def to_HEX(color:ColorSystem|RGB|HEX|CMYK|HSL|HSV|RGBA|HEXA) -> HEX:
4938 """
5039 Function which converts any Color Object to an HEX object.
5140 """
52- if isinstance (color , (RGB ,HEX )):
53- return HEX (CTC .rgb_to_hex (* color .export ()))
54- elif isinstance (color ,(RGBA ,HEXA )):
55- return HEX (CTC .rgb_to_hex (* color .export ()[:- 1 ]))
56- elif isinstance (color , HSV ):
57- return HEX (CTC .hsv_to_hex (* color .export ()))
58- elif isinstance (color , HSL ):
59- return HEX (CTC .hsl_to_hex (* color .export ()))
60- elif isinstance (color , CMYK ):
61- return HEX (CTC .cmyk_to_hex (* color .export ()))
62- else :
41+ try :
42+ return HEX (CTC .rgb_to_hex (* color_conversions_mapped [HEX ][type (color )](color )))
43+ except KeyError :
6344 return NotImplemented
6445
6546# ----------------------------------------------------------------------------------------------------------------------
@@ -70,17 +51,9 @@ def to_HSV(color:ColorSystem|RGB|HEX|CMYK|HSL|HSV|RGBA|HEXA) -> HSV:
7051 """
7152 Function which converts any Color Object to an HSV object.
7253 """
73- if isinstance (color , (RGB ,HEX )):
74- return HSV (* CTC .rgb_to_hsv (* color .export ()))
75- elif isinstance (color ,(RGBA ,HEXA )):
76- return HSV (* CTC .rgb_to_hsv (* color .export ()[:- 1 ]))
77- elif isinstance (color , HSV ):
78- return HSV (* color .export ())
79- elif isinstance (color , HSL ):
80- return HSV (* CTC .hsl_to_hsv (* color .export ()))
81- elif isinstance (color , CMYK ):
82- return HSV (* CTC .cmyk_to_hsv (* color .export ()))
83- else :
54+ try :
55+ return HSV (* color_conversions_mapped [HSV ][type (color )](color ))
56+ except KeyError :
8457 return NotImplemented
8558
8659# ----------------------------------------------------------------------------------------------------------------------
@@ -90,17 +63,9 @@ def to_HSL(color:ColorSystem|RGB|HEX|CMYK|HSL|HSV|RGBA|HEXA) -> HSL:
9063 """
9164 Function which converts any Color Object to an HSL object.
9265 """
93- if isinstance (color , (RGB ,HEX )):
94- return HSL (* CTC .rgb_to_hsl (* color .export ()))
95- elif isinstance (color ,(RGBA ,HEXA )):
96- return HSL (* CTC .rgb_to_hsl (* color .export ()[:- 1 ]))
97- elif isinstance (color , HSV ):
98- return HSL (* CTC .hsv_to_hsl (* color .export ()))
99- elif isinstance (color , HSL ):
100- return HSL (* color .export ())
101- elif isinstance (color , CMYK ):
102- return HSL (* CTC .cmyk_to_hsl (* color .export ()))
103- else :
66+ try :
67+ return HSL (* color_conversions_mapped [HSL ][type (color )](color ))
68+ except KeyError :
10469 return NotImplemented
10570
10671# ----------------------------------------------------------------------------------------------------------------------
@@ -110,17 +75,9 @@ def to_CMYK(color:ColorSystem|RGB|HEX|CMYK|HSL|HSV|RGBA|HEXA) -> CMYK:
11075 """
11176 Function which converts any Color Object to an CMYK object.
11277 """
113- if isinstance (color , (RGB ,HEX )):
114- return CMYK (* CTC .rgb_to_cmyk (* color .export ()))
115- elif isinstance (color ,(RGBA ,HEXA )):
116- return CMYK (* CTC .rgb_to_cmyk (* color .export ()[:- 1 ]))
117- elif isinstance (color , HSV ):
118- return CMYK (* CTC .hsv_to_cmyk (* color .export ()))
119- elif isinstance (color , HSL ):
120- return CMYK (* CTC .hsl_to_cmyk (* color .export ()))
121- elif isinstance (color , CMYK ):
122- return CMYK (* color .export ())
123- else :
78+ try :
79+ return CMYK (* color_conversions_mapped [CMYK ][type (color )](color ))
80+ except KeyError :
12481 return NotImplemented
12582
12683# ----------------------------------------------------------------------------------------------------------------------
@@ -130,38 +87,16 @@ def to_RGBA(color:ColorSystem|RGB|HEX|CMYK|HSL|HSV|RGBA|HEXA) -> RGBA:
13087 """
13188 Function which converts any Color Object to an RGBA object.
13289 """
133- if isinstance (color , RGBA ):
134- return RGBA (* color .export ())
135- elif isinstance (color , HEXA ):
136- return RGBA (* CTC .hexa_to_rgba (str (color )))
137- # below conversions will set the A part of RGBA to 1
138- elif isinstance (color , (RGB ,HEX )):
139- return RGBA (* color .export (), a = init .transparentDefault [1 ])
140- elif isinstance (color , HSV ):
141- return RGBA (* CTC .hsv_to_rgb (* color .export ()), a = init .transparentDefault [1 ])
142- elif isinstance (color , HSL ):
143- return RGBA (* CTC .hsl_to_rgb (* color .export ()), a = init .transparentDefault [1 ])
144- elif isinstance (color , CMYK ):
145- return RGBA (* CTC .cmyk_to_rgb (* color .export ()), a = init .transparentDefault [1 ])
146- else :
90+ try :
91+ return RGBA (* color_conversions_mapped [RGBA ][type (color )](color ))
92+ except KeyError :
14793 return NotImplemented
14894
14995def to_HEXA (color :ColorSystem | RGB | HEX | CMYK | HSL | HSV | RGBA | HEXA ) -> HEXA :
15096 """
15197 Function which converts any Color Object to an HEXA object.
15298 """
153- if isinstance (color , RGBA ):
154- return HEXA (CTC .rgba_to_hexa (* color .export ()))
155- elif isinstance (color , HEXA ):
156- return HEXA (str (color ))
157- # below conversions will set the A part of HEXA to ff
158- elif isinstance (color , (RGB ,HEX )):
159- return HEXA (CTC .rgb_to_hex (* color .export ()) + init .transparentDefault [0 ])
160- elif isinstance (color , HSV ):
161- return HEXA (CTC .hsv_to_hex (* color .export ()) + init .transparentDefault [0 ])
162- elif isinstance (color , HSL ):
163- return HEXA (CTC .hsl_to_hex (* color .export ()) + init .transparentDefault [0 ])
164- elif isinstance (color , CMYK ):
165- return HEXA (CTC .cmyk_to_hex (* color .export ()) + init .transparentDefault [0 ])
166- else :
99+ try :
100+ return HEXA (CTC .rgba_to_hexa (* color_conversions_mapped [HEXA ][type (color )](color )))
101+ except KeyError :
167102 return NotImplemented
0 commit comments