Class PNGPicture

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

public class PNGPicture extends Object implements BinaryObject, GraphicObject
Represents PNG-formatted data as a decompressed image, preserving offset information (grAb). The export functions write this data back as PNG with offset information.
Author:
Matthew Tropiano
  • Constructor Details

    • PNGPicture

      public PNGPicture()
      Creates a new image with dimensions (1, 1).
    • PNGPicture

      public PNGPicture(int width, int height)
      Creates a new PNG data image.
      Parameters:
      width - the width of the patch in pixels.
      height - the height of the patch in pixels.
    • PNGPicture

      public PNGPicture(BufferedImage image)
      Creates a new PNG data image from another image.
      Parameters:
      image - the source image.
  • Method Details

    • getWidth

      public int getWidth()
      Specified by:
      getWidth in interface GraphicObject
      Returns:
      the width of this graphic in pixels.
    • getHeight

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

      public int getPixel(int x, int y)
      Description copied from interface: GraphicObject
      Gets the pixel data at a location in the graphic.

      If this graphic is an indexed color graphic (i.e. Flat or Picture), this will return a palette index value from 0 to 255, or Picture.PIXEL_TRANSLUCENT if this graphic has translucent pixels.

      For full-color graphics, this returns an ARGB integer value representing the pixel color in RGB space (with Alpha).

      Specified by:
      getPixel in interface GraphicObject
      Parameters:
      x - graphic x-coordinate.
      y - graphic y-coordinate.
      Returns:
      a palette index value from 0 to 255, Picture.PIXEL_TRANSLUCENT if translucent, or an ARGB value.
    • setPixel

      public void setPixel(int x, int y, int value)
      Description copied from interface: GraphicObject
      Sets the pixel data at a location in the graphic.

      For indexed color graphics, valid values are in the range of -1 to 255, with 0 to 254 being palette indexes and Picture.PIXEL_TRANSLUCENT / 255 being translucent pixels (if supported).

      For full-color graphics, the value is an ARGB integer value representing the pixel color in RGB space (with Alpha).

      Specified by:
      setPixel in interface GraphicObject
      Parameters:
      x - picture x-coordinate.
      y - picture y-coordinate.
      value - the value to set.
    • setImage

      public void setImage(BufferedImage newImage)
      Sets the pixel data for this graphic using an Image.
      Parameters:
      newImage - the image to copy from.
    • getImage

      public BufferedImage getImage()
      Gets the reference to this image's internal buffered image.
      Returns:
      the image that this contains.
    • 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.