Style changes to Aztec, enable in web app and command line

git-svn-id: https://zxing.googlecode.com/svn/trunk@1669 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2010-11-21 20:47:00 +00:00
parent e1c047c54b
commit c4dede3689
8 changed files with 871 additions and 908 deletions

View file

@ -1,10 +1,26 @@
/*
* Copyright 2010 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.aztec;
import com.google.zxing.ResultPoint;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.DetectorResult;
public class AztecDetectorResult extends DetectorResult {
public final class AztecDetectorResult extends DetectorResult {
private final boolean compact;
private final int nbDatablocks;

View file

@ -1,5 +1,5 @@
/*
* Copyright 2007 ZXing authors
* Copyright 2010 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -28,7 +28,6 @@ import com.google.zxing.ResultMetadataType;
import com.google.zxing.ResultPoint;
import com.google.zxing.ResultPointCallback;
import com.google.zxing.common.DecoderResult;
import com.google.zxing.common.DetectorResult;
import com.google.zxing.aztec.decoder.Decoder;
import com.google.zxing.aztec.detector.Detector;
@ -41,8 +40,6 @@ import java.util.Hashtable;
*/
public final class AztecReader implements Reader {
private static final ResultPoint[] NO_POINTS = new ResultPoint[0];
/**
* Locates and decodes a Data Matrix code in an image.
*
@ -51,17 +48,15 @@ public final class AztecReader implements Reader {
* @throws FormatException if a Data Matrix code cannot be decoded
* @throws ChecksumException if error correction fails
*/
public Result decode(BinaryBitmap image) throws NotFoundException, ChecksumException, FormatException {
public Result decode(BinaryBitmap image) throws NotFoundException, FormatException {
return decode(image, null);
}
public Result decode(BinaryBitmap image, Hashtable hints)
throws NotFoundException, ChecksumException, FormatException {
DecoderResult decoderResult;
ResultPoint[] points;
throws NotFoundException, FormatException {
AztecDetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect();
points = detectorResult.getPoints();
ResultPoint[] points = detectorResult.getPoints();
if (hints != null && detectorResult.getPoints() != null) {
ResultPointCallback rpcb = (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
@ -72,7 +67,7 @@ public final class AztecReader implements Reader {
}
}
decoderResult = new Decoder().decode(detectorResult);
DecoderResult decoderResult = new Decoder().decode(detectorResult);
Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.AZTEC);

View file

@ -1,5 +1,5 @@
/*
* Copyright 2007 ZXing authors
* Copyright 2010 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,7 +16,6 @@
package com.google.zxing.aztec.decoder;
import com.google.zxing.ChecksumException;
import com.google.zxing.FormatException;
import com.google.zxing.aztec.AztecDetectorResult;
import com.google.zxing.common.BitMatrix;
@ -33,13 +32,61 @@ import com.google.zxing.common.reedsolomon.ReedSolomonException;
*/
public final class Decoder {
int numCodewords;
int codewordSize;
AztecDetectorResult ddata;
private static final int UPPER = 0;
private static final int LOWER = 1;
private static final int MIXED = 2;
private static final int DIGIT = 3;
private static final int PUNCT = 4;
private static final int BINARY = 5;
public Decoder() {}
private static final int[] NB_BITS_COMPACT = {
0, 104, 240, 408, 608
};
public DecoderResult decode(AztecDetectorResult detectorResult) throws FormatException, ChecksumException {
private static final int[] NB_BITS = {
0, 128, 288, 480, 704, 960, 1248, 1568, 1920, 2304, 2720, 3168, 3648, 4160, 4704, 5280, 5888, 6528,
7200, 7904, 8640, 9408, 10208, 11040, 11904, 12800, 13728, 14688, 15680, 16704, 17760, 18848, 19968
};
private static final int[] NB_DATABLOCK_COMPACT = {
0, 17, 40, 51, 76
};
private static final int[] NB_DATABLOCK = {
0, 21, 48, 60, 88, 120, 156, 196, 240, 230, 272, 316, 364, 416, 470, 528, 588, 652, 720, 790, 864,
940, 1020, 920, 992, 1066, 1144, 1224, 1306, 1392, 1480, 1570, 1664
};
private static final String[] UPPER_TABLE = {
"CTRL_PS", " ", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P",
"Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "CTRL_LL", "CTRL_ML", "CTRL_DL", "CTRL_BS"
};
private static final String[] LOWER_TABLE = {
"CTRL_PS", " ", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p",
"q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "CTRL_US", "CTRL_ML", "CTRL_DL", "CTRL_BS"
};
private static final String[] MIXED_TABLE = {
"CTRL_PS", " ", "\1", "\2", "\3", "\4", "\5", "\6", "\7", "\b", "\t", "\n",
"\13", "\f", "\r", "\33", "\34", "\35", "\36", "\37", "@", "\\", "^", "_",
"`", "|", "~", "\177", "CTRL_LL", "CTRL_UL", "CTRL_PL", "CTRL_BS"
};
private static final String[] PUNCT_TABLE = {
"", "\r", "\r\n", ". ", ", ", ": ", "!", "\"", "#", "$", "%", "&", "'", "(", ")",
"*", "+", ",", "-", ".", "/", ":", ";", "<", "=", ">", "?", "[", "]", "{", "}", "CTRL_UL"
};
private static final String[] DIGIT_TABLE = {
"CTRL_PS", " ", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ",", ".", "CTRL_UL", "CTRL_US"
};
private int numCodewords;
private int codewordSize;
private AztecDetectorResult ddata;
public DecoderResult decode(AztecDetectorResult detectorResult) throws FormatException {
ddata = detectorResult;
BitMatrix matrix = detectorResult.getBits();
@ -61,7 +108,6 @@ public final class Decoder {
*
* Gets the string encoded in the aztec code bits
*
* @param correctedBits
* @return the decoded string
* @throws FormatException if the input is not valid
*/
@ -75,8 +121,7 @@ public final class Decoder {
int lastTable = UPPER;
int table = UPPER;
int startIndex = 0;
int code;
StringBuilder result = new StringBuilder();
StringBuilder result = new StringBuilder(20);
boolean end = false;
boolean shift = false;
boolean switchShift = false;
@ -91,6 +136,7 @@ public final class Decoder {
lastTable = table;
}
int code;
switch (table) {
case BINARY:
if (endIndex - startIndex < 8) {
@ -119,15 +165,15 @@ public final class Decoder {
startIndex += size;
String str = getCharacter(table, code);
if (!str.startsWith("CTRL_")){
result.append(str);
} else {
if (str.startsWith("CTRL_")) {
// Table changes
table = getTable(str.charAt(5));
if (str.charAt(6) == 'S') {
shift = true;
}
} else {
result.append(str);
}
break;
@ -145,28 +191,30 @@ public final class Decoder {
/**
*
* gets the table corresponding to the char passed
*
* @param t
* @return
*/
private int getTable(char t) {
private static int getTable(char t) {
int table = UPPER;
switch (t) {
case 'U':
table = UPPER; break;
table = UPPER;
break;
case 'L':
table = LOWER; break;
table = LOWER;
break;
case 'P':
table = PUNCT; break;
table = PUNCT;
break;
case 'M':
table = MIXED; break;
table = MIXED;
break;
case 'D':
table = DIGIT; break;
table = DIGIT;
break;
case 'B':
table = BINARY; break;
table = BINARY;
break;
}
return table;
@ -178,9 +226,8 @@ public final class Decoder {
*
* @param table the table used
* @param code the code of the character
* @return
*/
private String getCharacter(int table, int code) {
private static String getCharacter(int table, int code) {
switch (table) {
case UPPER:
return UPPER_TABLE[code];
@ -201,7 +248,6 @@ public final class Decoder {
*
* <p> performs RS error correction on an array of bits </p>
*
* @param rawbits
* @return the corrected array
* @throws FormatException if the input contains too many errors
*/
@ -223,15 +269,15 @@ public final class Decoder {
}
int numDataCodewords = ddata.getNbDatablocks();
int numECCodewords = 0;
int offset = 0;
int numECCodewords;
int offset;
if (ddata.isCompact()) {
offset = NbBitsCompact[ddata.getNbLayers()] - numCodewords*codewordSize;
numECCodewords = NbDatablockCompact[ddata.getNbLayers()] - numDataCodewords;
offset = NB_BITS_COMPACT[ddata.getNbLayers()] - numCodewords*codewordSize;
numECCodewords = NB_DATABLOCK_COMPACT[ddata.getNbLayers()] - numDataCodewords;
} else {
offset = NbBits[ddata.getNbLayers()] - numCodewords*codewordSize;
numECCodewords = NbDatablock[ddata.getNbLayers()] - numDataCodewords;
offset = NB_BITS[ddata.getNbLayers()] - numCodewords*codewordSize;
numECCodewords = NB_DATABLOCK[ddata.getNbLayers()] - numDataCodewords;
}
int[] dataWords = new int[numCodewords];
@ -244,17 +290,15 @@ public final class Decoder {
flag <<= 1;
}
if (dataWords[i] >= flag){
flag++;
//if (dataWords[i] >= flag) {
// flag++;
//}
}
}
rawbits = null;
try {
ReedSolomonDecoder rsDecoder = new ReedSolomonDecoder(gf);
rsDecoder.decode(dataWords, numECCodewords);
} catch (ReedSolomonException rse) {
System.out.println("END: invalid RS");
throw FormatException.getFormatInstance();
}
@ -271,7 +315,17 @@ public final class Decoder {
boolean color = (dataWords[i] & flag) == flag;
if (seriesCount != codewordSize - 1){
if (seriesCount == codewordSize - 1) {
if (color == seriesColor) {
//bit must be inverted
throw FormatException.getFormatInstance();
}
seriesColor = false;
seriesCount = 0;
offset++;
} else {
if (seriesColor == color) {
seriesCount++;
@ -282,16 +336,6 @@ public final class Decoder {
correctedBits[i * codewordSize + j - offset] = color;
} else {
if (color == seriesColor){
//bit must be inverted
throw FormatException.getFormatInstance();
}
seriesColor = false;
seriesCount = 0;
offset++;
}
flag >>>= 1;
@ -305,7 +349,6 @@ public final class Decoder {
*
* Gets the array of bits from an Aztec Code matrix
*
* @param matrix
* @return the array of bits
* @throws FormatException if the matrix is not a valid aztec code
*/
@ -313,20 +356,19 @@ public final class Decoder {
boolean[] rawbits;
if (ddata.isCompact()) {
if (ddata.getNbLayers() > NbBitsCompact.length){
if (ddata.getNbLayers() > NB_BITS_COMPACT.length) {
throw FormatException.getFormatInstance();
}
rawbits = new boolean[NbBitsCompact[ddata.getNbLayers()]];
numCodewords = NbDatablockCompact[ddata.getNbLayers()];
rawbits = new boolean[NB_BITS_COMPACT[ddata.getNbLayers()]];
numCodewords = NB_DATABLOCK_COMPACT[ddata.getNbLayers()];
} else {
if (ddata.getNbLayers() > NbBits.length){
if (ddata.getNbLayers() > NB_BITS.length) {
throw FormatException.getFormatInstance();
}
rawbits = new boolean[NbBits[ddata.getNbLayers()]];
numCodewords = NbDatablock[ddata.getNbLayers()];
rawbits = new boolean[NB_BITS[ddata.getNbLayers()]];
numCodewords = NB_DATABLOCK[ddata.getNbLayers()];
}
int flip;
int layer = ddata.getNbLayers();
int size = matrix.height;
int rawbitsOffset = 0;
@ -334,7 +376,7 @@ public final class Decoder {
while (layer != 0) {
flip = 0;
int flip = 0;
for (int i = 0; i < 2*size - 4; i++) {
rawbits[rawbitsOffset+i] = matrix.get(matrixOffset + flip, matrixOffset + i/2);
rawbits[rawbitsOffset+2*size - 4 + i] = matrix.get(matrixOffset + i/2, matrixOffset + size-1-flip);
@ -359,27 +401,21 @@ public final class Decoder {
/**
*
* <p> Transforms an aztec code matrix by removing the control dashed lines </p>
*
* @param matrix
* @return
* Transforms an Aztec code matrix by removing the control dashed lines
*/
private BitMatrix removeDashedLines(BitMatrix matrix) {
private static BitMatrix removeDashedLines(BitMatrix matrix) {
int nbDashed = 1+ 2* ((matrix.width - 1)/2 / 16);
BitMatrix newMatrix = new BitMatrix(matrix.width - nbDashed, matrix.height - nbDashed);
int nx = 0;
int ny = 0;
for (int x = 0; x < matrix.width; x++) {
ny = 0;
if ((matrix.width / 2 - x)%16 == 0) {
continue;
}
int ny = 0;
for (int y = 0; y < matrix.height; y++) {
if ((matrix.width / 2 - y)%16 == 0) {
@ -398,19 +434,13 @@ public final class Decoder {
}
/**
*
* Reads a code of given length and at given index in an array of bits
*
* @param rawbits
* @param startIndex
* @param length
* @return
*/
private int readCode(boolean[] rawbits, int startIndex, int length) {
private static int readCode(boolean[] rawbits, int startIndex, int length) {
int res = 0;
for (int i = startIndex; i < startIndex + length; i++) {
res = res << 1;
res <<= 1;
if (rawbits[i]) {
res++;
}
@ -419,49 +449,4 @@ public final class Decoder {
return res;
}
static final int UPPER = 0;
static final int LOWER = 1;
static final int MIXED = 2;
static final int DIGIT = 3;
static final int PUNCT = 4;
static final int BINARY = 5;
static final int NbBitsCompact[] = {
0,104, 240, 408, 608
};
static final int NbBits[] = {
0, 128, 288, 480, 704, 960, 1248, 1568, 1920, 2304, 2720, 3168, 3648, 4160, 4704, 5280, 5888, 6528, 7200, 7904, 8640, 9408, 10208, 11040, 11904, 12800, 13728, 14688, 15680, 16704, 17760, 18848, 19968
};
static final int NbDatablockCompact[] = {
0, 17, 40, 51, 76
};
static final int NbDatablock[] = {
0, 21, 48, 60, 88, 120, 156, 196, 240, 230, 272, 316, 364, 416, 470, 528, 588, 652, 720, 790, 864, 940, 1020, 920, 992, 1066, 1144, 1224, 1306, 1392, 1480, 1570, 1664
};
static final String UPPER_TABLE[] = {
"CTRL_PS", " ", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "CTRL_LL", "CTRL_ML", "CTRL_DL", "CTRL_BS"
};
static final String LOWER_TABLE[] = {
"CTRL_PS", " ", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "CTRL_US", "CTRL_ML", "CTRL_DL", "CTRL_BS"
};
static final String MIXED_TABLE[] = {
"CTRL_PS", " ", ""+(char)1, ""+(char)2, ""+(char)3, ""+(char)4, ""+(char)5, ""+(char)6, ""+(char)7, ""+(char)8, ""+(char)9, ""+(char)10, ""+(char)11, ""+(char)12, ""+(char)13, ""+(char)27, ""+(char)28, ""+(char)29, ""+(char)30, ""+(char)31, "@", "\\", "^", ""+(char)95, "`", "|", "~", ""+(char)127, "CTRL_LL", "CTRL_UL", "CTRL_PL", "CTRL_BS"
};
static final String PUNCT_TABLE[] = {
"", ""+(char)13, ""+(char)13+(char)10, ""+(char)46+(char)32, ""+(char)44+(char)32, ""+(char)58+(char)32, "!", "\"", "#", "$", "%", "&", "'", "(", ")", ""+(char)42, "+", ",", "-", ".", "/", ":", ";", "<", "=", ">", "?", "[", "]", "{", "}", "CTRL_UL"
};
static final String DIGIT_TABLE[] = {
"CTRL_PS", " ", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ",", ".", "CTRL_UL", "CTRL_US"
};
}

View file

@ -1,5 +1,5 @@
/*
* Copyright 2008 ZXing authors
* Copyright 2010 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -87,17 +87,14 @@ public final class Detector {
boolean[] rescd = sampleLine(bullEyeCornerPoints[2], bullEyeCornerPoints[3], 2*nbCenterLayers+1);
boolean[] resda = sampleLine(bullEyeCornerPoints[3], bullEyeCornerPoints[0], 2*nbCenterLayers+1);
boolean[] shiftedParameterData;
boolean[] parameterData;
// Determine the orientation of the matrix
if (resab[0]==true && resab[2*nbCenterLayers]==true){
if (resab[0] && resab[2 * nbCenterLayers]) {
shift = 0;
} else if (resbc[0]==true && resbc[2*nbCenterLayers]==true){
} else if (resbc[0] && resbc[2 * nbCenterLayers]) {
shift = 1;
} else if (rescd[0]==true && rescd[2*nbCenterLayers]==true){
} else if (rescd[0] && rescd[2 * nbCenterLayers]) {
shift = 2;
} else if (resda[0]==true && resda[2*nbCenterLayers]==true){
} else if (resda[0] && resda[2 * nbCenterLayers]) {
shift = 3;
} else {
throw NotFoundException.getNotFoundInstance();
@ -108,6 +105,8 @@ public final class Detector {
//c b
// Flatten the bits in a single array
boolean[] parameterData;
boolean[] shiftedParameterData;
if (compact) {
shiftedParameterData = new boolean[28];
for (int i = 0; i < 7; i++) {
@ -199,11 +198,10 @@ public final class Detector {
* @param compact true if this is a compact Aztec code
* @throws NotFoundException if the array contains too many errors
*/
private void correctParameterData(boolean[] parameterData, boolean compact) throws NotFoundException {
private static void correctParameterData(boolean[] parameterData, boolean compact) throws NotFoundException {
int numCodewords;
int numDataCodewords;
int codewordSize = 4;
if (compact) {
numCodewords = 7;
@ -216,6 +214,7 @@ public final class Detector {
int numECCodewords = numCodewords - numDataCodewords;
int[] parameterWords = new int[numCodewords];
int codewordSize = 4;
for (int i = 0; i < numCodewords; i++) {
int flag = 1;
for (int j = 1; j <= codewordSize; j++) {
@ -256,25 +255,21 @@ public final class Detector {
Point pinb = pCenter;
Point pinc = pCenter;
Point pind = pCenter;
Point pouta;
Point poutb;
Point poutc;
Point poutd;
boolean color = true;
for (nbCenterLayers = 1; nbCenterLayers < 9; nbCenterLayers++) {
pouta = getFirstDifferent(pina, color, 1, -1);
poutb = getFirstDifferent(pinb, color, 1, 1);
poutc = getFirstDifferent(pinc, color, -1, 1);
poutd = getFirstDifferent(pind, color, -1, -1);
Point pouta = getFirstDifferent(pina, color, 1, -1);
Point poutb = getFirstDifferent(pinb, color, 1, 1);
Point poutc = getFirstDifferent(pinc, color, -1, 1);
Point poutd = getFirstDifferent(pind, color, -1, -1);
//d a
//
//c b
if (nbCenterLayers>2) {
float q = (float)distance(poutd, pouta)*nbCenterLayers/(distance(pind, pina)*(nbCenterLayers+2));
float q = distance(poutd, pouta)*nbCenterLayers/(distance(pind, pina)*(nbCenterLayers+2));
if ( q < 0.75 || q > 1.25 || !isWhiteOrBlackRectangle(pouta, poutb, poutc, poutd)) {
break;
}
@ -311,7 +306,8 @@ public final class Detector {
int targetbx = round(pinb.x+ratio*dx);
int targetby = round(pinb.y+ratio*dy);
if (!isValid(targetax, targetay) || !isValid(targetbx, targetby) || !isValid(targetcx, targetcy) || !isValid(targetdx, targetdy)){
if (!isValid(targetax, targetay) || !isValid(targetbx, targetby)
|| !isValid(targetcx, targetcy) || !isValid(targetdx, targetdy)) {
throw NotFoundException.getNotFoundInstance();
}
@ -386,22 +382,11 @@ public final class Detector {
cx = round((pointA.getX() + pointD.getX() + pointB.getX() + pointC.getX())/4);
cy = round((pointA.getY() + pointD.getY() + pointB.getY() + pointC.getY())/4);
Point pCenter = new Point(cx, cy);
return pCenter;
return new Point(cx, cy);
}
/**
*
* Samples an Aztec matrix from an image
*
* @param image
* @param topLeft
* @param bottomLeft
* @param bottomRight
* @param topRight
* @return
* @throws NotFoundException
*/
private BitMatrix sampleGrid(BitMatrix image,
ResultPoint topLeft,
@ -444,15 +429,12 @@ public final class Detector {
}
/**
*
* Sets number of layers and number of datablocks from parameter bits
*
* @param parameterData
*/
private void getParameters(boolean[] parameterData) {
int nbBitsForNbLayers = 0;
int nbBitsForNbDatablocks = 0;
int nbBitsForNbLayers;
int nbBitsForNbDatablocks;
if (compact) {
nbBitsForNbLayers = 2;
@ -463,14 +445,14 @@ public final class Detector {
}
for (int i = 0; i < nbBitsForNbLayers; i++) {
nbLayers = nbLayers << 1;
nbLayers <<= 1;
if (parameterData[i]) {
nbLayers += 1;
}
}
for (int i = nbBitsForNbLayers; i < nbBitsForNbLayers + nbBitsForNbDatablocks; i++) {
nbDataBlocks = nbDataBlocks << 1;
nbDataBlocks <<= 1;
if (parameterData[i]) {
nbDataBlocks += 1;
}
@ -495,8 +477,8 @@ public final class Detector {
boolean[] res = new boolean[size];
float d = distance(p1,p2);
float moduleSize = d/(size-1);
float dx = moduleSize*(p2.x - p1.x)/(float)d;
float dy = moduleSize*(p2.y - p1.y)/(float)d;
float dx = moduleSize*(p2.x - p1.x)/d;
float dy = moduleSize*(p2.y - p1.y)/d;
float px = p1.x;
float py = p1.y;
@ -511,14 +493,8 @@ public final class Detector {
}
/**
*
* <p> returns true if the border of the rectangle passed in parameter is compound of white points only or black points only</p>
*
* @param p1
* @param p2
* @param p3
* @param p4
* @return
* @return true if the border of the rectangle passed in parameter is compound of white points only
* or black points only
*/
private boolean isWhiteOrBlackRectangle(Point p1, Point p2, Point p3, Point p4) {
@ -549,19 +525,13 @@ private boolean isWhiteOrBlackRectangle(Point p1, Point p2, Point p3, Point p4)
c = getColor(p3, p4);
if (c!=cInit || c == 0){
return false;
}
return c == cInit && c != 0;
return true;
}
/**
*
* Gets the color of a segment
*
* @param p1
* @param p2
* @return 1 if segment more than 90% black, -1 if segment is more than 90% white, 0 else
*/
private int getColor(Point p1, Point p2) {
@ -597,14 +567,7 @@ private int getColor(Point p1, Point p2) {
}
/**
*
* Gets the coordinate of the first point with a different color in the given direction
*
* @param init Initial point
* @param color Color wanted
* @param dx
* @param dy
* @return
*/
private Point getFirstDifferent(Point init, boolean color, int dx, int dy) {
int x = init.x+dx;
@ -631,15 +594,15 @@ private Point getFirstDifferent(Point init, boolean color, int dx, int dy){
return new Point(x,y);
}
private class Point {
public int x;
public int y;
private static class Point {
public final int x;
public final int y;
public ResultPoint toResultPoint() {
return new ResultPoint(x, y);
}
public Point(int x, int y){
private Point(int x, int y) {
this.x = x;
this.y = y;
}

View file

@ -32,25 +32,25 @@ import com.google.zxing.common.BitMatrix;
*/
public final class WhiteRectangleDetector {
private final int INIT_SIZE = 30;
private final int CORR = 1;
private static final int INIT_SIZE = 30;
private static final int CORR = 1;
private final BitMatrix image;
private final int height;
private final int width;
private final int left_init;
private final int right_init;
private final int down_init;
private final int up_init;
private final int leftInit;
private final int rightInit;
private final int downInit;
private final int upInit;
public WhiteRectangleDetector(BitMatrix image) {
this.image = image;
height = image.getHeight();
width = image.getWidth();
left_init = (width - INIT_SIZE) >> 1;
right_init = (width + INIT_SIZE) >> 1;
up_init = (height - INIT_SIZE) >> 1;
down_init = (height + INIT_SIZE) >> 1;
leftInit = (width - INIT_SIZE) >> 1;
rightInit = (width + INIT_SIZE) >> 1;
upInit = (height - INIT_SIZE) >> 1;
downInit = (height + INIT_SIZE) >> 1;
}
public WhiteRectangleDetector(BitMatrix image, int INIT_SIZE, int x, int y) {
@ -58,10 +58,10 @@ public final class WhiteRectangleDetector {
height = image.getHeight();
width = image.getWidth();
int halfsize = INIT_SIZE >> 1;
left_init = x - halfsize;
right_init = x + halfsize;
up_init = y - halfsize;
down_init = y + halfsize;
leftInit = x - halfsize;
rightInit = x + halfsize;
upInit = y - halfsize;
downInit = y + halfsize;
}
/**
@ -80,10 +80,10 @@ public final class WhiteRectangleDetector {
*/
public ResultPoint[] detect() throws NotFoundException {
int left = left_init;
int right = right_init;
int up = up_init;
int down = down_init;
int left = leftInit;
int right = rightInit;
int up = upInit;
int down = downInit;
boolean sizeExceeded = false;
boolean aBlackPointFoundOnBorder = true;
boolean atLeastOneBlackPointFoundOnBorder = false;

View file

@ -85,7 +85,9 @@ public final class GenericGF {
}
private void checkInit(){
if (!initialized) initialize();
if (!initialized) {
initialize();
}
}
GenericGFPoly getZero() {

View file

@ -122,8 +122,9 @@ public final class CommandLineRunner {
vector.addElement(BarcodeFormat.ITF);
vector.addElement(BarcodeFormat.QR_CODE);
vector.addElement(BarcodeFormat.DATA_MATRIX);
vector.addElement(BarcodeFormat.AZTEC);
vector.addElement(BarcodeFormat.PDF417);
//vector.addElement(BarcodeFormat.CODABAR);
vector.addElement(BarcodeFormat.CODABAR);
}
hints.put(DecodeHintType.POSSIBLE_FORMATS, vector);
if (tryHarder) {

View file

@ -109,11 +109,12 @@ public final class DecodeServlet extends HttpServlet {
possibleFormats.add(BarcodeFormat.CODE_39);
possibleFormats.add(BarcodeFormat.CODE_93);
possibleFormats.add(BarcodeFormat.CODE_128);
//possibleFormats.add(BarcodeFormat.CODABAR);
possibleFormats.add(BarcodeFormat.CODABAR);
possibleFormats.add(BarcodeFormat.ITF);
possibleFormats.add(BarcodeFormat.RSS14);
possibleFormats.add(BarcodeFormat.QR_CODE);
possibleFormats.add(BarcodeFormat.DATA_MATRIX);
possibleFormats.add(BarcodeFormat.AZTEC);
possibleFormats.add(BarcodeFormat.PDF417);
HINTS.put(DecodeHintType.POSSIBLE_FORMATS, possibleFormats);
HINTS_PURE = new Hashtable<DecodeHintType, Object>(HINTS);