if (imageBounds.isEmpty()) {
// return back a constant image
return null;
}
// crop
ImageWorker iw = new ImageWorker(mosaic);
iw.setRenderingHints(localHints);
iw.crop(imageBounds.x, imageBounds.y, imageBounds.width, imageBounds.height);
mosaic = iw.getRenderedImage();
imageBounds = PlanarImage.wrapRenderedImage(mosaic).getBounds();
}
// and, do we need to add a BORDER around the image?
if (!imageBounds.contains(rasterBounds)) {
mosaic = MergeBehavior.FLAT
.process(
new RenderedImage[] { mosaic },
backgroundValues,
sourceThreshold,
(hasAlpha || doInputTransparency) ? new PlanarImage[] { in.alphaChannel }: new PlanarImage[] { null },
new ROI[] { in.roi },
request.isBlend() ? MosaicDescriptor.MOSAIC_TYPE_BLEND: MosaicDescriptor.MOSAIC_TYPE_OVERLAY,
localHints);
roi=roi.add(new ROIGeometry(JTS.toGeometry(new ReferencedEnvelope(rasterBounds, null))));
if (footprintBehavior!=FootprintBehavior.None) {
// Adding globalRoi to the output
RenderedOp rop = (RenderedOp) mosaic;
rop.setProperty("ROI", in.roi);
}
}
// add to final list
return new MosaicElement(in.alphaChannel, roi, mosaic, pamDataset);
}
}
}
}
// === do the mosaic as usual
// prepare sources for the mosaic operation
final RenderedImage[] sources = new RenderedImage[size];
final PlanarImage[] alphas = new PlanarImage[size];
ROI[] rois = new ROI[size];
final PAMDataset[] pams = new PAMDataset[size];
int realROIs=0;
for (int i = 0; i < size; i++) {
final MosaicElement mosaicElement = inputs.get(i);
sources[i] = mosaicElement.source;
alphas[i] = mosaicElement.alphaChannel;
rois[i] = mosaicElement.roi;
pams[i] = mosaicElement.pamDataset;
// compose the overall ROI if needed
if (mosaicElement.roi != null) {
realROIs++;
}
}
if (realROIs == 0){
rois = null;
}
// execute mosaic
final RenderedImage mosaic =
mergeBehavior.process(
sources,
backgroundValues,
sourceThreshold,
(hasAlpha || doInputTransparency) ? alphas : null,
rois,
request.isBlend() ? MosaicDescriptor.MOSAIC_TYPE_BLEND: MosaicDescriptor.MOSAIC_TYPE_OVERLAY,
localHints);
ROI overallROI = mosaicROIs(rois);
if (footprintBehavior != FootprintBehavior.None) {
// Adding globalRoi to the output
RenderedOp rop = (RenderedOp) mosaic;
rop.setProperty("ROI", overallROI);
}
final RenderedImage postProcessed = footprintBehavior.postProcessMosaic(mosaic, overallROI,localHints);
// prepare for next step
if(hasAlpha || doInputTransparency){
return new MosaicElement(new ImageWorker(postProcessed).retainLastBand().getPlanarImage(), overallROI, postProcessed, Utils.mergePamDatasets(pams));
} else {
return new MosaicElement(null, overallROI, postProcessed, Utils.mergePamDatasets(pams));
}
}