java.awt.image.ColorConvertOp Java Examples

The following examples show how to use java.awt.image.ColorConvertOp. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ColConvCCMTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static boolean testImage(int dataType, int rBits, int gBits, int bBits,
                          int cs, BufferedImage gldImage,
                          double accuracy)
 {
    BufferedImage src = ImageFactory.createCCMImage(cs, dataType);
    BufferedImage dst = ImageFactory.createDstImage(
        BufferedImage.TYPE_INT_RGB);
    ColorConvertOp op = new ColorConvertOp(null);
    op.filter(src, dst);

    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                              bBits);
    boolean result = cmp.compare(gldImage, dst);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}
 
Example #2
Source File: ColConvCCMTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
static boolean testImage(int dataType, int rBits, int gBits, int bBits,
                          int cs, BufferedImage gldImage,
                          double accuracy)
 {
    BufferedImage src = ImageFactory.createCCMImage(cs, dataType);
    BufferedImage dst = ImageFactory.createDstImage(
        BufferedImage.TYPE_INT_RGB);
    ColorConvertOp op = new ColorConvertOp(null);
    op.filter(src, dst);

    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                              bBits);
    boolean result = cmp.compare(gldImage, dst);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}
 
Example #3
Source File: ColConvDCMTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static boolean testImage(int type, int rBits, int gBits, int bBits,
                          int cs, BufferedImage gldImage,
                          double accuracy)
{
    BufferedImage src = ImageFactory.createDCMImage(type, cs);
    BufferedImage dst = ImageFactory.createDstImage(
        BufferedImage.TYPE_INT_RGB);
    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(src, dst);

    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                              bBits);
    boolean result = cmp.compare(gldImage, dst);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}
 
Example #4
Source File: ColConvCCMTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static boolean testSubImage(int x0, int y0, int dx, int dy,
                             int dataType, int rBits, int gBits,
                             int bBits, int cs, BufferedImage gldImage,
                             double accuracy)
 {
    BufferedImage src = ImageFactory.createCCMImage(cs, dataType);
    BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy);
    BufferedImage dst = ImageFactory.createDstImage(
        BufferedImage.TYPE_INT_RGB);
    BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy);
    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(subSrc, subDst);
    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                              bBits);
    boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}
 
Example #5
Source File: ColConvDCMTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
static boolean testSubImage(int x0, int y0, int dx, int dy, int type,
                            int rBits, int gBits, int bBits,
                            int cs, BufferedImage gldImage,
                            double accuracy)
{
   BufferedImage src = ImageFactory.createDCMImage(type, cs);
   BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy);
   BufferedImage dst = ImageFactory.createDstImage(
       BufferedImage.TYPE_INT_RGB);
   BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy);

   ColorConvertOp op = new ColorConvertOp(null);

   op.filter(subSrc, subDst);

   ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                             bBits);
   boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy);
   if (!result) {
       System.err.println(cmp.getStat());
   }
   return result;
}
 
Example #6
Source File: InvalidRenderIntentTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    ICC_Profile pSRGB = ICC_Profile.getInstance(CS_sRGB);

    byte[] raw_data = pSRGB.getData();

    setRenderingIntent(0x1000000, raw_data);

    ICC_Profile p = ICC_Profile.getInstance(raw_data);

    ICC_ColorSpace cs = new ICC_ColorSpace(p);

    // perfrom test color conversion
    ColorConvertOp op = new ColorConvertOp(cs,
            ColorSpace.getInstance(CS_sRGB), null);
    BufferedImage src = new BufferedImage(1, 1, TYPE_3BYTE_BGR);
    BufferedImage dst = new BufferedImage(1, 1, TYPE_3BYTE_BGR);

    try {
        op.filter(src.getRaster(), dst.getRaster());
    } catch (CMMException e) {
        throw new RuntimeException("Test failed.", e);
    }
    System.out.println("Test passed.");
}
 
