Hello

The BufferedImage Javadoc does not mention any constraint about the data type. In practice, BufferedImage with floating point values can be rendered as well as integers (only slower) 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 a test case, together with a proposed fix, in the following pull request:

   https://github.com/openjdk/jdk/pull/13797

The proposed fix is very simple: just replace the whole method body by a call to WritableRaster.setRect(Raster), which handles all supported data types correctly. The pull request description contains code comparison for showing that this is equivalent, except for robustness to integer underflow. The pull request discusses the possible impact on behavior, which are:

 * Change in behavior under integer underflow.
 * One more user-overrideable method get invoked.

Martin

Reply via email to