pub struct Transcoder(/* private fields */);
Expand description
A transcoder that can convert compressed basis-universal data to compressed GPU formats or raw color data
Implementations§
Source§impl Transcoder
impl Transcoder
Sourcepub fn new() -> Transcoder
pub fn new() -> Transcoder
Create a transcoder
Sourcepub fn validate_file_checksums(
&self,
data: &[u8],
full_validation: bool,
) -> bool
pub fn validate_file_checksums( &self, data: &[u8], full_validation: bool, ) -> bool
Validates the .basis file. This computes a crc16 over the entire file, so it’s slow.
Sourcepub fn validate_header(&self, data: &[u8]) -> bool
pub fn validate_header(&self, data: &[u8]) -> bool
Quick header validation - no crc16 checks.
Sourcepub fn basis_texture_type(&self, data: &[u8]) -> BasisTextureType
pub fn basis_texture_type(&self, data: &[u8]) -> BasisTextureType
The type of texture represented by the basis data
Sourcepub fn basis_texture_format(&self, data: &[u8]) -> BasisTextureFormat
pub fn basis_texture_format(&self, data: &[u8]) -> BasisTextureFormat
The basis texture format of the basis data
pub fn user_data(&self, data: &[u8]) -> Result<UserData, ()>
Sourcepub fn image_count(&self, data: &[u8]) -> u32
pub fn image_count(&self, data: &[u8]) -> u32
Number of images in the basis data
Sourcepub fn image_level_count(&self, data: &[u8], image_index: u32) -> u32
pub fn image_level_count(&self, data: &[u8], image_index: u32) -> u32
Number of mipmap levels for the specified image in the basis data
Sourcepub fn image_level_description(
&self,
data: &[u8],
image_index: u32,
level_index: u32,
) -> Option<ImageLevelDescription>
pub fn image_level_description( &self, data: &[u8], image_index: u32, level_index: u32, ) -> Option<ImageLevelDescription>
Returns basic information about an image. Note that orig_width/orig_height may not be a multiple of 4.
Sourcepub fn image_info(&self, data: &[u8], image_index: u32) -> Option<ImageInfo>
pub fn image_info(&self, data: &[u8], image_index: u32) -> Option<ImageInfo>
Returns information about the specified image.
Sourcepub fn image_level_info(
&self,
data: &[u8],
image_index: u32,
level_index: u32,
) -> Option<ImageLevelInfo>
pub fn image_level_info( &self, data: &[u8], image_index: u32, level_index: u32, ) -> Option<ImageLevelInfo>
Returns information about the specified image’s mipmap level.
Sourcepub fn file_info(&self, data: &[u8]) -> Option<FileInfo>
pub fn file_info(&self, data: &[u8]) -> Option<FileInfo>
Get a description of the basis file and low-level information about each slice.
Sourcepub fn prepare_transcoding(&mut self, data: &[u8]) -> Result<(), ()>
pub fn prepare_transcoding(&mut self, data: &[u8]) -> Result<(), ()>
prepare_transcoding() must be called before calling transcode_slice() or transcode_image_level().
This is start_transcoding
in the original library
For ETC1S files, this call decompresses the selector/endpoint codebooks, so ideally you would only call this once per .basis file (not each image/mipmap level).
Sourcepub fn end_transcoding(&mut self)
pub fn end_transcoding(&mut self)
Parallel with prepare_transcoding()
, named stop_transcoding
in the original library
Sourcepub fn is_prepared_to_transcode(&self) -> bool
pub fn is_prepared_to_transcode(&self) -> bool
Returns true if prepare_transcoding() has been called.
Sourcepub fn transcode_image_level(
&self,
data: &[u8],
transcode_format: TranscoderTextureFormat,
transcode_parameters: TranscodeParameters,
) -> Result<Vec<u8>, TranscodeError>
pub fn transcode_image_level( &self, data: &[u8], transcode_format: TranscoderTextureFormat, transcode_parameters: TranscodeParameters, ) -> Result<Vec<u8>, TranscodeError>
transcode_image_level() decodes a single mipmap level from the .basis file to any of the supported output texture formats. It’ll first find the slice(s) to transcode, then call transcode_slice() one or two times to decode both the color and alpha texture data (or RG texture data from two slices for BC5). If the .basis file doesn’t have alpha slices, the output alpha blocks will be set to fully opaque (all 255’s). Currently, to decode to PVRTC1 the basis texture’s dimensions in pixels must be a power of 2, due to PVRTC1 format requirements. output_blocks_buf_size_in_blocks_or_pixels should be at least the image level’s total_blocks (num_blocks_x * num_blocks_y), or the total number of output pixels if fmt==cTFRGBA32. output_row_pitch_in_blocks_or_pixels: Number of blocks or pixels per row. If 0, the transcoder uses the slice’s num_blocks_x or orig_width (NOT num_blocks_x * 4). Ignored for PVRTC1 (due to texture swizzling). output_rows_in_pixels: Ignored unless fmt is cRGBA32. The total number of output rows in the output buffer. If 0, the transcoder assumes the slice’s orig_height (NOT num_blocks_y * 4). Notes:
- basisu_transcoder_init() must have been called first to initialize the transcoder lookup tables before calling this function.
- This method assumes the output texture buffer is readable. In some cases to handle alpha, the transcoder will write temporary data to the output texture in a first pass, which will be read in a second pass.