2 * Copyright 2007 ZXing authors
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 using com.google.zxing;
\r
18 using com.google.zxing.common;
\r
20 namespace com.google.zxing.qrcode.decoder
\r
22 public sealed class Mode
\r
24 // No, we can't use an enum here. J2ME doesn't support it.
\r
25 public static Mode TERMINATOR = new Mode(new int[]{0, 0, 0}, 0x00, "TERMINATOR"); // Not really a mode...
\r
26 public static Mode NUMERIC = new Mode(new int[]{10, 12, 14}, 0x01, "NUMERIC");
\r
27 public static Mode ALPHANUMERIC = new Mode(new int[]{9, 11, 13}, 0x02, "ALPHANUMERIC");
\r
28 public static Mode BYTE = new Mode(new int[]{8, 16, 16}, 0x04, "BYTE");
\r
29 public static Mode ECI = new Mode(null, 0x07, "ECI"); // character counts don't apply
\r
30 public static Mode KANJI = new Mode(new int[]{8, 10, 12}, 0x08, "KANJI");
\r
31 public static Mode FNC1_FIRST_POSITION = new Mode(null, 0x05, "FNC1_FIRST_POSITION");
\r
32 public static Mode FNC1_SECOND_POSITION = new Mode(null, 0x09, "FNC1_SECOND_POSITION");
\r
34 private int[] characterCountBitsForVersions;
\r
36 private string name;
\r
38 private Mode(int[] characterCountBitsForVersions, int bits, string name) {
\r
39 this.characterCountBitsForVersions = characterCountBitsForVersions;
\r
45 * @param bits four bits encoding a QR Code data mode
\r
46 * @return {@link Mode} encoded by these bits
\r
47 * @throws ArgumentException if bits do not correspond to a known mode
\r
49 public static Mode forBits(int bits) {
\r
56 return ALPHANUMERIC;
\r
60 return FNC1_FIRST_POSITION;
\r
66 return FNC1_SECOND_POSITION;
\r
68 throw new ArgumentException();
\r
73 * @param version version in question
\r
74 * @return number of bits used, in this QR Code symbol {@link Version}, to encode the
\r
75 * count of characters that will follow encoded in this {@link Mode}
\r
77 public int getCharacterCountBits(Version version) {
\r
78 if (characterCountBitsForVersions == null) {
\r
79 throw new ArgumentException("Character count doesn't apply to this mode");
\r
81 int number = version.getVersionNumber();
\r
85 } else if (number <= 26) {
\r
90 return characterCountBitsForVersions[offset];
\r
93 public int getBits() {
\r
97 public string getName() {
\r
101 public string toString() {
\r