Search in sources :

Example 31 with DataBufferByte

use of java.awt.image.DataBufferByte 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;
}
Also used : WritableRaster(java.awt.image.WritableRaster) DataBufferByte(java.awt.image.DataBufferByte) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 32 with DataBufferByte

use of java.awt.image.DataBufferByte 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;
}
Also used : Graphics(java.awt.Graphics) WritableRaster(java.awt.image.WritableRaster) Hashtable(java.util.Hashtable) Color(java.awt.Color) DataBufferByte(java.awt.image.DataBufferByte) ByteBuffer(java.nio.ByteBuffer) BufferedImage(java.awt.image.BufferedImage)

Example 33 with DataBufferByte

use of java.awt.image.DataBufferByte in project jdk8u_jdk by JetBrains.

the class IncorrectClipXorModeSW2Surface method getBufferedImage.

private static BufferedImage getBufferedImage(int sw) {
    final BufferedImage bi = new BufferedImage(sw, sw, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = bi.createGraphics();
    g2d.setColor(Color.RED);
    g2d.fillRect(0, 0, sw, sw);
    g2d.dispose();
    final DataBuffer db = bi.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 {
            bi.setAccelerationPriority(0.0f);
        } catch (final Throwable ignored) {
        }
    }
    return bi;
}
Also used : DataBufferShort(java.awt.image.DataBufferShort) DataBufferInt(java.awt.image.DataBufferInt) DataBufferByte(java.awt.image.DataBufferByte) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) DataBuffer(java.awt.image.DataBuffer)

Example 34 with DataBufferByte

use of java.awt.image.DataBufferByte in project jdk8u_jdk by JetBrains.

the class InvalidTransformParameterTest method main.

public static void main(String[] args) {
    int count = 0;
    final int testScenarios = 12;
    double NaNArg = 0.0 / 0.0;
    double positiveInfArg = 1.0 / 0.0;
    double negativeInfArg = -1.0 / 0.0;
    BufferedImage img = new BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB);
    AffineTransform[] inputTransforms = new AffineTransform[testScenarios];
    for (int i = 0; i < inputTransforms.length; i++) {
        inputTransforms[i] = new AffineTransform();
    }
    inputTransforms[0].rotate(NaNArg, img.getWidth() / 2, img.getHeight() / 2);
    inputTransforms[1].translate(NaNArg, NaNArg);
    inputTransforms[2].scale(NaNArg, NaNArg);
    inputTransforms[3].shear(NaNArg, NaNArg);
    inputTransforms[4].rotate(positiveInfArg, img.getWidth() / 2, img.getHeight() / 2);
    inputTransforms[5].translate(positiveInfArg, positiveInfArg);
    inputTransforms[6].scale(positiveInfArg, positiveInfArg);
    inputTransforms[7].shear(positiveInfArg, positiveInfArg);
    inputTransforms[8].rotate(negativeInfArg, img.getWidth() / 2, img.getHeight() / 2);
    inputTransforms[9].translate(negativeInfArg, negativeInfArg);
    inputTransforms[10].scale(negativeInfArg, negativeInfArg);
    inputTransforms[11].shear(negativeInfArg, negativeInfArg);
    for (int i = 0; i < inputTransforms.length; i++) {
        try {
            testImageTransform(img, inputTransforms[i]);
        } catch (ImagingOpException ex) {
            count++;
        }
    }
    if (count != testScenarios) {
        throw new RuntimeException("Test failed. All test scenarios did not" + " result in exception as expected.");
    }
    // Test Raster AffineTransform ---------------------------------
    count = 0;
    int[] bandOffsets = { 0 };
    Point location = new Point(0, 0);
    DataBuffer db = new DataBufferByte(10 * 10);
    SampleModel sm = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, 10, 10, 1, 10, bandOffsets);
    Raster src = Raster.createRaster(sm, db, location);
    WritableRaster dst = Raster.createWritableRaster(sm, db, location);
    for (int i = 0; i < inputTransforms.length; i++) {
        try {
            testRasterTransform(src, dst, inputTransforms[i]);
        } catch (ImagingOpException ex) {
            count++;
        }
    }
    if (count != testScenarios) {
        throw new RuntimeException("Test failed. All test scenarios did not" + " result in exception as expected.");
    }
}
Also used : PixelInterleavedSampleModel(java.awt.image.PixelInterleavedSampleModel) Raster(java.awt.image.Raster) WritableRaster(java.awt.image.WritableRaster) Point(java.awt.Point) DataBufferByte(java.awt.image.DataBufferByte) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) PixelInterleavedSampleModel(java.awt.image.PixelInterleavedSampleModel) SampleModel(java.awt.image.SampleModel) WritableRaster(java.awt.image.WritableRaster) ImagingOpException(java.awt.image.ImagingOpException) AffineTransform(java.awt.geom.AffineTransform) DataBuffer(java.awt.image.DataBuffer)

Example 35 with DataBufferByte

use of java.awt.image.DataBufferByte in project jdk8u_jdk by JetBrains.

the class IncorrectUnmanagedImageRotatedClip method makeUnmanagedBI.

private static BufferedImage makeUnmanagedBI() {
    final BufferedImage bi = new BufferedImage(500, 200, TYPE_INT_ARGB);
    final DataBuffer db = bi.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 {
            bi.setAccelerationPriority(0.0f);
        } catch (final Throwable ignored) {
        }
    }
    return bi;
}
Also used : DataBufferShort(java.awt.image.DataBufferShort) DataBufferInt(java.awt.image.DataBufferInt) DataBufferByte(java.awt.image.DataBufferByte) BufferedImage(java.awt.image.BufferedImage) DataBuffer(java.awt.image.DataBuffer)

Aggregations

DataBufferByte (java.awt.image.DataBufferByte)64 BufferedImage (java.awt.image.BufferedImage)38 Point (java.awt.Point)36 WritableRaster (java.awt.image.WritableRaster)18 DataBufferInt (java.awt.image.DataBufferInt)14 DataBuffer (java.awt.image.DataBuffer)13 DataBufferShort (java.awt.image.DataBufferShort)10 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)8 Rectangle (java.awt.Rectangle)8 SampleModel (java.awt.image.SampleModel)8 DataBufferUShort (java.awt.image.DataBufferUShort)7 IndexColorModel (java.awt.image.IndexColorModel)7 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)7 Graphics2D (java.awt.Graphics2D)6 ComponentSampleModel (java.awt.image.ComponentSampleModel)6 UserCancelException (org.vcell.util.UserCancelException)6 UtilCancelException (org.vcell.util.UtilCancelException)6 SinglePixelPackedSampleModel (java.awt.image.SinglePixelPackedSampleModel)5 Hashtable (java.util.Hashtable)5 VCImage (cbit.image.VCImage)4