Class FullSpacedColorBuffer

java.lang.Object
de.pianoman911.mapengine.api.util.FullSpacedColorBuffer

public class FullSpacedColorBuffer extends Object
ARGB color buffer with 24 bit of rgb colors and 8 bits of an alpha channel.
  • Constructor Details

    • FullSpacedColorBuffer

      public FullSpacedColorBuffer(int[] data, int width, int height)
      Wraps the given argb data into a color buffer.
      Parameters:
      data - initial data
      width - the width of the buffer, must match the data
      height - the height of the buffer, must match the data
    • FullSpacedColorBuffer

      @Deprecated public FullSpacedColorBuffer(int size, int width, int height)
      Deprecated.
      should not be used for creation, use FullSpacedColorBuffer(int, int) instead
      Creates a new color buffer with the given size.
      Parameters:
      width - the width of the buffer
      height - the height of the buffer
    • FullSpacedColorBuffer

      public FullSpacedColorBuffer(int width, int height)
      Creates a new color buffer from with the given width and height.
      Parameters:
      width - the width of the buffer
      height - the height of the buffer
  • Method Details

    • pixel

      public void pixel(int x, int y, int newColor)
      Sets the pixel at the given position in the buffer to the given color. It respects the alpha channel of the color and blends the color with the existing color in the buffer.
      Parameters:
      x - the x position of the pixel
      y - the y position of the pixel
      newColor - the new color of the pixel
    • pixels

      public final void pixels(int[] pixels, int x, int y, int width, int height)
      Sets rectangular area of the buffer to the given color. It respects the alpha channel of the color and blends the color with the existing color in the buffer.
      Parameters:
      pixels - the pixels to set
      x - the x position of the area
      y - the y position of the area
      width - the width of the area
      height - the height of the area
    • buffer

      public final void buffer(FullSpacedColorBuffer buffer, int x, int y)
      Sets another buffer on top of this buffer It respects the alpha channel of the color and blends the color with the existing color in the buffer.
      Parameters:
      buffer - the buffer to set
      x - the x position of the buffer
      y - the y position of the buffer
    • replaceColor

      public final void replaceColor(int oldColor, int newColor)
      Replaces all occurrences of the old color with the new color.
      Parameters:
      oldColor - the color to replace
      newColor - the color to replace with
    • removeColor

      public final void removeColor(int color)
      Removes all occurrences of the given color, replacing them with transparent pixels.
      Parameters:
      color - the color to remove
    • scale

      public final FullSpacedColorBuffer scale(double scale, boolean smooth)
      Creates a scaled copy of this buffer
      Parameters:
      scale - the factor to scale by
      smooth - whether to use a smooth scaling algorithm
      Returns:
      the scaled copy
    • scale

      public FullSpacedColorBuffer scale(double scaleX, double scaleY, boolean smooth)
      Creates a scaled copy of this buffer with the given x- and y-scale.
      Parameters:
      scaleX - the factor to scale the x-axis by
      scaleY - the factor to scale the y-axis by
      smooth - whether to use a smooth scaling algorithm
      Returns:
      the scaled copy
    • rotate

      public FullSpacedColorBuffer rotate(Rotation rotation)
      Creates a rotated copy of this buffer.
      Parameters:
      rotation - the rotation to rotate by
      Returns:
      the rotated copy
    • applySuperSampling

      public FullSpacedColorBuffer applySuperSampling(int factor)
      Create a super-sampled copy of this buffer.
      Parameters:
      factor - the factor to super-sample by, must be above 0
      Returns:
      the super-sampled copy
    • scale

      public final FullSpacedColorBuffer scale(int newWidth, int newHeight, boolean smooth)
      Creates a scaled copy of this buffer with the specified new dimensions.
      Parameters:
      newWidth - the new width
      newHeight - the new height
      smooth - whether to use a smooth scaling algorithm
      Returns:
      the scaled copy
    • snapshot

      public BufferedImage snapshot()
      Returns:
      a snapshot of this buffer as a BufferedImage
    • subBuffer

      public final FullSpacedColorBuffer subBuffer(int x, int y, int width, int height)
      Creates a new sub-buffer of this buffer at the given position with the given dimensions.
      Parameters:
      x - the x-coordinate of where to start
      y - the y-coordinate of where to start
      width - the width of the sub-buffer
      height - the height of the sub-buffer
      Returns:
      the new sub-buffer
    • cropAlpha

      public final FullSpacedColorBuffer cropAlpha()
      * Creates a new sub-buffer of this buffer with the alpha channel cropped.
      Returns:
      the copy of this buffer with the alpha channel cropped
    • crop

      public FullSpacedColorBuffer crop(int background)
      Creates a new sub-buffer of this buffer with the given background color cropped. The rest of the background color will not be removed. If you want to remove the background color, use removeColor(int) afterward.
      Returns:
      the copy of this buffer with the given background color cropped
    • copy

      public final FullSpacedColorBuffer copy()
      Returns:
      a copy of this buffer
    • pixel

      public final int pixel(int x, int y)
      Returns the color of the pixel at the given position.
      Parameters:
      x - the x-coordinate of the pixel
      y - the y-coordinate of the pixel
      Returns:
      the color of the pixel
    • buffer

      public final int[] buffer()
      Returns:
      the raw argb data wrapped by this buffer, mutable
    • size

      public final int size()
      Returns:
      the internal length of the data
    • width

      public final int width()
      Returns:
      the width in pixels
    • height

      public final int height()
      Returns:
      the height in pixels