yta-colors 0.0.1__tar.gz → 0.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {yta_colors-0.0.1 → yta_colors-0.0.2}/PKG-INFO +3 -3
- yta_colors-0.0.2/README.md +3 -0
- {yta_colors-0.0.1 → yta_colors-0.0.2}/pyproject.toml +2 -2
- {yta_colors-0.0.1 → yta_colors-0.0.2}/src/yta_colors/__init__.py +49 -15
- {yta_colors-0.0.1 → yta_colors-0.0.2}/src/yta_colors/converter.py +53 -15
- yta_colors-0.0.1/README.md +0 -3
- {yta_colors-0.0.1 → yta_colors-0.0.2}/LICENSE +0 -0
- {yta_colors-0.0.1 → yta_colors-0.0.2}/src/yta_colors/utils.py +0 -0
@@ -1,7 +1,7 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: yta-colors
|
3
|
-
Version: 0.0.
|
4
|
-
Summary:
|
3
|
+
Version: 0.0.2
|
4
|
+
Summary: Youtube Autonomous Colors Module
|
5
5
|
Author: danialcala94
|
6
6
|
Author-email: danielalcalavalera@gmail.com
|
7
7
|
Requires-Python: ==3.9
|
@@ -11,6 +11,6 @@ Requires-Dist: yta_constants (>=0.0.1,<1.0.0)
|
|
11
11
|
Requires-Dist: yta_validation (>=0.0.1,<1.0.0)
|
12
12
|
Description-Content-Type: text/markdown
|
13
13
|
|
14
|
-
# Youtube Autonomous Colors
|
14
|
+
# Youtube Autonomous Colors Module
|
15
15
|
|
16
16
|
The way to handle and validate colors.
|
@@ -40,14 +40,22 @@ class Color:
|
|
40
40
|
value and 255 is everything.
|
41
41
|
"""
|
42
42
|
|
43
|
-
def __init__(
|
43
|
+
def __init__(
|
44
|
+
self,
|
45
|
+
r,
|
46
|
+
g,
|
47
|
+
b,
|
48
|
+
a
|
49
|
+
):
|
44
50
|
self.r, self.g, self.b, self.a = r, g, b, a
|
45
51
|
# TODO: Precalculate and store all the values
|
46
52
|
# internally so we don't need to calculate them
|
47
53
|
# later (?)
|
48
54
|
|
49
55
|
@property
|
50
|
-
def rgb_not_normalized(
|
56
|
+
def rgb_not_normalized(
|
57
|
+
self
|
58
|
+
):
|
51
59
|
"""
|
52
60
|
Get the color as a tuple of the 3 RGB values that
|
53
61
|
are, in order: red, green, blue. These values are
|
@@ -57,7 +65,9 @@ class Color:
|
|
57
65
|
return self.r, self.g, self.b
|
58
66
|
|
59
67
|
@property
|
60
|
-
def rgb_normalized(
|
68
|
+
def rgb_normalized(
|
69
|
+
self
|
70
|
+
):
|
61
71
|
"""
|
62
72
|
Get the color as a tuple of the 3 RGB values that
|
63
73
|
are, in order: red, green, blue. These values are
|
@@ -66,7 +76,9 @@ class Color:
|
|
66
76
|
return self.r / 255.0, self.g / 255.0, self.b / 255.0
|
67
77
|
|
68
78
|
@property
|
69
|
-
def rgba_not_normalized(
|
79
|
+
def rgba_not_normalized(
|
80
|
+
self
|
81
|
+
):
|
70
82
|
"""
|
71
83
|
Get the color as a tuple of the 3 RGB values and
|
72
84
|
a 4th value representing the transparency, that
|
@@ -77,7 +89,9 @@ class Color:
|
|
77
89
|
self.r, self.g, self.b, self.a
|
78
90
|
|
79
91
|
@property
|
80
|
-
def rgba_normalized(
|
92
|
+
def rgba_normalized(
|
93
|
+
self
|
94
|
+
):
|
81
95
|
"""
|
82
96
|
Get the color as a tuple of the 3 RGB values and
|
83
97
|
a 4th value representing the transparency, that
|
@@ -88,7 +102,9 @@ class Color:
|
|
88
102
|
return self.r / 255.0, self.g / 255.0, self.b / 255.0, self.a / 255.0
|
89
103
|
|
90
104
|
@property
|
91
|
-
def rgb_array_not_normalized(
|
105
|
+
def rgb_array_not_normalized(
|
106
|
+
self
|
107
|
+
):
|
92
108
|
"""
|
93
109
|
Get the color as an array of the 3 RGB values that
|
94
110
|
are, in order: red, green, blue. These values are
|
@@ -98,7 +114,9 @@ class Color:
|
|
98
114
|
return [*self.rgba_not_normalized]
|
99
115
|
|
100
116
|
@property
|
101
|
-
def rgb_array_normalized(
|
117
|
+
def rgb_array_normalized(
|
118
|
+
self
|
119
|
+
):
|
102
120
|
"""
|
103
121
|
Get the color as an array of the 3 RGB values that
|
104
122
|
are, in order: red, green, blue. These values are
|
@@ -107,7 +125,9 @@ class Color:
|
|
107
125
|
return [*self.rgba_normalized]
|
108
126
|
|
109
127
|
@property
|
110
|
-
def rgba_array_not_normalized(
|
128
|
+
def rgba_array_not_normalized(
|
129
|
+
self
|
130
|
+
):
|
111
131
|
"""
|
112
132
|
Get the color as an array of the 3 RGB values and
|
113
133
|
a 4th value representing the transparency, that
|
@@ -118,7 +138,9 @@ class Color:
|
|
118
138
|
return [*self.rgba_not_normalized]
|
119
139
|
|
120
140
|
@property
|
121
|
-
def rgba_array_normalized(
|
141
|
+
def rgba_array_normalized(
|
142
|
+
self
|
143
|
+
):
|
122
144
|
"""
|
123
145
|
Get the color as an array of the 3 RGB values and
|
124
146
|
a 4th value representing the transparency, that
|
@@ -129,7 +151,9 @@ class Color:
|
|
129
151
|
return [*self.rgba_normalized]
|
130
152
|
|
131
153
|
@property
|
132
|
-
def hex_with_alpha(
|
154
|
+
def hex_with_alpha(
|
155
|
+
self
|
156
|
+
):
|
133
157
|
"""
|
134
158
|
Get the color as a string representing it in
|
135
159
|
hexadecimal value. The result will be #RRGGBBAA
|
@@ -139,7 +163,9 @@ class Color:
|
|
139
163
|
return ColorConverter.rgba_to_hex(self.rgba_not_normalized, True)
|
140
164
|
|
141
165
|
@property
|
142
|
-
def hex_without_alpha(
|
166
|
+
def hex_without_alpha(
|
167
|
+
self
|
168
|
+
):
|
143
169
|
"""
|
144
170
|
Get the color as a string representing it in
|
145
171
|
hexadecimal value. The result will be #RRGGBB
|
@@ -148,21 +174,27 @@ class Color:
|
|
148
174
|
return ColorConverter.rgba_to_hex(self.rgba_not_normalized, False)
|
149
175
|
|
150
176
|
@property
|
151
|
-
def hsl(
|
177
|
+
def hsl(
|
178
|
+
self
|
179
|
+
):
|
152
180
|
"""
|
153
181
|
Get the color as an HSL color.
|
154
182
|
"""
|
155
183
|
return ColorConverter.rgba_to_hsl(self.rgba_not_normalized)
|
156
184
|
|
157
185
|
@property
|
158
|
-
def cymk(
|
186
|
+
def cymk(
|
187
|
+
self
|
188
|
+
):
|
159
189
|
"""
|
160
190
|
Get the color as an CYMK color.
|
161
191
|
"""
|
162
192
|
return ColorConverter.rgba_to_cymk(self.rgba_not_normalized)
|
163
193
|
|
164
194
|
@property
|
165
|
-
def hsv(
|
195
|
+
def hsv(
|
196
|
+
self
|
197
|
+
):
|
166
198
|
"""
|
167
199
|
Get the color as a HSV color.
|
168
200
|
"""
|
@@ -170,7 +202,9 @@ class Color:
|
|
170
202
|
|
171
203
|
# TODO: Use the cv2 library to make other changes
|
172
204
|
@staticmethod
|
173
|
-
def parse(
|
205
|
+
def parse(
|
206
|
+
color: Union[list, tuple, str, 'ColorString', 'Color']
|
207
|
+
):
|
174
208
|
"""
|
175
209
|
Parse the provided 'color' parameter and return the
|
176
210
|
color as r,g,b,a values or raises an Exception if it
|
@@ -1,5 +1,6 @@
|
|
1
1
|
from yta_colors.utils import is_hexadecimal_color, parse_rgba_color, rgba_to_hex, hex_to_rgba, rgb_to_hex, rgba_to_hex, rgb_to_hsl, rgb_to_cymk, rgb_to_hsv, hsv_to_rgb, rgba_to_hsv, parse_color, hsv_to_rgba
|
2
2
|
from yta_validation import PythonValidator
|
3
|
+
from yta_validation.parameter import ParameterValidator
|
3
4
|
from typing import Union
|
4
5
|
|
5
6
|
|
@@ -10,7 +11,11 @@ class ColorConverter:
|
|
10
11
|
"""
|
11
12
|
|
12
13
|
@staticmethod
|
13
|
-
def rgb_to_hex(
|
14
|
+
def rgb_to_hex(
|
15
|
+
red,
|
16
|
+
green,
|
17
|
+
blue
|
18
|
+
):
|
14
19
|
"""
|
15
20
|
Returns the provided RGB color as a hex color. The 'red', 'green' and
|
16
21
|
'blue' parameters must be between 0 and 255.
|
@@ -18,7 +23,9 @@ class ColorConverter:
|
|
18
23
|
return rgba_to_hex(red, green, blue)
|
19
24
|
|
20
25
|
@staticmethod
|
21
|
-
def hex_to_rgb(
|
26
|
+
def hex_to_rgb(
|
27
|
+
color: str
|
28
|
+
):
|
22
29
|
"""
|
23
30
|
Parse the provided hexadecimal 'color' parameter and
|
24
31
|
turn it into an RGB color (returned as r,g,b) or
|
@@ -29,14 +36,19 @@ class ColorConverter:
|
|
29
36
|
return r, g, b
|
30
37
|
|
31
38
|
@staticmethod
|
32
|
-
def hex_to_rgba(
|
39
|
+
def hex_to_rgba(
|
40
|
+
color: str
|
41
|
+
):
|
33
42
|
if not is_hexadecimal_color(color):
|
34
43
|
raise Exception(f'The provided "color" parameter "{str(color)}" is not an hexadecimal color.')
|
35
44
|
|
36
45
|
return hex_to_rgba(color)
|
37
46
|
|
38
47
|
@staticmethod
|
39
|
-
def rgb_to_hex(
|
48
|
+
def rgb_to_hex(
|
49
|
+
color: Union[tuple, list],
|
50
|
+
do_include_alpha: bool = False
|
51
|
+
):
|
40
52
|
"""
|
41
53
|
Parse the provided RGB 'color' parameter and turn it to
|
42
54
|
a hexadecimal color if valid or raises an Exception if
|
@@ -44,11 +56,15 @@ class ColorConverter:
|
|
44
56
|
False, or #RRGGBBAA if 'do_include_alpha' is True.
|
45
57
|
"""
|
46
58
|
validate_color(color)
|
59
|
+
ParameterValidator.validate_mandatory_bool('do_include_alpha', do_include_alpha)
|
47
60
|
|
48
61
|
return rgb_to_hex(color, do_include_alpha)
|
49
62
|
|
50
63
|
@staticmethod
|
51
|
-
def rgba_to_hex(
|
64
|
+
def rgba_to_hex(
|
65
|
+
color: Union[tuple, list],
|
66
|
+
do_include_alpha: bool = False
|
67
|
+
):
|
52
68
|
"""
|
53
69
|
Parse the provided RGBA 'color' parameter and turn it to
|
54
70
|
a hexadecimal color if valid or raises an Exception if
|
@@ -56,11 +72,14 @@ class ColorConverter:
|
|
56
72
|
False, or #RRGGBBAA if 'do_include_alpha' is True.
|
57
73
|
"""
|
58
74
|
validate_color(color)
|
75
|
+
ParameterValidator.validate_mandatory_bool('do_include_alpha', do_include_alpha)
|
59
76
|
|
60
77
|
return rgba_to_hex(color, do_include_alpha)
|
61
78
|
|
62
79
|
@staticmethod
|
63
|
-
def rgba_to_hsl(
|
80
|
+
def rgba_to_hsl(
|
81
|
+
color: Union[tuple, list]
|
82
|
+
):
|
64
83
|
# TODO: Explain
|
65
84
|
validate_color(color)
|
66
85
|
|
@@ -69,14 +88,18 @@ class ColorConverter:
|
|
69
88
|
return *ColorConverter.rgb_to_hsl(color), a
|
70
89
|
|
71
90
|
@staticmethod
|
72
|
-
def rgb_to_hsl(
|
91
|
+
def rgb_to_hsl(
|
92
|
+
color: Union[tuple, list]
|
93
|
+
):
|
73
94
|
# TODO: Explain
|
74
95
|
validate_color(color)
|
75
96
|
|
76
97
|
return rgb_to_hsl(color)
|
77
98
|
|
78
99
|
@staticmethod
|
79
|
-
def rgba_to_cymk(
|
100
|
+
def rgba_to_cymk(
|
101
|
+
color: Union[tuple, list]
|
102
|
+
):
|
80
103
|
# TODO: Explain
|
81
104
|
validate_color(color)
|
82
105
|
|
@@ -87,7 +110,9 @@ class ColorConverter:
|
|
87
110
|
return ColorConverter.rgb_to_cymk(color)
|
88
111
|
|
89
112
|
@staticmethod
|
90
|
-
def rgb_to_cymk(
|
113
|
+
def rgb_to_cymk(
|
114
|
+
color: Union[tuple, list]
|
115
|
+
):
|
91
116
|
# TODO: Explain
|
92
117
|
# It looks like you need to know the color profile before
|
93
118
|
# any conversion from RGB or RGBA
|
@@ -97,7 +122,9 @@ class ColorConverter:
|
|
97
122
|
return rgb_to_cymk(color)
|
98
123
|
|
99
124
|
@staticmethod
|
100
|
-
def rgb_to_hsv(
|
125
|
+
def rgb_to_hsv(
|
126
|
+
color: Union[tuple, list]
|
127
|
+
):
|
101
128
|
"""
|
102
129
|
Turn the provided RGB 'color' into a HSV color.
|
103
130
|
"""
|
@@ -106,7 +133,9 @@ class ColorConverter:
|
|
106
133
|
return rgb_to_hsv(color)
|
107
134
|
|
108
135
|
@staticmethod
|
109
|
-
def rgba_to_hsv(
|
136
|
+
def rgba_to_hsv(
|
137
|
+
color: Union[tuple, list]
|
138
|
+
):
|
110
139
|
"""
|
111
140
|
Turn the provided RGBA 'color' into a HSV color.
|
112
141
|
The HSV color doesn't pay attention to the alpha
|
@@ -118,7 +147,9 @@ class ColorConverter:
|
|
118
147
|
return rgba_to_hsv(color)
|
119
148
|
|
120
149
|
@staticmethod
|
121
|
-
def hsv_to_rgb(
|
150
|
+
def hsv_to_rgb(
|
151
|
+
color: Union[tuple, list]
|
152
|
+
):
|
122
153
|
"""
|
123
154
|
Turn the provided HSV 'color' into a RGB color.
|
124
155
|
"""
|
@@ -129,7 +160,9 @@ class ColorConverter:
|
|
129
160
|
return hsv_to_rgb(h, s, v)
|
130
161
|
|
131
162
|
@staticmethod
|
132
|
-
def hsv_to_rgba(
|
163
|
+
def hsv_to_rgba(
|
164
|
+
color: Union[tuple, list]
|
165
|
+
):
|
133
166
|
"""
|
134
167
|
Turn the provided HSV 'color' into a RGBA color.
|
135
168
|
The HSV color doesn't pay attention to the alpha
|
@@ -141,12 +174,17 @@ class ColorConverter:
|
|
141
174
|
|
142
175
|
return hsv_to_rgba(h, s, v)
|
143
176
|
|
144
|
-
def validate_color(
|
177
|
+
def validate_color(
|
178
|
+
color: Union[tuple, list]
|
179
|
+
):
|
145
180
|
"""
|
146
181
|
Validate the provided 'color' as a tuple or list of 3
|
147
182
|
or 4 elements.
|
148
183
|
"""
|
149
|
-
if
|
184
|
+
if (
|
185
|
+
not PythonValidator.is_instance(color, 'Color') and
|
186
|
+
parse_color(color) is None
|
187
|
+
):
|
150
188
|
raise Exception('The provided "color" is not a parsable color.')
|
151
189
|
|
152
190
|
return True
|
yta_colors-0.0.1/README.md
DELETED
File without changes
|
File without changes
|