add RgbaBitmap::load_file
This commit is contained in:
parent
04f57cf8da
commit
ec437974ee
|
@ -1,4 +1,7 @@
|
|||
use std::path::Path;
|
||||
|
||||
use crate::graphics::bitmap::{Bitmap, BitmapError};
|
||||
use crate::graphics::palette::Palette;
|
||||
|
||||
pub mod blit;
|
||||
|
||||
|
@ -16,4 +19,32 @@ impl RgbaBitmap {
|
|||
pub fn new(width: u32, height: u32) -> Result<Self, BitmapError> {
|
||||
Self::internal_new(width, height)
|
||||
}
|
||||
|
||||
pub fn load_file(path: &Path) -> Result<(Self, Option<Palette>), BitmapError> {
|
||||
if let Some(extension) = path.extension() {
|
||||
let extension = extension.to_ascii_lowercase();
|
||||
match extension.to_str() {
|
||||
Some("png") => Ok(Self::load_png_file(path)?),
|
||||
Some("pcx") => {
|
||||
let (bmp, palette) = Self::load_pcx_file(path)?;
|
||||
Ok((bmp, Some(palette)))
|
||||
},
|
||||
Some("gif") => {
|
||||
let (bmp, palette) = Self::load_gif_file(path)?;
|
||||
Ok((bmp, Some(palette)))
|
||||
},
|
||||
Some("iff") | Some("lbm") | Some("pbm") | Some("bbm") => {
|
||||
let (bmp, palette) = Self::load_iff_file(path)?;
|
||||
Ok((bmp, Some(palette)))
|
||||
}
|
||||
_ => Err(BitmapError::UnknownFileType(String::from(
|
||||
"Unrecognized file extension",
|
||||
))),
|
||||
}
|
||||
} else {
|
||||
Err(BitmapError::UnknownFileType(String::from(
|
||||
"No file extension",
|
||||
)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue