Initial support for DMRE

This commit is contained in:
Sean Owen 2021-01-15 17:14:02 -06:00
parent 3374aed3fd
commit 395dc6b83f
3 changed files with 44 additions and 7 deletions

View file

@ -159,7 +159,7 @@ public final class BitMatrix implements Cloneable {
*/ */
public boolean get(int x, int y) { public boolean get(int x, int y) {
int offset = y * rowSize + (x / 32); int offset = y * rowSize + (x / 32);
return ((bits[offset] >>> (x & 0x1f)) & 1) != 0; return offset < bits.length && ((bits[offset] >>> (x & 0x1f)) & 1) != 0;
} }
/** /**
@ -170,13 +170,17 @@ public final class BitMatrix implements Cloneable {
*/ */
public void set(int x, int y) { public void set(int x, int y) {
int offset = y * rowSize + (x / 32); int offset = y * rowSize + (x / 32);
if (offset < bits.length) {
bits[offset] |= 1 << (x & 0x1f); bits[offset] |= 1 << (x & 0x1f);
} }
}
public void unset(int x, int y) { public void unset(int x, int y) {
int offset = y * rowSize + (x / 32); int offset = y * rowSize + (x / 32);
if (offset < bits.length) {
bits[offset] &= ~(1 << (x & 0x1f)); bits[offset] &= ~(1 << (x & 0x1f));
} }
}
/** /**
* <p>Flips the given bit.</p> * <p>Flips the given bit.</p>
@ -186,8 +190,10 @@ public final class BitMatrix implements Cloneable {
*/ */
public void flip(int x, int y) { public void flip(int x, int y) {
int offset = y * rowSize + (x / 32); int offset = y * rowSize + (x / 32);
if (offset < bits.length) {
bits[offset] ^= 1 << (x & 0x1f); bits[offset] ^= 1 << (x & 0x1f);
} }
}
/** /**
* Exclusive-or (XOR): Flip the bit in this {@code BitMatrix} if the corresponding * Exclusive-or (XOR): Flip the bit in this {@code BitMatrix} if the corresponding

View file

@ -136,7 +136,8 @@ final class BitMatrixParser {
} }
} while ((row < numRows) || (column < numColumns)); } while ((row < numRows) || (column < numColumns));
if (resultOffset != version.getTotalCodewords()) { if (resultOffset != version.getTotalCodewords() &&
resultOffset != version.getTotalCodewords() - 1) {
throw FormatException.getFormatInstance(); throw FormatException.getFormatInstance();
} }
return result; return result;

View file

@ -230,7 +230,37 @@ public final class Version {
new Version(29, 16, 36, 14, 16, new Version(29, 16, 36, 14, 16,
new ECBlocks(24, new ECB(1, 32))), new ECBlocks(24, new ECB(1, 32))),
new Version(30, 16, 48, 14, 22, new Version(30, 16, 48, 14, 22,
new ECBlocks(28, new ECB(1, 49))) new ECBlocks(28, new ECB(1, 49))),
// extended forms as specified in
// AIM-D - Symbology Specification Data Matrix Rectangular Extension (DMRE)
// Revision 1.0 September 22, 2014
new Version(31, 8, 48, 6, 22,
new ECBlocks(15, new ECB(1, 18))),
new Version(32, 8, 64, 6, 14,
new ECBlocks(18, new ECB(1, 24))),
new Version(33, 12, 48, 10, 22,
new ECBlocks(23, new ECB(1, 32))),
new Version(34, 12, 64, 10, 14,
new ECBlocks(27, new ECB(1, 43))),
new Version(35, 16, 64, 14, 14,
new ECBlocks(36, new ECB(1, 62))),
new Version(36, 24, 32, 22, 14,
new ECBlocks(28, new ECB(1, 49))),
new Version(37, 24, 36, 22, 16,
new ECBlocks(33, new ECB(1, 55))),
new Version(38, 24, 48, 22, 22,
new ECBlocks(41, new ECB(1, 80))),
new Version(39, 24, 64, 22, 14,
new ECBlocks(46, new ECB(1, 108))),
new Version(40, 26, 32, 24, 14,
new ECBlocks(32, new ECB(1, 52))),
new Version(41, 26, 40, 24, 18,
new ECBlocks(38, new ECB(1, 70))),
new Version(42, 26, 48, 24, 22,
new ECBlocks(42, new ECB(1, 90))),
new Version(43, 26, 64, 24, 14,
new ECBlocks(50, new ECB(1, 118)))
}; };
} }