java.lang.Object
imagingbook.common.util.bits.BitMap
This class implements a true 2D bitmap container, i.e., each 0/1 element occupies only a single bit (unlike
boolean arrays, which require at least 8 bits per element).- Version:
- 2022/09/13
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BitMapcreate(int width, int height) Creates a new 2D bitmap of the specified size.booleanget(int x, int y) Returnstrueis the specified element is set (1),falseotherwise (0).booleanget(Pnt2d.PntInt p) Returnstrueis the specified element is set (1),falseotherwise (0).Returns the underlying 1DBitVector.intReturns the height of thisBitMap.intgetWidth()Returns the width of thisBitMap.voidset(int x, int y) Sets the specified element (to bit-value 1).voidset(int x, int y, boolean val) Sets the specified bit-element to the given boolean value (1 fortrue, 0 forfalse).voidset(Pnt2d.PntInt p) Sets the specified element (to bit-value 1).voidset(Pnt2d.PntInt p, boolean val) Sets the specified bit-element to the given boolean value (1 fortrue, 0 forfalse).voidsetAll()Sets all elements to 1.byte[]Returns the contents of this bitmap as a one-dimensionalbytearray, with elements in row-major order.voidunset(int x, int y) Unsets the specified element (to bit-value 0).voidUnsets the specified element (to bit-value 0).voidunsetAll()Sets all elements to 0.
-
Constructor Details
-
BitMap
Constructor, creates an empty bitmap (with all elements set to 0). Both dimensions must be at least 1.- Parameters:
width- the width of the new bitmapheight- the height of the new bitmap
-
BitMap
Constructor, creates a bitmap from a one-dimensional byte array. Elements of the specified byte array are assumed in row-major order, zero values map to 0, anything else to 1. Passingnullfor the byte array creates an empty bitmap (with all elements set to 0). Both dimensions must be at least 1.- Parameters:
width- the width of the new bitmapheight- the height of the new bitmapbytes- a byte array (nullis allowed)
-
-
Method Details
-
getWidth
Returns the width of thisBitMap.- Returns:
- the width
-
getHeight
Returns the height of thisBitMap.- Returns:
- the height
-
get
Returnstrueis the specified element is set (1),falseotherwise (0).- Parameters:
x- the x-coordinatey- the y-coordinate- Returns:
- as described
-
get
Returnstrueis the specified element is set (1),falseotherwise (0).- Parameters:
p- the x/y-coordinate (point)- Returns:
- as described
-
set
Sets the specified bit-element to the given boolean value (1 fortrue, 0 forfalse).- Parameters:
x- the x-coordinatey- the y-coordinateval- a boolean value
-
set
Sets the specified bit-element to the given boolean value (1 fortrue, 0 forfalse).- Parameters:
p- the x/y-coordinate (point)val- a boolean value
-
set
Sets the specified element (to bit-value 1).- Parameters:
x- the x-coordinatey- the y-coordinate
-
set
Sets the specified element (to bit-value 1).- Parameters:
p- the x/y-coordinate (point)
-
unset
Unsets the specified element (to bit-value 0).- Parameters:
x- the x-coordinatey- the y-coordinate
-
unset
Unsets the specified element (to bit-value 0).- Parameters:
p- the x/y-coordinate (point)
-
setAll
Sets all elements to 1. -
unsetAll
Sets all elements to 0. -
getBitVector
Returns the underlying 1DBitVector.- Returns:
- the bit vector
-
toByteArray
Returns the contents of this bitmap as a one-dimensionalbytearray, with elements in row-major order. Bit-value 0 maps to byte value 0, value 1 maps to 1.- Returns:
- a one-dimensional
bytearray
-
create
Creates a new 2D bitmap of the specified size.- Parameters:
width- the width of the new bitmapheight- the height of the new bitmap- Returns:
- the new bitmap
-