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

Last Built: Mar 06, 2020

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

Implementation

class pyffi.formats.dds.DdsFormat[source]

Bases: pyffi.object_models.xml.FileFormat

This class implements the DDS format.

class Data(version=150994944)[source]

Bases: pyffi.object_models.Data

A class to contain the actual dds data.

get_detail_child_names(edge_filter=(True, True))[source]

Generator which yields all child names of this item in the detail view.

Override this method if the node has children.

Returns

Generator for detail tree child names.

Return type

generator yielding strs

get_detail_child_nodes(edge_filter=(True, True))[source]

Generator which yields all children of this item in the detail view (by default, all acyclic and active ones).

Override this method if the node has children.

Parameters

edge_filter (EdgeFilter or type(None)) – The edge type to include.

Returns

Generator for detail tree child nodes.

Return type

generator yielding DetailNodes

inspect(stream)[source]

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

Parameters

stream (file) – The stream to inspect.

inspect_quick(stream)[source]

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)[source]

Read a dds file.

Parameters
  • stream (file) – The stream from which to read.

  • verbose (int) – The level of verbosity.

write(stream, verbose=0)[source]

Write a dds file.

Parameters
  • stream (file) – The stream to which to write.

  • verbose (int) – The level of verbosity.

class FourCC(**kwargs)

Bases: pyffi.object_models.xml.enum.EnumBase

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

class HeaderString(**kwargs)[source]

Bases: pyffi.object_models.xml.basic.BasicBase

Basic type which implements the header of a DDS file.

get_detail_display()[source]

Return an object that can be used to display the instance.

get_hash(data=None)[source]

Return a hash value for this value.

Returns

An immutable object that can be used as a hash.

get_size(data=None)[source]

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

Returns

Number of bytes.

read(stream, data)[source]

Read header string from stream and check it.

Parameters

stream (file) – The stream to read from.

write(stream, data)[source]

Write the header string to stream.

Parameters

stream (file) – The stream to write to.

PixelData

alias of pyffi.object_models.common.UndecodedData

byte

alias of pyffi.object_models.common.Byte

char

alias of pyffi.object_models.common.Char

float

alias of pyffi.object_models.common.Float

int

alias of pyffi.object_models.common.Int

short

alias of pyffi.object_models.common.Short

ubyte

alias of pyffi.object_models.common.UByte

uint

alias of pyffi.object_models.common.UInt

ushort

alias of pyffi.object_models.common.UShort

static version_number(version_str)[source]

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
>>> from os.path import dirname
>>> dirpath = __file__
>>> for i in range(4): #recurse up to root repo dir
...     dirpath = dirname(dirpath)
>>> repo_root = dirpath
>>> format_root = os.path.join(repo_root, 'tests', 'formats', 'dds')
>>> file = os.path.join(format_root, 'test.dds')
>>> stream = open(file, '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(format_root):
...     try:
...         # the replace call makes the doctest also pass on windows
...         os_path = stream.name
...         split = (os_path.split(os.sep))[-4:]
...         rejoin = os.path.join(*split).replace(os.sep, "/")
...         print("reading %s" % rejoin)
...     except Exception:
...         print(
...             "Warning: read failed due corrupt file,"
...             " corrupt format description, or bug.") 
reading tests/formats/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