com.google.zxing.qrcode.decoder.Mode Java Examples

The following examples show how to use com.google.zxing.qrcode.decoder.Mode. 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: Encoder.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".
 */
static void appendBytes(String content,
                        Mode mode,
                        BitArray bits,
                        String encoding) throws WriterException {
  switch (mode) {
    case NUMERIC:
      appendNumericBytes(content, bits);
      break;
    case ALPHANUMERIC:
      appendAlphanumericBytes(content, bits);
      break;
    case BYTE:
      append8BitBytes(content, bits, encoding);
      break;
    case KANJI:
      appendKanjiBytes(content, bits);
      break;
    default:
      throw new WriterException("Invalid mode: " + mode);
  }
}
 
Example #2
Source File: Encoder.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".
 */
static void appendBytes(String content,
                        Mode mode,
                        BitArray bits,
                        String encoding) throws WriterException {
  switch (mode) {
    case NUMERIC:
      appendNumericBytes(content, bits);
      break;
    case ALPHANUMERIC:
      appendAlphanumericBytes(content, bits);
      break;
    case BYTE:
      append8BitBytes(content, bits, encoding);
      break;
    case KANJI:
      appendKanjiBytes(content, bits);
      break;
    default:
      throw new WriterException("Invalid mode: " + mode);
  }
}
 
