mresTable = new Hashtable();
}
// Check for a SoftReference hashed on a ParameterBlock-derived key.
Object key = getKey(paramBlock);
SoftReference ref = (SoftReference)mresTable.get(key);
// Retrieve the image from the SoftReference if possible.
RenderableImage mres = null;
if(ref != null && (mres = (RenderableImage)ref.get()) == null) {
// null referent: remove the ParameterBlock key from the Hashtable.
mresTable.remove(key);
}
// Derive the image if necessary.
if(mres == null) {
// Retrieve the source and parameters.
RenderedImage source = paramBlock.getRenderedSource(0);
RenderedOp downSampler =
(RenderedOp)paramBlock.getObjectParameter(0);
int maxLowResDim = paramBlock.getIntParameter(1);
float minX = paramBlock.getFloatParameter(2);
float minY = paramBlock.getFloatParameter(3);
float height = paramBlock.getFloatParameter(4);
// Create an image pyramid.
ImageMIPMap pyramid = new ImageMIPMap(source, downSampler);
// Create a Vector of RenderedImages from the pyramid.
Vector sourceVector = new Vector();
RenderedImage currentImage = pyramid.getCurrentImage();
sourceVector.add(currentImage);
while(currentImage.getWidth() > maxLowResDim ||
currentImage.getHeight() > maxLowResDim) {
RenderedImage nextImage = pyramid.getDownImage();
if(nextImage.getWidth() >= currentImage.getWidth() ||
nextImage.getHeight() >= currentImage.getHeight()) {
throw new IllegalArgumentException(JaiI18N.getString("RenderableCRIF0"));
}
sourceVector.add(nextImage);
currentImage = nextImage;
}
// Create a RenderableImage
mres = new MultiResolutionRenderableImage(sourceVector,
minX, minY, height);
// Store a SoftReference to the RenderableImage in the Hashtable.
mresTable.put(key, new SoftReference(mres));
}
return mres;
}