How to find the tile inside a TiledImage to read a ROI?
First of all I'd like to write down what I think I understand about JAI and the image coordinate systems and my current task.
I try to read very large (width * height > Integer.MAX_VALUE) images with JAI. Because of memory limitations it is impossible to read them fully into RAM. But luckily all these images I want to read are tiled (ImageReader.isImageTiled = true). My understandin is that it is possible to read only one tile of an image without having to read the whole image into RAM.
At a first step I want to create a list of all tiles that cover the image contents and what "absolute" pixel coordinates (Upper left corner of the image = 0,0) are contained in a particular tile.
I think I understood all facts covered by this URL: http://java.sun.com/products/java-media/jai/forDevelopers/jaifaq.html#co...
My conclusion is that all methods provided by the ImageReader that are related to the tile grid (ImageReader.getTileGridX/YOffset , ImageReader.getTileWidth/Height) return information about the grid layout but no information can be obtained from the ImageReader that says something about the "absolute" position of a pixel coordinate in relation to the tile grid.
So I can get information about the tile 0,0 and therefore can derive the image coordinate of the upper left corner of that tile within the image coordinate system. But I can't find out where that origin in pixel coordinates is and therefore I still don't know what tile to read if I want to read a particular area of interest given in pixel coordinates (Let's say a quadratic roi in the upper left corner of my image given by the upper left corner 0,0 and width of 100 pixels and height of 100 pixels).
What I need seems to be an instance of the ImageLayout class. Its methods getMinX/Y return the "relative" coordinates within the image coordinates. These values can be used to determine the position of the tile 0,0 in reference to the absolute upper left pixel coordinate 0,0. So for example if the TileGridX/YOffsets are 200,400 and minX/Y return -200, 300 I know that the upper left corner of tile 0,0 is 400 pixels to the right and 100 pixels to the bottom of the upper left pixel coordinate of the image.
So far my understanding of the image layout.
Now what I don't understand: It seems that an instance of ImageLayout can only be obtained from a RenderedImage. So it seems that I need to read the whole image to get information about the absolute position of the tilegrid that overlays the image. But as I said before I can't read the whole image due to memory limitations.
So my final question is: How can I find out what tile I have to read if I am interested to read a roi given in pixel coordinates without having to read the whole image?
Thank you very much for any clarification or proof of my misunderstanding.