Example #3
Source File: Encoder.java    From QrCodeScanner with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Choose the best mode by examining the content. Note that 'encoding' is used as a hint;
 * if it is Shift_JIS, and the input is only double-byte Kanji, then we return {@link Mode#KANJI}.
 */
private static Mode chooseMode(String content, String encoding) {
  if ("Shift_JIS".equals(encoding) && isOnlyDoubleByteKanji(content)) {
    // Choose Kanji mode if all input are double-byte characters
    return Mode.KANJI;
  }
  boolean hasNumeric = false;
  boolean hasAlphanumeric = false;
  for (int i = 0; i < content.length(); ++i) {
    char c = content.charAt(i);
    if (c >= '0' && c <= '9') {
      hasNumeric = true;
    } else if (getAlphanumericCode(c) != -1) {
      hasAlphanumeric = true;
    } else {
      return Mode.BYTE;
    }
  }
  if (hasAlphanumeric) {
    return Mode.ALPHANUMERIC;
  }
  if (hasNumeric) {
    return Mode.NUMERIC;
  }
  return Mode.BYTE;
}
 
Example #4
Source File: Encoder.java    From barcodescanner-lib-aar with MIT License 6 votes vote down vote up
/**
 * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".
 */
static void appendBytes(String content,
                        Mode mode,
                        BitArray bits,
                        String encoding) throws WriterException {
  switch (mode) {
    case NUMERIC:
      appendNumericBytes(content, bits);
      break;
    case ALPHANUMERIC:
      appendAlphanumericBytes(content, bits);
      break;
    case BYTE:
      append8BitBytes(content, bits, encoding);
      break;
    case KANJI:
      appendKanjiBytes(content, bits);
      break;
    default:
      throw new WriterException("Invalid mode: " + mode);
  }
}
 
Example #5
Source File: Encoder.java    From Tesseract-OCR-Scanner with Apache License 2.0 6 votes vote down vote up
/**
 * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".
 */
static void appendBytes(String content,
                        Mode mode,
                        BitArray bits,
                        String encoding) throws WriterException {
  switch (mode) {
    case NUMERIC:
      appendNumericBytes(content, bits);
      break;
    case ALPHANUMERIC:
      appendAlphanumericBytes(content, bits);
      break;
    case BYTE:
      append8BitBytes(content, bits, encoding);
      break;
    case KANJI:
      appendKanjiBytes(content, bits);
      break;
    default:
      throw new WriterException("Invalid mode: " + mode);
  }
}
 
Example #6
Source File: Encoder.java    From QrCodeScanner with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".
 */
static void appendBytes(String content,
                        Mode mode,
                        BitArray bits,
                        String encoding) throws WriterException {
  switch (mode) {
    case NUMERIC:
      appendNumericBytes(content, bits);
      break;
    case ALPHANUMERIC:
      appendAlphanumericBytes(content, bits);
      break;
    case BYTE:
      append8BitBytes(content, bits, encoding);
      break;
    case KANJI:
      appendKanjiBytes(content, bits);
      break;
    default:
      throw new WriterException("Invalid mode: " + mode);
  }
}
 
Example #7
Source File: Encoder.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
/**
 * Append "bytes" in "mode" mode (encoding) into "bits". On success, store
 * the result in "bits".
 */
static void appendBytes(String content, Mode mode, BitArray bits, String encoding) throws WriterException {
	switch (mode) {
	case NUMERIC:
		appendNumericBytes(content, bits);
		break;
	case ALPHANUMERIC:
		appendAlphanumericBytes(content, bits);
		break;
	case BYTE:
		append8BitBytes(content, bits, encoding);
		break;
	case KANJI:
		appendKanjiBytes(content, bits);
		break;
	default:
		throw new WriterException("Invalid mode: " + mode);
	}
}
 
Example #8
Source File: Encoder.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
private static void a(int i, ErrorCorrectionLevel errorcorrectionlevel, Mode mode, QRCode qrcode)
{
    qrcode.setECLevel(errorcorrectionlevel);
    qrcode.setMode(mode);
    for (int j = 1; j <= 40; j++)
    {
        Version version = Version.getVersionForNumber(j);
        int k = version.getTotalCodewords();
        com.google.zxing.qrcode.decoder.Version.ECBlocks ecblocks = version.getECBlocksForLevel(errorcorrectionlevel);
        int l = ecblocks.getTotalECCodewords();
        int i1 = ecblocks.getNumBlocks();
        int j1 = k - l;
        if (j1 >= a(i, version, mode))
        {
            qrcode.setVersion(j);
            qrcode.setNumTotalBytes(k);
            qrcode.setNumDataBytes(j1);
            qrcode.setNumRSBlocks(i1);
            qrcode.setNumECBytes(l);
            qrcode.setMatrixWidth(version.getDimensionForVersion());
            return;
        }
    }

    throw new WriterException("Cannot find proper rs block info (input data too big?)");
}
 
Example #9
Source File: Encoder.java    From ZXing-Orient with Apache License 2.0 6 votes vote down vote up
/**
 * Choose the best mode by examining the content. Note that 'encoding' is used as a hint;
 * if it is Shift_JIS, and the input is only double-byte Kanji, then we return {@link Mode#KANJI}.
 */
private static Mode chooseMode(String content, String encoding) {
  if ("Shift_JIS".equals(encoding)) {
    // Choose Kanji mode if all input are double-byte characters
    return isOnlyDoubleByteKanji(content) ? Mode.KANJI : Mode.BYTE;
  }
  boolean hasNumeric = false;
  boolean hasAlphanumeric = false;
  for (int i = 0; i < content.length(); ++i) {
    char c = content.charAt(i);
    if (c >= '0' && c <= '9') {
      hasNumeric = true;
    } else if (getAlphanumericCode(c) != -1) {
      hasAlphanumeric = true;
    } else {
      return Mode.BYTE;
    }
  }
  if (hasAlphanumeric) {
    return Mode.ALPHANUMERIC;
  }
  if (hasNumeric) {
    return Mode.NUMERIC;
  }
  return Mode.BYTE;
}
 
Example #10
Source File: Encoder.java    From ZXing-Orient with Apache License 2.0 6 votes vote down vote up
/**
 * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".
 */
static void appendBytes(String content,
                        Mode mode,
                        BitArray bits,
                        String encoding) throws WriterException {
  switch (mode) {
    case NUMERIC:
      appendNumericBytes(content, bits);
      break;
    case ALPHANUMERIC:
      appendAlphanumericBytes(content, bits);
      break;
    case BYTE:
      append8BitBytes(content, bits, encoding);
      break;
    case KANJI:
      appendKanjiBytes(content, bits);
      break;
    default:
      throw new WriterException("Invalid mode: " + mode);
  }
}
 
Example #11
Source File: Encoder.java    From ScreenCapture with MIT License 6 votes vote down vote up
/**
 * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".
 */
static void appendBytes(String content,
                        Mode mode,
                        BitArray bits,
                        String encoding) throws WriterException {
  switch (mode) {
    case NUMERIC:
      appendNumericBytes(content, bits);
      break;
    case ALPHANUMERIC:
      appendAlphanumericBytes(content, bits);
      break;
    case BYTE:
      append8BitBytes(content, bits, encoding);
      break;
    case KANJI:
      appendKanjiBytes(content, bits);
      break;
    default:
      throw new WriterException("Invalid mode: " + mode);
  }
}
 
Example #12
Source File: Encoder.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
/**
 * Choose the best mode by examining the content. Note that 'encoding' is
 * used as a hint; if it is Shift_JIS, and the input is only double-byte
 * Kanji, then we return {@link Mode#KANJI}.
 */
private static Mode chooseMode(String content, String encoding) {
	if ("Shift_JIS".equals(encoding)) {
		// Choose Kanji mode if all input are double-byte characters
		return isOnlyDoubleByteKanji(content) ? Mode.KANJI : Mode.BYTE;
	}
	boolean hasNumeric = false;
	boolean hasAlphanumeric = false;
	for (int i = 0; i < content.length(); ++i) {
		char c = content.charAt(i);
		if (c >= '0' && c <= '9') {
			hasNumeric = true;
		} else if (getAlphanumericCode(c) != -1) {
			hasAlphanumeric = true;
		} else {
			return Mode.BYTE;
		}
	}
	if (hasAlphanumeric) {
		return Mode.ALPHANUMERIC;
	}
	if (hasNumeric) {
		return Mode.NUMERIC;
	}
	return Mode.BYTE;
}
 
Example #13
Source File: Encoder.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
/**
 * Choose the best mode by examining the content. Note that 'encoding' is used as a hint;
 * if it is Shift_JIS, and the input is only double-byte Kanji, then we return {@link Mode#KANJI}.
 */
private static Mode chooseMode(String content, String encoding) {
  if ("Shift_JIS".equals(encoding) && isOnlyDoubleByteKanji(content)) {
    // Choose Kanji mode if all input are double-byte characters
    return Mode.KANJI;
  }
  boolean hasNumeric = false;
  boolean hasAlphanumeric = false;
  for (int i = 0; i < content.length(); ++i) {
    char c = content.charAt(i);
    if (c >= '0' && c <= '9') {
      hasNumeric = true;
    } else if (getAlphanumericCode(c) != -1) {
      hasAlphanumeric = true;
    } else {
      return Mode.BYTE;
    }
  }
  if (hasAlphanumeric) {
    return Mode.ALPHANUMERIC;
  }
  if (hasNumeric) {
    return Mode.NUMERIC;
  }
  return Mode.BYTE;
}
 
Example #14
Source File: Encoder.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Choose the best mode by examining the content. Note that 'encoding' is used as a hint;
 * if it is Shift_JIS, and the input is only double-byte Kanji, then we return {@link Mode#KANJI}.
 */
private static Mode chooseMode(String content, String encoding) {
  if ("Shift_JIS".equals(encoding) && isOnlyDoubleByteKanji(content)) {
    // Choose Kanji mode if all input are double-byte characters
    return Mode.KANJI;
  }
  boolean hasNumeric = false;
  boolean hasAlphanumeric = false;
  for (int i = 0; i < content.length(); ++i) {
    char c = content.charAt(i);
    if (c >= '0' && c <= '9') {
      hasNumeric = true;
    } else if (getAlphanumericCode(c) != -1) {
      hasAlphanumeric = true;
    } else {
      return Mode.BYTE;
    }
  }
  if (hasAlphanumeric) {
    return Mode.ALPHANUMERIC;
  }
  if (hasNumeric) {
    return Mode.NUMERIC;
  }
  return Mode.BYTE;
}
 
Example #15
Source File: Encoder.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
/**
 * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".
 */
static void appendBytes(String content,
                        Mode mode,
                        BitArray bits,
                        String encoding) throws WriterException {
  switch (mode) {
    case NUMERIC:
      appendNumericBytes(content, bits);
      break;
    case ALPHANUMERIC:
      appendAlphanumericBytes(content, bits);
      break;
    case BYTE:
      append8BitBytes(content, bits, encoding);
      break;
    case KANJI:
      appendKanjiBytes(content, bits);
      break;
    default:
      throw new WriterException("Invalid mode: " + mode);
  }
}
 
Example #16
Source File: Encoder.java    From ZXing-Orient with Apache License 2.0 5 votes vote down vote up
/**
 * Append length info. On success, store the result in "bits".
 */
static void appendLengthInfo(int numLetters, Version version, Mode mode, BitArray bits) throws WriterException {
  int numBits = mode.getCharacterCountBits(version);
  if (numLetters >= (1 << numBits)) {
    throw new WriterException(numLetters + " is bigger than " + ((1 << numBits) - 1));
  }
  bits.appendBits(numLetters, numBits);
}
 
Example #17
Source File: Encoder.java    From barcodescanner-lib-aar with MIT License 5 votes vote down vote up
/**
 * Append length info. On success, store the result in "bits".
 */
static void appendLengthInfo(int numLetters, Version version, Mode mode, BitArray bits) throws WriterException {
  int numBits = mode.getCharacterCountBits(version);
  if (numLetters >= (1 << numBits)) {
    throw new WriterException(numLetters + " is bigger than " + ((1 << numBits) - 1));
  }
  bits.appendBits(numLetters, numBits);
}
 
Example #18
Source File: Encoder.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Append length info. On success, store the result in "bits".
 */
static void appendLengthInfo(int numLetters, Version version, Mode mode, BitArray bits) throws WriterException {
  int numBits = mode.getCharacterCountBits(version);
  if (numLetters >= (1 << numBits)) {
    throw new WriterException(numLetters + " is bigger than " + ((1 << numBits) - 1));
  }
  bits.appendBits(numLetters, numBits);
}
 
Example #19
Source File: Encoder.java    From ScreenCapture with MIT License 5 votes vote down vote up
/**
 * Append length info. On success, store the result in "bits".
 */
static void appendLengthInfo(int numLetters, Version version, Mode mode, BitArray bits) throws WriterException {
  int numBits = mode.getCharacterCountBits(version);
  if (numLetters >= (1 << numBits)) {
    throw new WriterException(numLetters + " is bigger than " + ((1 << numBits) - 1));
  }
  bits.appendBits(numLetters, numBits);
}
 
Example #20
Source File: Encoder.java    From Tesseract-OCR-Scanner with Apache License 2.0 5 votes vote down vote up
/**
 * Decides the smallest version of QR code that will contain all of the provided data.
 *
 * @throws WriterException if the data cannot fit in any version
 */
private static Version recommendVersion(ErrorCorrectionLevel ecLevel,
                                        Mode mode,
                                        BitArray headerBits,
                                        BitArray dataBits) throws WriterException {
  // Hard part: need to know version to know how many bits length takes. But need to know how many
  // bits it takes to know version. First we take a guess at version by assuming version will be
  // the minimum, 1:
  int provisionalBitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, Version.getVersionForNumber(1));
  Version provisionalVersion = chooseVersion(provisionalBitsNeeded, ecLevel);

  // Use that guess to calculate the right version. I am still not sure this works in 100% of cases.
  int bitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, provisionalVersion);
  return chooseVersion(bitsNeeded, ecLevel);
}
 
