本文整理汇总了Java中java.awt.image.DataBufferFloat类的典型用法代码示例。如果您正苦于以下问题:Java DataBufferFloat类的具体用法?Java DataBufferFloat怎么用?Java DataBufferFloat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataBufferFloat类属于java.awt.image包,在下文中一共展示了DataBufferFloat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createBuffer
import java.awt.image.DataBufferFloat; //导入依赖的package包/类
/**
* Create a data buffer of a particular type.
*
* @param dataType the desired data type of the buffer.
* @param size the size of the data buffer bank
* @param numBanks the number of banks the buffer should have
*/
public static DataBuffer createBuffer(int dataType, int size, int numBanks)
{
switch (dataType)
{
case DataBuffer.TYPE_BYTE:
return new DataBufferByte(size, numBanks);
case DataBuffer.TYPE_SHORT:
return new DataBufferShort(size, numBanks);
case DataBuffer.TYPE_USHORT:
return new DataBufferUShort(size, numBanks);
case DataBuffer.TYPE_INT:
return new DataBufferInt(size, numBanks);
case DataBuffer.TYPE_FLOAT:
return new DataBufferFloat(size, numBanks);
case DataBuffer.TYPE_DOUBLE:
return new DataBufferDouble(size, numBanks);
default:
throw new UnsupportedOperationException();
}
}
示例2: createBufferFromData
import java.awt.image.DataBufferFloat; //导入依赖的package包/类
/**
* Create a data buffer of a particular type.
*
* @param dataType the desired data type of the buffer
* @param data an array containing the data
* @param size the size of the data buffer bank
*/
public static DataBuffer createBufferFromData(int dataType, Object data,
int size)
{
switch (dataType)
{
case DataBuffer.TYPE_BYTE:
return new DataBufferByte((byte[]) data, size);
case DataBuffer.TYPE_SHORT:
return new DataBufferShort((short[]) data, size);
case DataBuffer.TYPE_USHORT:
return new DataBufferUShort((short[]) data, size);
case DataBuffer.TYPE_INT:
return new DataBufferInt((int[]) data, size);
case DataBuffer.TYPE_FLOAT:
return new DataBufferFloat((float[]) data, size);
case DataBuffer.TYPE_DOUBLE:
return new DataBufferDouble((double[]) data, size);
default:
throw new UnsupportedOperationException();
}
}
示例3: createFloatBufferedImage
import java.awt.image.DataBufferFloat; //导入依赖的package包/类
BufferedImage createFloatBufferedImage(int w, int h, int bands) {
// Define dimensions and layout of the image
//int bands = 4; // 4 bands for ARGB, 3 for RGB etc
int[] bandOffsets = {0, 1, 2, 3}; // length == bands, 0 == R, 1 == G, 2 == B and 3 == A
// Create a TYPE_FLOAT sample model (specifying how the pixels are stored)
SampleModel sampleModel = new PixelInterleavedSampleModel(DataBuffer.TYPE_FLOAT, w, h, bands, w * bands, bandOffsets);
// ...and data buffer (where the pixels are stored)
DataBuffer buffer = new DataBufferFloat(w * h * bands);
// Wrap it in a writable raster
WritableRaster raster = Raster.createWritableRaster(sampleModel, buffer, null);
// Create a color model compatible with this sample model/raster (TYPE_FLOAT)
// Note that the number of bands must equal the number of color components in the
// color space (3 for RGB) + 1 extra band if the color model contains alpha
ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
ColorModel colorModel = new ComponentColorModel(colorSpace, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_FLOAT);
// And finally create an image with this raster
return new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null);
}
示例4: createBuffer
import java.awt.image.DataBufferFloat; //导入依赖的package包/类
/**
* Create a data buffer of a particular type.
*
* @param dataType the desired data type of the buffer.
* @param size the size of the data buffer bank
* @param numBanks the number of banks the buffer should have
*/
public static DataBuffer createBuffer(int dataType, int size, int numBanks)
{
switch (dataType)
{
case DataBuffer.TYPE_BYTE:
return new DataBufferByte(size, numBanks);
case DataBuffer.TYPE_SHORT:
return new DataBufferShort(size, numBanks);
case DataBuffer.TYPE_USHORT:
return new DataBufferUShort(size, numBanks);
case DataBuffer.TYPE_INT:
return new DataBufferInt(size, numBanks);
case DataBuffer.TYPE_FLOAT:
return new DataBufferFloat(size, numBanks);
case DataBuffer.TYPE_DOUBLE:
return new DataBufferDouble(size, numBanks);
default:
throw new UnsupportedOperationException();
}
}
示例5: createBufferFromData
import java.awt.image.DataBufferFloat; //导入依赖的package包/类
/**
* Create a data buffer of a particular type.
*
* @param dataType the desired data type of the buffer
* @param data an array containing the data
* @param size the size of the data buffer bank
*/
public static DataBuffer createBufferFromData(int dataType, Object data,
int size)
{
switch (dataType)
{
case DataBuffer.TYPE_BYTE:
return new DataBufferByte((byte[]) data, size);
case DataBuffer.TYPE_SHORT:
return new DataBufferShort((short[]) data, size);
case DataBuffer.TYPE_USHORT:
return new DataBufferUShort((short[]) data, size);
case DataBuffer.TYPE_INT:
return new DataBufferInt((int[]) data, size);
case DataBuffer.TYPE_FLOAT:
return new DataBufferFloat((float[]) data, size);
case DataBuffer.TYPE_DOUBLE:
return new DataBufferDouble((double[]) data, size);
default:
throw new UnsupportedOperationException();
}
}
示例6: createFloatPlanarImage
import java.awt.image.DataBufferFloat; //导入依赖的package包/类
public static PlanarImage createFloatPlanarImage(float[] src, int width, int height){
int[] bandOffsets = {0};
SampleModel sampleModel = new PixelInterleavedSampleModel(TYPE_FLOAT, width, height, 1, width, bandOffsets);
ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY);
ColorModel colorModel = new ComponentColorModel(colorSpace, false, false, Transparency.TRANSLUCENT, TYPE_FLOAT);
PlanarImage opImage;
DataBuffer buffer = new DataBufferFloat(width * height);
// Wrap it in a writable raster
WritableRaster raster = Raster.createWritableRaster(sampleModel, buffer, null);
raster.setPixels(0, 0, width, height, src);
// Create an image with this raster
BufferedImage image = new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null);
opImage = PlanarImage.wrapRenderedImage(image);
return opImage;
}
示例7: getData
import java.awt.image.DataBufferFloat; //导入依赖的package包/类
public static Object getData(final DataBuffer db) {
if (db instanceof DataBufferByte) {
return ((DataBufferByte) db).getData();
} else if (db instanceof DataBufferUShort) {
return ((DataBufferUShort) db).getData();
} else if (db instanceof DataBufferShort) {
return ((DataBufferShort) db).getData();
} else if (db instanceof DataBufferInt) {
return ((DataBufferInt) db).getData();
} else if (db instanceof DataBufferFloat) {
return ((DataBufferFloat) db).getData();
} else if (db instanceof DataBufferDouble) {
return ((DataBufferDouble) db).getData();
} else {
throw new RuntimeException("Not found DataBuffer class !");
}
}
示例8: getData
import java.awt.image.DataBufferFloat; //导入依赖的package包/类
@Override
public Object getData(DataBuffer db) {
if (db instanceof DataBufferByte){
return ((DataBufferByte)db).getData();
} else if (db instanceof DataBufferUShort){
return ((DataBufferUShort)db).getData();
} else if (db instanceof DataBufferShort){
return ((DataBufferShort)db).getData();
} else if (db instanceof DataBufferInt){
return ((DataBufferInt)db).getData();
} else if (db instanceof DataBufferFloat){
return ((DataBufferFloat)db).getData();
} else if (db instanceof DataBufferDouble){
return ((DataBufferDouble)db).getData();
} else {
// awt.235=Wrong Data Buffer type : {0}
throw new IllegalArgumentException(Messages.getString("awt.235", //$NON-NLS-1$
db.getClass()));
}
}
示例9: setUp
import java.awt.image.DataBufferFloat; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
float dataArrays[][] = new float[numBanks][];
for(int i = 0; i < numBanks; i++){
dataArrays[i] = new float[arraySize];
}
float dataArray[] = new float[arraySize];
int offsets[] = new int[numBanks];
for(int i = 0; i < numBanks; i++){
offsets[i] = i;
}
db1 = new DataBufferFloat(dataArrays, size);
db2 = new DataBufferFloat(dataArrays, size, offsets);
db3 = new DataBufferFloat(dataArray, size);
db4 = new DataBufferFloat(dataArray, size, numBanks);
db5 = new DataBufferFloat(size);
db6 = new DataBufferFloat(size, numBanks);
}
示例10: test_from_BuffImg_to_FloatDataBuffer
import java.awt.image.DataBufferFloat; //导入依赖的package包/类
public final void test_from_BuffImg_to_FloatDataBuffer(){
src = createImage(BufferedImage.TYPE_INT_RGB);
DataBufferFloat dbf = new DataBufferFloat(w * h * 3);
int offsets[] = new int[]{0,1,2};
ComponentSampleModel csm = new ComponentSampleModel(DataBuffer.TYPE_FLOAT,
w, h, 3, 3 * w, offsets);
WritableRaster wr = new OrdinaryWritableRaster(csm, dbf, new Point(0, 0));
ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false, Transparency.OPAQUE, DataBuffer.TYPE_FLOAT);
BufferedImage dst = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
Graphics2D g2d = dst.createGraphics();
g2d.drawImage(src, 0, 0, null);
for(int y = 0; y < h; y++){
for(int x = 0; x < w; x++){
assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
}
}
}
示例11: getFloats
import java.awt.image.DataBufferFloat; //导入依赖的package包/类
/** 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;
}
示例12: getBufferedImage
import java.awt.image.DataBufferFloat; //导入依赖的package包/类
@Override
public BufferedImage getBufferedImage(final ByteSource byteSource, final Map<String, Object> params)
throws ImageReadException, IOException {
try (RgbeInfo info = new RgbeInfo(byteSource)) {
// It is necessary to create our own BufferedImage here as the
// org.apache.commons.imaging.common.IBufferedImageFactory interface does
// not expose this complexity
final DataBuffer buffer = new DataBufferFloat(info.getPixelData(),
info.getWidth() * info.getHeight());
final BufferedImage ret = new BufferedImage(new ComponentColorModel(
ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false,
Transparency.OPAQUE, buffer.getDataType()),
Raster.createWritableRaster(
new BandedSampleModel(buffer.getDataType(),
info.getWidth(), info.getHeight(), 3),
buffer,
new Point()), false, null);
return ret;
}
}
示例13: clone
import java.awt.image.DataBufferFloat; //导入依赖的package包/类
public static DataBuffer clone(DataBuffer dataBuffer) {
if (dataBuffer instanceof DataBufferByte) {
return clone((DataBufferByte) dataBuffer);
} else if (dataBuffer instanceof DataBufferDouble) {
return clone((DataBufferDouble) dataBuffer);
} else if (dataBuffer instanceof DataBufferFloat) {
return clone((DataBufferFloat) dataBuffer);
} else if (dataBuffer instanceof DataBufferInt) {
return clone((DataBufferInt) dataBuffer);
} else if (dataBuffer instanceof DataBufferShort) {
return clone((DataBufferShort) dataBuffer);
} else if (dataBuffer instanceof DataBufferUShort) {
return clone((DataBufferUShort) dataBuffer);
} else {
throw new UnsupportedOperationException("Don't know how to clone " + dataBuffer.getClass().getName());
}
}
示例14: getDataFloat
import java.awt.image.DataBufferFloat; //导入依赖的package包/类
@Override
public float[] getDataFloat(DataBuffer db) {
if (db instanceof DataBufferFloat){
return ((DataBufferFloat)db).getData();
}
return null;
}
示例15: setupLazyCustomConversion
import java.awt.image.DataBufferFloat; //导入依赖的package包/类
private void setupLazyCustomConversion(final BufferedImage image) {
imageForLazyCustomConversion = image;
final boolean hasAlpha = image.getColorModel().hasAlpha();
int pixelFormat = pixelAttributes.format;
int pixelType = pixelAttributes.type;
if (pixelFormat == 0) {
pixelFormat = hasAlpha ? GL.GL_RGBA : GL.GL_RGB;
}
alignment = 1; // FIXME: do we need better?
rowLength = width; // FIXME: correct in all cases?
// Allow previously-selected pixelType (if any) to override that
// we can infer from the DataBuffer
final DataBuffer data = image.getRaster().getDataBuffer();
if (data instanceof DataBufferByte || isPackedInt(image)) {
// Don't use GL_UNSIGNED_INT for BufferedImage packed int images
if (pixelType == 0) pixelType = GL.GL_UNSIGNED_BYTE;
} else if (data instanceof DataBufferDouble) {
throw new RuntimeException("DataBufferDouble rasters not supported by OpenGL");
} else if (data instanceof DataBufferFloat) {
if (pixelType == 0) pixelType = GL.GL_FLOAT;
} else if (data instanceof DataBufferInt) {
// FIXME: should we support signed ints?
if (pixelType == 0) pixelType = GL.GL_UNSIGNED_INT;
} else if (data instanceof DataBufferShort) {
if (pixelType == 0) pixelType = GL.GL_SHORT;
} else if (data instanceof DataBufferUShort) {
if (pixelType == 0) pixelType = GL.GL_UNSIGNED_SHORT;
} else {
throw new RuntimeException("Unexpected DataBuffer type?");
}
pixelAttributes = new GLPixelAttributes(pixelFormat, pixelType);
}