channel.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # import
  2. # ------------------------------------------------------------------------------------------
  3. import enum
  4. # ------------------------------------------------------------------------------------------
  5. # MIAM project 2020
  6. # ------------------------------------------------------------------------------------------
  7. # author: remi.cozot@univ-littoral.fr
  8. # ------------------------------------------------------------------------------------------
  9. class channel(enum.Enum):
  10. """ easy definition of channel """
  11. sR = 0
  12. sG = 1
  13. sB = 2
  14. sRGB = 3
  15. X = 4
  16. Y = 5
  17. Z = 6
  18. XYZ = 7
  19. L = 8
  20. a = 9
  21. b = 10
  22. Lab = 11
  23. def colorSpace(self):
  24. csIdx = self.value // 4
  25. res = None
  26. if csIdx == 0: res ='sRGB'
  27. elif csIdx == 1: res = 'XYZ'
  28. elif csIdx == 2: res = 'Lab'
  29. return res
  30. def getValue(self): return self.value % 4
  31. def toChannel(s):
  32. if s=='sR' : return channel.sR
  33. elif s=='sG' : return channel.sG
  34. elif s=='sB' : return channel.sB
  35. elif s=='X' : return channel.X
  36. elif s=='Y' : return channel.Y
  37. elif s=='Z' : return channel.Z
  38. elif s=='L' : return channel.L
  39. elif s=='a' : return channel.a
  40. elif s=='b' : return channel.b
  41. else: return channel.L