A DDS file starts with the four bytes DDS , the value
0x20534444, followed by a 124-byte DDS_HEADER. Offsets below are
from the start of the file. All numbers are little-endian 32-bit values. The structure is
the binary equivalent of DirectDraw’s DDSURFACEDESC2.
Fields
| Offset | Size | Name | Description |
|---|---|---|---|
| 0 | 4 | dwMagic | DDS , 44 44 53 20. |
| 4 | 4 | dwSize | Size of the structure: must be 124. |
| 8 | 4 | dwFlags | Which fields hold valid data; see below. |
| 12 | 4 | dwHeight | Surface height in pixels. |
| 16 | 4 | dwWidth | Surface width in pixels. |
| 20 | 4 | dwPitchOrLinearSize | Bytes per scan line of an uncompressed texture, or the total bytes in the top level of a compressed texture. Compute it instead of trusting it; see data layout. |
| 24 | 4 | dwDepth | Depth of a volume texture in pixels; otherwise unused. |
| 28 | 4 | dwMipMapCount | Number of mipmap levels; otherwise unused. |
| 32 | 44 | dwReserved1[11] | Unused. |
| 76 | 32 | ddspf | The pixel format. |
| 108 | 4 | dwCaps | The complexity of the surfaces; see below. |
| 112 | 4 | dwCaps2 | Cube map and volume detail; see below. |
| 116 | 4 | dwCaps3 | Unused. |
| 120 | 4 | dwCaps4 | Unused. |
| 124 | 4 | dwReserved2 | Unused. |
dwFlags
| Flag | Value | Meaning |
|---|---|---|
DDSD_CAPS | 0x1 | Required in every file. |
DDSD_HEIGHT | 0x2 | Required in every file. |
DDSD_WIDTH | 0x4 | Required in every file. |
DDSD_PITCH | 0x8 | The pitch is given, for an uncompressed texture. |
DDSD_PIXELFORMAT | 0x1000 | Required in every file. |
DDSD_MIPMAPCOUNT | 0x20000 | Required in a mipmapped texture. |
DDSD_LINEARSIZE | 0x80000 | The pitch is given, for a compressed texture. |
DDSD_DEPTH | 0x800000 | Required in a depth texture. |
Microsoft’s advice is that writers should set these flags, but that readers should not
depend on DDSD_CAPS, DDSD_PIXELFORMAT or
DDSD_MIPMAPCOUNT being set, because some writers leave them out.
dwCaps
| Flag | Value | Meaning |
|---|---|---|
DDSCAPS_COMPLEX | 0x8 | More than one surface: a mipmap, a cube map or a mipmapped volume. |
DDSCAPS_TEXTURE | 0x1000 | Required. |
DDSCAPS_MIPMAP | 0x400000 | Should be set for a mipmap. |
As with dwFlags, readers should not rely on DDSCAPS_TEXTURE
or DDSCAPS_COMPLEX being set.
dwCaps2
| Flag | Value | Meaning |
|---|---|---|
DDSCAPS2_CUBEMAP | 0x200 | Required for a cube map. |
DDSCAPS2_CUBEMAP_POSITIVEX | 0x400 | The positive x face is stored. |
DDSCAPS2_CUBEMAP_NEGATIVEX | 0x800 | The negative x face is stored. |
DDSCAPS2_CUBEMAP_POSITIVEY | 0x1000 | The positive y face is stored. |
DDSCAPS2_CUBEMAP_NEGATIVEY | 0x2000 | The negative y face is stored. |
DDSCAPS2_CUBEMAP_POSITIVEZ | 0x4000 | The positive z face is stored. |
DDSCAPS2_CUBEMAP_NEGATIVEZ | 0x8000 | The negative z face is stored. |
DDSCAPS2_VOLUME | 0x200000 | Required for a volume texture. |
Direct3D 9 supports partial cube maps; Direct3D 10, 10.1 and 11 require all six faces.
Checking a file
Microsoft recommends this minimum check. The file must be at least 128 bytes long, start
with the magic value, have a dwSize of 124 and a pixel format
dwSize of 32. If the pixel format is DDPF_FOURCC with
dwFourCC DX10, the file must be at least 148 bytes long.