Java Code Examples for com.google.zxing.common.BitMatrix#setRegion()

The following examples show how to use com.google.zxing.common.BitMatrix#setRegion() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OneDimensionalCodeWriter.java    From ScreenCapture with MIT License 6 votes vote down vote up
/**
 * @return a byte array of horizontal pixels (0 = white, 1 = black)
 */
private static BitMatrix renderResult(boolean[] code, int width, int height, int sidesMargin) {
  int inputWidth = code.length;
  // Add quiet zone on both sides.
  int fullWidth = inputWidth + sidesMargin;
  int outputWidth = Math.max(width, fullWidth);
  int outputHeight = Math.max(1, height);

  int multiple = outputWidth / fullWidth;
  int leftPadding = (outputWidth - (inputWidth * multiple)) / 2;

  BitMatrix output = new BitMatrix(outputWidth, outputHeight);
  for (int inputX = 0, outputX = leftPadding; inputX < inputWidth; inputX++, outputX += multiple) {
    if (code[inputX]) {
      output.setRegion(outputX, 0, multiple, outputHeight);
    }
  }
  return output;
}
 
Example 2
Source File: OneDimensionalCodeWriter.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
/**
 * @return a byte array of horizontal pixels (0 = white, 1 = black)
 */
private static BitMatrix renderResult(boolean[] code, int width, int height, int sidesMargin) {
	int inputWidth = code.length;
	// Add quiet zone on both sides.
	int fullWidth = inputWidth + sidesMargin;
	int outputWidth = Math.max(width, fullWidth);
	int outputHeight = Math.max(1, height);

	int multiple = outputWidth / fullWidth;
	int leftPadding = (outputWidth - (inputWidth * multiple)) / 2;

	BitMatrix output = new BitMatrix(outputWidth, outputHeight);
	for (int inputX = 0, outputX = leftPadding; inputX < inputWidth; inputX++, outputX += multiple) {
		if (code[inputX]) {
			output.setRegion(outputX, 0, multiple, outputHeight);
		}
	}
	return output;
}
 
Example 3
Source File: OneDimensionalCodeWriter.java    From ZXing-Orient with Apache License 2.0 6 votes vote down vote up
/**
 * @return a byte array of horizontal pixels (0 = white, 1 = black)
 */
private static BitMatrix renderResult(boolean[] code, int width, int height, int sidesMargin) {
  int inputWidth = code.length;
  // Add quiet zone on both sides.
  int fullWidth = inputWidth + sidesMargin;
  int outputWidth = Math.max(width, fullWidth);
  int outputHeight = Math.max(1, height);

  int multiple = outputWidth / fullWidth;
  int leftPadding = (outputWidth - (inputWidth * multiple)) / 2;

  BitMatrix output = new BitMatrix(outputWidth, outputHeight);
  for (int inputX = 0, outputX = leftPadding; inputX < inputWidth; inputX++, outputX += multiple) {
    if (code[inputX]) {
      output.setRegion(outputX, 0, multiple, outputHeight);
    }
  }
  return output;
}
 
Example 4
Source File: OneDimensionalCodeWriter.java    From Tesseract-OCR-Scanner with Apache License 2.0 6 votes vote down vote up
/**
 * @return a byte array of horizontal pixels (0 = white, 1 = black)
 */
private static BitMatrix renderResult(boolean[] code, int width, int height, int sidesMargin) {
  int inputWidth = code.length;
  // Add quiet zone on both sides.
  int fullWidth = inputWidth + sidesMargin;
  int outputWidth = Math.max(width, fullWidth);
  int outputHeight = Math.max(1, height);

  int multiple = outputWidth / fullWidth;
  int leftPadding = (outputWidth - (inputWidth * multiple)) / 2;

  BitMatrix output = new BitMatrix(outputWidth, outputHeight);
  for (int inputX = 0, outputX = leftPadding; inputX < inputWidth; inputX++, outputX += multiple) {
    if (code[inputX]) {
      output.setRegion(outputX, 0, multiple, outputHeight);
    }
  }
  return output;
}
 
