Search in sources :

Example 21 with SceneDef

use of org.geotoolkit.display2d.service.SceneDef in project geotoolkit by Geomatys.

the class ColorModelTest method testNoDataCM.

@Test
public void testNoDataCM() throws NoSuchAuthorityCodeException, FactoryException, PortrayalException {
    final MapLayers context = MapBuilder.createContext();
    final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.geographic());
    env.setRange(0, -180, 180);
    env.setRange(1, -90, 90);
    final BufferedImage img = DefaultPortrayalService.portray(new CanvasDef(new Dimension(800, 600), env), new SceneDef(context));
    assertTrue(img.getColorModel() instanceof IndexColorModel);
    final IndexColorModel icm = (IndexColorModel) img.getColorModel();
    // we should have only two value
    assertEquals(2, icm.getMapSize());
    // with one being transparent
    assertTrue(icm.getTransparentPixel() >= 0);
}
Also used : SceneDef(org.geotoolkit.display2d.service.SceneDef) Dimension(java.awt.Dimension) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) BufferedImage(java.awt.image.BufferedImage) MapLayers(org.apache.sis.portrayal.MapLayers) IndexColorModel(java.awt.image.IndexColorModel) Test(org.junit.Test)

Example 22 with SceneDef

use of org.geotoolkit.display2d.service.SceneDef in project geotoolkit by Geomatys.

the class ColorModelTest method testRasterData.

@Test
public void testRasterData() throws NoSuchAuthorityCodeException, FactoryException, PortrayalException {
    final MapLayers context = MapBuilder.createContext();
    context.getComponents().add(MapBuilder.createCoverageLayer(coverages.get(0), SF.style(SF.rasterSymbolizer()), "test"));
    final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.geographic());
    env.setRange(0, -180, 180);
    env.setRange(1, -90, 90);
    final CanvasDef cdef = new CanvasDef(new Dimension(800, 600), env);
    cdef.setBackground(Color.WHITE);
    final BufferedImage img = DefaultPortrayalService.portray(cdef, new SceneDef(context));
    // background is opaque we should obtain an RGB color model since raster styles
    // are unpredictable
    assertTrue(!(img.getColorModel() instanceof IndexColorModel));
    assertEquals(ColorSpace.TYPE_RGB, img.getColorModel().getColorSpace().getType());
    assertEquals(3, img.getColorModel().getNumComponents());
    assertEquals(3, img.getColorModel().getNumColorComponents());
}
Also used : SceneDef(org.geotoolkit.display2d.service.SceneDef) Dimension(java.awt.Dimension) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) BufferedImage(java.awt.image.BufferedImage) MapLayers(org.apache.sis.portrayal.MapLayers) IndexColorModel(java.awt.image.IndexColorModel) Test(org.junit.Test)

Example 23 with SceneDef

use of org.geotoolkit.display2d.service.SceneDef in project geotoolkit by Geomatys.

the class ColorModelTest method testOpaqueStyleDatas.

@Test
public void testOpaqueStyleDatas() throws NoSuchAuthorityCodeException, FactoryException, PortrayalException {
    final MapLayers context = MapBuilder.createContext();
    context.getComponents().add(createLayer(Color.BLUE, Color.RED, Color.YELLOW));
    context.getComponents().add(createLayer(Color.BLUE, Color.GREEN, Color.GRAY));
    final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.geographic());
    env.setRange(0, -180, 180);
    env.setRange(1, -90, 90);
    final CanvasDef cdef = new CanvasDef(new Dimension(800, 600), env);
    cdef.setBackground(Color.WHITE);
    final BufferedImage img = DefaultPortrayalService.portray(cdef, new SceneDef(context));
    assertTrue(img.getColorModel() instanceof IndexColorModel);
    final IndexColorModel icm = (IndexColorModel) img.getColorModel();
    assertEquals(Transparency.OPAQUE, icm.getTransparency());
    assertEquals(-1, icm.getTransparentPixel());
    assertFalse(icm.hasAlpha());
    // we should have only six value
    assertEquals(6, icm.getMapSize());
    final Set<Integer> colors = new HashSet<Integer>();
    colors.add(Color.WHITE.getRGB());
    colors.add(Color.BLUE.getRGB());
    colors.add(Color.RED.getRGB());
    colors.add(Color.YELLOW.getRGB());
    colors.add(Color.GREEN.getRGB());
    colors.add(Color.GRAY.getRGB());
    for (int i = 0; i < icm.getMapSize(); i++) {
        assertTrue(colors.contains(icm.getRGB(i)));
    }
}
Also used : SceneDef(org.geotoolkit.display2d.service.SceneDef) Dimension(java.awt.Dimension) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) BufferedImage(java.awt.image.BufferedImage) Point(org.locationtech.jts.geom.Point) MapLayers(org.apache.sis.portrayal.MapLayers) IndexColorModel(java.awt.image.IndexColorModel) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 24 with SceneDef

