diff --git a/Lib/colorsys.py b/Lib/colorsys.py index e97f91718a3a30..677ba741ab790e 100644 --- a/Lib/colorsys.py +++ b/Lib/colorsys.py @@ -130,15 +130,12 @@ def rgb_to_hsv(r, g, b): if minc == maxc: return 0.0, 0.0, v s = rangec / maxc - rc = (maxc-r) / rangec - gc = (maxc-g) / rangec - bc = (maxc-b) / rangec if r == maxc: - h = bc-gc + h = (g-b) / rangec elif g == maxc: - h = 2.0+rc-bc + h = 2.0 + (b-r) / rangec else: - h = 4.0+gc-rc + h = 4.0 + (r-g) / rangec h = (h/6.0) % 1.0 return h, s, v diff --git a/Misc/NEWS.d/next/Library/2024-10-02-16-47-45.gh-issue-124879.9m2Wmx.rst b/Misc/NEWS.d/next/Library/2024-10-02-16-47-45.gh-issue-124879.9m2Wmx.rst new file mode 100644 index 00000000000000..fa679ba0c6f198 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-10-02-16-47-45.gh-issue-124879.9m2Wmx.rst @@ -0,0 +1 @@ +Optimized :func:`colorsys.rgb_to_hsv` to reduce the number of operations.