Zxing: Update to 3.4.1 (2020-09-29)

Merge in javadoc fixes
This commit is contained in:
zzz
2020-11-16 15:55:27 +00:00
parent 0b0b93f26f
commit 2044474549
19 changed files with 227 additions and 105 deletions

View File

@ -255,7 +255,7 @@ Applications:
Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
Copyright (c) 2008 Alexander von Gernler. All rights reserved.
See licenses/LICENSE-BSD.txt
Zxing 3.3.0:
Zxing 3.4.1:
See licenses/LICENSE-Apache2.0.txt
Jetty 9.3.28.v20191105 (jetty-*.jar, org.mortbay.*.jar):

View File

@ -23,6 +23,7 @@ Chang Hyun Park
Christian Brunschen (Google)
Christoph Schulz (creatale GmbH)
crowdin.net
Daisuke Makiuchi
Daniel Switkin (Google)
Dave MacLachlan (Google)
David Phillip Oster (Google)

View File

@ -363,3 +363,39 @@
- BS 4.7.6 release with Android API 23 support
- TIFF support in online decoder
- Many small bug fixes, typo fixes and project build improvements
3.3.1 (26 Oct 2017)
- Various fixes to Code 128, 39 encoding; DataMatrix decoding
- Improvements to speed and robustness of zxing.org decoder
- Java 9 support
- Various translation updates for Barcode Scanner
- Removed Google Glass, ZXing Test apps
3.3.2 (31 Jan 2018)
- Add workaround for Gradle + Android build issues
- Minor DataMatrix bug fixes
- Improve WPA2 wi-fi configuration support in Barcode Scanner
- Various translation updates and minor improvements
3.3.3 (30 May 2018)
- Minor fixes and improvements
- Java 9+ support
3.4.0 (19 May 2019)
- Requires Java 8+
- core, javase modules declare a Java 9+ module
- HtmlAssetTranslator and StringsResourceTranslator legacy utilities are moved to a .client.j2se subpackage
- No more releases of the Barcode Scanner app
- Minor bug fixes to Code93Writer
- Minor improvements to QR code detection
3.4.1 (30 Sep 2020)
- Wifi QR codes now recognize PH2:, not H:, for phase 2 method
- Minor bug fixes and improvements
Note that further release notes will be published at https://github.com/zxing/zxing/releases

View File

@ -2,4 +2,4 @@ This is a small portion of zxing, including only what's required
to generate QR codes. There are no modifications.
We've added a build.xml for ant.
https://github.com/zxing/zxing/releases Version 3.3.0 Sept. 16, 2016
https://github.com/zxing/zxing/releases Version 3.4.1 Sept. 29, 2020

View File

