Added helper function to Java QrSegmentAdvanced to clarify code.

pull/39/merge
Project Nayuki 6 years ago
parent ecfa0a83c1
commit 432f3e0fed

@ -113,9 +113,9 @@ public final class QrSegmentAdvanced {
result[2][j] = result[2][i] + 20; // 3.33 bits per digit
// Switch modes, rounding up fractional bits
result[0][j] = Math.min((Math.min(result[1][j], result[2][j]) + 5) / 6 * 6 + bytesCost , result[0][j]);
result[1][j] = Math.min((Math.min(result[2][j], result[0][j]) + 5) / 6 * 6 + alphnumCost, result[1][j]);
result[2][j] = Math.min((Math.min(result[0][j], result[1][j]) + 5) / 6 * 6 + numberCost , result[2][j]);
result[0][j] = Math.min(roundUp6(Math.min(result[1][j], result[2][j])) + bytesCost , result[0][j]);
result[1][j] = Math.min(roundUp6(Math.min(result[2][j], result[0][j])) + alphnumCost, result[1][j]);
result[2][j] = Math.min(roundUp6(Math.min(result[0][j], result[1][j])) + numberCost , result[2][j]);
}
return result;
}
@ -147,21 +147,21 @@ public final class QrSegmentAdvanced {
if (curMode == NUMERIC) {
if (isNumeric(c))
curMode = NUMERIC;
else if (isAlphanumeric(c) && (bitCosts[1][i] + 33 + 5) / 6 * 6 + numberCost == bitCosts[2][i + 1])
else if (isAlphanumeric(c) && roundUp6(bitCosts[1][i] + 33) + numberCost == bitCosts[2][i + 1])
curMode = ALPHANUMERIC;
else
curMode = BYTE;
} else if (curMode == ALPHANUMERIC) {
if (isNumeric(c) && (bitCosts[2][i] + 20 + 5) / 6 * 6 + alphnumCost == bitCosts[1][i + 1])
if (isNumeric(c) && roundUp6(bitCosts[2][i] + 20) + alphnumCost == bitCosts[1][i + 1])
curMode = NUMERIC;
else if (isAlphanumeric(c))
curMode = ALPHANUMERIC;
else
curMode = BYTE;
} else if (curMode == BYTE) {
if (isNumeric(c) && (bitCosts[2][i] + 20 + 5) / 6 * 6 + bytesCost == bitCosts[0][i + 1])
if (isNumeric(c) && roundUp6(bitCosts[2][i] + 20) + bytesCost == bitCosts[0][i + 1])
curMode = NUMERIC;
else if (isAlphanumeric(c) && (bitCosts[1][i] + 33 + 5) / 6 * 6 + bytesCost == bitCosts[0][i + 1])
else if (isAlphanumeric(c) && roundUp6(bitCosts[1][i] + 33) + bytesCost == bitCosts[0][i + 1])
curMode = ALPHANUMERIC;
else
curMode = BYTE;
@ -224,6 +224,11 @@ public final class QrSegmentAdvanced {
}
private static int roundUp6(int x) {
return (x + 5) / 6 * 6;
}
/*---- Kanji mode segment encoder ----*/

Loading…
Cancel
Save