From 249d043f91f02048c04eaa7f6decb2b488ab3798 Mon Sep 17 00:00:00 2001 From: wood Date: Fri, 2 Oct 2015 00:25:39 +0800 Subject: [PATCH] Update BufferedImageLuminanceSource.java --- .../client/j2se/BufferedImageLuminanceSource.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/javase/src/main/java/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java b/javase/src/main/java/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java index f5d55abda..6fd5f38be 100644 --- a/javase/src/main/java/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java +++ b/javase/src/main/java/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java @@ -69,13 +69,15 @@ public final class BufferedImageLuminanceSource extends LuminanceSource { if ((pixel & 0xFF000000) == 0) { pixel = 0xFFFFFFFF; // = white } - - // .299R + 0.587G + 0.114B (YUV/YIQ for PAL and NTSC) + + // .299R + 0.587G + 0.114B (YUV/YIQ for PAL and NTSC), + // (306*R) >> 10 is approximately equal to R*0.299, and so on. + // 0x200 >> 10 is 0.5, it implements rounding. buffer[x] = (306 * ((pixel >> 16) & 0xFF) + 601 * ((pixel >> 8) & 0xFF) + - 117 * (pixel & 0xFF) - ) >> 10; + 117 * (pixel & 0xFF) + + 0x200) >> 10; } raster.setPixels(left, y, width, 1, buffer); }