Search in sources :

Example 1 with ColorSpace

use of java.awt.color.ColorSpace in project jdk8u_jdk by JetBrains.

the class BMPSubsamplingTest method create3ByteImage.

private BufferedImage create3ByteImage(int[] nBits, int[] bOffs) {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorModel colorModel = new ComponentColorModel(cs, nBits, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
    WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, w, h, w * 3, 3, bOffs, null);
    return new BufferedImage(colorModel, raster, false, null);
}
Also used : ColorSpace(java.awt.color.ColorSpace) DirectColorModel(java.awt.image.DirectColorModel) ComponentColorModel(java.awt.image.ComponentColorModel) ColorModel(java.awt.image.ColorModel) IndexColorModel(java.awt.image.IndexColorModel) ComponentColorModel(java.awt.image.ComponentColorModel) WritableRaster(java.awt.image.WritableRaster) BufferedImage(java.awt.image.BufferedImage)

Example 2 with ColorSpace

use of java.awt.color.ColorSpace in project jdk8u_jdk by JetBrains.

the class ImageTypeSpecifierTest method createBandedTest.

public static void createBandedTest() {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    int[] bankIndices = { 0, 100, 1000, 10000 };
    int[] bandOffsets = { 0, 100, 1000, 10000 };
    int dataType = 0;
    boolean hasAlpha = true;
    boolean isAlphaPremultiplied = true;
    try {
        ImageTypeSpecifier.createBanded(null, bankIndices, bandOffsets, dataType, hasAlpha, isAlphaPremultiplied);
        fail("Failed to get IAE!");
    } catch (IllegalArgumentException e) {
    }
    int[] bad_bankIndices = {};
    int[] bad_bandOffsets = {};
    try {
        ImageTypeSpecifier.createBanded(cs, bad_bankIndices, bad_bandOffsets, dataType, hasAlpha, isAlphaPremultiplied);
        fail("Failed to get IAE!");
    } catch (IllegalArgumentException e) {
    }
    try {
        ImageTypeSpecifier.createBanded(cs, bankIndices, bandOffsets, 99999, hasAlpha, isAlphaPremultiplied);
        fail("Failed to get IAE!");
    } catch (IllegalArgumentException e) {
    }
}
Also used : ColorSpace(java.awt.color.ColorSpace)

Example 3 with ColorSpace

use of java.awt.color.ColorSpace in project jdk8u_jdk by JetBrains.

the class NoExtraBytesTest method createTestImage.

private static BufferedImage createTestImage(int type) {
    BufferedImage dst = null;
    ColorModel colorModel = null;
    WritableRaster raster = null;
    ColorSpace cs = null;
    System.out.println("Create image for " + getImageTypeName(type));
    switch(type) {
        case TYPE_INT_GRB:
            colorModel = new DirectColorModel(24, 0x0000ff00, 0x00ff0000, 0x000000ff);
            break;
        case TYPE_INT_GBR:
            colorModel = new DirectColorModel(24, 0x000000ff, 0x00ff0000, 0x0000ff00);
            break;
        case TYPE_INT_RBG:
            colorModel = new DirectColorModel(24, 0x00ff0000, 0x000000ff, 0x0000ff00);
            break;
        case TYPE_INT_BRG:
            colorModel = new DirectColorModel(24, 0x0000ff00, 0x000000ff, 0x00ff0000);
            break;
        case TYPE_INT_555_GRB:
            colorModel = new DirectColorModel(24, 0x0000001F, 0x000003e0, 0x00007c00);
            break;
        case TYPE_3BYTE_RGB:
            cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
            int[] nBits = { 8, 8, 8 };
            int[] bOffs = { 0, 1, 2 };
            colorModel = new ComponentColorModel(cs, nBits, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
            raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, w, h, w * 3, 3, bOffs, null);
            break;
        case TYPE_3BYTE_GRB:
            cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
            //nBits = {8, 8, 8};
            //bOffs = {0, 1, 2};
            colorModel = new ComponentColorModel(cs, new int[] { 8, 8, 8 }, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
            raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, w, h, w * 3, 3, new int[] { 1, 0, 2 }, null);
            break;
        default:
            dst = new BufferedImage(w, h, type);
    }
    if (dst == null) {
        if (raster == null) {
            raster = colorModel.createCompatibleWritableRaster(w, h);
        }
        dst = new BufferedImage(colorModel, raster, false, null);
    }
    Graphics g = dst.createGraphics();
    for (int i = 0; i < usedColors.length; i++) {
        g.setColor(usedColors[i]);
        g.fillRect(i * dx, 0, dx, h);
    }
    g.dispose();
    return dst;
}
Also used : Graphics(java.awt.Graphics) DirectColorModel(java.awt.image.DirectColorModel) ComponentColorModel(java.awt.image.ComponentColorModel) ColorModel(java.awt.image.ColorModel) WritableRaster(java.awt.image.WritableRaster) ColorSpace(java.awt.color.ColorSpace) ComponentColorModel(java.awt.image.ComponentColorModel) DirectColorModel(java.awt.image.DirectColorModel) BufferedImage(java.awt.image.BufferedImage)

