@Override public float[] getValues(BufferedImage img, int x, int y, int w, int h, float[] array) { if (array == null || array.length < w * h) array = new float[w * h]; // long start = System.currentTimeMillis(); float[] samples = img.getRaster().getSamples(x, y, w, h, channel, array); // System.err.println("Time here: " + (System.currentTimeMillis() - start)); return samples; }
/** Extracts pixel data as arrays of signed integers, one per channel. */ public static int[][] getInts(WritableRaster r, int x, int y, int w, int h) { if (canUseBankDataDirectly(r, DataBuffer.TYPE_INT, DataBufferInt.class) && x == 0 && y == 0 && w == r.getWidth() && h == r.getHeight()) { return ((DataBufferInt) r.getDataBuffer()).getBankData(); } // NB: an order of magnitude faster than the naive makeType solution int c = r.getNumBands(); int[][] samples = new int[c][w * h]; for (int i=0; i<c; i++) r.getSamples(x, y, w, h, i, samples[i]); return samples; }
/** Extracts pixel data as arrays of signed integers, one per channel. */ public static int[][] getInts(WritableRaster r, int x, int y, int w, int h) { if (canUseBankDataDirectly(r, DataBuffer.TYPE_INT, DataBufferInt.class) && x == 0 && y == 0 && w == r.getWidth() && h == r.getHeight()) { return ((DataBufferInt) r.getDataBuffer()).getBankData(); } // NB: an order of magnitude faster than the naive makeType solution int c = r.getNumBands(); int[][] samples = new int[c][w * h]; for (int i=0; i<c; i++) r.getSamples(x, y, w, h, i, samples[i]); return samples; }
/** Extracts pixel data as arrays of signed integers, one per channel. */ public static int[][] getInts(WritableRaster r, int x, int y, int w, int h) { if (canUseBankDataDirectly(r, DataBuffer.TYPE_INT, DataBufferInt.class) && x == 0 && y == 0 && w == r.getWidth() && h == r.getHeight()) { return ((DataBufferInt) r.getDataBuffer()).getBankData(); } // NB: an order of magnitude faster than the naive makeType solution int c = r.getNumBands(); int[][] samples = new int[c][w * h]; for (int i=0; i<c; i++) r.getSamples(x, y, w, h, i, samples[i]); return samples; }
/** Extracts pixel data as arrays of unsigned bytes, one per channel. */ public static byte[][] getBytes(WritableRaster r, int x, int y, int w, int h) { if (canUseBankDataDirectly(r, DataBuffer.TYPE_BYTE, DataBufferByte.class) && x == 0 && y == 0 && w == r.getWidth() && h == r.getHeight()) { return ((DataBufferByte) r.getDataBuffer()).getBankData(); } int c = r.getNumBands(); byte[][] samples = new byte[c][w * h]; int[] buf = new int[w * h]; for (int i=0; i<c; i++) { r.getSamples(x, y, w, h, i, buf); for (int j=0; j<buf.length; j++) samples[i][j] = (byte) buf[j]; } return samples; }
/** Extracts pixel data as arrays of floats, one per channel. */ public static float[][] getFloats(WritableRaster r, int x, int y, int w, int h) { if (canUseBankDataDirectly(r, DataBuffer.TYPE_FLOAT, DataBufferFloat.class) && x == 0 && y == 0 && w == r.getWidth() && h == r.getHeight()) { return ((DataBufferFloat) r.getDataBuffer()).getBankData(); } // NB: an order of magnitude faster than the naive makeType solution int c = r.getNumBands(); float[][] samples = new float[c][w * h]; for (int i=0; i<c; i++) r.getSamples(x, y, w, h, i, samples[i]); return samples; }
/** Extracts pixel data as arrays of floats, one per channel. */ public static float[][] getFloats(final WritableRaster r, final int x, final int y, final int w, final int h) { if (canUseBankDataDirectly(r, DataBuffer.TYPE_FLOAT, DataBufferFloat.class) && x == 0 && y == 0 && w == r.getWidth() && h == r.getHeight()) { return ((DataBufferFloat) r.getDataBuffer()).getBankData(); } // NB: an order of magnitude faster than the naive makeType solution final int c = r.getNumBands(); final float[][] samples = new float[c][w * h]; for (int i = 0; i < c; i++) r.getSamples(x, y, w, h, i, samples[i]); return samples; }
/** Extracts pixel data as arrays of signed integers, one per channel. */ public static int[][] getInts(final WritableRaster r, final int x, final int y, final int w, final int h) { if (canUseBankDataDirectly(r, DataBuffer.TYPE_INT, DataBufferInt.class) && x == 0 && y == 0 && w == r.getWidth() && h == r.getHeight()) { return ((DataBufferInt) r.getDataBuffer()).getBankData(); } // NB: an order of magnitude faster than the naive makeType solution final int c = r.getNumBands(); final int[][] samples = new int[c][w * h]; for (int i = 0; i < c; i++) r.getSamples(x, y, w, h, i, samples[i]); return samples; }
/** Extracts pixel data as arrays of doubles, one per channel. */ public static double[][] getDoubles(WritableRaster r, int x, int y, int w, int h) { if (canUseBankDataDirectly(r, DataBuffer.TYPE_DOUBLE, DataBufferDouble.class) && x == 0 && y == 0 && w == r.getWidth() && h == r.getHeight()) { return ((DataBufferDouble) r.getDataBuffer()).getBankData(); } // NB: an order of magnitude faster than the naive makeType solution int c = r.getNumBands(); double[][] samples = new double[c][w * h]; for (int i=0; i<c; i++) r.getSamples(x, y, w, h, i, samples[i]); return samples; }
/** Extracts pixel data as arrays of floats, one per channel. */ public static float[][] getFloats(WritableRaster r, int x, int y, int w, int h) { if (canUseBankDataDirectly(r, DataBuffer.TYPE_FLOAT, DataBufferFloat.class) && x == 0 && y == 0 && w == r.getWidth() && h == r.getHeight()) { return ((DataBufferFloat) r.getDataBuffer()).getBankData(); } // NB: an order of magnitude faster than the naive makeType solution int c = r.getNumBands(); float[][] samples = new float[c][w * h]; for (int i=0; i<c; i++) r.getSamples(x, y, w, h, i, samples[i]); return samples; }
/** Extracts pixel data as arrays of floats, one per channel. */ public static float[][] getFloats(WritableRaster r, int x, int y, int w, int h) { if (canUseBankDataDirectly(r, DataBuffer.TYPE_FLOAT, DataBufferFloat.class) && x == 0 && y == 0 && w == r.getWidth() && h == r.getHeight()) { return ((DataBufferFloat) r.getDataBuffer()).getBankData(); } // NB: an order of magnitude faster than the naive makeType solution int c = r.getNumBands(); float[][] samples = new float[c][w * h]; for (int i=0; i<c; i++) r.getSamples(x, y, w, h, i, samples[i]); return samples; }
/** Extracts pixel data as arrays of doubles, one per channel. */ public static double[][] getDoubles(WritableRaster r, int x, int y, int w, int h) { if (canUseBankDataDirectly(r, DataBuffer.TYPE_DOUBLE, DataBufferDouble.class) && x == 0 && y == 0 && w == r.getWidth() && h == r.getHeight()) { return ((DataBufferDouble) r.getDataBuffer()).getBankData(); } // NB: an order of magnitude faster than the naive makeType solution int c = r.getNumBands(); double[][] samples = new double[c][w * h]; for (int i=0; i<c; i++) r.getSamples(x, y, w, h, i, samples[i]); return samples; }
/** Extracts pixel data as arrays of doubles, one per channel. */ public static double[][] getDoubles(WritableRaster r, int x, int y, int w, int h) { if (canUseBankDataDirectly(r, DataBuffer.TYPE_DOUBLE, DataBufferDouble.class) && x == 0 && y == 0 && w == r.getWidth() && h == r.getHeight()) { return ((DataBufferDouble) r.getDataBuffer()).getBankData(); } // NB: an order of magnitude faster than the naive makeType solution int c = r.getNumBands(); double[][] samples = new double[c][w * h]; for (int i=0; i<c; i++) r.getSamples(x, y, w, h, i, samples[i]); return samples; }
/** Extracts pixel data as arrays of signed integers, one per channel. */ public static int[][] getInts(final WritableRaster r, final int x, final int y, final int w, final int h) { if (canUseBankDataDirectly(r, DataBuffer.TYPE_INT, DataBufferInt.class) && x == 0 && y == 0 && w == r.getWidth() && h == r.getHeight()) { return ((DataBufferInt) r.getDataBuffer()).getBankData(); } // NB: an order of magnitude faster than the naive makeType solution final int c = r.getNumBands(); final int[][] samples = new int[c][w * h]; for (int i = 0; i < c; i++) r.getSamples(x, y, w, h, i, samples[i]); return samples; }
/** Extracts pixel data as arrays of unsigned bytes, one per channel. */ public static byte[][] getBytes(WritableRaster r, int x, int y, int w, int h) { if (canUseBankDataDirectly(r, DataBuffer.TYPE_BYTE, DataBufferByte.class) && x == 0 && y == 0 && w == r.getWidth() && h == r.getHeight()) { return ((DataBufferByte) r.getDataBuffer()).getBankData(); } int c = r.getNumBands(); byte[][] samples = new byte[c][w * h]; int[] buf = new int[w * h]; for (int i=0; i<c; i++) { r.getSamples(x, y, w, h, i, buf); for (int j=0; j<buf.length; j++) samples[i][j] = (byte) buf[j]; } return samples; }
/** Extracts pixel data as arrays of doubles, one per channel. */ public static double[][] getDoubles(final WritableRaster r, final int x, final int y, final int w, final int h) { if (canUseBankDataDirectly(r, DataBuffer.TYPE_DOUBLE, DataBufferDouble.class) && x == 0 && y == 0 && w == r.getWidth() && h == r.getHeight()) { return ((DataBufferDouble) r.getDataBuffer()).getBankData(); } // NB: an order of magnitude faster than the naive makeType solution final int c = r.getNumBands(); final double[][] samples = new double[c][w * h]; for (int i = 0; i < c; i++) r.getSamples(x, y, w, h, i, samples[i]); return samples; }
/** Extracts pixel data as arrays of floats, one per channel. */ public static float[][] getFloats(final WritableRaster r, final int x, final int y, final int w, final int h) { if (canUseBankDataDirectly(r, DataBuffer.TYPE_FLOAT, DataBufferFloat.class) && x == 0 && y == 0 && w == r.getWidth() && h == r.getHeight()) { return ((DataBufferFloat) r.getDataBuffer()).getBankData(); } // NB: an order of magnitude faster than the naive makeType solution final int c = r.getNumBands(); final float[][] samples = new float[c][w * h]; for (int i = 0; i < c; i++) r.getSamples(x, y, w, h, i, samples[i]); return samples; }
/** Extracts pixel data as arrays of unsigned bytes, one per channel. */ public static byte[][] getBytes(WritableRaster r, int x, int y, int w, int h) { if (canUseBankDataDirectly(r, DataBuffer.TYPE_BYTE, DataBufferByte.class) && x == 0 && y == 0 && w == r.getWidth() && h == r.getHeight()) { return ((DataBufferByte) r.getDataBuffer()).getBankData(); } int c = r.getNumBands(); byte[][] samples = new byte[c][w * h]; int[] buf = new int[w * h]; for (int i=0; i<c; i++) { r.getSamples(x, y, w, h, i, buf); for (int j=0; j<buf.length; j++) samples[i][j] = (byte) buf[j]; } return samples; }
/** Extracts pixel data as arrays of unsigned shorts, one per channel. */ public static short[][] getShorts(final WritableRaster r, final int x, final int y, final int w, final int h) { if (canUseBankDataDirectly(r, DataBuffer.TYPE_USHORT, DataBufferUShort.class) && x == 0 && y == 0 && w == r.getWidth() && h == r.getHeight()) { return ((DataBufferUShort) r.getDataBuffer()).getBankData(); } final int c = r.getNumBands(); final short[][] samples = new short[c][w * h]; final int[] buf = new int[w * h]; for (int i = 0; i < c; i++) { r.getSamples(x, y, w, h, i, buf); for (int j = 0; j < buf.length; j++) samples[i][j] = (short) buf[j]; } return samples; }
/** Extracts pixel data as arrays of doubles, one per channel. */ public static double[][] getDoubles(final WritableRaster r, final int x, final int y, final int w, final int h) { if (canUseBankDataDirectly(r, DataBuffer.TYPE_DOUBLE, DataBufferDouble.class) && x == 0 && y == 0 && w == r.getWidth() && h == r.getHeight()) { return ((DataBufferDouble) r.getDataBuffer()).getBankData(); } // NB: an order of magnitude faster than the naive makeType solution final int c = r.getNumBands(); final double[][] samples = new double[c][w * h]; for (int i = 0; i < c; i++) r.getSamples(x, y, w, h, i, samples[i]); return samples; }