java.lang.Object
com.google.zxing.qrcode.encoder.ByteMatrix

public final class ByteMatrixextends Object
JAVAPORT: The original code was a 2D array of ints, but since it only ever gets assigned -1, 0, and 1, I'm going to use less memory and go with bytes.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final byte[][]
    internal 2D array of bytes
    private final int
    height of the matrix
    private final int
    width of the matrix
  • Constructor Summary

    Constructors
    Constructor
    Description
    ByteMatrix(int width, int height)
    Creates a new ByteMatrix with the specified dimensions.
  • Method Summary

    All Methods
    Modifier and Type
    Method
    Description
    void
    clear(byte value)
    Clears all cells in the matrix to the specified value.
    byte
    get(int x, int y)
    Gets the value at the specified coordinates.
    byte[][]
    Returns the internal representation as bytes, in row-major order.
    int
    Returns the height of the matrix.
    int
    Returns the width of the matrix.
    void
    set(int x, int y, boolean value)
    Sets the value at the specified coordinates using a boolean value.
    void
    set(int x, int y, byte value)
    Sets the value at the specified coordinates.
    void
    set(int x, int y, int value)
    Sets the value at the specified coordinates using an int value.
    Matrix as text for debugging.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • bytes

      private final byte[][] bytes
      internal 2D array of bytes
    • width

      private final int width
      width of the matrix
    • height

      private final int height
      height of the matrix
  • Constructor Details

    • ByteMatrix

      public ByteMatrix(int width, int height)
      Creates a new ByteMatrix with the specified dimensions.
      Parameters:
      width - the width of the matrix
      height - the height of the matrix
  • Method Details

    • getHeight

      public int getHeight()
      Returns the height of the matrix.
      Returns:
      the height of the matrix
    • getWidth

      public int getWidth()
      Returns the width of the matrix.
      Returns:
      the width of the matrix
    • get

      public byte get(int x, int y)
      Gets the value at the specified coordinates.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      Returns:
      the byte value at the specified position
    • getArray

      public byte[][] getArray()
      Returns the internal representation as bytes, in row-major order.
      Returns:
      an internal representation as bytes, in row-major order. array[y][x] represents point (x,y)
    • set

      public void set(int x, int y, byte value)
      Sets the value at the specified coordinates.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      value - the byte value to set
    • set

      public void set(int x, int y, int value)
      Sets the value at the specified coordinates using an int value.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      value - the int value to set (will be cast to byte)
    • set

      public void set(int x, int y, boolean value)
      Sets the value at the specified coordinates using a boolean value.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      value - the boolean value to set (true = 1, false = 0)
    • clear

      public void clear(byte value)
      Clears all cells in the matrix to the specified value.
      Parameters:
      value - the byte value to set all cells to
    • toString

      public String toString()
      Matrix as text for debugging.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this ByteMatrix