Example #7
Source File: InvalidRenderIntentTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    ICC_Profile pSRGB = ICC_Profile.getInstance(CS_sRGB);

    byte[] raw_data = pSRGB.getData();

    setRenderingIntent(0x1000000, raw_data);

    ICC_Profile p = ICC_Profile.getInstance(raw_data);

    ICC_ColorSpace cs = new ICC_ColorSpace(p);

    // perfrom test color conversion
    ColorConvertOp op = new ColorConvertOp(cs,
            ColorSpace.getInstance(CS_sRGB), null);
    BufferedImage src = new BufferedImage(1, 1, TYPE_3BYTE_BGR);
    BufferedImage dst = new BufferedImage(1, 1, TYPE_3BYTE_BGR);

    try {
        op.filter(src.getRaster(), dst.getRaster());
    } catch (CMMException e) {
        throw new RuntimeException("Test failed.", e);
    }
    System.out.println("Test passed.");
}
 
Example #8
Source File: PDColorSpace.java    From sambox with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the (A)RGB equivalent of the given raster, using the given AWT color space to perform the conversion.
 * 
 * @param raster the source raster
 * @param colorSpace the AWT
 * @return an (A)RGB buffered image
 */
protected BufferedImage toRGBImageAWT(WritableRaster raster, ColorSpace colorSpace)
{
    //
    // WARNING: this method is performance sensitive, modify with care!
    //

    // ICC Profile color transforms are only fast when performed using ColorConvertOp
    ColorModel colorModel = new ComponentColorModel(colorSpace, false, false,
            Transparency.OPAQUE, raster.getDataBuffer().getDataType());

    BufferedImage src = new BufferedImage(colorModel, raster, false, null);
    BufferedImage dest = new BufferedImage(raster.getWidth(), raster.getHeight(),
            BufferedImage.TYPE_INT_RGB);
    ColorConvertOp op = new ColorConvertOp(null);
    op.filter(src, dest);
    return dest;
}
 
Example #9
Source File: ColConvCCMTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
static boolean testSubImage(int x0, int y0, int dx, int dy,
                             int dataType, int rBits, int gBits,
                             int bBits, int cs, BufferedImage gldImage,
                             double accuracy)
 {
    BufferedImage src = ImageFactory.createCCMImage(cs, dataType);
    BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy);
    BufferedImage dst = ImageFactory.createDstImage(
        BufferedImage.TYPE_INT_RGB);
    BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy);
    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(subSrc, subDst);
    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                              bBits);
    boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}
 
Example #10
Source File: ColConvDCMTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static boolean testImage(int type, int rBits, int gBits, int bBits,
                          int cs, BufferedImage gldImage,
                          double accuracy)
{
    BufferedImage src = ImageFactory.createDCMImage(type, cs);
    BufferedImage dst = ImageFactory.createDstImage(
        BufferedImage.TYPE_INT_RGB);
    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(src, dst);

    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                              bBits);
    boolean result = cmp.compare(gldImage, dst);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}
 
Example #11
Source File: ColConvDCMTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static boolean testSubImage(int x0, int y0, int dx, int dy, int type,
                            int rBits, int gBits, int bBits,
                            int cs, BufferedImage gldImage,
                            double accuracy)
{
   BufferedImage src = ImageFactory.createDCMImage(type, cs);
   BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy);
   BufferedImage dst = ImageFactory.createDstImage(
       BufferedImage.TYPE_INT_RGB);
   BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy);

   ColorConvertOp op = new ColorConvertOp(null);

   op.filter(subSrc, subDst);

   ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                             bBits);
   boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy);
   if (!result) {
       System.err.println(cmp.getStat());
   }
   return result;
}
 
Example #12
Source File: ColConvCCMTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
static boolean testSubImage(int x0, int y0, int dx, int dy,
                             int dataType, int rBits, int gBits,
                             int bBits, int cs, BufferedImage gldImage,
                             double accuracy)
 {
    BufferedImage src = ImageFactory.createCCMImage(cs, dataType);
    BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy);
    BufferedImage dst = ImageFactory.createDstImage(
        BufferedImage.TYPE_INT_RGB);
    BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy);
    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(subSrc, subDst);
    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                              bBits);
    boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}
 
Example #13
Source File: ColConvCCMTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static boolean testSubImage(int x0, int y0, int dx, int dy,
                             int dataType, int rBits, int gBits,
                             int bBits, int cs, BufferedImage gldImage,
                             double accuracy)
 {
    BufferedImage src = ImageFactory.createCCMImage(cs, dataType);
    BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy);
    BufferedImage dst = ImageFactory.createDstImage(
        BufferedImage.TYPE_INT_RGB);
    BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy);
    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(subSrc, subDst);
    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                              bBits);
    boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}
 
