use of org.opengis.style.ColorMap in project geotoolkit by Geomatys.
the class RasterSymbolizerRenderer method prepareCoverageToResampling.
/**
* Analyse input coverage to know if we need to add an alpha channel. Alpha channel is required in photographic
* coverage case, in order for the resample to deliver a ready to style image.
*
* @param source The coverage to analyse.
* @param symbolizer contain color Map.
* @return The same coverage as input if style do not require an ARGB data to properly render, or a new ARGB coverage
* computed from source data.
*/
@Override
protected final GridCoverage prepareCoverageToResampling(final GridCoverage source, final CachedRasterSymbolizer symbolizer) {
final ColorMap cMap = symbolizer.getSource().getColorMap();
if (cMap != null && cMap.getFunction() != null) {
// Coloration is handled externally
return source;
}
final List<SampleDimension> sds = source.getSampleDimensions();
if (sds == null || sds.size() != 3) {
return source;
}
if (source != source.forConvertedValues(false)) {
return source;
}
for (SampleDimension sd : sds) {
if (sd.getTransferFunction().isPresent())
return source;
}
// At this point, no geophysic information has been found. We will consider input coverage as a colorized image.
return new ForcedAlpha(source);
}
use of org.opengis.style.ColorMap 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.opengis.style.ColorMap in project geotoolkit by Geomatys.
the class Tester method createRasterSymbolizer.
private static RasterSymbolizer createRasterSymbolizer() {
String name = "Raster symbolizer name";
Description desc = STYLE_FACTORY.description("Raster symbolizer title", "Raster symbolizer description");
Unit uom = Units.METRE;
String geom = "geom";
Expression opacity = FILTER_FACTORY.literal(0.5);
ChannelSelection selection = STYLE_FACTORY.channelSelection(STYLE_FACTORY.selectedChannelType("chanel2", FILTER_FACTORY.literal(1)));
OverlapBehavior overlap = OverlapBehavior.RANDOM;
ColorMap colorMap = STYLE_FACTORY.colorMap();
ContrastEnhancement enchance = STYLE_FACTORY.contrastEnhancement();
ShadedRelief relief = STYLE_FACTORY.shadedRelief(FILTER_FACTORY.literal(3), true);
Symbolizer outline = createLineSymbolizer();
return STYLE_FACTORY.rasterSymbolizer(name, geom, desc, uom, opacity, selection, overlap, colorMap, enchance, relief, outline);
}
use of org.opengis.style.ColorMap in project geotoolkit by Geomatys.
the class XMLUtilitiesTest method createRasterSymbolizer.
private static RasterSymbolizer createRasterSymbolizer() {
String name = "Raster symbolizer name";
Description desc = STYLE_FACTORY.description("Raster symbolizer title", "Raster symbolizer description");
Unit uom = Units.METRE;
String geom = "geom";
Expression opacity = FILTER_FACTORY.literal(0.5);
ChannelSelection selection = STYLE_FACTORY.channelSelection(STYLE_FACTORY.selectedChannelType("chanel2", FILTER_FACTORY.literal(1)));
OverlapBehavior overlap = OverlapBehavior.RANDOM;
ColorMap colorMap = STYLE_FACTORY.colorMap();
ContrastEnhancement enchance = STYLE_FACTORY.contrastEnhancement();
ShadedRelief relief = STYLE_FACTORY.shadedRelief(FILTER_FACTORY.literal(3), true);
Symbolizer outline = createLineSymbolizer();
return STYLE_FACTORY.rasterSymbolizer(name, geom, desc, uom, opacity, selection, overlap, colorMap, enchance, relief, outline);
}
use of org.opengis.style.ColorMap in project geotoolkit by Geomatys.
the class Styles method colorCategorizeRaster.
public static MutableStyle colorCategorizeRaster() {
final Map<Expression, Expression> values = new HashMap<>();
values.put(StyleConstants.CATEGORIZE_LESS_INFINITY, SF.literal(new Color(46, 154, 88)));
values.put(FF.literal(1003), SF.literal(new Color(46, 154, 88)));
values.put(FF.literal(1800), SF.literal(new Color(251, 255, 128)));
values.put(FF.literal(2800), SF.literal(new Color(224, 108, 31)));
values.put(FF.literal(3500), SF.literal(new Color(200, 55, 55)));
values.put(FF.literal(4397), SF.literal(new Color(215, 244, 244)));
final Expression lookup = DEFAULT_CATEGORIZE_LOOKUP;
final Literal fallback = DEFAULT_FALLBACK;
final Expression function = SF.categorizeFunction(lookup, values, ThreshholdsBelongTo.SUCCEEDING, fallback);
final ChannelSelection selection = null;
final Expression opacity = LITERAL_ONE_FLOAT;
final OverlapBehavior overlap = OverlapBehavior.LATEST_ON_TOP;
final ColorMap colorMap = SF.colorMap(function);
final ContrastEnhancement enchance = SF.contrastEnhancement(LITERAL_ONE_FLOAT, ContrastMethod.NONE);
final ShadedRelief relief = SF.shadedRelief(LITERAL_ONE_FLOAT);
final Symbolizer outline = null;
final Unit uom = Units.POINT;
final String geom = DEFAULT_GEOM;
final String name = "raster symbol name";
final Description desc = DEFAULT_DESCRIPTION;
final RasterSymbolizer symbol = SF.rasterSymbolizer(name, geom, desc, uom, opacity, selection, overlap, colorMap, enchance, relief, outline);
return SF.style(symbol);
}
Aggregations