- for (int i = 0, offset = y * width + startX; i < getWidth; i++, offset++) {
- if (computeRGBLuminance(rgbPixels[offset]) < blackPoint) {
- row.set(i);
+
+ // If the current decoder calculated the blackPoint based on one row, assume we're trying to
+ // decode a 1D barcode, and apply some sharpening.
+ // TODO: We may want to add a fifth parameter to request the amount of shapening to be done.
+ if (lastMethod.equals(BlackPointEstimationMethod.ROW_SAMPLING)) {
+ int offset = y * width + startX;
+ int left = computeRGBLuminance(rgbPixels[offset]);
+ offset++;
+ int center = computeRGBLuminance(rgbPixels[offset]);
+ for (int i = 1; i < getWidth - 1; i++, offset++) {
+ int right = computeRGBLuminance(rgbPixels[offset + 1]);
+ // Simple -1 4 -1 box filter with a weight of 2
+ int luminance = ((center << 2) - left - right) >> 1;
+ if (luminance < blackPoint) {
+ row.set(i);
+ }
+ left = center;
+ center = right;
+ }
+ } else {
+ for (int i = 0, offset = y * width + startX; i < getWidth; i++, offset++) {
+ if (computeRGBLuminance(rgbPixels[offset]) < blackPoint) {
+ row.set(i);
+ }