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: I'm not happy about the argument ordering throughout the file, as I always like to have
24 * the horizontal component first, but this is for compatibility with the C++ code. The original
25 * code was a 2D array of ints, but since it only ever gets assigned -1, 0, and 1, I'm going to use
26 * less memory and go with bytes.
28 * @author dswitkin@google.com (Daniel Switkin)
30 public final class ByteMatrix {
32 private final byte[][] bytes;
33 private final int height;
34 private final int width;
36 public ByteMatrix(int height, int width) {
37 bytes = new byte[height][width];
50 public byte get(int y, int x) {
54 public byte[][] getArray() {
58 public void set(int y, int x, byte value) {
62 public void set(int y, int x, int value) {
63 bytes[y][x] = (byte) value;
66 public void clear(byte value) {
67 for (int y = 0; y < height; ++y) {
68 for (int x = 0; x < width; ++x) {
74 public String toString() {
75 StringBuffer result = new StringBuffer();
76 for (int y = 0; y < height; ++y) {
77 for (int x = 0; x < width; ++x) {
78 switch (bytes[y][x]) {
92 return result.toString();