if (targetInfo == maskedFormatInfo1 || targetInfo == maskedFormatInfo2) { return new FormatInformation(decodeInfo[1]); int bitsDifference = numBitsDiffering(maskedFormatInfo1, targetInfo); if (bitsDifference < bestDifference) { bestFormatInfo = decodeInfo[1]; bitsDifference = numBitsDiffering(maskedFormatInfo2, targetInfo); if (bitsDifference < bestDifference) { bestFormatInfo = decodeInfo[1]; return new FormatInformation(bestFormatInfo);
/** * @param maskedFormatInfo1 format info indicator, with mask still applied * @param maskedFormatInfo2 second copy of same info; both are checked at the same time * to establish best match * @return information about the format it specifies, or {@code null} * if doesn't seem to match any known pattern */ static FormatInformation decodeFormatInformation(int maskedFormatInfo1, int maskedFormatInfo2) { FormatInformation formatInfo = doDecodeFormatInformation(maskedFormatInfo1, maskedFormatInfo2); if (formatInfo != null) { return formatInfo; } // Should return null, but, some QR codes apparently // do not mask this info. Try again by actually masking the pattern // first return doDecodeFormatInformation(maskedFormatInfo1 ^ FORMAT_INFO_MASK_QR, maskedFormatInfo2 ^ FORMAT_INFO_MASK_QR); }
/** * Revert the mask removal done while reading the code words. The bit matrix should revert to its original state. */ void remask() { if (parsedFormatInfo == null) { return; // We have no format information, and have no data mask } DataMask dataMask = DataMask.values()[parsedFormatInfo.getDataMask()]; int dimension = bitMatrix.getHeight(); dataMask.unmaskBitMatrix(bitMatrix, dimension); }
static Version decodeVersionInformation(int versionBits) { int bestDifference = Integer.MAX_VALUE; int bestVersion = 0; for (int i = 0; i < VERSION_DECODE_INFO.length; i++) { int targetVersion = VERSION_DECODE_INFO[i]; // Do the version info bits match exactly? done. if (targetVersion == versionBits) { return getVersionForNumber(i + 7); } // Otherwise see if this is the closest to a real version info bit string // we have seen so far int bitsDifference = FormatInformation.numBitsDiffering(versionBits, targetVersion); if (bitsDifference < bestDifference) { bestVersion = i + 7; bestDifference = bitsDifference; } } // We can tolerate up to 3 bits of error since no two version info codewords will // differ in less than 8 bits. if (bestDifference <= 3) { return getVersionForNumber(bestVersion); } // If we didn't find a close enough match, fail return null; }
parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits1, formatInfoBits2); if (parsedFormatInfo != null) { return parsedFormatInfo;
private DecoderResult decode(BitMatrixParser parser, Map<DecodeHintType,?> hints) throws FormatException, ChecksumException { Version version = parser.readVersion(); ErrorCorrectionLevel ecLevel = parser.readFormatInformation().getErrorCorrectionLevel(); // Read codewords byte[] codewords = parser.readCodewords(); // Separate into data blocks DataBlock[] dataBlocks = DataBlock.getDataBlocks(codewords, version, ecLevel); // Count total number of data bytes int totalBytes = 0; for (DataBlock dataBlock : dataBlocks) { totalBytes += dataBlock.getNumDataCodewords(); } byte[] resultBytes = new byte[totalBytes]; int resultOffset = 0; // Error-correct and copy data blocks together into a stream of bytes for (DataBlock dataBlock : dataBlocks) { byte[] codewordBytes = dataBlock.getCodewords(); int numDataCodewords = dataBlock.getNumDataCodewords(); correctErrors(codewordBytes, numDataCodewords); for (int i = 0; i < numDataCodewords; i++) { resultBytes[resultOffset++] = codewordBytes[i]; } } // Decode the contents of that stream of bytes return DecodedBitStreamParser.decode(resultBytes, version, ecLevel, hints); }
/** * Revert the mask removal done while reading the code words. The bit matrix should revert to its original state. */ void remask() { if (parsedFormatInfo == null) { return; // We have no format information, and have no data mask } DataMask dataMask = DataMask.values()[parsedFormatInfo.getDataMask()]; int dimension = bitMatrix.getHeight(); dataMask.unmaskBitMatrix(bitMatrix, dimension); }
static Version decodeVersionInformation(int versionBits) { int bestDifference = Integer.MAX_VALUE; int bestVersion = 0; for (int i = 0; i < VERSION_DECODE_INFO.length; i++) { int targetVersion = VERSION_DECODE_INFO[i]; // Do the version info bits match exactly? done. if (targetVersion == versionBits) { return getVersionForNumber(i + 7); } // Otherwise see if this is the closest to a real version info bit string // we have seen so far int bitsDifference = FormatInformation.numBitsDiffering(versionBits, targetVersion); if (bitsDifference < bestDifference) { bestVersion = i + 7; bestDifference = bitsDifference; } } // We can tolerate up to 3 bits of error since no two version info codewords will // differ in less than 8 bits. if (bestDifference <= 3) { return getVersionForNumber(bestVersion); } // If we didn't find a close enough match, fail return null; }
parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits1, formatInfoBits2); if (parsedFormatInfo != null) { return parsedFormatInfo;
private DecoderResult decode(BitMatrixParser parser, Map<DecodeHintType,?> hints) throws FormatException, ChecksumException { Version version = parser.readVersion(); ErrorCorrectionLevel ecLevel = parser.readFormatInformation().getErrorCorrectionLevel(); // Read codewords byte[] codewords = parser.readCodewords(); // Separate into data blocks DataBlock[] dataBlocks = DataBlock.getDataBlocks(codewords, version, ecLevel); // Count total number of data bytes int totalBytes = 0; for (DataBlock dataBlock : dataBlocks) { totalBytes += dataBlock.getNumDataCodewords(); } byte[] resultBytes = new byte[totalBytes]; int resultOffset = 0; // Error-correct and copy data blocks together into a stream of bytes for (DataBlock dataBlock : dataBlocks) { byte[] codewordBytes = dataBlock.getCodewords(); int numDataCodewords = dataBlock.getNumDataCodewords(); correctErrors(codewordBytes, numDataCodewords); for (int i = 0; i < numDataCodewords; i++) { resultBytes[resultOffset++] = codewordBytes[i]; } } // Decode the contents of that stream of bytes return DecodedBitStreamParser.decode(resultBytes, version, ecLevel, hints); }
if (targetInfo == maskedFormatInfo1 || targetInfo == maskedFormatInfo2) { return new FormatInformation(decodeInfo[1]); int bitsDifference = numBitsDiffering(maskedFormatInfo1, targetInfo); if (bitsDifference < bestDifference) { bestFormatInfo = decodeInfo[1]; bitsDifference = numBitsDiffering(maskedFormatInfo2, targetInfo); if (bitsDifference < bestDifference) { bestFormatInfo = decodeInfo[1]; return new FormatInformation(bestFormatInfo);
DataMask dataMask = DataMask.forReference((int) formatInfo.getDataMask()); int dimension = bitMatrix.getHeight(); dataMask.unmaskBitMatrix(bitMatrix, dimension);
/** * @param maskedFormatInfo1 format info indicator, with mask still applied * @param maskedFormatInfo2 second copy of same info; both are checked at the same time * to establish best match * @return information about the format it specifies, or {@code null} * if doesn't seem to match any known pattern */ static FormatInformation decodeFormatInformation(int maskedFormatInfo1, int maskedFormatInfo2) { FormatInformation formatInfo = doDecodeFormatInformation(maskedFormatInfo1, maskedFormatInfo2); if (formatInfo != null) { return formatInfo; } // Should return null, but, some QR codes apparently // do not mask this info. Try again by actually masking the pattern // first return doDecodeFormatInformation(maskedFormatInfo1 ^ FORMAT_INFO_MASK_QR, maskedFormatInfo2 ^ FORMAT_INFO_MASK_QR); }
static Version decodeVersionInformation(int versionBits) { int bestDifference = Integer.MAX_VALUE; int bestVersion = 0; for (int i = 0; i < VERSION_DECODE_INFO.length; i++) { int targetVersion = VERSION_DECODE_INFO[i]; // Do the version info bits match exactly? done. if (targetVersion == versionBits) { return getVersionForNumber(i + 7); } // Otherwise see if this is the closest to a real version info bit string // we have seen so far int bitsDifference = FormatInformation.numBitsDiffering(versionBits, targetVersion); if (bitsDifference < bestDifference) { bestVersion = i + 7; bestDifference = bitsDifference; } } // We can tolerate up to 3 bits of error since no two version info codewords will // differ in less than 8 bits. if (bestDifference <= 3) { return getVersionForNumber(bestVersion); } // If we didn't find a close enough match, fail return null; }
parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits1, formatInfoBits2); if (parsedFormatInfo != null) { return parsedFormatInfo;
ErrorCorrectionLevel ecLevel = parser.readFormatInformation().getErrorCorrectionLevel();
if (targetInfo == maskedFormatInfo1 || targetInfo == maskedFormatInfo2) { return new FormatInformation(decodeInfo[1]); int bitsDifference = numBitsDiffering(maskedFormatInfo1, targetInfo); if (bitsDifference < bestDifference) { bestFormatInfo = decodeInfo[1]; bitsDifference = numBitsDiffering(maskedFormatInfo2, targetInfo); if (bitsDifference < bestDifference) { bestFormatInfo = decodeInfo[1]; return new FormatInformation(bestFormatInfo);
DataMask dataMask = DataMask.values()[formatInfo.getDataMask()]; int dimension = bitMatrix.getHeight(); dataMask.unmaskBitMatrix(bitMatrix, dimension);
/** * @param maskedFormatInfo1 format info indicator, with mask still applied * @param maskedFormatInfo2 second copy of same info; both are checked at the same time * to establish best match * @return information about the format it specifies, or <code>null</code> * if doesn't seem to match any known pattern */ static FormatInformation decodeFormatInformation(int maskedFormatInfo1, int maskedFormatInfo2) { FormatInformation formatInfo = doDecodeFormatInformation(maskedFormatInfo1, maskedFormatInfo2); if (formatInfo != null) { return formatInfo; } // Should return null, but, some QR codes apparently // do not mask this info. Try again by actually masking the pattern // first return doDecodeFormatInformation(maskedFormatInfo1 ^ FORMAT_INFO_MASK_QR, maskedFormatInfo2 ^ FORMAT_INFO_MASK_QR); }
static Version decodeVersionInformation(int versionBits) { int bestDifference = Integer.MAX_VALUE; int bestVersion = 0; for (int i = 0; i < VERSION_DECODE_INFO.length; i++) { int targetVersion = VERSION_DECODE_INFO[i]; // Do the version info bits match exactly? done. if (targetVersion == versionBits) { return getVersionForNumber(i + 7); } // Otherwise see if this is the closest to a real version info bit string // we have seen so far int bitsDifference = FormatInformation.numBitsDiffering(versionBits, targetVersion); if (bitsDifference < bestDifference) { bestVersion = i + 7; bestDifference = bitsDifference; } } // We can tolerate up to 3 bits of error since no two version info codewords will // differ in less than 8 bits. if (bestDifference <= 3) { return getVersionForNumber(bestVersion); } // If we didn't find a close enough match, fail return null; }