Prevent MaxiCode sampler from sampling off the edge of the image.

This commit is contained in:
Sean Owen 2020-12-30 15:44:03 -06:00
parent fd364d9338
commit 6dd0776b96

View file

@ -100,7 +100,11 @@ public final class MaxiCodeReader implements Reader {
for (int y = 0; y < MATRIX_HEIGHT; y++) {
int iy = top + (y * height + height / 2) / MATRIX_HEIGHT;
for (int x = 0; x < MATRIX_WIDTH; x++) {
int ix = left + (x * width + width / 2 + (y & 0x01) * width / 2) / MATRIX_WIDTH;
// srowen: I don't quite understand why the formula below is necessary, but it
// can walk off the image if left + width = the right boundary. So cap it.
int ix = left + Math.min(
(x * width + width / 2 + (y & 0x01) * width / 2) / MATRIX_WIDTH,
width);
if (image.get(ix, iy)) {
bits.set(x, y);
}