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.common;
19 import com.google.zxing.BlackPointEstimationMethod;
20 import com.google.zxing.MonochromeBitmapSource;
21 import com.google.zxing.ReaderException;
24 * Encapulates a cropped region of another {@link com.google.zxing.MonochromeBitmapSource}.
28 public final class CroppedMonochromeBitmapSource implements MonochromeBitmapSource {
30 private final MonochromeBitmapSource delegate;
31 private final int left;
32 private final int top;
33 private final int right;
34 private final int bottom;
37 * Creates an instance that uses only a region of the given image as a source of pixels to decode.
39 * @param delegate image to decode a region of
40 * @param left x coordinate of leftmost pixels to decode
41 * @param top y coordinate of topmost pixels to decode
42 * @param right one more than the x coordinate of rightmost pixels to decode, i.e. we will decode
43 * pixels whose x coordinate is in [left,right)
44 * @param bottom likewise, one more than the y coordinate of the bottommost pixels to decode
46 public CroppedMonochromeBitmapSource(MonochromeBitmapSource delegate,
47 int left, int top, int right, int bottom) {
48 this.delegate = delegate;
55 public boolean isBlack(int x, int y) {
56 return delegate.isBlack(left + x, top + y);
59 public BitArray getBlackRow(int y, BitArray row, int startX, int getWidth) {
60 return delegate.getBlackRow(top + y, row, left + startX, getWidth);
63 public BitArray getBlackColumn(int x, BitArray column, int startY, int getHeight) {
64 return delegate.getBlackColumn(left + x, column, top + startY, getHeight);
67 public int getHeight() {
71 public int getWidth() {
75 public void estimateBlackPoint(BlackPointEstimationMethod method, int argument)
76 throws ReaderException {
77 // Hmm, the delegate will probably base this on the whole image though...
78 delegate.estimateBlackPoint(method, argument);
81 public BlackPointEstimationMethod getLastEstimationMethod() {
82 return delegate.getLastEstimationMethod();
85 public MonochromeBitmapSource rotateCounterClockwise() {
86 MonochromeBitmapSource rotated = delegate.rotateCounterClockwise();
87 return new CroppedMonochromeBitmapSource(rotated,
89 delegate.getWidth() - right,
90 delegate.getHeight() - bottom,
94 public boolean isRotateSupported() {
95 return delegate.isRotateSupported();
98 public int getLuminance(int x, int y) {
99 return delegate.getLuminance(x, y);
102 public int[] getLuminanceRow(int y, int[] row) {
103 return delegate.getLuminanceRow(y, row);
106 public int[] getLuminanceColumn(int x, int[] column) {
107 return delegate.getLuminanceColumn(x, column);