Issue 183: Adds support for detecting multiple barcodes, and simplifies ResultPoint...
[zxing.git] / core / src / com / google / zxing / CroppedMonochromeBitmapSource.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
21 /**
22  * Encapulates a cropped region, a subset, of another {@link MonochromeBitmapSource}.
23  *
24  * @author Sean Owen
25  */
26 public final class CroppedMonochromeBitmapSource implements MonochromeBitmapSource {
27
28   private final MonochromeBitmapSource delegate;
29   private final int left;
30   private final int top;
31   private final int right;
32   private final int bottom;
33
34   /**
35    * Creates an instance that uses only a region of the given image as a source of pixels to decode.
36    *
37    * @param delegate image to decode a region of
38    * @param left x coordinate of leftmost pixels to decode
39    * @param top y coordinate of topmost pixels to decode
40    * @param right one more than the x coordinate of rightmost pixels to decode, i.e. we will decode
41    *  pixels whose x coordinate is in [left,right)
42    * @param bottom likewise, one more than the y coordinate of the bottommost pixels to decode
43    */
44   public CroppedMonochromeBitmapSource(MonochromeBitmapSource delegate,
45                                        int left, int top, int right, int bottom) {
46     this.delegate = delegate;
47     this.left = left;
48     this.top = top;
49     this.right = right;
50     this.bottom = bottom;
51   }
52
53   public boolean isBlack(int x, int y) {
54     return delegate.isBlack(left + x, top + y);
55   }
56
57   public BitArray getBlackRow(int y, BitArray row, int startX, int getWidth) {
58     return delegate.getBlackRow(top + y, row, left + startX, getWidth);
59   }
60
61   public BitArray getBlackColumn(int x, BitArray column, int startY, int getHeight) {
62     return delegate.getBlackColumn(left + x, column, top + startY, getHeight);
63   }
64
65   public int getHeight() {
66     return bottom - top;
67   }
68
69   public int getWidth() {
70     return right - left;
71   }
72
73   public void estimateBlackPoint(BlackPointEstimationMethod method, int argument) throws ReaderException {
74     // Hmm, the delegate will probably base this on the whole image though...
75     delegate.estimateBlackPoint(method, argument);
76   }
77
78   public BlackPointEstimationMethod getLastEstimationMethod() {
79     return delegate.getLastEstimationMethod();
80   }
81
82   public MonochromeBitmapSource rotateCounterClockwise() {
83     MonochromeBitmapSource rotated = delegate.rotateCounterClockwise();
84     return new CroppedMonochromeBitmapSource(rotated,
85                                              top,
86                                              delegate.getWidth() - right,
87                                              delegate.getHeight() - bottom,
88                                              left);
89   }
90
91   public boolean isRotateSupported() {
92     return delegate.isRotateSupported();
93   }
94
95 }