Java Code Examples for com.google.zxing.common.CharacterSetECI#getCharacterSetECIByValue()

The following examples show how to use com.google.zxing.common.CharacterSetECI#getCharacterSetECIByValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DecodedBitStreamParser.java    From ScreenCapture with MIT License 4 votes vote down vote up
static DecoderResult decode(byte[] bytes,
                            Version version,
                            ErrorCorrectionLevel ecLevel,
                            Map<DecodeHintType,?> hints) throws FormatException {
  BitSource bits = new BitSource(bytes);
  StringBuilder result = new StringBuilder(50);
  List<byte[]> byteSegments = new ArrayList<>(1);
  int symbolSequence = -1;
  int parityData = -1;

  try {
    CharacterSetECI currentCharacterSetECI = null;
    boolean fc1InEffect = false;
    Mode mode;
    do {
      // While still another segment to read...
      if (bits.available() < 4) {
        // OK, assume we're done. Really, a TERMINATOR mode should have been recorded here
        mode = Mode.TERMINATOR;
      } else {
        mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits
      }
      switch (mode) {
        case TERMINATOR:
          break;
        case FNC1_FIRST_POSITION:
        case FNC1_SECOND_POSITION:
          // We do little with FNC1 except alter the parsed result a bit according to the spec
          fc1InEffect = true;
          break;
        case STRUCTURED_APPEND:
          if (bits.available() < 16) {
            throw FormatException.getFormatInstance();
          }
          // sequence number and parity is added later to the result metadata
          // Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue
          symbolSequence = bits.readBits(8);
          parityData = bits.readBits(8);
          break;
        case ECI:
          // Count doesn't apply to ECI
          int value = parseECIValue(bits);
          currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value);
          if (currentCharacterSetECI == null) {
            throw FormatException.getFormatInstance();
          }
          break;
        case HANZI:
          // First handle Hanzi mode which does not start with character count
          // Chinese mode contains a sub set indicator right after mode indicator
          int subset = bits.readBits(4);
          int countHanzi = bits.readBits(mode.getCharacterCountBits(version));
          if (subset == GB2312_SUBSET) {
            decodeHanziSegment(bits, result, countHanzi);
          }
          break;
        default:
          // "Normal" QR code modes:
          // How many characters will follow, encoded in this mode?
          int count = bits.readBits(mode.getCharacterCountBits(version));
          switch (mode) {
            case NUMERIC:
              decodeNumericSegment(bits, result, count);
              break;
            case ALPHANUMERIC:
              decodeAlphanumericSegment(bits, result, count, fc1InEffect);
              break;
            case BYTE:
              decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints);
              break;
            case KANJI:
              decodeKanjiSegment(bits, result, count);
              break;
            default:
              throw FormatException.getFormatInstance();
          }
          break;
      }
    } while (mode != Mode.TERMINATOR);
  } catch (IllegalArgumentException iae) {
    // from readBits() calls
    throw FormatException.getFormatInstance();
  }

  return new DecoderResult(bytes,
                           result.toString(),
                           byteSegments.isEmpty() ? null : byteSegments,
                           ecLevel == null ? null : ecLevel.toString(),
                           symbolSequence,
                           parityData);
}
 
Example 2
Source File: DecodedBitStreamParser.java    From Tesseract-OCR-Scanner with Apache License 2.0 4 votes vote down vote up
static DecoderResult decode(byte[] bytes,
                            Version version,
                            ErrorCorrectionLevel ecLevel,
                            Map<DecodeHintType,?> hints) throws FormatException {
  BitSource bits = new BitSource(bytes);
  StringBuilder result = new StringBuilder(50);
  List<byte[]> byteSegments = new ArrayList<>(1);
  int symbolSequence = -1;
  int parityData = -1;

  try {
    CharacterSetECI currentCharacterSetECI = null;
    boolean fc1InEffect = false;
    Mode mode;
    do {
      // While still another segment to read...
      if (bits.available() < 4) {
        // OK, assume we're done. Really, a TERMINATOR mode should have been recorded here
        mode = Mode.TERMINATOR;
      } else {
        mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits
      }
      switch (mode) {
        case TERMINATOR:
          break;
        case FNC1_FIRST_POSITION:
        case FNC1_SECOND_POSITION:
          // We do little with FNC1 except alter the parsed result a bit according to the spec
          fc1InEffect = true;
          break;
        case STRUCTURED_APPEND:
          if (bits.available() < 16) {
            throw FormatException.getFormatInstance();
          }
          // sequence number and parity is added later to the result metadata
          // Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue
          symbolSequence = bits.readBits(8);
          parityData = bits.readBits(8);
          break;
        case ECI:
          // Count doesn't apply to ECI
          int value = parseECIValue(bits);
          currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value);
          if (currentCharacterSetECI == null) {
            throw FormatException.getFormatInstance();
          }
          break;
        case HANZI:
          // First handle Hanzi mode which does not start with character count
          // Chinese mode contains a sub set indicator right after mode indicator
          int subset = bits.readBits(4);
          int countHanzi = bits.readBits(mode.getCharacterCountBits(version));
          if (subset == GB2312_SUBSET) {
            decodeHanziSegment(bits, result, countHanzi);
          }
          break;
        default:
          // "Normal" QR code modes:
          // How many characters will follow, encoded in this mode?
          int count = bits.readBits(mode.getCharacterCountBits(version));
          switch (mode) {
            case NUMERIC:
              decodeNumericSegment(bits, result, count);
              break;
            case ALPHANUMERIC:
              decodeAlphanumericSegment(bits, result, count, fc1InEffect);
              break;
            case BYTE:
              decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints);
              break;
            case KANJI:
              decodeKanjiSegment(bits, result, count);
              break;
            default:
              throw FormatException.getFormatInstance();
          }
          break;
      }
    } while (mode != Mode.TERMINATOR);
  } catch (IllegalArgumentException iae) {
    // from readBits() calls
    throw FormatException.getFormatInstance();
  }

  return new DecoderResult(bytes,
                           result.toString(),
                           byteSegments.isEmpty() ? null : byteSegments,
                           ecLevel == null ? null : ecLevel.toString(),
                           symbolSequence,
                           parityData);
}
 
