mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Oops, delete old files that were moved
git-svn-id: https://zxing.googlecode.com/svn/trunk@280 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
94e3009849
commit
b6e14d880d
|
@ -1,89 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2007 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.qrcode.detector;
|
|
||||||
|
|
||||||
import com.google.zxing.MonochromeBitmapSource;
|
|
||||||
import com.google.zxing.ReaderException;
|
|
||||||
import com.google.zxing.common.BitMatrix;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author srowen@google.com (Sean Owen)
|
|
||||||
*/
|
|
||||||
public final class DefaultGridSampler extends GridSampler {
|
|
||||||
|
|
||||||
protected BitMatrix sampleGrid(MonochromeBitmapSource image,
|
|
||||||
FinderPattern topLeft,
|
|
||||||
FinderPattern topRight,
|
|
||||||
FinderPattern bottomLeft,
|
|
||||||
AlignmentPattern alignmentPattern,
|
|
||||||
int dimension) throws ReaderException {
|
|
||||||
float dimMinusThree = (float) dimension - 3.5f;
|
|
||||||
float bottomRightX, bottomRightY;
|
|
||||||
float sourceBottomRightX, sourceBottomRightY;
|
|
||||||
if (alignmentPattern != null) {
|
|
||||||
bottomRightX = alignmentPattern.getX();
|
|
||||||
bottomRightY = alignmentPattern.getY();
|
|
||||||
sourceBottomRightX = sourceBottomRightY = dimMinusThree - 3.0f;
|
|
||||||
} else {
|
|
||||||
// Don't have an alignment pattern, just make up the bottom-right point
|
|
||||||
bottomRightX = (topRight.getX() - topLeft.getX()) + bottomLeft.getX();
|
|
||||||
bottomRightY = (topRight.getY() - topLeft.getY()) + bottomLeft.getY();
|
|
||||||
sourceBottomRightX = sourceBottomRightY = dimMinusThree;
|
|
||||||
}
|
|
||||||
|
|
||||||
PerspectiveTransform transform = PerspectiveTransform.quadrilateralToQuadrilateral(
|
|
||||||
3.5f,
|
|
||||||
3.5f,
|
|
||||||
dimMinusThree,
|
|
||||||
3.5f,
|
|
||||||
sourceBottomRightX,
|
|
||||||
sourceBottomRightY,
|
|
||||||
3.5f,
|
|
||||||
dimMinusThree,
|
|
||||||
topLeft.getX(),
|
|
||||||
topLeft.getY(),
|
|
||||||
topRight.getX(),
|
|
||||||
topRight.getY(),
|
|
||||||
bottomRightX,
|
|
||||||
bottomRightY,
|
|
||||||
bottomLeft.getX(),
|
|
||||||
bottomLeft.getY());
|
|
||||||
|
|
||||||
BitMatrix bits = new BitMatrix(dimension);
|
|
||||||
float[] points = new float[dimension << 1];
|
|
||||||
for (int i = 0; i < dimension; i++) {
|
|
||||||
int max = points.length;
|
|
||||||
float iValue = (float) i + 0.5f;
|
|
||||||
for (int j = 0; j < max; j += 2) {
|
|
||||||
points[j] = (float) (j >> 1) + 0.5f;
|
|
||||||
points[j + 1] = iValue;
|
|
||||||
}
|
|
||||||
transform.transformPoints(points);
|
|
||||||
// Quick check to see if points transformed to something inside the image;
|
|
||||||
// sufficent to check the endpoints
|
|
||||||
checkEndpoint(image, points);
|
|
||||||
for (int j = 0; j < max; j += 2) {
|
|
||||||
if (image.isBlack((int) points[j], (int) points[j + 1])) {
|
|
||||||
// Black(-ish) pixel
|
|
||||||
bits.set(i, j >> 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return bits;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,128 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2007 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.qrcode.detector;
|
|
||||||
|
|
||||||
import com.google.zxing.MonochromeBitmapSource;
|
|
||||||
import com.google.zxing.ReaderException;
|
|
||||||
import com.google.zxing.common.BitMatrix;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementations of this class can, given locations of finder patterns for a QR code in an
|
|
||||||
* image, sample the right points in the image to reconstruct the QR code, accounting for
|
|
||||||
* perspective distortion. It is abstracted since it is relatively expensive and should be allowed
|
|
||||||
* to take advantage of platform-specific optimized implementations, like Sun's Java Advanced
|
|
||||||
* Imaging library, but which may not be available in other environments such as J2ME, and vice
|
|
||||||
* versa.
|
|
||||||
*
|
|
||||||
* The implementation used can be controlled by calling {@link #setGridSampler(GridSampler)}
|
|
||||||
* with an instance of a class which implements this interface.
|
|
||||||
*
|
|
||||||
* @author srowen@google.com (Sean Owen)
|
|
||||||
*/
|
|
||||||
public abstract class GridSampler {
|
|
||||||
|
|
||||||
private static GridSampler gridSampler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the implementation of {@link GridSampler} used by the library. One global
|
|
||||||
* instance is stored, which may sound problematic. But, the implementation provided
|
|
||||||
* ought to be appropriate for the entire platform, and all uses of this library
|
|
||||||
* in the whole lifetime of the JVM. For instance, an Android activity can swap in
|
|
||||||
* an implementation that takes advantage of native platform libraries.
|
|
||||||
*
|
|
||||||
* @param newGridSampler
|
|
||||||
*/
|
|
||||||
public static void setGridSampler(GridSampler newGridSampler) {
|
|
||||||
if (newGridSampler == null) {
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
gridSampler = newGridSampler;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the current implementation of {@link GridSampler}
|
|
||||||
*/
|
|
||||||
public static GridSampler getInstance() {
|
|
||||||
if (gridSampler == null) {
|
|
||||||
gridSampler = new DefaultGridSampler();
|
|
||||||
}
|
|
||||||
return gridSampler;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Given an image, locations of a QR Code's finder patterns and bottom-right alignment pattern,
|
|
||||||
* and the presumed dimension in modules of the QR Code, implemntations of this method extract
|
|
||||||
* the QR Code from the image by sampling the points in the image which should correspond to the
|
|
||||||
* modules of the QR Code.</p>
|
|
||||||
*
|
|
||||||
* @param image image to sample
|
|
||||||
* @param topLeft top-left finder pattern location
|
|
||||||
* @param topRight top-right finder pattern location
|
|
||||||
* @param bottomLeft bottom-left finder pattern location
|
|
||||||
* @param alignmentPattern bottom-right alignment pattern location
|
|
||||||
* @param dimension dimension of QR Code
|
|
||||||
* @return {@link BitMatrix} representing QR Code's modules
|
|
||||||
* @throws ReaderException if QR Code cannot be reasonably sampled -- for example if the location
|
|
||||||
* of the finder patterns imply a transformation that would require sampling off the image
|
|
||||||
*/
|
|
||||||
protected abstract BitMatrix sampleGrid(MonochromeBitmapSource image,
|
|
||||||
FinderPattern topLeft,
|
|
||||||
FinderPattern topRight,
|
|
||||||
FinderPattern bottomLeft,
|
|
||||||
AlignmentPattern alignmentPattern,
|
|
||||||
int dimension) throws ReaderException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Checks a set of points that have been transformed to sample points on an image against
|
|
||||||
* the image's dimensions to see if the endpoints are even within the image.
|
|
||||||
* This method actually only checks the endpoints since the points are assumed to lie
|
|
||||||
* on a line.</p>
|
|
||||||
*
|
|
||||||
* <p>This method will actually "nudge" the endpoints back onto the image if they are found to be barely
|
|
||||||
* (less than 1 pixel) off the image. This accounts for imperfect detection of finder patterns in an image
|
|
||||||
* where the QR Code runs all the way to the image border.</p>
|
|
||||||
*
|
|
||||||
* @param image image into which the points should map
|
|
||||||
* @param points actual points in x1,y1,...,xn,yn form
|
|
||||||
* @throws ReaderException if an endpoint is lies outside the image boundaries
|
|
||||||
*/
|
|
||||||
protected static void checkEndpoint(MonochromeBitmapSource image, float[] points) throws ReaderException {
|
|
||||||
int width = image.getWidth();
|
|
||||||
int height = image.getHeight();
|
|
||||||
checkOneEndpoint(points, (int) points[0], (int) points[1], width, height);
|
|
||||||
checkOneEndpoint(points, (int) points[points.length - 2], (int) points[points.length - 1], width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void checkOneEndpoint(float[] points, int x, int y, int width, int height) throws ReaderException {
|
|
||||||
if (x < -1 || x > width || y < -1 || y > height) {
|
|
||||||
throw new ReaderException("Transformed point out of bounds at " + x + ',' + y);
|
|
||||||
}
|
|
||||||
if (x == -1) {
|
|
||||||
points[0] = 0.0f;
|
|
||||||
}
|
|
||||||
if (y == -1) {
|
|
||||||
points[1] = 0.0f;
|
|
||||||
}
|
|
||||||
if (x == width) {
|
|
||||||
points[0] = width - 1;
|
|
||||||
}
|
|
||||||
if (y == height) {
|
|
||||||
points[1] = height - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in a new issue