There you go !
In the following code, when I uncomment (1) and comment (2), the image
is converted to grayscale
screen output :
www.mac.com/d.bouchard/dev/color2gray.png
If I comment (1) and uncomment (2), the image is not converted (i.e.
nothing happens)
console output :
INFO TestICC2 - loading profile
INFO TestICC2 - GAMMA COMPONENT [0] [2.6015625]
INFO TestICC2 - GAMMA COMPONENT [1] [2.6015625]
INFO TestICC2 - GAMMA COMPONENT [2] [2.6015625]
INFO TestICC2 - WHITE POINT [0] [0.9538574]
INFO TestICC2 - WHITE POINT [1] [1.0]
INFO TestICC2 - WHITE POINT [2] [1.4311523]
INFO TestICC2 - MATRIX
INFO TestICC2 - 0.3535614 0.43249512 0.17814636
INFO TestICC2 - 0.19529724 0.6667633 0.13853455
INFO TestICC2 - 0.012313843 0.092926025 0.71951294
screen output :
www.mac.com/d.bouchard/dev/color2icc.png
The code :
public TestICC2()
{
try
{
JFrame frame = new JFrame("test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel main = new JPanel(new BorderLayout());
frame.setContentPane(main);
ImageIcon ii = new ImageIcon(IMAGE);
JLabel srcLabel = new JLabel(ii);
main.add(srcLabel, BorderLayout.WEST);
frame.pack();
frame.setVisible(true);
logger.info("loading profile");
ICC_Profile profiles[] = new ICC_Profile[1];
// Color2Gray (1)
//profiles[0] = ICC_ProfileGray.getInstance(ICC_ColorSpace.CS_GRAY);
// Color2ICC (2)
profiles[0] = ICC_Profile.getInstance(new FileInputStream(PROFILE));
displayInfoProfil(profiles[0]);
BufferedImage src = new BufferedImage(ii.getIconWidth(),
ii.getIconHeight(), BufferedImage.TYPE_INT_RGB);
src.getGraphics().drawImage(ii.getImage(), 0, 0, this);
ColorConvertOp cco = new ColorConvertOp(profiles, null);
BufferedImage dest = cco.filter(src, null);
JLabel destLabel = new JLabel(new ImageIcon(dest));
main.add(destLabel, BorderLayout.EAST);
frame.pack();
}
catch (Exception e)
{
logger.error("erreur lecture profile", e);
}
}
public void displayInfoProfil(ICC_Profile profile)
{
if (profile instanceof ICC_ProfileRGB)
{
ICC_ProfileRGB iccPRGB = (ICC_ProfileRGB)profile;
int i , j;
for ( i = 0 ; i < iccPRGB.getNumComponents() ; i++ )
{
logger.info("GAMMA COMPONENT [" + i + "] ["
+ iccPRGB.getGamma(i) + "]");
}
float mwp[] = iccPRGB.getMediaWhitePoint();
for ( i = 0 ; i < mwp.length ; i++ )
{
logger.info("WHITE POINT [" + i + "] [" + mwp
+ "]");
}
float matrice[][] = iccPRGB.getMatrix();
StringBuffer sb = new StringBuffer();
logger.info("MATRIX");
for ( i = 0 ; i < matrice.length ; i++ )
{
sb.setLength(0);
sb.append("|");
for ( j = 0 ; j < matrice.length ; j++ )
{
sb.append(matrice[j] + "\t");
}
sb.append("|");
logger.info(sb.toString());
}
}
}