Java Code Examples for java.awt.image.ColorConvertOp

The following are top voted examples for showing how to use java.awt.image.ColorConvertOp. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Pogamut3   File: AgentNode.java   View source code 6 votes vote down vote up
@Override
public Image getIcon(int type) {
    if(agentIcon == null) {
        agentIcon = loadAgentIcon();
    }

    IAgentState agentState = agent.getState().getFlag();

    if (isEndState(agentState)) {
        // return grayscale icon
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
        ColorConvertOp op = new ColorConvertOp(cs, null);

        return op.filter((BufferedImage) agentIcon, null);
    } else {
        // use badge to indicate state of the agent
        Image badge = getBadgeIcon(agentState);

        return ImageUtilities.mergeImages(agentIcon, badge, 4, 4);
    }
}
 
Example 2
Project: freecol   File: ImageResource.java   View source code 6 votes vote down vote up
/**
 * Gets a grayscale version of the image of the given size.
 * 
 * @param d The requested size.
 * @return The {@code BufferedImage}.
 */
public BufferedImage getGrayscaleImage(Dimension d) {
    final BufferedImage cached = grayscaleImages.get(d);
    if (cached != null) return cached;
    final BufferedImage im = getImage(d);
    if (im == null) return null;
    int width = im.getWidth();
    int height = im.getHeight();
    // TODO: Find out why making a copy is necessary here to prevent
    //       images from getting too dark.
    BufferedImage srcImage = new BufferedImage(width, height,
        BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = srcImage.createGraphics();
    g.drawImage(im, 0, 0, null);
    g.dispose();
    ColorConvertOp filter = new ColorConvertOp(
        ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
    final BufferedImage grayscaleImage = filter.filter(srcImage, null);
    grayscaleImages.put(d, grayscaleImage);
    return grayscaleImage;
}
 
Example 3
Project: ServerlessPlatform   File: ImageService.java   View source code 6 votes vote down vote up
public void blackNWhite(String link, String email) throws Exception{
	try{
		download(link);
		doLogging("Request came for blackNWhite ", "INFO");
		String outPath=null;
		String fileName=null;
		String imageName = null;
		int lastSlashIndex = link.lastIndexOf('/');
		imageName = link.substring(lastSlashIndex + 1);
		String path = Path+imageName;
		BufferedImage src = ImageIO.read(new File(path));
		ColorConvertOp op =new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
		BufferedImage dest = op.filter(src, null);
		fileName = path.substring(path.lastIndexOf("/")+1);
		path = path.substring(0, path.lastIndexOf("/")+1);
		outPath=path+"BNW_"+fileName;
		ImageIO.write(dest, "jpg", new File(outPath));
		sendMail(outPath, email);
	}
	catch(Exception e){
		doLogging("Failed somewhere "+e.getMessage()+e.getStackTrace(), "Error");
	}
	
}
 
Example 4
Project: jdk8u-jdk   File: ColConvCCMTest.java   View source code 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 5
Project: jdk8u-jdk   File: ColConvCCMTest.java   View source code 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 6
Project: jdk8u-jdk   File: InvalidRenderIntentTest.java   View source code 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
Project: jdk8u-jdk   File: ColConvDCMTest.java   View source code 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 8
Project: jdk8u-jdk   File: ColConvDCMTest.java   View source code 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 9
Project: openjdk-jdk10   File: ColConvCCMTest.java   View source code 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 10
Project: openjdk-jdk10   File: ColConvCCMTest.java   View source code 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 11
Project: openjdk-jdk10   File: InvalidRenderIntentTest.java   View source code 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 12
Project: openjdk-jdk10   File: ColConvDCMTest.java   View source code 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 13
Project: openjdk-jdk10   File: ColConvDCMTest.java   View source code 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 14
Project: FreeCol   File: ImageResource.java   View source code 6 votes vote down vote up
/**
 * Gets a grayscale version of the image of the given size.
 * 
 * @param d The requested size.
 * @return The {@code BufferedImage}.
 */
public BufferedImage getGrayscaleImage(Dimension d) {
    final BufferedImage cached = grayscaleImages.get(d);
    if (cached != null) return cached;
    final BufferedImage im = getImage(d);
    if (im == null) return null;
    int width = im.getWidth();
    int height = im.getHeight();
    // TODO: Find out why making a copy is necessary here to prevent
    //       images from getting too dark.
    BufferedImage srcImage = new BufferedImage(width, height,
        BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = srcImage.createGraphics();
    g.drawImage(im, 0, 0, null);
    g.dispose();
    ColorConvertOp filter = new ColorConvertOp(
        ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
    final BufferedImage grayscaleImage = filter.filter(srcImage, null);
    grayscaleImages.put(d, grayscaleImage);
    return grayscaleImage;
}
 
Example 15
Project: openjdk9   File: ColConvCCMTest.java   View source code 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
Project: openjdk9   File: ColConvCCMTest.java   View source code 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
Project: openjdk9   File: InvalidRenderIntentTest.java   View source code 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 18
Project: openjdk9   File: ColConvDCMTest.java   View source code 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 19
Project: openjdk9   File: ColConvDCMTest.java   View source code 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
Project: orbit-image-analysis   File: JSliderOrbit.java   View source code 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 21
Project: jdk8u_jdk   File: ColConvCCMTest.java   View source code 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 22
Project: jdk8u_jdk   File: ColConvCCMTest.java   View source code 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 23
Project: jdk8u_jdk   File: InvalidRenderIntentTest.java   View source code 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 24
Project: jdk8u_jdk   File: ColConvDCMTest.java   View source code 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 25
Project: jdk8u_jdk   File: ColConvDCMTest.java   View source code 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 26
Project: lookaside_java-1.8.0-openjdk   File: ColConvCCMTest.java   View source code 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 27
Project: lookaside_java-1.8.0-openjdk   File: ColConvCCMTest.java   View source code 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 28
Project: lookaside_java-1.8.0-openjdk   File: InvalidRenderIntentTest.java   View source code 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 29
Project: lookaside_java-1.8.0-openjdk   File: ColConvDCMTest.java   View source code 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 30
Project: lookaside_java-1.8.0-openjdk   File: ColConvDCMTest.java   View source code 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 31
Project: Java-FPDF   File: JpegReader.java   View source code 6 votes vote down vote up
public static BufferedImage convertCmykToRgb(Raster cmykRaster, ICC_Profile cmykProfile) throws IOException {
    if (cmykProfile == null)
        cmykProfile = ICC_Profile.getInstance(JpegReader.class.getResourceAsStream("/ISOcoated_v2_300_eci.icc"));

    if (cmykProfile.getProfileClass() != ICC_Profile.CLASS_DISPLAY) {
        byte[] profileData = cmykProfile.getData();

        if (profileData[ICC_Profile.icHdrRenderingIntent] == ICC_Profile.icPerceptual) {
            intToBigEndian(ICC_Profile.icSigDisplayClass, profileData, ICC_Profile.icHdrDeviceClass); // Header is first

            cmykProfile = ICC_Profile.getInstance(profileData);
        }
    }

    ICC_ColorSpace cmykCS = new ICC_ColorSpace(cmykProfile);
    BufferedImage rgbImage = new BufferedImage(cmykRaster.getWidth(), cmykRaster.getHeight(), BufferedImage.TYPE_INT_RGB);
    WritableRaster rgbRaster = rgbImage.getRaster();
    ColorSpace rgbCS = rgbImage.getColorModel().getColorSpace();
    ColorConvertOp cmykToRgb = new ColorConvertOp(cmykCS, rgbCS, null);
    cmykToRgb.filter(cmykRaster, rgbRaster);
    return rgbImage;
}
 
Example 32
Project: imageweb   File: CmykImageUtil.java   View source code 6 votes vote down vote up
public static BufferedImage convertCmykToRgb(Raster cmykRaster, ICC_Profile cmykProfile) throws IOException {
    if (cmykProfile == null){
    	cmykProfile = ICC_Profile.getInstance(CmykImageUtil.class.getResourceAsStream("/ISOcoated_v2_300_eci.icc"));
    }

    if (cmykProfile.getProfileClass() != ICC_Profile.CLASS_DISPLAY) {
        byte[] profileData = cmykProfile.getData();

        if (profileData[ICC_Profile.icHdrRenderingIntent] == ICC_Profile.icPerceptual) {
            intToBigEndian(ICC_Profile.icSigDisplayClass, profileData, ICC_Profile.icHdrDeviceClass); // Header is first

            cmykProfile = ICC_Profile.getInstance(profileData);
        }
    }

    ICC_ColorSpace cmykCS = new ICC_ColorSpace(cmykProfile);
    BufferedImage rgbImage = new BufferedImage(cmykRaster.getWidth(), cmykRaster.getHeight(), BufferedImage.TYPE_INT_RGB);
    WritableRaster rgbRaster = rgbImage.getRaster();
    ColorSpace rgbCS = rgbImage.getColorModel().getColorSpace();
    ColorConvertOp cmykToRgb = new ColorConvertOp(cmykCS, rgbCS, null);
    cmykToRgb.filter(cmykRaster, rgbRaster);
    return rgbImage;
}
 
Example 33
Project: infobip-open-jdk-8   File: ColConvCCMTest.java   View source code 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 34
Project: infobip-open-jdk-8   File: ColConvCCMTest.java   View source code 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 35
Project: infobip-open-jdk-8   File: InvalidRenderIntentTest.java   View source code 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 36
Project: infobip-open-jdk-8   File: ColConvDCMTest.java   View source code 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 37
Project: infobip-open-jdk-8   File: ColConvDCMTest.java   View source code 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 38
Project: sambox   File: PDColorSpace.java   View source code 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 39
Project: sambox   File: JPEGFactory.java   View source code 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 40
Project: jdk8u-dev-jdk   File: ColConvCCMTest.java   View source code 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;
}