use of org.geotoolkit.display2d.service.SceneDef in project geotoolkit by Geomatys.

the class ColorModelTest method testJPEGOutput.

/**
 * Test that when asking a jpeg output, the resulting writen image has been
 * configured with a white background.
 */
@Test
public void testJPEGOutput() throws NoSuchAuthorityCodeException, FactoryException, IOException, PortrayalException {
    final MapLayers context = MapBuilder.createContext();
    final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.geographic());
    env.setRange(0, -180, 180);
    env.setRange(1, -90, 90);
    File tempFile = File.createTempFile("testjpeg", ".jpg");
    tempFile.deleteOnExit();
    final CanvasDef cdef = new CanvasDef(new Dimension(800, 600), env);
    DefaultPortrayalService.portray(cdef, new SceneDef(context), new OutputDef("image/jpeg", tempFile));
    // we should obtain a white background image
    final BufferedImage img = ImageIO.read(tempFile);
    for (int x = 0; x < img.getWidth(); x++) {
        for (int y = 0; y < img.getHeight(); y++) {
            // jpeg can't encode a perfect white image, CMY to RGB conversion lost I guess.
            Color c = new Color(img.getRGB(x, y));
            Assert.assertBetween("color is not white", 250, 255, c.getRed());
            Assert.assertBetween("color is not white", 250, 255, c.getGreen());
            Assert.assertBetween("color is not white", 250, 255, c.getBlue());
            Assert.assertBetween("color is not white", 250, 255, c.getAlpha());
        }
    }
}
Also used : Color(java.awt.Color) SceneDef(org.geotoolkit.display2d.service.SceneDef) Dimension(java.awt.Dimension) OutputDef(org.geotoolkit.display2d.service.OutputDef) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) File(java.io.File) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) BufferedImage(java.awt.image.BufferedImage) Point(org.locationtech.jts.geom.Point) MapLayers(org.apache.sis.portrayal.MapLayers) Test(org.junit.Test)

Example 25 with SceneDef

use of org.geotoolkit.display2d.service.SceneDef in project geotoolkit by Geomatys.

the class TileDebugTest method renderTileDebugTest.

/**
 * Sanity test, only ensure the rendering is successfull without errors not the final result.
 */
@Test
public void renderTileDebugTest() throws PortrayalException, FactoryException, DataStoreException {
    final CoordinateReferenceSystem crs = CRS.forCode("EPSG:2154");
    final TileDebugSymbolizer gs = new TileDebugSymbolizer();
    final MutableStyle style = GO2Utilities.STYLE_FACTORY.style(gs);
    final InMemoryTiledGridCoverageResource resource = new InMemoryTiledGridCoverageResource(Names.createLocalName(null, null, "test"));
    resource.createTileMatrixSet(TileMatrices.createWorldWGS84Template(12));
    final MapLayer layer = MapBuilder.createCoverageLayer(resource);
    layer.setStyle(style);
    final MapLayers context = MapBuilder.createContext();
    context.getComponents().add(layer);
    final SceneDef sdef = new SceneDef(context);
    final CanvasDef cdef = new CanvasDef();
    cdef.setDimension(new Dimension(100, 100));
    cdef.setBackground(Color.darkGray);
    cdef.setEnvelope(CRS.getDomainOfValidity(crs));
    final BufferedImage img = DefaultPortrayalService.portray(cdef, sdef);
    Assert.assertNotNull(img);
}
Also used : InMemoryTiledGridCoverageResource(org.geotoolkit.storage.memory.InMemoryTiledGridCoverageResource) MutableStyle(org.geotoolkit.style.MutableStyle) MapLayer(org.apache.sis.portrayal.MapLayer) SceneDef(org.geotoolkit.display2d.service.SceneDef) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Dimension(java.awt.Dimension) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) BufferedImage(java.awt.image.BufferedImage) MapLayers(org.apache.sis.portrayal.MapLayers) Test(org.junit.Test)

Aggregations

CanvasDef (org.geotoolkit.display2d.service.CanvasDef)28 SceneDef (org.geotoolkit.display2d.service.SceneDef)28 MapLayers (org.apache.sis.portrayal.MapLayers)26 Test (org.junit.Test)23 Dimension (java.awt.Dimension)21 BufferedImage (java.awt.image.BufferedImage)21 GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)15 MapLayer (org.apache.sis.portrayal.MapLayer)11 IndexColorModel (java.awt.image.IndexColorModel)10 GridCoverage2D (org.apache.sis.coverage.grid.GridCoverage2D)7 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)7 Hints (org.geotoolkit.factory.Hints)7 Point (org.locationtech.jts.geom.Point)7 Feature (org.opengis.feature.Feature)7 FeatureType (org.opengis.feature.FeatureType)7 File (java.io.File)6 MutableStyle (org.geotoolkit.style.MutableStyle)6 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)6 RenderingHints (java.awt.RenderingHints)5 SampleDimension (org.apache.sis.coverage.SampleDimension)5