Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions apps/desktop-gpui/kernels/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,8 @@ pub fn encode_jpeg_rgba_as_rgb(
rgba: &image::RgbaImage,
quality: u8,
) -> image::ImageResult<Vec<u8>> {
use image::buffer::ConvertBuffer as _;
let rgb: image::RgbImage = rgba.convert();
let mut encoded = Vec::new();
image::codecs::jpeg::JpegEncoder::new_with_quality(&mut encoded, quality).encode_image(&rgb)?;
Ok(encoded)
let rgb = rgba_to_rgb(rgba.as_raw());
encode_jpeg_rgb(&rgb, rgba.width(), rgba.height(), quality)
Comment on lines +102 to +103

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 JPEG test compares identical paths

Routing encode_jpeg_rgba_as_rgb through encode_jpeg_rgb makes jpeg_paths_agree_on_the_same_pixels compare the same conversion and encoder calls with themselves. It no longer checks that this replacement preserves the old JPEG output. Keep an independent reference in the test using ConvertBuffer and encode_image, then compare it with the new path.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop-gpui/kernels/src/codec.rs
Line: 127-128

Comment:
**JPEG test compares identical paths**

Routing `encode_jpeg_rgba_as_rgb` through `encode_jpeg_rgb` makes `jpeg_paths_agree_on_the_same_pixels` compare the same conversion and encoder calls with themselves. It no longer checks that this replacement preserves the old JPEG output. Keep an independent reference in the test using `ConvertBuffer` and `encode_image`, then compare it with the new path.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

}

pub fn save_rgb_image(
Expand Down Expand Up @@ -339,9 +336,18 @@ mod tests {
let rgba = image::RgbaImage::from_fn(9, 7, |x, y| {
image::Rgba([(x * 20) as u8, (y * 30) as u8, 90, 128])
});
let from_slice = encode_jpeg_rgb(&rgba_to_rgb(rgba.as_raw()), 9, 7, 80).unwrap();
use image::buffer::ConvertBuffer as _;

let legacy_rgb: image::RgbImage = rgba.convert();
let mut legacy = Vec::new();
image::codecs::jpeg::JpegEncoder::new_with_quality(&mut legacy, 80)
.encode_image(&legacy_rgb)
.unwrap();

let from_image = encode_jpeg_rgba_as_rgb(&rgba, 80).unwrap();
assert_eq!(from_slice, from_image);
assert_eq!(from_image, legacy);
let from_slice = encode_jpeg_rgb(&rgba_to_rgb(rgba.as_raw()), 9, 7, 80).unwrap();
assert_eq!(from_slice, legacy);
let bgra = decode_jpeg_to_bgra(&from_slice).unwrap();
assert_eq!(bgra.dimensions(), (9, 7));
}
Expand Down
Loading