/** * Creates a color instance representing a device-specific CMYK color. An sRGB value * is calculated from the CMYK colors but it may not correctly represent the given CMYK * values. * @param cmykComponents the CMYK components * @return the device-specific color */ public static Color createCMYKColor(float[] cmykComponents) { DeviceCMYKColorSpace cmykCs = ColorSpaces.getDeviceCMYKColorSpace(); Color cmykColor = new ColorWithAlternatives(cmykCs, cmykComponents, 1.0f, null); return cmykColor; }
/** * Constructor for RGBA colors. * @param rgba the combined RGBA value * @param hasalpha true if the alpha bits are valid, false otherwise * @param alternativeColors the prioritized list of alternative colors. * @see Color#Color(int, boolean) */ public ColorWithAlternatives(int rgba, boolean hasalpha, Color[] alternativeColors) { super(rgba, hasalpha); initAlternativeColors(alternativeColors); }
/** * Default constructor using the D65 white point. */ public CIELabColorSpace() { this(getD65WhitePoint()); }
/** * Returns an instance of the CIE L*a*b* color space using the D50 white point. * @return an instance of the requested CIE L*a*b* color space */ public static synchronized CIELabColorSpace getCIELabColorSpaceD50() { if (cieLabD50 == null) { cieLabD50 = new CIELabColorSpace(CIELabColorSpace.getD50WhitePoint()); } return cieLabD50; }
/** * Returns an instance of the CIE L*a*b* color space using the D65 white point. * @return an instance of the requested CIE L*a*b* color space */ public static synchronized CIELabColorSpace getCIELabColorSpaceD65() { if (cieLabD65 == null) { cieLabD65 = new CIELabColorSpace(CIELabColorSpace.getD65WhitePoint()); } return cieLabD65; }
/** * Creates a {@link Color} instance from color values usually used by the L*a*b* color space * by scaling them to the 0.0..1.0 range expected by Color's constructor. * @param l the L* component (values between 0 and 100) * @param a the a* component (usually between -128 and +127) * @param b the b* component (usually between -128 and +127) * @param alpha the alpha component (values between 0 and 1) * @return the requested color instance */ public Color toColor(float l, float a, float b, float alpha) { return toColor(new float[] {l, a, b}, alpha); }
private static Color[] getAlternativeColors(Color color) { if (color instanceof ColorWithAlternatives) { ColorWithAlternatives cwa = (ColorWithAlternatives)color; if (cwa.hasAlternativeColors()) { return cwa.getAlternativeColors(); } } return null; }
/** {@inheritDoc} */ @Override public float[] toCIEXYZ(float[] colorvalue) { checkNumComponents(colorvalue); //Scale to native value range float l = denormalize(colorvalue[0], 0); float a = denormalize(colorvalue[1], 1); float b = denormalize(colorvalue[2], 2); return toCIEXYZNative(l, a, b); }
/** * Sets the text color. * @param color the new text color */ public void setTextColor(Color color) { if (!ColorUtil.isSameColor(color, this.textColor)) { this.fontChanged = true; } this.textColor = color; }
/** * Converts normalized (0..1) color components to CIE L*a*b*'s native value range. * @param comps the normalized components. * @return the denormalized components */ public float[] toNativeComponents(float[] comps) { checkNumComponents(comps); float[] nativeComps = new float[comps.length]; for (int i = 0, c = comps.length; i < c; i++) { nativeComps[i] = denormalize(comps[i], i); } return nativeComps; }
/** * Creates an uncalibrated CMYK color with the given gray value. * @param black the gray component (0 - 1) * @return the CMYK color */ public static Color toCMYKGrayColor(float black) { return org.apache.xmlgraphics.java2d.color.ColorUtil.toCMYKGrayColor(black); } }
/** * Absolute colorimetric. NOT IMPLEMENTED. * Temporarily returns same as perceptual. * @param values the color values in the local color space * @return the sRGB values */ private float[] absoluteColorimetricToRGB(float[] values) { return perceptualToRGB(values); }
/** * Returns an instance of the device-specific CMYK color space. * @return an instance of the device-specific CMYK color space */ public static synchronized DeviceCMYKColorSpace getDeviceCMYKColorSpace() { if (deviceCMYK == null) { deviceCMYK = new DeviceCMYKColorSpace(); } return deviceCMYK; }
/** * CIE Lab space constructor which allows to give an arbitrary white point. * @param whitePoint the white point in XYZ coordinates (valid values: 0.0f to 1.0f, although * values slightly larger than 1.0f are common) */ public CIELabColorSpace(float[] whitePoint) { super(ColorSpace.TYPE_Lab, 3); checkNumComponents(whitePoint, 3); this.wpX = whitePoint[0]; this.wpY = whitePoint[1]; this.wpZ = whitePoint[2]; }
/** * Lightens up a color for groove, ridge, inset and outset border effects. * @param col the color to lighten up * @param factor factor by which to lighten up (negative values darken the color) * @return the modified color */ public static Color lightenColor(Color col, float factor) { return org.apache.xmlgraphics.java2d.color.ColorUtil.lightenColor(col, factor); }
/** {@inheritDoc} */ @Override public boolean equals(Object o) { if (this == o) { return true; } if (o instanceof ColorProperty) { return org.apache.xmlgraphics.java2d.color.ColorUtil.isSameColor( ((ColorProperty) o).color, this.color); } return false; }
/** * Constructor for RGB colors. * @param r the red component * @param g the green component * @param b the blue component * @param alternativeColors the prioritized list of alternative colors. * @see Color#Color(int, int, int) */ public ColorWithAlternatives(int r, int g, int b, Color[] alternativeColors) { super(r, g, b); initAlternativeColors(alternativeColors); }
/** * Saturation. NOT IMPLEMENTED. Temporarily returns same * as perceptual. * @param values the color values in the local color space * @return the sRGB values */ private float[] saturationToRGB(float[] values) { return perceptualToRGB(values); }
/** * Constructor for RGB colors. * @param rgb the combined RGB components * @param alternativeColors the prioritized list of alternative colors. * @see Color#Color(int) */ public ColorWithAlternatives(int rgb, Color[] alternativeColors) { super(rgb); initAlternativeColors(alternativeColors); }
/** * Constructor for RGBA colors. * @param r the red component * @param g the green component * @param b the blue component * @param a the alpha component * @param alternativeColors the prioritized list of alternative colors. * @see Color#Color(int, int, int, int) */ public ColorWithAlternatives(int r, int g, int b, int a, Color[] alternativeColors) { super(r, g, b, a); initAlternativeColors(alternativeColors); }