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
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns the height of this graphic in pixels.intintintgetPixel(int x, int y) Gets the pixel data at a location in the picture.intgetWidth()Returns the width of this graphic in pixels.voidreadBytes(InputStream in) Reads from anInputStreamand sets this object's fields.voidsetDimensions(int width, int height) Sets the dimensions of this picture.voidsetOffsetX(int offsetX) Sets the offset from the center, horizontally, in pixels.voidsetOffsetY(int offsetY) Sets the offset from the center, vertically, in pixels.voidsetPixel(int x, int y, int value) Sets the pixel data at a location in the picture.voidwriteBytes(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:
getOffsetXin 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:
getOffsetYin 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:
getWidthin interfaceGraphicObject- Returns:
- the width of this graphic in pixels.
-
getHeight
public int getHeight()Returns the height of this graphic in pixels.- Specified by:
getHeightin 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:
setPixelin 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:
getPixelin interfaceGraphicObject- Parameters:
x- picture x-coordinate.y- picture y-coordinate.- Returns:
- a palette index value from 0 to 254 or
PIXEL_TRANSLUCENTif the pixel is not filled in. - Throws:
ArrayIndexOutOfBoundsException- if the provided coordinates is outside the graphic.
-
readBytes
Description copied from interface:BinaryObjectReads from anInputStreamand 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:
readBytesin interfaceBinaryObject- Parameters:
in- theInputStreamto read from.- Throws:
IOException- if a read error occurs.
-
writeBytes
Description copied from interface:BinaryObjectWrites this object to anOutputStream.- Specified by:
writeBytesin interfaceBinaryObject- Parameters:
out- theOutputStreamto write to.- Throws:
IOException- if a write error occurs.
-