Example 3
Source File: DecodedBitStreamParser.java    From QrCodeScanner with GNU General Public License v3.0 4 votes vote down vote up
static DecoderResult decode(byte[] bytes,
                            Version version,
                            ErrorCorrectionLevel ecLevel,
                            Map<DecodeHintType,?> hints) throws FormatException {
  BitSource bits = new BitSource(bytes);
  StringBuilder result = new StringBuilder(50);
  List<byte[]> byteSegments = new ArrayList<>(1);
  int symbolSequence = -1;
  int parityData = -1;

  try {
    CharacterSetECI currentCharacterSetECI = null;
    boolean fc1InEffect = false;
    Mode mode;
    do {
      // While still another segment to read...
      if (bits.available() < 4) {
        // OK, assume we're done. Really, a TERMINATOR mode should have been recorded here
        mode = Mode.TERMINATOR;
      } else {
        mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits
      }
      switch (mode) {
        case TERMINATOR:
          break;
        case FNC1_FIRST_POSITION:
        case FNC1_SECOND_POSITION:
          // We do little with FNC1 except alter the parsed result a bit according to the spec
          fc1InEffect = true;
          break;
        case STRUCTURED_APPEND:
          if (bits.available() < 16) {
            throw FormatException.getFormatInstance();
          }
          // sequence number and parity is added later to the result metadata
          // Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue
          symbolSequence = bits.readBits(8);
          parityData = bits.readBits(8);
          break;
        case ECI:
          // Count doesn't apply to ECI
          int value = parseECIValue(bits);
          currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value);
          if (currentCharacterSetECI == null) {
            throw FormatException.getFormatInstance();
          }
          break;
        case HANZI:
          // First handle Hanzi mode which does not start with character count
          // Chinese mode contains a sub set indicator right after mode indicator
          int subset = bits.readBits(4);
          int countHanzi = bits.readBits(mode.getCharacterCountBits(version));
          if (subset == GB2312_SUBSET) {
            decodeHanziSegment(bits, result, countHanzi);
          }
          break;
        default:
          // "Normal" QR code modes:
          // How many characters will follow, encoded in this mode?
          int count = bits.readBits(mode.getCharacterCountBits(version));
          switch (mode) {
            case NUMERIC:
              decodeNumericSegment(bits, result, count);
              break;
            case ALPHANUMERIC:
              decodeAlphanumericSegment(bits, result, count, fc1InEffect);
              break;
            case BYTE:
              decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints);
              break;
            case KANJI:
              decodeKanjiSegment(bits, result, count);
              break;
            default:
              throw FormatException.getFormatInstance();
          }
          break;
      }
    } while (mode != Mode.TERMINATOR);
  } catch (IllegalArgumentException iae) {
    // from readBits() calls
    throw FormatException.getFormatInstance();
  }

  return new DecoderResult(bytes,
                           result.toString(),
                           byteSegments.isEmpty() ? null : byteSegments,
                           ecLevel == null ? null : ecLevel.toString(),
                           symbolSequence,
                           parityData);
}
 
Example 4
Source File: DecodedBitStreamParser.java    From ZXing-Orient with Apache License 2.0 4 votes vote down vote up
static DecoderResult decode(byte[] bytes,
                            Version version,
                            ErrorCorrectionLevel ecLevel,
                            Map<DecodeHintType,?> hints) throws FormatException {
  BitSource bits = new BitSource(bytes);
  StringBuilder result = new StringBuilder(50);
  List<byte[]> byteSegments = new ArrayList<>(1);
  int symbolSequence = -1;
  int parityData = -1;
  
  try {
    CharacterSetECI currentCharacterSetECI = null;
    boolean fc1InEffect = false;
    Mode mode;
    do {
      // While still another segment to read...
      if (bits.available() < 4) {
        // OK, assume we're done. Really, a TERMINATOR mode should have been recorded here
        mode = Mode.TERMINATOR;
      } else {
        mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits
      }
      if (mode != Mode.TERMINATOR) {
        if (mode == Mode.FNC1_FIRST_POSITION || mode == Mode.FNC1_SECOND_POSITION) {
          // We do little with FNC1 except alter the parsed result a bit according to the spec
          fc1InEffect = true;
        } else if (mode == Mode.STRUCTURED_APPEND) {
          if (bits.available() < 16) {
            throw FormatException.getFormatInstance();
          }
          // sequence number and parity is added later to the result metadata
          // Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue
          symbolSequence = bits.readBits(8);
          parityData = bits.readBits(8);
        } else if (mode == Mode.ECI) {
          // Count doesn't apply to ECI
          int value = parseECIValue(bits);
          currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value);
          if (currentCharacterSetECI == null) {
            throw FormatException.getFormatInstance();
          }
        } else {
          // First handle Hanzi mode which does not start with character count
          if (mode == Mode.HANZI) {
            //chinese mode contains a sub set indicator right after mode indicator
            int subset = bits.readBits(4);
            int countHanzi = bits.readBits(mode.getCharacterCountBits(version));
            if (subset == GB2312_SUBSET) {
              decodeHanziSegment(bits, result, countHanzi);
            }
          } else {
            // "Normal" QR code modes:
            // How many characters will follow, encoded in this mode?
            int count = bits.readBits(mode.getCharacterCountBits(version));
            if (mode == Mode.NUMERIC) {
              decodeNumericSegment(bits, result, count);
            } else if (mode == Mode.ALPHANUMERIC) {
              decodeAlphanumericSegment(bits, result, count, fc1InEffect);
            } else if (mode == Mode.BYTE) {
              decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints);
            } else if (mode == Mode.KANJI) {
              decodeKanjiSegment(bits, result, count);
            } else {
              throw FormatException.getFormatInstance();
            }
          }
        }
      }
    } while (mode != Mode.TERMINATOR);
  } catch (IllegalArgumentException iae) {
    // from readBits() calls
    throw FormatException.getFormatInstance();
  }

  return new DecoderResult(bytes,
                           result.toString(),
                           byteSegments.isEmpty() ? null : byteSegments,
                           ecLevel == null ? null : ecLevel.toString(),
                           symbolSequence,
                           parityData);
}
 
