Package java.awt.image

Examples of java.awt.image.ColorConvertOp$ICC_TransfomCreator


  {
    harness.checkPoint("createCompatibleDestImage");

    // Simple test
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorConvertOp op = new ColorConvertOp(cs, null);
   
    BufferedImage img = new BufferedImage(25, 40, BufferedImage.TYPE_INT_RGB);
    BufferedImage dest = op.createCompatibleDestImage(img, img.getColorModel());
   
    harness.check(dest.getHeight(), 40);
    harness.check(dest.getWidth(), 25);
    harness.check(dest.getColorModel(), img.getColorModel());
    harness.check(dest.getSampleModel().getTransferType(),
                  img.getColorModel().getTransferType());
   
    // Try a different colour model
    img = new BufferedImage(25, 40, BufferedImage.TYPE_BYTE_GRAY);
    DirectColorModel cm = new DirectColorModel(32, 0x00ff0000, 0x0000ff00, 0x000000ff);
    dest = op.createCompatibleDestImage(img, cm);
   
    harness.check(dest.getHeight(), 40);
    harness.check(dest.getWidth(), 25);
    harness.check(dest.getColorModel(), cm);
    harness.check(dest.getSampleModel().getTransferType(), cm.getTransferType());

    op = new ColorConvertOp(null);
    dest = op.createCompatibleDestImage(img, img.getColorModel());
    harness.check(dest.getHeight(), 40);
    harness.check(dest.getWidth(), 25);
    harness.check(dest.getColorModel(), img.getColorModel());
    harness.check(dest.getSampleModel().getTransferType(),
                  img.getColorModel().getTransferType());

    // ColorConvertOp's ColorModel can be null, or createCompatibleDestImage's
    // ColorModel can be null, but not both
    try
    {
      dest = op.createCompatibleDestImage(img, null);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
View Full Code Here


 
  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);
       
View Full Code Here

  }
 
 
  private void profileTest(TestHarness harness, ICC_Profile[] profile)
  {
    ColorConvertOp op = new ColorConvertOp(profile, 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];
        harness.checkPoint("profile " + profile[profile.length-1].getClass() + ", type: " + type);
       
        BufferedImage img = new BufferedImage(25, 40, type);
        BufferedImage dest = op.createCompatibleDestImage(img, null);
        dest = op.createCompatibleDestImage(img, null);
       
        harness.check(dest.getColorModel() instanceof ComponentColorModel);
        harness.check(dest.getSampleModel() instanceof PixelInterleavedSampleModel);
        harness.check(dest.getColorModel().isCompatibleSampleModel(dest.getSampleModel()));
        harness.check(dest.getColorModel().getTransferType(), DataBuffer.TYPE_BYTE);
View Full Code Here

    ColorSpace dstCs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
    RenderingHints hints = new RenderingHints(RenderingHints.KEY_DITHERING,
                                              RenderingHints.VALUE_DITHER_ENABLE);
    hints.put(RenderingHints.KEY_COLOR_RENDERING,
              RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    ColorConvertOp op = new ColorConvertOp(srcCs, dstCs, hints);
   
    harness.check(op.getICC_Profiles(), null);
    harness.check(op.getRenderingHints(), hints);

   
    // Null arguments
    op = new ColorConvertOp(srcCs, dstCs, null);
   
    harness.check(op.getICC_Profiles(), null);
    harness.check(op.getRenderingHints(), null);

    try
    {
      op = new ColorConvertOp(null, dstCs, null);
      harness.check(false);
    }
    catch (NullPointerException e)
    {
      harness.check(true);
    }
   
    try
    {
      op = new ColorConvertOp(srcCs, null, null);
      harness.check(false);
    }
    catch (NullPointerException e)
    {
      harness.check(true);
    }
   
    try
    {
      op = new ColorConvertOp(null, null, null);
      harness.check(false);
    }
    catch (NullPointerException e)
    {
      harness.check(true);
View Full Code Here

    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    RenderingHints hints = new RenderingHints(RenderingHints.KEY_DITHERING,
                                              RenderingHints.VALUE_DITHER_ENABLE);
    hints.put(RenderingHints.KEY_COLOR_RENDERING,
              RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    ColorConvertOp op = new ColorConvertOp(cs, hints);
   
    harness.check(op.getICC_Profiles(), null);
    harness.check(op.getRenderingHints(), hints);
   
    // Null arguments
    op = new ColorConvertOp(cs, null);
   
    harness.check(op.getICC_Profiles(), null);
    harness.check(op.getRenderingHints(), null);

    try
    {
      op = new ColorConvertOp((ColorSpace)null, (RenderingHints)null);
      harness.check(false);
    }
    catch (NullPointerException e)
    {
      harness.check(true);
View Full Code Here

   
    RenderingHints hints = new RenderingHints(RenderingHints.KEY_DITHERING,
                                              RenderingHints.VALUE_DITHER_ENABLE);
    hints.put(RenderingHints.KEY_COLOR_RENDERING,
              RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    ColorConvertOp op = new ColorConvertOp(profile, hints);
   
    // Work around lack of ICC_Profile.equals()
    harness.check(Arrays.equals(op.getICC_Profiles(), profile));
    harness.check(op.getRenderingHints(), hints);

    // Empty or too few profiles are not caught until filter(), so they are
    // allowed here
    try
    {
      op = new ColorConvertOp(new ICC_Profile[0], null);
      harness.check(Arrays.equals(op.getICC_Profiles(), new ICC_Profile[0]));
    }
    catch (IllegalArgumentException e)
    {
      harness.check(false);
    }
   
    try
    {
      profile = new ICC_Profile[]{ICC_Profile.getInstance(ColorSpace.CS_LINEAR_RGB)};
      op = new ColorConvertOp(profile, null);
      harness.check(Arrays.equals(op.getICC_Profiles(), profile));
    }
    catch (IllegalArgumentException e)
    {
      harness.check(false);
    }
   
    // Null arguments
    op = new ColorConvertOp(profile, null);
   
    // Work around lack of ICC_Profile.equals()
    harness.check(Arrays.equals(op.getICC_Profiles(), profile));
    harness.check(op.getRenderingHints(), null);

    try
    {
      op = new ColorConvertOp((ICC_Profile[])null, null);
      harness.check(false);
    }
    catch (NullPointerException e)
    {
      harness.check(true);
View Full Code Here

    // Simple test
    RenderingHints hints = new RenderingHints(RenderingHints.KEY_DITHERING,
                                              RenderingHints.VALUE_DITHER_ENABLE);
    hints.put(RenderingHints.KEY_COLOR_RENDERING,
              RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    ColorConvertOp op = new ColorConvertOp(hints);
   
    harness.check(op.getICC_Profiles(), null);
    harness.check(op.getRenderingHints(), hints);
   
    // Null arguments
    op = new ColorConvertOp(null);
   
    harness.check(op.getICC_Profiles(), null);
    harness.check(op.getRenderingHints(), null);
  }
View Full Code Here

    Graphics2D g = (Graphics2D)img.getGraphics();
    g.draw(new Line2D.Double(0, 0, 20, 20));
   
    ColorSpace cs1 = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorSpace cs2 = ColorSpace.getInstance(ColorSpace.CS_GRAY);
    ColorConvertOp op = new ColorConvertOp(cs1, cs2, null);
    WritableRaster raster = img.getRaster();
   
    // Src and dst rasters cannot be the same (different from
    // filter(BufferedImage, BufferedImage) )
    try
    {
      op.filter(raster, raster);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    // Src and dst are different sizes (not allowed, unlike some other Ops)
    BufferedImage dst = new BufferedImage(30, 40, BufferedImage.TYPE_BYTE_GRAY);
    WritableRaster raster2 = dst.getRaster();
    try
    {
      op.filter(raster, raster2);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    // Null destination
    WritableRaster dstRaster = op.filter(raster, null);
    harness.check(dstRaster.getTransferType(), op.createCompatibleDestRaster(raster).getTransferType());
    harness.check(dstRaster.getNumBands(), op.createCompatibleDestRaster(raster).getNumBands());
    harness.check(dstRaster.getNumDataElements(), op.createCompatibleDestRaster(raster).getNumDataElements());

    // Incompatible constructor (ie, not enough information)
    op = new ColorConvertOp(null);
    try
    {
      op.filter(raster, null);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    op = new ColorConvertOp(cs1, null);
    try
    {
      op.filter(raster, null);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    // Destination raster incompatible with defined conversion;
    // ie, with this conversion, cs2 is TYPE_GRAY thus a dest raster of
    // TYPE_RGB will have the wrong number of data elements
    op = new ColorConvertOp(cs1, cs2, null);
    dstRaster = new BufferedImage(20, 20, BufferedImage.TYPE_INT_ARGB).getRaster();
   
    try
    {
      op.filter(raster, dstRaster);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    // Also true if source raster is incompatible
    raster = new BufferedImage(20, 20, BufferedImage.TYPE_BYTE_GRAY).getRaster();
    try
    {
      op.filter(raster, raster2);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
View Full Code Here

  }
 
  private void simpleTest(TestHarness harness)
  {
    // This method can never be used with these constructors
    ColorConvertOp op = new ColorConvertOp(null);
    Raster src = Raster.createBandedRaster(DataBuffer.TYPE_BYTE, 10, 10,
                                           3, new Point(5, 5));
    try
    {
      op.createCompatibleDestRaster(src);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    op = new ColorConvertOp(cs, null);
    try
    {
      op.createCompatibleDestRaster(src);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
View Full Code Here

  {
    harness.checkPoint("two colorspaces defined, " + cspace1     + ", " + cspace2);

    ColorSpace cs = ColorSpace.getInstance(cspace1);
    ColorSpace cs2 = ColorSpace.getInstance(cspace2);
    ColorConvertOp op = new ColorConvertOp(cs, cs2, null);
    int bands = cs2.getNumComponents();

    Raster src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, bands, new Point(5, 5));

    try
    {
      Raster dst = op.createCompatibleDestRaster(src);
      harness.check(dst.getHeight(), src.getHeight());
      harness.check(dst.getWidth(), src.getWidth());
      harness.check(dst.getNumBands(), bands);
      harness.check(dst.getTransferType(), DataBuffer.TYPE_BYTE);
      harness.check(dst.getDataBuffer().getDataType(), DataBuffer.TYPE_BYTE);
      harness.check(dst.getNumDataElements(), cs2.getNumComponents());
      harness.check(dst.getSampleModel() instanceof PixelInterleavedSampleModel);
      harness.check(dst.getDataBuffer() instanceof DataBufferByte);
     
      PixelInterleavedSampleModel sm = (PixelInterleavedSampleModel)dst.getSampleModel();

      harness.check(sm.getPixelStride(), cs2.getNumComponents());
      harness.check(sm.getScanlineStride(), cs2.getNumComponents() * src.getWidth());
      int[] expected = new int[cs2.getNumComponents()];
     
      for (int i = 0; i < expected.length; i++)
        expected[i] = i;
      harness.check(Arrays.equals(sm.getBandOffsets(), expected));
     
      harness.check(dst.getDataBuffer().getNumBanks(), 1);
      harness.check(dst.getDataBuffer().getOffset(), 0);
      harness.check(dst.getDataBuffer().getSize(), src.getHeight() * src.getWidth() * cs2.getNumComponents());
     
    }
    catch (IllegalArgumentException e)
    {
      harness.check(false);
    }
   
    // Try a different type
    src = Raster.createBandedRaster(DataBuffer.TYPE_USHORT, 25, 40, bands, new Point(5, 5));
    try
    {
      Raster dst = op.createCompatibleDestRaster(src);
      harness.check(dst.getNumBands(), bands);
      harness.check(dst.getTransferType(), DataBuffer.TYPE_BYTE);
      harness.check(dst.getDataBuffer().getDataType(), DataBuffer.TYPE_BYTE);
      harness.check(dst.getNumDataElements(), cs2.getNumComponents());
      harness.check(dst.getSampleModel() instanceof PixelInterleavedSampleModel);
      harness.check(dst.getDataBuffer() instanceof DataBufferByte);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(false);
    }
   
    // Try different number of bands in the source; the destination should
    // ignore this and always have ColorSpace.getNumComponents() bands
    for (int i = 1; i < bands + 5; i++)
      {
        src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, i, new Point(5, 5));
        try
        {
          Raster dst = op.createCompatibleDestRaster(src);
          harness.check(dst.getNumBands(), cs2.getNumComponents());
          harness.check(dst.getNumDataElements(), cs2.getNumComponents());
        }
        catch (IllegalArgumentException e)
        {
View Full Code Here

TOP

Related Classes of java.awt.image.ColorConvertOp$ICC_TransfomCreator

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.