Skip to content

Commit

Permalink
Fixed crash when transcoding one- or two-channel KTX2 textures
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexorg committed Mar 21, 2024
1 parent 7b842e3 commit 63d0d4e
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions crates/bevy_render/src/texture/ktx2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,12 @@ pub fn ktx2_buffer_to_image(
TranscodeFormat::R8UnormSrgb => {
let (mut original_width, mut original_height) = (width, height);

for level_data in &levels {
transcoded.push(
level_data
.iter()
.copied()
.map(|v| (Srgba::gamma_function(v as f32 / 255.) * 255.).floor() as u8)
.collect::<Vec<u8>>(),
);
for (level, level_data) in levels.iter().enumerate() {
transcoded[level] = level_data
.iter()
.copied()
.map(|v| (Srgba::gamma_function(v as f32 / 255.) * 255.).floor() as u8)
.collect::<Vec<u8>>();

// Next mip dimensions are half the current, minimum 1x1
original_width = (original_width / 2).max(1);
Expand All @@ -109,14 +107,12 @@ pub fn ktx2_buffer_to_image(
TranscodeFormat::Rg8UnormSrgb => {
let (mut original_width, mut original_height) = (width, height);

for level_data in &levels {
transcoded.push(
level_data
.iter()
.copied()
.map(|v| (Srgba::gamma_function(v as f32 / 255.) * 255.).floor() as u8)
.collect::<Vec<u8>>(),
);
for (level, level_data) in levels.iter().enumerate() {
transcoded[level] = level_data
.iter()
.copied()
.map(|v| (Srgba::gamma_function(v as f32 / 255.) * 255.).floor() as u8)
.collect::<Vec<u8>>();

// Next mip dimensions are half the current, minimum 1x1
original_width = (original_width / 2).max(1);
Expand Down

0 comments on commit 63d0d4e

Please sign in to comment.