-
Notifications
You must be signed in to change notification settings - Fork 618
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
Saving RgbaImage as JPEG is incorrect #2173
Comments
I was just writing an issue as well :) For context, we're coming from this Stack Overflow question. Here's a simpler example (not requiring any input). It breaks even when just creating a use image::{Rgb, RgbImage, Rgba, RgbaImage};
fn main() {
let (w, h) = (64, 64);
let img = RgbImage::from_pixel(w, h, Rgb([255, 0, 0]));
img.save("rgb.jpg").unwrap();
let img = RgbaImage::from_pixel(w, h, Rgba([255, 0, 0, 255]));
img.save("rgba.jpg").unwrap();
}
|
JPEG doesn't support storing an alpha channel, so attempting to encode an RGBA image as JPEG should return an error. It is a bug that we silently produce a garbled image instead. (Silently dropping the alpha channel like in I'd suggest using one of the workarounds suggested in the linked stack overflow answer: switch to a different format like PNG which actually supports alpha or manually remove the alpha channel via |
fix rgba8 image jpeg encode bug |
Is there no way to statically prevent such code from compiling? |
This happens in the following code:
Expected
I would've expected this to create roughly the output image as the input.
Actual behaviour
The output is a jumbled mess.
Reproduction steps
Here is the
input.jpg
file tested with:And here is the
output.jpg
result:Just now seeing it also looks different between image viewers: Windows Photos App vs Firefox.
Notes
This can be worked around by either:
0.24.9
, or.into_rgb8()
(no alpha channel), or.png
The text was updated successfully, but these errors were encountered: