United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6294920 BMP Reader fails to read 3BYTE_BGR images encoded using BMP Writer with BI_JPEG compression
JDK-6294920 : BMP Reader fails to read 3BYTE_BGR images encoded using BMP Writer with BI_JPEG compression

Details
Type:
Bug
Submit Date:
2005-07-08
Status:
Closed
Updated Date:
2011-01-19
Project Name:
JDK
Resolved Date:
2005-09-19
Component:
client-libs
OS:
generic
Sub-Component:
javax.imageio
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
5.0,6
Fixed Versions:

Related Reports
Duplicate:
Relates:

Sub Tasks

Description
I am writing a buffered image of type 3BYTE_BGR to a file using BMP Writer and I am setting the 
available compression types one by one. When I set the compression type to BI_JPEG and write the image, I am getting an exception when reading back the image using BMP Image reader. Native applications also fail to read this BMP image. 

Here is the exception:
java.io.EOFException
at javax.imageio.stream.ImageInputStreamImpl.readFully(ImageInputStreamImpl.java:330)
at com.sun.imageio.plugins.bmp.BMPImageReader.read24Bit(BMPImageReader.java:1166)
at com.sun.imageio.plugins.bmp.BMPImageReader.read(BMPImageReader.java:800)
at javax.imageio.ImageIO.read(ImageIO.java:1400)
at javax.imageio.ImageIO.read(ImageIO.java:1286)
at BMPWriter3BYTEBGRTest.<init>(BMPWriter3BYTEBGRTest.java:143)
at BMPWriter3BYTEBGRTest.main(BMPWriter3BYTEBGRTest.java:216)

This is reproducible on all platforms, since Tiger-FCS. The image read using BMP reader is empty.

I have attached a sample test and the image that I used to reproduce this bug. Run the application as follows: 'java BMPWriter3BYTEBGRTest bmp'
You would see the above exception on the console. 

###@###.### 2005-07-08 11:24:17 GMT

                                    

Comments
EVALUATION

The reason on this problem is that BMP image reader does not expect to meet embedded image (compression type BI_JPEG or BI_PNG) if bmpBitCount is 24 or 16. According to MSDN description of BITMAPINFOHEADER, the appearance of BI_JPEG or BI_PNG compression seems to be legal in this case (this description can be found here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_1rw2.asp).

 The solution is to move the embedded image handling to the separate code path that is not linked to the bmpBitCount. Another reason to do it is that according to mentioned MSDN description the zero value of bmpBitCount is also legal in case of embedded image. In order to handle zero bit count correctly we need to skip the destination image creation (because this procedure is based on bit count). The creation of destination image for embedded images should be postponed until we will
get appropriate image reader that will be able to provide information about appropriate destination image type.

Please not that this fix also solves problem described in CR 6294926.
                                     
2005-09-12



Hardware and Software, Engineered to Work Together