diff --git a/androidtest/src/com/google/zxing/client/androidtest/RGBLuminanceSource.java b/androidtest/src/com/google/zxing/client/androidtest/RGBLuminanceSource.java index 5adaff87a..5d989bedc 100644 --- a/androidtest/src/com/google/zxing/client/androidtest/RGBLuminanceSource.java +++ b/androidtest/src/com/google/zxing/client/androidtest/RGBLuminanceSource.java @@ -55,13 +55,8 @@ public final class RGBLuminanceSource extends LuminanceSource { int r = (pixel >> 16) & 0xff; int g = (pixel >> 8) & 0xff; int b = pixel & 0xff; - if (r == g && g == b) { - // Image is already greyscale, so pick any channel. - luminances[offset + x] = (byte) r; - } else { - // Calculate luminance cheaply, favoring green. - luminances[offset + x] = (byte) ((r + g + g + b) >> 2); - } + // Calculate luminance cheaply, favoring green. + luminances[offset + x] = (byte) ((r + g + g + b) >> 2); } } } diff --git a/core/src/com/google/zxing/LuminanceSource.java b/core/src/com/google/zxing/LuminanceSource.java index 4b6d4539f..8bce1a37b 100644 --- a/core/src/com/google/zxing/LuminanceSource.java +++ b/core/src/com/google/zxing/LuminanceSource.java @@ -110,4 +110,28 @@ public abstract class LuminanceSource { throw new RuntimeException("This luminance source does not support rotation."); } + public String toString() { + byte[] row = new byte[width]; + StringBuffer result = new StringBuffer(height * (width + 1)); + for (int y = 0; y < height; y++) { + row = getRow(y, row); + for (int x = 0; x < width; x++) { + int luminance = row[x] & 0xFF; + char c; + if (luminance < 0x40) { + c = '#'; + } else if (luminance < 0x80) { + c = '+'; + } else if (luminance < 0xC0) { + c = '.'; + } else { + c = ' '; + } + result.append(c); + } + result.append('\n'); + } + return result.toString(); + } + } diff --git a/core/src/com/google/zxing/common/BitArray.java b/core/src/com/google/zxing/common/BitArray.java index 6eb0d57c6..1261ad1b6 100644 --- a/core/src/com/google/zxing/common/BitArray.java +++ b/core/src/com/google/zxing/common/BitArray.java @@ -92,6 +92,38 @@ public final class BitArray { bits[i >> 5] = newBits; } + /** + * Sets a range of bits. + * + * @param start start of range, inclusive. + * @param end end of range, exclusive + */ + public void setRange(int start, int end) { + if (end < start) { + throw new IllegalArgumentException(); + } + if (end == start) { + return; + } + end--; // will be easier to treat this as the last actually set bit -- inclusive + int firstInt = start >> 5; + int lastInt = end >> 5; + for (int i = firstInt; i <= lastInt; i++) { + int firstBit = i > firstInt ? 0 : start & 0x1F; + int lastBit = i < lastInt ? 31 : end & 0x1F; + int mask; + if (firstBit == 0 && lastBit == 31) { + mask = -1; + } else { + mask = 0; + for (int j = firstBit; j <= lastBit; j++) { + mask |= 1 << j; + } + } + bits[i] |= mask; + } + } + /** * Clears all bits (sets to false). */