@@ -38,19 +38,19 @@ def _is_hex(x: str) -> bool:
38
38
39
39
def _parse_hex (color_code : str ) -> TypeRGBAFloats :
40
40
return (
41
- _color_byte_to_normalized_float (int (color_code [1 :3 ], 16 )),
42
- _color_byte_to_normalized_float (int (color_code [3 :5 ], 16 )),
43
- _color_byte_to_normalized_float (int (color_code [5 :7 ], 16 )),
41
+ _color_int_to_float (int (color_code [1 :3 ], 16 )),
42
+ _color_int_to_float (int (color_code [3 :5 ], 16 )),
43
+ _color_int_to_float (int (color_code [5 :7 ], 16 )),
44
44
1.0 ,
45
45
)
46
46
47
47
48
- def _color_byte_to_normalized_float (x : Union [int , float ]) -> float :
48
+ def _color_int_to_float (x : Union [int , float ]) -> float :
49
49
"""Convert an integer between 0 and 255 to a float between 0. and 1.0"""
50
50
return x / 255.0
51
51
52
52
53
- def _color_normalized_float_to_byte_int (x : float ) -> int :
53
+ def _color_float_to_int (x : float ) -> int :
54
54
"""Convert a float between 0. and 1.0 to an integer between 0 and 255"""
55
55
return int (x * 255.9999 )
56
56
@@ -78,7 +78,7 @@ def _parse_color_as_numerical_sequence(x: Union[tuple, list]) -> TypeRGBAFloats:
78
78
raise ValueError (f"Color sequence should have 3 or 4 elements, not { len (x )} ." )
79
79
conversion_function : Callable = float
80
80
if 1 < max (x ) <= 255 :
81
- conversion_function = _color_byte_to_normalized_float
81
+ conversion_function = _color_int_to_float
82
82
if min (x ) < 0 or max (x ) > 255 :
83
83
raise ValueError ("Color components should be between 0.0 and 1.0 or 0 and 255." )
84
84
color : List [float ] = [conversion_function (value ) for value in x ]
@@ -175,9 +175,7 @@ def rgba_bytes_tuple(self, x: float) -> TypeRGBAInts:
175
175
"""Provides the color corresponding to value `x` in the
176
176
form of a tuple (R,G,B,A) with int values between 0 and 255.
177
177
"""
178
- return tuple (
179
- _color_normalized_float_to_byte_int (u ) for u in self .rgba_floats_tuple (x )
180
- ) # type: ignore
178
+ return tuple (_color_float_to_int (u ) for u in self .rgba_floats_tuple (x )) # type: ignore
181
179
182
180
def rgb_bytes_tuple (self , x : float ) -> TypeRGBInts :
183
181
"""Provides the color corresponding to value `x` in the
0 commit comments