Package arc.graphics
Class Pixmap
java.lang.Object
arc.graphics.Pixmap
- All Implemented Interfaces:
Disposable
A Pixmap represents an image in memory. It has a width and height expressed in pixels, with each pixel being stored in RGBA8888 format. Coordinates of pixels are specified with respect to the top left corner of the image, with the x-axis pointing to the right and the y-axis pointing downwards.
The draw(Pixmap, int, int, int, int, int, int, int, int)
method will scale and stretch the source image to a
target image. There either nearest neighbour or bilinear filtering can be used.
A Pixmap stores its data in native heap memory. It is mandatory to call dispose()
when the pixmap is no longer
needed, otherwise memory leaks will result.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionint
Size of the pixmap.Internal data, arranged as RGBA with 1 byte per component.int
Size of the pixmap. -
Constructor Summary
ConstructorDescriptionPixmap
(byte[] encodedData) Pixmap
(byte[] encodedData, int offset, int len) Creates a new Pixmap instance from the given encoded image data.Pixmap
(int width, int height) Creates a new Pixmap instance with the given width and height.Creates a new Pixmap instance from the given file.Pixmap
(ByteBuffer buffer, int width, int height) Creates a pixmap from a direct ByteBuffer. -
Method Summary
Modifier and TypeMethodDescriptionstatic int
blend
(int src, int dst) copy()
crop
(int x, int y, int width, int height) void
dispose()
Releases all resources associated with this Pixmap.void
draw
(PixmapRegion region) void
draw
(PixmapRegion region, boolean blend) void
draw
(PixmapRegion region, int x, int y) void
draw
(PixmapRegion region, int x, int y, int width, int height) void
draw
(PixmapRegion region, int x, int y, int srcx, int srcy, int srcWidth, int srcHeight) void
draw
(PixmapRegion region, int srcx, int srcy, int srcWidth, int srcHeight, int dstx, int dsty, int dstWidth, int dstHeight) void
void
void
Draws an area from another Pixmap to this Pixmap.void
Draws an area from another Pixmap to this Pixmap.void
Draws an area from another Pixmap to this Pixmap.void
Draws an area from another Pixmap to this Pixmap.void
Draws an area from another Pixmap to this Pixmap.void
draw
(Pixmap pixmap, int srcx, int srcy, int srcWidth, int srcHeight, int dstx, int dsty, int dstWidth, int dstHeight) Draws an area from another Pixmap to this Pixmap.void
draw
(Pixmap pixmap, int srcx, int srcy, int srcWidth, int srcHeight, int dstx, int dsty, int dstWidth, int dstHeight, boolean filtering) Draws an area from another Pixmap to this Pixmap.void
draw
(Pixmap pixmap, int srcx, int srcy, int srcWidth, int srcHeight, int dstx, int dsty, int dstWidth, int dstHeight, boolean filtering, boolean blending) Draws an area from another Pixmap to this Pixmap.void
drawCircle
(int x, int y, int radius, int col) void
drawLine
(int x, int y, int x2, int y2, int color) Draws a line between the given coordinates using the provided RGBA color.void
drawRect
(int x, int y, int width, int height, int color) Draws a rectangle outline starting at x, y extending by width to the right and by height downwards (y-axis points downwards) using the provided color.void
Iterates through every position in this Pixmap.static boolean
empty
(int i) boolean
empty
(int x, int y) void
fill
(int color) Fills the complete bitmap with the specified color.void
Fills the complete bitmap with the specified color.void
fillCircle
(int x, int y, int radius, int color) Fills a circle with the center at x,y and a radius using the current color.void
fillRect
(int x, int y, int width, int height, int color) Fills a rectangle starting at x, y extending by width to the right and by height downwards (y-axis points downwards) using the current color.flipX()
flipY()
int
get
(int x, int y) int
getA
(int x, int y) int
Returns the OpenGL ES format of this Pixmap.int
Returns the OpenGL ES format of this Pixmap.int
Returns the OpenGL ES type of this Pixmap.int
int
getRaw
(int x, int y) int
getWidth()
boolean
in
(int x, int y) boolean
outline
(int color, int radius) void
void
set
(int x, int y, int color) Sets a pixel at the given location with the given color.void
void
setRaw
(int x, int y, int color) Sets a pixel at the given location with the given color.
-
Field Details
-
width
public int widthSize of the pixmap. Do not modify unless you know what you are doing. -
height
public int heightSize of the pixmap. Do not modify unless you know what you are doing. -
pixels
Internal data, arranged as RGBA with 1 byte per component. This buffer must be direct or natively-allocated.
-
-
Constructor Details
-
Pixmap
public Pixmap(int width, int height) Creates a new Pixmap instance with the given width and height. -
Pixmap
public Pixmap(byte[] encodedData) - See Also:
-
Pixmap
public Pixmap(byte[] encodedData, int offset, int len) Creates a new Pixmap instance from the given encoded image data. The image can be encoded as JPEG, PNG or BMP.- Parameters:
encodedData
- the image data to load, typically read from a PNG file
-
Pixmap
-
Pixmap
Creates a new Pixmap instance from the given file. The file must be a Png, Jpeg or Bitmap.- Parameters:
file
- theFi
-
Pixmap
Creates a pixmap from a direct ByteBuffer.
-
-
Method Details
-
copy
- Returns:
- a newly allocated copy with the same pixels.
-
each
Iterates through every position in this Pixmap. -
replace
-
fill
public void fill(int color) Fills the complete bitmap with the specified color. -
fill
Fills the complete bitmap with the specified color. -
in
public boolean in(int x, int y) - Returns:
- whether this point is in the pixmap.
-
crop
-
flipY
- Returns:
- a newly allocated pixmap, flipped vertically.
-
flipX
- Returns:
- a newly allocated pixmap, flipped horizontally.
-
outline
- Returns:
- a newly allocated pixmap with the specified outline.
-
outline
- Returns:
- a newly allocated pixmap with the specified outline.
-
drawLine
public void drawLine(int x, int y, int x2, int y2, int color) Draws a line between the given coordinates using the provided RGBA color. -
drawRect
public void drawRect(int x, int y, int width, int height, int color) Draws a rectangle outline starting at x, y extending by width to the right and by height downwards (y-axis points downwards) using the provided color. -
drawCircle
public void drawCircle(int x, int y, int radius, int col) -
draw
-
draw
-
draw
-
draw
-
draw
public void draw(PixmapRegion region, int x, int y, int srcx, int srcy, int srcWidth, int srcHeight) -
draw
public void draw(PixmapRegion region, int srcx, int srcy, int srcWidth, int srcHeight, int dstx, int dsty, int dstWidth, int dstHeight) -
draw
-
draw
-
draw
Draws an area from another Pixmap to this Pixmap.- Parameters:
pixmap
- The other Pixmapx
- The target x-coordinate (top left corner)y
- The target y-coordinate (top left corner)
-
draw
Draws an area from another Pixmap to this Pixmap.- Parameters:
pixmap
- The other Pixmapx
- The target x-coordinate (top left corner)y
- The target y-coordinate (top left corner)
-
draw
Draws an area from another Pixmap to this Pixmap. -
draw
Draws an area from another Pixmap to this Pixmap. -
draw
Draws an area from another Pixmap to this Pixmap. -
draw
public void draw(Pixmap pixmap, int srcx, int srcy, int srcWidth, int srcHeight, int dstx, int dsty, int dstWidth, int dstHeight) Draws an area from another Pixmap to this Pixmap. This will automatically scale and stretch the source image to the specified target rectangle. -
draw
public void draw(Pixmap pixmap, int srcx, int srcy, int srcWidth, int srcHeight, int dstx, int dsty, int dstWidth, int dstHeight, boolean filtering) Draws an area from another Pixmap to this Pixmap. This will automatically scale and stretch the source image to the specified target rectangle. -
draw
public void draw(Pixmap pixmap, int srcx, int srcy, int srcWidth, int srcHeight, int dstx, int dsty, int dstWidth, int dstHeight, boolean filtering, boolean blending) Draws an area from another Pixmap to this Pixmap. This will automatically scale and stretch the source image to the specified target rectangle. Blending is currently unsupported for stretched/scaled pixmaps.- Parameters:
pixmap
- The other Pixmapsrcx
- The source x-coordinate (top left corner)srcy
- The source y-coordinate (top left corner);srcWidth
- The width of the area from the other Pixmap in pixelssrcHeight
- The height of the area from the other Pixmap in pixelsdstx
- The target x-coordinate (top left corner)dsty
- The target y-coordinate (top left corner)dstWidth
- The target widthdstHeight
- the target height
-
fillRect
public void fillRect(int x, int y, int width, int height, int color) Fills a rectangle starting at x, y extending by width to the right and by height downwards (y-axis points downwards) using the current color.- Parameters:
x
- The x coordinatey
- The y coordinatewidth
- The width in pixelsheight
- The height in pixels
-
fillCircle
public void fillCircle(int x, int y, int radius, int color) Fills a circle with the center at x,y and a radius using the current color.- Parameters:
radius
- The radius in pixels
-
get
public int get(int x, int y) - Returns:
- The pixel color in RGBA8888 format, or 0 if out of bounds.
-
getRaw
public int getRaw(int x, int y) - Returns:
- The pixel color in RGBA8888 format. No bounds checks are done!
-
getA
public int getA(int x, int y) - Returns:
- The pixel alpha as a byte, 0-255. No bounds checks are done!
-
empty
public boolean empty(int x, int y) - Returns:
- whether the alpha at a position is 0. No bounds checks are done.
-
getWidth
public int getWidth()- Returns:
- The width of the Pixmap in pixels.
-
getHeight
public int getHeight()- Returns:
- The height of the Pixmap in pixels.
-
dispose
public void dispose()Releases all resources associated with this Pixmap.- Specified by:
dispose
in interfaceDisposable
-
isDisposed
public boolean isDisposed()- Specified by:
isDisposed
in interfaceDisposable
-
set
-
set
public void set(int x, int y, int color) Sets a pixel at the given location with the given color.- Parameters:
color
- the color in RGBA8888 format.
-
setRaw
public void setRaw(int x, int y, int color) Sets a pixel at the given location with the given color. No bounds checks are done!- Parameters:
color
- the color in RGBA8888 format.
-
getGLFormat
public int getGLFormat()Returns the OpenGL ES format of this Pixmap. Used as the seventh parameter toGL20.glTexImage2D(int, int, int, int, int, int, int, int, java.nio.Buffer)
.- Returns:
- GL_RGBA
-
getGLInternalFormat
public int getGLInternalFormat()Returns the OpenGL ES format of this Pixmap. Used as the third parameter toGL20.glTexImage2D(int, int, int, int, int, int, int, int, java.nio.Buffer)
.- Returns:
- GL_RGBA
-
getGLType
public int getGLType()Returns the OpenGL ES type of this Pixmap. Used as the eighth parameter toGL20.glTexImage2D(int, int, int, int, int, int, int, int, java.nio.Buffer)
.- Returns:
- GL_UNSIGNED_BYTE
-
getPixels
- Returns:
- the direct
ByteBuffer
holding the pixel data.
-
blend
public static int blend(int src, int dst) - Returns:
- the blended result of the input colors
-
empty
public static boolean empty(int i)
-