- private int getRGB(int x, int y) {
- return image.getRGB(left + x, top + y);
- }
-
- private void getRGBRow(int startX, int startY, int[] result) {
- image.getRGB(left + startX, top + startY, result.length, 1, result, 0, result.length);
- }
-
- public boolean isBlack(int x, int y) {
- return computeRGBLuminance(getRGB(x, y)) < blackPoint;
- }
-
- public BitArray getBlackRow(int y, BitArray row, int startX, int getWidth) {
- if (row == null || row.getSize() < getWidth) {
- row = new BitArray(getWidth);
- } else {
- row.clear();
- }
- int[] pixelRow = new int[getWidth];
- getRGBRow(startX, y, pixelRow);
- for (int i = 0; i < getWidth; i++) {
- if (computeRGBLuminance(pixelRow[i]) < blackPoint) {
- row.set(i);
- }
- }
- return row;
- }
-
- public int getHeight() {
- return height;
- }
-
- public int getWidth() {
- return width;
- }
-
- public void estimateBlackPoint(BlackPointEstimationMethod method, int argument) throws ReaderException {
- if (!method.equals(lastMethod) || argument != lastArgument) {
- int[] histogram = new int[LUMINANCE_BUCKETS];
- if (method.equals(BlackPointEstimationMethod.TWO_D_SAMPLING)) {
- int minDimension = width < height ? width : height;
- int startI = height == minDimension ? 0 : (height - width) >> 1;
- int startJ = width == minDimension ? 0 : (width - height) >> 1;
- for (int n = 0; n < minDimension; n++) {
- int pixel = getRGB(startJ + n, startI + n);
- histogram[computeRGBLuminance(pixel) >> LUMINANCE_SHIFT]++;
- }
- } else if (method.equals(BlackPointEstimationMethod.ROW_SAMPLING)) {
- if (argument < 0 || argument >= height) {
- throw new IllegalArgumentException("Row is not within the image: " + argument);
- }
- int[] rgbArray = new int[width];
- getRGBRow(0, argument, rgbArray);
- for (int x = 0; x < width; x++) {
- histogram[computeRGBLuminance(rgbArray[x]) >> LUMINANCE_SHIFT]++;
- }
- } else {
- throw new IllegalArgumentException("Unknown method: " + method);
- }
- blackPoint = BlackPointEstimator.estimate(histogram) << LUMINANCE_SHIFT;
- lastMethod = method;
- lastArgument = argument;
- }
- }
-
- public BlackPointEstimationMethod getLastEstimationMethod() {
- return lastMethod;
- }
-