From 33a404b796fe85485ebf8ca6c1f0dfe25fe99485 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 23 Mar 2025 18:33:17 +0100 Subject: fix texture argb to rgba conversion --- src/classes/texture2d.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/classes/texture2d.rs') diff --git a/src/classes/texture2d.rs b/src/classes/texture2d.rs index 9ad2a1d..8f87625 100644 --- a/src/classes/texture2d.rs +++ b/src/classes/texture2d.rs @@ -41,7 +41,15 @@ impl Texture2D { use TextureFormat::*; let u32_rgba_buf_to_image = |buf: Vec| { let buf = buf.into_iter().flat_map(u32::to_be_bytes).collect(); - let im = ImageBuffer::, Vec<_>>::from_raw(w as u32, h as u32, buf).unwrap(); + let mut im = + ImageBuffer::, Vec<_>>::from_raw(w as u32, h as u32, buf).unwrap(); + for p in im.pixels_mut() { + let a = p.0[0]; + p.0[0] = p.0[1]; + p.0[1] = p.0[2]; + p.0[2] = p.0[3]; + p.0[3] = a; + } im.into() }; match self.format { @@ -87,16 +95,26 @@ impl Texture2D { Ok(im.into()) } DXT1Crunched | DXT5Crunched => { + info!( + "decompressing {w}x{h} crunched {} texture", + match self.format { + DXT1Crunched => "DXT1", + DXT5Crunched => "DXT5", + _ => unreachable!(), + } + ); let mut buf = vec![0u32; w * h]; texture2ddecoder::decode_unity_crunch(&self.image_data, w, h, &mut buf).unwrap(); Ok(u32_rgba_buf_to_image(buf)) } BC7 => { + info!("decompressing {w}x{h} BC7 texture",); let mut buf = vec![0u32; w * h]; texture2ddecoder::decode_bc7(&self.image_data, w, h, &mut buf).unwrap(); Ok(u32_rgba_buf_to_image(buf)) } BC6H => { + info!("decompressing {w}x{h} BC6H texture",); let mut buf = vec![0u32; w * h]; texture2ddecoder::decode_bc6(&self.image_data, w, h, &mut buf, false).unwrap(); Ok(u32_rgba_buf_to_image(buf)) -- cgit v1.2.3-70-g09d2