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

Make Palette handle greyscale #3

Open
hbldh opened this issue Nov 28, 2017 · 4 comments
Open

Make Palette handle greyscale #3

hbldh opened this issue Nov 28, 2017 · 4 comments

Comments

@hbldh
Copy link
Owner

hbldh commented Nov 28, 2017

Currently grayscale and BW images does not work very well att all with the palette object. Needs to be implemented.

@vitorio
Copy link

vitorio commented Nov 28, 2017

I noticed this! As a (temporary?) workaround, I'm currently converting my grayscale image to RGB before dithering it.

@hbldh
Copy link
Owner Author

hbldh commented Nov 30, 2017

Ah, of course. That should work; feels somewhat dirty though.
A grayscale palette might be easy to create though, since a grayscale value x maps to RGB tuple (x, x, x) and then handling the ugly conversions behind the scenes...

@llamasoft
Copy link

I was working on a unrelated project. Honestly, I think converting to RGB (or telling the user to do so) is probably the only way to go.
PIL will load images of any "mode" and modes return pixels in different forms. For example:

  • 1 and L return raw 8-bit ints.
  • LA returns a 2-tuple of 8-bit ints.
  • RGB, HSV, LAB, and YCbCr return a 3-tuple of 8-byte ints, but the values all represent something different.
  • RGBA and CMYK returns a 4-tuple of 8-bit ints, again with different meanings.
  • F returns a 32-bit floating point value.

I don't think it's the code's responsibility to handle the conversion for the user, but if the user passes an Image type not in RGB mode or sequences of non-3 length, an exception should probably be raised.

@tatarize
Copy link

if image.mode !=' RGB':
    image.convert('RGB')

It not very harsh with regards to responsibility.

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

No branches or pull requests

4 participants