public class Canvas extends Object
| Constructor and Description |
|---|
Canvas(byte[] matrix,
int height)
Constructs a Canvas which wraps the given matrix.
|
Canvas(int width,
int height)
Constructs a Canvas with a new matrix of the given width and height.
|
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
crop(byte[] matrix,
int x,
int y,
int width,
int height,
byte[] out)
Crops the given pixel matrix.
|
static byte[] |
cropX(byte[] matrix,
int x,
int width,
byte[] out)
Crops the given pixel matrix horizontally.
|
static byte[] |
cropY(byte[] matrix,
int y,
int height,
byte[] out)
Crops the given pixel matrix vertically.
|
void |
empty()
Empty the matrix (fill it with empty columns).
|
static byte[] |
empty(byte[] matrix)
Empties a byte array by filling it with zeros.
|
static byte[] |
fill(byte[] matrix)
Fills a byte array with 0xFF bytes (i.e.
|
static byte[] |
fill(byte[] matrix,
int value)
Fills a byte array with a single value.
|
void |
fill(int value)
Fills the matrix with the given column value.
|
static byte |
flip(byte b)
Flips the order of bits in a byte.
|
static byte[] |
flip(byte[] matrix,
int height,
byte[] out)
Flips the order of the least-significant bits in an array of bytes.
|
static byte |
flip(byte b,
int height)
Flips the order of the least-significant bits in a byte.
|
int |
getHeight()
Returns the canvas height in pixels.
|
byte[] |
getMatrix()
Returns the wrapped matrix bytes.
|
int |
getWidth()
Returns the canvas width in pixels.
|
static void |
graph(byte[] matrix,
int width,
int height,
float[] values,
Float low,
Float high,
boolean bars)
Draws a graph with the given width and height in pixels
from the given data values and boundaries.
|
static void |
graph(byte[] matrix,
int width,
int height,
int[] values,
Float low,
Float high,
boolean bars)
Draws a graph with the given width and height in pixels
from the given data values and boundaries.
|
void |
graph(int[] values,
Float low,
Float high,
boolean bars)
Draws a graph with the given width and height in pixels
from the given data values and boundaries.
|
byte[] |
render()
Render the matrix into a returned buffer,
with transformations applied (flip, reverse, crop, etc.)
|
static byte[] |
reverse(byte[] matrix,
byte[] out)
Reverses the order of bytes in an array.
|
void |
scroll(int delta)
Scrolls the rendered columns by the given number of columns
(positive or negative delta).
|
static void |
setBit(byte[] matrix,
int x,
int y,
boolean value)
Sets the value of a single bit within a matrix
of bits represented by a byte array.
|
void |
setColumn(int column,
int value)
Sets the value of a column.
|
void |
setColumns(int startColumn,
byte[] columns,
int offset,
int length)
Sets the value of a sequence of columns.
|
void |
setFlip(boolean flip)
Sets whether the rendered matrix should be flipped vertically.
|
void |
setMatrix(byte[] matrix)
Sets the wrapped matrix bytes.
|
void |
setOffset(int offset)
Sets the offset of the column within the matrix at which
the rendering will start.
|
void |
setPixel(int x,
int y,
boolean value)
Sets the value of a pixel.
|
void |
setReverse(boolean reverse)
Sets whether the rendered matrix should be reversed horizontally.
|
static String |
toAsciiArt(byte[] matrix,
int height)
Converts the pixel matrix represented by a given byte array to a string
containing the ASCII-art representation of the pixels.
|
static String |
toAsciiArt(byte[] matrix,
int offset,
int len,
int height)
Converts the pixel matrix represented by a given byte array to a string
containing the ASCII-art representation of the pixels.
|
public Canvas(byte[] matrix,
int height)
throws IOException
matrix - the matrix to wrapheight - the height of the pixel matrix in pixels (max 8)IOException - if an error occurspublic Canvas(int width,
int height)
throws IOException
width - the width of the pixel matrix in pixelsheight - the height of the pixel matrix in pixels (max 8)IOException - if an error occurspublic static String toAsciiArt(byte[] matrix, int offset, int len, int height)
matrix - the pixel matrixoffset - the offset within the matrix where the data to convert startslen - the length in bytes of the data to convertheight - the height of the pixel matrix in pixels (max 8)public static String toAsciiArt(byte[] matrix, int height)
matrix - the pixel matrixheight - the height of the pixel matrix in pixels (max 8)public static byte flip(byte b)
b - a bytepublic static byte flip(byte b,
int height)
b - a byteheight - the number of least-significant bits to flip
(all higher bits are set to zero)public static byte[] flip(byte[] matrix,
int height,
byte[] out)
matrix - the bytes to flipheight - the number of least-significant bits to flip
(all higher bits are set to zero)out - an array into which the flipped bits are written
(can be identical to the given source array)public static byte[] reverse(byte[] matrix,
byte[] out)
matrix - the bytes to flipout - an array into which the reversed bytes are written
(can be identical to the given source array)public static byte[] cropX(byte[] matrix,
int x,
int width,
byte[] out)
matrix - the pixel matrix to cropx - the X position to start cropping at (left side of cropped rectangle)width - the number of pixels to crop horizontallyout - an array into which the cropped bytes are written
(can be identical to the given source array)public static byte[] cropY(byte[] matrix,
int y,
int height,
byte[] out)
matrix - the pixel matrix to cropy - the Y position to start cropping at (top side of cropped rectangle)height - the number of pixels to crop verticallyout - an array into which the cropped bytes are written
(can be identical to the given source array)public static byte[] crop(byte[] matrix,
int x,
int y,
int width,
int height,
byte[] out)
matrix - the pixel matrix to cropx - the X position to start cropping at (left side of cropped rectangle)y - the Y position to start cropping at (top side of cropped rectangle)width - the number of pixels to crop horizontallyheight - the number of pixels to crop verticallyout - an array into which the cropped bytes are written
(can be identical to the given source array)public static byte[] empty(byte[] matrix)
matrix - a byte arraypublic static byte[] fill(byte[] matrix,
int value)
matrix - a byte arrayvalue - the value to fill withpublic static byte[] fill(byte[] matrix)
matrix - a byte arraypublic static void setBit(byte[] matrix,
int x,
int y,
boolean value)
matrix - a byte array (matrix of bits)x - the x coordinate of the bit to set (left to right)y - the y coordinate of the bit to set (top to bottom)value - the value to set (true means 1, false means 0)public static void graph(byte[] matrix,
int width,
int height,
float[] values,
Float low,
Float high,
boolean bars)
matrix - the pixel matrix to draw onwidth - the graph width in pixelsheight - the graph height in pixelsvalues - the data valueslow - the value represented at the bottom of the graph,
or null if the minimum data value should be usedhigh - the value represented at the top of the graph,
or null if the maximum data value should be usedbars - specifies whether the graph is a bar graph (with
filled area under the value), or a scatter plot
(single point per value)public static void graph(byte[] matrix,
int width,
int height,
int[] values,
Float low,
Float high,
boolean bars)
matrix - the pixel matrix to draw onwidth - the graph width in pixelsheight - the graph height in pixelsvalues - the data valueslow - the value represented at the bottom of the graph,
or null if the minimum data value should be usedhigh - the value represented at the top of the graph,
or null if the maximum data value should be usedbars - specifies whether the graph is a bar graph (with
filled area under the value), or a scatter plot
(single point per value)public int getWidth()
public int getHeight()
public void setFlip(boolean flip)
flip - true if the rendered matrix should be flipped vertically;
false otherwisepublic void setReverse(boolean reverse)
reverse - true if the rendered matrix should be reversed horizontally;
false otherwisepublic byte[] getMatrix()
public void setMatrix(byte[] matrix)
matrix - the wrapped matrix bytespublic void setColumn(int column,
int value)
column - the column to setvalue - the column valuepublic void setColumns(int startColumn,
byte[] columns,
int offset,
int length)
startColumn - the first target columncolumns - the column valuesoffset - the start offset of the column valueslength - the length of the column valuespublic void setPixel(int x,
int y,
boolean value)
x - the X coordinate of the pixely - the Y coordinate of the pixelvalue - the pixel value (true for on, false for off)public void fill(int value)
value - the column value to fill the matrix withpublic void empty()
throws IOException
IOException - if an error occurspublic byte[] render()
throws IOException
IOException - if an error occurspublic void setOffset(int offset)
offset - the offset of the column within the matrixpublic void scroll(int delta)
delta - the number of columns to scroll bypublic void graph(int[] values,
Float low,
Float high,
boolean bars)
values - the data valueslow - the value represented at the bottom of the graph,
or null if the minimum data value should be usedhigh - the value represented at the top of the graph,
or null if the maximum data value should be usedbars - specifies whether the graph is a bar graph (with
filled area under the value), or a scatter plot
(single point per value)Copyright © 2017 freeutils.net. All rights reserved.