Example 5
Source File: DecodedBitStreamParser.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 4 votes vote down vote up
static DecoderResult decode(int[] codewords, String ecLevel) throws FormatException {
  StringBuilder result = new StringBuilder(codewords.length * 2);
  Charset encoding = DEFAULT_ENCODING;
  // Get compaction mode
  int codeIndex = 1;
  int code = codewords[codeIndex++];
  PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
  while (codeIndex < codewords[0]) {
    switch (code) {
      case TEXT_COMPACTION_MODE_LATCH:
        codeIndex = textCompaction(codewords, codeIndex, result);
        break;
      case BYTE_COMPACTION_MODE_LATCH:
      case BYTE_COMPACTION_MODE_LATCH_6:
        codeIndex = byteCompaction(code, codewords, encoding, codeIndex, result);
        break;
      case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
        result.append((char) codewords[codeIndex++]);
        break;
      case NUMERIC_COMPACTION_MODE_LATCH:
        codeIndex = numericCompaction(codewords, codeIndex, result);
        break;
      case ECI_CHARSET:
        CharacterSetECI charsetECI =
            CharacterSetECI.getCharacterSetECIByValue(codewords[codeIndex++]);
        encoding = Charset.forName(charsetECI.name());
        break;
      case ECI_GENERAL_PURPOSE:
        // Can't do anything with generic ECI; skip its 2 characters
        codeIndex += 2;
        break;
      case ECI_USER_DEFINED:
        // Can't do anything with user ECI; skip its 1 character
        codeIndex ++;
        break;
      case BEGIN_MACRO_PDF417_CONTROL_BLOCK:
        codeIndex = decodeMacroBlock(codewords, codeIndex, resultMetadata);
        break;
      case BEGIN_MACRO_PDF417_OPTIONAL_FIELD:
      case MACRO_PDF417_TERMINATOR:
        // Should not see these outside a macro block
        throw FormatException.getFormatInstance();
      default:
        // Default to text compaction. During testing numerous barcodes
        // appeared to be missing the starting mode. In these cases defaulting
        // to text compaction seems to work.
        codeIndex--;
        codeIndex = textCompaction(codewords, codeIndex, result);
        break;
    }
    if (codeIndex < codewords.length) {
      code = codewords[codeIndex++];
    } else {
      throw FormatException.getFormatInstance();
    }
  }
  if (result.length() == 0) {
    throw FormatException.getFormatInstance();
  }
  DecoderResult decoderResult = new DecoderResult(null, result.toString(), null, ecLevel);
  decoderResult.setOther(resultMetadata);
  return decoderResult;
}
 
Example 6
Source File: DecodedBitStreamParser.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 4 votes vote down vote up
static DecoderResult decode(byte[] bytes,
                            Version version,
                            ErrorCorrectionLevel ecLevel,
                            Map<DecodeHintType,?> hints) throws FormatException {
  BitSource bits = new BitSource(bytes);
  StringBuilder result = new StringBuilder(50);
  List<byte[]> byteSegments = new ArrayList<>(1);
  int symbolSequence = -1;
  int parityData = -1;
  
  try {
    CharacterSetECI currentCharacterSetECI = null;
    boolean fc1InEffect = false;
    Mode mode;
    do {
      // While still another segment to read...
      if (bits.available() < 4) {
        // OK, assume we're done. Really, a TERMINATOR mode should have been recorded here
        mode = Mode.TERMINATOR;
      } else {
        mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits
      }
      if (mode != Mode.TERMINATOR) {
        if (mode == Mode.FNC1_FIRST_POSITION || mode == Mode.FNC1_SECOND_POSITION) {
          // We do little with FNC1 except alter the parsed result a bit according to the spec
          fc1InEffect = true;
        } else if (mode == Mode.STRUCTURED_APPEND) {
          if (bits.available() < 16) {
            throw FormatException.getFormatInstance();
          }
          // sequence number and parity is added later to the result metadata
          // Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue
          symbolSequence = bits.readBits(8);
          parityData = bits.readBits(8);
        } else if (mode == Mode.ECI) {
          // Count doesn't apply to ECI
          int value = parseECIValue(bits);
          currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value);
          if (currentCharacterSetECI == null) {
            throw FormatException.getFormatInstance();
          }
        } else {
          // First handle Hanzi mode which does not start with character count
          if (mode == Mode.HANZI) {
            //chinese mode contains a sub set indicator right after mode indicator
            int subset = bits.readBits(4);
            int countHanzi = bits.readBits(mode.getCharacterCountBits(version));
            if (subset == GB2312_SUBSET) {
              decodeHanziSegment(bits, result, countHanzi);
            }
          } else {
            // "Normal" QR code modes:
            // How many characters will follow, encoded in this mode?
            int count = bits.readBits(mode.getCharacterCountBits(version));
            if (mode == Mode.NUMERIC) {
              decodeNumericSegment(bits, result, count);
            } else if (mode == Mode.ALPHANUMERIC) {
              decodeAlphanumericSegment(bits, result, count, fc1InEffect);
            } else if (mode == Mode.BYTE) {
              decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints);
            } else if (mode == Mode.KANJI) {
              decodeKanjiSegment(bits, result, count);
            } else {
              throw FormatException.getFormatInstance();
            }
          }
        }
      }
    } while (mode != Mode.TERMINATOR);
  } catch (IllegalArgumentException iae) {
    // from readBits() calls
    throw FormatException.getFormatInstance();
  }

  return new DecoderResult(bytes,
                           result.toString(),
                           byteSegments.isEmpty() ? null : byteSegments,
                           ecLevel == null ? null : ecLevel.toString(),
                           symbolSequence,
                           parityData);
}
 
