Java Code Examples for java.awt.image.ColorConvertOp.createCompatibleDestImage()

The following are Jave code examples for showing how to use createCompatibleDestImage() of the java.awt.image.ColorConvertOp class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: photohawk   File: ICCProfileColorConverter.java   Source Code and License Vote up 6 votes
/**
 * Creates a new ICCProfileColorConverter.
 *
 * @param img the image
 * @param cs  the color space
 */
public ICCProfileColorConverter(ConvenientBufferedImageWrapper img, ColorSpace cs) {
    ColorConvertOp transform = new ColorConvertOp(null);

    int[] bits = new int[cs.getNumComponents()];
    Arrays.fill(bits, SIGNIFICANT_BITS);
    BufferedImage temp = transform.createCompatibleDestImage(img.getBufferedImage(),
                                                             new ComponentColorModel(cs, bits,
                                                                                     img.getColorModel().hasAlpha(),
                                                                                     img.getColorModel().isAlphaPremultiplied(),
                                                                                     img.getColorModel().getTransparency(),
                                                                                     DataBuffer.TYPE_INT)
    );

    temp = transform.filter(img.getBufferedImage(), temp);

    this.img = new ConvenientBufferedImageWrapper(temp);
}
 
Example 2
Project: sumo   File: KmlIO.java   Source Code and License Vote up 5 votes
private static URL createOverview(GeoImageReader gir, boolean toFlip) throws IOException {
    File f = File.createTempFile("kmloverview", ".png");
    // generate a suitable size image
    double ratio = Math.max(((double) gir.getWidth()) / 1024., ((double) gir.getHeight()) / 1024.);
    // generate overview image
    BufferedImage temp = new BufferedImage((int) (gir.getWidth() * (1.0 / ratio)), (int) (gir.getHeight() * (1.0 / ratio)), gir.getType(true));
    // get a handle on the raster data
    WritableRaster raster = temp.getRaster();
    int[] data = gir.readAndDecimateTile(0, 0, gir.getWidth(), gir.getHeight(), 1.0 / ratio, true,0);
    raster.setSamples(0, 0, temp.getWidth(), temp.getHeight(), 0, data);

    float average = 0;
    for (int i = 0; i < data.length; i++) {
        average = average + data[i];
    }
    average = average / data.length;
    RescaleOp rescale = new RescaleOp(((1 << (8 * gir.getNumberOfBytes())) / 5f / average), 0, null);
    rescale.filter(temp, temp);

    ColorConvertOp bop = new ColorConvertOp(null);
    BufferedImage out = bop.createCompatibleDestImage(temp, new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY), false, false, ComponentColorModel.OPAQUE, DataBuffer.TYPE_BYTE));
    out = bop.filter(temp, out);

    //flip the image if necessary
    if (toFlip) {
        int w = out.getWidth();
        int h = out.getHeight();
        BufferedImage dimg = new BufferedImage(w, h, out.getType());
        Graphics2D g = dimg.createGraphics();
        g.drawImage(out, 0, 0, w, h, w, 0, 0, h, null);
        g.dispose();
        ImageIO.write(dimg, "png", f);
    } else {
        ImageIO.write(out, "png", f);
    }
    return f.toURI().toURL();

}
 
Example 3
Project: OpenJSharp   File: ColorConvertOpTests.java   Source Code and License Vote up 5 votes
public Context(TestEnvironment env, Result res) {

            graphics = (Graphics2D)env.getGraphics();
            cs = getColorSpace(env);

            // TODO: provide rendering hints
            op_img = new ColorConvertOp(cs, null);
            ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
            op_rst = new ColorConvertOp(sRGB, cs, null);

            int size = env.getIntValue(sizeList);

            ImageContent content = (ImageContent)env.getModifier(contentList);
            ImageType srcType = (ImageType)env.getModifier(sourceType);

            src = createBufferedImage(size, size, content, srcType.type);
            rsrc = src.getRaster();

            ImageType dstType = (ImageType)env.getModifier(destinationType);
            if (dstType == ImageType.COMPATIBLE_DST) {
                dst = op_img.createCompatibleDestImage(src, null);
            } else {
                dst = createBufferedImage(size, size, content, dstType.type);
            }
            // raster always has to be comatible
            rdst = op_rst.createCompatibleDestRaster(rsrc);
        }
 
