static { // getting default hints final Hints defaultHints = GeoTools.getDefaultHints(); // check if someone asked us to use a specific precision model final Object o = defaultHints.get(Hints.JTS_PRECISION_MODEL); final PrecisionModel pm; if (o != null) pm = (PrecisionModel) o; else { pm = new PrecisionModel(); } GFACTORY = new GeometryFactory(pm, 0); // Register manually the GTCrop operation, in web containers JAI registration may fails GTCropDescriptor.register(); }
/** * Overrides to use the same method to slice the tiles than {@code MetatileMapOutputFormat} so the * GeoServer settings such as use native accel are leveraged in the same way when calling {@link * RenderedImageMapResponse#formatImageOutputStream}, * * @see org.geowebcache.layer.MetaTile#createTile(int, int, int, int) */ @Override public RenderedImage createTile( final int x, final int y, final int tileWidth, final int tileHeight) { // check image type final int type; if (metaTileImage instanceof PlanarImage) { type = 1; } else if (metaTileImage instanceof BufferedImage) { type = 2; } else { type = 0; } // now do the splitting RenderedImage tile; switch (type) { case 0: // do a crop, and then turn it into a buffered image so that we can release // the image chain RenderedOp cropped = GTCropDescriptor.create( metaTileImage, Float.valueOf(x), Float.valueOf(y), Float.valueOf(tileWidth), Float.valueOf(tileHeight), NO_CACHE); tile = cropped.getAsBufferedImage(); disposeLater(cropped); break; case 1: final PlanarImage pImage = (PlanarImage) metaTileImage; final WritableRaster wTile = WritableRaster.createWritableRaster( pImage.getSampleModel().createCompatibleSampleModel(tileWidth, tileHeight), new Point(x, y)); Rectangle sourceArea = new Rectangle(x, y, tileWidth, tileHeight); 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: final BufferedImage image = (BufferedImage) metaTileImage; tile = image.getSubimage(x, y, tileWidth, tileHeight); break; default: throw new IllegalStateException( Errors.format( ErrorKeys.ILLEGAL_ARGUMENT_$2, "metaTile class", metaTileImage.getClass().toString())); } return tile; }