Example #14
Source File: PDColorSpace.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Returns the (A)RGB equivalent of the given raster, using the given AWT color space
 * to perform the conversion.
 * @param raster the source raster
 * @param colorSpace the AWT
 * @return an (A)RGB buffered image
 */
protected BufferedImage toRGBImageAWT(WritableRaster raster, ColorSpace colorSpace)
{
    //
    // WARNING: this method is performance sensitive, modify with care!
    //

    // ICC Profile color transforms are only fast when performed using ColorConvertOp
    ColorModel colorModel = new ComponentColorModel(colorSpace,
        false, false, Transparency.OPAQUE, raster.getDataBuffer().getDataType());

    BufferedImage src = new BufferedImage(colorModel, raster, false, null);
    BufferedImage dest = new BufferedImage(raster.getWidth(), raster.getHeight(),
                                           BufferedImage.TYPE_INT_RGB);
    ColorConvertOp op = new ColorConvertOp(null);
    op.filter(src, dest);
    return dest;
}
 
Example #15
Source File: ColConvCCMTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static boolean testImage(int dataType, int rBits, int gBits, int bBits,
                          int cs, BufferedImage gldImage,
                          double accuracy)
 {
    BufferedImage src = ImageFactory.createCCMImage(cs, dataType);
    BufferedImage dst = ImageFactory.createDstImage(
        BufferedImage.TYPE_INT_RGB);
    ColorConvertOp op = new ColorConvertOp(null);
    op.filter(src, dst);

    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                              bBits);
    boolean result = cmp.compare(gldImage, dst);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}
 
Example #16
Source File: ColConvCCMTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
static boolean testSubImage(int x0, int y0, int dx, int dy,
                             int dataType, int rBits, int gBits,
                             int bBits, int cs, BufferedImage gldImage,
                             double accuracy)
 {
    BufferedImage src = ImageFactory.createCCMImage(cs, dataType);
    BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy);
    BufferedImage dst = ImageFactory.createDstImage(
        BufferedImage.TYPE_INT_RGB);
    BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy);
    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(subSrc, subDst);
    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                              bBits);
    boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}
 
Example #17
Source File: JPEGFactory.java    From sambox with Apache License 2.0 6 votes vote down vote up
private static BufferedImage getColorImage(BufferedImage image)
{
    if (!image.getColorModel().hasAlpha())
    {
        return image;
    }

    if (image.getColorModel().getColorSpace().getType() != ColorSpace.TYPE_RGB)
    {
        throw new UnsupportedOperationException("only RGB color spaces are implemented");
    }

    // create an RGB image without alpha
    // BEWARE: the previous solution in the history
    // g.setComposite(AlphaComposite.Src) and g.drawImage()
    // didn't work properly for TYPE_4BYTE_ABGR.
    // alpha values of 0 result in a black dest pixel!!!
    BufferedImage rgbImage = new BufferedImage(image.getWidth(), image.getHeight(),
            BufferedImage.TYPE_3BYTE_BGR);
    return new ColorConvertOp(null).filter(image, rgbImage);
}
 
Example #18
Source File: JSliderOrbit.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Icon getIcon ()
{
    // TODO Use that to get the state (-> highlight or not)
    TransitionAwareUI transitionAwareUI = (TransitionAwareUI) slider.getUI();
    StateTransitionTracker stateTransitionTracker = transitionAwareUI.getTransitionTracker();
    // stateTransitionTracker.getModelStateInfo().getCurrModelState();

    final Icon icon = super.getIcon();
    final BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
    final Graphics iconGraphics = image.createGraphics();
    icon.paintIcon(slider, iconGraphics, 0, 0);
    // Make it brighter (very simple approach)
    final RescaleOp rescaleOp = new RescaleOp(2.0f, 50, null);
    rescaleOp.filter(image, image);

    ColorConvertOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
    op.filter(image, image);

    return new ImageIcon(image);
}
 
