### Decode Unity Crunch Compressed Textures Source: https://context7.com/universalgameextraction/texture2ddecoder/llms.txt Decodes Unity's variant of Crunch compressed textures, supporting formats like ETC1/ETC2. Requires the `alloc` feature. The texture header must be parsed first to retrieve dimensions. ```rust use texture2ddecoder::{decode_unity_crunch, CrnTextureInfo}; // Full Unity Crunch texture decoding workflow fn decode_unity_crunch_texture(crn_data: &[u8]) -> (Vec, u32, u32) { // Parse header to get dimensions let mut tex_info = CrnTextureInfo::default(); tex_info.crnd_get_texture_info(crn_data, crn_data.len() as u32); let width = tex_info.width.max(1) as usize; let height = tex_info.height.max(1) as usize; // Allocate output buffer let mut image: Vec = vec![0; width * height]; // Decode the texture (auto-detects DXT, ETC1, ETC2 variants) decode_unity_crunch(crn_data, width, height, &mut image) .expect("Failed to decode Unity Crunch texture"); (image, width as u32, height as u32) } // Example: Processing Unity asset textures fn process_unity_texture(crn_data: &[u8]) -> Result, &'static str> { let mut tex_info = CrnTextureInfo::default(); if !tex_info.crnd_get_texture_info(crn_data, crn_data.len() as u32) { return Err("Invalid Unity Crunch file"); } let width = tex_info.width.max(1) as usize; let height = tex_info.height.max(1) as usize; let mut image: Vec = vec![0; width * height]; decode_unity_crunch(crn_data, width, height, &mut image)?; // Convert BGRA32 u32 to RGBA8 byte array let rgba_bytes: Vec = image.iter() .flat_map(|pixel| { let bytes = pixel.to_le_bytes(); [bytes[2], bytes[1], bytes[0], bytes[3]] // BGRA to RGBA }) .collect(); Ok(rgba_bytes) } ``` -------------------------------- ### Decode ETC and EAC textures in Rust Source: https://context7.com/universalgameextraction/texture2ddecoder/llms.txt Provides functions for decoding ETC1, ETC2 (RGB, RGBA1, RGBA8), and EAC (R11, R11 signed, RG11) formats. Each function requires a pre-allocated buffer of size width * height. ```rust use texture2ddecoder::{ decode_etc1, decode_etc2_rgb, decode_etc2_rgba1, decode_etc2_rgba8, decode_eacr, decode_eacr_signed, decode_eacrg }; // ETC1 - Legacy mobile texture format fn decode_etc1_texture(compressed_data: &[u8], width: usize, height: usize) -> Vec { let mut image: Vec = vec![0; width * height]; decode_etc1(compressed_data, width, height, &mut image) .expect("Failed to decode ETC1 texture"); image } // ETC2 RGB - Improved RGB compression fn decode_etc2_rgb_texture(compressed_data: &[u8], width: usize, height: usize) -> Vec { let mut image: Vec = vec![0; width * height]; decode_etc2_rgb(compressed_data, width, height, &mut image) .expect("Failed to decode ETC2 RGB texture"); image } // ETC2 RGBA1 - RGB with punch-through alpha (1-bit alpha) fn decode_etc2_rgba1_texture(compressed_data: &[u8], width: usize, height: usize) -> Vec { let mut image: Vec = vec![0; width * height]; decode_etc2_rgba1(compressed_data, width, height, &mut image) .expect("Failed to decode ETC2 RGBA1 texture"); image } // ETC2 RGBA8 - Full RGBA with 8-bit alpha fn decode_etc2_rgba8_texture(compressed_data: &[u8], width: usize, height: usize) -> Vec { let mut image: Vec = vec![0; width * height]; decode_etc2_rgba8(compressed_data, width, height, &mut image) .expect("Failed to decode ETC2 RGBA8 texture"); image } // EAC R11 - Single-channel (red) 11-bit compression fn decode_eacr_texture(compressed_data: &[u8], width: usize, height: usize) -> Vec { let mut image: Vec = vec![0; width * height]; decode_eacr(compressed_data, width, height, &mut image) .expect("Failed to decode EAC R11 texture"); image } // EAC R11 Signed - Single-channel signed variant fn decode_eacr_signed_texture(compressed_data: &[u8], width: usize, height: usize) -> Vec { let mut image: Vec = vec![0; width * height]; decode_eacr_signed(compressed_data, width, height, &mut image) .expect("Failed to decode EAC R11 signed texture"); image } // EAC RG11 - Dual-channel compression (useful for normal maps) fn decode_eacrg_texture(compressed_data: &[u8], width: usize, height: usize) -> Vec { let mut image: Vec = vec![0; width * height]; decode_eacrg(compressed_data, width, height, &mut image) .expect("Failed to decode EAC RG11 texture"); image } ``` -------------------------------- ### Texture Decoding Functions Source: https://github.com/universalgameextraction/texture2ddecoder/blob/master/README.md General signature and usage for the library's decoding functions. ```APIDOC ## Texture Decoding Functions ### Description Provides functions to decode compressed texture data into a raw buffer. Most formats support both full image decoding and individual block decoding. ### Parameters #### Request Body - **data** (&[u8]) - Required - The compressed data buffer. - **width** (usize) - Required - The width of the image. - **height** (usize) - Required - The height of the image. - **image** (&mut [u32]) - Required - The buffer to write the decoded image to. ### Response #### Success Response (Result<(), &'static str>) - **Ok** (()) - Decoding successful. - **Err** (&'static str) - Error message if decoding fails. ``` -------------------------------- ### Decode Crunch Compressed Textures Source: https://context7.com/universalgameextraction/texture2ddecoder/llms.txt Decodes Crunch compressed textures (.crn files). Requires the `alloc` feature. The header must be parsed first to retrieve texture dimensions. ```rust use texture2ddecoder::{decode_crunch, CrnTextureInfo}; // Parse Crunch file header to get texture info fn get_crunch_texture_info(crn_data: &[u8]) -> CrnTextureInfo { let mut tex_info = CrnTextureInfo::default(); tex_info.crnd_get_texture_info(crn_data, crn_data.len() as u32); tex_info } // Full Crunch texture decoding workflow fn decode_crunch_texture(crn_data: &[u8]) -> (Vec, u32, u32) { // First, parse the header to get dimensions let tex_info = get_crunch_texture_info(crn_data); let width = tex_info.width.max(1) as usize; let height = tex_info.height.max(1) as usize; // Allocate output buffer let mut image: Vec = vec![0; width * height]; // Decode the texture decode_crunch(crn_data, width, height, &mut image) .expect("Failed to decode Crunch texture"); (image, width as u32, height as u32) } // Example: Loading and decoding a .crn file fn load_and_decode_crn_file(file_path: &str) -> Result, Box> { let crn_data = std::fs::read(file_path)?; let mut tex_info = CrnTextureInfo::default(); if !tex_info.crnd_get_texture_info(&crn_data, crn_data.len() as u32) { return Err("Invalid Crunch file".into()); } let width = tex_info.width.max(1) as usize; let height = tex_info.height.max(1) as usize; let mut image: Vec = vec![0; width * height]; decode_crunch(&crn_data, width, height, &mut image)?; Ok(image) } ``` -------------------------------- ### Texture Decoding Function Signatures Source: https://github.com/universalgameextraction/texture2ddecoder/blob/master/README.md Standard function signatures for decoding compressed texture data into a provided buffer. The buffer must be sized according to the image dimensions or block size. ```rust fn decode_format(data: &[u8], width: usize, height: usize, image: &mut [u32]) -> Result<(), &'static str> // data: the compressed data, expected to be width * height / block_size in size // width: the width of the image // height: the height of the image // image: the buffer to write the decoded image to, expected to be width * height in size fn decode_format_block(data: &[u8], outbuf: &mut [u32]) -> Result<(), &'static str> // data: the compressed data (block), expected to be block_size in size // outbuf: the buffer to write the decoded image to, expected to be block_size in size ``` -------------------------------- ### Decode Compressed Texture Blocks in Rust Source: https://context7.com/universalgameextraction/texture2ddecoder/llms.txt Functions for decoding individual 4x4 pixel blocks or variable-sized ASTC blocks into pixel buffers. ```rust use texture2ddecoder::{ decode_bc1_block, decode_bc3_block, decode_bc7_block, decode_etc1_block, decode_etc2_rgb_block, decode_astc_block }; // BC1 block decoding (4x4 pixels, 8 bytes input) fn decode_bc1_block_example(block_data: &[u8]) -> [u32; 16] { let mut pixels: [u32; 16] = [0; 16]; decode_bc1_block(block_data, &mut pixels); pixels } // BC3 block decoding (4x4 pixels, 16 bytes input) fn decode_bc3_block_example(block_data: &[u8]) -> [u32; 16] { let mut pixels: [u32; 16] = [0; 16]; decode_bc3_block(block_data, &mut pixels); pixels } // BC7 block decoding (4x4 pixels, 16 bytes input) fn decode_bc7_block_example(block_data: &[u8]) -> [u32; 16] { let mut pixels: [u32; 16] = [0; 16]; decode_bc7_block(block_data, &mut pixels); pixels } // ETC1 block decoding (4x4 pixels, 8 bytes input) fn decode_etc1_block_example(block_data: &[u8]) -> [u32; 16] { let mut pixels: [u32; 16] = [0; 16]; decode_etc1_block(block_data, &mut pixels); pixels } // ETC2 RGB block decoding (4x4 pixels, 8 bytes input) fn decode_etc2_block_example(block_data: &[u8]) -> [u32; 16] { let mut pixels: [u32; 16] = [0; 16]; decode_etc2_rgb_block(block_data, &mut pixels); pixels } // ASTC block decoding (variable block size, 16 bytes input) fn decode_astc_block_example(block_data: &[u8], block_w: usize, block_h: usize) -> Vec { let mut pixels: Vec = vec![0; block_w * block_h]; decode_astc_block(block_data, block_w, block_h, &mut pixels); pixels } ``` -------------------------------- ### Decode PVRTC textures in Rust Source: https://context7.com/universalgameextraction/texture2ddecoder/llms.txt Provides functions for decoding PVRTC 2bpp and 4bpp textures. The generic decoder allows dynamic selection of the bits-per-pixel mode. ```rust use texture2ddecoder::{decode_pvrtc, decode_pvrtc_2bpp, decode_pvrtc_4bpp}; // Generic PVRTC decoding with bpp selection fn decode_pvrtc_texture( compressed_data: &[u8], width: usize, height: usize, is_2bpp: bool ) -> Vec { let mut image: Vec = vec![0; width * height]; decode_pvrtc(compressed_data, width, height, &mut image, is_2bpp) .expect("Failed to decode PVRTC texture"); image } // PVRTC 2bpp - Higher compression, lower quality fn decode_pvrtc_2bpp_texture(compressed_data: &[u8], width: usize, height: usize) -> Vec { let mut image: Vec = vec![0; width * height]; decode_pvrtc_2bpp(compressed_data, width, height, &mut image) .expect("Failed to decode PVRTC 2bpp texture"); image } // PVRTC 4bpp - Better quality, standard compression fn decode_pvrtc_4bpp_texture(compressed_data: &[u8], width: usize, height: usize) -> Vec { let mut image: Vec = vec![0; width * height]; decode_pvrtc_4bpp(compressed_data, width, height, &mut image) .expect("Failed to decode PVRTC 4bpp texture"); image } ``` -------------------------------- ### Texture Decoding Functions Source: https://github.com/universalgameextraction/texture2ddecoder/blob/master/bindings/python/README.md Functions for decoding various texture formats including ATC, ASTC, BCN, ETC, PVRTC, and Crunch. ```APIDOC ## Texture Decoding Functions ### Description These functions decode compressed texture data into raw byte arrays. Each function requires the texture data, width, and height. ### Parameters #### Arguments - **data** (bytes) - Required - The raw byte array of the compressed texture. - **width** (int) - Required - The width of the texture. - **height** (int) - Required - The height of the texture. - **block_width** (int) - Required (for decode_astc) - The block width for ASTC decoding. - **block_height** (int) - Required (for decode_astc) - The block height for ASTC decoding. ### Response - **bytes** - The decoded texture data. ``` -------------------------------- ### Decode BC3 (DXT5) Texture Source: https://context7.com/universalgameextraction/texture2ddecoder/llms.txt Decodes BC3 (DXT5) compressed textures, supporting RGBA with interpolated alpha. Ensure correct input data and dimensions. ```rust use texture2ddecoder::decode_bc3; // BC3 (DXT5) - RGBA with interpolated alpha fn decode_bc3_texture(compressed_data: &[u8], width: usize, height: usize) -> Vec { let mut image: Vec = vec![0; width * height]; decode_bc3(compressed_data, width, height, &mut image) .expect("Failed to decode BC3 texture"); image } ``` -------------------------------- ### Decode BC2 (DXT3) Texture Source: https://context7.com/universalgameextraction/texture2ddecoder/llms.txt Decodes BC2 (DXT3) compressed textures, which support RGBA with explicit alpha values. Verify input data and dimensions. ```rust use texture2ddecoder::decode_bc2; // BC2 (DXT3) - RGBA with explicit alpha fn decode_bc2_texture(compressed_data: &[u8], width: usize, height: usize) -> Vec { let mut image: Vec = vec![0; width * height]; decode_bc2(compressed_data, width, height, &mut image) .expect("Failed to decode BC2 texture"); image } ``` -------------------------------- ### Decode Single ATC RGB4 Block Source: https://context7.com/universalgameextraction/texture2ddecoder/llms.txt Performs block-level decoding for a single 4x4 ATC RGB4 block, outputting 16 BGRA32 pixel values. ```rust use texture2ddecoder::decode_atc_rgb4_block; // Block-level decoding for a single 4x4 block fn decode_single_atc_block(block_data: &[u8]) -> [u32; 16] { let mut block_pixels: [u32; 16] = [0; 16]; decode_atc_rgb4_block(block_data, &mut block_pixels); block_pixels } ``` -------------------------------- ### Decode BC1 (DXT1) Texture Source: https://context7.com/universalgameextraction/texture2ddecoder/llms.txt Decodes BC1 (DXT1) compressed textures, which support opaque RGB with optional 1-bit alpha. Ensure the input data and dimensions are correct. ```rust use texture2ddecoder::decode_bc1; // BC1 (DXT1) - Opaque RGB with optional 1-bit alpha fn decode_bc1_texture(compressed_data: &[u8], width: usize, height: usize) -> Vec { let mut image: Vec = vec![0; width * height]; decode_bc1(compressed_data, width, height, &mut image) .expect("Failed to decode BC1 texture"); image } ``` -------------------------------- ### Decode ATC RGBA8 Texture Source: https://context7.com/universalgameextraction/texture2ddecoder/llms.txt Decodes an ATC RGBA8 (with alpha) compressed texture into BGRA32 format. Requires the compressed data, width, height, and a mutable image buffer. ```rust use texture2ddecoder::{decode_atc_rgb4, decode_atc_rgba8}; // Decode ATC RGBA8 (with alpha) texture fn decode_atc_rgba8_texture(compressed_data: &[u8], width: usize, height: usize) -> Vec { let mut image: Vec = vec![0; width * height]; decode_atc_rgba8(compressed_data, width, height, &mut image) .expect("Failed to decode ATC RGBA8 texture"); image } ``` -------------------------------- ### Decode ATC RGB4 Texture Source: https://context7.com/universalgameextraction/texture2ddecoder/llms.txt Decodes an ATC RGB4 (opaque) compressed texture into BGRA32 format. Requires the compressed data, width, height, and a mutable image buffer. ```rust use texture2ddecoder::{decode_atc_rgb4, decode_atc_rgba8}; // Decode ATC RGB4 (opaque) texture fn decode_atc_rgb4_texture(compressed_data: &[u8], width: usize, height: usize) -> Vec { let mut image: Vec = vec![0; width * height]; decode_atc_rgb4(compressed_data, width, height, &mut image) .expect("Failed to decode ATC RGB4 texture"); image } ``` -------------------------------- ### Decode BC1A Texture Source: https://context7.com/universalgameextraction/texture2ddecoder/llms.txt Decodes BC1A compressed textures, which is a variant of BC1 that interprets alpha channels. Ensure correct input data and dimensions. ```rust use texture2ddecoder::decode_bc1a; // BC1A - BC1 with alpha interpretation fn decode_bc1a_texture(compressed_data: &[u8], width: usize, height: usize) -> Vec { let mut image: Vec = vec![0; width * height]; decode_bc1a(compressed_data, width, height, &mut image) .expect("Failed to decode BC1A texture"); image } ``` -------------------------------- ### Decode ASTC 4x4 Texture Source: https://context7.com/universalgameextraction/texture2ddecoder/llms.txt Convenience function to decode an ASTC texture using a 4x4 block size. Requires compressed data, width, height, and a mutable image buffer. ```rust use texture2ddecoder::{decode_astc, decode_astc_4_4, decode_astc_8_8, decode_astc_block}; // Convenience function for common 4x4 block size fn decode_astc_4x4_texture(compressed_data: &[u8], width: usize, height: usize) -> Vec { let mut image: Vec = vec![0; width * height]; decode_astc_4_4(compressed_data, width, height, &mut image) .expect("Failed to decode ASTC 4x4 texture"); image } ``` -------------------------------- ### Decode ASTC 8x8 Texture Source: https://context7.com/universalgameextraction/texture2ddecoder/llms.txt Convenience function to decode an ASTC texture using an 8x8 block size, offering higher compression. Requires compressed data, width, height, and a mutable image buffer. ```rust use texture2ddecoder::{decode_astc, decode_astc_4_4, decode_astc_8_8, decode_astc_block}; // Convenience function for 8x8 block size (higher compression) fn decode_astc_8x8_texture(compressed_data: &[u8], width: usize, height: usize) -> Vec { let mut image: Vec = vec![0; width * height]; decode_astc_8_8(compressed_data, width, height, &mut image) .expect("Failed to decode ASTC 8x8 texture"); image } ``` -------------------------------- ### Decode BC7 Texture Source: https://context7.com/universalgameextraction/texture2ddecoder/llms.txt Decodes BC7 compressed textures, which offer high-quality RGBA compression. Ensure the input data and dimensions are accurate. ```rust use texture2ddecoder::decode_bc7; // BC7 - High-quality RGBA compression fn decode_bc7_texture(compressed_data: &[u8], width: usize, height: usize) -> Vec { let mut image: Vec = vec![0; width * height]; decode_bc7(compressed_data, width, height, &mut image) .expect("Failed to decode BC7 texture"); image } ``` -------------------------------- ### Decode Generic ASTC Texture Source: https://context7.com/universalgameextraction/texture2ddecoder/llms.txt Decodes an ASTC compressed texture with specified block dimensions. Requires compressed data, image dimensions, block dimensions, and a mutable image buffer. ```rust use texture2ddecoder::{decode_astc, decode_astc_4_4, decode_astc_8_8, decode_astc_block}; // Generic ASTC decoding with custom block size fn decode_astc_texture( compressed_data: &[u8], width: usize, height: usize, block_width: usize, block_height: usize ) -> Vec { let mut image: Vec = vec![0; width * height]; decode_astc(compressed_data, width, height, block_width, block_height, &mut image) .expect("Failed to decode ASTC texture"); image } ``` -------------------------------- ### Decode Single ASTC Block Source: https://context7.com/universalgameextraction/texture2ddecoder/llms.txt Performs block-level decoding for a single ASTC block, outputting pixel values based on specified block dimensions. ```rust use texture2ddecoder::{decode_astc, decode_astc_4_4, decode_astc_8_8, decode_astc_block}; // Block-level ASTC decoding fn decode_single_astc_block(block_data: &[u8], block_width: usize, block_height: usize) -> Vec { let mut block_pixels: Vec = vec![0; block_width * block_height]; decode_astc_block(block_data, block_width, block_height, &mut block_pixels); block_pixels } ``` -------------------------------- ### Decode BC5 Texture Source: https://context7.com/universalgameextraction/texture2ddecoder/llms.txt Decodes BC5 compressed textures, used for dual-channel (RG) compression, commonly for normal maps. Ensure correct input data and dimensions. ```rust use texture2ddecoder::decode_bc5; // BC5 - Dual-channel (RG) compression, commonly used for normal maps fn decode_bc5_texture(compressed_data: &[u8], width: usize, height: usize) -> Vec { let mut image: Vec = vec![0; width * height]; decode_bc5(compressed_data, width, height, &mut image) .expect("Failed to decode BC5 texture"); image } ``` -------------------------------- ### Decode BC6H HDR Texture Source: https://context7.com/universalgameextraction/texture2ddecoder/llms.txt Decodes BC6H HDR (High Dynamic Range) textures, supporting both signed and unsigned variants. Provide the correct compressed data, dimensions, and signed flag. ```rust use texture2ddecoder::{decode_bc6, decode_bc6_signed, decode_bc6_unsigned}; // BC6H - HDR texture compression (signed and unsigned variants) fn decode_bc6_hdr_texture( compressed_data: &[u8], width: usize, height: usize, signed: bool ) -> Vec { let mut image: Vec = vec![0; width * height]; decode_bc6(compressed_data, width, height, &mut image, signed) .expect("Failed to decode BC6H texture"); image } ``` -------------------------------- ### Decode BC4 Texture Source: https://context7.com/universalgameextraction/texture2ddecoder/llms.txt Decodes BC4 compressed textures, which are used for single-channel (red) compression. Verify input data and dimensions. ```rust use texture2ddecoder::decode_bc4; // BC4 - Single-channel (red) compression fn decode_bc4_texture(compressed_data: &[u8], width: usize, height: usize) -> Vec { let mut image: Vec = vec![0; width * height]; decode_bc4(compressed_data, width, height, &mut image) .expect("Failed to decode BC4 texture"); image } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.