Example 4
Project: jdk8u-jdk   File: ColorConvertOpTests.java   Source Code and License Vote up 5 votes
public Context(TestEnvironment env, Result res) {

            graphics = (Graphics2D)env.getGraphics();
            cs = getColorSpace(env);

            // TODO: provide rendering hints
            op_img = new ColorConvertOp(cs, null);
            ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
            op_rst = new ColorConvertOp(sRGB, cs, null);

            int size = env.getIntValue(sizeList);

            ImageContent content = (ImageContent)env.getModifier(contentList);
            ImageType srcType = (ImageType)env.getModifier(sourceType);

            src = createBufferedImage(size, size, content, srcType.type);
            rsrc = src.getRaster();

            ImageType dstType = (ImageType)env.getModifier(destinationType);
            if (dstType == ImageType.COMPATIBLE_DST) {
                dst = op_img.createCompatibleDestImage(src, null);
            } else {
                dst = createBufferedImage(size, size, content, dstType.type);
            }
            // raster always has to be comatible
            rdst = op_rst.createCompatibleDestRaster(rsrc);
        }
 
Example 5
Project: openjdk-jdk10   File: ColorConvertOpTests.java   Source Code and License Vote up 5 votes
public Context(TestEnvironment env, Result res) {

            graphics = (Graphics2D)env.getGraphics();
            cs = getColorSpace(env);

            // TODO: provide rendering hints
            op_img = new ColorConvertOp(cs, null);
            ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
            op_rst = new ColorConvertOp(sRGB, cs, null);

            int size = env.getIntValue(sizeList);

            ImageContent content = (ImageContent)env.getModifier(contentList);
            ImageType srcType = (ImageType)env.getModifier(sourceType);

            src = createBufferedImage(size, size, content, srcType.type);
            rsrc = src.getRaster();

            ImageType dstType = (ImageType)env.getModifier(destinationType);
            if (dstType == ImageType.COMPATIBLE_DST) {
                dst = op_img.createCompatibleDestImage(src, null);
            } else {
                dst = createBufferedImage(size, size, content, dstType.type);
            }
            // raster always has to be comatible
            rdst = op_rst.createCompatibleDestRaster(rsrc);
        }
 
Example 6
Project: openjdk9   File: ColorConvertOpTests.java   Source Code and License Vote up 5 votes
public Context(TestEnvironment env, Result res) {

            graphics = (Graphics2D)env.getGraphics();
            cs = getColorSpace(env);

            // TODO: provide rendering hints
            op_img = new ColorConvertOp(cs, null);
            ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
            op_rst = new ColorConvertOp(sRGB, cs, null);

            int size = env.getIntValue(sizeList);

            ImageContent content = (ImageContent)env.getModifier(contentList);
            ImageType srcType = (ImageType)env.getModifier(sourceType);

            src = createBufferedImage(size, size, content, srcType.type);
            rsrc = src.getRaster();

            ImageType dstType = (ImageType)env.getModifier(destinationType);
            if (dstType == ImageType.COMPATIBLE_DST) {
                dst = op_img.createCompatibleDestImage(src, null);
            } else {
                dst = createBufferedImage(size, size, content, dstType.type);
            }
            // raster always has to be comatible
            rdst = op_rst.createCompatibleDestRaster(rsrc);
        }
 
Example 7
Project: jdk8u_jdk   File: ColorConvertOpTests.java   Source Code and License Vote up 5 votes
public Context(TestEnvironment env, Result res) {

            graphics = (Graphics2D)env.getGraphics();
            cs = getColorSpace(env);

            // TODO: provide rendering hints
            op_img = new ColorConvertOp(cs, null);
            ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
            op_rst = new ColorConvertOp(sRGB, cs, null);

            int size = env.getIntValue(sizeList);

            ImageContent content = (ImageContent)env.getModifier(contentList);
            ImageType srcType = (ImageType)env.getModifier(sourceType);

            src = createBufferedImage(size, size, content, srcType.type);
            rsrc = src.getRaster();

            ImageType dstType = (ImageType)env.getModifier(destinationType);
            if (dstType == ImageType.COMPATIBLE_DST) {
                dst = op_img.createCompatibleDestImage(src, null);
            } else {
                dst = createBufferedImage(size, size, content, dstType.type);
            }
            // raster always has to be comatible
            rdst = op_rst.createCompatibleDestRaster(rsrc);
        }
 
