use of javafx.scene.image.WritableImage in project tokentool by RPTools.
the class ImageUtil method clipImageWithMask.
/*
* Return the intersection between the source image and the mask. Note, the mask does not need to be magenta anymore, any non-transparent pixel is considering a mask
*/
private static Image clipImageWithMask(Image imageSource, Image imageMask) {
int imageWidth = (int) imageMask.getWidth();
int imageHeight = (int) imageMask.getHeight();
WritableImage outputImage = new WritableImage(imageWidth, imageHeight);
PixelReader pixelReader_Mask = imageMask.getPixelReader();
PixelReader pixelReader_Source = imageSource.getPixelReader();
PixelWriter pixelWriter = outputImage.getPixelWriter();
for (int readY = 0; readY < imageHeight; readY++) {
for (int readX = 0; readX < imageWidth; readX++) {
Color pixelColor = pixelReader_Mask.getColor(readX, readY);
if (pixelColor.equals(Color.TRANSPARENT))
pixelWriter.setColor(readX, readY, pixelReader_Source.getColor(readX, readY));
}
}
return outputImage;
}
use of javafx.scene.image.WritableImage in project Board-Instrumentation-Framework by intel.
the class BrushedMetalPaint method getImage.
// ******************** Methods *******************************************
public Image getImage(final double W, final double H) {
final int WIDTH = (int) W;
final int HEIGHT = (int) H;
WritableImage DESTINATION = new WritableImage(WIDTH, HEIGHT);
final int[] IN_PIXELS = new int[WIDTH];
final int[] OUT_PIXELS = new int[WIDTH];
randomNumbers = new Random(0);
final int ALPHA = color & 0xff000000;
final int RED = (color >> 16) & 0xff;
final int GREEN = (color >> 8) & 0xff;
final int BLUE = color & 0xff;
IntStream.range(0, HEIGHT).parallel().forEachOrdered(y -> {
IntStream.range(0, WIDTH).parallel().forEachOrdered(x -> {
int tr = RED;
int tg = GREEN;
int tb = BLUE;
if (shine != 0) {
int f = (int) (255 * shine * Math.sin((double) x / WIDTH * Math.PI));
tr += f;
tg += f;
tb += f;
}
if (monochrome) {
int n = (int) (255 * (2 * randomNumbers.nextFloat() - 1) * amount);
IN_PIXELS[x] = ALPHA | (clamp(tr + n) << 16) | (clamp(tg + n) << 8) | clamp(tb + n);
} else {
IN_PIXELS[x] = ALPHA | (random(tr) << 16) | (random(tg) << 8) | random(tb);
}
});
if (radius != 0) {
blur(IN_PIXELS, OUT_PIXELS, WIDTH, radius);
setRGB(DESTINATION, 0, y, OUT_PIXELS);
} else {
setRGB(DESTINATION, 0, y, IN_PIXELS);
}
});
return DESTINATION;
}
use of javafx.scene.image.WritableImage in project Board-Instrumentation-Framework by intel.
the class Util method createGrayNoise.
public static Image createGrayNoise(final double WIDTH, final double HEIGHT, final Color DARK_COLOR, final Color BRIGHT_COLOR) {
if (WIDTH <= 0 || HEIGHT <= 0) {
return null;
}
final WritableImage IMAGE = new WritableImage((int) WIDTH, (int) HEIGHT);
final PixelWriter PIXEL_WRITER = IMAGE.getPixelWriter();
final Random RND = new Random();
double redDark = DARK_COLOR.getRed();
double greenDark = DARK_COLOR.getGreen();
double blueDark = DARK_COLOR.getBlue();
double redBright = DARK_COLOR.getRed();
double greenBright = DARK_COLOR.getGreen();
double blueBright = DARK_COLOR.getBlue();
int startRed = (int) (Math.min(redDark, redBright) * 255);
int startGreen = (int) (Math.min(greenDark, greenBright) * 255);
int startBlue = (int) (Math.min(blueDark, blueBright) * 255);
int start = Math.max(Math.max(startRed, startGreen), startBlue);
int deltaRed = Math.abs((int) ((BRIGHT_COLOR.getRed() - DARK_COLOR.getRed()) * 255));
int deltaGreen = Math.abs((int) ((BRIGHT_COLOR.getGreen() - DARK_COLOR.getGreen()) * 255));
int deltaBlue = Math.abs((int) ((BRIGHT_COLOR.getBlue() - DARK_COLOR.getBlue()) * 255));
int delta = Math.max(Math.max(deltaRed, deltaGreen), deltaBlue);
int width = (int) WIDTH;
int height = (int) HEIGHT;
IntStream.range(0, height).parallel().forEach(y -> {
IntStream.range(0, width).parallel().forEach(x -> {
int gray = delta > 0 ? start + RND.nextInt(delta) : start;
PIXEL_WRITER.setColor(x, y, Color.rgb(clamp(0, 255, gray), clamp(0, 255, gray), clamp(0, 255, gray)));
});
});
return IMAGE;
}
use of javafx.scene.image.WritableImage in project gs-ui-javafx by graphstream.
the class FxFileSinkImages method initImage.
@Override
protected void initImage() {
//
// Little hack to initialize JavaFX Toolkit.
//
new JFXPanel();
image = new WritableImage(resolution.getWidth(), resolution.getHeight());
canvas = new Canvas(resolution.getWidth(), resolution.getHeight());
}
use of javafx.scene.image.WritableImage in project Board-Instrumentation-Framework by intel.
the class LcdClockSkin method createNoiseImage.
private Image createNoiseImage(final double WIDTH, final double HEIGHT, final Color DARK_COLOR, final Color BRIGHT_COLOR, final double ALPHA_VARIATION_IN_PERCENT) {
int width = WIDTH <= 0 ? (int) PREFERRED_WIDTH : (int) WIDTH;
int height = HEIGHT <= 0 ? (int) PREFERRED_HEIGHT : (int) HEIGHT;
double alphaVariationInPercent = getSkinnable().clamp(0, 100, ALPHA_VARIATION_IN_PERCENT);
final WritableImage IMAGE = new WritableImage(width, height);
final PixelWriter PIXEL_WRITER = IMAGE.getPixelWriter();
final Random BW_RND = new Random();
final Random ALPHA_RND = new Random();
final double ALPHA_START = alphaVariationInPercent / 100 / 2;
final double ALPHA_VARIATION = alphaVariationInPercent / 100;
/* This version makes problems when using Robovm
IntStream.range(0, height).parallel().forEachOrdered(
y -> {
IntStream.range(0, width).parallel().forEachOrdered(
x -> {
final Color NOISE_COLOR = BW_RND.nextBoolean() == true ? BRIGHT_COLOR : DARK_COLOR;
final double NOISE_ALPHA = getSkinnable().clamp(0, 1, ALPHA_START + ALPHA_RND.nextDouble() * ALPHA_VARIATION);
PIXEL_WRITER.setColor(x, y, Color.color(NOISE_COLOR.getRed(), NOISE_COLOR.getGreen(), NOISE_COLOR.getBlue(), NOISE_ALPHA));
}
);
}
);
*/
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
final Color NOISE_COLOR = BW_RND.nextBoolean() == true ? BRIGHT_COLOR : DARK_COLOR;
final double NOISE_ALPHA = getSkinnable().clamp(0, 1, ALPHA_START + ALPHA_RND.nextDouble() * ALPHA_VARIATION);
PIXEL_WRITER.setColor(x, y, Color.color(NOISE_COLOR.getRed(), NOISE_COLOR.getGreen(), NOISE_COLOR.getBlue(), NOISE_ALPHA));
}
}
return IMAGE;
}
Aggregations