com.jme.image.util
Class DDSLoader.DDSReader

java.lang.Object
  extended by com.jme.image.util.DDSLoader.DDSReader
Enclosing class:
DDSLoader

public static class DDSLoader.DDSReader
extends java.lang.Object

DDS reader

Author:
Gareth

Constructor Summary
DDSLoader.DDSReader(java.io.InputStream in)
           
 
Method Summary
 byte[] flipData(byte[] data, int scanlineSize, int height)
          Flips the given image data on the Y axis.
 void loadHeader()
          Reads the header (first 128 bytes) of a DDS File
 java.util.ArrayList<java.nio.ByteBuffer> readData(boolean flip)
          Reads the image data from the InputStream in the required format.
 java.nio.ByteBuffer readDXT2D(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 readRGB2D(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.DDSReader

public DDSLoader.DDSReader(java.io.InputStream in)
Method Detail

loadHeader

public void loadHeader()
                throws java.io.IOException
Reads the header (first 128 bytes) of a DDS File

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(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.