Java 类com.google.zxing.pdf417.PDF417ResultMetadata 实例源码

项目:weex-3d-map    文件:DecodedBitStreamParser.java   
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;
}
项目:weex-3d-map    文件:DecodedBitStreamParser.java   
private static int decodeMacroBlock(int[] codewords, int codeIndex, PDF417ResultMetadata resultMetadata)
    throws FormatException {
  if (codeIndex + NUMBER_OF_SEQUENCE_CODEWORDS > codewords[0]) {
    // we must have at least two bytes left for the segment index
    throw FormatException.getFormatInstance();
  }
  int[] segmentIndexArray = new int[NUMBER_OF_SEQUENCE_CODEWORDS];
  for (int i = 0; i < NUMBER_OF_SEQUENCE_CODEWORDS; i++, codeIndex++) {
    segmentIndexArray[i] = codewords[codeIndex];
  }
  resultMetadata.setSegmentIndex(Integer.parseInt(decodeBase900toBase10(segmentIndexArray,
      NUMBER_OF_SEQUENCE_CODEWORDS)));

  StringBuilder fileId = new StringBuilder();
  codeIndex = textCompaction(codewords, codeIndex, fileId);
  resultMetadata.setFileId(fileId.toString());

  if (codewords[codeIndex] == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) {
    codeIndex++;
    int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex];
    int additionalOptionCodeWordsIndex = 0;

    boolean end = false;
    while ((codeIndex < codewords[0]) && !end) {
      int code = codewords[codeIndex++];
      if (code < TEXT_COMPACTION_MODE_LATCH) {
        additionalOptionCodeWords[additionalOptionCodeWordsIndex++] = code;
      } else {
        switch (code) {
          case MACRO_PDF417_TERMINATOR:
            resultMetadata.setLastSegment(true);
            codeIndex++;
            end = true;
            break;
          default:
            throw FormatException.getFormatInstance();
        }
      }
    }

    resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex));
  } else if (codewords[codeIndex] == MACRO_PDF417_TERMINATOR) {
    resultMetadata.setLastSegment(true);
    codeIndex++;
  }

  return codeIndex;
}
项目:boohee_v5.6    文件:DecodedBitStreamParser.java   
static DecoderResult decode(int[] codewords, String ecLevel) throws FormatException {
    StringBuilder result = new StringBuilder(codewords.length * 2);
    Charset encoding = DEFAULT_ENCODING;
    int codeIndex = 1 + 1;
    int code = codewords[1];
    PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
    int codeIndex2 = codeIndex;
    while (codeIndex2 < codewords[0]) {
        switch (code) {
            case TEXT_COMPACTION_MODE_LATCH /*900*/:
                codeIndex2 = textCompaction(codewords, codeIndex2, result);
                break;
            case BYTE_COMPACTION_MODE_LATCH /*901*/:
            case BYTE_COMPACTION_MODE_LATCH_6 /*924*/:
                codeIndex2 = byteCompaction(code, codewords, encoding, codeIndex2, result);
                break;
            case NUMERIC_COMPACTION_MODE_LATCH /*902*/:
                codeIndex2 = numericCompaction(codewords, codeIndex2, result);
                break;
            case MODE_SHIFT_TO_BYTE_COMPACTION_MODE /*913*/:
                codeIndex = codeIndex2 + 1;
                result.append((char) codewords[codeIndex2]);
                codeIndex2 = codeIndex;
                break;
            case MACRO_PDF417_TERMINATOR /*922*/:
            case BEGIN_MACRO_PDF417_OPTIONAL_FIELD /*923*/:
                throw FormatException.getFormatInstance();
            case ECI_USER_DEFINED /*925*/:
                codeIndex2++;
                break;
            case ECI_GENERAL_PURPOSE /*926*/:
                codeIndex2 += 2;
                break;
            case ECI_CHARSET /*927*/:
                codeIndex = codeIndex2 + 1;
                encoding = Charset.forName(CharacterSetECI.getCharacterSetECIByValue
                        (codewords[codeIndex2]).name());
                codeIndex2 = codeIndex;
                break;
            case 928:
                codeIndex2 = decodeMacroBlock(codewords, codeIndex2, resultMetadata);
                break;
            default:
                codeIndex2 = textCompaction(codewords, codeIndex2 - 1, result);
                break;
        }
        if (codeIndex2 < codewords.length) {
            codeIndex = codeIndex2 + 1;
            code = codewords[codeIndex2];
            codeIndex2 = 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;
}
项目:boohee_v5.6    文件:DecodedBitStreamParser.java   
private static int decodeMacroBlock(int[] codewords, int codeIndex, PDF417ResultMetadata
        resultMetadata) throws FormatException {
    if (codeIndex + 2 > codewords[0]) {
        throw FormatException.getFormatInstance();
    }
    int[] segmentIndexArray = new int[2];
    int i = 0;
    while (i < 2) {
        segmentIndexArray[i] = codewords[codeIndex];
        i++;
        codeIndex++;
    }
    resultMetadata.setSegmentIndex(Integer.parseInt(decodeBase900toBase10(segmentIndexArray,
            2)));
    StringBuilder fileId = new StringBuilder();
    codeIndex = textCompaction(codewords, codeIndex, fileId);
    resultMetadata.setFileId(fileId.toString());
    if (codewords[codeIndex] == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) {
        codeIndex++;
        int[] additionalOptionCodeWords = new int[(codewords[0] - codeIndex)];
        int additionalOptionCodeWordsIndex = 0;
        boolean end = false;
        while (codeIndex < codewords[0] && !end) {
            int codeIndex2 = codeIndex + 1;
            int code = codewords[codeIndex];
            if (code < TEXT_COMPACTION_MODE_LATCH) {
                int additionalOptionCodeWordsIndex2 = additionalOptionCodeWordsIndex + 1;
                additionalOptionCodeWords[additionalOptionCodeWordsIndex] = code;
                additionalOptionCodeWordsIndex = additionalOptionCodeWordsIndex2;
                codeIndex = codeIndex2;
            } else {
                switch (code) {
                    case MACRO_PDF417_TERMINATOR /*922*/:
                        resultMetadata.setLastSegment(true);
                        codeIndex = codeIndex2 + 1;
                        end = true;
                        break;
                    default:
                        throw FormatException.getFormatInstance();
                }
            }
        }
        resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords,
                additionalOptionCodeWordsIndex));
        return codeIndex;
    } else if (codewords[codeIndex] != MACRO_PDF417_TERMINATOR) {
        return codeIndex;
    } else {
        resultMetadata.setLastSegment(true);
        return codeIndex + 1;
    }
}
项目:PortraitZXing    文件:DecodedBitStreamParser.java   
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;
}
项目:PortraitZXing    文件:DecodedBitStreamParser.java   
private static int decodeMacroBlock(int[] codewords, int codeIndex, PDF417ResultMetadata resultMetadata)
    throws FormatException {
  if (codeIndex + NUMBER_OF_SEQUENCE_CODEWORDS > codewords[0]) {
    // we must have at least two bytes left for the segment index
    throw FormatException.getFormatInstance();
  }
  int[] segmentIndexArray = new int[NUMBER_OF_SEQUENCE_CODEWORDS];
  for (int i = 0; i < NUMBER_OF_SEQUENCE_CODEWORDS; i++, codeIndex++) {
    segmentIndexArray[i] = codewords[codeIndex];
  }
  resultMetadata.setSegmentIndex(Integer.parseInt(decodeBase900toBase10(segmentIndexArray,
      NUMBER_OF_SEQUENCE_CODEWORDS)));

  StringBuilder fileId = new StringBuilder();
  codeIndex = textCompaction(codewords, codeIndex, fileId);
  resultMetadata.setFileId(fileId.toString());

  if (codewords[codeIndex] == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) {
    codeIndex++;
    int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex];
    int additionalOptionCodeWordsIndex = 0;

    boolean end = false;
    while ((codeIndex < codewords[0]) && !end) {
      int code = codewords[codeIndex++];
      if (code < TEXT_COMPACTION_MODE_LATCH) {
        additionalOptionCodeWords[additionalOptionCodeWordsIndex++] = code;
      } else {
        switch (code) {
          case MACRO_PDF417_TERMINATOR:
            resultMetadata.setLastSegment(true);
            codeIndex++;
            end = true;
            break;
          default:
            throw FormatException.getFormatInstance();
        }
      }
    }

    resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex));
  } else if (codewords[codeIndex] == MACRO_PDF417_TERMINATOR) {
    resultMetadata.setLastSegment(true);
    codeIndex++;
  }

  return codeIndex;
}
项目:PortraitZXing    文件:DecodedBitStreamParser.java   
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;
}
项目:PortraitZXing    文件:DecodedBitStreamParser.java   
private static int decodeMacroBlock(int[] codewords, int codeIndex, PDF417ResultMetadata resultMetadata)
    throws FormatException {
  if (codeIndex + NUMBER_OF_SEQUENCE_CODEWORDS > codewords[0]) {
    // we must have at least two bytes left for the segment index
    throw FormatException.getFormatInstance();
  }
  int[] segmentIndexArray = new int[NUMBER_OF_SEQUENCE_CODEWORDS];
  for (int i = 0; i < NUMBER_OF_SEQUENCE_CODEWORDS; i++, codeIndex++) {
    segmentIndexArray[i] = codewords[codeIndex];
  }
  resultMetadata.setSegmentIndex(Integer.parseInt(decodeBase900toBase10(segmentIndexArray,
      NUMBER_OF_SEQUENCE_CODEWORDS)));

  StringBuilder fileId = new StringBuilder();
  codeIndex = textCompaction(codewords, codeIndex, fileId);
  resultMetadata.setFileId(fileId.toString());

  if (codewords[codeIndex] == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) {
    codeIndex++;
    int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex];
    int additionalOptionCodeWordsIndex = 0;

    boolean end = false;
    while ((codeIndex < codewords[0]) && !end) {
      int code = codewords[codeIndex++];
      if (code < TEXT_COMPACTION_MODE_LATCH) {
        additionalOptionCodeWords[additionalOptionCodeWordsIndex++] = code;
      } else {
        switch (code) {
          case MACRO_PDF417_TERMINATOR:
            resultMetadata.setLastSegment(true);
            codeIndex++;
            end = true;
            break;
          default:
            throw FormatException.getFormatInstance();
        }
      }
    }

    resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex));
  } else if (codewords[codeIndex] == MACRO_PDF417_TERMINATOR) {
    resultMetadata.setLastSegment(true);
    codeIndex++;
  }

  return codeIndex;
}
项目:ZXing-Orient    文件:DecodedBitStreamParser.java   
static DecoderResult decode(int[] codewords, String ecLevel) throws FormatException {
  StringBuilder result = new StringBuilder(codewords.length * 2);
  // 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:
      case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
        codeIndex = byteCompaction(code, codewords, codeIndex, result);
        break;
      case NUMERIC_COMPACTION_MODE_LATCH:
        codeIndex = numericCompaction(codewords, codeIndex, result);
        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;
}
项目:ZXing-Orient    文件:DecodedBitStreamParser.java   
private static int decodeMacroBlock(int[] codewords, int codeIndex, PDF417ResultMetadata resultMetadata)
    throws FormatException {
  if (codeIndex + NUMBER_OF_SEQUENCE_CODEWORDS > codewords[0]) {
    // we must have at least two bytes left for the segment index
    throw FormatException.getFormatInstance();
  }
  int[] segmentIndexArray = new int[NUMBER_OF_SEQUENCE_CODEWORDS];
  for (int i = 0; i < NUMBER_OF_SEQUENCE_CODEWORDS; i++, codeIndex++) {
    segmentIndexArray[i] = codewords[codeIndex];
  }
  resultMetadata.setSegmentIndex(Integer.parseInt(decodeBase900toBase10(segmentIndexArray,
      NUMBER_OF_SEQUENCE_CODEWORDS)));

  StringBuilder fileId = new StringBuilder();
  codeIndex = textCompaction(codewords, codeIndex, fileId);
  resultMetadata.setFileId(fileId.toString());

  if (codewords[codeIndex] == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) {
    codeIndex++;
    int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex];
    int additionalOptionCodeWordsIndex = 0;

    boolean end = false;
    while ((codeIndex < codewords[0]) && !end) {
      int code = codewords[codeIndex++];
      if (code < TEXT_COMPACTION_MODE_LATCH) {
        additionalOptionCodeWords[additionalOptionCodeWordsIndex++] = code;
      } else {
        switch (code) {
          case MACRO_PDF417_TERMINATOR:
            resultMetadata.setLastSegment(true);
            codeIndex++;
            end = true;
            break;
          default:
            throw FormatException.getFormatInstance();
        }
      }
    }

    resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex));
  } else if (codewords[codeIndex] == MACRO_PDF417_TERMINATOR) {
    resultMetadata.setLastSegment(true);
    codeIndex++;
  }

  return codeIndex;
}
项目:event-app    文件:DecodedBitStreamParser.java   
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;
}
项目:event-app    文件:DecodedBitStreamParser.java   
private static int decodeMacroBlock(int[] codewords, int codeIndex, PDF417ResultMetadata resultMetadata)
    throws FormatException {
  if (codeIndex + NUMBER_OF_SEQUENCE_CODEWORDS > codewords[0]) {
    // we must have at least two bytes left for the segment index
    throw FormatException.getFormatInstance();
  }
  int[] segmentIndexArray = new int[NUMBER_OF_SEQUENCE_CODEWORDS];
  for (int i = 0; i < NUMBER_OF_SEQUENCE_CODEWORDS; i++, codeIndex++) {
    segmentIndexArray[i] = codewords[codeIndex];
  }
  resultMetadata.setSegmentIndex(Integer.parseInt(decodeBase900toBase10(segmentIndexArray,
      NUMBER_OF_SEQUENCE_CODEWORDS)));

  StringBuilder fileId = new StringBuilder();
  codeIndex = textCompaction(codewords, codeIndex, fileId);
  resultMetadata.setFileId(fileId.toString());

  if (codewords[codeIndex] == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) {
    codeIndex++;
    int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex];
    int additionalOptionCodeWordsIndex = 0;

    boolean end = false;
    while ((codeIndex < codewords[0]) && !end) {
      int code = codewords[codeIndex++];
      if (code < TEXT_COMPACTION_MODE_LATCH) {
        additionalOptionCodeWords[additionalOptionCodeWordsIndex++] = code;
      } else {
        switch (code) {
          case MACRO_PDF417_TERMINATOR:
            resultMetadata.setLastSegment(true);
            codeIndex++;
            end = true;
            break;
          default:
            throw FormatException.getFormatInstance();
        }
      }
    }

    resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex));
  } else if (codewords[codeIndex] == MACRO_PDF417_TERMINATOR) {
    resultMetadata.setLastSegment(true);
    codeIndex++;
  }

  return codeIndex;
}
项目:weex-analyzer-android    文件:DecodedBitStreamParser.java   
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;
}
项目:weex-analyzer-android    文件:DecodedBitStreamParser.java   
private static int decodeMacroBlock(int[] codewords, int codeIndex, PDF417ResultMetadata resultMetadata)
    throws FormatException {
  if (codeIndex + NUMBER_OF_SEQUENCE_CODEWORDS > codewords[0]) {
    // we must have at least two bytes left for the segment index
    throw FormatException.getFormatInstance();
  }
  int[] segmentIndexArray = new int[NUMBER_OF_SEQUENCE_CODEWORDS];
  for (int i = 0; i < NUMBER_OF_SEQUENCE_CODEWORDS; i++, codeIndex++) {
    segmentIndexArray[i] = codewords[codeIndex];
  }
  resultMetadata.setSegmentIndex(Integer.parseInt(decodeBase900toBase10(segmentIndexArray,
      NUMBER_OF_SEQUENCE_CODEWORDS)));

  StringBuilder fileId = new StringBuilder();
  codeIndex = textCompaction(codewords, codeIndex, fileId);
  resultMetadata.setFileId(fileId.toString());

  if (codewords[codeIndex] == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) {
    codeIndex++;
    int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex];
    int additionalOptionCodeWordsIndex = 0;

    boolean end = false;
    while ((codeIndex < codewords[0]) && !end) {
      int code = codewords[codeIndex++];
      if (code < TEXT_COMPACTION_MODE_LATCH) {
        additionalOptionCodeWords[additionalOptionCodeWordsIndex++] = code;
      } else {
        switch (code) {
          case MACRO_PDF417_TERMINATOR:
            resultMetadata.setLastSegment(true);
            codeIndex++;
            end = true;
            break;
          default:
            throw FormatException.getFormatInstance();
        }
      }
    }

    resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex));
  } else if (codewords[codeIndex] == MACRO_PDF417_TERMINATOR) {
    resultMetadata.setLastSegment(true);
    codeIndex++;
  }

  return codeIndex;
}
项目:weex-3d-map    文件:DecodedBitStreamParser.java   
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;
}
项目:weex-3d-map    文件:DecodedBitStreamParser.java   
private static int decodeMacroBlock(int[] codewords, int codeIndex, PDF417ResultMetadata resultMetadata)
    throws FormatException {
  if (codeIndex + NUMBER_OF_SEQUENCE_CODEWORDS > codewords[0]) {
    // we must have at least two bytes left for the segment index
    throw FormatException.getFormatInstance();
  }
  int[] segmentIndexArray = new int[NUMBER_OF_SEQUENCE_CODEWORDS];
  for (int i = 0; i < NUMBER_OF_SEQUENCE_CODEWORDS; i++, codeIndex++) {
    segmentIndexArray[i] = codewords[codeIndex];
  }
  resultMetadata.setSegmentIndex(Integer.parseInt(decodeBase900toBase10(segmentIndexArray,
      NUMBER_OF_SEQUENCE_CODEWORDS)));

  StringBuilder fileId = new StringBuilder();
  codeIndex = textCompaction(codewords, codeIndex, fileId);
  resultMetadata.setFileId(fileId.toString());

  if (codewords[codeIndex] == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) {
    codeIndex++;
    int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex];
    int additionalOptionCodeWordsIndex = 0;

    boolean end = false;
    while ((codeIndex < codewords[0]) && !end) {
      int code = codewords[codeIndex++];
      if (code < TEXT_COMPACTION_MODE_LATCH) {
        additionalOptionCodeWords[additionalOptionCodeWordsIndex++] = code;
      } else {
        switch (code) {
          case MACRO_PDF417_TERMINATOR:
            resultMetadata.setLastSegment(true);
            codeIndex++;
            end = true;
            break;
          default:
            throw FormatException.getFormatInstance();
        }
      }
    }

    resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex));
  } else if (codewords[codeIndex] == MACRO_PDF417_TERMINATOR) {
    resultMetadata.setLastSegment(true);
    codeIndex++;
  }

  return codeIndex;
}
项目:Weex-TestDemo    文件:DecodedBitStreamParser.java   
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;
}
项目:Weex-TestDemo    文件:DecodedBitStreamParser.java   
private static int decodeMacroBlock(int[] codewords, int codeIndex, PDF417ResultMetadata resultMetadata)
    throws FormatException {
  if (codeIndex + NUMBER_OF_SEQUENCE_CODEWORDS > codewords[0]) {
    // we must have at least two bytes left for the segment index
    throw FormatException.getFormatInstance();
  }
  int[] segmentIndexArray = new int[NUMBER_OF_SEQUENCE_CODEWORDS];
  for (int i = 0; i < NUMBER_OF_SEQUENCE_CODEWORDS; i++, codeIndex++) {
    segmentIndexArray[i] = codewords[codeIndex];
  }
  resultMetadata.setSegmentIndex(Integer.parseInt(decodeBase900toBase10(segmentIndexArray,
      NUMBER_OF_SEQUENCE_CODEWORDS)));

  StringBuilder fileId = new StringBuilder();
  codeIndex = textCompaction(codewords, codeIndex, fileId);
  resultMetadata.setFileId(fileId.toString());

  if (codewords[codeIndex] == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) {
    codeIndex++;
    int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex];
    int additionalOptionCodeWordsIndex = 0;

    boolean end = false;
    while ((codeIndex < codewords[0]) && !end) {
      int code = codewords[codeIndex++];
      if (code < TEXT_COMPACTION_MODE_LATCH) {
        additionalOptionCodeWords[additionalOptionCodeWordsIndex++] = code;
      } else {
        switch (code) {
          case MACRO_PDF417_TERMINATOR:
            resultMetadata.setLastSegment(true);
            codeIndex++;
            end = true;
            break;
          default:
            throw FormatException.getFormatInstance();
        }
      }
    }

    resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex));
  } else if (codewords[codeIndex] == MACRO_PDF417_TERMINATOR) {
    resultMetadata.setLastSegment(true);
    codeIndex++;
  }

  return codeIndex;
}
项目:QrScan_Demo    文件:DecodedBitStreamParser.java   
static DecoderResult decode(int[] codewords, String ecLevel) throws FormatException {
  StringBuilder result = new StringBuilder(codewords.length * 2);
  // 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:
      case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
        codeIndex = byteCompaction(code, codewords, codeIndex, result);
        break;
      case NUMERIC_COMPACTION_MODE_LATCH:
        codeIndex = numericCompaction(codewords, codeIndex, result);
        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;
}
项目:QrScan_Demo    文件:DecodedBitStreamParser.java   
private static int decodeMacroBlock(int[] codewords, int codeIndex, PDF417ResultMetadata resultMetadata)
    throws FormatException {
  if (codeIndex + NUMBER_OF_SEQUENCE_CODEWORDS > codewords[0]) {
    // we must have at least two bytes left for the segment index
    throw FormatException.getFormatInstance();
  }
  int[] segmentIndexArray = new int[NUMBER_OF_SEQUENCE_CODEWORDS];
  for (int i = 0; i < NUMBER_OF_SEQUENCE_CODEWORDS; i++, codeIndex++) {
    segmentIndexArray[i] = codewords[codeIndex];
  }
  resultMetadata.setSegmentIndex(Integer.parseInt(decodeBase900toBase10(segmentIndexArray,
      NUMBER_OF_SEQUENCE_CODEWORDS)));

  StringBuilder fileId = new StringBuilder();
  codeIndex = textCompaction(codewords, codeIndex, fileId);
  resultMetadata.setFileId(fileId.toString());

  if (codewords[codeIndex] == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) {
    codeIndex++;
    int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex];
    int additionalOptionCodeWordsIndex = 0;

    boolean end = false;
    while ((codeIndex < codewords[0]) && !end) {
      int code = codewords[codeIndex++];
      if (code < TEXT_COMPACTION_MODE_LATCH) {
        additionalOptionCodeWords[additionalOptionCodeWordsIndex++] = code;
      } else {
        switch (code) {
          case MACRO_PDF417_TERMINATOR:
            resultMetadata.setLastSegment(true);
            codeIndex++;
            end = true;
            break;
          default:
            throw FormatException.getFormatInstance();
        }
      }
    }

    resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex));
  } else if (codewords[codeIndex] == MACRO_PDF417_TERMINATOR) {
    resultMetadata.setLastSegment(true);
    codeIndex++;
  }

  return codeIndex;
}
项目:weex    文件:DecodedBitStreamParser.java   
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;
}
项目:weex    文件:DecodedBitStreamParser.java   
private static int decodeMacroBlock(int[] codewords, int codeIndex, PDF417ResultMetadata resultMetadata)
    throws FormatException {
  if (codeIndex + NUMBER_OF_SEQUENCE_CODEWORDS > codewords[0]) {
    // we must have at least two bytes left for the segment index
    throw FormatException.getFormatInstance();
  }
  int[] segmentIndexArray = new int[NUMBER_OF_SEQUENCE_CODEWORDS];
  for (int i = 0; i < NUMBER_OF_SEQUENCE_CODEWORDS; i++, codeIndex++) {
    segmentIndexArray[i] = codewords[codeIndex];
  }
  resultMetadata.setSegmentIndex(Integer.parseInt(decodeBase900toBase10(segmentIndexArray,
      NUMBER_OF_SEQUENCE_CODEWORDS)));

  StringBuilder fileId = new StringBuilder();
  codeIndex = textCompaction(codewords, codeIndex, fileId);
  resultMetadata.setFileId(fileId.toString());

  if (codewords[codeIndex] == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) {
    codeIndex++;
    int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex];
    int additionalOptionCodeWordsIndex = 0;

    boolean end = false;
    while ((codeIndex < codewords[0]) && !end) {
      int code = codewords[codeIndex++];
      if (code < TEXT_COMPACTION_MODE_LATCH) {
        additionalOptionCodeWords[additionalOptionCodeWordsIndex++] = code;
      } else {
        switch (code) {
          case MACRO_PDF417_TERMINATOR:
            resultMetadata.setLastSegment(true);
            codeIndex++;
            end = true;
            break;
          default:
            throw FormatException.getFormatInstance();
        }
      }
    }

    resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex));
  } else if (codewords[codeIndex] == MACRO_PDF417_TERMINATOR) {
    resultMetadata.setLastSegment(true);
    codeIndex++;
  }

  return codeIndex;
}
项目:TrueTone    文件:DecodedBitStreamParser.java   
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;
}
项目:TrueTone    文件:DecodedBitStreamParser.java   
private static int decodeMacroBlock(int[] codewords, int codeIndex, PDF417ResultMetadata resultMetadata)
        throws FormatException {
    if (codeIndex + NUMBER_OF_SEQUENCE_CODEWORDS > codewords[0]) {
        // we must have at least two bytes left for the segment index
        throw FormatException.getFormatInstance();
    }
    int[] segmentIndexArray = new int[NUMBER_OF_SEQUENCE_CODEWORDS];
    for (int i = 0; i < NUMBER_OF_SEQUENCE_CODEWORDS; i++, codeIndex++) {
        segmentIndexArray[i] = codewords[codeIndex];
    }
    resultMetadata.setSegmentIndex(Integer.parseInt(decodeBase900toBase10(segmentIndexArray,
            NUMBER_OF_SEQUENCE_CODEWORDS)));

    StringBuilder fileId = new StringBuilder();
    codeIndex = textCompaction(codewords, codeIndex, fileId);
    resultMetadata.setFileId(fileId.toString());

    if (codewords[codeIndex] == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) {
        codeIndex++;
        int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex];
        int additionalOptionCodeWordsIndex = 0;

        boolean end = false;
        while ((codeIndex < codewords[0]) && !end) {
            int code = codewords[codeIndex++];
            if (code < TEXT_COMPACTION_MODE_LATCH) {
                additionalOptionCodeWords[additionalOptionCodeWordsIndex++] = code;
            } else {
                switch (code) {
                    case MACRO_PDF417_TERMINATOR:
                        resultMetadata.setLastSegment(true);
                        codeIndex++;
                        end = true;
                        break;
                    default:
                        throw FormatException.getFormatInstance();
                }
            }
        }

        resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex));
    } else if (codewords[codeIndex] == MACRO_PDF417_TERMINATOR) {
        resultMetadata.setLastSegment(true);
        codeIndex++;
    }

    return codeIndex;
}
项目:Discounty    文件:DecodedBitStreamParser.java   
static DecoderResult decode(int[] codewords, String ecLevel) throws FormatException {
    StringBuilder result = new StringBuilder(codewords.length * 2);
    // 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:
                codeIndex = byteCompaction(code, codewords, codeIndex, result);
                break;
            case NUMERIC_COMPACTION_MODE_LATCH:
                codeIndex = numericCompaction(codewords, codeIndex, result);
                break;
            case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
                codeIndex = byteCompaction(code, codewords, codeIndex, result);
                break;
            case BYTE_COMPACTION_MODE_LATCH_6:
                codeIndex = byteCompaction(code, codewords, codeIndex, result);
                break;
            case BEGIN_MACRO_PDF417_CONTROL_BLOCK:
                codeIndex = decodeMacroBlock(codewords, codeIndex, resultMetadata);
                break;
            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;
}
项目:Discounty    文件:DecodedBitStreamParser.java   
private static int decodeMacroBlock(int[] codewords, int codeIndex, PDF417ResultMetadata resultMetadata)
        throws FormatException {
    if (codeIndex + NUMBER_OF_SEQUENCE_CODEWORDS > codewords[0]) {
        // we must have at least two bytes left for the segment index
        throw FormatException.getFormatInstance();
    }
    int[] segmentIndexArray = new int[NUMBER_OF_SEQUENCE_CODEWORDS];
    for (int i = 0; i < NUMBER_OF_SEQUENCE_CODEWORDS; i++, codeIndex++) {
        segmentIndexArray[i] = codewords[codeIndex];
    }
    resultMetadata.setSegmentIndex(Integer.parseInt(decodeBase900toBase10(segmentIndexArray,
            NUMBER_OF_SEQUENCE_CODEWORDS)));

    StringBuilder fileId = new StringBuilder();
    codeIndex = textCompaction(codewords, codeIndex, fileId);
    resultMetadata.setFileId(fileId.toString());

    if (codewords[codeIndex] == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) {
        codeIndex++;
        int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex];
        int additionalOptionCodeWordsIndex = 0;

        boolean end = false;
        while ((codeIndex < codewords[0]) && !end) {
            int code = codewords[codeIndex++];
            if (code < TEXT_COMPACTION_MODE_LATCH) {
                additionalOptionCodeWords[additionalOptionCodeWordsIndex++] = code;
            } else {
                switch (code) {
                    case MACRO_PDF417_TERMINATOR:
                        resultMetadata.setLastSegment(true);
                        codeIndex++;
                        end = true;
                        break;
                    default:
                        throw FormatException.getFormatInstance();
                }
            }
        }

        resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex));
    } else if (codewords[codeIndex] == MACRO_PDF417_TERMINATOR) {
        resultMetadata.setLastSegment(true);
        codeIndex++;
    }

    return codeIndex;
}
项目:bushido-android-app    文件:DecodedBitStreamParser.java   
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;
}
项目:bushido-android-app    文件:DecodedBitStreamParser.java   
private static int decodeMacroBlock(int[] codewords, int codeIndex, PDF417ResultMetadata resultMetadata)
    throws FormatException {
  if (codeIndex + NUMBER_OF_SEQUENCE_CODEWORDS > codewords[0]) {
    // we must have at least two bytes left for the segment index
    throw FormatException.getFormatInstance();
  }
  int[] segmentIndexArray = new int[NUMBER_OF_SEQUENCE_CODEWORDS];
  for (int i = 0; i < NUMBER_OF_SEQUENCE_CODEWORDS; i++, codeIndex++) {
    segmentIndexArray[i] = codewords[codeIndex];
  }
  resultMetadata.setSegmentIndex(Integer.parseInt(decodeBase900toBase10(segmentIndexArray,
      NUMBER_OF_SEQUENCE_CODEWORDS)));

  StringBuilder fileId = new StringBuilder();
  codeIndex = textCompaction(codewords, codeIndex, fileId);
  resultMetadata.setFileId(fileId.toString());

  if (codewords[codeIndex] == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) {
    codeIndex++;
    int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex];
    int additionalOptionCodeWordsIndex = 0;

    boolean end = false;
    while ((codeIndex < codewords[0]) && !end) {
      int code = codewords[codeIndex++];
      if (code < TEXT_COMPACTION_MODE_LATCH) {
        additionalOptionCodeWords[additionalOptionCodeWordsIndex++] = code;
      } else {
        switch (code) {
          case MACRO_PDF417_TERMINATOR:
            resultMetadata.setLastSegment(true);
            codeIndex++;
            end = true;
            break;
          default:
            throw FormatException.getFormatInstance();
        }
      }
    }

    resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex));
  } else if (codewords[codeIndex] == MACRO_PDF417_TERMINATOR) {
    resultMetadata.setLastSegment(true);
    codeIndex++;
  }

  return codeIndex;
}
项目:Android-Birdcopy-Application    文件:DecodedBitStreamParser.java   
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;
}
项目:Android-Birdcopy-Application    文件:DecodedBitStreamParser.java   
private static int decodeMacroBlock(int[] codewords, int codeIndex, PDF417ResultMetadata resultMetadata)
    throws FormatException {
  if (codeIndex + NUMBER_OF_SEQUENCE_CODEWORDS > codewords[0]) {
    // we must have at least two bytes left for the segment index
    throw FormatException.getFormatInstance();
  }
  int[] segmentIndexArray = new int[NUMBER_OF_SEQUENCE_CODEWORDS];
  for (int i = 0; i < NUMBER_OF_SEQUENCE_CODEWORDS; i++, codeIndex++) {
    segmentIndexArray[i] = codewords[codeIndex];
  }
  resultMetadata.setSegmentIndex(Integer.parseInt(decodeBase900toBase10(segmentIndexArray,
      NUMBER_OF_SEQUENCE_CODEWORDS)));

  StringBuilder fileId = new StringBuilder();
  codeIndex = textCompaction(codewords, codeIndex, fileId);
  resultMetadata.setFileId(fileId.toString());

  if (codewords[codeIndex] == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) {
    codeIndex++;
    int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex];
    int additionalOptionCodeWordsIndex = 0;

    boolean end = false;
    while ((codeIndex < codewords[0]) && !end) {
      int code = codewords[codeIndex++];
      if (code < TEXT_COMPACTION_MODE_LATCH) {
        additionalOptionCodeWords[additionalOptionCodeWordsIndex++] = code;
      } else {
        switch (code) {
          case MACRO_PDF417_TERMINATOR:
            resultMetadata.setLastSegment(true);
            codeIndex++;
            end = true;
            break;
          default:
            throw FormatException.getFormatInstance();
        }
      }
    }

    resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex));
  } else if (codewords[codeIndex] == MACRO_PDF417_TERMINATOR) {
    resultMetadata.setLastSegment(true);
    codeIndex++;
  }

  return codeIndex;
}
项目:zxing-bsplus    文件:DecodedBitStreamParser.java   
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;
}
项目:zxing-bsplus    文件:DecodedBitStreamParser.java   
private static int decodeMacroBlock(int[] codewords, int codeIndex, PDF417ResultMetadata resultMetadata)
    throws FormatException {
  if (codeIndex + NUMBER_OF_SEQUENCE_CODEWORDS > codewords[0]) {
    // we must have at least two bytes left for the segment index
    throw FormatException.getFormatInstance();
  }
  int[] segmentIndexArray = new int[NUMBER_OF_SEQUENCE_CODEWORDS];
  for (int i = 0; i < NUMBER_OF_SEQUENCE_CODEWORDS; i++, codeIndex++) {
    segmentIndexArray[i] = codewords[codeIndex];
  }
  resultMetadata.setSegmentIndex(Integer.parseInt(decodeBase900toBase10(segmentIndexArray,
      NUMBER_OF_SEQUENCE_CODEWORDS)));

  StringBuilder fileId = new StringBuilder();
  codeIndex = textCompaction(codewords, codeIndex, fileId);
  resultMetadata.setFileId(fileId.toString());

  if (codewords[codeIndex] == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) {
    codeIndex++;
    int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex];
    int additionalOptionCodeWordsIndex = 0;

    boolean end = false;
    while ((codeIndex < codewords[0]) && !end) {
      int code = codewords[codeIndex++];
      if (code < TEXT_COMPACTION_MODE_LATCH) {
        additionalOptionCodeWords[additionalOptionCodeWordsIndex++] = code;
      } else {
        switch (code) {
          case MACRO_PDF417_TERMINATOR:
            resultMetadata.setLastSegment(true);
            codeIndex++;
            end = true;
            break;
          default:
            throw FormatException.getFormatInstance();
        }
      }
    }

    resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex));
  } else if (codewords[codeIndex] == MACRO_PDF417_TERMINATOR) {
    resultMetadata.setLastSegment(true);
    codeIndex++;
  }

  return codeIndex;
}
项目:ZxingCore    文件:DecodedBitStreamParser.java   
static DecoderResult decode(int[] codewords, String ecLevel) throws FormatException {
  StringBuilder result = new StringBuilder(codewords.length * 2);
  // 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:
        codeIndex = byteCompaction(code, codewords, codeIndex, result);
        break;
      case NUMERIC_COMPACTION_MODE_LATCH:
        codeIndex = numericCompaction(codewords, codeIndex, result);
        break;
      case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
        codeIndex = byteCompaction(code, codewords, codeIndex, result);
        break;
      case BYTE_COMPACTION_MODE_LATCH_6:
        codeIndex = byteCompaction(code, codewords, codeIndex, result);
        break;
      case BEGIN_MACRO_PDF417_CONTROL_BLOCK:
        codeIndex = decodeMacroBlock(codewords, codeIndex, resultMetadata);
        break;
      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;
}
项目:ZxingCore    文件:DecodedBitStreamParser.java   
private static int decodeMacroBlock(int[] codewords, int codeIndex, PDF417ResultMetadata resultMetadata)
    throws FormatException {
  if (codeIndex + NUMBER_OF_SEQUENCE_CODEWORDS > codewords[0]) {
    // we must have at least two bytes left for the segment index
    throw FormatException.getFormatInstance();
  }
  int[] segmentIndexArray = new int[NUMBER_OF_SEQUENCE_CODEWORDS];
  for (int i = 0; i < NUMBER_OF_SEQUENCE_CODEWORDS; i++, codeIndex++) {
    segmentIndexArray[i] = codewords[codeIndex];
  }
  resultMetadata.setSegmentIndex(Integer.parseInt(decodeBase900toBase10(segmentIndexArray,
      NUMBER_OF_SEQUENCE_CODEWORDS)));

  StringBuilder fileId = new StringBuilder();
  codeIndex = textCompaction(codewords, codeIndex, fileId);
  resultMetadata.setFileId(fileId.toString());

  if (codewords[codeIndex] == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) {
    codeIndex++;
    int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex];
    int additionalOptionCodeWordsIndex = 0;

    boolean end = false;
    while ((codeIndex < codewords[0]) && !end) {
      int code = codewords[codeIndex++];
      if (code < TEXT_COMPACTION_MODE_LATCH) {
        additionalOptionCodeWords[additionalOptionCodeWordsIndex++] = code;
      } else {
        switch (code) {
          case MACRO_PDF417_TERMINATOR:
            resultMetadata.setLastSegment(true);
            codeIndex++;
            end = true;
            break;
          default:
            throw FormatException.getFormatInstance();
        }
      }
    }

    resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex));
  } else if (codewords[codeIndex] == MACRO_PDF417_TERMINATOR) {
    resultMetadata.setLastSegment(true);
    codeIndex++;
  }

  return codeIndex;
}