2 * Copyright 2008 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;
20 * A class which wraps a 2D array of bytes. The default usage is signed. If you want to use it as a
21 * unsigned container, it's up to you to do byteValue & 0xff at each location.
23 * JAVAPORT: The original code was a 2D array of ints, but since it only ever gets assigned
24 * -1, 0, and 1, I'm going to use less memory and go with bytes.
26 * @author dswitkin@google.com (Daniel Switkin)
28 public final class ByteMatrix {
30 private final byte[][] bytes;
31 private final int width;
32 private final int height;
34 public ByteMatrix(int width, int height) {
35 bytes = new byte[height][width];
40 public int getHeight() {
44 public int getWidth() {
48 public byte get(int x, int y) {
52 public byte[][] getArray() {
56 public void set(int x, int y, byte value) {
60 public void set(int x, int y, int value) {
61 bytes[y][x] = (byte) value;
64 public void clear(byte value) {
65 for (int y = 0; y < height; ++y) {
66 for (int x = 0; x < width; ++x) {
72 public String toString() {
73 StringBuffer result = new StringBuffer(2 * width * height + 2);
74 for (int y = 0; y < height; ++y) {
75 for (int x = 0; x < width; ++x) {
76 switch (bytes[y][x]) {
90 return result.toString();