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 BinaryObject
BinaryObject.InlineScanner<BO>, BinaryObject.Reflect, BinaryObject.Scanner<BO>, BinaryObject.Shared, BinaryObject.Transformer<BO> -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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 TypeMethodDescriptionintgetImage()Gets the reference to this image's internal buffered image.intintintgetPixel(int x, int y) Gets the pixel data at a location in the graphic.intgetPixelAlpha(int x, int y) Gets a pixel's alpha value from 0 to 255.intgetWidth()voidreadBytes(InputStream in) Reads from anInputStreamand sets this object's fields.voidsetImage(BufferedImage newImage) Sets the pixel data for this graphic using an Image.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 graphic.voidwriteBytes(OutputStream out) Writes this object to anOutputStream.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface GraphicObject
isOpaque
-
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:
getWidthin interfaceGraphicObject- Returns:
- the width of this graphic in pixels.
-
getHeight
public int getHeight()- Specified by:
getHeightin interfaceGraphicObject- Returns:
- the height of this graphic in pixels.
-
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.- Specified by:
setOffsetXin interfaceGraphicObject- Parameters:
offsetX- the new X offset.
-
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.- Specified by:
setOffsetYin interfaceGraphicObject- Parameters:
offsetY- the new Y offset.
-
getPixel
public int getPixel(int x, int y) Description copied from interface:GraphicObjectGets the pixel data at a location in the graphic.If this graphic is an indexed color graphic (i.e.
FlatorPicture), this will return a palette index value from 0 to 255, orPicture.PIXEL_TRANSLUCENTif this pixel is translucent.For full-color graphics, this returns an ARGB integer value representing the pixel color in RGB space (with Alpha).
- Specified by:
getPixelin interfaceGraphicObject- Parameters:
x- graphic x-coordinate.y- graphic y-coordinate.- Returns:
- a palette index value from 0 to 255,
Picture.PIXEL_TRANSLUCENTif translucent, or an ARGB value.
-
setPixel
public void setPixel(int x, int y, int value) Description copied from interface:GraphicObjectSets 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 255 being palette indexes and
Picture.PIXEL_TRANSLUCENTbeing 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:
setPixelin interfaceGraphicObject- Parameters:
x- picture x-coordinate.y- picture y-coordinate.value- the value to set.
-
getPixelAlpha
public int getPixelAlpha(int x, int y) Description copied from interface:GraphicObjectGets a pixel's alpha value from 0 to 255.- Specified by:
getPixelAlphain interfaceGraphicObject- Parameters:
x- picture x-coordinate.y- picture y-coordinate.- Returns:
- a value from 0 to 255 representing no alpha to full opacity, respectively.
-
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: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.
-