@ -1,6 +1,14 @@
<img align="right" src="https://raw.github.com/wiki/zxing/zxing/zxing-logo.png"/>
##Get Started Developing
## Project in Maintenance Mode Only
The project is in maintenance mode, meaning, changes are driven by contributed patches.
Only bug fixes and minor enhancements will be considered. The Barcode Scanner app can
no longer be published, so it's unlikely any changes will be accepted for it.
There is otherwise no active development or roadmap for this project. It is "DIY".
## Get Started Developing
To get started, please visit: https://github.com/zxing/zxing/wiki/Getting-Started-Developing
ZXing ("zebra crossing") is an open-source, multi-format 1D/2D barcode image processing
@ -8,15 +16,15 @@ library implemented in Java, with ports to other languages.
## Supported Formats
| 1D product | 1D industrial | 2D
| ---------- | ------------- | --------------
| UPC-A | Code 39 | QR Code
| UPC-E | Code 93 | Data Matrix
| EAN-8 | Code 128 | Aztec (beta)
| EAN-13 | Codabar | PDF 417 (beta)
| | ITF |
| | RSS-14 |
| | RSS-Expanded |
| 1D product | 1D industrial | 2D |
|:----------------------|:--------------|:---------------|
| UPC-A | Code 39 | QR Code |
| UPC-E | Code 93 | Data Matrix |
| EAN-8 | Code 128 | Aztec |
| EAN-13 | Codabar | PDF 417 |
| UPC/EAN Extension 2/5 | ITF | MaxiCode |
| | | RSS-14 |
| | | RSS-Expanded |
## Components
@ -26,11 +34,9 @@ library implemented in Java, with ports to other languages.
| ------------------- | -----------
| core | The core image decoding library, and test code
| javase | JavaSE-specific client code
| android | Android client Barcode Scanner [![Barcode Scanner](http://www.android.com/images/brand/android_app_on_play_logo_small.png)](https://play.google.com/store/apps/details?id=com.google.zxing.client.android)
| androidtest | Android test app, ZXing Test
| android | Android client Barcode Scanner [<img height='62' width='161' src='https://play.google.com/intl/en_us/badges/images/generic/en_badge_web_generic.png'/>](https://play.google.com/store/apps/details?id=com.google.zxing.client.android)
| android-integration | Supports integration with Barcode Scanner via `Intent`
| android-core | Android-related code shared among `android`, `androidtest`, `glass`
| glass | Simple Google Glass application
| android-core | Android-related code shared among `android`, other Android apps
| zxingorg | The source behind `zxing.org`
| zxing.appspot.com | The source behind web-based barcode generator at `zxing.appspot.com`
@ -46,14 +52,22 @@ library implemented in Java, with ports to other languages.
### ZXing-based third-party open source projects
| Module | Description
| --------------------------------------------------------------- | -----------
| [QZXing](https://sourceforge.net/projects/qzxing) | port to Qt framework
| [zxing-cpp](https://github.com/glassechidna/zxing-cpp) | port to C++ (forked from the [deprecated official C++ port](https://github.com/zxing/zxing/tree/00f634024ceeee591f54e6984ea7dd666fab22ae/cpp))
| [zxing_cpp.rb](https://github.com/glassechidna/zxing_cpp.rb) | bindings for Ruby (not just JRuby), powered by [zxing-cpp](https://github.com/glassechidna/zxing-cpp)
| [python-zxing](https://github.com/oostendo/python-zxing) | bindings for Python
| [ZXing .NET](http://zxingnet.codeplex.com/) | port to .NET and C#, and related Windows platform
| [php-qrcode-detector-decoder](https://github.com/khanamiryan/php-qrcode-detector-decoder) | port to PHP
| Module | Description
| ----------------------------------------------------------------------------------------- | -----------
| [QZXing](https://github.com/ftylitak/qzxing) | port to Qt framework
| [glassechidna/zxing-cpp](https://github.com/glassechidna/zxing-cpp) | port to C++ (forked from the [deprecated official C++ port](https://github.com/zxing/zxing/tree/00f634024ceeee591f54e6984ea7dd666fab22ae/cpp))
| [nu-book/zxing-cpp](https://github.com/nu-book/zxing-cpp) | recent port to C++
| [zxing_cpp.rb](https://github.com/glassechidna/zxing_cpp.rb) | bindings for Ruby (not just JRuby), powered by [zxing-cpp](https://github.com/glassechidna/zxing-cpp)
| [jsqrcode](https://github.com/LazarSoft/jsqrcode) | port to JavaScript
| [python-zxing](https://github.com/oostendo/python-zxing) | bindings for Python
| [ZXing .NET](https://github.com/micjahn/ZXing.Net) | port to .NET and C#, and related Windows platform
| [php-qrcode-detector-decoder](https://github.com/khanamiryan/php-qrcode-detector-decoder) | port to PHP
| [ZXing Delphi](https://github.com/Spelt/ZXing.Delphi) | Port to native Delphi object pascal, targeted at Firemonkey compatible devices (IOS/Android/Win/OSX) and VCL.
| [ZXingObjC](https://github.com/TheLevelUp/ZXingObjC) | Port to Objective-C
| [php-zxing](https://github.com/dsiddharth2/php-zxing) | PHP wrapper to Zxing Java library
| [zxing-js/library](https://github.com/zxing-js/library) | TypeScript port of ZXing library
| [pyzxing](https://github.com/ChenjieXu/pyzxing) | Python wrapper to ZXing library
### Other related third-party open source projects
@ -61,7 +75,7 @@ library implemented in Java, with ports to other languages.
| ---------------------------------------------- | -----------
| [Barcode4J](http://barcode4j.sourceforge.net/) | Generator library in Java
| [ZBar](http://zbar.sourceforge.net/) | Reader library in C99
| [OkapiBarcode](https://github.com/woo-j/OkapiBarcode) |
| [OkapiBarcode](https://github.com/woo-j/OkapiBarcode) | |
## Links
@ -73,14 +87,15 @@ library implemented in Java, with ports to other languages.
## Contacting
Post to the [discussion forum](https://groups.google.com/group/zxing) or tag a question with [`zxing`
on StackOverflow](http://stackoverflow.com/questions/tagged/zxing).
on StackOverflow](https://stackoverflow.com/questions/tagged/zxing).
## Etcetera
[![Build Status](https://travis-ci.org/zxing/zxing.png?branch=master)](https://travis-ci.org/zxing/zxing)
[![Build Status](https://travis-ci.org/zxing/zxing.svg?branch=master)](https://travis-ci.org/zxing/zxing)
[![Coverity Status](https://scan.coverity.com/projects/1924/badge.svg)](https://scan.coverity.com/projects/1924)
[![codecov.io](https://codecov.io/github/zxing/zxing/coverage.svg?branch=master)](https://codecov.io/github/zxing/zxing?branch=master)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/7270e4b57c50483699448bf32721ab10)](https://www.codacy.com/app/srowen/zxing?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=zxing/zxing&amp;utm_campaign=Badge_Grade)
QR code is trademarked by Denso Wave, inc. Thanks to Haase & Martin OHG for contributing the logo.
Optimized with [![JProfiler](http://www.ej-technologies.com/images/banners/jprofiler_small.png)](http://www.ej-technologies.com/products/jprofiler/overview.html)
Optimized with [![JProfiler](https://www.ej-technologies.com/images/banners/jprofiler_small.png)](https://www.ej-technologies.com/products/jprofiler/overview.html)

View File

@ -101,4 +101,18 @@ public enum EncodeHintType {
* (Type {@link Integer}, or {@link String} representation of the integer value).
*/
QR_VERSION,
/**
* Specifies the QR code mask pattern to be used. Allowed values are
* 0..QRCode.NUM_MASK_PATTERNS-1. By default the code will automatically select
* the optimal mask pattern.
* * (Type {@link Integer}, or {@link String} representation of the integer value).
*/
QR_MASK_PATTERN,
/**
* Specifies whether the data should be encoded to the GS1 standard (type {@link Boolean}, or "true" or "false"
* {@link String } value).
*/
GS1_FORMAT,
}

View File

@ -99,7 +99,7 @@ public final class BitArray implements Cloneable {
int bitsOffset = from / 32;
int currentBits = bits[bitsOffset];
// mask off lesser bits first
currentBits &= ~((1 << (from & 0x1F)) - 1);
currentBits &= -(1 << (from & 0x1F));
while (currentBits == 0) {
if (++bitsOffset == bits.length) {
return size;
@ -107,7 +107,7 @@ public final class BitArray implements Cloneable {
currentBits = bits[bitsOffset];
}
int result = (bitsOffset * 32) + Integer.numberOfTrailingZeros(currentBits);
return result > size ? size : result;
return Math.min(result, size);
}
/**
@ -122,7 +122,7 @@ public final class BitArray implements Cloneable {
int bitsOffset = from / 32;
int currentBits = ~bits[bitsOffset];
// mask off lesser bits first
currentBits &= ~((1 << (from & 0x1F)) - 1);
currentBits &= -(1 << (from & 0x1F));
while (currentBits == 0) {
if (++bitsOffset == bits.length) {
return size;
@ -130,7 +130,7 @@ public final class BitArray implements Cloneable {
currentBits = ~bits[bitsOffset];
}
int result = (bitsOffset * 32) + Integer.numberOfTrailingZeros(currentBits);
return result > size ? size : result;
return Math.min(result, size);
}
/**
@ -339,7 +339,7 @@ public final class BitArray implements Cloneable {
@Override
public String toString() {
StringBuilder result = new StringBuilder(size);
StringBuilder result = new StringBuilder(size + (size / 8) + 1);
for (int i = 0; i < size; i++) {
if ((i & 0x07) == 0) {
result.append(' ');

View File

@ -40,11 +40,21 @@ public final class BitMatrix implements Cloneable {
private final int rowSize;
private final int[] bits;
// A helper to construct a square matrix.
/**
* Creates an empty square {@code BitMatrix}.
*
* @param dimension height and width
*/
public BitMatrix(int dimension) {
this(dimension, dimension);
}
/**
* Creates an empty {@code BitMatrix}.
*
* @param width bit matrix width
* @param height bit matrix height
*/
public BitMatrix(int width, int height) {
if (width < 1 || height < 1) {
throw new IllegalArgumentException("Both dimensions must be greater than 0");
@ -62,6 +72,27 @@ public final class BitMatrix implements Cloneable {
this.bits = bits;
}
/**
* Interprets a 2D array of booleans as a {@code BitMatrix}, where "true" means an "on" bit.
*
* @param image bits of the image, as a row-major 2D array. Elements are arrays representing rows
* @return {@code BitMatrix} representation of image
*/
public static BitMatrix parse(boolean[][] image) {
int height = image.length;
int width = image[0].length;
BitMatrix bits = new BitMatrix(width, height);
for (int i = 0; i < height; i++) {
boolean[] imageI = image[i];
for (int j = 0; j < width; j++) {
if (imageI[j]) {
bits.set(j, i);
}
}
}
return bits;
}
public static BitMatrix parse(String stringRepresentation, String setString, String unsetString) {
if (stringRepresentation == null) {
throw new IllegalArgumentException();
@ -86,11 +117,11 @@ public final class BitMatrix implements Cloneable {
nRows++;
}
pos++;
} else if (stringRepresentation.substring(pos, pos + setString.length()).equals(setString)) {
} else if (stringRepresentation.startsWith(setString, pos)) {
pos += setString.length();
bits[bitsPos] = true;
bitsPos++;
} else if (stringRepresentation.substring(pos, pos + unsetString.length()).equals(unsetString)) {
} else if (stringRepresentation.startsWith(unsetString, pos)) {
pos += unsetString.length();
bits[bitsPos] = false;
bitsPos++;
@ -165,11 +196,10 @@ public final class BitMatrix implements Cloneable {
* @param mask XOR mask
*/
public void xor(BitMatrix mask) {
if (width != mask.getWidth() || height != mask.getHeight()
|| rowSize != mask.getRowSize()) {
if (width != mask.width || height != mask.height || rowSize != mask.rowSize) {
throw new IllegalArgumentException("input matrix dimensions do not match");
}
BitArray rowArray = new BitArray(width / 32 + 1);
BitArray rowArray = new BitArray(width);
for (int y = 0; y < height; y++) {
int offset = y * rowSize;
int[] row = mask.getRow(y, rowArray).getBitArray();
@ -250,17 +280,17 @@ public final class BitMatrix implements Cloneable {
* Modifies this {@code BitMatrix} to represent the same but rotated 180 degrees
*/
public void rotate180() {
int width = getWidth();
int height = getHeight();
BitArray topRow = new BitArray(width);
BitArray bottomRow = new BitArray(width);
for (int i = 0; i < (height + 1) / 2; i++) {
int maxHeight = (height + 1) / 2;
for (int i = 0; i < maxHeight; i++) {
topRow = getRow(i, topRow);
bottomRow = getRow(height - 1 - i, bottomRow);
int bottomRowIndex = height - 1 - i;
bottomRow = getRow(bottomRowIndex, bottomRow);
topRow.reverse();
bottomRow.reverse();
setRow(i, bottomRow);
setRow(height - 1 - i, topRow);
setRow(bottomRowIndex, topRow);
}
}

View File

@ -225,12 +225,19 @@ final class GenericGFPoly {
@Override
public String toString() {
if (isZero()) {
return "0";
}
StringBuilder result = new StringBuilder(8 * getDegree());
for (int degree = getDegree(); degree >= 0; degree--) {
int coefficient = getCoefficient(degree);
if (coefficient != 0) {
if (coefficient < 0) {
result.append(" - ");
if (degree == getDegree()) {
result.append("-");
} else {
result.append(" - ");
}
coefficient = -coefficient;
} else {
if (result.length() > 0) {

View File

@ -20,7 +20,7 @@ import java.util.ArrayList;
import java.util.List;
/**
* <p>Implements Reed-Solomon enbcoding, as the name implies.</p>
* <p>Implements Reed-Solomon encoding, as the name implies.</p>
*
* @author Sean Owen
* @author William Rucklidge

View File

@ -152,11 +152,10 @@ public final class Version {
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;
if ((x != 0 || (y != 0 && y != max - 1)) && (x != max - 1 || y != 0)) {
bitMatrix.setRegion(alignmentPatternCenters[y] - 2, i, 5, 5);
}
bitMatrix.setRegion(alignmentPatternCenters[y] - 2, i, 5, 5);
// else no o alignment patterns near the three finder patterns
}
}

View File

@ -16,6 +16,8 @@
package com.google.zxing.qrcode.encoder;
import java.util.Arrays;
/**
* JAVAPORT: The original code was a 2D array of ints, but since it only ever gets assigned
* -1, 0, and 1, I'm going to use less memory and go with bytes.
@ -66,10 +68,8 @@ public final class ByteMatrix {
}
public void clear(byte value) {
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
bytes[y][x] = value;
}
for (byte[] aByte : bytes) {
Arrays.fill(aByte, value);
}
}
@ -77,8 +77,9 @@ public final class ByteMatrix {
public String toString() {
StringBuilder result = new StringBuilder(2 * width * height + 2);
for (int y = 0; y < height; ++y) {
byte[] bytesY = bytes[y];
for (int x = 0; x < width; ++x) {
switch (bytes[y][x]) {
switch (bytesY[x]) {
case 0:
result.append(" 0");
break;

View File

@ -78,7 +78,8 @@ public final class Encoder {
// Determine what character encoding has been specified by the caller, if any
String encoding = DEFAULT_BYTE_MODE_ENCODING;
if (hints != null && hints.containsKey(EncodeHintType.CHARACTER_SET)) {
boolean hasEncodingHint = hints != null && hints.containsKey(EncodeHintType.CHARACTER_SET);
if (hasEncodingHint) {
encoding = hints.get(EncodeHintType.CHARACTER_SET).toString();
}
@ -91,13 +92,20 @@ public final class Encoder {
BitArray headerBits = new BitArray();
// Append ECI segment if applicable
if (mode == Mode.BYTE && !DEFAULT_BYTE_MODE_ENCODING.equals(encoding)) {
if (mode == Mode.BYTE && hasEncodingHint) {
CharacterSetECI eci = CharacterSetECI.getCharacterSetECIByName(encoding);
if (eci != null) {
appendECI(eci, headerBits);
}
}
// Append the FNC1 mode header for GS1 formatted data if applicable
boolean hasGS1FormatHint = hints != null && hints.containsKey(EncodeHintType.GS1_FORMAT);
if (hasGS1FormatHint && Boolean.parseBoolean(hints.get(EncodeHintType.GS1_FORMAT).toString())) {
// GS1 formatted codes are prefixed with a FNC1 in first position mode header
appendModeInfo(Mode.FNC1_FIRST_POSITION, headerBits);
}
// (With ECI in place,) Write the mode marker
appendModeInfo(mode, headerBits);
@ -147,7 +155,17 @@ public final class Encoder {
// Choose the mask pattern and set to "qrCode".
int dimension = version.getDimensionForVersion();
ByteMatrix matrix = new ByteMatrix(dimension, dimension);
int maskPattern = chooseMaskPattern(finalBits, ecLevel, version, matrix);
// Enable manual selection of the pattern to be used via hint
int maskPattern = -1;
if (hints != null && hints.containsKey(EncodeHintType.QR_MASK_PATTERN)) {
int hintMaskPattern = Integer.parseInt(hints.get(EncodeHintType.QR_MASK_PATTERN).toString());
maskPattern = QRCode.isValidMaskPattern(hintMaskPattern) ? hintMaskPattern : -1;
}
if (maskPattern == -1) {
maskPattern = chooseMaskPattern(finalBits, ecLevel, version, matrix);
}
qrCode.setMaskPattern(maskPattern);
// Build the matrix and set it to "qrCode".
@ -581,8 +599,11 @@ public final class Encoder {
} catch (UnsupportedEncodingException uee) {
throw new WriterException(uee);
}
int length = bytes.length;
for (int i = 0; i < length; i += 2) {
if (bytes.length % 2 != 0) {
throw new WriterException("Kanji byte size not even");
}
int maxI = bytes.length - 1; // bytes.length must be even
for (int i = 0; i < maxI; i += 2) {
int byte1 = bytes[i] & 0xFF;
int byte2 = bytes[i + 1] & 0xFF;
int code = (byte1 << 8) | byte2;

View File

@ -52,9 +52,10 @@ final class MaskUtil {
int width = matrix.getWidth();
int height = matrix.getHeight();
for (int y = 0; y < height - 1; y++) {
byte[] arrayY = array[y];
for (int x = 0; x < width - 1; x++) {
int value = array[y][x];
if (value == array[y][x + 1] && value == array[y + 1][x] && value == array[y + 1][x + 1]) {
int value = arrayY[x];
if (value == arrayY[x + 1] && value == array[y + 1][x] && value == array[y + 1][x + 1]) {
penalty++;
}
}

View File

@ -27,11 +27,7 @@ import com.google.zxing.qrcode.decoder.Version;
*/
final class MatrixUtil {
private MatrixUtil() {
// do nothing
}
private static final int[][] POSITION_DETECTION_PATTERN = {
private static final int[][] POSITION_DETECTION_PATTERN = {
{1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 1},
{1, 0, 1, 1, 1, 0, 1},
@ -119,6 +115,10 @@ final class MatrixUtil {
private static final int TYPE_INFO_POLY = 0x537;
private static final int TYPE_INFO_MASK_PATTERN = 0x5412;
private MatrixUtil() {
// do nothing
}
// Set all cells to -1. -1 means that the cell is empty (not set yet).
//
// JAVAPORT: We shouldn't need to do this at all. The code should be rewritten to begin encoding
@ -174,21 +174,23 @@ final class MatrixUtil {
boolean bit = typeInfoBits.get(typeInfoBits.getSize() - 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];
int[] coordinates = TYPE_INFO_COORDINATES[i];
int x1 = coordinates[0];
int y1 = coordinates[1];
matrix.set(x1, y1, bit);
int x2;
int y2;
if (i < 8) {
// Right top corner.
int x2 = matrix.getWidth() - i - 1;
int y2 = 8;
matrix.set(x2, y2, bit);
x2 = matrix.getWidth() - i - 1;
y2 = 8;
} else {
// Left bottom corner.
int x2 = 8;
int y2 = matrix.getHeight() - 7 + (i - 8);
matrix.set(x2, y2, bit);
x2 = 8;
y2 = matrix.getHeight() - 7 + (i - 8);
}
matrix.set(x2, y2, bit);
}
}
@ -298,7 +300,7 @@ final class MatrixUtil {
// 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.
// operations. We don't care if coefficients are positive or negative.
static int calculateBCHCode(int value, int poly) {
if (poly == 0) {
throw new IllegalArgumentException("0 polynomial");
@ -401,21 +403,20 @@ final class MatrixUtil {
}
}
// 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) {
int[] patternY = POSITION_ADJUSTMENT_PATTERN[y];
for (int x = 0; x < 5; ++x) {
matrix.set(xStart + x, yStart + y, POSITION_ADJUSTMENT_PATTERN[y][x]);
matrix.set(xStart + x, yStart + y, patternY[x]);
}
}
}
private static void embedPositionDetectionPattern(int xStart, int yStart, ByteMatrix matrix) {
for (int y = 0; y < 7; ++y) {
int[] patternY = POSITION_DETECTION_PATTERN[y];
for (int x = 0; x < 7; ++x) {
matrix.set(xStart + x, yStart + y, POSITION_DETECTION_PATTERN[y][x]);
matrix.set(xStart + x, yStart + y, patternY[x]);
}
}
}
@ -459,19 +460,15 @@ final class MatrixUtil {
}
int index = version.getVersionNumber() - 1;
int[] coordinates = POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[index];
int numCoordinates = POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[index].length;
for (int i = 0; i < numCoordinates; ++i) {
for (int j = 0; j < numCoordinates; ++j) {
int y = coordinates[i];
int x = coordinates[j];
if (x == -1 || y == -1) {
continue;
}
// If the cell is unset, we embed the position adjustment pattern here.
if (isEmpty(matrix.get(x, y))) {
// -2 is necessary since the x/y coordinates point to the center of the pattern, not the
// left top corner.
embedPositionAdjustmentPattern(x - 2, y - 2, matrix);
for (int y : coordinates) {
if (y >= 0) {
for (int x : coordinates) {
if (x >= 0 && isEmpty(matrix.get(x, y))) {
// If the cell is unset, we embed the position adjustment pattern here.
// -2 is necessary since the x/y coordinates point to the center of the pattern, not the
// left top corner.
embedPositionAdjustmentPattern(x - 2, y - 2, matrix);
}
}
}
}