com.jme3.texture.plugins
Class DDSLoader

java.lang.Object
  extended by com.jme3.texture.plugins.DDSLoader
All Implemented Interfaces:
AssetLoader

public class DDSLoader
extends java.lang.Object
implements AssetLoader

DDSLoader is an image loader that reads in a DirectX DDS file. Supports DXT1, DXT3, DXT5, RGB, RGBA, Grayscale, Alpha pixel formats. 2D images, mipmapped 2D images, and cubemaps.


Constructor Summary
DDSLoader()
           
 
Method Summary
 byte[] flipData(byte[] data, int scanlineSize, int height)
          Flips the given image data on the Y axis.
 java.lang.Object load(AssetInfo info)
          Loads asset from the given input stream, parsing it into an application-usable object.
 Image load(java.io.InputStream stream)
           
 java.util.ArrayList<java.nio.ByteBuffer> readData(boolean flip)
          Reads the image data from the InputStream in the required format.
 java.nio.ByteBuffer readDXT2D(boolean flip, int totalSize)
          Reads a DXT compressed image from the InputStream
 java.nio.ByteBuffer readDXT3D(boolean flip, int totalSize)
          Reads a DXT compressed image from the InputStream
 java.nio.ByteBuffer readGrayscale2D(boolean flip, int totalSize)
          Reads a grayscale image with mipmaps from the InputStream
 java.nio.ByteBuffer readGrayscale3D(boolean flip, int totalSize)
          Reads a grayscale image with mipmaps from the InputStream
 java.nio.ByteBuffer readRGB2D(boolean flip, int totalSize)
          Reads an uncompressed RGB or RGBA image.
 java.nio.ByteBuffer readRGB3D(boolean flip, int totalSize)
          Reads an uncompressed RGB or RGBA image.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DDSLoader

public DDSLoader()
Method Detail

load

public java.lang.Object load(AssetInfo info)
                      throws java.io.IOException
Description copied from interface: AssetLoader
Loads asset from the given input stream, parsing it into an application-usable object.

Specified by:
load in interface AssetLoader
Returns:
An object representing the resource.
Throws:
java.io.IOException - If an I/O error occurs while loading

load

public Image load(java.io.InputStream stream)
           throws java.io.IOException
Throws:
java.io.IOException

flipData

public byte[] flipData(byte[] data,
                       int scanlineSize,
                       int height)
Flips the given image data on the Y axis.

Parameters:
data - Data array containing image data (without mipmaps)
scanlineSize - Size of a single scanline = width * bytesPerPixel
height - Height of the image in pixels
Returns:
The new data flipped by the Y axis

readGrayscale2D

public java.nio.ByteBuffer readGrayscale2D(boolean flip,
                                           int totalSize)
                                    throws java.io.IOException
Reads a grayscale image with mipmaps from the InputStream

Parameters:
flip - Flip the loaded image by Y axis
totalSize - Total size of the image in bytes including the mipmaps
Returns:
A ByteBuffer containing the grayscale image data with mips.
Throws:
java.io.IOException - If an error occured while reading from InputStream

readRGB2D

public java.nio.ByteBuffer readRGB2D(boolean flip,
                                     int totalSize)
                              throws java.io.IOException
Reads an uncompressed RGB or RGBA image.

Parameters:
flip - Flip the image on the Y axis
totalSize - Size of the image in bytes including mipmaps
Returns:
ByteBuffer containing image data with mipmaps in the format specified by pixelFormat_
Throws:
java.io.IOException - If an error occured while reading from InputStream

readDXT2D

public java.nio.ByteBuffer readDXT2D(boolean flip,
                                     int totalSize)
                              throws java.io.IOException
Reads a DXT compressed image from the InputStream

Parameters:
totalSize - Total size of the image in bytes, including mipmaps
Returns:
ByteBuffer containing compressed DXT image in the format specified by pixelFormat_
Throws:
java.io.IOException - If an error occured while reading from InputStream

readGrayscale3D

public java.nio.ByteBuffer readGrayscale3D(boolean flip,
                                           int totalSize)
                                    throws java.io.IOException
Reads a grayscale image with mipmaps from the InputStream

Parameters:
flip - Flip the loaded image by Y axis
totalSize - Total size of the image in bytes including the mipmaps
Returns:
A ByteBuffer containing the grayscale image data with mips.
Throws:
java.io.IOException - If an error occured while reading from InputStream

readRGB3D

public java.nio.ByteBuffer readRGB3D(boolean flip,
                                     int totalSize)
                              throws java.io.IOException
Reads an uncompressed RGB or RGBA image.

Parameters:
flip - Flip the image on the Y axis
totalSize - Size of the image in bytes including mipmaps
Returns:
ByteBuffer containing image data with mipmaps in the format specified by pixelFormat_
Throws:
java.io.IOException - If an error occured while reading from InputStream

readDXT3D

public java.nio.ByteBuffer readDXT3D(boolean flip,
                                     int totalSize)
                              throws java.io.IOException
Reads a DXT compressed image from the InputStream

Parameters:
totalSize - Total size of the image in bytes, including mipmaps
Returns:
ByteBuffer containing compressed DXT image in the format specified by pixelFormat_
Throws:
java.io.IOException - If an error occured while reading from InputStream

readData

public java.util.ArrayList<java.nio.ByteBuffer> readData(boolean flip)
                                                  throws java.io.IOException
Reads the image data from the InputStream in the required format. If the file contains a cubemap image, it is loaded as 6 ByteBuffers (potentially containing mipmaps if they were specified), otherwise a single ByteBuffer is returned for a 2D image.

Parameters:
flip - Flip the image data or not. For cubemaps, each of the cubemap faces is flipped individually. If the image is DXT compressed, no flipping is done.
Returns:
An ArrayList containing a single ByteBuffer for a 2D image, or 6 ByteBuffers for a cubemap. The cubemap ByteBuffer order is PositiveX, NegativeX, PositiveY, NegativeY, PositiveZ, NegativeZ.
Throws:
java.io.IOException - If an error occured while reading from the stream.