Package com.itextpdf.barcodes.qrcode
Class MatrixUtil
- java.lang.Object
-
- com.itextpdf.barcodes.qrcode.MatrixUtil
-
final class MatrixUtil extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description private static int[][]
HORIZONTAL_SEPARATION_PATTERN
private static int[][]
POSITION_ADJUSTMENT_PATTERN
private static int[][]
POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE
private static int[][]
POSITION_DETECTION_PATTERN
private static int[][]
TYPE_INFO_COORDINATES
private static int
TYPE_INFO_MASK_PATTERN
private static int
TYPE_INFO_POLY
private static int
VERSION_INFO_POLY
private static int[][]
VERTICAL_SEPARATION_PATTERN
-
Constructor Summary
Constructors Modifier Constructor Description private
MatrixUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
buildMatrix(BitVector dataBits, ErrorCorrectionLevel ecLevel, int version, int maskPattern, ByteMatrix matrix)
Build 2D matrix of QR Code from "dataBits" with "ecLevel", "version" and "getMaskPattern".static int
calculateBCHCode(int value, int poly)
Calculate BCH (Bose-Chaudhuri-Hocquenghem) code for "value" using polynomial "poly".static void
clearMatrix(ByteMatrix matrix)
static void
embedBasicPatterns(int version, ByteMatrix matrix)
Embed basic patterns.private static void
embedDarkDotAtLeftBottomCorner(ByteMatrix matrix)
static void
embedDataBits(BitVector dataBits, int maskPattern, ByteMatrix matrix)
Embed "dataBits" using "getMaskPattern".private static void
embedHorizontalSeparationPattern(int xStart, int yStart, ByteMatrix matrix)
private static void
embedPositionAdjustmentPattern(int xStart, int yStart, ByteMatrix matrix)
private static void
embedPositionDetectionPattern(int xStart, int yStart, ByteMatrix matrix)
private static void
embedPositionDetectionPatternsAndSeparators(ByteMatrix matrix)
private static void
embedTimingPatterns(ByteMatrix matrix)
static void
embedTypeInfo(ErrorCorrectionLevel ecLevel, int maskPattern, ByteMatrix matrix)
Embed type information into the matrixprivate static void
embedVerticalSeparationPattern(int xStart, int yStart, ByteMatrix matrix)
static int
findMSBSet(int value)
Return the position of the most significant bit set (to one) in the "value".private static boolean
isEmpty(byte value)
private static boolean
isValidValue(byte value)
static void
makeTypeInfoBits(ErrorCorrectionLevel ecLevel, int maskPattern, BitVector bits)
Make bit vector of type information.static void
makeVersionInfoBits(int version, BitVector bits)
Make bit vector of version information.private static void
maybeEmbedPositionAdjustmentPatterns(int version, ByteMatrix matrix)
static void
maybeEmbedVersionInfo(int version, ByteMatrix matrix)
Embed version information if need be.
-
-
-
Field Detail
-
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:
- Constant Field Values
-
TYPE_INFO_POLY
private static final int TYPE_INFO_POLY
- See Also:
- Constant Field Values
-
TYPE_INFO_MASK_PATTERN
private static final int TYPE_INFO_MASK_PATTERN
- See Also:
- Constant Field Values
-
-
Method Detail
-
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 databitsecLevel
- Error correction level of the QR code (L,M,Q,H)version
- Version of the QR code, [1 .. 40]maskPattern
- masking patternmatrix
- 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 patternmatrix
- 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 versionmatrix
- 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 codemaskPattern
- masking pattern to apply to the data bitsmatrix
- 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^2The 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 frompoly
- 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 codemaskPattern
- masking pattern to usebits
- 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-codebits
- 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
-
-