* </p>\r
*\r
* @author srowen@google.com (Sean Owen)\r
+ * @author dswitkin@google.com (Daniel Switkin)\r
*/\r
public final class BlackPointEstimator {\r
\r
* count of the brightest luminance values that should be considered "black".</p>\r
*\r
* @param histogram an array of <em>counts</em> of luminance values\r
+ * @param biasTowardsWhite values higher than 1.0 suggest that a higher black point is desirable (e.g.\r
+ * more values are considered black); less than 1.0 suggests that lower is desirable. Must be greater\r
+ * than 0.0; 1.0 is a good "default"\r
* @return index within argument of bucket corresponding to brightest values which should be\r
* considered "black"\r
*/\r
- public static int estimate(int[] histogram) {\r
+ public static int estimate(int[] histogram, float biasTowardsWhite) {\r
+\r
+ if (Float.isNaN(biasTowardsWhite) || biasTowardsWhite <= 0.0f) {\r
+ throw new IllegalArgumentException("Illegal biasTowardsWhite: " + biasTowardsWhite);\r
+ }\r
\r
int numBuckets = histogram.length;\r
\r
int bestValley = secondPeak - 1;\r
int bestValleyScore = -1;\r
for (int i = secondPeak - 1; i > firstPeak; i--) {\r
- int fromFirst = i - firstPeak;\r
+ int fromFirst = (int) (biasTowardsWhite * (i - firstPeak));\r
// Favor a "valley" that is not too close to either peak -- especially not the black peak --\r
// and that has a low value of course\r
int score = fromFirst * fromFirst * (secondPeak - i) * (256 - histogram[i]);\r