@Override public byte[] getRow(int y, byte[] row) { row = delegate.getRow(y, row); int width = getWidth(); for (int i = 0; i < width; i++) { row[i] = (byte) (255 - (row[i] & 0xFF)); } return row; }
@Override public boolean isCropSupported() { return delegate.isCropSupported(); }
@Override public BitMatrix getBlackMatrix() throws NotFoundException { LuminanceSource source = getLuminanceSource(); int width = source.getWidth(); int height = source.getHeight(); BitMatrix matrix = new BitMatrix(width, height); for (int y = 1; y < 5; y++) { int row = height * y / 5; byte[] localLuminances = source.getRow(row, luminances); int right = (width * 4) / 5; for (int x = width / 5; x < right; x++) { byte[] localLuminances = source.getMatrix(); for (int y = 0; y < height; y++) { int offset = y * width;
private void binarizeEntireImage() throws NotFoundException { if (matrix == null) { LuminanceSource source = getLuminanceSource(); if (source.getWidth() >= MINIMUM_DIMENSION && source.getHeight() >= MINIMUM_DIMENSION) { byte[] luminances = source.getMatrix(); int width = source.getWidth(); int height = source.getHeight(); int subWidth = width >> 3; int subHeight = height >> 3; int[][] blackPoints = calculateBlackPoints(luminances, subWidth, subHeight, width); matrix = new BitMatrix(width, height); calculateThresholdForBlock(luminances, subWidth, subHeight, width, blackPoints, matrix); } else { // If the image is too small, fall back to the global histogram approach. matrix = super.getBlackMatrix(); } } }
public BitArray getBlackRow(int y, BitArray row) throws NotFoundException { LuminanceSource source = getLuminanceSource(); int width = source.getWidth(); if (row == null || row.getSize() < width) { row = new BitArray(width); } else { row.clear(); } initArrays(width); byte[] localLuminances = source.getRow(y, luminances); int[] localBuckets = buckets; for (int x = 0; x < width; x++) { int pixel = localLuminances[x] & 0xff; localBuckets[pixel >> LUMINANCE_SHIFT]++; } int blackPoint = estimateBlackPoint(localBuckets); int left = localLuminances[0] & 0xff; int center = localLuminances[1] & 0xff; for (int x = 1; x < width - 1; x++) { int right = localLuminances[x + 1] & 0xff; // A simple -1 4 -1 box filter with a weight of 2. int luminance = ((center << 2) - left - right) >> 1; if (luminance < blackPoint) { row.set(x); } left = center; center = right; } return row; }
@Override public boolean isRotateSupported() { return delegate.isRotateSupported(); }
@Override public LuminanceSource rotateCounterClockwise() { return new InvertedLuminanceSource(delegate.rotateCounterClockwise()); }
@Override public LuminanceSource crop(int left, int top, int width, int height) { return new InvertedLuminanceSource(delegate.crop(left, top, width, height)); }
public final int getHeight() { return source.getHeight(); }
public final int getWidth() { return source.getWidth(); }
@Override public byte[] getMatrix() { byte[] matrix = delegate.getMatrix(); int length = getWidth() * getHeight(); byte[] invertedMatrix = new byte[length]; for (int i = 0; i < length; i++) { invertedMatrix[i] = (byte) (255 - (matrix[i] & 0xFF)); } return invertedMatrix; }
@Override public LuminanceSource rotateCounterClockwise45() { return new InvertedLuminanceSource(delegate.rotateCounterClockwise45()); }
@Override public BitMatrix getBlackMatrix() throws NotFoundException { LuminanceSource source = getLuminanceSource(); int width = source.getWidth(); int height = source.getHeight(); BitMatrix matrix = new BitMatrix(width, height); for (int y = 1; y < 5; y++) { int row = height * y / 5; byte[] localLuminances = source.getRow(row, luminances); int right = (width * 4) / 5; for (int x = width / 5; x < right; x++) { byte[] localLuminances = source.getMatrix(); for (int y = 0; y < height; y++) { int offset = y * width;
@Override public BitArray getBlackRow(int y, BitArray row) throws NotFoundException { LuminanceSource source = getLuminanceSource(); int width = source.getWidth(); if (row == null || row.getSize() < width) { row = new BitArray(width); byte[] localLuminances = source.getRow(y, luminances); int[] localBuckets = buckets; for (int x = 0; x < width; x++) {
@Override public boolean isRotateSupported() { return delegate.isRotateSupported(); }
@Override public LuminanceSource rotateCounterClockwise() { return new InvertedLuminanceSource(delegate.rotateCounterClockwise()); }
@Override public LuminanceSource crop(int left, int top, int width, int height) { return new InvertedLuminanceSource(delegate.crop(left, top, width, height)); }
public final int getHeight() { return source.getHeight(); }