Java Code Examples for java.awt.image.WritableRaster#getSamples()

The following examples show how to use java.awt.image.WritableRaster#getSamples() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AWTImageTools.java    From scifio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Extracts pixel data as arrays of unsigned bytes, one per channel. */
public static byte[][] getBytes(final WritableRaster r, final int x,
	final int y, final int w, final 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();
	}
	final int c = r.getNumBands();
	final byte[][] samples = new byte[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] = (byte) buf[j];
	}
	return samples;
}
 
Example 2
Source File: AWTImageTools.java    From scifio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** 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;
}
 
Example 3
Source File: AWTImageTools.java    From scifio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** 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;
}
 
Example 4
Source File: AWTImageTools.java    From scifio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** 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;
}
 
Example 5
Source File: AWTImageTools.java    From scifio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** 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;
}