Example #19
Source File: ColConvDCMTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static boolean testSubImage(int x0, int y0, int dx, int dy, int type,
                            int rBits, int gBits, int bBits,
                            int cs, BufferedImage gldImage,
                            double accuracy)
{
   BufferedImage src = ImageFactory.createDCMImage(type, cs);
   BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy);
   BufferedImage dst = ImageFactory.createDstImage(
       BufferedImage.TYPE_INT_RGB);
   BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy);

   ColorConvertOp op = new ColorConvertOp(null);

   op.filter(subSrc, subDst);

   ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                             bBits);
   boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy);
   if (!result) {
       System.err.println(cmp.getStat());
   }
   return result;
}
 
Example #20
Source File: ColConvDCMTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static boolean testImage(int type, int rBits, int gBits, int bBits,
                          int cs, BufferedImage gldImage,
                          double accuracy)
{
    BufferedImage src = ImageFactory.createDCMImage(type, cs);
    BufferedImage dst = ImageFactory.createDstImage(
        BufferedImage.TYPE_INT_RGB);
    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(src, dst);

    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                              bBits);
    boolean result = cmp.compare(gldImage, dst);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}
 
Example #21
Source File: InvalidRenderIntentTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    ICC_Profile pSRGB = ICC_Profile.getInstance(CS_sRGB);

    byte[] raw_data = pSRGB.getData();

    setRenderingIntent(0x1000000, raw_data);

    ICC_Profile p = ICC_Profile.getInstance(raw_data);

    ICC_ColorSpace cs = new ICC_ColorSpace(p);

    // perfrom test color conversion
    ColorConvertOp op = new ColorConvertOp(cs,
            ColorSpace.getInstance(CS_sRGB), null);
    BufferedImage src = new BufferedImage(1, 1, TYPE_3BYTE_BGR);
    BufferedImage dst = new BufferedImage(1, 1, TYPE_3BYTE_BGR);

    try {
        op.filter(src.getRaster(), dst.getRaster());
    } catch (CMMException e) {
        throw new RuntimeException("Test failed.", e);
    }
    System.out.println("Test passed.");
}
 
Example #22
Source File: ColConvCCMTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
static boolean testImage(int dataType, int rBits, int gBits, int bBits,
                          int cs, BufferedImage gldImage,
                          double accuracy)
 {
    BufferedImage src = ImageFactory.createCCMImage(cs, dataType);
    BufferedImage dst = ImageFactory.createDstImage(
        BufferedImage.TYPE_INT_RGB);
    ColorConvertOp op = new ColorConvertOp(null);
    op.filter(src, dst);

    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                              bBits);
    boolean result = cmp.compare(gldImage, dst);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}
 
Example #23
Source File: JPEGFactory.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private static BufferedImage getColorImage(BufferedImage image)
{
    if (!image.getColorModel().hasAlpha())
    {
        return image;
    }

    if (image.getColorModel().getColorSpace().getType() != ColorSpace.TYPE_RGB)
    {
        throw new UnsupportedOperationException("only RGB color spaces are implemented");
    }

    // create an RGB image without alpha
    //BEWARE: the previous solution in the history 
    // g.setComposite(AlphaComposite.Src) and g.drawImage()
    // didn't work properly for TYPE_4BYTE_ABGR.
    // alpha values of 0 result in a black dest pixel!!!
    BufferedImage rgbImage = new BufferedImage(
            image.getWidth(),
            image.getHeight(),
            BufferedImage.TYPE_3BYTE_BGR);
    return new ColorConvertOp(null).filter(image, rgbImage);
}
 
Example #24
Source File: ColConvDCMTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static boolean testSubImage(int x0, int y0, int dx, int dy, int type,
                            int rBits, int gBits, int bBits,
                            int cs, BufferedImage gldImage,
                            double accuracy)
{
   BufferedImage src = ImageFactory.createDCMImage(type, cs);
   BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy);
   BufferedImage dst = ImageFactory.createDstImage(
       BufferedImage.TYPE_INT_RGB);
   BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy);

   ColorConvertOp op = new ColorConvertOp(null);

   op.filter(subSrc, subDst);

   ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                             bBits);
   boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy);
   if (!result) {
       System.err.println(cmp.getStat());
   }
   return result;
}
 
Example #25
Source File: ColConvDCMTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static boolean testImage(int type, int rBits, int gBits, int bBits,
                          int cs, BufferedImage gldImage,
                          double accuracy)
{
    BufferedImage src = ImageFactory.createDCMImage(type, cs);
    BufferedImage dst = ImageFactory.createDstImage(
        BufferedImage.TYPE_INT_RGB);
    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(src, dst);

    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                              bBits);
    boolean result = cmp.compare(gldImage, dst);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}
 
