j
This commit is contained in:
1 parent
3b09887131
commit
56e7abdad8
11 files changed
+2780
-478
No files matched your search
@@ -0,0 +1,46 @@
|
||||
//! Regenerate the small, valid sample images in `test_images`.
|
||||
use image::{codecs::gif::GifEncoder, Delay, DynamicImage, Frame, Rgba, RgbaImage};
|
||||
use std::{
|
||||
fs::{self, File},
|
||||
path::Path,
|
||||
};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let directory = Path::new("test_images");
|
||||
fs::create_dir_all(directory)?;
|
||||
let image = RgbaImage::from_fn(480, 320, |x, y| {
|
||||
let stripe = ((x / 32) + (y / 32)) % 2 == 0;
|
||||
if stripe {
|
||||
Rgba([57, 107, 155, 255])
|
||||
} else {
|
||||
Rgba([244, 172, 85, 255])
|
||||
}
|
||||
});
|
||||
let rgba = DynamicImage::ImageRgba8(image.clone());
|
||||
rgba.to_rgb8().save(directory.join("test_image_1.jpg"))?;
|
||||
rgba.save(directory.join("test_image_2.png"))?;
|
||||
rgba.save(directory.join("test_image_3.bmp"))?;
|
||||
rgba.save(directory.join("test_image_5.tiff"))?;
|
||||
rgba.save(directory.join("test_image_6.webp"))?;
|
||||
|
||||
let path = directory.join("test_image_4.gif");
|
||||
let mut encoder = GifEncoder::new(File::create(path)?);
|
||||
for (background, foreground) in [
|
||||
([57, 107, 155], [244, 172, 85]),
|
||||
([244, 172, 85], [57, 107, 155]),
|
||||
] {
|
||||
let frame = RgbaImage::from_fn(480, 320, |x, y| {
|
||||
let inside = (x as i32 - 240).pow(2) + (y as i32 - 160).pow(2) < 100 * 100;
|
||||
let color = if inside { foreground } else { background };
|
||||
Rgba([color[0], color[1], color[2], 255])
|
||||
});
|
||||
encoder.encode_frame(Frame::from_parts(
|
||||
frame,
|
||||
0,
|
||||
0,
|
||||
Delay::from_numer_denom_ms(400, 1),
|
||||
))?;
|
||||
}
|
||||
println!("Generated samples in {}", directory.display());
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user