The dds Module

Warning

This module is not yet ready and some changes should be expected.

Helper utilities for .dds-file processing.

See also

Wikipedia: DirectDraw Surface
Information and links.
MSDN: DDS
Reference material.

Functions

make4CC(int code) → str

Creates a 4CC string from an int.

get4CC(str code) → int

Creates a 4CC int from a string.

Classes

DDSFile

This class can load and manipulate a (very) limited set of .dds-files.

class dds.DDSFile
DDSFile(str path) → DDSFile

The constructor loads and verifies .dds headers.

getItemFormat() → str

Returns a format string describing one pixel. Compatible with the struct-module. Can return None if the format is not supported.

isVersion10() → bool

Returns True if the file has a DDS_HEADER_DXT10-header in it.

readSurface() → list

Reads the first surface into a list which in turn contains lists containing RGBA-objects.

f = DDSFile("myfile.dds")
data = f.readSurface()

#Process every pixel.
for row in data:
    for pixel in row:
        pixel.r = 0
        ...

#Change pixel (x=42, y=30) to red, full alpha.
data[42][30] = RGBA(255, 0, 0, 255)
#Set pixels (10, 15) alpha component to 0 (fully transparent).
data[10][15].a = 0

#Save the processed data into a new file.
f.save("myfile_out.dds", data)
save(str path, data, savealpha=False) → None
Parameters:
  • path – File path into the target file.
  • data – A list received previously from readSurface().
  • savealpha – If True the file is marked as containing alpha values.

Saves data into a file in RGBA8 format. DDS_HEADER_DXT10-header is not written.

size() → int width, int height

Returns textures dimensions.

Attributes

HEADER

The DDS_HEADER-header structure.

PIXELFORMAT

The DDS_PIXELFORMAT-header structure.

HEADER_DXT10

The DDS_HEADER_DXT10-header structure. This can be None if the file does not have this header.

f = DDSFile("image.dds")
print("Width of the image: %i" % f.HEADER.dwWidth)

RGBA

A very simple color class. Values can be intergers or floats.

class dds.RGBA
RGBA(r=0, g=0, b=0, a=0) → RGBA

Creates a new instance.

RGBA[int index] -> int/float

Indexing support.

rgba = RGBA(...)
assert(rgba[0] == rgba.r)
assert(rgba[1] == rgba.g)
#etc.

Attributes

r - int/float

The red component.

g - int/float

The green component.

b - int/float

The blue component.

a - int/float

The alpha component.

Table Of Contents

Get DirectPython 11 at SourceForge.net. Fast, secure and Free Open Source software downloads