/** * 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); }
/** * 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; }
private void checkNumComponents(float[] colorvalue) { checkNumComponents(colorvalue, getNumComponents()); }
/** * 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; }
/** {@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); }
/** * Returns a Color object that corresponds to the input Paint's * CIE Lab color value. * * @param e the element using the color * @param c the CIE Lab color definition * @param opacity the opacity * @param ctx the bridge context to use */ public static Color convertCIELabColor(Element e, CIELabColor c, float opacity, BridgeContext ctx) { CIELabColorSpace cs = new CIELabColorSpace(c.getWhitePoint()); float[] lab = c.getColorValues(); Color specColor = cs.toColor(lab[0], lab[1], lab[2], opacity); return specColor; }
private boolean establishColorFromColor(StringBuffer codeBuffer, Color color, boolean fill) { ColorSpace cs = color.getColorSpace(); if (cs instanceof DeviceCMYKColorSpace) { establishDeviceCMYK(codeBuffer, color, fill); return true; } else if (!cs.isCS_sRGB()) { if (cs instanceof ICC_ColorSpace) { PDFICCBasedColorSpace pdfcs = getICCBasedColorSpace((ICC_ColorSpace)cs); establishColor(codeBuffer, pdfcs, color, fill); return true; } else if (cs instanceof NamedColorSpace) { PDFSeparationColorSpace sepcs = getSeparationColorSpace((NamedColorSpace)cs); establishColor(codeBuffer, sepcs, color, fill); return true; } else if (cs instanceof CIELabColorSpace) { CIELabColorSpace labcs = (CIELabColorSpace)cs; PDFCIELabColorSpace pdflab = getCIELabColorSpace(labcs); selectColorSpace(codeBuffer, pdflab, fill); float[] comps = color.getColorComponents(null); float[] nativeComps = labcs.toNativeComponents(comps); writeColor(codeBuffer, nativeComps, labcs.getNumComponents(), (fill ? "sc" : "SC")); return true; } } return false; }
/** * 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; }
checkNumComponents(colorvalue, 3); float x = colorvalue[0]; float y = colorvalue[1]; l = normalize(l, 0); a = normalize(a, 1); b = normalize(b, 2); return new float[] {l, a, b};
/** * 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]; }
/** {@inheritDoc} */ @Override public float[] fromRGB(float[] rgbvalue) { ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB); float[] xyz = sRGB.toCIEXYZ(rgbvalue); return fromCIEXYZ(xyz); }
/** * Returns a Color object that corresponds to the input Paint's * CIE Lab color value. * * @param e the element using the color * @param c the CIE Lab color definition * @param opacity the opacity * @param ctx the bridge context to use */ public static Color convertCIELabColor(Element e, CIELabColor c, float opacity, BridgeContext ctx) { CIELabColorSpace cs = new CIELabColorSpace(c.getWhitePoint()); float[] lab = c.getColorValues(); Color specColor = cs.toColor(lab[0], lab[1], lab[2], opacity); return specColor; }
/** * Returns a Color object that corresponds to the input Paint's * CIE Lab color value. * * @param e the element using the color * @param c the CIE Lab color definition * @param opacity the opacity * @param ctx the bridge context to use */ public static Color convertCIELabColor(Element e, CIELabColor c, float opacity, BridgeContext ctx) { CIELabColorSpace cs = new CIELabColorSpace(c.getWhitePoint()); float[] lab = c.getColorValues(); Color specColor = cs.toColor(lab[0], lab[1], lab[2], opacity); return specColor; }
result[i] = new NamedColorSpace(name, labCS.toColor(colorvalue, 1.0f), profileName, profileURI); break;
Color labColor = cs.toColor(l, a, b, 1.0f);