List of usage examples for java.awt.color ColorSpace TYPE_CMYK
int TYPE_CMYK
To view the source code for java.awt.color ColorSpace TYPE_CMYK.
Click Source Link
From source file:io.warp10.script.processing.image.Pdecode.java
@Override public Object apply(WarpScriptStack stack) throws WarpScriptException { Object top = stack.pop();/*from w w w. j a v a 2 s.co m*/ String data = top.toString(); if (!(top instanceof String) || !data.startsWith("data:image/")) { throw new WarpScriptException(getName() + " expects a base64 data URI on top of the stack."); } data = data.substring(data.indexOf(",") + 1); byte[] bytes = Base64.decodeBase64(data); Image awtImage = new ImageIcon(bytes).getImage(); if (awtImage instanceof BufferedImage) { BufferedImage buffImage = (BufferedImage) awtImage; int space = buffImage.getColorModel().getColorSpace().getType(); if (space == ColorSpace.TYPE_CMYK) { throw new WarpScriptException(getName() + " only supports RGB images."); } } PImage image = new PImage(awtImage); // // Check transparency // if (null != image.pixels) { for (int i = 0; i < image.pixels.length; i++) { // since transparency is often at corners, hopefully this // will find a non-transparent pixel quickly and exit if ((image.pixels[i] & 0xff000000) != 0xff000000) { image.format = PImage.ARGB; break; } } } stack.push(image); return stack; }
From source file:fi.nls.oskari.printout.printing.PDPageContentStream.java
/** * Set the stroking color, specified as RGB. * /*from w ww. j a v a 2 s .c o m*/ * @param color * The color to set. * @throws IOException * If an IO error occurs while writing to the stream. */ public void setStrokingColor(Color color) throws IOException { ColorSpace colorSpace = color.getColorSpace(); if (colorSpace.getType() == ColorSpace.TYPE_RGB) { setStrokingColor(color.getRed(), color.getGreen(), color.getBlue()); } else if (colorSpace.getType() == ColorSpace.TYPE_GRAY) { color.getColorComponents(colorComponents); setStrokingColor(colorComponents[0]); } else if (colorSpace.getType() == ColorSpace.TYPE_CMYK) { color.getColorComponents(colorComponents); setStrokingColor(colorComponents[0], colorComponents[1], colorComponents[2], colorComponents[3]); } else { throw new IOException("Error: unknown colorspace:" + colorSpace); } }
From source file:fi.nls.oskari.printout.printing.PDPageContentStream.java
/** * Set the non stroking color, specified as RGB. * /* w w w. j a v a 2s . co m*/ * @param color * The color to set. * @throws IOException * If an IO error occurs while writing to the stream. */ public void setNonStrokingColor(Color color) throws IOException { ColorSpace colorSpace = color.getColorSpace(); if (colorSpace.getType() == ColorSpace.TYPE_RGB) { setNonStrokingColor(color.getRed(), color.getGreen(), color.getBlue()); } else if (colorSpace.getType() == ColorSpace.TYPE_GRAY) { color.getColorComponents(colorComponents); setNonStrokingColor(colorComponents[0]); } else if (colorSpace.getType() == ColorSpace.TYPE_CMYK) { color.getColorComponents(colorComponents); setNonStrokingColor(colorComponents[0], colorComponents[1], colorComponents[2], colorComponents[3]); } else { throw new IOException("Error: unknown colorspace:" + colorSpace); } }
From source file:org.apache.fop.afp.goca.GraphicsSetProcessColor.java
/** * Main constructor/*from w w w .j a v a2 s. c om*/ * * @param color the color to set */ public GraphicsSetProcessColor(Color color) { if (color instanceof ColorWithAlternatives) { ColorWithAlternatives cwa = (ColorWithAlternatives) color; Color alt = cwa.getFirstAlternativeOfType(ColorSpace.TYPE_CMYK); if (alt != null) { this.color = alt; this.componentsSize = 4; return; } } ColorSpace cs = color.getColorSpace(); int colSpaceType = cs.getType(); if (colSpaceType == ColorSpace.TYPE_CMYK) { this.color = color; } else if (cs instanceof CIELabColorSpace) { //TODO Convert between illuminants if not D50 according to rendering intents //Right now, we're assuming D50 as the GOCA spec requires. this.color = color; //16bit components didn't work, and 8-bit sadly has reduced accuracy. } else { if (!color.getColorSpace().isCS_sRGB()) { this.color = ColorUtil.toSRGBColor(color); } else { this.color = color; } } this.componentsSize = this.color.getColorSpace().getNumComponents(); }
From source file:org.apache.fop.afp.goca.GraphicsSetProcessColor.java
/** {@inheritDoc} */ public void writeToStream(OutputStream os) throws IOException { float[] colorComponents = color.getColorComponents(null); // COLSPCE/* www . j a v a 2s .com*/ byte colspace; ColorSpace cs = color.getColorSpace(); int colSpaceType = cs.getType(); ByteArrayOutputStream baout = new ByteArrayOutputStream(); byte[] colsizes; if (colSpaceType == ColorSpace.TYPE_CMYK) { colspace = CMYK; colsizes = new byte[] { 0x08, 0x08, 0x08, 0x08 }; for (int i = 0; i < colorComponents.length; i++) { baout.write(Math.round(colorComponents[i] * 255)); } } else if (colSpaceType == ColorSpace.TYPE_RGB) { colspace = RGB; colsizes = new byte[] { 0x08, 0x08, 0x08, 0x00 }; for (int i = 0; i < colorComponents.length; i++) { baout.write(Math.round(colorComponents[i] * 255)); } } else if (cs instanceof CIELabColorSpace) { colspace = CIELAB; colsizes = new byte[] { 0x08, 0x08, 0x08, 0x00 }; DataOutput dout = new java.io.DataOutputStream(baout); //According to GOCA, I'd expect the multiplicator below to be 255f, not 100f //But only IBM AFP Workbench seems to support Lab colors and it requires "c * 100f" int l = Math.round(colorComponents[0] * 100f); int a = Math.round(colorComponents[1] * 255f) - 128; int b = Math.round(colorComponents[2] * 255f) - 128; dout.writeByte(l); dout.writeByte(a); dout.writeByte(b); } else { throw new IllegalStateException(); } int len = getDataLength(); byte[] data = new byte[12]; data[0] = getOrderCode(); // GSPCOL order code data[1] = (byte) (len - 2); // LEN data[2] = 0x00; // reserved; must be zero data[3] = colspace; // COLSPCE data[4] = 0x00; // reserved; must be zero data[5] = 0x00; // reserved; must be zero data[6] = 0x00; // reserved; must be zero data[7] = 0x00; // reserved; must be zero data[8] = colsizes[0]; // COLSIZE(S) data[9] = colsizes[1]; data[10] = colsizes[2]; data[11] = colsizes[3]; os.write(data); baout.writeTo(os); }
From source file:org.apache.fop.afp.ptoca.PtocaBuilder.java
/** * The Set Extended Text Color control sequence specifies a color value and * defines the color space and encoding for that value. The specified color * value is applied to foreground areas of the text presentation space. * <p>/* www . ja va 2 s . co m*/ * This is a modal control sequence. * * @param col The color to be set. * @throws IOException if an I/O error occurs */ public void setExtendedTextColor(Color col) throws IOException { if (ColorUtil.isSameColor(col, currentColor)) { return; } if (col instanceof ColorWithAlternatives) { ColorWithAlternatives cwa = (ColorWithAlternatives) col; Color alt = cwa.getFirstAlternativeOfType(ColorSpace.TYPE_CMYK); if (alt != null) { col = alt; } } ColorSpace cs = col.getColorSpace(); newControlSequence(); if (col.getColorSpace().getType() == ColorSpace.TYPE_CMYK) { // Color space - 0x04 = CMYK, all else are reserved and must be zero writeBytes(0x00, 0x04, 0x00, 0x00, 0x00, 0x00); writeBytes(8, 8, 8, 8); // Number of bits in component 1, 2, 3 & 4 respectively float[] comps = col.getColorComponents(null); assert comps.length == 4; for (int i = 0; i < 4; i++) { int component = Math.round(comps[i] * 255); writeBytes(component); } } else if (cs instanceof CIELabColorSpace) { // Color space - 0x08 = CIELAB, all else are reserved and must be zero writeBytes(0x00, 0x08, 0x00, 0x00, 0x00, 0x00); writeBytes(8, 8, 8, 0); // Number of bits in component 1,2,3 & 4 //Sadly, 16 bit components don't seem to work float[] colorComponents = col.getColorComponents(null); int l = Math.round(colorComponents[0] * 255f); int a = Math.round(colorComponents[1] * 255f) - 128; int b = Math.round(colorComponents[2] * 255f) - 128; writeBytes(l, a, b); // l*, a* and b* } else { // Color space - 0x01 = RGB, all else are reserved and must be zero writeBytes(0x00, 0x01, 0x00, 0x00, 0x00, 0x00); writeBytes(8, 8, 8, 0); // Number of bits in component 1, 2, 3 & 4 respectively writeBytes(col.getRed(), col.getGreen(), col.getBlue()); // RGB intensity } commit(chained(SEC)); this.currentColor = col; }
From source file:org.apache.fop.render.afp.AFPImageHandlerRawJPEG.java
/** {@inheritDoc} */ public void handleImage(RenderingContext context, Image image, Rectangle pos) throws IOException { AFPRenderingContext afpContext = (AFPRenderingContext) context; AFPImageObjectInfo imageObjectInfo = (AFPImageObjectInfo) createDataObjectInfo(); AFPPaintingState paintingState = afpContext.getPaintingState(); // set resource information setResourceInformation(imageObjectInfo, image.getInfo().getOriginalURI(), afpContext.getForeignAttributes()); setDefaultResourceLevel(imageObjectInfo, afpContext.getResourceManager()); // Positioning imageObjectInfo.setObjectAreaInfo(createObjectAreaInfo(paintingState, pos)); updateIntrinsicSize(imageObjectInfo, paintingState, image.getSize()); // Image content ImageRawJPEG jpeg = (ImageRawJPEG) image; imageObjectInfo.setCompression(ImageContent.COMPID_JPEG); ColorSpace cs = jpeg.getColorSpace(); switch (cs.getType()) { case ColorSpace.TYPE_GRAY: imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS11); imageObjectInfo.setColor(false); imageObjectInfo.setBitsPerPixel(8); break;//from w w w . j a v a2 s . co m case ColorSpace.TYPE_RGB: imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS11); imageObjectInfo.setColor(true); imageObjectInfo.setBitsPerPixel(24); break; case ColorSpace.TYPE_CMYK: imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS45); imageObjectInfo.setColor(true); imageObjectInfo.setBitsPerPixel(32); break; default: throw new IllegalStateException("Color space of JPEG image not supported: " + cs); } boolean included = afpContext.getResourceManager().tryIncludeObject(imageObjectInfo); if (!included) { log.debug("Embedding undecoded JPEG as IOCA image..."); InputStream inputStream = jpeg.createInputStream(); try { imageObjectInfo.setData(IOUtils.toByteArray(inputStream)); } finally { IOUtils.closeQuietly(inputStream); } // Create image afpContext.getResourceManager().createObject(imageObjectInfo); } }
From source file:org.apache.fop.render.afp.AFPImageHandlerRawJPEG.java
/** {@inheritDoc} */ public boolean isCompatible(RenderingContext targetContext, Image image) { if (!(targetContext instanceof AFPRenderingContext)) { return false; //AFP-specific image handler }/*from w w w .j av a2 s . co m*/ AFPRenderingContext context = (AFPRenderingContext) targetContext; AFPPaintingState paintingState = context.getPaintingState(); if (!paintingState.canEmbedJpeg()) { return false; } if (paintingState.getBitsPerPixel() < 8) { return false; //This would stand in the way of dithering and cause exceptions } if (image == null) { return true; //Don't know the image format, yet } if (image instanceof ImageRawJPEG) { ImageRawJPEG jpeg = (ImageRawJPEG) image; ColorSpace cs = jpeg.getColorSpace(); switch (cs.getType()) { case ColorSpace.TYPE_GRAY: case ColorSpace.TYPE_RGB: //ok break; case ColorSpace.TYPE_CMYK: if (!paintingState.isCMYKImagesSupported()) { return false; //CMYK is disabled //Note: you may need to disable this image handler through configuration //if you want to paint a CMYK JPEG on 24bit and less configurations. } break; default: return false; //not supported } if (jpeg.getSOFType() != JPEGConstants.SOF0) { return false; //We'll let only baseline DCT through. } return true; } return false; }
From source file:org.apache.fop.render.pdf.AbstractImageAdapter.java
/** * Converts a ColorSpace object to a PDFColorSpace object. * @param cs ColorSpace instance// ww w . j a v a2 s. c om * @return PDFColorSpace new converted object */ public static PDFDeviceColorSpace toPDFColorSpace(ColorSpace cs) { if (cs == null) { return null; } PDFDeviceColorSpace pdfCS = new PDFDeviceColorSpace(0); switch (cs.getType()) { case ColorSpace.TYPE_CMYK: pdfCS.setColorSpace(PDFDeviceColorSpace.DEVICE_CMYK); break; case ColorSpace.TYPE_GRAY: pdfCS.setColorSpace(PDFDeviceColorSpace.DEVICE_GRAY); break; default: pdfCS.setColorSpace(PDFDeviceColorSpace.DEVICE_RGB); } return pdfCS; }
From source file:org.apache.fop.util.ColorUtil.java
/** * Creates a re-parsable string representation of the given color. * <p>// www . j av a 2 s .co m * First, the color will be converted into the sRGB colorspace. It will then * be printed as #rrggbb, or as #rrrggbbaa if an alpha value is present. * * @param color * the color to represent. * @return a re-parsable string representadion. */ public static String colorToString(Color color) { ColorSpace cs = color.getColorSpace(); if (color instanceof ColorWithAlternatives) { return toFunctionCall((ColorWithAlternatives) color); } else if (cs != null && cs.getType() == ColorSpace.TYPE_CMYK) { StringBuffer sbuf = new StringBuffer(24); float[] cmyk = color.getColorComponents(null); sbuf.append("cmyk(").append(cmyk[0]).append(",").append(cmyk[1]).append(",").append(cmyk[2]).append(",") .append(cmyk[3]).append(")"); return sbuf.toString(); } else { return toRGBFunctionCall(color); } }