Example 7
Source File: DecodedBitStreamParser.java    From weex with Apache License 2.0 4 votes vote down vote up
static DecoderResult decode(int[] codewords, String ecLevel) throws FormatException {
  StringBuilder result = new StringBuilder(codewords.length * 2);
  Charset encoding = DEFAULT_ENCODING;
  // Get compaction mode
  int codeIndex = 1;
  int code = codewords[codeIndex++];
  PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
  while (codeIndex < codewords[0]) {
    switch (code) {
      case TEXT_COMPACTION_MODE_LATCH:
        codeIndex = textCompaction(codewords, codeIndex, result);
        break;
      case BYTE_COMPACTION_MODE_LATCH:
      case BYTE_COMPACTION_MODE_LATCH_6:
        codeIndex = byteCompaction(code, codewords, encoding, codeIndex, result);
        break;
      case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
        result.append((char) codewords[codeIndex++]);
        break;
      case NUMERIC_COMPACTION_MODE_LATCH:
        codeIndex = numericCompaction(codewords, codeIndex, result);
        break;
      case ECI_CHARSET:
        CharacterSetECI charsetECI =
            CharacterSetECI.getCharacterSetECIByValue(codewords[codeIndex++]);
        encoding = Charset.forName(charsetECI.name());
        break;
      case ECI_GENERAL_PURPOSE:
        // Can't do anything with generic ECI; skip its 2 characters
        codeIndex += 2;
        break;
      case ECI_USER_DEFINED:
        // Can't do anything with user ECI; skip its 1 character
        codeIndex ++;
        break;
      case BEGIN_MACRO_PDF417_CONTROL_BLOCK:
        codeIndex = decodeMacroBlock(codewords, codeIndex, resultMetadata);
        break;
      case BEGIN_MACRO_PDF417_OPTIONAL_FIELD:
      case MACRO_PDF417_TERMINATOR:
        // Should not see these outside a macro block
        throw FormatException.getFormatInstance();
      default:
        // Default to text compaction. During testing numerous barcodes
        // appeared to be missing the starting mode. In these cases defaulting
        // to text compaction seems to work.
        codeIndex--;
        codeIndex = textCompaction(codewords, codeIndex, result);
        break;
    }
    if (codeIndex < codewords.length) {
      code = codewords[codeIndex++];
    } else {
      throw FormatException.getFormatInstance();
    }
  }
  if (result.length() == 0) {
    throw FormatException.getFormatInstance();
  }
  DecoderResult decoderResult = new DecoderResult(null, result.toString(), null, ecLevel);
  decoderResult.setOther(resultMetadata);
  return decoderResult;
}
 
Example 8
Source File: DecodedBitStreamParser.java    From weex with Apache License 2.0 4 votes vote down vote up
static DecoderResult decode(byte[] bytes,
                            Version version,
                            ErrorCorrectionLevel ecLevel,
                            Map<DecodeHintType,?> hints) throws FormatException {
  BitSource bits = new BitSource(bytes);
  StringBuilder result = new StringBuilder(50);
  List<byte[]> byteSegments = new ArrayList<>(1);
  int symbolSequence = -1;
  int parityData = -1;
  
  try {
    CharacterSetECI currentCharacterSetECI = null;
    boolean fc1InEffect = false;
    Mode mode;
    do {
      // While still another segment to read...
      if (bits.available() < 4) {
        // OK, assume we're done. Really, a TERMINATOR mode should have been recorded here
        mode = Mode.TERMINATOR;
      } else {
        mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits
      }
      if (mode != Mode.TERMINATOR) {
        if (mode == Mode.FNC1_FIRST_POSITION || mode == Mode.FNC1_SECOND_POSITION) {
          // We do little with FNC1 except alter the parsed result a bit according to the spec
          fc1InEffect = true;
        } else if (mode == Mode.STRUCTURED_APPEND) {
          if (bits.available() < 16) {
            throw FormatException.getFormatInstance();
          }
          // sequence number and parity is added later to the result metadata
          // Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue
          symbolSequence = bits.readBits(8);
          parityData = bits.readBits(8);
        } else if (mode == Mode.ECI) {
          // Count doesn't apply to ECI
          int value = parseECIValue(bits);
          currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value);
          if (currentCharacterSetECI == null) {
            throw FormatException.getFormatInstance();
          }
        } else {
          // First handle Hanzi mode which does not start with character count
          if (mode == Mode.HANZI) {
            //chinese mode contains a sub set indicator right after mode indicator
            int subset = bits.readBits(4);
            int countHanzi = bits.readBits(mode.getCharacterCountBits(version));
            if (subset == GB2312_SUBSET) {
              decodeHanziSegment(bits, result, countHanzi);
            }
          } else {
            // "Normal" QR code modes:
            // How many characters will follow, encoded in this mode?
            int count = bits.readBits(mode.getCharacterCountBits(version));
            if (mode == Mode.NUMERIC) {
              decodeNumericSegment(bits, result, count);
            } else if (mode == Mode.ALPHANUMERIC) {
              decodeAlphanumericSegment(bits, result, count, fc1InEffect);
            } else if (mode == Mode.BYTE) {
              decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints);
            } else if (mode == Mode.KANJI) {
              decodeKanjiSegment(bits, result, count);
            } else {
              throw FormatException.getFormatInstance();
            }
          }
        }
      }
    } while (mode != Mode.TERMINATOR);
  } catch (IllegalArgumentException iae) {
    // from readBits() calls
    throw FormatException.getFormatInstance();
  }

  return new DecoderResult(bytes,
                           result.toString(),
                           byteSegments.isEmpty() ? null : byteSegments,
                           ecLevel == null ? null : ecLevel.toString(),
                           symbolSequence,
                           parityData);
}
 
