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

The following examples show how to use java.awt.image.WritableRaster#getTransferType() . 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
/**
 * Gets the raster's pixel data as arrays of primitives, one per channel. The
 * returned type will be either byte[][], short[][], int[][], float[][] or
 * double[][], depending on the raster's transfer type.
 */
public static Object getPixels(final WritableRaster raster, final int x,
	final int y, final int w, final int h)
{
	final int tt = raster.getTransferType();
	if (tt == DataBuffer.TYPE_BYTE) return getBytes(raster, x, y, w, h);
	else if (tt == DataBuffer.TYPE_USHORT || tt == DataBuffer.TYPE_SHORT) {
		return getShorts(raster, x, y, w, h);
	}
	else if (tt == DataBuffer.TYPE_INT) return getInts(raster, x, y, w, h);
	else if (tt == DataBuffer.TYPE_FLOAT) return getFloats(raster, x, y, w, h);
	else if (tt == DataBuffer.TYPE_DOUBLE) {
		return getDoubles(raster, x, y, w, h);
	}
	else return null;
}
 
Example 2
Source File: AWTImageTools.java    From scifio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Whether we can return the data buffer's bank data without performing any
 * copy or conversion operations.
 */
private static boolean canUseBankDataDirectly(final WritableRaster r,
	final int transferType, final Class<? extends DataBuffer> dataBufferClass)
{
	final int tt = r.getTransferType();
	if (tt != transferType) return false;
	final DataBuffer buffer = r.getDataBuffer();
	if (!dataBufferClass.isInstance(buffer)) return false;
	final SampleModel model = r.getSampleModel();
	if (!(model instanceof ComponentSampleModel)) return false;
	final ComponentSampleModel csm = (ComponentSampleModel) model;
	final int pixelStride = csm.getPixelStride();
	if (pixelStride != 1) return false;
	final int w = r.getWidth();
	final int scanlineStride = csm.getScanlineStride();
	if (scanlineStride != w) return false;
	final int c = r.getNumBands();
	final int[] bandOffsets = csm.getBandOffsets();
	if (bandOffsets.length != c) return false;
	for (int i = 0; i < bandOffsets.length; i++) {
		if (bandOffsets[i] != 0) return false;
	}
	for (int i = 0; i < bandOffsets.length; i++) {
		if (bandOffsets[i] != i) return false;
	}
	return true;
}