Example usage for java.awt.image ColorModel coerceData

List of usage examples for java.awt.image ColorModel coerceData

Introduction

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

Prototype

public ColorModel coerceData(WritableRaster raster, boolean isAlphaPremultiplied) 

Source Link

Document

Forces the raster data to match the state specified in the isAlphaPremultiplied variable, assuming the data is currently correctly described by this ColorModel .

Usage

From source file:GraphicsUtil.java

/**
 * Create a new ColorModel with it's alpha premultiplied state matching
 * newAlphaPreMult./* w ww  . j av  a2  s . co m*/
 * @param cm The ColorModel to change the alpha premult state of.
 * @param newAlphaPreMult The new state of alpha premult.
 * @return   A new colorModel that has isAlphaPremultiplied()
 *           equal to newAlphaPreMult.
 */
public static ColorModel coerceColorModel(ColorModel cm, boolean newAlphaPreMult) {
    if (cm.isAlphaPremultiplied() == newAlphaPreMult)
        return cm;

    // Easiest way to build proper colormodel for new Alpha state...
    // Eventually this should switch on known ColorModel types and
    // only fall back on this hack when the CM type is unknown.
    WritableRaster wr = cm.createCompatibleWritableRaster(1, 1);
    return cm.coerceData(wr, newAlphaPreMult);
}