-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
163ba5d
commit c21ca04
Showing
2 changed files
with
76 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import yaml | ||
import Colourimetry | ||
|
||
class TColor(): | ||
"""Contains a set of known colour spaces. Allows for interacting with and | ||
adding or removing colour spaces""" | ||
|
||
def __init__(self) -> None: | ||
self.config = {} | ||
|
||
def RGBPrimaries_from_YAML(self, yaml_input) -> Colourimetry.RGBPrimaries: | ||
try: | ||
red = yaml_input["Red"] | ||
green = yaml_input["Green"] | ||
blue = yaml_input["Blue"] | ||
|
||
primaries = Colourimetry.RGBPrimaries(list(red.values()), list(green.values()), list(blue.values())) | ||
|
||
return primaries | ||
except KeyError as e: | ||
print("YAML ERROR: ", e) | ||
|
||
|
||
def parse_data(self, data:list): | ||
"""Parse the YAML data""" | ||
for id, idx in enumerate(data): | ||
new_colourimetry_set = Colourimetry.Colourimetry() | ||
name = list(data[id].keys())[0] | ||
colour_space = data[id][name] | ||
|
||
new_colourimetry_set.descriptor = name | ||
|
||
if "RGB Primaries" in colour_space: | ||
primaries = colour_space["RGB Primaries"] | ||
if type(primaries) is dict: | ||
new_colourimetry_set.primaries = self.RGBPrimaries_from_YAML(primaries) | ||
else: | ||
new_colourimetry_set.primaries = primaries | ||
|
||
if "Achromatic Centroid" in colour_space: | ||
new_colourimetry_set.achromatic = colour_space["Achromatic Centroid"] | ||
|
||
if "Transfer Characteristic" in colour_space: | ||
new_colourimetry_set.transfer_characteristic = colour_space["Transfer Characteristic"] | ||
|
||
if "Hints" in colour_space: | ||
new_colourimetry_set.hints = colour_space["Hints"] | ||
|
||
if "Alias" in colour_space: | ||
new_colourimetry_set.alias = colour_space["Alias"] | ||
|
||
if "CIE Version" in colour_space: | ||
new_colourimetry_set.cie_version = colour_space["CIE Version"] | ||
|
||
self.config[str(name)] = new_colourimetry_set | ||
|
||
|
||
|
||
|
||
def add_colour_space(self, colour_space): | ||
"""Add a colour space to the config as either a file or a string""" | ||
|
||
with open(colour_space, 'r') as file: | ||
data = yaml.safe_load(file) | ||
self.parse_data(data) | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
config = TColor() | ||
|
||
config.add_colour_space("..\\tests\\files\\tcolor_test.yaml") | ||
|
||
for key, value in config.config.items(): | ||
print(key, value) |