use of java.awt.image.DataBufferDouble in project bioformats by openmicroscopy.
the class AWTImageTools method makeImage.
/**
* Creates an image from the given double-precision floating point data.
*
* @param data Array containing image data.
* It is assumed that each channel corresponds to one element of the array.
* For example, for RGB data, data[0] is R, data[1] is G, and data[2] is B.
* @param w Width of image plane.
* @param h Height of image plane.
*/
public static BufferedImage makeImage(double[][] data, int w, int h) {
int dataType = DataBuffer.TYPE_DOUBLE;
DataBuffer buffer = new DataBufferDouble(data, data[0].length);
return constructImage(data.length, dataType, w, h, false, true, buffer);
}
use of java.awt.image.DataBufferDouble in project bioformats by openmicroscopy.
the class AWTImageTools method makeImage.
/**
* Creates an image from the given double data.
*
* @param data Array containing image data.
* @param w Width of image plane.
* @param h Height of image plane.
* @param c Number of channels.
* @param interleaved If set, the channels are assumed to be interleaved;
* otherwise they are assumed to be sequential.
* For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved,
* while "RRR...GGG...BBB..." is sequential.
*/
public static BufferedImage makeImage(double[] data, int w, int h, int c, boolean interleaved) {
if (c == 1)
return makeImage(data, w, h);
int dataType = DataBuffer.TYPE_DOUBLE;
DataBuffer buffer = new DataBufferDouble(data, c * w * h);
return constructImage(c, dataType, w, h, interleaved, false, buffer);
}
use of java.awt.image.DataBufferDouble in project javacv by bytedeco.
the class GLCanvasFrame method showImage.
public void showImage(BufferedImage image) {
if (image == null) {
return;
}
this.color = null;
this.width = image.getWidth();
this.height = image.getHeight();
DataBuffer buffer = image.getRaster().getDataBuffer();
if (buffer instanceof DataBufferByte) {
this.buffer = ByteBuffer.wrap(((DataBufferByte) buffer).getData());
this.type = GL2.GL_UNSIGNED_BYTE;
} else if (buffer instanceof DataBufferDouble) {
this.buffer = DoubleBuffer.wrap(((DataBufferDouble) buffer).getData());
this.type = GL2.GL_DOUBLE;
} else if (buffer instanceof DataBufferFloat) {
this.buffer = FloatBuffer.wrap(((DataBufferFloat) buffer).getData());
this.type = GL2.GL_FLOAT;
} else if (buffer instanceof DataBufferInt) {
this.buffer = IntBuffer.wrap(((DataBufferInt) buffer).getData());
this.type = GL2.GL_INT;
} else if (buffer instanceof DataBufferShort) {
this.buffer = ShortBuffer.wrap(((DataBufferShort) buffer).getData());
this.type = GL2.GL_SHORT;
} else if (buffer instanceof DataBufferUShort) {
this.buffer = ShortBuffer.wrap(((DataBufferUShort) buffer).getData());
this.type = GL2.GL_UNSIGNED_SHORT;
} else {
assert false;
}
switch(image.getSampleModel().getNumBands()) {
case 1:
this.format = GL2.GL_LUMINANCE;
break;
case 2:
this.format = GL2.GL_RG;
break;
case 3:
this.format = GL2.GL_RGB;
break;
case 4:
this.format = GL2.GL_RGBA;
break;
default:
assert false;
}
getGLCanvas().display();
}
use of java.awt.image.DataBufferDouble in project imageio-ext by geosolutions-it.
the class ImageIOUtils method rasterToBufferedImage.
/**
* Utility method for creating a BufferedImage from a source raster Currently only Float->Byte and Byte->Byte are supported. Will throw an
* {@link UnsupportedOperationException} if the conversion is not supported.
*
* @param raster
* @param imageType
* @return
*/
public static BufferedImage rasterToBufferedImage(Raster raster, ImageTypeSpecifier imageType) {
if (imageType == null) {
if (raster.getDataBuffer().getDataType() == DataBuffer.TYPE_BYTE)
imageType = ImageTypeSpecifier.createGrayscale(8, DataBuffer.TYPE_BYTE, false);
else
throw new IllegalArgumentException("unable to dynamically determine the imageType");
}
// create a new buffered image, for display
BufferedImage bufImage = imageType.createBufferedImage(raster.getWidth(), raster.getHeight());
if (raster.getDataBuffer().getDataType() == DataBuffer.TYPE_USHORT && bufImage.getRaster().getDataBuffer().getDataType() == DataBuffer.TYPE_BYTE) {
// convert short pixels to bytes
short[] shortData = ((DataBufferUShort) raster.getDataBuffer()).getData();
byte[] byteData = ((DataBufferByte) bufImage.getWritableTile(0, 0).getDataBuffer()).getData();
ImageIOUtils.shortToByteBuffer(shortData, byteData, 1, raster.getNumBands());
} else if (raster.getDataBuffer().getDataType() == DataBuffer.TYPE_FLOAT && bufImage.getRaster().getDataBuffer().getDataType() == DataBuffer.TYPE_BYTE) {
// convert float pixels to bytes
float[] floatData = ((DataBufferFloat) raster.getDataBuffer()).getData();
byte[] byteData = ((DataBufferByte) bufImage.getWritableTile(0, 0).getDataBuffer()).getData();
ImageIOUtils.floatToByteBuffer(floatData, byteData, 1, raster.getNumBands());
} else if (raster.getDataBuffer().getDataType() == DataBuffer.TYPE_DOUBLE && bufImage.getRaster().getDataBuffer().getDataType() == DataBuffer.TYPE_BYTE) {
// convert double pixels to bytes
double[] doubleData = ((DataBufferDouble) raster.getDataBuffer()).getData();
byte[] byteData = ((DataBufferByte) bufImage.getWritableTile(0, 0).getDataBuffer()).getData();
ImageIOUtils.doubleToByteBuffer(doubleData, byteData, 1, raster.getNumBands());
} else if ((raster.getDataBuffer().getDataType() == DataBuffer.TYPE_BYTE && bufImage.getRaster().getDataBuffer().getDataType() == DataBuffer.TYPE_BYTE) || (raster.getDataBuffer().getDataType() == DataBuffer.TYPE_USHORT && bufImage.getRaster().getDataBuffer().getDataType() == DataBuffer.TYPE_USHORT) || (raster.getDataBuffer().getDataType() == DataBuffer.TYPE_SHORT && bufImage.getRaster().getDataBuffer().getDataType() == DataBuffer.TYPE_SHORT)) {
bufImage.setData(raster);
} else {
throw new UnsupportedOperationException("Unable to convert raster type to bufferedImage type: " + raster.getDataBuffer().getDataType() + " ==> " + bufImage.getRaster().getDataBuffer().getDataType());
}
return bufImage;
}
use of java.awt.image.DataBufferDouble in project imageio-ext by geosolutions-it.
the class ImageIOUtils method makeGenericPixelInterleavedWritableRaster.
/**
* Returns a generic pixel interleaved WritableRaster
*
* @param numElems
* @param numLines
* @param bandOffsets
* @param dataType
* @return
*/
public static WritableRaster makeGenericPixelInterleavedWritableRaster(int numElems, int numLines, int numBands, int dataType) {
int[] bandOffsets = new int[numBands];
for (int i = 0; i < numBands; ++i) bandOffsets[i] = i;
DataBuffer d = null;
if (dataType == DataBuffer.TYPE_BYTE)
d = new DataBufferByte(numElems * numLines * numBands);
else if (dataType == DataBuffer.TYPE_SHORT)
d = new DataBufferShort(numElems * numLines * numBands);
else if (dataType == DataBuffer.TYPE_USHORT)
d = new DataBufferUShort(numElems * numLines * numBands);
else if (dataType == DataBuffer.TYPE_FLOAT)
d = new DataBufferFloat(numElems * numLines * numBands);
else if (dataType == DataBuffer.TYPE_DOUBLE)
d = new DataBufferDouble(numElems * numLines * numBands);
else
throw new IllegalArgumentException("Invalid datatype: " + dataType);
PixelInterleavedSampleModel pism = new PixelInterleavedSampleModel(dataType, numElems, numLines, bandOffsets.length, numElems * bandOffsets.length, bandOffsets);
SunWritableRaster ras = new SunWritableRaster(pism, d, new Point(0, 0));
return ras;
}
Aggregations