本文整理汇总了Java中java.awt.image.DataBufferInt类的典型用法代码示例。如果您正苦于以下问题:Java DataBufferInt类的具体用法?Java DataBufferInt怎么用?Java DataBufferInt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataBufferInt类属于java.awt.image包,在下文中一共展示了DataBufferInt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import java.awt.image.DataBufferInt; //导入依赖的package包/类
/**
* Write a tile image to a stream.
*
* @param tile the image
* @param out the stream
*
* @throws ImageIOException if the write fails
*/
public static void write(BufferedImage tile, OutputStream out)
throws IOException {
ByteBuffer bb;
// write the header
bb = ByteBuffer.allocate(18);
bb.put("VASSAL".getBytes())
.putInt(tile.getWidth())
.putInt(tile.getHeight())
.putInt(tile.getType());
out.write(bb.array());
// write the tile data
final DataBufferInt db = (DataBufferInt) tile.getRaster().getDataBuffer();
final int[] data = db.getData();
bb = ByteBuffer.allocate(4*data.length);
bb.asIntBuffer().put(data);
final GZIPOutputStream zout = new GZIPOutputStream(out);
zout.write(bb.array());
zout.finish();
}
示例2: initImageMem
import java.awt.image.DataBufferInt; //导入依赖的package包/类
private cl_mem initImageMem(BufferedImage img) {
cl_image_format imageFormat = new cl_image_format();
imageFormat.image_channel_order = CL_RGBA;
imageFormat.image_channel_data_type = CL_UNSIGNED_INT8;
// Create the memory object for the input image
DataBufferInt dataBufferSrc = (DataBufferInt)img.getRaster().getDataBuffer();
int dataSrc[] = dataBufferSrc.getData();
cl_mem inputImageMem = CL.clCreateImage2D(
context, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
new cl_image_format[]{imageFormat}, img.getWidth(), img.getHeight(),
img.getWidth() * Sizeof.cl_uint, Pointer.to(dataSrc), null);
return inputImageMem;
}
示例3: run
import java.awt.image.DataBufferInt; //导入依赖的package包/类
@Override
public void run() {
FrameRate framerate = new FrameRate();
int[] pixels = ((DataBufferInt) ps3eye_frame.getRaster().getDataBuffer()).getData();
// ps3eye.waitAvailable(false);
while (true) {
// if(ps3eye.isAvailable()){
ps3eye.getFrame(pixels);
repaint();
jframe.setTitle(""+framerate.update());
// }
// try {
// Thread.sleep(0);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
}
}
示例4: fix_tRNS
import java.awt.image.DataBufferInt; //导入依赖的package包/类
protected BufferedImage fix_tRNS(Reference<BufferedImage> ref,
int tRNS, int type) throws ImageIOException {
BufferedImage img = ref.obj;
// Ensure that we are working with integer ARGB data. Whether it's
// premultiplied doesn't matter, since fully transparent black pixels
// are the same in both.
if (img.getType() != BufferedImage.TYPE_INT_ARGB &&
img.getType() != BufferedImage.TYPE_INT_ARGB_PRE) {
// If the requested type is not an ARGB one, then we convert to ARGB
// for applying this fix.
if (type != BufferedImage.TYPE_INT_ARGB &&
type != BufferedImage.TYPE_INT_ARGB_PRE) {
type = BufferedImage.TYPE_INT_ARGB;
}
img = null;
img = tconv.convert(ref, type);
}
// NB: This unmanages the image.
final DataBufferInt db = (DataBufferInt) img.getRaster().getDataBuffer();
final int[] data = db.getData();
// Set all pixels of the transparent color to have alpha 0.
for (int i = 0; i < data.length; ++i) {
if (data[i] == tRNS) data[i] = 0x00000000;
}
return img;
}
示例5: fix_YCbCr
import java.awt.image.DataBufferInt; //导入依赖的package包/类
protected BufferedImage fix_YCbCr(Reference<BufferedImage> ref, int type)
throws ImageIOException {
BufferedImage img = ref.obj;
// Ensure that we are working with RGB or ARGB data.
if (img.getType() != BufferedImage.TYPE_INT_RGB &&
img.getType() != BufferedImage.TYPE_INT_ARGB) {
if (type != BufferedImage.TYPE_INT_RGB &&
type != BufferedImage.TYPE_INT_ARGB) {
type = BufferedImage.TYPE_INT_ARGB;
}
img = null;
img = tconv.convert(ref, type);
}
// NB: This unmanages the image.
final DataBufferInt db = (DataBufferInt) img.getRaster().getDataBuffer();
final int[] data = db.getData();
for (int i = 0; i < data.length; ++i) {
final int y = (data[i] >> 16) & 0xFF;
final int pb = ((data[i] >> 8) & 0xFF) - 128;
final int pr = ( data[i] & 0xFF) - 128;
final int a = (data[i] >> 24) & 0xFF;
final int r = (int) Math.round(y + 1.402*pr);
final int g = (int) Math.round(y - 0.34414*pb - 0.71414*pr);
final int b = (int) Math.round(y + 1.772*pb);
data[i] = (a << 24) |
((r < 0 ? 0 : (r > 0xFF ? 0xFF : r)) << 16) |
((g < 0 ? 0 : (g > 0xFF ? 0xFF : g)) << 8) |
(b < 0 ? 0 : (b > 0xFF ? 0xFF : b));
}
return img;
}
示例6: convertImage
import java.awt.image.DataBufferInt; //导入依赖的package包/类
/**
* Converts the given image to the stream deck format.<br>
* Format is:<br>
* Color Schema: BGR<br>
* Image size: 72 x 72 pixel<br>
* Stored in an array with each byte stored seperatly (Size of each array is
* 72 x 72 x 3 = 15_552).
*
* @param img
* Image to be converted
* @return Byte arraythat contains the given image, ready to be sent to the
* stream deck
*/
public static byte[] convertImage(BufferedImage img) {
img = IconHelper.createResizedCopy(IconHelper.fillBackground(IconHelper.rotate180(img), Color.BLACK));
if (APPLY_FRAME) {
BufferedImage frame = getImageFromResource("/resources/frame.png");
if (frame != null) {
Graphics2D g = img.createGraphics();
g.drawImage(frame, 0, 0, null);
g.dispose();
}
}
int[] pixels = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();
byte[] imgData = new byte[StreamDeck.ICON_SIZE * StreamDeck.ICON_SIZE * 3];
int imgDataCount = 0;
// remove the alpha channel
for (int i = 0; i < StreamDeck.ICON_SIZE * StreamDeck.ICON_SIZE; i++) {
// RGB -> BGR
imgData[imgDataCount++] = (byte) ((pixels[i] >> 16) & 0xFF);
imgData[imgDataCount++] = (byte) (pixels[i] & 0xFF);
imgData[imgDataCount++] = (byte) ((pixels[i] >> 8) & 0xFF);
}
return imgData;
}
示例7: toImage
import java.awt.image.DataBufferInt; //导入依赖的package包/类
/**
* Turns gl to BufferedImage with fixed format
*
* @param gl
* @param w
* @param h
* @return
*/
protected BufferedImage toImage(GL2 gl, int w, int h) {
gl.glReadBuffer(GL.GL_FRONT); // or GL.GL_BACK
ByteBuffer glBB = Buffers.newDirectByteBuffer(4 * w * h);
gl.glReadPixels(0, 0, w, h, GL2.GL_BGRA, GL.GL_BYTE, glBB);
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_BGR);
int[] bd = ((DataBufferInt) bi.getRaster().getDataBuffer()).getData();
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
int b = 2 * glBB.get();
int g = 2 * glBB.get();
int r = 2 * glBB.get();
int a = glBB.get(); // not using
bd[(h - y - 1) * w + x] = (b << 16) | (g << 8) | r | 0xFF000000;
}
}
return bi;
}
示例8: toImage
import java.awt.image.DataBufferInt; //导入依赖的package包/类
private BufferedImage toImage(DvsFramerSingleFrame subSampler) {
BufferedImage bi = new BufferedImage(dvsFrame.getWidth(), dvsFrame.getHeight(), BufferedImage.TYPE_INT_BGR);
int[] bd = ((DataBufferInt) bi.getRaster().getDataBuffer()).getData();
for (int y = 0; y < dvsFrame.getHeight(); y++) {
for (int x = 0; x < dvsFrame.getWidth(); x++) {
int b = (int) (255 * subSampler.getValueAtPixel(x, y));
int g = b;
int r = b;
int idx = (dvsFrame.getHeight() - y - 1) * dvsFrame.getWidth() + x;
if (idx >= bd.length) {
throw new RuntimeException(String.format("index %d out of bounds for x=%d y=%d", idx, x, y));
}
bd[idx] = (b << 16) | (g << 8) | r | 0xFF000000;
}
}
return bi;
}
示例9: makeImage
import java.awt.image.DataBufferInt; //导入依赖的package包/类
public Image makeImage(TestEnvironment env, int w, int h) {
BufferedImage img = new BufferedImage(w, h, type);
if (unmanaged) {
DataBuffer db = img.getRaster().getDataBuffer();
if (db instanceof DataBufferInt) {
((DataBufferInt)db).getData();
} else if (db instanceof DataBufferShort) {
((DataBufferShort)db).getData();
} else if (db instanceof DataBufferByte) {
((DataBufferByte)db).getData();
} else {
try {
img.setAccelerationPriority(0.0f);
} catch (Throwable e) {}
}
}
return img;
}
示例10: syncCopyBuffer
import java.awt.image.DataBufferInt; //导入依赖的package包/类
private void syncCopyBuffer(boolean reset, int x, int y, int w, int h, int scale) {
content.paintLock();
try {
int[] srcBuffer = ((DataBufferInt)bbImage.getRaster().getDataBuffer()).getData();
if (reset) {
copyBuffer = new int[srcBuffer.length];
}
int linestride = bbImage.getWidth();
x *= scale;
y *= scale;
w *= scale;
h *= scale;
for (int i=0; i<h; i++) {
int from = (y + i) * linestride + x;
System.arraycopy(srcBuffer, from, copyBuffer, from, w);
}
} finally {
content.paintUnlock();
}
}
示例11: createBuffer
import java.awt.image.DataBufferInt; //导入依赖的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();
}
}
示例12: createBufferFromData
import java.awt.image.DataBufferInt; //导入依赖的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();
}
}
示例13: allocateRgbImage
import java.awt.image.DataBufferInt; //导入依赖的package包/类
/**
* @param windowWidth
* @param windowHeight
* @param pBuffer
* @param windowSize
* @param backgroundTransparent
* @return an Image
*/
static Object allocateRgbImage(int windowWidth, int windowHeight,
int[] pBuffer, int windowSize,
boolean backgroundTransparent) {
//backgroundTransparent not working with antialiasDisplay. I have no idea why. BH 9/24/08
/* DEAD CODE if (false && backgroundTransparent)
return new BufferedImage(
rgbColorModelT,
Raster.createWritableRaster(
new SinglePixelPackedSampleModel(
DataBuffer.TYPE_INT,
windowWidth,
windowHeight,
sampleModelBitMasksT),
new DataBufferInt(pBuffer, windowSize),
null),
false,
null);
*/
return new BufferedImage(rgbColorModel, Raster.createWritableRaster(
new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, windowWidth,
windowHeight, sampleModelBitMasks), new DataBufferInt(pBuffer,
windowSize), null), false, null);
}
示例14: makeUnmanagedBI
import java.awt.image.DataBufferInt; //导入依赖的package包/类
private static BufferedImage makeUnmanagedBI(GraphicsConfiguration gc,
int type) {
BufferedImage img = gc.createCompatibleImage(SIZE, SIZE, type);
Graphics2D g2d = img.createGraphics();
g2d.setColor(RGB);
g2d.fillRect(0, 0, SIZE, SIZE);
g2d.dispose();
final DataBuffer db = img.getRaster().getDataBuffer();
if (db instanceof DataBufferInt) {
((DataBufferInt) db).getData();
} else if (db instanceof DataBufferShort) {
((DataBufferShort) db).getData();
} else if (db instanceof DataBufferByte) {
((DataBufferByte) db).getData();
} else {
try {
img.setAccelerationPriority(0.0f);
} catch (final Throwable ignored) {
}
}
return img;
}
示例15: makeUnmanagedBI
import java.awt.image.DataBufferInt; //导入依赖的package包/类
private static BufferedImage makeUnmanagedBI(final int type) {
final BufferedImage img = new BufferedImage(SIZE, SIZE, type);
final DataBuffer db = img.getRaster().getDataBuffer();
if (db instanceof DataBufferInt) {
((DataBufferInt) db).getData();
} else if (db instanceof DataBufferShort) {
((DataBufferShort) db).getData();
} else if (db instanceof DataBufferByte) {
((DataBufferByte) db).getData();
} else {
try {
img.setAccelerationPriority(0.0f);
} catch (final Throwable ignored) {
}
}
return img;
}