BitMatrix

class BitMatrix

Represents a 2D matrix of bits. In function arguments below, and throughout the common module, x is the column position, and y is the row position. The ordering is always x, y. The origin is at the top-left.

Internally the bits are represented in a 1-D array of 32-bit ints. However, each row begins with a new int. This is done intentionally so that we can copy out a row into a BitArray very efficiently.

The ordering of bits is row-major. Within each int, the least significant bits are used first, meaning they represent lower x values. This is compatible with BitArray's implementation.

Constructors

Link copied to clipboard
constructor(dimension: Int)

Creates an empty square BitMatrix.

constructor(width: Int, height: Int)

Creates an empty BitMatrix.

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun clear()

Clears all bits (sets to false).

Link copied to clipboard
Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
fun flip()

Flips every bit in the matrix.

fun flip(x: Int, y: Int)

Flips the given bit.

Link copied to clipboard
fun get(x: Int, y: Int): Boolean

Gets the requested bit, where true means black.

Link copied to clipboard
Link copied to clipboard

This is useful in detecting the enclosing rectangle of a 'pure' barcode.

Link copied to clipboard
fun getHeight(): Int
Link copied to clipboard
fun getRow(y: Int, row: BitArray?): BitArray

A fast method to retrieve one row of data from the matrix as a BitArray.

Link copied to clipboard
Link copied to clipboard

This is useful in detecting a corner of a 'pure' barcode.

Link copied to clipboard
fun getWidth(): Int
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
fun rotate(degrees: Int)

Modifies this BitMatrix to represent the same but rotated the given degrees (0, 90, 180, 270)

Link copied to clipboard
fun rotate180()

Modifies this BitMatrix to represent the same but rotated 180 degrees

Link copied to clipboard
fun rotate90()

Modifies this BitMatrix to represent the same but rotated 90 degrees counterclockwise

Link copied to clipboard
fun set(x: Int, y: Int)

Sets the given bit to true.

Link copied to clipboard
fun setRegion(left: Int, top: Int, width: Int, height: Int)

Sets a square region of the bit matrix to true.

Link copied to clipboard
fun setRow(y: Int, row: BitArray)
Link copied to clipboard
fun BitMatrix.toPng(scale: Int = 8, quietZone: Int = 4, dark: Int = 0, light: Int = 16777215): ByteArray

Renders a BitMatrix to PNG bytes via the dependency-free Png encoder.

Link copied to clipboard
open override fun toString(): String
fun toString(setString: String, unsetString: String): String
fun toString(setString: String, unsetString: String, lineSeparator: String): String
Link copied to clipboard
fun BitMatrix.toSvg(moduleSize: Int = 10, quietZone: Int = 4, dark: String = "#000000", light: String? = "#FFFFFF"): String

Renders a BitMatrix to a standalone SVG string: true vector output, no rasteriser, no platform. Each dark module becomes a 1×1 path cell, so the whole symbol is a single <path>.

Link copied to clipboard
fun unset(x: Int, y: Int)
Link copied to clipboard
fun xor(mask: BitMatrix)

Exclusive-or (XOR): Flip the bit in this BitMatrix if the corresponding mask bit is set.