Class QrCodePolynomialMath

java.lang.Object
boofcv.alg.fiducial.qrcode.QrCodePolynomialMath

public class QrCodePolynomialMath extends Object
Contains all the formulas for encoding and decoding BCH and Reed-Solomon codes. For a more accessible introduction to this material see [1] and [2].
 [1] S. A. Tretter "Introduction to Bose Chaudhuri Hocquenghem codes" Goddard Space Flight Center, September 1967
 [2] https://en.wikiversity.org/wiki/Reed–Solomon_codes_for_coders
 
  • Field Details

  • Constructor Details

    • QrCodePolynomialMath

      public QrCodePolynomialMath()
  • Method Details

    • encodeVersionBits

      public static int encodeVersionBits(int version)
      Encodes the version bits. BCH(18,6)
      Parameters:
      version - QR code version. 7 to 40
      Returns:
      encoded bit field
    • checkVersionBits

      public static boolean checkVersionBits(int bits)
      Encodes the version bits. BCH(18,6)
      Parameters:
      bits - Read in bits. Should encode 18-bits
      Returns:
      encoded bit field
    • correctVersionBits

      public static int correctVersionBits(int bits)
      Attempts to correct version bit sequence.
      Parameters:
      bits - Read in bits after removing the mask
      Returns:
      If the message could be corrected, th 5-bit format message. -1 if it couldn't
    • encodeFormatBits

      public static int encodeFormatBits(QrCode.ErrorLevel level, int mask)
      Encodes the format bits. BCH(15,5)
      Parameters:
      level - Error correction level
      mask - The type of mask that is applied to the qr code
      Returns:
      encoded bit field
    • encodeFormatBits

      public static int encodeFormatBits(int message5bits)
      Encodes the 5-bit format bits for QR and Micro QR. BCH(15,5)
      Parameters:
      message5bits - 5-bit message
      Returns:
      encoded bit field
    • checkFormatBits

      public static boolean checkFormatBits(int bitsNoMask)
      Check the format bits. BCH(15,5) code.
    • decodeFormatMessage

      public static void decodeFormatMessage(int message, QrCode qr)
      Assumes that the format message has no errors in it and decodes its data and saves it into the qr code
      Parameters:
      message - format data bits after the mask has been remove and shifted over 10 bits
      qr - Where the results are written to
    • correctFormatBits

      public static int correctFormatBits(int bitsNoMask)
      Attempts to correct format bit sequence.
      Parameters:
      bitsNoMask - Read in bits after removing the mask
      Returns:
      If the message could be corrected, th 5-bit format message. -1 if it couldn't
    • correctDCH

      public static int correctDCH(int N, int messageNoMask, int generator, int totalBits, int dataBits)
      Applies a brute force algorithm to find the message which has the smallest hamming distance. if two messages have the same distance -1 is returned.
      Parameters:
      N - Number of possible messages. 32 or 64
      messageNoMask - The observed message with mask removed
      generator - Generator polynomial
      totalBits - Total number of bits in the message.
      dataBits - Total number of data bits in the message
      Returns:
      The error corrected message or -1 if it can't be determined.
    • bitPolyModulus

      public static int bitPolyModulus(int data, int generator, int totalBits, int dataBits)
      Performs division using xcr operators on the encoded polynomials. used in BCH encoding/decoding
      Parameters:
      data - Data being checked
      generator - Generator polynomial
      totalBits - Total number of bits in data
      dataBits - Number of data bits. Rest are error correction bits
      Returns:
      Remainder after polynomial division