use of ol.PixelColor in project gwt-ol3 by TDesjardins.
the class RasterExample method getRasterSource.
private static Raster getRasterSource(Source source, RasterOperationType type) {
// wrap source with raster source layer
RasterOptions rasterOptions = OLFactory.createRasterOptionsWithSource(source);
rasterOptions.setOperationType(type);
RasterOperation<?> rasterOperation = null;
switch(type) {
case PIXEL:
rasterOperation = (PixelColor[] pixels) -> {
final int channel = 0;
final int threshold = 245;
// get pixel of first source
PixelColor pixel = pixels[0];
// extract pixel value and apply operation
int value = pixel.getChannel(channel);
pixel.clear();
if (value > threshold) {
pixel.setChannel(channel, 255);
pixel.setAlpha(128);
}
return pixel;
};
break;
case IMAGE:
rasterOperation = (ImageData[] sourceImages) -> {
// get image of first source
ImageData image = sourceImages[0];
// apply image wide operation, make the lower part of the image darker
final int width = image.width;
final int height = image.height;
PixelColor pixel = new PixelColor(0, 0, 0, 128);
for (int y = height / 2; y < height; ++y) {
for (int x = 0; x < width; ++x) {
image.putPixel(x, y, pixel);
}
}
return image;
};
break;
}
// set raster operation and return raster
rasterOptions.setOperation(rasterOperation);
return new Raster(rasterOptions);
}
use of ol.PixelColor in project gwt-ol3 by TDesjardins.
the class RasterTest method testRaster.
public void testRaster() {
injectUrlAndTest(() -> {
RasterOptions rasterOptions = new RasterOptions();
rasterOptions.disableWorkerSupport();
rasterOptions.setSource(new Osm());
rasterOptions.setOperationType(RasterOperationType.PIXEL);
rasterOptions.setOperation((PixelColor[] pixels) -> {
final int channel = 0;
final int threshold = 245;
// get pixel of first source
PixelColor pixel = pixels[0];
// extract pixel value and apply operation
int value = pixel.getChannel(channel);
pixel.clear();
if (value > threshold) {
pixel.setChannel(channel, 255);
pixel.setAlpha(128);
}
return pixel;
});
Raster raster = new Raster(rasterOptions);
assertNotNull(raster);
assertTrue(raster instanceof Source);
});
}
Aggregations