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.decoder;
19 import com.google.zxing.common.BitSource;
22 * Superclass of classes encapsulating types ECIs, according to "Extended Channel Interpretations" 5.3.
24 * @author srowen@google.com (Sean Owen)
28 private final int value;
38 static ECI getECIByValue(int value) {
39 if (value < 0 || value > 999999) {
40 throw new IllegalArgumentException("Bad ECI value: " + value);
42 if (value < 900) { // Character set ECIs use 000000 - 000899
43 return CharacterSetECI.getCharacterSetECIByValue(value);
45 throw new IllegalArgumentException("Unsupported ECI value: " + value);
48 static int parseECI(BitSource bits) {
49 int firstByte = bits.readBits(8);
50 if ((firstByte & 0x80) == 0) {
52 return firstByte & 0x7F;
53 } else if ((firstByte & 0xC0) == 0x80) {
55 int secondByte = bits.readBits(8);
56 return ((firstByte & 0x3F) << 8) | secondByte;
57 } else if ((firstByte & 0xE0) == 0xC0) {
59 int secondThirdBytes = bits.readBits(16);
60 return ((firstByte & 0x1F) << 16) | secondThirdBytes;
62 throw new IllegalArgumentException("Bad ECI bits starting with byte " + firstByte);