Example usage for java.awt.color ColorSpace toRGB

List of usage examples for java.awt.color ColorSpace toRGB

Introduction

In this page you can find the example usage for java.awt.color ColorSpace toRGB.

Prototype

public abstract float[] toRGB(float[] colorvalue);

Source Link

Document

Transforms a color value assumed to be in this ColorSpace into a value in the default CS_sRGB color space.

Usage

From source file:com.imaginary.home.lighting.Color.java

/**
 * Converts this color to {@link ColorMode#RGB}.
 * @return the RGB representation of this color
 *///from  www  .j a  v a 2s .  co  m
public @Nonnull Color convertToRGB() {
    switch (colorMode) {
    case RGB:
        return this;
    case HSV:
        java.awt.Color c = new java.awt.Color(
                java.awt.Color.HSBtoRGB(components[0] / 65535f, (components[1] * 100f) / 254f, 1f));

        return new Color(ColorMode.RGB, ((float) c.getRed()) / 255f, ((float) c.getGreen()) / 255f,
                ((float) c.getBlue()) / 255f);
    case CIEXYZ:
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_CIEXYZ);

        float[] tmp = cs.toRGB(components);
        return new Color(ColorMode.RGB, (tmp[0] * 100f) / 255f, (tmp[1] * 255f) / 100f, (tmp[2] * 255f) / 100f);
    case CT:
        // this is made up nonsense
        return new Color(ColorMode.RGB, 100f, 100f, 100f);
    }
    throw new RuntimeException("Invalid color mode: " + colorMode);
}