-
Notifications
You must be signed in to change notification settings - Fork 630
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
Encoder/Decoder supported ColorType
s for ImageFormat
#2210
Comments
Most of these color type restrictions are actually caused by limitations of the underlying image format. PNGs cannot store floating point data, WebP cannot hold 16-bit per sample images, JPEG cannot represent alpha, etc. Our encoders aren't going to add support for any of those in a future version. If they tried to include any of that data, other libraries would rightfully consider the resulting files to be corrupt! JPEG's inability to store alpha has unfortunately drawn a bunch of attention lately because we switched from silently dropping the alpha channel to returning an error instead (with a short span in between where trying to encode a RGBA jpeg would produce a corrupt image That said, I do like the idea of programmatically exposing the list of supported color types for each encoder and the For decoders, I don't think supported color types makes as much sense. Some of our decoders don't support all image format features (meaning there are some images they cannot decode) but that often doesn't align with specific color types |
Ok I will have a look at how best to implement this when I get a chance. As for |
Not quite. The idea is that end-users might get any possible |
Working on a piece of code that converts images from one format to another while applying some other options provided by
DynamicImage
. Just realized (the hard way) that if I try to blindly convert an Rgba8 png to jpg the Jpeg encoder would scream at me for a wrong ColorType.To prevent the encoder from screaming at me I did something like:
Before trying to save the image. This is pretty verbose, error-prone and most likely subject to changes.
It would be super nice to have 1-2 methods in
ImageFormat
to get a list of supportedColorType
s and perhaps a default (fallback)ColorType
.Then, maybe if
DynamicImage
offers ato_color(color: ColorType)
I could condense that verbose check into 2-3 lines of code and let theimage
crate dictate whenColorType
support for different encoders/decoders change.I could implement the above to contribute, if deemed appropriate.
The text was updated successfully, but these errors were encountered: