pub(crate) fn texture_to_image(texture: &Image) -> Option<image::DynamicImage> {
    match texture.texture_descriptor.format {
        TextureFormat::R8Unorm => image::ImageBuffer::from_raw(
            texture.texture_descriptor.size.width,
            texture.texture_descriptor.size.height,
            texture.data.clone(),
        )
        .map(image::DynamicImage::ImageLuma8),
        TextureFormat::Rg8Unorm => image::ImageBuffer::from_raw(
            texture.texture_descriptor.size.width,
            texture.texture_descriptor.size.height,
            texture.data.clone(),
        )
        .map(image::DynamicImage::ImageLumaA8),
        TextureFormat::Rgba8UnormSrgb => image::ImageBuffer::from_raw(
            texture.texture_descriptor.size.width,
            texture.texture_descriptor.size.height,
            texture.data.clone(),
        )
        .map(image::DynamicImage::ImageRgba8),
        TextureFormat::Bgra8UnormSrgb => image::ImageBuffer::from_raw(
            texture.texture_descriptor.size.width,
            texture.texture_descriptor.size.height,
            texture.data.clone(),
        )
        .map(image::DynamicImage::ImageBgra8),
        _ => None,
    }
}
/// Helper method to convert a `Texture` to a `DynamicImage`. Not all `Texture` formats are
/// covered, it will return `None` if the format is not supported
Helper method to convert a `Texture` to a `DynamicImage`. Not all `Texture` formats are
covered, it will return `None` if the format is not supported
Helper method to convert a ` Texture ` to a ` DynamicImage ` . Not all ` Texture ` formats are covered it will return ` None ` if the format is not supported
pub(crate) fn texture_to_image(texture: &Image) -> Option<image::DynamicImage> {
    match texture.texture_descriptor.format {
        TextureFormat::R8Unorm => image::ImageBuffer::from_raw(
            texture.texture_descriptor.size.width,
            texture.texture_descriptor.size.height,
            texture.data.clone(),
        )
        .map(image::DynamicImage::ImageLuma8),
        TextureFormat::Rg8Unorm => image::ImageBuffer::from_raw(
            texture.texture_descriptor.size.width,
            texture.texture_descriptor.size.height,
            texture.data.clone(),
        )
        .map(image::DynamicImage::ImageLumaA8),
        TextureFormat::Rgba8UnormSrgb => image::ImageBuffer::from_raw(
            texture.texture_descriptor.size.width,
            texture.texture_descriptor.size.height,
            texture.data.clone(),
        )
        .map(image::DynamicImage::ImageRgba8),
        TextureFormat::Bgra8UnormSrgb => image::ImageBuffer::from_raw(
            texture.texture_descriptor.size.width,
            texture.texture_descriptor.size.height,
            texture.data.clone(),
        )
        .map(image::DynamicImage::ImageBgra8),
        _ => None,
    }
}
pub ( crate ) fn texture_to_image ( texture : & Image ) -> Option < image :: DynamicImage > { match texture . texture_descriptor . format { TextureFormat :: R8Unorm => image :: ImageBuffer :: from_raw ( texture . texture_descriptor . size . width , texture . texture_descriptor . size . height , texture . data . clone ( ) , ) . map ( image :: DynamicImage :: ImageLuma8 ) , TextureFormat :: Rg8Unorm => image :: ImageBuffer :: from_raw ( texture . texture_descriptor . size . width , texture . texture_descriptor . size . height , texture . data . clone ( ) , ) . map ( image :: DynamicImage :: ImageLumaA8 ) , TextureFormat :: Rgba8UnormSrgb => image :: ImageBuffer :: from_raw ( texture . texture_descriptor . size . width , texture . texture_descriptor . size . height , texture . data . clone ( ) , ) . map ( image :: DynamicImage :: ImageRgba8 ) , TextureFormat :: Bgra8UnormSrgb => image :: ImageBuffer :: from_raw ( texture . texture_descriptor . size . width , texture . texture_descriptor . size . height , texture . data . clone ( ) , ) . map ( image :: DynamicImage :: ImageBgra8 ) , _ => None , } }
Helper method to convert a `Texture` to a `DynamicImage`.
Helper method to convert a ` Texture ` to a ` DynamicImage ` .
texture
&Image
texture
&Image