RenderedImage source,
int leftPad,
int rightPad,
int topPad,
int bottomPad) {
ImageLayout il = layout == null ?
new ImageLayout() : (ImageLayout)layout.clone();
// Set the image bounds according to the padding.
il.setMinX(source.getMinX() - leftPad);
il.setMinY(source.getMinY() - topPad);
il.setWidth(source.getWidth() + leftPad + rightPad);
il.setHeight(source.getHeight() + topPad + bottomPad);
// Set tile grid offset to minimize the probability that a
// tile's bounds does not intersect the source image bounds.
if(!il.isValid(ImageLayout.TILE_GRID_X_OFFSET_MASK)) {
il.setTileGridXOffset(il.getMinX(null));
}
if (!il.isValid(ImageLayout.TILE_GRID_Y_OFFSET_MASK)) {
il.setTileGridYOffset(il.getMinY(null));
}
// Force inheritance of source image SampleModel and ColorModel.
il.setSampleModel(source.getSampleModel());
il.setColorModel(source.getColorModel());
return il;
}