basis_universal::transcoding

Struct Transcoder

Source
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

Source

pub fn new() -> Transcoder

Create a transcoder

Source

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.

Source

pub fn validate_header(&self, data: &[u8]) -> bool

Quick header validation - no crc16 checks.

Source

pub fn basis_texture_type(&self, data: &[u8]) -> BasisTextureType

The type of texture represented by the basis data

Source

pub fn basis_texture_format(&self, data: &[u8]) -> BasisTextureFormat

The basis texture format of the basis data

Source

pub fn user_data(&self, data: &[u8]) -> Result<UserData, ()>

Source

pub fn image_count(&self, data: &[u8]) -> u32

Number of images in the basis data

Source

pub fn image_level_count(&self, data: &[u8], image_index: u32) -> u32

Number of mipmap levels for the specified image in the basis data

Source

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.

Source

pub fn image_info(&self, data: &[u8], image_index: u32) -> Option<ImageInfo>

Returns information about the specified image.

Source

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.

Source

pub fn file_info(&self, data: &[u8]) -> Option<FileInfo>

Get a description of the basis file and low-level information about each slice.

Source

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).

Source

pub fn end_transcoding(&mut self)

Parallel with prepare_transcoding(), named stop_transcoding in the original library

Source

pub fn is_prepared_to_transcode(&self) -> bool

Returns true if prepare_transcoding() has been called.

Source

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.

Trait Implementations§

Source§

impl Default for Transcoder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for Transcoder

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.