A reader and writer for DirectDraw Surface (.dds) files, which are
used to describe textures. These files can contain multiple mipmap
levels in one file. This class is currently minimal and does not
support all of the possible file formats.
D3DFMT_A8R8G8B8
public static final int D3DFMT_A8R8G8B8
D3DFMT_DXT1
public static final int D3DFMT_DXT1
D3DFMT_DXT2
public static final int D3DFMT_DXT2
D3DFMT_DXT3
public static final int D3DFMT_DXT3
D3DFMT_DXT4
public static final int D3DFMT_DXT4
D3DFMT_DXT5
public static final int D3DFMT_DXT5
D3DFMT_R8G8B8
public static final int D3DFMT_R8G8B8
D3DFMT_UNKNOWN
public static final int D3DFMT_UNKNOWN
D3DFMT_X8R8G8B8
public static final int D3DFMT_X8R8G8B8
DDPF_ALPHA
public static final int DDPF_ALPHA
DDPF_ALPHAPIXELS
public static final int DDPF_ALPHAPIXELS
DDPF_COMPRESSED
public static final int DDPF_COMPRESSED
DDPF_FOURCC
public static final int DDPF_FOURCC
DDPF_PALETTEINDEXED1
public static final int DDPF_PALETTEINDEXED1
DDPF_PALETTEINDEXED2
public static final int DDPF_PALETTEINDEXED2
DDPF_PALETTEINDEXED4
public static final int DDPF_PALETTEINDEXED4
DDPF_PALETTEINDEXED8
public static final int DDPF_PALETTEINDEXED8
DDPF_PALETTEINDEXEDTO8
public static final int DDPF_PALETTEINDEXEDTO8
DDPF_RGB
public static final int DDPF_RGB
DDPF_RGBTOYUV
public static final int DDPF_RGBTOYUV
DDPF_YUV
public static final int DDPF_YUV
DDPF_ZBUFFER
public static final int DDPF_ZBUFFER
DDPF_ZPIXELS
public static final int DDPF_ZPIXELS
DDSCAPS2_CUBEMAP
public static final int DDSCAPS2_CUBEMAP
DDSCAPS2_CUBEMAP_NEGATIVEX
public static final int DDSCAPS2_CUBEMAP_NEGATIVEX
DDSCAPS2_CUBEMAP_NEGATIVEY
public static final int DDSCAPS2_CUBEMAP_NEGATIVEY
DDSCAPS2_CUBEMAP_NEGATIVEZ
public static final int DDSCAPS2_CUBEMAP_NEGATIVEZ
DDSCAPS2_CUBEMAP_POSITIVEX
public static final int DDSCAPS2_CUBEMAP_POSITIVEX
DDSCAPS2_CUBEMAP_POSITIVEY
public static final int DDSCAPS2_CUBEMAP_POSITIVEY
DDSCAPS2_CUBEMAP_POSITIVEZ
public static final int DDSCAPS2_CUBEMAP_POSITIVEZ
DDSCAPS_COMPLEX
public static final int DDSCAPS_COMPLEX
DDSCAPS_MIPMAP
public static final int DDSCAPS_MIPMAP
DDSCAPS_TEXTURE
public static final int DDSCAPS_TEXTURE
DDSD_ALPHABITDEPTH
public static final int DDSD_ALPHABITDEPTH
DDSD_BACKBUFFERCOUNT
public static final int DDSD_BACKBUFFERCOUNT
DDSD_CAPS
public static final int DDSD_CAPS
DDSD_DEPTH
public static final int DDSD_DEPTH
DDSD_HEIGHT
public static final int DDSD_HEIGHT
DDSD_LINEARSIZE
public static final int DDSD_LINEARSIZE
DDSD_LPSURFACE
public static final int DDSD_LPSURFACE
DDSD_MIPMAPCOUNT
public static final int DDSD_MIPMAPCOUNT
DDSD_PITCH
public static final int DDSD_PITCH
DDSD_PIXELFORMAT
public static final int DDSD_PIXELFORMAT
DDSD_WIDTH
public static final int DDSD_WIDTH
DDSD_ZBUFFERBITDEPTH
public static final int DDSD_ZBUFFERBITDEPTH
allocateBlankBuffer
public static ByteBuffer allocateBlankBuffer(int width,
int height,
int openGLInternalFormat)
Allocates a temporary, empty ByteBuffer suitable for use in a
call to glCompressedTexImage2D. This is used by the Texture
class to expand non-power-of-two DDS compressed textures to
power-of-two sizes on hardware not supporting OpenGL 2.0 and the
NPOT texture extension. The specified OpenGL internal format
must be one of GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, or
GL_COMPRESSED_RGBA_S3TC_DXT5_EXT.
close
public void close()
Closes open files and resources associated with the open
DDSImage. No other methods may be called on this object once
this is called.
createFromData
public static DDSImage createFromData(int d3dFormat,
int width,
int height,
ByteBuffer[] mipmapData)
throws IllegalArgumentException
Creates a new DDSImage from data supplied by the user. The
resulting DDSImage can be written to disk using the write()
method.
d3dFormat
- the D3DFMT_ constant describing the data; it is
assumed that it is packed tightlywidth
- the width in pixels of the topmost mipmap imageheight
- the height in pixels of the topmost mipmap imagemipmapData
- the data for each mipmap level of the resulting
DDSImage; either only one mipmap level should
be specified, or they all must be
debugPrint
public void debugPrint()
getAllMipMaps
public DDSImage.ImageInfo[] getAllMipMaps()
Returns an array of ImageInfos corresponding to all mipmap
levels of this DDS file.
getAllMipMaps
public DDSImage.ImageInfo[] getAllMipMaps(int side)
Returns an array of ImageInfos corresponding to all mipmap
levels of this DDS file.
side
- Cubemap side or 0 for 2D texture
getCompressionFormat
public int getCompressionFormat()
If this surface is compressed, returns the kind of compression
used (DXT1..DXT5).
getCompressionFormatName
public static String getCompressionFormatName(int compressionFormat)
compressionFormat
- Compression format constant
getDepth
public int getDepth()
Total number of bits per pixel. Only valid if DDPF_RGB is
present. For A8R8G8B8, would be 32.
getHeight
public int getHeight()
Height of the texture (or the top-most mipmap if mipmaps are
present)
getMipMap
public DDSImage.ImageInfo getMipMap(int map)
Gets the ith mipmap data (0..getNumMipMaps() - 1)
getMipMap
public DDSImage.ImageInfo getMipMap(int side,
int map)
Gets the ith mipmap data (0..getNumMipMaps() - 1)
side
- Cubemap side or 0 for 2D texturemap
- Mipmap index
getNumMipMaps
public int getNumMipMaps()
Number of mip maps in the texture
getPixelFormat
public int getPixelFormat()
Gets the pixel format of this texture (D3DFMT_*) based on some
heuristics. Returns D3DFMT_UNKNOWN if could not recognize the
pixel format.
getWidth
public int getWidth()
Width of the texture (or the top-most mipmap if mipmaps are
present)
isCompressed
public boolean isCompressed()
Indicates whether this texture is compressed.
isCubemap
public boolean isCubemap()
Indicates whether this texture is cubemap
- true if cubemap or false otherwise
isCubemapSidePresent
public boolean isCubemapSidePresent(int side)
Indicates whethe this cubemap side present
- true if side present or false otherwise
isDDSImage
public static boolean isDDSImage(InputStream in)
throws IOException
Determines from the magic number whether the given InputStream
points to a DDS image. The given InputStream must return true
from markSupported() and support a minimum of four bytes of
read-ahead.
- true if input stream is DDS image or false otherwise
isPixelFormatFlagSet
public boolean isPixelFormatFlagSet(int flag)
Test for presence/absence of pixel format flags (DDPF_*)
isSurfaceDescFlagSet
public boolean isSurfaceDescFlagSet(int flag)
Test for presence/absence of surface description flags (DDSD_*)
flag
- DDSD_* flags set to test
- true if flag present or false otherwise
read
public static DDSImage read(ByteBuffer buf)
throws IOException
Reads a DirectDraw surface from the specified ByteBuffer, returning
the resulting DDSImage.
read
public static DDSImage read(File file)
throws IOException
Reads a DirectDraw surface from the specified file, returning
the resulting DDSImage.
read
public static DDSImage read(String filename)
throws IOException
Reads a DirectDraw surface from the specified file name,
returning the resulting DDSImage.
write
public void write(File file)
throws IOException
Writes this DDSImage to the specified file name.
file
- File object to write to
write
public void write(String filename)
throws IOException
Writes this DDSImage to the specified file name.
filename
- File name to write to