Skip to main content

Reader

Struct Reader 

Source
pub struct Reader<Data: AsRef<[u8]>> { /* private fields */ }
Expand description

Parses and validates a KTX2 texture container from an in-memory buffer.

All validation (magic bytes, bounds checks, DFD integrity, level index) is performed eagerly in Reader::new. Subsequent accessors are infallible.

Data can be any type that derefs to [u8]&[u8], Vec<u8>, Arc<[u8]>, etc.

Implementations§

Source§

impl<Data: AsRef<[u8]>> Reader<Data>

Source

pub fn new(input: Data) -> Result<Self, ParseError>

Parse and validate a KTX2 buffer.

Validates the header magic, all section bounds, the DFD, and the level index. Returns ParseError on any structural problem.

Source

pub fn data(&self) -> &[u8]

The raw KTX2 file bytes backing this reader.

Source

pub fn header(&self) -> Header

Container-level metadata (dimensions, format, compression, etc.).

Source

pub fn color_primaries(&self) -> Option<ColorPrimaries>

The color primaries used by this image (e.g. BT.709, BT.2020, etc.).

Shorthand for dfd::Basic::color_primaries. Returns None if there is no basic DFD block.

Source

pub fn transfer_function(&self) -> Option<TransferFunction>

The transfer function used by this image (e.g. Linear, sRGB, PQ, etc.).

Shorthand for dfd::Basic::transfer_function. Returns None if there is no basic DFD block.

Source

pub fn color_model(&self) -> Option<ColorModel>

The color model used by this image (e.g. RGB, YUV, etc.). Note that compressed formats will have a dedicated color model (e.g. BC1, ASTC) rather than RGB, even if the uncompressed data would be RGB.

Shorthand for dfd::Basic::color_model. Returns None if there is no basic DFD block.

Source

pub fn is_alpha_premultiplied(&self) -> Option<bool>

The alpha premuliplication state of the image. true if the RGB channels are premultiplied by alpha, false if not.

Shorthand for dfd::Basic::flags’s dfd::DataFormatFlags::ALPHA_PREMULTIPLIED flag. Returns None if there is no basic DFD block.

Source

pub fn writer(&self) -> Option<&str>

The program used to write this file, if specified by this file.

Shorthand for retrieving the KTXwriter key from the key/value data.

Returns None if:

  • The file doesn’t contain a KTXwriter key.
  • The KTXwriter value is not valid UTF-8.
Source

pub fn levels(&self) -> impl ExactSizeIterator<Item = Level<'_>> + '_

Iterator over the texture’s mip levels, ordered largest to smallest (level 0 first, level N-1 last). Each Level contains the raw (possibly supercompressed) bytes for that level.

Source

pub fn supercompression_global_data(&self) -> &[u8]

Supercompression Global Data (SGD) section. Currently only used by BasisLZ (scheme 1) for codebooks and image descriptors. Empty for other schemes.

Source

pub fn dfd_blocks(&self) -> &[Block]

The Data Format Descriptor blocks. Most KTX2 files contain exactly one dfd::Block::Basic block. Use this to inspect color model, transfer function, primaries, and per-sample layout.

Source

pub fn basic_dfd(&self) -> Option<&Basic>

The first dfd::Basic block, if present.

Nearly all KTX2 files contain exactly one basic DFD block. Returns None only for files that exclusively use non-standard descriptor blocks.

Source

pub fn key_value_data(&self) -> KeyValueDataIterator<'_>

Iterator over key/value metadata pairs. Keys are UTF-8 strings; values are raw bytes (often NUL-terminated UTF-8, but not always).

§Standard Keys

The KTX specification defines a number of standard keys. Most commonly, the KTXwriter key is used to indicate the tool that wrote the file.

For a full list of standard keys, see the KTX specification.

Auto Trait Implementations§

§

impl<Data> Freeze for Reader<Data>
where Data: Freeze,

§

impl<Data> RefUnwindSafe for Reader<Data>
where Data: RefUnwindSafe,

§

impl<Data> Send for Reader<Data>
where Data: Send,

§

impl<Data> Sync for Reader<Data>
where Data: Sync,

§

impl<Data> Unpin for Reader<Data>
where Data: Unpin,

§

impl<Data> UnsafeUnpin for Reader<Data>
where Data: UnsafeUnpin,

§

impl<Data> UnwindSafe for Reader<Data>
where Data: UnwindSafe,

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.