### Navigation

- index
- modules |
- next |
- previous |
- PyFFI 2.2.2 documentation »
- `pyffi` — Interfacing block structured files »
- `pyffi.formats` — File format interfaces »

# `pyffi.formats.dds` — DirectDraw Surface (.dds)

## Implementation

class `pyffi.formats.dds.``DdsFormat`

  Bases: `pyffi.object_models.xml.FileFormat`

  This class implements the DDS format.

  class `Data`(version=150994944)

    Bases: `pyffi.object_models.Data`

    A class to contain the actual dds data.

    `inspect`(stream)

      Quickly checks if stream contains DDS data, and reads the header.

      Parameters: | stream (file) – The stream to inspect.

    `inspect_quick`(stream)

      Quickly checks if stream contains DDS data, and gets the version, by looking at the first 8 bytes.

      Parameters: | stream (file) – The stream to inspect.

    `read`(stream, verbose=0)

      Read a dds file.

      Parameters: | stream (`file`) – The stream from which to read. verbose (`int`) – The level of verbosity.

    `write`(stream, verbose=0)

      Write a dds file.

      Parameters: | stream (`file`) – The stream to which to write. verbose (`int`) – The level of verbosity.

  class `DdsFormat.``FourCC`(**kwargs)

    Bases: `pyffi.object_models.xml.enum.EnumBase`

    An unsigned 32-bit integer, describing the compression type.

  class `DdsFormat.``HeaderString`(**kwargs)

    Bases: `pyffi.object_models.xml.basic.BasicBase`

    Basic type which implements the header of a DDS file.

    `get_hash`(data=None)

      Return a hash value for this value.

      Returns: | An immutable object that can be used as a hash.

    `get_size`(data=None)

      Return number of bytes the header string occupies in a file.

      Returns: | Number of bytes.

    `read`(stream, data)

      Read header string from stream and check it.

      Parameters: | stream (file) – The stream to read from.

    `write`(stream, data)

      Write the header string to stream.

      Parameters: | stream (file) – The stream to write to.

  `DdsFormat.``PixelData`

    alias of `UndecodedData`

  `DdsFormat.``byte`

    alias of `Byte`

  `DdsFormat.``char`

    alias of `Char`

  `DdsFormat.``float`

    alias of `Float`

  `DdsFormat.``int`

    alias of `Int`

  `DdsFormat.``short`

    alias of `Short`

  `DdsFormat.``ubyte`

    alias of `UByte`

  `DdsFormat.``uint`

    alias of `UInt`

  `DdsFormat.``ushort`

    alias of `UShort`

  static `DdsFormat.``version_number`(version_str)

    Converts version string into an integer.

    Parameters: | version_str (str) – The version string.
    Returns: | A version integer.

        >>> hex(DdsFormat.version_number('DX10'))
        '0xa000000'

## Regression tests

### Read a DDS file

    >>> # check and read dds file
    >>> stream = open('tests/dds/test.dds', 'rb')
    >>> data = DdsFormat.Data()
    >>> data.inspect(stream)
    >>> data.header.pixel_format.size
    32
    >>> data.header.height
    20
    >>> data.read(stream)
    >>> len(data.pixeldata.get_value())
    888

### Parse all DDS files in a directory tree

    >>> for stream, data in DdsFormat.walkData('tests/dds'):
    ...     print(stream.name)
    tests/dds/test.dds

### Create a DDS file from scratch and write to file

    >>> data = DdsFormat.Data()
    >>> from tempfile import TemporaryFile
    >>> stream = TemporaryFile()
    >>> data.write(stream)

### Get list of versions

    >>> for vnum in sorted(DdsFormat.versions.values()):
    ...     print('0x%08X' % vnum)
    0x09000000
    0x0A000000

### Navigation

- index
- modules |
- next |
- previous |
- PyFFI 2.2.2 documentation »
- `pyffi` — Interfacing block structured files »
- `pyffi.formats` — File format interfaces »