21 if x > 0.00313080495356037152: val = math.pow(x, 1./2.4)*1.055 - 0.055
26 if x > 0.04045: val = math.pow((x + 0.055)/1.055, 2.4)
27 else: val = (x+0.)/12.92
36 return fRGB((r+0.)/100.),
fRGB((g+0.)/100.),
fRGB((b+0.)/100.)
49 x = 0.4124*sr + 0.3576*sg + 0.1805*sb
50 y = 0.2126*sr + 0.7152*sg + 0.0722*sb
51 z = 0.0193*sr + 0.1192*sg + 0.9505*sb
55 r = 3.24063*x - 1.53721*y - 0.498629*z
56 g = -0.968931*x + 1.87576*y + 0.0415175*z
57 b = 0.0557101*x - 0.204021*y + 1.057*z
68 if v > 0.008856:
return math.pow(v, 1./3.)
69 else:
return 7.787*v + 16./116.
72 if v > 0.20689270648:
return math.pow(v, 3)
73 else:
return (v - 16./116.)/7.787
84 L = 116*(
F((y+0.)/(yn +0.)) - 16./116.)
85 a = 500*(
F((x+0.)/(xn+0.)) -
F((y+0.)/(yn+0.)))
86 b = 200*(
F((y+0.)/(yn+0.)) -
F((z+0.)/(zn+0.)))
97 x =
Finv((a+0.)/500. + (L + 16.)/116.)*xn
98 y =
Finv((L + 16.)/116.)*yn
99 z =
Finv((L + 16.)/116. - (b+0.)/200.)*zn
103 M = math.sqrt(math.pow(L,2) + math.pow(a,2) + math.pow(b,2))
104 s = math.acos((L+0.)/(M+0.))
110 a = M*math.sin(s)*math.cos(h)
111 b = M*math.sin(s)*math.sin(h)
116 xr, yr, zr =
rgb2xyz(refW[0], refW[1], refW[2])
117 L, a, b =
xyz2Lab(x, y, z, [xr, yr, zr])
121 xr, yr, zr =
rgb2xyz(refW[0], refW[1], refW[2])
123 x, y, z =
Lab2xyz(L, a, b, [xr, yr, zr])
128 if Ms >= Mu:
return hs
129 h = ss*math.sqrt(math.pow(Mu, 2.) - math.pow(Ms, 2.))/(Ms*math.sin(ss)+0.)
130 if hs > -math.pi/3.:
return hs + h
135 if diff > math.pi:
return abs(diff - 2*math.pi)
142 M1, s1, h1 =
rgb2Msh(col1[0], col1[1], col1[2], white)
143 M2, s2, h2 =
rgb2Msh(col2[0], col2[1], col2[2], white)
146 if s1 > 0.05
and s2 > 0.05
and abs(h1 - h2) > math.pi/3.:
147 Mmid =
max(
max(M1,M2),88.)
158 if s1 < 0.05
and s2 > 0.05: h1 =
AdjustHue(M2, s2, h2, M1)
159 elif s2 < 0.05
and s1 > 0.05: h2 =
AdjustHue(M1, s1, h1, M2)
161 M = (1 - frac)*M1 + frac*M2
162 s = (1 - frac)*s1 + frac*s2
163 h = (1 - frac)*h1 + frac*h2
168 if __name__ ==
'__main__':
169 Msh = [83.9912098 , 0.54009147, -0.18776355]
170 Msh_np = np.array(Msh)
S & print(S &os, JobReport::InputFile const &f)
def Msh2rgb(M, s, h, refW)
def DivergingColor(col1, col2, white, frac)
Abs< T >::type abs(const T &t)
def xyz2Lab(x, y, z, refW)
def AdjustHue(Ms, ss, hs, Mu)
def Lab2xyz(L, a, b, refW)
def rgb2Msh(r, g, b, refW)