Format

Enum Format 

Source
#[non_exhaustive]
pub enum Format {
Show 73 variants R8G8B8_UNORM, B8G8R8_UNORM, R8G8B8A8_UNORM, R8G8B8A8_SNORM, B8G8R8A8_UNORM, B8G8R8X8_UNORM, B5G6R5_UNORM, B5G5R5A1_UNORM, B4G4R4A4_UNORM, A4B4G4R4_UNORM, R8_SNORM, R8_UNORM, R8G8_UNORM, R8G8_SNORM, A8_UNORM, R16_UNORM, R16_SNORM, R16G16_UNORM, R16G16_SNORM, R16G16B16A16_UNORM, R16G16B16A16_SNORM, R10G10B10A2_UNORM, R11G11B10_FLOAT, R9G9B9E5_SHAREDEXP, R16_FLOAT, R16G16_FLOAT, R16G16B16A16_FLOAT, R32_FLOAT, R32G32_FLOAT, R32G32B32_FLOAT, R32G32B32A32_FLOAT, R10G10B10_XR_BIAS_A2_UNORM, AYUV, Y410, Y416, R1_UNORM, R8G8_B8G8_UNORM, G8R8_G8B8_UNORM, UYVY, YUY2, Y210, Y216, NV12, P010, P016, BC1_UNORM, BC2_UNORM, BC2_UNORM_PREMULTIPLIED_ALPHA, BC3_UNORM, BC3_UNORM_PREMULTIPLIED_ALPHA, BC4_UNORM, BC4_SNORM, BC5_UNORM, BC5_SNORM, BC6H_UF16, BC6H_SF16, BC7_UNORM, ASTC_4X4_UNORM, ASTC_5X4_UNORM, ASTC_5X5_UNORM, ASTC_6X5_UNORM, ASTC_6X6_UNORM, ASTC_8X5_UNORM, ASTC_8X6_UNORM, ASTC_8X8_UNORM, ASTC_10X5_UNORM, ASTC_10X6_UNORM, ASTC_10X8_UNORM, ASTC_10X10_UNORM, ASTC_12X10_UNORM, ASTC_12X12_UNORM, BC3_UNORM_RXGB, BC3_UNORM_NORMAL,
}
Expand description

The format of the pixel data of a surface.

This enumeration is modelled after the DXGI_FORMAT enumeration and has the same semantics and naming conventions.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

R8G8B8_UNORM

§

B8G8R8_UNORM

§

R8G8B8A8_UNORM

§

R8G8B8A8_SNORM

§

B8G8R8A8_UNORM

§

B8G8R8X8_UNORM

§

B5G6R5_UNORM

§

B5G5R5A1_UNORM

§

B4G4R4A4_UNORM

§

A4B4G4R4_UNORM

§

R8_SNORM

§

R8_UNORM

§

R8G8_UNORM

§

R8G8_SNORM

§

A8_UNORM

§

R16_UNORM

§

R16_SNORM

§

R16G16_UNORM

§

R16G16_SNORM

§

R16G16B16A16_UNORM

§

R16G16B16A16_SNORM

§

R10G10B10A2_UNORM

§

R11G11B10_FLOAT

§

R9G9B9E5_SHAREDEXP

§

R16_FLOAT

§

R16G16_FLOAT

§

R16G16B16A16_FLOAT

§

R32_FLOAT

§

R32G32_FLOAT

§

R32G32B32_FLOAT

§

R32G32B32A32_FLOAT

§

R10G10B10_XR_BIAS_A2_UNORM

§

AYUV

§

Y410

§

Y416

§

R1_UNORM

§

R8G8_B8G8_UNORM

§

G8R8_G8B8_UNORM

§

UYVY

§

YUY2

§

Y210

§

Y216

§

NV12

§

P010

§

P016

§

BC1_UNORM

§

BC2_UNORM

§

BC2_UNORM_PREMULTIPLIED_ALPHA

§

BC3_UNORM

§

BC3_UNORM_PREMULTIPLIED_ALPHA

§

BC4_UNORM

§

BC4_SNORM

§

BC5_UNORM

§

BC5_SNORM

§

BC6H_UF16

§

BC6H_SF16

§

BC7_UNORM

§

ASTC_4X4_UNORM

§

ASTC_5X4_UNORM

§

ASTC_5X5_UNORM

