| 1 |
#!/usr/bin/python |
| 2 |
import sys, struct |
| 3 |
|
| 4 |
# Lookup tables for DDS flags |
| 5 |
|
| 6 |
DDSD_FLAG_TABLE = \ |
| 7 |
{ |
| 8 |
'DDSD_CAPS' : 0x1, |
| 9 |
'DDSD_HEIGHT' : 0x2, |
| 10 |
'DDSD_WIDTH' : 0x4, |
| 11 |
'DDSD_PITCH' : 0x8, |
| 12 |
'DDSD_PIXELFORMAT' : 0x1000, |
| 13 |
'DDSD_MIPMAPCOUNT' : 0x20000, |
| 14 |
'DDSD_LINEARSIZE' : 0x80000, |
| 15 |
'DDSD_DEPTH' : 0x800000 |
| 16 |
} |
| 17 |
|
| 18 |
DDPF_FLAG_TABLE = \ |
| 19 |
{ |
| 20 |
'DDPF_ALPHAPIXELS' : 0x1, |
| 21 |
'DDPF_FOURCC' : 0x4, |
| 22 |
'DDPF_RGB' : 0x40 |
| 23 |
} |
| 24 |
|
| 25 |
# ----------------------------------------------------------------------------- |
| 26 |
# Main script |
| 27 |
|
| 28 |
inFile = open(sys.argv[1]) |
| 29 |
|
| 30 |
# Read and unpack the header |
| 31 |
rawData = inFile.read(32) |
| 32 |
( sMagic, |
| 33 |
dwSize, |
| 34 |
dwFlags, |
| 35 |
dwHeight, |
| 36 |
dwWidth, |
| 37 |
dwPitchOrLinearSize, |
| 38 |
dwDepth, |
| 39 |
dwMipMapCount |
| 40 |
) = \ |
| 41 |
struct.unpack('4s I I I I I I I', rawData) |
| 42 |
|
| 43 |
# Must have magic header |
| 44 |
if (sMagic != 'DDS ' or dwSize != 124): |
| 45 |
print "Not a valid DDS file." |
| 46 |
sys.exit(1) |
| 47 |
|
| 48 |
# Print out header information |
| 49 |
print "DDS file, %dx%d" % (dwWidth, dwHeight) |
| 50 |
|
| 51 |
if (dwFlags & DDSD_FLAG_TABLE['DDSD_LINEARSIZE']): |
| 52 |
print "\t%d bytes" % dwPitchOrLinearSize |
| 53 |
|
| 54 |
if (dwFlags & DDSD_FLAG_TABLE['DDSD_MIPMAPCOUNT']): |
| 55 |
print "\t%d mipmaps" % dwMipMapCount |
| 56 |
|
| 57 |
# Discard the 11 reserved DWORDS |
| 58 |
inFile.read(11 * 4) |
| 59 |
|
| 60 |
# Read the pixel format |
| 61 |
rawPixelFormat = inFile.read(32) |
| 62 |
( |
| 63 |
dwSize, |
| 64 |
dwFlags, |
| 65 |
sFourCC, |
| 66 |
dwRGBBitCount, |
| 67 |
dwRBitMask, |
| 68 |
dwGBitMask, |
| 69 |
dwBBitMask, |
| 70 |
dwRGBAlphaBitMask |
| 71 |
) = \ |
| 72 |
struct.unpack('2I 4s 5I', rawPixelFormat) |
| 73 |
|
| 74 |
# Print out pixel format information |
| 75 |
if (DDPF_FLAG_TABLE['DDPF_FOURCC'] & dwFlags): |
| 76 |
print "\t%s" % sFourCC |
| 77 |
|
| 78 |
# Close file |
| 79 |
inFile.close() |
| 80 |
|
| 81 |
|