Top Description Inners Fields Constructors Methods
com.jogamp.opengl.util.texture.spi

public Class DDSImage

extends Object
Class Inheritance
Imports
java.io.BufferedInputStream, .File, .FileInputStream, .FileOutputStream, .IOException, .InputStream, .PrintStream, java.nio.ByteBuffer, .ByteOrder, java.nio.channels.FileChannel, com.jogamp.opengl.GL, com.jogamp.common.nio.Buffers, com.jogamp.common.util.IOUtil, com.jogamp.opengl.util.texture.ImageType

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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
public static class
DDSImage.ImageInfo

Simple class describing images and data; does not encapsulate image format information.

Field Summary

Modifier and TypeField and Description
private ByteBuffer
private FileChannel
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
private FileInputStream
private DDSImage.Header
private static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ByteBuffer
allocateBlankBuffer(final int width, final int height, final int openGLInternalFormat)

Allocates a temporary, empty ByteBuffer suitable for use in a call to glCompressedTexImage2D.

public void
close()

Closes open files and resources associated with the open DDSImage.

private static int
computeBlockSize(final int width, final int height, final int depth, final int pixelFormat)

private static int
computeCompressedBlockSize(final int width, final int height, final int depth, final int compressionFormat)

public static DDSImage

Returns:

DDS image object
createFromData
(final int
the D3DFMT_ constant describing the data; it is assumed that it is packed tightly
d3dFormat
,
final int
the width in pixels of the topmost mipmap image
width
,
final int
the height in pixels of the topmost mipmap image
height
,
final ByteBuffer[]
the data for each mipmap level of the resulting DDSImage; either only one mipmap level should be specified, or they all must be
mipmapData
)

Creates a new DDSImage from data supplied by the user.

public void
private void
public DDSImage.ImageInfo[]

Returns:

Mipmap image objects set
getAllMipMaps
()

Returns an array of ImageInfos corresponding to all mipmap levels of this DDS file.

public DDSImage.ImageInfo[]

Returns:

Mipmap image objects set
getAllMipMaps
(final int
Cubemap side or 0 for 2D texture
side
)

Returns an array of ImageInfos corresponding to all mipmap levels of this DDS file.

public int
getCompressionFormat()

If this surface is compressed, returns the kind of compression used (DXT1..DXT5).

public static String

Returns:

String format code
getCompressionFormatName
(int
Compression format constant
compressionFormat
)

Converts e.g. DXT1 compression format constant (see getCompressionFormat) into "DXT1".

public int
getDepth()

Total number of bits per pixel.

public int
getHeight()

Height of the texture (or the top-most mipmap if mipmaps are present)

public DDSImage.ImageInfo

Returns:

Image object
getMipMap
(final int
Mipmap index
map
)

Gets the ith mipmap data (0..getNumMipMaps() - 1)

public DDSImage.ImageInfo

Returns:

Image object
getMipMap
(final int
Cubemap side or 0 for 2D texture
side
,
final int
Mipmap index
map
)

Gets the ith mipmap data (0..getNumMipMaps() - 1)

public int
getNumMipMaps()

Number of mip maps in the texture

public int
getPixelFormat()

Gets the pixel format of this texture (D3DFMT_*) based on some heuristics.

public int
getWidth()

Width of the texture (or the top-most mipmap if mipmaps are present)

private void
initFromData(final int d3dFormat, final int width, final int height, final ByteBuffer[] mipmapData)

public boolean
isCompressed()

Indicates whether this texture is compressed.

public boolean

Returns:

true if cubemap or false otherwise
isCubemap
()

Indicates whether this texture is cubemap

public boolean

Returns:

true if side present or false otherwise
isCubemapSidePresent
(final int
Side to test
side
)

Indicates whethe this cubemap side present

public static boolean

Returns:

true if input stream is DDS image or false otherwise
isDDSImage
(InputStream
Stream to check
in
)

Deprecated rather call ImageType#getFileSuffix(InputStream)
Determines from the magic number whether the given InputStream points to a DDS image.
public boolean
isPixelFormatFlagSet(final int flag)

Test for presence/absence of pixel format flags (DDPF_*)

public boolean

Returns:

true if flag present or false otherwise
isSurfaceDescFlagSet
(final int
DDSD_* flags set to test
flag
)

Test for presence/absence of surface description flags (DDSD_*)

private int
mipMapHeight(final int map)

private int
mipMapSizeInBytes(final int map)