§

ASTC_6X5_UNORM

§

ASTC_6X6_UNORM

§

ASTC_8X5_UNORM

§

ASTC_8X6_UNORM

§

ASTC_8X8_UNORM

§

ASTC_10X5_UNORM

§

ASTC_10X6_UNORM

§

ASTC_10X8_UNORM

§

ASTC_10X10_UNORM

§

ASTC_12X10_UNORM

§

ASTC_12X12_UNORM

§

BC3_UNORM_RXGB

This is just Format::BC3_UNORM, but with the R channel stored in alpha.

BC3 stores the A channel with a much higher precision than the other (color) channels. RXGB uses this by storing the R channel of the image in the BC3 A channel, effectively increasing the precision of not just the R channel, but also the G and B channels.

Note that this is an RGB format. The BC3-encoded R channel is commonly set to 0 to improve the quality of G and B.

§

BC3_UNORM_NORMAL

This format is also called DXT5n, DXT5nm, or BC3n. It’s intended for storing normal maps.

Similar to Format::BC3_UNORM_RXGB, this format stores the R channel in alpha. The B channel is discarded when encoding (set to 0), and reconstructed when decoding using the following formula:

B = 0.5 * sqrt(1 - (2*R - 1)^2 - (2*G - 1)^2) + 0.5

This format does not have a specified DXGI format or FourCC code. As such, it cannot be detected from a DDS header. This makes it the user’s to detect this format. When creating a header, this format will be represented by DxgiFormat::BC3_UNORM.

Note: This format is only supported for completeness. Don’t actually use it. BC7 and BC5 offer superior quality for the same compression ratio.

Implementations§

Source§

impl Format

Source

pub fn from_header(header: &Header) -> Result<Format, FormatError>

Returns the format of the surfaces from a DDS header.

Source

pub const fn from_dxgi(dxgi: DxgiFormat) -> Option<Format>

Returns the format of a surface from a DXGI format.

None if the DXGI format is not supported for decoding.

Source

pub const fn from_four_cc(four_cc: FourCC) -> Option<Format>

Returns the format of a surface from a FourCC code.

None if the FourCC code is not supported for decoding.

Source

pub const fn channels(&self) -> Channels

The number and type of (color) channels in the surface.

If the channels of a format cannot be accurately described by Channels, the next larger type is used. For example, a format with only R and G channels will be described as Channels::Rgb.

Source

pub const fn precision(&self) -> Precision

The precision/bit depth closest to the values in the surface.

DDS supports formats with various precisions and ranges, and not all of them can be represented exactly by the Precision enum. The closest precision is chosen based on the format’s range and encoded bit depth. It is typically larger than the encoded bit depth.

E.g. the format B5G6R5_UNORM is a 5/6-bit per channel format and the closest precision is Precision::U8. While U8 can closely approximate all B5G6R5_UNORM values, it is not exact. E.g. a 5-bit UNORM value of 11 is 90.48 as an 8-bit UNORM value exactly but will be rounded to 90.

Source

pub const fn color(&self) -> ColorFormat

The native color format of the surface.

This is simply Self::channels and Self::precision combined.

Source

pub const fn encoding_support(self) -> Option<EncodingSupport>

Returns information about the encoding support of this format.

If the format does not support encoding, None is returned.

Trait Implementations§

Source§

impl Clone for Format

Source§

fn clone(&self) -> Format

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Format

Source§

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

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

impl From<Format> for PixelInfo

Source§

fn from(value: Format) -> Self

Converts to this type from the input type.
Source§

impl Hash for Format

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Format

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 TryFrom<Format> for Dx9PixelFormat

Source§

type Error = ()

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

fn try_from(value: Format) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Format> for DxgiFormat

Source§

type Error = ()

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

fn try_from(value: Format) -> Result<DxgiFormat, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Format> for FourCC

Source§

type Error = ()

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

fn try_from(value: Format) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Format> for MaskPixelFormat

Source§

type Error = ()

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

fn try_from(value: Format) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for Format

Source§

impl Eq for Format

Source§

impl StructuralPartialEq for Format

Auto Trait Implementations§

§

impl Freeze for Format

§

impl RefUnwindSafe for Format

§

impl Send for Format

§

impl Sync for Format

§

impl Unpin for Format

§

impl UnwindSafe for Format

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.