Example 5
Source File: AztecWriter.java    From weex with Apache License 2.0 6 votes vote down vote up
private static BitMatrix renderResult(AztecCode code, int width, int height) {
  BitMatrix input = code.getMatrix();
  if (input == null) {
    throw new IllegalStateException();
  }
  int inputWidth = input.getWidth();
  int inputHeight = input.getHeight();
  int outputWidth = Math.max(width, inputWidth);
  int outputHeight = Math.max(height, inputHeight);

  int multiple = Math.min(outputWidth / inputWidth, outputHeight / inputHeight);
  int leftPadding = (outputWidth - (inputWidth * multiple)) / 2;
  int topPadding = (outputHeight - (inputHeight * multiple)) / 2;

  BitMatrix output = new BitMatrix(outputWidth, outputHeight);

  for (int inputY = 0, outputY = topPadding; inputY < inputHeight; inputY++, outputY += multiple) {
    // Write the contents of this row of the barcode
    for (int inputX = 0, outputX = leftPadding; inputX < inputWidth; inputX++, outputX += multiple) {
      if (input.get(inputX, inputY)) {
        output.setRegion(outputX, outputY, multiple, multiple);
      }
    }
  }
  return output;
}
 
Example 6
Source File: OneDimensionalCodeWriter.java    From QrCodeScanner with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @return a byte array of horizontal pixels (0 = white, 1 = black)
 */
private static BitMatrix renderResult(boolean[] code, int width, int height, int sidesMargin) {
  int inputWidth = code.length;
  // Add quiet zone on both sides.
  int fullWidth = inputWidth + sidesMargin;
  int outputWidth = Math.max(width, fullWidth);
  int outputHeight = Math.max(1, height);

  int multiple = outputWidth / fullWidth;
  int leftPadding = (outputWidth - (inputWidth * multiple)) / 2;

  BitMatrix output = new BitMatrix(outputWidth, outputHeight);
  for (int inputX = 0, outputX = leftPadding; inputX < inputWidth; inputX++, outputX += multiple) {
    if (code[inputX]) {
      output.setRegion(outputX, 0, multiple, outputHeight);
    }
  }
  return output;
}
 
Example 7
Source File: Version.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * See ISO 18004:2006 Annex E
 */
BitMatrix buildFunctionPattern() {
  int dimension = getDimensionForVersion();
  BitMatrix bitMatrix = new BitMatrix(dimension);

  // Top left finder pattern + separator + format
  bitMatrix.setRegion(0, 0, 9, 9);
  // Top right finder pattern + separator + format
  bitMatrix.setRegion(dimension - 8, 0, 8, 9);
  // Bottom left finder pattern + separator + format
  bitMatrix.setRegion(0, dimension - 8, 9, 8);

  // Alignment patterns
  int max = alignmentPatternCenters.length;
  for (int x = 0; x < max; x++) {
    int i = alignmentPatternCenters[x] - 2;
    for (int y = 0; y < max; y++) {
      if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)) {
        // No alignment patterns near the three finder paterns
        continue;
      }
      bitMatrix.setRegion(alignmentPatternCenters[y] - 2, i, 5, 5);
    }
  }

  // Vertical timing pattern
  bitMatrix.setRegion(6, 9, 1, dimension - 17);
  // Horizontal timing pattern
  bitMatrix.setRegion(9, 6, dimension - 17, 1);

  if (versionNumber > 6) {
    // Version info, top right
    bitMatrix.setRegion(dimension - 11, 0, 3, 6);
    // Version info, bottom left
    bitMatrix.setRegion(0, dimension - 11, 6, 3);
  }

  return bitMatrix;
}
 
