python-pillow / Pillow

Python Imaging Library (Fork)
https://python-pillow.org
Other
11.8k stars 2.13k forks source link

Add packers for RGB;15/16 and BGR;15/16 #8019

Closed Yay295 closed 1 month ago

Yay295 commented 1 month ago

I made these to be the opposite of the unpackers for these rawmodes, but this conversion method isn't actually roundtrippable. I know of two other methods that are roundtrippable, but I would have to change the unpackers as well for that.

radarhere commented 1 month ago

What is the motivation behind this? Are these packers something that you plan on using in your own external code that uses Pillow?

Yay295 commented 1 month ago

It's currently possible to create or convert an image to BGR;15/16 and save it as that mode because there's a copy packer for those modes, but when those modes are removed that will no longer be possible. By adding these packers it will still be possible to save data in these formats.

I added the RGB versions because it's basically the same code with just two variables swapped.

radarhere commented 1 month ago

So to demonstrate in code, your plan is for any user currently running

from PIL import Image
im = Image.new("RGB", (1, 1))
im.convert("BGR;15").tobytes()

to instead transition to running

from PIL import Image
im = Image.new("RGB", (1, 1))
im.tobytes("raw", "BGR;15")

Others should feel free to chime in with their thoughts, but I would think that the modes are being deprecated because they aren't used by any image format, and since we added our very rudimentary support for these modes, there's never been an issue from anyone using them. Because they're not used, we don't need to try and offer a workaround for this functionality when it is removed.

If you're aware of a portion of users that are using BGR;15 and BGR;16 in this way, feel free to say so.

radarhere commented 1 month ago

If you've moved on and are coming up with a different plan, can this be closed?