Search in sources :

Example 46 with ColorSpace

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

the class CMMTests method getColorSpace.

protected static ColorSpace getColorSpace(TestEnvironment env) {
    ColorSpace cs;
    //(Boolean)env.getModifier(usePlatfromProfiles);
    Boolean usePlatfrom = true;
    int cs_code = env.getIntValue(csList);
    if (usePlatfrom) {
        cs = ColorSpace.getInstance(cs_code);
    } else {
        String resource = "profiles/";
        switch(cs_code) {
            case ColorSpace.CS_CIEXYZ:
                resource += "CIEXYZ.pf";
                break;
            case ColorSpace.CS_GRAY:
                resource += "GRAY.pf";
                break;
            case ColorSpace.CS_LINEAR_RGB:
                resource += "LINEAR_RGB.pf";
                break;
            case ColorSpace.CS_PYCC:
                resource += "PYCC.pf";
                break;
            case ColorSpace.CS_sRGB:
                resource += "sRGB.pf";
                break;
            default:
                throw new RuntimeException("Unknown color space: " + cs_code);
        }
        try {
            InputStream is = CMMTests.class.getResourceAsStream(resource);
            ICC_Profile p = ICC_Profile.getInstance(is);
            cs = new ICC_ColorSpace(p);
        } catch (IOException e) {
            throw new RuntimeException("Unable load profile from resource " + resource, e);
        }
    }
    return cs;
}
Also used : ICC_ColorSpace(java.awt.color.ICC_ColorSpace) ICC_ColorSpace(java.awt.color.ICC_ColorSpace) ColorSpace(java.awt.color.ColorSpace) InputStream(java.io.InputStream) IOException(java.io.IOException) ICC_Profile(java.awt.color.ICC_Profile)

Example 47 with ColorSpace

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

the class RGBColorConvertTest method main.

public static void main(String[] args) {
    BufferedImage src = new BufferedImage(256, 3, BufferedImage.TYPE_INT_RGB);
    BufferedImage dst = new BufferedImage(256, 3, BufferedImage.TYPE_INT_RGB);
    for (int i = 0; i < 256; i++) {
        src.setRGB(i, 0, i);
        src.setRGB(i, 1, i << 8);
        src.setRGB(i, 2, i << 16);
    }
    ColorSpace srcColorSpace = src.getColorModel().getColorSpace();
    ColorConvertOp op = new ColorConvertOp(srcColorSpace, srcColorSpace, null);
    op.filter(src, dst);
    int errCount = 0;
    for (int i = 0; i < src.getWidth(); i++) {
        for (int j = 0; j < src.getHeight(); j++) {
            int scol = src.getRGB(i, j);
            int dcol = dst.getRGB(i, j);
            if (scol != dcol) {
                System.err.println("(" + i + "," + j + ") : " + Integer.toHexString(scol) + "!=" + Integer.toHexString(dcol));
                errCount++;
            }
        }
    }
    if (errCount > 0) {
        throw new RuntimeException(errCount + " pixels are changed by " + "transform between the same ICC color " + "spaces");
    }
}
Also used : ColorSpace(java.awt.color.ColorSpace)

Example 48 with ColorSpace

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

the class ITSDataType method main.

public static void main(String[] args) {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
    int[] bankIndices = new int[] { 1 };
    int[] bandOffsets = new int[] { 0 };
    // test createBanded()
    for (int i = 0; i < dataTypes.length; i++) {
        int dataType = dataTypes[i];
        try {
            ImageTypeSpecifier.createBanded(cs, bankIndices, bandOffsets, dataType, false, false);
        } catch (IllegalArgumentException e) {
            throw new RuntimeException("createBanded() test failed for " + "dataType = " + dataType);
        }
    }
    // test createInterleaved()
    for (int i = 0; i < dataTypes.length; i++) {
        int dataType = dataTypes[i];
        try {
            ImageTypeSpecifier.createInterleaved(cs, bandOffsets, dataType, false, false);
        } catch (IllegalArgumentException e) {
            throw new RuntimeException("createInterleaved() test failed " + "for dataType = " + dataType);
        }
    }
}
Also used : ColorSpace(java.awt.color.ColorSpace)

Example 49 with ColorSpace

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

the class TestCompressionBI_BITFIELDS method compareImages.

protected void compareImages(BufferedImage src, BufferedImage dst) {
    ColorSpace srcCS = src.getColorModel().getColorSpace();
    ColorSpace dstCS = dst.getColorModel().getColorSpace();
    if (!srcCS.equals(dstCS) && srcCS.getType() == ColorSpace.TYPE_GRAY) {
        System.out.println("Workaround color difference with GRAY.");
        BufferedImage tmp = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_RGB);
        Graphics g = tmp.createGraphics();
        g.drawImage(src, 0, 0, null);
        src = tmp;
    }
    int y = h / 2;
    for (int i = 0; i < colors.length; i++) {
        int x = dx * i + dx / 2;
        int srcRgb = src.getRGB(x, y);
        int dstRgb = dst.getRGB(x, y);
        if (srcRgb != dstRgb) {
            throw new RuntimeException("Test failed due to color difference: " + "src_pixel=" + Integer.toHexString(srcRgb) + "dst_pixel=" + Integer.toHexString(dstRgb));
        }
    }
}
Also used : Graphics(java.awt.Graphics) ColorSpace(java.awt.color.ColorSpace) BufferedImage(java.awt.image.BufferedImage)

Example 50 with ColorSpace

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

the class AlphaTest method main.

public static void main(String[] args) {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
    ColorConvertOp op = new ColorConvertOp(cs, null);
    // create source image filled with an opaque color
    BufferedImage src = createSrc();
    int srcAlpha = getAlpha(src);
    System.out.printf("Src alpha: 0x%02x\n", srcAlpha);
    // create clear (transparent black) destination image
    BufferedImage dst = createDst();
    int dstAlpha = getAlpha(dst);
    System.out.printf("Dst alpha: 0x%02x\n", dstAlpha);
    dst = op.filter(src, dst);
    dstAlpha = getAlpha(dst);
    // we expect that destination image is opaque
    // i.e. alpha is transferred from source to
    // the destination
    System.out.printf("Result alpha: 0x%02x\n", dstAlpha);
    if (srcAlpha != dstAlpha) {
        throw new RuntimeException("Test failed!");
    }
    System.out.println("Test passed");
}
Also used : ColorConvertOp(java.awt.image.ColorConvertOp) ColorSpace(java.awt.color.ColorSpace) BufferedImage(java.awt.image.BufferedImage)

Aggregations

ColorSpace (java.awt.color.ColorSpace)86 ColorModel (java.awt.image.ColorModel)33 BufferedImage (java.awt.image.BufferedImage)30 ComponentColorModel (java.awt.image.ComponentColorModel)29 ICC_ColorSpace (java.awt.color.ICC_ColorSpace)24 IndexColorModel (java.awt.image.IndexColorModel)17 SampleModel (java.awt.image.SampleModel)17 WritableRaster (java.awt.image.WritableRaster)13 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)11 ColorConvertOp (java.awt.image.ColorConvertOp)10 DirectColorModel (java.awt.image.DirectColorModel)10 Point (java.awt.Point)8 DataBuffer (java.awt.image.DataBuffer)8 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)8 DataBufferByte (java.awt.image.DataBufferByte)6 SinglePixelPackedSampleModel (java.awt.image.SinglePixelPackedSampleModel)6 IIOException (javax.imageio.IIOException)5 Test (org.junit.Test)5 Rectangle (java.awt.Rectangle)4 ComponentSampleModel (java.awt.image.ComponentSampleModel)4