Added support for JPEG backgrounds

This commit is contained in:
Joshua Barretto 2021-06-18 12:27:39 +01:00
parent 2b269c7556
commit 38907a8bf2
16 changed files with 9 additions and 6 deletions

2
.gitattributes vendored
View File

@ -1,4 +1,6 @@
*.png filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text
*.jpeg filter=lfs diff=lfs merge=lfs -text
*.vox filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.wav filter=lfs diff=lfs merge=lfs -text

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1018 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 493 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 939 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 877 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 644 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 914 KiB

View File

@ -97,19 +97,20 @@ impl Image {
pub fn to_image(&self) -> Arc<DynamicImage> { Arc::clone(&self.0) }
}
pub struct PngLoader;
impl Loader<Image> for PngLoader {
fn load(content: Cow<[u8]>, _: &str) -> Result<Image, BoxedError> {
let format = image::ImageFormat::Png;
pub struct ImageLoader;
impl Loader<Image> for ImageLoader {
fn load(content: Cow<[u8]>, ext: &str) -> Result<Image, BoxedError> {
let format = image::ImageFormat::from_extension(ext)
.ok_or_else(|| format!("Invalid file extension {}", ext))?;
let image = image::load_from_memory_with_format(&content, format)?;
Ok(Image(Arc::new(image)))
}
}
impl Asset for Image {
type Loader = PngLoader;
type Loader = ImageLoader;
const EXTENSION: &'static str = "png";
const EXTENSIONS: &'static [&'static str] = &["png", "jpg", "jpeg"];
}
pub struct DotVoxAsset(pub DotVoxData);