use of org.geotoolkit.factory.Hints 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.factory.Hints in project geotoolkit by Geomatys.
the class CoverageImageTest method testImageLayer.
/**
* Compute and compare result image from {@link MapContext} build with {@link CoverageMapLayer},
* and sourceImage.
*
* @param sourceImage expected image will be tested.
* @param cml {@link CoverageMapLayer} use to build {@link MapContext}.
* @throws PortrayalException
*/
private void testImageLayer(RenderedImage sourceImage, MapLayer cml) throws PortrayalException {
// create a mapcontext
final MapLayers context = MapBuilder.createContext();
context.getComponents().add(cml);
outputImgDim.setSize(proportionalityCoefficient * srcWidth, proportionalityCoefficient * srcHeight);
hints = new Hints(GO2Hints.KEY_COLOR_MODEL, sourceImage.getColorModel(), RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
cdef.setDimension(outputImgDim);
sdef.setContext(context);
sdef.setHints(hints);
cdef.setEnvelope(resEnv);
final BufferedImage imgResult = DefaultPortrayalService.portray(cdef, sdef);
checkImage(sourceImage, imgResult, proportionalityCoefficient);
}
use of org.geotoolkit.factory.Hints in project geotoolkit by Geomatys.
the class RasterSymbolizerTest method UTM32632Test.
/**
* Check proper image reprojection in UTM
*/
@Ignore
@Test
public void UTM32632Test() throws Exception {
final BufferedImage img = new BufferedImage(120, 90, BufferedImage.TYPE_INT_ARGB);
final Graphics2D g2d = img.createGraphics();
g2d.setColor(Color.GREEN);
g2d.fillRect(0, 0, 120, 90);
// set it's envelope
final GeneralEnvelope gridEnv = new GeneralEnvelope(CommonCRS.WGS84.normalizedGeographic());
gridEnv.setRange(0, 0, 120);
gridEnv.setRange(1, 0, 90);
// create the coverage
final GridCoverage coverage = new GridCoverage2D(new GridGeometry(null, gridEnv, GridOrientation.HOMOTHETY), null, img);
final MapLayers context = MapBuilder.createContext();
final MapLayer cl = MapBuilder.createCoverageLayer(coverage, SF.style(StyleConstants.DEFAULT_RASTER_SYMBOLIZER), "coverage");
context.getComponents().add(cl);
final GeneralEnvelope env = new GeneralEnvelope(CRS.forCode("EPSG:32632"));
env.setRange(0, -2574823.6832217844, 5487970.783439655);
env.setRange(1, 4289777.45228916, 1.0491927042028729E7);
final Hints hints = new Hints();
final SceneDef scenedef = new SceneDef(context, hints);
final CanvasDef canvasdef = new CanvasDef(new Dimension(800, 800), env);
canvasdef.setBackground(Color.WHITE);
final BufferedImage buffer = DefaultPortrayalService.portray(canvasdef, scenedef);
ImageIO.write(buffer, "PNG", new File("test.png"));
// We should obtain a green triangle crossing the image looking like this :
//
// |\
// |_\
// we can't test the shape so we test we found more and more green pixels on each line
// we expect to have a blue label at the center of the image
final int[] pixel = new int[4];
final int[] green = new int[] { 0, 255, 0, 255 };
int nbGreen = 0;
final Raster raster = buffer.getData();
for (int y = 0; y < 800; y++) {
int nb = 0;
for (int x = 0; x < 800; x++) {
raster.getPixel(x, y, pixel);
if (Arrays.equals(green, pixel)) {
nb++;
}
}
assertTrue("expected at least one green pixel", nb > 0);
assertTrue(nb >= nbGreen);
nbGreen = nb;
}
}
use of org.geotoolkit.factory.Hints in project geotoolkit by Geomatys.
the class RasterSymbolizerTest method coverage_whose_grid_origin_is_lower_left_should_be_flipped.
/**
* Source coverage will be a matrix <em>with origin lower-left</em>:
* <table>
* <tr><td>4</td><td>3</td></tr>
* <tr><td>1</td><td>2</td></tr>
* </table>
* @throws PortrayalException
*/
@Test
public void coverage_whose_grid_origin_is_lower_left_should_be_flipped() throws PortrayalException {
final BufferedImage image = new BufferedImage(2, 2, BufferedImage.TYPE_BYTE_GRAY);
image.getRaster().setSample(0, 0, 0, 1);
image.getRaster().setSample(1, 0, 0, 2);
image.getRaster().setSample(1, 1, 0, 3);
image.getRaster().setSample(0, 1, 0, 4);
final GridGeometry geom = new GridGeometry(new GridExtent(2, 2), PixelInCell.CELL_CENTER, new AffineTransform2D(1, 0, 0, 1, 10, 10), CommonCRS.defaultGeographic());
final GridCoverage baseData = new GridCoverage2D(geom, null, image);
MapLayer layer = MapBuilder.createLayer(new InMemoryGridCoverageResource(baseData));
final MapLayers ctx = MapBuilder.createContext();
ctx.getComponents().add(layer);
BufferedImage rendering = DefaultPortrayalService.portray(new CanvasDef(new Dimension(2, 2), geom.getEnvelope()), new SceneDef(ctx, new Hints(GO2Hints.KEY_INTERPOLATION, InterpolationCase.NEIGHBOR, RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)));
// As display is oriented upper-left, output should be flipped on y axis. Also, the renderer will stretch values
// along 256 colors, so we have to adapt comparison.
final int[] pixels = rendering.getRaster().getPixels(0, 0, 2, 2, (int[]) null);
final int[] expected = { 255, 255, 255, 255, 165, 165, 165, 255, 0, 0, 0, 255, 88, 88, 88, 255 };
assertArrayEquals(expected, pixels);
final ColorMap colorMap = SF.colorMap(SF.interpolateFunction(null, Arrays.asList(SF.interpolationPoint(1, FF.literal(Color.RED)), SF.interpolationPoint(2, FF.literal(Color.GREEN)), SF.interpolationPoint(3, FF.literal(Color.BLUE)), SF.interpolationPoint(4, FF.literal(Color.WHITE))), null, null, FF.literal(Color.BLACK)));
final RasterSymbolizer symbol = SF.rasterSymbolizer(null, null, null, null, colorMap, null, null, null);
ctx.getComponents().set(0, MapBuilder.createCoverageLayer(baseData, SF.style(symbol), "test"));
rendering = DefaultPortrayalService.portray(new CanvasDef(new Dimension(2, 2), geom.getEnvelope()), new SceneDef(ctx, new Hints(GO2Hints.KEY_INTERPOLATION, InterpolationCase.NEIGHBOR, RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)));
assertEquals(Color.WHITE.getRGB(), rendering.getRGB(0, 0));
assertEquals(Color.BLUE.getRGB(), rendering.getRGB(1, 0));
assertEquals(Color.RED.getRGB(), rendering.getRGB(0, 1));
assertEquals(Color.GREEN.getRGB(), rendering.getRGB(1, 1));
}
use of org.geotoolkit.factory.Hints in project geotoolkit by Geomatys.
the class RasterSymbolizerTest method renderInterpolationCoverage.
/**
* Render a coverage with nearest and lanczos interpolation.
*/
@Test
public void renderInterpolationCoverage() throws FactoryException, PortrayalException, IOException {
final CoordinateReferenceSystem crs = CommonCRS.WGS84.normalizedGeographic();
final BufferedImage image = new BufferedImage(36, 18, BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
g.setColor(Color.RED);
g.fillRect(0, 0, 18, 9);
g.setColor(Color.GREEN);
g.fillRect(18, 0, 18, 9);
g.setColor(Color.BLUE);
g.fillRect(0, 9, 18, 9);
g.setColor(Color.YELLOW);
g.fillRect(18, 9, 18, 9);
g.dispose();
final GridExtent extent = new GridExtent(36, 18);
final AffineTransform2D gridToCrs = new AffineTransform2D(10, 0, 0, -10, -180, 90);
final GridGeometry grid = new GridGeometry(extent, PixelInCell.CELL_CORNER, gridToCrs, crs);
final SampleDimension red = new SampleDimension.Builder().setName("1").build();
final SampleDimension green = new SampleDimension.Builder().setName("2").build();
final SampleDimension blue = new SampleDimension.Builder().setName("3").build();
final GridCoverage2D coverage = new GridCoverage2D(grid, Arrays.asList(red, green, blue), image);
final GridExtent queryextent = new GridExtent(360, 180);
final GeneralEnvelope queryenv = new GeneralEnvelope(crs);
queryenv.setRange(0, -180, 180);
queryenv.setRange(1, -90, 90);
final GridGeometry querygrid = new GridGeometry(queryextent, queryenv, GridOrientation.HOMOTHETY);
final MapLayers context = MapBuilder.createContext();
context.getComponents().add(MapBuilder.createCoverageLayer(new InMemoryGridCoverageResource(coverage)));
final BufferedImage nearest;
final BufferedImage bicubic;
final BufferedImage lanczos;
{
final Hints hints = new Hints();
hints.put(GO2Hints.KEY_INTERPOLATION, InterpolationCase.NEIGHBOR);
final CanvasDef cdef = new CanvasDef(querygrid);
final SceneDef sdef = new SceneDef(context, hints);
nearest = DefaultPortrayalService.portray(cdef, sdef);
}
{
final Hints hints = new Hints();
hints.put(GO2Hints.KEY_INTERPOLATION, InterpolationCase.BICUBIC2);
final CanvasDef cdef = new CanvasDef(querygrid);
final SceneDef sdef = new SceneDef(context, hints);
bicubic = DefaultPortrayalService.portray(cdef, sdef);
}
{
final Hints hints = new Hints();
hints.put(GO2Hints.KEY_INTERPOLATION, InterpolationCase.LANCZOS);
final CanvasDef cdef = new CanvasDef(querygrid);
final SceneDef sdef = new SceneDef(context, hints);
lanczos = DefaultPortrayalService.portray(cdef, sdef);
}
int nearestRgb = nearest.getRGB(179, 0);
int bicubicRgb = bicubic.getRGB(179, 0);
int naczosRgb = lanczos.getRGB(179, 0);
assertTrue(nearestRgb != bicubicRgb);
assertTrue(bicubicRgb != naczosRgb);
}
Aggregations