[OpenJDK 2D-Dev] BufferedImage.getTileGridXOffset() not compliant with its specification?
Sergey Bylokhov
Sergey.Bylokhov at oracle.com
Sun Feb 23 07:13:10 UTC 2020
> My understanding is that the origin cited in the specification is the origin of current image, not the origin of a parent or source image. Otherwise given that RenderedImage.getSources() can return an arbitrary amount of source (or parent) images, which one would define the origin?
>
> But anyway, while I agree that the first part of the sentence has ambiguity because of different possible interpretations of "origin", the second part of the sentence is much clearer:
>
> i.e., the X coordinate of the upper-left pixel of tile (0, 0). (Note that tile (0, 0) may not actually exist.)
Note that this part does not exists in the specification of the BufferedImage.
> So we can write:
>
> tileGridXOffset = minX - minTileX * tileWidth
>
> (Note: Java Advanced Imaging was also doing this mathematics if my memory serves me right.)
>
> In BufferedImage implementation, getMinTileX() and getNumTileX() are hard-coded to 0 and 1 respectively, while getMinX() and getTileWidth() delegate to raster methods. If we substitute variables in above formulas by BufferedImage implementations we get:
>
> tileGridXOffset = raster.getMinX() - 0 * raster.getTileWidth()
>
> which simplify as:
>
> tileGridXOffset = raster.getMinX()
>
> Where raster.getMinX() always returns 0 in BufferedImage case, consistently with BufferedImage javadoc which said getTileGridXOffset() value is always zero.
I agree that all calculation above are valid for the simple BufferedImage, but not sure about sub image, will check the history of the file and its usage.
--
Best regards, Sergey.
More information about the 2d-dev
mailing list