java.lang.Object
com.google.zxing.qrcode.encoder.MaskUtil
Utility class for QR code mask operations.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intPenalty weight for runs of five like modules, spec section 6.8.2.1.private static final intPenalty weight for 2x2 blocks of like modules.private static final intPenalty weight for finder-like patterns.private static final intPenalty weight for dark-light imbalance.Constructor Summary
ConstructorsMethod Summary
Private MethodsModifier and TypeMethodDescription(package private) static intapplyMaskPenaltyRule1(ByteMatrix matrix) Apply mask penalty rule 1 and return the penalty.private static intapplyMaskPenaltyRule1Internal(ByteMatrix matrix, boolean isHorizontal) Helper function for applyMaskPenaltyRule1.(package private) static intapplyMaskPenaltyRule2(ByteMatrix matrix) Apply mask penalty rule 2 and return the penalty.(package private) static intapplyMaskPenaltyRule3(ByteMatrix matrix) Apply mask penalty rule 3 and return the penalty.(package private) static intapplyMaskPenaltyRule4(ByteMatrix matrix) Apply mask penalty rule 4 and return the penalty.(package private) static booleangetDataMaskBit(int maskPattern, int x, int y) Return the mask bit for "getMaskPattern" at "x" and "y".private static booleanisWhiteHorizontal(byte[] rowArray, int from, int to) Checks whether a stretch of one row is all white.private static booleanisWhiteVertical(byte[][] array, int col, int from, int to) Checks whether a stretch of one column is all white.
Field Details
N1
private static final int N1Penalty weight for runs of five like modules, spec section 6.8.2.1.- See Also:
N2
private static final int N2Penalty weight for 2x2 blocks of like modules.- See Also:
N3
N4
Constructor Details
MaskUtil
private MaskUtil()Utility class, not intended for instantiation.
Method Details
applyMaskPenaltyRule1
Apply mask penalty rule 1 and return the penalty. Find repetitive cells with the same color and give penalty to them. Example: 00000 or 11111.- Parameters:
matrix- the byte matrix- Returns:
- N1 (3) points for each run of five or more same-colored cells
applyMaskPenaltyRule2
Apply mask penalty rule 2 and return the penalty. Find 2x2 blocks with the same color and give penalty to them. This is actually equivalent to the spec's rule, which is to find MxN blocks and give a penalty proportional to (M-1)x(N-1), because this is the number of 2x2 blocks inside such a block.- Parameters:
matrix- the byte matrix- Returns:
- N2 (3) points for each solid 2x2 block of one color
applyMaskPenaltyRule3
Apply mask penalty rule 3 and return the penalty. Find consecutive runs of 1:1:3:1:1:4 starting with black, or 4:1:1:3:1:1 starting with white, and give penalty to them. If we find patterns like 000010111010000, we give penalty once.- Parameters:
matrix- the byte matrix- Returns:
- N3 (40) points for each 1:1:3:1:1 or 4:1:1:3:1:1 pattern
isWhiteHorizontal
private static boolean isWhiteHorizontal(byte[] rowArray, int from, int to) Checks whether a stretch of one row is all white.- Parameters:
rowArray- the row's modulesfrom- the first column to checkto- the last column to check- Returns:
- true if every module in the stretch is white
isWhiteVertical
private static boolean isWhiteVertical(byte[][] array, int col, int from, int to) Checks whether a stretch of one column is all white.- Parameters:
array- the symbol's rowscol- the column to checkfrom- the first row to checkto- the last row to check- Returns:
- true if every module in the stretch is white
applyMaskPenaltyRule4
Apply mask penalty rule 4 and return the penalty. Calculate the ratio of dark cells and give penalty if the ratio is far from 50%. It gives 10 penalty for 5% distance.- Parameters:
matrix- the byte matrix- Returns:
- N4 (10) points per 5% the dark-module ratio deviates from 50%
getDataMaskBit
static boolean getDataMaskBit(int maskPattern, int x, int y) Return the mask bit for "getMaskPattern" at "x" and "y". See 8.8 of JISX0510:2004 for mask pattern conditions.- Parameters:
maskPattern- the mask patternx- the x coordinatey- the y coordinate- Returns:
- the mask bit
applyMaskPenaltyRule1Internal
Helper function for applyMaskPenaltyRule1. We need this for doing this calculation in both vertical and horizontal orders respectively.- Parameters:
matrix- the QR code matrix to scanisHorizontal- true to scan row by row, false to scan column by column- Returns:
- the penalty for runs of five or more identical cells in any row or column of the matrix