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

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.

else if (*in >= 255)
out[2] = 255;
else
out[2] = (UINT8) *in;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's bracket these single-liners for safety.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Converting P mode images to HSV fails with "ValueError: conversion not supported" in version 6.0.0 and later
2 participants