allow png files to be loaded via IndexedBitmap::load_file

This commit is contained in:
Gered 2023-03-21 15:23:47 -04:00
parent 6829800caa
commit b6e69ca084
2 changed files with 7 additions and 0 deletions

View file

@ -26,6 +26,10 @@ impl IndexedBitmap {
if let Some(extension) = path.extension() { if let Some(extension) = path.extension() {
let extension = extension.to_ascii_lowercase(); let extension = extension.to_ascii_lowercase();
match extension.to_str() { match extension.to_str() {
Some("png") => {
let (bmp, palette) = Self::load_png_file(path)?;
Ok((bmp, palette.expect("Indexed color PNG loaded and should have returned a Palette")))
},
Some("pcx") => Ok(Self::load_pcx_file(path)?), Some("pcx") => Ok(Self::load_pcx_file(path)?),
Some("gif") => Ok(Self::load_gif_file(path)?), Some("gif") => Ok(Self::load_gif_file(path)?),
Some("iff") | Some("lbm") | Some("pbm") | Some("bbm") => { Some("iff") | Some("lbm") | Some("pbm") | Some("bbm") => {

View file

@ -32,6 +32,9 @@ pub enum BitmapError {
#[error("Bitmap GIF file error")] #[error("Bitmap GIF file error")]
GifError(#[from] gif::GifError), GifError(#[from] gif::GifError),
#[error("Bitmap PNG file error")]
PngError(#[from] png::PngError),
} }
/// Container for 256 color 2D pixel/image data that can be rendered to the screen. Pixel data /// Container for 256 color 2D pixel/image data that can be rendered to the screen. Pixel data