mirror of https://github.com/python/cpython
Improve consistency of colorsys.rgb_to_hsv (GH-27277)
Cache repeated difference to make code easier to read and consistent with colorsys.rgb_to_hls.
This commit is contained in:
parent
17575f73ce
commit
7d28a6eb90
|
@ -125,13 +125,14 @@ def _v(m1, m2, hue):
|
||||||
def rgb_to_hsv(r, g, b):
|
def rgb_to_hsv(r, g, b):
|
||||||
maxc = max(r, g, b)
|
maxc = max(r, g, b)
|
||||||
minc = min(r, g, b)
|
minc = min(r, g, b)
|
||||||
|
rangec = (maxc-minc)
|
||||||
v = maxc
|
v = maxc
|
||||||
if minc == maxc:
|
if minc == maxc:
|
||||||
return 0.0, 0.0, v
|
return 0.0, 0.0, v
|
||||||
s = (maxc-minc) / maxc
|
s = rangec / maxc
|
||||||
rc = (maxc-r) / (maxc-minc)
|
rc = (maxc-r) / rangec
|
||||||
gc = (maxc-g) / (maxc-minc)
|
gc = (maxc-g) / rangec
|
||||||
bc = (maxc-b) / (maxc-minc)
|
bc = (maxc-b) / rangec
|
||||||
if r == maxc:
|
if r == maxc:
|
||||||
h = bc-gc
|
h = bc-gc
|
||||||
elif g == maxc:
|
elif g == maxc:
|
||||||
|
|
Loading…
Reference in New Issue