Top Description Fields Constructors Methods
org.lwjgl.util

public Class XPMFile

extends Object
Class Inheritance
Imports
java.io.BufferedOutputStream, .File, .FileInputStream, .FileOutputStream, .IOException, .InputStream, .InputStreamReader, .LineNumberReader, java.util.HashMap, .StringTokenizer

Note

This simple XPM reader does not support extensions nor hotspots

Authors
Brian Matzon , Jos Hirth
Version
$Revision$ $Id$

Field Summary

Modifier and TypeField and Description
private byte[]
bytes

Array of bytes (RGBA)

private static final int
private static int[]
private static final int
private static final int
private static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public byte[]

Returns:

The data of the image.
getBytes
()

public int

Returns:

the height of the image.
getHeight
()

public int

Returns:

the width of the image.
getWidth
()

public static XPMFile

Returns:

XPMFile loaded, or exception
load
(String
path to file
file
)

Loads the XPM file

public static XPMFile

Returns:

XPMFile loaded, or exception
load
(InputStream
InputStream to read file from
is
)

Loads the XPM file

public static void
main(String[] args)

private static String

Returns:

The next interesting String (with stripped quotes)
nextLineOfInterest
(LineNumberReader
The LineNumberReader to read from
reader
)

Finds the next interesting line of text.

private static Object[]

Returns:

Array containing a key (String) and a color (Integer)
parseColor
(String
Line to parse
line
)

Given a line defining a color/pixel, parses this into an array containing a key and a color

private static int[]

Returns:

Array specifying width, height, colors, characters per pixel
parseFormat
(String
String to parse
format
)

Parses the format of the xpm file given a format string

private void
parseImageLine(String
Line of chars to parse
line
,
int[]
Format to expext it in
format
,
HashMap<String, Integer>
Colors to lookup
colors
,
int
current index into lines, we've reached
index
)

Parses an Image line into its byte values

private void
readImage(InputStream is)

Read the image from the specified file.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bytesback to summary
private byte[] bytes

Array of bytes (RGBA)

CHARACTERS_PER_PIXELback to summary
private static final int CHARACTERS_PER_PIXEL
formatback to summary
private static int[] format
HEIGHTback to summary
private static final int HEIGHT
NUMBER_OF_COLORSback to summary
private static final int NUMBER_OF_COLORS
WIDTHback to summary
private static final int WIDTH

Constructor Detail

XPMFileback to summary
private XPMFile()

Method Detail

getBytesback to summary
public byte[] getBytes()
Returns:byte[]

The data of the image.

getHeightback to summary
public int getHeight()
Returns:int

the height of the image.

getWidthback to summary
public int getWidth()
Returns:int

the width of the image.

loadback to summary
public static XPMFile load(String file) throws IOException

Loads the XPM file

Parameters
file:String

path to file

Returns:XPMFile

XPMFile loaded, or exception

Exceptions
IOException:
If any IO exceptions occurs while reading file
loadback to summary
public static XPMFile load(InputStream is)

Loads the XPM file

Parameters
is:InputStream

InputStream to read file from

Returns:XPMFile

XPMFile loaded, or exception

mainback to summary
public static void main(String[] args)
nextLineOfInterestback to summary
private static String nextLineOfInterest(LineNumberReader reader) throws IOException

Finds the next interesting line of text.

Parameters
reader:LineNumberReader

The LineNumberReader to read from

Returns:String

The next interesting String (with stripped quotes)

Exceptions
IOException:
If any IO exceptions occurs while reading file
parseColorback to summary
private static Object[] parseColor(String line)

Given a line defining a color/pixel, parses this into an array containing a key and a color

Parameters
line:String

Line to parse

Returns:Object[]

Array containing a key (String) and a color (Integer)

parseFormatback to summary
private static int[] parseFormat(String format)

Parses the format of the xpm file given a format string

Parameters
format:String

String to parse

Returns:int[]

Array specifying width, height, colors, characters per pixel

parseImageLineback to summary
private void parseImageLine(String line, int[] format, HashMap<String, Integer> colors, int index)

Parses an Image line into its byte values

Parameters
line:String

Line of chars to parse

format:int[]

Format to expext it in

colors:HashMap<String, Integer>

Colors to lookup

index:int

current index into lines, we've reached

readImageback to summary
private void readImage(InputStream is)

Read the image from the specified file.