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.
- stream (
-
write
(stream, verbose=0)¶ Write a dds file.
Parameters: - stream (
file
) – The stream to which to write. - verbose (
int
) – The level of verbosity.
- stream (
-
-
class
FourCC
(**kwargs)¶ Bases:
pyffi.object_models.xml.enum.EnumBase
An unsigned 32-bit integer, describing the compression type.
-
class
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.
-
-
PixelData
¶ alias of
UndecodedData
-
byte
¶ alias of
Byte
-
char
¶ alias of
Char
-
float
¶ alias of
Float
-
int
¶ alias of
Int
-
short
¶ alias of
Short
-
ubyte
¶ alias of
UByte
-
uint
¶ alias of
UInt
-
ushort
¶ alias of
UShort
-
static
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'
-
class
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