Example 8
Source File: Version.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
BitMatrix a()
{
    int i = getDimensionForVersion();
    BitMatrix bitmatrix = new BitMatrix(i);
    bitmatrix.setRegion(0, 0, 9, 9);
    bitmatrix.setRegion(i - 8, 0, 8, 9);
    bitmatrix.setRegion(0, i - 8, 9, 8);
    int j = d.length;
    for (int k = 0; k < j; k++)
    {
        int l = -2 + d[k];
        int i1 = 0;
        while (i1 < j) 
        {
            if ((k != 0 || i1 != 0 && i1 != j - 1) && (k != j - 1 || i1 != 0))
            {
                bitmatrix.setRegion(-2 + d[i1], l, 5, 5);
            }
            i1++;
        }
    }

    bitmatrix.setRegion(6, 9, 1, i - 17);
    bitmatrix.setRegion(9, 6, i - 17, 1);
    if (c > 6)
    {
        bitmatrix.setRegion(i - 11, 0, 3, 6);
        bitmatrix.setRegion(0, i - 11, 6, 3);
    }
    return bitmatrix;
}
 
Example 9
Source File: Version.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
/**
 * See ISO 18004:2006 Annex E
 */
BitMatrix buildFunctionPattern() {
  int dimension = getDimensionForVersion();
  BitMatrix bitMatrix = new BitMatrix(dimension);

  // Top left finder pattern + separator + format
  bitMatrix.setRegion(0, 0, 9, 9);
  // Top right finder pattern + separator + format
  bitMatrix.setRegion(dimension - 8, 0, 8, 9);
  // Bottom left finder pattern + separator + format
  bitMatrix.setRegion(0, dimension - 8, 9, 8);

  // Alignment patterns
  int max = alignmentPatternCenters.length;
  for (int x = 0; x < max; x++) {
    int i = alignmentPatternCenters[x] - 2;
    for (int y = 0; y < max; y++) {
      if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)) {
        // No alignment patterns near the three finder paterns
        continue;
      }
      bitMatrix.setRegion(alignmentPatternCenters[y] - 2, i, 5, 5);
    }
  }

  // Vertical timing pattern
  bitMatrix.setRegion(6, 9, 1, dimension - 17);
  // Horizontal timing pattern
  bitMatrix.setRegion(9, 6, dimension - 17, 1);

  if (versionNumber > 6) {
    // Version info, top right
    bitMatrix.setRegion(dimension - 11, 0, 3, 6);
    // Version info, bottom left
    bitMatrix.setRegion(0, dimension - 11, 6, 3);
  }

  return bitMatrix;
}
 
Example 10
Source File: QRCodeWriter.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
private static BitMatrix renderResult(QRCode code, int width, int height, int quietZone) {
  ByteMatrix input = code.getMatrix();
  if (input == null) {
    throw new IllegalStateException();
  }
  int inputWidth = input.getWidth();
  int inputHeight = input.getHeight();
  int qrWidth = inputWidth + (quietZone * 2);
  int qrHeight = inputHeight + (quietZone * 2);
  int outputWidth = Math.max(width, qrWidth);
  int outputHeight = Math.max(height, qrHeight);

  int multiple = Math.min(outputWidth / qrWidth, outputHeight / qrHeight);
  // Padding includes both the quiet zone and the extra white pixels to accommodate the requested
  // dimensions. For example, if input is 25x25 the QR will be 33x33 including the quiet zone.
  // If the requested size is 200x160, the multiple will be 4, for a QR of 132x132. These will
  // handle all the padding from 100x100 (the actual QR) up to 200x160.
  int leftPadding = (outputWidth - (inputWidth * multiple)) / 2;
  int topPadding = (outputHeight - (inputHeight * multiple)) / 2;

  BitMatrix output = new BitMatrix(outputWidth, outputHeight);

  for (int inputY = 0, outputY = topPadding; inputY < inputHeight; inputY++, outputY += multiple) {
    // Write the contents of this row of the barcode
    for (int inputX = 0, outputX = leftPadding; inputX < inputWidth; inputX++, outputX += multiple) {
      if (input.get(inputX, inputY) == 1) {
        output.setRegion(outputX, outputY, multiple, multiple);
      }
    }
  }

  return output;
}
 
