Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved HSV conversion #4004

merged 2 commits into from Sep 6, 2019

Improved HSV conversion #4004

merged 2 commits into from Sep 6, 2019


Copy link

@radarhere radarhere commented Aug 2, 2019

Resolves #3997

The issue reports that you can't convert from P to HSV, whereas this previously worked.

If a direct conversion from a mode to another is not possible, then Pillow attempts to convert the image to its base mode first, and then convert from that intermediate image.


Lines 1050 to 1056 in f3f45cf

im =, dither)
except ValueError:
# normalize source image and try again
im =
im = im.convert(mode, dither)

PR #3726 changed the base mode of P from RGB to P. So while Pillow previously worked around the absence of a direct method for converting from P to HSV, it now throws an error.

This PR fixes that by assigning direct methods for conversion from P to HSV, as well as 1 to HSV, L to HSV, LA to HSV, I to HSV, RGBA to HSV, RGBX to HSV and CMYK to HSV.

hugovk approved these changes Sep 5, 2019
else if (*in >= 255)
out[2] = 255;
out[2] = (UINT8) *in;
Copy link

@hugovk hugovk Sep 5, 2019

Let's bracket these single-liners for safety.

Copy link
Member Author

@radarhere radarhere Sep 6, 2019

Okay, done

@radarhere radarhere merged commit 14859ce into python-pillow:master Sep 6, 2019
16 checks passed
@radarhere radarhere deleted the hsv branch Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants