Package net.mtrop.doom.graphics
Class PNGPicture
java.lang.Object
net.mtrop.doom.graphics.PNGPicture
- All Implemented Interfaces:
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
-
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>
-
Constructor Summary
ConstructorDescriptionCreates a new image with dimensions (1, 1).PNGPicture
(int width, int height) Creates a new PNG data image.PNGPicture
(BufferedImage image) Creates a new PNG data image from another image. -
Method Summary
Modifier and TypeMethodDescriptionint
getImage()
Gets the reference to this image's internal buffered image.int
int
int
getPixel
(int x, int y) Gets the pixel data at a location in the graphic.int
getWidth()
void
readBytes
(InputStream in) Reads from anInputStream
and sets this object's fields.void
setImage
(BufferedImage newImage) Sets the pixel data for this graphic using an Image.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 graphic.void
writeBytes
(OutputStream out) Writes this object to anOutputStream
.
-
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
Creates a new PNG data image from another image.- Parameters:
image
- the source image.
-
-
Method Details
-
getWidth
public int getWidth()- Specified by:
getWidth
in interfaceGraphicObject
- Returns:
- the width of this graphic in pixels.
-
getHeight
public int getHeight()- Specified by:
getHeight
in interfaceGraphicObject
- Returns:
- the height of this graphic in pixels.
-
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.
-
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.
-
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
orPicture
), this will return a palette index value from 0 to 255, orPicture.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 interfaceGraphicObject
- 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 interfaceGraphicObject
- Parameters:
x
- picture x-coordinate.y
- picture y-coordinate.value
- the value to set.
-
setImage
Sets the pixel data for this graphic using an Image.- Parameters:
newImage
- the image to copy from.
-
getImage
Gets the reference to this image's internal buffered image.- Returns:
- the image that this contains.
-
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.
-