2 * Copyright 2009 ZXing authors
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.google.zxing;
19 import com.google.zxing.common.BitArray;
22 * Encapulates a cropped region, a subset, of another {@link MonochromeBitmapSource}.
26 public final class CroppedMonochromeBitmapSource implements MonochromeBitmapSource {
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;
35 * Creates an instance that uses only a region of the given image as a source of pixels to decode.
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
44 public CroppedMonochromeBitmapSource(MonochromeBitmapSource delegate,
45 int left, int top, int right, int bottom) {
46 this.delegate = delegate;
53 public boolean isBlack(int x, int y) {
54 return delegate.isBlack(left + x, top + y);
57 public BitArray getBlackRow(int y, BitArray row, int startX, int getWidth) {
58 return delegate.getBlackRow(top + y, row, left + startX, getWidth);
61 public BitArray getBlackColumn(int x, BitArray column, int startY, int getHeight) {
62 return delegate.getBlackColumn(left + x, column, top + startY, getHeight);
65 public int getHeight() {
69 public int getWidth() {
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);
78 public BlackPointEstimationMethod getLastEstimationMethod() {
79 return delegate.getLastEstimationMethod();
82 public MonochromeBitmapSource rotateCounterClockwise() {
83 MonochromeBitmapSource rotated = delegate.rotateCounterClockwise();
84 return new CroppedMonochromeBitmapSource(rotated,
86 delegate.getWidth() - right,
87 delegate.getHeight() - bottom,
91 public boolean isRotateSupported() {
92 return delegate.isRotateSupported();