The dds Module


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.
Reference material.


make4CC(int code) → str

Creates a 4CC string from an int.

get4CC(str code) → int

Creates a 4CC int from a string.



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("")
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."", data)
save(str path, data, savealpha=False) → None
  • 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.



The DDS_HEADER-header structure.


The DDS_PIXELFORMAT-header structure.


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

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


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)


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 Fast, secure and Free Open Source software downloads