return;
}
// BufferedImage case: use a simple drawImage call
if (img instanceof BufferedImage) {
BufferedImage bufImg = (BufferedImage)img;
drawImage(bufImg,xform,null);
return;
}
// transformState tracks the state of transform and
// transX, transY contain the integer casts of the
// translation factors
boolean isIntegerTranslate =
(transformState <= TRANSFORM_INT_TRANSLATE) &&
isIntegerTranslation(xform);
// Include padding for interpolation/antialiasing if necessary
int pad = isIntegerTranslate ? 0 : 3;
// Determine the region of the image that may contribute to
// the clipped drawing area
Rectangle region = getImageRegion(img,
getCompClip(),
transform,
xform,
pad, pad);
if (region.width <= 0 || region.height <= 0) {
return;
}
// Attempt to optimize integer translation of tiled images.
// Although theoretically we are O.K. if the concatenation of
// the user transform and the device transform is an integer
// translation, we'll play it safe and only optimize the case
// where both are integer translations.
if (isIntegerTranslate) {
// Use optimized code
// Note that drawTranslatedRenderedImage calls copyImage
// which takes the user space to device space transform into
// account, but we need to provide the image space to user space
// translations.
drawTranslatedRenderedImage(img, region,
(int) xform.getTranslateX(),
(int) xform.getTranslateY());
return;
}
// General case: cobble the necessary region into a single Raster
Raster raster = img.getData(region);
// Make a new Raster with the same contents as raster
// but starting at (0, 0). This raster is thus in the same
// coordinate system as the SampleModel of the original raster.
WritableRaster wRaster =
Raster.createWritableRaster(raster.getSampleModel(),
raster.getDataBuffer(),
null);
// If the original raster was in a different coordinate
// system than its SampleModel, we need to perform an
// additional translation in order to get the (minX, minY)
// pixel of raster to be pixel (0, 0) of wRaster. We also
// have to have the correct width and height.
int minX = raster.getMinX();
int minY = raster.getMinY();
int width = raster.getWidth();
int height = raster.getHeight();
int px = minX - raster.getSampleModelTranslateX();
int py = minY - raster.getSampleModelTranslateY();
if (px != 0 || py != 0 || width != wRaster.getWidth() ||
height != wRaster.getHeight()) {
wRaster =
wRaster.createWritableChild(px,
py,
width,
height,
0, 0,
null);
}
// Now we have a BufferedImage starting at (0, 0)
// with the same contents that started at (minX, minY)
// in raster. So we must draw the BufferedImage with a
// translation of (minX, minY).
AffineTransform transXform = (AffineTransform)xform.clone();
transXform.translate(minX, minY);
ColorModel cm = img.getColorModel();
BufferedImage bufImg = new BufferedImage(cm,
wRaster,
cm.isAlphaPremultiplied(),
null);
drawImage(bufImg, transXform, null);
}