if(invalidBounds.isEmpty()) {
return;
}
// Intersect with ROI.
Area invalidArea = new Area(invalidRegion);
if(srcROI != null) {
Shape roiShape = srcROI.getAsShape();
if(roiShape != null) {
invalidArea.intersect(new Area(roiShape));
} else {
LinkedList rectList =
srcROI.getAsRectangleList(invalidBounds.x,
invalidBounds.y,
invalidBounds.width,
invalidBounds.height);
Iterator it = rectList.iterator();
while(it.hasNext() && !invalidArea.isEmpty()) {
invalidArea.intersect(new Area((Rectangle)it.next()));
}
}
}
// If empty, all is valid.
if(invalidArea.isEmpty()) {
return;
}
// Determine all possible overlapping tiles.
Point[] tileIndices = getTileIndices(invalidArea.getBounds());
int numIndices = tileIndices.length;
// Clear any tiles which intersect the invalid area.
for(int i = 0; i < numIndices; i++) {
int tx = tileIndices[i].x;
int ty = tileIndices[i].y;
Raster tile = tiles[tx][ty];
if ((tile != null) &&
invalidArea.intersects(tile.getBounds())) {
tiles[tx][ty] = null;
}
}
if(eventManager.hasListeners("InvalidRegion")) {
// Determine the old invalid region.
Shape oldInvalidRegion = new Rectangle(); // default is empty.
// If there is a ROI, the old invalid region is the
// complement of the ROI within the image bounds.
if(srcROI != null) {
Area oldInvalidArea = new Area(getBounds());
Shape roiShape = srcROI.getAsShape();
if(roiShape != null) {
oldInvalidArea.subtract(new Area(roiShape));
} else {
Rectangle oldInvalidBounds =
oldInvalidArea.getBounds();
LinkedList rectList =
srcROI.getAsRectangleList(oldInvalidBounds.x,
oldInvalidBounds.y,
oldInvalidBounds.width,
oldInvalidBounds.height);
Iterator it = rectList.iterator();
while(it.hasNext() && !oldInvalidArea.isEmpty()) {
oldInvalidArea.subtract(new Area((Rectangle)it.next()));
}
}
oldInvalidRegion = oldInvalidArea;
}