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):
|
||||
maxc = max(r, g, b)
|
||||
minc = min(r, g, b)
|
||||
rangec = (maxc-minc)
|
||||
v = maxc
|
||||
if minc == maxc:
|
||||
return 0.0, 0.0, v
|
||||
s = (maxc-minc) / maxc
|
||||
rc = (maxc-r) / (maxc-minc)
|
||||
gc = (maxc-g) / (maxc-minc)
|
||||
bc = (maxc-b) / (maxc-minc)
|
||||
s = rangec / maxc
|
||||
rc = (maxc-r) / rangec
|
||||
gc = (maxc-g) / rangec
|
||||
bc = (maxc-b) / rangec
|
||||
if r == maxc:
|
||||
h = bc-gc
|
||||
elif g == maxc:
|
||||
|
|
Loading…
Reference in New Issue