Example usage for java.awt.image DirectColorModel getDataElement

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

Introduction

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

Prototype

public int getDataElement(int[] components, int offset) 

Source Link

Document

Returns a pixel value represented as an int in this ColorModel , given an array of unnormalized color/alpha components.

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  ww.  jav  a  2 s .co  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;
}