Options
All
  • Public
  • Public/Protected
  • All
Menu

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.

author

Sean Owen

author

dswitkin@google.com (Daniel Switkin)

Hierarchy

  • BitMatrix

Index

Constructors

constructor

  • new BitMatrix(width: number, height?: number, rowSize?: number, bits?: Int32Array): BitMatrix

Properties

Private Optional bits

bits: Int32Array

Private Optional height

height: number

bit matrix height

Private Optional rowSize

rowSize: number

Private width

width: number

bit matrix width

Methods

Private buildToString

  • buildToString(setString: string, unsetString: string, lineSeparator: string): string

clear

  • clear(): void

clone

equals

  • equals(o: Object): boolean

flip

  • flip(x: number, y: number): void
  • Flips the given bit.

    Parameters

    • x: number

      The horizontal component (i.e. which column)

    • y: number

      The vertical component (i.e. which row)

    Returns void

get

  • get(x: number, y: number): boolean
  • Gets the requested bit, where true means black.

    Parameters

    • x: number

      The horizontal component (i.e. which column)

    • y: number

      The vertical component (i.e. which row)

    Returns boolean

    value of given bit in matrix

getBottomRightOnBit

  • getBottomRightOnBit(): Int32Array

getEnclosingRectangle

  • getEnclosingRectangle(): Int32Array
  • This is useful in detecting the enclosing rectangle of a 'pure' barcode.

    Returns Int32Array

    {@code left,top,width,height} enclosing rectangle of all 1 bits, or null if it is all white

getHeight

  • getHeight(): number

getRow

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

    Parameters

    • y: number

      The row to retrieve

    • Optional row: BitArray

      An optional caller-allocated BitArray, will be allocated if null or too small

    Returns BitArray

    The resulting BitArray - this reference should always be used even when passing your own row

getRowSize

  • getRowSize(): number

getTopLeftOnBit

  • getTopLeftOnBit(): Int32Array
  • This is useful in detecting a corner of a 'pure' barcode.

    Returns Int32Array

    {@code x,y} coordinate of top-left-most 1 bit, or null if it is all white

getWidth

  • getWidth(): number

hashCode

  • hashCode(): int

rotate180

  • rotate180(): void

set

  • set(x: number, y: number): void
  • Sets the given bit to true.

    Parameters

    • x: number

      The horizontal component (i.e. which column)

    • y: number

      The vertical component (i.e. which row)

    Returns void

setRegion

  • setRegion(left: number, top: number, width: number, height: number): void
  • Sets a square region of the bit matrix to true.

    Parameters

    • left: number

      The horizontal position to begin at (inclusive)

    • top: number

      The vertical position to begin at (inclusive)

    • width: number

      The width of the region

    • height: number

      The height of the region

    Returns void

setRow

  • setRow(y: number, row: BitArray): void

toString

  • toString(setString?: string, unsetString?: string, lineSeparator?: string): string
  • deprecated

    call {@link #toString(String,String)} only, which uses \n line separator always

    Parameters

    • Default value setString: string = "X "

      representation of a set bit

    • Default value unsetString: string = " "

      representation of an unset bit

    • Default value lineSeparator: string = ""

      newline character in string representation

    Returns string

    string representation of entire matrix utilizing given strings and line separator

unset

  • unset(x: number, y: number): void

xor

Static parseFromBooleanArray

  • parseFromBooleanArray(image: boolean[][]): BitMatrix
  • Interprets a 2D array of booleans as a BitMatrix, where "true" means an "on" bit.

    function

    parse

    Parameters

    • image: boolean[][]

      bits of the image, as a row-major 2D array. Elements are arrays representing rows

    Returns BitMatrix

    BitMatrix representation of image

Static parseFromString

  • parseFromString(stringRepresentation: string, setString: string, unsetString: string): BitMatrix

Generated using TypeDoc