Example #21
Source File: Encoder.java    From QrCodeScanner with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Decides the smallest version of QR code that will contain all of the provided data.
 *
 * @throws WriterException if the data cannot fit in any version
 */
private static Version recommendVersion(ErrorCorrectionLevel ecLevel,
                                        Mode mode,
                                        BitArray headerBits,
                                        BitArray dataBits) throws WriterException {
  // Hard part: need to know version to know how many bits length takes. But need to know how many
  // bits it takes to know version. First we take a guess at version by assuming version will be
  // the minimum, 1:
  int provisionalBitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, Version.getVersionForNumber(1));
  Version provisionalVersion = chooseVersion(provisionalBitsNeeded, ecLevel);

  // Use that guess to calculate the right version. I am still not sure this works in 100% of cases.
  int bitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, provisionalVersion);
  return chooseVersion(bitsNeeded, ecLevel);
}
 
Example #22
Source File: Encoder.java    From ScreenCapture with MIT License 5 votes vote down vote up
/**
 * Decides the smallest version of QR code that will contain all of the provided data.
 *
 * @throws WriterException if the data cannot fit in any version
 */
private static Version recommendVersion(ErrorCorrectionLevel ecLevel,
                                        Mode mode,
                                        BitArray headerBits,
                                        BitArray dataBits) throws WriterException {
  // Hard part: need to know version to know how many bits length takes. But need to know how many
  // bits it takes to know version. First we take a guess at version by assuming version will be
  // the minimum, 1:
  int provisionalBitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, Version.getVersionForNumber(1));
  Version provisionalVersion = chooseVersion(provisionalBitsNeeded, ecLevel);

  // Use that guess to calculate the right version. I am still not sure this works in 100% of cases.
  int bitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, provisionalVersion);
  return chooseVersion(bitsNeeded, ecLevel);
}
 
