RenderedImage src = args.getRenderedSource(0);
Integer datatype = (Integer)args.getObjectParameter(0);
int type = datatype.intValue();
// Get ImageLayout from renderHints if any.
ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
// If there is no change return the source image directly.
if(layout == null && type == src.getSampleModel().getDataType()) {
return src;
}
// Create or clone the ImageLayout.
if(layout == null) {
layout = new ImageLayout(src);
} else {
layout = (ImageLayout)layout.clone();
}
boolean isDataTypeChange = false;
// Get prospective destination SampleModel.
SampleModel sampleModel = layout.getSampleModel(src);
// Create a new SampleModel if the type is not as desired.
if (sampleModel.getDataType() != type) {
int tileWidth = layout.getTileWidth(src);
int tileHeight = layout.getTileHeight(src);
int numBands = src.getSampleModel().getNumBands();
SampleModel csm =
RasterFactory.createComponentSampleModel(sampleModel,
type,
tileWidth,
tileHeight,
numBands);
layout.setSampleModel(csm);
isDataTypeChange = true;
}
// Check ColorModel.
ColorModel colorModel = layout.getColorModel(null);
if(colorModel != null &&
!JDKWorkarounds.areCompatibleDataModels(layout.getSampleModel(src),
colorModel)) {
// Clear the mask bit if incompatible.
layout.unsetValid(ImageLayout.COLOR_MODEL_MASK);
}
// Check whether anything but the ColorModel is changing.
if (layout.getSampleModel(src) == src.getSampleModel() &&
layout.getMinX(src) == src.getMinX() &&
layout.getMinY(src) == src.getMinY() &&
layout.getWidth(src) == src.getWidth() &&
layout.getHeight(src) == src.getHeight() &&
layout.getTileWidth(src) == src.getTileWidth() &&
layout.getTileHeight(src) == src.getTileHeight() &&
layout.getTileGridXOffset(src) == src.getTileGridXOffset() &&
layout.getTileGridYOffset(src) == src.getTileGridYOffset()) {
if(layout.getColorModel(src) == src.getColorModel()) {
// Nothing changed: return the source directly.
return src;
} else {
// Remove TileCache hint from RenderingHints if present.
RenderingHints hints = renderHints;