mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Cache the test pet spritesheet encoding (#39028)
## Why Pet tests reuse the same blank WebP spritesheet fixture, so encoding a new image for every temporary path does unnecessary repeated work. ## What changed Encode the test spritesheet once with `LazyLock`, then write the cached WebP bytes to each requested fixture path. GitOrigin-RevId: 26d75bb1bac448717ca63aeb82eb4e500c86fad8
This commit is contained in:
1 parent
171ae66d74
commit
10fbb61838
1 file changed
+16
-2
@@ -1,5 +1,12 @@
|
|||||||
//! Built-in pet catalog ported from the Codex App avatar catalog.
|
//! Built-in pet catalog ported from the Codex App avatar catalog.
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
use std::fs;
|
||||||
|
#[cfg(test)]
|
||||||
|
use std::io::Cursor;
|
||||||
|
#[cfg(test)]
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
pub(super) const DEFAULT_FRAME_WIDTH: u32 = 192;
|
pub(super) const DEFAULT_FRAME_WIDTH: u32 = 192;
|
||||||
pub(super) const DEFAULT_FRAME_HEIGHT: u32 = 208;
|
pub(super) const DEFAULT_FRAME_HEIGHT: u32 = 208;
|
||||||
pub(super) const DEFAULT_FRAME_COLUMNS: u32 = 8;
|
pub(super) const DEFAULT_FRAME_COLUMNS: u32 = 8;
|
||||||
@@ -72,6 +79,13 @@ pub(super) fn builtin_pet(id: &str) -> Option<BuiltinPet> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(super) fn write_test_spritesheet(path: &std::path::Path) {
|
pub(super) fn write_test_spritesheet(path: &std::path::Path) {
|
||||||
let image = image::RgbaImage::new(SPRITESHEET_WIDTH, SPRITESHEET_HEIGHT);
|
static TEST_SPRITESHEET: LazyLock<Vec<u8>> = LazyLock::new(|| {
|
||||||
image.save(path).unwrap();
|
let image = image::RgbaImage::new(SPRITESHEET_WIDTH, SPRITESHEET_HEIGHT);
|
||||||
|
let mut bytes = Vec::new();
|
||||||
|
image::DynamicImage::ImageRgba8(image)
|
||||||
|
.write_to(&mut Cursor::new(&mut bytes), image::ImageFormat::WebP)
|
||||||
|
.unwrap();
|
||||||
|
bytes
|
||||||
|
});
|
||||||
|
fs::write(path, TEST_SPRITESHEET.as_slice()).unwrap();
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user