Example 4 with ColorSpace

use of java.awt.color.ColorSpace in project jdk8u_jdk by JetBrains.

the class Write3ByteBgrTest method createTestImage.

private static BufferedImage createTestImage(int type, Color c) {
    BufferedImage i = null;
    if (type == BufferedImage.TYPE_CUSTOM) {
        WritableRaster wr = Raster.createBandedRaster(DataBuffer.TYPE_BYTE, width, height, // scanlineStride
        width, // bankIndices[],
        new int[] { 0, 1, 2 }, // bankOffsets[],
        new int[] { 1, 2, 0 }, null);
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        ColorModel cm = new ComponentColorModel(cs, new int[] { 8, 8, 8 }, false, false, ColorModel.OPAQUE, DataBuffer.TYPE_BYTE);
        i = new BufferedImage(cm, wr, false, null);
    } else {
        i = new BufferedImage(width, height, type);
    }
    Graphics2D g = i.createGraphics();
    g.setColor(c);
    g.fillRect(0, 0, width, height);
    g.setColor(Color.white);
    g.drawRect(10, 10, width - 20, height - 20);
    return i;
}
Also used : WritableRaster(java.awt.image.WritableRaster) ColorSpace(java.awt.color.ColorSpace) ComponentColorModel(java.awt.image.ComponentColorModel) ColorModel(java.awt.image.ColorModel) ComponentColorModel(java.awt.image.ComponentColorModel) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 5 with ColorSpace

use of java.awt.color.ColorSpace in project jdk8u_jdk by JetBrains.

the class ImageFactory method createCCMImage.

public static BufferedImage createCCMImage(int cs, int dataType) {
    ColorSpace cSpace = ColorSpace.getInstance(cs);
    ComponentColorModel ccm = null;
    if (dataType == DataBuffer.TYPE_INT) {
        ccm = new ComponentColorModel(cSpace, ((cs == ColorSpace.CS_GRAY) ? new int[] { 8 } : new int[] { 8, 8, 8 }), false, false, Transparency.OPAQUE, dataType);
    } else {
        ccm = new ComponentColorModel(cSpace, false, false, Transparency.OPAQUE, dataType);
    }
    SampleModel sm = ccm.createCompatibleSampleModel(WIDTH, HEIGHT);
    WritableRaster raster = ccm.createCompatibleWritableRaster(WIDTH, HEIGHT);
    DataBuffer data = raster.getDataBuffer();
    fillCCM(data, sm, cSpace);
    return new BufferedImage(ccm, raster, false, null);
}
Also used : SampleModel(java.awt.image.SampleModel) ColorSpace(java.awt.color.ColorSpace) ComponentColorModel(java.awt.image.ComponentColorModel) WritableRaster(java.awt.image.WritableRaster) BufferedImage(java.awt.image.BufferedImage) DataBuffer(java.awt.image.DataBuffer)

Aggregations

ColorSpace (java.awt.color.ColorSpace)74 BufferedImage (java.awt.image.BufferedImage)28 ColorModel (java.awt.image.ColorModel)28 ComponentColorModel (java.awt.image.ComponentColorModel)25 ICC_ColorSpace (java.awt.color.ICC_ColorSpace)22 SampleModel (java.awt.image.SampleModel)15 IndexColorModel (java.awt.image.IndexColorModel)13 WritableRaster (java.awt.image.WritableRaster)12 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)11 ColorConvertOp (java.awt.image.ColorConvertOp)8 DataBuffer (java.awt.image.DataBuffer)8 DirectColorModel (java.awt.image.DirectColorModel)8 Point (java.awt.Point)7 DataBufferByte (java.awt.image.DataBufferByte)6 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)6 IIOException (javax.imageio.IIOException)5 Rectangle (java.awt.Rectangle)4 ComponentSampleModel (java.awt.image.ComponentSampleModel)4 PixelInterleavedSampleModel (java.awt.image.PixelInterleavedSampleModel)4 SinglePixelPackedSampleModel (java.awt.image.SinglePixelPackedSampleModel)4