Example usage for java.awt.image ColorModel getComponentSize

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

Introduction

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

Prototype

public int getComponentSize(int componentIdx) 

Source Link

Document

Returns the number of bits for the specified color/alpha component.

Usage

From source file:org.apache.fop.render.pdf.ImageRenderedAdapter.java

/** {@inheritDoc} */
public int getBitsPerComponent() {
    ColorModel cm = getEffectiveColorModel();
    if (cm instanceof IndexColorModel) {
        IndexColorModel icm = (IndexColorModel) cm;
        return icm.getComponentSize(0);
    } else {//from  w w  w.ja  v a 2 s .  c o  m
        return cm.getComponentSize(0);
    }
}

From source file:org.apache.xmlgraphics.ps.PSImageUtils.java

private static ColorModel populateImageDictionary(ImageEncodingHelper helper, PSDictionary imageDict) {
    RenderedImage img = helper.getImage();
    String w = Integer.toString(img.getWidth());
    String h = Integer.toString(img.getHeight());
    imageDict.put("/ImageType", "1");
    imageDict.put("/Width", w);
    imageDict.put("/Height", h);

    ColorModel cm = helper.getEncodedColorModel();

    boolean invertColors = false;
    String decodeArray = getDecodeArray(cm.getNumComponents(), invertColors);
    int bitsPerComp = cm.getComponentSize(0);

    // Setup scanning for left-to-right and top-to-bottom
    imageDict.put("/ImageMatrix", "[" + w + " 0 0 " + h + " 0 0]");

    if ((cm instanceof IndexColorModel)) {
        IndexColorModel im = (IndexColorModel) cm;
        int c = im.getMapSize();
        int hival = c - 1;
        if (hival > 4095) {
            throw new UnsupportedOperationException("hival must not go beyond 4095");
        }//  ww  w .  ja v a2  s .c o  m
        bitsPerComp = im.getPixelSize();
        int ceiling = ((int) Math.pow(2, bitsPerComp)) - 1;
        decodeArray = "[0 " + ceiling + "]";
    }
    imageDict.put("/BitsPerComponent", Integer.toString(bitsPerComp));
    imageDict.put("/Decode", decodeArray);
    return cm;
}