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>
impl<Data: AsRef<[u8]>> Reader<Data>
Sourcepub fn new(input: Data) -> Result<Self, ParseError>
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.
Sourcepub fn header(&self) -> Header
pub fn header(&self) -> Header
Container-level metadata (dimensions, format, compression, etc.).
Sourcepub fn color_primaries(&self) -> Option<ColorPrimaries>
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.
Sourcepub fn transfer_function(&self) -> Option<TransferFunction>
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.
Sourcepub fn color_model(&self) -> Option<ColorModel>
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.
Sourcepub fn is_alpha_premultiplied(&self) -> Option<bool>
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.
Sourcepub fn writer(&self) -> Option<&str>
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
KTXwriterkey. - The
KTXwritervalue is not valid UTF-8.
Sourcepub fn levels(&self) -> impl ExactSizeIterator<Item = Level<'_>> + '_
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.
Sourcepub fn supercompression_global_data(&self) -> &[u8] ⓘ
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.
Sourcepub fn dfd_blocks(&self) -> &[Block]
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.
Sourcepub fn basic_dfd(&self) -> Option<&Basic>
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.
Sourcepub fn key_value_data(&self) -> KeyValueDataIterator<'_> ⓘ
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.