Example 11
Source File: QRCodeWriter.java    From android-quick-response-code with Apache License 2.0 5 votes vote down vote up
private static BitMatrix renderResult(QRCode code, int width, int height) {
    ByteMatrix input = code.getMatrix();
    if (input == null) {
        throw new IllegalStateException();
    }
    int inputWidth = input.getWidth();
    int inputHeight = input.getHeight();
    int qrWidth = inputWidth + (QUIET_ZONE_SIZE << 1);
    int qrHeight = inputHeight + (QUIET_ZONE_SIZE << 1);
    int outputWidth = Math.max(width, qrWidth);
    int outputHeight = Math.max(height, qrHeight);

    int multiple = Math.min(outputWidth / qrWidth, outputHeight / qrHeight);
    // Padding includes both the quiet zone and the extra white pixels to
    // accommodate the
    // requested
    // dimensions. For example, if input is 25x25 the QR will be 33x33
    // including the quiet zone.
    // If the requested size is 200x160, the multiple will be 4, for a QR of
    // 132x132. These will
    // handle all the padding from 100x100 (the actual QR) up to 200x160.
    int leftPadding = (outputWidth - (inputWidth * multiple)) / 2;
    int topPadding = (outputHeight - (inputHeight * multiple)) / 2;

    BitMatrix output = new BitMatrix(outputWidth, outputHeight);

    for (int inputY = 0, outputY = topPadding; inputY < inputHeight; inputY++, outputY += multiple) {
        // Write the contents of this row of the barcode
        for (int inputX = 0, outputX = leftPadding; inputX < inputWidth; inputX++, outputX += multiple) {
            if (input.get(inputX, inputY) == 1) {
                output.setRegion(outputX, outputY, multiple, multiple);
            }
        }
    }

    return output;
}
 
Example 12
Source File: Version.java    From ZXing-Orient with Apache License 2.0 5 votes vote down vote up
/**
 * See ISO 18004:2006 Annex E
 */
BitMatrix buildFunctionPattern() {
  int dimension = getDimensionForVersion();
  BitMatrix bitMatrix = new BitMatrix(dimension);

  // Top left finder pattern + separator + format
  bitMatrix.setRegion(0, 0, 9, 9);
  // Top right finder pattern + separator + format
  bitMatrix.setRegion(dimension - 8, 0, 8, 9);
  // Bottom left finder pattern + separator + format
  bitMatrix.setRegion(0, dimension - 8, 9, 8);

  // Alignment patterns
  int max = alignmentPatternCenters.length;
  for (int x = 0; x < max; x++) {
    int i = alignmentPatternCenters[x] - 2;
    for (int y = 0; y < max; y++) {
      if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)) {
        // No alignment patterns near the three finder paterns
        continue;
      }
      bitMatrix.setRegion(alignmentPatternCenters[y] - 2, i, 5, 5);
    }
  }

  // Vertical timing pattern
  bitMatrix.setRegion(6, 9, 1, dimension - 17);
  // Horizontal timing pattern
  bitMatrix.setRegion(9, 6, dimension - 17, 1);

  if (versionNumber > 6) {
    // Version info, top right
    bitMatrix.setRegion(dimension - 11, 0, 3, 6);
    // Version info, bottom left
    bitMatrix.setRegion(0, dimension - 11, 6, 3);
  }

  return bitMatrix;
}
 
Example 13
Source File: QRCodeWriter.java    From barcodescanner-lib-aar with MIT License 5 votes vote down vote up
private static BitMatrix renderResult(QRCode code, int width, int height, int quietZone) {
  ByteMatrix input = code.getMatrix();
  if (input == null) {
    throw new IllegalStateException();
  }
  int inputWidth = input.getWidth();
  int inputHeight = input.getHeight();
  int qrWidth = inputWidth + (quietZone * 2);
  int qrHeight = inputHeight + (quietZone * 2);
  int outputWidth = Math.max(width, qrWidth);
  int outputHeight = Math.max(height, qrHeight);

  int multiple = Math.min(outputWidth / qrWidth, outputHeight / qrHeight);
  // Padding includes both the quiet zone and the extra white pixels to accommodate the requested
  // dimensions. For example, if input is 25x25 the QR will be 33x33 including the quiet zone.
  // If the requested size is 200x160, the multiple will be 4, for a QR of 132x132. These will
  // handle all the padding from 100x100 (the actual QR) up to 200x160.
  int leftPadding = (outputWidth - (inputWidth * multiple)) / 2;
  int topPadding = (outputHeight - (inputHeight * multiple)) / 2;

  BitMatrix output = new BitMatrix(outputWidth, outputHeight);

  for (int inputY = 0, outputY = topPadding; inputY < inputHeight; inputY++, outputY += multiple) {
    // Write the contents of this row of the barcode
    for (int inputX = 0, outputX = leftPadding; inputX < inputWidth; inputX++, outputX += multiple) {
      if (input.get(inputX, inputY) == 1) {
        output.setRegion(outputX, outputY, multiple, multiple);
      }
    }
  }

  return output;
}
 
