com.google.zxing.pdf417.PDF417ResultMetadata Java Examples

The following examples show how to use com.google.zxing.pdf417.PDF417ResultMetadata. 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 ZXing-Orient 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);
  // 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;
}
 
Example #2
Source File: DecodedBitStreamParser.java    From ZXing-Orient with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example #3
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 #4
Source File: DecodedBitStreamParser.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example #5
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 #6
Source File: DecodedBitStreamParser.java    From weex with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example #7
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 #8
Source File: DecodedBitStreamParser.java    From barcodescanner-lib-aar with MIT License 4 votes vote down vote up
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;
}