Search in sources :

Example 81 with WritableRaster

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

the class GLXGraphicsConfig method createAcceleratedImage.

/**
     * Creates a new hidden-acceleration image of the given width and height
     * that is associated with the target Component.
     */
@Override
public Image createAcceleratedImage(Component target, int width, int height) {
    ColorModel model = getColorModel(Transparency.OPAQUE);
    WritableRaster wr = model.createCompatibleWritableRaster(width, height);
    return new OffScreenImage(target, model, wr, model.isAlphaPremultiplied());
}
Also used : DirectColorModel(java.awt.image.DirectColorModel) ColorModel(java.awt.image.ColorModel) WritableRaster(java.awt.image.WritableRaster) OffScreenImage(sun.awt.image.OffScreenImage)

Example 82 with WritableRaster

use of java.awt.image.WritableRaster 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 83 with WritableRaster

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

the class X11GraphicsConfig method createAcceleratedImage.

/**
     * Creates a new hidden-acceleration image of the given width and height
     * that is associated with the target Component.
     */
public Image createAcceleratedImage(Component target, int width, int height) {
    // As of 1.7 we no longer create pmoffscreens here...
    ColorModel model = getColorModel(Transparency.OPAQUE);
    WritableRaster wr = model.createCompatibleWritableRaster(width, height);
    return new OffScreenImage(target, model, wr, model.isAlphaPremultiplied());
}
Also used : DirectColorModel(java.awt.image.DirectColorModel) ComponentColorModel(java.awt.image.ComponentColorModel) ColorModel(java.awt.image.ColorModel) WritableRaster(java.awt.image.WritableRaster) OffScreenImage(sun.awt.image.OffScreenImage)

Example 84 with WritableRaster

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

the class IncorrectSampleMaskTest method doTest.

private static void doTest(int dataType) {
    int maxSize = DataBuffer.getDataTypeSize(dataType);
    System.out.println("Type size: " + maxSize);
    int theMask = (int) (1L << (maxSize + 2)) - 1;
    System.out.printf("theMask=%x\n", theMask);
    SinglePixelPackedSampleModel sm = new SinglePixelPackedSampleModel(dataType, w, h, new int[] { theMask });
    int[] sampleSize = sm.getSampleSize();
    for (int s : sampleSize) {
        if (s > maxSize) {
            throw new RuntimeException("Test failed: sample size is too big:" + s);
        }
    }
    System.out.println("Test medialib...");
    DataBuffer buf = createDataBuffer(dataType);
    WritableRaster wr = Raster.createWritableRaster(sm, buf, null);
    op.filter(wr, null);
    System.out.println("Test PASSED.");
}
Also used : WritableRaster(java.awt.image.WritableRaster) SinglePixelPackedSampleModel(java.awt.image.SinglePixelPackedSampleModel) DataBuffer(java.awt.image.DataBuffer)

Example 85 with WritableRaster

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

the class ColCvtAlpha method main.

public static void main(String[] args) {
    BufferedImage src = new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB);
    // Set src pixel values
    Color pelColor = new Color(100, 100, 100, 128);
    for (int i = 0; i < 10; i++) {
        src.setRGB(0, i, pelColor.getRGB());
    }
    ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] { 8, 8 }, true, src.getColorModel().isAlphaPremultiplied(), Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
    SampleModel sm = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, 100, 100, 2, 200, new int[] { 0, 1 });
    WritableRaster wr = Raster.createWritableRaster(sm, new Point(0, 0));
    BufferedImage dst = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
    dst = dst.getSubimage(0, 0, 1, 10);
    ColorConvertOp op = new ColorConvertOp(null);
    op.filter(src, dst);
    for (int i = 0; i < 10; i++) {
        if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) {
            throw new RuntimeException("Incorrect destination alpha value.");
        }
    }
}
Also used : PixelInterleavedSampleModel(java.awt.image.PixelInterleavedSampleModel) PixelInterleavedSampleModel(java.awt.image.PixelInterleavedSampleModel) SampleModel(java.awt.image.SampleModel) ColorConvertOp(java.awt.image.ColorConvertOp) ComponentColorModel(java.awt.image.ComponentColorModel) ColorModel(java.awt.image.ColorModel) ComponentColorModel(java.awt.image.ComponentColorModel) WritableRaster(java.awt.image.WritableRaster) Color(java.awt.Color) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) Point(java.awt.Point)

Aggregations

WritableRaster (java.awt.image.WritableRaster)110 BufferedImage (java.awt.image.BufferedImage)74 ColorModel (java.awt.image.ColorModel)33 DirectColorModel (java.awt.image.DirectColorModel)20 IndexColorModel (java.awt.image.IndexColorModel)19 DataBufferByte (java.awt.image.DataBufferByte)17 Point (java.awt.Point)15 Raster (java.awt.image.Raster)15 Rectangle (java.awt.Rectangle)13 Graphics2D (java.awt.Graphics2D)12 ComponentColorModel (java.awt.image.ComponentColorModel)12 DataBufferInt (java.awt.image.DataBufferInt)10 SampleModel (java.awt.image.SampleModel)9 DataBuffer (java.awt.image.DataBuffer)8 IOException (java.io.IOException)8 ColorSpace (java.awt.color.ColorSpace)7 Color (java.awt.Color)6 Iterator (java.util.Iterator)6 AffineTransform (java.awt.geom.AffineTransform)5 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)5