private TextureTile getTextureTile( double minX, double minY, double maxX, double maxY ) { int width = (int) ( ( maxX - minX ) / res ); int height = (int) ( ( maxY - minY ) / res ); LOG.debug( "Fetching texture tile (" + width + "x" + height + ") via WMSClient." ); Envelope bbox = fac.createEnvelope( minX, minY, maxX, maxY, requestedCRS ); SimpleRaster raster = null; try { raster = getMapAsSimpleRaster( client, layers, width, height, bbox, requestedCRS, requestedFormat, true, true, requestTimeout ).first; LOG.debug( "Success" ); } catch ( IOException e ) { LOG.debug( "Failed: " + e.getMessage(), e ); // this must never happen, cause the above request uses errorsInImage=true throw new RuntimeException( e.getMessage() ); } PixelInterleavedRasterData rasterData = (PixelInterleavedRasterData) raster.getRasterData(); return new TextureTile( minX, minY, maxX, maxY, rasterData.getColumns(), rasterData.getRows(), rasterData.getByteBuffer(), true, true ); }
private void setSubset( PixelInterleavedRasterData targetData, int x0, int y0, int width, int height, RasterData sourceRaster ) { // clamp to maximum possible size int subWidth = min( targetData.getColumns() - x0, width, sourceRaster.getColumns() ); int subHeight = min( targetData.getRows() - y0, height, sourceRaster.getRows() ); byte[] tmp = new byte[targetData.getDataInfo().getDataSize()]; for ( int y = 0; y < subHeight; y++ ) { for ( int x = 0; x < subWidth; x++ ) { byte[] color = new byte[3]; byte[] c = new byte[1]; c = sourceRaster.getSample( x, y, 0, c ); color[0] = c[0]; c = sourceRaster.getSample( x, y, 1, c ); color[1] = c[0]; c = sourceRaster.getSample( x, y, 2, c ); color[2] = c[0]; if ( !shouldBeTransparent( color ) ) { targetData.setSample( x0 + x, y0 + y, 0, sourceRaster.getSample( x, y, 0, tmp ) ); targetData.setSample( x0 + x, y0 + y, 1, sourceRaster.getSample( x, y, 1, tmp ) ); targetData.setSample( x0 + x, y0 + y, 2, sourceRaster.getSample( x, y, 2, tmp ) ); } } } }