mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Miscellaneous tweaks from inspection
git-svn-id: https://zxing.googlecode.com/svn/trunk@2244 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
b1dfc23418
commit
cc204e1bde
|
@ -36,13 +36,14 @@ public class GlobalHistogramBinarizer extends Binarizer {
|
||||||
private static final int LUMINANCE_BITS = 5;
|
private static final int LUMINANCE_BITS = 5;
|
||||||
private static final int LUMINANCE_SHIFT = 8 - LUMINANCE_BITS;
|
private static final int LUMINANCE_SHIFT = 8 - LUMINANCE_BITS;
|
||||||
private static final int LUMINANCE_BUCKETS = 1 << LUMINANCE_BITS;
|
private static final int LUMINANCE_BUCKETS = 1 << LUMINANCE_BITS;
|
||||||
|
private static final byte[] EMPTY = new byte[0];
|
||||||
|
|
||||||
private byte[] luminances;
|
private byte[] luminances;
|
||||||
private final int[] buckets;
|
private final int[] buckets;
|
||||||
|
|
||||||
public GlobalHistogramBinarizer(LuminanceSource source) {
|
public GlobalHistogramBinarizer(LuminanceSource source) {
|
||||||
super(source);
|
super(source);
|
||||||
luminances = new byte[0];
|
luminances = EMPTY;
|
||||||
buckets = new int[LUMINANCE_BUCKETS];
|
buckets = new int[LUMINANCE_BUCKETS];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,8 +103,8 @@ final class GenericGFPoly {
|
||||||
if (a == 1) {
|
if (a == 1) {
|
||||||
// Just the sum of the coefficients
|
// Just the sum of the coefficients
|
||||||
int result = 0;
|
int result = 0;
|
||||||
for (int i = 0; i < size; i++) {
|
for (int coefficient : coefficients) {
|
||||||
result = GenericGF.addOrSubtract(result, coefficients[i]);
|
result = GenericGF.addOrSubtract(result, coefficient);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,8 +84,8 @@ public final class Decoder {
|
||||||
|
|
||||||
// Count total number of data bytes
|
// Count total number of data bytes
|
||||||
int totalBytes = 0;
|
int totalBytes = 0;
|
||||||
for (int i = 0; i < dataBlocksCount; i++) {
|
for (DataBlock db : dataBlocks) {
|
||||||
totalBytes += dataBlocks[i].getNumDataCodewords();
|
totalBytes += db.getNumDataCodewords();
|
||||||
}
|
}
|
||||||
byte[] resultBytes = new byte[totalBytes];
|
byte[] resultBytes = new byte[totalBytes];
|
||||||
|
|
||||||
|
|
|
@ -100,12 +100,7 @@ public final class Version {
|
||||||
throw FormatException.getFormatInstance();
|
throw FormatException.getFormatInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(bbrown): This is doing a linear search through the array of versions.
|
for (Version version : VERSIONS) {
|
||||||
// If we interleave the rectangular versions with the square versions we could
|
|
||||||
// do a binary search.
|
|
||||||
int numVersions = VERSIONS.length;
|
|
||||||
for (int i = 0; i < numVersions; ++i){
|
|
||||||
Version version = VERSIONS[i];
|
|
||||||
if (version.symbolSizeRows == numRows && version.symbolSizeColumns == numColumns) {
|
if (version.symbolSizeRows == numRows && version.symbolSizeColumns == numColumns) {
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,8 +213,7 @@ public final class Code39Reader extends OneDReader {
|
||||||
int wideCounters;
|
int wideCounters;
|
||||||
do {
|
do {
|
||||||
int minCounter = Integer.MAX_VALUE;
|
int minCounter = Integer.MAX_VALUE;
|
||||||
for (int i = 0; i < numCounters; i++) {
|
for (int counter : counters) {
|
||||||
int counter = counters[i];
|
|
||||||
if (counter < minCounter && counter > maxNarrowCounter) {
|
if (counter < minCounter && counter > maxNarrowCounter) {
|
||||||
minCounter = counter;
|
minCounter = counter;
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,8 +147,8 @@ public final class Code93Reader extends OneDReader {
|
||||||
private static int toPattern(int[] counters) {
|
private static int toPattern(int[] counters) {
|
||||||
int max = counters.length;
|
int max = counters.length;
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
for (int i = 0; i < max; i++) {
|
for (int counter : counters) {
|
||||||
sum += counters[i];
|
sum += counter;
|
||||||
}
|
}
|
||||||
int pattern = 0;
|
int pattern = 0;
|
||||||
for (int i = 0; i < max; i++) {
|
for (int i = 0; i < max; i++) {
|
||||||
|
|
|
@ -64,8 +64,8 @@ public final class RSSUtils {
|
||||||
public static int getRSSvalue(int[] widths, int maxWidth, boolean noNarrow) {
|
public static int getRSSvalue(int[] widths, int maxWidth, boolean noNarrow) {
|
||||||
int elements = widths.length;
|
int elements = widths.length;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
for (int i = 0; i < elements; i++) {
|
for (int width : widths) {
|
||||||
n += widths[i];
|
n += width;
|
||||||
}
|
}
|
||||||
int val = 0;
|
int val = 0;
|
||||||
int narrowMask = 0;
|
int narrowMask = 0;
|
||||||
|
|
|
@ -55,10 +55,12 @@ public final class MatrixUtilTestCase extends Assert {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmbedBasicPatterns() throws WriterException {
|
public void testEmbedBasicPatterns1() throws WriterException {
|
||||||
{
|
// Version 1.
|
||||||
// Version 1.
|
ByteMatrix matrix = new ByteMatrix(21, 21);
|
||||||
String expected =
|
MatrixUtil.clearMatrix(matrix);
|
||||||
|
MatrixUtil.embedBasicPatterns(1, matrix);
|
||||||
|
String expected =
|
||||||
" 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1\n" +
|
" 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1\n" +
|
||||||
" 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1\n" +
|
" 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1\n" +
|
||||||
" 1 0 1 1 1 0 1 0 0 1 0 1 1 1 0 1\n" +
|
" 1 0 1 1 1 0 1 0 0 1 0 1 1 1 0 1\n" +
|
||||||
|
@ -80,15 +82,17 @@ public final class MatrixUtilTestCase extends Assert {
|
||||||
" 1 0 1 1 1 0 1 0 \n" +
|
" 1 0 1 1 1 0 1 0 \n" +
|
||||||
" 1 0 0 0 0 0 1 0 \n" +
|
" 1 0 0 0 0 0 1 0 \n" +
|
||||||
" 1 1 1 1 1 1 1 0 \n";
|
" 1 1 1 1 1 1 1 0 \n";
|
||||||
ByteMatrix matrix = new ByteMatrix(21, 21);
|
assertEquals(expected, matrix.toString());
|
||||||
MatrixUtil.clearMatrix(matrix);
|
}
|
||||||
MatrixUtil.embedBasicPatterns(1, matrix);
|
|
||||||
assertEquals(expected, matrix.toString());
|
@Test
|
||||||
}
|
public void testEmbedBasicPatterns2() throws WriterException {
|
||||||
{
|
// Version 2. Position adjustment pattern should apppear at right
|
||||||
// Version 2. Position adjustment pattern should apppear at right
|
// bottom corner.
|
||||||
// bottom corner.
|
ByteMatrix matrix = new ByteMatrix(25, 25);
|
||||||
String expected =
|
MatrixUtil.clearMatrix(matrix);
|
||||||
|
MatrixUtil.embedBasicPatterns(2, matrix);
|
||||||
|
String expected =
|
||||||
" 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1\n" +
|
" 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1\n" +
|
||||||
" 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1\n" +
|
" 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1\n" +
|
||||||
" 1 0 1 1 1 0 1 0 0 1 0 1 1 1 0 1\n" +
|
" 1 0 1 1 1 0 1 0 0 1 0 1 1 1 0 1\n" +
|
||||||
|
@ -114,135 +118,109 @@ public final class MatrixUtilTestCase extends Assert {
|
||||||
" 1 0 1 1 1 0 1 0 \n" +
|
" 1 0 1 1 1 0 1 0 \n" +
|
||||||
" 1 0 0 0 0 0 1 0 \n" +
|
" 1 0 0 0 0 0 1 0 \n" +
|
||||||
" 1 1 1 1 1 1 1 0 \n";
|
" 1 1 1 1 1 1 1 0 \n";
|
||||||
ByteMatrix matrix = new ByteMatrix(25, 25);
|
assertEquals(expected, matrix.toString());
|
||||||
MatrixUtil.clearMatrix(matrix);
|
|
||||||
MatrixUtil.embedBasicPatterns(2, matrix);
|
|
||||||
assertEquals(expected, matrix.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmbedTypeInfo() throws WriterException {
|
public void testEmbedTypeInfo() throws WriterException {
|
||||||
// Type info bits = 100000011001110.
|
// Type info bits = 100000011001110.
|
||||||
String expected =
|
|
||||||
" 0 \n" +
|
|
||||||
" 1 \n" +
|
|
||||||
" 1 \n" +
|
|
||||||
" 1 \n" +
|
|
||||||
" 0 \n" +
|
|
||||||
" 0 \n" +
|
|
||||||
" \n" +
|
|
||||||
" 1 \n" +
|
|
||||||
" 1 0 0 0 0 0 0 1 1 1 0 0 1 1 1 0\n" +
|
|
||||||
" \n" +
|
|
||||||
" \n" +
|
|
||||||
" \n" +
|
|
||||||
" \n" +
|
|
||||||
" \n" +
|
|
||||||
" 0 \n" +
|
|
||||||
" 0 \n" +
|
|
||||||
" 0 \n" +
|
|
||||||
" 0 \n" +
|
|
||||||
" 0 \n" +
|
|
||||||
" 0 \n" +
|
|
||||||
" 1 \n";
|
|
||||||
ByteMatrix matrix = new ByteMatrix(21, 21);
|
ByteMatrix matrix = new ByteMatrix(21, 21);
|
||||||
MatrixUtil.clearMatrix(matrix);
|
MatrixUtil.clearMatrix(matrix);
|
||||||
MatrixUtil.embedTypeInfo(ErrorCorrectionLevel.M, 5, matrix);
|
MatrixUtil.embedTypeInfo(ErrorCorrectionLevel.M, 5, matrix);
|
||||||
|
String expected =
|
||||||
|
" 0 \n" +
|
||||||
|
" 1 \n" +
|
||||||
|
" 1 \n" +
|
||||||
|
" 1 \n" +
|
||||||
|
" 0 \n" +
|
||||||
|
" 0 \n" +
|
||||||
|
" \n" +
|
||||||
|
" 1 \n" +
|
||||||
|
" 1 0 0 0 0 0 0 1 1 1 0 0 1 1 1 0\n" +
|
||||||
|
" \n" +
|
||||||
|
" \n" +
|
||||||
|
" \n" +
|
||||||
|
" \n" +
|
||||||
|
" \n" +
|
||||||
|
" 0 \n" +
|
||||||
|
" 0 \n" +
|
||||||
|
" 0 \n" +
|
||||||
|
" 0 \n" +
|
||||||
|
" 0 \n" +
|
||||||
|
" 0 \n" +
|
||||||
|
" 1 \n";
|
||||||
assertEquals(expected, matrix.toString());
|
assertEquals(expected, matrix.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmbedVersionInfo() throws WriterException {
|
public void testEmbedVersionInfo() throws WriterException {
|
||||||
// Version info bits = 000111 110010 010100
|
// Version info bits = 000111 110010 010100
|
||||||
String expected =
|
|
||||||
" 0 0 1 \n" +
|
|
||||||
" 0 1 0 \n" +
|
|
||||||
" 0 1 0 \n" +
|
|
||||||
" 0 1 1 \n" +
|
|
||||||
" 1 1 1 \n" +
|
|
||||||
" 0 0 0 \n" +
|
|
||||||
" \n" +
|
|
||||||
" \n" +
|
|
||||||
" \n" +
|
|
||||||
" \n" +
|
|
||||||
" 0 0 0 0 1 0 \n" +
|
|
||||||
" 0 1 1 1 1 0 \n" +
|
|
||||||
" 1 0 0 1 1 0 \n" +
|
|
||||||
" \n" +
|
|
||||||
" \n" +
|
|
||||||
" \n" +
|
|
||||||
" \n" +
|
|
||||||
" \n" +
|
|
||||||
" \n" +
|
|
||||||
" \n" +
|
|
||||||
" \n";
|
|
||||||
// Actually, version 7 QR Code has 45x45 matrix but we use 21x21 here
|
// Actually, version 7 QR Code has 45x45 matrix but we use 21x21 here
|
||||||
// since 45x45 matrix is too big to depict.
|
// since 45x45 matrix is too big to depict.
|
||||||
ByteMatrix matrix = new ByteMatrix(21, 21);
|
ByteMatrix matrix = new ByteMatrix(21, 21);
|
||||||
MatrixUtil.clearMatrix(matrix);
|
MatrixUtil.clearMatrix(matrix);
|
||||||
MatrixUtil.maybeEmbedVersionInfo(7, matrix);
|
MatrixUtil.maybeEmbedVersionInfo(7, matrix);
|
||||||
|
String expected =
|
||||||
|
" 0 0 1 \n" +
|
||||||
|
" 0 1 0 \n" +
|
||||||
|
" 0 1 0 \n" +
|
||||||
|
" 0 1 1 \n" +
|
||||||
|
" 1 1 1 \n" +
|
||||||
|
" 0 0 0 \n" +
|
||||||
|
" \n" +
|
||||||
|
" \n" +
|
||||||
|
" \n" +
|
||||||
|
" \n" +
|
||||||
|
" 0 0 0 0 1 0 \n" +
|
||||||
|
" 0 1 1 1 1 0 \n" +
|
||||||
|
" 1 0 0 1 1 0 \n" +
|
||||||
|
" \n" +
|
||||||
|
" \n" +
|
||||||
|
" \n" +
|
||||||
|
" \n" +
|
||||||
|
" \n" +
|
||||||
|
" \n" +
|
||||||
|
" \n" +
|
||||||
|
" \n";
|
||||||
assertEquals(expected, matrix.toString());
|
assertEquals(expected, matrix.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmbedDataBits() throws WriterException {
|
public void testEmbedDataBits() throws WriterException {
|
||||||
// Cells other than basic patterns should be filled with zero.
|
// Cells other than basic patterns should be filled with zero.
|
||||||
String expected =
|
|
||||||
" 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1\n" +
|
|
||||||
" 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1\n" +
|
|
||||||
" 1 0 1 1 1 0 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1\n" +
|
|
||||||
" 1 0 1 1 1 0 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1\n" +
|
|
||||||
" 1 0 1 1 1 0 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1\n" +
|
|
||||||
" 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1\n" +
|
|
||||||
" 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1\n" +
|
|
||||||
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
|
||||||
" 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
|
||||||
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
|
||||||
" 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
|
||||||
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
|
||||||
" 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
|
||||||
" 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
|
||||||
" 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
|
||||||
" 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
|
||||||
" 1 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
|
||||||
" 1 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
|
||||||
" 1 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
|
||||||
" 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
|
||||||
" 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n";
|
|
||||||
BitArray bits = new BitArray();
|
BitArray bits = new BitArray();
|
||||||
ByteMatrix matrix = new ByteMatrix(21, 21);
|
ByteMatrix matrix = new ByteMatrix(21, 21);
|
||||||
MatrixUtil.clearMatrix(matrix);
|
MatrixUtil.clearMatrix(matrix);
|
||||||
MatrixUtil.embedBasicPatterns(1, matrix);
|
MatrixUtil.embedBasicPatterns(1, matrix);
|
||||||
MatrixUtil.embedDataBits(bits, -1, matrix);
|
MatrixUtil.embedDataBits(bits, -1, matrix);
|
||||||
|
String expected =
|
||||||
|
" 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1\n" +
|
||||||
|
" 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1\n" +
|
||||||
|
" 1 0 1 1 1 0 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1\n" +
|
||||||
|
" 1 0 1 1 1 0 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1\n" +
|
||||||
|
" 1 0 1 1 1 0 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1\n" +
|
||||||
|
" 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1\n" +
|
||||||
|
" 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1\n" +
|
||||||
|
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
||||||
|
" 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
||||||
|
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
||||||
|
" 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
||||||
|
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
||||||
|
" 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
||||||
|
" 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
||||||
|
" 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
||||||
|
" 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
||||||
|
" 1 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
||||||
|
" 1 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
||||||
|
" 1 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
||||||
|
" 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
|
||||||
|
" 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n";
|
||||||
assertEquals(expected, matrix.toString());
|
assertEquals(expected, matrix.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildMatrix() throws WriterException {
|
public void testBuildMatrix() throws WriterException {
|
||||||
// From http://www.swetake.com/qr/qr7.html
|
// From http://www.swetake.com/qr/qr7.html
|
||||||
String expected =
|
|
||||||
" 1 1 1 1 1 1 1 0 0 1 1 0 0 0 1 1 1 1 1 1 1\n" +
|
|
||||||
" 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1\n" +
|
|
||||||
" 1 0 1 1 1 0 1 0 0 0 0 1 0 0 1 0 1 1 1 0 1\n" +
|
|
||||||
" 1 0 1 1 1 0 1 0 0 1 1 0 0 0 1 0 1 1 1 0 1\n" +
|
|
||||||
" 1 0 1 1 1 0 1 0 1 1 0 0 1 0 1 0 1 1 1 0 1\n" +
|
|
||||||
" 1 0 0 0 0 0 1 0 0 0 1 1 1 0 1 0 0 0 0 0 1\n" +
|
|
||||||
" 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1\n" +
|
|
||||||
" 0 0 0 0 0 0 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0\n" +
|
|
||||||
" 0 0 1 1 0 0 1 1 1 0 0 1 1 1 1 0 1 0 0 0 0\n" +
|
|
||||||
" 1 0 1 0 1 0 0 0 0 0 1 1 1 0 0 1 0 1 1 1 0\n" +
|
|
||||||
" 1 1 1 1 0 1 1 0 1 0 1 1 1 0 0 1 1 1 0 1 0\n" +
|
|
||||||
" 1 0 1 0 1 1 0 1 1 1 0 0 1 1 1 0 0 1 0 1 0\n" +
|
|
||||||
" 0 0 1 0 0 1 1 1 0 0 0 0 0 0 1 0 1 1 1 1 1\n" +
|
|
||||||
" 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 1 0 1 1\n" +
|
|
||||||
" 1 1 1 1 1 1 1 0 1 1 1 1 0 0 0 0 1 0 1 1 0\n" +
|
|
||||||
" 1 0 0 0 0 0 1 0 0 0 0 1 0 1 1 1 0 0 0 0 0\n" +
|
|
||||||
" 1 0 1 1 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 1\n" +
|
|
||||||
" 1 0 1 1 1 0 1 0 1 1 0 1 0 0 0 0 0 1 1 1 0\n" +
|
|
||||||
" 1 0 1 1 1 0 1 0 1 1 1 1 0 0 0 0 1 1 1 0 0\n" +
|
|
||||||
" 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0\n" +
|
|
||||||
" 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 1 0 0 1 0\n";
|
|
||||||
char[] bytes = {32, 65, 205, 69, 41, 220, 46, 128, 236,
|
char[] bytes = {32, 65, 205, 69, 41, 220, 46, 128, 236,
|
||||||
42, 159, 74, 221, 244, 169, 239, 150, 138,
|
42, 159, 74, 221, 244, 169, 239, 150, 138,
|
||||||
70, 237, 85, 224, 96, 74, 219 , 61};
|
70, 237, 85, 224, 96, 74, 219 , 61};
|
||||||
|
@ -256,6 +234,28 @@ public final class MatrixUtilTestCase extends Assert {
|
||||||
1, // Version 1
|
1, // Version 1
|
||||||
3, // Mask pattern 3
|
3, // Mask pattern 3
|
||||||
matrix);
|
matrix);
|
||||||
|
String expected =
|
||||||
|
" 1 1 1 1 1 1 1 0 0 1 1 0 0 0 1 1 1 1 1 1 1\n" +
|
||||||
|
" 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1\n" +
|
||||||
|
" 1 0 1 1 1 0 1 0 0 0 0 1 0 0 1 0 1 1 1 0 1\n" +
|
||||||
|
" 1 0 1 1 1 0 1 0 0 1 1 0 0 0 1 0 1 1 1 0 1\n" +
|
||||||
|
" 1 0 1 1 1 0 1 0 1 1 0 0 1 0 1 0 1 1 1 0 1\n" +
|
||||||
|
" 1 0 0 0 0 0 1 0 0 0 1 1 1 0 1 0 0 0 0 0 1\n" +
|
||||||
|
" 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1\n" +
|
||||||
|
" 0 0 0 0 0 0 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0\n" +
|
||||||
|
" 0 0 1 1 0 0 1 1 1 0 0 1 1 1 1 0 1 0 0 0 0\n" +
|
||||||
|
" 1 0 1 0 1 0 0 0 0 0 1 1 1 0 0 1 0 1 1 1 0\n" +
|
||||||
|
" 1 1 1 1 0 1 1 0 1 0 1 1 1 0 0 1 1 1 0 1 0\n" +
|
||||||
|
" 1 0 1 0 1 1 0 1 1 1 0 0 1 1 1 0 0 1 0 1 0\n" +
|
||||||
|
" 0 0 1 0 0 1 1 1 0 0 0 0 0 0 1 0 1 1 1 1 1\n" +
|
||||||
|
" 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 1 0 1 1\n" +
|
||||||
|
" 1 1 1 1 1 1 1 0 1 1 1 1 0 0 0 0 1 0 1 1 0\n" +
|
||||||
|
" 1 0 0 0 0 0 1 0 0 0 0 1 0 1 1 1 0 0 0 0 0\n" +
|
||||||
|
" 1 0 1 1 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 1\n" +
|
||||||
|
" 1 0 1 1 1 0 1 0 1 1 0 1 0 0 0 0 0 1 1 1 0\n" +
|
||||||
|
" 1 0 1 1 1 0 1 0 1 1 1 1 0 0 0 0 1 1 1 0 0\n" +
|
||||||
|
" 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0\n" +
|
||||||
|
" 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 1 0 0 1 0\n";
|
||||||
assertEquals(expected, matrix.toString());
|
assertEquals(expected, matrix.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,27 +83,45 @@ public final class QRCodeTestCase extends Assert {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToString() {
|
public void testToString1() {
|
||||||
{
|
QRCode qrCode = new QRCode();
|
||||||
QRCode qrCode = new QRCode();
|
String expected =
|
||||||
String expected =
|
"<<\n" +
|
||||||
"<<\n" +
|
" mode: null\n" +
|
||||||
" mode: null\n" +
|
" ecLevel: null\n" +
|
||||||
" ecLevel: null\n" +
|
" version: -1\n" +
|
||||||
" version: -1\n" +
|
" matrixWidth: -1\n" +
|
||||||
" matrixWidth: -1\n" +
|
" maskPattern: -1\n" +
|
||||||
" maskPattern: -1\n" +
|
" numTotalBytes: -1\n" +
|
||||||
" numTotalBytes: -1\n" +
|
" numDataBytes: -1\n" +
|
||||||
" numDataBytes: -1\n" +
|
" numECBytes: -1\n" +
|
||||||
" numECBytes: -1\n" +
|
" numRSBlocks: -1\n" +
|
||||||
" numRSBlocks: -1\n" +
|
" matrix: null\n" +
|
||||||
" matrix: null\n" +
|
">>\n";
|
||||||
">>\n";
|
assertEquals(expected, qrCode.toString());
|
||||||
assertEquals(expected, qrCode.toString());
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testToString2() {
|
||||||
|
QRCode qrCode = new QRCode();
|
||||||
|
qrCode.setMode(Mode.BYTE);
|
||||||
|
qrCode.setECLevel(ErrorCorrectionLevel.H);
|
||||||
|
qrCode.setVersion(1);
|
||||||
|
qrCode.setMatrixWidth(21);
|
||||||
|
qrCode.setMaskPattern(3);
|
||||||
|
qrCode.setNumTotalBytes(26);
|
||||||
|
qrCode.setNumDataBytes(9);
|
||||||
|
qrCode.setNumECBytes(17);
|
||||||
|
qrCode.setNumRSBlocks(1);
|
||||||
|
ByteMatrix 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
{
|
qrCode.setMatrix(matrix);
|
||||||
String expected =
|
assertTrue(qrCode.isValid());
|
||||||
"<<\n" +
|
String expected = "<<\n" +
|
||||||
" mode: BYTE\n" +
|
" mode: BYTE\n" +
|
||||||
" ecLevel: H\n" +
|
" ecLevel: H\n" +
|
||||||
" version: 1\n" +
|
" version: 1\n" +
|
||||||
|
@ -136,26 +154,7 @@ public final class QRCodeTestCase extends Assert {
|
||||||
" 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\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" +
|
" 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" +
|
||||||
">>\n";
|
">>\n";
|
||||||
QRCode qrCode = new QRCode();
|
assertEquals(expected, qrCode.toString());
|
||||||
qrCode.setMode(Mode.BYTE);
|
|
||||||
qrCode.setECLevel(ErrorCorrectionLevel.H);
|
|
||||||
qrCode.setVersion(1);
|
|
||||||
qrCode.setMatrixWidth(21);
|
|
||||||
qrCode.setMaskPattern(3);
|
|
||||||
qrCode.setNumTotalBytes(26);
|
|
||||||
qrCode.setNumDataBytes(9);
|
|
||||||
qrCode.setNumECBytes(17);
|
|
||||||
qrCode.setNumRSBlocks(1);
|
|
||||||
ByteMatrix 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
qrCode.setMatrix(matrix);
|
|
||||||
assertTrue(qrCode.isValid());
|
|
||||||
assertEquals(expected, qrCode.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in a new issue