Skip to content

Commit

Permalink
Add print functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasWilshaw committed Sep 28, 2024
1 parent 455f7f2 commit 8f1456b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
3 changes: 3 additions & 0 deletions tcolour/Colourimetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def valid(self) -> bool:
def __repr__(self) -> str:
return "RGBPrimaries(r=%r, g=%r, b=%r)" % (self.r, self.g, self.b)

def __str__(self) -> str:
return "%r, %r, %r" % (self.r, self.g, self.b)

class CIEVersion(Enum):
CIE_1931_2_DEGREE = 1
CIE_2015_2_DEGREE = 2
Expand Down
2 changes: 1 addition & 1 deletion tcolour/TransferCharacteristic.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def valid(self) -> bool:

def __repr__(self) -> str:
return "TransferCharacteristicPower(parameters=%r)" % (self.parameters)

class TransferCharacteristicPowerWithBreak(TransferCharacteristicParametric):
"""A power function with a linear segment near zero transfer characteristic"""

Expand Down
25 changes: 18 additions & 7 deletions tcolour/tcolour.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,34 @@ def parse_data(self, data:list):
print(e, "Skipping this Colourimetry chunk")




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)

def print_colourimetry(self, descriptor):
"""Pretty prints the colourimetry data set for the given descriptor"""

item:Colourimetry = config.config[descriptor]
print("-", item.descriptor)
print("\tRGB Primaries: " + item.primaries.__str__())
print("\tAchromatic Centroid: ", item.achromatic)
print("\tTransfer Characteristic:", item.transfer_characteristic)
print("\tHints: ", item.hints)
print("\tAlias: ", item.alias)
print("\tCIE Version:", item.cie_version)
print()

def print_all_colourimetry(self):
for key, value in self.config.items():
self.print_colourimetry(key)



if __name__ == "__main__":
config = TColor()

config.add_colour_space("..\\tests\\files\\tcolor_test.yaml")

for key, value in config.config.items():
print(key, value)
print()
pass
config.print_all_colourimetry()

0 comments on commit 8f1456b

Please sign in to comment.