Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update image requirement from 0.24 to 0.25 #12458

Merged
merged 5 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bevy_render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" }
bevy_tasks = { path = "../bevy_tasks", version = "0.14.0-dev" }

# rendering
image = { version = "0.24", default-features = false }
image = { version = "0.25", default-features = false }

# misc
codespan-reporting = "0.11.0"
Expand Down
15 changes: 12 additions & 3 deletions crates/bevy_render/src/texture/hdr_texture_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{
texture::{Image, TextureFormatPixelInfo},
};
use bevy_asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext};
use image::{DynamicImage, ImageDecoder};
use serde::{Deserialize, Serialize};
use thiserror::Error;
use wgpu::{Extent3d, TextureDimension, TextureFormat};
Expand All @@ -23,6 +24,10 @@ pub enum HdrTextureLoaderError {
Io(#[from] std::io::Error),
#[error("Could not extract image: {0}")]
Image(#[from] image::ImageError),
#[error("Could not convert total number of bytes in decoded image from u64 to usize: {0}")]
TryIntoTotalBytes(#[from] std::num::TryFromIntError),
mnmaita marked this conversation as resolved.
Show resolved Hide resolved
#[error("Could not return a 32bit RGB image reference")]
ImageReferenceRgb32F,
mnmaita marked this conversation as resolved.
Show resolved Hide resolved
}

impl AssetLoader for HdrTextureLoader {
Expand All @@ -46,10 +51,14 @@ impl AssetLoader for HdrTextureLoader {
reader.read_to_end(&mut bytes).await?;
let decoder = image::codecs::hdr::HdrDecoder::new(bytes.as_slice())?;
let info = decoder.metadata();
let rgb_data = decoder.read_image_hdr()?;
let mut rgba_data = Vec::with_capacity(rgb_data.len() * format.pixel_size());
let total_bytes = decoder.total_bytes().try_into()?;
let dynamic_image = DynamicImage::from_decoder(decoder)?;
let image_buffer = dynamic_image
.as_rgb32f()
.ok_or(HdrTextureLoaderError::ImageReferenceRgb32F)?;
let mut rgba_data = Vec::with_capacity(total_bytes);
mnmaita marked this conversation as resolved.
Show resolved Hide resolved

for rgb in rgb_data {
for rgb in image_buffer.pixels() {
let alpha = 1.0f32;

rgba_data.extend_from_slice(&rgb.0[0].to_ne_bytes());
Expand Down