Example 14
Source File: Version.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * See ISO 18004:2006 Annex E
 */
BitMatrix buildFunctionPattern() {
  int dimension = getDimensionForVersion();
  BitMatrix bitMatrix = new BitMatrix(dimension);

  // Top left finder pattern + separator + format
  bitMatrix.setRegion(0, 0, 9, 9);
  // Top right finder pattern + separator + format
  bitMatrix.setRegion(dimension - 8, 0, 8, 9);
  // Bottom left finder pattern + separator + format
  bitMatrix.setRegion(0, dimension - 8, 9, 8);

  // Alignment patterns
  int max = alignmentPatternCenters.length;
  for (int x = 0; x < max; x++) {
    int i = alignmentPatternCenters[x] - 2;
    for (int y = 0; y < max; y++) {
      if ((x != 0 || (y != 0 && y != max - 1)) && (x != max - 1 || y != 0)) {
        bitMatrix.setRegion(alignmentPatternCenters[y] - 2, i, 5, 5);
      }
      // else no o alignment patterns near the three finder patterns
    }
  }

  // Vertical timing pattern
  bitMatrix.setRegion(6, 9, 1, dimension - 17);
  // Horizontal timing pattern
  bitMatrix.setRegion(9, 6, dimension - 17, 1);

  if (versionNumber > 6) {
    // Version info, top right
    bitMatrix.setRegion(dimension - 11, 0, 3, 6);
    // Version info, bottom left
    bitMatrix.setRegion(0, dimension - 11, 6, 3);
  }

  return bitMatrix;
}
 
Example 15
Source File: Version.java    From Tesseract-OCR-Scanner with Apache License 2.0 5 votes vote down vote up
/**
 * See ISO 18004:2006 Annex E
 */
BitMatrix buildFunctionPattern() {
  int dimension = getDimensionForVersion();
  BitMatrix bitMatrix = new BitMatrix(dimension);

  // Top left finder pattern + separator + format
  bitMatrix.setRegion(0, 0, 9, 9);
  // Top right finder pattern + separator + format
  bitMatrix.setRegion(dimension - 8, 0, 8, 9);
  // Bottom left finder pattern + separator + format
  bitMatrix.setRegion(0, dimension - 8, 9, 8);

  // Alignment patterns
  int max = alignmentPatternCenters.length;
  for (int x = 0; x < max; x++) {
    int i = alignmentPatternCenters[x] - 2;
    for (int y = 0; y < max; y++) {
      if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)) {
        // No alignment patterns near the three finder patterns
        continue;
      }
      bitMatrix.setRegion(alignmentPatternCenters[y] - 2, i, 5, 5);
    }
  }

  // Vertical timing pattern
  bitMatrix.setRegion(6, 9, 1, dimension - 17);
  // Horizontal timing pattern
  bitMatrix.setRegion(9, 6, dimension - 17, 1);

  if (versionNumber > 6) {
    // Version info, top right
    bitMatrix.setRegion(dimension - 11, 0, 3, 6);
    // Version info, bottom left
    bitMatrix.setRegion(0, dimension - 11, 6, 3);
  }

  return bitMatrix;
}
 
