Class FullSpacedColorBuffer
java.lang.Object
de.pianoman911.mapengine.api.util.FullSpacedColorBuffer
ARGB color buffer with 24 bit of rgb colors and 8 bits of an alpha channel.
-
Constructor Summary
ConstructorsConstructorDescriptionFullSpacedColorBuffer
(int[] data, int width, int height) Wraps the given argb data into a color buffer.FullSpacedColorBuffer
(int width, int height) Creates a new color buffer from with the given width and height.FullSpacedColorBuffer
(int size, int width, int height) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionapplySuperSampling
(int factor) Create a super-sampled copy of this buffer.final int[]
buffer()
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.final FullSpacedColorBuffer
copy()
crop
(int background) Creates a new sub-buffer of this buffer with the given background color cropped.final FullSpacedColorBuffer
* Creates a new sub-buffer of this buffer with the alpha channel cropped.final int
height()
final int
pixel
(int x, int y) Returns the color of the pixel at the given position.void
pixel
(int x, int y, int newColor) Sets the pixel at the given position in the buffer to the given color.final void
pixels
(int[] pixels, int x, int y, int width, int height) Sets rectangular area of the buffer to the given color.final void
removeColor
(int color) Removes all occurrences of the given color, replacing them with transparent pixels.final void
replaceColor
(int oldColor, int newColor) Replaces all occurrences of the old color with the new color.Creates a rotated copy of this buffer.final FullSpacedColorBuffer
scale
(double scale, boolean smooth) Creates a scaled copy of this bufferscale
(double scaleX, double scaleY, boolean smooth) Creates a scaled copy of this buffer with the given x- and y-scale.final FullSpacedColorBuffer
scale
(int newWidth, int newHeight, boolean smooth) Creates a scaled copy of this buffer with the specified new dimensions.final int
size()
snapshot()
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.final int
width()
-
Constructor Details
-
FullSpacedColorBuffer
public FullSpacedColorBuffer(int[] data, int width, int height) Wraps the given argb data into a color buffer.- Parameters:
data
- initial datawidth
- the width of the buffer, must match the dataheight
- the height of the buffer, must match the data
-
FullSpacedColorBuffer
Deprecated.should not be used for creation, useFullSpacedColorBuffer(int, int)
insteadCreates a new color buffer with the given size.- Parameters:
width
- the width of the bufferheight
- 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 bufferheight
- 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 pixely
- the y position of the pixelnewColor
- 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 setx
- the x position of the areay
- the y position of the areawidth
- the width of the areaheight
- the height of the area
-
buffer
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 setx
- the x position of the buffery
- 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 replacenewColor
- 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
Creates a scaled copy of this buffer- Parameters:
scale
- the factor to scale bysmooth
- whether to use a smooth scaling algorithm- Returns:
- the scaled copy
-
scale
Creates a scaled copy of this buffer with the given x- and y-scale.- Parameters:
scaleX
- the factor to scale the x-axis byscaleY
- the factor to scale the y-axis bysmooth
- whether to use a smooth scaling algorithm- Returns:
- the scaled copy
-
rotate
Creates a rotated copy of this buffer.- Parameters:
rotation
- the rotation to rotate by- Returns:
- the rotated copy
-
applySuperSampling
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
Creates a scaled copy of this buffer with the specified new dimensions.- Parameters:
newWidth
- the new widthnewHeight
- the new heightsmooth
- whether to use a smooth scaling algorithm- Returns:
- the scaled copy
-
snapshot
- Returns:
- a snapshot of this buffer as a
BufferedImage
-
subBuffer
Creates a new sub-buffer of this buffer at the given position with the given dimensions.- Parameters:
x
- the x-coordinate of where to starty
- the y-coordinate of where to startwidth
- the width of the sub-bufferheight
- the height of the sub-buffer- Returns:
- the new sub-buffer
-
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
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, useremoveColor(int)
afterward.- Returns:
- the copy of this buffer with the given background color cropped
-
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 pixely
- 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
-
FullSpacedColorBuffer(int, int)
instead