private int
mipMapWidth(final int map)

private boolean
printIfRecognized(final PrintStream tty, final int flags, final int flag, final String what)

public static DDSImage

Returns:

DDS image object
read
(final String
File name
filename
)

Reads a DirectDraw surface from the specified file name, returning the resulting DDSImage.

public static DDSImage

Returns:

DDS image object
read
(final File
File object
file
)

Reads a DirectDraw surface from the specified file, returning the resulting DDSImage.

public static DDSImage

Returns:

DDS image object
read
(final ByteBuffer
Input data
buf
)

Reads a DirectDraw surface from the specified ByteBuffer, returning the resulting DDSImage.

private void
private void
readFromFile(final File file)

private int
sideShiftInBytes(final int side)

private int
public void
write(final String
File name to write to
filename
)

Writes this DDSImage to the specified file name.

public void
write(final File
File object to write to
file
)

Writes this DDSImage to the specified file name.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufback to summary
private ByteBuffer buf
chanback to summary
private FileChannel chan
D3DFMT_A8R8G8B8back to summary
public static final int D3DFMT_A8R8G8B8
D3DFMT_DXT1back to summary
public static final int D3DFMT_DXT1
D3DFMT_DXT2back to summary
public static final int D3DFMT_DXT2
D3DFMT_DXT3back to summary
public static final int D3DFMT_DXT3
D3DFMT_DXT4back to summary
public static final int D3DFMT_DXT4
D3DFMT_DXT5back to summary
public static final int D3DFMT_DXT5
D3DFMT_R8G8B8back to summary
public static final int D3DFMT_R8G8B8
D3DFMT_UNKNOWNback to summary
public static final int D3DFMT_UNKNOWN
D3DFMT_X8R8G8B8back to summary
public static final int D3DFMT_X8R8G8B8
DDPF_ALPHAback to summary
public static final int DDPF_ALPHA
DDPF_ALPHAPIXELSback to summary
public static final int DDPF_ALPHAPIXELS
DDPF_COMPRESSEDback to summary
public static final int DDPF_COMPRESSED
DDPF_FOURCCback to summary
public static final int DDPF_FOURCC
DDPF_PALETTEINDEXED1back to summary
public static final int DDPF_PALETTEINDEXED1
DDPF_PALETTEINDEXED2back to summary
public static final int DDPF_PALETTEINDEXED2
DDPF_PALETTEINDEXED4back to summary
public static final int DDPF_PALETTEINDEXED4
DDPF_PALETTEINDEXED8back to summary
public static final int DDPF_PALETTEINDEXED8
DDPF_PALETTEINDEXEDTO8back to summary
public static final int DDPF_PALETTEINDEXEDTO8
DDPF_RGBback to summary
public static final int DDPF_RGB
DDPF_RGBTOYUVback to summary
public static final int DDPF_RGBTOYUV
DDPF_YUVback to summary
public static final int DDPF_YUV
DDPF_ZBUFFERback to summary
public static final int DDPF_ZBUFFER
DDPF_ZPIXELSback to summary
public static final int DDPF_ZPIXELS
DDSCAPS2_CUBEMAPback to summary
public static final int DDSCAPS2_CUBEMAP
DDSCAPS2_CUBEMAP_NEGATIVEXback to summary
public static final int DDSCAPS2_CUBEMAP_NEGATIVEX
DDSCAPS2_CUBEMAP_NEGATIVEYback to summary
public static final int DDSCAPS2_CUBEMAP_NEGATIVEY
DDSCAPS2_CUBEMAP_NEGATIVEZback to summary
public static final int DDSCAPS2_CUBEMAP_NEGATIVEZ
DDSCAPS2_CUBEMAP_POSITIVEXback to summary
public static final int DDSCAPS2_CUBEMAP_POSITIVEX
DDSCAPS2_CUBEMAP_POSITIVEYback to summary
public static final int DDSCAPS2_CUBEMAP_POSITIVEY
DDSCAPS2_CUBEMAP_POSITIVEZback to summary
public static final int DDSCAPS2_CUBEMAP_POSITIVEZ
DDSCAPS_COMPLEXback to summary
public static final int DDSCAPS_COMPLEX
DDSCAPS_MIPMAPback to summary
public static final int DDSCAPS_MIPMAP
DDSCAPS_TEXTUREback to summary
public static final int DDSCAPS_TEXTURE
DDSD_ALPHABITDEPTHback to summary
public static final int DDSD_ALPHABITDEPTH
DDSD_BACKBUFFERCOUNTback to summary
public static final int DDSD_BACKBUFFERCOUNT
DDSD_CAPSback to summary
public static final int DDSD_CAPS
DDSD_DEPTHback to summary
public static final int DDSD_DEPTH
DDSD_HEIGHTback to summary
public static final int DDSD_HEIGHT
DDSD_LINEARSIZEback to summary
public static final int DDSD_LINEARSIZE
DDSD_LPSURFACEback to summary
public static final int DDSD_LPSURFACE
DDSD_MIPMAPCOUNTback to summary
public static final int DDSD_MIPMAPCOUNT
DDSD_PITCHback to summary
public static final int DDSD_PITCH
DDSD_PIXELFORMATback to summary
public static final int DDSD_PIXELFORMAT
DDSD_WIDTHback to summary
public static final int DDSD_WIDTH
DDSD_ZBUFFERBITDEPTHback to summary
public static final int DDSD_ZBUFFERBITDEPTH
fisback to summary
private FileInputStream fis
MAGICback to summary
private static final int MAGIC