Example 16
Source File: QRCodeWriter.java    From Tesseract-OCR-Scanner with Apache License 2.0 5 votes vote down vote up
private static BitMatrix renderResult(QRCode code, int width, int height, int quietZone) {
  ByteMatrix input = code.getMatrix();
  if (input == null) {
    throw new IllegalStateException();
  }
  int inputWidth = input.getWidth();
  int inputHeight = input.getHeight();
  int qrWidth = inputWidth + (quietZone * 2);
  int qrHeight = inputHeight + (quietZone * 2);
  int outputWidth = Math.max(width, qrWidth);
  int outputHeight = Math.max(height, qrHeight);

  int multiple = Math.min(outputWidth / qrWidth, outputHeight / qrHeight);
  // Padding includes both the quiet zone and the extra white pixels to accommodate the requested
  // dimensions. For example, if input is 25x25 the QR will be 33x33 including the quiet zone.
  // If the requested size is 200x160, the multiple will be 4, for a QR of 132x132. These will
  // handle all the padding from 100x100 (the actual QR) up to 200x160.
  int leftPadding = (outputWidth - (inputWidth * multiple)) / 2;
  int topPadding = (outputHeight - (inputHeight * multiple)) / 2;

  BitMatrix output = new BitMatrix(outputWidth, outputHeight);

  for (int inputY = 0, outputY = topPadding; inputY < inputHeight; inputY++, outputY += multiple) {
    // Write the contents of this row of the barcode
    for (int inputX = 0, outputX = leftPadding; inputX < inputWidth; inputX++, outputX += multiple) {
      if (input.get(inputX, inputY) == 1) {
        output.setRegion(outputX, outputY, multiple, multiple);
      }
    }
  }

  return output;
}
 
Example 17
Source File: Version.java    From android-quick-response-code with Apache License 2.0 5 votes vote down vote up
/**
 * See ISO 18004:2006 Annex E
 */
BitMatrix buildFunctionPattern() {
    int dimension = getDimensionForVersion();
    BitMatrix bitMatrix = new BitMatrix(dimension);

    // Top left finder pattern + separator + format
    bitMatrix.setRegion(0, 0, 9, 9);
    // Top right finder pattern + separator + format
    bitMatrix.setRegion(dimension - 8, 0, 8, 9);
    // Bottom left finder pattern + separator + format
    bitMatrix.setRegion(0, dimension - 8, 9, 8);

    // Alignment patterns
    int max = alignmentPatternCenters.length;
    for (int x = 0; x < max; x++) {
        int i = alignmentPatternCenters[x] - 2;
        for (int y = 0; y < max; y++) {
            if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)) {
                // No alignment patterns near the three finder paterns
                continue;
            }
            bitMatrix.setRegion(alignmentPatternCenters[y] - 2, i, 5, 5);
        }
    }

    // Vertical timing pattern
    bitMatrix.setRegion(6, 9, 1, dimension - 17);
    // Horizontal timing pattern
    bitMatrix.setRegion(9, 6, dimension - 17, 1);

    if (versionNumber > 6) {
        // Version info, top right
        bitMatrix.setRegion(dimension - 11, 0, 3, 6);
        // Version info, bottom left
        bitMatrix.setRegion(0, dimension - 11, 6, 3);
    }

    return bitMatrix;
}
 
Example 18
Source File: Version.java    From ScreenCapture with MIT License 5 votes vote down vote up
/**
 * See ISO 18004:2006 Annex E
 */
BitMatrix buildFunctionPattern() {
  int dimension = getDimensionForVersion();
  BitMatrix bitMatrix = new BitMatrix(dimension);

  // Top left finder pattern + separator + format
  bitMatrix.setRegion(0, 0, 9, 9);
  // Top right finder pattern + separator + format
  bitMatrix.setRegion(dimension - 8, 0, 8, 9);
  // Bottom left finder pattern + separator + format
  bitMatrix.setRegion(0, dimension - 8, 9, 8);

  // Alignment patterns
  int max = alignmentPatternCenters.length;
  for (int x = 0; x < max; x++) {
    int i = alignmentPatternCenters[x] - 2;
    for (int y = 0; y < max; y++) {
      if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)) {
        // No alignment patterns near the three finder patterns
        continue;
      }
      bitMatrix.setRegion(alignmentPatternCenters[y] - 2, i, 5, 5);
    }
  }

  // Vertical timing pattern
  bitMatrix.setRegion(6, 9, 1, dimension - 17);
  // Horizontal timing pattern
  bitMatrix.setRegion(9, 6, dimension - 17, 1);

  if (versionNumber > 6) {
    // Version info, top right
    bitMatrix.setRegion(dimension - 11, 0, 3, 6);
    // Version info, bottom left
    bitMatrix.setRegion(0, dimension - 11, 6, 3);
  }

  return bitMatrix;
}
 
