FULL PRODUCT VERSION :
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Jpeg files saved with the ICC profile "Nikon sRGB 4.0.0.3001" do not load properly using Java ImageIO.read(). This appears to be similar to the problems reported in bugid 6246622, which was fixed in 1.5_04 and is now closed. The image in this case is far too dark, but the colors are not swapped.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use Nikon Picture Project to save a JPEG, this will add the ICC profile "Nikon sRGB 4.0.0.3001" to the Jpeg. Use ImageIO.read to create a BufferedImage from the Jpeg file.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
An image that displays as it does when loaded with Adobe PhotoShop.
ACTUAL -
The image was far too dark, close to totally black.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.imageio.*;
import javax.imageio.stream.*;
import javax.swing.*;
import java.awt.*;
import java.awt.color.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.util.*;
public class Gui {
private JFrame frame = new JFrame();
private Container contentPane;
private BufferedImage bug;
private BufferedImage fix;
private JLabel bugLabel = new JLabel("bug not loaded");
private JLabel fixLabel = new JLabel("fix not loaded");
Gui() {
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
File file = new File("nikon.jpg");
try {
bug = ImageIO.read(file);
bugLabel = new JLabel("buggy", new ImageIcon(bug), SwingConstants.LEFT);
fix = read(file);
fixLabel = new JLabel("fixed", new ImageIcon(fix), SwingConstants.LEFT);
} catch (IOException e) {
e.printStackTrace();
}
frame.getContentPane().add(bugLabel, BorderLayout.NORTH);
frame.getContentPane().add(fixLabel, BorderLayout.SOUTH);
frame.pack();
frame.setVisible(true);
}
public static void main(String [] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new Gui();
}
});
}
public static BufferedImage read(File file) throws IOException {
BufferedImage image = null;
ImageInputStream iis = ImageIO.createImageInputStream(file);
if (iis == null) {
throw new IOException("File not found");
}
Iterator<ImageReader> iir = ImageIO.getImageReaders(iis);
boolean looking = true;
ImageReader reader = null;
ImageReadParam param = null;
while(looking && iir.hasNext()) {
reader = iir.next();
reader.setInput(iis);
param = reader.getDefaultReadParam();
Iterator it = reader.getImageTypes(0);
while (looking && it.hasNext()) {
ImageTypeSpecifier type = (ImageTypeSpecifier) it.next();
ColorSpace cs = type.getColorModel().getColorSpace();
if ( cs.isCS_sRGB() ) {
param.setDestinationType(type);
looking = false;
}
if ( cs.getType() != ColorSpace.TYPE_RGB ) {
looking = false;
}
}
}
if (reader != null) {
image = reader.read(0, param);
}
return image;
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Replace the ImageIO.read(file) with
[code]
ImageInputStream iis = ImageIO.createImageInputStream(file);
Iterator<ImageReader> iir = ImageIO.getImageReaders(iis);
boolean looking = true;
ImageReader reader = null;
ImageReadParam param = null;
while(looking && iir.hasNext()) {
reader = iir.next();
reader.setInput(iis);
param = reader.getDefaultReadParam();
Iterator it = reader.getImageTypes(0);
while (looking && it.hasNext()) {
ImageTypeSpecifier type = (ImageTypeSpecifier) it.next();
ColorSpace cs = type.getColorModel().getColorSpace();
if (cs.isCS_sRGB()) {
param.setDestinationType(type);
looking = false;
}
if (cs.getType() != ColorSpace.TYPE_RGB) {
looking = false;
}
}
}
if (reader != null) {
img = reader.read(0, param);
}
[/code]