Example 8
Project: lookaside_java-1.8.0-openjdk   File: ColorConvertOpTests.java   Source Code and License Vote up 5 votes
public Context(TestEnvironment env, Result res) {

            graphics = (Graphics2D)env.getGraphics();
            cs = getColorSpace(env);

            // TODO: provide rendering hints
            op_img = new ColorConvertOp(cs, null);
            ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
            op_rst = new ColorConvertOp(sRGB, cs, null);

            int size = env.getIntValue(sizeList);

            ImageContent content = (ImageContent)env.getModifier(contentList);
            ImageType srcType = (ImageType)env.getModifier(sourceType);

            src = createBufferedImage(size, size, content, srcType.type);
            rsrc = src.getRaster();

            ImageType dstType = (ImageType)env.getModifier(destinationType);
            if (dstType == ImageType.COMPATIBLE_DST) {
                dst = op_img.createCompatibleDestImage(src, null);
            } else {
                dst = createBufferedImage(size, size, content, dstType.type);
            }
            // raster always has to be comatible
            rdst = op_rst.createCompatibleDestRaster(rsrc);
        }
 
Example 9
Project: infobip-open-jdk-8   File: ColorConvertOpTests.java   Source Code and License Vote up 5 votes
public Context(TestEnvironment env, Result res) {

            graphics = (Graphics2D)env.getGraphics();
            cs = getColorSpace(env);

            // TODO: provide rendering hints
            op_img = new ColorConvertOp(cs, null);
            ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
            op_rst = new ColorConvertOp(sRGB, cs, null);

            int size = env.getIntValue(sizeList);

            ImageContent content = (ImageContent)env.getModifier(contentList);
            ImageType srcType = (ImageType)env.getModifier(sourceType);

            src = createBufferedImage(size, size, content, srcType.type);
            rsrc = src.getRaster();

            ImageType dstType = (ImageType)env.getModifier(destinationType);
            if (dstType == ImageType.COMPATIBLE_DST) {
                dst = op_img.createCompatibleDestImage(src, null);
            } else {
                dst = createBufferedImage(size, size, content, dstType.type);
            }
            // raster always has to be comatible
            rdst = op_rst.createCompatibleDestRaster(rsrc);
        }
 
Example 10
Project: jdk8u-dev-jdk   File: ColorConvertOpTests.java   Source Code and License Vote up 5 votes
public Context(TestEnvironment env, Result res) {

            graphics = (Graphics2D)env.getGraphics();
            cs = getColorSpace(env);

            // TODO: provide rendering hints
            op_img = new ColorConvertOp(cs, null);
            ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
            op_rst = new ColorConvertOp(sRGB, cs, null);

            int size = env.getIntValue(sizeList);

            ImageContent content = (ImageContent)env.getModifier(contentList);
            ImageType srcType = (ImageType)env.getModifier(sourceType);

            src = createBufferedImage(size, size, content, srcType.type);
            rsrc = src.getRaster();

            ImageType dstType = (ImageType)env.getModifier(destinationType);
            if (dstType == ImageType.COMPATIBLE_DST) {
                dst = op_img.createCompatibleDestImage(src, null);
            } else {
                dst = createBufferedImage(size, size, content, dstType.type);
            }
            // raster always has to be comatible
            rdst = op_rst.createCompatibleDestRaster(rsrc);
        }
 
Example 11
Project: OLD-OpenJDK8   File: ColorConvertOpTests.java   Source Code and License Vote up 5 votes
public Context(TestEnvironment env, Result res) {

            graphics = (Graphics2D)env.getGraphics();
            cs = getColorSpace(env);

            // TODO: provide rendering hints
            op_img = new ColorConvertOp(cs, null);
            ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
            op_rst = new ColorConvertOp(sRGB, cs, null);

            int size = env.getIntValue(sizeList);

            ImageContent content = (ImageContent)env.getModifier(contentList);
            ImageType srcType = (ImageType)env.getModifier(sourceType);

            src = createBufferedImage(size, size, content, srcType.type);
            rsrc = src.getRaster();

            ImageType dstType = (ImageType)env.getModifier(destinationType);
            if (dstType == ImageType.COMPATIBLE_DST) {
                dst = op_img.createCompatibleDestImage(src, null);
            } else {
                dst = createBufferedImage(size, size, content, dstType.type);
            }
            // raster always has to be comatible
            rdst = op_rst.createCompatibleDestRaster(rsrc);
        }