Issue 494 round luminance values rather than truncate
[zxing.git] / javase / src / com / google / zxing / client / j2se / BufferedImageLuminanceSource.java
index 2d613cc..28b0129 100644 (file)
@@ -95,7 +95,8 @@ public final class BufferedImageLuminanceSource extends LuminanceSource {
         int pixel = rgb[offset + x];
         int luminance = (306 * ((pixel >> 16) & 0xFF) +
             601 * ((pixel >> 8) & 0xFF) +
-            117 * (pixel & 0xFF)) >> 10;
+            117 * (pixel & 0xFF) +
+            (0x200)) >> 10; // 0x200 = 1<<9, half an lsb of the result to force rounding
         matrix[offset + x] = (byte) luminance;
       }
     }