Skip to content
This repository was archived by the owner on Nov 22, 2019. It is now read-only.

Commit 0d01824

Browse files
author
mfe
committed
Add sRGB colorspace
Now Rec709 is a child of sRGB.
1 parent 85a3f68 commit 0d01824

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

utils/colorspaces.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,10 @@ def gamma_to_lin(self, value):
7878
pass
7979

8080

81-
class Rec709(AbstractColorspace):
82-
"""rec709 colorspace
81+
class sRGB(AbstractColorspace):
82+
"""sRGB colorspace
8383
8484
"""
85-
def __init__(self):
86-
self._alpha = 1.099
87-
self._beta = 0.018
88-
self._round_depth = 3
89-
9085
def get_red_primaries(self):
9186
return 0.64, 0.33
9287

@@ -99,6 +94,28 @@ def get_blue_primaries(self):
9994
def get_white_point(self):
10095
return 0.3127, 0.3290
10196

97+
def lin_to_gamma(self, value):
98+
if value > 0.0031308:
99+
return 1.055 * pow(value, 1.0 / 2.4) - 0.055
100+
else:
101+
return 12.92 * value
102+
103+
def gamma_to_lin(self, value):
104+
if value > 0.04045:
105+
return pow((value + 0.055) / 1.055, 2.4)
106+
else:
107+
return value / 12.92
108+
109+
110+
class Rec709(sRGB):
111+
"""rec709 colorspace
112+
113+
"""
114+
def __init__(self):
115+
self._alpha = 1.099
116+
self._beta = 0.018
117+
self._round_depth = 3
118+
102119
def lin_to_gamma(self, value):
103120
if value < self._beta:
104121
return value * 4.5
@@ -229,11 +246,13 @@ def gamma_to_lin(self, value):
229246
REC2020_10B = Rec2020(is_ten_bits=True)
230247
REC2020_12B = Rec2020(is_ten_bits=False)
231248
ACES = ACES()
249+
sRGB = sRGB()
232250
COLORSPACES = {
233251
'REC709': REC709,
234252
'ALEXALOGCV3': ALEXALOGCV3,
235253
'WIDEGAMUT': WIDEGAMUT,
236254
'REC2020_10bits': REC2020_10B,
237255
'REC2020_12bits': REC2020_12B,
238256
'ACES': ACES,
257+
'sRGB': sRGB,
239258
}

0 commit comments

Comments
 (0)