Class MatrixUtil

java.lang.Object
com.itextpdf.barcodes.qrcode.MatrixUtil

final class MatrixUtil extends Object
  • Field Details

    • POSITION_DETECTION_PATTERN

      private static final int[][] POSITION_DETECTION_PATTERN
    • HORIZONTAL_SEPARATION_PATTERN

      private static final int[][] HORIZONTAL_SEPARATION_PATTERN
    • VERTICAL_SEPARATION_PATTERN

      private static final int[][] VERTICAL_SEPARATION_PATTERN
    • POSITION_ADJUSTMENT_PATTERN

      private static final int[][] POSITION_ADJUSTMENT_PATTERN
    • POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE

      private static final int[][] POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE
    • TYPE_INFO_COORDINATES

      private static final int[][] TYPE_INFO_COORDINATES
    • VERSION_INFO_POLY

      private static final int VERSION_INFO_POLY
      See Also:
    • TYPE_INFO_POLY

      private static final int TYPE_INFO_POLY
      See Also:
    • TYPE_INFO_MASK_PATTERN

      private static final int TYPE_INFO_MASK_PATTERN
      See Also:
  • Constructor Details

    • MatrixUtil

      private MatrixUtil()
  • Method Details

    • clearMatrix

      public static void clearMatrix(ByteMatrix matrix)
    • buildMatrix

      public static void buildMatrix(BitVector dataBits, ErrorCorrectionLevel ecLevel, int version, int maskPattern, ByteMatrix matrix) throws WriterException
      Build 2D matrix of QR Code from "dataBits" with "ecLevel", "version" and "getMaskPattern". On success, store the result in "matrix".
      Parameters:
      dataBits - BitVector containing the databits
      ecLevel - Error correction level of the QR code (L,M,Q,H)
      version - Version of the QR code, [1 .. 40]
      maskPattern - masking pattern
      matrix - Bytematrix in which the output will be stored
      Throws:
      WriterException
    • embedBasicPatterns

      public static void embedBasicPatterns(int version, ByteMatrix matrix) throws WriterException
      Embed basic patterns. On success, modify the matrix. The basic patterns are: - Position detection patterns - Timing patterns - Dark dot at the left bottom corner - Position adjustment patterns, if need be
      Parameters:
      version - Version of the QR code, [1 .. 40]
      matrix - Bytematrix in which the output will be stored
      Throws:
      WriterException
    • embedTypeInfo

      public static void embedTypeInfo(ErrorCorrectionLevel ecLevel, int maskPattern, ByteMatrix matrix) throws WriterException
      Embed type information into the matrix
      Parameters:
      ecLevel - The error correction level (L,M,Q,H)
      maskPattern - the masking pattern
      matrix - Bytematrix in which the output will be stored
      Throws:
      WriterException
    • maybeEmbedVersionInfo

      public static void maybeEmbedVersionInfo(int version, ByteMatrix matrix) throws WriterException
      Embed version information if need be. For version < 7, version info is not necessary On success, the matrix is modified See 8.10 of JISX0510:2004 (p.47) for how to embed version information.
      Parameters:
      version - QR code version
      matrix - Byte matrix representing the QR code
      Throws:
      WriterException
    • embedDataBits

      public static void embedDataBits(BitVector dataBits, int maskPattern, ByteMatrix matrix) throws WriterException
      Embed "dataBits" using "getMaskPattern". On success, the matrix is modified For debugging purposes, it skips masking process if "getMaskPattern" is -1. See 8.7 of JISX0510:2004 (p.38) for how to embed data bits.
      Parameters:
      dataBits - data bits to embed in the QR code
      maskPattern - masking pattern to apply to the data bits
      matrix - Byte matrix representing the QR code
      Throws:
      WriterException
    • findMSBSet

      public static int findMSBSet(int value)
      Return the position of the most significant bit set (to one) in the "value". The most significant bit is position 32. If there is no bit set, return 0. Examples: - findMSBSet(0) => 0 - findMSBSet(1) => 1 - findMSBSet(255) => 8
      Parameters:
      value - bitstring as integer
      Returns:
      the position of the most significant bit set to 1 in the bit-representation of value
    • calculateBCHCode

      public static int calculateBCHCode(int value, int poly)
      Calculate BCH (Bose-Chaudhuri-Hocquenghem) code for "value" using polynomial "poly". The BCH code is used for encoding type information and version information. Example: Calculation of version information of 7. f(x) is created from 7. - 7 = 000111 in 6 bits - f(x) = x^2 + x^2 + x^1 g(x) is given by the standard (p. 67) - g(x) = x^12 + x^11 + x^10 + x^9 + x^8 + x^5 + x^2 + 1 Multiply f(x) by x^(18 - 6) - f'(x) = f(x) * x^(18 - 6) - f'(x) = x^14 + x^13 + x^12 Calculate the remainder of f'(x) / g(x) x^2 __________________________________________________ g(x) )x^14 + x^13 + x^12 x^14 + x^13 + x^12 + x^11 + x^10 + x^7 + x^4 + x^2 -------------------------------------------------- x^11 + x^10 + x^7 + x^4 + x^2

      The remainder is x^11 + x^10 + x^7 + x^4 + x^2 Encode it in binary: 110010010100 The return value is 0xc94 (1100 1001 0100)

      Since all coefficients in the polynomials are 1 or 0, we can do the calculation by bit operations. We don't care if cofficients are positive or negative.

      Parameters:
      value - the bitstring to calculate the BCH Code from
      poly - the polynomial in GF[2^n] to use
    • makeTypeInfoBits

      public static void makeTypeInfoBits(ErrorCorrectionLevel ecLevel, int maskPattern, BitVector bits) throws WriterException
      Make bit vector of type information. On success, store the result in "bits". Encode error correction level and mask pattern. See 8.9 of JISX0510:2004 (p.45) for details.
      Parameters:
      ecLevel - error correction level of the QR code
      maskPattern - masking pattern to use
      bits - Vactor of bits to contain the result
      Throws:
      WriterException
    • makeVersionInfoBits

      public static void makeVersionInfoBits(int version, BitVector bits) throws WriterException
      Make bit vector of version information. On success, store the result in "bits". See 8.10 of JISX0510:2004 (p.45) for details.
      Parameters:
      version - Version of the QR-code
      bits - Vector of bits to contain the result
      Throws:
      WriterException
    • isEmpty

      private static boolean isEmpty(byte value)
    • isValidValue

      private static boolean isValidValue(byte value)
    • embedTimingPatterns

      private static void embedTimingPatterns(ByteMatrix matrix) throws WriterException
      Throws:
      WriterException
    • embedDarkDotAtLeftBottomCorner

      private static void embedDarkDotAtLeftBottomCorner(ByteMatrix matrix) throws WriterException
      Throws:
      WriterException
    • embedHorizontalSeparationPattern

      private static void embedHorizontalSeparationPattern(int xStart, int yStart, ByteMatrix matrix) throws WriterException
      Throws:
      WriterException
    • embedVerticalSeparationPattern

      private static void embedVerticalSeparationPattern(int xStart, int yStart, ByteMatrix matrix) throws WriterException
      Throws:
      WriterException
    • embedPositionAdjustmentPattern

      private static void embedPositionAdjustmentPattern(int xStart, int yStart, ByteMatrix matrix) throws WriterException
      Throws:
      WriterException
    • embedPositionDetectionPattern

      private static void embedPositionDetectionPattern(int xStart, int yStart, ByteMatrix matrix) throws WriterException
      Throws:
      WriterException
    • embedPositionDetectionPatternsAndSeparators

      private static void embedPositionDetectionPatternsAndSeparators(ByteMatrix matrix) throws WriterException
      Throws:
      WriterException
    • maybeEmbedPositionAdjustmentPatterns

      private static void maybeEmbedPositionAdjustmentPatterns(int version, ByteMatrix matrix) throws WriterException
      Throws:
      WriterException