Skip to content

Commit

Permalink
Expose Image conversion functions (fixes #5452)
Browse files Browse the repository at this point in the history
  • Loading branch information
micron-mushroom committed Aug 1, 2022
1 parent 6752c9c commit 8e2d7f7
Show file tree
Hide file tree
Showing 2 changed files with 212 additions and 178 deletions.
11 changes: 5 additions & 6 deletions crates/bevy_render/src/texture/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use super::dds::*;
#[cfg(feature = "ktx2")]
use super::ktx2::*;

use super::image_texture_conversion::image_to_texture;
use crate::{
render_asset::{PrepareAssetError, RenderAsset},
render_resource::{Sampler, Texture, TextureView},
Expand Down Expand Up @@ -347,7 +346,9 @@ impl Image {
/// - `TextureFormat::Rg8Unorm`
/// - `TextureFormat::Rgba8UnormSrgb`
pub fn convert(&self, new_format: TextureFormat) -> Option<Self> {
super::image_texture_conversion::texture_to_image(self)
self.clone()
.try_into_dynamic()
.ok()
.and_then(|img| match new_format {
TextureFormat::R8Unorm => {
Some((image::DynamicImage::ImageLuma8(img.into_luma8()), false))
Expand All @@ -361,9 +362,7 @@ impl Image {
}
_ => None,
})
.map(|(dyn_img, is_srgb)| {
super::image_texture_conversion::image_to_texture(dyn_img, is_srgb)
})
.map(|(dyn_img, is_srgb)| Self::from_dynamic(dyn_img, is_srgb))
}

/// Load a bytes buffer in a [`Image`], according to type `image_type`, using the `image`
Expand Down Expand Up @@ -401,7 +400,7 @@ impl Image {
reader.set_format(image_crate_format);
reader.no_limits();
let dyn_img = reader.decode()?;
Ok(image_to_texture(dyn_img, is_srgb))
Ok(Self::from_dynamic(dyn_img, is_srgb))
}
}
}
Expand Down
Loading

0 comments on commit 8e2d7f7

Please sign in to comment.