Example #23
Source File: Encoder.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Decides the smallest version of QR code that will contain all of the provided data.
 *
 * @throws WriterException if the data cannot fit in any version
 */
private static Version recommendVersion(ErrorCorrectionLevel ecLevel,
                                        Mode mode,
                                        BitArray headerBits,
                                        BitArray dataBits) throws WriterException {
  // Hard part: need to know version to know how many bits length takes. But need to know how many
  // bits it takes to know version. First we take a guess at version by assuming version will be
  // the minimum, 1:
  int provisionalBitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, Version.getVersionForNumber(1));
  Version provisionalVersion = chooseVersion(provisionalBitsNeeded, ecLevel);

  // Use that guess to calculate the right version. I am still not sure this works in 100% of cases.
  int bitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, provisionalVersion);
  return chooseVersion(bitsNeeded, ecLevel);
}
 
Example #24
Source File: Encoder.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
/**
 * Append length info. On success, store the result in "bits".
 */
static void appendLengthInfo(int numLetters, Version version, Mode mode, BitArray bits) throws WriterException {
	int numBits = mode.getCharacterCountBits(version);
	if (numLetters >= (1 << numBits)) {
		throw new WriterException(numLetters + " is bigger than " + ((1 << numBits) - 1));
	}
	bits.appendBits(numLetters, numBits);
}
 