Example 9
Source File: DecodedBitStreamParser.java    From barcodescanner-lib-aar with MIT License 4 votes vote down vote up
static DecoderResult decode(int[] codewords, String ecLevel) throws FormatException {
  StringBuilder result = new StringBuilder(codewords.length * 2);
  Charset encoding = DEFAULT_ENCODING;
  // Get compaction mode
  int codeIndex = 1;
  int code = codewords[codeIndex++];
  PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
  while (codeIndex < codewords[0]) {
    switch (code) {
      case TEXT_COMPACTION_MODE_LATCH:
        codeIndex = textCompaction(codewords, codeIndex, result);
        break;
      case BYTE_COMPACTION_MODE_LATCH:
      case BYTE_COMPACTION_MODE_LATCH_6:
        codeIndex = byteCompaction(code, codewords, encoding, codeIndex, result);
        break;
      case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
        result.append((char) codewords[codeIndex++]);
        break;
      case NUMERIC_COMPACTION_MODE_LATCH:
        codeIndex = numericCompaction(codewords, codeIndex, result);
        break;
      case ECI_CHARSET:
        CharacterSetECI charsetECI =
            CharacterSetECI.getCharacterSetECIByValue(codewords[codeIndex++]);
        encoding = Charset.forName(charsetECI.name());
        break;
      case ECI_GENERAL_PURPOSE:
        // Can't do anything with generic ECI; skip its 2 characters
        codeIndex += 2;
        break;
      case ECI_USER_DEFINED:
        // Can't do anything with user ECI; skip its 1 character
        codeIndex ++;
        break;
      case BEGIN_MACRO_PDF417_CONTROL_BLOCK:
        codeIndex = decodeMacroBlock(codewords, codeIndex, resultMetadata);
        break;
      case BEGIN_MACRO_PDF417_OPTIONAL_FIELD:
      case MACRO_PDF417_TERMINATOR:
        // Should not see these outside a macro block
        throw FormatException.getFormatInstance();
      default:
        // Default to text compaction. During testing numerous barcodes
        // appeared to be missing the starting mode. In these cases defaulting
        // to text compaction seems to work.
        codeIndex--;
        codeIndex = textCompaction(codewords, codeIndex, result);
        break;
    }
    if (codeIndex < codewords.length) {
      code = codewords[codeIndex++];
    } else {
      throw FormatException.getFormatInstance();
    }
  }
  if (result.length() == 0) {
    throw FormatException.getFormatInstance();
  }
  DecoderResult decoderResult = new DecoderResult(null, result.toString(), null, ecLevel);
  decoderResult.setOther(resultMetadata);
  return decoderResult;
}
 
Example 10
Source File: DecodedBitStreamParser.java    From barcodescanner-lib-aar with MIT License 4 votes vote down vote up
static DecoderResult decode(byte[] bytes,
                            Version version,
                            ErrorCorrectionLevel ecLevel,
                            Map<DecodeHintType,?> hints) throws FormatException {
  BitSource bits = new BitSource(bytes);
  StringBuilder result = new StringBuilder(50);
  List<byte[]> byteSegments = new ArrayList<>(1);
  int symbolSequence = -1;
  int parityData = -1;
  
  try {
    CharacterSetECI currentCharacterSetECI = null;
    boolean fc1InEffect = false;
    Mode mode;
    do {
      // While still another segment to read...
      if (bits.available() < 4) {
        // OK, assume we're done. Really, a TERMINATOR mode should have been recorded here
        mode = Mode.TERMINATOR;
      } else {
        mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits
      }
      if (mode != Mode.TERMINATOR) {
        if (mode == Mode.FNC1_FIRST_POSITION || mode == Mode.FNC1_SECOND_POSITION) {
          // We do little with FNC1 except alter the parsed result a bit according to the spec
          fc1InEffect = true;
        } else if (mode == Mode.STRUCTURED_APPEND) {
          if (bits.available() < 16) {
            throw FormatException.getFormatInstance();
          }
          // sequence number and parity is added later to the result metadata
          // Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue
          symbolSequence = bits.readBits(8);
          parityData = bits.readBits(8);
        } else if (mode == Mode.ECI) {
          // Count doesn't apply to ECI
          int value = parseECIValue(bits);
          currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value);
          if (currentCharacterSetECI == null) {
            throw FormatException.getFormatInstance();
          }
        } else {
          // First handle Hanzi mode which does not start with character count
          if (mode == Mode.HANZI) {
            //chinese mode contains a sub set indicator right after mode indicator
            int subset = bits.readBits(4);
            int countHanzi = bits.readBits(mode.getCharacterCountBits(version));
            if (subset == GB2312_SUBSET) {
              decodeHanziSegment(bits, result, countHanzi);
            }
          } else {
            // "Normal" QR code modes:
            // How many characters will follow, encoded in this mode?
            int count = bits.readBits(mode.getCharacterCountBits(version));
            if (mode == Mode.NUMERIC) {
              decodeNumericSegment(bits, result, count);
            } else if (mode == Mode.ALPHANUMERIC) {
              decodeAlphanumericSegment(bits, result, count, fc1InEffect);
            } else if (mode == Mode.BYTE) {
              decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints);
            } else if (mode == Mode.KANJI) {
              decodeKanjiSegment(bits, result, count);
            } else {
              throw FormatException.getFormatInstance();
            }
          }
        }
      }
    } while (mode != Mode.TERMINATOR);
  } catch (IllegalArgumentException iae) {
    // from readBits() calls
    throw FormatException.getFormatInstance();
  }

  return new DecoderResult(bytes,
                           result.toString(),
                           byteSegments.isEmpty() ? null : byteSegments,
                           ecLevel == null ? null : ecLevel.toString(),
                           symbolSequence,
                           parityData);
}
 
