2 * Copyright 2009 ZXing authors
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 using BitArray = com.google.zxing.common.BitArray;
\r
18 using BitMatrix = com.google.zxing.common.BitMatrix;
\r
19 namespace com.google.zxing
\r
22 /// <summary> This class is the core bitmap class used by ZXing to represent 1 bit data. Reader objects
\r
23 /// accept a BinaryBitmap and attempt to decode it.
\r
26 /// <author> dswitkin@google.com (Daniel Switkin)
\r
28 /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
\r
31 public sealed class BinaryBitmap
\r
33 /// <returns> The width of the bitmap.
\r
39 return binarizer.LuminanceSource.Width;
\r
43 /// <returns> The height of the bitmap.
\r
49 return binarizer.LuminanceSource.Height;
\r
53 /// <summary> Converts a 2D array of luminance data to 1 bit. As above, assume this method is expensive
\r
54 /// and do not call it repeatedly. This method is intended for decoding 2D barcodes and may or
\r
55 /// may not apply sharpening. Therefore, a row from this matrix may not be identical to one
\r
56 /// fetched using getBlackRow(), so don't mix and match between them.
\r
59 /// <returns> The 2D array of bits for the image (true means black).
\r
61 public BitMatrix BlackMatrix
\r
65 // The matrix is created on demand the first time it is requested, then cached. There are two
\r
66 // reasons for this:
\r
67 // 1. This work will never be done if the caller only installs 1D Reader objects, or if a
\r
68 // 1D Reader finds a barcode before the 2D Readers run.
\r
69 // 2. This work will only be done once even if the caller installs multiple 2D Readers.
\r
72 matrix = binarizer.BlackMatrix;
\r
78 /// <returns> Whether this bitmap can be cropped.
\r
80 public bool CropSupported
\r
84 return binarizer.LuminanceSource.CropSupported;
\r
88 /// <returns> Whether this bitmap supports counter-clockwise rotation.
\r
90 public bool RotateSupported
\r
94 return binarizer.LuminanceSource.RotateSupported;
\r
99 //UPGRADE_NOTE: Final was removed from the declaration of 'binarizer '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
\r
100 private Binarizer binarizer;
\r
101 private BitMatrix matrix;
\r
103 public BinaryBitmap(Binarizer binarizer)
\r
105 if (binarizer == null)
\r
107 throw new System.ArgumentException("Binarizer must be non-null.");
\r
109 this.binarizer = binarizer;
\r
113 /// <summary> Converts one row of luminance data to 1 bit data. May actually do the conversion, or return
\r
114 /// cached data. Callers should assume this method is expensive and call it as seldom as possible.
\r
115 /// This method is intended for decoding 1D barcodes and may choose to apply sharpening.
\r
118 /// <param name="y">The row to fetch, 0 <= y < bitmap height.
\r
120 /// <param name="row">An optional preallocated array. If null or too small, it will be ignored.
\r
121 /// If used, the Binarizer will call BitArray.clear(). Always use the returned object.
\r
123 /// <returns> The array of bits for this row (true means black).
\r
125 public BitArray getBlackRow(int y, BitArray row)
\r
127 return binarizer.getBlackRow(y, row);
\r
130 /// <summary> Returns a new object with cropped image data. Implementations may keep a reference to the
\r
131 /// original data rather than a copy. Only callable if isCropSupported() is true.
\r
134 /// <param name="left">The left coordinate, 0 <= left < getWidth().
\r
136 /// <param name="top">The top coordinate, 0 <= top <= getHeight().
\r
138 /// <param name="width">The width of the rectangle to crop.
\r
140 /// <param name="height">The height of the rectangle to crop.
\r
142 /// <returns> A cropped version of this object.
\r
144 public BinaryBitmap crop(int left, int top, int width, int height)
\r
146 LuminanceSource newSource = binarizer.LuminanceSource.crop(left, top, width, height);
\r
147 return new BinaryBitmap(binarizer.createBinarizer(newSource));
\r
150 /// <summary> Returns a new object with rotated image data. Only callable if isRotateSupported() is true.
\r
153 /// <returns> A rotated version of this object.
\r
155 public BinaryBitmap rotateCounterClockwise()
\r
157 LuminanceSource newSource = binarizer.LuminanceSource.rotateCounterClockwise();
\r
158 return new BinaryBitmap(binarizer.createBinarizer(newSource));
\r