Decode a texture byte slice into RGBA8 pixels + dimensions. Tries DDS first when the URI extension suggests it (for asset packs like Lumberyard Bistro that ship BC-compressed textures), falling back to the `image` crate for PNG/JPEG/etc. Returns None on failure.
(bytes: &[u8], uri: &str)
| 1860 | /// Lumberyard Bistro that ship BC-compressed textures), falling back |
| 1861 | /// to the `image` crate for PNG/JPEG/etc. Returns None on failure. |
| 1862 | fn decode_texture_bytes(bytes: &[u8], uri: &str) -> Option<(Vec<u8>, u32, u32)> { |
| 1863 | let is_dds = uri.to_ascii_lowercase().ends_with(".dds") |
| 1864 | || bytes.len() >= 4 && &bytes[..4] == b"DDS "; |
| 1865 | if is_dds { |
| 1866 | if let Ok(dds) = image_dds::ddsfile::Dds::read(bytes) { |
| 1867 | // Decode mip 0 → RGBA8. image_from_dds handles the common |
| 1868 | // BC1–BC7 formats; anything it can't decode falls through |
| 1869 | // to the image crate which will almost certainly fail too. |
| 1870 | if let Ok(rgba) = image_dds::image_from_dds(&dds, 0) { |
| 1871 | let (w, h) = (rgba.width(), rgba.height()); |
| 1872 | return Some((rgba.into_raw(), w, h)); |
| 1873 | } |
| 1874 | } |
| 1875 | } |
| 1876 | let img = image::load_from_memory(bytes).ok()?; |
| 1877 | let rgba = img.to_rgba8(); |
| 1878 | let (w, h) = (rgba.width(), rgba.height()); |
| 1879 | Some((rgba.into_raw(), w, h)) |
| 1880 | } |
| 1881 | |
| 1882 | fn base64_decode(input: &str, output: &mut Vec<u8>) { |
| 1883 | let mut buf = 0u32; |
no test coverage detected