Example #26
Source File: ColConvDCMTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static boolean testImage(int type, int rBits, int gBits, int bBits,
                          int cs, BufferedImage gldImage,
                          double accuracy)
{
    BufferedImage src = ImageFactory.createDCMImage(type, cs);
    BufferedImage dst = ImageFactory.createDstImage(
        BufferedImage.TYPE_INT_RGB);
    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(src, dst);

    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                              bBits);
    boolean result = cmp.compare(gldImage, dst);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}
 
Example #27
Source File: InvalidRenderIntentTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    ICC_Profile pSRGB = ICC_Profile.getInstance(CS_sRGB);

    byte[] raw_data = pSRGB.getData();

    setRenderingIntent(0x1000000, raw_data);

    ICC_Profile p = ICC_Profile.getInstance(raw_data);

    ICC_ColorSpace cs = new ICC_ColorSpace(p);

    // perfrom test color conversion
    ColorConvertOp op = new ColorConvertOp(cs,
            ColorSpace.getInstance(CS_sRGB), null);
    BufferedImage src = new BufferedImage(1, 1, TYPE_3BYTE_BGR);
    BufferedImage dst = new BufferedImage(1, 1, TYPE_3BYTE_BGR);

    try {
        op.filter(src.getRaster(), dst.getRaster());
    } catch (CMMException e) {
        throw new RuntimeException("Test failed.", e);
    }
    System.out.println("Test passed.");
}
 
Example #28
Source File: IMGUtils.java    From icafe with Eclipse Public License 1.0 6 votes vote down vote up
public static void RGB2CMYK(ICC_ColorSpace cmykColorSpace, int[] rgb, float[][] C, float[][] M, float[][] Y, float[][] K, int imageWidth, int imageHeight) {
	DataBuffer db = new DataBufferInt(rgb, rgb.length);
	WritableRaster raster = Raster.createPackedRaster(db, imageWidth, imageHeight, imageWidth,  new int[] {0x00ff0000, 0x0000ff00, 0x000000ff}, null);
	ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);

	ColorConvertOp cco = new ColorConvertOp(sRGB, cmykColorSpace, null);
	
	BufferedImage rgbImage = new BufferedImage(new DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff), raster, false, null);
	BufferedImage cmykImage = cco.filter(rgbImage, null);
	WritableRaster cmykRaster = cmykImage.getRaster();
	
	byte[] cmyk = (byte[])cmykRaster.getDataElements(0, 0, imageWidth, imageHeight, null);
	
	for(int i = 0, index = 0; i < imageHeight; i++) {
		for(int j = 0; j < imageWidth; j++) {
			C[i][j] = (cmyk[index++]&0xff) - 128.0f;
			M[i][j] = (cmyk[index++]&0xff) - 128.0f;
			Y[i][j] = (cmyk[index++]&0xff) - 128.0f;
			K[i][j] = (cmyk[index++]&0xff) - 128.0f;
		}
	}
}
 
Example #29
Source File: ColConvCCMTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static boolean testSubImage(int x0, int y0, int dx, int dy,
                             int dataType, int rBits, int gBits,
                             int bBits, int cs, BufferedImage gldImage,
                             double accuracy)
 {
    BufferedImage src = ImageFactory.createCCMImage(cs, dataType);
    BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy);
    BufferedImage dst = ImageFactory.createDstImage(
        BufferedImage.TYPE_INT_RGB);
    BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy);
    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(subSrc, subDst);
    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                              bBits);
    boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}
 
Example #30
Source File: ColConvCCMTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static boolean testImage(int dataType, int rBits, int gBits, int bBits,
                          int cs, BufferedImage gldImage,
                          double accuracy)
 {
    BufferedImage src = ImageFactory.createCCMImage(cs, dataType);
    BufferedImage dst = ImageFactory.createDstImage(
        BufferedImage.TYPE_INT_RGB);
    ColorConvertOp op = new ColorConvertOp(null);
    op.filter(src, dst);

    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                              bBits);
    boolean result = cmp.compare(gldImage, dst);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}