update image to 0.24 (#4121)
# Objective - update image to 0.24 ## Solution - `Bgra*` variants support have been removed from image, remove them from Bevy code - replace #4003 changeling: https://github.com/image-rs/image/blob/master/CHANGES.md
This commit is contained in:
parent
99e689cfd2
commit
d353fbc6ea
@ -41,7 +41,7 @@ bevy_window = { path = "../bevy_window", version = "0.8.0-dev" }
|
|||||||
bevy_utils = { path = "../bevy_utils", version = "0.8.0-dev" }
|
bevy_utils = { path = "../bevy_utils", version = "0.8.0-dev" }
|
||||||
|
|
||||||
# rendering
|
# rendering
|
||||||
image = { version = "0.23.12", default-features = false }
|
image = { version = "0.24", default-features = false }
|
||||||
|
|
||||||
# misc
|
# misc
|
||||||
wgpu = { version = "0.12.0", features = ["spirv"] }
|
wgpu = { version = "0.12.0", features = ["spirv"] }
|
||||||
|
|||||||
@ -22,7 +22,7 @@ impl AssetLoader for HdrTextureLoader {
|
|||||||
"Format should have 32bit x 4 size"
|
"Format should have 32bit x 4 size"
|
||||||
);
|
);
|
||||||
|
|
||||||
let decoder = image::hdr::HdrDecoder::new(bytes)?;
|
let decoder = image::codecs::hdr::HdrDecoder::new(bytes)?;
|
||||||
let info = decoder.metadata();
|
let info = decoder.metadata();
|
||||||
let rgb_data = decoder.read_image_hdr()?;
|
let rgb_data = decoder.read_image_hdr()?;
|
||||||
let mut rgba_data = Vec::with_capacity(rgb_data.len() * format.pixel_size());
|
let mut rgba_data = Vec::with_capacity(rgb_data.len() * format.pixel_size());
|
||||||
|
|||||||
@ -260,7 +260,6 @@ impl Image {
|
|||||||
/// - `TextureFormat::R8Unorm`
|
/// - `TextureFormat::R8Unorm`
|
||||||
/// - `TextureFormat::Rg8Unorm`
|
/// - `TextureFormat::Rg8Unorm`
|
||||||
/// - `TextureFormat::Rgba8UnormSrgb`
|
/// - `TextureFormat::Rgba8UnormSrgb`
|
||||||
/// - `TextureFormat::Bgra8UnormSrgb`
|
|
||||||
pub fn convert(&self, new_format: TextureFormat) -> Option<Self> {
|
pub fn convert(&self, new_format: TextureFormat) -> Option<Self> {
|
||||||
super::image_texture_conversion::texture_to_image(self)
|
super::image_texture_conversion::texture_to_image(self)
|
||||||
.and_then(|img| match new_format {
|
.and_then(|img| match new_format {
|
||||||
@ -274,9 +273,6 @@ impl Image {
|
|||||||
TextureFormat::Rgba8UnormSrgb => {
|
TextureFormat::Rgba8UnormSrgb => {
|
||||||
Some((image::DynamicImage::ImageRgba8(img.into_rgba8()), true))
|
Some((image::DynamicImage::ImageRgba8(img.into_rgba8()), true))
|
||||||
}
|
}
|
||||||
TextureFormat::Bgra8UnormSrgb => {
|
|
||||||
Some((image::DynamicImage::ImageBgra8(img.into_bgra8()), true))
|
|
||||||
}
|
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.map(|(dyn_img, is_srgb)| {
|
.map(|(dyn_img, is_srgb)| {
|
||||||
|
|||||||
@ -60,30 +60,6 @@ pub(crate) fn image_to_texture(dyn_img: DynamicImage, is_srgb: bool) -> Image {
|
|||||||
|
|
||||||
data = i.into_raw();
|
data = i.into_raw();
|
||||||
}
|
}
|
||||||
DynamicImage::ImageBgr8(i) => {
|
|
||||||
let i = DynamicImage::ImageBgr8(i).into_bgra8();
|
|
||||||
|
|
||||||
width = i.width();
|
|
||||||
height = i.height();
|
|
||||||
format = if is_srgb {
|
|
||||||
TextureFormat::Bgra8UnormSrgb
|
|
||||||
} else {
|
|
||||||
TextureFormat::Bgra8Unorm
|
|
||||||
};
|
|
||||||
|
|
||||||
data = i.into_raw();
|
|
||||||
}
|
|
||||||
DynamicImage::ImageBgra8(i) => {
|
|
||||||
width = i.width();
|
|
||||||
height = i.height();
|
|
||||||
format = if is_srgb {
|
|
||||||
TextureFormat::Bgra8UnormSrgb
|
|
||||||
} else {
|
|
||||||
TextureFormat::Bgra8Unorm
|
|
||||||
};
|
|
||||||
|
|
||||||
data = i.into_raw();
|
|
||||||
}
|
|
||||||
DynamicImage::ImageLuma16(i) => {
|
DynamicImage::ImageLuma16(i) => {
|
||||||
width = i.width();
|
width = i.width();
|
||||||
height = i.height();
|
height = i.height();
|
||||||
@ -135,6 +111,48 @@ pub(crate) fn image_to_texture(dyn_img: DynamicImage, is_srgb: bool) -> Image {
|
|||||||
|
|
||||||
data = cast_slice(&raw_data).to_owned();
|
data = cast_slice(&raw_data).to_owned();
|
||||||
}
|
}
|
||||||
|
DynamicImage::ImageRgb32F(image) => {
|
||||||
|
width = image.width();
|
||||||
|
height = image.height();
|
||||||
|
format = TextureFormat::Rgba32Float;
|
||||||
|
|
||||||
|
let mut local_data =
|
||||||
|
Vec::with_capacity(width as usize * height as usize * format.pixel_size());
|
||||||
|
|
||||||
|
for pixel in image.into_raw().chunks_exact(3) {
|
||||||
|
// TODO: use the array_chunks method once stabilised
|
||||||
|
// https://github.com/rust-lang/rust/issues/74985
|
||||||
|
let r = pixel[0];
|
||||||
|
let g = pixel[1];
|
||||||
|
let b = pixel[2];
|
||||||
|
let a = u16::max_value();
|
||||||
|
|
||||||
|
local_data.extend_from_slice(&r.to_ne_bytes());
|
||||||
|
local_data.extend_from_slice(&g.to_ne_bytes());
|
||||||
|
local_data.extend_from_slice(&b.to_ne_bytes());
|
||||||
|
local_data.extend_from_slice(&a.to_ne_bytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
data = local_data;
|
||||||
|
}
|
||||||
|
DynamicImage::ImageRgba32F(image) => {
|
||||||
|
width = image.width();
|
||||||
|
height = image.height();
|
||||||
|
format = TextureFormat::Rgba32Float;
|
||||||
|
|
||||||
|
let raw_data = image.into_raw();
|
||||||
|
|
||||||
|
data = cast_slice(&raw_data).to_owned();
|
||||||
|
}
|
||||||
|
// DynamicImage is now non exhaustive, catch future variants and convert them
|
||||||
|
_ => {
|
||||||
|
let image = dyn_img.into_rgba8();
|
||||||
|
width = image.width();
|
||||||
|
height = image.height();
|
||||||
|
format = TextureFormat::Rgba8UnormSrgb;
|
||||||
|
|
||||||
|
data = image.into_raw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Image::new(
|
Image::new(
|
||||||
@ -171,12 +189,6 @@ pub(crate) fn texture_to_image(texture: &Image) -> Option<DynamicImage> {
|
|||||||
texture.data.clone(),
|
texture.data.clone(),
|
||||||
)
|
)
|
||||||
.map(DynamicImage::ImageRgba8),
|
.map(DynamicImage::ImageRgba8),
|
||||||
TextureFormat::Bgra8UnormSrgb => ImageBuffer::from_raw(
|
|
||||||
texture.texture_descriptor.size.width,
|
|
||||||
texture.texture_descriptor.size.height,
|
|
||||||
texture.data.clone(),
|
|
||||||
)
|
|
||||||
.map(DynamicImage::ImageBgra8),
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user