pub type Dds = DdsBase<Vec<u8>>;Expand description
A DDS that owns its payload. This is what Dds::read produces, and it is
what Dds has always meant.
Aliased Type§
pub struct Dds {
pub header: Header,
pub header10: Option<Header10>,
pub data: Vec<u8>,
}Fields§
§header: Header§header10: Option<Header10>§data: Vec<u8>Implementations§
Source§impl Dds
impl Dds
Sourcepub fn encode_from_rgba8(
pixels: &[u8],
layout: EncodeLayout,
) -> Result<Dds, Error>
Available on crate feature encode only.
pub fn encode_from_rgba8( pixels: &[u8], layout: EncodeLayout, ) -> Result<Dds, Error>
encode only.Encode tightly packed RGBA8 pixels into a new DDS matching EncodeLayout.
Source layout (mip 0 only; extra mips are box-filtered):
- 2D:
width * height * 4 - Array: layers stacked
- Cubemap: faces in DirectX order, then cubes
- Volume: depth slices stacked (
zmajor after rows)
Source§impl Dds
impl Dds
Sourcepub fn encode_bc6h_uf16(
pixels: &[f32],
width: u32,
height: u32,
) -> Result<Dds, Error>
Available on crate feature encode only.
pub fn encode_bc6h_uf16( pixels: &[f32], width: u32, height: u32, ) -> Result<Dds, Error>
encode only.Encode tightly packed RGBA f32 pixels (alpha ignored) as a 2D
BC6H_UF16 DDS (mode 11: single subset, 10-bit endpoints, 4-bit
indices). Negative / NaN inputs clamp to 0, values above the half
range clamp to 65504. Round-trips through Dds::decode_rgba_f32.
Source§impl Dds
impl Dds
Sourcepub fn new_d3d(params: NewD3dParams) -> Result<Dds, Error>
pub fn new_d3d(params: NewD3dParams) -> Result<Dds, Error>
Create a new DirectDraw Surface with a D3DFormat
Sourcepub fn new_dxgi(params: NewDxgiParams) -> Result<Dds, Error>
pub fn new_dxgi(params: NewDxgiParams) -> Result<Dds, Error>
Create a new DirectDraw Surface with a DxgiFormat
Sourcepub fn read<R: Read>(r: R) -> Result<Dds, Error>
pub fn read<R: Read>(r: R) -> Result<Dds, Error>
Read a DDS file, accepting a payload of any length.
The payload is read to end-of-stream with no cap, so the peak allocation
is whatever the reader yields. That is the right behaviour for a trusted
file on disk and the wrong one for bytes arriving from a network, a
user upload, or a mod archive — for those, use Dds::read_limited,
which fails closed at a byte budget you choose.
Sourcepub fn read_limited<R: Read>(r: R, max_data_len: usize) -> Result<Dds, Error>
pub fn read_limited<R: Read>(r: R, max_data_len: usize) -> Result<Dds, Error>
Read a DDS file, refusing a payload larger than max_data_len bytes.
The limit covers the payload only — the 128-byte header (148 with a
DX10 header) is read first and is not counted. Exceeding it returns
Error::SizeLimitExceeded without buffering the overrun, so a hostile
or corrupt stream cannot force an unbounded allocation.
use rusty_dds::{Dds, Error};
let mut bytes = Vec::new();
Dds::new_dxgi(rusty_dds::NewDxgiParams {
height: 64, width: 64, depth: None,
format: rusty_dds::DxgiFormat::BC1_UNorm,
mipmap_levels: None, array_layers: None, caps2: None, is_cubemap: false,
resource_dimension: rusty_dds::D3D10ResourceDimension::Texture2D,
alpha_mode: rusty_dds::AlphaMode::Straight,
})?.write(&mut bytes)?;
assert!(Dds::read_limited(&bytes[..], 8 * 1024).is_ok());
assert!(matches!(
Dds::read_limited(&bytes[..], 16),
Err(Error::SizeLimitExceeded { .. })
));