update all explicit Path instance allocation and use
previously, there were a ton of places that were allocating new Path instances via `Path::new` for the purpose of creating a path to be passed into a function as a Path argument this has now been simplified everywhere by updating all functions and methods that previously took Path arguments to instead take AsRef<Path> arguments, allowing much more flexibility in the types of path arguments passed in
This commit is contained in:
parent
a18aee300d
commit
4d359f3e3c
|
@ -11,15 +11,15 @@ struct AudioChannelStatus {
|
|||
playing: bool,
|
||||
}
|
||||
|
||||
fn load_and_convert_wav(path: &Path, target_spec: &AudioSpec) -> Result<AudioBuffer> {
|
||||
let sound = AudioBuffer::load_wav_file(path)?;
|
||||
fn load_and_convert_wav(path: impl AsRef<Path>, target_spec: &AudioSpec) -> Result<AudioBuffer> {
|
||||
let sound = AudioBuffer::load_wav_file(&path)?;
|
||||
let original_spec = *sound.spec();
|
||||
let sound = sound.convert(target_spec)?;
|
||||
let final_spec = *sound.spec();
|
||||
if original_spec != final_spec {
|
||||
println!("{:?} was converted from {:?} to {:?}", path, original_spec, final_spec);
|
||||
println!("{:?} was converted from {:?} to {:?}", path.as_ref(), original_spec, final_spec);
|
||||
} else {
|
||||
println!("{:?} did not need to be converted from {:?}", path, original_spec);
|
||||
println!("{:?} did not need to be converted from {:?}", path.as_ref(), original_spec);
|
||||
}
|
||||
Ok(sound)
|
||||
}
|
||||
|
@ -58,11 +58,11 @@ fn main() -> Result<()> {
|
|||
let mut volume = 1.0;
|
||||
|
||||
let sounds = [
|
||||
load_and_convert_wav(system.app_root_dir.join("./assets/pickup-coin.wav").as_path(), system.res.audio.spec())?,
|
||||
load_and_convert_wav(system.app_root_dir.join("./assets/powerup.wav").as_path(), system.res.audio.spec())?,
|
||||
load_and_convert_wav(system.app_root_dir.join("./assets/explosion.wav").as_path(), system.res.audio.spec())?,
|
||||
load_and_convert_wav(system.app_root_dir.join("./assets/jump.wav").as_path(), system.res.audio.spec())?,
|
||||
load_and_convert_wav(system.app_root_dir.join("./assets/laser-shoot.wav").as_path(), system.res.audio.spec())?,
|
||||
load_and_convert_wav(system.app_root_dir.join("./assets/pickup-coin.wav"), system.res.audio.spec())?,
|
||||
load_and_convert_wav(system.app_root_dir.join("./assets/powerup.wav"), system.res.audio.spec())?,
|
||||
load_and_convert_wav(system.app_root_dir.join("./assets/explosion.wav"), system.res.audio.spec())?,
|
||||
load_and_convert_wav(system.app_root_dir.join("./assets/jump.wav"), system.res.audio.spec())?,
|
||||
load_and_convert_wav(system.app_root_dir.join("./assets/laser-shoot.wav"), system.res.audio.spec())?,
|
||||
];
|
||||
|
||||
let mut statuses = [AudioChannelStatus { size: 0, position: 0, playing: false }; NUM_CHANNELS];
|
||||
|
|
|
@ -24,8 +24,7 @@ fn main() -> Result<()> {
|
|||
|
||||
let font = BitmaskFont::new_vga_font()?;
|
||||
|
||||
let (balls_bmp, balls_palette) =
|
||||
IndexedBitmap::load_pcx_file(system.app_root_dir.join("./assets/balls.pcx").as_path())?;
|
||||
let (balls_bmp, balls_palette) = IndexedBitmap::load_pcx_file(system.app_root_dir.join("./assets/balls.pcx"))?;
|
||||
system.res.palette = balls_palette.clone();
|
||||
|
||||
let mut sprites = Vec::<IndexedBitmap>::new();
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use std::path::Path;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use ggdt::prelude::*;
|
||||
|
|
|
@ -25,8 +25,7 @@ impl Game {
|
|||
pub fn new(mut system: System<DosLike>) -> Result<Self> {
|
||||
let font = BitmaskFont::new_vga_font()?;
|
||||
|
||||
let (balls_bmp, balls_palette) =
|
||||
IndexedBitmap::load_pcx_file(system.app_root_dir.join("./assets/balls.pcx").as_path())?;
|
||||
let (balls_bmp, balls_palette) = IndexedBitmap::load_pcx_file(system.app_root_dir.join("./assets/balls.pcx"))?;
|
||||
system.res.palette = balls_palette.clone();
|
||||
|
||||
let mut sprites = Vec::new();
|
||||
|
|
|
@ -90,20 +90,17 @@ impl AppContext<Standard> for GameContext {
|
|||
|
||||
impl GameContext {
|
||||
pub fn new(system: System<Standard>) -> Result<Self> {
|
||||
let palette = load_palette(system.app_root_dir.join("./assets/db16.pal").as_path())?;
|
||||
let palette = load_palette(system.app_root_dir.join("./assets/db16.pal"))?;
|
||||
|
||||
let font = load_font(system.app_root_dir.join("./assets/dp.fnt").as_path())?;
|
||||
let small_font = load_font(system.app_root_dir.join("./assets/small.fnt").as_path())?;
|
||||
let font = load_font(system.app_root_dir.join("./assets/dp.fnt"))?;
|
||||
let small_font = load_font(system.app_root_dir.join("./assets/small.fnt"))?;
|
||||
|
||||
let tiles = Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/tiles.pcx").as_path())?);
|
||||
let green_slime =
|
||||
Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/green_slime.pcx").as_path())?);
|
||||
let blue_slime =
|
||||
Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/blue_slime.pcx").as_path())?);
|
||||
let orange_slime =
|
||||
Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/orange_slime.pcx").as_path())?);
|
||||
let tiles = Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/tiles.pcx"))?);
|
||||
let green_slime = Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/green_slime.pcx"))?);
|
||||
let blue_slime = Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/blue_slime.pcx"))?);
|
||||
let orange_slime = Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/orange_slime.pcx"))?);
|
||||
|
||||
let tilemap = TileMap::load_from(system.app_root_dir.join("./assets/arena.map.json").as_path())?;
|
||||
let tilemap = TileMap::load_from(system.app_root_dir.join("./assets/arena.map.json"))?;
|
||||
|
||||
let entities = Entities::new();
|
||||
let component_systems = ComponentSystems::new();
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
use std::path::Path;
|
||||
|
||||
use crate::tilemap::{TILE_HEIGHT, TILE_WIDTH};
|
||||
use anyhow::{Context, Result};
|
||||
use ggdt::prelude::*;
|
||||
|
||||
pub fn load_palette(path: &std::path::Path) -> Result<Palette> {
|
||||
Palette::load_from_file(path, PaletteFormat::Vga).context(format!("Loading palette: {:?}", path))
|
||||
pub fn load_palette(path: impl AsRef<Path>) -> Result<Palette> {
|
||||
Palette::load_from_file(&path, PaletteFormat::Vga).context(format!("Loading palette: {:?}", path.as_ref()))
|
||||
}
|
||||
|
||||
pub fn load_font(path: &std::path::Path) -> Result<BitmaskFont> {
|
||||
BitmaskFont::load_from_file(path).context(format!("Loading font: {:?}", path))
|
||||
pub fn load_font(path: impl AsRef<Path>) -> Result<BitmaskFont> {
|
||||
BitmaskFont::load_from_file(&path).context(format!("Loading font: {:?}", path.as_ref()))
|
||||
}
|
||||
|
||||
pub fn load_bitmap_atlas_autogrid(path: &std::path::Path) -> Result<BitmapAtlas<RgbaBitmap>> {
|
||||
let (bmp, _) = RgbaBitmap::load_file(path).context(format!("Loading bitmap atlas: {:?}", path))?;
|
||||
pub fn load_bitmap_atlas_autogrid(path: impl AsRef<Path>) -> Result<BitmapAtlas<RgbaBitmap>> {
|
||||
let (bmp, _) = RgbaBitmap::load_file(&path).context(format!("Loading bitmap atlas: {:?}", path.as_ref()))?;
|
||||
let mut atlas = BitmapAtlas::new(bmp);
|
||||
atlas.add_grid(TILE_WIDTH, TILE_HEIGHT)?;
|
||||
Ok(atlas)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::path::Path;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use ggdt::prelude::*;
|
||||
|
||||
|
@ -16,10 +18,10 @@ pub struct TileMap {
|
|||
}
|
||||
|
||||
impl TileMap {
|
||||
pub fn load_from(path: &std::path::Path) -> Result<Self> {
|
||||
let f = std::fs::File::open(path)?;
|
||||
pub fn load_from(path: impl AsRef<Path>) -> Result<Self> {
|
||||
let f = std::fs::File::open(&path)?;
|
||||
let reader = std::io::BufReader::new(f);
|
||||
serde_json::from_reader(reader).context(format!("Loading json tilemap: {:?}", path))
|
||||
serde_json::from_reader(reader).context(format!("Loading json tilemap: {:?}", path.as_ref()))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -381,7 +381,7 @@ pub struct Pickuper;
|
|||
|
||||
pub fn init_everything(
|
||||
context: &mut Game,
|
||||
map_file: &Path,
|
||||
map_file: impl AsRef<Path>,
|
||||
min_spawn_time: f32,
|
||||
max_spawn_time: f32,
|
||||
max_slimes: usize,
|
||||
|
|
|
@ -107,36 +107,30 @@ impl AppContext<DosLike> for Game {
|
|||
|
||||
impl Game {
|
||||
pub fn new(mut system: System<DosLike>) -> Result<Self> {
|
||||
let palette = load_palette(system.app_root_dir.join("./assets/db16.pal").as_path())?;
|
||||
let palette = load_palette(system.app_root_dir.join("./assets/db16.pal"))?;
|
||||
system.res.palette = palette.clone();
|
||||
|
||||
let font = load_font(system.app_root_dir.join("./assets/dp.fnt").as_path())?;
|
||||
let font = load_font(system.app_root_dir.join("./assets/dp.fnt"))?;
|
||||
|
||||
let tiles = Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/tiles.pcx").as_path())?);
|
||||
let hero_male =
|
||||
Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/hero_male.pcx").as_path())?);
|
||||
let hero_female =
|
||||
Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/hero_female.pcx").as_path())?);
|
||||
let green_slime =
|
||||
Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/green_slime.pcx").as_path())?);
|
||||
let blue_slime =
|
||||
Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/blue_slime.pcx").as_path())?);
|
||||
let orange_slime =
|
||||
Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/orange_slime.pcx").as_path())?);
|
||||
let fist = Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/fist.pcx").as_path())?);
|
||||
let sword = Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/sword.pcx").as_path())?);
|
||||
let particles =
|
||||
Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/particles.pcx").as_path())?);
|
||||
let items = Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/items.pcx").as_path())?);
|
||||
let tiles = Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/tiles.pcx"))?);
|
||||
let hero_male = Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/hero_male.pcx"))?);
|
||||
let hero_female = Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/hero_female.pcx"))?);
|
||||
let green_slime = Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/green_slime.pcx"))?);
|
||||
let blue_slime = Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/blue_slime.pcx"))?);
|
||||
let orange_slime = Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/orange_slime.pcx"))?);
|
||||
let fist = Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/fist.pcx"))?);
|
||||
let sword = Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/sword.pcx"))?);
|
||||
let particles = Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/particles.pcx"))?);
|
||||
let items = Rc::new(load_bitmap_atlas_autogrid(system.app_root_dir.join("./assets/items.pcx"))?);
|
||||
|
||||
let mut ui = load_bitmap_atlas(system.app_root_dir.join("./assets/ui.pcx").as_path())?;
|
||||
let mut ui = load_bitmap_atlas(system.app_root_dir.join("./assets/ui.pcx"))?;
|
||||
ui.add(Rect::new(0, 0, 16, 16))?;
|
||||
ui.add(Rect::new(16, 0, 16, 16))?;
|
||||
for i in 0..8 {
|
||||
ui.add(Rect::new(i * 8, 16, 8, 8))?;
|
||||
}
|
||||
|
||||
let tilemap = TileMap::load_from(system.app_root_dir.join("./assets/title_screen.map.json").as_path())?;
|
||||
let tilemap = TileMap::load_from(system.app_root_dir.join("./assets/title_screen.map.json"))?;
|
||||
|
||||
let entities = Entities::new();
|
||||
let component_systems = ComponentSystems::new();
|
||||
|
|
|
@ -88,7 +88,7 @@ impl AppState<Game> for MainMenuState {
|
|||
State::Pending | State::Resume => {
|
||||
init_everything(
|
||||
context,
|
||||
context.core.system.app_root_dir.join("./assets/title_screen.map.json").as_path(),
|
||||
context.core.system.app_root_dir.join("./assets/title_screen.map.json"),
|
||||
0.2,
|
||||
1.0,
|
||||
32,
|
||||
|
@ -225,7 +225,7 @@ impl AppState<Game> for GamePlayState {
|
|||
State::Pending => {
|
||||
init_everything(
|
||||
context,
|
||||
context.core.system.app_root_dir.join("./assets/arena.map.json").as_path(),
|
||||
context.core.system.app_root_dir.join("./assets/arena.map.json"),
|
||||
0.5,
|
||||
2.0,
|
||||
100,
|
||||
|
|
|
@ -6,23 +6,23 @@ use ggdt::prelude::*;
|
|||
|
||||
use crate::{Game, TILE_HEIGHT, TILE_WIDTH};
|
||||
|
||||
pub fn load_palette(path: &Path) -> Result<Palette> {
|
||||
Palette::load_from_file(path, PaletteFormat::Vga).context(format!("Loading palette: {:?}", path))
|
||||
pub fn load_palette(path: impl AsRef<Path>) -> Result<Palette> {
|
||||
Palette::load_from_file(&path, PaletteFormat::Vga).context(format!("Loading palette: {:?}", path.as_ref()))
|
||||
}
|
||||
|
||||
pub fn load_font(path: &Path) -> Result<BitmaskFont> {
|
||||
BitmaskFont::load_from_file(path).context(format!("Loading font: {:?}", path))
|
||||
pub fn load_font(path: impl AsRef<Path>) -> Result<BitmaskFont> {
|
||||
BitmaskFont::load_from_file(&path).context(format!("Loading font: {:?}", path.as_ref()))
|
||||
}
|
||||
|
||||
pub fn load_bitmap_atlas_autogrid(path: &Path) -> Result<BitmapAtlas<IndexedBitmap>> {
|
||||
let (bmp, _) = IndexedBitmap::load_file(path).context(format!("Loading bitmap atlas: {:?}", path))?;
|
||||
pub fn load_bitmap_atlas_autogrid(path: impl AsRef<Path>) -> Result<BitmapAtlas<IndexedBitmap>> {
|
||||
let (bmp, _) = IndexedBitmap::load_file(&path).context(format!("Loading bitmap atlas: {:?}", path.as_ref()))?;
|
||||
let mut atlas = BitmapAtlas::new(bmp);
|
||||
atlas.add_grid(TILE_WIDTH, TILE_HEIGHT)?;
|
||||
Ok(atlas)
|
||||
}
|
||||
|
||||
pub fn load_bitmap_atlas(path: &Path) -> Result<BitmapAtlas<IndexedBitmap>> {
|
||||
let (bmp, _) = IndexedBitmap::load_file(path).context(format!("Loading bitmap atlas: {:?}", path))?;
|
||||
pub fn load_bitmap_atlas(path: impl AsRef<Path>) -> Result<BitmapAtlas<IndexedBitmap>> {
|
||||
let (bmp, _) = IndexedBitmap::load_file(&path).context(format!("Loading bitmap atlas: {:?}", path.as_ref()))?;
|
||||
let atlas = BitmapAtlas::new(bmp);
|
||||
Ok(atlas)
|
||||
}
|
||||
|
|
|
@ -21,10 +21,10 @@ pub struct TileMap {
|
|||
}
|
||||
|
||||
impl TileMap {
|
||||
pub fn load_from(path: &Path) -> Result<Self> {
|
||||
let f = File::open(path)?;
|
||||
pub fn load_from(path: impl AsRef<Path>) -> Result<Self> {
|
||||
let f = File::open(&path)?;
|
||||
let reader = BufReader::new(f);
|
||||
serde_json::from_reader(reader).context(format!("Loading json tilemap: {:?}", path))
|
||||
serde_json::from_reader(reader).context(format!("Loading json tilemap: {:?}", path.as_ref()))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
use std::path::Path;
|
||||
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
|
||||
use ggdt::prelude::*;
|
||||
|
||||
pub fn criterion_benchmark(c: &mut Criterion) {
|
||||
let mut framebuffer = IndexedBitmap::new(320, 240).unwrap();
|
||||
let (bmp, _) = IndexedBitmap::load_iff_file(Path::new("./test-assets/test-tiles.lbm")).unwrap();
|
||||
let (bmp, _) = IndexedBitmap::load_iff_file("./test-assets/test-tiles.lbm").unwrap();
|
||||
|
||||
let mut solid_bmp = IndexedBitmap::new(16, 16).unwrap();
|
||||
solid_bmp.blit_region(IndexedBlitMethod::Solid, &bmp, &Rect::new(16, 16, 16, 16), 0, 0);
|
||||
|
|
|
@ -7,7 +7,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
|||
let height = 240;
|
||||
|
||||
let mut dest = RgbaBitmap::new(width, height).unwrap();
|
||||
let (texture, _) = RgbaBitmap::load_gif_file(std::path::Path::new("./test-assets/gif/small.gif")).unwrap();
|
||||
let (texture, _) = RgbaBitmap::load_gif_file("./test-assets/gif/small.gif").unwrap();
|
||||
|
||||
let big_v1 = Vector2::new(47.0, 23.0);
|
||||
let big_v2 = Vector2::new(60.0, 192.0);
|
||||
|
|
|
@ -270,7 +270,7 @@ impl AudioBuffer {
|
|||
|
||||
/// Loads a WAV file into an [`AudioBuffer`]. The returned buffer will be in its original
|
||||
/// format and may need to be converted before it can be played.
|
||||
pub fn load_wav_file(path: &Path) -> Result<AudioBuffer, WavError> {
|
||||
pub fn load_wav_file(path: impl AsRef<Path>) -> Result<AudioBuffer, WavError> {
|
||||
let f = File::open(path)?;
|
||||
let mut reader = BufReader::new(f);
|
||||
Self::load_wav_bytes(&mut reader)
|
||||
|
@ -287,31 +287,31 @@ mod tests {
|
|||
|
||||
const BASE_PATH: &str = "./test-assets/wav/";
|
||||
|
||||
fn test_file(file: &Path) -> PathBuf {
|
||||
fn test_file(file: impl AsRef<Path>) -> PathBuf {
|
||||
PathBuf::from(BASE_PATH).join(file)
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn load_wav_file() -> Result<(), WavError> {
|
||||
let wav_buffer = AudioBuffer::load_wav_file(test_file(Path::new("22khz_8bit_1ch.wav")).as_path())?;
|
||||
let wav_buffer = AudioBuffer::load_wav_file(test_file("22khz_8bit_1ch.wav").as_path())?;
|
||||
assert_eq!(AUDIO_FREQUENCY_22KHZ, wav_buffer.spec().frequency());
|
||||
assert_eq!(1, wav_buffer.spec().channels());
|
||||
assert_eq!(AudioFormat::U8, wav_buffer.spec.format);
|
||||
assert_eq!(11248, wav_buffer.data.len());
|
||||
|
||||
let wav_buffer = AudioBuffer::load_wav_file(test_file(Path::new("44khz_8bit_1ch.wav")).as_path())?;
|
||||
let wav_buffer = AudioBuffer::load_wav_file(test_file("44khz_8bit_1ch.wav").as_path())?;
|
||||
assert_eq!(AUDIO_FREQUENCY_44KHZ, wav_buffer.spec().frequency());
|
||||
assert_eq!(1, wav_buffer.spec().channels());
|
||||
assert_eq!(AudioFormat::U8, wav_buffer.spec.format);
|
||||
assert_eq!(22496, wav_buffer.data.len());
|
||||
|
||||
let wav_buffer = AudioBuffer::load_wav_file(test_file(Path::new("22khz_16bit_1ch.wav")).as_path())?;
|
||||
let wav_buffer = AudioBuffer::load_wav_file(test_file("22khz_16bit_1ch.wav").as_path())?;
|
||||
assert_eq!(AUDIO_FREQUENCY_22KHZ, wav_buffer.spec().frequency());
|
||||
assert_eq!(1, wav_buffer.spec().channels());
|
||||
assert_eq!(AudioFormat::S16LSB, wav_buffer.spec.format);
|
||||
assert_eq!(22496, wav_buffer.data.len());
|
||||
|
||||
let wav_buffer = AudioBuffer::load_wav_file(test_file(Path::new("44khz_16bit_1ch.wav")).as_path())?;
|
||||
let wav_buffer = AudioBuffer::load_wav_file(test_file("44khz_16bit_1ch.wav").as_path())?;
|
||||
assert_eq!(AUDIO_FREQUENCY_44KHZ, wav_buffer.spec().frequency());
|
||||
assert_eq!(1, wav_buffer.spec().channels());
|
||||
assert_eq!(AudioFormat::S16LSB, wav_buffer.spec.format);
|
||||
|
|
|
@ -468,7 +468,7 @@ impl IndexedBitmap {
|
|||
Ok((bitmap.unwrap(), palette.unwrap()))
|
||||
}
|
||||
|
||||
pub fn load_gif_file(path: &Path) -> Result<(IndexedBitmap, Palette), GifError> {
|
||||
pub fn load_gif_file(path: impl AsRef<Path>) -> Result<(IndexedBitmap, Palette), GifError> {
|
||||
let f = File::open(path)?;
|
||||
let mut reader = BufReader::new(f);
|
||||
Self::load_gif_bytes(&mut reader)
|
||||
|
@ -520,7 +520,12 @@ impl IndexedBitmap {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn to_gif_file(&self, path: &Path, palette: &Palette, settings: GifSettings) -> Result<(), GifError> {
|
||||
pub fn to_gif_file(
|
||||
&self,
|
||||
path: impl AsRef<Path>,
|
||||
palette: &Palette,
|
||||
settings: GifSettings,
|
||||
) -> Result<(), GifError> {
|
||||
let f = File::create(path)?;
|
||||
let mut writer = BufWriter::new(f);
|
||||
self.to_gif_bytes(&mut writer, palette, settings)
|
||||
|
@ -537,7 +542,7 @@ impl RgbaBitmap {
|
|||
Ok((output, palette))
|
||||
}
|
||||
|
||||
pub fn load_gif_file(path: &Path) -> Result<(RgbaBitmap, Palette), GifError> {
|
||||
pub fn load_gif_file(path: impl AsRef<Path>) -> Result<(RgbaBitmap, Palette), GifError> {
|
||||
let (temp_bitmap, palette) = IndexedBitmap::load_gif_file(path)?;
|
||||
let output = temp_bitmap.to_rgba(&palette);
|
||||
Ok((output, palette))
|
||||
|
@ -556,7 +561,7 @@ mod tests {
|
|||
|
||||
const BASE_PATH: &str = "./test-assets/gif/";
|
||||
|
||||
fn test_file(file: &Path) -> PathBuf {
|
||||
fn test_file(file: impl AsRef<Path>) -> PathBuf {
|
||||
PathBuf::from(BASE_PATH).join(file)
|
||||
}
|
||||
|
||||
|
@ -564,14 +569,14 @@ mod tests {
|
|||
fn load_and_save() -> Result<(), GifError> {
|
||||
let tmp_dir = TempDir::new()?;
|
||||
|
||||
let ref_pixels = load_raw_indexed(test_file(Path::new("small.bin")).as_path())?;
|
||||
let ref_pixels = load_raw_indexed(test_file("small.bin"))?;
|
||||
let dp2_palette = Palette::load_from_file(
|
||||
test_assets_file(Path::new("dp2.pal")).as_path(), //
|
||||
test_assets_file("dp2.pal"), //
|
||||
PaletteFormat::Normal,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let (bmp, palette) = IndexedBitmap::load_gif_file(test_file(Path::new("small.gif")).as_path())?;
|
||||
let (bmp, palette) = IndexedBitmap::load_gif_file(test_file("small.gif"))?;
|
||||
assert_eq!(16, bmp.width());
|
||||
assert_eq!(16, bmp.height());
|
||||
assert_eq!(bmp.pixels(), ref_pixels.as_ref());
|
||||
|
@ -597,9 +602,9 @@ mod tests {
|
|||
|
||||
// first image
|
||||
|
||||
let ref_pixels = load_raw_indexed(test_file(Path::new("large_1.bin")).as_path())?;
|
||||
let ref_pixels = load_raw_indexed(test_file("large_1.bin"))?;
|
||||
|
||||
let (bmp, palette) = IndexedBitmap::load_gif_file(test_file(Path::new("large_1.gif")).as_path())?;
|
||||
let (bmp, palette) = IndexedBitmap::load_gif_file(test_file("large_1.gif"))?;
|
||||
assert_eq!(320, bmp.width());
|
||||
assert_eq!(200, bmp.height());
|
||||
assert_eq!(bmp.pixels(), ref_pixels.as_ref());
|
||||
|
@ -613,9 +618,9 @@ mod tests {
|
|||
|
||||
// second image
|
||||
|
||||
let ref_pixels = load_raw_indexed(test_file(Path::new("large_2.bin")).as_path())?;
|
||||
let ref_pixels = load_raw_indexed(test_file("large_2.bin"))?;
|
||||
|
||||
let (bmp, palette) = IndexedBitmap::load_gif_file(test_file(Path::new("large_2.gif")).as_path())?;
|
||||
let (bmp, palette) = IndexedBitmap::load_gif_file(test_file("large_2.gif"))?;
|
||||
assert_eq!(320, bmp.width());
|
||||
assert_eq!(200, bmp.height());
|
||||
assert_eq!(bmp.pixels(), ref_pixels.as_ref());
|
||||
|
|
|
@ -430,7 +430,7 @@ impl IndexedBitmap {
|
|||
Ok((bitmap.unwrap(), palette.unwrap()))
|
||||
}
|
||||
|
||||
pub fn load_iff_file(path: &Path) -> Result<(IndexedBitmap, Palette), IffError> {
|
||||
pub fn load_iff_file(path: impl AsRef<Path>) -> Result<(IndexedBitmap, Palette), IffError> {
|
||||
let f = File::open(path)?;
|
||||
let mut reader = BufReader::new(f);
|
||||
Self::load_iff_bytes(&mut reader)
|
||||
|
@ -522,7 +522,7 @@ impl IndexedBitmap {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn to_iff_file(&self, path: &Path, palette: &Palette, format: IffFormat) -> Result<(), IffError> {
|
||||
pub fn to_iff_file(&self, path: impl AsRef<Path>, palette: &Palette, format: IffFormat) -> Result<(), IffError> {
|
||||
let f = File::create(path)?;
|
||||
let mut writer = BufWriter::new(f);
|
||||
self.to_iff_bytes(&mut writer, palette, format)
|
||||
|
@ -539,7 +539,7 @@ impl RgbaBitmap {
|
|||
Ok((output, palette))
|
||||
}
|
||||
|
||||
pub fn load_iff_file(path: &Path) -> Result<(RgbaBitmap, Palette), IffError> {
|
||||
pub fn load_iff_file(path: impl AsRef<Path>) -> Result<(RgbaBitmap, Palette), IffError> {
|
||||
let (temp_bitmap, palette) = IndexedBitmap::load_iff_file(path)?;
|
||||
let output = temp_bitmap.to_rgba(&palette);
|
||||
Ok((output, palette))
|
||||
|
@ -558,7 +558,7 @@ mod tests {
|
|||
|
||||
const BASE_PATH: &str = "./test-assets/iff/";
|
||||
|
||||
fn test_file(file: &Path) -> PathBuf {
|
||||
fn test_file(file: impl AsRef<Path>) -> PathBuf {
|
||||
PathBuf::from(BASE_PATH).join(file)
|
||||
}
|
||||
|
||||
|
@ -566,16 +566,16 @@ mod tests {
|
|||
pub fn load_and_save() -> Result<(), IffError> {
|
||||
let tmp_dir = TempDir::new()?;
|
||||
|
||||
let ref_pixels = load_raw_indexed(test_file(Path::new("small.bin")).as_path())?;
|
||||
let ref_pixels = load_raw_indexed(test_file("small.bin"))?;
|
||||
let dp2_palette = Palette::load_from_file(
|
||||
test_assets_file(Path::new("dp2.pal")).as_path(), //
|
||||
test_assets_file("dp2.pal"), //
|
||||
PaletteFormat::Normal,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// ILBM format
|
||||
|
||||
let (bmp, palette) = IndexedBitmap::load_iff_file(test_file(Path::new("small.lbm")).as_path())?;
|
||||
let (bmp, palette) = IndexedBitmap::load_iff_file(test_file("small.lbm"))?;
|
||||
assert_eq!(16, bmp.width());
|
||||
assert_eq!(16, bmp.height());
|
||||
assert_eq!(bmp.pixels(), ref_pixels.as_ref());
|
||||
|
@ -591,7 +591,7 @@ mod tests {
|
|||
|
||||
// PBM format
|
||||
|
||||
let (bmp, palette) = IndexedBitmap::load_iff_file(test_file(Path::new("small.pbm")).as_path())?;
|
||||
let (bmp, palette) = IndexedBitmap::load_iff_file(test_file("small.pbm"))?;
|
||||
assert_eq!(16, bmp.width());
|
||||
assert_eq!(16, bmp.height());
|
||||
assert_eq!(bmp.pixels(), ref_pixels.as_ref());
|
||||
|
@ -614,9 +614,9 @@ mod tests {
|
|||
|
||||
// first image, PBM format
|
||||
|
||||
let ref_pixels = load_raw_indexed(test_file(Path::new("large_1.bin")).as_path())?;
|
||||
let ref_pixels = load_raw_indexed(test_file("large_1.bin"))?;
|
||||
|
||||
let (bmp, palette) = IndexedBitmap::load_iff_file(test_file(Path::new("large_1.pbm")).as_path())?;
|
||||
let (bmp, palette) = IndexedBitmap::load_iff_file(test_file("large_1.pbm"))?;
|
||||
assert_eq!(320, bmp.width());
|
||||
assert_eq!(200, bmp.height());
|
||||
assert_eq!(bmp.pixels(), ref_pixels.as_ref());
|
||||
|
@ -630,7 +630,7 @@ mod tests {
|
|||
|
||||
// first image, ILBM format
|
||||
|
||||
let (bmp, palette) = IndexedBitmap::load_iff_file(test_file(Path::new("large_1.lbm")).as_path())?;
|
||||
let (bmp, palette) = IndexedBitmap::load_iff_file(test_file("large_1.lbm"))?;
|
||||
assert_eq!(320, bmp.width());
|
||||
assert_eq!(200, bmp.height());
|
||||
assert_eq!(bmp.pixels(), ref_pixels.as_ref());
|
||||
|
@ -644,9 +644,9 @@ mod tests {
|
|||
|
||||
// second image, PBM format
|
||||
|
||||
let ref_pixels = load_raw_indexed(test_file(Path::new("large_2.bin")).as_path())?;
|
||||
let ref_pixels = load_raw_indexed(test_file("large_2.bin"))?;
|
||||
|
||||
let (bmp, palette) = IndexedBitmap::load_iff_file(test_file(Path::new("large_2.lbm")).as_path())?;
|
||||
let (bmp, palette) = IndexedBitmap::load_iff_file(test_file("large_2.lbm"))?;
|
||||
assert_eq!(320, bmp.width());
|
||||
assert_eq!(200, bmp.height());
|
||||
assert_eq!(bmp.pixels(), ref_pixels.as_ref());
|
||||
|
@ -660,7 +660,7 @@ mod tests {
|
|||
|
||||
// second image, ILBM format
|
||||
|
||||
let (bmp, palette) = IndexedBitmap::load_iff_file(test_file(Path::new("large_2.lbm")).as_path())?;
|
||||
let (bmp, palette) = IndexedBitmap::load_iff_file(test_file("large_2.lbm"))?;
|
||||
assert_eq!(320, bmp.width());
|
||||
assert_eq!(200, bmp.height());
|
||||
assert_eq!(bmp.pixels(), ref_pixels.as_ref());
|
||||
|
|
|
@ -25,8 +25,8 @@ impl IndexedBitmap {
|
|||
Self::internal_new(width, height, 0)
|
||||
}
|
||||
|
||||
pub fn load_file(path: &Path) -> Result<(Self, Palette), BitmapError> {
|
||||
if let Some(extension) = path.extension() {
|
||||
pub fn load_file(path: impl AsRef<Path>) -> Result<(Self, Palette), BitmapError> {
|
||||
if let Some(extension) = path.as_ref().extension() {
|
||||
let extension = extension.to_ascii_lowercase();
|
||||
match extension.to_str() {
|
||||
Some("png") => {
|
||||
|
|
|
@ -178,7 +178,7 @@ impl IndexedBitmap {
|
|||
Ok((bmp, palette))
|
||||
}
|
||||
|
||||
pub fn load_pcx_file(path: &Path) -> Result<(IndexedBitmap, Palette), PcxError> {
|
||||
pub fn load_pcx_file(path: impl AsRef<Path>) -> Result<(IndexedBitmap, Palette), PcxError> {
|
||||
let f = File::open(path)?;
|
||||
let mut reader = BufReader::new(f);
|
||||
Self::load_pcx_bytes(&mut reader)
|
||||
|
@ -250,7 +250,7 @@ impl IndexedBitmap {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn to_pcx_file(&self, path: &Path, palette: &Palette) -> Result<(), PcxError> {
|
||||
pub fn to_pcx_file(&self, path: impl AsRef<Path>, palette: &Palette) -> Result<(), PcxError> {
|
||||
let f = File::create(path)?;
|
||||
let mut writer = BufWriter::new(f);
|
||||
self.to_pcx_bytes(&mut writer, palette)
|
||||
|
@ -267,7 +267,7 @@ impl RgbaBitmap {
|
|||
Ok((output, palette))
|
||||
}
|
||||
|
||||
pub fn load_pcx_file(path: &Path) -> Result<(RgbaBitmap, Palette), PcxError> {
|
||||
pub fn load_pcx_file(path: impl AsRef<Path>) -> Result<(RgbaBitmap, Palette), PcxError> {
|
||||
let (temp_bitmap, palette) = IndexedBitmap::load_pcx_file(path)?;
|
||||
let output = temp_bitmap.to_rgba(&palette);
|
||||
Ok((output, palette))
|
||||
|
@ -286,7 +286,7 @@ mod tests {
|
|||
|
||||
const BASE_PATH: &str = "./test-assets/pcx/";
|
||||
|
||||
fn test_file(file: &Path) -> PathBuf {
|
||||
fn test_file(file: impl AsRef<Path>) -> PathBuf {
|
||||
PathBuf::from(BASE_PATH).join(file)
|
||||
}
|
||||
|
||||
|
@ -294,14 +294,14 @@ mod tests {
|
|||
pub fn load_and_save() -> Result<(), PcxError> {
|
||||
let tmp_dir = TempDir::new()?;
|
||||
|
||||
let ref_pixels = load_raw_indexed(test_file(Path::new("small.bin")).as_path())?;
|
||||
let ref_pixels = load_raw_indexed(test_file("small.bin"))?;
|
||||
let dp2_palette = Palette::load_from_file(
|
||||
test_assets_file(Path::new("dp2.pal")).as_path(), //
|
||||
test_assets_file("dp2.pal"), //
|
||||
PaletteFormat::Normal,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let (bmp, palette) = IndexedBitmap::load_pcx_file(test_file(Path::new("small.pcx")).as_path())?;
|
||||
let (bmp, palette) = IndexedBitmap::load_pcx_file(test_file("small.pcx"))?;
|
||||
assert_eq!(16, bmp.width());
|
||||
assert_eq!(16, bmp.height());
|
||||
assert_eq!(bmp.pixels(), ref_pixels.as_ref());
|
||||
|
@ -324,9 +324,9 @@ mod tests {
|
|||
|
||||
// first image
|
||||
|
||||
let ref_pixels = load_raw_indexed(test_file(Path::new("large_1.bin")).as_path())?;
|
||||
let ref_pixels = load_raw_indexed(test_file("large_1.bin"))?;
|
||||
|
||||
let (bmp, palette) = IndexedBitmap::load_pcx_file(test_file(Path::new("large_1.pcx")).as_path())?;
|
||||
let (bmp, palette) = IndexedBitmap::load_pcx_file(test_file("large_1.pcx"))?;
|
||||
assert_eq!(320, bmp.width());
|
||||
assert_eq!(200, bmp.height());
|
||||
assert_eq!(bmp.pixels(), ref_pixels.as_ref());
|
||||
|
@ -340,9 +340,9 @@ mod tests {
|
|||
|
||||
// second image
|
||||
|
||||
let ref_pixels = load_raw_indexed(test_file(Path::new("large_2.bin")).as_path())?;
|
||||
let ref_pixels = load_raw_indexed(test_file("large_2.bin"))?;
|
||||
|
||||
let (bmp, palette) = IndexedBitmap::load_pcx_file(test_file(Path::new("large_2.pcx")).as_path())?;
|
||||
let (bmp, palette) = IndexedBitmap::load_pcx_file(test_file("large_2.pcx"))?;
|
||||
assert_eq!(320, bmp.width());
|
||||
assert_eq!(200, bmp.height());
|
||||
assert_eq!(bmp.pixels(), ref_pixels.as_ref());
|
||||
|
|
|
@ -560,7 +560,7 @@ impl IndexedBitmap {
|
|||
load_png_bytes(reader)
|
||||
}
|
||||
|
||||
pub fn load_png_file(path: &Path) -> Result<(IndexedBitmap, Option<Palette>), PngError> {
|
||||
pub fn load_png_file(path: impl AsRef<Path>) -> Result<(IndexedBitmap, Option<Palette>), PngError> {
|
||||
let f = File::open(path)?;
|
||||
let mut reader = BufReader::new(f);
|
||||
Self::load_png_bytes(&mut reader)
|
||||
|
@ -570,7 +570,7 @@ impl IndexedBitmap {
|
|||
write_png_bytes(writer, self, ColorFormat::IndexedColor, Some(palette))
|
||||
}
|
||||
|
||||
pub fn to_png_file(&self, path: &Path, palette: &Palette) -> Result<(), PngError> {
|
||||
pub fn to_png_file(&self, path: impl AsRef<Path>, palette: &Palette) -> Result<(), PngError> {
|
||||
let f = File::create(path)?;
|
||||
let mut writer = BufWriter::new(f);
|
||||
self.to_png_bytes(&mut writer, palette)
|
||||
|
@ -582,7 +582,7 @@ impl RgbaBitmap {
|
|||
load_png_bytes(reader)
|
||||
}
|
||||
|
||||
pub fn load_png_file(path: &Path) -> Result<(RgbaBitmap, Option<Palette>), PngError> {
|
||||
pub fn load_png_file(path: impl AsRef<Path>) -> Result<(RgbaBitmap, Option<Palette>), PngError> {
|
||||
let f = File::open(path)?;
|
||||
let mut reader = BufReader::new(f);
|
||||
Self::load_png_bytes(&mut reader)
|
||||
|
@ -600,7 +600,7 @@ impl RgbaBitmap {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn to_png_file(&self, path: &Path, format: PngFormat) -> Result<(), PngError> {
|
||||
pub fn to_png_file(&self, path: impl AsRef<Path>, format: PngFormat) -> Result<(), PngError> {
|
||||
let f = File::create(path)?;
|
||||
let mut writer = BufWriter::new(f);
|
||||
self.to_png_bytes(&mut writer, format)
|
||||
|
@ -620,14 +620,14 @@ mod tests {
|
|||
|
||||
const BASE_PATH: &str = "./test-assets/png/";
|
||||
|
||||
fn test_file(file: &Path) -> PathBuf {
|
||||
fn test_file(file: impl AsRef<Path>) -> PathBuf {
|
||||
PathBuf::from(BASE_PATH).join(file)
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn loads_indexed_256_color() -> Result<(), PngError> {
|
||||
let ref_bytes = load_raw_indexed(test_file(Path::new("indexed_8.bin")).as_path())?;
|
||||
let (bmp, palette) = IndexedBitmap::load_png_file(test_file(Path::new("indexed_8.png")).as_path())?;
|
||||
let ref_bytes = load_raw_indexed(test_file("indexed_8.bin"))?;
|
||||
let (bmp, palette) = IndexedBitmap::load_png_file(test_file("indexed_8.png"))?;
|
||||
assert!(palette.is_some());
|
||||
assert_eq!(ref_bytes, bmp.pixels);
|
||||
Ok(())
|
||||
|
@ -635,8 +635,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
pub fn loads_indexed_256_color_to_rgba_destination() -> Result<(), PngError> {
|
||||
let ref_bytes = load_raw_rgba(test_file(Path::new("indexed_8_rgba.bin")).as_path())?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("indexed_8.png")).as_path())?;
|
||||
let ref_bytes = load_raw_rgba(test_file("indexed_8_rgba.bin"))?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file("indexed_8.png"))?;
|
||||
assert!(palette.is_some());
|
||||
assert_eq!(ref_bytes, bmp.pixels);
|
||||
Ok(())
|
||||
|
@ -644,8 +644,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
pub fn loads_rgb_color() -> Result<(), PngError> {
|
||||
let ref_bytes = load_raw_rgba(test_file(Path::new("rgb.bin")).as_path())?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("rgb.png")).as_path())?;
|
||||
let ref_bytes = load_raw_rgba(test_file("rgb.bin"))?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file("rgb.png"))?;
|
||||
assert!(palette.is_none());
|
||||
assert_eq!(ref_bytes, bmp.pixels);
|
||||
Ok(())
|
||||
|
@ -653,8 +653,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
pub fn loads_rgba_color() -> Result<(), PngError> {
|
||||
let ref_bytes = load_raw_rgba(test_file(Path::new("rgba.bin")).as_path())?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("rgba.png")).as_path())?;
|
||||
let ref_bytes = load_raw_rgba(test_file("rgba.bin"))?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file("rgba.png"))?;
|
||||
assert!(palette.is_none());
|
||||
assert_eq!(ref_bytes, bmp.pixels);
|
||||
Ok(())
|
||||
|
@ -662,8 +662,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
pub fn loads_filter_0() -> Result<(), PngError> {
|
||||
let ref_bytes = load_raw_rgba(test_file(Path::new("filter_0_rgb.bin")).as_path())?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("filter_0_rgb.png")).as_path())?;
|
||||
let ref_bytes = load_raw_rgba(test_file("filter_0_rgb.bin"))?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file("filter_0_rgb.png"))?;
|
||||
assert!(palette.is_none());
|
||||
assert_eq!(ref_bytes, bmp.pixels);
|
||||
Ok(())
|
||||
|
@ -671,8 +671,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
pub fn loads_filter_1() -> Result<(), PngError> {
|
||||
let ref_bytes = load_raw_rgba(test_file(Path::new("filter_1_rgb.bin")).as_path())?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("filter_1_rgb.png")).as_path())?;
|
||||
let ref_bytes = load_raw_rgba(test_file("filter_1_rgb.bin"))?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file("filter_1_rgb.png"))?;
|
||||
assert!(palette.is_none());
|
||||
assert_eq!(ref_bytes, bmp.pixels);
|
||||
Ok(())
|
||||
|
@ -680,8 +680,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
pub fn loads_filter_2() -> Result<(), PngError> {
|
||||
let ref_bytes = load_raw_rgba(test_file(Path::new("filter_2_rgb.bin")).as_path())?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("filter_2_rgb.png")).as_path())?;
|
||||
let ref_bytes = load_raw_rgba(test_file("filter_2_rgb.bin"))?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file("filter_2_rgb.png"))?;
|
||||
assert!(palette.is_none());
|
||||
assert_eq!(ref_bytes, bmp.pixels);
|
||||
Ok(())
|
||||
|
@ -689,8 +689,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
pub fn loads_filter_3() -> Result<(), PngError> {
|
||||
let ref_bytes = load_raw_rgba(test_file(Path::new("filter_3_rgb.bin")).as_path())?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("filter_3_rgb.png")).as_path())?;
|
||||
let ref_bytes = load_raw_rgba(test_file("filter_3_rgb.bin"))?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file("filter_3_rgb.png"))?;
|
||||
assert!(palette.is_none());
|
||||
assert_eq!(ref_bytes, bmp.pixels);
|
||||
Ok(())
|
||||
|
@ -698,8 +698,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
pub fn loads_filter_4() -> Result<(), PngError> {
|
||||
let ref_bytes = load_raw_rgba(test_file(Path::new("filter_4_rgb.bin")).as_path())?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("filter_4_rgb.png")).as_path())?;
|
||||
let ref_bytes = load_raw_rgba(test_file("filter_4_rgb.bin"))?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file("filter_4_rgb.png"))?;
|
||||
assert!(palette.is_none());
|
||||
assert_eq!(ref_bytes, bmp.pixels);
|
||||
Ok(())
|
||||
|
@ -707,13 +707,13 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
pub fn loads_larger_indexed_256color_images() -> Result<(), PngError> {
|
||||
let ref_bytes = load_raw_indexed(test_file(Path::new("large_1_indexed.bin")).as_path())?;
|
||||
let (bmp, palette) = IndexedBitmap::load_png_file(test_file(Path::new("large_1_indexed.png")).as_path())?;
|
||||
let ref_bytes = load_raw_indexed(test_file("large_1_indexed.bin"))?;
|
||||
let (bmp, palette) = IndexedBitmap::load_png_file(test_file("large_1_indexed.png"))?;
|
||||
assert!(palette.is_some());
|
||||
assert_eq!(ref_bytes, bmp.pixels);
|
||||
|
||||
let ref_bytes = load_raw_indexed(test_file(Path::new("large_2_indexed.bin")).as_path())?;
|
||||
let (bmp, palette) = IndexedBitmap::load_png_file(test_file(Path::new("large_2_indexed.png")).as_path())?;
|
||||
let ref_bytes = load_raw_indexed(test_file("large_2_indexed.bin"))?;
|
||||
let (bmp, palette) = IndexedBitmap::load_png_file(test_file("large_2_indexed.png"))?;
|
||||
assert!(palette.is_some());
|
||||
assert_eq!(ref_bytes, bmp.pixels);
|
||||
|
||||
|
@ -722,13 +722,13 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
pub fn loads_larger_rgb_images() -> Result<(), PngError> {
|
||||
let ref_bytes = load_raw_rgba(test_file(Path::new("large_1_rgba.bin")).as_path())?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("large_1_rgb.png")).as_path())?;
|
||||
let ref_bytes = load_raw_rgba(test_file("large_1_rgba.bin"))?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file("large_1_rgb.png"))?;
|
||||
assert!(palette.is_none());
|
||||
assert_eq!(ref_bytes, bmp.pixels);
|
||||
|
||||
let ref_bytes = load_raw_rgba(test_file(Path::new("large_2_rgba.bin")).as_path())?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("large_2_rgb.png")).as_path())?;
|
||||
let ref_bytes = load_raw_rgba(test_file("large_2_rgba.bin"))?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file("large_2_rgb.png"))?;
|
||||
assert!(palette.is_none());
|
||||
assert_eq!(ref_bytes, bmp.pixels);
|
||||
|
||||
|
@ -739,9 +739,9 @@ mod tests {
|
|||
pub fn load_and_save_indexed_256_color() -> Result<(), PngError> {
|
||||
let tmp_dir = TempDir::new()?;
|
||||
|
||||
let ref_bytes = load_raw_indexed(test_file(Path::new("indexed_8.bin")).as_path())?;
|
||||
let ref_bytes = load_raw_indexed(test_file("indexed_8.bin"))?;
|
||||
|
||||
let (bmp, palette) = IndexedBitmap::load_png_file(test_file(Path::new("indexed_8.png")).as_path())?;
|
||||
let (bmp, palette) = IndexedBitmap::load_png_file(test_file("indexed_8.png"))?;
|
||||
assert_eq!(32, bmp.width());
|
||||
assert_eq!(32, bmp.height());
|
||||
assert_eq!(bmp.pixels, ref_bytes);
|
||||
|
@ -764,9 +764,9 @@ mod tests {
|
|||
|
||||
// first image
|
||||
|
||||
let ref_bytes = load_raw_indexed(test_file(Path::new("large_1_indexed.bin")).as_path())?;
|
||||
let ref_bytes = load_raw_indexed(test_file("large_1_indexed.bin"))?;
|
||||
|
||||
let (bmp, palette) = IndexedBitmap::load_png_file(test_file(Path::new("large_1_indexed.png")).as_path())?;
|
||||
let (bmp, palette) = IndexedBitmap::load_png_file(test_file("large_1_indexed.png"))?;
|
||||
assert_eq!(320, bmp.width());
|
||||
assert_eq!(200, bmp.height());
|
||||
assert_eq!(bmp.pixels, ref_bytes);
|
||||
|
@ -782,9 +782,9 @@ mod tests {
|
|||
|
||||
// second image
|
||||
|
||||
let ref_bytes = load_raw_indexed(test_file(Path::new("large_2_indexed.bin")).as_path())?;
|
||||
let ref_bytes = load_raw_indexed(test_file("large_2_indexed.bin"))?;
|
||||
|
||||
let (bmp, palette) = IndexedBitmap::load_png_file(test_file(Path::new("large_2_indexed.png")).as_path())?;
|
||||
let (bmp, palette) = IndexedBitmap::load_png_file(test_file("large_2_indexed.png"))?;
|
||||
assert_eq!(320, bmp.width());
|
||||
assert_eq!(200, bmp.height());
|
||||
assert_eq!(bmp.pixels, ref_bytes);
|
||||
|
@ -805,9 +805,9 @@ mod tests {
|
|||
pub fn load_and_save_rgb_color() -> Result<(), PngError> {
|
||||
let tmp_dir = TempDir::new()?;
|
||||
|
||||
let ref_bytes = load_raw_rgba(test_file(Path::new("rgb.bin")).as_path())?;
|
||||
let ref_bytes = load_raw_rgba(test_file("rgb.bin"))?;
|
||||
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("rgb.png")).as_path())?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file("rgb.png"))?;
|
||||
assert_eq!(32, bmp.width());
|
||||
assert_eq!(32, bmp.height());
|
||||
assert_eq!(bmp.pixels, ref_bytes);
|
||||
|
@ -830,9 +830,9 @@ mod tests {
|
|||
|
||||
// first image
|
||||
|
||||
let ref_bytes = load_raw_rgba(test_file(Path::new("large_1_rgba.bin")).as_path())?;
|
||||
let ref_bytes = load_raw_rgba(test_file("large_1_rgba.bin"))?;
|
||||
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("large_1_rgb.png")).as_path())?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file("large_1_rgb.png"))?;
|
||||
assert_eq!(320, bmp.width());
|
||||
assert_eq!(200, bmp.height());
|
||||
assert_eq!(bmp.pixels, ref_bytes);
|
||||
|
@ -848,9 +848,9 @@ mod tests {
|
|||
|
||||
// second image
|
||||
|
||||
let ref_bytes = load_raw_rgba(test_file(Path::new("large_2_rgba.bin")).as_path())?;
|
||||
let ref_bytes = load_raw_rgba(test_file("large_2_rgba.bin"))?;
|
||||
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file(Path::new("large_2_rgb.png")).as_path())?;
|
||||
let (bmp, palette) = RgbaBitmap::load_png_file(test_file("large_2_rgb.png"))?;
|
||||
assert_eq!(320, bmp.width());
|
||||
assert_eq!(200, bmp.height());
|
||||
assert_eq!(bmp.pixels, ref_bytes);
|
||||
|
@ -869,58 +869,43 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
pub fn load_fails_on_unsupported_formats() -> Result<(), PngError> {
|
||||
assert_matches!(RgbaBitmap::load_png_file(test_file("unsupported_alpha_8bit.png")), Err(PngError::BadFile(..)));
|
||||
assert_matches!(
|
||||
RgbaBitmap::load_png_file(test_file(Path::new("unsupported_alpha_8bit.png")).as_path()),
|
||||
RgbaBitmap::load_png_file(test_file("unsupported_greyscale_8bit.png")),
|
||||
Err(PngError::BadFile(..))
|
||||
);
|
||||
assert_matches!(
|
||||
RgbaBitmap::load_png_file(test_file(Path::new("unsupported_greyscale_8bit.png")).as_path()),
|
||||
Err(PngError::BadFile(..))
|
||||
);
|
||||
assert_matches!(
|
||||
RgbaBitmap::load_png_file(test_file(Path::new("unsupported_indexed_16col.png")).as_path()),
|
||||
Err(PngError::BadFile(..))
|
||||
);
|
||||
assert_matches!(
|
||||
RgbaBitmap::load_png_file(test_file(Path::new("unsupported_rgb_16bit.png")).as_path()),
|
||||
Err(PngError::BadFile(..))
|
||||
);
|
||||
assert_matches!(
|
||||
RgbaBitmap::load_png_file(test_file(Path::new("unsupported_rgba_16bit.png")).as_path()),
|
||||
RgbaBitmap::load_png_file(test_file("unsupported_indexed_16col.png")),
|
||||
Err(PngError::BadFile(..))
|
||||
);
|
||||
assert_matches!(RgbaBitmap::load_png_file(test_file("unsupported_rgb_16bit.png")), Err(PngError::BadFile(..)));
|
||||
assert_matches!(RgbaBitmap::load_png_file(test_file("unsupported_rgba_16bit.png")), Err(PngError::BadFile(..)));
|
||||
|
||||
assert_matches!(
|
||||
IndexedBitmap::load_png_file(test_file(Path::new("unsupported_alpha_8bit.png")).as_path()),
|
||||
IndexedBitmap::load_png_file(test_file("unsupported_alpha_8bit.png")),
|
||||
Err(PngError::BadFile(..))
|
||||
);
|
||||
assert_matches!(
|
||||
IndexedBitmap::load_png_file(test_file(Path::new("unsupported_greyscale_8bit.png")).as_path()),
|
||||
IndexedBitmap::load_png_file(test_file("unsupported_greyscale_8bit.png")),
|
||||
Err(PngError::BadFile(..))
|
||||
);
|
||||
assert_matches!(
|
||||
IndexedBitmap::load_png_file(test_file(Path::new("unsupported_indexed_16col.png")).as_path()),
|
||||
IndexedBitmap::load_png_file(test_file("unsupported_indexed_16col.png")),
|
||||
Err(PngError::BadFile(..))
|
||||
);
|
||||
assert_matches!(
|
||||
IndexedBitmap::load_png_file(test_file(Path::new("unsupported_rgb_16bit.png")).as_path()),
|
||||
IndexedBitmap::load_png_file(test_file("unsupported_rgb_16bit.png")),
|
||||
Err(PngError::BadFile(..))
|
||||
);
|
||||
assert_matches!(
|
||||
IndexedBitmap::load_png_file(test_file(Path::new("unsupported_rgba_16bit.png")).as_path()),
|
||||
IndexedBitmap::load_png_file(test_file("unsupported_rgba_16bit.png")),
|
||||
Err(PngError::BadFile(..))
|
||||
);
|
||||
|
||||
// also test the extra formats that IndexedBitmap does not support which RgbaBitmap does
|
||||
// (anything not 256-color indexed basically ...)
|
||||
assert_matches!(
|
||||
IndexedBitmap::load_png_file(test_file(Path::new("rgb.png")).as_path()),
|
||||
Err(PngError::BadFile(..))
|
||||
);
|
||||
assert_matches!(
|
||||
IndexedBitmap::load_png_file(test_file(Path::new("rgba.png")).as_path()),
|
||||
Err(PngError::BadFile(..))
|
||||
);
|
||||
assert_matches!(IndexedBitmap::load_png_file(test_file("rgb.png")), Err(PngError::BadFile(..)));
|
||||
assert_matches!(IndexedBitmap::load_png_file(test_file("rgba.png")), Err(PngError::BadFile(..)));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -60,8 +60,8 @@ impl RgbaBitmap {
|
|||
Ok(bitmap)
|
||||
}
|
||||
|
||||
pub fn load_file(path: &Path) -> Result<(Self, Option<Palette>), BitmapError> {
|
||||
if let Some(extension) = path.extension() {
|
||||
pub fn load_file(path: impl AsRef<Path>) -> Result<(Self, Option<Palette>), BitmapError> {
|
||||
if let Some(extension) = path.as_ref().extension() {
|
||||
let extension = extension.to_ascii_lowercase();
|
||||
match extension.to_str() {
|
||||
Some("png") => Ok(Self::load_png_file(path)?),
|
||||
|
|
|
@ -232,7 +232,7 @@ pub struct BitmapAtlasDescriptor {
|
|||
}
|
||||
|
||||
impl BitmapAtlasDescriptor {
|
||||
pub fn load_from_file(path: &Path) -> Result<Self, BitmapAtlasDescriptorError> {
|
||||
pub fn load_from_file(path: impl AsRef<Path>) -> Result<Self, BitmapAtlasDescriptorError> {
|
||||
let f = File::open(path)?;
|
||||
let mut reader = BufReader::new(f);
|
||||
Self::load_from_bytes(&mut reader)
|
||||
|
@ -245,7 +245,7 @@ impl BitmapAtlasDescriptor {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn to_file(&self, path: &Path) -> Result<(), BitmapAtlasDescriptorError> {
|
||||
pub fn to_file(&self, path: impl AsRef<Path>) -> Result<(), BitmapAtlasDescriptorError> {
|
||||
let f = File::create(path)?;
|
||||
let mut writer = BufWriter::new(f);
|
||||
self.to_bytes(&mut writer)
|
||||
|
|
|
@ -239,7 +239,7 @@ impl BlendMap {
|
|||
self.get_mapping(source_color).map(|mapping| mapping[dest_color as usize])
|
||||
}
|
||||
|
||||
pub fn load_from_file(path: &Path) -> Result<Self, BlendMapError> {
|
||||
pub fn load_from_file(path: impl AsRef<Path>) -> Result<Self, BlendMapError> {
|
||||
let f = File::open(path)?;
|
||||
let mut reader = BufReader::new(f);
|
||||
Self::load_from_bytes(&mut reader)
|
||||
|
@ -268,7 +268,7 @@ impl BlendMap {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn to_file(&self, path: &Path) -> Result<(), BlendMapError> {
|
||||
pub fn to_file(&self, path: impl AsRef<Path>) -> Result<(), BlendMapError> {
|
||||
let f = File::create(path)?;
|
||||
let mut writer = BufWriter::new(f);
|
||||
self.to_bytes(&mut writer)
|
||||
|
|
|
@ -209,7 +209,7 @@ impl BitmaskFont {
|
|||
Ok(font)
|
||||
}
|
||||
|
||||
pub fn load_from_file(path: &Path) -> Result<BitmaskFont, FontError> {
|
||||
pub fn load_from_file(path: impl AsRef<Path>) -> Result<BitmaskFont, FontError> {
|
||||
let f = File::open(path)?;
|
||||
let mut reader = BufReader::new(f);
|
||||
|
||||
|
@ -242,7 +242,7 @@ impl BitmaskFont {
|
|||
Self::new(&characters, line_height as usize)
|
||||
}
|
||||
|
||||
pub fn to_file(&self, path: &Path) -> Result<(), FontError> {
|
||||
pub fn to_file(&self, path: impl AsRef<Path>) -> Result<(), FontError> {
|
||||
let f = File::create(path)?;
|
||||
let mut writer = BufWriter::new(f);
|
||||
self.to_bytes(&mut writer)
|
||||
|
@ -327,13 +327,13 @@ mod tests {
|
|||
|
||||
const BASE_PATH: &str = "./test-assets/font/";
|
||||
|
||||
fn test_file(file: &Path) -> PathBuf {
|
||||
fn test_file(file: impl AsRef<Path>) -> PathBuf {
|
||||
PathBuf::from(BASE_PATH).join(file)
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn load_font() -> Result<(), FontError> {
|
||||
let font = BitmaskFont::load_from_file(test_file(Path::new("vga.fnt")).as_path())?;
|
||||
let font = BitmaskFont::load_from_file(test_file("vga.fnt"))?;
|
||||
assert_eq!(256, font.characters.len());
|
||||
assert_eq!(CHAR_FIXED_WIDTH as u8, font.space_width);
|
||||
for character in font.characters.iter() {
|
||||
|
@ -347,7 +347,7 @@ mod tests {
|
|||
#[test]
|
||||
pub fn measure_text() -> Result<(), FontError> {
|
||||
{
|
||||
let font = BitmaskFont::load_from_file(test_file(Path::new("vga.fnt")).as_path())?;
|
||||
let font = BitmaskFont::load_from_file(test_file("vga.fnt"))?;
|
||||
|
||||
assert_eq!((40, 8), font.measure("Hello", FontRenderOpts::<u8>::None));
|
||||
assert_eq!((40, 16), font.measure("Hello\nthere", FontRenderOpts::<u8>::None));
|
||||
|
@ -361,7 +361,7 @@ mod tests {
|
|||
}
|
||||
|
||||
{
|
||||
let font = BitmaskFont::load_from_file(test_file(Path::new("small.fnt")).as_path())?;
|
||||
let font = BitmaskFont::load_from_file(test_file("small.fnt"))?;
|
||||
|
||||
assert_eq!((22, 7), font.measure("Hello", FontRenderOpts::<u8>::None));
|
||||
assert_eq!((24, 14), font.measure("Hello\nthere", FontRenderOpts::<u8>::None));
|
||||
|
|
|
@ -137,7 +137,7 @@ impl Palette {
|
|||
///
|
||||
/// * `path`: the path of the palette file to be loaded
|
||||
/// * `format`: the format that the palette data is expected to be in
|
||||
pub fn load_from_file(path: &Path, format: PaletteFormat) -> Result<Palette, PaletteError> {
|
||||
pub fn load_from_file(path: impl AsRef<Path>, format: PaletteFormat) -> Result<Palette, PaletteError> {
|
||||
let f = File::open(path)?;
|
||||
let mut reader = BufReader::new(f);
|
||||
Self::load_from_bytes(&mut reader, format)
|
||||
|
@ -168,7 +168,7 @@ impl Palette {
|
|||
/// * `format`: the format that the palette data is expected to be in
|
||||
/// * `num_colors`: the expected number of colors in the palette to be loaded (<= 256)
|
||||
pub fn load_num_colors_from_file(
|
||||
path: &Path,
|
||||
path: impl AsRef<Path>,
|
||||
format: PaletteFormat,
|
||||
num_colors: usize,
|
||||
) -> Result<Palette, PaletteError> {
|
||||
|
@ -208,7 +208,7 @@ impl Palette {
|
|||
///
|
||||
/// * `path`: the path of the file to save the palette to
|
||||
/// * `format`: the format to write the palette data in
|
||||
pub fn to_file(&self, path: &Path, format: PaletteFormat) -> Result<(), PaletteError> {
|
||||
pub fn to_file(&self, path: impl AsRef<Path>, format: PaletteFormat) -> Result<(), PaletteError> {
|
||||
let f = File::create(path)?;
|
||||
let mut writer = BufWriter::new(f);
|
||||
self.to_bytes(&mut writer, format)
|
||||
|
@ -239,7 +239,7 @@ impl Palette {
|
|||
/// * `num_colors`: the number of colors from this palette to write out to the file (<= 256)
|
||||
pub fn num_colors_to_file(
|
||||
&self,
|
||||
path: &Path,
|
||||
path: impl AsRef<Path>,
|
||||
format: PaletteFormat,
|
||||
num_colors: usize,
|
||||
) -> Result<(), PaletteError> {
|
||||
|
@ -499,7 +499,7 @@ mod tests {
|
|||
|
||||
const BASE_PATH: &str = "./test-assets/palette/";
|
||||
|
||||
fn test_file(file: &Path) -> PathBuf {
|
||||
fn test_file(file: impl AsRef<Path>) -> PathBuf {
|
||||
PathBuf::from(BASE_PATH).join(file)
|
||||
}
|
||||
|
||||
|
@ -538,7 +538,7 @@ mod tests {
|
|||
|
||||
// vga rgb format (6-bit)
|
||||
|
||||
let palette = Palette::load_from_file(test_file(Path::new("vga.pal")).as_path(), PaletteFormat::Vga)?;
|
||||
let palette = Palette::load_from_file(test_file("vga.pal"), PaletteFormat::Vga)?;
|
||||
assert_ega_colors(&palette);
|
||||
|
||||
let save_path = tmp_dir.path().join("test_save_vga_format.pal");
|
||||
|
@ -548,7 +548,7 @@ mod tests {
|
|||
|
||||
// normal rgb format (8-bit)
|
||||
|
||||
let palette = Palette::load_from_file(test_file(Path::new("dp2.pal")).as_path(), PaletteFormat::Normal)?;
|
||||
let palette = Palette::load_from_file(test_file("dp2.pal"), PaletteFormat::Normal)?;
|
||||
|
||||
let save_path = tmp_dir.path().join("test_save_normal_format.pal");
|
||||
palette.to_file(&save_path, PaletteFormat::Normal)?;
|
||||
|
@ -564,8 +564,7 @@ mod tests {
|
|||
|
||||
// vga rgb format (6-bit)
|
||||
|
||||
let palette =
|
||||
Palette::load_num_colors_from_file(test_file(Path::new("ega_6bit.pal")).as_path(), PaletteFormat::Vga, 16)?;
|
||||
let palette = Palette::load_num_colors_from_file(test_file("ega_6bit.pal"), PaletteFormat::Vga, 16)?;
|
||||
assert_ega_colors(&palette);
|
||||
|
||||
let save_path = tmp_dir.path().join("test_save_vga_format_16_colors.pal");
|
||||
|
@ -575,11 +574,7 @@ mod tests {
|
|||
|
||||
// normal rgb format (8-bit)
|
||||
|
||||
let palette = Palette::load_num_colors_from_file(
|
||||
test_file(Path::new("ega_8bit.pal")).as_path(),
|
||||
PaletteFormat::Normal,
|
||||
16,
|
||||
)?;
|
||||
let palette = Palette::load_num_colors_from_file(test_file("ega_8bit.pal"), PaletteFormat::Normal, 16)?;
|
||||
|
||||
let save_path = tmp_dir.path().join("test_save_normal_format_16_colors.pal");
|
||||
palette.to_file(&save_path, PaletteFormat::Normal)?;
|
||||
|
|
|
@ -30,15 +30,15 @@ mod tests {
|
|||
const TEST_ASSETS_PATH: &str = "./test-assets/";
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn assets_file(file: &Path) -> PathBuf {
|
||||
pub fn assets_file(file: impl AsRef<Path>) -> PathBuf {
|
||||
PathBuf::from(ASSETS_PATH).join(file)
|
||||
}
|
||||
|
||||
pub fn test_assets_file(file: &Path) -> PathBuf {
|
||||
pub fn test_assets_file(file: impl AsRef<Path>) -> PathBuf {
|
||||
PathBuf::from(TEST_ASSETS_PATH).join(file)
|
||||
}
|
||||
|
||||
pub fn load_raw_indexed(bin_file: &Path) -> Result<Box<[u8]>, io::Error> {
|
||||
pub fn load_raw_indexed(bin_file: impl AsRef<Path>) -> Result<Box<[u8]>, io::Error> {
|
||||
let f = File::open(bin_file)?;
|
||||
let mut reader = BufReader::new(f);
|
||||
let mut buffer = Vec::new();
|
||||
|
@ -46,7 +46,7 @@ mod tests {
|
|||
Ok(buffer.into_boxed_slice())
|
||||
}
|
||||
|
||||
pub fn load_raw_rgba(bin_file: &Path) -> Result<Box<[RGBA]>, io::Error> {
|
||||
pub fn load_raw_rgba(bin_file: impl AsRef<Path>) -> Result<Box<[RGBA]>, io::Error> {
|
||||
let f = File::open(bin_file)?;
|
||||
let mut reader = BufReader::new(f);
|
||||
let mut buffer = Vec::new();
|
||||
|
|
|
@ -11,7 +11,7 @@ const SCREEN_HEIGHT: u32 = 240;
|
|||
|
||||
const BASE_PATH: &str = "./tests/ref/indexed/";
|
||||
|
||||
fn reference_file(file: &Path) -> PathBuf {
|
||||
fn reference_file(file: impl AsRef<Path>) -> PathBuf {
|
||||
PathBuf::from(BASE_PATH).join(file)
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,8 @@ fn setup() -> (IndexedBitmap, Palette) {
|
|||
}
|
||||
|
||||
fn setup_for_blending() -> (IndexedBitmap, Palette, BlendMap) {
|
||||
let (texture, palette) = IndexedBitmap::load_file(test_assets_file(Path::new("texture.lbm")).as_path()).unwrap();
|
||||
let blend_map = BlendMap::load_from_file(test_assets_file(Path::new("test.blendmap")).as_path()).unwrap();
|
||||
let (texture, palette) = IndexedBitmap::load_file(test_assets_file("texture.lbm")).unwrap();
|
||||
let blend_map = BlendMap::load_from_file(test_assets_file("test.blendmap")).unwrap();
|
||||
let mut screen = IndexedBitmap::new(SCREEN_WIDTH, SCREEN_HEIGHT).unwrap();
|
||||
for y in 0..(SCREEN_HEIGHT as f32 / texture.height() as f32).ceil() as i32 {
|
||||
for x in 0..(SCREEN_WIDTH as f32 / texture.width() as f32).ceil() as i32 {
|
||||
|
@ -33,7 +33,7 @@ fn setup_for_blending() -> (IndexedBitmap, Palette, BlendMap) {
|
|||
(screen, palette, blend_map)
|
||||
}
|
||||
|
||||
fn verify_visual(screen: &IndexedBitmap, palette: &Palette, source: &Path) -> bool {
|
||||
fn verify_visual(screen: &IndexedBitmap, palette: &Palette, source: impl AsRef<Path>) -> bool {
|
||||
let (source_bmp, source_pal) = IndexedBitmap::load_file(source).unwrap();
|
||||
*screen == source_bmp && *palette == source_pal
|
||||
}
|
||||
|
@ -79,11 +79,11 @@ fn pixel_addressing() {
|
|||
}
|
||||
}
|
||||
|
||||
let path = reference_file(Path::new("pixel_addressing.png"));
|
||||
let path = &reference_file("pixel_addressing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -133,11 +133,11 @@ fn pixel_drawing() {
|
|||
screen.set_pixel(160, i + 234, 15);
|
||||
}
|
||||
|
||||
let path = reference_file(Path::new("pixel_drawing.png"));
|
||||
let path = &reference_file("pixel_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -169,11 +169,11 @@ fn blended_pixel_drawing() {
|
|||
screen.set_blended_pixel(160, i + 234, 15, &blend_map);
|
||||
}
|
||||
|
||||
let path = reference_file(Path::new("blended_pixel_drawing.png"));
|
||||
let path = &reference_file("blended_pixel_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -191,11 +191,11 @@ fn horiz_line_drawing() {
|
|||
screen.horiz_line(100, 200, -10, 6);
|
||||
screen.horiz_line(20, 80, 250, 7);
|
||||
|
||||
let path = reference_file(Path::new("horiz_line_drawing.png"));
|
||||
let path = &reference_file("horiz_line_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -213,11 +213,11 @@ fn blended_horiz_line_drawing() {
|
|||
screen.blended_horiz_line(100, 200, -10, 6, &blend_map);
|
||||
screen.blended_horiz_line(20, 80, 250, 7, &blend_map);
|
||||
|
||||
let path = reference_file(Path::new("blended_horiz_line_drawing.png"));
|
||||
let path = &reference_file("blended_horiz_line_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -235,11 +235,11 @@ fn vert_line_drawing() {
|
|||
screen.vert_line(-17, 10, 20, 6);
|
||||
screen.vert_line(400, 100, 300, 7);
|
||||
|
||||
let path = reference_file(Path::new("vert_line_drawing.png"));
|
||||
let path = &reference_file("vert_line_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -257,11 +257,11 @@ fn blended_vert_line_drawing() {
|
|||
screen.blended_vert_line(-17, 10, 20, 6, &blend_map);
|
||||
screen.blended_vert_line(400, 100, 300, 7, &blend_map);
|
||||
|
||||
let path = reference_file(Path::new("blended_vert_line_drawing.png"));
|
||||
let path = &reference_file("blended_vert_line_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -296,11 +296,11 @@ fn line_drawing() {
|
|||
screen.line(-100, 120, -100, 239, 3);
|
||||
screen.line(320, 99, 320, 199, 5);
|
||||
|
||||
let path = reference_file(Path::new("line_drawing.png"));
|
||||
let path = &reference_file("line_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -335,11 +335,11 @@ fn blended_line_drawing() {
|
|||
screen.blended_line(-100, 120, -100, 239, 3, &blend_map);
|
||||
screen.blended_line(320, 99, 320, 199, 5, &blend_map);
|
||||
|
||||
let path = reference_file(Path::new("blended_line_drawing.png"));
|
||||
let path = &reference_file("blended_line_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -365,11 +365,11 @@ fn rect_drawing() {
|
|||
screen.rect(300, 20, 340, -20, 13);
|
||||
screen.rect(20, 220, -20, 260, 14);
|
||||
|
||||
let path = reference_file(Path::new("rect_drawing.png"));
|
||||
let path = &reference_file("rect_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -395,11 +395,11 @@ fn blended_rect_drawing() {
|
|||
screen.blended_rect(300, 20, 340, -20, 13, &blend_map);
|
||||
screen.blended_rect(20, 220, -20, 260, 14, &blend_map);
|
||||
|
||||
let path = reference_file(Path::new("blended_rect_drawing.png"));
|
||||
let path = &reference_file("blended_rect_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -425,11 +425,11 @@ fn filled_rect_drawing() {
|
|||
screen.filled_rect(300, 20, 340, -20, 13);
|
||||
screen.filled_rect(20, 220, -20, 260, 14);
|
||||
|
||||
let path = reference_file(Path::new("filled_rect_drawing.png"));
|
||||
let path = &reference_file("filled_rect_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -455,11 +455,11 @@ fn blended_filled_rect_drawing() {
|
|||
screen.blended_filled_rect(300, 20, 340, -20, 13, &blend_map);
|
||||
screen.blended_filled_rect(20, 220, -20, 260, 14, &blend_map);
|
||||
|
||||
let path = reference_file(Path::new("blended_filled_rect_drawing.png"));
|
||||
let path = &reference_file("blended_filled_rect_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -480,11 +480,11 @@ fn circle_drawing() {
|
|||
screen.circle(319, 1, 22, 9);
|
||||
screen.circle(2, 242, 19, 10);
|
||||
|
||||
let path = reference_file(Path::new("circle_drawing.png"));
|
||||
let path = &reference_file("circle_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -505,11 +505,11 @@ fn filled_circle_drawing() {
|
|||
screen.filled_circle(319, 1, 22, 9);
|
||||
screen.filled_circle(2, 242, 19, 10);
|
||||
|
||||
let path = reference_file(Path::new("filled_circle_drawing.png"));
|
||||
let path = &reference_file("filled_circle_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -517,8 +517,8 @@ fn text_drawing() {
|
|||
let (mut screen, palette) = setup();
|
||||
|
||||
let font = BitmaskFont::new_vga_font().unwrap();
|
||||
let small_font = BitmaskFont::load_from_file(test_assets_file(Path::new("small.fnt")).as_path()).unwrap();
|
||||
let chunky_font = BitmaskFont::load_from_file(test_assets_file(Path::new("chunky.fnt")).as_path()).unwrap();
|
||||
let small_font = BitmaskFont::load_from_file(test_assets_file("small.fnt")).unwrap();
|
||||
let chunky_font = BitmaskFont::load_from_file(test_assets_file("chunky.fnt")).unwrap();
|
||||
|
||||
let message = "Hello, world! HELLO, WORLD!\nTesting 123";
|
||||
|
||||
|
@ -558,11 +558,11 @@ fn text_drawing() {
|
|||
screen.print_string(message, 360, 120, FontRenderOpts::Color(7), &font);
|
||||
screen.print_string(message, 200, 250, FontRenderOpts::Color(8), &font);
|
||||
|
||||
let path = reference_file(Path::new("text_drawing.png"));
|
||||
let path = &reference_file("text_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
fn generate_bitmap(width: i32, height: i32) -> IndexedBitmap {
|
||||
|
@ -645,11 +645,11 @@ fn solid_blits() {
|
|||
screen.blit(method.clone(), &bmp16, 196, 238);
|
||||
screen.blit(method.clone(), &bmp16, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("solid_blits.png"));
|
||||
let path = &reference_file("solid_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -716,11 +716,11 @@ fn blended_solid_blits() {
|
|||
screen.blit(method.clone(), &bmp16, 196, 238);
|
||||
screen.blit(method.clone(), &bmp16, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("blended_solid_blits.png"));
|
||||
let path = &reference_file("blended_solid_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -782,11 +782,11 @@ fn solid_flipped_blits() {
|
|||
screen.blit(SolidFlipped { horizontal_flip: true, vertical_flip: false }, &bmp, 196, 238);
|
||||
screen.blit(SolidFlipped { horizontal_flip: false, vertical_flip: true }, &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("solid_flipped_blits.png"));
|
||||
let path = &reference_file("solid_flipped_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -849,11 +849,11 @@ fn blended_solid_flipped_blits() {
|
|||
screen.blit(SolidFlippedBlended { horizontal_flip: true, vertical_flip: false, blend_map: blend_map.clone() }, &bmp, 196, 238);
|
||||
screen.blit(SolidFlippedBlended { horizontal_flip: false, vertical_flip: true, blend_map: blend_map.clone() }, &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("blended_solid_flipped_blits.png"));
|
||||
let path = &reference_file("blended_solid_flipped_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -919,11 +919,11 @@ fn solid_offset_blits() {
|
|||
screen.blit(method.clone(), &bmp, 196, 238);
|
||||
screen.blit(method.clone(), &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("solid_offset_blits.png"));
|
||||
let path = &reference_file("solid_offset_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -990,11 +990,11 @@ fn solid_flipped_offset_blits() {
|
|||
screen.blit(SolidFlippedOffset { offset, horizontal_flip: true, vertical_flip: false }, &bmp, 196, 238);
|
||||
screen.blit(SolidFlippedOffset { offset, horizontal_flip: false, vertical_flip: true }, &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("solid_flipped_offset_blits.png"));
|
||||
let path = &reference_file("solid_flipped_offset_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1061,11 +1061,11 @@ fn transparent_blits() {
|
|||
screen.blit(method.clone(), &bmp16, 196, 238);
|
||||
screen.blit(method.clone(), &bmp16, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("transparent_blits.png"));
|
||||
let path = &reference_file("transparent_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1132,11 +1132,11 @@ fn blended_transparent_blits() {
|
|||
screen.blit(method.clone(), &bmp16, 196, 238);
|
||||
screen.blit(method.clone(), &bmp16, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("blended_transparent_blits.png"));
|
||||
let path = &reference_file("blended_transparent_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -1201,11 +1201,11 @@ fn transparent_flipped_blits() {
|
|||
screen.blit(TransparentFlipped { transparent_color, horizontal_flip: true, vertical_flip: false }, &bmp, 196, 238);
|
||||
screen.blit(TransparentFlipped { transparent_color, horizontal_flip: false, vertical_flip: true }, &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("transparent_flipped_blits.png"));
|
||||
let path = &reference_file("transparent_flipped_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -1270,11 +1270,11 @@ fn blended_transparent_flipped_blits() {
|
|||
screen.blit(TransparentFlippedBlended { transparent_color, horizontal_flip: true, vertical_flip: false, blend_map: blend_map.clone() }, &bmp, 196, 238);
|
||||
screen.blit(TransparentFlippedBlended { transparent_color, horizontal_flip: false, vertical_flip: true, blend_map: blend_map.clone() }, &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("blended_transparent_flipped_blits.png"));
|
||||
let path = &reference_file("blended_transparent_flipped_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1342,11 +1342,11 @@ fn transparent_offset_blits() {
|
|||
screen.blit(method.clone(), &bmp, 196, 238);
|
||||
screen.blit(method.clone(), &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("transparent_offset_blits.png"));
|
||||
let path = &reference_file("transparent_offset_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -1415,11 +1415,11 @@ fn transparent_flipped_offset_blits() {
|
|||
screen.blit(TransparentFlippedOffset { transparent_color, offset, horizontal_flip: true, vertical_flip: false }, &bmp, 196, 238);
|
||||
screen.blit(TransparentFlippedOffset { transparent_color, offset, horizontal_flip: false, vertical_flip: true }, &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("transparent_flipped_offset_blits.png"));
|
||||
let path = &reference_file("transparent_flipped_offset_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1487,11 +1487,11 @@ fn transparent_single_blits() {
|
|||
screen.blit(method.clone(), &bmp, 196, 238);
|
||||
screen.blit(method.clone(), &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("transparent_single_blits.png"));
|
||||
let path = &reference_file("transparent_single_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -1560,11 +1560,11 @@ fn transparent_flipped_single_blits() {
|
|||
screen.blit(TransparentFlippedSingle { transparent_color, draw_color, horizontal_flip: true, vertical_flip: false }, &bmp, 196, 238);
|
||||
screen.blit(TransparentFlippedSingle { transparent_color, draw_color, horizontal_flip: false, vertical_flip: true }, &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("transparent_flipped_single_blits.png"));
|
||||
let path = &reference_file("transparent_flipped_single_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1628,11 +1628,11 @@ fn rotozoom_blits() {
|
|||
screen.blit(method.clone(), &bmp, 196, 238);
|
||||
screen.blit(method.clone(), &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("rotozoom_blits.png"));
|
||||
let path = &reference_file("rotozoom_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -1697,11 +1697,11 @@ fn blended_rotozoom_blits() {
|
|||
screen.blit(method.clone(), &bmp, 196, 238);
|
||||
screen.blit(method.clone(), &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("blended_rotozoom_blits.png"));
|
||||
let path = &reference_file("blended_rotozoom_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -1768,11 +1768,11 @@ fn rotozoom_offset_blits() {
|
|||
screen.blit(method.clone(), &bmp, 196, 238);
|
||||
screen.blit(method.clone(), &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("rotozoom_offset_blits.png"));
|
||||
let path = &reference_file("rotozoom_offset_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -1839,11 +1839,11 @@ fn rotozoom_transparent_blits() {
|
|||
screen.blit(method.clone(), &bmp, 196, 238);
|
||||
screen.blit(method.clone(), &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("rotozoom_transparent_blits.png"));
|
||||
let path = &reference_file("rotozoom_transparent_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -1916,11 +1916,11 @@ fn blended_rotozoom_transparent_blits() {
|
|||
screen.blit(method.clone(), &bmp, 196, 238);
|
||||
screen.blit(method.clone(), &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("blended_rotozoom_transparent_blits.png"));
|
||||
let path = &reference_file("blended_rotozoom_transparent_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -1989,11 +1989,11 @@ fn rotozoom_transparent_offset_blits() {
|
|||
screen.blit(method.clone(), &bmp, 196, 238);
|
||||
screen.blit(method.clone(), &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("rotozoom_transparent_offset_blits.png"));
|
||||
let path = &reference_file("rotozoom_transparent_offset_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2203,11 +2203,11 @@ fn triangle_2d() {
|
|||
color,
|
||||
});
|
||||
|
||||
let path = reference_file(Path::new("triangle_2d.png"));
|
||||
let path = &reference_file("triangle_2d.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
@ -2378,11 +2378,11 @@ fn triangle_2d_solid_textured() {
|
|||
|
||||
draw_triangles(&mut screen, TriangleType::SolidTextured, Some(&texture), None);
|
||||
|
||||
let path = reference_file(Path::new("triangle_2d_solid_textured.png"));
|
||||
let path = &reference_file("triangle_2d_solid_textured.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2391,11 +2391,11 @@ fn triangle_2d_solid_blended() {
|
|||
|
||||
draw_triangles(&mut screen, TriangleType::SolidBlended, None, Some(&blend_map));
|
||||
|
||||
let path = reference_file(Path::new("triangle_2d_solid_blended.png"));
|
||||
let path = &reference_file("triangle_2d_solid_blended.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2406,9 +2406,9 @@ fn triangle_2d_solid_textured_blended() {
|
|||
|
||||
draw_triangles(&mut screen, TriangleType::SolidTexturedBlended, Some(&texture), Some(&blend_map));
|
||||
|
||||
let path = reference_file(Path::new("triangle_2d_solid_textured_blended.png"));
|
||||
let path = &reference_file("triangle_2d_solid_textured_blended.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), &palette).unwrap();
|
||||
screen.to_png_file(path, &palette).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &palette, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, &palette, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ const SCREEN_HEIGHT: u32 = 240;
|
|||
|
||||
const BASE_PATH: &str = "./tests/ref/rgba/";
|
||||
|
||||
fn reference_file(file: &Path) -> PathBuf {
|
||||
fn reference_file(file: impl AsRef<Path>) -> PathBuf {
|
||||
PathBuf::from(BASE_PATH).join(file)
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ fn setup() -> RgbaBitmap {
|
|||
}
|
||||
|
||||
fn setup_for_blending() -> RgbaBitmap {
|
||||
let (texture, _) = RgbaBitmap::load_file(test_assets_file(Path::new("texture.lbm")).as_path()).unwrap();
|
||||
let (texture, _) = RgbaBitmap::load_file(test_assets_file("texture.lbm")).unwrap();
|
||||
let mut screen = RgbaBitmap::new(SCREEN_WIDTH, SCREEN_HEIGHT).unwrap();
|
||||
for y in 0..(SCREEN_HEIGHT as f32 / texture.height() as f32).ceil() as i32 {
|
||||
for x in 0..(SCREEN_WIDTH as f32 / texture.width() as f32).ceil() as i32 {
|
||||
|
@ -49,7 +49,7 @@ fn setup_for_blending() -> RgbaBitmap {
|
|||
}
|
||||
|
||||
fn setup_for_blending_half_solid_half_semi_transparent() -> RgbaBitmap {
|
||||
let (texture, _) = RgbaBitmap::load_file(test_assets_file(Path::new("texture.lbm")).as_path()).unwrap();
|
||||
let (texture, _) = RgbaBitmap::load_file(test_assets_file("texture.lbm")).unwrap();
|
||||
let mut screen = RgbaBitmap::new(SCREEN_WIDTH, SCREEN_HEIGHT).unwrap();
|
||||
for y in 0..(screen.height() as f32 / texture.height() as f32).ceil() as i32 {
|
||||
for x in 0..(screen.width() as f32 / texture.width() as f32).ceil() as i32 {
|
||||
|
@ -69,7 +69,7 @@ fn setup_for_blending_half_solid_half_semi_transparent() -> RgbaBitmap {
|
|||
screen
|
||||
}
|
||||
|
||||
fn verify_visual(screen: &RgbaBitmap, source: &Path) -> bool {
|
||||
fn verify_visual(screen: &RgbaBitmap, source: impl AsRef<Path>) -> bool {
|
||||
let (source_bmp, _) = RgbaBitmap::load_file(source).unwrap();
|
||||
*screen == source_bmp
|
||||
}
|
||||
|
@ -115,11 +115,11 @@ fn pixel_addressing() {
|
|||
}
|
||||
}
|
||||
|
||||
let path = reference_file(Path::new("pixel_addressing.png"));
|
||||
let path = &reference_file("pixel_addressing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -169,11 +169,11 @@ fn pixel_drawing() {
|
|||
screen.set_pixel(160, i + 234, COLOR_BRIGHT_WHITE);
|
||||
}
|
||||
|
||||
let path = reference_file(Path::new("pixel_drawing.png"));
|
||||
let path = &reference_file("pixel_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -207,11 +207,11 @@ fn blended_pixel_drawing() {
|
|||
screen.set_blended_pixel(160, i + 234, COLOR_BRIGHT_WHITE_HALF_ALPHA, blend);
|
||||
}
|
||||
|
||||
let path = reference_file(Path::new("blended_pixel_drawing.png"));
|
||||
let path = &reference_file("blended_pixel_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -229,11 +229,11 @@ fn horiz_line_drawing() {
|
|||
screen.horiz_line(100, 200, -10, COLOR_BROWN);
|
||||
screen.horiz_line(20, 80, 250, COLOR_DARK_GRAY);
|
||||
|
||||
let path = reference_file(Path::new("horiz_line_drawing.png"));
|
||||
let path = &reference_file("horiz_line_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -253,11 +253,11 @@ fn blended_horiz_line_drawing() {
|
|||
screen.blended_horiz_line(100, 200, -10, COLOR_BROWN_HALF_ALPHA, blend);
|
||||
screen.blended_horiz_line(20, 80, 250, COLOR_LIGHT_GRAY_HALF_ALPHA, blend);
|
||||
|
||||
let path = reference_file(Path::new("blended_horiz_line_drawing.png"));
|
||||
let path = &reference_file("blended_horiz_line_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -275,11 +275,11 @@ fn vert_line_drawing() {
|
|||
screen.vert_line(-17, 10, 20, COLOR_BROWN);
|
||||
screen.vert_line(400, 100, 300, COLOR_LIGHT_GRAY);
|
||||
|
||||
let path = reference_file(Path::new("vert_line_drawing.png"));
|
||||
let path = &reference_file("vert_line_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -299,11 +299,11 @@ fn blended_vert_line_drawing() {
|
|||
screen.blended_vert_line(-17, 10, 20, COLOR_BROWN_HALF_ALPHA, blend);
|
||||
screen.blended_vert_line(400, 100, 300, COLOR_LIGHT_GRAY_HALF_ALPHA, blend);
|
||||
|
||||
let path = reference_file(Path::new("blended_vert_line_drawing.png"));
|
||||
let path = &reference_file("blended_vert_line_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -338,11 +338,11 @@ fn line_drawing() {
|
|||
screen.line(-100, 120, -100, 239, COLOR_CYAN);
|
||||
screen.line(320, 99, 320, 199, COLOR_MAGENTA);
|
||||
|
||||
let path = reference_file(Path::new("line_drawing.png"));
|
||||
let path = &reference_file("line_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -379,11 +379,11 @@ fn blended_line_drawing() {
|
|||
screen.blended_line(-100, 120, -100, 239, COLOR_CYAN_HALF_ALPHA, blend);
|
||||
screen.blended_line(320, 99, 320, 199, COLOR_MAGENTA_HALF_ALPHA, blend);
|
||||
|
||||
let path = reference_file(Path::new("blended_line_drawing.png"));
|
||||
let path = &reference_file("blended_line_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -409,11 +409,11 @@ fn rect_drawing() {
|
|||
screen.rect(300, 20, 340, -20, COLOR_BRIGHT_MAGENTA);
|
||||
screen.rect(20, 220, -20, 260, COLOR_BRIGHT_YELLOW);
|
||||
|
||||
let path = reference_file(Path::new("rect_drawing.png"));
|
||||
let path = &reference_file("rect_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -441,11 +441,11 @@ fn blended_rect_drawing() {
|
|||
screen.blended_rect(300, 20, 340, -20, COLOR_BRIGHT_MAGENTA_HALF_ALPHA, blend);
|
||||
screen.blended_rect(20, 220, -20, 260, COLOR_BRIGHT_YELLOW_HALF_ALPHA, blend);
|
||||
|
||||
let path = reference_file(Path::new("blended_rect_drawing.png"));
|
||||
let path = &reference_file("blended_rect_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -471,11 +471,11 @@ fn filled_rect_drawing() {
|
|||
screen.filled_rect(300, 20, 340, -20, COLOR_BRIGHT_MAGENTA);
|
||||
screen.filled_rect(20, 220, -20, 260, COLOR_BRIGHT_YELLOW);
|
||||
|
||||
let path = reference_file(Path::new("filled_rect_drawing.png"));
|
||||
let path = &reference_file("filled_rect_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -503,11 +503,11 @@ fn blended_filled_rect_drawing() {
|
|||
screen.blended_filled_rect(300, 20, 340, -20, COLOR_BRIGHT_MAGENTA_HALF_ALPHA, blend);
|
||||
screen.blended_filled_rect(20, 220, -20, 260, COLOR_BRIGHT_YELLOW_HALF_ALPHA, blend);
|
||||
|
||||
let path = reference_file(Path::new("blended_filled_rect_drawing.png"));
|
||||
let path = &reference_file("blended_filled_rect_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -528,11 +528,11 @@ fn circle_drawing() {
|
|||
screen.circle(319, 1, 22, COLOR_BRIGHT_BLUE);
|
||||
screen.circle(2, 242, 19, COLOR_BRIGHT_GREEN);
|
||||
|
||||
let path = reference_file(Path::new("circle_drawing.png"));
|
||||
let path = &reference_file("circle_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -553,11 +553,11 @@ fn filled_circle_drawing() {
|
|||
screen.filled_circle(319, 1, 22, COLOR_BRIGHT_BLUE);
|
||||
screen.filled_circle(2, 242, 19, COLOR_BRIGHT_GREEN);
|
||||
|
||||
let path = reference_file(Path::new("filled_circle_drawing.png"));
|
||||
let path = &reference_file("filled_circle_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -565,8 +565,8 @@ fn text_drawing() {
|
|||
let mut screen = setup();
|
||||
|
||||
let font = BitmaskFont::new_vga_font().unwrap();
|
||||
let small_font = BitmaskFont::load_from_file(test_assets_file(Path::new("small.fnt")).as_path()).unwrap();
|
||||
let chunky_font = BitmaskFont::load_from_file(test_assets_file(Path::new("chunky.fnt")).as_path()).unwrap();
|
||||
let small_font = BitmaskFont::load_from_file(test_assets_file("small.fnt")).unwrap();
|
||||
let chunky_font = BitmaskFont::load_from_file(test_assets_file("chunky.fnt")).unwrap();
|
||||
|
||||
let message = "Hello, world! HELLO, WORLD!\nTesting 123";
|
||||
|
||||
|
@ -606,11 +606,11 @@ fn text_drawing() {
|
|||
screen.print_string(message, 360, 120, FontRenderOpts::Color(COLOR_LIGHT_GRAY), &font);
|
||||
screen.print_string(message, 200, 250, FontRenderOpts::Color(COLOR_DARK_GRAY), &font);
|
||||
|
||||
let path = reference_file(Path::new("text_drawing.png"));
|
||||
let path = &reference_file("text_drawing.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
fn generate_bitmap(width: i32, height: i32) -> RgbaBitmap {
|
||||
|
@ -737,11 +737,11 @@ fn solid_blits() {
|
|||
screen.blit(method.clone(), &bmp16, 196, 238);
|
||||
screen.blit(method.clone(), &bmp16, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("solid_blits.png"));
|
||||
let path = &reference_file("solid_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -808,11 +808,11 @@ fn solid_tinted_blits() {
|
|||
screen.blit(method.clone(), &bmp16, 196, 238);
|
||||
screen.blit(method.clone(), &bmp16, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("solid_tinted_blits.png"));
|
||||
let path = &reference_file("solid_tinted_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -878,11 +878,11 @@ fn blended_solid_blits() {
|
|||
screen.blit(method.clone(), &bmp16, 196, 238);
|
||||
screen.blit(method.clone(), &bmp16, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("blended_solid_blits.png"));
|
||||
let path = &reference_file("blended_solid_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -944,11 +944,11 @@ fn solid_flipped_blits() {
|
|||
screen.blit(SolidFlipped { horizontal_flip: true, vertical_flip: false }, &bmp, 196, 238);
|
||||
screen.blit(SolidFlipped { horizontal_flip: false, vertical_flip: true }, &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("solid_flipped_blits.png"));
|
||||
let path = &reference_file("solid_flipped_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -1013,11 +1013,11 @@ fn solid_flipped_tinted_blits() {
|
|||
screen.blit(SolidFlippedTinted { tint_color, horizontal_flip: true, vertical_flip: false }, &bmp, 196, 238);
|
||||
screen.blit(SolidFlippedTinted { tint_color, horizontal_flip: false, vertical_flip: true }, &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("solid_flipped_tinted_blits.png"));
|
||||
let path = &reference_file("solid_flipped_tinted_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -1081,11 +1081,11 @@ fn blended_solid_flipped_blits() {
|
|||
screen.blit(SolidFlippedBlended { horizontal_flip: true, vertical_flip: false, blend }, &bmp, 196, 238);
|
||||
screen.blit(SolidFlippedBlended { horizontal_flip: false, vertical_flip: true, blend }, &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("blended_solid_flipped_blits.png"));
|
||||
let path = &reference_file("blended_solid_flipped_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1152,11 +1152,11 @@ fn transparent_blits() {
|
|||
screen.blit(method.clone(), &bmp16, 196, 238);
|
||||
screen.blit(method.clone(), &bmp16, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("transparent_blits.png"));
|
||||
let path = &reference_file("transparent_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1226,11 +1226,11 @@ fn transparent_tinted_blits() {
|
|||
screen.blit(method.clone(), &bmp16, 196, 238);
|
||||
screen.blit(method.clone(), &bmp16, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("transparent_tinted_blits.png"));
|
||||
let path = &reference_file("transparent_tinted_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1296,11 +1296,11 @@ fn blended_transparent_blits() {
|
|||
screen.blit(method.clone(), &bmp16, 196, 238);
|
||||
screen.blit(method.clone(), &bmp16, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("blended_transparent_blits.png"));
|
||||
let path = &reference_file("blended_transparent_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -1365,11 +1365,11 @@ fn transparent_flipped_blits() {
|
|||
screen.blit(TransparentFlipped { transparent_color, horizontal_flip: true, vertical_flip: false }, &bmp, 196, 238);
|
||||
screen.blit(TransparentFlipped { transparent_color, horizontal_flip: false, vertical_flip: true }, &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("transparent_flipped_blits.png"));
|
||||
let path = &reference_file("transparent_flipped_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -1435,11 +1435,11 @@ fn transparent_flipped_tinted_blits() {
|
|||
screen.blit(TransparentFlippedTinted { transparent_color, tint_color, horizontal_flip: true, vertical_flip: false }, &bmp, 196, 238);
|
||||
screen.blit(TransparentFlippedTinted { transparent_color, tint_color, horizontal_flip: false, vertical_flip: true }, &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("transparent_flipped_tinted_blits.png"));
|
||||
let path = &reference_file("transparent_flipped_tinted_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -1504,11 +1504,11 @@ fn blended_transparent_flipped_blits() {
|
|||
screen.blit(TransparentFlippedBlended { transparent_color, horizontal_flip: true, vertical_flip: false, blend }, &bmp, 196, 238);
|
||||
screen.blit(TransparentFlippedBlended { transparent_color, horizontal_flip: false, vertical_flip: true, blend }, &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("blended_transparent_flipped_blits.png"));
|
||||
let path = &reference_file("blended_transparent_flipped_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -1577,11 +1577,11 @@ fn transparent_single_blits() {
|
|||
screen.blit(method.clone(), &bmp, 196, 238);
|
||||
screen.blit(method.clone(), &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("transparent_single_blits.png"));
|
||||
let path = &reference_file("transparent_single_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -1646,11 +1646,11 @@ fn transparent_flipped_single_blits() {
|
|||
screen.blit(TransparentFlippedSingle { transparent_color, draw_color: COLOR_BRIGHT_GREEN, horizontal_flip: true, vertical_flip: false }, &bmp, 196, 238);
|
||||
screen.blit(TransparentFlippedSingle { transparent_color, draw_color: COLOR_BRIGHT_GREEN, horizontal_flip: false, vertical_flip: true }, &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("transparent_flipped_single_blits.png"));
|
||||
let path = &reference_file("transparent_flipped_single_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1714,11 +1714,11 @@ fn rotozoom_blits() {
|
|||
screen.blit(method.clone(), &bmp, 196, 238);
|
||||
screen.blit(method.clone(), &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("rotozoom_blits.png"));
|
||||
let path = &reference_file("rotozoom_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -1785,11 +1785,11 @@ fn rotozoom_tinted_blits() {
|
|||
screen.blit(method.clone(), &bmp, 196, 238);
|
||||
screen.blit(method.clone(), &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("rotozoom_tinted_blits.png"));
|
||||
let path = &reference_file("rotozoom_tinted_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1854,11 +1854,11 @@ fn blended_rotozoom_blits() {
|
|||
screen.blit(method.clone(), &bmp, 196, 238);
|
||||
screen.blit(method.clone(), &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("blended_rotozoom_blits.png"));
|
||||
let path = &reference_file("blended_rotozoom_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -1925,11 +1925,11 @@ fn rotozoom_transparent_blits() {
|
|||
screen.blit(method.clone(), &bmp, 196, 238);
|
||||
screen.blit(method.clone(), &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("rotozoom_transparent_blits.png"));
|
||||
let path = &reference_file("rotozoom_transparent_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -1997,11 +1997,11 @@ fn rotozoom_transparent_tinted_blits() {
|
|||
screen.blit(method.clone(), &bmp, 196, 238);
|
||||
screen.blit(method.clone(), &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("rotozoom_transparent_tinted_blits.png"));
|
||||
let path = &reference_file("rotozoom_transparent_tinted_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -2068,11 +2068,11 @@ fn blended_rotozoom_transparent_blits() {
|
|||
screen.blit(method.clone(), &bmp, 196, 238);
|
||||
screen.blit(method.clone(), &bmp, 226, 240);
|
||||
|
||||
let path = reference_file(Path::new("blended_rotozoom_transparent_blits.png"));
|
||||
let path = &reference_file("blended_rotozoom_transparent_blits.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2095,11 +2095,11 @@ fn blend_function_blend() {
|
|||
screen.blit(method.clone(), &bmp_solid_with_varied_alpha, 100, 130);
|
||||
screen.blit(method.clone(), &bmp_with_varied_alpha, 200, 130);
|
||||
|
||||
let path = reference_file(Path::new("blend_function_blend.png"));
|
||||
let path = &reference_file("blend_function_blend.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2142,11 +2142,11 @@ fn blend_function_tinted_blend() {
|
|||
screen.blit(method.clone(), &bmp_solid_with_varied_alpha, 100, 195);
|
||||
screen.blit(method.clone(), &bmp_with_varied_alpha, 200, 195);
|
||||
|
||||
let path = reference_file(Path::new("blend_function_tinted_blend.png"));
|
||||
let path = &reference_file("blend_function_tinted_blend.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2189,11 +2189,11 @@ fn blend_function_blend_source_with_alpha() {
|
|||
screen.blit(method.clone(), &bmp_solid_with_varied_alpha, 100, 195);
|
||||
screen.blit(method.clone(), &bmp_with_varied_alpha, 200, 195);
|
||||
|
||||
let path = reference_file(Path::new("blend_function_blend_source_with_alpha.png"));
|
||||
let path = &reference_file("blend_function_blend_source_with_alpha.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2236,11 +2236,11 @@ fn blend_function_multiplied_blend() {
|
|||
screen.blit(method.clone(), &bmp_solid_with_varied_alpha, 100, 195);
|
||||
screen.blit(method.clone(), &bmp_with_varied_alpha, 200, 195);
|
||||
|
||||
let path = reference_file(Path::new("blend_function_multiplied_blend.png"));
|
||||
let path = &reference_file("blend_function_multiplied_blend.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2450,11 +2450,11 @@ fn triangle_2d() {
|
|||
color,
|
||||
});
|
||||
|
||||
let path = reference_file(Path::new("triangle_2d.png"));
|
||||
let path = &reference_file("triangle_2d.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
@ -2716,11 +2716,11 @@ fn triangle_2d_solid_blended() {
|
|||
|
||||
draw_triangles(&mut screen, TriangleType::SolidBlended, None);
|
||||
|
||||
let path = reference_file(Path::new("triangle_2d_solid_blended.png"));
|
||||
let path = &reference_file("triangle_2d_solid_blended.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2729,11 +2729,11 @@ fn triangle_2d_solid_multicolor_blended() {
|
|||
|
||||
draw_triangles(&mut screen, TriangleType::SolidMultiColorBlended, None);
|
||||
|
||||
let path = reference_file(Path::new("triangle_2d_solid_multicolor_blended.png"));
|
||||
let path = &reference_file("triangle_2d_solid_multicolor_blended.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2745,11 +2745,11 @@ fn triangle_2d_solid_textured() {
|
|||
|
||||
draw_triangles(&mut screen, TriangleType::SolidTextured, Some(&texture));
|
||||
|
||||
let path = reference_file(Path::new("triangle_2d_solid_textured.png"));
|
||||
let path = &reference_file("triangle_2d_solid_textured.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2761,11 +2761,11 @@ fn triangle_2d_solid_textured_colored() {
|
|||
|
||||
draw_triangles(&mut screen, TriangleType::SolidTexturedColored, Some(&texture));
|
||||
|
||||
let path = reference_file(Path::new("triangle_2d_solid_textured_colored.png"));
|
||||
let path = &reference_file("triangle_2d_solid_textured_colored.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2776,11 +2776,11 @@ fn triangle_2d_solid_textured_colored_blended() {
|
|||
|
||||
draw_triangles(&mut screen, TriangleType::SolidTexturedColoredBlended, Some(&texture));
|
||||
|
||||
let path = reference_file(Path::new("triangle_2d_solid_textured_colored_blended.png"));
|
||||
let path = &reference_file("triangle_2d_solid_textured_colored_blended.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2792,11 +2792,11 @@ fn triangle_2d_solid_textured_multicolored() {
|
|||
|
||||
draw_triangles(&mut screen, TriangleType::SolidTexturedMultiColored, Some(&texture));
|
||||
|
||||
let path = reference_file(Path::new("triangle_2d_solid_textured_multicolored.png"));
|
||||
let path = &reference_file("triangle_2d_solid_textured_multicolored.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2807,11 +2807,11 @@ fn triangle_2d_solid_textured_multicolored_blended() {
|
|||
|
||||
draw_triangles(&mut screen, TriangleType::SolidTexturedMultiColoredBlended, Some(&texture));
|
||||
|
||||
let path = reference_file(Path::new("triangle_2d_solid_textured_multicolored_blended.png"));
|
||||
let path = &reference_file("triangle_2d_solid_textured_multicolored_blended.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2823,11 +2823,11 @@ fn triangle_2d_solid_textured_tinted() {
|
|||
|
||||
draw_triangles(&mut screen, TriangleType::SolidTexturedTinted, Some(&texture));
|
||||
|
||||
let path = reference_file(Path::new("triangle_2d_solid_textured_tinted.png"));
|
||||
let path = &reference_file("triangle_2d_solid_textured_tinted.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2838,9 +2838,9 @@ fn triangle_2d_solid_textured_blended() {
|
|||
|
||||
draw_triangles(&mut screen, TriangleType::SolidTexturedBlended, Some(&texture));
|
||||
|
||||
let path = reference_file(Path::new("triangle_2d_solid_textured_blended.png"));
|
||||
let path = &reference_file("triangle_2d_solid_textured_blended.png");
|
||||
if cfg!(recreate_ref_test_images) {
|
||||
screen.to_png_file(path.as_path(), PngFormat::RGBA).unwrap();
|
||||
screen.to_png_file(path, PngFormat::RGBA).unwrap();
|
||||
}
|
||||
assert!(verify_visual(&screen, &path), "bitmap differs from source image: {:?}", path);
|
||||
assert!(verify_visual(&screen, path), "bitmap differs from source image: {:?}", path);
|
||||
}
|
||||
|
|
|
@ -8,15 +8,15 @@ use byteorder::{LittleEndian, ReadBytesExt};
|
|||
const ASSETS_PATH: &str = "./assets/";
|
||||
const TEST_ASSETS_PATH: &str = "./test-assets/";
|
||||
|
||||
pub fn assets_file(file: &Path) -> PathBuf {
|
||||
pub fn assets_file(file: impl AsRef<Path>) -> PathBuf {
|
||||
PathBuf::from(ASSETS_PATH).join(file)
|
||||
}
|
||||
|
||||
pub fn test_assets_file(file: &Path) -> PathBuf {
|
||||
pub fn test_assets_file(file: impl AsRef<Path>) -> PathBuf {
|
||||
PathBuf::from(TEST_ASSETS_PATH).join(file)
|
||||
}
|
||||
|
||||
pub fn load_raw_indexed(bin_file: &Path) -> Result<Box<[u8]>, io::Error> {
|
||||
pub fn load_raw_indexed(bin_file: impl AsRef<Path>) -> Result<Box<[u8]>, io::Error> {
|
||||
let f = File::open(bin_file)?;
|
||||
let mut reader = BufReader::new(f);
|
||||
let mut buffer = Vec::new();
|
||||
|
@ -24,7 +24,7 @@ pub fn load_raw_indexed(bin_file: &Path) -> Result<Box<[u8]>, io::Error> {
|
|||
Ok(buffer.into_boxed_slice())
|
||||
}
|
||||
|
||||
pub fn load_raw_rgba(bin_file: &Path) -> Result<Box<[u32]>, io::Error> {
|
||||
pub fn load_raw_rgba(bin_file: impl AsRef<Path>) -> Result<Box<[u32]>, io::Error> {
|
||||
let f = File::open(bin_file)?;
|
||||
let mut reader = BufReader::new(f);
|
||||
let mut buffer = Vec::new();
|
||||
|
|
Loading…
Reference in a new issue