[OpenJDK 2D-Dev] BufferedImage.getTileGridXOffset() not compliant with its specification?

Sergey Bylokhov Sergey.Bylokhov at oracle.com
Mon Mar 9 00:29:20 UTC 2020

Hi, Martin.

On 2/23/20 3:12 am, Martin Desruisseaux wrote:
> The purpose of RenderedImage.getTileGridXOffset() is to provide information needed for converting pixel coordinates to tile indices and conversely. Current BufferedImage.getTileGridXOffset() implementation breaks this purpose, and in turn does not provide any information that I can see as useful at the image level (it is useful at the Raster / SampleModel level, but developers already have dedicated API for that). It is not even an offset of the sub-image compared to the parent image except by coincidence in the simple case (it depends on how the BufferedImage has been constructed).

I have checked the history of these methods and their usage.

These methods were added to the BufferedImage back in 1997 when the
generic support of rendered images was added. Since then these methods
were used in the implementation of Graphics2D.drawRenderedImage(), but
in fact for BufferedImage they are never called [1]. I think it is
possible to change getTileGridXOffset()/getTileGridYOffset to return 0.
But it will be necessary to create a CSR, since the change has
compatibility impact.

[1] https://github.com/openjdk/client/blob/master/src/java.desktop/share/classes/sun/java2d/SunGraphics2D.java#L2662

Best regards, Sergey.

More information about the 2d-dev mailing list