Skip to content

Commit

Permalink
Update image to 0.24
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk authored and asny committed Apr 7, 2022
1 parent bb1eb9a commit 4aa06c3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ reqwest = { version = "0.11", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
gltf = { version = "1.0.0", features = ["utils"], optional = true }
wavefront_obj = { version = "10.0", optional = true }
image = { version = "0.23", optional = true, default-features = false, features = ["gif", "jpeg", "ico", "png", "pnm", "tga", "tiff", "webp", "bmp", "hdr", "dxt", "dds", "farbfeld"]}
image = { version = "0.24", optional = true, default-features = false, features = ["gif", "jpeg", "ico", "png", "pnm", "tga", "tiff", "webp", "bmp", "hdr", "dxt", "dds", "farbfeld"]}
egui = { version = "0.13", optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.build-dependencies]
Expand Down
14 changes: 5 additions & 9 deletions src/io/parser/img.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,29 @@ use std::path::Path;
///
pub fn image_from_bytes(bytes: &[u8]) -> ThreeDResult<CpuTexture> {
use image::DynamicImage;
use image::GenericImageView;
let img = image::load_from_memory(bytes)?;
let bytes = img.to_bytes();
let width = img.width();
let height = img.height();
let data = match img {
DynamicImage::ImageLuma8(_) => TextureData::RU8(bytes),
DynamicImage::ImageLuma8(_) => TextureData::RU8(img.into_bytes()),
DynamicImage::ImageLumaA8(_) => {
let bytes = img.as_bytes();
let mut data = Vec::new();
for i in 0..bytes.len() / 2 {
data.push([bytes[i * 2], bytes[i * 2 + 1]]);
}
TextureData::RgU8(data)
}
DynamicImage::ImageRgb8(_) => {
let bytes = img.as_bytes();
let mut data = Vec::new();
for i in 0..bytes.len() / 3 {
data.push([bytes[i * 3], bytes[i * 3 + 1], bytes[i * 3 + 2]]);
}
TextureData::RgbU8(data)
}
DynamicImage::ImageRgba8(_) => {
let bytes = img.as_bytes();
let mut data = Vec::new();
for i in 0..bytes.len() / 4 {
data.push([
Expand All @@ -44,12 +45,7 @@ pub fn image_from_bytes(bytes: &[u8]) -> ThreeDResult<CpuTexture> {
}
TextureData::RgbaU8(data)
}
DynamicImage::ImageBgr8(_) => unimplemented!(),
DynamicImage::ImageBgra8(_) => unimplemented!(),
DynamicImage::ImageLuma16(_) => unimplemented!(),
DynamicImage::ImageLumaA16(_) => unimplemented!(),
DynamicImage::ImageRgb16(_) => unimplemented!(),
DynamicImage::ImageRgba16(_) => unimplemented!(),
_ => unimplemented!(),
};
Ok(CpuTexture {
data,
Expand Down

0 comments on commit 4aa06c3

Please sign in to comment.