Example 11
Source File: DecodedBitStreamParser.java    From reacteu-app with MIT License 4 votes vote down vote up
static DecoderResult decode(byte[] bytes,
                            Version version,
                            ErrorCorrectionLevel ecLevel,
                            Map<DecodeHintType,?> hints) throws FormatException {
  BitSource bits = new BitSource(bytes);
  StringBuilder result = new StringBuilder(50);
  CharacterSetECI currentCharacterSetECI = null;
  boolean fc1InEffect = false;
  List<byte[]> byteSegments = new ArrayList<byte[]>(1);
  Mode mode;
  do {
    // While still another segment to read...
    if (bits.available() < 4) {
      // OK, assume we're done. Really, a TERMINATOR mode should have been recorded here
      mode = Mode.TERMINATOR;
    } else {
      try {
        mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits
      } catch (IllegalArgumentException iae) {
        throw FormatException.getFormatInstance();
      }
    }
    if (mode != Mode.TERMINATOR) {
      if (mode == Mode.FNC1_FIRST_POSITION || mode == Mode.FNC1_SECOND_POSITION) {
        // We do little with FNC1 except alter the parsed result a bit according to the spec
        fc1InEffect = true;
      } else if (mode == Mode.STRUCTURED_APPEND) {
        if (bits.available() < 16) {
          throw FormatException.getFormatInstance();
        }
        // not really supported; all we do is ignore it
        // Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue
        bits.readBits(16);
      } else if (mode == Mode.ECI) {
        // Count doesn't apply to ECI
        int value = parseECIValue(bits);
        currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value);
        if (currentCharacterSetECI == null) {
          throw FormatException.getFormatInstance();
        }
      } else {
        // First handle Hanzi mode which does not start with character count
        if (mode == Mode.HANZI) {
          //chinese mode contains a sub set indicator right after mode indicator
          int subset = bits.readBits(4);
          int countHanzi = bits.readBits(mode.getCharacterCountBits(version));
          if (subset == GB2312_SUBSET) {
            decodeHanziSegment(bits, result, countHanzi);
          }
        } else {
          // "Normal" QR code modes:
          // How many characters will follow, encoded in this mode?
          int count = bits.readBits(mode.getCharacterCountBits(version));
          if (mode == Mode.NUMERIC) {
            decodeNumericSegment(bits, result, count);
          } else if (mode == Mode.ALPHANUMERIC) {
            decodeAlphanumericSegment(bits, result, count, fc1InEffect);
          } else if (mode == Mode.BYTE) {
            decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints);
          } else if (mode == Mode.KANJI) {
            decodeKanjiSegment(bits, result, count);
          } else {
            throw FormatException.getFormatInstance();
          }
        }
      }
    }
  } while (mode != Mode.TERMINATOR);

  return new DecoderResult(bytes,
                           result.toString(),
                           byteSegments.isEmpty() ? null : byteSegments,
                           ecLevel == null ? null : ecLevel.toString());
}
 
Example 12
Source File: DecodedBitStreamParser.java    From RipplePower with Apache License 2.0 4 votes vote down vote up
static DecoderResult decode(byte[] bytes, Version version, ErrorCorrectionLevel ecLevel,
		Map<DecodeHintType, ?> hints) throws FormatException {
	BitSource bits = new BitSource(bytes);
	StringBuilder result = new StringBuilder(50);
	List<byte[]> byteSegments = new ArrayList<>(1);
	int symbolSequence = -1;
	int parityData = -1;

	try {
		CharacterSetECI currentCharacterSetECI = null;
		boolean fc1InEffect = false;
		Mode mode;
		do {
			// While still another segment to read...
			if (bits.available() < 4) {
				// OK, assume we're done. Really, a TERMINATOR mode should
				// have been recorded here
				mode = Mode.TERMINATOR;
			} else {
				mode = Mode.forBits(bits.readBits(4)); // mode is encoded by
														// 4 bits
			}
			if (mode != Mode.TERMINATOR) {
				if (mode == Mode.FNC1_FIRST_POSITION || mode == Mode.FNC1_SECOND_POSITION) {
					// We do little with FNC1 except alter the parsed result
					// a bit according to the spec
					fc1InEffect = true;
				} else if (mode == Mode.STRUCTURED_APPEND) {
					if (bits.available() < 16) {
						throw FormatException.getFormatInstance();
					}
					// sequence number and parity is added later to the
					// result metadata
					// Read next 8 bits (symbol sequence #) and 8 bits
					// (parity data), then continue
					symbolSequence = bits.readBits(8);
					parityData = bits.readBits(8);
				} else if (mode == Mode.ECI) {
					// Count doesn't apply to ECI
					int value = parseECIValue(bits);
					currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value);
					if (currentCharacterSetECI == null) {
						throw FormatException.getFormatInstance();
					}
				} else {
					// First handle Hanzi mode which does not start with
					// character count
					if (mode == Mode.HANZI) {
						// chinese mode contains a sub set indicator right
						// after mode indicator
						int subset = bits.readBits(4);
						int countHanzi = bits.readBits(mode.getCharacterCountBits(version));
						if (subset == GB2312_SUBSET) {
							decodeHanziSegment(bits, result, countHanzi);
						}
					} else {
						// "Normal" QR code modes:
						// How many characters will follow, encoded in this
						// mode?
						int count = bits.readBits(mode.getCharacterCountBits(version));
						if (mode == Mode.NUMERIC) {
							decodeNumericSegment(bits, result, count);
						} else if (mode == Mode.ALPHANUMERIC) {
							decodeAlphanumericSegment(bits, result, count, fc1InEffect);
						} else if (mode == Mode.BYTE) {
							decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints);
						} else if (mode == Mode.KANJI) {
							decodeKanjiSegment(bits, result, count);
						} else {
							throw FormatException.getFormatInstance();
						}
					}
				}
			}
		} while (mode != Mode.TERMINATOR);
	} catch (IllegalArgumentException iae) {
		// from readBits() calls
		throw FormatException.getFormatInstance();
	}

	return new DecoderResult(bytes, result.toString(), byteSegments.isEmpty() ? null : byteSegments,
			ecLevel == null ? null : ecLevel.toString(), symbolSequence, parityData);
}
 
