]> Pileus Git - ~andy/freeotp/blob - src/com/google/zxing/Binarizer.java
Add native camera support
[~andy/freeotp] / src / com / google / zxing / Binarizer.java
1 /*
2  * Copyright 2009 ZXing authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.google.zxing;
18
19 import com.google.zxing.common.BitArray;
20 import com.google.zxing.common.BitMatrix;
21
22 /**
23  * This class hierarchy provides a set of methods to convert luminance data to 1 bit data.
24  * It allows the algorithm to vary polymorphically, for example allowing a very expensive
25  * thresholding technique for servers and a fast one for mobile. It also permits the implementation
26  * to vary, e.g. a JNI version for Android and a Java fallback version for other platforms.
27  *
28  * @author dswitkin@google.com (Daniel Switkin)
29  */
30 public abstract class Binarizer {
31
32   private final LuminanceSource source;
33
34   protected Binarizer(LuminanceSource source) {
35     this.source = source;
36   }
37
38   public final LuminanceSource getLuminanceSource() {
39     return source;
40   }
41
42   /**
43    * Converts one row of luminance data to 1 bit data. May actually do the conversion, or return
44    * cached data. Callers should assume this method is expensive and call it as seldom as possible.
45    * This method is intended for decoding 1D barcodes and may choose to apply sharpening.
46    * For callers which only examine one row of pixels at a time, the same BitArray should be reused
47    * and passed in with each call for performance. However it is legal to keep more than one row
48    * at a time if needed.
49    *
50    * @param y The row to fetch, 0 <= y < bitmap height.
51    * @param row An optional preallocated array. If null or too small, it will be ignored.
52    *            If used, the Binarizer will call BitArray.clear(). Always use the returned object.
53    * @return The array of bits for this row (true means black).
54    */
55   public abstract BitArray getBlackRow(int y, BitArray row) throws NotFoundException;
56
57   /**
58    * Converts a 2D array of luminance data to 1 bit data. As above, assume this method is expensive
59    * and do not call it repeatedly. This method is intended for decoding 2D barcodes and may or
60    * may not apply sharpening. Therefore, a row from this matrix may not be identical to one
61    * fetched using getBlackRow(), so don't mix and match between them.
62    *
63    * @return The 2D array of bits for the image (true means black).
64    */
65   public abstract BitMatrix getBlackMatrix() throws NotFoundException;
66
67   /**
68    * Creates a new object with the same type as this Binarizer implementation, but with pristine
69    * state. This is needed because Binarizer implementations may be stateful, e.g. keeping a cache
70    * of 1 bit data. See Effective Java for why we can't use Java's clone() method.
71    *
72    * @param source The LuminanceSource this Binarizer will operate on.
73    * @return A new concrete Binarizer implementation object.
74    */
75   public abstract Binarizer createBinarizer(LuminanceSource source);
76
77   public final int getWidth() {
78     return source.getWidth();
79   }
80
81   public final int getHeight() {
82     return source.getHeight();
83   }
84
85 }