JDK-6379404 : conversion of gif to jpeg produces corrupt file
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-01-31
  • Updated: 2011-01-19
  • Resolved: 2006-02-01
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.4.2_10"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_10-b03)
Java HotSpot(TM) Client VM (build 1.4.2_10-b03, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Windows XP Version 2002 Service Pack 2

A DESCRIPTION OF THE PROBLEM :
Saving some small gif files as a jpeg produces a corrupt file.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
save http://www.nabble.com/images/icon_alert_sm.gif as t.gif
run the code I supplied to convert this to t.jpeg
try loading t.jpeg into a browser


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect a usable jpeg.
ACTUAL -
Browser complains that t.jpeg has errors.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.*;
import java.awt.image.*;
import javax.imageio.*;

public class Gif {

	public static void main(String[] args) throws Exception {
		BufferedImage bi = ImageIO.read(new File("t.gif"));
		ImageIO.write(bi, "jpeg", new File("t.jpeg"));
	}
}

---------- END SOURCE ----------

Comments
EVALUATION Please note that test image t.gif contains transparent background. Therefore, buffered image created by ImageIO used index color model with bitmask transparency. In this case ImageIO JPEG writer creates images with alpha channel using RGBA or YCbCrA color spaces. Such images are compliant with the JPEG specification and can be read by ImageIO JPEG reader or some native applications (like Jasc Paint Shop Photo Album for example). However, many native applications are not aware of these color spaces and render a corrupted image. Please see bug 4836466 for more details.
01-02-2006