diff options
author | metamuffin <metamuffin@disroot.org> | 2025-03-23 18:33:17 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-03-23 18:33:17 +0100 |
commit | 33a404b796fe85485ebf8ca6c1f0dfe25fe99485 (patch) | |
tree | 47cfddf7aa705110b76b8ebb57d11645faf2987d /src/classes/texture2d.rs | |
parent | 6dc7f94764bdbb502884bde0641f59f70d0f92b3 (diff) | |
download | unity-tools-33a404b796fe85485ebf8ca6c1f0dfe25fe99485.tar unity-tools-33a404b796fe85485ebf8ca6c1f0dfe25fe99485.tar.bz2 unity-tools-33a404b796fe85485ebf8ca6c1f0dfe25fe99485.tar.zst |
fix texture argb to rgba conversion
Diffstat (limited to 'src/classes/texture2d.rs')
-rw-r--r-- | src/classes/texture2d.rs | 20 |
1 files changed, 19 insertions, 1 deletions
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<u32>| { let buf = buf.into_iter().flat_map(u32::to_be_bytes).collect(); - let im = ImageBuffer::<Rgba<u8>, Vec<_>>::from_raw(w as u32, h as u32, buf).unwrap(); + let mut im = + ImageBuffer::<Rgba<u8>, 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)) |