JDK-6519600 : BMP Writer fails when writing TYPE_USHORT_565_RGB with BI_BITFIELDS and sub-sampling
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2007-01-31
  • Updated: 2011-03-07
  • Resolved: 2011-03-07
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.
JDK 7
7 b10Fixed
Related Reports
Relates :  
Description
I am running the attached test which writes a TYPE_USHORT_565_RGB buffered image using BMP Writer with all supported compression types. This test fails to read the image back from the file using ImageIO when image is encoded with BITFIELDS compression. An exception is thrown.

Here is the exception -

java.io.EOFException
at javax.imageio.stream.ImageInputStreamImpl.readFully(ImageInputStreamImpl.java:339)
at javax.imageio.stream.ImageInputStreamImpl.readFully(ImageInputStreamImpl.java:359)
at com.sun.imageio.plugins.bmp.BMPImageReader.read16Bit(BMPImageReader.java:1230)
at com.sun.imageio.plugins.bmp.BMPImageReader.read(BMPImageReader.java:821)
at javax.imageio.ImageIO.read(ImageIO.java:1422)
at javax.imageio.ImageIO.read(ImageIO.java:1282)
at BMPWriterUshort555RGBTest.<init>(BMPWriterUshort555RGBTest.java:148)
at BMPWriterUshort555RGBTest.main(BMPWriterUshort555RGBTest.java:222)

Also the output image created by BMP writer has got 2 black lines which is not there in the original image, running diagonally. 

This is reproducible on all platforms atleast since 1.5. 

I have attached the source image, output image and the sample test.

Comments
EVALUATION BMP writer can handle BI_BITFIELDS compression in two different ways(depends on sub-sampling setting): - direct data copying if no sub-sampling is required - using writePixels() routine if sub-sampling settings is specified. Note that writePixels() routine writes padding bytes only for BI_RGB compression type and miss them for BI_BITFIELDS compression. Absence of padding bytes causes the incorrect alignment of raster data and leads to the reader failure.
01-02-2007