Fixed a few more extractPureBits() gotchas that came up, and added a couple tests for UPC-E

git-svn-id: https://zxing.googlecode.com/svn/trunk@269 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2008-03-11 17:43:32 +00:00
parent 0be4184870
commit 727cc95858
10 changed files with 56 additions and 4 deletions

View file

@ -98,7 +98,7 @@ public final class DataMatrixReader implements Reader {
int moduleSize = moduleEnd - borderWidth;
// And now find where the bottommost black module on the first column ends
int columnEndOfSymbol = image.getHeight() - 1;
int columnEndOfSymbol = height - 1;
while (columnEndOfSymbol >= 0 && !image.isBlack(borderWidth, columnEndOfSymbol)) {
columnEndOfSymbol--;
}
@ -119,6 +119,11 @@ public final class DataMatrixReader implements Reader {
// little off, this will help recover.
borderWidth += moduleSize >> 1;
int sampleDimension = borderWidth + (dimension - 1) * moduleSize;
if (sampleDimension >= width || sampleDimension >= height) {
throw new ReaderException("Estimated pure image size is beyond image boundaries");
}
// Now just read off the bits
BitMatrix bits = new BitMatrix(dimension);
for (int i = 0; i < dimension; i++) {

View file

@ -76,7 +76,9 @@ public final class QRCodeReader implements Reader {
private static BitMatrix extractPureBits(MonochromeBitmapSource image) throws ReaderException {
// Now need to determine module size in pixels
int minDimension = Math.min(image.getHeight(), image.getWidth());
int height = image.getHeight();
int width = image.getWidth();
int minDimension = Math.min(height, width);
// First, skip white border by tracking diagonally from the top left down and to the right:
int borderWidth = 0;
@ -99,7 +101,7 @@ public final class QRCodeReader implements Reader {
int moduleSize = moduleEnd - borderWidth;
// And now find where the rightmost black module on the first row ends
int rowEndOfSymbol = image.getWidth() - 1;
int rowEndOfSymbol = width - 1;
while (rowEndOfSymbol >= 0 && !image.isBlack(rowEndOfSymbol, borderWidth)) {
rowEndOfSymbol--;
}
@ -120,6 +122,11 @@ public final class QRCodeReader implements Reader {
// little off, this will help recover.
borderWidth += moduleSize >> 1;
int sampleDimension = borderWidth + (dimension - 1) * moduleSize;
if (sampleDimension >= width || sampleDimension >= height) {
throw new ReaderException("Estimated pure image size is beyond image boundaries");
}
// Now just read off the bits
BitMatrix bits = new BitMatrix(dimension);
for (int i = 0; i < dimension; i++) {

View file

@ -0,0 +1 @@
01234565

View file

@ -0,0 +1 @@
http://www.ciax.com/manuals/ref/images/upce_1.gif

View file

@ -0,0 +1 @@
00123457

View file

@ -0,0 +1 @@
http://www.gs1.org/images/barcodes/UPC_E.gif

View file

@ -0,0 +1 @@
01234531

View file

@ -0,0 +1 @@
http://www.varlink.co.uk/Images/gls_upcE.jpg

View file

@ -28,7 +28,7 @@ import java.io.File;
public final class EAN8BlackBox1TestCase extends AbstractBlackBoxTestCase {
public EAN8BlackBox1TestCase() {
super(new File("test/data/blackbox/ean8-1"), new MultiFormatReader(), 0.66, BarcodeFormat.EAN_8);
super(new File("test/data/blackbox/ean8-1"), new MultiFormatReader(), 1.0, BarcodeFormat.EAN_8);
}
}

View file

@ -0,0 +1,34 @@
/*
* Copyright 2008 Google Inc.
*
* 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.oned;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.common.AbstractBlackBoxTestCase;
import java.io.File;
/**
* @author srowen@google.com (Sean Owen)
*/
public final class UPCEBlackBox1TestCase extends AbstractBlackBoxTestCase {
public UPCEBlackBox1TestCase() {
super(new File("test/data/blackbox/upce-1"), new MultiFormatReader(), 1.0, BarcodeFormat.UPC_E);
}
}