Example 13
Source File: DecodedBitStreamParser.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
static DecoderResult decode(byte[] bytes,
                            Version version,
                            ErrorCorrectionLevel ecLevel,
                            Map<DecodeHintType,?> hints) throws FormatException {
  BitSource bits = new BitSource(bytes);
  StringBuilder result = new StringBuilder(50);
  List<byte[]> byteSegments = new ArrayList<>(1);
  int symbolSequence = -1;
  int parityData = -1;

  try {
    CharacterSetECI currentCharacterSetECI = null;
    boolean fc1InEffect = false;
    Mode mode;
    do {
      // While still another segment to read...
      if (bits.available() < 4) {
        // OK, assume we're done. Really, a TERMINATOR mode should have been recorded here
        mode = Mode.TERMINATOR;
      } else {
        mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits
      }
      switch (mode) {
        case TERMINATOR:
          break;
        case FNC1_FIRST_POSITION:
        case FNC1_SECOND_POSITION:
          // We do little with FNC1 except alter the parsed result a bit according to the spec
          fc1InEffect = true;
          break;
        case STRUCTURED_APPEND:
          if (bits.available() < 16) {
            throw FormatException.getFormatInstance();
          }
          // sequence number and parity is added later to the result metadata
          // Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue
          symbolSequence = bits.readBits(8);
          parityData = bits.readBits(8);
          break;
        case ECI:
          // Count doesn't apply to ECI
          int value = parseECIValue(bits);
          currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value);
          if (currentCharacterSetECI == null) {
            throw FormatException.getFormatInstance();
          }
          break;
        case HANZI:
          // First handle Hanzi mode which does not start with character count
          // Chinese mode contains a sub set indicator right after mode indicator
          int subset = bits.readBits(4);
          int countHanzi = bits.readBits(mode.getCharacterCountBits(version));
          if (subset == GB2312_SUBSET) {
            decodeHanziSegment(bits, result, countHanzi);
          }
          break;
        default:
          // "Normal" QR code modes:
          // How many characters will follow, encoded in this mode?
          int count = bits.readBits(mode.getCharacterCountBits(version));
          switch (mode) {
            case NUMERIC:
              decodeNumericSegment(bits, result, count);
              break;
            case ALPHANUMERIC:
              decodeAlphanumericSegment(bits, result, count, fc1InEffect);
              break;
            case BYTE:
              decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints);
              break;
            case KANJI:
              decodeKanjiSegment(bits, result, count);
              break;
            default:
              throw FormatException.getFormatInstance();
          }
          break;
      }
    } while (mode != Mode.TERMINATOR);
  } catch (IllegalArgumentException iae) {
    // from readBits() calls
    throw FormatException.getFormatInstance();
  }

  return new DecoderResult(bytes,
                           result.toString(),
                           byteSegments.isEmpty() ? null : byteSegments,
                           ecLevel == null ? null : ecLevel.toString(),
                           symbolSequence,
                           parityData);
}
 
Example 14
Source File: DecodedBitStreamParser.java    From barterli_android with Apache License 2.0 4 votes vote down vote up
static DecoderResult decode(byte[] bytes, Version version, ErrorCorrectionLevel ecLevel, Map<DecodeHintType, ?> hints) throws FormatException {
    BitSource bits = new BitSource(bytes);
    StringBuilder result = new StringBuilder(50);
    CharacterSetECI currentCharacterSetECI = null;
    boolean fc1InEffect = false;
    List<byte[]> byteSegments = new ArrayList<byte[]>(1);
    Mode mode;
    do {
        // While still another segment to read...
        if (bits.available() < 4) {
            // OK, assume we're done. Really, a TERMINATOR mode should have
            // been recorded here
            mode = Mode.TERMINATOR;
        } else {
            try {
                mode = Mode.forBits(bits.readBits(4)); // mode is encoded by
                                                       // 4 bits
            } catch (IllegalArgumentException iae) {
                throw FormatException.getFormatInstance();
            }
        }
        if (mode != Mode.TERMINATOR) {
            if (mode == Mode.FNC1_FIRST_POSITION || mode == Mode.FNC1_SECOND_POSITION) {
                // We do little with FNC1 except alter the parsed result a
                // bit according to the
                // spec
                fc1InEffect = true;
            } else if (mode == Mode.STRUCTURED_APPEND) {
                // not really supported; all we do is ignore it
                // Read next 8 bits (symbol sequence #) and 8 bits (parity
                // data), then continue
                bits.readBits(16);
            } else if (mode == Mode.ECI) {
                // Count doesn't apply to ECI
                int value = parseECIValue(bits);
                currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value);
                if (currentCharacterSetECI == null) {
                    throw FormatException.getFormatInstance();
                }
            } else {
                // First handle Hanzi mode which does not start with
                // character count
                if (mode == Mode.HANZI) {
                    // chinese mode contains a sub set indicator right after
                    // mode indicator
                    int subset = bits.readBits(4);
                    int countHanzi = bits.readBits(mode.getCharacterCountBits(version));
                    if (subset == GB2312_SUBSET) {
                        decodeHanziSegment(bits, result, countHanzi);
                    }
                } else {
                    // "Normal" QR code modes:
                    // How many characters will follow, encoded in this
                    // mode?
                    int count = bits.readBits(mode.getCharacterCountBits(version));
                    if (mode == Mode.NUMERIC) {
                        decodeNumericSegment(bits, result, count);
                    } else if (mode == Mode.ALPHANUMERIC) {
                        decodeAlphanumericSegment(bits, result, count, fc1InEffect);
                    } else if (mode == Mode.BYTE) {
                        decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints);
                    } else if (mode == Mode.KANJI) {
                        decodeKanjiSegment(bits, result, count);
                    } else {
                        throw FormatException.getFormatInstance();
                    }
                }
            }
        }
    } while (mode != Mode.TERMINATOR);

    return new DecoderResult(bytes, result.toString(), byteSegments.isEmpty() ? null : byteSegments, ecLevel == null ? null : ecLevel.toString());
}
 
