Improved black point estimation -- favor a point not white so close the white peak

git-svn-id: https://zxing.googlecode.com/svn/trunk@135 59b500cc-1b3d-0410-9834-0bbf25fbcc57
diff --git a/core/src/com/google/zxing/common/BlackPointEstimator.java b/core/src/com/google/zxing/common/BlackPointEstimator.java
index 81e3148..a570a19 100644
--- a/core/src/com/google/zxing/common/BlackPointEstimator.java
+++ b/core/src/com/google/zxing/common/BlackPointEstimator.java
@@ -77,11 +77,13 @@
 

     // Find a valley between them that is low and closer to the white peak

     int bestValley = secondPeak - 1;

-    int bestValleyScore = Integer.MAX_VALUE;

+    int bestValleyScore = -1;

     for (int i = secondPeak - 1; i > firstPeak; i--) {

-      int distance = secondPeak - i + 3;

-      int score = distance * histogram[i];

-      if (score < bestValleyScore) {

+      int fromFirst = i - firstPeak;

+      // Favor a "valley" that is not too close to either peak -- especially not the black peak --

+      // and that has a low value of course

+      int score = fromFirst * fromFirst * (secondPeak - i) * (256 - histogram[i]);

+      if (score > bestValleyScore) {

         bestValley = i;

         bestValleyScore = score;

       }

diff --git a/core/test/src/com/google/zxing/qrcode/QRCodeReaderTestCase.java b/core/test/src/com/google/zxing/qrcode/QRCodeReaderTestCase.java
index c5e314c..ed72461 100644
--- a/core/test/src/com/google/zxing/qrcode/QRCodeReaderTestCase.java
+++ b/core/test/src/com/google/zxing/qrcode/QRCodeReaderTestCase.java
@@ -73,6 +73,8 @@
               "http://staticrooster.com");
     doTestURI("http://www.ihaveanidea.org/blogs/uploads/i/interactive/270.png",
               "Morden");
+    doTestURI("http://www.google.co.jp/mobile/images/qrcode_mobile.gif",
+              "Google \u30e2\u30d0\u30a4\u30eb\r\nhttp://google.jp");
   }
 
   private static void doTestURI(final String uriString, final String expected)