Example 19
Source File: Version.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
/**
 * See ISO 18004:2006 Annex E
 */
BitMatrix buildFunctionPattern() {
	int dimension = getDimensionForVersion();
	BitMatrix bitMatrix = new BitMatrix(dimension);

	// Top left finder pattern + separator + format
	bitMatrix.setRegion(0, 0, 9, 9);
	// Top right finder pattern + separator + format
	bitMatrix.setRegion(dimension - 8, 0, 8, 9);
	// Bottom left finder pattern + separator + format
	bitMatrix.setRegion(0, dimension - 8, 9, 8);

	// Alignment patterns
	int max = alignmentPatternCenters.length;
	for (int x = 0; x < max; x++) {
		int i = alignmentPatternCenters[x] - 2;
		for (int y = 0; y < max; y++) {
			if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)) {
				// No alignment patterns near the three finder paterns
				continue;
			}
			bitMatrix.setRegion(alignmentPatternCenters[y] - 2, i, 5, 5);
		}
	}

	// Vertical timing pattern
	bitMatrix.setRegion(6, 9, 1, dimension - 17);
	// Horizontal timing pattern
	bitMatrix.setRegion(9, 6, dimension - 17, 1);

	if (versionNumber > 6) {
		// Version info, top right
		bitMatrix.setRegion(dimension - 11, 0, 3, 6);
		// Version info, bottom left
		bitMatrix.setRegion(0, dimension - 11, 6, 3);
	}

	return bitMatrix;
}
 
Example 20
Source File: QRCodeWriter.java    From ShareBox with Apache License 2.0 4 votes vote down vote up
private static BitMatrix renderResult(QRCode code, int width, int height, int quietZone) {
    ByteMatrix input = code.getMatrix();
    if (input == null) {
        throw new IllegalStateException();
    }
    int inputWidth = input.getWidth();
    int inputHeight = input.getHeight();
    int qrWidth = inputWidth;
    int qrHeight = inputHeight;
    int outputWidth = Math.max(width, qrWidth);
    int outputHeight = Math.max(height, qrHeight);

    int multiple = Math.min(outputWidth / qrWidth, outputHeight / qrHeight);
    // Padding includes both the quiet zone and the extra white pixels to
    // accommodate the requested
    // dimensions. For example, if input is 25x25 the QR will be 33x33
    // including the quiet zone.
    // If the requested size is 200x160, the multiple will be 4, for a QR of
    // 132x132. These will
    // handle all the padding from 100x100 (the actual QR) up to 200x160.

    int leftPadding = (outputWidth - (inputWidth * multiple)) / 2;
    int topPadding = (outputHeight - (inputHeight * multiple)) / 2;

    if (leftPadding >= 0) {
        outputWidth = outputWidth - 2 * leftPadding;
        leftPadding = 0;
    }
    if (topPadding >= 0) {
        outputHeight = outputHeight - 2 * topPadding;
        topPadding = 0;
    }

    BitMatrix output = new BitMatrix(outputWidth, outputHeight);

    for (int inputY = 0, outputY = topPadding; inputY < inputHeight; inputY++, outputY += multiple) {
        // Write the contents of this row of the barcode
        for (int inputX = 0, outputX = leftPadding; inputX < inputWidth; inputX++, outputX += multiple) {
            if (input.get(inputX, inputY) == 1) {
                output.setRegion(outputX, outputY, multiple, multiple);
            }
        }
    }

    return output;
}