|
|
@ -27,6 +27,7 @@ package io.nayuki.qrcodegen;
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -51,8 +52,8 @@ public final class QrCode {
|
|
|
|
* @throws IllegalArgumentException if the text fails to fit in the largest version QR Code, which means it is too long
|
|
|
|
* @throws IllegalArgumentException if the text fails to fit in the largest version QR Code, which means it is too long
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static QrCode encodeText(String text, Ecc ecl) {
|
|
|
|
public static QrCode encodeText(String text, Ecc ecl) {
|
|
|
|
if (text == null || ecl == null)
|
|
|
|
Objects.requireNonNull(text);
|
|
|
|
throw new NullPointerException();
|
|
|
|
Objects.requireNonNull(ecl);
|
|
|
|
List<QrSegment> segs = QrSegment.makeSegments(text);
|
|
|
|
List<QrSegment> segs = QrSegment.makeSegments(text);
|
|
|
|
return encodeSegments(segs, ecl);
|
|
|
|
return encodeSegments(segs, ecl);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -70,8 +71,8 @@ public final class QrCode {
|
|
|
|
* @throws IllegalArgumentException if the data fails to fit in the largest version QR Code, which means it is too long
|
|
|
|
* @throws IllegalArgumentException if the data fails to fit in the largest version QR Code, which means it is too long
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static QrCode encodeBinary(byte[] data, Ecc ecl) {
|
|
|
|
public static QrCode encodeBinary(byte[] data, Ecc ecl) {
|
|
|
|
if (data == null || ecl == null)
|
|
|
|
Objects.requireNonNull(data);
|
|
|
|
throw new NullPointerException();
|
|
|
|
Objects.requireNonNull(ecl);
|
|
|
|
QrSegment seg = QrSegment.makeBytes(data);
|
|
|
|
QrSegment seg = QrSegment.makeBytes(data);
|
|
|
|
return encodeSegments(Arrays.asList(seg), ecl);
|
|
|
|
return encodeSegments(Arrays.asList(seg), ecl);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -112,8 +113,8 @@ public final class QrCode {
|
|
|
|
* < −1 or mask > 7, or if the data is too long to fit in a QR Code at maxVersion at the ECL
|
|
|
|
* < −1 or mask > 7, or if the data is too long to fit in a QR Code at maxVersion at the ECL
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static QrCode encodeSegments(List<QrSegment> segs, Ecc ecl, int minVersion, int maxVersion, int mask, boolean boostEcl) {
|
|
|
|
public static QrCode encodeSegments(List<QrSegment> segs, Ecc ecl, int minVersion, int maxVersion, int mask, boolean boostEcl) {
|
|
|
|
if (segs == null || ecl == null)
|
|
|
|
Objects.requireNonNull(segs);
|
|
|
|
throw new NullPointerException();
|
|
|
|
Objects.requireNonNull(ecl);
|
|
|
|
if (!(1 <= minVersion && minVersion <= maxVersion && maxVersion <= 40) || mask < -1 || mask > 7)
|
|
|
|
if (!(1 <= minVersion && minVersion <= maxVersion && maxVersion <= 40) || mask < -1 || mask > 7)
|
|
|
|
throw new IllegalArgumentException("Invalid value");
|
|
|
|
throw new IllegalArgumentException("Invalid value");
|
|
|
|
|
|
|
|
|
|
|
@ -201,12 +202,10 @@ public final class QrCode {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public QrCode(int ver, Ecc ecl, byte[] dataCodewords, int mask) {
|
|
|
|
public QrCode(int ver, Ecc ecl, byte[] dataCodewords, int mask) {
|
|
|
|
// Check arguments
|
|
|
|
// Check arguments
|
|
|
|
if (ecl == null)
|
|
|
|
Objects.requireNonNull(ecl);
|
|
|
|
throw new NullPointerException();
|
|
|
|
|
|
|
|
if (ver < 1 || ver > 40 || mask < -1 || mask > 7)
|
|
|
|
if (ver < 1 || ver > 40 || mask < -1 || mask > 7)
|
|
|
|
throw new IllegalArgumentException("Value out of range");
|
|
|
|
throw new IllegalArgumentException("Value out of range");
|
|
|
|
if (dataCodewords == null)
|
|
|
|
Objects.requireNonNull(dataCodewords);
|
|
|
|
throw new NullPointerException();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize fields
|
|
|
|
// Initialize fields
|
|
|
|
version = ver;
|
|
|
|
version = ver;
|
|
|
@ -234,8 +233,7 @@ public final class QrCode {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public QrCode(QrCode qr, int mask) {
|
|
|
|
public QrCode(QrCode qr, int mask) {
|
|
|
|
// Check arguments
|
|
|
|
// Check arguments
|
|
|
|
if (qr == null)
|
|
|
|
Objects.requireNonNull(qr);
|
|
|
|
throw new NullPointerException();
|
|
|
|
|
|
|
|
if (mask < -1 || mask > 7)
|
|
|
|
if (mask < -1 || mask > 7)
|
|
|
|
throw new IllegalArgumentException("Mask value out of range");
|
|
|
|
throw new IllegalArgumentException("Mask value out of range");
|
|
|
|
|
|
|
|
|
|
|
@ -497,8 +495,7 @@ public final class QrCode {
|
|
|
|
// Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
|
|
|
|
// Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
|
|
|
|
// data area of this QR Code symbol. Function modules need to be marked off before this is called.
|
|
|
|
// data area of this QR Code symbol. Function modules need to be marked off before this is called.
|
|
|
|
private void drawCodewords(byte[] data) {
|
|
|
|
private void drawCodewords(byte[] data) {
|
|
|
|
if (data == null)
|
|
|
|
Objects.requireNonNull(data);
|
|
|
|
throw new NullPointerException();
|
|
|
|
|
|
|
|
if (data.length != getNumRawDataModules(version) / 8)
|
|
|
|
if (data.length != getNumRawDataModules(version) / 8)
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
|
|
|
|
|
|
|
@ -832,8 +829,7 @@ public final class QrCode {
|
|
|
|
* @throws NullPointerException if the data is {@code null}
|
|
|
|
* @throws NullPointerException if the data is {@code null}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public byte[] getRemainder(byte[] data) {
|
|
|
|
public byte[] getRemainder(byte[] data) {
|
|
|
|
if (data == null)
|
|
|
|
Objects.requireNonNull(data);
|
|
|
|
throw new NullPointerException();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Compute the remainder by performing polynomial division
|
|
|
|
// Compute the remainder by performing polynomial division
|
|
|
|
byte[] result = new byte[coefficients.length];
|
|
|
|
byte[] result = new byte[coefficients.length];
|
|
|
|