Search in sources :

Example 1 with SceneDef

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

the class ColorModelTest method testReprojectionCoverageARGB.

@Test
public void testReprojectionCoverageARGB() throws TransformException, PortrayalException, NoSuchAuthorityCodeException, FactoryException {
    // create a test coverage
    final BufferedImage img = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB);
    final Graphics2D g2d = img.createGraphics();
    g2d.setColor(Color.GREEN);
    g2d.fillRect(0, 0, 500, 500);
    final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.normalizedGeographic());
    env.setRange(0, 0, 20);
    env.setRange(1, 0, 20);
    final GridCoverage coverage = new GridCoverage2D(new GridGeometry(null, env, GridOrientation.HOMOTHETY), null, img);
    // display it
    final MapLayers context = MapBuilder.createContext();
    final MapLayer cl = MapBuilder.createCoverageLayer(coverage, SF.style(StyleConstants.DEFAULT_RASTER_SYMBOLIZER), "coverage");
    context.getComponents().add(cl);
    final Envelope envelope = Envelopes.transform(env, CRS.forCode("EPSG:3031"));
    final CanvasDef cdef = new CanvasDef(new Dimension(800, 600), envelope);
    cdef.setBackground(Color.WHITE);
    final BufferedImage result = DefaultPortrayalService.portray(cdef, new SceneDef(context));
    // background is opaque we should obtain an RGB color model since raster styles
    // are unpredictable
    assertTrue(!(result.getColorModel() instanceof IndexColorModel));
    assertEquals(ColorSpace.TYPE_RGB, result.getColorModel().getColorSpace().getType());
    assertEquals(3, result.getColorModel().getNumComponents());
    assertEquals(3, result.getColorModel().getNumColorComponents());
    // check we don't have any black reprojection pixels
    int[] buffer = new int[4];
    final Raster raster = result.getData();
    for (int x = 0; x < raster.getWidth(); x++) {
        for (int y = 0; y < raster.getHeight(); y++) {
            raster.getPixel(x, y, buffer);
            if (buffer[0] == 0 && buffer[1] == 0 && buffer[2] == 0) {
                // black pixel
                fail("reprojection should not have generated black pixels.");
            }
        }
    }
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) GridCoverage2D(org.apache.sis.coverage.grid.GridCoverage2D) MapLayer(org.apache.sis.portrayal.MapLayer) Raster(java.awt.image.Raster) Dimension(java.awt.Dimension) Envelope(org.opengis.geometry.Envelope) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) BufferedImage(java.awt.image.BufferedImage) Point(org.locationtech.jts.geom.Point) Graphics2D(java.awt.Graphics2D) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) SceneDef(org.geotoolkit.display2d.service.SceneDef) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) MapLayers(org.apache.sis.portrayal.MapLayers) IndexColorModel(java.awt.image.IndexColorModel) Test(org.junit.Test)

Example 2 with SceneDef

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

the class ColorModelTest method testSolidColorBackgroundWithAA.

@Test
public void testSolidColorBackgroundWithAA() 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 CanvasDef cdef = new CanvasDef(new Dimension(800, 600), env);
    cdef.setBackground(Color.GREEN);
    final BufferedImage img = DefaultPortrayalService.portray(cdef, new SceneDef(context, new Hints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)));
    // background is single color opaque we should obtain an RGB color model because of active
    // anti-aliasing
    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 : Hints(org.geotoolkit.factory.Hints) RenderingHints(java.awt.RenderingHints) 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 3 with SceneDef

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

the class ColorModelTest method testOpaqueUnpredictableBackground.

@Test
public void testOpaqueUnpredictableBackground() 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 CanvasDef cdef = new CanvasDef(new Dimension(800, 600), env);
    cdef.setBackground(Color.GREEN);
    final BufferedImage img = DefaultPortrayalService.portray(cdef, new SceneDef(context, null, new PortrayalExtension() {

        @Override
        public void completeCanvas(J2DCanvas canvas) throws PortrayalException {
            canvas.setBackgroundPainter(new GradiantColorPainter());
        }
    }));
    // background is opaque we should obtain an RGB color model
    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) PortrayalExtension(org.geotoolkit.display2d.service.PortrayalExtension) Dimension(java.awt.Dimension) GradiantColorPainter(org.geotoolkit.display2d.canvas.painter.GradiantColorPainter) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) J2DCanvas(org.geotoolkit.display2d.canvas.J2DCanvas) BufferedImage(java.awt.image.BufferedImage) MapLayers(org.apache.sis.portrayal.MapLayers) IndexColorModel(java.awt.image.IndexColorModel) Test(org.junit.Test)

Example 4 with SceneDef

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

the class ColorModelTest method testSolidColorBackground.

@Test
public void testSolidColorBackground() 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 CanvasDef cdef = new CanvasDef(new Dimension(800, 600), env);
    cdef.setBackground(Color.GREEN);
    final BufferedImage img = DefaultPortrayalService.portray(cdef, new SceneDef(context));
    assertTrue(img.getColorModel() instanceof IndexColorModel);
    final IndexColorModel icm = (IndexColorModel) img.getColorModel();
    // we should have only two value
    assertEquals(2, icm.getMapSize());
    assertTrue(Color.GREEN.getRGB() == icm.getRGB(0) || Color.GREEN.getRGB() == icm.getRGB(1));
}
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 5 with SceneDef

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

the class ColorModelTest method testAlphaColorBackground.

@Test
public void testAlphaColorBackground() 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 CanvasDef cdef = new CanvasDef(new Dimension(800, 600), env);
    cdef.setBackground(new Color(0.5f, 0.1f, 0.7f, 0.6f));
    final BufferedImage img = DefaultPortrayalService.portray(cdef, new SceneDef(context));
    // background is not opaque we should obtain an RGBA color model
    assertTrue(!(img.getColorModel() instanceof IndexColorModel));
    assertEquals(ColorSpace.TYPE_RGB, img.getColorModel().getColorSpace().getType());
    assertEquals(4, img.getColorModel().getNumComponents());
    assertEquals(3, img.getColorModel().getNumColorComponents());
}
Also used : Color(java.awt.Color) 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)

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