JDK-6294920 : BMP Reader fails to read 3BYTE_BGR images encoded using BMP Writer with BI_JPEG compression
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 5.0,6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2005-07-08
  • Updated: 2011-01-19
  • Resolved: 2005-09-19
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.
6 b53Fixed
Related Reports
Duplicate :  
Relates :  
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:
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

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.