Example usage for java.awt.image DirectColorModel getComponents

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

Introduction

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

Prototype

public final int[] getComponents(Object pixel, int[] components, int offset) 

Source Link

Document

Returns an array of unnormalized color/alpha components given a pixel in this ColorModel .

Usage

From source file:SampleAWTRenderer.java

private int[] processImage(Buffer buf) {
    int[] data = (int[]) buf.getData();
    int[] ret = new int[data.length];
    RGBFormat fmt = (RGBFormat) buf.getFormat();

    DirectColorModel dcm = new DirectColorModel(fmt.getBitsPerPixel(), fmt.getRedMask(), fmt.getGreenMask(),
            fmt.getBlueMask());/*from w  w  w.  j  ava2s .  c o m*/
    int[] rgb;
    int k;
    for (int i = 0; i < data.length; i++) {
        rgb = dcm.getComponents(data[i], null, 0);
        k = toGray(rgb);
        rgb[0] = rgb[1] = rgb[2] = k;
        ret[i] = dcm.getDataElement(rgb, 0);
    }
    return ret;
}