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