List of usage examples for java.awt.image RenderedImage getData
Raster getData();
From source file:org.esa.nest.gpf.oceantools.WindFieldEstimationOp.java
private static double getPeakSpectrumValue(final RenderedImage filteredImage, final double[][] array, final int n3) { final Raster data = filteredImage.getData(); double peakValue = 0.0; final int length = 2 * n3 + 1; for (int y = 0; y < length; y++) { for (int x = 0; x < length; x++) { array[y][x] = data.getSampleDouble(x, y, 0); if (peakValue < array[y][x]) { peakValue = array[y][x]; }//from w w w . jav a2s. c o m } } return peakValue; }
From source file:org.esa.s2tbx.dataio.jp2.internal.JP2TileOpImage.java
private void computeRectIndirect(WritableRaster dest, Rectangle destRect) { try {/*from w w w .j a va 2 s .c o m*/ Path tile = decompressTile(tileIndex, getLevel()); RenderedImage readTileImage = null; if (tile != null) { try (ImageReader imageReader = new ImageReader(tile)) { final DataBuffer dataBuffer = dest.getDataBuffer(); int tileWidth = this.getTileWidth(); int tileHeight = this.getTileHeight(); final int fileTileX = destRect.x / tileLayout.tileWidth; final int fileTileY = destRect.y / tileLayout.tileHeight; int fileTileOriginX = destRect.x - fileTileX * tileLayout.tileWidth; int fileTileOriginY = destRect.y - fileTileY * tileLayout.tileHeight; Rectangle fileTileRect = tileDims.get(tile); if (fileTileRect == null) { fileTileRect = new Rectangle(0, 0, imageReader.getImageWidth(), imageReader.getImageHeight()); tileDims.put(tile, fileTileRect); } if (fileTileOriginX == 0 && tileLayout.tileWidth == tileWidth && fileTileOriginY == 0 && tileLayout.tileHeight == tileHeight && tileWidth * tileHeight == dataBuffer.getSize()) { readTileImage = imageReader.read(); } else { final Rectangle tileRect = new Rectangle(fileTileOriginX, fileTileOriginY, tileWidth, tileHeight); final Rectangle intersection = fileTileRect.intersection(tileRect); if (!intersection.isEmpty()) { readTileImage = imageReader.read(intersection); } } if (readTileImage != null) { Raster readBandRaster = readTileImage.getData().createChild(0, 0, readTileImage.getWidth(), readTileImage.getHeight(), 0, 0, new int[] { bandIndex }); dest.setDataElements(dest.getMinX(), dest.getMinY(), readBandRaster); } } catch (IOException e) { logger.severe(e.getMessage()); } } } catch (IOException e) { logger.severe(e.getMessage()); } }
From source file:org.geoserver.wcs.GetCoverageTest.java
@Test public void testRasterFilterGreen() throws Exception { String queryString = "wcs?identifier=" + getLayerId(MOSAIC) + "&request=getcoverage" + "&service=wcs&version=1.1.1&&format=image/tiff" + "&BoundingBox=0,0,1,1,urn:ogc:def:crs:EPSG:6.6:4326" + "&CQL_FILTER=location like 'green%25'"; MockHttpServletResponse response = getAsServletResponse(queryString); // parse the multipart, check there are two parts Multipart multipart = getMultipart(response); assertEquals(2, multipart.getCount()); BodyPart coveragePart = multipart.getBodyPart(1); assertEquals("image/tiff", coveragePart.getContentType()); assertEquals("<theCoverage>", coveragePart.getHeader("Content-ID")[0]); // make sure we can read the coverage back ImageReader reader = ImageIO.getImageReadersByFormatName("tiff").next(); reader.setInput(ImageIO.createImageInputStream(coveragePart.getInputStream())); RenderedImage image = reader.read(0); // check the pixel int[] pixel = new int[3]; image.getData().getPixel(0, 0, pixel); assertEquals(0, pixel[0]);// w w w . j a va 2 s .c o m assertEquals(255, pixel[1]); assertEquals(0, pixel[2]); }
From source file:org.geoserver.wcs.GetCoverageTest.java
@Test public void testRasterFilterRed() throws Exception { String queryString = "wcs?identifier=" + getLayerId(MOSAIC) + "&request=getcoverage" + "&service=wcs&version=1.1.1&&format=image/tiff" + "&BoundingBox=0,0,1,1,urn:ogc:def:crs:EPSG:6.6:4326" + "&CQL_FILTER=location like 'red%25'"; MockHttpServletResponse response = getAsServletResponse(queryString); // parse the multipart, check there are two parts Multipart multipart = getMultipart(response); assertEquals(2, multipart.getCount()); BodyPart coveragePart = multipart.getBodyPart(1); assertEquals("image/tiff", coveragePart.getContentType()); assertEquals("<theCoverage>", coveragePart.getHeader("Content-ID")[0]); // make sure we can read the coverage back ImageReader reader = ImageIO.getImageReadersByFormatName("tiff").next(); reader.setInput(ImageIO.createImageInputStream(coveragePart.getInputStream())); RenderedImage image = reader.read(0); // check the pixel int[] pixel = new int[3]; image.getData().getPixel(0, 0, pixel); assertEquals(255, pixel[0]);/*from ww w . ja v a 2 s . co m*/ assertEquals(0, pixel[1]); assertEquals(0, pixel[2]); }
From source file:org.geoserver.wms.map.RenderedImageMapOutputFormatTest.java
/** * Test to check if we can successfully create a direct rendered image by using * a coverage view as a source, and a symbolizer defining which three bands of the * input coverage view can be used for RGB coloring, and with what order. *///from w w w. j a v a 2 s . com @Test public void testStyleUsingChannelsFromCoverageView() throws Exception { GetMapRequest request = new GetMapRequest(); CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84; ReferencedEnvelope bbox = new ReferencedEnvelope(new Envelope(-116.90673461649858211, -114.30988665660261461, 32.07093728218402617, 33.89032847348440214), crs); request.setBbox(bbox); request.setSRS("urn:x-ogc:def:crs:EPSG:4326"); request.setFormat("image/png"); final WMSMapContent map = new WMSMapContent(request); map.setMapWidth(300); map.setMapHeight(300); map.setTransparent(false); map.getViewport().setBounds(bbox); StyleBuilder styleBuilder = new StyleBuilder(); Catalog catalog = getCatalog(); // Source image CoverageInfo ci = catalog.getCoverageByName(SystemTestData.MULTIBAND.getPrefix(), SystemTestData.MULTIBAND.getLocalPart()); GridCoverage2DReader reader = (GridCoverage2DReader) ci.getGridCoverageReader(null, null); reader.getCoordinateReferenceSystem(); Layer sl = new CachedGridReaderLayer(reader, styleBuilder.createStyle(styleBuilder.createRasterSymbolizer())); map.addLayer(sl); RenderedImageMap srcImageMap = this.rasterMapProducer.produceMap(map); RenderedImage srcImage = srcImageMap.getImage(); // CoverageView band creation. We create a coverage view with 6 bands, using // the original bands from the multiband coverage //Note that first three bands are int reverse order of the bands of the source coverage final InputCoverageBand ib0 = new InputCoverageBand("multiband", "2"); final CoverageBand b0 = new CoverageBand(Collections.singletonList(ib0), "multiband@2", 0, CompositionType.BAND_SELECT); final InputCoverageBand ib1 = new InputCoverageBand("multiband", "1"); final CoverageBand b1 = new CoverageBand(Collections.singletonList(ib1), "multiband@1", 1, CompositionType.BAND_SELECT); final InputCoverageBand ib2 = new InputCoverageBand("multiband", "0"); final CoverageBand b2 = new CoverageBand(Collections.singletonList(ib2), "multiband@0", 2, CompositionType.BAND_SELECT); final InputCoverageBand ib3 = new InputCoverageBand("multiband", "0"); final CoverageBand b3 = new CoverageBand(Collections.singletonList(ib3), "multiband@0", 0, CompositionType.BAND_SELECT); final InputCoverageBand ib4 = new InputCoverageBand("multiband", "1"); final CoverageBand b4 = new CoverageBand(Collections.singletonList(ib4), "multiband@1", 1, CompositionType.BAND_SELECT); final InputCoverageBand ib5 = new InputCoverageBand("multiband", "2"); final CoverageBand b5 = new CoverageBand(Collections.singletonList(ib5), "multiband@2", 2, CompositionType.BAND_SELECT); final List<CoverageBand> coverageBands = new ArrayList<CoverageBand>(1); coverageBands.add(b0); coverageBands.add(b1); coverageBands.add(b2); coverageBands.add(b3); coverageBands.add(b4); coverageBands.add(b5); CoverageView multiBandCoverageView = new CoverageView("multiband_select", coverageBands); CoverageStoreInfo storeInfo = catalog.getCoverageStoreByName("multiband"); CatalogBuilder builder = new CatalogBuilder(catalog); // Reordered bands coverage CoverageInfo coverageInfo = multiBandCoverageView.createCoverageInfo("multiband_select", storeInfo, builder); coverageInfo.getParameters().put("USE_JAI_IMAGEREAD", "false"); catalog.add(coverageInfo); final LayerInfo layerInfoView = builder.buildLayer(coverageInfo); catalog.add(layerInfoView); final Envelope env = ci.boundingBox(); LOGGER.info("about to create map ctx for BasicPolygons with bounds " + env); RasterSymbolizer symbolizer = styleBuilder.createRasterSymbolizer(); ChannelSelection cs = new ChannelSelectionImpl(); SelectedChannelType red = new SelectedChannelTypeImpl(); SelectedChannelType green = new SelectedChannelTypeImpl(); SelectedChannelType blue = new SelectedChannelTypeImpl(); // We want to create an image where the RGB channels are in reverse order // regarding the band order of the input coverage view // Note that channel names start with index "1" red.setChannelName("3"); green.setChannelName("2"); blue.setChannelName("1"); cs.setRGBChannels(new SelectedChannelType[] { red, green, blue }); symbolizer.setChannelSelection(cs); reader = (GridCoverage2DReader) coverageInfo.getGridCoverageReader(null, null); reader.getCoordinateReferenceSystem(); Layer dl = new CachedGridReaderLayer(reader, styleBuilder.createStyle(symbolizer)); map.removeLayer(sl); map.addLayer(dl); RenderedImageMap dstImageMap = this.rasterMapProducer.produceMap(map); RenderedImage destImage = dstImageMap.getImage(); int dWidth = destImage.getWidth(); int dHeight = destImage.getHeight(); int[] destImageRowBand0 = new int[dWidth * dHeight]; int[] destImageRowBand1 = new int[destImageRowBand0.length]; int[] destImageRowBand2 = new int[destImageRowBand0.length]; destImage.getData().getSamples(0, 0, dWidth, dHeight, 0, destImageRowBand0); destImage.getData().getSamples(0, 0, dWidth, dHeight, 1, destImageRowBand1); destImage.getData().getSamples(0, 0, dWidth, dHeight, 2, destImageRowBand2); int sWidth = srcImage.getWidth(); int sHeight = srcImage.getHeight(); int[] srcImageRowBand0 = new int[sWidth * sHeight]; int[] srcImageRowBand2 = new int[srcImageRowBand0.length]; srcImage.getData().getSamples(0, 0, sWidth, sHeight, 0, srcImageRowBand0); // Source and result image first bands should be the same. We have reversed the order // of the three first bands of the source coverage and then we re-reversed the three // first bands using channel selection on the raster symbolizer used for rendering. Assert.assertTrue(Arrays.equals(destImageRowBand0, srcImageRowBand0)); //Result band 0 should not be equal to source image band 2 Assert.assertFalse(Arrays.equals(destImageRowBand0, srcImageRowBand2)); srcImageMap.dispose(); dstImageMap.dispose(); map.dispose(); }
From source file:org.geoserver.wms.wms_1_1_1.GetMapIntegrationTest.java
@Test public void testEnvDefault() throws Exception { MockHttpServletResponse response = getAsServletResponse( "wms?bbox=" + bbox + "&styles=parametric&layers=" + layers + "&Format=image/png" + "&request=GetMap" + "&width=550" + "&height=250" + "&srs=EPSG:4326"); assertEquals("image/png", response.getContentType()); RenderedImage image = ImageIO.read(getBinaryInputStream(response)); int[] rgba = new int[3]; // fully black pixel in the middle of the map image.getData().getPixel(250, 125, rgba); //assertEquals(0, rgba[0]); //assertEquals(0, rgba[1]); //assertEquals(0, rgba[2]); }
From source file:org.geoserver.wms.wms_1_1_1.GetMapIntegrationTest.java
@Test public void testEnvRed() throws Exception { MockHttpServletResponse response = getAsServletResponse( "wms?bbox=" + bbox + "&styles=parametric&layers=" + layers + "&Format=image/png" + "&request=GetMap" + "&width=550" + "&height=250" + "&srs=EPSG:4326&env=color:0xFF0000"); assertEquals("image/png", response.getContentType()); RenderedImage image = ImageIO.read(getBinaryInputStream(response)); int[] rgba = new int[3]; // fully red pixel in the middle of the map image.getData().getPixel(250, 125, rgba); //assertEquals(255, rgba[0]); //assertEquals(0, rgba[1]); //assertEquals(0, rgba[2]); }
From source file:org.sensorML.process.WMS_Process.java
/** * Executes process algorithm on inputs and set output data *//* w w w . ja v a 2 s .c om*/ public void execute() throws ProcessException { RenderedImage renderedImage = null; try { initRequest(); //switchBytes(); if (log.isDebugEnabled()) log.debug(owsUtils.buildURLQuery(request)); URLConnection urlCon = owsUtils.sendGetRequest(request); // Check on mimeType catches all three types (blank, inimage, xml) // of OGC service exceptions String mimeType = urlCon.getContentType(); if (mimeType.contains("xml") || mimeType.startsWith("application")) { OGCExceptionReader reader = new OGCExceptionReader(); reader.parseException(urlCon.getInputStream()); } else { // use JAI MemorySeekableStream for better performance dataStream = new MemoryCacheSeekableStream(urlCon.getInputStream()); // Create the ParameterBlock and add the SeekableStream to it. ParameterBlock pb = new ParameterBlock(); pb.add(dataStream); // decode image using JAI RenderedOp rop = JAI.create("stream", pb); if (rop != null) { renderedImage = rop.createInstance(); // put data buffer in output datablock byte[] data = ((DataBufferByte) renderedImage.getData().getDataBuffer()).getData(); ((DataBlockByte) outputImage.getData()).setUnderlyingObject(data); } } // adjust width and height of the output int width = 0; int height = 0; if (renderedImage != null) { width = renderedImage.getWidth(); height = renderedImage.getHeight(); } outputWidth.getData().setIntValue(width); outputHeight.getData().setIntValue(height); output.combineDataBlocks(); } catch (Exception e) { throw new ProcessException("Error while requesting data from WMS server: " + request.getGetServer(), e); } finally { endRequest(); } }