public void testApplyMaskPenaltyRule1() { { ByteMatrix matrix = new ByteMatrix(4, 1); matrix.set(0, 0, 0); matrix.set(1, 0, 0); matrix.set(2, 0, 0); matrix.set(3, 0, 0); Assert.AreEqual(0, MaskUtil.applyMaskPenaltyRule1(matrix)); } { // Horizontal. ByteMatrix matrix = new ByteMatrix(6, 1); matrix.set(0, 0, 0); matrix.set(1, 0, 0); matrix.set(2, 0, 0); matrix.set(3, 0, 0); matrix.set(4, 0, 0); matrix.set(5, 0, 1); Assert.AreEqual(3, MaskUtil.applyMaskPenaltyRule1(matrix)); matrix.set(5, 0, 0); Assert.AreEqual(4, MaskUtil.applyMaskPenaltyRule1(matrix)); } { // Vertical. ByteMatrix matrix = new ByteMatrix(1, 6); matrix.set(0, 0, 0); matrix.set(0, 1, 0); matrix.set(0, 2, 0); matrix.set(0, 3, 0); matrix.set(0, 4, 0); matrix.set(0, 5, 1); Assert.AreEqual(3, MaskUtil.applyMaskPenaltyRule1(matrix)); matrix.set(0, 5, 0); Assert.AreEqual(4, MaskUtil.applyMaskPenaltyRule1(matrix)); } }
public void testApplyMaskPenaltyRule2() { var matrix = new ByteMatrix(1, 1); matrix.set(0, 0, 0); Assert.AreEqual(0, MaskUtil.applyMaskPenaltyRule2(matrix)); matrix = new ByteMatrix(2, 2); matrix.set(0, 0, 0); matrix.set(1, 0, 0); matrix.set(0, 1, 0); matrix.set(1, 1, 1); Assert.AreEqual(0, MaskUtil.applyMaskPenaltyRule2(matrix)); matrix = new ByteMatrix(2, 2); matrix.set(0, 0, 0); matrix.set(1, 0, 0); matrix.set(0, 1, 0); matrix.set(1, 1, 0); Assert.AreEqual(3, MaskUtil.applyMaskPenaltyRule2(matrix)); matrix = new ByteMatrix(3, 3); matrix.set(0, 0, 0); matrix.set(1, 0, 0); matrix.set(2, 0, 0); matrix.set(0, 1, 0); matrix.set(1, 1, 0); matrix.set(2, 1, 0); matrix.set(0, 2, 0); matrix.set(1, 2, 0); matrix.set(2, 2, 0); // Four instances of 2x2 blocks. Assert.AreEqual(3*4, MaskUtil.applyMaskPenaltyRule2(matrix)); }
// Embed version information if need be. On success, modify the matrix and return true. // See 8.10 of JISX0510:2004 (p.47) for how to embed version information. public static void maybeEmbedVersionInfo(int version, ByteMatrix matrix) { if (version < 7) // Version info is necessary if version >= 7. { return; // Don't need version info. } BitVector versionInfoBits = new BitVector(); makeVersionInfoBits(version, versionInfoBits); int bitIndex = 6 * 3 - 1; // It will decrease from 17 to 0. for (int i = 0; i < 6; ++i) { for (int j = 0; j < 3; ++j) { // Place bits in LSB (least significant bit) to MSB order. int bit = versionInfoBits.at(bitIndex); bitIndex--; // Left bottom corner. matrix.set(matrix.height() - 11 + j, i, bit); // Right bottom corner. matrix.set(i, matrix.height() - 11 + j, bit); } } }
private static void embedTimingPatterns(ByteMatrix matrix) { // -8 is for skipping position detection patterns (size 7), and two horizontal/vertical // separation patterns (size 1). Thus, 8 = 7 + 1. for (int i = 8; i < matrix.width() - 8; ++i) { int bit = (i + 1) % 2; // Horizontal line. if (!isValidValue(matrix.get(6, i))) { throw new WriterException(); } if (isEmpty(matrix.get(6, i))) { matrix.set(6, i, bit); } // Vertical line. if (!isValidValue(matrix.get(i, 6))) { throw new WriterException(); } if (isEmpty(matrix.get(i, 6))) { matrix.set(i, 6, bit); } } }
// Embed type information. On success, modify the matrix. //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: static void embedTypeInfo(com.google.zxing.qrcode.decoder.ErrorCorrectionLevel ecLevel, int maskPattern, ByteMatrix matrix) throws com.google.zxing.WriterException internal static void embedTypeInfo(ErrorCorrectionLevel ecLevel, int maskPattern, ByteMatrix matrix) { BitArray typeInfoBits = new BitArray(); makeTypeInfoBits(ecLevel, maskPattern, typeInfoBits); for (int i = 0; i < typeInfoBits.Size; ++i) { // Place bits in LSB to MSB order. LSB (least significant bit) is the last value in // "typeInfoBits". bool bit = typeInfoBits.get(typeInfoBits.Size - 1 - i); // Type info bits at the left top corner. See 8.9 of JISX0510:2004 (p.46). int x1 = TYPE_INFO_COORDINATES[i][0]; int y1 = TYPE_INFO_COORDINATES[i][1]; matrix.set(x1, y1, bit); if (i < 8) { // Right top corner. int x2 = matrix.Width - i - 1; int y2 = 8; matrix.set(x2, y2, bit); } else { // Left bottom corner. int x2 = 8; int y2 = matrix.Height - 7 + (i - 8); matrix.set(x2, y2, bit); } } }
public void testApplyMaskPenaltyRule2() { var matrix = new ByteMatrix(1, 1); matrix.set(0, 0, 0); Assert.AreEqual(0, MaskUtil.applyMaskPenaltyRule2(matrix)); matrix = new ByteMatrix(2, 2); matrix.set(0, 0, 0); matrix.set(1, 0, 0); matrix.set(0, 1, 0); matrix.set(1, 1, 1); Assert.AreEqual(0, MaskUtil.applyMaskPenaltyRule2(matrix)); matrix = new ByteMatrix(2, 2); matrix.set(0, 0, 0); matrix.set(1, 0, 0); matrix.set(0, 1, 0); matrix.set(1, 1, 0); Assert.AreEqual(3, MaskUtil.applyMaskPenaltyRule2(matrix)); matrix = new ByteMatrix(3, 3); matrix.set(0, 0, 0); matrix.set(1, 0, 0); matrix.set(2, 0, 0); matrix.set(0, 1, 0); matrix.set(1, 1, 0); matrix.set(2, 1, 0); matrix.set(0, 2, 0); matrix.set(1, 2, 0); matrix.set(2, 2, 0); // Four instances of 2x2 blocks. Assert.AreEqual(3 * 4, MaskUtil.applyMaskPenaltyRule2(matrix)); }
public void testApplyMaskPenaltyRule4() { { // Dark cell ratio = 0% ByteMatrix matrix = new ByteMatrix(1, 1); matrix.set(0, 0, 0); Assert.AreEqual(100, MaskUtil.applyMaskPenaltyRule4(matrix)); } { // Dark cell ratio = 5% ByteMatrix matrix = new ByteMatrix(2, 1); matrix.set(0, 0, 0); matrix.set(0, 0, 1); Assert.AreEqual(0, MaskUtil.applyMaskPenaltyRule4(matrix)); } { // Dark cell ratio = 66.67% ByteMatrix matrix = new ByteMatrix(6, 1); matrix.set(0, 0, 0); matrix.set(1, 0, 1); matrix.set(2, 0, 1); matrix.set(3, 0, 1); matrix.set(4, 0, 1); matrix.set(5, 0, 0); Assert.AreEqual(30, MaskUtil.applyMaskPenaltyRule4(matrix)); } }
// Embed type information. On success, modify the matrix. public static void embedTypeInfo(ErrorCorrectionLevel ecLevel, int maskPattern, ByteMatrix matrix) { BitVector typeInfoBits = new BitVector(); makeTypeInfoBits(ecLevel, maskPattern, typeInfoBits); for (int i = 0; i < typeInfoBits.size(); ++i) { // Place bits in LSB to MSB order. LSB (least significant bit) is the last value in // "typeInfoBits". int bit = typeInfoBits.at(typeInfoBits.size() - 1 - i); // Type info bits at the left top corner. See 8.9 of JISX0510:2004 (p.46). int x1 = TYPE_INFO_COORDINATES[i][0]; int y1 = TYPE_INFO_COORDINATES[i][1]; matrix.set(y1, x1, bit); if (i < 8) { // Right top corner. int x2 = matrix.width() - i - 1; int y2 = 8; matrix.set(y2, x2, bit); } else { // Left bottom corner. int x2 = 8; int y2 = matrix.height() - 7 + (i - 8); matrix.set(y2, x2, bit); } } }
/// <summary> /// Encode the given symbol info to a bit matrix. /// </summary> /// <param name="placement">The DataMatrix placement.</param> /// <param name="symbolInfo">The symbol info to encode.</param> /// <param name="width"></param> /// <param name="height"></param> /// <returns>The bit matrix generated.</returns> private static BitMatrix encodeLowLevel(DefaultPlacement placement, SymbolInfo symbolInfo, int width, int height) { int symbolWidth = symbolInfo.getSymbolDataWidth(); int symbolHeight = symbolInfo.getSymbolDataHeight(); var matrix = new ByteMatrix(symbolInfo.getSymbolWidth(), symbolInfo.getSymbolHeight()); int matrixY = 0; for (int y = 0; y < symbolHeight; y++) { // Fill the top edge with alternate 0 / 1 int matrixX; if ((y % symbolInfo.matrixHeight) == 0) { matrixX = 0; for (int x = 0; x < symbolInfo.getSymbolWidth(); x++) { matrix.set(matrixX, matrixY, (x % 2) == 0); matrixX++; } matrixY++; } matrixX = 0; for (int x = 0; x < symbolWidth; x++) { // Fill the right edge with full 1 if ((x % symbolInfo.matrixWidth) == 0) { matrix.set(matrixX, matrixY, true); matrixX++; } matrix.set(matrixX, matrixY, placement.getBit(x, y)); matrixX++; // Fill the right edge with alternate 0 / 1 if ((x % symbolInfo.matrixWidth) == symbolInfo.matrixWidth - 1) { matrix.set(matrixX, matrixY, (y % 2) == 0); matrixX++; } } matrixY++; // Fill the bottom edge with full 1 if ((y % symbolInfo.matrixHeight) == symbolInfo.matrixHeight - 1) { matrixX = 0; for (int x = 0; x < symbolInfo.getSymbolWidth(); x++) { matrix.set(matrixX, matrixY, true); matrixX++; } matrixY++; } } return(convertByteMatrixToBitMatrix(matrix, width, height)); }
public void test() { var qrCode = new QRCode(); // First, test simple setters and getters. // We use numbers of version 7-H. qrCode.Mode = Mode.BYTE; qrCode.ECLevel = ErrorCorrectionLevel.H; qrCode.Version = Version.getVersionForNumber(7); qrCode.MaskPattern = 3; Assert.AreEqual(Mode.BYTE, qrCode.Mode); Assert.AreEqual(ErrorCorrectionLevel.H, qrCode.ECLevel); Assert.AreEqual(7, qrCode.Version.VersionNumber); Assert.AreEqual(3, qrCode.MaskPattern); // Prepare the matrix. var matrix = new ByteMatrix(45, 45); // Just set bogus zero/one values. for (int y = 0; y < 45; ++y) { for (int x = 0; x < 45; ++x) { matrix.set(x, y, (y + x) % 2 == 1); } } // Set the matrix. qrCode.Matrix = matrix; Assert.AreEqual(matrix, qrCode.Matrix); }
// Embed the lonely dark dot at left bottom corner. JISX0510:2004 (p.46) private static void embedDarkDotAtLeftBottomCorner(ByteMatrix matrix) { if (matrix.get(matrix.height() - 8, 8) == 0) { throw new WriterException(); } matrix.set(matrix.height() - 8, 8, 1); }
// Embed "dataBits" using "getMaskPattern". On success, modify the matrix and return true. // 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. public static void embedDataBits(BitVector dataBits, int maskPattern, ByteMatrix matrix) { int bitIndex = 0; int direction = -1; // Start from the right bottom cell. int x = matrix.width() - 1; int y = matrix.height() - 1; while (x > 0) { // Skip the vertical timing pattern. if (x == 6) { x -= 1; } while (y >= 0 && y < matrix.height()) { for (int i = 0; i < 2; ++i) { int xx = x - i; // Skip the cell if it's not empty. if (!isEmpty(matrix.get(y, xx))) { continue; } int bit; if (bitIndex < dataBits.size()) { bit = dataBits.at(bitIndex); ++bitIndex; } else { // Padding bit. If there is no bit left, we'll fill the left cells with 0, as described // in 8.4.9 of JISX0510:2004 (p. 24). bit = 0; } // Skip masking if mask_pattern is -1. if (maskPattern != -1) { int mask = MaskUtil.getDataMaskBit(maskPattern, xx, y); bit ^= mask; } matrix.set(y, xx, bit); } y += direction; } direction = -direction; // Reverse the direction. y += direction; x -= 2; // Move to the left. } // All bits should be consumed. if (bitIndex != dataBits.size()) { throw new WriterException("Not all bits consumed: " + bitIndex + '/' + dataBits.size()); } }
private static void embedPositionDetectionPattern(int xStart, int yStart, ByteMatrix matrix) { for (int y = 0; y < 7; ++y) { for (int x = 0; x < 7; ++x) { matrix.set(xStart + x, yStart + y, POSITION_DETECTION_PATTERN[y][x]); } } }
// Note that we cannot unify the function with embedPositionDetectionPattern() despite they are // almost identical, since we cannot write a function that takes 2D arrays in different sizes in // C/C++. We should live with the fact. private static void embedPositionAdjustmentPattern(int xStart, int yStart, ByteMatrix matrix) { for (int y = 0; y < 5; ++y) { for (int x = 0; x < 5; ++x) { matrix.set(xStart + x, yStart + y, POSITION_ADJUSTMENT_PATTERN[y][x]); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static void embedVerticalSeparationPattern(int xStart, int yStart, ByteMatrix matrix) throws com.google.zxing.WriterException private static void embedVerticalSeparationPattern(int xStart, int yStart, ByteMatrix matrix) { for (int y = 0; y < 7; ++y) { if (!isEmpty(matrix.get(xStart, yStart + y))) { throw new WriterException(); } matrix.set(xStart, yStart + y, 0); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static void embedHorizontalSeparationPattern(int xStart, int yStart, ByteMatrix matrix) throws com.google.zxing.WriterException private static void embedHorizontalSeparationPattern(int xStart, int yStart, ByteMatrix matrix) { for (int x = 0; x < 8; ++x) { if (!isEmpty(matrix.get(xStart + x, yStart))) { throw new WriterException(); } matrix.set(xStart + x, yStart, 0); } }
public void testToString() { ByteMatrix array = new ByteMatrix(3, 3); array.set(0, 0, 0); array.set(1, 0, 1); array.set(2, 0, 0); array.set(0, 1, 1); array.set(1, 1, 0); array.set(2, 1, 1); array.set(0, 2, -1); array.set(1, 2, -1); array.set(2, 2, -1); String expected = " 0 1 0\n" + " 1 0 1\n" + " \n"; Assert.AreEqual(expected, array.ToString()); }
public void testToString2() { var qrCode = new QRCode { Mode = Mode.BYTE, ECLevel = ErrorCorrectionLevel.H, Version = Version.getVersionForNumber(1), MaskPattern = 3, }; var matrix = new ByteMatrix(21, 21); for (int y = 0; y < 21; ++y) { for (int x = 0; x < 21; ++x) { matrix.set(x, y, (y + x) % 2 == 1); } } qrCode.Matrix = matrix; const string expected = "<<\n" + " mode: BYTE\n" + " ecLevel: H\n" + " version: 1\n" + " maskPattern: 3\n" + " matrix:\n" + " 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" + " 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n" + " 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" + " 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n" + " 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" + " 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n" + " 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" + " 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n" + " 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" + " 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n" + " 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" + " 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n" + " 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" + " 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n" + " 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" + " 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n" + " 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" + " 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n" + " 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" + " 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n" + " 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" + ">>\n"; Assert.AreEqual(expected, qrCode.ToString()); }
private static void embedHorizontalSeparationPattern(int xStart, int yStart, ByteMatrix matrix) { // We know the width and height. if (HORIZONTAL_SEPARATION_PATTERN[0].Length != 8 || HORIZONTAL_SEPARATION_PATTERN.Length != 1) { throw new WriterException("Bad horizontal separation pattern"); } for (int x = 0; x < 8; ++x) { if (!isEmpty(matrix.get(yStart, xStart + x))) { throw new WriterException(); } matrix.set(yStart, xStart + x, HORIZONTAL_SEPARATION_PATTERN[0][x]); } }
private static void embedVerticalSeparationPattern(int xStart, int yStart, ByteMatrix matrix) { // We know the width and height. if (VERTICAL_SEPARATION_PATTERN[0].Length != 1 || VERTICAL_SEPARATION_PATTERN.Length != 7) { throw new WriterException("Bad vertical separation pattern"); } for (int y = 0; y < 7; ++y) { if (!isEmpty(matrix.get(yStart + y, xStart))) { throw new WriterException(); } matrix.set(yStart + y, xStart, VERTICAL_SEPARATION_PATTERN[y][0]); } }
private static void embedPositionDetectionPattern(int xStart, int yStart, ByteMatrix matrix) { // We know the width and height. if (POSITION_DETECTION_PATTERN[0].Length != 7 || POSITION_DETECTION_PATTERN.Length != 7) { throw new WriterException("Bad position detection pattern"); } for (int y = 0; y < 7; ++y) { for (int x = 0; x < 7; ++x) { if (!isEmpty(matrix.get(yStart + y, xStart + x))) { throw new WriterException(); } matrix.set(yStart + y, xStart + x, POSITION_DETECTION_PATTERN[y][x]); } } }
// Note that we cannot unify the function with embedPositionDetectionPattern() despite they are // almost identical, since we cannot write a function that takes 2D arrays in different sizes in // C/C++. We should live with the fact. private static void embedPositionAdjustmentPattern(int xStart, int yStart, ByteMatrix matrix) { // We know the width and height. if (POSITION_ADJUSTMENT_PATTERN[0].Length != 5 || POSITION_ADJUSTMENT_PATTERN.Length != 5) { throw new WriterException("Bad position adjustment"); } for (int y = 0; y < 5; ++y) { for (int x = 0; x < 5; ++x) { if (!isEmpty(matrix.get(yStart + y, xStart + x))) { throw new WriterException(); } matrix.set(yStart + y, xStart + x, POSITION_ADJUSTMENT_PATTERN[y][x]); } } }
public void testApplyMaskPenaltyRule3() { { // Horizontal 00001011101. ByteMatrix matrix = new ByteMatrix(11, 1); matrix.set(0, 0, 0); matrix.set(1, 0, 0); matrix.set(2, 0, 0); matrix.set(3, 0, 0); matrix.set(4, 0, 1); matrix.set(5, 0, 0); matrix.set(6, 0, 1); matrix.set(7, 0, 1); matrix.set(8, 0, 1); matrix.set(9, 0, 0); matrix.set(10, 0, 1); Assert.AreEqual(40, MaskUtil.applyMaskPenaltyRule3(matrix)); } { // Horizontal 10111010000. ByteMatrix matrix = new ByteMatrix(11, 1); matrix.set(0, 0, 1); matrix.set(1, 0, 0); matrix.set(2, 0, 1); matrix.set(3, 0, 1); matrix.set(4, 0, 1); matrix.set(5, 0, 0); matrix.set(6, 0, 1); matrix.set(7, 0, 0); matrix.set(8, 0, 0); matrix.set(9, 0, 0); matrix.set(10, 0, 0); Assert.AreEqual(40, MaskUtil.applyMaskPenaltyRule3(matrix)); } { // Vertical 00001011101. ByteMatrix matrix = new ByteMatrix(1, 11); matrix.set(0, 0, 0); matrix.set(0, 1, 0); matrix.set(0, 2, 0); matrix.set(0, 3, 0); matrix.set(0, 4, 1); matrix.set(0, 5, 0); matrix.set(0, 6, 1); matrix.set(0, 7, 1); matrix.set(0, 8, 1); matrix.set(0, 9, 0); matrix.set(0, 10, 1); Assert.AreEqual(40, MaskUtil.applyMaskPenaltyRule3(matrix)); } { // Vertical 10111010000. ByteMatrix matrix = new ByteMatrix(1, 11); matrix.set(0, 0, 1); matrix.set(0, 1, 0); matrix.set(0, 2, 1); matrix.set(0, 3, 1); matrix.set(0, 4, 1); matrix.set(0, 5, 0); matrix.set(0, 6, 1); matrix.set(0, 7, 0); matrix.set(0, 8, 0); matrix.set(0, 9, 0); matrix.set(0, 10, 0); Assert.AreEqual(40, MaskUtil.applyMaskPenaltyRule3(matrix)); } }
// Embed version information if need be. On success, modify the matrix and return true. // See 8.10 of JISX0510:2004 (p.47) for how to embed version information. //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: static void maybeEmbedVersionInfo(com.google.zxing.qrcode.decoder.Version version, ByteMatrix matrix) throws com.google.zxing.WriterException internal static void maybeEmbedVersionInfo(Version version, ByteMatrix matrix) { if (version.VersionNumber < 7) // Version info is necessary if version >= 7. { return; // Don't need version info. } BitArray versionInfoBits = new BitArray(); makeVersionInfoBits(version, versionInfoBits); int bitIndex = 6 * 3 - 1; // It will decrease from 17 to 0. for (int i = 0; i < 6; ++i) { for (int j = 0; j < 3; ++j) { // Place bits in LSB (least significant bit) to MSB order. bool bit = versionInfoBits.get(bitIndex); bitIndex--; // Left bottom corner. matrix.set(i, matrix.Height - 11 + j, bit); // Right bottom corner. matrix.set(matrix.Height - 11 + j, i, bit); } } }
// Embed the lonely dark dot at left bottom corner. JISX0510:2004 (p.46) //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static void embedDarkDotAtLeftBottomCorner(ByteMatrix matrix) throws com.google.zxing.WriterException private static void embedDarkDotAtLeftBottomCorner(ByteMatrix matrix) { if (matrix.get(8, matrix.Height - 8) == 0) { throw new WriterException(); } matrix.set(8, matrix.Height - 8, 1); }
private static void embedTimingPatterns(ByteMatrix matrix) { // -8 is for skipping position detection patterns (size 7), and two horizontal/vertical // separation patterns (size 1). Thus, 8 = 7 + 1. for (int i = 8; i < matrix.Width - 8; ++i) { int bit = (i + 1) % 2; // Horizontal line. if (isEmpty(matrix.get(i, 6))) { matrix.set(i, 6, bit); } // Vertical line. if (isEmpty(matrix.get(6, i))) { matrix.set(6, i, bit); } } }
// Embed "dataBits" using "getMaskPattern". On success, modify the matrix and return true. // 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. //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: static void embedDataBits(com.google.zxing.common.BitArray dataBits, int maskPattern, ByteMatrix matrix) throws com.google.zxing.WriterException internal static void embedDataBits(BitArray dataBits, int maskPattern, ByteMatrix matrix) { int bitIndex = 0; int direction = -1; // Start from the right bottom cell. int x = matrix.Width - 1; int y = matrix.Height - 1; while (x > 0) { // Skip the vertical timing pattern. if (x == 6) { x -= 1; } while (y >= 0 && y < matrix.Height) { for (int i = 0; i < 2; ++i) { int xx = x - i; // Skip the cell if it's not empty. if (!isEmpty(matrix.get(xx, y))) { continue; } bool bit; if (bitIndex < dataBits.Size) { bit = dataBits.get(bitIndex); ++bitIndex; } else { // Padding bit. If there is no bit left, we'll fill the left cells with 0, as described // in 8.4.9 of JISX0510:2004 (p. 24). bit = false; } // Skip masking if mask_pattern is -1. if (maskPattern != -1 && MaskUtil.getDataMaskBit(maskPattern, xx, y)) { bit = !bit; } matrix.set(xx, y, bit); } y += direction; } direction = -direction; // Reverse the direction. y += direction; x -= 2; // Move to the left. } // All bits should be consumed. if (bitIndex != dataBits.Size) { throw new WriterException("Not all bits consumed: " + bitIndex + '/' + dataBits.Size); } }