Package java.awt.color

Examples of java.awt.color.ColorSpace


    colorModelTest(harness, -1, cspace);
  }
 
  private void colorModelTest(TestHarness harness, int cspace, int cspace2)
  {
    ColorSpace cs;
    ColorSpace cs2;
    ColorConvertOp op;
   
    if (cspace == -1)
      {
        cs2 = ColorSpace.getInstance(cspace2);
        op = new ColorConvertOp(cs2, null);
      }
    else
      {
        cs = ColorSpace.getInstance(cspace);
        cs2 = ColorSpace.getInstance(cspace2);
        op = new ColorConvertOp(cs, cs2, null);
      }

    int[] types = {BufferedImage.TYPE_INT_RGB,
                   BufferedImage.TYPE_INT_ARGB,
                   BufferedImage.TYPE_INT_ARGB_PRE,
                   BufferedImage.TYPE_3BYTE_BGR,
                   BufferedImage.TYPE_4BYTE_ABGR,
                   BufferedImage.TYPE_4BYTE_ABGR_PRE,
                   BufferedImage.TYPE_USHORT_565_RGB,
                   BufferedImage.TYPE_USHORT_555_RGB,
                   BufferedImage.TYPE_BYTE_GRAY,
                   BufferedImage.TYPE_USHORT_GRAY};
    // Skipped types that are not implemented yet:
    // TYPE_CUSTOM, TYPE_INT_BGR, TYPE_BYTE_BINARY, TYPE_BYTE_INDEXED

    for (int i = 0; i < types.length; i++)
      {
        int type = types[i];
        if (cspace == -1)
          harness.checkPoint("colorspace " + cspace2  + ", type: " + type);
        else
          harness.checkPoint("src colorspace " + cspace + ", dest colorspace " + cspace2 + ", type: " + type);
       
        BufferedImage img = new BufferedImage(25, 40, type);
        BufferedImage dest = op.createCompatibleDestImage(img, null);
        dest = op.createCompatibleDestImage(img, null);
       
        // Standard check of common properties
        harness.check(dest.isAlphaPremultiplied(), img.isAlphaPremultiplied());
        harness.check(dest.getSampleModel() instanceof PixelInterleavedSampleModel);
       
        harness.check(dest.getColorModel() instanceof ComponentColorModel);
        harness.check(dest.getColorModel().isCompatibleSampleModel(dest.getSampleModel()));
        harness.check(dest.getColorModel().getTransferType(), DataBuffer.TYPE_BYTE);
        harness.check(dest.getColorModel().getColorSpace().getType(), cs2.getType());
       
        harness.check(dest.getColorModel().hasAlpha(), img.getColorModel().hasAlpha());
        harness.check(dest.getColorModel().getTransparency(), img.getColorModel().getTransparency());

        harness.check(dest.getColorModel().getPixelSize(),
                      DataBuffer.getDataTypeSize(DataBuffer.TYPE_BYTE)
                      * dest.getRaster().getNumDataElements());

        harness.check(dest.getRaster().getNumDataElements(),
                      dest.getColorModel().getNumComponents());
        harness.check(dest.getRaster().getNumBands(),
                      dest.getRaster().getNumDataElements());
       
        harness.check(dest.getSampleModel().getTransferType(),
                      DataBuffer.TYPE_BYTE);
       
        // This ensures that we have the same defaults as the reference implementation
        switch (type)
        {
          // Images with an extra alpha component
          case BufferedImage.TYPE_INT_ARGB:
          case BufferedImage.TYPE_INT_ARGB_PRE:
          case BufferedImage.TYPE_4BYTE_ABGR:
          case BufferedImage.TYPE_4BYTE_ABGR_PRE:
            if (cspace2 == ColorSpace.CS_GRAY)
              {
                harness.check(dest.getColorModel().getNumComponents(), 2);
              }
            else
              {
                harness.check(dest.getColorModel().getNumComponents(), 4);
              }
           
            harness.check(dest.getColorModel().getNumColorComponents(),
                          dest.getColorModel().getNumComponents() - 1);
           
            harness.check(dest.getColorModel().getTransparency(), ColorModel.TRANSLUCENT);
            harness.check(dest.getColorModel().hasAlpha(), true);
            harness.check(dest.getColorModel().isAlphaPremultiplied(),
                          (type == BufferedImage.TYPE_INT_ARGB_PRE
                              || type == BufferedImage.TYPE_4BYTE_ABGR_PRE));
           
            harness.check(dest.getType(), BufferedImage.TYPE_CUSTOM);
            break;
           
          case BufferedImage.TYPE_INT_RGB:
          case BufferedImage.TYPE_3BYTE_BGR:
          case BufferedImage.TYPE_USHORT_565_RGB:
          case BufferedImage.TYPE_USHORT_555_RGB:
          case BufferedImage.TYPE_BYTE_GRAY:
          case BufferedImage.TYPE_USHORT_GRAY:
            if (cs2.getType() == ColorSpace.TYPE_GRAY)
              {
                // This fails, but due to a limitation in BufferedImage.
                // Somehow, Sun is able to modify a BufferedImage after creating
                // it based on a pre-defined type, without it being considered
                // a custom type...
View Full Code Here


     * @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
View Full Code Here

     * @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
View Full Code Here

        this.shading = shading;
        deviceBounds = dBounds;
        shadingColorSpace = shading.getColorSpace();

        // create the output color model using RGB+alpha as color space
        ColorSpace outputCS = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        outputColorModel = new ComponentColorModel(outputCS, true, false, Transparency.TRANSLUCENT,
                DataBuffer.TYPE_BYTE);

        bboxRect = shading.getBBox();
        if (bboxRect != null)
View Full Code Here

            int dstInXShift = dstIn.getMinX() - x0;
            int dstInYShift = dstIn.getMinY() - y0;
            int dstOutXShift = dstOut.getMinX() - x0;
            int dstOutYShift = dstOut.getMinY() - y0;

            ColorSpace srcColorSpace = srcColorModel.getColorSpace();
            int numSrcColorComponents = srcColorModel.getNumColorComponents();
            int numSrcComponents = src.getNumBands();
            boolean srcHasAlpha = (numSrcComponents > numSrcColorComponents);
            ColorSpace dstColorSpace = dstColorModel.getColorSpace();
            int numDstColorComponents = dstColorModel.getNumColorComponents();
            int numDstComponents = dstIn.getNumBands();
            boolean dstHasAlpha = (numDstComponents > numDstColorComponents);

            int colorSpaceType = dstColorSpace.getType();
            boolean subtractive = (colorSpaceType != ColorSpace.TYPE_RGB)
                    && (colorSpaceType != ColorSpace.TYPE_GRAY);

            boolean blendModeIsSeparable = blendMode instanceof SeparableBlendMode;
            SeparableBlendMode separableBlendMode = blendModeIsSeparable ?
                    (SeparableBlendMode) blendMode : null;

            boolean needsColorConversion = !srcColorSpace.equals(dstColorSpace);

            Object srcPixel = null;
            Object dstPixel = null;
            float[] srcComponents = new float[numSrcComponents];
            float[] dstComponents = new float[numDstComponents];

            float[] srcColor = new float[numSrcColorComponents];
            float[] srcConverted;

            for (int y = y0; y < y1; y++)
            {
                for (int x = x0; x < x1; x++)
                {
                    srcPixel = src.getDataElements(x, y, srcPixel);
                    dstPixel = dstIn.getDataElements(dstInXShift + x, dstInYShift + y, dstPixel);

                    srcComponents = srcColorModel.getNormalizedComponents(srcPixel, srcComponents,
                            0);
                    dstComponents = dstColorModel.getNormalizedComponents(dstPixel, dstComponents,
                            0);

                    float srcAlpha = srcHasAlpha ? srcComponents[numSrcColorComponents] : 1.0f;
                    float dstAlpha = dstHasAlpha ? dstComponents[numDstColorComponents] : 1.0f;

                    srcAlpha = srcAlpha * constantAlpha;

                    float resultAlpha = dstAlpha + srcAlpha - srcAlpha * dstAlpha;
                    float srcAlphaRatio = (resultAlpha > 0) ? srcAlpha / resultAlpha : 0;

                    // convert color
                    System.arraycopy(srcComponents, 0, srcColor, 0, numSrcColorComponents);
                    if (needsColorConversion)
                    {
                        // TODO - very very slow - Hash results???
                        float[] cieXYZ = srcColorSpace.toCIEXYZ(srcColor);
                        srcConverted = dstColorSpace.fromCIEXYZ(cieXYZ);
                    }
                    else
                    {
                        srcConverted = srcColor;
                    }
View Full Code Here

    // gets image in parent stream coordinates
    private static BufferedImage getImage(PageDrawer drawer, PDTilingPattern pattern,
                                          PDColorSpace colorSpace, PDColor color,
                                          AffineTransform xform) throws IOException
    {
        ColorSpace outputCS = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        ColorModel cm = new ComponentColorModel(outputCS, true, false,
                Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);

        Rectangle2D anchor = getAnchorRect(pattern);
        float width = (float)Math.abs(anchor.getWidth());
View Full Code Here

public class TestPDPageContentStream extends TestCase {

    public void testSetCmykColors() throws IOException, COSVisitorException {
        PDDocument doc = new PDDocument();

        ColorSpace colorSpace = new ColorSpaceCMYK();

        PDPage page = new PDPage();
        doc.addPage(page);

        PDPageContentStream contentStream = new PDPageContentStream(doc, page, false, true);
View Full Code Here

        if (cs instanceof PDICCBased)
        {
            PDICCBased iccBased = (PDICCBased) cs;
            try
            {
                ColorSpace iccColorSpace = iccBased.getJavaColorSpace();
                switch (expectedType)
                {
                case RGB:
                    result = (iccColorSpace.getType() == ICC_ColorSpace.TYPE_RGB);
                    break;
                case CMYK:
                    result = (iccColorSpace.getType() == ICC_ColorSpace.TYPE_CMYK);
                    break;
                default:
                    result = true;
                    break;
                }
View Full Code Here

     * @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
View Full Code Here

     * @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
View Full Code Here

TOP

Related Classes of java.awt.color.ColorSpace

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.