mirror of
https://github.com/zxing/zxing.git
synced 2025-01-12 11:47:26 -08:00
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:
parent
0be4184870
commit
727cc95858
|
@ -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++) {
|
||||
|
|
|
@ -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++) {
|
||||
|
|
1
core/test/data/blackbox/upce-1/1.txt
Normal file
1
core/test/data/blackbox/upce-1/1.txt
Normal file
|
@ -0,0 +1 @@
|
|||
01234565
|
1
core/test/data/blackbox/upce-1/1.url
Normal file
1
core/test/data/blackbox/upce-1/1.url
Normal file
|
@ -0,0 +1 @@
|
|||
http://www.ciax.com/manuals/ref/images/upce_1.gif
|
1
core/test/data/blackbox/upce-1/2.txt
Normal file
1
core/test/data/blackbox/upce-1/2.txt
Normal file
|
@ -0,0 +1 @@
|
|||
00123457
|
1
core/test/data/blackbox/upce-1/2.url
Normal file
1
core/test/data/blackbox/upce-1/2.url
Normal file
|
@ -0,0 +1 @@
|
|||
http://www.gs1.org/images/barcodes/UPC_E.gif
|
1
core/test/data/blackbox/upce-1/4.txt
Normal file
1
core/test/data/blackbox/upce-1/4.txt
Normal file
|
@ -0,0 +1 @@
|
|||
01234531
|
1
core/test/data/blackbox/upce-1/4.url
Normal file
1
core/test/data/blackbox/upce-1/4.url
Normal file
|
@ -0,0 +1 @@
|
|||
http://www.varlink.co.uk/Images/gls_upcE.jpg
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue