use of java.awt.image.WritableRaster in project scriptographer by scriptographer.
the class Raster method getSubImage.
public BufferedImage getSubImage(int x, int y, int width, int height) {
if (width == -1 || height == -1) {
Size size = getSize();
if (width == -1)
width = (int) size.width;
if (height == -1)
height = (int) size.height;
}
BufferedImage img = createCompatibleImage(width, height);
Graphics2D g2d = img.createGraphics();
g2d.setColor(java.awt.Color.WHITE);
// g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0));
g2d.fillRect(0, 0, width, height);
g2d.dispose();
WritableRaster raster = img.getRaster();
byte[] data = ((DataBufferByte) raster.getDataBuffer()).getData();
nativeGetPixels(data, raster.getNumBands(), x, y, width, height);
return img;
}
use of java.awt.image.WritableRaster in project intellij-code-outline by sitano.
the class CodeOutlineImage method moveDataDown.
/**
* Copies data between the given images, starting at the bottom of the
* images and copying then moving upwards line by line. This method is
* suitable for when the two given images are subimages of the same image,
* and their data may overlap.
*
* @param from the source image
* @param to the destination image
*/
private static void moveDataDown(BufferedImage from, BufferedImage to) {
Raster raster = from.getRaster();
WritableRaster outRaster = to.getRaster();
int width = outRaster.getWidth();
int height = outRaster.getHeight();
int startX = outRaster.getMinX();
int startY = outRaster.getMinY();
Object tdata = null;
for (int i = startY + height - 1; i >= startY; i--) {
tdata = raster.getDataElements(startX, i, width, 1, tdata);
outRaster.setDataElements(startX, i, width, 1, tdata);
}
}
use of java.awt.image.WritableRaster in project lwjgl by LWJGL.
the class TextureLoader method convertImageData.
/**
* Convert the buffered image to a texture
*
* @param bufferedImage The image to convert to a texture
* @param texture The texture to store the data into
* @return A buffer containing the data
*/
private ByteBuffer convertImageData(BufferedImage bufferedImage, Texture texture) {
ByteBuffer imageBuffer;
WritableRaster raster;
BufferedImage texImage;
int texWidth = 2;
int texHeight = 2;
// of the produced texture
while (texWidth < bufferedImage.getWidth()) {
texWidth *= 2;
}
while (texHeight < bufferedImage.getHeight()) {
texHeight *= 2;
}
texture.setTextureHeight(texHeight);
texture.setTextureWidth(texWidth);
// for a texture
if (bufferedImage.getColorModel().hasAlpha()) {
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, texWidth, texHeight, 4, null);
texImage = new BufferedImage(glAlphaColorModel, raster, false, new Hashtable());
} else {
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, texWidth, texHeight, 3, null);
texImage = new BufferedImage(glColorModel, raster, false, new Hashtable());
}
// copy the source image into the produced image
Graphics g = texImage.getGraphics();
g.setColor(new Color(0f, 0f, 0f, 0f));
g.fillRect(0, 0, texWidth, texHeight);
g.drawImage(bufferedImage, 0, 0, null);
// build a byte buffer from the temporary image
// that be used by OpenGL to produce a texture.
byte[] data = ((DataBufferByte) texImage.getRaster().getDataBuffer()).getData();
imageBuffer = ByteBuffer.allocateDirect(data.length);
imageBuffer.order(ByteOrder.nativeOrder());
imageBuffer.put(data, 0, data.length);
imageBuffer.flip();
return imageBuffer;
}
use of java.awt.image.WritableRaster in project cloudstack by apache.
the class AwtCanvasAdapter method handleBitmap.
private void handleBitmap(BitmapOrder order, ByteBuffer buf) {
// Draw rectangle on offline buffer
BufferedImage image = canvas.getOfflineImage();
Graphics2D g = (Graphics2D) image.getGraphics();
for (BitmapRectangle rectangle : order.rectangles) {
// *DEBUG*/System.out.println("["+this+"] DEBUG: Rectangle: " +
// rectangle.toString());
int x = rectangle.x;
int y = rectangle.y;
int width = rectangle.width;
int height = rectangle.height;
int bufferWidth = rectangle.bufferWidth;
int bufferHeight = rectangle.bufferHeight;
BufferedImage rectImage;
switch(rectangle.colorDepth) {
case 8:
{
rectImage = new BufferedImage(bufferWidth, height, BufferedImage.TYPE_BYTE_INDEXED, screen.colorMap);
WritableRaster raster = rectImage.getRaster();
raster.setDataElements(0, 0, bufferWidth, bufferHeight, rectangle.bitmapDataStream.toByteArray());
break;
}
case 15:
{
rectImage = new BufferedImage(bufferWidth, height, BufferedImage.TYPE_USHORT_555_RGB);
WritableRaster raster = rectImage.getRaster();
raster.setDataElements(0, 0, bufferWidth, bufferHeight, rectangle.bitmapDataStream.toShortArray());
break;
}
case 16:
{
rectImage = new BufferedImage(bufferWidth, height, BufferedImage.TYPE_USHORT_565_RGB);
WritableRaster raster = rectImage.getRaster();
raster.setDataElements(0, 0, bufferWidth, bufferHeight, rectangle.bitmapDataStream.toShortArray());
break;
}
case 24:
case 32:
{
rectImage = new BufferedImage(bufferWidth, height, BufferedImage.TYPE_INT_RGB);
WritableRaster raster = rectImage.getRaster();
raster.setDataElements(0, 0, bufferWidth, bufferHeight, rectangle.bitmapDataStream.toIntLEArray());
break;
}
default:
throw new RuntimeException("Unsupported color depth: " + rectangle.colorDepth + ".");
}
g.setClip(x, y, width, height);
g.drawImage(rectImage, x, y, null);
// Request update of repainted area
canvas.updateFrameBuffer(x, y, width, height);
canvas.repaint(x, y, width, height);
}
}
use of java.awt.image.WritableRaster in project ChatGameFontificator by GlitchCog.
the class Sprite method copyImage.
private static BufferedImage copyImage(BufferedImage bi) {
ColorModel cm = bi.getColorModel();
WritableRaster raster = bi.copyData(null);
return new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);
}
Aggregations