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

Martin Desruisseaux martin.desruisseaux at geomatys.com
Fri Feb 21 13:36:16 UTC 2020

Hello all

Implementation of getTileGridXOffset() and getTileGridXOffset() in 
BufferedImage seems in contradiction with specification. The 
RenderedImage specification said:

    Returns the X offset of the tile grid relative to the origin, i.e.,
    the X coordinate of the upper-left pixel of tile (0, 0). (Note that
    tile (0, 0) may not actually exist.)

Since BufferedImage has only one tile, always at index (0,0), the (x,y) 
coordinates of the upper-left pixel of that tile should be the image 
(minX, minY), which is always (0,0) in a BufferedImage. Indeed 
BufferedImage.getTileGridXOffset() javadoc adds the following sentence:

    This is always zero.

But the BufferedImage implementation is:

    public int getTileGridXOffset() {
         return raster.getSampleModelTranslateX();

Which does not always returns zero. It can be demonstrated by the 
following test case:

    import java.awt.Dimension;
    import java.awt.image.BufferedImage;

    class Test {
         public static void main(String[] args) throws Exception {
             BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
             BufferedImage sub = img.getSubimage(10, 20, 50, 50);

Which prints -10 and -20.

Proposed fix: given that coordinates of BufferedImage == coordinates of 
tile (0,0) (this fact is hard-coded in BuffereImage.getMinTileX() 
returning the hard-coded 0 value, BuffereImage.getNumXTiles() returning 
the hard-coded 1 value (same for Y), and in BufferedImage.getMinX(), 
getMinY(), getWidth() and getHeight() delegating to the Raster), 
applying the same logic we should have:

    public int getTileGridXOffset() {
         return raster.getMinX();

    public int getTileGridXOffset() {
         return raster.getMinY();

Even if raster.getMinX() / getMinY() should always return 0, those 
methods are invoked for consistency with current implementation of 
BufferedImage.getMinX() / getMinY().

If above analysis is correct, do I need to provide a GitHub pull request 
or other submission mechanism?



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/2d-dev/attachments/20200221/d230d3a5/attachment.htm>

More information about the 2d-dev mailing list