Class Picture

java.lang.Object
net.mtrop.doom.graphics.Picture
All Implemented Interfaces:
BinaryObject, GraphicObject

public class Picture extends Object implements 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
  • Field Details

    • PIXEL_TRANSLUCENT

      public static final byte PIXEL_TRANSLUCENT
      Transparent 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 interface GraphicObject
      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 interface GraphicObject
      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 interface GraphicObject
      Returns:
      the width of this graphic in pixels.
    • getHeight

      public int getHeight()
      Returns the height of this graphic in pixels.
      Specified by:
      getHeight in interface GraphicObject
      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 interface GraphicObject
      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 interface GraphicObject
      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

      public void readBytes(InputStream in) throws IOException
      Description copied from interface: BinaryObject
      Reads from an InputStream 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 interface BinaryObject
      Parameters:
      in - the InputStream to read from.
      Throws:
      IOException - if a read error occurs.
    • writeBytes

      public void writeBytes(OutputStream out) throws IOException
      Description copied from interface: BinaryObject
      Writes this object to an OutputStream.
      Specified by:
      writeBytes in interface BinaryObject
      Parameters:
      out - the OutputStream to write to.
      Throws:
      IOException - if a write error occurs.