Class Raster

java.lang.Object
com.codename1.art.Raster

public final class Raster extends Object

A rectangle of non-premultiplied 0xAARRGGBB pixels with a position.

The renderer paints every layer into a Raster and composites them with Compositor, so a document looks the same on every port and in tests that have no display.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The largest number of pixels a raster may hold: 64 megapixels.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Raster(int x, int y, int width, int height)
    Creates a transparent raster.
    Raster(int x, int y, int width, int height, int[] pixels)
    Wraps existing pixels.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    applyMask(byte[] mask)
    Multiplies each pixel's alpha by a coverage mask of the same geometry (0..255).
    void
    composite(Raster src, BlendMode mode, float opacity)
    Composites src onto this raster where they overlap.
    A deep copy.
    int
    get(int px, int py)
    The pixel at absolute coordinates, transparent outside.
    int
    Height in pixels.
    int[]
    The pixel array, row major.
    int
    Width in pixels.
    int
    Left edge.
    int
    Top edge.
    boolean
    True when every pixel is fully transparent.
    resize(int nx, int ny, int nw, int nh)
    Returns a raster covering [nx, ny, nw, nh] with this one's pixels copied in.
    transform(Matrix m, int[] clip)
    Returns this raster drawn through a transform, sampled bilinearly, clipped to the device rectangle clip (x, y, w, h) when it is not null.

    Methods inherited from class Object

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

    • MAX_PIXELS

      public static final int MAX_PIXELS
      The largest number of pixels a raster may hold: 64 megapixels.
      See Also:
  • Constructor Details

    • Raster

      public Raster(int x, int y, int width, int height)

      Creates a transparent raster.

      Parameters
      • x: left edge in device pixels
      • y: top edge in device pixels
      • width: width, at least 0
      • height: height, at least 0
    • Raster

      public Raster(int x, int y, int width, int height, int[] pixels)

      Wraps existing pixels.

      Parameters
      • x: left edge
      • y: top edge
      • width: width
      • height: height
      • pixels: width * height pixels, row major; null for transparent
  • Method Details

    • getX

      public int getX()
      Left edge.
    • getY

      public int getY()
      Top edge.
    • getWidth

      public int getWidth()
      Width in pixels.
    • getHeight

      public int getHeight()
      Height in pixels.
    • getPixels

      public int[] getPixels()
      The pixel array, row major. Changes write through.
    • get

      public int get(int px, int py)

      The pixel at absolute coordinates, transparent outside.

      Parameters
      • px: absolute x
      • py: absolute y
    • copy

      public Raster copy()
      A deep copy.
    • isEmpty

      public boolean isEmpty()
      True when every pixel is fully transparent.
    • resize

      public Raster resize(int nx, int ny, int nw, int nh)

      Returns a raster covering [nx, ny, nw, nh] with this one's pixels copied in.

      Parameters
      • nx: new left edge
      • ny: new top edge
      • nw: new width
      • nh: new height
    • composite

      public void composite(Raster src, BlendMode mode, float opacity)

      Composites src onto this raster where they overlap.

      Parameters
      • src: the layer
      • mode: how colors combine
      • opacity: the layer's opacity, 0 to 1
    • applyMask

      public void applyMask(byte[] mask)

      Multiplies each pixel's alpha by a coverage mask of the same geometry (0..255).

      Parameters
      • mask: one byte of coverage per pixel
    • transform

      public Raster transform(Matrix m, int[] clip)

      Returns this raster drawn through a transform, sampled bilinearly, clipped to the device rectangle clip (x, y, w, h) when it is not null.

      Parameters
      • m: maps this raster's absolute coordinates to device coordinates
      • clip: limits the result; may be null