JDK-5043459 : 8bit monochrome jpeg images are displayed too bright
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-05-06
  • Updated: 2004-05-19
  • Resolved: 2004-05-19
Related Reports
Duplicate :  
Description

Name: rmT116609			Date: 05/06/2004


FULL PRODUCT VERSION :
java version "1.4.2_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)

java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Windows XP

A DESCRIPTION OF THE PROBLEM :
- When loading an 8-bit monochrome jpeg image via ImageIO.read(..), the image is displayed too bright. This does not happen when the image is loaded via Toolkit.createImage(..).
- This problem is visible when using Graphics2D for displaying with a scaling != 1 (via AffineTransform) and certain RenderingHints.
For the exact parameters, please see the code example.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use the code example below. Compare the 2 image renderings; also use an image viewer (like IrfanView) to compare the appearance.
You can use the 8-bit monochrome image from
http://www.deutsche-synchronsprecher.de/baltho.jpg
and copy it into the classes folder, using the name "image.jpg".



REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import javax.swing.*;
import java.io.*;


public class JImagePanel extends JPanel
{
  Image xImage;
  java.awt.geom.AffineTransform xPaintScaling;
  
  public JImagePanel(Image xImage)
  {
    this.xImage = xImage;
    xPaintScaling = new java.awt.geom.AffineTransform();
  }
  
  public void paintComponent(Graphics g)
  {
    xPaintScaling.setToScale(1.2, 1.2);
    Graphics2D gg = (Graphics2D)g;
    gg.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
      RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    gg.drawImage(xImage, xPaintScaling, JImagePanel.this);
  }
  
  public static void main(String[] args)
  {
    try
    {
      JFrame xJFrame = new JFrame();
      
      // The image must be an 8-bit monochrome JPEG
      String name = "image.jpg";
      
      Image xImage1 = Toolkit.getDefaultToolkit().createImage(name);
      
      // The following image is displayed too bright:
      Image xImage2 = javax.imageio.ImageIO.read(new File(name));
      
      JSplitPane xJSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
        new JImagePanel(xImage1), new JImagePanel(xImage2));
      xJFrame.getContentPane().add(xJSplitPane);
      
      xJFrame.setSize(800, 600);
      xJFrame.setVisible(true);
      xJSplitPane.setDividerLocation(0.5);
    }
    catch(Exception e)
    {
    }
  }
}


---------- END SOURCE ----------
(Incident Review ID: 260739) 
======================================================================

Comments
EVALUATION Not for tiger. ###@###.### 2004-05-10 Name: abR10136 Date: 05/19/2004 This problem is duplicate of problem described in bug 4904494 (Gray BufferedImage is too bright). The ImageIO JPEG reader uses TYPE_BYTE_GRAY buffered image as image reading destination. When we grab pixels data from such buffered image with color model based on gray color space then these data are shifted to the white color. ======================================================================
21-08-2004

WORK AROUND Name: abR10136 Date: 05/19/2004 We can draw image produced by the ImageIO.read() method to the some buffered image with color model based on RGB color space and use this rgb buffered image for applying affine transforms. The example of workaround code is listed below: import java.awt.*; import java.awt.image.*; import javax.swing.*; import java.io.*; import javax.imageio.*; public class JImagePanel extends JPanel { Image xImage; java.awt.geom.AffineTransform xPaintScaling; public JImagePanel(Image xImage) { this.xImage = xImage; xPaintScaling = new java.awt.geom.AffineTransform(); } public void paintComponent(Graphics g) { xPaintScaling.setToScale(1.2, 1.2); Graphics2D gg = (Graphics2D)g; gg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); gg.drawImage(xImage, xPaintScaling, JImagePanel.this); } public static void main(String[] args) { try { JFrame xJFrame = new JFrame(); // The image must be an 8-bit monochrome JPEG String name = "image.jpg"; Image xImage1 = Toolkit.getDefaultToolkit().createImage(name); // The following image is displayed too bright: Image xImage2 = readImage(name); JSplitPane xJSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JImagePanel(xImage1), new JImagePanel(xImage2)); xJFrame.getContentPane().add(xJSplitPane); xJFrame.setSize(800, 600); xJFrame.setVisible(true); xJSplitPane.setDividerLocation(0.5); } catch(Exception e) { e.printStackTrace(); } } private static Image readImage(String fname) throws IOException { BufferedImage img = ImageIO.read(new File(fname)); BufferedImage out = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics g = out.createGraphics(); g.drawImage(img, 0, 0, null); return out; } } ======================================================================
21-08-2004