List of usage examples for java.awt.color ICC_ColorSpace getProfile
public ICC_Profile getProfile()
From source file:org.apache.fop.pdf.PDFColorHandler.java
private PDFICCBasedColorSpace getICCBasedColorSpace(ICC_ColorSpace cs) { ICC_Profile profile = cs.getProfile(); String desc = ColorProfileUtil.getICCProfileDescription(profile); if (log.isDebugEnabled()) { log.trace("ICC profile encountered: " + desc); }/*from ww w . j a v a 2s . co m*/ PDFICCBasedColorSpace pdfcs = this.resources.getICCColorSpaceByProfileName(desc); if (pdfcs == null) { //color space is not in the PDF, yet PDFFactory factory = getDocument().getFactory(); PDFICCStream pdfICCStream = factory.makePDFICCStream(); PDFDeviceColorSpace altSpace = PDFDeviceColorSpace.toPDFColorSpace(cs); pdfICCStream.setColorSpace(profile, altSpace); pdfcs = factory.makeICCBasedColorSpace(null, desc, pdfICCStream); } return pdfcs; }
From source file:org.apache.fop.render.pdf.ImageRenderedAdapter.java
/** {@inheritDoc} */ @Override/*from w w w . j a v a 2s. co m*/ protected ICC_Profile getEffectiveICCProfile() { ColorSpace cs = getImageColorSpace(); if (cs instanceof ICC_ColorSpace) { ICC_ColorSpace iccSpace = (ICC_ColorSpace) cs; return iccSpace.getProfile(); } else { return null; } }
From source file:org.apache.fop.util.ColorUtil.java
/** * Parse a color specified using the fop-rgb-named-color() function. * * @param value the function call//from w w w. jav a2s .c o m * @return a color if possible * @throws PropertyException if the format is wrong. */ private static Color parseAsFopRgbNamedColor(FOUserAgent foUserAgent, String value) throws PropertyException { Color parsedColor; int poss = value.indexOf("("); int pose = value.indexOf(")"); if (poss != -1 && pose != -1) { String[] args = value.substring(poss + 1, pose).split(","); try { if (args.length != 6) { throw new PropertyException("rgb-named-color() function must have 6 arguments"); } //Set up fallback sRGB value Color sRGB = parseFallback(args, value); /* Get and verify ICC profile name */ String iccProfileName = args[3].trim(); if (iccProfileName == null || "".equals(iccProfileName)) { throw new PropertyException("ICC profile name missing"); } ICC_ColorSpace colorSpace = null; String iccProfileSrc; if (isPseudoProfile(iccProfileName)) { throw new IllegalArgumentException( "Pseudo-profiles are not allowed with fop-rgb-named-color()"); } else { /* Get and verify ICC profile source */ iccProfileSrc = args[4].trim(); if (iccProfileSrc == null || "".equals(iccProfileSrc)) { throw new PropertyException("ICC profile source missing"); } iccProfileSrc = unescapeString(iccProfileSrc); } // color name String colorName = unescapeString(args[5].trim()); /* Ask FOP factory to get ColorSpace for the specified ICC profile source */ if (foUserAgent != null && iccProfileSrc != null) { RenderingIntent renderingIntent = RenderingIntent.AUTO; //TODO connect to fo:color-profile/@rendering-intent colorSpace = (ICC_ColorSpace) foUserAgent.getFactory().getColorSpaceCache().get(iccProfileName, foUserAgent.getBaseURL(), iccProfileSrc, renderingIntent); } if (colorSpace != null) { ICC_Profile profile = colorSpace.getProfile(); if (NamedColorProfileParser.isNamedColorProfile(profile)) { NamedColorProfileParser parser = new NamedColorProfileParser(); NamedColorProfile ncp = parser.parseProfile(profile, iccProfileName, iccProfileSrc); NamedColorSpace ncs = ncp.getNamedColor(colorName); if (ncs != null) { parsedColor = new ColorWithFallback(ncs, new float[] { 1.0f }, 1.0f, null, sRGB); } else { log.warn("Color '" + colorName + "' does not exist in named color profile: " + iccProfileSrc); parsedColor = sRGB; } } else { log.warn("ICC profile is no named color profile: " + iccProfileSrc); parsedColor = sRGB; } } else { // ICC profile could not be loaded - use rgb replacement values */ log.warn("Color profile '" + iccProfileSrc + "' not found. Using sRGB replacement values."); parsedColor = sRGB; } } catch (IOException ioe) { //wrap in a PropertyException throw new PropertyException(ioe); } catch (RuntimeException re) { throw new PropertyException(re); //wrap in a PropertyException } } else { throw new PropertyException("Unknown color format: " + value + ". Must be fop-rgb-named-color(r,g,b,NCNAME,src,color-name)"); } return parsedColor; }
From source file:org.apache.pdfbox.pdmodel.graphics.color.PDColorSpaceFactory.java
/** * This will create the correct color space from a java colorspace. * * @param doc The doc to potentiall write information to. * @param cs The awt colorspace./* w ww . j a v a 2 s. c o m*/ * * @return The color space. * * @throws IOException If the color space name is unknown. */ public static PDColorSpace createColorSpace(PDDocument doc, ColorSpace cs) throws IOException { PDColorSpace retval = null; if (cs.isCS_sRGB()) { retval = PDDeviceRGB.INSTANCE; } else if (cs instanceof ICC_ColorSpace) { ICC_ColorSpace ics = (ICC_ColorSpace) cs; PDICCBased pdCS = new PDICCBased(doc); retval = pdCS; COSArray ranges = new COSArray(); for (int i = 0; i < cs.getNumComponents(); i++) { ranges.add(new COSFloat(ics.getMinValue(i))); ranges.add(new COSFloat(ics.getMaxValue(i))); } PDStream iccData = pdCS.getPDStream(); OutputStream output = null; try { output = iccData.createOutputStream(); output.write(ics.getProfile().getData()); } finally { if (output != null) { output.close(); } } pdCS.setNumberOfComponents(cs.getNumComponents()); } else { throw new IOException("Not yet implemented:" + cs); } return retval; }