Example #25
Source File: Encoder.java    From barcodescanner-lib-aar with MIT License 5 votes vote down vote up
/**
 * Decides the smallest version of QR code that will contain all of the provided data.
 *
 * @throws WriterException if the data cannot fit in any version
 */
private static Version recommendVersion(ErrorCorrectionLevel ecLevel,
                                        Mode mode,
                                        BitArray headerBits,
                                        BitArray dataBits) throws WriterException {
  // Hard part: need to know version to know how many bits length takes. But need to know how many
  // bits it takes to know version. First we take a guess at version by assuming version will be
  // the minimum, 1:
  int provisionalBitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, Version.getVersionForNumber(1));
  Version provisionalVersion = chooseVersion(provisionalBitsNeeded, ecLevel);

  // Use that guess to calculate the right version. I am still not sure this works in 100% of cases.
  int bitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, provisionalVersion);
  return chooseVersion(bitsNeeded, ecLevel);
}
 
Example #26
Source File: Encoder.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Decides the smallest version of QR code that will contain all of the provided data.
 *
 * @throws WriterException if the data cannot fit in any version
 */
private static Version recommendVersion(ErrorCorrectionLevel ecLevel,
                                        Mode mode,
                                        BitArray headerBits,
                                        BitArray dataBits) throws WriterException {
  // Hard part: need to know version to know how many bits length takes. But need to know how many
  // bits it takes to know version. First we take a guess at version by assuming version will be
  // the minimum, 1:
  int provisionalBitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, Version.getVersionForNumber(1));
  Version provisionalVersion = chooseVersion(provisionalBitsNeeded, ecLevel);

  // Use that guess to calculate the right version. I am still not sure this works in 100% of cases.
  int bitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, provisionalVersion);
  return chooseVersion(bitsNeeded, ecLevel);
}
 
Example #27
Source File: Encoder.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Append length info. On success, store the result in "bits".
 */
static void appendLengthInfo(int numLetters, Version version, Mode mode, BitArray bits) throws WriterException {
  int numBits = mode.getCharacterCountBits(version);
  if (numLetters >= (1 << numBits)) {
    throw new WriterException(numLetters + " is bigger than " + ((1 << numBits) - 1));
  }
  bits.appendBits(numLetters, numBits);
}
 
Example #28
Source File: QRCode.java    From RipplePower with Apache License 2.0 4 votes vote down vote up
public Mode getMode() {
	return mode;
}
 
Example #29
Source File: QRCode.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public Mode getMode() {
  return mode;
}
 
Example #30
Source File: Encoder.java    From reacteu-app with MIT License 4 votes vote down vote up
/**
 * Append mode info. On success, store the result in "bits".
 */
static void appendModeInfo(Mode mode, BitArray bits) {
  bits.appendBits(mode.getBits(), 4);
}