bevy/crates/bevy_render/src/texture
Tianlan Zhou b1a634cade Fix alpha channel in RGB32F image texture format conversion (#6914)
# Objective

The following code:

```rs
use bevy::prelude::Image;
use image::{ DynamicImage, GenericImage, Rgba };

fn main() {
    let mut dynamic_image = DynamicImage::new_rgb32f(1, 1);
    dynamic_image.put_pixel(0, 0, Rgba([1, 1, 1, 1]));
    
    let image = Image::from_dynamic(dynamic_image, false); // Panic!
    println!("{image:?}");
}
```

Can cause an assertion failed:

```
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `16`,
 right: `14`: Pixel data, size and format have to match', .../bevy_render-0.9.1/src/texture/image.rs:209:9
stack backtrace:
...
   4: core::panicking::assert_failed<usize,usize>
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:181
   5: bevy_render::texture::image::Image::new
             at .../bevy_render-0.9.1/src/texture/image.rs:209
   6: bevy_render::texture::image::Image::from_dynamic
             at .../bevy_render-0.9.1/src/texture/image_texture_conversion.rs:159
   7: bevy_test::main
             at ./src/main.rs:8
...
```

It seems to be cause by a copypasta in `crates/bevy_render/src/texture/image_texture_conversion.rs`. Let's fix it.

## Solution

```diff
  // DynamicImage::ImageRgb32F(image) => {
- let a = u16::max_value();
+ let a = 1f32;
```

This will fix the conversion.

---

## Changelog

- Fixed the alpha channel of the `image::DynamicImage::ImageRgb32F` to `bevy_render::texture::Image` conversion in `bevy_render::texture::Image::from_dynamic()`.
2022-12-11 18:46:47 +00:00
..
basis.rs Use new let-else syntax where possible (#6463) 2022-11-04 21:32:09 +00:00
dds.rs dds: Ensure the Extent3d for compressed textures represents the physical size (#5406) 2022-07-20 22:43:36 +00:00
fallback_image.rs Make Resource trait opt-in, requiring #[derive(Resource)] V2 (#5577) 2022-08-08 21:36:35 +00:00
hdr_texture_loader.rs update image to 0.24 (#4121) 2022-05-28 02:00:55 +00:00
image.rs get pixel size from wgpu (#6820) 2022-12-11 18:22:07 +00:00
image_texture_conversion.rs Fix alpha channel in RGB32F image texture format conversion (#6914) 2022-12-11 18:46:47 +00:00
image_texture_loader.rs Do not crash if RenderDevice doesn't exist (#4427) 2022-04-05 19:37:23 +00:00
ktx2.rs fix nightly clippy warnings (#6395) 2022-10-28 21:03:01 +00:00
mod.rs bevy_reflect: Register missing reflected types for bevy_render (#6725) 2022-11-23 00:41:21 +00:00
texture_cache.rs Make Resource trait opt-in, requiring #[derive(Resource)] V2 (#5577) 2022-08-08 21:36:35 +00:00