Package arc.graphics

Class Pixmap

java.lang.Object
arc.graphics.Pixmap
All Implemented Interfaces:
Disposable

public class Pixmap extends Object implements 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

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Different pixel formats.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
    Size of the pixmap.
    Internal data, arranged as RGBA with 1 byte per component.
    int
    Size of the pixmap.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Pixmap(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.
    Pixmap(Fi file)
    Creates a new Pixmap instance from the given file.
    Pixmap(String file)
     
    Pixmap(ByteBuffer buffer, int width, int height)
    Creates a pixmap from a direct ByteBuffer.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    blend(int src, int dst)
     
     
    crop(int x, int y, int width, int height)
     
    void
    Releases all resources associated with this Pixmap.
    void
     
    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
    draw(Pixmap pixmap)
     
    void
    draw(Pixmap pixmap, boolean blend)
     
    void
    draw(Pixmap pixmap, int x, int y)
    Draws an area from another Pixmap to this Pixmap.
    void
    draw(Pixmap pixmap, int x, int y, boolean blending)
    Draws an area from another Pixmap to this Pixmap.
    void
    draw(Pixmap pixmap, int x, int y, int width, int height)
    Draws an area from another Pixmap to this Pixmap.
    void
    draw(Pixmap pixmap, int x, int y, int width, int height, boolean filter)
    Draws an area from another Pixmap to this Pixmap.
    void
    draw(Pixmap pixmap, int x, int y, int srcx, int srcy, int srcWidth, int srcHeight)
    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
    each(Intc2 cons)
    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
    fill(Color color)
    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.
     
     
    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
     
    boolean
    in(int x, int y)
     
    boolean
     
    outline(int color, int radius)
     
    outline(Color color, int radius)
     
    void
     
    void
    set(int x, int y, int color)
    Sets a pixel at the given location with the given color.
    void
    set(int x, int y, Color color)
     
    void
    setRaw(int x, int y, int color)
    Sets a pixel at the given location with the given color.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • width

      public int width
      Size of the pixmap. Do not modify unless you know what you are doing.
    • height

      public int height
      Size of the pixmap. Do not modify unless you know what you are doing.
    • pixels

      public ByteBuffer 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

      public Pixmap(String file)
    • Pixmap

      public Pixmap(Fi file)
      Creates a new Pixmap instance from the given file. The file must be a Png, Jpeg or Bitmap.
      Parameters:
      file - the Fi
    • Pixmap

      public Pixmap(ByteBuffer buffer, int width, int height)
      Creates a pixmap from a direct ByteBuffer.
  • Method Details

    • copy

      public Pixmap copy()
      Returns:
      a newly allocated copy with the same pixels.
    • each

      public void each(Intc2 cons)
      Iterates through every position in this Pixmap.
    • replace

      public void replace(IntIntf func)
    • fill

      public void fill(int color)
      Fills the complete bitmap with the specified color.
    • fill

      public void fill(Color color)
      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

      public Pixmap crop(int x, int y, int width, int height)
    • flipY

      public Pixmap flipY()
      Returns:
      a newly allocated pixmap, flipped vertically.
    • flipX

      public Pixmap flipX()
      Returns:
      a newly allocated pixmap, flipped horizontally.
    • outline

      public Pixmap outline(Color color, int radius)
      Returns:
      a newly allocated pixmap with the specified outline.
    • outline

      public Pixmap outline(int color, int radius)
      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

      public void draw(PixmapRegion region)
    • draw

      public void draw(PixmapRegion region, boolean blend)
    • draw

      public void draw(PixmapRegion region, int x, int y)
    • draw

      public void draw(PixmapRegion region, int x, int y, int width, int height)
    • 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

      public void draw(Pixmap pixmap, boolean blend)
    • draw

      public void draw(Pixmap pixmap)
    • draw

      public void draw(Pixmap pixmap, int x, int y)
      Draws an area from another Pixmap to this Pixmap.
      Parameters:
      pixmap - The other Pixmap
      x - The target x-coordinate (top left corner)
      y - The target y-coordinate (top left corner)
    • draw

      public void draw(Pixmap pixmap, int x, int y, boolean blending)
      Draws an area from another Pixmap to this Pixmap.
      Parameters:
      pixmap - The other Pixmap
      x - The target x-coordinate (top left corner)
      y - The target y-coordinate (top left corner)
    • draw

      public void draw(Pixmap pixmap, int x, int y, int width, int height)
      Draws an area from another Pixmap to this Pixmap.
    • draw

      public void draw(Pixmap pixmap, int x, int y, int width, int height, boolean filter)
      Draws an area from another Pixmap to this Pixmap.
    • draw

      public void draw(Pixmap pixmap, int x, int y, int srcx, int srcy, int srcWidth, int srcHeight)
      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 Pixmap
      srcx - 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 pixels
      srcHeight - The height of the area from the other Pixmap in pixels
      dstx - The target x-coordinate (top left corner)
      dsty - The target y-coordinate (top left corner)
      dstWidth - The target width
      dstHeight - 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 coordinate
      y - The y coordinate
      width - The width in pixels
      height - 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 interface Disposable
    • isDisposed

      public boolean isDisposed()
      Specified by:
      isDisposed in interface Disposable
    • set

      public void set(int x, int y, Color color)
    • 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 to GL20.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 to GL20.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 to GL20.glTexImage2D(int, int, int, int, int, int, int, int, java.nio.Buffer).
      Returns:
      GL_UNSIGNED_BYTE
    • getPixels

      public ByteBuffer 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)