Commit 5cab962c authored by Andrea Aime's avatar Andrea Aime
Browse files

[GEOS-7302] Using on the fly meta tiling in WMS request may result in rendered...

[GEOS-7302] Using on the fly meta tiling in WMS request may result in rendered images not being disposed of
parent af9d12be
......@@ -102,5 +102,13 @@ public class RasterCleaner extends AbstractDispatcherCallback {
list.clear();
}
}
public List<RenderedImage> getImages() {
return images.get();
}
public List<GridCoverage2D> getCoverages() {
return coverages.get();
}
}
......@@ -32,7 +32,6 @@ import org.geoserver.wms.WebMap;
import org.geoserver.wms.map.QuickTileCache.MetaTileKey;
import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.filter.function.EnvFunction;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.renderer.lite.gridcoverage2d.GridCoverageRenderer;
import org.geotools.resources.i18n.ErrorKeys;
import org.geotools.resources.i18n.Errors;
......@@ -164,7 +163,7 @@ public final class MetatileMapOutputFormat implements GetMapOutputFormat {
RenderedImageMap metaTileMap = delegate.produceMap(mapContent);
RenderedImage metaTile = metaTileMap.getImage();
RenderedImage[] tiles = split(key, metaTile, mapContent);
RenderedImage[] tiles = split(key, metaTile);
tileCache.storeTiles(key, tiles);
tile = tileCache.getTile(key, request, tiles);
renderedCoverages = metaTileMap.getRenderedCoverages();
......@@ -225,10 +224,9 @@ public final class MetatileMapOutputFormat implements GetMapOutputFormat {
*
* @param key
* @param metaTile
* @param map
* @return
*/
private static RenderedImage[] split(MetaTileKey key, RenderedImage metaTile, WMSMapContent map) {
static RenderedImage[] split(MetaTileKey key, RenderedImage metaTile) {
final int metaFactor = key.getMetaFactor();
final RenderedImage[] tiles = new RenderedImage[key.getMetaFactor() * key.getMetaFactor()];
final int tileSize = key.getTileSize();
......@@ -245,66 +243,71 @@ public final class MetatileMapOutputFormat implements GetMapOutputFormat {
}
// now do the splitting
if(DEBUG){
writeRenderedImage(metaTile,"metaTile");
}
for (int i = 0; i < metaFactor; i++) {
for (int j = 0; j < metaFactor; j++) {
int x = j * tileSize;
int y = (tileSize * (metaFactor - 1)) - (i * tileSize);
RenderedImage tile;
switch (type) {
case 0:
// RENDERED IMAGE
if(LOGGER.isLoggable(Level.FINER)){
LOGGER.finer("Metatile split on RenderedImage");
}
metaTile=PlanarImage.wrapRenderedImage(metaTile);
RasterCleaner.addImage(metaTile);
case 1:
// PLANAR IMAGE
if(LOGGER.isLoggable(Level.FINER)){
LOGGER.finer("Metatile split on PlanarImage");
}
final PlanarImage pImage = (PlanarImage) metaTile;
final WritableRaster wTile = WritableRaster.createWritableRaster(
pImage.getSampleModel().createCompatibleSampleModel(tileSize, tileSize),
new Point(x, y));
Rectangle sourceArea = new Rectangle(x, y, tileSize, tileSize);
sourceArea = sourceArea.intersection(pImage.getBounds());
// copying the data to ensure we don't have side effects when we clean the cache
pImage.copyData(wTile);
if(wTile.getMinX()!=0||wTile.getMinY()!=0) {
tile = new BufferedImage(pImage.getColorModel(), (WritableRaster) wTile.createTranslatedChild(0, 0), pImage.getColorModel().isAlphaPremultiplied(), null);
} else {
tile = new BufferedImage(pImage.getColorModel(), wTile, pImage.getColorModel().isAlphaPremultiplied(), null);
try {
if (DEBUG) {
writeRenderedImage(metaTile, "metaTile");
}
for (int i = 0; i < metaFactor; i++) {
for (int j = 0; j < metaFactor; j++) {
int x = j * tileSize;
int y = (tileSize * (metaFactor - 1)) - (i * tileSize);
RenderedImage tile;
switch (type) {
case 0:
// RENDERED IMAGE
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer("Metatile split on RenderedImage");
}
metaTile = PlanarImage.wrapRenderedImage(metaTile);
case 1:
// PLANAR IMAGE
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer("Metatile split on PlanarImage");
}
final PlanarImage pImage = (PlanarImage) metaTile;
final WritableRaster wTile = WritableRaster.createWritableRaster(pImage
.getSampleModel().createCompatibleSampleModel(tileSize, tileSize),
new Point(x, y));
Rectangle sourceArea = new Rectangle(x, y, tileSize, tileSize);
sourceArea = sourceArea.intersection(pImage.getBounds());
// copying the data to ensure we don't have side effects when we clean the cache
pImage.copyData(wTile);
if (wTile.getMinX() != 0 || wTile.getMinY() != 0) {
tile = new BufferedImage(pImage.getColorModel(),
(WritableRaster) wTile.createTranslatedChild(0, 0),
pImage.getColorModel().isAlphaPremultiplied(), null);
} else {
tile = new BufferedImage(pImage.getColorModel(), wTile,
pImage.getColorModel().isAlphaPremultiplied(), null);
}
break;
case 2:
// BUFFERED IMAGE
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer("Metatile split on BufferedImage");
}
final BufferedImage image = (BufferedImage) metaTile;
tile = image.getSubimage(x, y, tileSize, tileSize);
break;
default:
throw new IllegalStateException(Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$2,
"metaTile class", metaTile.getClass().toString()));
}
break;
case 2:
// BUFFERED IMAGE
if(LOGGER.isLoggable(Level.FINER)){
LOGGER.finer("Metatile split on BufferedImage");
}
final BufferedImage image = (BufferedImage) metaTile;
tile = image.getSubimage(x, y, tileSize, tileSize);
break;
default:
throw new IllegalStateException(Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$2,"metaTile class",metaTile.getClass().toString()));
tiles[(i * key.getMetaFactor()) + j] = tile;
if (DEBUG) {
writeRenderedImage(tile, "tile" + i + "-" + j);
}
}
tiles[(i * key.getMetaFactor()) + j] = tile;
if(DEBUG){
writeRenderedImage(tile, "tile"+i+"-"+j);
}
}
} finally {
// dispose input image if necessary/possible
RasterCleaner.addImage(metaTile);
}
// dispose input image if necessary/possible
RasterCleaner.addImage(metaTile);
return tiles;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment