JDK-6294960 : BMP Reader throws NPE when reading TYPE_BYTE_GRAY encoded by BMP Writer with BI_BITFIELDS compressn
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2005-07-08
  • Updated: 2011-01-19
  • Resolved: 2005-09-27
Related Reports
Duplicate :  
Relates :  
Description
I am encoding a TYPE_BYTE_GRAY buffered image using BMP ImageWriter and writing this image to a file. I am setting the compression mode to MODE_EXPLICIT and setting the compression type to BI_BITFIELDS compression type. BMP writer claims that it supports the given buffered image and the given compression type. canEncodeImage() method of BMPWriter does not enforce any restriction for this combination. The writing process was successful But there was a NPE when I tried to read the image back from the file using BMP ImageReader. 

Here is the exception:
Exception in thread "main" java.lang.NullPointerException
at com.sun.imageio.plugins.bmp.BMPImageReader.readHeader(BMPImageReader.java:510)
at com.sun.imageio.plugins.bmp.BMPImageReader.read(BMPImageReader.java:657)
at javax.imageio.ImageIO.read(ImageIO.java:1400)
at javax.imageio.ImageIO.read(ImageIO.java:1286)
at BMPWriterByteGrayTest.<init>(BMPWriterByteGrayTest.java:135)
at BMPWriterByteGrayTest.main(BMPWriterByteGrayTest.java:208)

This is reproducible on all platforms, since Tiger-FCS.

I have attached a sample test and the image. Execute the sample test as follows:
'java BMPWriterByteGrayTest bmp'. You would see the above exception on the console.
###@###.### 2005-07-08 12:29:57 GMT

The same exception is reproducible when writing TYPE_BYTE_INDEXED image also, with the same compression type.
###@###.### 2005-07-08 12:38:09 GMT

Comments
EVALUATION The content of BYTE_GRAY image should be handled by writePixels() procedure in order to provide correct data storage format. However, this procedure should be updated to handle case of gray-scaled images correctly we need to replicate the level of the gray to color components.
26-09-2005