Skip to main content

SampleInformation

Struct SampleInformation 

Source
pub struct SampleInformation {
    pub bit_offset: u16,
    pub bit_length: NonZeroU8,
    pub channel_type: u8,
    pub channel_type_qualifiers: ChannelTypeQualifiers,
    pub sample_positions: [u8; 4],
    pub lower: u32,
    pub upper: u32,
}
Expand description

Information about each “sample” within an image.

A “sample” consisting of a single channel of data and with a single corresponding “position” within the texel block.

See the DFD specification for more extremely verbose information.

Fields§

§bit_offset: u16

Offset from the beginning of the texel block in bits.

§bit_length: NonZeroU8

The length of this sample in bits.

§channel_type: u8

The type of channel this sample represents. This varies by ColorModel.

§channel_type_qualifiers: ChannelTypeQualifiers

Qualifiers modifying the channel type.

§sample_positions: [u8; 4]

The position in texels of this sample relative to the 0,0,0,0 texel in the 4D texel block.

§lower: u32

The sample value that maps to the format’s logical minimum — typically 0 for unsigned formats, -1 for signed formats, or -0.5 for chroma channels in color difference models (e.g. Y′CbCr).

Together with upper, this defines how raw sample values are converted to their conceptual numeric interpretation. Values are not guaranteed to fall within this range — for example, HDR formats may define 1.0 as a nominal level well below the actual maximum. When samples should be interpreted directly as integers (unnormalized), set upper to 1 and lower to 0 (unsigned) or -1 (signed).

For integer formats, this is stored as a 32-bit integer (signed or unsigned matching the channel encoding). For floating-point formats, it is stored as a 32-bit float. For formats wider than 32 bits (e.g. 64-bit), integer values are expanded by preserving the sign bit and replicating the top non-sign bit, and float values are converted to the native representation (e.g. f32 to f64).

§Examples

FormatlowerupperEffect
R8 unorm0255Maps 0–255 to 0.0–1.0
R8 snorm-127 (0xFFFFFF81)127Maps -127–127 to -1.0–1.0
R8 uint01Integer value used directly
R16 sfloat0xBF800000 (-1.0f)0x3F800000 (1.0f)Float range -1.0–1.0
R64 uint01Expands to 64-bit 0 and 1
R64 uint norm00xFFFFFFFFExpands to u64::MAX, maps to 0.0–1.0
BT.709 Y′ (8-bit)16235Maps 16–235 to 0.0–1.0

For a very long and confusing explanation of this, please see the DFD specification

§upper: u32

The sample value that maps to 1.0 (the white point), or 0.5 for chroma channels in color difference models (e.g. Y′CbCr).

See lower for more details on interpretation and encoding and examples.

Implementations§

Source§

impl SampleInformation

Source

pub const LENGTH: usize = 16

Number of bytes in a SampleInformation entry.

Source

pub fn as_bytes(&self) -> [u8; 16]

Serializes this sample information to bytes.

Source

pub fn from_bytes(bytes: &[u8; 16]) -> Result<Self, ParseError>

Deserializes sample information from the given bytes.

Trait Implementations§

Source§

impl Clone for SampleInformation

Source§

fn clone(&self) -> SampleInformation

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for SampleInformation

Source§

impl Debug for SampleInformation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for SampleInformation

Source§

impl PartialEq for SampleInformation

Source§

fn eq(&self, other: &SampleInformation) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for SampleInformation

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.