JDK-4881314 : ImageIO does not correctly read some standard JPG files
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 5.0,6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_2000,windows_xp
  • CPU: generic,x86
  • Submitted: 2003-06-19
  • Updated: 2005-04-18
  • Resolved: 2005-04-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6
5.0u4Fixed 6 b33Fixed
Related Reports
Duplicate :  
Description

Name: rmT116609			Date: 06/19/2003


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

FULL OS VERSION :
Windows 2000 SP3

A DESCRIPTION OF THE PROBLEM :
Java ImageIO incorrectly reads some JPG files, the result is a red/green image that looks somthing like a photographic negative.
Images created with "Adobe Photoshop Album" can cause this problem, but some photos are read incorrectly straight out of a digital camera.
In all cases the photos Java has problems with can be read correctly in any image editing program, or displayed correctly on any browser.

The code necessary to produce the error is as simple as:

File inFile = new File(inname);
BufferedImage im = ImageIO.read(inFile);
File outFile = new File(outname);
ImageIO.write(im, "jpg", outFile);


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
File inFile = new File(inname);
BufferedImage im = ImageIO.read(inFile);
File outFile = new File(outname);
ImageIO.write(im, "jpg", outFile);

An example of a JPG that JAVA cannot read is here:
www.PhotoShare.co.nz/PhotoShareGallery1/100041/101268/MistyMorn-334229207.jpg
The photo that JAVA produced from this image is here:
www.PhotoShare.co.nz/PhotoShareGallery1/100041/101268/MistyMorn-334229207_S.jpg

I can provide you with many more samples of JPG files that Java cannot read correctly if you wish.

Steps to reproduce the problem:
-------------------------------

I call this program with

java makeSmall 480 c:\MistyMorn-334229207.jpg c:\MistyMorn-334229207_S.jpg 640

This means that I want to read the photo file "C:\MistyMorn-334229207.jpg"
and create a new file called "C:\MistyMorn-334229207_S.jpg"
which has a height of 480 pixels unless that would make the width wider than 640, in which case the height is reduced.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The JPG file created should display correctly, but instead it has mostly red/green colours, and looks like a photographic negative
ACTUAL -
An example of a JPG that JAVA cannot read is here:
www.PhotoShare.co.nz/PhotoShareGallery1/100041/101268/MistyMorn-334229207.jpg
The photo that JAVA produced from this image is here:
www.PhotoShare.co.nz/PhotoShareGallery1/100041/101268/MistyMorn-334229207_S.jpg



ERROR MESSAGES/STACK TRACES THAT OCCUR :
No error message

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.*;
import java.util.*;
import java.awt.image.*;
import java.awt.geom.*;
import javax.imageio.*;
import javax.imageio.event.*;
import javax.imageio.stream.*;

public class makeSmall
{
	public static void main(String[] args){
		if (args.length < 4) {
			System.out.println("Usage: java makeSmall height infile outfile maxwidth");
			System.exit(0);
		}

		try {
			int newH = Integer.valueOf(args[0]).intValue();
			int maxW = Integer.valueOf(args[3]).intValue();

			String inname = args[1];
			String outname = args[2];

			File inFile = new File(inname);
			BufferedImage im = ImageIO.read(inFile);
			
			double w = im.getWidth();
			double h = im.getHeight();
			
			double scaleRatio = newH/h ;
			if (scaleRatio > 1){
				scaleRatio = 1;
			}
			if (w * scaleRatio > maxW){
				scaleRatio = maxW/w;
			}
			
			AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(scaleRatio, scaleRatio),null);
			/*AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(xratio, yratio),2);*/
			
			BufferedImage scaledIm = op.filter(im,null);
			
			File outFile = new File(outname);
			ImageIO.write(scaledIm, "jpg", outFile);
			
		} catch(IOException ioe){
			/*System.out.println("Error reading or writing file");*/
			System.exit(2);
		} catch(Exception e){
			/*System.out.println("Error scaling image");*/
			System.exit(3);
		}
	}
}
---------- END SOURCE ----------


(Review ID: 187571) 
======================================================================

Comments
EVALUATION Not for mantis. ###@###.### 2003-06-19 Developers and users are running into this problem more frequently, so we should investigate this for Mustang. ###@###.### 2004-09-09 We should not perform color space conversion for EXIF images - they are already using YCbCr. (see http://www.exif.org/Exif2-2.PDF, section 4.7, page 63). To detect EXIF image we may check for presense of the APP1 marker in the image header. (see http://www.exif.org/Exif2-2.PDF, section 4.7, page 58). ###@###.### 2005-03-28 12:11:39 GMT
28-03-2005

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang
12-09-2004