Constructor Detail

DDSImageback to summary
private DDSImage()

Method Detail

allocateBlankBufferback to summary
public static ByteBuffer allocateBlankBuffer(final int width, final int height, final 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.

closeback to summary
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.

computeBlockSizeback to summary
private static int computeBlockSize(final int width, final int height, final int depth, final int pixelFormat)
computeCompressedBlockSizeback to summary
private static int computeCompressedBlockSize(final int width, final int height, final int depth, final int compressionFormat)
createFromDataback to summary
public static DDSImage createFromData(final int d3dFormat, final int width, final int height, final 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.

Parameters
d3dFormat:int

the D3DFMT_ constant describing the data; it is assumed that it is packed tightly

width:int

the width in pixels of the topmost mipmap image

height:int

the height in pixels of the topmost mipmap image

mipmapData:ByteBuffer[]

the data for each mipmap level of the resulting DDSImage; either only one mipmap level should be specified, or they all must be

Returns:DDSImage

DDS image object

Exceptions
IllegalArgumentException:
if the data does not match the specified arguments
debugPrintback to summary
public void debugPrint()
fixupHeaderback to summary
private void fixupHeader()
getAllMipMapsback to summary
public DDSImage.ImageInfo[] getAllMipMaps()

Returns an array of ImageInfos corresponding to all mipmap levels of this DDS file.

Returns:DDSImage.ImageInfo[]

Mipmap image objects set

getAllMipMapsback to summary
public DDSImage.ImageInfo[] getAllMipMaps(final int side)

Returns an array of ImageInfos corresponding to all mipmap levels of this DDS file.

Parameters
side:int

Cubemap side or 0 for 2D texture

Returns:DDSImage.ImageInfo[]

Mipmap image objects set

getCompressionFormatback to summary
public int getCompressionFormat()

If this surface is compressed, returns the kind of compression used (DXT1..DXT5).

getCompressionFormatNameback to summary
public static String getCompressionFormatName(int compressionFormat)

Converts e.g. DXT1 compression format constant (see getCompressionFormat) into "DXT1".

Parameters
compressionFormat:int

Compression format constant

Returns:String

String format code

getDepthback to summary
public int getDepth()

Total number of bits per pixel. Only valid if DDPF_RGB is present. For A8R8G8B8, would be 32.

getHeightback to summary
public int getHeight()

Height of the texture (or the top-most mipmap if mipmaps are present)

getMipMapback to summary
public DDSImage.ImageInfo getMipMap(final int map)

Gets the ith mipmap data (0..getNumMipMaps() - 1)

Parameters
map:int

Mipmap index

Returns:DDSImage.ImageInfo

Image object

getMipMapback to summary
public DDSImage.ImageInfo getMipMap(final int side, final int map)

Gets the ith mipmap data (0..getNumMipMaps() - 1)

Parameters
side:int

Cubemap side or 0 for 2D texture

map:int

Mipmap index

Returns:DDSImage.ImageInfo

Image object

getNumMipMapsback to summary
public int getNumMipMaps()

Number of mip maps in the texture

getPixelFormatback to summary
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.

getWidthback to summary
public int getWidth()

Width of the texture (or the top-most mipmap if mipmaps are present)

initFromDataback to summary
private void initFromData(final int d3dFormat, final int width, final int height, final ByteBuffer[] mipmapData) throws IllegalArgumentException
isCompressedback to summary
public boolean isCompressed()

Indicates whether this texture is compressed.

isCubemapback to summary
public boolean isCubemap()

Indicates whether this texture is cubemap

Returns:boolean

true if cubemap or false otherwise

isCubemapSidePresentback to summary
public boolean isCubemapSidePresent(final int side)

Indicates whethe this cubemap side present

Parameters
side:int

Side to test

Returns:boolean

true if side present or false otherwise

isDDSImageback to summary
public static boolean isDDSImage(InputStream in) throws IOException

Deprecated

rather call ImageType#getFileSuffix(InputStream)

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.

Parameters
in:InputStream

Stream to check

Returns:boolean

true if input stream is DDS image or false otherwise

Annotations
@Deprecated
Exceptions
IOException:
if an I/O exception occurred
isPixelFormatFlagSetback to summary
public boolean isPixelFormatFlagSet(final int flag)

Test for presence/absence of pixel format flags (DDPF_*)

isSurfaceDescFlagSetback to summary
public boolean isSurfaceDescFlagSet(final int flag)

Test for presence/absence of surface description flags (DDSD_*)

Parameters
flag:int

DDSD_* flags set to test

Returns:boolean

true if flag present or false otherwise

mipMapHeightback to summary
private int mipMapHeight(final int map)
mipMapSizeInBytesback to summary
private int mipMapSizeInBytes(final int map)
mipMapWidthback to summary
private int mipMapWidth(final int map)
printIfRecognizedback to summary
private boolean printIfRecognized(final PrintStream tty, final int flags, final int flag, final String what)
readback to summary
public static DDSImage read(final String filename) throws IOException

Reads a DirectDraw surface from the specified file name, returning the resulting DDSImage.

Parameters
filename:String

File name

Returns:DDSImage

DDS image object

Exceptions
IOException:
if an I/O exception occurred
readback to summary
public static DDSImage read(final File file) throws IOException

Reads a DirectDraw surface from the specified file, returning the resulting DDSImage.

Parameters
file:File

File object

Returns:DDSImage

DDS image object

Exceptions
IOException:
if an I/O exception occurred
readback to summary
public static DDSImage read(final ByteBuffer buf) throws IOException

Reads a DirectDraw surface from the specified ByteBuffer, returning the resulting DDSImage.

Parameters
buf:ByteBuffer

Input data

Returns:DDSImage

DDS image object

Exceptions
IOException:
if an I/O exception occurred
readFromBufferback to summary
private void readFromBuffer(final ByteBuffer buf) throws IOException
readFromFileback to summary
private void readFromFile(final File file) throws IOException
sideShiftInBytesback to summary
private int sideShiftInBytes(final int side)
sideSizeInBytesback to summary
private int sideSizeInBytes()
writeback to summary
public void write(final String filename) throws IOException

Writes this DDSImage to the specified file name.

Parameters
filename:String

File name to write to

Exceptions
IOException:
if an I/O exception occurred
writeback to summary
public void write(final File file) throws IOException

Writes this DDSImage to the specified file name.

Parameters
file:File

File object to write to

Exceptions
IOException:
if an I/O exception occurred
com.jogamp.opengl.util.texture.spi back to summary

public Class DDSImage.ImageInfo

extends Object
Class Inheritance

Simple class describing images and data; does not encapsulate image format information. User is responsible for transmitting that information in another way.

Field Summary

Modifier and TypeField and Description
private final int
private final ByteBuffer
private final int
private final boolean
private final int

Constructor Summary

AccessConstructor and Description
public
ImageInfo(final ByteBuffer data, final int width, final int height, final boolean compressed, final int compressionFormat)

Method Summary

Modifier and TypeMethod and Description
public int
public ByteBuffer
public int
public int
public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

compressionFormatback to summary
private final int compressionFormat
databack to summary
private final ByteBuffer data
heightback to summary
private final int height
isCompressedback to summary
private final boolean isCompressed
widthback to summary
private final int width

Constructor Detail

ImageInfoback to summary
public ImageInfo(final ByteBuffer data, final int width, final int height, final boolean compressed, final int compressionFormat)

Method Detail

getCompressionFormatback to summary
public int getCompressionFormat()
getDataback to summary
public ByteBuffer getData()
getHeightback to summary
public int getHeight()
getWidthback to summary
public int getWidth()
isCompressedback to summary
public boolean isCompressed()