-
Bug
-
Resolution: Fixed
-
P4
-
17, 21, 22
-
None
-
b07
-
generic
-
generic
The BufferedImage Javadoc does not mention any constraint about the data type. In practice, BufferedImage with floating point values can be rendered by Java2D as well as integers, provided that a compatible ColorModel was supplied at construction time. However calls to setData(Raster) unexpectedly cast floating point values to integers. For example sample value 0.8 become 0. This is demonstrated by the SetData test case in this pull request.
An easy fix, which is proposed in this pull request, is to replace the whole BufferedImage.setData(Raster) method body by a simple call to WritableRaster.setRect(Raster), which handles all DataBuffer types correctly. The method contracts documented in their respective Javadoc are compatible. Furthermore an examination of their source code shows that they are equivalent, except for the differences noted in the Behavioural changes section below.
An easy fix, which is proposed in this pull request, is to replace the whole BufferedImage.setData(Raster) method body by a simple call to WritableRaster.setRect(Raster), which handles all DataBuffer types correctly. The method contracts documented in their respective Javadoc are compatible. Furthermore an examination of their source code shows that they are equivalent, except for the differences noted in the Behavioural changes section below.