Package net.mtrop.doom.graphics
Class Picture
java.lang.Object
net.mtrop.doom.graphics.Picture
- All Implemented Interfaces:
BinaryObject
,GraphicObject
Doom graphic data stored as column-major indices (patches and most graphics with baked-in offsets).
Useful for editing/displaying graphics.
NOTE: The readBytes(InputStream)
method will read until the end of the stream is reached.
Doom's Picture format does not contain information about the length of a picture's total pixel data.
- Author:
- Matthew Tropiano
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.mtrop.doom.object.BinaryObject
BinaryObject.InlineScanner<BO extends BinaryObject>, BinaryObject.Reflect, BinaryObject.Scanner<BO extends BinaryObject>, BinaryObject.Shared, BinaryObject.Transformer<BO extends BinaryObject>
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
Returns the height of this graphic in pixels.int
int
int
getPixel
(int x, int y) Gets the pixel data at a location in the picture.int
getWidth()
Returns the width of this graphic in pixels.void
readBytes
(InputStream in) Reads from anInputStream
and sets this object's fields.void
setDimensions
(int width, int height) Sets the dimensions of this picture.void
setOffsetX
(int offsetX) Sets the offset from the center, horizontally, in pixels.void
setOffsetY
(int offsetY) Sets the offset from the center, vertically, in pixels.void
setPixel
(int x, int y, int value) Sets the pixel data at a location in the picture.void
writeBytes
(OutputStream out) Writes this object to anOutputStream
.
-
Field Details
-
PIXEL_TRANSLUCENT
public static final byte PIXEL_TRANSLUCENTTransparent pixel value.- See Also:
-
-
Constructor Details
-
Picture
public Picture()Creates a new picture with dimensions (1, 1). -
Picture
public Picture(int width, int height) Creates a new picture.- Parameters:
width
- the width of the picture in pixels.height
- the height of the picture in pixels.- Throws:
IllegalArgumentException
- if width is < 1 or > 256, or height is < 1 or > 65535.
-
-
Method Details
-
setDimensions
public void setDimensions(int width, int height) Sets the dimensions of this picture. WARNING: This will clear all of the data in the picture.- Parameters:
width
- the width of the picture in pixels.height
- the height of the picture in pixels.- Throws:
IllegalArgumentException
- if width is < 1 or > 256, or height is < 1 or > 65535.
-
getOffsetX
public int getOffsetX()- Specified by:
getOffsetX
in interfaceGraphicObject
- Returns:
- the offset from the center, horizontally, in pixels.
-
setOffsetX
public void setOffsetX(int offsetX) Sets the offset from the center, horizontally, in pixels.- Parameters:
offsetX
- the new X offset.- Throws:
IllegalArgumentException
- if the offset is outside the range -32768 to 32767.
-
getOffsetY
public int getOffsetY()- Specified by:
getOffsetY
in interfaceGraphicObject
- Returns:
- the offset from the center, vertically, in pixels.
-
setOffsetY
public void setOffsetY(int offsetY) Sets the offset from the center, vertically, in pixels.- Parameters:
offsetY
- the new Y offset.- Throws:
IllegalArgumentException
- if the offset is outside the range -32768 to 32767.
-
getWidth
public int getWidth()Returns the width of this graphic in pixels.- Specified by:
getWidth
in interfaceGraphicObject
- Returns:
- the width of this graphic in pixels.
-
getHeight
public int getHeight()Returns the height of this graphic in pixels.- Specified by:
getHeight
in interfaceGraphicObject
- Returns:
- the height of this graphic in pixels.
-
setPixel
public void setPixel(int x, int y, int value) Sets the pixel data at a location in the picture. Valid values are in the range of -1 to 255, with 0 to 254 being palette indexes and -1 / 255 being translucent pixels. Note that palette value 255 does not get used as a color!- Specified by:
setPixel
in interfaceGraphicObject
- Parameters:
x
- picture x-coordinate.y
- picture y-coordinate.value
- the value to set.- Throws:
IllegalArgumentException
- if the value is outside the range -1 to 255.ArrayIndexOutOfBoundsException
- if the provided coordinates is outside the graphic.
-
getPixel
public int getPixel(int x, int y) Gets the pixel data at a location in the picture.- Specified by:
getPixel
in interfaceGraphicObject
- Parameters:
x
- picture x-coordinate.y
- picture y-coordinate.- Returns:
- a palette index value from 0 to 254 or
PIXEL_TRANSLUCENT
if the pixel is not filled in. - Throws:
ArrayIndexOutOfBoundsException
- if the provided coordinates is outside the graphic.
-
readBytes
Description copied from interface:BinaryObject
Reads from anInputStream
and sets this object's fields. Only reads the amount of bytes that it takes to read a single instance of the object. Note that not every object may have a consistent length!- Specified by:
readBytes
in interfaceBinaryObject
- Parameters:
in
- theInputStream
to read from.- Throws:
IOException
- if a read error occurs.
-
writeBytes
Description copied from interface:BinaryObject
Writes this object to anOutputStream
.- Specified by:
writeBytes
in interfaceBinaryObject
- Parameters:
out
- theOutputStream
to write to.- Throws:
IOException
- if a write error occurs.
-