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.qrcode.encoder;
20 * A class which wraps a 2D array.
22 * JAVAPORT: I'm not happy about the argument ordering throughout the file, as I always like to have
23 * the horizontal component first, but this is for compatibility with the C++ code. The original
24 * code was a 2D array of ints, but since it only ever gets assigned -1, 0, and 1, I'm going to use
25 * less memory and go with bytes.
27 * @author dswitkin@google.com (Daniel Switkin)
29 public final class Matrix {
31 private final byte[][] bytes;
32 private final int height;
33 private final int width;
35 public Matrix(int height, int width) {
36 bytes = new byte[height][width];
41 public final int height() {
45 public final int width() {
49 public final byte get(int y, int x) {
53 public final void set(int y, int x, byte value) {
57 public final void set(int y, int x, int value) {
58 bytes[y][x] = (byte) value;
61 public final void clear(byte value) {
62 for (int y = 0; y < height; ++y) {
63 for (int x = 0; x < width; ++x) {
69 public final String toString() {
70 StringBuffer result = new StringBuffer();
71 for (int y = 0; y < height; ++y) {
72 for (int x = 0; x < width; ++x) {
73 switch (bytes[y][x]) {
87 return result.toString();