Example usage for java.awt.color ColorSpace getType

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

Introduction

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

Prototype

public int getType() 

Source Link

Document

Returns the color space type of this ColorSpace (for example TYPE_RGB , TYPE_XYZ , ...).

Usage

From source file:fi.nls.oskari.printout.printing.PDPageContentStream.java

/**
 * Set the stroking color, specified as RGB.
 * /*from w  ww  .  jav 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 2  s . 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:lucee.runtime.img.Image.java

private String toStringColorSpace(ColorSpace colorSpace) {
    switch (colorSpace.getType()) {
    case 0:/* ww w  .  j  a  v a2s .  c om*/
        return "Any of the family of XYZ color spaces";
    case 1:
        return "Any of the family of Lab color spaces";
    case 2:
        return "Any of the family of Luv color spaces";
    case 3:
        return "Any of the family of YCbCr color spaces";
    case 4:
        return "Any of the family of Yxy color spaces";
    case 5:
        return "Any of the family of RGB color spaces";
    case 6:
        return "Any of the family of GRAY color spaces";
    case 7:
        return "Any of the family of HSV color spaces";
    case 8:
        return "Any of the family of HLS color spaces";
    case 9:
        return "Any of the family of CMYK color spaces";
    case 11:
        return "Any of the family of CMY color spaces";
    case 12:
        return "Generic 2 component color space.";
    case 13:
        return "Generic 3 component color space.";
    case 14:
        return "Generic 4 component color space.";
    case 15:
        return "Generic 5 component color space.";
    case 16:
        return "Generic 6 component color space.";
    case 17:
        return "Generic 7 component color space.";
    case 18:
        return "Generic 8 component color space.";
    case 19:
        return "Generic 9 component color space.";
    case 20:
        return "Generic 10 component color space.";
    case 21:
        return "Generic 11 component color space.";
    case 22:
        return "Generic 12 component color space.";
    case 23:
        return "Generic 13 component color space.";
    case 24:
        return "Generic 14 component color space.";
    case 25:
        return "Generic 15 component color space.";
    case 1001:
        return "CIEXYZ";
    case 1003:
        return "GRAY";
    case 1004:
        return "LINEAR_RGB";
    case 1002:
        return "PYCC";
    case 1000:
        return "sRGB";
    }

    return "Unknown ColorSpace" + colorSpace;
}

From source file:org.apache.fop.afp.goca.GraphicsSetProcessColor.java

/**
 * Main constructor/*from  w  w  w  .  ja  va2 s .  com*/
 *
 * @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/*w ww .java 2  s.c om*/
    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.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   www.  j  ava2 s  . com
    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
    }//w  w  w  .ja v  a  2 s  .c o  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//  w  w  w .  ja  v a2s  .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>/*w  w  w.ja va  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);
    }
}

From source file:org.apache.pdfbox.pdmodel.edit.PDPageContentStream.java

/**
 * Set the stroking color, specified as RGB.
 *
 * @param color The color to set.//w w  w  .j a va  2 s.c o m
 * @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[2], colorComponents[2], colorComponents[3]);
    } else {
        throw new IOException("Error: unknown colorspace:" + colorSpace);
    }
}