java.lang.Object
com.google.zxing.qrcode.encoder.MatrixUtil
Utility class for QR code matrix operations.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int[][]The 5 by 5 position adjustment pattern.private static final int[][]The adjustment pattern centers, by version, from JISX 0510, with the coordinates doubled.private static final int[][]The 7 by 7 position detection pattern.private static final int[][]The type info bit positions in the matrix, copied at the top left corner.private static final intMask XORed into the type info bits.private static final intGenerator polynomial of the type info bits, from JISX 0510.private static final intGenerator polynomial of the version bits, from JISX 0510.Constructor Summary
ConstructorsMethod Summary
Private MethodsModifier and TypeMethodDescription(package private) static voidbuildMatrix(BitArray dataBits, ErrorCorrectionLevel ecLevel, Version version, int maskPattern, ByteMatrix matrix) Build the QR code matrix(package private) static intcalculateBCHCode(int value, int poly) Calculate BCH code(package private) static voidclearMatrix(ByteMatrix matrix) Set all cells to empty (-1)(package private) static voidembedBasicPatterns(Version version, ByteMatrix matrix) Embed position detection, timing, and adjustment patternsprivate static voidDraws the always dark bottom left module.(package private) static voidembedDataBits(BitArray dataBits, int maskPattern, ByteMatrix matrix) Embed data bits into matrixprivate static voidembedHorizontalSeparationPattern(int xStart, int yStart, ByteMatrix matrix) Draws the horizontal separator beside a pattern.private static voidembedPositionAdjustmentPattern(int xStart, int yStart, ByteMatrix matrix) Draws one position adjustment pattern.private static voidembedPositionDetectionPattern(int xStart, int yStart, ByteMatrix matrix) Draws one position detection pattern.private static voidDraws the three position detection patterns with their separators.private static voidembedTimingPatterns(ByteMatrix matrix) Draws the timing patterns into the matrix.(package private) static voidembedTypeInfo(ErrorCorrectionLevel ecLevel, int maskPattern, ByteMatrix matrix) Embed type informationprivate static voidembedVerticalSeparationPattern(int xStart, int yStart, ByteMatrix matrix) Draws the vertical separator beside a pattern.(package private) static intfindMSBSet(int value) Find the bit length of a valueprivate static booleanisEmpty(int value) Checks whether a matrix cell is unset.(package private) static voidmakeTypeInfoBits(ErrorCorrectionLevel ecLevel, int maskPattern, BitArray bits) Make type information bit vector(package private) static voidmakeVersionInfoBits(Version version, BitArray bits) Make version information bit vectorprivate static voidmaybeEmbedPositionAdjustmentPatterns(Version version, ByteMatrix matrix) Draws the adjustment patterns the version needs.(package private) static voidmaybeEmbedVersionInfo(Version version, ByteMatrix matrix) Embed version info if version >= 7
Field Details
POSITION_DETECTION_PATTERN
private static final int[][] POSITION_DETECTION_PATTERNThe 7 by 7 position detection pattern.POSITION_ADJUSTMENT_PATTERN
private static final int[][] POSITION_ADJUSTMENT_PATTERNThe 5 by 5 position adjustment pattern.POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE
private static final int[][] POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLEThe adjustment pattern centers, by version, from JISX 0510, with the coordinates doubled.TYPE_INFO_COORDINATES
private static final int[][] TYPE_INFO_COORDINATESThe type info bit positions in the matrix, copied at the top left corner.VERSION_INFO_POLY
private static final int VERSION_INFO_POLYGenerator polynomial of the version bits, from JISX 0510.- See Also:
TYPE_INFO_POLY
private static final int TYPE_INFO_POLYGenerator polynomial of the type info bits, from JISX 0510.- See Also:
TYPE_INFO_MASK_PATTERN
private static final int TYPE_INFO_MASK_PATTERNMask XORed into the type info bits.- See Also:
Constructor Details
MatrixUtil
private MatrixUtil()Prevents instantiating the utility class.
Method Details
clearMatrix
Set all cells to empty (-1)- Parameters:
matrix- the matrix to reset, every cell overwritten with the empty value -1
buildMatrix
static void buildMatrix(BitArray dataBits, ErrorCorrectionLevel ecLevel, Version version, int maskPattern, ByteMatrix matrix) throws WriterException Build the QR code matrix- Parameters:
dataBits- the codeword bits to lay down into the data regionecLevel- the error correction level whose type information is embeddedversion- the symbol version, deciding whether the version information is embeddedmaskPattern- the data mask 0-7 to apply, or -1 to leave the data unmaskedmatrix- the matrix to populate, sized for the given version- Throws:
WriterException- if the mask pattern is out of range, or the data bits do not exactly fill the remaining data region
embedBasicPatterns
Embed position detection, timing, and adjustment patterns- Parameters:
version- the symbol version, deciding whether the adjustment patterns appearmatrix- the matrix to lay the function patterns into- Throws:
WriterException- if a corner cell is already occupied, so the detection or separation patterns do not fit
embedTypeInfo
static void embedTypeInfo(ErrorCorrectionLevel ecLevel, int maskPattern, ByteMatrix matrix) throws WriterException Embed type information- Parameters:
ecLevel- the error correction level encoded into the type informationmaskPattern- the data mask 0-7 in use, also encoded into the type informationmatrix- the matrix to write the two type information copies into- Throws:
WriterException- if the mask pattern is out of range, or the generated type information is not the expected 15 bits
maybeEmbedVersionInfo
Embed version info if version >= 7- Parameters:
version- the symbol version; nothing is written below version 7matrix- the matrix to write the two version information copies into- Throws:
WriterException- if the generated version information is not the expected 18 bits
embedDataBits
static void embedDataBits(BitArray dataBits, int maskPattern, ByteMatrix matrix) throws WriterException Embed data bits into matrix- Parameters:
dataBits- the codeword bits to place, in the order they are consumedmaskPattern- the data mask 0-7 to apply, or -1 to place the bits unmaskedmatrix- the matrix to fill, whose non-empty cells mark the already embedded function patterns and are skipped- Throws:
WriterException- if the bits are not all consumed once the data region is full, meaning they did not fit the symbol
findMSBSet
static int findMSBSet(int value) Find the bit length of a value- Parameters:
value- input value- Returns:
- the position one past the most significant bit set, so 32 for a negative value and 0 for zero
calculateBCHCode
static int calculateBCHCode(int value, int poly) Calculate BCH code- Parameters:
value- the data whose error correction code is wantedpoly- the BCH generator polynomial, whose bit length fixes the code, for example 0x537 for type information or 0x1f25 for version information- Returns:
- the remainder of dividing value by poly, the BCH error correction code
makeTypeInfoBits
static void makeTypeInfoBits(ErrorCorrectionLevel ecLevel, int maskPattern, BitArray bits) throws WriterException Make type information bit vector- Parameters:
ecLevel- the error correction level to encodemaskPattern- the data mask 0-7 to encode alongside the levelbits- the vector to append the 15 type information bits to- Throws:
WriterException- if the mask pattern is out of range, or the generated type information is not the expected 15 bits
makeVersionInfoBits
Make version information bit vector- Parameters:
version- the symbol version whose number is encodedbits- the vector to append the 18 version information bits to- Throws:
WriterException- if the generated version information is not the expected 18 bits
isEmpty
private static boolean isEmpty(int value) Checks whether a matrix cell is unset.- Parameters:
value- the cell value to check- Returns:
- true if the cell is still empty
embedTimingPatterns
Draws the timing patterns into the matrix.- Parameters:
matrix- the matrix to draw on
embedDarkDotAtLeftBottomCorner
Draws the always dark bottom left module.- Parameters:
matrix- the matrix to draw on- Throws:
WriterException- if the module is already set
embedHorizontalSeparationPattern
private static void embedHorizontalSeparationPattern(int xStart, int yStart, ByteMatrix matrix) throws WriterException Draws the horizontal separator beside a pattern.- Parameters:
xStart- the left column of the separatoryStart- the top row of the separatormatrix- the matrix to draw on- Throws:
WriterException- if a module is already set
embedVerticalSeparationPattern
private static void embedVerticalSeparationPattern(int xStart, int yStart, ByteMatrix matrix) throws WriterException Draws the vertical separator beside a pattern.- Parameters:
xStart- the left column of the separatoryStart- the top row of the separatormatrix- the matrix to draw on- Throws:
WriterException- if a module is already set
embedPositionAdjustmentPattern
Draws one position adjustment pattern.- Parameters:
xStart- the left column of the patternyStart- the top row of the patternmatrix- the matrix to draw on
embedPositionDetectionPattern
Draws one position detection pattern.- Parameters:
xStart- the left column of the patternyStart- the top row of the patternmatrix- the matrix to draw on
embedPositionDetectionPatternsAndSeparators
private static void embedPositionDetectionPatternsAndSeparators(ByteMatrix matrix) throws WriterException Draws the three position detection patterns with their separators.- Parameters:
matrix- the matrix to draw on- Throws:
WriterException- if a module is already set
maybeEmbedPositionAdjustmentPatterns
Draws the adjustment patterns the version needs.- Parameters:
version- the QR code versionmatrix- the matrix to draw on