JDK-4957775 : ConvolveOp.filter() fails on some BufferedImages delivered from ImageIO.read()
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 1.4.0,1.4.2
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic,windows_2000
  • CPU: generic,x86
  • Submitted: 2003-11-20
  • Updated: 2015-11-03
Description

Name: rmT116609			Date: 11/20/2003


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


FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

EXTRA RELEVANT SYSTEM CONFIGURATION :
Dell Inspiron 8000 Laptop with Geforce2Go VGA

A DESCRIPTION OF THE PROBLEM :
When loading images via javax.imageio.ImageIO.read(...) I sometimes cannot use ConvolveOp.filter(...) to filter the BufferedImage delivered from ImageIO.read(...) - I get the exception "java.awt.image.ImagingOpException: Unable to convolve src image"
When loading the image via com.sun.image.codec.jpeg.JPEGImageDecoder.decodeAsBufferedImage() ConvolveOp.filter(...) works as expected.
        


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
An image to reproduce the exception can be downloaded here:
http://rekasys.at.tf/img/TestImg.jpg

Use the source code to execute the test-application.

First load the image via the button "load via JPEGImageDecoder",
then press "Sharpen". This should work.

Second load the image via the button "load via imageio",
then press "Sharpen". Now you should get an exception.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
When loading the image via the button "load via JPEGImageDecoder",
Sharpen-Image works.

When loading the same image via the button "load via imageio",
you should get an exception when "Sharpening" the image.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.awt.image.ImagingOpException: Unable to convolve src image

	at java.awt.image.ConvolveOp.filter(ConvolveOp.java:180)

	at sharpentest.Main.btnSharpen_actionPerformed(Main.java:128)

	at sharpentest.Main$3.actionPerformed(Main.java:57)

	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)

	at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)

	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)

	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

	at java.awt.Component.processMouseEvent(Component.java:5100)

	at java.awt.Component.processEvent(Component.java:4897)

	at java.awt.Container.processEvent(Container.java:1569)

	at java.awt.Component.dispatchEventImpl(Component.java:3615)

	at java.awt.Container.dispatchEventImpl(Container.java:1627)

	at java.awt.Component.dispatchEvent(Component.java:3477)

	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)

	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

	at java.awt.Container.dispatchEventImpl(Container.java:1613)

	at java.awt.Window.dispatchEventImpl(Window.java:1606)

	at java.awt.Component.dispatchEvent(Component.java:3477)

	at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)

	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

	at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)



REPRODUCIBILITY :
This bug can be reproduced often.

---------- BEGIN SOURCE ----------
package sharpentest;

import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import javax.imageio.*;
import com.sun.image.codec.jpeg.*;

public class Main extends JFrame {
private JPanel jPanel1 = new JPanel();
private JButton btnLoadJPEGDecoder = new JButton();
private JSplitPane jSplitPane1 = new JSplitPane();
private JButton btnLoadImageIO = new JButton();
private JScrollPane jScrollPane1 = new JScrollPane();
private JScrollPane jScrollPane2 = new JScrollPane();
private JLabel lblSource = new JLabel();
private JLabel lblDest = new JLabel();
private BufferedImage sourceImage = null;
private BufferedImage destImage = null;
private JButton btnSharpen = new JButton();

public static void main( String[] args )
{
JFrame f = new Main();
f.setSize(800, 600);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.show();
}

public Main() throws HeadlessException {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}

private void jbInit() throws Exception {
btnLoadJPEGDecoder.setText("load via JPEGImageDecoder");
btnLoadJPEGDecoder.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
btnLoadJPEGDecoder_actionPerformed(e);
}
});
btnLoadImageIO.setText("load via imageio");
btnLoadImageIO.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
btnLoadImageIO_actionPerformed(e);
}
});
btnSharpen.setText("sharpen");
btnSharpen.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
btnSharpen_actionPerformed(e);
}
});
this.getContentPane().add(jPanel1, BorderLayout.NORTH);
jPanel1.add(btnLoadJPEGDecoder, null);
jPanel1.add(btnLoadImageIO, null);
jPanel1.add(btnSharpen, null);
this.getContentPane().add(jSplitPane1, BorderLayout.CENTER);
jSplitPane1.add(jScrollPane1, JSplitPane.TOP);
jScrollPane1.getViewport().add(lblSource, null);
jSplitPane1.add(jScrollPane2, JSplitPane.BOTTOM);
jScrollPane2.getViewport().add(lblDest, null);
}

void btnLoadJPEGDecoder_actionPerformed(ActionEvent e) {
JFileChooser fchooser = new JFileChooser();
int returnVal = fchooser.showOpenDialog(this);
if(returnVal == JFileChooser.APPROVE_OPTION) {
try
{
destImage = null;
FileInputStream fis = new FileInputStream(fchooser.getSelectedFile());
JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(fis);
sourceImage = decoder.decodeAsBufferedImage();
Icon icon = new ImageIcon(sourceImage);

lblSource.setIcon(icon);
lblDest.setIcon(null);
}
catch( Exception exc )
{
JOptionPane.showMessageDialog(this, exc.toString());
}
}
}

void btnLoadImageIO_actionPerformed(ActionEvent e) {
JFileChooser fchooser = new JFileChooser();
int returnVal = fchooser.showOpenDialog(this);
if(returnVal == JFileChooser.APPROVE_OPTION) {
try
{
destImage = null;
sourceImage = ImageIO.read(fchooser.getSelectedFile());
Icon icon = new ImageIcon(sourceImage);

lblSource.setIcon(icon);
lblDest.setIcon(null);
}
catch( Exception exc )
{
JOptionPane.showMessageDialog(this, exc.toString());
}
}
}

void btnSharpen_actionPerformed(ActionEvent e) {
try
{
BufferedImage img = null;
if( destImage!=null )
img = destImage;
else
img = sourceImage;

Kernel kernel = new Kernel(3, 3,
new float[] {
-1, -1, -1,
-1, 9, -1,
-1, -1, -1});
BufferedImageOp op = new ConvolveOp(kernel);
destImage = op.filter(img, null);
Icon icon = new ImageIcon(destImage);
lblDest.setIcon(icon);
}
catch( Exception exc )
{
JOptionPane.showMessageDialog(this, exc.toString());
}
}
} 
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Use com.sun.image.codec.jpeg.JPEGImageDecoder.decodeAsBufferedImage() for loading jpg-files.
(Incident Review ID: 215980) 
======================================================================

Comments
Please re-open if - if fix is in progress or on the plan to fix soon - if this is a P3 (file as P3, not P4)
18-03-2014