2 * Copyright 2007 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.decoder;
20 * <p>See ISO 18004:2006, 6.4.1, Tables 2 and 3. This enum encapsulates the various modes in which
21 * data can be encoded to bits in the QR code standard.</p>
27 TERMINATOR(new int[]{0, 0, 0}, 0x00), // Not really a mode...
28 NUMERIC(new int[]{10, 12, 14}, 0x01),
29 ALPHANUMERIC(new int[]{9, 11, 13}, 0x02),
30 STRUCTURED_APPEND(new int[]{0, 0, 0}, 0x03), // Not supported
31 BYTE(new int[]{8, 16, 16}, 0x04),
32 ECI(new int[]{0, 0, 0}, 0x07), // character counts don't apply
33 KANJI(new int[]{8, 10, 12}, 0x08),
34 FNC1_FIRST_POSITION(new int[]{0, 0, 0}, 0x05),
35 FNC1_SECOND_POSITION(new int[]{0, 0, 0}, 0x09),
36 /** See GBT 18284-2000; "Hanzi" is a transliteration of this mode name. */
37 HANZI(new int[]{8, 10, 12}, 0x0D);
39 private final int[] characterCountBitsForVersions;
40 private final int bits;
42 Mode(int[] characterCountBitsForVersions, int bits) {
43 this.characterCountBitsForVersions = characterCountBitsForVersions;
48 * @param bits four bits encoding a QR Code data mode
49 * @return Mode encoded by these bits
50 * @throws IllegalArgumentException if bits do not correspond to a known mode
52 public static Mode forBits(int bits) {
61 return STRUCTURED_APPEND;
65 return FNC1_FIRST_POSITION;
71 return FNC1_SECOND_POSITION;
73 // 0xD is defined in GBT 18284-2000, may not be supported in foreign country
76 throw new IllegalArgumentException();
81 * @param version version in question
82 * @return number of bits used, in this QR Code symbol {@link Version}, to encode the
83 * count of characters that will follow encoded in this Mode
85 public int getCharacterCountBits(Version version) {
86 int number = version.getVersionNumber();
90 } else if (number <= 26) {
95 return characterCountBitsForVersions[offset];
98 public int getBits() {