Example usage for java.awt Color getColorComponents

List of usage examples for java.awt Color getColorComponents

Introduction

In this page you can find the example usage for java.awt Color getColorComponents.

Prototype

public float[] getColorComponents(float[] compArray) 

Source Link

Document

Returns a float array containing only the color components of the Color , in the ColorSpace of the Color .

Usage

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

private boolean establishColorFromColor(StringBuffer codeBuffer, Color color) {
    //Important: see above note about color handling!
    float[] comps = color.getColorComponents(null);
    if (color.getColorSpace().getType() == ColorSpace.TYPE_CMYK) {
        // colorspace is CMYK
        writeSetColor(codeBuffer, comps, "setcmykcolor");
        return true;
    }/*w w w .j  a  va  2s. co  m*/
    return false;
}

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

private void establishFallbackRGB(StringBuffer codeBuffer, Color color) {
    float[] comps;
    if (color.getColorSpace().isCS_sRGB()) {
        comps = color.getColorComponents(null);
    } else {/*from ww w  .ja v  a 2  s . c o  m*/
        if (log.isDebugEnabled()) {
            log.debug("Converting color to sRGB as a fallback: " + color);
        }
        ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        comps = color.getColorComponents(sRGB, null);
    }
    assert comps.length == 3;
    boolean gray = ColorUtil.isGray(color);
    if (gray) {
        comps = new float[] { comps[0] };
    }
    writeSetColor(codeBuffer, comps, gray ? "setgray" : "setrgbcolor");
}

From source file:pl.edu.icm.visnow.geometries.viewer3d.Display3DPanel.java

public void setBackgroundGradient(Color c0, Color c1, Color c2) {
    bgColor = new Color3f(c0.getColorComponents(null));
    myFog.setColor(bgColor);//  w  ww .  j a va 2  s. c  o  m
    fireBgrColorChanged();
    int r0 = c0.getRed(), r1 = c1.getRed(), r2 = c2.getRed();
    int g0 = c0.getGreen(), g1 = c1.getGreen(), g2 = c2.getGreen();
    int b0 = c0.getBlue(), b1 = c1.getBlue(), b2 = c2.getBlue();
    int[] bgrData = new int[256 * 256];
    int k = 0;
    for (int i = 0; i < 128; i++) {
        float t = i / 127.f;
        int r = (int) (t * r1 + (1 - t) * r0);
        int g = (int) (t * g1 + (1 - t) * g0);
        int b = (int) (t * b1 + (1 - t) * b0);
        int c = ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);
        for (int j = 0; j < 256; j++, k++) {
            bgrData[k] = c;
        }
    }
    for (int i = 0; i < 128; i++) {
        float t = i / 127.f;
        int r = (int) (t * r2 + (1 - t) * r1);
        int g = (int) (t * g2 + (1 - t) * g1);
        int b = (int) (t * b2 + (1 - t) * b1);
        int c = ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);
        for (int j = 0; j < 256; j++, k++) {
            bgrData[k] = c;
        }
    }
    BufferedImage bgrImage = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB);
    bgrImage.setRGB(0, 0, 256, 256, bgrData, 0, 256);
    ImageComponent2D bgrImageComponent = new ImageComponent2D(ImageComponent2D.FORMAT_RGBA, bgrImage);
    bg.setImage(bgrImageComponent);
}

From source file:umich.ms.batmass.gui.viewers.map2d.components.Map2DZoomLevel.java

/**
 * Returns a Jet colormap almost like the Jet map from MatLab.
 * to white.//from w  w  w . ja v  a 2 s  .  c  o  m
 * @param size the size of the color palette
 * @return the color palette
 */
public int[] getJetPalette(int size) {
    int[] cm = new int[size];

    List<Color> colorPivots = baseMap.getColorPalette();

    // High contrast
    //        colorPivots.add(Color.decode("#000000")); // black
    //        colorPivots.add(Color.decode("#00007F")); // dark blue
    //        colorPivots.add(Color.decode("#007FFF")); // azure
    //        colorPivots.add(Color.decode("#FFFF00")); // yellow
    //        colorPivots.add(Color.decode("#00FFFF")); // cyan
    //        colorPivots.add(Color.decode("#FF7F00")); // orange
    //        colorPivots.add(Color.decode("#0000FF")); // blue
    //        colorPivots.add(Color.decode("#FF0000")); // red
    //        colorPivots.add(Color.decode("#7FFF7F")); // light green
    //        colorPivots.add(Color.decode("#7F0000")); // dark red

    int transCount = colorPivots.size() - 1;
    int transSize = (int) Math.ceil((double) size / (double) transCount);
    int curTrans = 0;
    int curMapPoint = 0;
    Color c1, c2;
    int r1, r2, g1, g2, b1, b2;
    float[] comp1 = new float[3];
    float[] comp2 = new float[3];
    float[] comp3 = new float[3];
    float weight;

    for (int transNum = 0; transNum < transCount; transNum++) {
        int curTransSize = Math.min(transSize, size - curMapPoint);
        c1 = colorPivots.get(transNum);
        c2 = colorPivots.get(transNum + 1);
        c1.getColorComponents(comp1);
        c2.getColorComponents(comp2);
        for (int ptTransNum = 0; ptTransNum < curTransSize; ptTransNum++) {
            weight = ((float) ptTransNum) / curTransSize;
            for (int i = 0; i < comp1.length; i++) {
                comp3[i] = (1.0f - weight) * comp1[i] + weight * comp2[i];
            }
            Color c3 = new Color(comp3[0], comp3[1], comp3[2]);
            cm[curMapPoint] = c3.getRGB();
            curMapPoint++;
        }
    }

    return cm;
}