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
merged 2 commits into from Sep 6, 2019
Merged

Improved HSV conversion #4004

merged 2 commits into from Sep 6, 2019

Conversation

@radarhere
Copy link
Member

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.

Pillow/src/PIL/Image.py

Lines 1050 to 1056 in f3f45cf

try:
im = self.im.convert(mode, dither)
except ValueError:
try:
# normalize source image and try again
im = self.im.convert(getmodebase(self.mode))
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.

@radarhere radarhere force-pushed the radarhere:hsv branch from 8832636 to 27d6fc7 Aug 11, 2019
@hugovk
hugovk approved these changes Sep 5, 2019
else if (*in >= 255)
out[2] = 255;
else
out[2] = (UINT8) *in;

This comment has been minimized.

Copy link
@hugovk

hugovk Sep 5, 2019

Member

Let's bracket these single-liners for safety.

This comment has been minimized.

Copy link
@radarhere

radarhere Sep 6, 2019

Author Member

Okay, done

@radarhere radarhere force-pushed the radarhere:hsv branch from 8ffe9a5 to 76e5bd0 Sep 6, 2019
@radarhere radarhere merged commit 14859ce into python-pillow:master Sep 6, 2019
16 checks passed
16 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
python-pillow.Pillow Build #20190906.5 succeeded
Details
python-pillow.Pillow (Lint Python37) Lint Python37 succeeded
Details
python-pillow.Pillow (alpine) alpine succeeded
Details
python-pillow.Pillow (amazon_1_amd64) amazon_1_amd64 succeeded
Details
python-pillow.Pillow (amazon_2_amd64) amazon_2_amd64 succeeded
Details
python-pillow.Pillow (arch) arch succeeded
Details
python-pillow.Pillow (centos_6_amd64) centos_6_amd64 succeeded
Details
python-pillow.Pillow (centos_7_amd64) centos_7_amd64 succeeded
Details
python-pillow.Pillow (debian_10_buster_x86) debian_10_buster_x86 succeeded
Details
python-pillow.Pillow (debian_9_stretch_x86) debian_9_stretch_x86 succeeded
Details
python-pillow.Pillow (fedora_29_amd64) fedora_29_amd64 succeeded
Details
python-pillow.Pillow (fedora_30_amd64) fedora_30_amd64 succeeded
Details
python-pillow.Pillow (ubuntu_16_04_xenial_amd64) ubuntu_16_04_xenial_amd64 succeeded
Details
python-pillow.Pillow (ubuntu_18_04_bionic_amd64) ubuntu_18_04_bionic_amd64 succeeded
Details
@radarhere radarhere deleted the radarhere:hsv branch Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants
You can’t perform that action at this time.