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.");
}
}
}
}
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());
}
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());
}
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));
}
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());
}
Aggregations