// Retrieve layout information from the hints. The tile size hints
// are ignored if a SampleModel hint is supplied. Set the hints
// observed if any hints are used.
SampleModel sm = null;
ColorModel cm = null;
RenderingHints hintsObserved = null;
if(hints != null) {
// Get the ImageLayout.
ImageLayout layout = (ImageLayout)hints.get(JAI.KEY_IMAGE_LAYOUT);
if(layout != null) {
// Initialize the observed hint variables.
hintsObserved = new RenderingHints(null);
ImageLayout layoutObserved = new ImageLayout();
// Get the SampleModel.
if(layout.isValid(ImageLayout.SAMPLE_MODEL_MASK)) {
sm = layout.getSampleModel(null);
if(sm.getWidth() != tileWidth ||
sm.getHeight() != tileHeight) {
sm = sm.createCompatibleSampleModel(tileWidth,
tileHeight);
}
if(layoutObserved != null) {
layoutObserved.setSampleModel(sm);
}
}
// Get the ColorModel.
if(layout.isValid(ImageLayout.COLOR_MODEL_MASK)) {
cm = layout.getColorModel(null);
if(layoutObserved != null) {
layoutObserved.setColorModel(cm);
}
}
// Get the tile dimensions.
if(layout.isValid(ImageLayout.TILE_WIDTH_MASK)) {
tileWidth = layout.getTileWidth(null);
if(layoutObserved != null) {
layoutObserved.setTileWidth(tileWidth);
}
} else if(sm != null) {
tileWidth = sm.getWidth();
}
if(layout.isValid(ImageLayout.TILE_HEIGHT_MASK)) {
tileHeight = layout.getTileHeight(null);
if(layoutObserved != null) {
layoutObserved.setTileHeight(tileHeight);
}
} else if(sm != null) {
tileHeight = sm.getHeight();
}
// Set the observed hints layout.
hintsObserved.put(JAI.KEY_IMAGE_LAYOUT, layoutObserved);
} // layout != null
} // hints != null
// Ensure that the SampleModel is compatible with the tile size.
if(sm != null &&