Example usage for java.awt.image DirectColorModel DirectColorModel

List of usage examples for java.awt.image DirectColorModel DirectColorModel

Introduction

In this page you can find the example usage for java.awt.image DirectColorModel DirectColorModel.

Prototype

public DirectColorModel(int bits, int rmask, int gmask, int bmask, int amask) 

Source Link

Document

Constructs a DirectColorModel from the specified masks that indicate which bits in an int pixel representation contain the red, green and blue color samples and the alpha sample, if present.

Usage

From source file:FindComponents.java

/**
 * FindComponents.java -- prints out normalized color components for two
 * different/* w  w  w  .ja  v a 2s  .co m*/
 */
public FindComponents() {
    red8 = red5 = 30;
    green8 = green5 = 20;
    blue8 = blue5 = 10;
    alpha8 = 255;

    dcm32 = new DirectColorModel(32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
    value32 = (alpha8 << 24) + (red8 << 16) + (green8 << 8) + blue8;
    components = dcm32.getComponents(value32, null, 0);
    componentsf = dcm32.getNormalizedComponents(components, 0, null, 0);
    System.out.println("Normalized components are: ");
    for (int i = 0; i < componentsf.length; i++)
        System.out.println("\t" + componentsf[i]);

    dcm16 = new DirectColorModel(16, 0x7c00, 0x3e0, 0x1f);
    value16 = (short) ((red5 << 10) + (green5 << 5) + blue5);
    components = dcm16.getComponents(value16, null, 0);
    componentsf = dcm16.getNormalizedComponents(components, 0, null, 0);
    System.out.println("Normalized components are: ");
    for (int i = 0; i < componentsf.length; i++)
        System.out.println("\t" + componentsf[i]);
}

From source file:ImageOpByRomain.java

/**
 * {@inheritDoc}/*  www . j  a v  a  2 s  . c om*/
 */
@Override
public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    if (dst == null) {
        DirectColorModel directCM = new DirectColorModel(32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
        dst = createCompatibleDestImage(src, directCM);
    }

    int width = src.getWidth();
    int height = src.getHeight();

    int[] pixels = new int[width * height];
    GraphicsUtilities.getPixels(src, 0, 0, width, height, pixels);
    mixColor(pixels);
    GraphicsUtilities.setPixels(dst, 0, 0, width, height, pixels);

    return dst;
}

From source file:org.polymap.core.data.image.ImageEncodeProcessor.java

private void imageioEncodeJPEG(Image image, ChunkedResponseOutputStream out) throws IOException {
    // this code is from http://forums.sun.com/thread.jspa?threadID=5197061
    ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next();
    ImageWriteParam param = writer.getDefaultWriteParam();
    param.setSourceBands(new int[] { 0, 1, 2 });
    ColorModel cm = new DirectColorModel(24, 0x00ff0000, // Red
            0x0000ff00, // Green
            0x000000ff, // Blue
            0x0); // Alpha
    param.setDestinationType(new ImageTypeSpecifier(cm, cm.createCompatibleSampleModel(1, 1)));

    ImageOutputStream imageOut = ImageIO.createImageOutputStream(out);
    writer.setOutput(imageOut);/*  w w  w.  j  a  v a  2s.  co  m*/
    writer.write(null, new IIOImage((RenderedImage) image, null, null), param);
    writer.dispose();
    imageOut.close();
}