🧱 DDS

Contents

🧱 DDS#

DDS Format.

Name:

DirectDraw Surface

Type:

🧱 Texture Encoder

Wiki:

https://en.wikipedia.org/wiki/DirectDraw_Surface

Suffix:

.dds

Support:

βœ… Full

Features:

DXT1, DXT3, DXT5, RGBA8, BGRA8, DXN_XY (ATI2), RGBA32F (DX10)

Example:

from scfile import formats

with formats.dds.DdsEncoder(data) as dds:
    dds.encode().save("output.dds")

Encoder#

class DdsEncoder(data, options=None, output=None)[source]#

Bases: FileEncoder[TextureContent[TextureType]]

format: FileFormat = 'dds'#

Associated file format.

signature: Optional[bytes] = b'DDS '#

Expected file signature.

order: ByteOrder = '<'#

Default byte order for pack/unpack operations.

serialize()[source]#

Write self.data to the output stream. Called by encode().

add_signature()#

Write the format signature to the output stream.

Return type:

None

close()#

Flush and close the IO object.

This method has no effect if the file is already closed.

Return type:

None

property closed: bool#
encode(transforms=None)#

Runs encoding pipeline.

Parameters:

transforms (Optional[list[Callable[[ModelScene], ModelScene]]]) – Override the default transforms for this call.

Return type:

Self

Returns:

Self (chaining).

export(path, mode='wb')#

Write encoded data to file by stem. Format suffix appended. Closes encoder.

Parameters:
  • path (str | Path | PathLike[str]) – Output file path.

  • mode (Literal['rb', 'rb+', 'wb', 'wb+', 'ab', 'ab+']) – File mode (binary).

Return type:

None

export_as(path, mode='wb')#

Write encoded data to file by stem. Format suffix appended. Keeps the encoder open.

Parameters:
  • path (str | Path | PathLike[str]) – Output file path.

  • mode (Literal['rb', 'rb+', 'wb', 'wb+', 'ab', 'ab+']) – File mode (binary).

Return type:

Self

fileno()#

Returns underlying file descriptor if one exists.

OSError is raised if the IO object does not use a file descriptor.

flush()#

Flush write buffers, if applicable.

This is not implemented for read-only and non-blocking streams.

Return type:

None

getvalue()#
Return type:

bytes

is_eof()#
Return type:

bool

isatty()#

Return whether this is an β€˜interactive’ stream.

Return False if it can’t be determined.

property location: str#
prelude()#

Hook called before transforms, signature and serialization.

Return type:

None

read(size=-1)#
Return type:

bytes

readable()#

Return whether object was opened for reading.

If False, read() will raise OSError.

Return type:

bool

readline(size=-1, /)#

Read and return a line from the stream.

If size is specified, at most size bytes will be read.

The line terminator is always b’n’ for binary files; for text files, the newlines argument to open can be used to select the line terminator(s) recognized.

readlines(hint=-1, /)#

Return a list of lines from the stream.

hint can be specified to control the number of lines read: no more lines will be read if the total size (in bytes/characters) of all lines so far exceeds hint.

save(path, mode='wb')#

Write encoded data to file by name. Closes encoder.

Parameters:
  • path (str | Path | PathLike[str]) – Output file path.

  • mode (Literal['rb', 'rb+', 'wb', 'wb+', 'ab', 'ab+']) – File mode (binary).

Return type:

None

save_as(path, mode='wb')#

Write encoded data to file by name. Keeps encoder open.

Parameters:
  • path (str | Path | PathLike[str]) – Output file path.

  • mode (Literal['rb', 'rb+', 'wb', 'wb+', 'ab', 'ab+']) – File mode (binary).

Return type:

Self

seek(pos, whence=0)#

Change the stream position to the given byte offset.

offset

The stream position, relative to β€˜whence’.

whence

The relative position to seek from.

The offset is interpreted relative to the position indicated by whence. Values for whence are:

  • os.SEEK_SET or 0 – start of stream (the default); offset should be zero or positive

  • os.SEEK_CUR or 1 – current stream position; offset may be negative

  • os.SEEK_END or 2 – end of stream; offset is usually negative

Return the new absolute position.

Return type:

int

seekable()#

Return whether object supports random access.

If False, seek(), tell() and truncate() will raise OSError. This method may need to do a test seek().

Return type:

bool

size()#
Return type:

int

skip(size)#
property suffix: str#
tell()#

Return current stream position.

Return type:

int

transform(transforms=None)#

Apply format-specific transforms to model data.

transforms: EncoderTransforms = None#

Format-specific transforms applied to model data before serialization.

truncate()#

Truncate file to size bytes.

File pointer is left unchanged. Size defaults to the current IO position as reported by tell(). Returns the new size.

unicode_errors: str = 'replace'#

Error handling mode for UTF-8 encoding/decoding.

writable()#

Return whether object was opened for writing.

If False, write() will raise OSError.

Return type:

bool

write(data)#
Return type:

int

writelines(lines, /)#

Write a list of lines to stream.

Line separators are not added, so it is usual for each of the lines provided to have a line separator at the end.

data: ContentType#
options: Options#

Shared handlers options.

ctx: TempContext#

Enums#

class HeaderFlag(value)[source]#

Bases: IntFlag

CAPS = 1#
HEIGHT = 2#
WIDTH = 4#
PITCH = 8#
PIXELFORMAT = 4096#
MIPMAPCOUNT = 131072#
LINEARSIZE = 524288#
DEPTH = 8388608#
class PixelFormatFlag(value)[source]#

Bases: IntFlag

ALPHAPIXELS = 1#
ALPHA = 2#
FOURCC = 4#
RGB = 64#
class CubemapFlag(value)[source]#

Bases: IntFlag

POSITIVE_X = 1024#
POSX = 1024#
NEGATIVE_X = 2048#
NEGX = 2048#
POSITIVE_Y = 4096#
POSY = 4096#
NEGATIVE_Y = 8192#
NEGY = 8192#
POSITIVE_Z = 16384#
POSZ = 16384#
NEGATIVE_Z = 32768#
NEGZ = 32768#
class DXGIFormat(value)[source]#

Bases: IntFlag

FLOAT_R32G32B32A32 = 2#
FLOAT_R32G32B32 = 6#
class DXGIDimension(value)[source]#

Bases: IntFlag

BUFFER = 1#
TEXTURE1D = 2#
TEXTURE2D = 3#
TEXTURE3D = 4#
class ChannelMask(value)[source]#

Bases: IntFlag

RED = 255#
R = 255#
GREEN = 65280#
G = 65280#
BLUE = 16711680#
B = 16711680#
ALPHA = 4278190080#
A = 4278190080#

Header#

class Header[source]#
SIZE = 124#
FLAG#

alias of HeaderFlag

FLAGS = 135175#
class PixelFormat[source]#
SIZE = 32#
BIT_COUNT = 32#
FLAG#

alias of PixelFormatFlag

RGB = 65#
class DDS[source]#
HEADER#

alias of Header

PF#

alias of PixelFormat

CF#

alias of CubemapFlag

CUBEMAP = 512#
CUBEMAPS = 65024#
COMPLEX = 8#
TEXTURE = 4096#
MIPMAP = 4194304#
CAPS1 = 4198408#