Tweaked small pieces of code.

This commit is contained in:
Project Nayuki 2018-08-28 19:32:44 +00:00
parent 4ede209d9a
commit 9c670453a8
3 changed files with 10 additions and 13 deletions

View File

@ -61,7 +61,7 @@ testable void appendBitsToBuffer(unsigned int val, int numBits, uint8_t buffer[]
testable void addEccAndInterleave(uint8_t data[], int version, enum qrcodegen_Ecc ecl, uint8_t result[]); testable void addEccAndInterleave(uint8_t data[], int version, enum qrcodegen_Ecc ecl, uint8_t result[]);
testable int getNumDataCodewords(int version, enum qrcodegen_Ecc ecl); testable int getNumDataCodewords(int version, enum qrcodegen_Ecc ecl);
testable int getNumRawDataModules(int version); testable int getNumRawDataModules(int ver);
testable void calcReedSolomonGenerator(int degree, uint8_t result[]); testable void calcReedSolomonGenerator(int degree, uint8_t result[]);
testable void calcReedSolomonRemainder(const uint8_t data[], int dataLen, testable void calcReedSolomonRemainder(const uint8_t data[], int dataLen,
@ -242,13 +242,13 @@ testable int getNumDataCodewords(int version, enum qrcodegen_Ecc ecl) {
// Returns the number of data bits that can be stored in a QR Code of the given version number, after // Returns the number of data bits that can be stored in a QR Code of the given version number, after
// all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8. // all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
// The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table. // The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
testable int getNumRawDataModules(int version) { testable int getNumRawDataModules(int ver) {
assert(qrcodegen_VERSION_MIN <= version && version <= qrcodegen_VERSION_MAX); assert(qrcodegen_VERSION_MIN <= ver && ver <= qrcodegen_VERSION_MAX);
int result = (16 * version + 128) * version + 64; int result = (16 * ver + 128) * ver + 64;
if (version >= 2) { if (ver >= 2) {
int numAlign = version / 7 + 2; int numAlign = ver / 7 + 2;
result -= (25 * numAlign - 10) * numAlign - 55; result -= (25 * numAlign - 10) * numAlign - 55;
if (version >= 7) if (ver >= 7)
result -= 36; result -= 36;
} }
return result; return result;

View File

@ -297,13 +297,10 @@ public final class QrCode {
size + brd * 2)) size + brd * 2))
.append("\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n") .append("\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n")
.append("\t<path d=\""); .append("\t<path d=\"");
boolean head = true;
for (int y = 0; y < size; y++) { for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) { for (int x = 0; x < size; x++) {
if (getModule(x, y)) { if (getModule(x, y)) {
if (head) if (x != 0 || y != 0)
head = false;
else
sb.append(" "); sb.append(" ");
sb.append(String.format("M%d,%dh1v1h-1z", x + brd, y + brd)); sb.append(String.format("M%d,%dh1v1h-1z", x + brd, y + brd));
} }

View File

@ -57,7 +57,7 @@ public final class QrSegmentAdvanced {
// Check arguments // Check arguments
Objects.requireNonNull(text); Objects.requireNonNull(text);
Objects.requireNonNull(ecl); Objects.requireNonNull(ecl);
if (!(1 <= minVersion && minVersion <= maxVersion && maxVersion <= 40)) if (!(QrCode.MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= QrCode.MAX_VERSION))
throw new IllegalArgumentException("Invalid value"); throw new IllegalArgumentException("Invalid value");
// Iterate through version numbers, and make tentative segments // Iterate through version numbers, and make tentative segments
@ -253,7 +253,7 @@ public final class QrSegmentAdvanced {
throw new IllegalArgumentException("String contains non-kanji-mode characters"); throw new IllegalArgumentException("String contains non-kanji-mode characters");
bb.appendBits(val, 13); bb.appendBits(val, 13);
} }
return new QrSegment(QrSegment.Mode.KANJI, text.length(), bb); return new QrSegment(Mode.KANJI, text.length(), bb);
} }