mirror of
https://github.com/openai/codex.git
synced 2026-12-03 00:41:03 +00:00
## Why Composer thumbnails and transcript tool previews read and decoded files during rendering. A JPEG whose decoded pixels exceeded the 32 MiB allocation budget could lose its preview even when the encoded file fit within the file size limit. ## What changed - Load visible composer thumbnails and transcript previews on background workers and request a redraw when the result is ready. Reuse prepared tool previews when the viewport changes size. - Share the sidebar's scaled JPEG fallback with composer and transcript previews. Preserve the oriented source aspect ratio and enforce the encoded file size limit separately from the decode budget. - Check that the owning thread has a local workspace before reading an inspected image. Generated artifacts can still load from the daemon host. ## Testing Cover large JPEG previews in the composer and transcript, thumbnail refresh after an attachment is replaced, text fallback for oversized PNGs, and an inspected path shared by local and remote workspaces. GitOrigin-RevId: f2c8948a9abaa2527932423224b6ebeda3e122ae
55 lines
1.7 KiB
Rust
55 lines
1.7 KiB
Rust
#![cfg(test)]
|
|
//! Pixel-level checks for fitting previews into terminal cells.
|
|
|
|
use super::*;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[test]
|
|
fn padding_keeps_fitted_pixels_at_their_original_scale() {
|
|
let pixel = |x, y| image::Rgba([x as u8, y as u8, 42, 255]);
|
|
let toolbar = RgbaImage::from_fn(/*width*/ 299, /*height*/ 37, pixel);
|
|
let expected = RgbaImage::from_fn(/*width*/ 300, /*height*/ 52, |x, y| {
|
|
*toolbar
|
|
.get_pixel_checked(x, y)
|
|
.unwrap_or(&image::Rgba([0; 4]))
|
|
});
|
|
assert_eq!(
|
|
pad_to_cells(toolbar, /*cell_width*/ 12, /*cell_height*/ 26),
|
|
expected
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn sixel_output_fits_wide_images_within_the_original_encoding_budget() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let path = dir.path().join("image.png");
|
|
let load = |columns| {
|
|
PreparedImage::load_for_cells(
|
|
&local::ImageFile::at(&path).unwrap(),
|
|
columns,
|
|
ImageProtocol::Sixel,
|
|
PreviewKind::Generated,
|
|
/*cell_size*/ Some((10, 20)),
|
|
)
|
|
.unwrap()
|
|
.image
|
|
};
|
|
let source = RgbaImage::from_fn(
|
|
/*width*/ 300,
|
|
/*height*/ 37,
|
|
|x, y| image::Rgba([x as u8, y as u8, 42, 255]),
|
|
);
|
|
source.save(&path).unwrap();
|
|
let image = load(30);
|
|
assert_eq!((image.columns, image.rows), (30, 2));
|
|
assert_eq!(image.pixels, source);
|
|
assert_eq!(load(20).pixels.dimensions(), (200, 25));
|
|
|
|
for (width, height) in [(600, 74), (900, 42), (720, 320)] {
|
|
RgbaImage::new(width, height).save(&path).unwrap();
|
|
let (w, h) = load(48).pixels.dimensions();
|
|
assert!(w * h <= 160 * 80);
|
|
assert!(w * h.div_ceil(6) <= 160 * 14);
|
|
}
|
|
}
|