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

public Class TGAImage

extends Object
Class Inheritance
Imports
java.io.*, java.nio.*, java.nio.channels.*, com.jogamp.opengl.*, com.jogamp.common.util.IOUtil

Targa image reader and writer adapted from sources of the Jimi image I/O class library.

Image decoder for image data stored in TGA file format. Currently only the original TGA file format is supported. This is because the new TGA format has data at the end of the file, getting to the end of a file in an InputStream orient environment presents several difficulties which are avoided at the moment.

This is a simple decoder and is only setup to load a single image from the input stream

Authors
Robin Luiten, Kenneth Russell
Version
$Revision: 1768 $

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
TGAImage.Header

This class reads in all of the TGA image header in addition it also reads in the imageID field as it is convenient to handle that here.

Field Summary

Modifier and TypeField and Description
private int
private ByteBuffer
private int
private final TGAImage.Header

Constructor Summary

AccessConstructor and Description
private
TGAImage(final TGAImage.Header header)

Method Summary

Modifier and TypeMethod and Description
public static TGAImage
createFromData(final int width, final int height, final boolean hasAlpha, final boolean topToBottom, final ByteBuffer data)

Creates a TGAImage from data supplied by the end user.

private void
decodeImage(final GLProfile glp, final LEDataInputStream dIn)

Identifies the image type of the tga image data and loads it into the JimiImage structure.

private void
decodeRGBImageRLE24_32(final GLProfile glp, final LEDataInputStream dIn)

This assumes that the body is for a 24 bit or 32 bit for a RGB or ARGB image respectively.

private void
decodeRGBImageU24_32(final GLProfile glp, final LEDataInputStream dIn)

This assumes that the body is for a 24 bit or 32 bit for a RGB or ARGB image respectively.

public int
getBytesPerPixel()

Returns the bytes per pixel

public ByteBuffer
getData()

Returns the raw data for this texture in the correct (bottom-to-top) order for calls to glTexImage2D.

public int
getGLFormat()

Returns the OpenGL format for this texture; e.g. GL.GL_BGR or GL.GL_BGRA.

public int
getHeight()

Returns the height of the image.

public int
getWidth()

Returns the width of the image.

public static TGAImage
read(final GLProfile glp, final String filename)

Reads a Targa image from the specified file.

public static TGAImage
read(final GLProfile glp, final InputStream in)

Reads a Targa image from the specified InputStream.

private void
private static void
swapBGR(final byte[] data, final int bWidth, final int height, final int bpp)

public void
write(final String filename)

Writes the image in Targa format to the specified file name.

public void
write(final File file)

Writes the image in Targa format to the specified file.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bppback to summary
private int bpp
databack to summary
private ByteBuffer data
formatback to summary
private int format

Constructor Detail

TGAImageback to summary
private TGAImage(final TGAImage.Header header)

Method Detail

createFromDataback to summary
public static TGAImage createFromData(final int width, final int height, final boolean hasAlpha, final boolean topToBottom, final ByteBuffer data)

Creates a TGAImage from data supplied by the end user. Shares data with the passed ByteBuffer. Assumes the data is already in the correct byte order for writing to disk, i.e., BGR or BGRA.

decodeImageback to summary
private void decodeImage(final GLProfile glp, final LEDataInputStream dIn) throws IOException

Identifies the image type of the tga image data and loads it into the JimiImage structure. This was taken from the prototype and modified for the new Jimi structure

decodeRGBImageRLE24_32back to summary
private void decodeRGBImageRLE24_32(final GLProfile glp, final LEDataInputStream dIn) throws IOException

This assumes that the body is for a 24 bit or 32 bit for a RGB or ARGB image respectively.

decodeRGBImageU24_32back to summary
private void decodeRGBImageU24_32(final GLProfile glp, final LEDataInputStream dIn) throws IOException

This assumes that the body is for a 24 bit or 32 bit for a RGB or ARGB image respectively.

getBytesPerPixelback to summary
public int getBytesPerPixel()

Returns the bytes per pixel

getDataback to summary
public ByteBuffer getData()

Returns the raw data for this texture in the correct (bottom-to-top) order for calls to glTexImage2D.

getGLFormatback to summary
public int getGLFormat()

Returns the OpenGL format for this texture; e.g. GL.GL_BGR or GL.GL_BGRA.

getHeightback to summary
public int getHeight()

Returns the height of the image.

getWidthback to summary
public int getWidth()

Returns the width of the image.

readback to summary
public static TGAImage read(final GLProfile glp, final String filename) throws IOException

Reads a Targa image from the specified file.

readback to summary
public static TGAImage read(final GLProfile glp, final InputStream in) throws IOException

Reads a Targa image from the specified InputStream.

setupImage24_32back to summary
private void setupImage24_32(final GLProfile glp)
swapBGRback to summary
private static void swapBGR(final byte[] data, final int bWidth, final int height, final int bpp)
writeback to summary
public void write(final String filename) throws IOException

Writes the image in Targa format to the specified file name.

writeback to summary
public void write(final File file) throws IOException

Writes the image in Targa format to the specified file.