Example 15
Source File: DecodedBitStreamParser.java    From android-quick-response-code with Apache License 2.0 4 votes vote down vote up
static DecoderResult decode(byte[] bytes, Version version, ErrorCorrectionLevel ecLevel, Map<DecodeHintType, ?> hints) throws FormatException {
    BitSource bits = new BitSource(bytes);
    StringBuilder result = new StringBuilder(50);
    CharacterSetECI currentCharacterSetECI = null;
    boolean fc1InEffect = false;
    List<byte[]> byteSegments = new ArrayList<byte[]>(1);
    Mode mode;
    do {
        // While still another segment to read...
        if (bits.available() < 4) {
            // OK, assume we're done. Really, a TERMINATOR mode should have
            // been recorded here
            mode = Mode.TERMINATOR;
        } else {
            try {
                mode = Mode.forBits(bits.readBits(4)); // mode is encoded by
                                                       // 4 bits
            } catch (IllegalArgumentException iae) {
                throw FormatException.getFormatInstance();
            }
        }
        if (mode != Mode.TERMINATOR) {
            if (mode == Mode.FNC1_FIRST_POSITION || mode == Mode.FNC1_SECOND_POSITION) {
                // We do little with FNC1 except alter the parsed result a
                // bit according to the
                // spec
                fc1InEffect = true;
            } else if (mode == Mode.STRUCTURED_APPEND) {
                // not really supported; all we do is ignore it
                // Read next 8 bits (symbol sequence #) and 8 bits (parity
                // data), then continue
                bits.readBits(16);
            } else if (mode == Mode.ECI) {
                // Count doesn't apply to ECI
                int value = parseECIValue(bits);
                currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value);
                if (currentCharacterSetECI == null) {
                    throw FormatException.getFormatInstance();
                }
            } else {
                // First handle Hanzi mode which does not start with
                // character count
                if (mode == Mode.HANZI) {
                    // chinese mode contains a sub set indicator right after
                    // mode indicator
                    int subset = bits.readBits(4);
                    int countHanzi = bits.readBits(mode.getCharacterCountBits(version));
                    if (subset == GB2312_SUBSET) {
                        decodeHanziSegment(bits, result, countHanzi);
                    }
                } else {
                    // "Normal" QR code modes:
                    // How many characters will follow, encoded in this
                    // mode?
                    int count = bits.readBits(mode.getCharacterCountBits(version));
                    if (mode == Mode.NUMERIC) {
                        decodeNumericSegment(bits, result, count);
                    } else if (mode == Mode.ALPHANUMERIC) {
                        decodeAlphanumericSegment(bits, result, count, fc1InEffect);
                    } else if (mode == Mode.BYTE) {
                        decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints);
                    } else if (mode == Mode.KANJI) {
                        decodeKanjiSegment(bits, result, count);
                    } else {
                        throw FormatException.getFormatInstance();
                    }
                }
            }
        }
    } while (mode != Mode.TERMINATOR);

    return new DecoderResult(bytes, result.toString(), byteSegments.isEmpty() ? null : byteSegments, ecLevel == null ? null : ecLevel.toString());
}
 
Example 16
Source File: DecodedBitStreamParser.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
static DecoderResult decode(byte[] bytes,
                            Version version,
                            ErrorCorrectionLevel ecLevel,
                            Map<DecodeHintType,?> hints) throws FormatException {
  BitSource bits = new BitSource(bytes);
  StringBuilder result = new StringBuilder(50);
  List<byte[]> byteSegments = new ArrayList<>(1);
  int symbolSequence = -1;
  int parityData = -1;

  try {
    CharacterSetECI currentCharacterSetECI = null;
    boolean fc1InEffect = false;
    Mode mode;
    do {
      // While still another segment to read...
      if (bits.available() < 4) {
        // OK, assume we're done. Really, a TERMINATOR mode should have been recorded here
        mode = Mode.TERMINATOR;
      } else {
        mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits
      }
      switch (mode) {
        case TERMINATOR:
          break;
        case FNC1_FIRST_POSITION:
        case FNC1_SECOND_POSITION:
          // We do little with FNC1 except alter the parsed result a bit according to the spec
          fc1InEffect = true;
          break;
        case STRUCTURED_APPEND:
          if (bits.available() < 16) {
            throw FormatException.getFormatInstance();
          }
          // sequence number and parity is added later to the result metadata
          // Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue
          symbolSequence = bits.readBits(8);
          parityData = bits.readBits(8);
          break;
        case ECI:
          // Count doesn't apply to ECI
          int value = parseECIValue(bits);
          currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value);
          if (currentCharacterSetECI == null) {
            throw FormatException.getFormatInstance();
          }
          break;
        case HANZI:
          // First handle Hanzi mode which does not start with character count
          // Chinese mode contains a sub set indicator right after mode indicator
          int subset = bits.readBits(4);
          int countHanzi = bits.readBits(mode.getCharacterCountBits(version));
          if (subset == GB2312_SUBSET) {
            decodeHanziSegment(bits, result, countHanzi);
          }
          break;
        default:
          // "Normal" QR code modes:
          // How many characters will follow, encoded in this mode?
          int count = bits.readBits(mode.getCharacterCountBits(version));
          switch (mode) {
            case NUMERIC:
              decodeNumericSegment(bits, result, count);
              break;
            case ALPHANUMERIC:
              decodeAlphanumericSegment(bits, result, count, fc1InEffect);
              break;
            case BYTE:
              decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints);
              break;
            case KANJI:
              decodeKanjiSegment(bits, result, count);
              break;
            default:
              throw FormatException.getFormatInstance();
          }
          break;
      }
    } while (mode != Mode.TERMINATOR);
  } catch (IllegalArgumentException iae) {
    // from readBits() calls
    throw FormatException.getFormatInstance();
  }

  return new DecoderResult(bytes,
                           result.toString(),
                           byteSegments.isEmpty() ? null : byteSegments,
                           ecLevel == null ? null : ecLevel.toString(),
                           symbolSequence,
                           parityData);
}