Skip to main content

getTiles(image) is null

6 replies [Last post]
darwinjob
Offline
Joined: 2004-11-16
Points: 0

Why do I get null when I ask for the tiles like this:

for(...) {
...
//some operations on image
...
TileCache cache = JAI.getDefaultInstance().getTileCache();
logger.debug(cache + ":" + cache.getTiles(image));
}

output:
com.sun.media.jai.util.SunTileCache@3bb9bfe4: memoryCapacity = 200000000 memoryUsage = 3820bc0 #tilesInCache = 220:null

I can see that #tilesInCache increasing with every loop but getTiles(image) is always null. Why?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rgd
Offline
Joined: 2005-08-23
Points: 0

Hey...

In general you're not "supposed" to manipulate the cache at that level;
it should be transparent. So unless you're doing this for debugging or
tuning, you may want to reexamine if you really need to be looking at
the cache.

But the issue probably is that you're using the wrong image. The
RenderedOp chain of images you create with e.g. JAI.create() has a
parallel set of RenderedImage's, called renderings, that actually
process the pixels. These are typically but not always OpImage
subclasses. I believe it is these that go into the cache.

If image is a RnederedOp (you don't say where you get it from), then try
using image.getCurrentRendering() to get the rendering and pass that one
into the cache.

Hope that helps...

-Bob

On 11/8/11 5:07 AM, forums@java.net wrote:
> Why do I get null when I ask for the tiles like this:
>
> for(...) {
> ...
> //some operations on image
> ...
> TileCache cache = JAI.getDefaultInstance().getTileCache();
> logger.debug(cache + ":" + cache.getTiles(image));
> }
>
> output:
> com.sun.media.jai.util.SunTileCache@3bb9bfe4: memoryCapacity = 200000000
> memoryUsage = 3820bc0 #tilesInCache = 220:null
>
> I can see that #tilesInCache increasing with every loop but getTiles(image)
> is always null. Why?
>
>

darwinjob
Offline
Joined: 2004-11-16
Points: 0

rgd wrote:
In general you're not "supposed" to manipulate the cache at that level; it should be transparent.

Well, actually that is what I was going to do. The idea was to manually remove the tiles which are not going to be used with cache.removeTiles(image). I render a huge tiled pyramid image, so, in theory, to render Nth layer I only need N-1 layer's tiles, N-2 layer's tiles can be safely disposed.

Once you gave me an advice to use private cache for each "scale" operator, but I thought it might work with the common cache.

If I go for the private cache approach, can I somehow dispose these cache objects for the lower levels?

rgd
Offline
Joined: 2005-08-23
Points: 0

Well TileCache's are not expensive to create, outside of the memory they
use for the cache itself. I think it would be much more robust and
probably faster too to simply attach a different cache to each level of
the scale and then tune the sizes as needed (n-1 big enough to hold that
entire level, n-2 big enough to hold what's needed for an n-1 tile plus
appropriate overhead (or maybe an entire row of n-1's), etc.).

I'm not saying you can't go manipulate the cache directly; the API is
there of course. It just wouldn't be my first choice. ;-)

-Bob

On 11/8/11 3:47 PM, forums@java.net wrote:
>

rgd wrote:
In general you're not "supposed" to manipulate the cache at
> that level; it should be transparent.

>
> Well, actually that is what I was going to do. The idea was to manually
> remove the tiles which are not going to be used with
> cache.removeTiles(image). I render a huge tiled pyramid image, so, in
> theory,
> to render Nth layer I only need N-1 layer's tiles, N-2 layer's tiles can be
> safely disposed.
>
> Once you gave me an advice to use private cache for each "scale" operator,
> but I thought it might work with the common cache.
>
>
>
>

darwinjob
Offline
Joined: 2004-11-16
Points: 0

Quote:
to simply attach a different cache to each level of the scale and then tune the sizes

OK, but how can I dispose these huge (especially for the lower levels) tile-filled TileCache objects? I mean If work with N-2 level I don't need (and never will) Nth TileCache object and I guess I should remove it from the memory. I don't see the API for that...

rgd
Offline
Joined: 2005-08-23
Points: 0

Set the tile cache capacity to what you want and it'll dispose of extra
stuff automatically. At least it's supposed to. ;-) I think if you
change the capacity it'll flush to match.

-Bob

On 11/9/11 1:04 AM, forums@java.net wrote:
>

Quote:
to simply attach a different cache to each level of the scale and
> then tune the sizes

>
> OK, but how can I dispose these huge (especially for the lower levels)
> tile-filled TileCache objects? I mean If work with N-2 level I don't need
> (and never will) Nth TileCache object and I guess I should remove it
> from the
> memory. I don't see the API for that...
>
>
>
>

darwinjob
Offline
Joined: 2004-11-16
Points: 0

Or maybe I can use the same TileCache for all "scale"s?